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
);
349 /* Remember x_pixels_diff and y_pixels_diff. */
350 f
->x_pixels_diff
= pt
.x
- rect
.left
;
351 f
->y_pixels_diff
= pt
.y
- rect
.top
;
357 /* Returns the window rectangle appropriate for the given fullscreen mode.
358 The normal rect parameter was the window's rectangle prior to entering
359 fullscreen mode. If multiple monitor support is available, the nearest
360 monitor to the window is chosen. */
363 w32_fullscreen_rect (HWND hwnd
, int fsmode
, RECT normal
, RECT
*rect
)
365 struct MONITOR_INFO mi
= { sizeof(mi
) };
366 if (monitor_from_window_fn
&& get_monitor_info_fn
)
369 monitor_from_window_fn (hwnd
, MONITOR_DEFAULT_TO_NEAREST
);
370 get_monitor_info_fn (monitor
, &mi
);
374 mi
.rcMonitor
.left
= 0;
375 mi
.rcMonitor
.top
= 0;
376 mi
.rcMonitor
.right
= GetSystemMetrics (SM_CXSCREEN
);
377 mi
.rcMonitor
.bottom
= GetSystemMetrics (SM_CYSCREEN
);
380 mi
.rcWork
.right
= GetSystemMetrics (SM_CXMAXIMIZED
);
381 mi
.rcWork
.bottom
= GetSystemMetrics (SM_CYMAXIMIZED
);
386 case FULLSCREEN_BOTH
:
387 rect
->left
= mi
.rcMonitor
.left
;
388 rect
->top
= mi
.rcMonitor
.top
;
389 rect
->right
= mi
.rcMonitor
.right
;
390 rect
->bottom
= mi
.rcMonitor
.bottom
;
392 case FULLSCREEN_WIDTH
:
393 rect
->left
= mi
.rcWork
.left
;
394 rect
->top
= normal
.top
;
395 rect
->right
= mi
.rcWork
.right
;
396 rect
->bottom
= normal
.bottom
;
398 case FULLSCREEN_HEIGHT
:
399 rect
->left
= normal
.left
;
400 rect
->top
= mi
.rcWork
.top
;
401 rect
->right
= normal
.right
;
402 rect
->bottom
= mi
.rcWork
.bottom
;
412 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
,
413 Sw32_define_rgb_color
, 4, 4, 0,
414 doc
: /* Convert RGB numbers to a Windows color reference and associate with NAME.
415 This adds or updates a named color to `w32-color-map', making it
416 available for use. The original entry's RGB ref is returned, or nil
417 if the entry is new. */)
418 (Lisp_Object red
, Lisp_Object green
, Lisp_Object blue
, Lisp_Object name
)
421 Lisp_Object oldrgb
= Qnil
;
425 CHECK_NUMBER (green
);
429 XSETINT (rgb
, RGB (XUINT (red
), XUINT (green
), XUINT (blue
)));
433 /* replace existing entry in w32-color-map or add new entry. */
434 entry
= Fassoc (name
, Vw32_color_map
);
437 entry
= Fcons (name
, rgb
);
438 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
442 oldrgb
= Fcdr (entry
);
443 Fsetcdr (entry
, rgb
);
451 /* The default colors for the w32 color map */
452 typedef struct colormap_t
458 colormap_t w32_color_map
[] =
460 {"snow" , PALETTERGB (255,250,250)},
461 {"ghost white" , PALETTERGB (248,248,255)},
462 {"GhostWhite" , PALETTERGB (248,248,255)},
463 {"white smoke" , PALETTERGB (245,245,245)},
464 {"WhiteSmoke" , PALETTERGB (245,245,245)},
465 {"gainsboro" , PALETTERGB (220,220,220)},
466 {"floral white" , PALETTERGB (255,250,240)},
467 {"FloralWhite" , PALETTERGB (255,250,240)},
468 {"old lace" , PALETTERGB (253,245,230)},
469 {"OldLace" , PALETTERGB (253,245,230)},
470 {"linen" , PALETTERGB (250,240,230)},
471 {"antique white" , PALETTERGB (250,235,215)},
472 {"AntiqueWhite" , PALETTERGB (250,235,215)},
473 {"papaya whip" , PALETTERGB (255,239,213)},
474 {"PapayaWhip" , PALETTERGB (255,239,213)},
475 {"blanched almond" , PALETTERGB (255,235,205)},
476 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
477 {"bisque" , PALETTERGB (255,228,196)},
478 {"peach puff" , PALETTERGB (255,218,185)},
479 {"PeachPuff" , PALETTERGB (255,218,185)},
480 {"navajo white" , PALETTERGB (255,222,173)},
481 {"NavajoWhite" , PALETTERGB (255,222,173)},
482 {"moccasin" , PALETTERGB (255,228,181)},
483 {"cornsilk" , PALETTERGB (255,248,220)},
484 {"ivory" , PALETTERGB (255,255,240)},
485 {"lemon chiffon" , PALETTERGB (255,250,205)},
486 {"LemonChiffon" , PALETTERGB (255,250,205)},
487 {"seashell" , PALETTERGB (255,245,238)},
488 {"honeydew" , PALETTERGB (240,255,240)},
489 {"mint cream" , PALETTERGB (245,255,250)},
490 {"MintCream" , PALETTERGB (245,255,250)},
491 {"azure" , PALETTERGB (240,255,255)},
492 {"alice blue" , PALETTERGB (240,248,255)},
493 {"AliceBlue" , PALETTERGB (240,248,255)},
494 {"lavender" , PALETTERGB (230,230,250)},
495 {"lavender blush" , PALETTERGB (255,240,245)},
496 {"LavenderBlush" , PALETTERGB (255,240,245)},
497 {"misty rose" , PALETTERGB (255,228,225)},
498 {"MistyRose" , PALETTERGB (255,228,225)},
499 {"white" , PALETTERGB (255,255,255)},
500 {"black" , PALETTERGB ( 0, 0, 0)},
501 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
502 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
503 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
504 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
505 {"dim gray" , PALETTERGB (105,105,105)},
506 {"DimGray" , PALETTERGB (105,105,105)},
507 {"dim grey" , PALETTERGB (105,105,105)},
508 {"DimGrey" , PALETTERGB (105,105,105)},
509 {"slate gray" , PALETTERGB (112,128,144)},
510 {"SlateGray" , PALETTERGB (112,128,144)},
511 {"slate grey" , PALETTERGB (112,128,144)},
512 {"SlateGrey" , PALETTERGB (112,128,144)},
513 {"light slate gray" , PALETTERGB (119,136,153)},
514 {"LightSlateGray" , PALETTERGB (119,136,153)},
515 {"light slate grey" , PALETTERGB (119,136,153)},
516 {"LightSlateGrey" , PALETTERGB (119,136,153)},
517 {"gray" , PALETTERGB (190,190,190)},
518 {"grey" , PALETTERGB (190,190,190)},
519 {"light grey" , PALETTERGB (211,211,211)},
520 {"LightGrey" , PALETTERGB (211,211,211)},
521 {"light gray" , PALETTERGB (211,211,211)},
522 {"LightGray" , PALETTERGB (211,211,211)},
523 {"midnight blue" , PALETTERGB ( 25, 25,112)},
524 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
525 {"navy" , PALETTERGB ( 0, 0,128)},
526 {"navy blue" , PALETTERGB ( 0, 0,128)},
527 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
528 {"cornflower blue" , PALETTERGB (100,149,237)},
529 {"CornflowerBlue" , PALETTERGB (100,149,237)},
530 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
531 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
532 {"slate blue" , PALETTERGB (106, 90,205)},
533 {"SlateBlue" , PALETTERGB (106, 90,205)},
534 {"medium slate blue" , PALETTERGB (123,104,238)},
535 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
536 {"light slate blue" , PALETTERGB (132,112,255)},
537 {"LightSlateBlue" , PALETTERGB (132,112,255)},
538 {"medium blue" , PALETTERGB ( 0, 0,205)},
539 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
540 {"royal blue" , PALETTERGB ( 65,105,225)},
541 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
542 {"blue" , PALETTERGB ( 0, 0,255)},
543 {"dodger blue" , PALETTERGB ( 30,144,255)},
544 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
545 {"deep sky blue" , PALETTERGB ( 0,191,255)},
546 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
547 {"sky blue" , PALETTERGB (135,206,235)},
548 {"SkyBlue" , PALETTERGB (135,206,235)},
549 {"light sky blue" , PALETTERGB (135,206,250)},
550 {"LightSkyBlue" , PALETTERGB (135,206,250)},
551 {"steel blue" , PALETTERGB ( 70,130,180)},
552 {"SteelBlue" , PALETTERGB ( 70,130,180)},
553 {"light steel blue" , PALETTERGB (176,196,222)},
554 {"LightSteelBlue" , PALETTERGB (176,196,222)},
555 {"light blue" , PALETTERGB (173,216,230)},
556 {"LightBlue" , PALETTERGB (173,216,230)},
557 {"powder blue" , PALETTERGB (176,224,230)},
558 {"PowderBlue" , PALETTERGB (176,224,230)},
559 {"pale turquoise" , PALETTERGB (175,238,238)},
560 {"PaleTurquoise" , PALETTERGB (175,238,238)},
561 {"dark turquoise" , PALETTERGB ( 0,206,209)},
562 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
563 {"medium turquoise" , PALETTERGB ( 72,209,204)},
564 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
565 {"turquoise" , PALETTERGB ( 64,224,208)},
566 {"cyan" , PALETTERGB ( 0,255,255)},
567 {"light cyan" , PALETTERGB (224,255,255)},
568 {"LightCyan" , PALETTERGB (224,255,255)},
569 {"cadet blue" , PALETTERGB ( 95,158,160)},
570 {"CadetBlue" , PALETTERGB ( 95,158,160)},
571 {"medium aquamarine" , PALETTERGB (102,205,170)},
572 {"MediumAquamarine" , PALETTERGB (102,205,170)},
573 {"aquamarine" , PALETTERGB (127,255,212)},
574 {"dark green" , PALETTERGB ( 0,100, 0)},
575 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
576 {"dark olive green" , PALETTERGB ( 85,107, 47)},
577 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
578 {"dark sea green" , PALETTERGB (143,188,143)},
579 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
580 {"sea green" , PALETTERGB ( 46,139, 87)},
581 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
582 {"medium sea green" , PALETTERGB ( 60,179,113)},
583 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
584 {"light sea green" , PALETTERGB ( 32,178,170)},
585 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
586 {"pale green" , PALETTERGB (152,251,152)},
587 {"PaleGreen" , PALETTERGB (152,251,152)},
588 {"spring green" , PALETTERGB ( 0,255,127)},
589 {"SpringGreen" , PALETTERGB ( 0,255,127)},
590 {"lawn green" , PALETTERGB (124,252, 0)},
591 {"LawnGreen" , PALETTERGB (124,252, 0)},
592 {"green" , PALETTERGB ( 0,255, 0)},
593 {"chartreuse" , PALETTERGB (127,255, 0)},
594 {"medium spring green" , PALETTERGB ( 0,250,154)},
595 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
596 {"green yellow" , PALETTERGB (173,255, 47)},
597 {"GreenYellow" , PALETTERGB (173,255, 47)},
598 {"lime green" , PALETTERGB ( 50,205, 50)},
599 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
600 {"yellow green" , PALETTERGB (154,205, 50)},
601 {"YellowGreen" , PALETTERGB (154,205, 50)},
602 {"forest green" , PALETTERGB ( 34,139, 34)},
603 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
604 {"olive drab" , PALETTERGB (107,142, 35)},
605 {"OliveDrab" , PALETTERGB (107,142, 35)},
606 {"dark khaki" , PALETTERGB (189,183,107)},
607 {"DarkKhaki" , PALETTERGB (189,183,107)},
608 {"khaki" , PALETTERGB (240,230,140)},
609 {"pale goldenrod" , PALETTERGB (238,232,170)},
610 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
611 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
612 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
613 {"light yellow" , PALETTERGB (255,255,224)},
614 {"LightYellow" , PALETTERGB (255,255,224)},
615 {"yellow" , PALETTERGB (255,255, 0)},
616 {"gold" , PALETTERGB (255,215, 0)},
617 {"light goldenrod" , PALETTERGB (238,221,130)},
618 {"LightGoldenrod" , PALETTERGB (238,221,130)},
619 {"goldenrod" , PALETTERGB (218,165, 32)},
620 {"dark goldenrod" , PALETTERGB (184,134, 11)},
621 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
622 {"rosy brown" , PALETTERGB (188,143,143)},
623 {"RosyBrown" , PALETTERGB (188,143,143)},
624 {"indian red" , PALETTERGB (205, 92, 92)},
625 {"IndianRed" , PALETTERGB (205, 92, 92)},
626 {"saddle brown" , PALETTERGB (139, 69, 19)},
627 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
628 {"sienna" , PALETTERGB (160, 82, 45)},
629 {"peru" , PALETTERGB (205,133, 63)},
630 {"burlywood" , PALETTERGB (222,184,135)},
631 {"beige" , PALETTERGB (245,245,220)},
632 {"wheat" , PALETTERGB (245,222,179)},
633 {"sandy brown" , PALETTERGB (244,164, 96)},
634 {"SandyBrown" , PALETTERGB (244,164, 96)},
635 {"tan" , PALETTERGB (210,180,140)},
636 {"chocolate" , PALETTERGB (210,105, 30)},
637 {"firebrick" , PALETTERGB (178,34, 34)},
638 {"brown" , PALETTERGB (165,42, 42)},
639 {"dark salmon" , PALETTERGB (233,150,122)},
640 {"DarkSalmon" , PALETTERGB (233,150,122)},
641 {"salmon" , PALETTERGB (250,128,114)},
642 {"light salmon" , PALETTERGB (255,160,122)},
643 {"LightSalmon" , PALETTERGB (255,160,122)},
644 {"orange" , PALETTERGB (255,165, 0)},
645 {"dark orange" , PALETTERGB (255,140, 0)},
646 {"DarkOrange" , PALETTERGB (255,140, 0)},
647 {"coral" , PALETTERGB (255,127, 80)},
648 {"light coral" , PALETTERGB (240,128,128)},
649 {"LightCoral" , PALETTERGB (240,128,128)},
650 {"tomato" , PALETTERGB (255, 99, 71)},
651 {"orange red" , PALETTERGB (255, 69, 0)},
652 {"OrangeRed" , PALETTERGB (255, 69, 0)},
653 {"red" , PALETTERGB (255, 0, 0)},
654 {"hot pink" , PALETTERGB (255,105,180)},
655 {"HotPink" , PALETTERGB (255,105,180)},
656 {"deep pink" , PALETTERGB (255, 20,147)},
657 {"DeepPink" , PALETTERGB (255, 20,147)},
658 {"pink" , PALETTERGB (255,192,203)},
659 {"light pink" , PALETTERGB (255,182,193)},
660 {"LightPink" , PALETTERGB (255,182,193)},
661 {"pale violet red" , PALETTERGB (219,112,147)},
662 {"PaleVioletRed" , PALETTERGB (219,112,147)},
663 {"maroon" , PALETTERGB (176, 48, 96)},
664 {"medium violet red" , PALETTERGB (199, 21,133)},
665 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
666 {"violet red" , PALETTERGB (208, 32,144)},
667 {"VioletRed" , PALETTERGB (208, 32,144)},
668 {"magenta" , PALETTERGB (255, 0,255)},
669 {"violet" , PALETTERGB (238,130,238)},
670 {"plum" , PALETTERGB (221,160,221)},
671 {"orchid" , PALETTERGB (218,112,214)},
672 {"medium orchid" , PALETTERGB (186, 85,211)},
673 {"MediumOrchid" , PALETTERGB (186, 85,211)},
674 {"dark orchid" , PALETTERGB (153, 50,204)},
675 {"DarkOrchid" , PALETTERGB (153, 50,204)},
676 {"dark violet" , PALETTERGB (148, 0,211)},
677 {"DarkViolet" , PALETTERGB (148, 0,211)},
678 {"blue violet" , PALETTERGB (138, 43,226)},
679 {"BlueViolet" , PALETTERGB (138, 43,226)},
680 {"purple" , PALETTERGB (160, 32,240)},
681 {"medium purple" , PALETTERGB (147,112,219)},
682 {"MediumPurple" , PALETTERGB (147,112,219)},
683 {"thistle" , PALETTERGB (216,191,216)},
684 {"gray0" , PALETTERGB ( 0, 0, 0)},
685 {"grey0" , PALETTERGB ( 0, 0, 0)},
686 {"dark grey" , PALETTERGB (169,169,169)},
687 {"DarkGrey" , PALETTERGB (169,169,169)},
688 {"dark gray" , PALETTERGB (169,169,169)},
689 {"DarkGray" , PALETTERGB (169,169,169)},
690 {"dark blue" , PALETTERGB ( 0, 0,139)},
691 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
692 {"dark cyan" , PALETTERGB ( 0,139,139)},
693 {"DarkCyan" , PALETTERGB ( 0,139,139)},
694 {"dark magenta" , PALETTERGB (139, 0,139)},
695 {"DarkMagenta" , PALETTERGB (139, 0,139)},
696 {"dark red" , PALETTERGB (139, 0, 0)},
697 {"DarkRed" , PALETTERGB (139, 0, 0)},
698 {"light green" , PALETTERGB (144,238,144)},
699 {"LightGreen" , PALETTERGB (144,238,144)},
703 w32_default_color_map (void)
706 colormap_t
*pc
= w32_color_map
;
713 for (i
= 0; i
< ARRAYELTS (w32_color_map
); pc
++, i
++)
714 cmap
= Fcons (Fcons (build_string (pc
->name
),
715 make_number (pc
->colorref
)),
723 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
724 0, 0, 0, doc
: /* Return the default color map. */)
727 return w32_default_color_map ();
731 w32_color_map_lookup (const char *colorname
)
733 Lisp_Object tail
, ret
= Qnil
;
737 for (tail
= Vw32_color_map
; CONSP (tail
); tail
= XCDR (tail
))
739 register Lisp_Object elt
, tem
;
742 if (!CONSP (elt
)) continue;
746 if (lstrcmpi (SDATA (tem
), colorname
) == 0)
762 add_system_logical_colors_to_map (Lisp_Object
*system_colors
)
766 /* Other registry operations are done with input blocked. */
769 /* Look for "Control Panel/Colors" under User and Machine registry
771 if (RegOpenKeyEx (HKEY_CURRENT_USER
, "Control Panel\\Colors", 0,
772 KEY_READ
, &colors_key
) == ERROR_SUCCESS
773 || RegOpenKeyEx (HKEY_LOCAL_MACHINE
, "Control Panel\\Colors", 0,
774 KEY_READ
, &colors_key
) == ERROR_SUCCESS
)
777 char color_buffer
[64];
778 char full_name_buffer
[MAX_PATH
+ SYSTEM_COLOR_PREFIX_LEN
];
780 DWORD name_size
, color_size
;
781 char *name_buffer
= full_name_buffer
+ SYSTEM_COLOR_PREFIX_LEN
;
783 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
784 color_size
= sizeof (color_buffer
);
786 strcpy (full_name_buffer
, SYSTEM_COLOR_PREFIX
);
788 while (RegEnumValueA (colors_key
, index
, name_buffer
, &name_size
,
789 NULL
, NULL
, color_buffer
, &color_size
)
793 if (sscanf (color_buffer
, " %u %u %u", &r
, &g
, &b
) == 3)
794 *system_colors
= Fcons (Fcons (build_string (full_name_buffer
),
795 make_number (RGB (r
, g
, b
))),
798 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
799 color_size
= sizeof (color_buffer
);
802 RegCloseKey (colors_key
);
810 x_to_w32_color (const char * colorname
)
812 register Lisp_Object ret
= Qnil
;
816 if (colorname
[0] == '#')
818 /* Could be an old-style RGB Device specification. */
819 int size
= strlen (colorname
+ 1);
820 char *color
= alloca (size
+ 1);
822 strcpy (color
, colorname
+ 1);
823 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
831 for (i
= 0; i
< 3; i
++)
837 /* The check for 'x' in the following conditional takes into
838 account the fact that strtol allows a "0x" in front of
839 our numbers, and we don't. */
840 if (!isxdigit (color
[0]) || color
[1] == 'x')
844 value
= strtoul (color
, &end
, 16);
846 if (errno
== ERANGE
|| end
- color
!= size
)
851 value
= value
* 0x10;
862 colorval
|= (value
<< pos
);
867 XSETINT (ret
, colorval
);
874 else if (strnicmp (colorname
, "rgb:", 4) == 0)
882 color
= colorname
+ 4;
883 for (i
= 0; i
< 3; i
++)
888 /* The check for 'x' in the following conditional takes into
889 account the fact that strtol allows a "0x" in front of
890 our numbers, and we don't. */
891 if (!isxdigit (color
[0]) || color
[1] == 'x')
893 value
= strtoul (color
, &end
, 16);
899 value
= value
* 0x10 + value
;
912 if (value
== ULONG_MAX
)
914 colorval
|= (value
<< pos
);
921 XSETINT (ret
, colorval
);
929 else if (strnicmp (colorname
, "rgbi:", 5) == 0)
931 /* This is an RGB Intensity specification. */
938 color
= colorname
+ 5;
939 for (i
= 0; i
< 3; i
++)
945 value
= strtod (color
, &end
);
948 if (value
< 0.0 || value
> 1.0)
950 val
= (UINT
)(0x100 * value
);
951 /* We used 0x100 instead of 0xFF to give a continuous
952 range between 0.0 and 1.0 inclusive. The next statement
953 fixes the 1.0 case. */
956 colorval
|= (val
<< pos
);
963 XSETINT (ret
, colorval
);
971 /* I am not going to attempt to handle any of the CIE color schemes
972 or TekHVC, since I don't know the algorithms for conversion to
975 /* If we fail to lookup the color name in w32_color_map, then check the
976 colorname to see if it can be crudely approximated: If the X color
977 ends in a number (e.g., "darkseagreen2"), strip the number and
978 return the result of looking up the base color name. */
979 ret
= w32_color_map_lookup (colorname
);
982 int len
= strlen (colorname
);
984 if (isdigit (colorname
[len
- 1]))
986 char *ptr
, *approx
= alloca (len
+ 1);
988 strcpy (approx
, colorname
);
989 ptr
= &approx
[len
- 1];
990 while (ptr
> approx
&& isdigit (*ptr
))
993 ret
= w32_color_map_lookup (approx
);
1002 w32_regenerate_palette (struct frame
*f
)
1004 struct w32_palette_entry
* list
;
1005 LOGPALETTE
* log_palette
;
1006 HPALETTE new_palette
;
1009 /* don't bother trying to create palette if not supported */
1010 if (! FRAME_DISPLAY_INFO (f
)->has_palette
)
1013 log_palette
= (LOGPALETTE
*)
1014 alloca (sizeof (LOGPALETTE
) +
1015 FRAME_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
1016 log_palette
->palVersion
= 0x300;
1017 log_palette
->palNumEntries
= FRAME_DISPLAY_INFO (f
)->num_colors
;
1019 list
= FRAME_DISPLAY_INFO (f
)->color_list
;
1021 i
< FRAME_DISPLAY_INFO (f
)->num_colors
;
1022 i
++, list
= list
->next
)
1023 log_palette
->palPalEntry
[i
] = list
->entry
;
1025 new_palette
= CreatePalette (log_palette
);
1029 if (FRAME_DISPLAY_INFO (f
)->palette
)
1030 DeleteObject (FRAME_DISPLAY_INFO (f
)->palette
);
1031 FRAME_DISPLAY_INFO (f
)->palette
= new_palette
;
1033 /* Realize display palette and garbage all frames. */
1034 release_frame_dc (f
, get_frame_dc (f
));
1039 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
1040 #define SET_W32_COLOR(pe, color) \
1043 pe.peRed = GetRValue (color); \
1044 pe.peGreen = GetGValue (color); \
1045 pe.peBlue = GetBValue (color); \
1050 /* Keep these around in case we ever want to track color usage. */
1052 w32_map_color (struct frame
*f
, COLORREF color
)
1054 struct w32_palette_entry
* list
= FRAME_DISPLAY_INFO (f
)->color_list
;
1056 if (NILP (Vw32_enable_palette
))
1059 /* check if color is already mapped */
1062 if (W32_COLOR (list
->entry
) == color
)
1070 /* not already mapped, so add to list and recreate Windows palette */
1071 list
= xmalloc (sizeof (struct w32_palette_entry
));
1072 SET_W32_COLOR (list
->entry
, color
);
1074 list
->next
= FRAME_DISPLAY_INFO (f
)->color_list
;
1075 FRAME_DISPLAY_INFO (f
)->color_list
= list
;
1076 FRAME_DISPLAY_INFO (f
)->num_colors
++;
1078 /* set flag that palette must be regenerated */
1079 FRAME_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1083 w32_unmap_color (struct frame
*f
, COLORREF color
)
1085 struct w32_palette_entry
* list
= FRAME_DISPLAY_INFO (f
)->color_list
;
1086 struct w32_palette_entry
**prev
= &FRAME_DISPLAY_INFO (f
)->color_list
;
1088 if (NILP (Vw32_enable_palette
))
1091 /* check if color is already mapped */
1094 if (W32_COLOR (list
->entry
) == color
)
1096 if (--list
->refcount
== 0)
1100 FRAME_DISPLAY_INFO (f
)->num_colors
--;
1110 /* set flag that palette must be regenerated */
1111 FRAME_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1116 /* Gamma-correct COLOR on frame F. */
1119 gamma_correct (struct frame
*f
, COLORREF
*color
)
1123 *color
= PALETTERGB (
1124 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1125 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1126 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1131 /* Decide if color named COLOR is valid for the display associated with
1132 the selected frame; if so, return the rgb values in COLOR_DEF.
1133 If ALLOC is nonzero, allocate a new colormap cell. */
1136 w32_defined_color (struct frame
*f
, const char *color
, XColor
*color_def
,
1139 register Lisp_Object tem
;
1140 COLORREF w32_color_ref
;
1142 tem
= x_to_w32_color (color
);
1148 /* Apply gamma correction. */
1149 w32_color_ref
= XUINT (tem
);
1150 gamma_correct (f
, &w32_color_ref
);
1151 XSETINT (tem
, w32_color_ref
);
1154 /* Map this color to the palette if it is enabled. */
1155 if (!NILP (Vw32_enable_palette
))
1157 struct w32_palette_entry
* entry
=
1158 one_w32_display_info
.color_list
;
1159 struct w32_palette_entry
** prev
=
1160 &one_w32_display_info
.color_list
;
1162 /* check if color is already mapped */
1165 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1167 prev
= &entry
->next
;
1168 entry
= entry
->next
;
1171 if (entry
== NULL
&& alloc_p
)
1173 /* not already mapped, so add to list */
1174 entry
= xmalloc (sizeof (struct w32_palette_entry
));
1175 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1178 one_w32_display_info
.num_colors
++;
1180 /* set flag that palette must be regenerated */
1181 one_w32_display_info
.regen_palette
= TRUE
;
1184 /* Ensure COLORREF value is snapped to nearest color in (default)
1185 palette by simulating the PALETTERGB macro. This works whether
1186 or not the display device has a palette. */
1187 w32_color_ref
= XUINT (tem
) | 0x2000000;
1189 color_def
->pixel
= w32_color_ref
;
1190 color_def
->red
= GetRValue (w32_color_ref
) * 256;
1191 color_def
->green
= GetGValue (w32_color_ref
) * 256;
1192 color_def
->blue
= GetBValue (w32_color_ref
) * 256;
1202 /* Given a string ARG naming a color, compute a pixel value from it
1203 suitable for screen F.
1204 If F is not a color screen, return DEF (default) regardless of what
1208 x_decode_color (struct frame
*f
, Lisp_Object arg
, int def
)
1214 if (strcmp (SDATA (arg
), "black") == 0)
1215 return BLACK_PIX_DEFAULT (f
);
1216 else if (strcmp (SDATA (arg
), "white") == 0)
1217 return WHITE_PIX_DEFAULT (f
);
1219 if ((FRAME_DISPLAY_INFO (f
)->n_planes
* FRAME_DISPLAY_INFO (f
)->n_cbits
) == 1)
1222 /* w32_defined_color is responsible for coping with failures
1223 by looking for a near-miss. */
1224 if (w32_defined_color (f
, SDATA (arg
), &cdef
, true))
1227 /* defined_color failed; return an ultimate default. */
1233 /* Functions called only from `x_set_frame_param'
1234 to set individual parameters.
1236 If FRAME_W32_WINDOW (f) is 0,
1237 the frame is being created and its window does not exist yet.
1238 In that case, just record the parameter's new value
1239 in the standard place; do not attempt to change the window. */
1242 x_set_foreground_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1244 struct w32_output
*x
= f
->output_data
.w32
;
1245 PIX_TYPE fg
, old_fg
;
1247 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1248 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
1249 FRAME_FOREGROUND_PIXEL (f
) = fg
;
1251 if (FRAME_W32_WINDOW (f
) != 0)
1253 if (x
->cursor_pixel
== old_fg
)
1255 x
->cursor_pixel
= fg
;
1256 x
->cursor_gc
->background
= fg
;
1259 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
1260 if (FRAME_VISIBLE_P (f
))
1266 x_set_background_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1268 FRAME_BACKGROUND_PIXEL (f
)
1269 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
1271 if (FRAME_W32_WINDOW (f
) != 0)
1273 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
1274 FRAME_BACKGROUND_PIXEL (f
));
1276 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
1278 if (FRAME_VISIBLE_P (f
))
1284 x_set_mouse_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1286 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
1290 if (!EQ (Qnil
, arg
))
1291 f
->output_data
.w32
->mouse_pixel
1292 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1293 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
1295 /* Don't let pointers be invisible. */
1296 if (mask_color
== f
->output_data
.w32
->mouse_pixel
1297 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
1298 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
1300 #if 0 /* TODO : Mouse cursor customization. */
1303 /* It's not okay to crash if the user selects a screwy cursor. */
1304 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
1306 if (!EQ (Qnil
, Vx_pointer_shape
))
1308 CHECK_NUMBER (Vx_pointer_shape
);
1309 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
1312 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1313 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
1315 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
1317 CHECK_NUMBER (Vx_nontext_pointer_shape
);
1318 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1319 XINT (Vx_nontext_pointer_shape
));
1322 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
1323 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1325 if (!EQ (Qnil
, Vx_hourglass_pointer_shape
))
1327 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
1328 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1329 XINT (Vx_hourglass_pointer_shape
));
1332 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
1333 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
1335 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1336 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
1338 CHECK_NUMBER (Vx_mode_pointer_shape
);
1339 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1340 XINT (Vx_mode_pointer_shape
));
1343 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1344 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
1346 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
1348 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
1350 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1351 XINT (Vx_sensitive_text_pointer_shape
));
1354 hand_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
1356 if (!NILP (Vx_window_horizontal_drag_shape
))
1358 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
1359 horizontal_drag_cursor
1360 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1361 XINT (Vx_window_horizontal_drag_shape
));
1364 horizontal_drag_cursor
1365 = XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_sb_h_double_arrow
);
1367 if (!NILP (Vx_window_vertical_drag_shape
))
1369 CHECK_NUMBER (Vx_window_vertical_drag_shape
);
1370 vertical_drag_cursor
1371 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1372 XINT (Vx_window_vertical_drag_shape
));
1375 vertical_drag_cursor
1376 = XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_sb_v_double_arrow
);
1378 /* Check and report errors with the above calls. */
1379 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
1380 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
1383 XColor fore_color
, back_color
;
1385 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
1386 back_color
.pixel
= mask_color
;
1387 XQueryColor (FRAME_W32_DISPLAY (f
),
1388 DefaultColormap (FRAME_W32_DISPLAY (f
),
1389 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1391 XQueryColor (FRAME_W32_DISPLAY (f
),
1392 DefaultColormap (FRAME_W32_DISPLAY (f
),
1393 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1395 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
1396 &fore_color
, &back_color
);
1397 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
1398 &fore_color
, &back_color
);
1399 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
1400 &fore_color
, &back_color
);
1401 XRecolorCursor (FRAME_W32_DISPLAY (f
), hand_cursor
,
1402 &fore_color
, &back_color
);
1403 XRecolorCursor (FRAME_W32_DISPLAY (f
), hourglass_cursor
,
1404 &fore_color
, &back_color
);
1407 if (FRAME_W32_WINDOW (f
) != 0)
1408 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
1410 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
1411 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
1412 f
->output_data
.w32
->text_cursor
= cursor
;
1414 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
1415 && f
->output_data
.w32
->nontext_cursor
!= 0)
1416 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
1417 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
1419 if (hourglass_cursor
!= f
->output_data
.w32
->hourglass_cursor
1420 && f
->output_data
.w32
->hourglass_cursor
!= 0)
1421 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hourglass_cursor
);
1422 f
->output_data
.w32
->hourglass_cursor
= hourglass_cursor
;
1424 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
1425 && f
->output_data
.w32
->modeline_cursor
!= 0)
1426 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
1427 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
1429 if (hand_cursor
!= f
->output_data
.w32
->hand_cursor
1430 && f
->output_data
.w32
->hand_cursor
!= 0)
1431 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hand_cursor
);
1432 f
->output_data
.w32
->hand_cursor
= hand_cursor
;
1434 XFlush (FRAME_W32_DISPLAY (f
));
1437 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1442 x_set_cursor_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1444 unsigned long fore_pixel
, pixel
;
1446 if (!NILP (Vx_cursor_fore_pixel
))
1447 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1448 WHITE_PIX_DEFAULT (f
));
1450 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1452 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1454 /* Make sure that the cursor color differs from the background color. */
1455 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
1457 pixel
= f
->output_data
.w32
->mouse_pixel
;
1458 if (pixel
== fore_pixel
)
1459 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1462 f
->output_data
.w32
->cursor_foreground_pixel
= fore_pixel
;
1463 f
->output_data
.w32
->cursor_pixel
= pixel
;
1465 if (FRAME_W32_WINDOW (f
) != 0)
1468 /* Update frame's cursor_gc. */
1469 f
->output_data
.w32
->cursor_gc
->foreground
= fore_pixel
;
1470 f
->output_data
.w32
->cursor_gc
->background
= pixel
;
1474 if (FRAME_VISIBLE_P (f
))
1476 x_update_cursor (f
, 0);
1477 x_update_cursor (f
, 1);
1481 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1484 /* Set the border-color of frame F to pixel value PIX.
1485 Note that this does not fully take effect if done before
1489 x_set_border_pixel (struct frame
*f
, int pix
)
1492 f
->output_data
.w32
->border_pixel
= pix
;
1494 if (FRAME_W32_WINDOW (f
) != 0 && f
->border_width
> 0)
1496 if (FRAME_VISIBLE_P (f
))
1501 /* Set the border-color of frame F to value described by ARG.
1502 ARG can be a string naming a color.
1503 The border-color is used for the border that is drawn by the server.
1504 Note that this does not fully take effect if done before
1505 F has a window; it must be redone when the window is created. */
1508 x_set_border_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1513 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1514 x_set_border_pixel (f
, pix
);
1515 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1520 x_set_cursor_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1522 set_frame_cursor_types (f
, arg
);
1526 x_set_icon_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1530 if (NILP (arg
) && NILP (oldval
))
1533 if (STRINGP (arg
) && STRINGP (oldval
)
1534 && EQ (Fstring_equal (oldval
, arg
), Qt
))
1537 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
1542 result
= x_bitmap_icon (f
, arg
);
1546 error ("No icon window available");
1553 x_set_icon_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1557 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1560 else if (!NILP (arg
) || NILP (oldval
))
1563 fset_icon_name (f
, arg
);
1566 if (f
->output_data
.w32
->icon_bitmap
!= 0)
1571 result
= x_text_icon (f
,
1572 SSDATA ((!NILP (f
->icon_name
)
1581 error ("No icon window available");
1584 /* If the window was unmapped (and its icon was mapped),
1585 the new icon is not mapped, so map the window in its stead. */
1586 if (FRAME_VISIBLE_P (f
))
1588 #ifdef USE_X_TOOLKIT
1589 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
1591 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
1594 XFlush (FRAME_W32_DISPLAY (f
));
1600 x_clear_under_internal_border (struct frame
*f
)
1602 int border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1604 /* Clear border if it's larger than before. */
1607 HDC hdc
= get_frame_dc (f
);
1608 int width
= FRAME_PIXEL_WIDTH (f
);
1609 int height
= FRAME_PIXEL_HEIGHT (f
);
1612 w32_clear_area (f
, hdc
, 0, FRAME_TOP_MARGIN_HEIGHT (f
), width
, border
);
1613 w32_clear_area (f
, hdc
, 0, 0, border
, height
);
1614 w32_clear_area (f
, hdc
, width
- border
, 0, border
, height
);
1615 w32_clear_area (f
, hdc
, 0, height
- border
, width
, border
);
1616 release_frame_dc (f
, hdc
);
1623 x_set_internal_border_width (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1627 CHECK_TYPE_RANGED_INTEGER (int, arg
);
1628 border
= max (XINT (arg
), 0);
1630 if (border
!= FRAME_INTERNAL_BORDER_WIDTH (f
))
1632 FRAME_INTERNAL_BORDER_WIDTH (f
) = border
;
1634 if (FRAME_X_WINDOW (f
) != 0)
1636 adjust_frame_size (f
, -1, -1, 3, false, Qinternal_border_width
);
1638 if (FRAME_VISIBLE_P (f
))
1639 x_clear_under_internal_border (f
);
1646 x_set_menu_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1650 /* Right now, menu bars don't work properly in minibuf-only frames;
1651 most of the commands try to apply themselves to the minibuffer
1652 frame itself, and get an error because you can't switch buffers
1653 in or split the minibuffer window. */
1654 if (FRAME_MINIBUF_ONLY_P (f
))
1657 if (INTEGERP (value
))
1658 nlines
= XINT (value
);
1662 FRAME_MENU_BAR_LINES (f
) = 0;
1663 FRAME_MENU_BAR_HEIGHT (f
) = 0;
1666 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1667 windows_or_buffers_changed
= 23;
1671 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1672 free_frame_menubar (f
);
1673 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1675 /* Adjust the frame size so that the client (text) dimensions
1676 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
1677 set correctly. Note that we resize twice: The first time upon
1678 a request from the window manager who wants to keep the height
1679 of the outer rectangle (including decorations) unchanged, and a
1680 second time because we want to keep the height of the inner
1681 rectangle (without the decorations unchanged). */
1682 adjust_frame_size (f
, -1, -1, 2, true, Qmenu_bar_lines
);
1684 /* Not sure whether this is needed. */
1685 x_clear_under_internal_border (f
);
1690 /* Set the number of lines used for the tool bar of frame F to VALUE.
1691 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL is
1692 the old number of tool bar lines (and is unused). This function may
1693 change the height of all windows on frame F to match the new tool bar
1694 height. By design, the frame's height doesn't change (but maybe it
1695 should if we don't get enough space otherwise). */
1698 x_set_tool_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1702 /* Treat tool bars like menu bars. */
1703 if (FRAME_MINIBUF_ONLY_P (f
))
1706 /* Use VALUE only if an integer >= 0. */
1707 if (INTEGERP (value
) && XINT (value
) >= 0)
1708 nlines
= XFASTINT (value
);
1712 x_change_tool_bar_height (f
, nlines
* FRAME_LINE_HEIGHT (f
));
1716 /* Set the pixel height of the tool bar of frame F to HEIGHT. */
1718 x_change_tool_bar_height (struct frame
*f
, int height
)
1721 int unit
= FRAME_LINE_HEIGHT (f
);
1722 int old_height
= FRAME_TOOL_BAR_HEIGHT (f
);
1723 int lines
= (height
+ unit
- 1) / unit
;
1724 int old_text_height
= FRAME_TEXT_HEIGHT (f
);
1726 /* Make sure we redisplay all windows in this frame. */
1727 windows_or_buffers_changed
= 23;
1729 /* Recalculate tool bar and frame text sizes. */
1730 FRAME_TOOL_BAR_HEIGHT (f
) = height
;
1731 FRAME_TOOL_BAR_LINES (f
) = lines
;
1732 /* Store `tool-bar-lines' and `height' frame parameters. */
1733 store_frame_param (f
, Qtool_bar_lines
, make_number (lines
));
1734 store_frame_param (f
, Qheight
, make_number (FRAME_LINES (f
)));
1736 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_HEIGHT (f
) == 0)
1739 clear_current_matrices (f
);
1742 if ((height
< old_height
) && WINDOWP (f
->tool_bar_window
))
1743 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1745 /* Recalculate toolbar height. */
1746 f
->n_tool_bar_rows
= 0;
1748 adjust_frame_size (f
, -1, -1,
1749 (!f
->tool_bar_redisplayed_once
? 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
);
3329 case WM_IME_ENDCOMPOSITION
:
3330 ignore_ime_char
= 0;
3333 /* Simulate middle mouse button events when left and right buttons
3334 are used together, but only if user has two button mouse. */
3335 case WM_LBUTTONDOWN
:
3336 case WM_RBUTTONDOWN
:
3337 if (w32_num_mouse_buttons
> 2)
3338 goto handle_plain_button
;
3341 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
3342 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
3344 if (button_state
& this)
3347 if (button_state
== 0)
3350 button_state
|= this;
3352 if (button_state
& other
)
3354 if (mouse_button_timer
)
3356 KillTimer (hwnd
, mouse_button_timer
);
3357 mouse_button_timer
= 0;
3359 /* Generate middle mouse event instead. */
3360 msg
= WM_MBUTTONDOWN
;
3361 button_state
|= MMOUSE
;
3363 else if (button_state
& MMOUSE
)
3365 /* Ignore button event if we've already generated a
3366 middle mouse down event. This happens if the
3367 user releases and press one of the two buttons
3368 after we've faked a middle mouse event. */
3373 /* Flush out saved message. */
3374 post_msg (&saved_mouse_button_msg
);
3376 wmsg
.dwModifiers
= w32_get_modifiers ();
3377 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3378 signal_user_input ();
3380 /* Clear message buffer. */
3381 saved_mouse_button_msg
.msg
.hwnd
= 0;
3385 /* Hold onto message for now. */
3386 mouse_button_timer
=
3387 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
3388 w32_mouse_button_tolerance
, NULL
);
3389 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
3390 saved_mouse_button_msg
.msg
.message
= msg
;
3391 saved_mouse_button_msg
.msg
.wParam
= wParam
;
3392 saved_mouse_button_msg
.msg
.lParam
= lParam
;
3393 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
3394 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
3401 if (w32_num_mouse_buttons
> 2)
3402 goto handle_plain_button
;
3405 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
3406 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
3408 if ((button_state
& this) == 0)
3411 button_state
&= ~this;
3413 if (button_state
& MMOUSE
)
3415 /* Only generate event when second button is released. */
3416 if ((button_state
& other
) == 0)
3419 button_state
&= ~MMOUSE
;
3421 if (button_state
) emacs_abort ();
3428 /* Flush out saved message if necessary. */
3429 if (saved_mouse_button_msg
.msg
.hwnd
)
3431 post_msg (&saved_mouse_button_msg
);
3434 wmsg
.dwModifiers
= w32_get_modifiers ();
3435 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3436 signal_user_input ();
3438 /* Always clear message buffer and cancel timer. */
3439 saved_mouse_button_msg
.msg
.hwnd
= 0;
3440 KillTimer (hwnd
, mouse_button_timer
);
3441 mouse_button_timer
= 0;
3443 if (button_state
== 0)
3448 case WM_XBUTTONDOWN
:
3450 if (w32_pass_extra_mouse_buttons_to_system
)
3452 /* else fall through and process them. */
3453 case WM_MBUTTONDOWN
:
3455 handle_plain_button
:
3460 /* Ignore middle and extra buttons as long as the menu is active. */
3461 f
= x_window_to_frame (dpyinfo
, hwnd
);
3462 if (f
&& f
->output_data
.w32
->menubar_active
)
3465 if (parse_button (msg
, HIWORD (wParam
), &button
, &up
))
3467 if (up
) ReleaseCapture ();
3468 else SetCapture (hwnd
);
3469 button
= (button
== 0) ? LMOUSE
:
3470 ((button
== 1) ? MMOUSE
: RMOUSE
);
3472 button_state
&= ~button
;
3474 button_state
|= button
;
3478 wmsg
.dwModifiers
= w32_get_modifiers ();
3479 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3480 signal_user_input ();
3482 /* Need to return true for XBUTTON messages, false for others,
3483 to indicate that we processed the message. */
3484 return (msg
== WM_XBUTTONDOWN
|| msg
== WM_XBUTTONUP
);
3487 /* Ignore mouse movements as long as the menu is active. These
3488 movements are processed by the window manager anyway, and
3489 it's wrong to handle them as if they happened on the
3490 underlying frame. */
3491 f
= x_window_to_frame (dpyinfo
, hwnd
);
3492 if (f
&& f
->output_data
.w32
->menubar_active
)
3495 /* If the mouse has just moved into the frame, start tracking
3496 it, so we will be notified when it leaves the frame. Mouse
3497 tracking only works under W98 and NT4 and later. On earlier
3498 versions, there is no way of telling when the mouse leaves the
3499 frame, so we just have to put up with help-echo and mouse
3500 highlighting remaining while the frame is not active. */
3501 if (track_mouse_event_fn
&& !track_mouse_window
3502 /* If the menu bar is active, turning on tracking of mouse
3503 movement events might send these events to the tooltip
3504 frame, if the user happens to move the mouse pointer over
3505 the tooltip. But since we don't process events for
3506 tooltip frames, this causes Windows to present a
3507 hourglass cursor, which is ugly and unexpected. So don't
3508 enable tracking mouse events in this case; they will be
3509 restarted when the menu pops down. (Confusingly, the
3510 menubar_active member of f->output_data.w32, tested
3511 above, is only set when a menu was popped up _not_ from
3512 the frame's menu bar, but via x-popup-menu.) */
3515 TRACKMOUSEEVENT tme
;
3516 tme
.cbSize
= sizeof (tme
);
3517 tme
.dwFlags
= TME_LEAVE
;
3518 tme
.hwndTrack
= hwnd
;
3519 tme
.dwHoverTime
= HOVER_DEFAULT
;
3521 track_mouse_event_fn (&tme
);
3522 track_mouse_window
= hwnd
;
3526 if (w32_mouse_move_interval
<= 0
3527 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
3529 wmsg
.dwModifiers
= w32_get_modifiers ();
3530 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3534 /* Hang onto mouse move and scroll messages for a bit, to avoid
3535 sending such events to Emacs faster than it can process them.
3536 If we get more events before the timer from the first message
3537 expires, we just replace the first message. */
3539 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
3541 SetTimer (hwnd
, MOUSE_MOVE_ID
,
3542 w32_mouse_move_interval
, NULL
);
3544 /* Hold onto message for now. */
3545 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
3546 saved_mouse_move_msg
.msg
.message
= msg
;
3547 saved_mouse_move_msg
.msg
.wParam
= wParam
;
3548 saved_mouse_move_msg
.msg
.lParam
= lParam
;
3549 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
3550 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
3556 wmsg
.dwModifiers
= w32_get_modifiers ();
3557 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3558 signal_user_input ();
3562 if (w32_pass_multimedia_buttons_to_system
)
3564 /* Otherwise, pass to lisp, the same way we do with mousehwheel. */
3565 case WM_MOUSEHWHEEL
:
3566 wmsg
.dwModifiers
= w32_get_modifiers ();
3567 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3568 signal_user_input ();
3569 /* Non-zero must be returned when WM_MOUSEHWHEEL messages are
3570 handled, to prevent the system trying to handle it by faking
3571 scroll bar events. */
3575 /* Flush out saved messages if necessary. */
3576 if (wParam
== mouse_button_timer
)
3578 if (saved_mouse_button_msg
.msg
.hwnd
)
3580 post_msg (&saved_mouse_button_msg
);
3581 signal_user_input ();
3582 saved_mouse_button_msg
.msg
.hwnd
= 0;
3584 KillTimer (hwnd
, mouse_button_timer
);
3585 mouse_button_timer
= 0;
3587 else if (wParam
== mouse_move_timer
)
3589 if (saved_mouse_move_msg
.msg
.hwnd
)
3591 post_msg (&saved_mouse_move_msg
);
3592 saved_mouse_move_msg
.msg
.hwnd
= 0;
3594 KillTimer (hwnd
, mouse_move_timer
);
3595 mouse_move_timer
= 0;
3597 else if (wParam
== menu_free_timer
)
3599 KillTimer (hwnd
, menu_free_timer
);
3600 menu_free_timer
= 0;
3601 f
= x_window_to_frame (dpyinfo
, hwnd
);
3602 /* If a popup menu is active, don't wipe its strings. */
3604 && current_popup_menu
== NULL
)
3606 /* Free memory used by owner-drawn and help-echo strings. */
3607 w32_free_menu_strings (hwnd
);
3609 f
->output_data
.w32
->menubar_active
= 0;
3616 /* Windows doesn't send us focus messages when putting up and
3617 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
3618 The only indication we get that something happened is receiving
3619 this message afterwards. So this is a good time to reset our
3620 keyboard modifiers' state. */
3627 /* We must ensure menu bar is fully constructed and up to date
3628 before allowing user interaction with it. To achieve this
3629 we send this message to the lisp thread and wait for a
3630 reply (whose value is not actually needed) to indicate that
3631 the menu bar is now ready for use, so we can now return.
3633 To remain responsive in the meantime, we enter a nested message
3634 loop that can process all other messages.
3636 However, we skip all this if the message results from calling
3637 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
3638 thread a message because it is blocked on us at this point. We
3639 set menubar_active before calling TrackPopupMenu to indicate
3640 this (there is no possibility of confusion with real menubar
3643 f
= x_window_to_frame (dpyinfo
, hwnd
);
3645 && (f
->output_data
.w32
->menubar_active
3646 /* We can receive this message even in the absence of a
3647 menubar (ie. when the system menu is activated) - in this
3648 case we do NOT want to forward the message, otherwise it
3649 will cause the menubar to suddenly appear when the user
3650 had requested it to be turned off! */
3651 || f
->output_data
.w32
->menubar_widget
== NULL
))
3655 deferred_msg msg_buf
;
3657 /* Detect if message has already been deferred; in this case
3658 we cannot return any sensible value to ignore this. */
3659 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3664 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
3667 case WM_EXITMENULOOP
:
3668 f
= x_window_to_frame (dpyinfo
, hwnd
);
3670 /* If a menu is still active, check again after a short delay,
3671 since Windows often (always?) sends the WM_EXITMENULOOP
3672 before the corresponding WM_COMMAND message.
3673 Don't do this if a popup menu is active, since it is only
3674 menubar menus that require cleaning up in this way.
3676 if (f
&& menubar_in_use
&& current_popup_menu
== NULL
)
3677 menu_free_timer
= SetTimer (hwnd
, MENU_FREE_ID
, MENU_FREE_DELAY
, NULL
);
3679 /* If hourglass cursor should be displayed, display it now. */
3680 if (f
&& f
->output_data
.w32
->hourglass_p
)
3681 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
3686 /* Direct handling of help_echo in menus. Should be safe now
3687 that we generate the help_echo by placing a help event in the
3690 HMENU menu
= (HMENU
) lParam
;
3691 UINT menu_item
= (UINT
) LOWORD (wParam
);
3692 UINT flags
= (UINT
) HIWORD (wParam
);
3694 w32_menu_display_help (hwnd
, menu
, menu_item
, flags
);
3698 case WM_MEASUREITEM
:
3699 f
= x_window_to_frame (dpyinfo
, hwnd
);
3702 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
3704 if (pMis
->CtlType
== ODT_MENU
)
3706 /* Work out dimensions for popup menu titles. */
3707 char * title
= (char *) pMis
->itemData
;
3708 HDC hdc
= GetDC (hwnd
);
3709 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3710 LOGFONT menu_logfont
;
3714 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3715 menu_logfont
.lfWeight
= FW_BOLD
;
3716 menu_font
= CreateFontIndirect (&menu_logfont
);
3717 old_font
= SelectObject (hdc
, menu_font
);
3719 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
3722 if (unicode_append_menu
)
3723 GetTextExtentPoint32W (hdc
, (WCHAR
*) title
,
3724 wcslen ((WCHAR
*) title
),
3727 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
3729 pMis
->itemWidth
= size
.cx
;
3730 if (pMis
->itemHeight
< size
.cy
)
3731 pMis
->itemHeight
= size
.cy
;
3734 pMis
->itemWidth
= 0;
3736 SelectObject (hdc
, old_font
);
3737 DeleteObject (menu_font
);
3738 ReleaseDC (hwnd
, hdc
);
3745 f
= x_window_to_frame (dpyinfo
, hwnd
);
3748 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
3750 if (pDis
->CtlType
== ODT_MENU
)
3752 /* Draw popup menu title. */
3753 char * title
= (char *) pDis
->itemData
;
3756 HDC hdc
= pDis
->hDC
;
3757 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3758 LOGFONT menu_logfont
;
3761 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3762 menu_logfont
.lfWeight
= FW_BOLD
;
3763 menu_font
= CreateFontIndirect (&menu_logfont
);
3764 old_font
= SelectObject (hdc
, menu_font
);
3766 /* Always draw title as if not selected. */
3767 if (unicode_append_menu
)
3770 + GetSystemMetrics (SM_CXMENUCHECK
),
3772 ETO_OPAQUE
, &pDis
->rcItem
,
3774 wcslen ((WCHAR
*) title
), NULL
);
3778 + GetSystemMetrics (SM_CXMENUCHECK
),
3780 ETO_OPAQUE
, &pDis
->rcItem
,
3781 title
, strlen (title
), NULL
);
3783 SelectObject (hdc
, old_font
);
3784 DeleteObject (menu_font
);
3792 /* Still not right - can't distinguish between clicks in the
3793 client area of the frame from clicks forwarded from the scroll
3794 bars - may have to hook WM_NCHITTEST to remember the mouse
3795 position and then check if it is in the client area ourselves. */
3796 case WM_MOUSEACTIVATE
:
3797 /* Discard the mouse click that activates a frame, allowing the
3798 user to click anywhere without changing point (or worse!).
3799 Don't eat mouse clicks on scrollbars though!! */
3800 if (LOWORD (lParam
) == HTCLIENT
)
3801 return MA_ACTIVATEANDEAT
;
3806 /* No longer tracking mouse. */
3807 track_mouse_window
= NULL
;
3809 case WM_ACTIVATEAPP
:
3811 case WM_WINDOWPOSCHANGED
:
3813 /* Inform lisp thread that a frame might have just been obscured
3814 or exposed, so should recheck visibility of all frames. */
3815 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3819 dpyinfo
->faked_key
= 0;
3821 register_hot_keys (hwnd
);
3824 unregister_hot_keys (hwnd
);
3827 /* Relinquish the system caret. */
3828 if (w32_system_caret_hwnd
)
3830 w32_visible_system_caret_hwnd
= NULL
;
3831 w32_system_caret_hwnd
= NULL
;
3837 f
= x_window_to_frame (dpyinfo
, hwnd
);
3838 if (f
&& HIWORD (wParam
) == 0)
3840 if (menu_free_timer
)
3842 KillTimer (hwnd
, menu_free_timer
);
3843 menu_free_timer
= 0;
3849 wmsg
.dwModifiers
= w32_get_modifiers ();
3850 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3858 wmsg
.dwModifiers
= w32_get_modifiers ();
3859 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3862 case WM_WINDOWPOSCHANGING
:
3863 /* Don't restrict the sizing of any kind of frames. If the window
3864 manager doesn't, there's no reason to do it ourselves. */
3866 if (frame_resize_pixelwise
|| hwnd
== tip_window
)
3871 /* Don't restrict the sizing of fullscreened frames, allowing them to be
3872 flush with the sides of the screen. */
3873 f
= x_window_to_frame (dpyinfo
, hwnd
);
3874 if (f
&& FRAME_PREV_FSMODE (f
) != FULLSCREEN_NONE
)
3879 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
3881 wp
.length
= sizeof (WINDOWPLACEMENT
);
3882 GetWindowPlacement (hwnd
, &wp
);
3884 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
&& wp
.showCmd
!= SW_SHOWMINIMIZED
3885 && (lppos
->flags
& SWP_NOSIZE
) == 0)
3892 DWORD internal_border
;
3893 DWORD vscrollbar_extra
;
3894 DWORD hscrollbar_extra
;
3897 wp
.length
= sizeof (wp
);
3898 GetWindowRect (hwnd
, &wr
);
3902 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
3903 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
3904 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
3905 vscrollbar_extra
= GetWindowLong (hwnd
, WND_VSCROLLBAR_INDEX
);
3906 hscrollbar_extra
= GetWindowLong (hwnd
, WND_HSCROLLBAR_INDEX
);
3910 memset (&rect
, 0, sizeof (rect
));
3911 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
3912 GetMenu (hwnd
) != NULL
);
3914 /* Force width and height of client area to be exact
3915 multiples of the character cell dimensions. */
3916 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
3917 - 2 * internal_border
- vscrollbar_extra
)
3919 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
3920 - 2 * internal_border
- hscrollbar_extra
)
3925 /* For right/bottom sizing we can just fix the sizes.
3926 However for top/left sizing we will need to fix the X
3927 and Y positions as well. */
3929 int cx_mintrack
= GetSystemMetrics (SM_CXMINTRACK
);
3930 int cy_mintrack
= GetSystemMetrics (SM_CYMINTRACK
);
3932 lppos
->cx
= max (lppos
->cx
- wdiff
, cx_mintrack
);
3933 lppos
->cy
= max (lppos
->cy
- hdiff
, cy_mintrack
);
3935 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
3936 && (lppos
->flags
& SWP_NOMOVE
) == 0)
3938 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
3945 lppos
->flags
|= SWP_NOMOVE
;
3957 case WM_GETMINMAXINFO
:
3958 /* Hack to allow resizing the Emacs frame above the screen size.
3959 Note that Windows 9x limits coordinates to 16-bits. */
3960 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.x
= 32767;
3961 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.y
= 32767;
3965 if (LOWORD (lParam
) == HTCLIENT
)
3967 f
= x_window_to_frame (dpyinfo
, hwnd
);
3968 if (f
&& f
->output_data
.w32
->hourglass_p
3969 && !menubar_in_use
&& !current_popup_menu
)
3970 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
3972 SetCursor (f
->output_data
.w32
->current_cursor
);
3977 case WM_EMACS_SETCURSOR
:
3979 Cursor cursor
= (Cursor
) wParam
;
3980 f
= x_window_to_frame (dpyinfo
, hwnd
);
3983 f
->output_data
.w32
->current_cursor
= cursor
;
3984 if (!f
->output_data
.w32
->hourglass_p
)
3990 case WM_EMACS_SHOWCURSOR
:
3992 ShowCursor ((BOOL
) wParam
);
3997 case WM_EMACS_CREATEVSCROLLBAR
:
3998 return (LRESULT
) w32_createvscrollbar ((struct frame
*) wParam
,
3999 (struct scroll_bar
*) lParam
);
4001 case WM_EMACS_CREATEHSCROLLBAR
:
4002 return (LRESULT
) w32_createhscrollbar ((struct frame
*) wParam
,
4003 (struct scroll_bar
*) lParam
);
4005 case WM_EMACS_SHOWWINDOW
:
4006 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
4008 case WM_EMACS_BRINGTOTOP
:
4009 case WM_EMACS_SETFOREGROUND
:
4011 HWND foreground_window
;
4012 DWORD foreground_thread
, retval
;
4014 /* On NT 5.0, and apparently Windows 98, it is necessary to
4015 attach to the thread that currently has focus in order to
4016 pull the focus away from it. */
4017 foreground_window
= GetForegroundWindow ();
4018 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
4019 if (!foreground_window
4020 || foreground_thread
== GetCurrentThreadId ()
4021 || !AttachThreadInput (GetCurrentThreadId (),
4022 foreground_thread
, TRUE
))
4023 foreground_thread
= 0;
4025 retval
= SetForegroundWindow ((HWND
) wParam
);
4026 if (msg
== WM_EMACS_BRINGTOTOP
)
4027 retval
= BringWindowToTop ((HWND
) wParam
);
4029 /* Detach from the previous foreground thread. */
4030 if (foreground_thread
)
4031 AttachThreadInput (GetCurrentThreadId (),
4032 foreground_thread
, FALSE
);
4037 case WM_EMACS_SETWINDOWPOS
:
4039 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
4040 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
4041 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
4044 case WM_EMACS_DESTROYWINDOW
:
4045 DragAcceptFiles ((HWND
) wParam
, FALSE
);
4046 return DestroyWindow ((HWND
) wParam
);
4048 case WM_EMACS_HIDE_CARET
:
4049 return HideCaret (hwnd
);
4051 case WM_EMACS_SHOW_CARET
:
4052 return ShowCaret (hwnd
);
4054 case WM_EMACS_DESTROY_CARET
:
4055 w32_system_caret_hwnd
= NULL
;
4056 w32_visible_system_caret_hwnd
= NULL
;
4057 return DestroyCaret ();
4059 case WM_EMACS_TRACK_CARET
:
4060 /* If there is currently no system caret, create one. */
4061 if (w32_system_caret_hwnd
== NULL
)
4063 /* Use the default caret width, and avoid changing it
4064 unnecessarily, as it confuses screen reader software. */
4065 w32_system_caret_hwnd
= hwnd
;
4066 CreateCaret (hwnd
, NULL
, 0,
4067 w32_system_caret_height
);
4070 if (!SetCaretPos (w32_system_caret_x
, w32_system_caret_y
))
4072 /* Ensure visible caret gets turned on when requested. */
4073 else if (w32_use_visible_system_caret
4074 && w32_visible_system_caret_hwnd
!= hwnd
)
4076 w32_visible_system_caret_hwnd
= hwnd
;
4077 return ShowCaret (hwnd
);
4079 /* Ensure visible caret gets turned off when requested. */
4080 else if (!w32_use_visible_system_caret
4081 && w32_visible_system_caret_hwnd
)
4083 w32_visible_system_caret_hwnd
= NULL
;
4084 return HideCaret (hwnd
);
4089 case WM_EMACS_TRACKPOPUPMENU
:
4094 pos
= (POINT
*)lParam
;
4095 flags
= TPM_CENTERALIGN
;
4096 if (button_state
& LMOUSE
)
4097 flags
|= TPM_LEFTBUTTON
;
4098 else if (button_state
& RMOUSE
)
4099 flags
|= TPM_RIGHTBUTTON
;
4101 /* Remember we did a SetCapture on the initial mouse down event,
4102 so for safety, we make sure the capture is canceled now. */
4106 /* Use menubar_active to indicate that WM_INITMENU is from
4107 TrackPopupMenu below, and should be ignored. */
4108 f
= x_window_to_frame (dpyinfo
, hwnd
);
4110 f
->output_data
.w32
->menubar_active
= 1;
4112 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
4116 /* Eat any mouse messages during popupmenu */
4117 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
4119 /* Get the menu selection, if any */
4120 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
4122 retval
= LOWORD (amsg
.wParam
);
4136 case WM_EMACS_FILENOTIFY
:
4137 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4141 /* Check for messages registered at runtime. */
4142 if (msg
== msh_mousewheel
)
4144 wmsg
.dwModifiers
= w32_get_modifiers ();
4145 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4146 signal_user_input ();
4151 return (w32_unicode_gui
? DefWindowProcW
: DefWindowProcA
) (hwnd
, msg
, wParam
, lParam
);
4154 /* The most common default return code for handled messages is 0. */
4159 my_create_window (struct frame
* f
)
4162 static int coords
[2];
4163 Lisp_Object left
, top
;
4164 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
4166 /* When called with RES_TYPE_NUMBER, x_get_arg will return zero for
4167 anything that is not a number and is not Qunbound. */
4168 left
= x_get_arg (dpyinfo
, Qnil
, Qleft
, "left", "Left", RES_TYPE_NUMBER
);
4169 top
= x_get_arg (dpyinfo
, Qnil
, Qtop
, "top", "Top", RES_TYPE_NUMBER
);
4170 if (EQ (left
, Qunbound
))
4171 coords
[0] = CW_USEDEFAULT
;
4173 coords
[0] = XINT (left
);
4174 if (EQ (top
, Qunbound
))
4175 coords
[1] = CW_USEDEFAULT
;
4177 coords
[1] = XINT (top
);
4179 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
,
4180 (WPARAM
)f
, (LPARAM
)coords
))
4182 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
4186 /* Create a tooltip window. Unlike my_create_window, we do not do this
4187 indirectly via the Window thread, as we do not need to process Window
4188 messages for the tooltip. Creating tooltips indirectly also creates
4189 deadlocks when tooltips are created for menu items. */
4191 my_create_tip_window (struct frame
*f
)
4195 rect
.left
= rect
.top
= 0;
4196 rect
.right
= FRAME_PIXEL_WIDTH (f
);
4197 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
4199 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
4200 FRAME_EXTERNAL_MENU_BAR (f
));
4202 tip_window
= FRAME_W32_WINDOW (f
)
4203 = CreateWindow (EMACS_CLASS
,
4205 f
->output_data
.w32
->dwStyle
,
4208 rect
.right
- rect
.left
,
4209 rect
.bottom
- rect
.top
,
4210 FRAME_W32_WINDOW (SELECTED_FRAME ()), /* owner */
4217 SetWindowLong (tip_window
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
4218 SetWindowLong (tip_window
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
4219 SetWindowLong (tip_window
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
4220 SetWindowLong (tip_window
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
4222 /* Tip frames have no scrollbars. */
4223 SetWindowLong (tip_window
, WND_VSCROLLBAR_INDEX
, 0);
4224 SetWindowLong (tip_window
, WND_HSCROLLBAR_INDEX
, 0);
4226 /* Do this to discard the default setting specified by our parent. */
4227 ShowWindow (tip_window
, SW_HIDE
);
4232 /* Create and set up the w32 window for frame F. */
4235 w32_window (struct frame
*f
, long window_prompting
, bool minibuffer_only
)
4239 /* Use the resource name as the top-level window name
4240 for looking up resources. Make a non-Lisp copy
4241 for the window manager, so GC relocation won't bother it.
4243 Elsewhere we specify the window name for the window manager. */
4244 f
->namebuf
= xlispstrdup (Vx_resource_name
);
4246 my_create_window (f
);
4248 validate_x_resource_name ();
4250 /* x_set_name normally ignores requests to set the name if the
4251 requested name is the same as the current name. This is the one
4252 place where that assumption isn't correct; f->name is set, but
4253 the server hasn't been told. */
4256 int explicit = f
->explicit_name
;
4258 f
->explicit_name
= 0;
4260 fset_name (f
, Qnil
);
4261 x_set_name (f
, name
, explicit);
4266 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
4267 initialize_frame_menubar (f
);
4269 if (FRAME_W32_WINDOW (f
) == 0)
4270 error ("Unable to create window");
4273 /* Handle the icon stuff for this window. Perhaps later we might
4274 want an x_set_icon_position which can be called interactively as
4278 x_icon (struct frame
*f
, Lisp_Object parms
)
4280 Lisp_Object icon_x
, icon_y
;
4281 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
4283 /* Set the position of the icon. Note that Windows 95 groups all
4284 icons in the tray. */
4285 icon_x
= x_get_arg (dpyinfo
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
4286 icon_y
= x_get_arg (dpyinfo
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
4287 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
4289 CHECK_NUMBER (icon_x
);
4290 CHECK_NUMBER (icon_y
);
4292 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
4293 error ("Both left and top icon corners of icon must be specified");
4298 /* Start up iconic or window? */
4299 x_wm_set_window_state
4300 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
4304 x_text_icon (f
, SSDATA ((!NILP (f
->icon_name
)
4314 x_make_gc (struct frame
*f
)
4316 XGCValues gc_values
;
4320 /* Create the GC's of this frame.
4321 Note that many default values are used. */
4324 gc_values
.font
= FRAME_FONT (f
);
4326 /* Cursor has cursor-color background, background-color foreground. */
4327 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
4328 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
4329 f
->output_data
.w32
->cursor_gc
4330 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
4331 (GCFont
| GCForeground
| GCBackground
),
4335 f
->output_data
.w32
->white_relief
.gc
= 0;
4336 f
->output_data
.w32
->black_relief
.gc
= 0;
4342 /* Handler for signals raised during x_create_frame and
4343 x_create_tip_frame. FRAME is the frame which is partially
4347 unwind_create_frame (Lisp_Object frame
)
4349 struct frame
*f
= XFRAME (frame
);
4351 /* If frame is ``official'', nothing to do. */
4352 if (NILP (Fmemq (frame
, Vframe_list
)))
4355 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
4357 /* If the frame's image cache refcount is still the same as our
4358 private shadow variable, it means we are unwinding a frame
4359 for which we didn't yet call init_frame_faces, where the
4360 refcount is incremented. Therefore, we increment it here, so
4361 that free_frame_faces, called in x_free_frame_resources
4362 below, will not mistakenly decrement the counter that was not
4363 incremented yet to account for this new frame. */
4364 if (FRAME_IMAGE_CACHE (f
) != NULL
4365 && FRAME_IMAGE_CACHE (f
)->refcount
== image_cache_refcount
)
4366 FRAME_IMAGE_CACHE (f
)->refcount
++;
4369 x_free_frame_resources (f
);
4373 /* Check that reference counts are indeed correct. */
4374 eassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
4375 eassert ((dpyinfo
->terminal
->image_cache
== NULL
4376 && image_cache_refcount
== 0)
4377 || (dpyinfo
->terminal
->image_cache
!= NULL
4378 && dpyinfo
->terminal
->image_cache
->refcount
== image_cache_refcount
));
4387 do_unwind_create_frame (Lisp_Object frame
)
4389 unwind_create_frame (frame
);
4393 unwind_create_frame_1 (Lisp_Object val
)
4395 inhibit_lisp_code
= val
;
4399 x_default_font_parameter (struct frame
*f
, Lisp_Object parms
)
4401 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
4402 Lisp_Object font_param
= x_get_arg (dpyinfo
, parms
, Qfont
, NULL
, NULL
,
4405 if (EQ (font_param
, Qunbound
))
4407 font
= !NILP (font_param
) ? font_param
4408 : x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4410 if (!STRINGP (font
))
4413 static char *names
[]
4414 = { "Courier New-10",
4415 "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1",
4416 "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1",
4420 for (i
= 0; names
[i
]; i
++)
4422 font
= font_open_by_name (f
, build_unibyte_string (names
[i
]));
4427 error ("No suitable font was found");
4429 else if (!NILP (font_param
))
4431 /* Remember the explicit font parameter, so we can re-apply it after
4432 we've applied the `default' face settings. */
4433 x_set_frame_parameters (f
, Fcons (Fcons (Qfont_param
, font_param
), Qnil
));
4435 x_default_parameter (f
, parms
, Qfont
, font
, "font", "Font", RES_TYPE_STRING
);
4438 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
4440 doc
: /* Make a new window, which is called a \"frame\" in Emacs terms.
4441 Return an Emacs frame object.
4442 PARAMETERS is an alist of frame parameters.
4443 If the parameters specify that the frame should not have a minibuffer,
4444 and do not specify a specific minibuffer window to use,
4445 then `default-minibuffer-frame' must be a frame whose minibuffer can
4446 be shared by the new frame.
4448 This function is an internal primitive--use `make-frame' instead. */)
4449 (Lisp_Object parameters
)
4452 Lisp_Object frame
, tem
;
4454 bool minibuffer_only
= false;
4455 long window_prompting
= 0;
4456 ptrdiff_t count
= SPECPDL_INDEX ();
4457 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4458 Lisp_Object display
;
4459 struct w32_display_info
*dpyinfo
= NULL
;
4463 if (!FRAME_W32_P (SELECTED_FRAME ())
4464 && !FRAME_INITIAL_P (SELECTED_FRAME ()))
4465 error ("Cannot create a GUI frame in a -nw session");
4467 /* Make copy of frame parameters because the original is in pure
4469 parameters
= Fcopy_alist (parameters
);
4471 /* Use this general default value to start with
4472 until we know if this frame has a specified name. */
4473 Vx_resource_name
= Vinvocation_name
;
4475 display
= x_get_arg (dpyinfo
, parameters
, Qterminal
, 0, 0, RES_TYPE_NUMBER
);
4476 if (EQ (display
, Qunbound
))
4477 display
= x_get_arg (dpyinfo
, parameters
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
4478 if (EQ (display
, Qunbound
))
4480 dpyinfo
= check_x_display_info (display
);
4481 kb
= dpyinfo
->terminal
->kboard
;
4483 if (!dpyinfo
->terminal
->name
)
4484 error ("Terminal is not live, can't create new frames on it");
4486 name
= x_get_arg (dpyinfo
, parameters
, Qname
, "name", "Name", RES_TYPE_STRING
);
4488 && ! EQ (name
, Qunbound
)
4490 error ("Invalid frame name--not a string or nil");
4493 Vx_resource_name
= name
;
4495 /* See if parent window is specified. */
4496 parent
= x_get_arg (dpyinfo
, parameters
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
4497 if (EQ (parent
, Qunbound
))
4499 if (! NILP (parent
))
4500 CHECK_NUMBER (parent
);
4502 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
4503 /* No need to protect DISPLAY because that's not used after passing
4504 it to make_frame_without_minibuffer. */
4506 GCPRO4 (parameters
, parent
, name
, frame
);
4507 tem
= x_get_arg (dpyinfo
, parameters
, Qminibuffer
, "minibuffer", "Minibuffer",
4509 if (EQ (tem
, Qnone
) || NILP (tem
))
4510 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
4511 else if (EQ (tem
, Qonly
))
4513 f
= make_minibuffer_frame ();
4514 minibuffer_only
= true;
4516 else if (WINDOWP (tem
))
4517 f
= make_frame_without_minibuffer (tem
, kb
, display
);
4519 f
= make_frame (true);
4521 XSETFRAME (frame
, f
);
4523 /* By default, make scrollbars the system standard width and height. */
4524 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
4525 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f
) = GetSystemMetrics (SM_CXHSCROLL
);
4527 f
->terminal
= dpyinfo
->terminal
;
4529 f
->output_method
= output_w32
;
4530 f
->output_data
.w32
= xzalloc (sizeof (struct w32_output
));
4531 FRAME_FONTSET (f
) = -1;
4534 (f
, x_get_arg (dpyinfo
, parameters
, Qicon_name
, "iconName", "Title",
4536 if (! STRINGP (f
->icon_name
))
4537 fset_icon_name (f
, Qnil
);
4539 /* FRAME_DISPLAY_INFO (f) = dpyinfo; */
4541 /* With FRAME_DISPLAY_INFO set up, this unwind-protect is safe. */
4542 record_unwind_protect (do_unwind_create_frame
, frame
);
4545 image_cache_refcount
=
4546 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
4547 dpyinfo_refcount
= dpyinfo
->reference_count
;
4548 #endif /* GLYPH_DEBUG */
4550 /* Specify the parent under which to make this window. */
4553 /* Cast to UINT_PTR shuts up compiler warnings about cast to
4554 pointer from integer of different size. */
4555 f
->output_data
.w32
->parent_desc
= (Window
) (UINT_PTR
) XFASTINT (parent
);
4556 f
->output_data
.w32
->explicit_parent
= true;
4560 f
->output_data
.w32
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
4561 f
->output_data
.w32
->explicit_parent
= false;
4564 /* Set the name; the functions to which we pass f expect the name to
4566 if (EQ (name
, Qunbound
) || NILP (name
))
4568 fset_name (f
, build_string (dpyinfo
->w32_id_name
));
4569 f
->explicit_name
= false;
4573 fset_name (f
, name
);
4574 f
->explicit_name
= true;
4575 /* Use the frame's title when getting resources for this frame. */
4576 specbind (Qx_resource_name
, name
);
4579 if (uniscribe_available
)
4580 register_font_driver (&uniscribe_font_driver
, f
);
4581 register_font_driver (&w32font_driver
, f
);
4583 x_default_parameter (f
, parameters
, Qfont_backend
, Qnil
,
4584 "fontBackend", "FontBackend", RES_TYPE_STRING
);
4586 /* Extract the window parameters from the supplied values
4587 that are needed to determine window geometry. */
4588 x_default_font_parameter (f
, parameters
);
4590 x_default_parameter (f
, parameters
, Qborder_width
, make_number (2),
4591 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4593 /* We recognize either internalBorderWidth or internalBorder
4594 (which is what xterm calls it). */
4595 if (NILP (Fassq (Qinternal_border_width
, parameters
)))
4599 value
= x_get_arg (dpyinfo
, parameters
, Qinternal_border_width
,
4600 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
4601 if (! EQ (value
, Qunbound
))
4602 parameters
= Fcons (Fcons (Qinternal_border_width
, value
),
4605 /* Default internalBorderWidth to 0 on Windows to match other programs. */
4606 x_default_parameter (f
, parameters
, Qinternal_border_width
, make_number (0),
4607 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
4608 x_default_parameter (f
, parameters
, Qright_divider_width
, make_number (0),
4609 NULL
, NULL
, RES_TYPE_NUMBER
);
4610 x_default_parameter (f
, parameters
, Qbottom_divider_width
, make_number (0),
4611 NULL
, NULL
, RES_TYPE_NUMBER
);
4612 x_default_parameter (f
, parameters
, Qvertical_scroll_bars
, Qright
,
4613 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
4614 x_default_parameter (f
, parameters
, Qhorizontal_scroll_bars
, Qnil
,
4615 "horizontalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
4617 /* Also do the stuff which must be set before the window exists. */
4618 x_default_parameter (f
, parameters
, Qforeground_color
, build_string ("black"),
4619 "foreground", "Foreground", RES_TYPE_STRING
);
4620 x_default_parameter (f
, parameters
, Qbackground_color
, build_string ("white"),
4621 "background", "Background", RES_TYPE_STRING
);
4622 x_default_parameter (f
, parameters
, Qmouse_color
, build_string ("black"),
4623 "pointerColor", "Foreground", RES_TYPE_STRING
);
4624 x_default_parameter (f
, parameters
, Qborder_color
, build_string ("black"),
4625 "borderColor", "BorderColor", RES_TYPE_STRING
);
4626 x_default_parameter (f
, parameters
, Qscreen_gamma
, Qnil
,
4627 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
4628 x_default_parameter (f
, parameters
, Qline_spacing
, Qnil
,
4629 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
4630 x_default_parameter (f
, parameters
, Qleft_fringe
, Qnil
,
4631 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
4632 x_default_parameter (f
, parameters
, Qright_fringe
, Qnil
,
4633 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
4634 /* Process alpha here (Bug#16619). */
4635 x_default_parameter (f
, parameters
, Qalpha
, Qnil
,
4636 "alpha", "Alpha", RES_TYPE_NUMBER
);
4638 /* Init faces first since we need the frame's column width/line
4639 height in various occasions. */
4640 init_frame_faces (f
);
4642 /* The following call of change_frame_size is needed since otherwise
4643 x_set_tool_bar_lines will already work with the character sizes
4644 installed by init_frame_faces while the frame's pixel size is
4645 still calculated from a character size of 1 and we subsequently
4646 hit the (height >= 0) assertion in window_box_height.
4648 The non-pixelwise code apparently worked around this because it
4649 had one frame line vs one toolbar line which left us with a zero
4650 root window height which was obviously wrong as well ... */
4651 adjust_frame_size (f
, FRAME_COLS (f
) * FRAME_COLUMN_WIDTH (f
),
4652 FRAME_LINES (f
) * FRAME_LINE_HEIGHT (f
), 5, true,
4655 /* The X resources controlling the menu-bar and tool-bar are
4656 processed specially at startup, and reflected in the mode
4657 variables; ignore them here. */
4658 x_default_parameter (f
, parameters
, Qmenu_bar_lines
,
4659 NILP (Vmenu_bar_mode
)
4660 ? make_number (0) : make_number (1),
4661 NULL
, NULL
, RES_TYPE_NUMBER
);
4662 x_default_parameter (f
, parameters
, Qtool_bar_lines
,
4663 NILP (Vtool_bar_mode
)
4664 ? make_number (0) : make_number (1),
4665 NULL
, NULL
, RES_TYPE_NUMBER
);
4667 x_default_parameter (f
, parameters
, Qbuffer_predicate
, Qnil
,
4668 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
4669 x_default_parameter (f
, parameters
, Qtitle
, Qnil
,
4670 "title", "Title", RES_TYPE_STRING
);
4671 x_default_parameter (f
, parameters
, Qfullscreen
, Qnil
,
4672 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
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 /* Make the window appear on the frame and enable display, unless
4732 the caller says not to. However, with explicit parent, Emacs
4733 cannot control visibility, so don't try. */
4734 if (! f
->output_data
.w32
->explicit_parent
)
4736 Lisp_Object visibility
;
4738 visibility
= x_get_arg (dpyinfo
, parameters
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
4739 if (EQ (visibility
, Qunbound
))
4742 if (EQ (visibility
, Qicon
))
4743 x_iconify_frame (f
);
4744 else if (! NILP (visibility
))
4745 x_make_frame_visible (f
);
4747 /* Must have been Qnil. */
4751 /* Initialize `default-minibuffer-frame' in case this is the first
4752 frame on this terminal. */
4753 if (FRAME_HAS_MINIBUF_P (f
)
4754 && (!FRAMEP (KVAR (kb
, Vdefault_minibuffer_frame
))
4755 || !FRAME_LIVE_P (XFRAME (KVAR (kb
, Vdefault_minibuffer_frame
)))))
4756 kset_default_minibuffer_frame (kb
, frame
);
4758 /* All remaining specified parameters, which have not been "used"
4759 by x_get_arg and friends, now go in the misc. alist of the frame. */
4760 for (tem
= parameters
; CONSP (tem
); tem
= XCDR (tem
))
4761 if (CONSP (XCAR (tem
)) && !NILP (XCAR (XCAR (tem
))))
4762 fset_param_alist (f
, Fcons (XCAR (tem
), f
->param_alist
));
4766 /* Make sure windows on this frame appear in calls to next-window
4767 and similar functions. */
4768 Vwindow_list
= Qnil
;
4770 return unbind_to (count
, frame
);
4773 /* FRAME is used only to get a handle on the X display. We don't pass the
4774 display info directly because we're called from frame.c, which doesn't
4775 know about that structure. */
4777 x_get_focus_frame (struct frame
*frame
)
4779 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (frame
);
4781 if (! dpyinfo
->w32_focus_frame
)
4784 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
4788 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
4789 doc
: /* Internal function called by `color-defined-p', which see.
4790 \(Note that the Nextstep version of this function ignores FRAME.) */)
4791 (Lisp_Object color
, Lisp_Object frame
)
4794 struct frame
*f
= decode_window_system_frame (frame
);
4796 CHECK_STRING (color
);
4798 if (w32_defined_color (f
, SDATA (color
), &foo
, false))
4804 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
4805 doc
: /* Internal function called by `color-values', which see. */)
4806 (Lisp_Object color
, Lisp_Object frame
)
4809 struct frame
*f
= decode_window_system_frame (frame
);
4811 CHECK_STRING (color
);
4813 if (w32_defined_color (f
, SDATA (color
), &foo
, false))
4814 return list3i ((GetRValue (foo
.pixel
) << 8) | GetRValue (foo
.pixel
),
4815 (GetGValue (foo
.pixel
) << 8) | GetGValue (foo
.pixel
),
4816 (GetBValue (foo
.pixel
) << 8) | GetBValue (foo
.pixel
));
4821 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
4822 doc
: /* Internal function called by `display-color-p', which see. */)
4823 (Lisp_Object display
)
4825 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4827 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
4833 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
,
4834 Sx_display_grayscale_p
, 0, 1, 0,
4835 doc
: /* Return t if DISPLAY supports shades of gray.
4836 Note that color displays do support shades of gray.
4837 The optional argument DISPLAY specifies which display to ask about.
4838 DISPLAY should be either a frame or a display name (a string).
4839 If omitted or nil, that stands for the selected frame's display. */)
4840 (Lisp_Object display
)
4842 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4844 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
4850 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
,
4851 Sx_display_pixel_width
, 0, 1, 0,
4852 doc
: /* Return the width in pixels of DISPLAY.
4853 The optional argument DISPLAY specifies which display to ask about.
4854 DISPLAY should be either a frame or a display name (a string).
4855 If omitted or nil, that stands for the selected frame's display.
4857 On \"multi-monitor\" setups this refers to the pixel width for all
4858 physical monitors associated with DISPLAY. To get information for
4859 each physical monitor, use `display-monitor-attributes-list'. */)
4860 (Lisp_Object display
)
4862 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4864 return make_number (x_display_pixel_width (dpyinfo
));
4867 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
4868 Sx_display_pixel_height
, 0, 1, 0,
4869 doc
: /* Return the height in pixels of DISPLAY.
4870 The optional argument DISPLAY specifies which display to ask about.
4871 DISPLAY should be either a frame or a display name (a string).
4872 If omitted or nil, that stands for the selected frame's display.
4874 On \"multi-monitor\" setups this refers to the pixel height for all
4875 physical monitors associated with DISPLAY. To get information for
4876 each physical monitor, use `display-monitor-attributes-list'. */)
4877 (Lisp_Object display
)
4879 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4881 return make_number (x_display_pixel_height (dpyinfo
));
4884 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
4886 doc
: /* Return the number of bitplanes of DISPLAY.
4887 The optional argument DISPLAY specifies which display to ask about.
4888 DISPLAY should be either a frame or a display name (a string).
4889 If omitted or nil, that stands for the selected frame's display. */)
4890 (Lisp_Object display
)
4892 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4894 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
4897 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
4899 doc
: /* Return the number of color cells of DISPLAY.
4900 The optional argument DISPLAY specifies which display to ask about.
4901 DISPLAY should be either a frame or a display name (a string).
4902 If omitted or nil, that stands for the selected frame's display. */)
4903 (Lisp_Object display
)
4905 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4908 /* Don't use NCOLORS: it returns incorrect results under remote
4909 * desktop. We force 24+ bit depths to 24-bit, both to prevent an
4910 * overflow and because probably is more meaningful on Windows
4913 cap
= 1 << min (dpyinfo
->n_planes
* dpyinfo
->n_cbits
, 24);
4914 return make_number (cap
);
4917 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
4918 Sx_server_max_request_size
,
4920 doc
: /* Return the maximum request size of the server of DISPLAY.
4921 The optional argument DISPLAY specifies which display to ask about.
4922 DISPLAY should be either a frame or a display name (a string).
4923 If omitted or nil, that stands for the selected frame's display. */)
4924 (Lisp_Object display
)
4926 return make_number (1);
4929 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
4930 doc
: /* Return the "vendor ID" string of the GUI software on TERMINAL.
4932 \(Labeling every distributor as a "vendor" embodies the false assumption
4933 that operating systems cannot be developed and distributed noncommercially.)
4935 For GNU and Unix systems, this queries the X server software; for
4936 MS-Windows, this queries the OS.
4938 The optional argument TERMINAL specifies which display to ask about.
4939 TERMINAL should be a terminal object, a frame or a display name (a string).
4940 If omitted or nil, that stands for the selected frame's display. */)
4941 (Lisp_Object terminal
)
4943 return build_string ("Microsoft Corp.");
4946 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
4947 doc
: /* Return the version numbers of the GUI software on TERMINAL.
4948 The value is a list of three integers specifying the version of the GUI
4951 For GNU and Unix system, the first 2 numbers are the version of the X
4952 Protocol used on TERMINAL and the 3rd number is the distributor-specific
4953 release number. For MS-Windows, the 3 numbers report the version and
4954 the build number of the OS.
4956 See also the function `x-server-vendor'.
4958 The optional argument TERMINAL specifies which display to ask about.
4959 TERMINAL should be a terminal object, a frame or a display name (a string).
4960 If omitted or nil, that stands for the selected frame's display. */)
4961 (Lisp_Object terminal
)
4963 return list3i (w32_major_version
, w32_minor_version
, w32_build_number
);
4966 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
4967 doc
: /* Return the number of screens on the server of DISPLAY.
4968 The optional argument DISPLAY specifies which display to ask about.
4969 DISPLAY should be either a frame or a display name (a string).
4970 If omitted or nil, that stands for the selected frame's display. */)
4971 (Lisp_Object display
)
4973 return make_number (1);
4976 DEFUN ("x-display-mm-height", Fx_display_mm_height
,
4977 Sx_display_mm_height
, 0, 1, 0,
4978 doc
: /* Return the height in millimeters of DISPLAY.
4979 The optional argument DISPLAY specifies which display to ask about.
4980 DISPLAY should be either a frame or a display name (a string).
4981 If omitted or nil, that stands for the selected frame's display.
4983 On \"multi-monitor\" setups this refers to the height in millimeters for
4984 all physical monitors associated with DISPLAY. To get information
4985 for each physical monitor, use `display-monitor-attributes-list'. */)
4986 (Lisp_Object display
)
4988 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4990 double mm_per_pixel
;
4993 mm_per_pixel
= ((double) GetDeviceCaps (hdc
, VERTSIZE
)
4994 / GetDeviceCaps (hdc
, VERTRES
));
4995 ReleaseDC (NULL
, hdc
);
4997 return make_number (x_display_pixel_height (dpyinfo
) * mm_per_pixel
+ 0.5);
5000 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
5001 doc
: /* Return the width in millimeters of DISPLAY.
5002 The optional argument DISPLAY specifies which display to ask about.
5003 DISPLAY should be either a frame or a display name (a string).
5004 If omitted or nil, that stands for the selected frame's display.
5006 On \"multi-monitor\" setups this refers to the width in millimeters for
5007 all physical monitors associated with TERMINAL. To get information
5008 for each physical monitor, use `display-monitor-attributes-list'. */)
5009 (Lisp_Object display
)
5011 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
5013 double mm_per_pixel
;
5016 mm_per_pixel
= ((double) GetDeviceCaps (hdc
, HORZSIZE
)
5017 / GetDeviceCaps (hdc
, HORZRES
));
5018 ReleaseDC (NULL
, hdc
);
5020 return make_number (x_display_pixel_width (dpyinfo
) * mm_per_pixel
+ 0.5);
5023 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
5024 Sx_display_backing_store
, 0, 1, 0,
5025 doc
: /* Return an indication of whether DISPLAY does backing store.
5026 The value may be `always', `when-mapped', or `not-useful'.
5027 The optional argument DISPLAY specifies which display to ask about.
5028 DISPLAY should be either a frame or a display name (a string).
5029 If omitted or nil, that stands for the selected frame's display. */)
5030 (Lisp_Object display
)
5032 return intern ("not-useful");
5035 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
5036 Sx_display_visual_class
, 0, 1, 0,
5037 doc
: /* Return the visual class of DISPLAY.
5038 The value is one of the symbols `static-gray', `gray-scale',
5039 `static-color', `pseudo-color', `true-color', or `direct-color'.
5041 The optional argument DISPLAY specifies which display to ask about.
5042 DISPLAY should be either a frame or a display name (a string).
5043 If omitted or nil, that stands for the selected frame's display. */)
5044 (Lisp_Object display
)
5046 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
5047 Lisp_Object result
= Qnil
;
5049 if (dpyinfo
->has_palette
)
5050 result
= intern ("pseudo-color");
5051 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
5052 result
= intern ("static-grey");
5053 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
5054 result
= intern ("static-color");
5055 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
5056 result
= intern ("true-color");
5061 DEFUN ("x-display-save-under", Fx_display_save_under
,
5062 Sx_display_save_under
, 0, 1, 0,
5063 doc
: /* Return t if DISPLAY supports the save-under feature.
5064 The optional argument DISPLAY specifies which display to ask about.
5065 DISPLAY should be either a frame or a display name (a string).
5066 If omitted or nil, that stands for the selected frame's display. */)
5067 (Lisp_Object display
)
5072 static BOOL CALLBACK ALIGN_STACK
5073 w32_monitor_enum (HMONITOR monitor
, HDC hdc
, RECT
*rcMonitor
, LPARAM dwData
)
5075 Lisp_Object
*monitor_list
= (Lisp_Object
*) dwData
;
5077 *monitor_list
= Fcons (make_save_ptr (monitor
), *monitor_list
);
5083 w32_display_monitor_attributes_list (void)
5085 Lisp_Object attributes_list
= Qnil
, primary_monitor_attributes
= Qnil
;
5086 Lisp_Object monitor_list
= Qnil
, monitor_frames
, rest
, frame
;
5089 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5091 if (!(enum_display_monitors_fn
&& get_monitor_info_fn
5092 && monitor_from_window_fn
))
5095 if (!enum_display_monitors_fn (NULL
, NULL
, w32_monitor_enum
,
5096 (LPARAM
) &monitor_list
)
5097 || NILP (monitor_list
))
5101 for (rest
= monitor_list
; CONSP (rest
); rest
= XCDR (rest
))
5104 monitors
= xmalloc (n_monitors
* sizeof (*monitors
));
5105 for (i
= 0; i
< n_monitors
; i
++)
5107 monitors
[i
] = XSAVE_POINTER (XCAR (monitor_list
), 0);
5108 monitor_list
= XCDR (monitor_list
);
5111 monitor_frames
= Fmake_vector (make_number (n_monitors
), Qnil
);
5112 FOR_EACH_FRAME (rest
, frame
)
5114 struct frame
*f
= XFRAME (frame
);
5116 if (FRAME_W32_P (f
) && !EQ (frame
, tip_frame
))
5119 monitor_from_window_fn (FRAME_W32_WINDOW (f
),
5120 MONITOR_DEFAULT_TO_NEAREST
);
5122 for (i
= 0; i
< n_monitors
; i
++)
5123 if (monitors
[i
] == monitor
)
5127 ASET (monitor_frames
, i
, Fcons (frame
, AREF (monitor_frames
, i
)));
5131 GCPRO3 (attributes_list
, primary_monitor_attributes
, monitor_frames
);
5133 for (i
= 0; i
< n_monitors
; i
++)
5135 Lisp_Object geometry
, workarea
, name
, attributes
= Qnil
;
5137 int width_mm
, height_mm
;
5138 struct MONITOR_INFO_EX mi
;
5140 mi
.cbSize
= sizeof (mi
);
5141 if (!get_monitor_info_fn (monitors
[i
], (struct MONITOR_INFO
*) &mi
))
5144 hdc
= CreateDCA ("DISPLAY", mi
.szDevice
, NULL
, NULL
);
5147 width_mm
= GetDeviceCaps (hdc
, HORZSIZE
);
5148 height_mm
= GetDeviceCaps (hdc
, VERTSIZE
);
5151 attributes
= Fcons (Fcons (Qframes
, AREF (monitor_frames
, i
)),
5154 name
= DECODE_SYSTEM (build_unibyte_string (mi
.szDevice
));
5156 attributes
= Fcons (Fcons (Qname
, name
), attributes
);
5158 attributes
= Fcons (Fcons (Qmm_size
, list2i (width_mm
, height_mm
)),
5161 workarea
= list4i (mi
.rcWork
.left
, mi
.rcWork
.top
,
5162 mi
.rcWork
.right
- mi
.rcWork
.left
,
5163 mi
.rcWork
.bottom
- mi
.rcWork
.top
);
5164 attributes
= Fcons (Fcons (Qworkarea
, workarea
), attributes
);
5166 geometry
= list4i (mi
.rcMonitor
.left
, mi
.rcMonitor
.top
,
5167 mi
.rcMonitor
.right
- mi
.rcMonitor
.left
,
5168 mi
.rcMonitor
.bottom
- mi
.rcMonitor
.top
);
5169 attributes
= Fcons (Fcons (Qgeometry
, geometry
), attributes
);
5171 if (mi
.dwFlags
& MONITORINFOF_PRIMARY
)
5172 primary_monitor_attributes
= attributes
;
5174 attributes_list
= Fcons (attributes
, attributes_list
);
5177 if (!NILP (primary_monitor_attributes
))
5178 attributes_list
= Fcons (primary_monitor_attributes
, attributes_list
);
5184 return attributes_list
;
5188 w32_display_monitor_attributes_list_fallback (struct w32_display_info
*dpyinfo
)
5190 Lisp_Object geometry
, workarea
, frames
, rest
, frame
, attributes
= Qnil
;
5192 double mm_per_pixel
;
5193 int pixel_width
, pixel_height
, width_mm
, height_mm
;
5196 /* Fallback: treat (possibly) multiple physical monitors as if they
5197 formed a single monitor as a whole. This should provide a
5198 consistent result at least on single monitor environments. */
5199 attributes
= Fcons (Fcons (Qname
, build_string ("combined screen")),
5203 FOR_EACH_FRAME (rest
, frame
)
5205 struct frame
*f
= XFRAME (frame
);
5207 if (FRAME_W32_P (f
) && !EQ (frame
, tip_frame
))
5208 frames
= Fcons (frame
, frames
);
5210 attributes
= Fcons (Fcons (Qframes
, frames
), attributes
);
5212 pixel_width
= x_display_pixel_width (dpyinfo
);
5213 pixel_height
= x_display_pixel_height (dpyinfo
);
5216 mm_per_pixel
= ((double) GetDeviceCaps (hdc
, HORZSIZE
)
5217 / GetDeviceCaps (hdc
, HORZRES
));
5218 width_mm
= pixel_width
* mm_per_pixel
+ 0.5;
5219 mm_per_pixel
= ((double) GetDeviceCaps (hdc
, VERTSIZE
)
5220 / GetDeviceCaps (hdc
, VERTRES
));
5221 height_mm
= pixel_height
* mm_per_pixel
+ 0.5;
5222 ReleaseDC (NULL
, hdc
);
5223 attributes
= Fcons (Fcons (Qmm_size
, list2i (width_mm
, height_mm
)),
5226 /* GetSystemMetrics below may return 0 for Windows 95 or NT 4.0, but
5228 geometry
= list4i (GetSystemMetrics (SM_XVIRTUALSCREEN
),
5229 GetSystemMetrics (SM_YVIRTUALSCREEN
),
5230 pixel_width
, pixel_height
);
5231 if (SystemParametersInfo (SPI_GETWORKAREA
, 0, &workarea_rect
, 0))
5232 workarea
= list4i (workarea_rect
.left
, workarea_rect
.top
,
5233 workarea_rect
.right
- workarea_rect
.left
,
5234 workarea_rect
.bottom
- workarea_rect
.top
);
5236 workarea
= geometry
;
5237 attributes
= Fcons (Fcons (Qworkarea
, workarea
), attributes
);
5239 attributes
= Fcons (Fcons (Qgeometry
, geometry
), attributes
);
5241 return list1 (attributes
);
5244 DEFUN ("w32-display-monitor-attributes-list", Fw32_display_monitor_attributes_list
,
5245 Sw32_display_monitor_attributes_list
,
5247 doc
: /* Return a list of physical monitor attributes on the W32 display DISPLAY.
5249 The optional argument DISPLAY specifies which display to ask about.
5250 DISPLAY should be either a frame or a display name (a string).
5251 If omitted or nil, that stands for the selected frame's display.
5253 Internal use only, use `display-monitor-attributes-list' instead. */)
5254 (Lisp_Object display
)
5256 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
5257 Lisp_Object attributes_list
;
5260 attributes_list
= w32_display_monitor_attributes_list ();
5261 if (NILP (attributes_list
))
5262 attributes_list
= w32_display_monitor_attributes_list_fallback (dpyinfo
);
5265 return attributes_list
;
5268 DEFUN ("set-message-beep", Fset_message_beep
, Sset_message_beep
, 1, 1, 0,
5269 doc
: /* Set the sound generated when the bell is rung.
5270 SOUND is 'asterisk, 'exclamation, 'hand, 'question, 'ok, or 'silent
5271 to use the corresponding system sound for the bell. The 'silent sound
5272 prevents Emacs from making any sound at all.
5273 SOUND is nil to use the normal beep. */)
5276 CHECK_SYMBOL (sound
);
5279 sound_type
= 0xFFFFFFFF;
5280 else if (EQ (sound
, intern ("asterisk")))
5281 sound_type
= MB_ICONASTERISK
;
5282 else if (EQ (sound
, intern ("exclamation")))
5283 sound_type
= MB_ICONEXCLAMATION
;
5284 else if (EQ (sound
, intern ("hand")))
5285 sound_type
= MB_ICONHAND
;
5286 else if (EQ (sound
, intern ("question")))
5287 sound_type
= MB_ICONQUESTION
;
5288 else if (EQ (sound
, intern ("ok")))
5290 else if (EQ (sound
, intern ("silent")))
5291 sound_type
= MB_EMACS_SILENT
;
5293 sound_type
= 0xFFFFFFFF;
5299 x_screen_planes (register struct frame
*f
)
5301 return FRAME_DISPLAY_INFO (f
)->n_planes
;
5304 /* Return the display structure for the display named NAME.
5305 Open a new connection if necessary. */
5307 struct w32_display_info
*
5308 x_display_info_for_name (Lisp_Object name
)
5310 struct w32_display_info
*dpyinfo
;
5312 CHECK_STRING (name
);
5314 for (dpyinfo
= &one_w32_display_info
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
5315 if (!NILP (Fstring_equal (XCAR (dpyinfo
->name_list_element
), name
)))
5318 /* Use this general default value to start with. */
5319 Vx_resource_name
= Vinvocation_name
;
5321 validate_x_resource_name ();
5323 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
5324 SSDATA (Vx_resource_name
));
5327 error ("Cannot connect to server %s", SDATA (name
));
5329 XSETFASTINT (Vwindow_system_version
, w32_major_version
);
5334 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
5335 1, 3, 0, doc
: /* Open a connection to a display server.
5336 DISPLAY is the name of the display to connect to.
5337 Optional second arg XRM-STRING is a string of resources in xrdb format.
5338 If the optional third arg MUST-SUCCEED is non-nil,
5339 terminate Emacs if we can't open the connection.
5340 \(In the Nextstep version, the last two arguments are currently ignored.) */)
5341 (Lisp_Object display
, Lisp_Object xrm_string
, Lisp_Object must_succeed
)
5343 unsigned char *xrm_option
;
5344 struct w32_display_info
*dpyinfo
;
5346 CHECK_STRING (display
);
5348 /* Signal an error in order to encourage correct use from callers.
5349 * If we ever support multiple window systems in the same Emacs,
5350 * we'll need callers to be precise about what window system they
5353 if (strcmp (SSDATA (display
), "w32") != 0)
5354 error ("The name of the display in this Emacs must be \"w32\"");
5356 /* If initialization has already been done, return now to avoid
5357 overwriting critical parts of one_w32_display_info. */
5358 if (window_system_available (NULL
))
5361 if (! NILP (xrm_string
))
5362 CHECK_STRING (xrm_string
);
5364 /* Allow color mapping to be defined externally; first look in user's
5365 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
5367 Lisp_Object color_file
;
5368 struct gcpro gcpro1
;
5370 color_file
= build_string ("~/rgb.txt");
5372 GCPRO1 (color_file
);
5374 if (NILP (Ffile_readable_p (color_file
)))
5376 Fexpand_file_name (build_string ("rgb.txt"),
5377 Fsymbol_value (intern ("data-directory")));
5379 Vw32_color_map
= Fx_load_color_file (color_file
);
5383 if (NILP (Vw32_color_map
))
5384 Vw32_color_map
= w32_default_color_map ();
5386 /* Merge in system logical colors. */
5387 add_system_logical_colors_to_map (&Vw32_color_map
);
5389 if (! NILP (xrm_string
))
5390 xrm_option
= SDATA (xrm_string
);
5392 xrm_option
= (unsigned char *) 0;
5394 /* Use this general default value to start with. */
5395 /* First remove .exe suffix from invocation-name - it looks ugly. */
5397 char basename
[ MAX_PATH
], *str
;
5399 lispstpcpy (basename
, Vinvocation_name
);
5400 str
= strrchr (basename
, '.');
5402 Vinvocation_name
= build_string (basename
);
5404 Vx_resource_name
= Vinvocation_name
;
5406 validate_x_resource_name ();
5408 /* This is what opens the connection and sets x_current_display.
5409 This also initializes many symbols, such as those used for input. */
5410 dpyinfo
= w32_term_init (display
, xrm_option
,
5411 SSDATA (Vx_resource_name
));
5415 if (!NILP (must_succeed
))
5416 fatal ("Cannot connect to server %s.\n",
5419 error ("Cannot connect to server %s", SDATA (display
));
5422 XSETFASTINT (Vwindow_system_version
, w32_major_version
);
5426 DEFUN ("x-close-connection", Fx_close_connection
,
5427 Sx_close_connection
, 1, 1, 0,
5428 doc
: /* Close the connection to DISPLAY's server.
5429 For DISPLAY, specify either a frame or a display name (a string).
5430 If DISPLAY is nil, that stands for the selected frame's display. */)
5431 (Lisp_Object display
)
5433 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
5435 if (dpyinfo
->reference_count
> 0)
5436 error ("Display still has frames on it");
5439 x_destroy_all_bitmaps (dpyinfo
);
5441 x_delete_display (dpyinfo
);
5447 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
5448 doc
: /* Return the list of display names that Emacs has connections to. */)
5451 Lisp_Object result
= Qnil
;
5452 struct w32_display_info
*wdi
;
5454 for (wdi
= x_display_list
; wdi
; wdi
= wdi
->next
)
5455 result
= Fcons (XCAR (wdi
->name_list_element
), result
);
5460 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
5461 doc
: /* If ON is non-nil, report X errors as soon as the erring request is made.
5462 This function only has an effect on X Windows. With MS Windows, it is
5463 defined but does nothing.
5465 If ON is nil, allow buffering of requests.
5466 Turning on synchronization prohibits the Xlib routines from buffering
5467 requests and seriously degrades performance, but makes debugging much
5469 The optional second argument TERMINAL specifies which display to act on.
5470 TERMINAL should be a terminal object, a frame or a display name (a string).
5471 If TERMINAL is omitted or nil, that stands for the selected frame's display. */)
5472 (Lisp_Object on
, Lisp_Object display
)
5479 /***********************************************************************
5481 ***********************************************************************/
5483 #if 0 /* TODO : port window properties to W32 */
5485 DEFUN ("x-change-window-property", Fx_change_window_property
,
5486 Sx_change_window_property
, 2, 6, 0,
5487 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
5488 PROP must be a string. VALUE may be a string or a list of conses,
5489 numbers and/or strings. If an element in the list is a string, it is
5490 converted to an atom and the value of the Atom is used. If an element
5491 is a cons, it is converted to a 32 bit number where the car is the 16
5492 top bits and the cdr is the lower 16 bits.
5494 FRAME nil or omitted means use the selected frame.
5495 If TYPE is given and non-nil, it is the name of the type of VALUE.
5496 If TYPE is not given or nil, the type is STRING.
5497 FORMAT gives the size in bits of each element if VALUE is a list.
5498 It must be one of 8, 16 or 32.
5499 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
5500 If OUTER-P is non-nil, the property is changed for the outer X window of
5501 FRAME. Default is to change on the edit X window. */)
5502 (Lisp_Object prop
, Lisp_Object value
, Lisp_Object frame
,
5503 Lisp_Object type
, Lisp_Object format
, Lisp_Object outer_p
)
5505 struct frame
*f
= decode_window_system_frame (frame
);
5508 CHECK_STRING (prop
);
5509 CHECK_STRING (value
);
5512 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5513 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5514 prop_atom
, XA_STRING
, 8, PropModeReplace
,
5515 SDATA (value
), SCHARS (value
));
5517 /* Make sure the property is set when we return. */
5518 XFlush (FRAME_W32_DISPLAY (f
));
5525 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
5526 Sx_delete_window_property
, 1, 2, 0,
5527 doc
: /* Remove window property PROP from X window of FRAME.
5528 FRAME nil or omitted means use the selected frame. Value is PROP. */)
5529 (Lisp_Object prop
, Lisp_Object frame
)
5531 struct frame
*f
= decode_window_system_frame (frame
);
5534 CHECK_STRING (prop
);
5536 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5537 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
5539 /* Make sure the property is removed when we return. */
5540 XFlush (FRAME_W32_DISPLAY (f
));
5547 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
5549 doc
: /* Value is the value of window property PROP on FRAME.
5550 If FRAME is nil or omitted, use the selected frame.
5552 On X Windows, the following optional arguments are also accepted:
5553 If TYPE is nil or omitted, get the property as a string.
5554 Otherwise TYPE is the name of the atom that denotes the type expected.
5555 If SOURCE is non-nil, get the property on that window instead of from
5556 FRAME. The number 0 denotes the root window.
5557 If DELETE-P is non-nil, delete the property after retrieving it.
5558 If VECTOR-RET-P is non-nil, don't return a string but a vector of values.
5560 On MS Windows, this function accepts but ignores those optional arguments.
5562 Value is nil if FRAME hasn't a property with name PROP or if PROP has
5563 no value of TYPE (always string in the MS Windows case). */)
5564 (Lisp_Object prop
, Lisp_Object frame
, Lisp_Object type
,
5565 Lisp_Object source
, Lisp_Object delete_p
, Lisp_Object vector_ret_p
)
5567 struct frame
*f
= decode_window_system_frame (frame
);
5570 Lisp_Object prop_value
= Qnil
;
5571 char *tmp_data
= NULL
;
5574 unsigned long actual_size
, bytes_remaining
;
5576 CHECK_STRING (prop
);
5578 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5579 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5580 prop_atom
, 0, 0, False
, XA_STRING
,
5581 &actual_type
, &actual_format
, &actual_size
,
5582 &bytes_remaining
, (unsigned char **) &tmp_data
);
5585 int size
= bytes_remaining
;
5590 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5591 prop_atom
, 0, bytes_remaining
,
5593 &actual_type
, &actual_format
,
5594 &actual_size
, &bytes_remaining
,
5595 (unsigned char **) &tmp_data
);
5597 prop_value
= make_string (tmp_data
, size
);
5611 /***********************************************************************
5613 ***********************************************************************/
5615 static Lisp_Object
x_create_tip_frame (struct w32_display_info
*,
5616 Lisp_Object
, Lisp_Object
);
5617 static void compute_tip_xy (struct frame
*, Lisp_Object
, Lisp_Object
,
5618 Lisp_Object
, int, int, int *, int *);
5620 /* The frame of a currently visible tooltip. */
5622 Lisp_Object tip_frame
;
5624 /* If non-nil, a timer started that hides the last tooltip when it
5627 Lisp_Object tip_timer
;
5630 /* If non-nil, a vector of 3 elements containing the last args
5631 with which x-show-tip was called. See there. */
5633 Lisp_Object last_show_tip_args
;
5637 unwind_create_tip_frame (Lisp_Object frame
)
5639 Lisp_Object deleted
;
5641 deleted
= unwind_create_frame (frame
);
5642 if (EQ (deleted
, Qt
))
5650 /* Create a frame for a tooltip on the display described by DPYINFO.
5651 PARMS is a list of frame parameters. TEXT is the string to
5652 display in the tip frame. Value is the frame.
5654 Note that functions called here, esp. x_default_parameter can
5655 signal errors, for instance when a specified color name is
5656 undefined. We have to make sure that we're in a consistent state
5657 when this happens. */
5660 x_create_tip_frame (struct w32_display_info
*dpyinfo
,
5661 Lisp_Object parms
, Lisp_Object text
)
5666 long window_prompting
= 0;
5668 ptrdiff_t count
= SPECPDL_INDEX ();
5669 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5671 bool face_change_before
= face_change
;
5673 struct buffer
*old_buffer
;
5675 /* Use this general default value to start with until we know if
5676 this frame has a specified name. */
5677 Vx_resource_name
= Vinvocation_name
;
5679 kb
= dpyinfo
->terminal
->kboard
;
5681 /* The calls to x_get_arg remove elements from PARMS, so copy it to
5682 avoid destructive changes behind our caller's back. */
5683 parms
= Fcopy_alist (parms
);
5685 /* Get the name of the frame to use for resource lookup. */
5686 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
5688 && !EQ (name
, Qunbound
)
5690 error ("Invalid frame name--not a string or nil");
5691 Vx_resource_name
= name
;
5694 GCPRO3 (parms
, name
, frame
);
5695 /* Make a frame without minibuffer nor mode-line. */
5696 f
= make_frame (false);
5697 f
->wants_modeline
= 0;
5698 XSETFRAME (frame
, f
);
5700 AUTO_STRING (tip
, " *tip*");
5701 buffer
= Fget_buffer_create (tip
);
5702 /* Use set_window_buffer instead of Fset_window_buffer (see
5703 discussion of bug#11984, bug#12025, bug#12026). */
5704 set_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, false, false);
5705 old_buffer
= current_buffer
;
5706 set_buffer_internal_1 (XBUFFER (buffer
));
5707 bset_truncate_lines (current_buffer
, Qnil
);
5708 specbind (Qinhibit_read_only
, Qt
);
5709 specbind (Qinhibit_modification_hooks
, Qt
);
5712 set_buffer_internal_1 (old_buffer
);
5714 record_unwind_protect (unwind_create_tip_frame
, frame
);
5716 /* By setting the output method, we're essentially saying that
5717 the frame is live, as per FRAME_LIVE_P. If we get a signal
5718 from this point on, x_destroy_window might screw up reference
5720 f
->terminal
= dpyinfo
->terminal
;
5721 f
->output_method
= output_w32
;
5722 f
->output_data
.w32
= xzalloc (sizeof (struct w32_output
));
5724 FRAME_FONTSET (f
) = -1;
5725 fset_icon_name (f
, Qnil
);
5728 image_cache_refcount
=
5729 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
5730 dpyinfo_refcount
= dpyinfo
->reference_count
;
5731 #endif /* GLYPH_DEBUG */
5732 FRAME_KBOARD (f
) = kb
;
5733 f
->output_data
.w32
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
5734 f
->output_data
.w32
->explicit_parent
= false;
5736 /* Set the name; the functions to which we pass f expect the name to
5738 if (EQ (name
, Qunbound
) || NILP (name
))
5740 fset_name (f
, build_string (dpyinfo
->w32_id_name
));
5741 f
->explicit_name
= false;
5745 fset_name (f
, name
);
5746 f
->explicit_name
= true;
5747 /* use the frame's title when getting resources for this frame. */
5748 specbind (Qx_resource_name
, name
);
5751 if (uniscribe_available
)
5752 register_font_driver (&uniscribe_font_driver
, f
);
5753 register_font_driver (&w32font_driver
, f
);
5755 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
5756 "fontBackend", "FontBackend", RES_TYPE_STRING
);
5758 /* Extract the window parameters from the supplied values
5759 that are needed to determine window geometry. */
5760 x_default_font_parameter (f
, parms
);
5762 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
5763 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5764 /* This defaults to 2 in order to match xterm. We recognize either
5765 internalBorderWidth or internalBorder (which is what xterm calls
5767 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5771 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
5772 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
5773 if (! EQ (value
, Qunbound
))
5774 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
5777 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
5778 "internalBorderWidth", "internalBorderWidth",
5780 x_default_parameter (f
, parms
, Qright_divider_width
, make_number (0),
5781 NULL
, NULL
, RES_TYPE_NUMBER
);
5782 x_default_parameter (f
, parms
, Qbottom_divider_width
, make_number (0),
5783 NULL
, NULL
, RES_TYPE_NUMBER
);
5785 /* Also do the stuff which must be set before the window exists. */
5786 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
5787 "foreground", "Foreground", RES_TYPE_STRING
);
5788 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
5789 "background", "Background", RES_TYPE_STRING
);
5790 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
5791 "pointerColor", "Foreground", RES_TYPE_STRING
);
5792 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
5793 "cursorColor", "Foreground", RES_TYPE_STRING
);
5794 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
5795 "borderColor", "BorderColor", RES_TYPE_STRING
);
5796 x_default_parameter (f
, parms
, Qalpha
, Qnil
,
5797 "alpha", "Alpha", RES_TYPE_NUMBER
);
5799 /* Init faces before x_default_parameter is called for the
5800 scroll-bar-width parameter because otherwise we end up in
5801 init_iterator with a null face cache, which should not happen. */
5802 init_frame_faces (f
);
5804 f
->output_data
.w32
->dwStyle
= WS_BORDER
| WS_POPUP
| WS_DISABLED
;
5805 f
->output_data
.w32
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
5807 window_prompting
= x_figure_window_size (f
, parms
, false);
5809 /* No fringes on tip frame. */
5811 f
->left_fringe_width
= 0;
5812 f
->right_fringe_width
= 0;
5815 my_create_tip_window (f
);
5820 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
5821 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5822 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5823 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5824 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5825 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5827 /* Dimensions, especially FRAME_LINES (f), must be done via
5828 change_frame_size. Change will not be effected unless different
5829 from the current FRAME_LINES (f). */
5830 width
= FRAME_COLS (f
);
5831 height
= FRAME_LINES (f
);
5832 SET_FRAME_COLS (f
, 0);
5833 SET_FRAME_LINES (f
, 0);
5834 adjust_frame_size (f
, width
* FRAME_COLUMN_WIDTH (f
),
5835 height
* FRAME_LINE_HEIGHT (f
), 0, true, Qnil
);
5837 /* Add `tooltip' frame parameter's default value. */
5838 if (NILP (Fframe_parameter (frame
, Qtooltip
)))
5839 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qtooltip
, Qt
), Qnil
));
5841 /* Set up faces after all frame parameters are known. This call
5842 also merges in face attributes specified for new frames.
5844 Frame parameters may be changed if .Xdefaults contains
5845 specifications for the default font. For example, if there is an
5846 `Emacs.default.attributeBackground: pink', the `background-color'
5847 attribute of the frame get's set, which let's the internal border
5848 of the tooltip frame appear in pink. Prevent this. */
5850 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
5851 Lisp_Object fg
= Fframe_parameter (frame
, Qforeground_color
);
5852 Lisp_Object colors
= Qnil
;
5854 /* Set tip_frame here, so that */
5856 call2 (Qface_set_after_frame_default
, frame
, Qnil
);
5858 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
5859 colors
= Fcons (Fcons (Qbackground_color
, bg
), colors
);
5860 if (!EQ (fg
, Fframe_parameter (frame
, Qforeground_color
)))
5861 colors
= Fcons (Fcons (Qforeground_color
, fg
), colors
);
5864 Fmodify_frame_parameters (frame
, colors
);
5871 /* Now that the frame is official, it counts as a reference to
5873 FRAME_DISPLAY_INFO (f
)->reference_count
++;
5874 f
->terminal
->reference_count
++;
5876 /* It is now ok to make the frame official even if we get an error
5877 below. And the frame needs to be on Vframe_list or making it
5878 visible won't work. */
5879 Vframe_list
= Fcons (frame
, Vframe_list
);
5880 f
->can_x_set_window_size
= true;
5882 /* Setting attributes of faces of the tooltip frame from resources
5883 and similar will set face_change, which leads to the
5884 clearing of all current matrices. Since this isn't necessary
5885 here, avoid it by resetting face_change to the value it
5886 had before we created the tip frame. */
5887 face_change
= face_change_before
;
5889 /* Discard the unwind_protect. */
5890 return unbind_to (count
, frame
);
5894 /* Compute where to display tip frame F. PARMS is the list of frame
5895 parameters for F. DX and DY are specified offsets from the current
5896 location of the mouse. WIDTH and HEIGHT are the width and height
5897 of the tooltip. Return coordinates relative to the root window of
5898 the display in *ROOT_X, and *ROOT_Y. */
5901 compute_tip_xy (struct frame
*f
,
5902 Lisp_Object parms
, Lisp_Object dx
, Lisp_Object dy
,
5903 int width
, int height
, int *root_x
, int *root_y
)
5905 Lisp_Object left
, top
;
5906 int min_x
, min_y
, max_x
, max_y
;
5908 /* User-specified position? */
5909 left
= Fcdr (Fassq (Qleft
, parms
));
5910 top
= Fcdr (Fassq (Qtop
, parms
));
5912 /* Move the tooltip window where the mouse pointer is. Resize and
5914 if (!INTEGERP (left
) || !INTEGERP (top
))
5918 /* Default min and max values. */
5921 max_x
= x_display_pixel_width (FRAME_DISPLAY_INFO (f
));
5922 max_y
= x_display_pixel_height (FRAME_DISPLAY_INFO (f
));
5930 /* If multiple monitor support is available, constrain the tip onto
5931 the current monitor. This improves the above by allowing negative
5932 co-ordinates if monitor positions are such that they are valid, and
5933 snaps a tooltip onto a single monitor if we are close to the edge
5934 where it would otherwise flow onto the other monitor (or into
5935 nothingness if there is a gap in the overlap). */
5936 if (monitor_from_point_fn
&& get_monitor_info_fn
)
5938 struct MONITOR_INFO info
;
5940 = monitor_from_point_fn (pt
, MONITOR_DEFAULT_TO_NEAREST
);
5941 info
.cbSize
= sizeof (info
);
5943 if (get_monitor_info_fn (monitor
, &info
))
5945 min_x
= info
.rcWork
.left
;
5946 min_y
= info
.rcWork
.top
;
5947 max_x
= info
.rcWork
.right
;
5948 max_y
= info
.rcWork
.bottom
;
5954 *root_y
= XINT (top
);
5955 else if (*root_y
+ XINT (dy
) <= min_y
)
5956 *root_y
= min_y
; /* Can happen for negative dy */
5957 else if (*root_y
+ XINT (dy
) + height
<= max_y
)
5958 /* It fits below the pointer */
5959 *root_y
+= XINT (dy
);
5960 else if (height
+ XINT (dy
) + min_y
<= *root_y
)
5961 /* It fits above the pointer. */
5962 *root_y
-= height
+ XINT (dy
);
5964 /* Put it on the top. */
5967 if (INTEGERP (left
))
5968 *root_x
= XINT (left
);
5969 else if (*root_x
+ XINT (dx
) <= min_x
)
5970 *root_x
= 0; /* Can happen for negative dx */
5971 else if (*root_x
+ XINT (dx
) + width
<= max_x
)
5972 /* It fits to the right of the pointer. */
5973 *root_x
+= XINT (dx
);
5974 else if (width
+ XINT (dx
) + min_x
<= *root_x
)
5975 /* It fits to the left of the pointer. */
5976 *root_x
-= width
+ XINT (dx
);
5978 /* Put it left justified on the screen -- it ought to fit that way. */
5983 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
5984 doc
: /* Show STRING in a \"tooltip\" window on frame FRAME.
5985 A tooltip window is a small window displaying a string.
5987 This is an internal function; Lisp code should call `tooltip-show'.
5989 FRAME nil or omitted means use the selected frame.
5991 PARMS is an optional list of frame parameters which can be
5992 used to change the tooltip's appearance.
5994 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
5995 means use the default timeout of 5 seconds.
5997 If the list of frame parameters PARMS contains a `left' parameter,
5998 the tooltip is displayed at that x-position. Otherwise it is
5999 displayed at the mouse position, with offset DX added (default is 5 if
6000 DX isn't specified). Likewise for the y-position; if a `top' frame
6001 parameter is specified, it determines the y-position of the tooltip
6002 window, otherwise it is displayed at the mouse position, with offset
6003 DY added (default is -10).
6005 A tooltip's maximum size is specified by `x-max-tooltip-size'.
6006 Text larger than the specified size is clipped. */)
6007 (Lisp_Object string
, Lisp_Object frame
, Lisp_Object parms
, Lisp_Object timeout
, Lisp_Object dx
, Lisp_Object dy
)
6012 struct buffer
*old_buffer
;
6013 struct text_pos pos
;
6014 int i
, width
, height
;
6015 bool seen_reversed_p
;
6016 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
6017 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
6018 ptrdiff_t count
= SPECPDL_INDEX ();
6020 specbind (Qinhibit_redisplay
, Qt
);
6022 GCPRO4 (string
, parms
, frame
, timeout
);
6024 CHECK_STRING (string
);
6025 f
= decode_window_system_frame (frame
);
6027 timeout
= make_number (5);
6029 CHECK_NATNUM (timeout
);
6032 dx
= make_number (5);
6037 dy
= make_number (-10);
6041 if (NILP (last_show_tip_args
))
6042 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
6044 if (!NILP (tip_frame
))
6046 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
6047 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
6048 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
6050 if (EQ (frame
, last_frame
)
6051 && !NILP (Fequal (last_string
, string
))
6052 && !NILP (Fequal (last_parms
, parms
)))
6054 struct frame
*f
= XFRAME (tip_frame
);
6056 /* Only DX and DY have changed. */
6057 if (!NILP (tip_timer
))
6059 Lisp_Object timer
= tip_timer
;
6061 call1 (Qcancel_timer
, timer
);
6065 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
6066 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
6068 /* Put tooltip in topmost group and in position. */
6069 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
6070 root_x
, root_y
, 0, 0,
6071 SWP_NOSIZE
| SWP_NOACTIVATE
| SWP_NOOWNERZORDER
);
6073 /* Ensure tooltip is on top of other topmost windows (eg menus). */
6074 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
6076 SWP_NOMOVE
| SWP_NOSIZE
6077 | SWP_NOACTIVATE
| SWP_NOOWNERZORDER
);
6084 /* Hide a previous tip, if any. */
6087 ASET (last_show_tip_args
, 0, string
);
6088 ASET (last_show_tip_args
, 1, frame
);
6089 ASET (last_show_tip_args
, 2, parms
);
6091 /* Add default values to frame parameters. */
6092 if (NILP (Fassq (Qname
, parms
)))
6093 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
6094 if (NILP (Fassq (Qinternal_border_width
, parms
)))
6095 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
6096 if (NILP (Fassq (Qright_divider_width
, parms
)))
6097 parms
= Fcons (Fcons (Qright_divider_width
, make_number (0)), parms
);
6098 if (NILP (Fassq (Qbottom_divider_width
, parms
)))
6099 parms
= Fcons (Fcons (Qbottom_divider_width
, make_number (0)), parms
);
6100 if (NILP (Fassq (Qborder_width
, parms
)))
6101 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
6102 if (NILP (Fassq (Qborder_color
, parms
)))
6103 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
6104 if (NILP (Fassq (Qbackground_color
, parms
)))
6105 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
6108 /* Block input until the tip has been fully drawn, to avoid crashes
6109 when drawing tips in menus. */
6112 /* Create a frame for the tooltip, and record it in the global
6113 variable tip_frame. */
6114 frame
= x_create_tip_frame (FRAME_DISPLAY_INFO (f
), parms
, string
);
6117 /* Set up the frame's root window. */
6118 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6124 if (CONSP (Vx_max_tooltip_size
)
6125 && INTEGERP (XCAR (Vx_max_tooltip_size
))
6126 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
6127 && INTEGERP (XCDR (Vx_max_tooltip_size
))
6128 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
6130 w
->total_cols
= XFASTINT (XCAR (Vx_max_tooltip_size
));
6131 w
->total_lines
= XFASTINT (XCDR (Vx_max_tooltip_size
));
6136 w
->total_lines
= 40;
6139 w
->pixel_width
= w
->total_cols
* FRAME_COLUMN_WIDTH (f
);
6140 w
->pixel_height
= w
->total_lines
* FRAME_LINE_HEIGHT (f
);
6142 FRAME_TOTAL_COLS (f
) = WINDOW_TOTAL_COLS (w
);
6143 adjust_frame_glyphs (f
);
6144 w
->pseudo_window_p
= true;
6146 /* Display the tooltip text in a temporary buffer. */
6147 old_buffer
= current_buffer
;
6148 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->contents
));
6149 bset_truncate_lines (current_buffer
, Qnil
);
6150 clear_glyph_matrix (w
->desired_matrix
);
6151 clear_glyph_matrix (w
->current_matrix
);
6152 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
6153 try_window (FRAME_ROOT_WINDOW (f
), pos
, TRY_WINDOW_IGNORE_FONTS_CHANGE
);
6155 /* Compute width and height of the tooltip. */
6157 seen_reversed_p
= false;
6158 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
6160 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
6164 /* Stop at the first empty row at the end. */
6165 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
6168 /* Let the row go over the full width of the frame. */
6169 row
->full_width_p
= true;
6171 row_width
= row
->pixel_width
;
6172 if (row
->used
[TEXT_AREA
])
6174 if (!row
->reversed_p
)
6176 /* There's a glyph at the end of rows that is used to
6177 place the cursor there. Don't include the width of
6179 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
6180 if (NILP (last
->object
))
6181 row_width
-= last
->pixel_width
;
6185 /* There could be a stretch glyph at the beginning of R2L
6186 rows that is produced by extend_face_to_end_of_line.
6187 Don't count that glyph. */
6188 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
6190 if (g
->type
== STRETCH_GLYPH
&& NILP (g
->object
))
6192 row_width
-= g
->pixel_width
;
6193 seen_reversed_p
= true;
6198 height
+= row
->height
;
6199 width
= max (width
, row_width
);
6202 /* If we've seen partial-length R2L rows, we need to re-adjust the
6203 tool-tip frame width and redisplay it again, to avoid over-wide
6204 tips due to the stretch glyph that extends R2L lines to full
6205 width of the frame. */
6206 if (seen_reversed_p
)
6208 /* PXW: Why do we do the pixel-to-cols conversion only if
6209 seen_reversed_p holds? Don't we have to set other fields of
6210 the window/frame structure?
6212 w->total_cols and FRAME_TOTAL_COLS want the width in columns,
6214 w
->pixel_width
= width
;
6215 width
/= WINDOW_FRAME_COLUMN_WIDTH (w
);
6216 w
->total_cols
= width
;
6217 FRAME_TOTAL_COLS (f
) = width
;
6218 SET_FRAME_WIDTH (f
, width
);
6219 adjust_frame_glyphs (f
);
6220 w
->pseudo_window_p
= 1;
6221 clear_glyph_matrix (w
->desired_matrix
);
6222 clear_glyph_matrix (w
->current_matrix
);
6223 try_window (FRAME_ROOT_WINDOW (f
), pos
, TRY_WINDOW_IGNORE_FONTS_CHANGE
);
6225 /* Recompute width and height of the tooltip. */
6226 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
6228 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
6232 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
6234 row
->full_width_p
= true;
6235 row_width
= row
->pixel_width
;
6236 if (row
->used
[TEXT_AREA
] && !row
->reversed_p
)
6238 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
6239 if (NILP (last
->object
))
6240 row_width
-= last
->pixel_width
;
6243 height
+= row
->height
;
6244 width
= max (width
, row_width
);
6248 /* Add the frame's internal border to the width and height the w32
6249 window should have. */
6250 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
6251 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
6253 /* Move the tooltip window where the mouse pointer is. Resize and
6256 PXW: This should use the frame's pixel coordinates. */
6257 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
6260 /* Adjust Window size to take border into account. */
6262 rect
.left
= rect
.top
= 0;
6264 rect
.bottom
= height
;
6265 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
6266 FRAME_EXTERNAL_MENU_BAR (f
));
6268 /* Position and size tooltip, and put it in the topmost group.
6269 The add-on of FRAME_COLUMN_WIDTH to the 5th argument is a
6270 peculiarity of w32 display: without it, some fonts cause the
6271 last character of the tip to be truncated or wrapped around to
6273 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
6275 rect
.right
- rect
.left
+ FRAME_COLUMN_WIDTH (f
),
6276 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
| SWP_NOOWNERZORDER
);
6278 /* Ensure tooltip is on top of other topmost windows (eg menus). */
6279 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
6281 SWP_NOMOVE
| SWP_NOSIZE
6282 | SWP_NOACTIVATE
| SWP_NOOWNERZORDER
);
6284 /* Let redisplay know that we have made the frame visible already. */
6285 SET_FRAME_VISIBLE (f
, 1);
6287 ShowWindow (FRAME_W32_WINDOW (f
), SW_SHOWNOACTIVATE
);
6290 /* Draw into the window. */
6291 w
->must_be_updated_p
= true;
6292 update_single_window (w
);
6296 /* Restore original current buffer. */
6297 set_buffer_internal_1 (old_buffer
);
6298 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
6301 /* Let the tip disappear after timeout seconds. */
6302 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
6303 intern ("x-hide-tip"));
6306 return unbind_to (count
, Qnil
);
6310 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
6311 doc
: /* Hide the current tooltip window, if there is any.
6312 Value is t if tooltip was open, nil otherwise. */)
6316 Lisp_Object deleted
, frame
, timer
;
6317 struct gcpro gcpro1
, gcpro2
;
6319 /* Return quickly if nothing to do. */
6320 if (NILP (tip_timer
) && NILP (tip_frame
))
6325 GCPRO2 (frame
, timer
);
6326 tip_frame
= tip_timer
= deleted
= Qnil
;
6328 count
= SPECPDL_INDEX ();
6329 specbind (Qinhibit_redisplay
, Qt
);
6330 specbind (Qinhibit_quit
, Qt
);
6333 call1 (Qcancel_timer
, timer
);
6337 delete_frame (frame
, Qnil
);
6342 return unbind_to (count
, deleted
);
6345 /***********************************************************************
6346 File selection dialog
6347 ***********************************************************************/
6349 #define FILE_NAME_TEXT_FIELD edt1
6350 #define FILE_NAME_COMBO_BOX cmb13
6351 #define FILE_NAME_LIST lst1
6353 /* Callback for altering the behavior of the Open File dialog.
6354 Makes the Filename text field contain "Current Directory" and be
6355 read-only when "Directories" is selected in the filter. This
6356 allows us to work around the fact that the standard Open File
6357 dialog does not support directories. */
6358 static UINT_PTR CALLBACK
6359 file_dialog_callback (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
6361 if (msg
== WM_NOTIFY
)
6363 OFNOTIFYW
* notify_w
= (OFNOTIFYW
*)lParam
;
6364 OFNOTIFYA
* notify_a
= (OFNOTIFYA
*)lParam
;
6365 int dropdown_changed
;
6367 #ifdef NTGUI_UNICODE
6368 const int use_unicode
= 1;
6369 #else /* !NTGUI_UNICODE */
6370 int use_unicode
= w32_unicode_filenames
;
6371 #endif /* NTGUI_UNICODE */
6373 /* Detect when the Filter dropdown is changed. */
6376 notify_w
->hdr
.code
== CDN_TYPECHANGE
6377 || notify_w
->hdr
.code
== CDN_INITDONE
;
6380 notify_a
->hdr
.code
== CDN_TYPECHANGE
6381 || notify_a
->hdr
.code
== CDN_INITDONE
;
6382 if (dropdown_changed
)
6384 HWND dialog
= GetParent (hwnd
);
6385 HWND edit_control
= GetDlgItem (dialog
, FILE_NAME_TEXT_FIELD
);
6386 HWND list
= GetDlgItem (dialog
, FILE_NAME_LIST
);
6389 /* At least on Windows 7, the above attempt to get the window handle
6390 to the File Name Text Field fails. The following code does the
6391 job though. Note that this code is based on my examination of the
6392 window hierarchy using Microsoft Spy++. bk */
6393 if (edit_control
== NULL
)
6395 HWND tmp
= GetDlgItem (dialog
, FILE_NAME_COMBO_BOX
);
6398 tmp
= GetWindow (tmp
, GW_CHILD
);
6400 edit_control
= GetWindow (tmp
, GW_CHILD
);
6404 /* Directories is in index 2. */
6407 dir_index
= notify_w
->lpOFN
->nFilterIndex
;
6408 hdr_code
= notify_w
->hdr
.code
;
6412 dir_index
= notify_a
->lpOFN
->nFilterIndex
;
6413 hdr_code
= notify_a
->hdr
.code
;
6418 SendMessageW (dialog
, CDM_SETCONTROLTEXT
, FILE_NAME_TEXT_FIELD
,
6419 (LPARAM
)L
"Current Directory");
6421 SendMessageA (dialog
, CDM_SETCONTROLTEXT
, FILE_NAME_TEXT_FIELD
,
6422 (LPARAM
)"Current Directory");
6423 EnableWindow (edit_control
, FALSE
);
6424 /* Note that at least on Windows 7, the above call to EnableWindow
6425 disables the window that would ordinarily have focus. If we
6426 do not set focus to some other window here, focus will land in
6427 no man's land and the user will be unable to tab through the
6428 dialog box (pressing tab will only result in a beep).
6429 Avoid that problem by setting focus to the list here. */
6430 if (hdr_code
== CDN_INITDONE
)
6435 /* Don't override default filename on init done. */
6436 if (hdr_code
== CDN_TYPECHANGE
)
6439 SendMessageW (dialog
, CDM_SETCONTROLTEXT
,
6440 FILE_NAME_TEXT_FIELD
, (LPARAM
)L
"");
6442 SendMessageA (dialog
, CDM_SETCONTROLTEXT
,
6443 FILE_NAME_TEXT_FIELD
, (LPARAM
)"");
6445 EnableWindow (edit_control
, TRUE
);
6452 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
6453 doc
: /* Read file name, prompting with PROMPT in directory DIR.
6454 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
6455 selection box, if specified. If MUSTMATCH is non-nil, the returned file
6456 or directory must exist.
6458 This function is only defined on NS, MS Windows, and X Windows with the
6459 Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
6460 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories.
6461 On Windows 7 and later, the file selection dialog "remembers" the last
6462 directory where the user selected a file, and will open that directory
6463 instead of DIR on subsequent invocations of this function with the same
6464 value of DIR as in previous invocations; this is standard Windows behavior. */)
6465 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
, Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
6467 /* Filter index: 1: All Files, 2: Directories only */
6468 static const wchar_t filter_w
[] = L
"All Files (*.*)\0*.*\0Directories\0*|*\0";
6469 static const char filter_a
[] = "All Files (*.*)\0*.*\0Directories\0*|*\0";
6471 Lisp_Object filename
= default_filename
;
6472 struct frame
*f
= SELECTED_FRAME ();
6473 BOOL file_opened
= FALSE
;
6474 Lisp_Object orig_dir
= dir
;
6475 Lisp_Object orig_prompt
= prompt
;
6477 /* If we compile with _WIN32_WINNT set to 0x0400 (for NT4
6478 compatibility) we end up with the old file dialogs. Define a big
6479 enough struct for the new dialog to trick GetOpenFileName into
6480 giving us the new dialogs on newer versions of Windows. */
6482 OPENFILENAMEW details
;
6483 #if _WIN32_WINNT < 0x500 /* < win2k */
6487 #endif /* < win2k */
6488 } new_file_details_w
;
6490 #ifdef NTGUI_UNICODE
6491 wchar_t filename_buf_w
[32*1024 + 1]; // NT kernel maximum
6492 OPENFILENAMEW
* file_details_w
= &new_file_details_w
.details
;
6493 const int use_unicode
= 1;
6494 #else /* not NTGUI_UNICODE */
6496 OPENFILENAMEA details
;
6497 #if _WIN32_WINNT < 0x500 /* < win2k */
6501 #endif /* < win2k */
6502 } new_file_details_a
;
6503 wchar_t filename_buf_w
[MAX_PATH
+ 1], dir_w
[MAX_PATH
];
6504 char filename_buf_a
[MAX_PATH
+ 1], dir_a
[MAX_PATH
];
6505 OPENFILENAMEW
* file_details_w
= &new_file_details_w
.details
;
6506 OPENFILENAMEA
* file_details_a
= &new_file_details_a
.details
;
6507 int use_unicode
= w32_unicode_filenames
;
6511 char fname_ret
[MAX_UTF8_PATH
];
6512 #endif /* NTGUI_UNICODE */
6514 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
6515 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, filename
);
6518 struct gcpro gcpro1
, gcpro2
;
6519 GCPRO2 (orig_dir
, orig_prompt
); /* There is no GCPRON, N>6. */
6521 /* Note: under NTGUI_UNICODE, we do _NOT_ use ENCODE_FILE: the
6522 system file encoding expected by the platform APIs (e.g. Cygwin's
6523 POSIX implementation) may not be the same as the encoding expected
6524 by the Windows "ANSI" APIs! */
6526 CHECK_STRING (prompt
);
6529 dir
= Fexpand_file_name (dir
, Qnil
);
6531 if (STRINGP (filename
))
6532 filename
= Ffile_name_nondirectory (filename
);
6534 filename
= empty_unibyte_string
;
6537 dir
= Fcygwin_convert_file_name_to_windows (dir
, Qt
);
6538 if (SCHARS (filename
) > 0)
6539 filename
= Fcygwin_convert_file_name_to_windows (filename
, Qnil
);
6543 CHECK_STRING (filename
);
6545 /* The code in file_dialog_callback that attempts to set the text
6546 of the file name edit window when handling the CDN_INITDONE
6547 WM_NOTIFY message does not work. Setting filename to "Current
6548 Directory" in the only_dir_p case here does work however. */
6549 if (SCHARS (filename
) == 0 && ! NILP (only_dir_p
))
6550 filename
= build_string ("Current Directory");
6552 /* Convert the values we've computed so far to system form. */
6553 #ifdef NTGUI_UNICODE
6554 to_unicode (prompt
, &prompt
);
6555 to_unicode (dir
, &dir
);
6556 to_unicode (filename
, &filename
);
6557 if (SBYTES (filename
) + 1 > sizeof (filename_buf_w
))
6558 report_file_error ("filename too long", default_filename
);
6560 memcpy (filename_buf_w
, SDATA (filename
), SBYTES (filename
) + 1);
6561 #else /* !NTGUI_UNICODE */
6562 prompt
= ENCODE_FILE (prompt
);
6563 dir
= ENCODE_FILE (dir
);
6564 filename
= ENCODE_FILE (filename
);
6566 /* We modify these in-place, so make copies for safety. */
6567 dir
= Fcopy_sequence (dir
);
6568 unixtodos_filename (SDATA (dir
));
6569 filename
= Fcopy_sequence (filename
);
6570 unixtodos_filename (SDATA (filename
));
6571 if (SBYTES (filename
) >= MAX_UTF8_PATH
)
6572 report_file_error ("filename too long", default_filename
);
6573 if (w32_unicode_filenames
)
6575 filename_to_utf16 (SSDATA (dir
), dir_w
);
6576 if (filename_to_utf16 (SSDATA (filename
), filename_buf_w
) != 0)
6578 /* filename_to_utf16 sets errno to ENOENT when the file
6579 name is too long or cannot be converted to UTF-16. */
6580 if (errno
== ENOENT
&& filename_buf_w
[MAX_PATH
- 1] != 0)
6581 report_file_error ("filename too long", default_filename
);
6583 len
= pMultiByteToWideChar (CP_UTF8
, MB_ERR_INVALID_CHARS
,
6584 SSDATA (prompt
), -1, NULL
, 0);
6587 prompt_w
= alloca (len
* sizeof (wchar_t));
6588 pMultiByteToWideChar (CP_UTF8
, MB_ERR_INVALID_CHARS
,
6589 SSDATA (prompt
), -1, prompt_w
, len
);
6593 filename_to_ansi (SSDATA (dir
), dir_a
);
6594 if (filename_to_ansi (SSDATA (filename
), filename_buf_a
) != '\0')
6596 /* filename_to_ansi sets errno to ENOENT when the file
6597 name is too long or cannot be converted to UTF-16. */
6598 if (errno
== ENOENT
&& filename_buf_a
[MAX_PATH
- 1] != 0)
6599 report_file_error ("filename too long", default_filename
);
6601 len
= pMultiByteToWideChar (CP_UTF8
, MB_ERR_INVALID_CHARS
,
6602 SSDATA (prompt
), -1, NULL
, 0);
6605 prompt_w
= alloca (len
* sizeof (wchar_t));
6606 pMultiByteToWideChar (CP_UTF8
, MB_ERR_INVALID_CHARS
,
6607 SSDATA (prompt
), -1, prompt_w
, len
);
6608 len
= pWideCharToMultiByte (CP_ACP
, 0, prompt_w
, -1, NULL
, 0, NULL
, NULL
);
6611 prompt_a
= alloca (len
);
6612 pWideCharToMultiByte (CP_ACP
, 0, prompt_w
, -1, prompt_a
, len
, NULL
, NULL
);
6614 #endif /* NTGUI_UNICODE */
6616 /* Fill in the structure for the call to GetOpenFileName below.
6617 For NTGUI_UNICODE builds (which run only on NT), we just use
6618 the actual size of the structure. For non-NTGUI_UNICODE
6619 builds, we tell the OS we're using an old version of the
6620 structure if the OS isn't new enough to support the newer
6624 memset (&new_file_details_w
, 0, sizeof (new_file_details_w
));
6625 if (w32_major_version
> 4 && w32_major_version
< 95)
6626 file_details_w
->lStructSize
= sizeof (new_file_details_w
);
6628 file_details_w
->lStructSize
= sizeof (*file_details_w
);
6629 /* Set up the inout parameter for the selected file name. */
6630 file_details_w
->lpstrFile
= filename_buf_w
;
6631 file_details_w
->nMaxFile
=
6632 sizeof (filename_buf_w
) / sizeof (*filename_buf_w
);
6633 file_details_w
->hwndOwner
= FRAME_W32_WINDOW (f
);
6634 /* Undocumented Bug in Common File Dialog:
6635 If a filter is not specified, shell links are not resolved. */
6636 file_details_w
->lpstrFilter
= filter_w
;
6637 #ifdef NTGUI_UNICODE
6638 file_details_w
->lpstrInitialDir
= (wchar_t*) SDATA (dir
);
6639 file_details_w
->lpstrTitle
= (guichar_t
*) SDATA (prompt
);
6641 file_details_w
->lpstrInitialDir
= dir_w
;
6642 file_details_w
->lpstrTitle
= prompt_w
;
6644 file_details_w
->nFilterIndex
= NILP (only_dir_p
) ? 1 : 2;
6645 file_details_w
->Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
6646 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
6647 if (!NILP (mustmatch
))
6649 /* Require that the path to the parent directory exists. */
6650 file_details_w
->Flags
|= OFN_PATHMUSTEXIST
;
6651 /* If we are looking for a file, require that it exists. */
6652 if (NILP (only_dir_p
))
6653 file_details_w
->Flags
|= OFN_FILEMUSTEXIST
;
6656 #ifndef NTGUI_UNICODE
6659 memset (&new_file_details_a
, 0, sizeof (new_file_details_a
));
6660 if (w32_major_version
> 4 && w32_major_version
< 95)
6661 file_details_a
->lStructSize
= sizeof (new_file_details_a
);
6663 file_details_a
->lStructSize
= sizeof (*file_details_a
);
6664 file_details_a
->lpstrFile
= filename_buf_a
;
6665 file_details_a
->nMaxFile
=
6666 sizeof (filename_buf_a
) / sizeof (*filename_buf_a
);
6667 file_details_a
->hwndOwner
= FRAME_W32_WINDOW (f
);
6668 file_details_a
->lpstrFilter
= filter_a
;
6669 file_details_a
->lpstrInitialDir
= dir_a
;
6670 file_details_a
->lpstrTitle
= prompt_a
;
6671 file_details_a
->nFilterIndex
= NILP (only_dir_p
) ? 1 : 2;
6672 file_details_a
->Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
6673 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
6674 if (!NILP (mustmatch
))
6676 /* Require that the path to the parent directory exists. */
6677 file_details_a
->Flags
|= OFN_PATHMUSTEXIST
;
6678 /* If we are looking for a file, require that it exists. */
6679 if (NILP (only_dir_p
))
6680 file_details_a
->Flags
|= OFN_FILEMUSTEXIST
;
6683 #endif /* !NTGUI_UNICODE */
6686 int count
= SPECPDL_INDEX ();
6687 /* Prevent redisplay. */
6688 specbind (Qinhibit_redisplay
, Qt
);
6692 file_details_w
->lpfnHook
= file_dialog_callback
;
6694 file_opened
= GetOpenFileNameW (file_details_w
);
6696 #ifndef NTGUI_UNICODE
6699 file_details_a
->lpfnHook
= file_dialog_callback
;
6701 file_opened
= GetOpenFileNameA (file_details_a
);
6703 #endif /* !NTGUI_UNICODE */
6705 unbind_to (count
, Qnil
);
6710 /* Get an Emacs string from the value Windows gave us. */
6711 #ifdef NTGUI_UNICODE
6712 filename
= from_unicode_buffer (filename_buf_w
);
6713 #else /* !NTGUI_UNICODE */
6715 filename_from_utf16 (filename_buf_w
, fname_ret
);
6717 filename_from_ansi (filename_buf_a
, fname_ret
);
6718 dostounix_filename (fname_ret
);
6719 filename
= DECODE_FILE (build_unibyte_string (fname_ret
));
6720 #endif /* NTGUI_UNICODE */
6723 filename
= Fcygwin_convert_file_name_from_windows (filename
, Qt
);
6726 /* Strip the dummy filename off the end of the string if we
6727 added it to select a directory. */
6728 if ((use_unicode
&& file_details_w
->nFilterIndex
== 2)
6729 #ifndef NTGUI_UNICODE
6730 || (!use_unicode
&& file_details_a
->nFilterIndex
== 2)
6733 filename
= Ffile_name_directory (filename
);
6735 /* User canceled the dialog without making a selection. */
6736 else if (!CommDlgExtendedError ())
6738 /* An error occurred, fallback on reading from the mini-buffer. */
6740 filename
= Fcompleting_read (
6742 intern ("read-file-name-internal"),
6753 /* Make "Cancel" equivalent to C-g. */
6754 if (NILP (filename
))
6755 Fsignal (Qquit
, Qnil
);
6757 RETURN_UNGCPRO (filename
);
6762 /* Moving files to the system recycle bin.
6763 Used by `move-file-to-trash' instead of the default moving to ~/.Trash */
6764 DEFUN ("system-move-file-to-trash", Fsystem_move_file_to_trash
,
6765 Ssystem_move_file_to_trash
, 1, 1, 0,
6766 doc
: /* Move file or directory named FILENAME to the recycle bin. */)
6767 (Lisp_Object filename
)
6769 Lisp_Object handler
;
6770 Lisp_Object encoded_file
;
6771 Lisp_Object operation
;
6773 operation
= Qdelete_file
;
6774 if (!NILP (Ffile_directory_p (filename
))
6775 && NILP (Ffile_symlink_p (filename
)))
6777 operation
= intern ("delete-directory");
6778 filename
= Fdirectory_file_name (filename
);
6781 /* Must have fully qualified file names for moving files to Recycle
6783 filename
= Fexpand_file_name (filename
, Qnil
);
6785 handler
= Ffind_file_name_handler (filename
, operation
);
6786 if (!NILP (handler
))
6787 return call2 (handler
, operation
, filename
);
6793 encoded_file
= ENCODE_FILE (filename
);
6795 path
= map_w32_filename (SDATA (encoded_file
), NULL
);
6797 /* The Unicode version of SHFileOperation is not supported on
6799 if (w32_unicode_filenames
&& os_subtype
!= OS_9X
)
6801 SHFILEOPSTRUCTW file_op_w
;
6802 /* We need one more element beyond MAX_PATH because this is
6803 a list of file names, with the last element double-null
6805 wchar_t tmp_path_w
[MAX_PATH
+ 1];
6807 memset (tmp_path_w
, 0, sizeof (tmp_path_w
));
6808 filename_to_utf16 (path
, tmp_path_w
);
6810 /* On Windows, write permission is required to delete/move files. */
6811 _wchmod (tmp_path_w
, 0666);
6813 memset (&file_op_w
, 0, sizeof (file_op_w
));
6814 file_op_w
.hwnd
= HWND_DESKTOP
;
6815 file_op_w
.wFunc
= FO_DELETE
;
6816 file_op_w
.pFrom
= tmp_path_w
;
6817 file_op_w
.fFlags
= FOF_SILENT
| FOF_NOCONFIRMATION
| FOF_ALLOWUNDO
6818 | FOF_NOERRORUI
| FOF_NO_CONNECTED_ELEMENTS
;
6819 file_op_w
.fAnyOperationsAborted
= FALSE
;
6821 result
= SHFileOperationW (&file_op_w
);
6825 SHFILEOPSTRUCTA file_op_a
;
6826 char tmp_path_a
[MAX_PATH
+ 1];
6828 memset (tmp_path_a
, 0, sizeof (tmp_path_a
));
6829 filename_to_ansi (path
, tmp_path_a
);
6831 /* If a file cannot be represented in ANSI codepage, don't
6832 let them inadvertently delete other files because some
6833 characters are interpreted as a wildcards. */
6834 if (_mbspbrk (tmp_path_a
, "?*"))
6835 result
= ERROR_FILE_NOT_FOUND
;
6838 _chmod (tmp_path_a
, 0666);
6840 memset (&file_op_a
, 0, sizeof (file_op_a
));
6841 file_op_a
.hwnd
= HWND_DESKTOP
;
6842 file_op_a
.wFunc
= FO_DELETE
;
6843 file_op_a
.pFrom
= tmp_path_a
;
6844 file_op_a
.fFlags
= FOF_SILENT
| FOF_NOCONFIRMATION
| FOF_ALLOWUNDO
6845 | FOF_NOERRORUI
| FOF_NO_CONNECTED_ELEMENTS
;
6846 file_op_a
.fAnyOperationsAborted
= FALSE
;
6848 result
= SHFileOperationA (&file_op_a
);
6852 report_file_error ("Removing old name", list1 (filename
));
6857 #endif /* WINDOWSNT */
6860 /***********************************************************************
6861 w32 specialized functions
6862 ***********************************************************************/
6864 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
,
6865 Sw32_send_sys_command
, 1, 2, 0,
6866 doc
: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND.
6867 Some useful values for COMMAND are #xf030 to maximize frame (#xf020
6868 to minimize), #xf120 to restore frame to original size, and #xf100
6869 to activate the menubar for keyboard access. #xf140 activates the
6870 screen saver if defined.
6872 If optional parameter FRAME is not specified, use selected frame. */)
6873 (Lisp_Object command
, Lisp_Object frame
)
6875 struct frame
*f
= decode_window_system_frame (frame
);
6877 CHECK_NUMBER (command
);
6879 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
6884 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
6885 doc
: /* Get Windows to perform OPERATION on DOCUMENT.
6886 This is a wrapper around the ShellExecute system function, which
6887 invokes the application registered to handle OPERATION for DOCUMENT.
6889 OPERATION is either nil or a string that names a supported operation.
6890 What operations can be used depends on the particular DOCUMENT and its
6891 handler application, but typically it is one of the following common
6894 \"open\" - open DOCUMENT, which could be a file, a directory, or an
6895 executable program (application). If it is an application,
6896 that application is launched in the current buffer's default
6897 directory. Otherwise, the application associated with
6898 DOCUMENT is launched in the buffer's default directory.
6899 \"opennew\" - like \"open\", but instruct the application to open
6900 DOCUMENT in a new window.
6901 \"openas\" - open the \"Open With\" dialog for DOCUMENT.
6902 \"print\" - print DOCUMENT, which must be a file.
6903 \"printto\" - print DOCUMENT, which must be a file, to a specified printer.
6904 The printer should be provided in PARAMETERS, see below.
6905 \"explore\" - start the Windows Explorer on DOCUMENT.
6906 \"edit\" - launch an editor and open DOCUMENT for editing; which
6907 editor is launched depends on the association for the
6909 \"find\" - initiate search starting from DOCUMENT, which must specify
6911 \"delete\" - move DOCUMENT, a file or a directory, to Recycle Bin.
6912 \"copy\" - copy DOCUMENT, which must be a file or a directory, into
6914 \"cut\" - move DOCUMENT, a file or a directory, into the clipboard.
6915 \"paste\" - paste the file whose name is in the clipboard into DOCUMENT,
6916 which must be a directory.
6918 - create a shortcut in DOCUMENT (which must be a directory)
6919 the file or directory whose name is in the clipboard.
6920 \"runas\" - run DOCUMENT, which must be an excutable file, with
6921 elevated privileges (a.k.a. \"as Administrator\").
6923 - open the property sheet dialog for DOCUMENT.
6924 nil - invoke the default OPERATION, or \"open\" if default is
6925 not defined or unavailable.
6927 DOCUMENT is typically the name of a document file or a URL, but can
6928 also be an executable program to run, or a directory to open in the
6929 Windows Explorer. If it is a file or a directory, it must be a local
6930 one; this function does not support remote file names.
6932 If DOCUMENT is an executable program, the optional third arg PARAMETERS
6933 can be a string containing command line parameters, separated by blanks,
6934 that will be passed to the program. Some values of OPERATION also require
6935 parameters (e.g., \"printto\" requires the printer address). Otherwise,
6936 PARAMETERS should be nil or unspecified. Note that double quote characters
6937 in PARAMETERS must each be enclosed in 2 additional quotes, as in \"\"\".
6939 Optional fourth argument SHOW-FLAG can be used to control how the
6940 application will be displayed when it is invoked. If SHOW-FLAG is nil
6941 or unspecified, the application is displayed as if SHOW-FLAG of 10 was
6942 specified, otherwise it is an integer between 0 and 11 representing
6946 1 - start as normal-size window
6947 3 - start in a maximized window
6948 6 - start in a minimized window
6949 10 - start as the application itself specifies; this is the default. */)
6950 (Lisp_Object operation
, Lisp_Object document
, Lisp_Object parameters
, Lisp_Object show_flag
)
6953 Lisp_Object current_dir
= BVAR (current_buffer
, directory
);;
6954 wchar_t *doc_w
= NULL
, *params_w
= NULL
, *ops_w
= NULL
;
6958 int use_unicode
= w32_unicode_filenames
;
6959 char *doc_a
= NULL
, *params_a
= NULL
, *ops_a
= NULL
;
6960 Lisp_Object absdoc
, handler
;
6962 struct gcpro gcpro1
;
6965 CHECK_STRING (document
);
6968 current_dir
= Fcygwin_convert_file_name_to_windows (current_dir
, Qt
);
6969 document
= Fcygwin_convert_file_name_to_windows (document
, Qt
);
6971 /* Encode filename, current directory and parameters. */
6972 current_dir
= GUI_ENCODE_FILE (current_dir
);
6973 document
= GUI_ENCODE_FILE (document
);
6974 doc_w
= GUI_SDATA (document
);
6975 if (STRINGP (parameters
))
6977 parameters
= GUI_ENCODE_SYSTEM (parameters
);
6978 params_w
= GUI_SDATA (parameters
);
6980 if (STRINGP (operation
))
6982 operation
= GUI_ENCODE_SYSTEM (operation
);
6983 ops_w
= GUI_SDATA (operation
);
6985 result
= (intptr_t) ShellExecuteW (NULL
, ops_w
, doc_w
, params_w
,
6986 GUI_SDATA (current_dir
),
6987 (INTEGERP (show_flag
)
6988 ? XINT (show_flag
) : SW_SHOWDEFAULT
));
6995 case SE_ERR_ACCESSDENIED
:
6996 errstr
= w32_strerror (ERROR_ACCESS_DENIED
);
6998 case SE_ERR_ASSOCINCOMPLETE
:
6999 case SE_ERR_NOASSOC
:
7000 errstr
= w32_strerror (ERROR_NO_ASSOCIATION
);
7002 case SE_ERR_DDEBUSY
:
7003 case SE_ERR_DDEFAIL
:
7004 errstr
= w32_strerror (ERROR_DDE_FAIL
);
7006 case SE_ERR_DDETIMEOUT
:
7007 errstr
= w32_strerror (ERROR_TIMEOUT
);
7009 case SE_ERR_DLLNOTFOUND
:
7010 errstr
= w32_strerror (ERROR_DLL_NOT_FOUND
);
7013 errstr
= w32_strerror (ERROR_FILE_NOT_FOUND
);
7016 errstr
= w32_strerror (ERROR_NOT_ENOUGH_MEMORY
);
7019 errstr
= w32_strerror (ERROR_PATH_NOT_FOUND
);
7022 errstr
= w32_strerror (ERROR_SHARING_VIOLATION
);
7025 errstr
= w32_strerror (0);
7031 current_dir
= ENCODE_FILE (current_dir
);
7032 /* We have a situation here. If DOCUMENT is a relative file name,
7033 but its name includes leading directories, i.e. it lives not in
7034 CURRENT_DIR, but in its subdirectory, then ShellExecute below
7035 will fail to find it. So we need to make the file name is
7036 absolute. But DOCUMENT does not have to be a file, it can be a
7037 URL, for example. So we make it absolute only if it is an
7038 existing file; if it is a file that does not exist, tough. */
7040 absdoc
= Fexpand_file_name (document
, Qnil
);
7041 /* Don't call file handlers for file-exists-p, since they might
7042 attempt to access the file, which could fail or produce undesired
7043 consequences, see bug#16558 for an example. */
7044 handler
= Ffind_file_name_handler (absdoc
, Qfile_exists_p
);
7047 Lisp_Object absdoc_encoded
= ENCODE_FILE (absdoc
);
7049 if (faccessat (AT_FDCWD
, SSDATA (absdoc_encoded
), F_OK
, AT_EACCESS
) == 0)
7051 /* ShellExecute fails if DOCUMENT is a UNC with forward
7052 slashes (expand-file-name above converts all backslashes
7053 to forward slashes). Now that we know DOCUMENT is a
7054 file, we can mirror all forward slashes into backslashes. */
7055 unixtodos_filename (SSDATA (absdoc_encoded
));
7056 document
= absdoc_encoded
;
7059 document
= ENCODE_FILE (document
);
7062 document
= ENCODE_FILE (document
);
7066 wchar_t document_w
[MAX_PATH
], current_dir_w
[MAX_PATH
];
7067 SHELLEXECUTEINFOW shexinfo_w
;
7069 /* Encode filename, current directory and parameters, and
7070 convert operation to UTF-16. */
7071 filename_to_utf16 (SSDATA (current_dir
), current_dir_w
);
7072 filename_to_utf16 (SSDATA (document
), document_w
);
7074 if (STRINGP (parameters
))
7078 parameters
= ENCODE_SYSTEM (parameters
);
7079 len
= pMultiByteToWideChar (CP_ACP
, MB_ERR_INVALID_CHARS
,
7080 SSDATA (parameters
), -1, NULL
, 0);
7083 params_w
= alloca (len
* sizeof (wchar_t));
7084 pMultiByteToWideChar (CP_ACP
, MB_ERR_INVALID_CHARS
,
7085 SSDATA (parameters
), -1, params_w
, len
);
7087 if (STRINGP (operation
))
7089 /* Assume OPERATION is pure ASCII. */
7090 const char *s
= SSDATA (operation
);
7092 int len
= SBYTES (operation
) + 1;
7096 d
= ops_w
= alloca (len
* sizeof (wchar_t));
7097 while (d
< ops_w
+ len
- 1)
7102 /* Using ShellExecuteEx and setting the SEE_MASK_INVOKEIDLIST
7103 flag succeeds with more OPERATIONs (a.k.a. "verbs"), as it is
7104 able to invoke verbs from shortcut menu extensions, not just
7105 static verbs listed in the Registry. */
7106 memset (&shexinfo_w
, 0, sizeof (shexinfo_w
));
7107 shexinfo_w
.cbSize
= sizeof (shexinfo_w
);
7109 SEE_MASK_INVOKEIDLIST
| SEE_MASK_FLAG_DDEWAIT
| SEE_MASK_FLAG_NO_UI
;
7110 shexinfo_w
.hwnd
= NULL
;
7111 shexinfo_w
.lpVerb
= ops_w
;
7112 shexinfo_w
.lpFile
= doc_w
;
7113 shexinfo_w
.lpParameters
= params_w
;
7114 shexinfo_w
.lpDirectory
= current_dir_w
;
7116 (INTEGERP (show_flag
) ? XINT (show_flag
) : SW_SHOWDEFAULT
);
7117 success
= ShellExecuteExW (&shexinfo_w
);
7121 char document_a
[MAX_PATH
], current_dir_a
[MAX_PATH
];
7122 SHELLEXECUTEINFOA shexinfo_a
;
7124 filename_to_ansi (SSDATA (current_dir
), current_dir_a
);
7125 filename_to_ansi (SSDATA (document
), document_a
);
7127 if (STRINGP (parameters
))
7129 parameters
= ENCODE_SYSTEM (parameters
);
7130 params_a
= SSDATA (parameters
);
7132 if (STRINGP (operation
))
7134 /* Assume OPERATION is pure ASCII. */
7135 ops_a
= SSDATA (operation
);
7137 memset (&shexinfo_a
, 0, sizeof (shexinfo_a
));
7138 shexinfo_a
.cbSize
= sizeof (shexinfo_a
);
7140 SEE_MASK_INVOKEIDLIST
| SEE_MASK_FLAG_DDEWAIT
| SEE_MASK_FLAG_NO_UI
;
7141 shexinfo_a
.hwnd
= NULL
;
7142 shexinfo_a
.lpVerb
= ops_a
;
7143 shexinfo_a
.lpFile
= doc_a
;
7144 shexinfo_a
.lpParameters
= params_a
;
7145 shexinfo_a
.lpDirectory
= current_dir_a
;
7147 (INTEGERP (show_flag
) ? XINT (show_flag
) : SW_SHOWDEFAULT
);
7148 success
= ShellExecuteExA (&shexinfo_a
);
7154 errstr
= w32_strerror (0);
7156 #endif /* !CYGWIN */
7158 /* The error string might be encoded in the locale's encoding. */
7159 if (!NILP (Vlocale_coding_system
))
7161 Lisp_Object decoded
=
7162 code_convert_string_norecord (build_unibyte_string (errstr
),
7163 Vlocale_coding_system
, 0);
7164 errstr
= SSDATA (decoded
);
7166 error ("ShellExecute failed: %s", errstr
);
7169 /* Lookup virtual keycode from string representing the name of a
7170 non-ascii keystroke into the corresponding virtual key, using
7171 lispy_function_keys. */
7173 lookup_vk_code (char *key
)
7177 for (i
= 0; i
< 256; i
++)
7178 if (lispy_function_keys
[i
]
7179 && strcmp (lispy_function_keys
[i
], key
) == 0)
7185 /* Convert a one-element vector style key sequence to a hot key
7188 w32_parse_hot_key (Lisp_Object key
)
7190 /* Copied from Fdefine_key and store_in_keymap. */
7191 register Lisp_Object c
;
7195 struct gcpro gcpro1
;
7199 if (ASIZE (key
) != 1)
7206 if (CONSP (c
) && lucid_event_type_list_p (c
))
7207 c
= Fevent_convert_list (c
);
7211 if (! INTEGERP (c
) && ! SYMBOLP (c
))
7212 error ("Key definition is invalid");
7214 /* Work out the base key and the modifiers. */
7217 c
= parse_modifiers (c
);
7218 lisp_modifiers
= XINT (Fcar (Fcdr (c
)));
7222 vk_code
= lookup_vk_code (SDATA (SYMBOL_NAME (c
)));
7224 else if (INTEGERP (c
))
7226 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
7227 /* Many ascii characters are their own virtual key code. */
7228 vk_code
= XINT (c
) & CHARACTERBITS
;
7231 if (vk_code
< 0 || vk_code
> 255)
7234 if ((lisp_modifiers
& meta_modifier
) != 0
7235 && !NILP (Vw32_alt_is_meta
))
7236 lisp_modifiers
|= alt_modifier
;
7238 /* Supply defs missing from mingw32. */
7240 #define MOD_ALT 0x0001
7241 #define MOD_CONTROL 0x0002
7242 #define MOD_SHIFT 0x0004
7243 #define MOD_WIN 0x0008
7246 /* Convert lisp modifiers to Windows hot-key form. */
7247 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
7248 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
7249 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
7250 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
7252 return HOTKEY (vk_code
, w32_modifiers
);
7255 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
,
7256 Sw32_register_hot_key
, 1, 1, 0,
7257 doc
: /* Register KEY as a hot-key combination.
7258 Certain key combinations like Alt-Tab are reserved for system use on
7259 Windows, and therefore are normally intercepted by the system. However,
7260 most of these key combinations can be received by registering them as
7261 hot-keys, overriding their special meaning.
7263 KEY must be a one element key definition in vector form that would be
7264 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta
7265 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper
7266 is always interpreted as the Windows modifier keys.
7268 The return value is the hotkey-id if registered, otherwise nil. */)
7271 key
= w32_parse_hot_key (key
);
7273 if (!NILP (key
) && NILP (Fmemq (key
, w32_grabbed_keys
)))
7275 /* Reuse an empty slot if possible. */
7276 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
7278 /* Safe to add new key to list, even if we have focus. */
7280 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
7282 XSETCAR (item
, key
);
7284 /* Notify input thread about new hot-key definition, so that it
7285 takes effect without needing to switch focus. */
7286 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
7287 (WPARAM
) XINT (key
), 0);
7293 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
,
7294 Sw32_unregister_hot_key
, 1, 1, 0,
7295 doc
: /* Unregister KEY as a hot-key combination. */)
7300 if (!INTEGERP (key
))
7301 key
= w32_parse_hot_key (key
);
7303 item
= Fmemq (key
, w32_grabbed_keys
);
7309 eassert (CONSP (item
));
7310 /* Pass the tail of the list as a pointer to a Lisp_Cons cell,
7311 so that it works in a --with-wide-int build as well. */
7312 lparam
= (LPARAM
) XUNTAG (item
, Lisp_Cons
);
7314 /* Notify input thread about hot-key definition being removed, so
7315 that it takes effect without needing focus switch. */
7316 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
7317 (WPARAM
) XINT (XCAR (item
)), lparam
))
7320 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
7327 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
,
7328 Sw32_registered_hot_keys
, 0, 0, 0,
7329 doc
: /* Return list of registered hot-key IDs. */)
7332 return Fdelq (Qnil
, Fcopy_sequence (w32_grabbed_keys
));
7335 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
,
7336 Sw32_reconstruct_hot_key
, 1, 1, 0,
7337 doc
: /* Convert hot-key ID to a lisp key combination.
7338 usage: (w32-reconstruct-hot-key ID) */)
7339 (Lisp_Object hotkeyid
)
7341 int vk_code
, w32_modifiers
;
7344 CHECK_NUMBER (hotkeyid
);
7346 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
7347 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
7349 if (vk_code
< 256 && lispy_function_keys
[vk_code
])
7350 key
= intern (lispy_function_keys
[vk_code
]);
7352 key
= make_number (vk_code
);
7354 key
= Fcons (key
, Qnil
);
7355 if (w32_modifiers
& MOD_SHIFT
)
7356 key
= Fcons (Qshift
, key
);
7357 if (w32_modifiers
& MOD_CONTROL
)
7358 key
= Fcons (Qctrl
, key
);
7359 if (w32_modifiers
& MOD_ALT
)
7360 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
7361 if (w32_modifiers
& MOD_WIN
)
7362 key
= Fcons (Qhyper
, key
);
7367 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
,
7368 Sw32_toggle_lock_key
, 1, 2, 0,
7369 doc
: /* Toggle the state of the lock key KEY.
7370 KEY can be `capslock', `kp-numlock', or `scroll'.
7371 If the optional parameter NEW-STATE is a number, then the state of KEY
7372 is set to off if the low bit of NEW-STATE is zero, otherwise on.
7373 If NEW-STATE is omitted or nil, the function toggles the state,
7375 Value is the new state of the key, or nil if the function failed
7376 to change the state. */)
7377 (Lisp_Object key
, Lisp_Object new_state
)
7382 if (EQ (key
, intern ("capslock")))
7383 vk_code
= VK_CAPITAL
;
7384 else if (EQ (key
, intern ("kp-numlock")))
7385 vk_code
= VK_NUMLOCK
;
7386 else if (EQ (key
, intern ("scroll")))
7387 vk_code
= VK_SCROLL
;
7391 if (!dwWindowsThreadId
)
7392 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
7394 if (NILP (new_state
))
7397 lparam
= (XUINT (new_state
)) & 1;
7398 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
7399 (WPARAM
) vk_code
, lparam
))
7402 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
7403 return make_number (msg
.wParam
);
7408 DEFUN ("w32-window-exists-p", Fw32_window_exists_p
, Sw32_window_exists_p
,
7410 doc
: /* Return non-nil if a window exists with the specified CLASS and NAME.
7412 This is a direct interface to the Windows API FindWindow function. */)
7413 (Lisp_Object
class, Lisp_Object name
)
7418 CHECK_STRING (class);
7420 CHECK_STRING (name
);
7422 hnd
= FindWindow (STRINGP (class) ? ((LPCTSTR
) SDATA (class)) : NULL
,
7423 STRINGP (name
) ? ((LPCTSTR
) SDATA (name
)) : NULL
);
7429 DEFUN ("w32-frame-menu-bar-size", Fw32_frame_menu_bar_size
, Sw32_frame_menu_bar_size
, 0, 1, 0,
7430 doc
: /* Return sizes of menu bar on frame FRAME.
7431 The return value is a list of four elements: The current width and
7432 height of FRAME's menu bar in pixels, the height of one menu bar line in
7433 a wrapped menu bar in pixels, and the height of a single line menu bar
7436 If FRAME is omitted or nil, the selected frame is used. */)
7439 struct frame
*f
= decode_any_frame (frame
);
7440 MENUBARINFO menu_bar
;
7441 int width
, height
, single_height
, wrapped_height
;
7445 single_height
= GetSystemMetrics (SM_CYMENU
);
7446 wrapped_height
= GetSystemMetrics (SM_CYMENUSIZE
);
7447 menu_bar
.cbSize
= sizeof (menu_bar
);
7448 menu_bar
.rcBar
.right
= menu_bar
.rcBar
.left
= 0;
7449 menu_bar
.rcBar
.top
= menu_bar
.rcBar
.bottom
= 0;
7450 GetMenuBarInfo (FRAME_W32_WINDOW (f
), 0xFFFFFFFD, 0, &menu_bar
);
7451 width
= menu_bar
.rcBar
.right
- menu_bar
.rcBar
.left
;
7452 height
= menu_bar
.rcBar
.bottom
- menu_bar
.rcBar
.top
;
7456 return list4 (make_number (width
), make_number (height
),
7457 make_number (wrapped_height
), make_number (single_height
));
7460 DEFUN ("w32-frame-rect", Fw32_frame_rect
, Sw32_frame_rect
, 0, 2, 0,
7461 doc
: /* Return boundary rectangle of FRAME in screen coordinates.
7462 FRAME must be a live frame and defaults to the selected one.
7464 The boundary rectangle is a list of four elements, specifying the left,
7465 top, right and bottom screen coordinates of FRAME including menu and
7466 title bar and decorations. Optional argument CLIENT non-nil means to
7467 return the boundaries of the client rectangle which excludes menu and
7468 title bar and decorations. */)
7469 (Lisp_Object frame
, Lisp_Object client
)
7471 struct frame
*f
= decode_live_frame (frame
);
7477 GetClientRect (FRAME_W32_WINDOW (f
), &rect
);
7479 GetWindowRect (FRAME_W32_WINDOW (f
), &rect
);
7483 return list4 (make_number (rect
.left
), make_number (rect
.top
),
7484 make_number (rect
.right
), make_number (rect
.bottom
));
7487 DEFUN ("x-frame-geometry", Fx_frame_geometry
, Sx_frame_geometry
, 0, 1, 0,
7488 doc
: /* Return geometric attributes of frame FRAME.
7489 FRAME must be a live frame and defaults to the selected one.
7491 The return value is an association list containing the following
7492 elements (all size values are in pixels).
7494 - `frame-outer-size' is a cons of the outer width and height of FRAME.
7495 The outer size includes the title bar and the external borders as well
7496 as any menu and/or tool bar of frame.
7498 - `border' is a cons of the horizontal and vertical width of FRAME's
7501 - `title-bar-height' is the height of the title bar of FRAME.
7503 - `menu-bar-external' if `t' means the menu bar is by default external
7504 (not included in the inner size of FRAME).
7506 - `menu-bar-size' is a cons of the width and height of the menu bar of
7509 - `tool-bar-external' if `t' means the tool bar is by default external
7510 (not included in the inner size of FRAME).
7512 - `tool-bar-side' tells tells on which side the tool bar on FRAME is by
7513 default and can be one of `left', `top', `right' or `bottom'.
7515 - `tool-bar-size' is a cons of the width and height of the tool bar of
7518 - `frame-inner-size' is a cons of the inner width and height of FRAME.
7519 This excludes FRAME's title bar and external border as well as any
7520 external menu and/or tool bar. */)
7523 struct frame
*f
= decode_live_frame (frame
);
7524 Lisp_Object geometry
= Qnil
;
7525 RECT frame_outer_edges
, frame_inner_edges
;
7526 MENUBARINFO menu_bar
;
7527 int border_width
, border_height
, title_height
;
7528 int single_bar_height
, wrapped_bar_height
, menu_bar_height
;
7529 Lisp_Object fullscreen
= Fframe_parameter (frame
, Qfullscreen
);
7533 /* Outer frame rectangle, including outer borders and title bar. */
7534 GetWindowRect (FRAME_W32_WINDOW (f
), &frame_outer_edges
);
7535 /* Inner frame rectangle, excluding borders and title bar. */
7536 GetClientRect (FRAME_W32_WINDOW (f
), &frame_inner_edges
);
7538 border_width
= GetSystemMetrics (SM_CXFRAME
);
7539 border_height
= GetSystemMetrics (SM_CYFRAME
);
7541 title_height
= GetSystemMetrics (SM_CYCAPTION
);
7543 menu_bar
.cbSize
= sizeof (menu_bar
);
7544 menu_bar
.rcBar
.right
= menu_bar
.rcBar
.left
= 0;
7545 menu_bar
.rcBar
.top
= menu_bar
.rcBar
.bottom
= 0;
7546 GetMenuBarInfo (FRAME_W32_WINDOW (f
), 0xFFFFFFFD, 0, &menu_bar
);
7547 single_bar_height
= GetSystemMetrics (SM_CYMENU
);
7548 wrapped_bar_height
= GetSystemMetrics (SM_CYMENUSIZE
);
7551 menu_bar_height
= menu_bar
.rcBar
.bottom
- menu_bar
.rcBar
.top
;
7552 /* Fix menu bar height reported by GetMenuBarInfo. */
7553 if (menu_bar_height
> single_bar_height
)
7554 /* A wrapped menu bar. */
7555 menu_bar_height
+= single_bar_height
- wrapped_bar_height
;
7556 else if (menu_bar_height
> 0)
7557 /* A single line menu bar. */
7558 menu_bar_height
= single_bar_height
;
7561 listn (CONSTYPE_PURE
, 10,
7562 Fcons (Qframe_position
,
7563 Fcons (make_number (frame_outer_edges
.left
),
7564 make_number (frame_outer_edges
.top
))),
7565 Fcons (Qframe_outer_size
,
7567 (frame_outer_edges
.right
- frame_outer_edges
.left
),
7569 (frame_outer_edges
.bottom
- frame_outer_edges
.top
))),
7570 Fcons (Qexternal_border_size
,
7571 ((EQ (fullscreen
, Qfullboth
) || EQ (fullscreen
, Qfullscreen
))
7572 ? Fcons (make_number (0), make_number (0))
7573 : Fcons (make_number (border_width
),
7574 make_number (border_height
)))),
7575 Fcons (Qtitle_height
,
7576 ((EQ (fullscreen
, Qfullboth
) || EQ (fullscreen
, Qfullscreen
))
7578 : make_number (title_height
))),
7579 Fcons (Qmenu_bar_external
, Qt
),
7580 Fcons (Qmenu_bar_size
,
7582 (menu_bar
.rcBar
.right
- menu_bar
.rcBar
.left
),
7583 make_number (menu_bar_height
))),
7584 Fcons (Qtool_bar_external
, Qnil
),
7585 Fcons (Qtool_bar_position
, Qtop
),
7586 Fcons (Qtool_bar_size
,
7587 Fcons (make_number (FRAME_TOOL_BAR_LINES (f
)
7588 ? (FRAME_PIXEL_WIDTH (f
)
7589 - 2 * FRAME_INTERNAL_BORDER_WIDTH (f
))
7591 make_number (FRAME_TOOL_BAR_HEIGHT (f
)))),
7592 Fcons (Qframe_inner_size
,
7594 (frame_inner_edges
.right
- frame_inner_edges
.left
),
7596 (frame_inner_edges
.bottom
- frame_inner_edges
.top
))));
7599 DEFUN ("w32-battery-status", Fw32_battery_status
, Sw32_battery_status
, 0, 0, 0,
7600 doc
: /* Get power status information from Windows system.
7602 The following %-sequences are provided:
7603 %L AC line status (verbose)
7604 %B Battery status (verbose)
7605 %b Battery status, empty means high, `-' means low,
7606 `!' means critical, and `+' means charging
7607 %p Battery load percentage
7608 %s Remaining time (to charge or discharge) in seconds
7609 %m Remaining time (to charge or discharge) in minutes
7610 %h Remaining time (to charge or discharge) in hours
7611 %t Remaining time (to charge or discharge) in the form `h:min' */)
7614 Lisp_Object status
= Qnil
;
7616 SYSTEM_POWER_STATUS system_status
;
7617 if (GetSystemPowerStatus (&system_status
))
7619 Lisp_Object line_status
, battery_status
, battery_status_symbol
;
7620 Lisp_Object load_percentage
, seconds
, minutes
, hours
, remain
;
7622 long seconds_left
= (long) system_status
.BatteryLifeTime
;
7624 if (system_status
.ACLineStatus
== 0)
7625 line_status
= build_string ("off-line");
7626 else if (system_status
.ACLineStatus
== 1)
7627 line_status
= build_string ("on-line");
7629 line_status
= build_string ("N/A");
7631 if (system_status
.BatteryFlag
& 128)
7633 battery_status
= build_string ("N/A");
7634 battery_status_symbol
= empty_unibyte_string
;
7636 else if (system_status
.BatteryFlag
& 8)
7638 battery_status
= build_string ("charging");
7639 battery_status_symbol
= build_string ("+");
7640 if (system_status
.BatteryFullLifeTime
!= -1L)
7641 seconds_left
= system_status
.BatteryFullLifeTime
- seconds_left
;
7643 else if (system_status
.BatteryFlag
& 4)
7645 battery_status
= build_string ("critical");
7646 battery_status_symbol
= build_string ("!");
7648 else if (system_status
.BatteryFlag
& 2)
7650 battery_status
= build_string ("low");
7651 battery_status_symbol
= build_string ("-");
7653 else if (system_status
.BatteryFlag
& 1)
7655 battery_status
= build_string ("high");
7656 battery_status_symbol
= empty_unibyte_string
;
7660 battery_status
= build_string ("medium");
7661 battery_status_symbol
= empty_unibyte_string
;
7664 if (system_status
.BatteryLifePercent
> 100)
7665 load_percentage
= build_string ("N/A");
7669 snprintf (buffer
, 16, "%d", system_status
.BatteryLifePercent
);
7670 load_percentage
= build_string (buffer
);
7673 if (seconds_left
< 0)
7674 seconds
= minutes
= hours
= remain
= build_string ("N/A");
7680 snprintf (buffer
, 16, "%ld", seconds_left
);
7681 seconds
= build_string (buffer
);
7683 m
= seconds_left
/ 60;
7684 snprintf (buffer
, 16, "%ld", m
);
7685 minutes
= build_string (buffer
);
7687 h
= seconds_left
/ 3600.0;
7688 snprintf (buffer
, 16, "%3.1f", h
);
7689 hours
= build_string (buffer
);
7691 snprintf (buffer
, 16, "%ld:%02ld", m
/ 60, m
% 60);
7692 remain
= build_string (buffer
);
7695 status
= listn (CONSTYPE_HEAP
, 8,
7696 Fcons (make_number ('L'), line_status
),
7697 Fcons (make_number ('B'), battery_status
),
7698 Fcons (make_number ('b'), battery_status_symbol
),
7699 Fcons (make_number ('p'), load_percentage
),
7700 Fcons (make_number ('s'), seconds
),
7701 Fcons (make_number ('m'), minutes
),
7702 Fcons (make_number ('h'), hours
),
7703 Fcons (make_number ('t'), remain
));
7710 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
7711 doc
: /* Return storage information about the file system FILENAME is on.
7712 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
7713 storage of the file system, FREE is the free storage, and AVAIL is the
7714 storage available to a non-superuser. All 3 numbers are in bytes.
7715 If the underlying system call fails, value is nil. */)
7716 (Lisp_Object filename
)
7718 Lisp_Object encoded
, value
;
7720 CHECK_STRING (filename
);
7721 filename
= Fexpand_file_name (filename
, Qnil
);
7722 encoded
= ENCODE_FILE (filename
);
7726 /* Determining the required information on Windows turns out, sadly,
7727 to be more involved than one would hope. The original Windows API
7728 call for this will return bogus information on some systems, but we
7729 must dynamically probe for the replacement api, since that was
7730 added rather late on. */
7732 HMODULE hKernel
= GetModuleHandle ("kernel32");
7733 BOOL (WINAPI
*pfn_GetDiskFreeSpaceExW
)
7734 (wchar_t *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
7735 = GetProcAddress (hKernel
, "GetDiskFreeSpaceExW");
7736 BOOL (WINAPI
*pfn_GetDiskFreeSpaceExA
)
7737 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
7738 = GetProcAddress (hKernel
, "GetDiskFreeSpaceExA");
7739 bool have_pfn_GetDiskFreeSpaceEx
=
7740 ((w32_unicode_filenames
&& pfn_GetDiskFreeSpaceExW
)
7741 || (!w32_unicode_filenames
&& pfn_GetDiskFreeSpaceExA
));
7743 /* On Windows, we may need to specify the root directory of the
7744 volume holding FILENAME. */
7745 char rootname
[MAX_UTF8_PATH
];
7746 wchar_t rootname_w
[MAX_PATH
];
7747 char rootname_a
[MAX_PATH
];
7748 char *name
= SDATA (encoded
);
7751 /* find the root name of the volume if given */
7752 if (isalpha (name
[0]) && name
[1] == ':')
7754 rootname
[0] = name
[0];
7755 rootname
[1] = name
[1];
7759 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
7761 char *str
= rootname
;
7765 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
7775 if (w32_unicode_filenames
)
7776 filename_to_utf16 (rootname
, rootname_w
);
7778 filename_to_ansi (rootname
, rootname_a
);
7780 if (have_pfn_GetDiskFreeSpaceEx
)
7782 /* Unsigned large integers cannot be cast to double, so
7783 use signed ones instead. */
7784 LARGE_INTEGER availbytes
;
7785 LARGE_INTEGER freebytes
;
7786 LARGE_INTEGER totalbytes
;
7788 if (w32_unicode_filenames
)
7789 result
= pfn_GetDiskFreeSpaceExW (rootname_w
,
7790 (ULARGE_INTEGER
*)&availbytes
,
7791 (ULARGE_INTEGER
*)&totalbytes
,
7792 (ULARGE_INTEGER
*)&freebytes
);
7794 result
= pfn_GetDiskFreeSpaceExA (rootname_a
,
7795 (ULARGE_INTEGER
*)&availbytes
,
7796 (ULARGE_INTEGER
*)&totalbytes
,
7797 (ULARGE_INTEGER
*)&freebytes
);
7799 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
7800 make_float ((double) freebytes
.QuadPart
),
7801 make_float ((double) availbytes
.QuadPart
));
7805 DWORD sectors_per_cluster
;
7806 DWORD bytes_per_sector
;
7807 DWORD free_clusters
;
7808 DWORD total_clusters
;
7810 if (w32_unicode_filenames
)
7811 result
= GetDiskFreeSpaceW (rootname_w
,
7812 §ors_per_cluster
,
7817 result
= GetDiskFreeSpaceA (rootname_a
,
7818 §ors_per_cluster
,
7823 value
= list3 (make_float ((double) total_clusters
7824 * sectors_per_cluster
* bytes_per_sector
),
7825 make_float ((double) free_clusters
7826 * sectors_per_cluster
* bytes_per_sector
),
7827 make_float ((double) free_clusters
7828 * sectors_per_cluster
* bytes_per_sector
));
7834 #endif /* WINDOWSNT */
7838 DEFUN ("default-printer-name", Fdefault_printer_name
, Sdefault_printer_name
,
7839 0, 0, 0, doc
: /* Return the name of Windows default printer device. */)
7842 static char pname_buf
[256];
7845 PRINTER_INFO_2W
*ppi2w
= NULL
;
7846 PRINTER_INFO_2A
*ppi2a
= NULL
;
7847 DWORD dwNeeded
= 0, dwReturned
= 0;
7848 char server_name
[MAX_UTF8_PATH
], share_name
[MAX_UTF8_PATH
];
7849 char port_name
[MAX_UTF8_PATH
];
7851 /* Retrieve the default string from Win.ini (the registry).
7852 * String will be in form "printername,drivername,portname".
7853 * This is the most portable way to get the default printer. */
7854 if (GetProfileString ("windows", "device", ",,", pname_buf
, sizeof (pname_buf
)) <= 0)
7856 /* printername precedes first "," character */
7857 strtok (pname_buf
, ",");
7858 /* We want to know more than the printer name */
7859 if (!OpenPrinter (pname_buf
, &hPrn
, NULL
))
7861 /* GetPrinterW is not supported by unicows.dll. */
7862 if (w32_unicode_filenames
&& os_subtype
!= OS_9X
)
7863 GetPrinterW (hPrn
, 2, NULL
, 0, &dwNeeded
);
7865 GetPrinterA (hPrn
, 2, NULL
, 0, &dwNeeded
);
7868 ClosePrinter (hPrn
);
7871 /* Call GetPrinter again with big enough memory block. */
7872 if (w32_unicode_filenames
&& os_subtype
!= OS_9X
)
7874 /* Allocate memory for the PRINTER_INFO_2 struct. */
7875 ppi2w
= xmalloc (dwNeeded
);
7876 err
= GetPrinterW (hPrn
, 2, (LPBYTE
)ppi2w
, dwNeeded
, &dwReturned
);
7877 ClosePrinter (hPrn
);
7884 if ((ppi2w
->Attributes
& PRINTER_ATTRIBUTE_SHARED
)
7885 && ppi2w
->pServerName
)
7887 filename_from_utf16 (ppi2w
->pServerName
, server_name
);
7888 filename_from_utf16 (ppi2w
->pShareName
, share_name
);
7892 server_name
[0] = '\0';
7893 filename_from_utf16 (ppi2w
->pPortName
, port_name
);
7898 ppi2a
= xmalloc (dwNeeded
);
7899 err
= GetPrinterA (hPrn
, 2, (LPBYTE
)ppi2a
, dwNeeded
, &dwReturned
);
7900 ClosePrinter (hPrn
);
7907 if ((ppi2a
->Attributes
& PRINTER_ATTRIBUTE_SHARED
)
7908 && ppi2a
->pServerName
)
7910 filename_from_ansi (ppi2a
->pServerName
, server_name
);
7911 filename_from_ansi (ppi2a
->pShareName
, share_name
);
7915 server_name
[0] = '\0';
7916 filename_from_ansi (ppi2a
->pPortName
, port_name
);
7922 /* a remote printer */
7923 if (server_name
[0] == '\\')
7924 snprintf (pname_buf
, sizeof (pname_buf
), "%s\\%s", server_name
,
7927 snprintf (pname_buf
, sizeof (pname_buf
), "\\\\%s\\%s", server_name
,
7929 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
7933 /* a local printer */
7934 strncpy (pname_buf
, port_name
, sizeof (pname_buf
));
7935 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
7936 /* `pPortName' can include several ports, delimited by ','.
7937 * we only use the first one. */
7938 strtok (pname_buf
, ",");
7941 return DECODE_FILE (build_unibyte_string (pname_buf
));
7943 #endif /* WINDOWSNT */
7946 /* Equivalent of strerror for W32 error codes. */
7948 w32_strerror (int error_no
)
7950 static char buf
[500];
7954 error_no
= GetLastError ();
7956 ret
= FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
|
7957 FORMAT_MESSAGE_IGNORE_INSERTS
,
7960 0, /* choose most suitable language */
7961 buf
, sizeof (buf
), NULL
);
7963 while (ret
> 0 && (buf
[ret
- 1] == '\n' ||
7964 buf
[ret
- 1] == '\r' ))
7968 sprintf (buf
, "w32 error %u", error_no
);
7973 /* For convenience when debugging. (You cannot call GetLastError
7974 directly from GDB: it will crash, because it uses the __stdcall
7975 calling convention, not the _cdecl convention assumed by GDB.) */
7977 w32_last_error (void)
7979 return GetLastError ();
7982 /* Cache information describing the NT system for later use. */
7984 cache_system_info (void)
7997 /* Cache the module handle of Emacs itself. */
7998 hinst
= GetModuleHandle (NULL
);
8000 /* Cache the version of the operating system. */
8001 version
.data
= GetVersion ();
8002 w32_major_version
= version
.info
.major
;
8003 w32_minor_version
= version
.info
.minor
;
8005 if (version
.info
.platform
& 0x8000)
8010 /* Cache page size, allocation unit, processor type, etc. */
8011 GetSystemInfo (&sysinfo_cache
);
8012 syspage_mask
= (DWORD_PTR
)sysinfo_cache
.dwPageSize
- 1;
8014 /* Cache os info. */
8015 osinfo_cache
.dwOSVersionInfoSize
= sizeof (OSVERSIONINFO
);
8016 GetVersionEx (&osinfo_cache
);
8018 w32_build_number
= osinfo_cache
.dwBuildNumber
;
8019 if (os_subtype
== OS_9X
)
8020 w32_build_number
&= 0xffff;
8022 w32_num_mouse_buttons
= GetSystemMetrics (SM_CMOUSEBUTTONS
);
8027 _DebPrint (const char *fmt
, ...)
8032 va_start (args
, fmt
);
8033 vsprintf (buf
, fmt
, args
);
8036 fprintf (stderr
, "%s", buf
);
8038 OutputDebugString (buf
);
8043 w32_console_toggle_lock_key (int vk_code
, Lisp_Object new_state
)
8045 int cur_state
= (GetKeyState (vk_code
) & 1);
8047 if (NILP (new_state
)
8048 || (NUMBERP (new_state
)
8049 && ((XUINT (new_state
)) & 1) != cur_state
))
8052 faked_key
= vk_code
;
8053 #endif /* WINDOWSNT */
8055 keybd_event ((BYTE
) vk_code
,
8056 (BYTE
) MapVirtualKey (vk_code
, 0),
8057 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
8058 keybd_event ((BYTE
) vk_code
,
8059 (BYTE
) MapVirtualKey (vk_code
, 0),
8060 KEYEVENTF_EXTENDEDKEY
| 0, 0);
8061 keybd_event ((BYTE
) vk_code
,
8062 (BYTE
) MapVirtualKey (vk_code
, 0),
8063 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
8064 cur_state
= !cur_state
;
8070 /* Translate console modifiers to emacs modifiers.
8071 German keyboard support (Kai Morgan Zeise 2/18/95). */
8073 w32_kbd_mods_to_emacs (DWORD mods
, WORD key
)
8077 /* If we recognize right-alt and left-ctrl as AltGr, and it has been
8078 pressed, first remove those modifiers. */
8079 if (!NILP (Vw32_recognize_altgr
)
8080 && (mods
& (RIGHT_ALT_PRESSED
| LEFT_CTRL_PRESSED
))
8081 == (RIGHT_ALT_PRESSED
| LEFT_CTRL_PRESSED
))
8082 mods
&= ~ (RIGHT_ALT_PRESSED
| LEFT_CTRL_PRESSED
);
8084 if (mods
& (RIGHT_ALT_PRESSED
| LEFT_ALT_PRESSED
))
8085 retval
= ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
);
8087 if (mods
& (RIGHT_CTRL_PRESSED
| LEFT_CTRL_PRESSED
))
8089 retval
|= ctrl_modifier
;
8090 if ((mods
& (RIGHT_CTRL_PRESSED
| LEFT_CTRL_PRESSED
))
8091 == (RIGHT_CTRL_PRESSED
| LEFT_CTRL_PRESSED
))
8092 retval
|= meta_modifier
;
8095 if (mods
& LEFT_WIN_PRESSED
)
8096 retval
|= w32_key_to_modifier (VK_LWIN
);
8097 if (mods
& RIGHT_WIN_PRESSED
)
8098 retval
|= w32_key_to_modifier (VK_RWIN
);
8099 if (mods
& APPS_PRESSED
)
8100 retval
|= w32_key_to_modifier (VK_APPS
);
8101 if (mods
& SCROLLLOCK_ON
)
8102 retval
|= w32_key_to_modifier (VK_SCROLL
);
8104 /* Just in case someone wanted the original behavior, make it
8105 optional by setting w32-capslock-is-shiftlock to t. */
8106 if (NILP (Vw32_capslock_is_shiftlock
)
8107 /* Keys that should _not_ be affected by CapsLock. */
8108 && ( (key
== VK_BACK
)
8110 || (key
== VK_CLEAR
)
8111 || (key
== VK_RETURN
)
8112 || (key
== VK_ESCAPE
)
8113 || ((key
>= VK_SPACE
) && (key
<= VK_HELP
))
8114 || ((key
>= VK_NUMPAD0
) && (key
<= VK_F24
))
8115 || ((key
>= VK_NUMPAD_CLEAR
) && (key
<= VK_NUMPAD_DELETE
))
8118 /* Only consider shift state. */
8119 if ((mods
& SHIFT_PRESSED
) != 0)
8120 retval
|= shift_modifier
;
8124 /* Ignore CapsLock state if not enabled. */
8125 if (NILP (Vw32_enable_caps_lock
))
8126 mods
&= ~CAPSLOCK_ON
;
8127 if ((mods
& (SHIFT_PRESSED
| CAPSLOCK_ON
)) != 0)
8128 retval
|= shift_modifier
;
8134 /* The return code indicates key code size. cpID is the codepage to
8135 use for translation to Unicode; -1 means use the current console
8138 w32_kbd_patch_key (KEY_EVENT_RECORD
*event
, int cpId
)
8140 unsigned int key_code
= event
->wVirtualKeyCode
;
8141 unsigned int mods
= event
->dwControlKeyState
;
8143 static BYTE ansi_code
[4];
8144 static int isdead
= 0;
8148 event
->uChar
.AsciiChar
= ansi_code
[2];
8152 if (event
->uChar
.AsciiChar
!= 0)
8155 memset (keystate
, 0, sizeof (keystate
));
8156 keystate
[key_code
] = 0x80;
8157 if (mods
& SHIFT_PRESSED
)
8158 keystate
[VK_SHIFT
] = 0x80;
8159 if (mods
& CAPSLOCK_ON
)
8160 keystate
[VK_CAPITAL
] = 1;
8161 /* If we recognize right-alt and left-ctrl as AltGr, set the key
8162 states accordingly before invoking ToAscii. */
8163 if (!NILP (Vw32_recognize_altgr
)
8164 && (mods
& LEFT_CTRL_PRESSED
) && (mods
& RIGHT_ALT_PRESSED
))
8166 keystate
[VK_CONTROL
] = 0x80;
8167 keystate
[VK_LCONTROL
] = 0x80;
8168 keystate
[VK_MENU
] = 0x80;
8169 keystate
[VK_RMENU
] = 0x80;
8173 /* Because of an OS bug, ToAscii corrupts the stack when called to
8174 convert a dead key in console mode on NT4. Unfortunately, trying
8175 to check for dead keys using MapVirtualKey doesn't work either -
8176 these functions apparently use internal information about keyboard
8177 layout which doesn't get properly updated in console programs when
8178 changing layout (though apparently it gets partly updated,
8179 otherwise ToAscii wouldn't crash). */
8180 if (is_dead_key (event
->wVirtualKeyCode
))
8184 /* On NT, call ToUnicode instead and then convert to the current
8185 console input codepage. */
8186 if (os_subtype
== OS_NT
)
8190 isdead
= ToUnicode (event
->wVirtualKeyCode
, event
->wVirtualScanCode
,
8191 keystate
, buf
, 128, 0);
8194 /* When we are called from the GUI message processing code,
8195 we are passed the current keyboard codepage, a positive
8196 number, to use below. */
8198 cpId
= GetConsoleCP ();
8200 event
->uChar
.UnicodeChar
= buf
[isdead
- 1];
8201 isdead
= WideCharToMultiByte (cpId
, 0, buf
, isdead
,
8202 ansi_code
, 4, NULL
, NULL
);
8209 isdead
= ToAscii (event
->wVirtualKeyCode
, event
->wVirtualScanCode
,
8210 keystate
, (LPWORD
) ansi_code
, 0);
8215 event
->uChar
.AsciiChar
= ansi_code
[0];
8221 w32_sys_ring_bell (struct frame
*f
)
8223 if (sound_type
== 0xFFFFFFFF)
8227 else if (sound_type
== MB_EMACS_SILENT
)
8232 MessageBeep (sound_type
);
8236 /***********************************************************************
8238 ***********************************************************************/
8240 /* Keep this list in the same order as frame_parms in frame.c.
8241 Use 0 for unsupported frame parameters. */
8243 frame_parm_handler w32_frame_parm_handlers
[] =
8247 x_set_background_color
,
8253 x_set_foreground_color
,
8256 x_set_internal_border_width
,
8257 x_set_right_divider_width
,
8258 x_set_bottom_divider_width
,
8259 x_set_menu_bar_lines
,
8261 x_explicitly_set_name
,
8262 x_set_scroll_bar_width
,
8263 x_set_scroll_bar_height
,
8266 x_set_vertical_scroll_bars
,
8267 x_set_horizontal_scroll_bars
,
8269 x_set_tool_bar_lines
,
8270 0, /* x_set_scroll_bar_foreground, */
8271 0, /* x_set_scroll_bar_background, */
8276 0, /* x_set_wait_for_wm, */
8280 0, /* x_set_sticky */
8281 0, /* x_set_tool_bar_position */
8285 syms_of_w32fns (void)
8287 globals_of_w32fns ();
8288 track_mouse_window
= NULL
;
8290 w32_visible_system_caret_hwnd
= NULL
;
8292 DEFSYM (Qundefined_color
, "undefined-color");
8293 DEFSYM (Qcancel_timer
, "cancel-timer");
8294 DEFSYM (Qhyper
, "hyper");
8295 DEFSYM (Qsuper
, "super");
8296 DEFSYM (Qmeta
, "meta");
8297 DEFSYM (Qalt
, "alt");
8298 DEFSYM (Qctrl
, "ctrl");
8299 DEFSYM (Qcontrol
, "control");
8300 DEFSYM (Qshift
, "shift");
8301 DEFSYM (Qfont_param
, "font-parameter");
8302 DEFSYM (Qgeometry
, "geometry");
8303 DEFSYM (Qworkarea
, "workarea");
8304 DEFSYM (Qmm_size
, "mm-size");
8305 DEFSYM (Qframes
, "frames");
8307 Fput (Qundefined_color
, Qerror_conditions
,
8308 listn (CONSTYPE_PURE
, 2, Qundefined_color
, Qerror
));
8309 Fput (Qundefined_color
, Qerror_message
,
8310 build_pure_c_string ("Undefined color"));
8312 staticpro (&w32_grabbed_keys
);
8313 w32_grabbed_keys
= Qnil
;
8315 DEFVAR_LISP ("w32-color-map", Vw32_color_map
,
8316 doc
: /* An array of color name mappings for Windows. */);
8317 Vw32_color_map
= Qnil
;
8319 DEFVAR_LISP ("w32-pass-alt-to-system", Vw32_pass_alt_to_system
,
8320 doc
: /* Non-nil if Alt key presses are passed on to Windows.
8321 When non-nil, for example, Alt pressed and released and then space will
8322 open the System menu. When nil, Emacs processes the Alt key events, and
8323 then silently swallows them. */);
8324 Vw32_pass_alt_to_system
= Qnil
;
8326 DEFVAR_LISP ("w32-alt-is-meta", Vw32_alt_is_meta
,
8327 doc
: /* Non-nil if the Alt key is to be considered the same as the META key.
8328 When nil, Emacs will translate the Alt key to the ALT modifier, not to META. */);
8329 Vw32_alt_is_meta
= Qt
;
8331 DEFVAR_INT ("w32-quit-key", w32_quit_key
,
8332 doc
: /* If non-zero, the virtual key code for an alternative quit key. */);
8335 DEFVAR_LISP ("w32-pass-lwindow-to-system",
8336 Vw32_pass_lwindow_to_system
,
8337 doc
: /* If non-nil, the left \"Windows\" key is passed on to Windows.
8339 When non-nil, the Start menu is opened by tapping the key.
8340 If you set this to nil, the left \"Windows\" key is processed by Emacs
8341 according to the value of `w32-lwindow-modifier', which see.
8343 Note that some combinations of the left \"Windows\" key with other keys are
8344 caught by Windows at low level, and so binding them in Emacs will have no
8345 effect. For example, <lwindow>-r always pops up the Windows Run dialog,
8346 <lwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
8347 the doc string of `w32-phantom-key-code'. */);
8348 Vw32_pass_lwindow_to_system
= Qt
;
8350 DEFVAR_LISP ("w32-pass-rwindow-to-system",
8351 Vw32_pass_rwindow_to_system
,
8352 doc
: /* If non-nil, the right \"Windows\" key is passed on to Windows.
8354 When non-nil, the Start menu is opened by tapping the key.
8355 If you set this to nil, the right \"Windows\" key is processed by Emacs
8356 according to the value of `w32-rwindow-modifier', which see.
8358 Note that some combinations of the right \"Windows\" key with other keys are
8359 caught by Windows at low level, and so binding them in Emacs will have no
8360 effect. For example, <rwindow>-r always pops up the Windows Run dialog,
8361 <rwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
8362 the doc string of `w32-phantom-key-code'. */);
8363 Vw32_pass_rwindow_to_system
= Qt
;
8365 DEFVAR_LISP ("w32-phantom-key-code",
8366 Vw32_phantom_key_code
,
8367 doc
: /* Virtual key code used to generate \"phantom\" key presses.
8368 Value is a number between 0 and 255.
8370 Phantom key presses are generated in order to stop the system from
8371 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or
8372 `w32-pass-rwindow-to-system' is nil. */);
8373 /* Although 255 is technically not a valid key code, it works and
8374 means that this hack won't interfere with any real key code. */
8375 XSETINT (Vw32_phantom_key_code
, 255);
8377 DEFVAR_LISP ("w32-enable-num-lock",
8378 Vw32_enable_num_lock
,
8379 doc
: /* If non-nil, the Num Lock key acts normally.
8380 Set to nil to handle Num Lock as the `kp-numlock' key. */);
8381 Vw32_enable_num_lock
= Qt
;
8383 DEFVAR_LISP ("w32-enable-caps-lock",
8384 Vw32_enable_caps_lock
,
8385 doc
: /* If non-nil, the Caps Lock key acts normally.
8386 Set to nil to handle Caps Lock as the `capslock' key. */);
8387 Vw32_enable_caps_lock
= Qt
;
8389 DEFVAR_LISP ("w32-scroll-lock-modifier",
8390 Vw32_scroll_lock_modifier
,
8391 doc
: /* Modifier to use for the Scroll Lock ON state.
8392 The value can be hyper, super, meta, alt, control or shift for the
8393 respective modifier, or nil to handle Scroll Lock as the `scroll' key.
8394 Any other value will cause the Scroll Lock key to be ignored. */);
8395 Vw32_scroll_lock_modifier
= Qnil
;
8397 DEFVAR_LISP ("w32-lwindow-modifier",
8398 Vw32_lwindow_modifier
,
8399 doc
: /* Modifier to use for the left \"Windows\" key.
8400 The value can be hyper, super, meta, alt, control or shift for the
8401 respective modifier, or nil to appear as the `lwindow' key.
8402 Any other value will cause the key to be ignored. */);
8403 Vw32_lwindow_modifier
= Qnil
;
8405 DEFVAR_LISP ("w32-rwindow-modifier",
8406 Vw32_rwindow_modifier
,
8407 doc
: /* Modifier to use for the right \"Windows\" key.
8408 The value can be hyper, super, meta, alt, control or shift for the
8409 respective modifier, or nil to appear as the `rwindow' key.
8410 Any other value will cause the key to be ignored. */);
8411 Vw32_rwindow_modifier
= Qnil
;
8413 DEFVAR_LISP ("w32-apps-modifier",
8415 doc
: /* Modifier to use for the \"Apps\" key.
8416 The value can be hyper, super, meta, alt, control or shift for the
8417 respective modifier, or nil to appear as the `apps' key.
8418 Any other value will cause the key to be ignored. */);
8419 Vw32_apps_modifier
= Qnil
;
8421 DEFVAR_BOOL ("w32-enable-synthesized-fonts", w32_enable_synthesized_fonts
,
8422 doc
: /* Non-nil enables selection of artificially italicized and bold fonts. */);
8423 w32_enable_synthesized_fonts
= 0;
8425 DEFVAR_LISP ("w32-enable-palette", Vw32_enable_palette
,
8426 doc
: /* Non-nil enables Windows palette management to map colors exactly. */);
8427 Vw32_enable_palette
= Qt
;
8429 DEFVAR_INT ("w32-mouse-button-tolerance",
8430 w32_mouse_button_tolerance
,
8431 doc
: /* Analogue of double click interval for faking middle mouse events.
8432 The value is the minimum time in milliseconds that must elapse between
8433 left and right button down events before they are considered distinct events.
8434 If both mouse buttons are depressed within this interval, a middle mouse
8435 button down event is generated instead. */);
8436 w32_mouse_button_tolerance
= GetDoubleClickTime () / 2;
8438 DEFVAR_INT ("w32-mouse-move-interval",
8439 w32_mouse_move_interval
,
8440 doc
: /* Minimum interval between mouse move events.
8441 The value is the minimum time in milliseconds that must elapse between
8442 successive mouse move (or scroll bar drag) events before they are
8443 reported as lisp events. */);
8444 w32_mouse_move_interval
= 0;
8446 DEFVAR_BOOL ("w32-pass-extra-mouse-buttons-to-system",
8447 w32_pass_extra_mouse_buttons_to_system
,
8448 doc
: /* If non-nil, the fourth and fifth mouse buttons are passed to Windows.
8449 Recent versions of Windows support mice with up to five buttons.
8450 Since most applications don't support these extra buttons, most mouse
8451 drivers will allow you to map them to functions at the system level.
8452 If this variable is non-nil, Emacs will pass them on, allowing the
8453 system to handle them. */);
8454 w32_pass_extra_mouse_buttons_to_system
= 0;
8456 DEFVAR_BOOL ("w32-pass-multimedia-buttons-to-system",
8457 w32_pass_multimedia_buttons_to_system
,
8458 doc
: /* If non-nil, media buttons are passed to Windows.
8459 Some modern keyboards contain buttons for controlling media players, web
8460 browsers and other applications. Generally these buttons are handled on a
8461 system wide basis, but by setting this to nil they are made available
8462 to Emacs for binding. Depending on your keyboard, additional keys that
8463 may be available are:
8465 browser-back, browser-forward, browser-refresh, browser-stop,
8466 browser-search, browser-favorites, browser-home,
8467 mail, mail-reply, mail-forward, mail-send,
8469 help, find, new, open, close, save, print, undo, redo, copy, cut, paste,
8470 spell-check, correction-list, toggle-dictate-command,
8471 media-next, media-previous, media-stop, media-play-pause, media-select,
8472 media-play, media-pause, media-record, media-fast-forward, media-rewind,
8473 media-channel-up, media-channel-down,
8474 volume-mute, volume-up, volume-down,
8475 mic-volume-mute, mic-volume-down, mic-volume-up, mic-toggle,
8476 bass-down, bass-boost, bass-up, treble-down, treble-up */);
8477 w32_pass_multimedia_buttons_to_system
= 1;
8479 #if 0 /* TODO: Mouse cursor customization. */
8480 DEFVAR_LISP ("x-pointer-shape", Vx_pointer_shape
,
8481 doc
: /* The shape of the pointer when over text.
8482 Changing the value does not affect existing frames
8483 unless you set the mouse color. */);
8484 Vx_pointer_shape
= Qnil
;
8486 Vx_nontext_pointer_shape
= Qnil
;
8488 Vx_mode_pointer_shape
= Qnil
;
8490 DEFVAR_LISP ("x-hourglass-pointer-shape", Vx_hourglass_pointer_shape
,
8491 doc
: /* The shape of the pointer when Emacs is busy.
8492 This variable takes effect when you create a new frame
8493 or when you set the mouse color. */);
8494 Vx_hourglass_pointer_shape
= Qnil
;
8496 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
8497 Vx_sensitive_text_pointer_shape
,
8498 doc
: /* The shape of the pointer when over mouse-sensitive text.
8499 This variable takes effect when you create a new frame
8500 or when you set the mouse color. */);
8501 Vx_sensitive_text_pointer_shape
= Qnil
;
8503 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
8504 Vx_window_horizontal_drag_shape
,
8505 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
8506 This variable takes effect when you create a new frame
8507 or when you set the mouse color. */);
8508 Vx_window_horizontal_drag_shape
= Qnil
;
8510 DEFVAR_LISP ("x-window-vertical-drag-cursor",
8511 Vx_window_vertical_drag_shape
,
8512 doc
: /* Pointer shape to use for indicating a window can be dragged vertically.
8513 This variable takes effect when you create a new frame
8514 or when you set the mouse color. */);
8515 Vx_window_vertical_drag_shape
= Qnil
;
8518 DEFVAR_LISP ("x-cursor-fore-pixel", Vx_cursor_fore_pixel
,
8519 doc
: /* A string indicating the foreground color of the cursor box. */);
8520 Vx_cursor_fore_pixel
= Qnil
;
8522 DEFVAR_LISP ("x-max-tooltip-size", Vx_max_tooltip_size
,
8523 doc
: /* Maximum size for tooltips.
8524 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
8525 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
8527 DEFVAR_LISP ("x-no-window-manager", Vx_no_window_manager
,
8528 doc
: /* Non-nil if no window manager is in use.
8529 Emacs doesn't try to figure this out; this is always nil
8530 unless you set it to something else. */);
8531 /* We don't have any way to find this out, so set it to nil
8532 and maybe the user would like to set it to t. */
8533 Vx_no_window_manager
= Qnil
;
8535 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
8536 Vx_pixel_size_width_font_regexp
,
8537 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
8539 Since Emacs gets width of a font matching with this regexp from
8540 PIXEL_SIZE field of the name, font finding mechanism gets faster for
8541 such a font. This is especially effective for such large fonts as
8542 Chinese, Japanese, and Korean. */);
8543 Vx_pixel_size_width_font_regexp
= Qnil
;
8545 DEFVAR_LISP ("w32-bdf-filename-alist",
8546 Vw32_bdf_filename_alist
,
8547 doc
: /* List of bdf fonts and their corresponding filenames. */);
8548 Vw32_bdf_filename_alist
= Qnil
;
8550 DEFVAR_BOOL ("w32-strict-fontnames",
8551 w32_strict_fontnames
,
8552 doc
: /* Non-nil means only use fonts that are exact matches for those requested.
8553 Default is nil, which allows old fontnames that are not XLFD compliant,
8554 and allows third-party CJK display to work by specifying false charset
8555 fields to trick Emacs into translating to Big5, SJIS etc.
8556 Setting this to t will prevent wrong fonts being selected when
8557 fontsets are automatically created. */);
8558 w32_strict_fontnames
= 0;
8560 DEFVAR_BOOL ("w32-strict-painting",
8561 w32_strict_painting
,
8562 doc
: /* Non-nil means use strict rules for repainting frames.
8563 Set this to nil to get the old behavior for repainting; this should
8564 only be necessary if the default setting causes problems. */);
8565 w32_strict_painting
= 1;
8567 #if 0 /* TODO: Port to W32 */
8568 defsubr (&Sx_change_window_property
);
8569 defsubr (&Sx_delete_window_property
);
8570 defsubr (&Sx_window_property
);
8572 defsubr (&Sxw_display_color_p
);
8573 defsubr (&Sx_display_grayscale_p
);
8574 defsubr (&Sxw_color_defined_p
);
8575 defsubr (&Sxw_color_values
);
8576 defsubr (&Sx_server_max_request_size
);
8577 defsubr (&Sx_server_vendor
);
8578 defsubr (&Sx_server_version
);
8579 defsubr (&Sx_display_pixel_width
);
8580 defsubr (&Sx_display_pixel_height
);
8581 defsubr (&Sx_display_mm_width
);
8582 defsubr (&Sx_display_mm_height
);
8583 defsubr (&Sx_display_screens
);
8584 defsubr (&Sx_display_planes
);
8585 defsubr (&Sx_display_color_cells
);
8586 defsubr (&Sx_display_visual_class
);
8587 defsubr (&Sx_display_backing_store
);
8588 defsubr (&Sx_display_save_under
);
8589 defsubr (&Sx_create_frame
);
8590 defsubr (&Sx_open_connection
);
8591 defsubr (&Sx_close_connection
);
8592 defsubr (&Sx_display_list
);
8593 defsubr (&Sx_frame_geometry
);
8594 defsubr (&Sx_synchronize
);
8596 /* W32 specific functions */
8598 defsubr (&Sw32_define_rgb_color
);
8599 defsubr (&Sw32_default_color_map
);
8600 defsubr (&Sw32_display_monitor_attributes_list
);
8601 defsubr (&Sw32_send_sys_command
);
8602 defsubr (&Sw32_shell_execute
);
8603 defsubr (&Sw32_register_hot_key
);
8604 defsubr (&Sw32_unregister_hot_key
);
8605 defsubr (&Sw32_registered_hot_keys
);
8606 defsubr (&Sw32_reconstruct_hot_key
);
8607 defsubr (&Sw32_toggle_lock_key
);
8608 defsubr (&Sw32_window_exists_p
);
8609 defsubr (&Sw32_frame_rect
);
8610 defsubr (&Sw32_frame_menu_bar_size
);
8611 defsubr (&Sw32_battery_status
);
8614 defsubr (&Sfile_system_info
);
8615 defsubr (&Sdefault_printer_name
);
8618 defsubr (&Sset_message_beep
);
8619 defsubr (&Sx_show_tip
);
8620 defsubr (&Sx_hide_tip
);
8622 staticpro (&tip_timer
);
8624 staticpro (&tip_frame
);
8626 last_show_tip_args
= Qnil
;
8627 staticpro (&last_show_tip_args
);
8629 defsubr (&Sx_file_dialog
);
8631 defsubr (&Ssystem_move_file_to_trash
);
8637 /* Crashing and reporting backtrace. */
8640 static LONG CALLBACK
my_exception_handler (EXCEPTION_POINTERS
*);
8641 static LPTOP_LEVEL_EXCEPTION_FILTER prev_exception_handler
;
8643 static DWORD except_code
;
8644 static PVOID except_addr
;
8647 /* This handler records the exception code and the address where it
8648 was triggered so that this info could be included in the backtrace.
8649 Without that, the backtrace in some cases has no information
8650 whatsoever about the offending code, and looks as if the top-level
8651 exception handler in the MinGW startup code di the one that
8653 static LONG CALLBACK
8654 my_exception_handler (EXCEPTION_POINTERS
* exception_data
)
8656 except_code
= exception_data
->ExceptionRecord
->ExceptionCode
;
8657 except_addr
= exception_data
->ExceptionRecord
->ExceptionAddress
;
8659 if (prev_exception_handler
)
8660 return prev_exception_handler (exception_data
);
8661 return EXCEPTION_EXECUTE_HANDLER
;
8665 typedef USHORT (WINAPI
* CaptureStackBackTrace_proc
) (ULONG
, ULONG
, PVOID
*,
8668 #define BACKTRACE_LIMIT_MAX 62
8671 w32_backtrace (void **buffer
, int limit
)
8673 static CaptureStackBackTrace_proc s_pfn_CaptureStackBackTrace
= NULL
;
8674 HMODULE hm_kernel32
= NULL
;
8676 if (!s_pfn_CaptureStackBackTrace
)
8678 hm_kernel32
= LoadLibrary ("Kernel32.dll");
8679 s_pfn_CaptureStackBackTrace
=
8680 (CaptureStackBackTrace_proc
) GetProcAddress (hm_kernel32
,
8681 "RtlCaptureStackBackTrace");
8683 if (s_pfn_CaptureStackBackTrace
)
8684 return s_pfn_CaptureStackBackTrace (0, min (BACKTRACE_LIMIT_MAX
, limit
),
8693 button
= MessageBox (NULL
,
8694 "A fatal error has occurred!\n\n"
8695 "Would you like to attach a debugger?\n\n"
8697 "YES -- to debug Emacs, or\n"
8698 "NO -- to abort Emacs and produce a backtrace\n"
8699 " (emacs_backtrace.txt in current directory)."
8701 "\n\n(type \"gdb -p <emacs-PID>\" and\n"
8702 "\"continue\" inside GDB before clicking YES.)"
8704 , "Emacs Abort Dialog",
8705 MB_ICONEXCLAMATION
| MB_TASKMODAL
8706 | MB_SETFOREGROUND
| MB_YESNO
);
8711 exit (2); /* tell the compiler we will never return */
8715 void *stack
[BACKTRACE_LIMIT_MAX
+ 1];
8716 int i
= w32_backtrace (stack
, BACKTRACE_LIMIT_MAX
+ 1);
8720 int errfile_fd
= -1;
8722 char buf
[sizeof ("\r\nException at this address:\r\n\r\n")
8723 /* The type below should really be 'void *', but
8724 INT_BUFSIZE_BOUND cannot handle that without
8725 triggering compiler warnings (under certain
8726 pedantic warning switches), it wants an
8728 + 2 * INT_BUFSIZE_BOUND (intptr_t)];
8732 HANDLE errout
= GetStdHandle (STD_ERROR_HANDLE
);
8735 if (errout
&& errout
!= INVALID_HANDLE_VALUE
)
8736 stderr_fd
= _open_osfhandle ((intptr_t)errout
, O_APPEND
| O_BINARY
);
8739 /* We use %p, not 0x%p, as %p produces a leading "0x" on XP,
8740 but not on Windows 7. addr2line doesn't mind a missing
8741 "0x", but will be confused by an extra one. */
8743 sprintf (buf
, "\r\nException 0x%lx at this address:\r\n%p\r\n",
8744 except_code
, except_addr
);
8748 write (stderr_fd
, buf
, strlen (buf
));
8749 write (stderr_fd
, "\r\nBacktrace:\r\n", 14);
8754 errfile_fd
= _open ("emacs_backtrace.txt", O_RDWR
| O_CREAT
| O_BINARY
, S_IREAD
| S_IWRITE
);
8755 if (errfile_fd
>= 0)
8757 lseek (errfile_fd
, 0L, SEEK_END
);
8759 write (errfile_fd
, buf
, strlen (buf
));
8760 write (errfile_fd
, "\r\nBacktrace:\r\n", 14);
8763 for (j
= 0; j
< i
; j
++)
8765 /* stack[] gives the return addresses, whereas we want
8766 the address of the call, so decrease each address
8767 by approximate size of 1 CALL instruction. */
8768 sprintf (buf
, "%p\r\n", (char *)stack
[j
] - sizeof(void *));
8770 write (stderr_fd
, buf
, strlen (buf
));
8771 if (errfile_fd
>= 0)
8772 write (errfile_fd
, buf
, strlen (buf
));
8774 if (i
== BACKTRACE_LIMIT_MAX
)
8777 write (stderr_fd
, "...\r\n", 5);
8778 if (errfile_fd
>= 0)
8779 write (errfile_fd
, "...\r\n", 5);
8781 if (errfile_fd
>= 0)
8792 /* Initialization. */
8795 globals_of_w32fns is used to initialize those global variables that
8796 must always be initialized on startup even when the global variable
8797 initialized is non zero (see the function main in emacs.c).
8798 globals_of_w32fns is called from syms_of_w32fns when the global
8799 variable initialized is 0 and directly from main when initialized
8803 globals_of_w32fns (void)
8805 HMODULE user32_lib
= GetModuleHandle ("user32.dll");
8807 TrackMouseEvent not available in all versions of Windows, so must load
8808 it dynamically. Do it once, here, instead of every time it is used.
8810 track_mouse_event_fn
= (TrackMouseEvent_Proc
)
8811 GetProcAddress (user32_lib
, "TrackMouseEvent");
8813 monitor_from_point_fn
= (MonitorFromPoint_Proc
)
8814 GetProcAddress (user32_lib
, "MonitorFromPoint");
8815 get_monitor_info_fn
= (GetMonitorInfo_Proc
)
8816 GetProcAddress (user32_lib
, "GetMonitorInfoA");
8817 monitor_from_window_fn
= (MonitorFromWindow_Proc
)
8818 GetProcAddress (user32_lib
, "MonitorFromWindow");
8819 enum_display_monitors_fn
= (EnumDisplayMonitors_Proc
)
8820 GetProcAddress (user32_lib
, "EnumDisplayMonitors");
8823 HMODULE imm32_lib
= GetModuleHandle ("imm32.dll");
8824 get_composition_string_fn
= (ImmGetCompositionString_Proc
)
8825 GetProcAddress (imm32_lib
, "ImmGetCompositionStringW");
8826 get_ime_context_fn
= (ImmGetContext_Proc
)
8827 GetProcAddress (imm32_lib
, "ImmGetContext");
8828 release_ime_context_fn
= (ImmReleaseContext_Proc
)
8829 GetProcAddress (imm32_lib
, "ImmReleaseContext");
8830 set_ime_composition_window_fn
= (ImmSetCompositionWindow_Proc
)
8831 GetProcAddress (imm32_lib
, "ImmSetCompositionWindow");
8837 prev_exception_handler
= SetUnhandledExceptionFilter (my_exception_handler
);
8840 DEFVAR_INT ("w32-ansi-code-page",
8842 doc
: /* The ANSI code page used by the system. */);
8843 w32_ansi_code_page
= GetACP ();
8845 if (os_subtype
== OS_NT
)
8846 w32_unicode_gui
= 1;
8848 w32_unicode_gui
= 0;
8850 /* MessageBox does not work without this when linked to comctl32.dll 6.0. */
8851 InitCommonControls ();
8853 syms_of_w32uniscribe ();
8856 #ifdef NTGUI_UNICODE
8859 ntgui_encode_system (Lisp_Object str
)
8861 Lisp_Object encoded
;
8862 to_unicode (str
, &encoded
);
8866 #endif /* NTGUI_UNICODE */