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
);
92 /* If non-NULL, a handle to a frame where to display the hourglass cursor. */
93 static HWND hourglass_hwnd
= NULL
;
96 #define IDC_HAND MAKEINTRESOURCE(32649)
99 Lisp_Object Qsuppress_icon
;
100 Lisp_Object Qundefined_color
;
101 Lisp_Object Qcancel_timer
;
102 Lisp_Object Qfont_param
;
108 Lisp_Object Qcontrol
;
110 static Lisp_Object Qgeometry
, Qworkarea
, Qmm_size
, Qframes
;
113 /* Prefix for system colors. */
114 #define SYSTEM_COLOR_PREFIX "System"
115 #define SYSTEM_COLOR_PREFIX_LEN (sizeof (SYSTEM_COLOR_PREFIX) - 1)
117 /* State variables for emulating a three button mouse. */
122 static int button_state
= 0;
123 static W32Msg saved_mouse_button_msg
;
124 static unsigned mouse_button_timer
= 0; /* non-zero when timer is active */
125 static W32Msg saved_mouse_move_msg
;
126 static unsigned mouse_move_timer
= 0;
128 /* Window that is tracking the mouse. */
129 static HWND track_mouse_window
;
131 /* Multi-monitor API definitions that are not pulled from the headers
132 since we are compiling for NT 4. */
133 #ifndef MONITOR_DEFAULT_TO_NEAREST
134 #define MONITOR_DEFAULT_TO_NEAREST 2
136 #ifndef MONITORINFOF_PRIMARY
137 #define MONITORINFOF_PRIMARY 1
139 #ifndef SM_XVIRTUALSCREEN
140 #define SM_XVIRTUALSCREEN 76
142 #ifndef SM_YVIRTUALSCREEN
143 #define SM_YVIRTUALSCREEN 77
145 /* MinGW headers define MONITORINFO unconditionally, but MSVC ones don't.
146 To avoid a compile error on one or the other, redefine with a new name. */
155 #ifndef CCHDEVICENAME
156 #define CCHDEVICENAME 32
158 struct MONITOR_INFO_EX
164 char szDevice
[CCHDEVICENAME
];
167 /* Reportedly, MSVC does not have this in its headers. */
168 #if defined (_MSC_VER) && _WIN32_WINNT < 0x0500
169 DECLARE_HANDLE(HMONITOR
);
172 typedef BOOL (WINAPI
* TrackMouseEvent_Proc
)
173 (IN OUT LPTRACKMOUSEEVENT lpEventTrack
);
174 typedef LONG (WINAPI
* ImmGetCompositionString_Proc
)
175 (IN HIMC context
, IN DWORD index
, OUT LPVOID buffer
, IN DWORD bufLen
);
176 typedef HIMC (WINAPI
* ImmGetContext_Proc
) (IN HWND window
);
177 typedef HWND (WINAPI
* ImmReleaseContext_Proc
) (IN HWND wnd
, IN HIMC context
);
178 typedef HWND (WINAPI
* ImmSetCompositionWindow_Proc
) (IN HIMC context
,
179 IN COMPOSITIONFORM
*form
);
180 typedef HMONITOR (WINAPI
* MonitorFromPoint_Proc
) (IN POINT pt
, IN DWORD flags
);
181 typedef BOOL (WINAPI
* GetMonitorInfo_Proc
)
182 (IN HMONITOR monitor
, OUT
struct MONITOR_INFO
* info
);
183 typedef HMONITOR (WINAPI
* MonitorFromWindow_Proc
)
184 (IN HWND hwnd
, IN DWORD dwFlags
);
185 typedef BOOL
CALLBACK (* MonitorEnum_Proc
)
186 (IN HMONITOR monitor
, IN HDC hdc
, IN RECT
*rcMonitor
, IN LPARAM dwData
);
187 typedef BOOL (WINAPI
* EnumDisplayMonitors_Proc
)
188 (IN HDC hdc
, IN RECT
*rcClip
, IN MonitorEnum_Proc fnEnum
, IN LPARAM dwData
);
190 TrackMouseEvent_Proc track_mouse_event_fn
= NULL
;
191 ImmGetCompositionString_Proc get_composition_string_fn
= NULL
;
192 ImmGetContext_Proc get_ime_context_fn
= NULL
;
193 ImmReleaseContext_Proc release_ime_context_fn
= NULL
;
194 ImmSetCompositionWindow_Proc set_ime_composition_window_fn
= NULL
;
195 MonitorFromPoint_Proc monitor_from_point_fn
= NULL
;
196 GetMonitorInfo_Proc get_monitor_info_fn
= NULL
;
197 MonitorFromWindow_Proc monitor_from_window_fn
= NULL
;
198 EnumDisplayMonitors_Proc enum_display_monitors_fn
= NULL
;
201 #define unicode_append_menu AppendMenuW
202 #else /* !NTGUI_UNICODE */
203 extern AppendMenuW_Proc unicode_append_menu
;
204 #endif /* NTGUI_UNICODE */
206 /* Flag to selectively ignore WM_IME_CHAR messages. */
207 static int ignore_ime_char
= 0;
209 /* W95 mousewheel handler */
210 unsigned int msh_mousewheel
= 0;
213 #define MOUSE_BUTTON_ID 1
214 #define MOUSE_MOVE_ID 2
215 #define MENU_FREE_ID 3
216 /* The delay (milliseconds) before a menu is freed after WM_EXITMENULOOP
218 #define MENU_FREE_DELAY 1000
219 static unsigned menu_free_timer
= 0;
222 static int image_cache_refcount
, dpyinfo_refcount
;
225 static HWND w32_visible_system_caret_hwnd
;
227 static int w32_unicode_gui
;
230 extern HMENU current_popup_menu
;
231 static int menubar_in_use
= 0;
233 /* From w32uniscribe.c */
234 extern void syms_of_w32uniscribe (void);
235 extern int uniscribe_available
;
237 /* Function prototypes for hourglass support. */
238 static void w32_show_hourglass (struct frame
*);
239 static void w32_hide_hourglass (void);
242 /* From w32inevt.c */
243 extern int faked_key
;
244 #endif /* WINDOWSNT */
246 /* This gives us the page size and the size of the allocation unit on NT. */
247 SYSTEM_INFO sysinfo_cache
;
249 /* This gives us version, build, and platform identification. */
250 OSVERSIONINFO osinfo_cache
;
252 DWORD_PTR syspage_mask
= 0;
254 /* The major and minor versions of NT. */
255 int w32_major_version
;
256 int w32_minor_version
;
257 int w32_build_number
;
259 /* Distinguish between Windows NT and Windows 95. */
263 HINSTANCE hinst
= NULL
;
266 static unsigned int sound_type
= 0xFFFFFFFF;
267 #define MB_EMACS_SILENT (0xFFFFFFFF - 1)
269 /* Let the user specify a display with a frame.
270 nil stands for the selected frame--or, if that is not a w32 frame,
271 the first display on the list. */
273 struct w32_display_info
*
274 check_x_display_info (Lisp_Object frame
)
278 struct frame
*sf
= XFRAME (selected_frame
);
280 if (FRAME_W32_P (sf
) && FRAME_LIVE_P (sf
))
281 return FRAME_DISPLAY_INFO (sf
);
283 return &one_w32_display_info
;
285 else if (STRINGP (frame
))
286 return x_display_info_for_name (frame
);
291 CHECK_LIVE_FRAME (frame
);
293 if (! FRAME_W32_P (f
))
294 error ("Non-W32 frame used");
295 return FRAME_DISPLAY_INFO (f
);
299 /* Return the Emacs frame-object corresponding to an w32 window.
300 It could be the frame's main window or an icon window. */
303 x_window_to_frame (struct w32_display_info
*dpyinfo
, HWND wdesc
)
305 Lisp_Object tail
, frame
;
308 FOR_EACH_FRAME (tail
, frame
)
311 if (!FRAME_W32_P (f
) || FRAME_DISPLAY_INFO (f
) != dpyinfo
)
314 if (FRAME_W32_WINDOW (f
) == wdesc
)
321 static Lisp_Object
unwind_create_frame (Lisp_Object
);
322 static void unwind_create_tip_frame (Lisp_Object
);
323 static void my_create_window (struct frame
*);
324 static void my_create_tip_window (struct frame
*);
326 /* TODO: Native Input Method support; see x_create_im. */
327 void x_set_foreground_color (struct frame
*, Lisp_Object
, Lisp_Object
);
328 void x_set_background_color (struct frame
*, Lisp_Object
, Lisp_Object
);
329 void x_set_mouse_color (struct frame
*, Lisp_Object
, Lisp_Object
);
330 void x_set_cursor_color (struct frame
*, Lisp_Object
, Lisp_Object
);
331 void x_set_border_color (struct frame
*, Lisp_Object
, Lisp_Object
);
332 void x_set_cursor_type (struct frame
*, Lisp_Object
, Lisp_Object
);
333 void x_set_icon_type (struct frame
*, Lisp_Object
, Lisp_Object
);
334 void x_set_icon_name (struct frame
*, Lisp_Object
, Lisp_Object
);
335 void x_explicitly_set_name (struct frame
*, Lisp_Object
, Lisp_Object
);
336 void x_set_menu_bar_lines (struct frame
*, Lisp_Object
, Lisp_Object
);
337 void x_set_title (struct frame
*, Lisp_Object
, Lisp_Object
);
338 void x_set_tool_bar_lines (struct frame
*, Lisp_Object
, Lisp_Object
);
343 /* Store the screen positions of frame F into XPTR and YPTR.
344 These are the positions of the containing window manager window,
345 not Emacs's own window. */
348 x_real_positions (struct frame
*f
, int *xptr
, int *yptr
)
353 /* Get the bounds of the WM window. */
354 GetWindowRect (FRAME_W32_WINDOW (f
), &rect
);
359 /* Convert (0, 0) in the client area to screen co-ordinates. */
360 ClientToScreen (FRAME_W32_WINDOW (f
), &pt
);
362 /* Remember x_pixels_diff and y_pixels_diff. */
363 f
->x_pixels_diff
= pt
.x
- rect
.left
;
364 f
->y_pixels_diff
= pt
.y
- rect
.top
;
370 /* Returns the window rectangle appropriate for the given fullscreen mode.
371 The normal rect parameter was the window's rectangle prior to entering
372 fullscreen mode. If multiple monitor support is available, the nearest
373 monitor to the window is chosen. */
376 w32_fullscreen_rect (HWND hwnd
, int fsmode
, RECT normal
, RECT
*rect
)
378 struct MONITOR_INFO mi
= { sizeof(mi
) };
379 if (monitor_from_window_fn
&& get_monitor_info_fn
)
382 monitor_from_window_fn (hwnd
, MONITOR_DEFAULT_TO_NEAREST
);
383 get_monitor_info_fn (monitor
, &mi
);
387 mi
.rcMonitor
.left
= 0;
388 mi
.rcMonitor
.top
= 0;
389 mi
.rcMonitor
.right
= GetSystemMetrics (SM_CXSCREEN
);
390 mi
.rcMonitor
.bottom
= GetSystemMetrics (SM_CYSCREEN
);
393 mi
.rcWork
.right
= GetSystemMetrics (SM_CXMAXIMIZED
);
394 mi
.rcWork
.bottom
= GetSystemMetrics (SM_CYMAXIMIZED
);
399 case FULLSCREEN_BOTH
:
400 rect
->left
= mi
.rcMonitor
.left
;
401 rect
->top
= mi
.rcMonitor
.top
;
402 rect
->right
= mi
.rcMonitor
.right
;
403 rect
->bottom
= mi
.rcMonitor
.bottom
;
405 case FULLSCREEN_WIDTH
:
406 rect
->left
= mi
.rcWork
.left
;
407 rect
->top
= normal
.top
;
408 rect
->right
= mi
.rcWork
.right
;
409 rect
->bottom
= normal
.bottom
;
411 case FULLSCREEN_HEIGHT
:
412 rect
->left
= normal
.left
;
413 rect
->top
= mi
.rcWork
.top
;
414 rect
->right
= normal
.right
;
415 rect
->bottom
= mi
.rcWork
.bottom
;
425 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
,
426 Sw32_define_rgb_color
, 4, 4, 0,
427 doc
: /* Convert RGB numbers to a Windows color reference and associate with NAME.
428 This adds or updates a named color to `w32-color-map', making it
429 available for use. The original entry's RGB ref is returned, or nil
430 if the entry is new. */)
431 (Lisp_Object red
, Lisp_Object green
, Lisp_Object blue
, Lisp_Object name
)
434 Lisp_Object oldrgb
= Qnil
;
438 CHECK_NUMBER (green
);
442 XSETINT (rgb
, RGB (XUINT (red
), XUINT (green
), XUINT (blue
)));
446 /* replace existing entry in w32-color-map or add new entry. */
447 entry
= Fassoc (name
, Vw32_color_map
);
450 entry
= Fcons (name
, rgb
);
451 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
455 oldrgb
= Fcdr (entry
);
456 Fsetcdr (entry
, rgb
);
464 /* The default colors for the w32 color map */
465 typedef struct colormap_t
471 colormap_t w32_color_map
[] =
473 {"snow" , PALETTERGB (255,250,250)},
474 {"ghost white" , PALETTERGB (248,248,255)},
475 {"GhostWhite" , PALETTERGB (248,248,255)},
476 {"white smoke" , PALETTERGB (245,245,245)},
477 {"WhiteSmoke" , PALETTERGB (245,245,245)},
478 {"gainsboro" , PALETTERGB (220,220,220)},
479 {"floral white" , PALETTERGB (255,250,240)},
480 {"FloralWhite" , PALETTERGB (255,250,240)},
481 {"old lace" , PALETTERGB (253,245,230)},
482 {"OldLace" , PALETTERGB (253,245,230)},
483 {"linen" , PALETTERGB (250,240,230)},
484 {"antique white" , PALETTERGB (250,235,215)},
485 {"AntiqueWhite" , PALETTERGB (250,235,215)},
486 {"papaya whip" , PALETTERGB (255,239,213)},
487 {"PapayaWhip" , PALETTERGB (255,239,213)},
488 {"blanched almond" , PALETTERGB (255,235,205)},
489 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
490 {"bisque" , PALETTERGB (255,228,196)},
491 {"peach puff" , PALETTERGB (255,218,185)},
492 {"PeachPuff" , PALETTERGB (255,218,185)},
493 {"navajo white" , PALETTERGB (255,222,173)},
494 {"NavajoWhite" , PALETTERGB (255,222,173)},
495 {"moccasin" , PALETTERGB (255,228,181)},
496 {"cornsilk" , PALETTERGB (255,248,220)},
497 {"ivory" , PALETTERGB (255,255,240)},
498 {"lemon chiffon" , PALETTERGB (255,250,205)},
499 {"LemonChiffon" , PALETTERGB (255,250,205)},
500 {"seashell" , PALETTERGB (255,245,238)},
501 {"honeydew" , PALETTERGB (240,255,240)},
502 {"mint cream" , PALETTERGB (245,255,250)},
503 {"MintCream" , PALETTERGB (245,255,250)},
504 {"azure" , PALETTERGB (240,255,255)},
505 {"alice blue" , PALETTERGB (240,248,255)},
506 {"AliceBlue" , PALETTERGB (240,248,255)},
507 {"lavender" , PALETTERGB (230,230,250)},
508 {"lavender blush" , PALETTERGB (255,240,245)},
509 {"LavenderBlush" , PALETTERGB (255,240,245)},
510 {"misty rose" , PALETTERGB (255,228,225)},
511 {"MistyRose" , PALETTERGB (255,228,225)},
512 {"white" , PALETTERGB (255,255,255)},
513 {"black" , PALETTERGB ( 0, 0, 0)},
514 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
515 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
516 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
517 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
518 {"dim gray" , PALETTERGB (105,105,105)},
519 {"DimGray" , PALETTERGB (105,105,105)},
520 {"dim grey" , PALETTERGB (105,105,105)},
521 {"DimGrey" , PALETTERGB (105,105,105)},
522 {"slate gray" , PALETTERGB (112,128,144)},
523 {"SlateGray" , PALETTERGB (112,128,144)},
524 {"slate grey" , PALETTERGB (112,128,144)},
525 {"SlateGrey" , PALETTERGB (112,128,144)},
526 {"light slate gray" , PALETTERGB (119,136,153)},
527 {"LightSlateGray" , PALETTERGB (119,136,153)},
528 {"light slate grey" , PALETTERGB (119,136,153)},
529 {"LightSlateGrey" , PALETTERGB (119,136,153)},
530 {"gray" , PALETTERGB (190,190,190)},
531 {"grey" , PALETTERGB (190,190,190)},
532 {"light grey" , PALETTERGB (211,211,211)},
533 {"LightGrey" , PALETTERGB (211,211,211)},
534 {"light gray" , PALETTERGB (211,211,211)},
535 {"LightGray" , PALETTERGB (211,211,211)},
536 {"midnight blue" , PALETTERGB ( 25, 25,112)},
537 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
538 {"navy" , PALETTERGB ( 0, 0,128)},
539 {"navy blue" , PALETTERGB ( 0, 0,128)},
540 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
541 {"cornflower blue" , PALETTERGB (100,149,237)},
542 {"CornflowerBlue" , PALETTERGB (100,149,237)},
543 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
544 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
545 {"slate blue" , PALETTERGB (106, 90,205)},
546 {"SlateBlue" , PALETTERGB (106, 90,205)},
547 {"medium slate blue" , PALETTERGB (123,104,238)},
548 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
549 {"light slate blue" , PALETTERGB (132,112,255)},
550 {"LightSlateBlue" , PALETTERGB (132,112,255)},
551 {"medium blue" , PALETTERGB ( 0, 0,205)},
552 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
553 {"royal blue" , PALETTERGB ( 65,105,225)},
554 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
555 {"blue" , PALETTERGB ( 0, 0,255)},
556 {"dodger blue" , PALETTERGB ( 30,144,255)},
557 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
558 {"deep sky blue" , PALETTERGB ( 0,191,255)},
559 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
560 {"sky blue" , PALETTERGB (135,206,235)},
561 {"SkyBlue" , PALETTERGB (135,206,235)},
562 {"light sky blue" , PALETTERGB (135,206,250)},
563 {"LightSkyBlue" , PALETTERGB (135,206,250)},
564 {"steel blue" , PALETTERGB ( 70,130,180)},
565 {"SteelBlue" , PALETTERGB ( 70,130,180)},
566 {"light steel blue" , PALETTERGB (176,196,222)},
567 {"LightSteelBlue" , PALETTERGB (176,196,222)},
568 {"light blue" , PALETTERGB (173,216,230)},
569 {"LightBlue" , PALETTERGB (173,216,230)},
570 {"powder blue" , PALETTERGB (176,224,230)},
571 {"PowderBlue" , PALETTERGB (176,224,230)},
572 {"pale turquoise" , PALETTERGB (175,238,238)},
573 {"PaleTurquoise" , PALETTERGB (175,238,238)},
574 {"dark turquoise" , PALETTERGB ( 0,206,209)},
575 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
576 {"medium turquoise" , PALETTERGB ( 72,209,204)},
577 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
578 {"turquoise" , PALETTERGB ( 64,224,208)},
579 {"cyan" , PALETTERGB ( 0,255,255)},
580 {"light cyan" , PALETTERGB (224,255,255)},
581 {"LightCyan" , PALETTERGB (224,255,255)},
582 {"cadet blue" , PALETTERGB ( 95,158,160)},
583 {"CadetBlue" , PALETTERGB ( 95,158,160)},
584 {"medium aquamarine" , PALETTERGB (102,205,170)},
585 {"MediumAquamarine" , PALETTERGB (102,205,170)},
586 {"aquamarine" , PALETTERGB (127,255,212)},
587 {"dark green" , PALETTERGB ( 0,100, 0)},
588 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
589 {"dark olive green" , PALETTERGB ( 85,107, 47)},
590 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
591 {"dark sea green" , PALETTERGB (143,188,143)},
592 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
593 {"sea green" , PALETTERGB ( 46,139, 87)},
594 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
595 {"medium sea green" , PALETTERGB ( 60,179,113)},
596 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
597 {"light sea green" , PALETTERGB ( 32,178,170)},
598 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
599 {"pale green" , PALETTERGB (152,251,152)},
600 {"PaleGreen" , PALETTERGB (152,251,152)},
601 {"spring green" , PALETTERGB ( 0,255,127)},
602 {"SpringGreen" , PALETTERGB ( 0,255,127)},
603 {"lawn green" , PALETTERGB (124,252, 0)},
604 {"LawnGreen" , PALETTERGB (124,252, 0)},
605 {"green" , PALETTERGB ( 0,255, 0)},
606 {"chartreuse" , PALETTERGB (127,255, 0)},
607 {"medium spring green" , PALETTERGB ( 0,250,154)},
608 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
609 {"green yellow" , PALETTERGB (173,255, 47)},
610 {"GreenYellow" , PALETTERGB (173,255, 47)},
611 {"lime green" , PALETTERGB ( 50,205, 50)},
612 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
613 {"yellow green" , PALETTERGB (154,205, 50)},
614 {"YellowGreen" , PALETTERGB (154,205, 50)},
615 {"forest green" , PALETTERGB ( 34,139, 34)},
616 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
617 {"olive drab" , PALETTERGB (107,142, 35)},
618 {"OliveDrab" , PALETTERGB (107,142, 35)},
619 {"dark khaki" , PALETTERGB (189,183,107)},
620 {"DarkKhaki" , PALETTERGB (189,183,107)},
621 {"khaki" , PALETTERGB (240,230,140)},
622 {"pale goldenrod" , PALETTERGB (238,232,170)},
623 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
624 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
625 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
626 {"light yellow" , PALETTERGB (255,255,224)},
627 {"LightYellow" , PALETTERGB (255,255,224)},
628 {"yellow" , PALETTERGB (255,255, 0)},
629 {"gold" , PALETTERGB (255,215, 0)},
630 {"light goldenrod" , PALETTERGB (238,221,130)},
631 {"LightGoldenrod" , PALETTERGB (238,221,130)},
632 {"goldenrod" , PALETTERGB (218,165, 32)},
633 {"dark goldenrod" , PALETTERGB (184,134, 11)},
634 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
635 {"rosy brown" , PALETTERGB (188,143,143)},
636 {"RosyBrown" , PALETTERGB (188,143,143)},
637 {"indian red" , PALETTERGB (205, 92, 92)},
638 {"IndianRed" , PALETTERGB (205, 92, 92)},
639 {"saddle brown" , PALETTERGB (139, 69, 19)},
640 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
641 {"sienna" , PALETTERGB (160, 82, 45)},
642 {"peru" , PALETTERGB (205,133, 63)},
643 {"burlywood" , PALETTERGB (222,184,135)},
644 {"beige" , PALETTERGB (245,245,220)},
645 {"wheat" , PALETTERGB (245,222,179)},
646 {"sandy brown" , PALETTERGB (244,164, 96)},
647 {"SandyBrown" , PALETTERGB (244,164, 96)},
648 {"tan" , PALETTERGB (210,180,140)},
649 {"chocolate" , PALETTERGB (210,105, 30)},
650 {"firebrick" , PALETTERGB (178,34, 34)},
651 {"brown" , PALETTERGB (165,42, 42)},
652 {"dark salmon" , PALETTERGB (233,150,122)},
653 {"DarkSalmon" , PALETTERGB (233,150,122)},
654 {"salmon" , PALETTERGB (250,128,114)},
655 {"light salmon" , PALETTERGB (255,160,122)},
656 {"LightSalmon" , PALETTERGB (255,160,122)},
657 {"orange" , PALETTERGB (255,165, 0)},
658 {"dark orange" , PALETTERGB (255,140, 0)},
659 {"DarkOrange" , PALETTERGB (255,140, 0)},
660 {"coral" , PALETTERGB (255,127, 80)},
661 {"light coral" , PALETTERGB (240,128,128)},
662 {"LightCoral" , PALETTERGB (240,128,128)},
663 {"tomato" , PALETTERGB (255, 99, 71)},
664 {"orange red" , PALETTERGB (255, 69, 0)},
665 {"OrangeRed" , PALETTERGB (255, 69, 0)},
666 {"red" , PALETTERGB (255, 0, 0)},
667 {"hot pink" , PALETTERGB (255,105,180)},
668 {"HotPink" , PALETTERGB (255,105,180)},
669 {"deep pink" , PALETTERGB (255, 20,147)},
670 {"DeepPink" , PALETTERGB (255, 20,147)},
671 {"pink" , PALETTERGB (255,192,203)},
672 {"light pink" , PALETTERGB (255,182,193)},
673 {"LightPink" , PALETTERGB (255,182,193)},
674 {"pale violet red" , PALETTERGB (219,112,147)},
675 {"PaleVioletRed" , PALETTERGB (219,112,147)},
676 {"maroon" , PALETTERGB (176, 48, 96)},
677 {"medium violet red" , PALETTERGB (199, 21,133)},
678 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
679 {"violet red" , PALETTERGB (208, 32,144)},
680 {"VioletRed" , PALETTERGB (208, 32,144)},
681 {"magenta" , PALETTERGB (255, 0,255)},
682 {"violet" , PALETTERGB (238,130,238)},
683 {"plum" , PALETTERGB (221,160,221)},
684 {"orchid" , PALETTERGB (218,112,214)},
685 {"medium orchid" , PALETTERGB (186, 85,211)},
686 {"MediumOrchid" , PALETTERGB (186, 85,211)},
687 {"dark orchid" , PALETTERGB (153, 50,204)},
688 {"DarkOrchid" , PALETTERGB (153, 50,204)},
689 {"dark violet" , PALETTERGB (148, 0,211)},
690 {"DarkViolet" , PALETTERGB (148, 0,211)},
691 {"blue violet" , PALETTERGB (138, 43,226)},
692 {"BlueViolet" , PALETTERGB (138, 43,226)},
693 {"purple" , PALETTERGB (160, 32,240)},
694 {"medium purple" , PALETTERGB (147,112,219)},
695 {"MediumPurple" , PALETTERGB (147,112,219)},
696 {"thistle" , PALETTERGB (216,191,216)},
697 {"gray0" , PALETTERGB ( 0, 0, 0)},
698 {"grey0" , PALETTERGB ( 0, 0, 0)},
699 {"dark grey" , PALETTERGB (169,169,169)},
700 {"DarkGrey" , PALETTERGB (169,169,169)},
701 {"dark gray" , PALETTERGB (169,169,169)},
702 {"DarkGray" , PALETTERGB (169,169,169)},
703 {"dark blue" , PALETTERGB ( 0, 0,139)},
704 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
705 {"dark cyan" , PALETTERGB ( 0,139,139)},
706 {"DarkCyan" , PALETTERGB ( 0,139,139)},
707 {"dark magenta" , PALETTERGB (139, 0,139)},
708 {"DarkMagenta" , PALETTERGB (139, 0,139)},
709 {"dark red" , PALETTERGB (139, 0, 0)},
710 {"DarkRed" , PALETTERGB (139, 0, 0)},
711 {"light green" , PALETTERGB (144,238,144)},
712 {"LightGreen" , PALETTERGB (144,238,144)},
716 w32_default_color_map (void)
719 colormap_t
*pc
= w32_color_map
;
726 for (i
= 0; i
< sizeof (w32_color_map
) / sizeof (w32_color_map
[0]);
728 cmap
= Fcons (Fcons (build_string (pc
->name
),
729 make_number (pc
->colorref
)),
737 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
738 0, 0, 0, doc
: /* Return the default color map. */)
741 return w32_default_color_map ();
745 w32_color_map_lookup (const char *colorname
)
747 Lisp_Object tail
, ret
= Qnil
;
751 for (tail
= Vw32_color_map
; CONSP (tail
); tail
= XCDR (tail
))
753 register Lisp_Object elt
, tem
;
756 if (!CONSP (elt
)) continue;
760 if (lstrcmpi (SDATA (tem
), colorname
) == 0)
776 add_system_logical_colors_to_map (Lisp_Object
*system_colors
)
780 /* Other registry operations are done with input blocked. */
783 /* Look for "Control Panel/Colors" under User and Machine registry
785 if (RegOpenKeyEx (HKEY_CURRENT_USER
, "Control Panel\\Colors", 0,
786 KEY_READ
, &colors_key
) == ERROR_SUCCESS
787 || RegOpenKeyEx (HKEY_LOCAL_MACHINE
, "Control Panel\\Colors", 0,
788 KEY_READ
, &colors_key
) == ERROR_SUCCESS
)
791 char color_buffer
[64];
792 char full_name_buffer
[MAX_PATH
+ SYSTEM_COLOR_PREFIX_LEN
];
794 DWORD name_size
, color_size
;
795 char *name_buffer
= full_name_buffer
+ SYSTEM_COLOR_PREFIX_LEN
;
797 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
798 color_size
= sizeof (color_buffer
);
800 strcpy (full_name_buffer
, SYSTEM_COLOR_PREFIX
);
802 while (RegEnumValueA (colors_key
, index
, name_buffer
, &name_size
,
803 NULL
, NULL
, color_buffer
, &color_size
)
807 if (sscanf (color_buffer
, " %u %u %u", &r
, &g
, &b
) == 3)
808 *system_colors
= Fcons (Fcons (build_string (full_name_buffer
),
809 make_number (RGB (r
, g
, b
))),
812 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
813 color_size
= sizeof (color_buffer
);
816 RegCloseKey (colors_key
);
824 x_to_w32_color (const char * colorname
)
826 register Lisp_Object ret
= Qnil
;
830 if (colorname
[0] == '#')
832 /* Could be an old-style RGB Device specification. */
833 int size
= strlen (colorname
+ 1);
834 char *color
= alloca (size
+ 1);
836 strcpy (color
, colorname
+ 1);
837 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
845 for (i
= 0; i
< 3; i
++)
851 /* The check for 'x' in the following conditional takes into
852 account the fact that strtol allows a "0x" in front of
853 our numbers, and we don't. */
854 if (!isxdigit (color
[0]) || color
[1] == 'x')
858 value
= strtoul (color
, &end
, 16);
860 if (errno
== ERANGE
|| end
- color
!= size
)
865 value
= value
* 0x10;
876 colorval
|= (value
<< pos
);
881 XSETINT (ret
, colorval
);
888 else if (strnicmp (colorname
, "rgb:", 4) == 0)
896 color
= colorname
+ 4;
897 for (i
= 0; i
< 3; i
++)
902 /* The check for 'x' in the following conditional takes into
903 account the fact that strtol allows a "0x" in front of
904 our numbers, and we don't. */
905 if (!isxdigit (color
[0]) || color
[1] == 'x')
907 value
= strtoul (color
, &end
, 16);
913 value
= value
* 0x10 + value
;
926 if (value
== ULONG_MAX
)
928 colorval
|= (value
<< pos
);
935 XSETINT (ret
, colorval
);
943 else if (strnicmp (colorname
, "rgbi:", 5) == 0)
945 /* This is an RGB Intensity specification. */
952 color
= colorname
+ 5;
953 for (i
= 0; i
< 3; i
++)
959 value
= strtod (color
, &end
);
962 if (value
< 0.0 || value
> 1.0)
964 val
= (UINT
)(0x100 * value
);
965 /* We used 0x100 instead of 0xFF to give a continuous
966 range between 0.0 and 1.0 inclusive. The next statement
967 fixes the 1.0 case. */
970 colorval
|= (val
<< pos
);
977 XSETINT (ret
, colorval
);
985 /* I am not going to attempt to handle any of the CIE color schemes
986 or TekHVC, since I don't know the algorithms for conversion to
989 /* If we fail to lookup the color name in w32_color_map, then check the
990 colorname to see if it can be crudely approximated: If the X color
991 ends in a number (e.g., "darkseagreen2"), strip the number and
992 return the result of looking up the base color name. */
993 ret
= w32_color_map_lookup (colorname
);
996 int len
= strlen (colorname
);
998 if (isdigit (colorname
[len
- 1]))
1000 char *ptr
, *approx
= alloca (len
+ 1);
1002 strcpy (approx
, colorname
);
1003 ptr
= &approx
[len
- 1];
1004 while (ptr
> approx
&& isdigit (*ptr
))
1007 ret
= w32_color_map_lookup (approx
);
1016 w32_regenerate_palette (struct frame
*f
)
1018 struct w32_palette_entry
* list
;
1019 LOGPALETTE
* log_palette
;
1020 HPALETTE new_palette
;
1023 /* don't bother trying to create palette if not supported */
1024 if (! FRAME_DISPLAY_INFO (f
)->has_palette
)
1027 log_palette
= (LOGPALETTE
*)
1028 alloca (sizeof (LOGPALETTE
) +
1029 FRAME_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
1030 log_palette
->palVersion
= 0x300;
1031 log_palette
->palNumEntries
= FRAME_DISPLAY_INFO (f
)->num_colors
;
1033 list
= FRAME_DISPLAY_INFO (f
)->color_list
;
1035 i
< FRAME_DISPLAY_INFO (f
)->num_colors
;
1036 i
++, list
= list
->next
)
1037 log_palette
->palPalEntry
[i
] = list
->entry
;
1039 new_palette
= CreatePalette (log_palette
);
1043 if (FRAME_DISPLAY_INFO (f
)->palette
)
1044 DeleteObject (FRAME_DISPLAY_INFO (f
)->palette
);
1045 FRAME_DISPLAY_INFO (f
)->palette
= new_palette
;
1047 /* Realize display palette and garbage all frames. */
1048 release_frame_dc (f
, get_frame_dc (f
));
1053 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
1054 #define SET_W32_COLOR(pe, color) \
1057 pe.peRed = GetRValue (color); \
1058 pe.peGreen = GetGValue (color); \
1059 pe.peBlue = GetBValue (color); \
1064 /* Keep these around in case we ever want to track color usage. */
1066 w32_map_color (struct frame
*f
, COLORREF color
)
1068 struct w32_palette_entry
* list
= FRAME_DISPLAY_INFO (f
)->color_list
;
1070 if (NILP (Vw32_enable_palette
))
1073 /* check if color is already mapped */
1076 if (W32_COLOR (list
->entry
) == color
)
1084 /* not already mapped, so add to list and recreate Windows palette */
1085 list
= xmalloc (sizeof (struct w32_palette_entry
));
1086 SET_W32_COLOR (list
->entry
, color
);
1088 list
->next
= FRAME_DISPLAY_INFO (f
)->color_list
;
1089 FRAME_DISPLAY_INFO (f
)->color_list
= list
;
1090 FRAME_DISPLAY_INFO (f
)->num_colors
++;
1092 /* set flag that palette must be regenerated */
1093 FRAME_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1097 w32_unmap_color (struct frame
*f
, COLORREF color
)
1099 struct w32_palette_entry
* list
= FRAME_DISPLAY_INFO (f
)->color_list
;
1100 struct w32_palette_entry
**prev
= &FRAME_DISPLAY_INFO (f
)->color_list
;
1102 if (NILP (Vw32_enable_palette
))
1105 /* check if color is already mapped */
1108 if (W32_COLOR (list
->entry
) == color
)
1110 if (--list
->refcount
== 0)
1114 FRAME_DISPLAY_INFO (f
)->num_colors
--;
1124 /* set flag that palette must be regenerated */
1125 FRAME_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1130 /* Gamma-correct COLOR on frame F. */
1133 gamma_correct (struct frame
*f
, COLORREF
*color
)
1137 *color
= PALETTERGB (
1138 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1139 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1140 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1145 /* Decide if color named COLOR is valid for the display associated with
1146 the selected frame; if so, return the rgb values in COLOR_DEF.
1147 If ALLOC is nonzero, allocate a new colormap cell. */
1150 w32_defined_color (struct frame
*f
, const char *color
, XColor
*color_def
, int alloc
)
1152 register Lisp_Object tem
;
1153 COLORREF w32_color_ref
;
1155 tem
= x_to_w32_color (color
);
1161 /* Apply gamma correction. */
1162 w32_color_ref
= XUINT (tem
);
1163 gamma_correct (f
, &w32_color_ref
);
1164 XSETINT (tem
, w32_color_ref
);
1167 /* Map this color to the palette if it is enabled. */
1168 if (!NILP (Vw32_enable_palette
))
1170 struct w32_palette_entry
* entry
=
1171 one_w32_display_info
.color_list
;
1172 struct w32_palette_entry
** prev
=
1173 &one_w32_display_info
.color_list
;
1175 /* check if color is already mapped */
1178 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1180 prev
= &entry
->next
;
1181 entry
= entry
->next
;
1184 if (entry
== NULL
&& alloc
)
1186 /* not already mapped, so add to list */
1187 entry
= xmalloc (sizeof (struct w32_palette_entry
));
1188 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1191 one_w32_display_info
.num_colors
++;
1193 /* set flag that palette must be regenerated */
1194 one_w32_display_info
.regen_palette
= TRUE
;
1197 /* Ensure COLORREF value is snapped to nearest color in (default)
1198 palette by simulating the PALETTERGB macro. This works whether
1199 or not the display device has a palette. */
1200 w32_color_ref
= XUINT (tem
) | 0x2000000;
1202 color_def
->pixel
= w32_color_ref
;
1203 color_def
->red
= GetRValue (w32_color_ref
) * 256;
1204 color_def
->green
= GetGValue (w32_color_ref
) * 256;
1205 color_def
->blue
= GetBValue (w32_color_ref
) * 256;
1215 /* Given a string ARG naming a color, compute a pixel value from it
1216 suitable for screen F.
1217 If F is not a color screen, return DEF (default) regardless of what
1221 x_decode_color (struct frame
*f
, Lisp_Object arg
, int def
)
1227 if (strcmp (SDATA (arg
), "black") == 0)
1228 return BLACK_PIX_DEFAULT (f
);
1229 else if (strcmp (SDATA (arg
), "white") == 0)
1230 return WHITE_PIX_DEFAULT (f
);
1232 if ((FRAME_DISPLAY_INFO (f
)->n_planes
* FRAME_DISPLAY_INFO (f
)->n_cbits
) == 1)
1235 /* w32_defined_color is responsible for coping with failures
1236 by looking for a near-miss. */
1237 if (w32_defined_color (f
, SDATA (arg
), &cdef
, 1))
1240 /* defined_color failed; return an ultimate default. */
1246 /* Functions called only from `x_set_frame_param'
1247 to set individual parameters.
1249 If FRAME_W32_WINDOW (f) is 0,
1250 the frame is being created and its window does not exist yet.
1251 In that case, just record the parameter's new value
1252 in the standard place; do not attempt to change the window. */
1255 x_set_foreground_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1257 struct w32_output
*x
= f
->output_data
.w32
;
1258 PIX_TYPE fg
, old_fg
;
1260 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1261 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
1262 FRAME_FOREGROUND_PIXEL (f
) = fg
;
1264 if (FRAME_W32_WINDOW (f
) != 0)
1266 if (x
->cursor_pixel
== old_fg
)
1268 x
->cursor_pixel
= fg
;
1269 x
->cursor_gc
->background
= fg
;
1272 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
1273 if (FRAME_VISIBLE_P (f
))
1279 x_set_background_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1281 FRAME_BACKGROUND_PIXEL (f
)
1282 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
1284 if (FRAME_W32_WINDOW (f
) != 0)
1286 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
1287 FRAME_BACKGROUND_PIXEL (f
));
1289 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
1291 if (FRAME_VISIBLE_P (f
))
1297 x_set_mouse_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1299 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
1303 if (!EQ (Qnil
, arg
))
1304 f
->output_data
.w32
->mouse_pixel
1305 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1306 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
1308 /* Don't let pointers be invisible. */
1309 if (mask_color
== f
->output_data
.w32
->mouse_pixel
1310 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
1311 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
1313 #if 0 /* TODO : Mouse cursor customization. */
1316 /* It's not okay to crash if the user selects a screwy cursor. */
1317 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
1319 if (!EQ (Qnil
, Vx_pointer_shape
))
1321 CHECK_NUMBER (Vx_pointer_shape
);
1322 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
1325 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1326 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
1328 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
1330 CHECK_NUMBER (Vx_nontext_pointer_shape
);
1331 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1332 XINT (Vx_nontext_pointer_shape
));
1335 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
1336 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1338 if (!EQ (Qnil
, Vx_hourglass_pointer_shape
))
1340 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
1341 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1342 XINT (Vx_hourglass_pointer_shape
));
1345 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
1346 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
1348 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1349 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
1351 CHECK_NUMBER (Vx_mode_pointer_shape
);
1352 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1353 XINT (Vx_mode_pointer_shape
));
1356 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1357 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
1359 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
1361 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
1363 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1364 XINT (Vx_sensitive_text_pointer_shape
));
1367 hand_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
1369 if (!NILP (Vx_window_horizontal_drag_shape
))
1371 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
1372 horizontal_drag_cursor
1373 = XCreateFontCursor (FRAME_X_DISPLAY (f
),
1374 XINT (Vx_window_horizontal_drag_shape
));
1377 horizontal_drag_cursor
1378 = XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_sb_h_double_arrow
);
1380 if (!NILP (Vx_window_vertical_drag_shape
))
1382 CHECK_NUMBER (Vx_window_vertical_drag_shape
);
1383 vertical_drag_cursor
1384 = XCreateFontCursor (FRAME_X_DISPLAY (f
),
1385 XINT (Vx_window_vertical_drag_shape
));
1388 vertical_drag_cursor
1389 = XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_sb_v_double_arrow
);
1391 /* Check and report errors with the above calls. */
1392 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
1393 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
1396 XColor fore_color
, back_color
;
1398 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
1399 back_color
.pixel
= mask_color
;
1400 XQueryColor (FRAME_W32_DISPLAY (f
),
1401 DefaultColormap (FRAME_W32_DISPLAY (f
),
1402 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1404 XQueryColor (FRAME_W32_DISPLAY (f
),
1405 DefaultColormap (FRAME_W32_DISPLAY (f
),
1406 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1408 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
1409 &fore_color
, &back_color
);
1410 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
1411 &fore_color
, &back_color
);
1412 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
1413 &fore_color
, &back_color
);
1414 XRecolorCursor (FRAME_W32_DISPLAY (f
), hand_cursor
,
1415 &fore_color
, &back_color
);
1416 XRecolorCursor (FRAME_W32_DISPLAY (f
), hourglass_cursor
,
1417 &fore_color
, &back_color
);
1420 if (FRAME_W32_WINDOW (f
) != 0)
1421 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
1423 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
1424 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
1425 f
->output_data
.w32
->text_cursor
= cursor
;
1427 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
1428 && f
->output_data
.w32
->nontext_cursor
!= 0)
1429 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
1430 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
1432 if (hourglass_cursor
!= f
->output_data
.w32
->hourglass_cursor
1433 && f
->output_data
.w32
->hourglass_cursor
!= 0)
1434 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hourglass_cursor
);
1435 f
->output_data
.w32
->hourglass_cursor
= hourglass_cursor
;
1437 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
1438 && f
->output_data
.w32
->modeline_cursor
!= 0)
1439 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
1440 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
1442 if (hand_cursor
!= f
->output_data
.w32
->hand_cursor
1443 && f
->output_data
.w32
->hand_cursor
!= 0)
1444 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hand_cursor
);
1445 f
->output_data
.w32
->hand_cursor
= hand_cursor
;
1447 XFlush (FRAME_W32_DISPLAY (f
));
1450 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1455 x_set_cursor_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1457 unsigned long fore_pixel
, pixel
;
1459 if (!NILP (Vx_cursor_fore_pixel
))
1460 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1461 WHITE_PIX_DEFAULT (f
));
1463 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1465 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1467 /* Make sure that the cursor color differs from the background color. */
1468 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
1470 pixel
= f
->output_data
.w32
->mouse_pixel
;
1471 if (pixel
== fore_pixel
)
1472 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1475 f
->output_data
.w32
->cursor_foreground_pixel
= fore_pixel
;
1476 f
->output_data
.w32
->cursor_pixel
= pixel
;
1478 if (FRAME_W32_WINDOW (f
) != 0)
1481 /* Update frame's cursor_gc. */
1482 f
->output_data
.w32
->cursor_gc
->foreground
= fore_pixel
;
1483 f
->output_data
.w32
->cursor_gc
->background
= pixel
;
1487 if (FRAME_VISIBLE_P (f
))
1489 x_update_cursor (f
, 0);
1490 x_update_cursor (f
, 1);
1494 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1497 /* Set the border-color of frame F to pixel value PIX.
1498 Note that this does not fully take effect if done before
1502 x_set_border_pixel (struct frame
*f
, int pix
)
1505 f
->output_data
.w32
->border_pixel
= pix
;
1507 if (FRAME_W32_WINDOW (f
) != 0 && f
->border_width
> 0)
1509 if (FRAME_VISIBLE_P (f
))
1514 /* Set the border-color of frame F to value described by ARG.
1515 ARG can be a string naming a color.
1516 The border-color is used for the border that is drawn by the server.
1517 Note that this does not fully take effect if done before
1518 F has a window; it must be redone when the window is created. */
1521 x_set_border_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1526 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1527 x_set_border_pixel (f
, pix
);
1528 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1533 x_set_cursor_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1535 set_frame_cursor_types (f
, arg
);
1539 x_set_icon_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1543 if (NILP (arg
) && NILP (oldval
))
1546 if (STRINGP (arg
) && STRINGP (oldval
)
1547 && EQ (Fstring_equal (oldval
, arg
), Qt
))
1550 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
1555 result
= x_bitmap_icon (f
, arg
);
1559 error ("No icon window available");
1566 x_set_icon_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1570 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1573 else if (!NILP (arg
) || NILP (oldval
))
1576 fset_icon_name (f
, arg
);
1579 if (f
->output_data
.w32
->icon_bitmap
!= 0)
1584 result
= x_text_icon (f
,
1585 SSDATA ((!NILP (f
->icon_name
)
1594 error ("No icon window available");
1597 /* If the window was unmapped (and its icon was mapped),
1598 the new icon is not mapped, so map the window in its stead. */
1599 if (FRAME_VISIBLE_P (f
))
1601 #ifdef USE_X_TOOLKIT
1602 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
1604 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
1607 XFlush (FRAME_W32_DISPLAY (f
));
1614 x_set_menu_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1618 /* Right now, menu bars don't work properly in minibuf-only frames;
1619 most of the commands try to apply themselves to the minibuffer
1620 frame itself, and get an error because you can't switch buffers
1621 in or split the minibuffer window. */
1622 if (FRAME_MINIBUF_ONLY_P (f
))
1625 if (INTEGERP (value
))
1626 nlines
= XINT (value
);
1630 FRAME_MENU_BAR_LINES (f
) = 0;
1631 FRAME_MENU_BAR_HEIGHT (f
) = 0;
1633 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1636 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1637 free_frame_menubar (f
);
1638 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1640 /* Adjust the frame size so that the client (text) dimensions
1641 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
1643 x_set_window_size (f
, 0, FRAME_TEXT_WIDTH (f
), FRAME_TEXT_HEIGHT (f
), 1);
1644 do_pending_window_change (0);
1646 adjust_frame_glyphs (f
);
1650 /* Set the number of lines used for the tool bar of frame F to VALUE.
1651 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL is
1652 the old number of tool bar lines (and is unused). This function may
1653 change the height of all windows on frame F to match the new tool bar
1654 height. By design, the frame's height doesn't change (but maybe it
1655 should if we don't get enough space otherwise). */
1658 x_set_tool_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1660 int delta
, nlines
, root_height
;
1661 int unit
= FRAME_LINE_HEIGHT (f
);
1663 /* Treat tool bars like menu bars. */
1664 if (FRAME_MINIBUF_ONLY_P (f
))
1667 /* Use VALUE only if an integer >= 0. */
1668 if (INTEGERP (value
) && XINT (value
) >= 0)
1669 nlines
= XFASTINT (value
);
1673 /* Make sure we redisplay all windows in this frame. */
1674 windows_or_buffers_changed
= 23;
1676 /* DELTA is in pixels now. */
1677 delta
= (nlines
- FRAME_TOOL_BAR_LINES (f
)) * unit
;
1679 /* Don't resize the tool-bar to more than we have room for. Note: The
1680 calculations below and the subsequent call to resize_frame_windows
1681 are inherently flawed because they can make the toolbar higher than
1682 the containing frame. */
1685 root_height
= WINDOW_PIXEL_HEIGHT (XWINDOW (FRAME_ROOT_WINDOW (f
)));
1686 if (root_height
- delta
< unit
)
1688 delta
= root_height
- unit
;
1689 /* When creating a new frame and toolbar mode is enabled, we
1690 need at least one toolbar line. */
1691 nlines
= max (FRAME_TOOL_BAR_LINES (f
) + delta
/ unit
, 1);
1695 FRAME_TOOL_BAR_LINES (f
) = nlines
;
1696 FRAME_TOOL_BAR_HEIGHT (f
) = nlines
* FRAME_LINE_HEIGHT (f
);
1697 ++windows_or_buffers_changed
;
1698 resize_frame_windows (f
, FRAME_TEXT_HEIGHT (f
), 0, 1);
1699 adjust_frame_glyphs (f
);
1701 /* We also have to make sure that the internal border at the top of
1702 the frame, below the menu bar or tool bar, is redrawn when the
1703 tool bar disappears. This is so because the internal border is
1704 below the tool bar if one is displayed, but is below the menu bar
1705 if there isn't a tool bar. The tool bar draws into the area
1706 below the menu bar. */
1707 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_HEIGHT (f
) == 0)
1710 clear_current_matrices (f
);
1713 /* If the tool bar gets smaller, the internal border below it
1714 has to be cleared. It was formerly part of the display
1715 of the larger tool bar, and updating windows won't clear it. */
1716 if (FRAME_INTERNAL_BORDER_WIDTH (f
) != 0 && FRAME_VISIBLE_P (f
))
1718 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1719 int width
= FRAME_PIXEL_WIDTH (f
);
1720 int y
= nlines
* unit
;
1721 HDC hdc
= get_frame_dc (f
);
1724 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
1725 release_frame_dc (f
, hdc
);
1729 if (delta
< 0 && WINDOWP (f
->tool_bar_window
))
1730 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1732 run_window_configuration_change_hook (f
);
1736 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1739 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1740 name; if NAME is a string, set F's name to NAME and set
1741 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1743 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1744 suggesting a new name, which lisp code should override; if
1745 F->explicit_name is set, ignore the new name; otherwise, set it. */
1748 x_set_name (struct frame
*f
, Lisp_Object name
, int explicit)
1750 /* Make sure that requests from lisp code override requests from
1751 Emacs redisplay code. */
1754 /* If we're switching from explicit to implicit, we had better
1755 update the mode lines and thereby update the title. */
1756 if (f
->explicit_name
&& NILP (name
))
1757 update_mode_lines
= 25;
1759 f
->explicit_name
= ! NILP (name
);
1761 else if (f
->explicit_name
)
1764 /* If NAME is nil, set the name to the w32_id_name. */
1767 /* Check for no change needed in this very common case
1768 before we do any consing. */
1769 if (!strcmp (FRAME_DISPLAY_INFO (f
)->w32_id_name
,
1772 name
= build_string (FRAME_DISPLAY_INFO (f
)->w32_id_name
);
1775 CHECK_STRING (name
);
1777 /* Don't change the name if it's already NAME. */
1778 if (! NILP (Fstring_equal (name
, f
->name
)))
1781 fset_name (f
, name
);
1783 /* For setting the frame title, the title parameter should override
1784 the name parameter. */
1785 if (! NILP (f
->title
))
1788 if (FRAME_W32_WINDOW (f
))
1791 GUI_FN (SetWindowText
) (FRAME_W32_WINDOW (f
),
1792 GUI_SDATA (GUI_ENCODE_SYSTEM (name
)));
1797 /* This function should be called when the user's lisp code has
1798 specified a name for the frame; the name will override any set by the
1801 x_explicitly_set_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1803 x_set_name (f
, arg
, 1);
1806 /* This function should be called by Emacs redisplay code to set the
1807 name; names set this way will never override names set by the user's
1810 x_implicitly_set_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1812 x_set_name (f
, arg
, 0);
1815 /* Change the title of frame F to NAME.
1816 If NAME is nil, use the frame name as the title. */
1819 x_set_title (struct frame
*f
, Lisp_Object name
, Lisp_Object old_name
)
1821 /* Don't change the title if it's already NAME. */
1822 if (EQ (name
, f
->title
))
1825 update_mode_lines
= 26;
1827 fset_title (f
, name
);
1832 if (FRAME_W32_WINDOW (f
))
1835 GUI_FN (SetWindowText
) (FRAME_W32_WINDOW (f
),
1836 GUI_SDATA (GUI_ENCODE_SYSTEM (name
)));
1842 x_set_scroll_bar_default_width (struct frame
*f
)
1844 int unit
= FRAME_COLUMN_WIDTH (f
);
1846 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
1847 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
1848 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + unit
- 1) / unit
;
1852 /* Subroutines for creating a frame. */
1855 w32_load_cursor (LPCTSTR name
)
1857 /* Try first to load cursor from application resource. */
1858 Cursor cursor
= LoadImage ((HINSTANCE
) GetModuleHandle (NULL
),
1859 name
, IMAGE_CURSOR
, 0, 0,
1860 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
1863 /* Then try to load a shared predefined cursor. */
1864 cursor
= LoadImage (NULL
, name
, IMAGE_CURSOR
, 0, 0,
1865 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
1870 static LRESULT CALLBACK
w32_wnd_proc (HWND
, UINT
, WPARAM
, LPARAM
);
1872 #define INIT_WINDOW_CLASS(WC) \
1873 (WC).style = CS_HREDRAW | CS_VREDRAW; \
1874 (WC).lpfnWndProc = (WNDPROC) w32_wnd_proc; \
1875 (WC).cbClsExtra = 0; \
1876 (WC).cbWndExtra = WND_EXTRA_BYTES; \
1877 (WC).hInstance = hinst; \
1878 (WC).hIcon = LoadIcon (hinst, EMACS_CLASS); \
1879 (WC).hCursor = w32_load_cursor (IDC_ARROW); \
1880 (WC).hbrBackground = NULL; \
1881 (WC).lpszMenuName = NULL; \
1884 w32_init_class (HINSTANCE hinst
)
1886 if (w32_unicode_gui
)
1889 INIT_WINDOW_CLASS(uwc
);
1890 uwc
.lpszClassName
= L
"Emacs";
1892 return RegisterClassW (&uwc
);
1897 INIT_WINDOW_CLASS(wc
);
1898 wc
.lpszClassName
= EMACS_CLASS
;
1900 return RegisterClassA (&wc
);
1905 w32_createscrollbar (struct frame
*f
, struct scroll_bar
* bar
)
1907 return CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
1908 /* Position and size of scroll bar. */
1909 bar
->left
, bar
->top
, bar
->width
, bar
->height
,
1910 FRAME_W32_WINDOW (f
), NULL
, hinst
, NULL
);
1914 w32_createwindow (struct frame
*f
, int *coords
)
1921 rect
.left
= rect
.top
= 0;
1922 rect
.right
= FRAME_PIXEL_WIDTH (f
);
1923 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
1925 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
1926 FRAME_EXTERNAL_MENU_BAR (f
));
1928 /* Do first time app init */
1930 w32_init_class (hinst
);
1932 if (f
->size_hint_flags
& USPosition
|| f
->size_hint_flags
& PPosition
)
1943 FRAME_W32_WINDOW (f
) = hwnd
1944 = CreateWindow (EMACS_CLASS
,
1946 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
1948 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
1956 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
1957 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
1958 SetWindowLong (hwnd
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
1959 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, FRAME_SCROLL_BAR_AREA_WIDTH (f
));
1960 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
1962 /* Enable drag-n-drop. */
1963 DragAcceptFiles (hwnd
, TRUE
);
1965 /* Do this to discard the default setting specified by our parent. */
1966 ShowWindow (hwnd
, SW_HIDE
);
1968 /* Update frame positions. */
1969 GetWindowRect (hwnd
, &rect
);
1970 f
->left_pos
= rect
.left
;
1971 f
->top_pos
= rect
.top
;
1976 my_post_msg (W32Msg
* wmsg
, HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1978 wmsg
->msg
.hwnd
= hwnd
;
1979 wmsg
->msg
.message
= msg
;
1980 wmsg
->msg
.wParam
= wParam
;
1981 wmsg
->msg
.lParam
= lParam
;
1982 wmsg
->msg
.time
= GetMessageTime ();
1987 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
1988 between left and right keys as advertised. We test for this
1989 support dynamically, and set a flag when the support is absent. If
1990 absent, we keep track of the left and right control and alt keys
1991 ourselves. This is particularly necessary on keyboards that rely
1992 upon the AltGr key, which is represented as having the left control
1993 and right alt keys pressed. For these keyboards, we need to know
1994 when the left alt key has been pressed in addition to the AltGr key
1995 so that we can properly support M-AltGr-key sequences (such as M-@
1996 on Swedish keyboards). */
1998 #define EMACS_LCONTROL 0
1999 #define EMACS_RCONTROL 1
2000 #define EMACS_LMENU 2
2001 #define EMACS_RMENU 3
2003 static int modifiers
[4];
2004 static int modifiers_recorded
;
2005 static int modifier_key_support_tested
;
2008 test_modifier_support (unsigned int wparam
)
2012 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
2014 if (wparam
== VK_CONTROL
)
2024 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
2025 modifiers_recorded
= 1;
2027 modifiers_recorded
= 0;
2028 modifier_key_support_tested
= 1;
2032 record_keydown (unsigned int wparam
, unsigned int lparam
)
2036 if (!modifier_key_support_tested
)
2037 test_modifier_support (wparam
);
2039 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2042 if (wparam
== VK_CONTROL
)
2043 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2045 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2051 record_keyup (unsigned int wparam
, unsigned int lparam
)
2055 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2058 if (wparam
== VK_CONTROL
)
2059 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2061 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2066 /* Emacs can lose focus while a modifier key has been pressed. When
2067 it regains focus, be conservative and clear all modifiers since
2068 we cannot reconstruct the left and right modifier state. */
2070 reset_modifiers (void)
2074 if (GetFocus () == NULL
)
2075 /* Emacs doesn't have keyboard focus. Do nothing. */
2078 ctrl
= GetAsyncKeyState (VK_CONTROL
);
2079 alt
= GetAsyncKeyState (VK_MENU
);
2081 if (!(ctrl
& 0x08000))
2082 /* Clear any recorded control modifier state. */
2083 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2085 if (!(alt
& 0x08000))
2086 /* Clear any recorded alt modifier state. */
2087 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2089 /* Update the state of all modifier keys, because modifiers used in
2090 hot-key combinations can get stuck on if Emacs loses focus as a
2091 result of a hot-key being pressed. */
2095 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
2097 memset (keystate
, 0, sizeof (keystate
));
2098 GetKeyboardState (keystate
);
2099 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
2100 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
2101 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
2102 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
2103 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
2104 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
2105 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
2106 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
2107 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
2108 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
2109 SetKeyboardState (keystate
);
2113 /* Synchronize modifier state with what is reported with the current
2114 keystroke. Even if we cannot distinguish between left and right
2115 modifier keys, we know that, if no modifiers are set, then neither
2116 the left or right modifier should be set. */
2118 sync_modifiers (void)
2120 if (!modifiers_recorded
)
2123 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
2124 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2126 if (!(GetKeyState (VK_MENU
) & 0x8000))
2127 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2131 modifier_set (int vkey
)
2133 /* Warning: The fact that VK_NUMLOCK is not treated as the other 2
2134 toggle keys is not an omission! If you want to add it, you will
2135 have to make changes in the default sub-case of the WM_KEYDOWN
2136 switch, because if the NUMLOCK modifier is set, the code there
2137 will directly convert any key that looks like an ASCII letter,
2138 and also downcase those that look like upper-case ASCII. */
2139 if (vkey
== VK_CAPITAL
)
2141 if (NILP (Vw32_enable_caps_lock
))
2144 return (GetKeyState (vkey
) & 0x1);
2146 if (vkey
== VK_SCROLL
)
2148 if (NILP (Vw32_scroll_lock_modifier
)
2149 /* w32-scroll-lock-modifier can be any non-nil value that is
2150 not one of the modifiers, in which case it shall be ignored. */
2151 || !( EQ (Vw32_scroll_lock_modifier
, Qhyper
)
2152 || EQ (Vw32_scroll_lock_modifier
, Qsuper
)
2153 || EQ (Vw32_scroll_lock_modifier
, Qmeta
)
2154 || EQ (Vw32_scroll_lock_modifier
, Qalt
)
2155 || EQ (Vw32_scroll_lock_modifier
, Qcontrol
)
2156 || EQ (Vw32_scroll_lock_modifier
, Qshift
)))
2159 return (GetKeyState (vkey
) & 0x1);
2162 if (!modifiers_recorded
)
2163 return (GetKeyState (vkey
) & 0x8000);
2168 return modifiers
[EMACS_LCONTROL
];
2170 return modifiers
[EMACS_RCONTROL
];
2172 return modifiers
[EMACS_LMENU
];
2174 return modifiers
[EMACS_RMENU
];
2176 return (GetKeyState (vkey
) & 0x8000);
2179 /* Convert between the modifier bits W32 uses and the modifier bits
2183 w32_key_to_modifier (int key
)
2185 Lisp_Object key_mapping
;
2190 key_mapping
= Vw32_lwindow_modifier
;
2193 key_mapping
= Vw32_rwindow_modifier
;
2196 key_mapping
= Vw32_apps_modifier
;
2199 key_mapping
= Vw32_scroll_lock_modifier
;
2205 /* NB. This code runs in the input thread, asynchronously to the lisp
2206 thread, so we must be careful to ensure access to lisp data is
2207 thread-safe. The following code is safe because the modifier
2208 variable values are updated atomically from lisp and symbols are
2209 not relocated by GC. Also, we don't have to worry about seeing GC
2211 if (EQ (key_mapping
, Qhyper
))
2212 return hyper_modifier
;
2213 if (EQ (key_mapping
, Qsuper
))
2214 return super_modifier
;
2215 if (EQ (key_mapping
, Qmeta
))
2216 return meta_modifier
;
2217 if (EQ (key_mapping
, Qalt
))
2218 return alt_modifier
;
2219 if (EQ (key_mapping
, Qctrl
))
2220 return ctrl_modifier
;
2221 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
2222 return ctrl_modifier
;
2223 if (EQ (key_mapping
, Qshift
))
2224 return shift_modifier
;
2226 /* Don't generate any modifier if not explicitly requested. */
2231 w32_get_modifiers (void)
2233 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
2234 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
2235 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
2236 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
2237 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
2238 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
2239 (modifier_set (VK_MENU
) ?
2240 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
2243 /* We map the VK_* modifiers into console modifier constants
2244 so that we can use the same routines to handle both console
2245 and window input. */
2248 construct_console_modifiers (void)
2253 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
2254 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
2255 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
2256 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
2257 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
2258 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
2259 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
2260 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
2261 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
2262 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
2263 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
2269 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
2273 /* Convert to emacs modifiers. */
2274 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
2280 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
2282 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
2285 if (virt_key
== VK_RETURN
)
2286 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
2288 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
2289 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
2291 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
2292 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
2294 if (virt_key
== VK_CLEAR
)
2295 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
2300 /* List of special key combinations which w32 would normally capture,
2301 but Emacs should grab instead. Not directly visible to lisp, to
2302 simplify synchronization. Each item is an integer encoding a virtual
2303 key code and modifier combination to capture. */
2304 static Lisp_Object w32_grabbed_keys
;
2306 #define HOTKEY(vk, mods) make_number (((vk) & 255) | ((mods) << 8))
2307 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
2308 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
2309 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
2311 #define RAW_HOTKEY_ID(k) ((k) & 0xbfff)
2312 #define RAW_HOTKEY_VK_CODE(k) ((k) & 255)
2313 #define RAW_HOTKEY_MODIFIERS(k) ((k) >> 8)
2315 /* Register hot-keys for reserved key combinations when Emacs has
2316 keyboard focus, since this is the only way Emacs can receive key
2317 combinations like Alt-Tab which are used by the system. */
2320 register_hot_keys (HWND hwnd
)
2322 Lisp_Object keylist
;
2324 /* Use CONSP, since we are called asynchronously. */
2325 for (keylist
= w32_grabbed_keys
; CONSP (keylist
); keylist
= XCDR (keylist
))
2327 Lisp_Object key
= XCAR (keylist
);
2329 /* Deleted entries get set to nil. */
2330 if (!INTEGERP (key
))
2333 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
2334 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
2339 unregister_hot_keys (HWND hwnd
)
2341 Lisp_Object keylist
;
2343 for (keylist
= w32_grabbed_keys
; CONSP (keylist
); keylist
= XCDR (keylist
))
2345 Lisp_Object key
= XCAR (keylist
);
2347 if (!INTEGERP (key
))
2350 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
2356 w32_name_of_message (UINT msg
)
2359 static char buf
[64];
2360 static const struct {
2364 #define M(msg) { msg, # msg }
2372 M (WM_EMACS_CREATEWINDOW
),
2374 M (WM_EMACS_CREATESCROLLBAR
),
2375 M (WM_EMACS_SHOWWINDOW
),
2376 M (WM_EMACS_SETWINDOWPOS
),
2377 M (WM_EMACS_DESTROYWINDOW
),
2378 M (WM_EMACS_TRACKPOPUPMENU
),
2379 M (WM_EMACS_SETFOCUS
),
2380 M (WM_EMACS_SETFOREGROUND
),
2381 M (WM_EMACS_SETLOCALE
),
2382 M (WM_EMACS_SETKEYBOARDLAYOUT
),
2383 M (WM_EMACS_REGISTER_HOT_KEY
),
2384 M (WM_EMACS_UNREGISTER_HOT_KEY
),
2385 M (WM_EMACS_TOGGLE_LOCK_KEY
),
2386 M (WM_EMACS_TRACK_CARET
),
2387 M (WM_EMACS_DESTROY_CARET
),
2388 M (WM_EMACS_SHOW_CARET
),
2389 M (WM_EMACS_HIDE_CARET
),
2390 M (WM_EMACS_SETCURSOR
),
2397 for (i
= 0; msgnames
[i
].name
; ++i
)
2398 if (msgnames
[i
].msg
== msg
)
2399 return msgnames
[i
].name
;
2401 sprintf (buf
, "message 0x%04x", (unsigned)msg
);
2404 #endif /* EMACSDEBUG */
2406 /* Here's an overview of how Emacs input works in GUI sessions on
2407 MS-Windows. (For description of non-GUI input, see the commentary
2408 before w32_console_read_socket in w32inevt.c.)
2410 System messages are read and processed by w32_msg_pump below. This
2411 function runs in a separate thread. It handles a small number of
2412 custom WM_EMACS_* messages (posted by the main thread, look for
2413 PostMessage calls), and dispatches the rest to w32_wnd_proc, which
2414 is the main window procedure for the entire Emacs application.
2416 w32_wnd_proc also runs in the same separate input thread. It
2417 handles some messages, mostly those that need GDI calls, by itself.
2418 For the others, it calls my_post_msg, which inserts the messages
2419 into the input queue serviced by w32_read_socket.
2421 w32_read_socket runs in the main (a.k.a. "Lisp") thread, and is
2422 called synchronously from keyboard.c when it is known or suspected
2423 that some input is available. w32_read_socket either handles
2424 messages immediately, or converts them into Emacs input events and
2425 stuffs them into kbd_buffer, where kbd_buffer_get_event can get at
2426 them and process them when read_char and its callers require
2429 Under Cygwin with the W32 toolkit, the use of /dev/windows with
2430 select(2) takes the place of w32_read_socket.
2434 /* Main message dispatch loop. */
2437 w32_msg_pump (deferred_msg
* msg_buf
)
2443 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
2445 while ((w32_unicode_gui
? GetMessageW
: GetMessageA
) (&msg
, NULL
, 0, 0))
2448 /* DebPrint (("w32_msg_pump: %s time:%u\n", */
2449 /* w32_name_of_message (msg.message), msg.time)); */
2451 if (msg
.hwnd
== NULL
)
2453 switch (msg
.message
)
2456 /* Produced by complete_deferred_msg; just ignore. */
2458 case WM_EMACS_CREATEWINDOW
:
2459 /* Initialize COM for this window. Even though we don't use it,
2460 some third party shell extensions can cause it to be used in
2461 system dialogs, which causes a crash if it is not initialized.
2462 This is a known bug in Windows, which was fixed long ago, but
2463 the patch for XP is not publicly available until XP SP3,
2464 and older versions will never be patched. */
2465 CoInitialize (NULL
);
2466 w32_createwindow ((struct frame
*) msg
.wParam
,
2467 (int *) msg
.lParam
);
2468 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2471 case WM_EMACS_SETLOCALE
:
2472 SetThreadLocale (msg
.wParam
);
2473 /* Reply is not expected. */
2475 case WM_EMACS_SETKEYBOARDLAYOUT
:
2476 result
= (WPARAM
) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
2477 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2481 case WM_EMACS_REGISTER_HOT_KEY
:
2482 focus_window
= GetFocus ();
2483 if (focus_window
!= NULL
)
2484 RegisterHotKey (focus_window
,
2485 RAW_HOTKEY_ID (msg
.wParam
),
2486 RAW_HOTKEY_MODIFIERS (msg
.wParam
),
2487 RAW_HOTKEY_VK_CODE (msg
.wParam
));
2488 /* Reply is not expected. */
2490 case WM_EMACS_UNREGISTER_HOT_KEY
:
2491 focus_window
= GetFocus ();
2492 if (focus_window
!= NULL
)
2493 UnregisterHotKey (focus_window
, RAW_HOTKEY_ID (msg
.wParam
));
2494 /* Mark item as erased. NB: this code must be
2495 thread-safe. The next line is okay because the cons
2496 cell is never made into garbage and is not relocated by
2498 XSETCAR (XIL ((EMACS_INT
) msg
.lParam
), Qnil
);
2499 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2502 case WM_EMACS_TOGGLE_LOCK_KEY
:
2504 int vk_code
= (int) msg
.wParam
;
2505 int cur_state
= (GetKeyState (vk_code
) & 1);
2506 Lisp_Object new_state
= XIL ((EMACS_INT
) msg
.lParam
);
2508 /* NB: This code must be thread-safe. It is safe to
2509 call NILP because symbols are not relocated by GC,
2510 and pointer here is not touched by GC (so the markbit
2511 can't be set). Numbers are safe because they are
2512 immediate values. */
2513 if (NILP (new_state
)
2514 || (NUMBERP (new_state
)
2515 && ((XUINT (new_state
)) & 1) != cur_state
))
2517 one_w32_display_info
.faked_key
= vk_code
;
2519 keybd_event ((BYTE
) vk_code
,
2520 (BYTE
) MapVirtualKey (vk_code
, 0),
2521 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2522 keybd_event ((BYTE
) vk_code
,
2523 (BYTE
) MapVirtualKey (vk_code
, 0),
2524 KEYEVENTF_EXTENDEDKEY
| 0, 0);
2525 keybd_event ((BYTE
) vk_code
,
2526 (BYTE
) MapVirtualKey (vk_code
, 0),
2527 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2528 cur_state
= !cur_state
;
2530 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2536 /* Broadcast messages make it here, so you need to be looking
2537 for something in particular for this to be useful. */
2539 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
2545 if (w32_unicode_gui
)
2546 DispatchMessageW (&msg
);
2548 DispatchMessageA (&msg
);
2551 /* Exit nested loop when our deferred message has completed. */
2552 if (msg_buf
->completed
)
2557 deferred_msg
* deferred_msg_head
;
2559 static deferred_msg
*
2560 find_deferred_msg (HWND hwnd
, UINT msg
)
2562 deferred_msg
* item
;
2564 /* Don't actually need synchronization for read access, since
2565 modification of single pointer is always atomic. */
2566 /* enter_crit (); */
2568 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2569 if (item
->w32msg
.msg
.hwnd
== hwnd
2570 && item
->w32msg
.msg
.message
== msg
)
2573 /* leave_crit (); */
2579 send_deferred_msg (deferred_msg
* msg_buf
,
2585 /* Only input thread can send deferred messages. */
2586 if (GetCurrentThreadId () != dwWindowsThreadId
)
2589 /* It is an error to send a message that is already deferred. */
2590 if (find_deferred_msg (hwnd
, msg
) != NULL
)
2593 /* Enforced synchronization is not needed because this is the only
2594 function that alters deferred_msg_head, and the following critical
2595 section is guaranteed to only be serially reentered (since only the
2596 input thread can call us). */
2598 /* enter_crit (); */
2600 msg_buf
->completed
= 0;
2601 msg_buf
->next
= deferred_msg_head
;
2602 deferred_msg_head
= msg_buf
;
2603 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
2605 /* leave_crit (); */
2607 /* Start a new nested message loop to process other messages until
2608 this one is completed. */
2609 w32_msg_pump (msg_buf
);
2611 deferred_msg_head
= msg_buf
->next
;
2613 return msg_buf
->result
;
2617 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
2619 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
2621 if (msg_buf
== NULL
)
2622 /* Message may have been canceled, so don't abort. */
2625 msg_buf
->result
= result
;
2626 msg_buf
->completed
= 1;
2628 /* Ensure input thread is woken so it notices the completion. */
2629 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2633 cancel_all_deferred_msgs (void)
2635 deferred_msg
* item
;
2637 /* Don't actually need synchronization for read access, since
2638 modification of single pointer is always atomic. */
2639 /* enter_crit (); */
2641 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2644 item
->completed
= 1;
2647 /* leave_crit (); */
2649 /* Ensure input thread is woken so it notices the completion. */
2650 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2654 w32_msg_worker (void *arg
)
2657 deferred_msg dummy_buf
;
2659 /* Ensure our message queue is created */
2661 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
2663 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2666 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
2667 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
2668 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
2670 /* This is the initial message loop which should only exit when the
2671 application quits. */
2672 w32_msg_pump (&dummy_buf
);
2678 signal_user_input (void)
2680 /* Interrupt any lisp that wants to be interrupted by input. */
2681 if (!NILP (Vthrow_on_input
))
2683 Vquit_flag
= Vthrow_on_input
;
2684 /* Doing a QUIT from this thread is a bad idea, since this
2685 unwinds the stack of the Lisp thread, and the Windows runtime
2686 rightfully barfs. Disabled. */
2688 /* If we're inside a function that wants immediate quits,
2690 if (immediate_quit
&& NILP (Vinhibit_quit
))
2701 post_character_message (HWND hwnd
, UINT msg
,
2702 WPARAM wParam
, LPARAM lParam
,
2707 wmsg
.dwModifiers
= modifiers
;
2709 /* Detect quit_char and set quit-flag directly. Note that we
2710 still need to post a message to ensure the main thread will be
2711 woken up if blocked in sys_select, but we do NOT want to post
2712 the quit_char message itself (because it will usually be as if
2713 the user had typed quit_char twice). Instead, we post a dummy
2714 message that has no particular effect. */
2717 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
2718 c
= make_ctrl_char (c
) & 0377;
2720 || (wmsg
.dwModifiers
== 0
2721 && w32_quit_key
&& wParam
== w32_quit_key
))
2725 /* The choice of message is somewhat arbitrary, as long as
2726 the main thread handler just ignores it. */
2729 /* Interrupt any blocking system calls. */
2732 /* As a safety precaution, forcibly complete any deferred
2733 messages. This is a kludge, but I don't see any particularly
2734 clean way to handle the situation where a deferred message is
2735 "dropped" in the lisp thread, and will thus never be
2736 completed, eg. by the user trying to activate the menubar
2737 when the lisp thread is busy, and then typing C-g when the
2738 menubar doesn't open promptly (with the result that the
2739 menubar never responds at all because the deferred
2740 WM_INITMENU message is never completed). Another problem
2741 situation is when the lisp thread calls SendMessage (to send
2742 a window manager command) when a message has been deferred;
2743 the lisp thread gets blocked indefinitely waiting for the
2744 deferred message to be completed, which itself is waiting for
2745 the lisp thread to respond.
2747 Note that we don't want to block the input thread waiting for
2748 a response from the lisp thread (although that would at least
2749 solve the deadlock problem above), because we want to be able
2750 to receive C-g to interrupt the lisp thread. */
2751 cancel_all_deferred_msgs ();
2754 signal_user_input ();
2757 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2760 /* Main window procedure */
2762 static LRESULT CALLBACK
2763 w32_wnd_proc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2766 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
2768 int windows_translate
;
2771 /* Note that it is okay to call x_window_to_frame, even though we are
2772 not running in the main lisp thread, because frame deletion
2773 requires the lisp thread to synchronize with this thread. Thus, if
2774 a frame struct is returned, it can be used without concern that the
2775 lisp thread might make it disappear while we are using it.
2777 NB. Walking the frame list in this thread is safe (as long as
2778 writes of Lisp_Object slots are atomic, which they are on Windows).
2779 Although delete-frame can destructively modify the frame list while
2780 we are walking it, a garbage collection cannot occur until after
2781 delete-frame has synchronized with this thread.
2783 It is also safe to use functions that make GDI calls, such as
2784 w32_clear_rect, because these functions must obtain a DC handle
2785 from the frame struct using get_frame_dc which is thread-aware. */
2790 f
= x_window_to_frame (dpyinfo
, hwnd
);
2793 HDC hdc
= get_frame_dc (f
);
2794 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
2795 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
2796 release_frame_dc (f
, hdc
);
2798 #if defined (W32_DEBUG_DISPLAY)
2799 DebPrint (("WM_ERASEBKGND (frame %p): erasing %d,%d-%d,%d\n",
2801 wmsg
.rect
.left
, wmsg
.rect
.top
,
2802 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2803 #endif /* W32_DEBUG_DISPLAY */
2806 case WM_PALETTECHANGED
:
2807 /* ignore our own changes */
2808 if ((HWND
)wParam
!= hwnd
)
2810 f
= x_window_to_frame (dpyinfo
, hwnd
);
2812 /* get_frame_dc will realize our palette and force all
2813 frames to be redrawn if needed. */
2814 release_frame_dc (f
, get_frame_dc (f
));
2819 PAINTSTRUCT paintStruct
;
2821 memset (&update_rect
, 0, sizeof (update_rect
));
2823 f
= x_window_to_frame (dpyinfo
, hwnd
);
2826 DebPrint (("WM_PAINT received for unknown window %p\n", hwnd
));
2830 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
2831 fails. Apparently this can happen under some
2833 if (GetUpdateRect (hwnd
, &update_rect
, FALSE
) || !w32_strict_painting
)
2836 BeginPaint (hwnd
, &paintStruct
);
2838 /* The rectangles returned by GetUpdateRect and BeginPaint
2839 do not always match. Play it safe by assuming both areas
2841 UnionRect (&(wmsg
.rect
), &update_rect
, &(paintStruct
.rcPaint
));
2843 #if defined (W32_DEBUG_DISPLAY)
2844 DebPrint (("WM_PAINT (frame %p): painting %d,%d-%d,%d\n",
2846 wmsg
.rect
.left
, wmsg
.rect
.top
,
2847 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2848 DebPrint ((" [update region is %d,%d-%d,%d]\n",
2849 update_rect
.left
, update_rect
.top
,
2850 update_rect
.right
, update_rect
.bottom
));
2852 EndPaint (hwnd
, &paintStruct
);
2855 /* Change the message type to prevent Windows from
2856 combining WM_PAINT messages in the Lisp thread's queue,
2857 since Windows assumes that each message queue is
2858 dedicated to one frame and does not bother checking
2859 that hwnd matches before combining them. */
2860 my_post_msg (&wmsg
, hwnd
, WM_EMACS_PAINT
, wParam
, lParam
);
2865 /* If GetUpdateRect returns 0 (meaning there is no update
2866 region), assume the whole window needs to be repainted. */
2867 GetClientRect (hwnd
, &wmsg
.rect
);
2868 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2872 case WM_INPUTLANGCHANGE
:
2873 /* Inform lisp thread of keyboard layout changes. */
2874 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2876 /* Clear dead keys in the keyboard state; for simplicity only
2877 preserve modifier key states. */
2882 GetKeyboardState (keystate
);
2883 for (i
= 0; i
< 256; i
++)
2900 SetKeyboardState (keystate
);
2905 /* Synchronize hot keys with normal input. */
2906 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
2911 record_keyup (wParam
, lParam
);
2916 /* Ignore keystrokes we fake ourself; see below. */
2917 if (dpyinfo
->faked_key
== wParam
)
2919 dpyinfo
->faked_key
= 0;
2920 /* Make sure TranslateMessage sees them though (as long as
2921 they don't produce WM_CHAR messages). This ensures that
2922 indicator lights are toggled promptly on Windows 9x, for
2924 if (wParam
< 256 && lispy_function_keys
[wParam
])
2926 windows_translate
= 1;
2932 /* Synchronize modifiers with current keystroke. */
2934 record_keydown (wParam
, lParam
);
2935 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
2937 windows_translate
= 0;
2942 if (NILP (Vw32_pass_lwindow_to_system
))
2944 /* Prevent system from acting on keyup (which opens the
2945 Start menu if no other key was pressed) by simulating a
2946 press of Space which we will ignore. */
2947 if (GetAsyncKeyState (wParam
) & 1)
2949 if (NUMBERP (Vw32_phantom_key_code
))
2950 key
= XUINT (Vw32_phantom_key_code
) & 255;
2953 dpyinfo
->faked_key
= key
;
2954 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
2957 if (!NILP (Vw32_lwindow_modifier
))
2961 if (NILP (Vw32_pass_rwindow_to_system
))
2963 if (GetAsyncKeyState (wParam
) & 1)
2965 if (NUMBERP (Vw32_phantom_key_code
))
2966 key
= XUINT (Vw32_phantom_key_code
) & 255;
2969 dpyinfo
->faked_key
= key
;
2970 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
2973 if (!NILP (Vw32_rwindow_modifier
))
2977 if (!NILP (Vw32_apps_modifier
))
2981 if (NILP (Vw32_pass_alt_to_system
))
2982 /* Prevent DefWindowProc from activating the menu bar if an
2983 Alt key is pressed and released by itself. */
2985 windows_translate
= 1;
2988 /* Decide whether to treat as modifier or function key. */
2989 if (NILP (Vw32_enable_caps_lock
))
2990 goto disable_lock_key
;
2991 windows_translate
= 1;
2994 /* Decide whether to treat as modifier or function key. */
2995 if (NILP (Vw32_enable_num_lock
))
2996 goto disable_lock_key
;
2997 windows_translate
= 1;
3000 /* Decide whether to treat as modifier or function key. */
3001 if (NILP (Vw32_scroll_lock_modifier
))
3002 goto disable_lock_key
;
3003 windows_translate
= 1;
3006 /* Ensure the appropriate lock key state (and indicator light)
3007 remains in the same state. We do this by faking another
3008 press of the relevant key. Apparently, this really is the
3009 only way to toggle the state of the indicator lights. */
3010 dpyinfo
->faked_key
= wParam
;
3011 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3012 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3013 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3014 KEYEVENTF_EXTENDEDKEY
| 0, 0);
3015 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3016 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3017 /* Ensure indicator lights are updated promptly on Windows 9x
3018 (TranslateMessage apparently does this), after forwarding
3020 post_character_message (hwnd
, msg
, wParam
, lParam
,
3021 w32_get_key_modifiers (wParam
, lParam
));
3022 windows_translate
= 1;
3026 case VK_PROCESSKEY
: /* Generated by IME. */
3027 windows_translate
= 1;
3030 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
3031 which is confusing for purposes of key binding; convert
3032 VK_CANCEL events into VK_PAUSE events. */
3036 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
3037 for purposes of key binding; convert these back into
3038 VK_NUMLOCK events, at least when we want to see NumLock key
3039 presses. (Note that there is never any possibility that
3040 VK_PAUSE with Ctrl really is C-Pause as per above.) */
3041 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
3042 wParam
= VK_NUMLOCK
;
3045 /* If not defined as a function key, change it to a WM_CHAR message. */
3046 if (wParam
> 255 || !lispy_function_keys
[wParam
])
3048 DWORD modifiers
= construct_console_modifiers ();
3050 if (!NILP (Vw32_recognize_altgr
)
3051 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
3053 /* Always let TranslateMessage handle AltGr key chords;
3054 for some reason, ToAscii doesn't always process AltGr
3055 chords correctly. */
3056 windows_translate
= 1;
3058 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
3060 /* Handle key chords including any modifiers other
3061 than shift directly, in order to preserve as much
3062 modifier information as possible. */
3063 if ('A' <= wParam
&& wParam
<= 'Z')
3065 /* Don't translate modified alphabetic keystrokes,
3066 so the user doesn't need to constantly switch
3067 layout to type control or meta keystrokes when
3068 the normal layout translates alphabetic
3069 characters to non-ascii characters. */
3070 if (!modifier_set (VK_SHIFT
))
3071 wParam
+= ('a' - 'A');
3076 /* Try to handle other keystrokes by determining the
3077 base character (ie. translating the base key plus
3080 KEY_EVENT_RECORD key
;
3082 key
.bKeyDown
= TRUE
;
3083 key
.wRepeatCount
= 1;
3084 key
.wVirtualKeyCode
= wParam
;
3085 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
3086 key
.uChar
.AsciiChar
= 0;
3087 key
.dwControlKeyState
= modifiers
;
3089 add
= w32_kbd_patch_key (&key
, w32_keyboard_codepage
);
3090 /* 0 means an unrecognized keycode, negative means
3091 dead key. Ignore both. */
3094 /* Forward asciified character sequence. */
3095 post_character_message
3097 (unsigned char) key
.uChar
.AsciiChar
, lParam
,
3098 w32_get_key_modifiers (wParam
, lParam
));
3099 w32_kbd_patch_key (&key
, w32_keyboard_codepage
);
3106 /* Let TranslateMessage handle everything else. */
3107 windows_translate
= 1;
3113 if (windows_translate
)
3115 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
3116 windows_msg
.time
= GetMessageTime ();
3117 TranslateMessage (&windows_msg
);
3129 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3130 signal_user_input ();
3131 my_post_msg (&wmsg
, hwnd
, WM_UNICHAR
, wParam
, lParam
);
3135 post_character_message (hwnd
, msg
, wParam
, lParam
,
3136 w32_get_key_modifiers (wParam
, lParam
));
3140 /* WM_UNICHAR looks promising from the docs, but the exact
3141 circumstances in which TranslateMessage sends it is one of those
3142 Microsoft secret API things that EU and US courts are supposed
3143 to have put a stop to already. Spy++ shows it being sent to Notepad
3144 and other MS apps, but never to Emacs.
3146 Some third party IMEs send it in accordance with the official
3147 documentation though, so handle it here.
3149 UNICODE_NOCHAR is used to test for support for this message.
3150 TRUE indicates that the message is supported. */
3151 if (wParam
== UNICODE_NOCHAR
)
3156 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3157 signal_user_input ();
3158 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3163 /* If we can't get the IME result as Unicode, use default processing,
3164 which will at least allow characters decodable in the system locale
3166 if (!get_composition_string_fn
)
3169 else if (!ignore_ime_char
)
3174 HIMC context
= get_ime_context_fn (hwnd
);
3175 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3176 /* Get buffer size. */
3177 size
= get_composition_string_fn (context
, GCS_RESULTSTR
, NULL
, 0);
3178 buffer
= alloca (size
);
3179 size
= get_composition_string_fn (context
, GCS_RESULTSTR
,
3181 release_ime_context_fn (hwnd
, context
);
3183 signal_user_input ();
3184 for (i
= 0; i
< size
/ sizeof (wchar_t); i
++)
3186 my_post_msg (&wmsg
, hwnd
, WM_UNICHAR
, (WPARAM
) buffer
[i
],
3189 /* Ignore the messages for the rest of the
3190 characters in the string that was output above. */
3191 ignore_ime_char
= (size
/ sizeof (wchar_t)) - 1;
3198 case WM_IME_STARTCOMPOSITION
:
3199 if (!set_ime_composition_window_fn
)
3203 COMPOSITIONFORM form
;
3207 /* Implementation note: The code below does something that
3208 one shouldn't do: it accesses the window object from a
3209 separate thread, while the main (a.k.a. "Lisp") thread
3210 runs and can legitimately delete and even GC it. That is
3211 why we are extra careful not to futz with a window that
3212 is different from the one recorded when the system caret
3213 coordinates were last modified. That is also why we are
3214 careful not to move the IME window if the window
3215 described by W was deleted, as indicated by its buffer
3216 field being reset to nil. */
3217 f
= x_window_to_frame (dpyinfo
, hwnd
);
3218 if (!(f
&& FRAME_LIVE_P (f
)))
3220 w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
3221 /* Punt if someone changed the frame's selected window
3223 if (w
!= w32_system_caret_window
)
3226 form
.dwStyle
= CFS_RECT
;
3227 form
.ptCurrentPos
.x
= w32_system_caret_x
;
3228 form
.ptCurrentPos
.y
= w32_system_caret_y
;
3230 form
.rcArea
.left
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, 0);
3231 form
.rcArea
.top
= (WINDOW_TOP_EDGE_Y (w
)
3232 + w32_system_caret_hdr_height
);
3233 form
.rcArea
.right
= (WINDOW_BOX_RIGHT_EDGE_X (w
)
3234 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
3235 - WINDOW_RIGHT_FRINGE_WIDTH (w
));
3236 form
.rcArea
.bottom
= (WINDOW_BOTTOM_EDGE_Y (w
)
3237 - WINDOW_BOTTOM_DIVIDER_WIDTH (w
)
3238 - w32_system_caret_mode_height
);
3240 /* Punt if the window was deleted behind our back. */
3241 if (!BUFFERP (w
->contents
))
3244 context
= get_ime_context_fn (hwnd
);
3249 set_ime_composition_window_fn (context
, &form
);
3250 release_ime_context_fn (hwnd
, context
);
3254 case WM_IME_ENDCOMPOSITION
:
3255 ignore_ime_char
= 0;
3258 /* Simulate middle mouse button events when left and right buttons
3259 are used together, but only if user has two button mouse. */
3260 case WM_LBUTTONDOWN
:
3261 case WM_RBUTTONDOWN
:
3262 if (w32_num_mouse_buttons
> 2)
3263 goto handle_plain_button
;
3266 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
3267 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
3269 if (button_state
& this)
3272 if (button_state
== 0)
3275 button_state
|= this;
3277 if (button_state
& other
)
3279 if (mouse_button_timer
)
3281 KillTimer (hwnd
, mouse_button_timer
);
3282 mouse_button_timer
= 0;
3284 /* Generate middle mouse event instead. */
3285 msg
= WM_MBUTTONDOWN
;
3286 button_state
|= MMOUSE
;
3288 else if (button_state
& MMOUSE
)
3290 /* Ignore button event if we've already generated a
3291 middle mouse down event. This happens if the
3292 user releases and press one of the two buttons
3293 after we've faked a middle mouse event. */
3298 /* Flush out saved message. */
3299 post_msg (&saved_mouse_button_msg
);
3301 wmsg
.dwModifiers
= w32_get_modifiers ();
3302 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3303 signal_user_input ();
3305 /* Clear message buffer. */
3306 saved_mouse_button_msg
.msg
.hwnd
= 0;
3310 /* Hold onto message for now. */
3311 mouse_button_timer
=
3312 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
3313 w32_mouse_button_tolerance
, NULL
);
3314 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
3315 saved_mouse_button_msg
.msg
.message
= msg
;
3316 saved_mouse_button_msg
.msg
.wParam
= wParam
;
3317 saved_mouse_button_msg
.msg
.lParam
= lParam
;
3318 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
3319 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
3326 if (w32_num_mouse_buttons
> 2)
3327 goto handle_plain_button
;
3330 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
3331 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
3333 if ((button_state
& this) == 0)
3336 button_state
&= ~this;
3338 if (button_state
& MMOUSE
)
3340 /* Only generate event when second button is released. */
3341 if ((button_state
& other
) == 0)
3344 button_state
&= ~MMOUSE
;
3346 if (button_state
) emacs_abort ();
3353 /* Flush out saved message if necessary. */
3354 if (saved_mouse_button_msg
.msg
.hwnd
)
3356 post_msg (&saved_mouse_button_msg
);
3359 wmsg
.dwModifiers
= w32_get_modifiers ();
3360 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3361 signal_user_input ();
3363 /* Always clear message buffer and cancel timer. */
3364 saved_mouse_button_msg
.msg
.hwnd
= 0;
3365 KillTimer (hwnd
, mouse_button_timer
);
3366 mouse_button_timer
= 0;
3368 if (button_state
== 0)
3373 case WM_XBUTTONDOWN
:
3375 if (w32_pass_extra_mouse_buttons_to_system
)
3377 /* else fall through and process them. */
3378 case WM_MBUTTONDOWN
:
3380 handle_plain_button
:
3385 /* Ignore middle and extra buttons as long as the menu is active. */
3386 f
= x_window_to_frame (dpyinfo
, hwnd
);
3387 if (f
&& f
->output_data
.w32
->menubar_active
)
3390 if (parse_button (msg
, HIWORD (wParam
), &button
, &up
))
3392 if (up
) ReleaseCapture ();
3393 else SetCapture (hwnd
);
3394 button
= (button
== 0) ? LMOUSE
:
3395 ((button
== 1) ? MMOUSE
: RMOUSE
);
3397 button_state
&= ~button
;
3399 button_state
|= button
;
3403 wmsg
.dwModifiers
= w32_get_modifiers ();
3404 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3405 signal_user_input ();
3407 /* Need to return true for XBUTTON messages, false for others,
3408 to indicate that we processed the message. */
3409 return (msg
== WM_XBUTTONDOWN
|| msg
== WM_XBUTTONUP
);
3412 /* Ignore mouse movements as long as the menu is active. These
3413 movements are processed by the window manager anyway, and
3414 it's wrong to handle them as if they happened on the
3415 underlying frame. */
3416 f
= x_window_to_frame (dpyinfo
, hwnd
);
3417 if (f
&& f
->output_data
.w32
->menubar_active
)
3420 /* If the mouse has just moved into the frame, start tracking
3421 it, so we will be notified when it leaves the frame. Mouse
3422 tracking only works under W98 and NT4 and later. On earlier
3423 versions, there is no way of telling when the mouse leaves the
3424 frame, so we just have to put up with help-echo and mouse
3425 highlighting remaining while the frame is not active. */
3426 if (track_mouse_event_fn
&& !track_mouse_window
3427 /* If the menu bar is active, turning on tracking of mouse
3428 movement events might send these events to the tooltip
3429 frame, if the user happens to move the mouse pointer over
3430 the tooltip. But since we don't process events for
3431 tooltip frames, this causes Windows to present a
3432 hourglass cursor, which is ugly and unexpected. So don't
3433 enable tracking mouse events in this case; they will be
3434 restarted when the menu pops down. (Confusingly, the
3435 menubar_active member of f->output_data.w32, tested
3436 above, is only set when a menu was popped up _not_ from
3437 the frame's menu bar, but via x-popup-menu.) */
3440 TRACKMOUSEEVENT tme
;
3441 tme
.cbSize
= sizeof (tme
);
3442 tme
.dwFlags
= TME_LEAVE
;
3443 tme
.hwndTrack
= hwnd
;
3444 tme
.dwHoverTime
= HOVER_DEFAULT
;
3446 track_mouse_event_fn (&tme
);
3447 track_mouse_window
= hwnd
;
3450 if (w32_mouse_move_interval
<= 0
3451 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
3453 wmsg
.dwModifiers
= w32_get_modifiers ();
3454 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3458 /* Hang onto mouse move and scroll messages for a bit, to avoid
3459 sending such events to Emacs faster than it can process them.
3460 If we get more events before the timer from the first message
3461 expires, we just replace the first message. */
3463 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
3465 SetTimer (hwnd
, MOUSE_MOVE_ID
,
3466 w32_mouse_move_interval
, NULL
);
3468 /* Hold onto message for now. */
3469 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
3470 saved_mouse_move_msg
.msg
.message
= msg
;
3471 saved_mouse_move_msg
.msg
.wParam
= wParam
;
3472 saved_mouse_move_msg
.msg
.lParam
= lParam
;
3473 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
3474 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
3480 wmsg
.dwModifiers
= w32_get_modifiers ();
3481 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3482 signal_user_input ();
3486 if (w32_pass_multimedia_buttons_to_system
)
3488 /* Otherwise, pass to lisp, the same way we do with mousehwheel. */
3489 case WM_MOUSEHWHEEL
:
3490 wmsg
.dwModifiers
= w32_get_modifiers ();
3491 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3492 signal_user_input ();
3493 /* Non-zero must be returned when WM_MOUSEHWHEEL messages are
3494 handled, to prevent the system trying to handle it by faking
3495 scroll bar events. */
3499 /* Flush out saved messages if necessary. */
3500 if (wParam
== mouse_button_timer
)
3502 if (saved_mouse_button_msg
.msg
.hwnd
)
3504 post_msg (&saved_mouse_button_msg
);
3505 signal_user_input ();
3506 saved_mouse_button_msg
.msg
.hwnd
= 0;
3508 KillTimer (hwnd
, mouse_button_timer
);
3509 mouse_button_timer
= 0;
3511 else if (wParam
== mouse_move_timer
)
3513 if (saved_mouse_move_msg
.msg
.hwnd
)
3515 post_msg (&saved_mouse_move_msg
);
3516 saved_mouse_move_msg
.msg
.hwnd
= 0;
3518 KillTimer (hwnd
, mouse_move_timer
);
3519 mouse_move_timer
= 0;
3521 else if (wParam
== menu_free_timer
)
3523 KillTimer (hwnd
, menu_free_timer
);
3524 menu_free_timer
= 0;
3525 f
= x_window_to_frame (dpyinfo
, hwnd
);
3526 /* If a popup menu is active, don't wipe its strings. */
3528 && current_popup_menu
== NULL
)
3530 /* Free memory used by owner-drawn and help-echo strings. */
3531 w32_free_menu_strings (hwnd
);
3533 f
->output_data
.w32
->menubar_active
= 0;
3540 /* Windows doesn't send us focus messages when putting up and
3541 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
3542 The only indication we get that something happened is receiving
3543 this message afterwards. So this is a good time to reset our
3544 keyboard modifiers' state. */
3551 /* We must ensure menu bar is fully constructed and up to date
3552 before allowing user interaction with it. To achieve this
3553 we send this message to the lisp thread and wait for a
3554 reply (whose value is not actually needed) to indicate that
3555 the menu bar is now ready for use, so we can now return.
3557 To remain responsive in the meantime, we enter a nested message
3558 loop that can process all other messages.
3560 However, we skip all this if the message results from calling
3561 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
3562 thread a message because it is blocked on us at this point. We
3563 set menubar_active before calling TrackPopupMenu to indicate
3564 this (there is no possibility of confusion with real menubar
3567 f
= x_window_to_frame (dpyinfo
, hwnd
);
3569 && (f
->output_data
.w32
->menubar_active
3570 /* We can receive this message even in the absence of a
3571 menubar (ie. when the system menu is activated) - in this
3572 case we do NOT want to forward the message, otherwise it
3573 will cause the menubar to suddenly appear when the user
3574 had requested it to be turned off! */
3575 || f
->output_data
.w32
->menubar_widget
== NULL
))
3579 deferred_msg msg_buf
;
3581 /* Detect if message has already been deferred; in this case
3582 we cannot return any sensible value to ignore this. */
3583 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3588 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
3591 case WM_EXITMENULOOP
:
3592 f
= x_window_to_frame (dpyinfo
, hwnd
);
3594 /* If a menu is still active, check again after a short delay,
3595 since Windows often (always?) sends the WM_EXITMENULOOP
3596 before the corresponding WM_COMMAND message.
3597 Don't do this if a popup menu is active, since it is only
3598 menubar menus that require cleaning up in this way.
3600 if (f
&& menubar_in_use
&& current_popup_menu
== NULL
)
3601 menu_free_timer
= SetTimer (hwnd
, MENU_FREE_ID
, MENU_FREE_DELAY
, NULL
);
3603 /* If hourglass cursor should be displayed, display it now. */
3604 if (f
&& f
->output_data
.w32
->hourglass_p
)
3605 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
3610 /* Direct handling of help_echo in menus. Should be safe now
3611 that we generate the help_echo by placing a help event in the
3614 HMENU menu
= (HMENU
) lParam
;
3615 UINT menu_item
= (UINT
) LOWORD (wParam
);
3616 UINT flags
= (UINT
) HIWORD (wParam
);
3618 w32_menu_display_help (hwnd
, menu
, menu_item
, flags
);
3622 case WM_MEASUREITEM
:
3623 f
= x_window_to_frame (dpyinfo
, hwnd
);
3626 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
3628 if (pMis
->CtlType
== ODT_MENU
)
3630 /* Work out dimensions for popup menu titles. */
3631 char * title
= (char *) pMis
->itemData
;
3632 HDC hdc
= GetDC (hwnd
);
3633 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3634 LOGFONT menu_logfont
;
3638 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3639 menu_logfont
.lfWeight
= FW_BOLD
;
3640 menu_font
= CreateFontIndirect (&menu_logfont
);
3641 old_font
= SelectObject (hdc
, menu_font
);
3643 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
3646 if (unicode_append_menu
)
3647 GetTextExtentPoint32W (hdc
, (WCHAR
*) title
,
3648 wcslen ((WCHAR
*) title
),
3651 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
3653 pMis
->itemWidth
= size
.cx
;
3654 if (pMis
->itemHeight
< size
.cy
)
3655 pMis
->itemHeight
= size
.cy
;
3658 pMis
->itemWidth
= 0;
3660 SelectObject (hdc
, old_font
);
3661 DeleteObject (menu_font
);
3662 ReleaseDC (hwnd
, hdc
);
3669 f
= x_window_to_frame (dpyinfo
, hwnd
);
3672 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
3674 if (pDis
->CtlType
== ODT_MENU
)
3676 /* Draw popup menu title. */
3677 char * title
= (char *) pDis
->itemData
;
3680 HDC hdc
= pDis
->hDC
;
3681 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3682 LOGFONT menu_logfont
;
3685 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3686 menu_logfont
.lfWeight
= FW_BOLD
;
3687 menu_font
= CreateFontIndirect (&menu_logfont
);
3688 old_font
= SelectObject (hdc
, menu_font
);
3690 /* Always draw title as if not selected. */
3691 if (unicode_append_menu
)
3694 + GetSystemMetrics (SM_CXMENUCHECK
),
3696 ETO_OPAQUE
, &pDis
->rcItem
,
3698 wcslen ((WCHAR
*) title
), NULL
);
3702 + GetSystemMetrics (SM_CXMENUCHECK
),
3704 ETO_OPAQUE
, &pDis
->rcItem
,
3705 title
, strlen (title
), NULL
);
3707 SelectObject (hdc
, old_font
);
3708 DeleteObject (menu_font
);
3716 /* Still not right - can't distinguish between clicks in the
3717 client area of the frame from clicks forwarded from the scroll
3718 bars - may have to hook WM_NCHITTEST to remember the mouse
3719 position and then check if it is in the client area ourselves. */
3720 case WM_MOUSEACTIVATE
:
3721 /* Discard the mouse click that activates a frame, allowing the
3722 user to click anywhere without changing point (or worse!).
3723 Don't eat mouse clicks on scrollbars though!! */
3724 if (LOWORD (lParam
) == HTCLIENT
)
3725 return MA_ACTIVATEANDEAT
;
3730 /* No longer tracking mouse. */
3731 track_mouse_window
= NULL
;
3733 case WM_ACTIVATEAPP
:
3735 case WM_WINDOWPOSCHANGED
:
3737 /* Inform lisp thread that a frame might have just been obscured
3738 or exposed, so should recheck visibility of all frames. */
3739 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3743 dpyinfo
->faked_key
= 0;
3745 register_hot_keys (hwnd
);
3748 unregister_hot_keys (hwnd
);
3751 /* Relinquish the system caret. */
3752 if (w32_system_caret_hwnd
)
3754 w32_visible_system_caret_hwnd
= NULL
;
3755 w32_system_caret_hwnd
= NULL
;
3761 f
= x_window_to_frame (dpyinfo
, hwnd
);
3762 if (f
&& HIWORD (wParam
) == 0)
3764 if (menu_free_timer
)
3766 KillTimer (hwnd
, menu_free_timer
);
3767 menu_free_timer
= 0;
3773 wmsg
.dwModifiers
= w32_get_modifiers ();
3774 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3782 wmsg
.dwModifiers
= w32_get_modifiers ();
3783 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3786 case WM_WINDOWPOSCHANGING
:
3787 /* Don't restrict the sizing of tip frames. */
3788 if (frame_resize_pixelwise
|| hwnd
== tip_window
)
3791 /* Don't restrict the sizing of fullscreened frames, allowing them to be
3792 flush with the sides of the screen. */
3793 f
= x_window_to_frame (dpyinfo
, hwnd
);
3794 if (f
&& FRAME_PREV_FSMODE (f
) != FULLSCREEN_NONE
)
3799 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
3801 wp
.length
= sizeof (WINDOWPLACEMENT
);
3802 GetWindowPlacement (hwnd
, &wp
);
3804 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
&& wp
.showCmd
!= SW_SHOWMINIMIZED
3805 && (lppos
->flags
& SWP_NOSIZE
) == 0)
3812 DWORD internal_border
;
3813 DWORD scrollbar_extra
;
3816 wp
.length
= sizeof (wp
);
3817 GetWindowRect (hwnd
, &wr
);
3821 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
3822 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
3823 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
3824 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
3828 memset (&rect
, 0, sizeof (rect
));
3829 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
3830 GetMenu (hwnd
) != NULL
);
3832 /* Force width and height of client area to be exact
3833 multiples of the character cell dimensions. */
3834 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
3835 - 2 * internal_border
- scrollbar_extra
)
3837 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
3838 - 2 * internal_border
)
3843 /* For right/bottom sizing we can just fix the sizes.
3844 However for top/left sizing we will need to fix the X
3845 and Y positions as well. */
3847 int cx_mintrack
= GetSystemMetrics (SM_CXMINTRACK
);
3848 int cy_mintrack
= GetSystemMetrics (SM_CYMINTRACK
);
3850 lppos
->cx
= max (lppos
->cx
- wdiff
, cx_mintrack
);
3851 lppos
->cy
= max (lppos
->cy
- hdiff
, cy_mintrack
);
3853 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
3854 && (lppos
->flags
& SWP_NOMOVE
) == 0)
3856 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
3863 lppos
->flags
|= SWP_NOMOVE
;
3874 case WM_GETMINMAXINFO
:
3875 /* Hack to allow resizing the Emacs frame above the screen size.
3876 Note that Windows 9x limits coordinates to 16-bits. */
3877 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.x
= 32767;
3878 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.y
= 32767;
3882 if (LOWORD (lParam
) == HTCLIENT
)
3884 f
= x_window_to_frame (dpyinfo
, hwnd
);
3885 if (f
&& f
->output_data
.w32
->hourglass_p
3886 && !menubar_in_use
&& !current_popup_menu
)
3887 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
3889 SetCursor (f
->output_data
.w32
->current_cursor
);
3894 case WM_EMACS_SETCURSOR
:
3896 Cursor cursor
= (Cursor
) wParam
;
3897 f
= x_window_to_frame (dpyinfo
, hwnd
);
3900 f
->output_data
.w32
->current_cursor
= cursor
;
3901 if (!f
->output_data
.w32
->hourglass_p
)
3907 case WM_EMACS_CREATESCROLLBAR
:
3908 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
3909 (struct scroll_bar
*) lParam
);
3911 case WM_EMACS_SHOWWINDOW
:
3912 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
3914 case WM_EMACS_BRINGTOTOP
:
3915 case WM_EMACS_SETFOREGROUND
:
3917 HWND foreground_window
;
3918 DWORD foreground_thread
, retval
;
3920 /* On NT 5.0, and apparently Windows 98, it is necessary to
3921 attach to the thread that currently has focus in order to
3922 pull the focus away from it. */
3923 foreground_window
= GetForegroundWindow ();
3924 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
3925 if (!foreground_window
3926 || foreground_thread
== GetCurrentThreadId ()
3927 || !AttachThreadInput (GetCurrentThreadId (),
3928 foreground_thread
, TRUE
))
3929 foreground_thread
= 0;
3931 retval
= SetForegroundWindow ((HWND
) wParam
);
3932 if (msg
== WM_EMACS_BRINGTOTOP
)
3933 retval
= BringWindowToTop ((HWND
) wParam
);
3935 /* Detach from the previous foreground thread. */
3936 if (foreground_thread
)
3937 AttachThreadInput (GetCurrentThreadId (),
3938 foreground_thread
, FALSE
);
3943 case WM_EMACS_SETWINDOWPOS
:
3945 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
3946 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
3947 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
3950 case WM_EMACS_DESTROYWINDOW
:
3951 DragAcceptFiles ((HWND
) wParam
, FALSE
);
3952 return DestroyWindow ((HWND
) wParam
);
3954 case WM_EMACS_HIDE_CARET
:
3955 return HideCaret (hwnd
);
3957 case WM_EMACS_SHOW_CARET
:
3958 return ShowCaret (hwnd
);
3960 case WM_EMACS_DESTROY_CARET
:
3961 w32_system_caret_hwnd
= NULL
;
3962 w32_visible_system_caret_hwnd
= NULL
;
3963 return DestroyCaret ();
3965 case WM_EMACS_TRACK_CARET
:
3966 /* If there is currently no system caret, create one. */
3967 if (w32_system_caret_hwnd
== NULL
)
3969 /* Use the default caret width, and avoid changing it
3970 unnecessarily, as it confuses screen reader software. */
3971 w32_system_caret_hwnd
= hwnd
;
3972 CreateCaret (hwnd
, NULL
, 0,
3973 w32_system_caret_height
);
3976 if (!SetCaretPos (w32_system_caret_x
, w32_system_caret_y
))
3978 /* Ensure visible caret gets turned on when requested. */
3979 else if (w32_use_visible_system_caret
3980 && w32_visible_system_caret_hwnd
!= hwnd
)
3982 w32_visible_system_caret_hwnd
= hwnd
;
3983 return ShowCaret (hwnd
);
3985 /* Ensure visible caret gets turned off when requested. */
3986 else if (!w32_use_visible_system_caret
3987 && w32_visible_system_caret_hwnd
)
3989 w32_visible_system_caret_hwnd
= NULL
;
3990 return HideCaret (hwnd
);
3995 case WM_EMACS_TRACKPOPUPMENU
:
4000 pos
= (POINT
*)lParam
;
4001 flags
= TPM_CENTERALIGN
;
4002 if (button_state
& LMOUSE
)
4003 flags
|= TPM_LEFTBUTTON
;
4004 else if (button_state
& RMOUSE
)
4005 flags
|= TPM_RIGHTBUTTON
;
4007 /* Remember we did a SetCapture on the initial mouse down event,
4008 so for safety, we make sure the capture is canceled now. */
4012 /* Use menubar_active to indicate that WM_INITMENU is from
4013 TrackPopupMenu below, and should be ignored. */
4014 f
= x_window_to_frame (dpyinfo
, hwnd
);
4016 f
->output_data
.w32
->menubar_active
= 1;
4018 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
4022 /* Eat any mouse messages during popupmenu */
4023 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
4025 /* Get the menu selection, if any */
4026 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
4028 retval
= LOWORD (amsg
.wParam
);
4042 case WM_EMACS_FILENOTIFY
:
4043 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4047 /* Check for messages registered at runtime. */
4048 if (msg
== msh_mousewheel
)
4050 wmsg
.dwModifiers
= w32_get_modifiers ();
4051 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4052 signal_user_input ();
4057 return (w32_unicode_gui
? DefWindowProcW
: DefWindowProcA
) (hwnd
, msg
, wParam
, lParam
);
4060 /* The most common default return code for handled messages is 0. */
4065 my_create_window (struct frame
* f
)
4068 static int coords
[2];
4069 Lisp_Object left
, top
;
4070 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
4072 /* When called with RES_TYPE_NUMBER, x_get_arg will return zero for
4073 anything that is not a number and is not Qunbound. */
4074 left
= x_get_arg (dpyinfo
, Qnil
, Qleft
, "left", "Left", RES_TYPE_NUMBER
);
4075 top
= x_get_arg (dpyinfo
, Qnil
, Qtop
, "top", "Top", RES_TYPE_NUMBER
);
4076 if (EQ (left
, Qunbound
))
4077 coords
[0] = CW_USEDEFAULT
;
4079 coords
[0] = XINT (left
);
4080 if (EQ (top
, Qunbound
))
4081 coords
[1] = CW_USEDEFAULT
;
4083 coords
[1] = XINT (top
);
4085 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
,
4086 (WPARAM
)f
, (LPARAM
)coords
))
4088 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
4092 /* Create a tooltip window. Unlike my_create_window, we do not do this
4093 indirectly via the Window thread, as we do not need to process Window
4094 messages for the tooltip. Creating tooltips indirectly also creates
4095 deadlocks when tooltips are created for menu items. */
4097 my_create_tip_window (struct frame
*f
)
4101 rect
.left
= rect
.top
= 0;
4102 rect
.right
= FRAME_PIXEL_WIDTH (f
);
4103 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
4105 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
4106 FRAME_EXTERNAL_MENU_BAR (f
));
4108 tip_window
= FRAME_W32_WINDOW (f
)
4109 = CreateWindow (EMACS_CLASS
,
4111 f
->output_data
.w32
->dwStyle
,
4114 rect
.right
- rect
.left
,
4115 rect
.bottom
- rect
.top
,
4116 FRAME_W32_WINDOW (SELECTED_FRAME ()), /* owner */
4123 SetWindowLong (tip_window
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
4124 SetWindowLong (tip_window
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
4125 SetWindowLong (tip_window
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
4126 SetWindowLong (tip_window
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
4128 /* Tip frames have no scrollbars. */
4129 SetWindowLong (tip_window
, WND_SCROLLBAR_INDEX
, 0);
4131 /* Do this to discard the default setting specified by our parent. */
4132 ShowWindow (tip_window
, SW_HIDE
);
4137 /* Create and set up the w32 window for frame F. */
4140 w32_window (struct frame
*f
, long window_prompting
, int minibuffer_only
)
4144 /* Use the resource name as the top-level window name
4145 for looking up resources. Make a non-Lisp copy
4146 for the window manager, so GC relocation won't bother it.
4148 Elsewhere we specify the window name for the window manager. */
4149 f
->namebuf
= xstrdup (SSDATA (Vx_resource_name
));
4151 my_create_window (f
);
4153 validate_x_resource_name ();
4155 /* x_set_name normally ignores requests to set the name if the
4156 requested name is the same as the current name. This is the one
4157 place where that assumption isn't correct; f->name is set, but
4158 the server hasn't been told. */
4161 int explicit = f
->explicit_name
;
4163 f
->explicit_name
= 0;
4165 fset_name (f
, Qnil
);
4166 x_set_name (f
, name
, explicit);
4171 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
4172 initialize_frame_menubar (f
);
4174 if (FRAME_W32_WINDOW (f
) == 0)
4175 error ("Unable to create window");
4178 /* Handle the icon stuff for this window. Perhaps later we might
4179 want an x_set_icon_position which can be called interactively as
4183 x_icon (struct frame
*f
, Lisp_Object parms
)
4185 Lisp_Object icon_x
, icon_y
;
4186 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
4188 /* Set the position of the icon. Note that Windows 95 groups all
4189 icons in the tray. */
4190 icon_x
= x_get_arg (dpyinfo
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
4191 icon_y
= x_get_arg (dpyinfo
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
4192 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
4194 CHECK_NUMBER (icon_x
);
4195 CHECK_NUMBER (icon_y
);
4197 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
4198 error ("Both left and top icon corners of icon must be specified");
4203 /* Start up iconic or window? */
4204 x_wm_set_window_state
4205 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
4209 x_text_icon (f
, SSDATA ((!NILP (f
->icon_name
)
4219 x_make_gc (struct frame
*f
)
4221 XGCValues gc_values
;
4225 /* Create the GC's of this frame.
4226 Note that many default values are used. */
4229 gc_values
.font
= FRAME_FONT (f
);
4231 /* Cursor has cursor-color background, background-color foreground. */
4232 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
4233 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
4234 f
->output_data
.w32
->cursor_gc
4235 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
4236 (GCFont
| GCForeground
| GCBackground
),
4240 f
->output_data
.w32
->white_relief
.gc
= 0;
4241 f
->output_data
.w32
->black_relief
.gc
= 0;
4247 /* Handler for signals raised during x_create_frame and
4248 x_create_tip_frame. FRAME is the frame which is partially
4252 unwind_create_frame (Lisp_Object frame
)
4254 struct frame
*f
= XFRAME (frame
);
4256 /* If frame is ``official'', nothing to do. */
4257 if (NILP (Fmemq (frame
, Vframe_list
)))
4260 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
4262 /* If the frame's image cache refcount is still the same as our
4263 private shadow variable, it means we are unwinding a frame
4264 for which we didn't yet call init_frame_faces, where the
4265 refcount is incremented. Therefore, we increment it here, so
4266 that free_frame_faces, called in x_free_frame_resources
4267 below, will not mistakenly decrement the counter that was not
4268 incremented yet to account for this new frame. */
4269 if (FRAME_IMAGE_CACHE (f
) != NULL
4270 && FRAME_IMAGE_CACHE (f
)->refcount
== image_cache_refcount
)
4271 FRAME_IMAGE_CACHE (f
)->refcount
++;
4274 x_free_frame_resources (f
);
4278 /* Check that reference counts are indeed correct. */
4279 eassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
4280 eassert ((dpyinfo
->terminal
->image_cache
== NULL
4281 && image_cache_refcount
== 0)
4282 || (dpyinfo
->terminal
->image_cache
!= NULL
4283 && dpyinfo
->terminal
->image_cache
->refcount
== image_cache_refcount
));
4292 do_unwind_create_frame (Lisp_Object frame
)
4294 unwind_create_frame (frame
);
4298 unwind_create_frame_1 (Lisp_Object val
)
4300 inhibit_lisp_code
= val
;
4304 x_default_font_parameter (struct frame
*f
, Lisp_Object parms
)
4306 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
4307 Lisp_Object font_param
= x_get_arg (dpyinfo
, parms
, Qfont
, NULL
, NULL
,
4310 if (EQ (font_param
, Qunbound
))
4312 font
= !NILP (font_param
) ? font_param
4313 : x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4315 if (!STRINGP (font
))
4318 static char *names
[]
4319 = { "Courier New-10",
4320 "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1",
4321 "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1",
4325 for (i
= 0; names
[i
]; i
++)
4327 font
= font_open_by_name (f
, build_unibyte_string (names
[i
]));
4332 error ("No suitable font was found");
4334 else if (!NILP (font_param
))
4336 /* Remember the explicit font parameter, so we can re-apply it after
4337 we've applied the `default' face settings. */
4338 x_set_frame_parameters (f
, Fcons (Fcons (Qfont_param
, font_param
), Qnil
));
4340 x_default_parameter (f
, parms
, Qfont
, font
, "font", "Font", RES_TYPE_STRING
);
4343 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
4345 doc
: /* Make a new window, which is called a \"frame\" in Emacs terms.
4346 Return an Emacs frame object.
4347 PARAMETERS is an alist of frame parameters.
4348 If the parameters specify that the frame should not have a minibuffer,
4349 and do not specify a specific minibuffer window to use,
4350 then `default-minibuffer-frame' must be a frame whose minibuffer can
4351 be shared by the new frame.
4353 This function is an internal primitive--use `make-frame' instead. */)
4354 (Lisp_Object parameters
)
4357 Lisp_Object frame
, tem
;
4359 int minibuffer_only
= 0;
4360 long window_prompting
= 0;
4362 ptrdiff_t count
= SPECPDL_INDEX ();
4363 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4364 Lisp_Object display
;
4365 struct w32_display_info
*dpyinfo
= NULL
;
4369 if (!FRAME_W32_P (SELECTED_FRAME ())
4370 && !FRAME_INITIAL_P (SELECTED_FRAME ()))
4371 error ("Cannot create a GUI frame in a -nw session");
4373 /* Make copy of frame parameters because the original is in pure
4375 parameters
= Fcopy_alist (parameters
);
4377 /* Use this general default value to start with
4378 until we know if this frame has a specified name. */
4379 Vx_resource_name
= Vinvocation_name
;
4381 display
= x_get_arg (dpyinfo
, parameters
, Qterminal
, 0, 0, RES_TYPE_NUMBER
);
4382 if (EQ (display
, Qunbound
))
4383 display
= x_get_arg (dpyinfo
, parameters
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
4384 if (EQ (display
, Qunbound
))
4386 dpyinfo
= check_x_display_info (display
);
4387 kb
= dpyinfo
->terminal
->kboard
;
4389 if (!dpyinfo
->terminal
->name
)
4390 error ("Terminal is not live, can't create new frames on it");
4392 name
= x_get_arg (dpyinfo
, parameters
, Qname
, "name", "Name", RES_TYPE_STRING
);
4394 && ! EQ (name
, Qunbound
)
4396 error ("Invalid frame name--not a string or nil");
4399 Vx_resource_name
= name
;
4401 /* See if parent window is specified. */
4402 parent
= x_get_arg (dpyinfo
, parameters
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
4403 if (EQ (parent
, Qunbound
))
4405 if (! NILP (parent
))
4406 CHECK_NUMBER (parent
);
4408 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
4409 /* No need to protect DISPLAY because that's not used after passing
4410 it to make_frame_without_minibuffer. */
4412 GCPRO4 (parameters
, parent
, name
, frame
);
4413 tem
= x_get_arg (dpyinfo
, parameters
, Qminibuffer
, "minibuffer", "Minibuffer",
4415 if (EQ (tem
, Qnone
) || NILP (tem
))
4416 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
4417 else if (EQ (tem
, Qonly
))
4419 f
= make_minibuffer_frame ();
4420 minibuffer_only
= 1;
4422 else if (WINDOWP (tem
))
4423 f
= make_frame_without_minibuffer (tem
, kb
, display
);
4427 XSETFRAME (frame
, f
);
4429 /* By default, make scrollbars the system standard width. */
4430 x_set_scroll_bar_default_width (f
);
4432 f
->terminal
= dpyinfo
->terminal
;
4434 f
->output_method
= output_w32
;
4435 f
->output_data
.w32
= xzalloc (sizeof (struct w32_output
));
4436 FRAME_FONTSET (f
) = -1;
4439 (f
, x_get_arg (dpyinfo
, parameters
, Qicon_name
, "iconName", "Title",
4441 if (! STRINGP (f
->icon_name
))
4442 fset_icon_name (f
, Qnil
);
4444 /* FRAME_DISPLAY_INFO (f) = dpyinfo; */
4446 /* With FRAME_DISPLAY_INFO set up, this unwind-protect is safe. */
4447 record_unwind_protect (do_unwind_create_frame
, frame
);
4450 image_cache_refcount
=
4451 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
4452 dpyinfo_refcount
= dpyinfo
->reference_count
;
4453 #endif /* GLYPH_DEBUG */
4455 /* Specify the parent under which to make this window. */
4459 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
4460 f
->output_data
.w32
->explicit_parent
= 1;
4464 f
->output_data
.w32
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
4465 f
->output_data
.w32
->explicit_parent
= 0;
4468 /* Set the name; the functions to which we pass f expect the name to
4470 if (EQ (name
, Qunbound
) || NILP (name
))
4472 fset_name (f
, build_string (dpyinfo
->w32_id_name
));
4473 f
->explicit_name
= 0;
4477 fset_name (f
, name
);
4478 f
->explicit_name
= 1;
4479 /* use the frame's title when getting resources for this frame. */
4480 specbind (Qx_resource_name
, name
);
4483 if (uniscribe_available
)
4484 register_font_driver (&uniscribe_font_driver
, f
);
4485 register_font_driver (&w32font_driver
, f
);
4487 x_default_parameter (f
, parameters
, Qfont_backend
, Qnil
,
4488 "fontBackend", "FontBackend", RES_TYPE_STRING
);
4489 /* Extract the window parameters from the supplied values
4490 that are needed to determine window geometry. */
4491 x_default_font_parameter (f
, parameters
);
4492 x_default_parameter (f
, parameters
, Qborder_width
, make_number (2),
4493 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4495 /* We recognize either internalBorderWidth or internalBorder
4496 (which is what xterm calls it). */
4497 if (NILP (Fassq (Qinternal_border_width
, parameters
)))
4501 value
= x_get_arg (dpyinfo
, parameters
, Qinternal_border_width
,
4502 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
4503 if (! EQ (value
, Qunbound
))
4504 parameters
= Fcons (Fcons (Qinternal_border_width
, value
),
4507 /* Default internalBorderWidth to 0 on Windows to match other programs. */
4508 x_default_parameter (f
, parameters
, Qinternal_border_width
, make_number (0),
4509 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
4510 x_default_parameter (f
, parameters
, Qright_divider_width
, make_number (0),
4511 NULL
, NULL
, RES_TYPE_NUMBER
);
4512 x_default_parameter (f
, parameters
, Qbottom_divider_width
, make_number (0),
4513 NULL
, NULL
, RES_TYPE_NUMBER
);
4514 x_default_parameter (f
, parameters
, Qvertical_scroll_bars
, Qright
,
4515 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
4517 /* Also do the stuff which must be set before the window exists. */
4518 x_default_parameter (f
, parameters
, Qforeground_color
, build_string ("black"),
4519 "foreground", "Foreground", RES_TYPE_STRING
);
4520 x_default_parameter (f
, parameters
, Qbackground_color
, build_string ("white"),
4521 "background", "Background", RES_TYPE_STRING
);
4522 x_default_parameter (f
, parameters
, Qmouse_color
, build_string ("black"),
4523 "pointerColor", "Foreground", RES_TYPE_STRING
);
4524 x_default_parameter (f
, parameters
, Qborder_color
, build_string ("black"),
4525 "borderColor", "BorderColor", RES_TYPE_STRING
);
4526 x_default_parameter (f
, parameters
, Qscreen_gamma
, Qnil
,
4527 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
4528 x_default_parameter (f
, parameters
, Qline_spacing
, Qnil
,
4529 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
4530 x_default_parameter (f
, parameters
, Qleft_fringe
, Qnil
,
4531 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
4532 x_default_parameter (f
, parameters
, Qright_fringe
, Qnil
,
4533 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
4534 /* Process alpha here (Bug#16619). */
4535 x_default_parameter (f
, parameters
, Qalpha
, Qnil
,
4536 "alpha", "Alpha", RES_TYPE_NUMBER
);
4538 /* Init faces before x_default_parameter is called for scroll-bar
4539 parameters because that function calls x_set_scroll_bar_width,
4540 which calls change_frame_size, which calls Fset_window_buffer,
4541 which runs hooks, which call Fvertical_motion. At the end, we
4542 end up in init_iterator with a null face cache, which should not
4544 init_frame_faces (f
);
4546 /* Avoid calling window-configuration-change-hook; otherwise we
4547 could get an infloop in next_frame since the frame is not yet in
4550 ptrdiff_t count2
= SPECPDL_INDEX ();
4552 record_unwind_protect (unwind_create_frame_1
, inhibit_lisp_code
);
4553 inhibit_lisp_code
= Qt
;
4555 /* PXW: This is a duplicate from below. We have to do it here since
4556 otherwise x_set_tool_bar_lines will work with the character sizes
4557 installed by init_frame_faces while the frame's pixel size is still
4558 calculated from a character size of 1 and we subsequently hit the
4559 eassert (height >= 0) assertion in window_box_height. The
4560 non-pixelwise code apparently worked around this because it had one
4561 frame line vs one toolbar line which left us with a zero root
4562 window height which was obviously wrong as well ... */
4563 change_frame_size (f
, FRAME_COLS (f
) * FRAME_COLUMN_WIDTH (f
),
4564 FRAME_LINES (f
) * FRAME_LINE_HEIGHT (f
), 1, 0, 0, 1);
4566 /* The X resources controlling the menu-bar and tool-bar are
4567 processed specially at startup, and reflected in the mode
4568 variables; ignore them here. */
4569 x_default_parameter (f
, parameters
, Qmenu_bar_lines
,
4570 NILP (Vmenu_bar_mode
)
4571 ? make_number (0) : make_number (1),
4572 NULL
, NULL
, RES_TYPE_NUMBER
);
4573 x_default_parameter (f
, parameters
, Qtool_bar_lines
,
4574 NILP (Vtool_bar_mode
)
4575 ? make_number (0) : make_number (1),
4576 NULL
, NULL
, RES_TYPE_NUMBER
);
4578 unbind_to (count2
, Qnil
);
4581 x_default_parameter (f
, parameters
, Qbuffer_predicate
, Qnil
,
4582 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
4583 x_default_parameter (f
, parameters
, Qtitle
, Qnil
,
4584 "title", "Title", RES_TYPE_STRING
);
4585 x_default_parameter (f
, parameters
, Qfullscreen
, Qnil
,
4586 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
4588 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
4589 f
->output_data
.w32
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
4591 f
->output_data
.w32
->text_cursor
= w32_load_cursor (IDC_IBEAM
);
4592 f
->output_data
.w32
->nontext_cursor
= w32_load_cursor (IDC_ARROW
);
4593 f
->output_data
.w32
->modeline_cursor
= w32_load_cursor (IDC_ARROW
);
4594 f
->output_data
.w32
->hand_cursor
= w32_load_cursor (IDC_HAND
);
4595 f
->output_data
.w32
->hourglass_cursor
= w32_load_cursor (IDC_WAIT
);
4596 f
->output_data
.w32
->horizontal_drag_cursor
= w32_load_cursor (IDC_SIZEWE
);
4597 f
->output_data
.w32
->vertical_drag_cursor
= w32_load_cursor (IDC_SIZENS
);
4599 f
->output_data
.w32
->current_cursor
= f
->output_data
.w32
->nontext_cursor
;
4601 window_prompting
= x_figure_window_size (f
, parameters
, 1);
4603 tem
= x_get_arg (dpyinfo
, parameters
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
4604 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
4606 w32_window (f
, window_prompting
, minibuffer_only
);
4607 x_icon (f
, parameters
);
4611 /* Now consider the frame official. */
4612 f
->terminal
->reference_count
++;
4613 FRAME_DISPLAY_INFO (f
)->reference_count
++;
4614 Vframe_list
= Fcons (frame
, Vframe_list
);
4616 /* We need to do this after creating the window, so that the
4617 icon-creation functions can say whose icon they're describing. */
4618 x_default_parameter (f
, parameters
, Qicon_type
, Qnil
,
4619 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
4621 x_default_parameter (f
, parameters
, Qauto_raise
, Qnil
,
4622 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4623 x_default_parameter (f
, parameters
, Qauto_lower
, Qnil
,
4624 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4625 x_default_parameter (f
, parameters
, Qcursor_type
, Qbox
,
4626 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4627 x_default_parameter (f
, parameters
, Qscroll_bar_width
, Qnil
,
4628 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
4630 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4631 Change will not be effected unless different from the current
4633 width
= FRAME_TEXT_WIDTH (f
);
4634 height
= FRAME_TEXT_HEIGHT (f
);
4635 FRAME_TEXT_HEIGHT (f
) = 0;
4636 SET_FRAME_WIDTH (f
, 0);
4637 change_frame_size (f
, width
, height
, 1, 0, 0, 1);
4639 /* Tell the server what size and position, etc, we want, and how
4640 badly we want them. This should be done after we have the menu
4641 bar so that its size can be taken into account. */
4643 x_wm_set_size_hint (f
, window_prompting
, 0);
4646 /* Make the window appear on the frame and enable display, unless
4647 the caller says not to. However, with explicit parent, Emacs
4648 cannot control visibility, so don't try. */
4649 if (! f
->output_data
.w32
->explicit_parent
)
4651 Lisp_Object visibility
;
4653 visibility
= x_get_arg (dpyinfo
, parameters
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
4654 if (EQ (visibility
, Qunbound
))
4657 if (EQ (visibility
, Qicon
))
4658 x_iconify_frame (f
);
4659 else if (! NILP (visibility
))
4660 x_make_frame_visible (f
);
4662 /* Must have been Qnil. */
4666 /* Initialize `default-minibuffer-frame' in case this is the first
4667 frame on this terminal. */
4668 if (FRAME_HAS_MINIBUF_P (f
)
4669 && (!FRAMEP (KVAR (kb
, Vdefault_minibuffer_frame
))
4670 || !FRAME_LIVE_P (XFRAME (KVAR (kb
, Vdefault_minibuffer_frame
)))))
4671 kset_default_minibuffer_frame (kb
, frame
);
4673 /* All remaining specified parameters, which have not been "used"
4674 by x_get_arg and friends, now go in the misc. alist of the frame. */
4675 for (tem
= parameters
; CONSP (tem
); tem
= XCDR (tem
))
4676 if (CONSP (XCAR (tem
)) && !NILP (XCAR (XCAR (tem
))))
4677 fset_param_alist (f
, Fcons (XCAR (tem
), f
->param_alist
));
4681 /* Make sure windows on this frame appear in calls to next-window
4682 and similar functions. */
4683 Vwindow_list
= Qnil
;
4685 return unbind_to (count
, frame
);
4688 /* FRAME is used only to get a handle on the X display. We don't pass the
4689 display info directly because we're called from frame.c, which doesn't
4690 know about that structure. */
4692 x_get_focus_frame (struct frame
*frame
)
4694 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (frame
);
4696 if (! dpyinfo
->w32_focus_frame
)
4699 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
4703 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
4704 doc
: /* Internal function called by `color-defined-p', which see.
4705 \(Note that the Nextstep version of this function ignores FRAME.) */)
4706 (Lisp_Object color
, Lisp_Object frame
)
4709 struct frame
*f
= decode_window_system_frame (frame
);
4711 CHECK_STRING (color
);
4713 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
4719 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
4720 doc
: /* Internal function called by `color-values', which see. */)
4721 (Lisp_Object color
, Lisp_Object frame
)
4724 struct frame
*f
= decode_window_system_frame (frame
);
4726 CHECK_STRING (color
);
4728 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
4729 return list3i ((GetRValue (foo
.pixel
) << 8) | GetRValue (foo
.pixel
),
4730 (GetGValue (foo
.pixel
) << 8) | GetGValue (foo
.pixel
),
4731 (GetBValue (foo
.pixel
) << 8) | GetBValue (foo
.pixel
));
4736 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
4737 doc
: /* Internal function called by `display-color-p', which see. */)
4738 (Lisp_Object display
)
4740 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4742 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
4748 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
,
4749 Sx_display_grayscale_p
, 0, 1, 0,
4750 doc
: /* Return t if DISPLAY supports shades of gray.
4751 Note that color displays do support shades of gray.
4752 The optional argument DISPLAY specifies which display to ask about.
4753 DISPLAY should be either a frame or a display name (a string).
4754 If omitted or nil, that stands for the selected frame's display. */)
4755 (Lisp_Object display
)
4757 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4759 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
4765 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
,
4766 Sx_display_pixel_width
, 0, 1, 0,
4767 doc
: /* Return the width in pixels of DISPLAY.
4768 The optional argument DISPLAY specifies which display to ask about.
4769 DISPLAY should be either a frame or a display name (a string).
4770 If omitted or nil, that stands for the selected frame's display.
4772 On \"multi-monitor\" setups this refers to the pixel width for all
4773 physical monitors associated with DISPLAY. To get information for
4774 each physical monitor, use `display-monitor-attributes-list'. */)
4775 (Lisp_Object display
)
4777 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4779 return make_number (x_display_pixel_width (dpyinfo
));
4782 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
4783 Sx_display_pixel_height
, 0, 1, 0,
4784 doc
: /* Return the height in pixels of DISPLAY.
4785 The optional argument DISPLAY specifies which display to ask about.
4786 DISPLAY should be either a frame or a display name (a string).
4787 If omitted or nil, that stands for the selected frame's display.
4789 On \"multi-monitor\" setups this refers to the pixel height for all
4790 physical monitors associated with DISPLAY. To get information for
4791 each physical monitor, use `display-monitor-attributes-list'. */)
4792 (Lisp_Object display
)
4794 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4796 return make_number (x_display_pixel_height (dpyinfo
));
4799 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
4801 doc
: /* Return the number of bitplanes of DISPLAY.
4802 The optional argument DISPLAY specifies which display to ask about.
4803 DISPLAY should be either a frame or a display name (a string).
4804 If omitted or nil, that stands for the selected frame's display. */)
4805 (Lisp_Object display
)
4807 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4809 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
4812 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
4814 doc
: /* Return the number of color cells of DISPLAY.
4815 The optional argument DISPLAY specifies which display to ask about.
4816 DISPLAY should be either a frame or a display name (a string).
4817 If omitted or nil, that stands for the selected frame's display. */)
4818 (Lisp_Object display
)
4820 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4823 /* Don't use NCOLORS: it returns incorrect results under remote
4824 * desktop. We force 24+ bit depths to 24-bit, both to prevent an
4825 * overflow and because probably is more meaningful on Windows
4828 cap
= 1 << min (dpyinfo
->n_planes
* dpyinfo
->n_cbits
, 24);
4829 return make_number (cap
);
4832 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
4833 Sx_server_max_request_size
,
4835 doc
: /* Return the maximum request size of the server of DISPLAY.
4836 The optional argument DISPLAY specifies which display to ask about.
4837 DISPLAY should be either a frame or a display name (a string).
4838 If omitted or nil, that stands for the selected frame's display. */)
4839 (Lisp_Object display
)
4841 return make_number (1);
4844 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
4845 doc
: /* Return the "vendor ID" string of the GUI software on TERMINAL.
4847 \(Labeling every distributor as a "vendor" embodies the false assumption
4848 that operating systems cannot be developed and distributed noncommercially.)
4850 For GNU and Unix systems, this queries the X server software; for
4851 MS-Windows, this queries the OS.
4853 The optional argument TERMINAL specifies which display to ask about.
4854 TERMINAL should be a terminal object, a frame or a display name (a string).
4855 If omitted or nil, that stands for the selected frame's display. */)
4856 (Lisp_Object terminal
)
4858 return build_string ("Microsoft Corp.");
4861 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
4862 doc
: /* Return the version numbers of the GUI software on TERMINAL.
4863 The value is a list of three integers specifying the version of the GUI
4866 For GNU and Unix system, the first 2 numbers are the version of the X
4867 Protocol used on TERMINAL and the 3rd number is the distributor-specific
4868 release number. For MS-Windows, the 3 numbers report the version and
4869 the build number of the OS.
4871 See also the function `x-server-vendor'.
4873 The optional argument TERMINAL specifies which display to ask about.
4874 TERMINAL should be a terminal object, a frame or a display name (a string).
4875 If omitted or nil, that stands for the selected frame's display. */)
4876 (Lisp_Object terminal
)
4878 return list3i (w32_major_version
, w32_minor_version
, w32_build_number
);
4881 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
4882 doc
: /* Return the number of screens on the server of DISPLAY.
4883 The optional argument DISPLAY specifies which display to ask about.
4884 DISPLAY should be either a frame or a display name (a string).
4885 If omitted or nil, that stands for the selected frame's display. */)
4886 (Lisp_Object display
)
4888 return make_number (1);
4891 DEFUN ("x-display-mm-height", Fx_display_mm_height
,
4892 Sx_display_mm_height
, 0, 1, 0,
4893 doc
: /* Return the height in millimeters of DISPLAY.
4894 The optional argument DISPLAY specifies which display to ask about.
4895 DISPLAY should be either a frame or a display name (a string).
4896 If omitted or nil, that stands for the selected frame's display.
4898 On \"multi-monitor\" setups this refers to the height in millimeters for
4899 all physical monitors associated with DISPLAY. To get information
4900 for each physical monitor, use `display-monitor-attributes-list'. */)
4901 (Lisp_Object display
)
4903 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4905 double mm_per_pixel
;
4908 mm_per_pixel
= ((double) GetDeviceCaps (hdc
, VERTSIZE
)
4909 / GetDeviceCaps (hdc
, VERTRES
));
4910 ReleaseDC (NULL
, hdc
);
4912 return make_number (x_display_pixel_height (dpyinfo
) * mm_per_pixel
+ 0.5);
4915 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
4916 doc
: /* Return the width in millimeters of DISPLAY.
4917 The optional argument DISPLAY specifies which display to ask about.
4918 DISPLAY should be either a frame or a display name (a string).
4919 If omitted or nil, that stands for the selected frame's display.
4921 On \"multi-monitor\" setups this refers to the width in millimeters for
4922 all physical monitors associated with TERMINAL. To get information
4923 for each physical monitor, use `display-monitor-attributes-list'. */)
4924 (Lisp_Object display
)
4926 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4928 double mm_per_pixel
;
4931 mm_per_pixel
= ((double) GetDeviceCaps (hdc
, HORZSIZE
)
4932 / GetDeviceCaps (hdc
, HORZRES
));
4933 ReleaseDC (NULL
, hdc
);
4935 return make_number (x_display_pixel_width (dpyinfo
) * mm_per_pixel
+ 0.5);
4938 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
4939 Sx_display_backing_store
, 0, 1, 0,
4940 doc
: /* Return an indication of whether DISPLAY does backing store.
4941 The value may be `always', `when-mapped', or `not-useful'.
4942 The optional argument DISPLAY specifies which display to ask about.
4943 DISPLAY should be either a frame or a display name (a string).
4944 If omitted or nil, that stands for the selected frame's display. */)
4945 (Lisp_Object display
)
4947 return intern ("not-useful");
4950 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
4951 Sx_display_visual_class
, 0, 1, 0,
4952 doc
: /* Return the visual class of DISPLAY.
4953 The value is one of the symbols `static-gray', `gray-scale',
4954 `static-color', `pseudo-color', `true-color', or `direct-color'.
4956 The optional argument DISPLAY specifies which display to ask about.
4957 DISPLAY should be either a frame or a display name (a string).
4958 If omitted or nil, that stands for the selected frame's display. */)
4959 (Lisp_Object display
)
4961 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4962 Lisp_Object result
= Qnil
;
4964 if (dpyinfo
->has_palette
)
4965 result
= intern ("pseudo-color");
4966 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
4967 result
= intern ("static-grey");
4968 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
4969 result
= intern ("static-color");
4970 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
4971 result
= intern ("true-color");
4976 DEFUN ("x-display-save-under", Fx_display_save_under
,
4977 Sx_display_save_under
, 0, 1, 0,
4978 doc
: /* Return t if DISPLAY supports the save-under feature.
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. */)
4982 (Lisp_Object display
)
4987 static BOOL CALLBACK
4988 w32_monitor_enum (HMONITOR monitor
, HDC hdc
, RECT
*rcMonitor
, LPARAM dwData
)
4990 Lisp_Object
*monitor_list
= (Lisp_Object
*) dwData
;
4992 *monitor_list
= Fcons (make_save_ptr (monitor
), *monitor_list
);
4998 w32_display_monitor_attributes_list (void)
5000 Lisp_Object attributes_list
= Qnil
, primary_monitor_attributes
= Qnil
;
5001 Lisp_Object monitor_list
= Qnil
, monitor_frames
, rest
, frame
;
5004 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5006 if (!(enum_display_monitors_fn
&& get_monitor_info_fn
5007 && monitor_from_window_fn
))
5010 if (!enum_display_monitors_fn (NULL
, NULL
, w32_monitor_enum
,
5011 (LPARAM
) &monitor_list
)
5012 || NILP (monitor_list
))
5016 for (rest
= monitor_list
; CONSP (rest
); rest
= XCDR (rest
))
5019 monitors
= xmalloc (n_monitors
* sizeof (*monitors
));
5020 for (i
= 0; i
< n_monitors
; i
++)
5022 monitors
[i
] = XSAVE_POINTER (XCAR (monitor_list
), 0);
5023 monitor_list
= XCDR (monitor_list
);
5026 monitor_frames
= Fmake_vector (make_number (n_monitors
), Qnil
);
5027 FOR_EACH_FRAME (rest
, frame
)
5029 struct frame
*f
= XFRAME (frame
);
5031 if (FRAME_W32_P (f
) && !EQ (frame
, tip_frame
))
5034 monitor_from_window_fn (FRAME_W32_WINDOW (f
),
5035 MONITOR_DEFAULT_TO_NEAREST
);
5037 for (i
= 0; i
< n_monitors
; i
++)
5038 if (monitors
[i
] == monitor
)
5042 ASET (monitor_frames
, i
, Fcons (frame
, AREF (monitor_frames
, i
)));
5046 GCPRO3 (attributes_list
, primary_monitor_attributes
, monitor_frames
);
5048 for (i
= 0; i
< n_monitors
; i
++)
5050 Lisp_Object geometry
, workarea
, name
, attributes
= Qnil
;
5052 int width_mm
, height_mm
;
5053 struct MONITOR_INFO_EX mi
;
5055 mi
.cbSize
= sizeof (mi
);
5056 if (!get_monitor_info_fn (monitors
[i
], (struct MONITOR_INFO
*) &mi
))
5059 hdc
= CreateDCA ("DISPLAY", mi
.szDevice
, NULL
, NULL
);
5062 width_mm
= GetDeviceCaps (hdc
, HORZSIZE
);
5063 height_mm
= GetDeviceCaps (hdc
, VERTSIZE
);
5066 attributes
= Fcons (Fcons (Qframes
, AREF (monitor_frames
, i
)),
5069 name
= DECODE_SYSTEM (build_unibyte_string (mi
.szDevice
));
5071 attributes
= Fcons (Fcons (Qname
, name
), attributes
);
5073 attributes
= Fcons (Fcons (Qmm_size
, list2i (width_mm
, height_mm
)),
5076 workarea
= list4i (mi
.rcWork
.left
, mi
.rcWork
.top
,
5077 mi
.rcWork
.right
- mi
.rcWork
.left
,
5078 mi
.rcWork
.bottom
- mi
.rcWork
.top
);
5079 attributes
= Fcons (Fcons (Qworkarea
, workarea
), attributes
);
5081 geometry
= list4i (mi
.rcMonitor
.left
, mi
.rcMonitor
.top
,
5082 mi
.rcMonitor
.right
- mi
.rcMonitor
.left
,
5083 mi
.rcMonitor
.bottom
- mi
.rcMonitor
.top
);
5084 attributes
= Fcons (Fcons (Qgeometry
, geometry
), attributes
);
5086 if (mi
.dwFlags
& MONITORINFOF_PRIMARY
)
5087 primary_monitor_attributes
= attributes
;
5089 attributes_list
= Fcons (attributes
, attributes_list
);
5092 if (!NILP (primary_monitor_attributes
))
5093 attributes_list
= Fcons (primary_monitor_attributes
, attributes_list
);
5099 return attributes_list
;
5103 w32_display_monitor_attributes_list_fallback (struct w32_display_info
*dpyinfo
)
5105 Lisp_Object geometry
, workarea
, frames
, rest
, frame
, attributes
= Qnil
;
5107 double mm_per_pixel
;
5108 int pixel_width
, pixel_height
, width_mm
, height_mm
;
5111 /* Fallback: treat (possibly) multiple physical monitors as if they
5112 formed a single monitor as a whole. This should provide a
5113 consistent result at least on single monitor environments. */
5114 attributes
= Fcons (Fcons (Qname
, build_string ("combined screen")),
5118 FOR_EACH_FRAME (rest
, frame
)
5120 struct frame
*f
= XFRAME (frame
);
5122 if (FRAME_W32_P (f
) && !EQ (frame
, tip_frame
))
5123 frames
= Fcons (frame
, frames
);
5125 attributes
= Fcons (Fcons (Qframes
, frames
), attributes
);
5127 pixel_width
= x_display_pixel_width (dpyinfo
);
5128 pixel_height
= x_display_pixel_height (dpyinfo
);
5131 mm_per_pixel
= ((double) GetDeviceCaps (hdc
, HORZSIZE
)
5132 / GetDeviceCaps (hdc
, HORZRES
));
5133 width_mm
= pixel_width
* mm_per_pixel
+ 0.5;
5134 mm_per_pixel
= ((double) GetDeviceCaps (hdc
, VERTSIZE
)
5135 / GetDeviceCaps (hdc
, VERTRES
));
5136 height_mm
= pixel_height
* mm_per_pixel
+ 0.5;
5137 ReleaseDC (NULL
, hdc
);
5138 attributes
= Fcons (Fcons (Qmm_size
, list2i (width_mm
, height_mm
)),
5141 /* GetSystemMetrics below may return 0 for Windows 95 or NT 4.0, but
5143 geometry
= list4i (GetSystemMetrics (SM_XVIRTUALSCREEN
),
5144 GetSystemMetrics (SM_YVIRTUALSCREEN
),
5145 pixel_width
, pixel_height
);
5146 if (SystemParametersInfo (SPI_GETWORKAREA
, 0, &workarea_rect
, 0))
5147 workarea
= list4i (workarea_rect
.left
, workarea_rect
.top
,
5148 workarea_rect
.right
- workarea_rect
.left
,
5149 workarea_rect
.bottom
- workarea_rect
.top
);
5151 workarea
= geometry
;
5152 attributes
= Fcons (Fcons (Qworkarea
, workarea
), attributes
);
5154 attributes
= Fcons (Fcons (Qgeometry
, geometry
), attributes
);
5156 return list1 (attributes
);
5159 DEFUN ("w32-display-monitor-attributes-list", Fw32_display_monitor_attributes_list
,
5160 Sw32_display_monitor_attributes_list
,
5162 doc
: /* Return a list of physical monitor attributes on the W32 display DISPLAY.
5164 The optional argument DISPLAY specifies which display to ask about.
5165 DISPLAY should be either a frame or a display name (a string).
5166 If omitted or nil, that stands for the selected frame's display.
5168 Internal use only, use `display-monitor-attributes-list' instead. */)
5169 (Lisp_Object display
)
5171 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
5172 Lisp_Object attributes_list
;
5175 attributes_list
= w32_display_monitor_attributes_list ();
5176 if (NILP (attributes_list
))
5177 attributes_list
= w32_display_monitor_attributes_list_fallback (dpyinfo
);
5180 return attributes_list
;
5183 DEFUN ("set-message-beep", Fset_message_beep
, Sset_message_beep
, 1, 1, 0,
5184 doc
: /* Set the sound generated when the bell is rung.
5185 SOUND is 'asterisk, 'exclamation, 'hand, 'question, 'ok, or 'silent
5186 to use the corresponding system sound for the bell. The 'silent sound
5187 prevents Emacs from making any sound at all.
5188 SOUND is nil to use the normal beep. */)
5191 CHECK_SYMBOL (sound
);
5194 sound_type
= 0xFFFFFFFF;
5195 else if (EQ (sound
, intern ("asterisk")))
5196 sound_type
= MB_ICONASTERISK
;
5197 else if (EQ (sound
, intern ("exclamation")))
5198 sound_type
= MB_ICONEXCLAMATION
;
5199 else if (EQ (sound
, intern ("hand")))
5200 sound_type
= MB_ICONHAND
;
5201 else if (EQ (sound
, intern ("question")))
5202 sound_type
= MB_ICONQUESTION
;
5203 else if (EQ (sound
, intern ("ok")))
5205 else if (EQ (sound
, intern ("silent")))
5206 sound_type
= MB_EMACS_SILENT
;
5208 sound_type
= 0xFFFFFFFF;
5214 x_screen_planes (register struct frame
*f
)
5216 return FRAME_DISPLAY_INFO (f
)->n_planes
;
5219 /* Return the display structure for the display named NAME.
5220 Open a new connection if necessary. */
5222 struct w32_display_info
*
5223 x_display_info_for_name (Lisp_Object name
)
5225 struct w32_display_info
*dpyinfo
;
5227 CHECK_STRING (name
);
5229 for (dpyinfo
= &one_w32_display_info
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
5230 if (!NILP (Fstring_equal (XCAR (dpyinfo
->name_list_element
), name
)))
5233 /* Use this general default value to start with. */
5234 Vx_resource_name
= Vinvocation_name
;
5236 validate_x_resource_name ();
5238 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
5239 SSDATA (Vx_resource_name
));
5242 error ("Cannot connect to server %s", SDATA (name
));
5244 XSETFASTINT (Vwindow_system_version
, w32_major_version
);
5249 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
5250 1, 3, 0, doc
: /* Open a connection to a display server.
5251 DISPLAY is the name of the display to connect to.
5252 Optional second arg XRM-STRING is a string of resources in xrdb format.
5253 If the optional third arg MUST-SUCCEED is non-nil,
5254 terminate Emacs if we can't open the connection.
5255 \(In the Nextstep version, the last two arguments are currently ignored.) */)
5256 (Lisp_Object display
, Lisp_Object xrm_string
, Lisp_Object must_succeed
)
5258 unsigned char *xrm_option
;
5259 struct w32_display_info
*dpyinfo
;
5261 CHECK_STRING (display
);
5263 /* Signal an error in order to encourage correct use from callers.
5264 * If we ever support multiple window systems in the same Emacs,
5265 * we'll need callers to be precise about what window system they
5268 if (strcmp (SSDATA (display
), "w32") != 0)
5269 error ("The name of the display in this Emacs must be \"w32\"");
5271 /* If initialization has already been done, return now to avoid
5272 overwriting critical parts of one_w32_display_info. */
5273 if (window_system_available (NULL
))
5276 if (! NILP (xrm_string
))
5277 CHECK_STRING (xrm_string
);
5279 /* Allow color mapping to be defined externally; first look in user's
5280 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
5282 Lisp_Object color_file
;
5283 struct gcpro gcpro1
;
5285 color_file
= build_string ("~/rgb.txt");
5287 GCPRO1 (color_file
);
5289 if (NILP (Ffile_readable_p (color_file
)))
5291 Fexpand_file_name (build_string ("rgb.txt"),
5292 Fsymbol_value (intern ("data-directory")));
5294 Vw32_color_map
= Fx_load_color_file (color_file
);
5298 if (NILP (Vw32_color_map
))
5299 Vw32_color_map
= w32_default_color_map ();
5301 /* Merge in system logical colors. */
5302 add_system_logical_colors_to_map (&Vw32_color_map
);
5304 if (! NILP (xrm_string
))
5305 xrm_option
= SDATA (xrm_string
);
5307 xrm_option
= (unsigned char *) 0;
5309 /* Use this general default value to start with. */
5310 /* First remove .exe suffix from invocation-name - it looks ugly. */
5312 char basename
[ MAX_PATH
], *str
;
5314 strcpy (basename
, SDATA (Vinvocation_name
));
5315 str
= strrchr (basename
, '.');
5317 Vinvocation_name
= build_string (basename
);
5319 Vx_resource_name
= Vinvocation_name
;
5321 validate_x_resource_name ();
5323 /* This is what opens the connection and sets x_current_display.
5324 This also initializes many symbols, such as those used for input. */
5325 dpyinfo
= w32_term_init (display
, xrm_option
,
5326 SSDATA (Vx_resource_name
));
5330 if (!NILP (must_succeed
))
5331 fatal ("Cannot connect to server %s.\n",
5334 error ("Cannot connect to server %s", SDATA (display
));
5337 XSETFASTINT (Vwindow_system_version
, w32_major_version
);
5341 DEFUN ("x-close-connection", Fx_close_connection
,
5342 Sx_close_connection
, 1, 1, 0,
5343 doc
: /* Close the connection to DISPLAY's server.
5344 For DISPLAY, specify either a frame or a display name (a string).
5345 If DISPLAY is nil, that stands for the selected frame's display. */)
5346 (Lisp_Object display
)
5348 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
5350 if (dpyinfo
->reference_count
> 0)
5351 error ("Display still has frames on it");
5354 x_destroy_all_bitmaps (dpyinfo
);
5356 x_delete_display (dpyinfo
);
5362 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
5363 doc
: /* Return the list of display names that Emacs has connections to. */)
5366 Lisp_Object result
= Qnil
;
5367 struct w32_display_info
*wdi
;
5369 for (wdi
= x_display_list
; wdi
; wdi
= wdi
->next
)
5370 result
= Fcons (XCAR (wdi
->name_list_element
), result
);
5375 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
5376 doc
: /* If ON is non-nil, report X errors as soon as the erring request is made.
5377 This function only has an effect on X Windows. With MS Windows, it is
5378 defined but does nothing.
5380 If ON is nil, allow buffering of requests.
5381 Turning on synchronization prohibits the Xlib routines from buffering
5382 requests and seriously degrades performance, but makes debugging much
5384 The optional second argument TERMINAL specifies which display to act on.
5385 TERMINAL should be a terminal object, a frame or a display name (a string).
5386 If TERMINAL is omitted or nil, that stands for the selected frame's display. */)
5387 (Lisp_Object on
, Lisp_Object display
)
5394 /***********************************************************************
5396 ***********************************************************************/
5398 #if 0 /* TODO : port window properties to W32 */
5400 DEFUN ("x-change-window-property", Fx_change_window_property
,
5401 Sx_change_window_property
, 2, 6, 0,
5402 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
5403 PROP must be a string. VALUE may be a string or a list of conses,
5404 numbers and/or strings. If an element in the list is a string, it is
5405 converted to an atom and the value of the Atom is used. If an element
5406 is a cons, it is converted to a 32 bit number where the car is the 16
5407 top bits and the cdr is the lower 16 bits.
5409 FRAME nil or omitted means use the selected frame.
5410 If TYPE is given and non-nil, it is the name of the type of VALUE.
5411 If TYPE is not given or nil, the type is STRING.
5412 FORMAT gives the size in bits of each element if VALUE is a list.
5413 It must be one of 8, 16 or 32.
5414 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
5415 If OUTER-P is non-nil, the property is changed for the outer X window of
5416 FRAME. Default is to change on the edit X window. */)
5417 (Lisp_Object prop
, Lisp_Object value
, Lisp_Object frame
,
5418 Lisp_Object type
, Lisp_Object format
, Lisp_Object outer_p
)
5420 struct frame
*f
= decode_window_system_frame (frame
);
5423 CHECK_STRING (prop
);
5424 CHECK_STRING (value
);
5427 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5428 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5429 prop_atom
, XA_STRING
, 8, PropModeReplace
,
5430 SDATA (value
), SCHARS (value
));
5432 /* Make sure the property is set when we return. */
5433 XFlush (FRAME_W32_DISPLAY (f
));
5440 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
5441 Sx_delete_window_property
, 1, 2, 0,
5442 doc
: /* Remove window property PROP from X window of FRAME.
5443 FRAME nil or omitted means use the selected frame. Value is PROP. */)
5444 (Lisp_Object prop
, Lisp_Object frame
)
5446 struct frame
*f
= decode_window_system_frame (frame
);
5449 CHECK_STRING (prop
);
5451 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5452 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
5454 /* Make sure the property is removed when we return. */
5455 XFlush (FRAME_W32_DISPLAY (f
));
5462 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
5464 doc
: /* Value is the value of window property PROP on FRAME.
5465 If FRAME is nil or omitted, use the selected frame.
5467 On X Windows, the following optional arguments are also accepted:
5468 If TYPE is nil or omitted, get the property as a string.
5469 Otherwise TYPE is the name of the atom that denotes the type expected.
5470 If SOURCE is non-nil, get the property on that window instead of from
5471 FRAME. The number 0 denotes the root window.
5472 If DELETE-P is non-nil, delete the property after retrieving it.
5473 If VECTOR-RET-P is non-nil, don't return a string but a vector of values.
5475 On MS Windows, this function accepts but ignores those optional arguments.
5477 Value is nil if FRAME hasn't a property with name PROP or if PROP has
5478 no value of TYPE (always string in the MS Windows case). */)
5479 (Lisp_Object prop
, Lisp_Object frame
, Lisp_Object type
,
5480 Lisp_Object source
, Lisp_Object delete_p
, Lisp_Object vector_ret_p
)
5482 struct frame
*f
= decode_window_system_frame (frame
);
5485 Lisp_Object prop_value
= Qnil
;
5486 char *tmp_data
= NULL
;
5489 unsigned long actual_size
, bytes_remaining
;
5491 CHECK_STRING (prop
);
5493 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5494 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5495 prop_atom
, 0, 0, False
, XA_STRING
,
5496 &actual_type
, &actual_format
, &actual_size
,
5497 &bytes_remaining
, (unsigned char **) &tmp_data
);
5500 int size
= bytes_remaining
;
5505 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5506 prop_atom
, 0, bytes_remaining
,
5508 &actual_type
, &actual_format
,
5509 &actual_size
, &bytes_remaining
,
5510 (unsigned char **) &tmp_data
);
5512 prop_value
= make_string (tmp_data
, size
);
5527 /***********************************************************************
5529 ***********************************************************************/
5532 w32_note_current_window (void)
5534 struct frame
* f
= SELECTED_FRAME ();
5536 if (!FRAME_W32_P (f
))
5539 hourglass_hwnd
= FRAME_W32_WINDOW (f
);
5543 show_hourglass (struct atimer
*timer
)
5547 hourglass_atimer
= NULL
;
5550 f
= x_window_to_frame (&one_w32_display_info
,
5554 f
->output_data
.w32
->hourglass_p
= 0;
5556 f
= SELECTED_FRAME ();
5558 if (!FRAME_W32_P (f
))
5564 w32_show_hourglass (f
);
5569 hide_hourglass (void)
5572 w32_hide_hourglass ();
5577 /* Display an hourglass cursor. Set the hourglass_p flag in display info
5578 to indicate that an hourglass cursor is shown. */
5581 w32_show_hourglass (struct frame
*f
)
5583 if (!hourglass_shown_p
)
5585 f
->output_data
.w32
->hourglass_p
= 1;
5586 if (!menubar_in_use
&& !current_popup_menu
)
5587 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
5588 hourglass_shown_p
= 1;
5593 /* Hide the hourglass cursor on all frames, if it is currently shown. */
5596 w32_hide_hourglass (void)
5598 if (hourglass_shown_p
)
5600 struct frame
*f
= x_window_to_frame (&one_w32_display_info
,
5603 f
->output_data
.w32
->hourglass_p
= 0;
5605 /* If frame was deleted, restore to selected frame's cursor. */
5606 f
= SELECTED_FRAME ();
5608 if (FRAME_W32_P (f
))
5609 SetCursor (f
->output_data
.w32
->current_cursor
);
5611 /* No cursors on non GUI frames - restore to stock arrow cursor. */
5612 SetCursor (w32_load_cursor (IDC_ARROW
));
5614 hourglass_shown_p
= 0;
5620 /***********************************************************************
5622 ***********************************************************************/
5624 static Lisp_Object
x_create_tip_frame (struct w32_display_info
*,
5625 Lisp_Object
, Lisp_Object
);
5626 static void compute_tip_xy (struct frame
*, Lisp_Object
, Lisp_Object
,
5627 Lisp_Object
, int, int, int *, int *);
5629 /* The frame of a currently visible tooltip. */
5631 Lisp_Object tip_frame
;
5633 /* If non-nil, a timer started that hides the last tooltip when it
5636 Lisp_Object tip_timer
;
5639 /* If non-nil, a vector of 3 elements containing the last args
5640 with which x-show-tip was called. See there. */
5642 Lisp_Object last_show_tip_args
;
5646 unwind_create_tip_frame (Lisp_Object frame
)
5648 Lisp_Object deleted
;
5650 deleted
= unwind_create_frame (frame
);
5651 if (EQ (deleted
, Qt
))
5659 /* Create a frame for a tooltip on the display described by DPYINFO.
5660 PARMS is a list of frame parameters. TEXT is the string to
5661 display in the tip frame. Value is the frame.
5663 Note that functions called here, esp. x_default_parameter can
5664 signal errors, for instance when a specified color name is
5665 undefined. We have to make sure that we're in a consistent state
5666 when this happens. */
5669 x_create_tip_frame (struct w32_display_info
*dpyinfo
,
5670 Lisp_Object parms
, Lisp_Object text
)
5675 long window_prompting
= 0;
5677 ptrdiff_t count
= SPECPDL_INDEX ();
5678 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5680 int face_change_count_before
= face_change_count
;
5682 struct buffer
*old_buffer
;
5684 /* Use this general default value to start with until we know if
5685 this frame has a specified name. */
5686 Vx_resource_name
= Vinvocation_name
;
5688 kb
= dpyinfo
->terminal
->kboard
;
5690 /* The calls to x_get_arg remove elements from PARMS, so copy it to
5691 avoid destructive changes behind our caller's back. */
5692 parms
= Fcopy_alist (parms
);
5694 /* Get the name of the frame to use for resource lookup. */
5695 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
5697 && !EQ (name
, Qunbound
)
5699 error ("Invalid frame name--not a string or nil");
5700 Vx_resource_name
= name
;
5703 GCPRO3 (parms
, name
, frame
);
5704 /* Make a frame without minibuffer nor mode-line. */
5706 f
->wants_modeline
= 0;
5707 XSETFRAME (frame
, f
);
5709 buffer
= Fget_buffer_create (build_string (" *tip*"));
5710 /* Use set_window_buffer instead of Fset_window_buffer (see
5711 discussion of bug#11984, bug#12025, bug#12026). */
5712 set_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, 0, 0);
5713 old_buffer
= current_buffer
;
5714 set_buffer_internal_1 (XBUFFER (buffer
));
5715 bset_truncate_lines (current_buffer
, Qnil
);
5716 specbind (Qinhibit_read_only
, Qt
);
5717 specbind (Qinhibit_modification_hooks
, Qt
);
5720 set_buffer_internal_1 (old_buffer
);
5722 record_unwind_protect (unwind_create_tip_frame
, frame
);
5724 /* By setting the output method, we're essentially saying that
5725 the frame is live, as per FRAME_LIVE_P. If we get a signal
5726 from this point on, x_destroy_window might screw up reference
5728 f
->terminal
= dpyinfo
->terminal
;
5729 f
->output_method
= output_w32
;
5730 f
->output_data
.w32
= xzalloc (sizeof (struct w32_output
));
5732 FRAME_FONTSET (f
) = -1;
5733 fset_icon_name (f
, Qnil
);
5736 image_cache_refcount
=
5737 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
5738 dpyinfo_refcount
= dpyinfo
->reference_count
;
5739 #endif /* GLYPH_DEBUG */
5740 FRAME_KBOARD (f
) = kb
;
5741 f
->output_data
.w32
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
5742 f
->output_data
.w32
->explicit_parent
= 0;
5744 /* Set the name; the functions to which we pass f expect the name to
5746 if (EQ (name
, Qunbound
) || NILP (name
))
5748 fset_name (f
, build_string (dpyinfo
->w32_id_name
));
5749 f
->explicit_name
= 0;
5753 fset_name (f
, name
);
5754 f
->explicit_name
= 1;
5755 /* use the frame's title when getting resources for this frame. */
5756 specbind (Qx_resource_name
, name
);
5759 if (uniscribe_available
)
5760 register_font_driver (&uniscribe_font_driver
, f
);
5761 register_font_driver (&w32font_driver
, f
);
5763 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
5764 "fontBackend", "FontBackend", RES_TYPE_STRING
);
5766 /* Extract the window parameters from the supplied values
5767 that are needed to determine window geometry. */
5768 x_default_font_parameter (f
, parms
);
5770 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
5771 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5772 /* This defaults to 2 in order to match xterm. We recognize either
5773 internalBorderWidth or internalBorder (which is what xterm calls
5775 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5779 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
5780 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
5781 if (! EQ (value
, Qunbound
))
5782 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
5785 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
5786 "internalBorderWidth", "internalBorderWidth",
5788 x_default_parameter (f
, parms
, Qright_divider_width
, make_number (0),
5789 NULL
, NULL
, RES_TYPE_NUMBER
);
5790 x_default_parameter (f
, parms
, Qbottom_divider_width
, make_number (0),
5791 NULL
, NULL
, RES_TYPE_NUMBER
);
5793 /* Also do the stuff which must be set before the window exists. */
5794 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
5795 "foreground", "Foreground", RES_TYPE_STRING
);
5796 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
5797 "background", "Background", RES_TYPE_STRING
);
5798 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
5799 "pointerColor", "Foreground", RES_TYPE_STRING
);
5800 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
5801 "cursorColor", "Foreground", RES_TYPE_STRING
);
5802 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
5803 "borderColor", "BorderColor", RES_TYPE_STRING
);
5805 /* Init faces before x_default_parameter is called for scroll-bar
5806 parameters because that function calls x_set_scroll_bar_width,
5807 which calls change_frame_size, which calls Fset_window_buffer,
5808 which runs hooks, which call Fvertical_motion. At the end, we
5809 end up in init_iterator with a null face cache, which should not
5811 init_frame_faces (f
);
5813 f
->output_data
.w32
->dwStyle
= WS_BORDER
| WS_POPUP
| WS_DISABLED
;
5814 f
->output_data
.w32
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
5816 window_prompting
= x_figure_window_size (f
, parms
, 0);
5818 /* No fringes on tip frame. */
5820 f
->left_fringe_width
= 0;
5821 f
->right_fringe_width
= 0;
5824 my_create_tip_window (f
);
5829 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
5830 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5831 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5832 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5833 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5834 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5836 /* Dimensions, especially FRAME_LINES (f), must be done via
5837 change_frame_size. Change will not be effected unless different
5838 from the current FRAME_LINES (f). */
5839 width
= FRAME_COLS (f
);
5840 height
= FRAME_LINES (f
);
5841 FRAME_LINES (f
) = 0;
5842 SET_FRAME_COLS (f
, 0);
5843 change_frame_size (f
, width
, height
, 1, 0, 0, 0);
5845 /* Add `tooltip' frame parameter's default value. */
5846 if (NILP (Fframe_parameter (frame
, Qtooltip
)))
5847 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qtooltip
, Qt
), Qnil
));
5849 /* Set up faces after all frame parameters are known. This call
5850 also merges in face attributes specified for new frames.
5852 Frame parameters may be changed if .Xdefaults contains
5853 specifications for the default font. For example, if there is an
5854 `Emacs.default.attributeBackground: pink', the `background-color'
5855 attribute of the frame get's set, which let's the internal border
5856 of the tooltip frame appear in pink. Prevent this. */
5858 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
5859 Lisp_Object fg
= Fframe_parameter (frame
, Qforeground_color
);
5860 Lisp_Object colors
= Qnil
;
5862 /* Set tip_frame here, so that */
5864 call2 (Qface_set_after_frame_default
, frame
, Qnil
);
5866 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
5867 colors
= Fcons (Fcons (Qbackground_color
, bg
), colors
);
5868 if (!EQ (fg
, Fframe_parameter (frame
, Qforeground_color
)))
5869 colors
= Fcons (Fcons (Qforeground_color
, fg
), colors
);
5872 Fmodify_frame_parameters (frame
, colors
);
5879 /* Now that the frame is official, it counts as a reference to
5881 FRAME_DISPLAY_INFO (f
)->reference_count
++;
5882 f
->terminal
->reference_count
++;
5884 /* It is now ok to make the frame official even if we get an error
5885 below. And the frame needs to be on Vframe_list or making it
5886 visible won't work. */
5887 Vframe_list
= Fcons (frame
, Vframe_list
);
5889 /* Setting attributes of faces of the tooltip frame from resources
5890 and similar will increment face_change_count, which leads to the
5891 clearing of all current matrices. Since this isn't necessary
5892 here, avoid it by resetting face_change_count to the value it
5893 had before we created the tip frame. */
5894 face_change_count
= face_change_count_before
;
5896 /* Discard the unwind_protect. */
5897 return unbind_to (count
, frame
);
5901 /* Compute where to display tip frame F. PARMS is the list of frame
5902 parameters for F. DX and DY are specified offsets from the current
5903 location of the mouse. WIDTH and HEIGHT are the width and height
5904 of the tooltip. Return coordinates relative to the root window of
5905 the display in *ROOT_X, and *ROOT_Y. */
5908 compute_tip_xy (struct frame
*f
,
5909 Lisp_Object parms
, Lisp_Object dx
, Lisp_Object dy
,
5910 int width
, int height
, int *root_x
, int *root_y
)
5912 Lisp_Object left
, top
;
5913 int min_x
, min_y
, max_x
, max_y
;
5915 /* User-specified position? */
5916 left
= Fcdr (Fassq (Qleft
, parms
));
5917 top
= Fcdr (Fassq (Qtop
, parms
));
5919 /* Move the tooltip window where the mouse pointer is. Resize and
5921 if (!INTEGERP (left
) || !INTEGERP (top
))
5925 /* Default min and max values. */
5928 max_x
= x_display_pixel_width (FRAME_DISPLAY_INFO (f
));
5929 max_y
= x_display_pixel_height (FRAME_DISPLAY_INFO (f
));
5937 /* If multiple monitor support is available, constrain the tip onto
5938 the current monitor. This improves the above by allowing negative
5939 co-ordinates if monitor positions are such that they are valid, and
5940 snaps a tooltip onto a single monitor if we are close to the edge
5941 where it would otherwise flow onto the other monitor (or into
5942 nothingness if there is a gap in the overlap). */
5943 if (monitor_from_point_fn
&& get_monitor_info_fn
)
5945 struct MONITOR_INFO info
;
5947 = monitor_from_point_fn (pt
, MONITOR_DEFAULT_TO_NEAREST
);
5948 info
.cbSize
= sizeof (info
);
5950 if (get_monitor_info_fn (monitor
, &info
))
5952 min_x
= info
.rcWork
.left
;
5953 min_y
= info
.rcWork
.top
;
5954 max_x
= info
.rcWork
.right
;
5955 max_y
= info
.rcWork
.bottom
;
5961 *root_y
= XINT (top
);
5962 else if (*root_y
+ XINT (dy
) <= min_y
)
5963 *root_y
= min_y
; /* Can happen for negative dy */
5964 else if (*root_y
+ XINT (dy
) + height
<= max_y
)
5965 /* It fits below the pointer */
5966 *root_y
+= XINT (dy
);
5967 else if (height
+ XINT (dy
) + min_y
<= *root_y
)
5968 /* It fits above the pointer. */
5969 *root_y
-= height
+ XINT (dy
);
5971 /* Put it on the top. */
5974 if (INTEGERP (left
))
5975 *root_x
= XINT (left
);
5976 else if (*root_x
+ XINT (dx
) <= min_x
)
5977 *root_x
= 0; /* Can happen for negative dx */
5978 else if (*root_x
+ XINT (dx
) + width
<= max_x
)
5979 /* It fits to the right of the pointer. */
5980 *root_x
+= XINT (dx
);
5981 else if (width
+ XINT (dx
) + min_x
<= *root_x
)
5982 /* It fits to the left of the pointer. */
5983 *root_x
-= width
+ XINT (dx
);
5985 /* Put it left justified on the screen -- it ought to fit that way. */
5990 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
5991 doc
: /* Show STRING in a \"tooltip\" window on frame FRAME.
5992 A tooltip window is a small window displaying a string.
5994 This is an internal function; Lisp code should call `tooltip-show'.
5996 FRAME nil or omitted means use the selected frame.
5998 PARMS is an optional list of frame parameters which can be
5999 used to change the tooltip's appearance.
6001 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
6002 means use the default timeout of 5 seconds.
6004 If the list of frame parameters PARMS contains a `left' parameter,
6005 the tooltip is displayed at that x-position. Otherwise it is
6006 displayed at the mouse position, with offset DX added (default is 5 if
6007 DX isn't specified). Likewise for the y-position; if a `top' frame
6008 parameter is specified, it determines the y-position of the tooltip
6009 window, otherwise it is displayed at the mouse position, with offset
6010 DY added (default is -10).
6012 A tooltip's maximum size is specified by `x-max-tooltip-size'.
6013 Text larger than the specified size is clipped. */)
6014 (Lisp_Object string
, Lisp_Object frame
, Lisp_Object parms
, Lisp_Object timeout
, Lisp_Object dx
, Lisp_Object dy
)
6019 struct buffer
*old_buffer
;
6020 struct text_pos pos
;
6021 int i
, width
, height
, seen_reversed_p
;
6022 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
6023 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
6024 ptrdiff_t count
= SPECPDL_INDEX ();
6026 specbind (Qinhibit_redisplay
, Qt
);
6028 GCPRO4 (string
, parms
, frame
, timeout
);
6030 CHECK_STRING (string
);
6031 f
= decode_window_system_frame (frame
);
6033 timeout
= make_number (5);
6035 CHECK_NATNUM (timeout
);
6038 dx
= make_number (5);
6043 dy
= make_number (-10);
6047 if (NILP (last_show_tip_args
))
6048 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
6050 if (!NILP (tip_frame
))
6052 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
6053 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
6054 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
6056 if (EQ (frame
, last_frame
)
6057 && !NILP (Fequal (last_string
, string
))
6058 && !NILP (Fequal (last_parms
, parms
)))
6060 struct frame
*f
= XFRAME (tip_frame
);
6062 /* Only DX and DY have changed. */
6063 if (!NILP (tip_timer
))
6065 Lisp_Object timer
= tip_timer
;
6067 call1 (Qcancel_timer
, timer
);
6071 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
6072 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
6074 /* Put tooltip in topmost group and in position. */
6075 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
6076 root_x
, root_y
, 0, 0,
6077 SWP_NOSIZE
| SWP_NOACTIVATE
| SWP_NOOWNERZORDER
);
6079 /* Ensure tooltip is on top of other topmost windows (eg menus). */
6080 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
6082 SWP_NOMOVE
| SWP_NOSIZE
6083 | SWP_NOACTIVATE
| SWP_NOOWNERZORDER
);
6090 /* Hide a previous tip, if any. */
6093 ASET (last_show_tip_args
, 0, string
);
6094 ASET (last_show_tip_args
, 1, frame
);
6095 ASET (last_show_tip_args
, 2, parms
);
6097 /* Add default values to frame parameters. */
6098 if (NILP (Fassq (Qname
, parms
)))
6099 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
6100 if (NILP (Fassq (Qinternal_border_width
, parms
)))
6101 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
6102 if (NILP (Fassq (Qright_divider_width
, parms
)))
6103 parms
= Fcons (Fcons (Qright_divider_width
, make_number (0)), parms
);
6104 if (NILP (Fassq (Qbottom_divider_width
, parms
)))
6105 parms
= Fcons (Fcons (Qbottom_divider_width
, make_number (0)), parms
);
6106 if (NILP (Fassq (Qborder_width
, parms
)))
6107 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
6108 if (NILP (Fassq (Qborder_color
, parms
)))
6109 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
6110 if (NILP (Fassq (Qbackground_color
, parms
)))
6111 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
6114 /* Block input until the tip has been fully drawn, to avoid crashes
6115 when drawing tips in menus. */
6118 /* Create a frame for the tooltip, and record it in the global
6119 variable tip_frame. */
6120 frame
= x_create_tip_frame (FRAME_DISPLAY_INFO (f
), parms
, string
);
6123 /* Set up the frame's root window. */
6124 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6130 if (CONSP (Vx_max_tooltip_size
)
6131 && INTEGERP (XCAR (Vx_max_tooltip_size
))
6132 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
6133 && INTEGERP (XCDR (Vx_max_tooltip_size
))
6134 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
6136 w
->total_cols
= XFASTINT (XCAR (Vx_max_tooltip_size
));
6137 w
->total_lines
= XFASTINT (XCDR (Vx_max_tooltip_size
));
6142 w
->total_lines
= 40;
6145 w
->pixel_width
= w
->total_cols
* FRAME_COLUMN_WIDTH (f
);
6146 w
->pixel_height
= w
->total_lines
* FRAME_LINE_HEIGHT (f
);
6148 FRAME_TOTAL_COLS (f
) = WINDOW_TOTAL_COLS (w
);
6149 adjust_frame_glyphs (f
);
6150 w
->pseudo_window_p
= 1;
6152 /* Display the tooltip text in a temporary buffer. */
6153 old_buffer
= current_buffer
;
6154 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->contents
));
6155 bset_truncate_lines (current_buffer
, Qnil
);
6156 clear_glyph_matrix (w
->desired_matrix
);
6157 clear_glyph_matrix (w
->current_matrix
);
6158 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
6159 try_window (FRAME_ROOT_WINDOW (f
), pos
, TRY_WINDOW_IGNORE_FONTS_CHANGE
);
6161 /* Compute width and height of the tooltip. */
6162 width
= height
= seen_reversed_p
= 0;
6163 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
6165 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
6169 /* Stop at the first empty row at the end. */
6170 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
6173 /* Let the row go over the full width of the frame. */
6174 row
->full_width_p
= 1;
6176 row_width
= row
->pixel_width
;
6177 if (row
->used
[TEXT_AREA
])
6179 if (!row
->reversed_p
)
6181 /* There's a glyph at the end of rows that is used to
6182 place the cursor there. Don't include the width of
6184 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
6185 if (INTEGERP (last
->object
))
6186 row_width
-= last
->pixel_width
;
6190 /* There could be a stretch glyph at the beginning of R2L
6191 rows that is produced by extend_face_to_end_of_line.
6192 Don't count that glyph. */
6193 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
6195 if (g
->type
== STRETCH_GLYPH
&& INTEGERP (g
->object
))
6197 row_width
-= g
->pixel_width
;
6198 seen_reversed_p
= 1;
6203 height
+= row
->height
;
6204 width
= max (width
, row_width
);
6207 /* If we've seen partial-length R2L rows, we need to re-adjust the
6208 tool-tip frame width and redisplay it again, to avoid over-wide
6209 tips due to the stretch glyph that extends R2L lines to full
6210 width of the frame. */
6211 if (seen_reversed_p
)
6213 /* PXW: Why do we do the pixel-to-cols conversion only if
6214 seen_reversed_p holds? Don't we have to set other fields of
6215 the window/frame structure?
6217 w->total_cols and FRAME_TOTAL_COLS want the width in columns,
6219 w
->pixel_width
= width
;
6220 width
/= WINDOW_FRAME_COLUMN_WIDTH (w
);
6221 w
->total_cols
= width
;
6222 FRAME_TOTAL_COLS (f
) = width
;
6223 SET_FRAME_WIDTH (f
, width
);
6224 adjust_frame_glyphs (f
);
6225 w
->pseudo_window_p
= 1;
6226 clear_glyph_matrix (w
->desired_matrix
);
6227 clear_glyph_matrix (w
->current_matrix
);
6228 try_window (FRAME_ROOT_WINDOW (f
), pos
, TRY_WINDOW_IGNORE_FONTS_CHANGE
);
6230 /* Recompute width and height of the tooltip. */
6231 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
6233 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
6237 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
6239 row
->full_width_p
= 1;
6240 row_width
= row
->pixel_width
;
6241 if (row
->used
[TEXT_AREA
] && !row
->reversed_p
)
6243 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
6244 if (INTEGERP (last
->object
))
6245 row_width
-= last
->pixel_width
;
6248 height
+= row
->height
;
6249 width
= max (width
, row_width
);
6253 /* Add the frame's internal border to the width and height the w32
6254 window should have. */
6255 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
6256 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
6258 /* Move the tooltip window where the mouse pointer is. Resize and
6261 PXW: This should use the frame's pixel coordinates. */
6262 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
6265 /* Adjust Window size to take border into account. */
6267 rect
.left
= rect
.top
= 0;
6269 rect
.bottom
= height
;
6270 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
6271 FRAME_EXTERNAL_MENU_BAR (f
));
6273 /* Position and size tooltip, and put it in the topmost group.
6274 The add-on of FRAME_COLUMN_WIDTH to the 5th argument is a
6275 peculiarity of w32 display: without it, some fonts cause the
6276 last character of the tip to be truncated or wrapped around to
6278 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
6280 rect
.right
- rect
.left
+ FRAME_COLUMN_WIDTH (f
),
6281 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
| SWP_NOOWNERZORDER
);
6283 /* Ensure tooltip is on top of other topmost windows (eg menus). */
6284 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
6286 SWP_NOMOVE
| SWP_NOSIZE
6287 | SWP_NOACTIVATE
| SWP_NOOWNERZORDER
);
6289 /* Let redisplay know that we have made the frame visible already. */
6290 SET_FRAME_VISIBLE (f
, 1);
6292 ShowWindow (FRAME_W32_WINDOW (f
), SW_SHOWNOACTIVATE
);
6295 /* Draw into the window. */
6296 w
->must_be_updated_p
= 1;
6297 update_single_window (w
, 1);
6301 /* Restore original current buffer. */
6302 set_buffer_internal_1 (old_buffer
);
6303 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
6306 /* Let the tip disappear after timeout seconds. */
6307 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
6308 intern ("x-hide-tip"));
6311 return unbind_to (count
, Qnil
);
6315 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
6316 doc
: /* Hide the current tooltip window, if there is any.
6317 Value is t if tooltip was open, nil otherwise. */)
6321 Lisp_Object deleted
, frame
, timer
;
6322 struct gcpro gcpro1
, gcpro2
;
6324 /* Return quickly if nothing to do. */
6325 if (NILP (tip_timer
) && NILP (tip_frame
))
6330 GCPRO2 (frame
, timer
);
6331 tip_frame
= tip_timer
= deleted
= Qnil
;
6333 count
= SPECPDL_INDEX ();
6334 specbind (Qinhibit_redisplay
, Qt
);
6335 specbind (Qinhibit_quit
, Qt
);
6338 call1 (Qcancel_timer
, timer
);
6342 delete_frame (frame
, Qnil
);
6347 return unbind_to (count
, deleted
);
6350 /***********************************************************************
6351 File selection dialog
6352 ***********************************************************************/
6354 #define FILE_NAME_TEXT_FIELD edt1
6355 #define FILE_NAME_COMBO_BOX cmb13
6356 #define FILE_NAME_LIST lst1
6358 /* Callback for altering the behavior of the Open File dialog.
6359 Makes the Filename text field contain "Current Directory" and be
6360 read-only when "Directories" is selected in the filter. This
6361 allows us to work around the fact that the standard Open File
6362 dialog does not support directories. */
6363 static UINT_PTR CALLBACK
6364 file_dialog_callback (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
6366 if (msg
== WM_NOTIFY
)
6368 OFNOTIFYW
* notify_w
= (OFNOTIFYW
*)lParam
;
6369 OFNOTIFYA
* notify_a
= (OFNOTIFYA
*)lParam
;
6370 int dropdown_changed
;
6372 #ifdef NTGUI_UNICODE
6373 const int use_unicode
= 1;
6374 #else /* !NTGUI_UNICODE */
6375 int use_unicode
= w32_unicode_filenames
;
6376 #endif /* NTGUI_UNICODE */
6378 /* Detect when the Filter dropdown is changed. */
6381 notify_w
->hdr
.code
== CDN_TYPECHANGE
6382 || notify_w
->hdr
.code
== CDN_INITDONE
;
6385 notify_a
->hdr
.code
== CDN_TYPECHANGE
6386 || notify_a
->hdr
.code
== CDN_INITDONE
;
6387 if (dropdown_changed
)
6389 HWND dialog
= GetParent (hwnd
);
6390 HWND edit_control
= GetDlgItem (dialog
, FILE_NAME_TEXT_FIELD
);
6391 HWND list
= GetDlgItem (dialog
, FILE_NAME_LIST
);
6394 /* At least on Windows 7, the above attempt to get the window handle
6395 to the File Name Text Field fails. The following code does the
6396 job though. Note that this code is based on my examination of the
6397 window hierarchy using Microsoft Spy++. bk */
6398 if (edit_control
== NULL
)
6400 HWND tmp
= GetDlgItem (dialog
, FILE_NAME_COMBO_BOX
);
6403 tmp
= GetWindow (tmp
, GW_CHILD
);
6405 edit_control
= GetWindow (tmp
, GW_CHILD
);
6409 /* Directories is in index 2. */
6412 dir_index
= notify_w
->lpOFN
->nFilterIndex
;
6413 hdr_code
= notify_w
->hdr
.code
;
6417 dir_index
= notify_a
->lpOFN
->nFilterIndex
;
6418 hdr_code
= notify_a
->hdr
.code
;
6423 SendMessageW (dialog
, CDM_SETCONTROLTEXT
, FILE_NAME_TEXT_FIELD
,
6424 (LPARAM
)L
"Current Directory");
6426 SendMessageA (dialog
, CDM_SETCONTROLTEXT
, FILE_NAME_TEXT_FIELD
,
6427 (LPARAM
)"Current Directory");
6428 EnableWindow (edit_control
, FALSE
);
6429 /* Note that at least on Windows 7, the above call to EnableWindow
6430 disables the window that would ordinarily have focus. If we
6431 do not set focus to some other window here, focus will land in
6432 no man's land and the user will be unable to tab through the
6433 dialog box (pressing tab will only result in a beep).
6434 Avoid that problem by setting focus to the list here. */
6435 if (hdr_code
== CDN_INITDONE
)
6440 /* Don't override default filename on init done. */
6441 if (hdr_code
== CDN_TYPECHANGE
)
6444 SendMessageW (dialog
, CDM_SETCONTROLTEXT
,
6445 FILE_NAME_TEXT_FIELD
, (LPARAM
)L
"");
6447 SendMessageA (dialog
, CDM_SETCONTROLTEXT
,
6448 FILE_NAME_TEXT_FIELD
, (LPARAM
)"");
6450 EnableWindow (edit_control
, TRUE
);
6457 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
6458 doc
: /* Read file name, prompting with PROMPT in directory DIR.
6459 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
6460 selection box, if specified. If MUSTMATCH is non-nil, the returned file
6461 or directory must exist.
6463 This function is only defined on NS, MS Windows, and X Windows with the
6464 Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
6465 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories.
6466 On Windows 7 and later, the file selection dialog "remembers" the last
6467 directory where the user selected a file, and will open that directory
6468 instead of DIR on subsequent invocations of this function with the same
6469 value of DIR as in previous invocations; this is standard Windows behavior. */)
6470 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
, Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
6472 /* Filter index: 1: All Files, 2: Directories only */
6473 static const wchar_t filter_w
[] = L
"All Files (*.*)\0*.*\0Directories\0*|*\0";
6474 static const char filter_a
[] = "All Files (*.*)\0*.*\0Directories\0*|*\0";
6476 Lisp_Object filename
= default_filename
;
6477 struct frame
*f
= SELECTED_FRAME ();
6478 BOOL file_opened
= FALSE
;
6479 Lisp_Object orig_dir
= dir
;
6480 Lisp_Object orig_prompt
= prompt
;
6482 /* If we compile with _WIN32_WINNT set to 0x0400 (for NT4
6483 compatibility) we end up with the old file dialogs. Define a big
6484 enough struct for the new dialog to trick GetOpenFileName into
6485 giving us the new dialogs on newer versions of Windows. */
6487 OPENFILENAMEW details
;
6488 #if _WIN32_WINNT < 0x500 /* < win2k */
6492 #endif /* < win2k */
6493 } new_file_details_w
;
6495 #ifdef NTGUI_UNICODE
6496 wchar_t filename_buf_w
[32*1024 + 1]; // NT kernel maximum
6497 OPENFILENAMEW
* file_details_w
= &new_file_details_w
.details
;
6498 const int use_unicode
= 1;
6499 #else /* not NTGUI_UNICODE */
6501 OPENFILENAMEA details
;
6502 #if _WIN32_WINNT < 0x500 /* < win2k */
6506 #endif /* < win2k */
6507 } new_file_details_a
;
6508 wchar_t filename_buf_w
[MAX_PATH
+ 1], dir_w
[MAX_PATH
];
6509 char filename_buf_a
[MAX_PATH
+ 1], dir_a
[MAX_PATH
];
6510 OPENFILENAMEW
* file_details_w
= &new_file_details_w
.details
;
6511 OPENFILENAMEA
* file_details_a
= &new_file_details_a
.details
;
6512 int use_unicode
= w32_unicode_filenames
;
6516 char fname_ret
[MAX_UTF8_PATH
];
6517 #endif /* NTGUI_UNICODE */
6519 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
6520 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, filename
);
6523 struct gcpro gcpro1
, gcpro2
;
6524 GCPRO2 (orig_dir
, orig_prompt
); /* There is no GCPRON, N>6. */
6526 /* Note: under NTGUI_UNICODE, we do _NOT_ use ENCODE_FILE: the
6527 system file encoding expected by the platform APIs (e.g. Cygwin's
6528 POSIX implementation) may not be the same as the encoding expected
6529 by the Windows "ANSI" APIs! */
6531 CHECK_STRING (prompt
);
6534 dir
= Fexpand_file_name (dir
, Qnil
);
6536 if (STRINGP (filename
))
6537 filename
= Ffile_name_nondirectory (filename
);
6539 filename
= empty_unibyte_string
;
6542 dir
= Fcygwin_convert_file_name_to_windows (dir
, Qt
);
6543 if (SCHARS (filename
) > 0)
6544 filename
= Fcygwin_convert_file_name_to_windows (filename
, Qnil
);
6548 CHECK_STRING (filename
);
6550 /* The code in file_dialog_callback that attempts to set the text
6551 of the file name edit window when handling the CDN_INITDONE
6552 WM_NOTIFY message does not work. Setting filename to "Current
6553 Directory" in the only_dir_p case here does work however. */
6554 if (SCHARS (filename
) == 0 && ! NILP (only_dir_p
))
6555 filename
= build_string ("Current Directory");
6557 /* Convert the values we've computed so far to system form. */
6558 #ifdef NTGUI_UNICODE
6559 to_unicode (prompt
, &prompt
);
6560 to_unicode (dir
, &dir
);
6561 to_unicode (filename
, &filename
);
6562 if (SBYTES (filename
) + 1 > sizeof (filename_buf_w
))
6563 report_file_error ("filename too long", default_filename
);
6565 memcpy (filename_buf_w
, SDATA (filename
), SBYTES (filename
) + 1);
6566 #else /* !NTGUI_UNICODE */
6567 prompt
= ENCODE_FILE (prompt
);
6568 dir
= ENCODE_FILE (dir
);
6569 filename
= ENCODE_FILE (filename
);
6571 /* We modify these in-place, so make copies for safety. */
6572 dir
= Fcopy_sequence (dir
);
6573 unixtodos_filename (SDATA (dir
));
6574 filename
= Fcopy_sequence (filename
);
6575 unixtodos_filename (SDATA (filename
));
6576 if (SBYTES (filename
) >= MAX_UTF8_PATH
)
6577 report_file_error ("filename too long", default_filename
);
6578 if (w32_unicode_filenames
)
6580 filename_to_utf16 (SSDATA (dir
), dir_w
);
6581 if (filename_to_utf16 (SSDATA (filename
), filename_buf_w
) != 0)
6583 /* filename_to_utf16 sets errno to ENOENT when the file
6584 name is too long or cannot be converted to UTF-16. */
6585 if (errno
== ENOENT
&& filename_buf_w
[MAX_PATH
- 1] != 0)
6586 report_file_error ("filename too long", default_filename
);
6588 len
= pMultiByteToWideChar (CP_UTF8
, MB_ERR_INVALID_CHARS
,
6589 SSDATA (prompt
), -1, NULL
, 0);
6592 prompt_w
= alloca (len
* sizeof (wchar_t));
6593 pMultiByteToWideChar (CP_UTF8
, MB_ERR_INVALID_CHARS
,
6594 SSDATA (prompt
), -1, prompt_w
, len
);
6598 filename_to_ansi (SSDATA (dir
), dir_a
);
6599 if (filename_to_ansi (SSDATA (filename
), filename_buf_a
) != '\0')
6601 /* filename_to_ansi sets errno to ENOENT when the file
6602 name is too long or cannot be converted to UTF-16. */
6603 if (errno
== ENOENT
&& filename_buf_a
[MAX_PATH
- 1] != 0)
6604 report_file_error ("filename too long", default_filename
);
6606 len
= pMultiByteToWideChar (CP_UTF8
, MB_ERR_INVALID_CHARS
,
6607 SSDATA (prompt
), -1, NULL
, 0);
6610 prompt_w
= alloca (len
* sizeof (wchar_t));
6611 pMultiByteToWideChar (CP_UTF8
, MB_ERR_INVALID_CHARS
,
6612 SSDATA (prompt
), -1, prompt_w
, len
);
6613 len
= pWideCharToMultiByte (CP_ACP
, 0, prompt_w
, -1, NULL
, 0, NULL
, NULL
);
6616 prompt_a
= alloca (len
);
6617 pWideCharToMultiByte (CP_ACP
, 0, prompt_w
, -1, prompt_a
, len
, NULL
, NULL
);
6619 #endif /* NTGUI_UNICODE */
6621 /* Fill in the structure for the call to GetOpenFileName below.
6622 For NTGUI_UNICODE builds (which run only on NT), we just use
6623 the actual size of the structure. For non-NTGUI_UNICODE
6624 builds, we tell the OS we're using an old version of the
6625 structure if the OS isn't new enough to support the newer
6629 memset (&new_file_details_w
, 0, sizeof (new_file_details_w
));
6630 if (w32_major_version
> 4 && w32_major_version
< 95)
6631 file_details_w
->lStructSize
= sizeof (new_file_details_w
);
6633 file_details_w
->lStructSize
= sizeof (*file_details_w
);
6634 /* Set up the inout parameter for the selected file name. */
6635 file_details_w
->lpstrFile
= filename_buf_w
;
6636 file_details_w
->nMaxFile
=
6637 sizeof (filename_buf_w
) / sizeof (*filename_buf_w
);
6638 file_details_w
->hwndOwner
= FRAME_W32_WINDOW (f
);
6639 /* Undocumented Bug in Common File Dialog:
6640 If a filter is not specified, shell links are not resolved. */
6641 file_details_w
->lpstrFilter
= filter_w
;
6642 #ifdef NTGUI_UNICODE
6643 file_details_w
->lpstrInitialDir
= (wchar_t*) SDATA (dir
);
6644 file_details_w
->lpstrTitle
= (guichar_t
*) SDATA (prompt
);
6646 file_details_w
->lpstrInitialDir
= dir_w
;
6647 file_details_w
->lpstrTitle
= prompt_w
;
6649 file_details_w
->nFilterIndex
= NILP (only_dir_p
) ? 1 : 2;
6650 file_details_w
->Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
6651 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
6652 if (!NILP (mustmatch
))
6654 /* Require that the path to the parent directory exists. */
6655 file_details_w
->Flags
|= OFN_PATHMUSTEXIST
;
6656 /* If we are looking for a file, require that it exists. */
6657 if (NILP (only_dir_p
))
6658 file_details_w
->Flags
|= OFN_FILEMUSTEXIST
;
6661 #ifndef NTGUI_UNICODE
6664 memset (&new_file_details_a
, 0, sizeof (new_file_details_a
));
6665 if (w32_major_version
> 4 && w32_major_version
< 95)
6666 file_details_a
->lStructSize
= sizeof (new_file_details_a
);
6668 file_details_a
->lStructSize
= sizeof (*file_details_a
);
6669 file_details_a
->lpstrFile
= filename_buf_a
;
6670 file_details_a
->nMaxFile
=
6671 sizeof (filename_buf_a
) / sizeof (*filename_buf_a
);
6672 file_details_a
->hwndOwner
= FRAME_W32_WINDOW (f
);
6673 file_details_a
->lpstrFilter
= filter_a
;
6674 file_details_a
->lpstrInitialDir
= dir_a
;
6675 file_details_a
->lpstrTitle
= prompt_a
;
6676 file_details_a
->nFilterIndex
= NILP (only_dir_p
) ? 1 : 2;
6677 file_details_a
->Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
6678 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
6679 if (!NILP (mustmatch
))
6681 /* Require that the path to the parent directory exists. */
6682 file_details_a
->Flags
|= OFN_PATHMUSTEXIST
;
6683 /* If we are looking for a file, require that it exists. */
6684 if (NILP (only_dir_p
))
6685 file_details_a
->Flags
|= OFN_FILEMUSTEXIST
;
6688 #endif /* !NTGUI_UNICODE */
6691 int count
= SPECPDL_INDEX ();
6692 /* Prevent redisplay. */
6693 specbind (Qinhibit_redisplay
, Qt
);
6697 file_details_w
->lpfnHook
= file_dialog_callback
;
6699 file_opened
= GetOpenFileNameW (file_details_w
);
6701 #ifndef NTGUI_UNICODE
6704 file_details_a
->lpfnHook
= file_dialog_callback
;
6706 file_opened
= GetOpenFileNameA (file_details_a
);
6708 #endif /* !NTGUI_UNICODE */
6710 unbind_to (count
, Qnil
);
6715 /* Get an Emacs string from the value Windows gave us. */
6716 #ifdef NTGUI_UNICODE
6717 filename
= from_unicode_buffer (filename_buf_w
);
6718 #else /* !NTGUI_UNICODE */
6720 filename_from_utf16 (filename_buf_w
, fname_ret
);
6722 filename_from_ansi (filename_buf_a
, fname_ret
);
6723 dostounix_filename (fname_ret
);
6724 filename
= DECODE_FILE (build_unibyte_string (fname_ret
));
6725 #endif /* NTGUI_UNICODE */
6728 filename
= Fcygwin_convert_file_name_from_windows (filename
, Qt
);
6731 /* Strip the dummy filename off the end of the string if we
6732 added it to select a directory. */
6733 if ((use_unicode
&& file_details_w
->nFilterIndex
== 2)
6734 #ifndef NTGUI_UNICODE
6735 || (!use_unicode
&& file_details_a
->nFilterIndex
== 2)
6738 filename
= Ffile_name_directory (filename
);
6740 /* User canceled the dialog without making a selection. */
6741 else if (!CommDlgExtendedError ())
6743 /* An error occurred, fallback on reading from the mini-buffer. */
6745 filename
= Fcompleting_read (
6747 intern ("read-file-name-internal"),
6758 /* Make "Cancel" equivalent to C-g. */
6759 if (NILP (filename
))
6760 Fsignal (Qquit
, Qnil
);
6762 RETURN_UNGCPRO (filename
);
6767 /* Moving files to the system recycle bin.
6768 Used by `move-file-to-trash' instead of the default moving to ~/.Trash */
6769 DEFUN ("system-move-file-to-trash", Fsystem_move_file_to_trash
,
6770 Ssystem_move_file_to_trash
, 1, 1, 0,
6771 doc
: /* Move file or directory named FILENAME to the recycle bin. */)
6772 (Lisp_Object filename
)
6774 Lisp_Object handler
;
6775 Lisp_Object encoded_file
;
6776 Lisp_Object operation
;
6778 operation
= Qdelete_file
;
6779 if (!NILP (Ffile_directory_p (filename
))
6780 && NILP (Ffile_symlink_p (filename
)))
6782 operation
= intern ("delete-directory");
6783 filename
= Fdirectory_file_name (filename
);
6786 /* Must have fully qualified file names for moving files to Recycle
6788 filename
= Fexpand_file_name (filename
, Qnil
);
6790 handler
= Ffind_file_name_handler (filename
, operation
);
6791 if (!NILP (handler
))
6792 return call2 (handler
, operation
, filename
);
6798 encoded_file
= ENCODE_FILE (filename
);
6800 path
= map_w32_filename (SDATA (encoded_file
), NULL
);
6802 /* The Unicode version of SHFileOperation is not supported on
6804 if (w32_unicode_filenames
&& os_subtype
!= OS_9X
)
6806 SHFILEOPSTRUCTW file_op_w
;
6807 /* We need one more element beyond MAX_PATH because this is
6808 a list of file names, with the last element double-null
6810 wchar_t tmp_path_w
[MAX_PATH
+ 1];
6812 memset (tmp_path_w
, 0, sizeof (tmp_path_w
));
6813 filename_to_utf16 (path
, tmp_path_w
);
6815 /* On Windows, write permission is required to delete/move files. */
6816 _wchmod (tmp_path_w
, 0666);
6818 memset (&file_op_w
, 0, sizeof (file_op_w
));
6819 file_op_w
.hwnd
= HWND_DESKTOP
;
6820 file_op_w
.wFunc
= FO_DELETE
;
6821 file_op_w
.pFrom
= tmp_path_w
;
6822 file_op_w
.fFlags
= FOF_SILENT
| FOF_NOCONFIRMATION
| FOF_ALLOWUNDO
6823 | FOF_NOERRORUI
| FOF_NO_CONNECTED_ELEMENTS
;
6824 file_op_w
.fAnyOperationsAborted
= FALSE
;
6826 result
= SHFileOperationW (&file_op_w
);
6830 SHFILEOPSTRUCTA file_op_a
;
6831 char tmp_path_a
[MAX_PATH
+ 1];
6833 memset (tmp_path_a
, 0, sizeof (tmp_path_a
));
6834 filename_to_ansi (path
, tmp_path_a
);
6836 /* If a file cannot be represented in ANSI codepage, don't
6837 let them inadvertently delete other files because some
6838 characters are interpreted as a wildcards. */
6839 if (_mbspbrk (tmp_path_a
, "?*"))
6840 result
= ERROR_FILE_NOT_FOUND
;
6843 _chmod (tmp_path_a
, 0666);
6845 memset (&file_op_a
, 0, sizeof (file_op_a
));
6846 file_op_a
.hwnd
= HWND_DESKTOP
;
6847 file_op_a
.wFunc
= FO_DELETE
;
6848 file_op_a
.pFrom
= tmp_path_a
;
6849 file_op_a
.fFlags
= FOF_SILENT
| FOF_NOCONFIRMATION
| FOF_ALLOWUNDO
6850 | FOF_NOERRORUI
| FOF_NO_CONNECTED_ELEMENTS
;
6851 file_op_a
.fAnyOperationsAborted
= FALSE
;
6853 result
= SHFileOperationA (&file_op_a
);
6857 report_file_error ("Removing old name", list1 (filename
));
6862 #endif /* WINDOWSNT */
6865 /***********************************************************************
6866 w32 specialized functions
6867 ***********************************************************************/
6869 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
,
6870 Sw32_send_sys_command
, 1, 2, 0,
6871 doc
: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND.
6872 Some useful values for COMMAND are #xf030 to maximize frame (#xf020
6873 to minimize), #xf120 to restore frame to original size, and #xf100
6874 to activate the menubar for keyboard access. #xf140 activates the
6875 screen saver if defined.
6877 If optional parameter FRAME is not specified, use selected frame. */)
6878 (Lisp_Object command
, Lisp_Object frame
)
6880 struct frame
*f
= decode_window_system_frame (frame
);
6882 CHECK_NUMBER (command
);
6884 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
6889 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
6890 doc
: /* Get Windows to perform OPERATION on DOCUMENT.
6891 This is a wrapper around the ShellExecute system function, which
6892 invokes the application registered to handle OPERATION for DOCUMENT.
6894 OPERATION is either nil or a string that names a supported operation.
6895 What operations can be used depends on the particular DOCUMENT and its
6896 handler application, but typically it is one of the following common
6899 \"open\" - open DOCUMENT, which could be a file, a directory, or an
6900 executable program (application). If it is an application,
6901 that application is launched in the current buffer's default
6902 directory. Otherwise, the application associated with
6903 DOCUMENT is launched in the buffer's default directory.
6904 \"opennew\" - like \"open\", but instruct the application to open
6905 DOCUMENT in a new window.
6906 \"openas\" - open the \"Open With\" dialog for DOCUMENT.
6907 \"print\" - print DOCUMENT, which must be a file.
6908 \"printto\" - print DOCUMENT, which must be a file, to a specified printer.
6909 The printer should be provided in PARAMETERS, see below.
6910 \"explore\" - start the Windows Explorer on DOCUMENT.
6911 \"edit\" - launch an editor and open DOCUMENT for editing; which
6912 editor is launched depends on the association for the
6914 \"find\" - initiate search starting from DOCUMENT, which must specify
6916 \"runas\" - run DOCUMENT, which must be an excutable file, with
6917 elevated privileges (a.k.a. \"as Administrator\").
6919 - open the the property sheet dialog for DOCUMENT; works
6920 for *.lnk desktop shortcuts, and little or nothing else.
6921 nil - invoke the default OPERATION, or \"open\" if default is
6922 not defined or unavailable.
6924 DOCUMENT is typically the name of a document file or a URL, but can
6925 also be an executable program to run, or a directory to open in the
6926 Windows Explorer. If it is a file, it must be a local one; this
6927 function does not support remote file names.
6929 If DOCUMENT is an executable program, the optional third arg PARAMETERS
6930 can be a string containing command line parameters that will be passed
6931 to the program. Some values of OPERATION also require parameters (e.g.,
6932 \"printto\" requires the printer address). Otherwise, PARAMETERS should
6933 be nil or unspecified.
6935 Optional fourth argument SHOW-FLAG can be used to control how the
6936 application will be displayed when it is invoked. If SHOW-FLAG is nil
6937 or unspecified, the application is displayed as if SHOW-FLAG of 10 was
6938 specified, otherwise it is an integer between 0 and 11 representing
6942 1 - start as normal-size window
6943 3 - start in a maximized window
6944 6 - start in a minimized window
6945 10 - start as the application itself specifies; this is the default. */)
6946 (Lisp_Object operation
, Lisp_Object document
, Lisp_Object parameters
, Lisp_Object show_flag
)
6949 Lisp_Object current_dir
= BVAR (current_buffer
, directory
);;
6950 wchar_t *doc_w
= NULL
, *params_w
= NULL
, *ops_w
= NULL
;
6953 int use_unicode
= w32_unicode_filenames
;
6954 char *doc_a
= NULL
, *params_a
= NULL
, *ops_a
= NULL
;
6955 Lisp_Object absdoc
, handler
;
6956 struct gcpro gcpro1
;
6959 CHECK_STRING (document
);
6962 current_dir
= Fcygwin_convert_file_name_to_windows (current_dir
, Qt
);
6963 document
= Fcygwin_convert_file_name_to_windows (document
, Qt
);
6965 /* Encode filename, current directory and parameters. */
6966 current_dir
= GUI_ENCODE_FILE (current_dir
);
6967 document
= GUI_ENCODE_FILE (document
);
6968 doc_w
= GUI_SDATA (document
);
6969 if (STRINGP (parameters
))
6971 parameters
= GUI_ENCODE_SYSTEM (parameters
);
6972 params_w
= GUI_SDATA (parameters
);
6974 if (STRINGP (operation
))
6976 operation
= GUI_ENCODE_SYSTEM (operation
);
6977 ops_w
= GUI_SDATA (operation
);
6979 result
= (intptr_t) ShellExecuteW (NULL
, ops_w
, doc_w
, params_w
,
6980 GUI_SDATA (current_dir
),
6981 (INTEGERP (show_flag
)
6982 ? XINT (show_flag
) : SW_SHOWDEFAULT
));
6984 current_dir
= ENCODE_FILE (current_dir
);
6985 /* We have a situation here. If DOCUMENT is a relative file name,
6986 but its name includes leading directories, i.e. it lives not in
6987 CURRENT_DIR, but in its subdirectory, then ShellExecute below
6988 will fail to find it. So we need to make the file name is
6989 absolute. But DOCUMENT does not have to be a file, it can be a
6990 URL, for example. So we make it absolute only if it is an
6991 existing file; if it is a file that does not exist, tough. */
6993 absdoc
= Fexpand_file_name (document
, Qnil
);
6994 /* Don't call file handlers for file-exists-p, since they might
6995 attempt to access the file, which could fail or produce undesired
6996 consequences, see bug#16558 for an example. */
6997 handler
= Ffind_file_name_handler (absdoc
, Qfile_exists_p
);
7000 Lisp_Object absdoc_encoded
= ENCODE_FILE (absdoc
);
7002 if (faccessat (AT_FDCWD
, SSDATA (absdoc_encoded
), F_OK
, AT_EACCESS
) == 0)
7004 /* ShellExecute fails if DOCUMENT is a UNC with forward
7005 slashes (expand-file-name above converts all backslashes
7006 to forward slashes). Now that we know DOCUMENT is a
7007 file, we can mirror all forward slashes into backslashes. */
7008 unixtodos_filename (SSDATA (absdoc_encoded
));
7009 document
= absdoc_encoded
;
7012 document
= ENCODE_FILE (document
);
7015 document
= ENCODE_FILE (document
);
7019 wchar_t document_w
[MAX_PATH
], current_dir_w
[MAX_PATH
];
7021 /* Encode filename, current directory and parameters, and
7022 convert operation to UTF-16. */
7023 filename_to_utf16 (SSDATA (current_dir
), current_dir_w
);
7024 filename_to_utf16 (SSDATA (document
), document_w
);
7026 if (STRINGP (parameters
))
7030 parameters
= ENCODE_SYSTEM (parameters
);
7031 len
= pMultiByteToWideChar (CP_ACP
, MB_ERR_INVALID_CHARS
,
7032 SSDATA (parameters
), -1, NULL
, 0);
7035 params_w
= alloca (len
* sizeof (wchar_t));
7036 pMultiByteToWideChar (CP_ACP
, MB_ERR_INVALID_CHARS
,
7037 SSDATA (parameters
), -1, params_w
, len
);
7039 if (STRINGP (operation
))
7041 /* Assume OPERATION is pure ASCII. */
7042 const char *s
= SSDATA (operation
);
7044 int len
= SBYTES (operation
) + 1;
7048 d
= ops_w
= alloca (len
* sizeof (wchar_t));
7049 while (d
< ops_w
+ len
- 1)
7053 result
= (intptr_t) ShellExecuteW (NULL
, ops_w
, doc_w
, params_w
,
7055 (INTEGERP (show_flag
)
7056 ? XINT (show_flag
) : SW_SHOWDEFAULT
));
7060 char document_a
[MAX_PATH
], current_dir_a
[MAX_PATH
];
7062 filename_to_ansi (SSDATA (current_dir
), current_dir_a
);
7063 filename_to_ansi (SSDATA (document
), document_a
);
7065 if (STRINGP (parameters
))
7067 parameters
= ENCODE_SYSTEM (parameters
);
7068 params_a
= SSDATA (parameters
);
7070 if (STRINGP (operation
))
7072 /* Assume OPERATION is pure ASCII. */
7073 ops_a
= SSDATA (operation
);
7075 result
= (intptr_t) ShellExecuteA (NULL
, ops_a
, doc_a
, params_a
,
7077 (INTEGERP (show_flag
)
7078 ? XINT (show_flag
) : SW_SHOWDEFAULT
));
7080 #endif /* !CYGWIN */
7087 case SE_ERR_ACCESSDENIED
:
7088 errstr
= w32_strerror (ERROR_ACCESS_DENIED
);
7090 case SE_ERR_ASSOCINCOMPLETE
:
7091 case SE_ERR_NOASSOC
:
7092 errstr
= w32_strerror (ERROR_NO_ASSOCIATION
);
7094 case SE_ERR_DDEBUSY
:
7095 case SE_ERR_DDEFAIL
:
7096 errstr
= w32_strerror (ERROR_DDE_FAIL
);
7098 case SE_ERR_DDETIMEOUT
:
7099 errstr
= w32_strerror (ERROR_TIMEOUT
);
7101 case SE_ERR_DLLNOTFOUND
:
7102 errstr
= w32_strerror (ERROR_DLL_NOT_FOUND
);
7105 errstr
= w32_strerror (ERROR_FILE_NOT_FOUND
);
7108 errstr
= w32_strerror (ERROR_NOT_ENOUGH_MEMORY
);
7111 errstr
= w32_strerror (ERROR_PATH_NOT_FOUND
);
7114 errstr
= w32_strerror (ERROR_SHARING_VIOLATION
);
7117 errstr
= w32_strerror (0);
7120 /* The error string might be encoded in the locale's encoding. */
7121 if (!NILP (Vlocale_coding_system
))
7123 Lisp_Object decoded
=
7124 code_convert_string_norecord (build_unibyte_string (errstr
),
7125 Vlocale_coding_system
, 0);
7126 errstr
= SSDATA (decoded
);
7128 error ("ShellExecute failed: %s", errstr
);
7131 /* Lookup virtual keycode from string representing the name of a
7132 non-ascii keystroke into the corresponding virtual key, using
7133 lispy_function_keys. */
7135 lookup_vk_code (char *key
)
7139 for (i
= 0; i
< 256; i
++)
7140 if (lispy_function_keys
[i
]
7141 && strcmp (lispy_function_keys
[i
], key
) == 0)
7147 /* Convert a one-element vector style key sequence to a hot key
7150 w32_parse_hot_key (Lisp_Object key
)
7152 /* Copied from Fdefine_key and store_in_keymap. */
7153 register Lisp_Object c
;
7157 struct gcpro gcpro1
;
7161 if (ASIZE (key
) != 1)
7168 if (CONSP (c
) && lucid_event_type_list_p (c
))
7169 c
= Fevent_convert_list (c
);
7173 if (! INTEGERP (c
) && ! SYMBOLP (c
))
7174 error ("Key definition is invalid");
7176 /* Work out the base key and the modifiers. */
7179 c
= parse_modifiers (c
);
7180 lisp_modifiers
= XINT (Fcar (Fcdr (c
)));
7184 vk_code
= lookup_vk_code (SDATA (SYMBOL_NAME (c
)));
7186 else if (INTEGERP (c
))
7188 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
7189 /* Many ascii characters are their own virtual key code. */
7190 vk_code
= XINT (c
) & CHARACTERBITS
;
7193 if (vk_code
< 0 || vk_code
> 255)
7196 if ((lisp_modifiers
& meta_modifier
) != 0
7197 && !NILP (Vw32_alt_is_meta
))
7198 lisp_modifiers
|= alt_modifier
;
7200 /* Supply defs missing from mingw32. */
7202 #define MOD_ALT 0x0001
7203 #define MOD_CONTROL 0x0002
7204 #define MOD_SHIFT 0x0004
7205 #define MOD_WIN 0x0008
7208 /* Convert lisp modifiers to Windows hot-key form. */
7209 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
7210 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
7211 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
7212 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
7214 return HOTKEY (vk_code
, w32_modifiers
);
7217 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
,
7218 Sw32_register_hot_key
, 1, 1, 0,
7219 doc
: /* Register KEY as a hot-key combination.
7220 Certain key combinations like Alt-Tab are reserved for system use on
7221 Windows, and therefore are normally intercepted by the system. However,
7222 most of these key combinations can be received by registering them as
7223 hot-keys, overriding their special meaning.
7225 KEY must be a one element key definition in vector form that would be
7226 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta
7227 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper
7228 is always interpreted as the Windows modifier keys.
7230 The return value is the hotkey-id if registered, otherwise nil. */)
7233 key
= w32_parse_hot_key (key
);
7235 if (!NILP (key
) && NILP (Fmemq (key
, w32_grabbed_keys
)))
7237 /* Reuse an empty slot if possible. */
7238 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
7240 /* Safe to add new key to list, even if we have focus. */
7242 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
7244 XSETCAR (item
, key
);
7246 /* Notify input thread about new hot-key definition, so that it
7247 takes effect without needing to switch focus. */
7248 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
7249 (WPARAM
) XLI (key
), 0);
7255 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
,
7256 Sw32_unregister_hot_key
, 1, 1, 0,
7257 doc
: /* Unregister KEY as a hot-key combination. */)
7262 if (!INTEGERP (key
))
7263 key
= w32_parse_hot_key (key
);
7265 item
= Fmemq (key
, w32_grabbed_keys
);
7269 /* Notify input thread about hot-key definition being removed, so
7270 that it takes effect without needing focus switch. */
7271 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
7272 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) XLI (item
)))
7275 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
7282 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
,
7283 Sw32_registered_hot_keys
, 0, 0, 0,
7284 doc
: /* Return list of registered hot-key IDs. */)
7287 return Fdelq (Qnil
, Fcopy_sequence (w32_grabbed_keys
));
7290 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
,
7291 Sw32_reconstruct_hot_key
, 1, 1, 0,
7292 doc
: /* Convert hot-key ID to a lisp key combination.
7293 usage: (w32-reconstruct-hot-key ID) */)
7294 (Lisp_Object hotkeyid
)
7296 int vk_code
, w32_modifiers
;
7299 CHECK_NUMBER (hotkeyid
);
7301 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
7302 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
7304 if (vk_code
< 256 && lispy_function_keys
[vk_code
])
7305 key
= intern (lispy_function_keys
[vk_code
]);
7307 key
= make_number (vk_code
);
7309 key
= Fcons (key
, Qnil
);
7310 if (w32_modifiers
& MOD_SHIFT
)
7311 key
= Fcons (Qshift
, key
);
7312 if (w32_modifiers
& MOD_CONTROL
)
7313 key
= Fcons (Qctrl
, key
);
7314 if (w32_modifiers
& MOD_ALT
)
7315 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
7316 if (w32_modifiers
& MOD_WIN
)
7317 key
= Fcons (Qhyper
, key
);
7322 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
,
7323 Sw32_toggle_lock_key
, 1, 2, 0,
7324 doc
: /* Toggle the state of the lock key KEY.
7325 KEY can be `capslock', `kp-numlock', or `scroll'.
7326 If the optional parameter NEW-STATE is a number, then the state of KEY
7327 is set to off if the low bit of NEW-STATE is zero, otherwise on. */)
7328 (Lisp_Object key
, Lisp_Object new_state
)
7332 if (EQ (key
, intern ("capslock")))
7333 vk_code
= VK_CAPITAL
;
7334 else if (EQ (key
, intern ("kp-numlock")))
7335 vk_code
= VK_NUMLOCK
;
7336 else if (EQ (key
, intern ("scroll")))
7337 vk_code
= VK_SCROLL
;
7341 if (!dwWindowsThreadId
)
7342 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
7344 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
7345 (WPARAM
) vk_code
, (LPARAM
) XLI (new_state
)))
7348 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
7349 return make_number (msg
.wParam
);
7354 DEFUN ("w32-window-exists-p", Fw32_window_exists_p
, Sw32_window_exists_p
,
7356 doc
: /* Return non-nil if a window exists with the specified CLASS and NAME.
7358 This is a direct interface to the Windows API FindWindow function. */)
7359 (Lisp_Object
class, Lisp_Object name
)
7364 CHECK_STRING (class);
7366 CHECK_STRING (name
);
7368 hnd
= FindWindow (STRINGP (class) ? ((LPCTSTR
) SDATA (class)) : NULL
,
7369 STRINGP (name
) ? ((LPCTSTR
) SDATA (name
)) : NULL
);
7375 DEFUN ("w32-frame-rect", Fw32_frame_rect
, Sw32_frame_rect
, 0, 2, 0,
7376 doc
: /* Return boundary rectangle of FRAME in screen coordinates.
7377 FRAME must be a live frame and defaults to the selected one.
7379 The boundary rectangle is a list of four elements, specifying the left,
7380 top, right and bottom screen coordinates of FRAME including menu and
7381 title bar and decorations. Optional argument CLIENT non-nil means to
7382 return the boundaries of the client rectangle which excludes menu and
7383 title bar and decorations. */)
7384 (Lisp_Object frame
, Lisp_Object client
)
7386 struct frame
*f
= decode_live_frame (frame
);
7390 GetClientRect (FRAME_W32_WINDOW (f
), &rect
);
7392 GetWindowRect (FRAME_W32_WINDOW (f
), &rect
);
7394 return list4 (make_number (rect
.left
), make_number (rect
.top
),
7395 make_number (rect
.right
), make_number (rect
.bottom
));
7398 DEFUN ("w32-battery-status", Fw32_battery_status
, Sw32_battery_status
, 0, 0, 0,
7399 doc
: /* Get power status information from Windows system.
7401 The following %-sequences are provided:
7402 %L AC line status (verbose)
7403 %B Battery status (verbose)
7404 %b Battery status, empty means high, `-' means low,
7405 `!' means critical, and `+' means charging
7406 %p Battery load percentage
7407 %s Remaining time (to charge or discharge) in seconds
7408 %m Remaining time (to charge or discharge) in minutes
7409 %h Remaining time (to charge or discharge) in hours
7410 %t Remaining time (to charge or discharge) in the form `h:min' */)
7413 Lisp_Object status
= Qnil
;
7415 SYSTEM_POWER_STATUS system_status
;
7416 if (GetSystemPowerStatus (&system_status
))
7418 Lisp_Object line_status
, battery_status
, battery_status_symbol
;
7419 Lisp_Object load_percentage
, seconds
, minutes
, hours
, remain
;
7421 long seconds_left
= (long) system_status
.BatteryLifeTime
;
7423 if (system_status
.ACLineStatus
== 0)
7424 line_status
= build_string ("off-line");
7425 else if (system_status
.ACLineStatus
== 1)
7426 line_status
= build_string ("on-line");
7428 line_status
= build_string ("N/A");
7430 if (system_status
.BatteryFlag
& 128)
7432 battery_status
= build_string ("N/A");
7433 battery_status_symbol
= empty_unibyte_string
;
7435 else if (system_status
.BatteryFlag
& 8)
7437 battery_status
= build_string ("charging");
7438 battery_status_symbol
= build_string ("+");
7439 if (system_status
.BatteryFullLifeTime
!= -1L)
7440 seconds_left
= system_status
.BatteryFullLifeTime
- seconds_left
;
7442 else if (system_status
.BatteryFlag
& 4)
7444 battery_status
= build_string ("critical");
7445 battery_status_symbol
= build_string ("!");
7447 else if (system_status
.BatteryFlag
& 2)
7449 battery_status
= build_string ("low");
7450 battery_status_symbol
= build_string ("-");
7452 else if (system_status
.BatteryFlag
& 1)
7454 battery_status
= build_string ("high");
7455 battery_status_symbol
= empty_unibyte_string
;
7459 battery_status
= build_string ("medium");
7460 battery_status_symbol
= empty_unibyte_string
;
7463 if (system_status
.BatteryLifePercent
> 100)
7464 load_percentage
= build_string ("N/A");
7468 snprintf (buffer
, 16, "%d", system_status
.BatteryLifePercent
);
7469 load_percentage
= build_string (buffer
);
7472 if (seconds_left
< 0)
7473 seconds
= minutes
= hours
= remain
= build_string ("N/A");
7479 snprintf (buffer
, 16, "%ld", seconds_left
);
7480 seconds
= build_string (buffer
);
7482 m
= seconds_left
/ 60;
7483 snprintf (buffer
, 16, "%ld", m
);
7484 minutes
= build_string (buffer
);
7486 h
= seconds_left
/ 3600.0;
7487 snprintf (buffer
, 16, "%3.1f", h
);
7488 hours
= build_string (buffer
);
7490 snprintf (buffer
, 16, "%ld:%02ld", m
/ 60, m
% 60);
7491 remain
= build_string (buffer
);
7494 status
= listn (CONSTYPE_HEAP
, 8,
7495 Fcons (make_number ('L'), line_status
),
7496 Fcons (make_number ('B'), battery_status
),
7497 Fcons (make_number ('b'), battery_status_symbol
),
7498 Fcons (make_number ('p'), load_percentage
),
7499 Fcons (make_number ('s'), seconds
),
7500 Fcons (make_number ('m'), minutes
),
7501 Fcons (make_number ('h'), hours
),
7502 Fcons (make_number ('t'), remain
));
7509 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
7510 doc
: /* Return storage information about the file system FILENAME is on.
7511 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
7512 storage of the file system, FREE is the free storage, and AVAIL is the
7513 storage available to a non-superuser. All 3 numbers are in bytes.
7514 If the underlying system call fails, value is nil. */)
7515 (Lisp_Object filename
)
7517 Lisp_Object encoded
, value
;
7519 CHECK_STRING (filename
);
7520 filename
= Fexpand_file_name (filename
, Qnil
);
7521 encoded
= ENCODE_FILE (filename
);
7525 /* Determining the required information on Windows turns out, sadly,
7526 to be more involved than one would hope. The original Windows API
7527 call for this will return bogus information on some systems, but we
7528 must dynamically probe for the replacement api, since that was
7529 added rather late on. */
7531 HMODULE hKernel
= GetModuleHandle ("kernel32");
7532 BOOL (WINAPI
*pfn_GetDiskFreeSpaceExW
)
7533 (wchar_t *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
7534 = GetProcAddress (hKernel
, "GetDiskFreeSpaceExW");
7535 BOOL (WINAPI
*pfn_GetDiskFreeSpaceExA
)
7536 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
7537 = GetProcAddress (hKernel
, "GetDiskFreeSpaceExA");
7538 bool have_pfn_GetDiskFreeSpaceEx
=
7539 (w32_unicode_filenames
&& pfn_GetDiskFreeSpaceExW
7540 || !w32_unicode_filenames
&& pfn_GetDiskFreeSpaceExA
);
7542 /* On Windows, we may need to specify the root directory of the
7543 volume holding FILENAME. */
7544 char rootname
[MAX_UTF8_PATH
];
7545 wchar_t rootname_w
[MAX_PATH
];
7546 char rootname_a
[MAX_PATH
];
7547 char *name
= SDATA (encoded
);
7550 /* find the root name of the volume if given */
7551 if (isalpha (name
[0]) && name
[1] == ':')
7553 rootname
[0] = name
[0];
7554 rootname
[1] = name
[1];
7558 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
7560 char *str
= rootname
;
7564 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
7574 if (w32_unicode_filenames
)
7575 filename_to_utf16 (rootname
, rootname_w
);
7577 filename_to_ansi (rootname
, rootname_a
);
7579 if (have_pfn_GetDiskFreeSpaceEx
)
7581 /* Unsigned large integers cannot be cast to double, so
7582 use signed ones instead. */
7583 LARGE_INTEGER availbytes
;
7584 LARGE_INTEGER freebytes
;
7585 LARGE_INTEGER totalbytes
;
7587 if (w32_unicode_filenames
)
7588 result
= pfn_GetDiskFreeSpaceExW (rootname_w
,
7589 (ULARGE_INTEGER
*)&availbytes
,
7590 (ULARGE_INTEGER
*)&totalbytes
,
7591 (ULARGE_INTEGER
*)&freebytes
);
7593 result
= pfn_GetDiskFreeSpaceExA (rootname_a
,
7594 (ULARGE_INTEGER
*)&availbytes
,
7595 (ULARGE_INTEGER
*)&totalbytes
,
7596 (ULARGE_INTEGER
*)&freebytes
);
7598 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
7599 make_float ((double) freebytes
.QuadPart
),
7600 make_float ((double) availbytes
.QuadPart
));
7604 DWORD sectors_per_cluster
;
7605 DWORD bytes_per_sector
;
7606 DWORD free_clusters
;
7607 DWORD total_clusters
;
7609 if (w32_unicode_filenames
)
7610 result
= GetDiskFreeSpaceW (rootname_w
,
7611 §ors_per_cluster
,
7616 result
= GetDiskFreeSpaceA (rootname_a
,
7617 §ors_per_cluster
,
7622 value
= list3 (make_float ((double) total_clusters
7623 * sectors_per_cluster
* bytes_per_sector
),
7624 make_float ((double) free_clusters
7625 * sectors_per_cluster
* bytes_per_sector
),
7626 make_float ((double) free_clusters
7627 * sectors_per_cluster
* bytes_per_sector
));
7633 #endif /* WINDOWSNT */
7637 DEFUN ("default-printer-name", Fdefault_printer_name
, Sdefault_printer_name
,
7638 0, 0, 0, doc
: /* Return the name of Windows default printer device. */)
7641 static char pname_buf
[256];
7644 PRINTER_INFO_2W
*ppi2w
= NULL
;
7645 PRINTER_INFO_2A
*ppi2a
= NULL
;
7646 DWORD dwNeeded
= 0, dwReturned
= 0;
7647 char server_name
[MAX_UTF8_PATH
], share_name
[MAX_UTF8_PATH
];
7648 char port_name
[MAX_UTF8_PATH
];
7650 /* Retrieve the default string from Win.ini (the registry).
7651 * String will be in form "printername,drivername,portname".
7652 * This is the most portable way to get the default printer. */
7653 if (GetProfileString ("windows", "device", ",,", pname_buf
, sizeof (pname_buf
)) <= 0)
7655 /* printername precedes first "," character */
7656 strtok (pname_buf
, ",");
7657 /* We want to know more than the printer name */
7658 if (!OpenPrinter (pname_buf
, &hPrn
, NULL
))
7660 /* GetPrinterW is not supported by unicows.dll. */
7661 if (w32_unicode_filenames
&& os_subtype
!= OS_9X
)
7662 GetPrinterW (hPrn
, 2, NULL
, 0, &dwNeeded
);
7664 GetPrinterA (hPrn
, 2, NULL
, 0, &dwNeeded
);
7667 ClosePrinter (hPrn
);
7670 /* Call GetPrinter again with big enough memory block. */
7671 if (w32_unicode_filenames
&& os_subtype
!= OS_9X
)
7673 /* Allocate memory for the PRINTER_INFO_2 struct. */
7674 ppi2w
= xmalloc (dwNeeded
);
7675 err
= GetPrinterW (hPrn
, 2, (LPBYTE
)ppi2w
, dwNeeded
, &dwReturned
);
7676 ClosePrinter (hPrn
);
7683 if ((ppi2w
->Attributes
& PRINTER_ATTRIBUTE_SHARED
)
7684 && ppi2w
->pServerName
)
7686 filename_from_utf16 (ppi2w
->pServerName
, server_name
);
7687 filename_from_utf16 (ppi2w
->pShareName
, share_name
);
7691 server_name
[0] = '\0';
7692 filename_from_utf16 (ppi2w
->pPortName
, port_name
);
7697 ppi2a
= xmalloc (dwNeeded
);
7698 err
= GetPrinterA (hPrn
, 2, (LPBYTE
)ppi2a
, dwNeeded
, &dwReturned
);
7699 ClosePrinter (hPrn
);
7706 if ((ppi2a
->Attributes
& PRINTER_ATTRIBUTE_SHARED
)
7707 && ppi2a
->pServerName
)
7709 filename_from_ansi (ppi2a
->pServerName
, server_name
);
7710 filename_from_ansi (ppi2a
->pShareName
, share_name
);
7714 server_name
[0] = '\0';
7715 filename_from_ansi (ppi2a
->pPortName
, port_name
);
7721 /* a remote printer */
7722 if (server_name
[0] == '\\')
7723 snprintf (pname_buf
, sizeof (pname_buf
), "%s\\%s", server_name
,
7726 snprintf (pname_buf
, sizeof (pname_buf
), "\\\\%s\\%s", server_name
,
7728 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
7732 /* a local printer */
7733 strncpy (pname_buf
, port_name
, sizeof (pname_buf
));
7734 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
7735 /* `pPortName' can include several ports, delimited by ','.
7736 * we only use the first one. */
7737 strtok (pname_buf
, ",");
7740 return DECODE_FILE (build_unibyte_string (pname_buf
));
7742 #endif /* WINDOWSNT */
7745 /* Equivalent of strerror for W32 error codes. */
7747 w32_strerror (int error_no
)
7749 static char buf
[500];
7753 error_no
= GetLastError ();
7755 ret
= FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
|
7756 FORMAT_MESSAGE_IGNORE_INSERTS
,
7759 0, /* choose most suitable language */
7760 buf
, sizeof (buf
), NULL
);
7762 while (ret
> 0 && (buf
[ret
- 1] == '\n' ||
7763 buf
[ret
- 1] == '\r' ))
7767 sprintf (buf
, "w32 error %u", error_no
);
7772 /* For convenience when debugging. (You cannot call GetLastError
7773 directly from GDB: it will crash, because it uses the __stdcall
7774 calling convention, not the _cdecl convention assumed by GDB.) */
7776 w32_last_error (void)
7778 return GetLastError ();
7781 /* Cache information describing the NT system for later use. */
7783 cache_system_info (void)
7796 /* Cache the module handle of Emacs itself. */
7797 hinst
= GetModuleHandle (NULL
);
7799 /* Cache the version of the operating system. */
7800 version
.data
= GetVersion ();
7801 w32_major_version
= version
.info
.major
;
7802 w32_minor_version
= version
.info
.minor
;
7804 if (version
.info
.platform
& 0x8000)
7809 /* Cache page size, allocation unit, processor type, etc. */
7810 GetSystemInfo (&sysinfo_cache
);
7811 syspage_mask
= (DWORD_PTR
)sysinfo_cache
.dwPageSize
- 1;
7813 /* Cache os info. */
7814 osinfo_cache
.dwOSVersionInfoSize
= sizeof (OSVERSIONINFO
);
7815 GetVersionEx (&osinfo_cache
);
7817 w32_build_number
= osinfo_cache
.dwBuildNumber
;
7818 if (os_subtype
== OS_9X
)
7819 w32_build_number
&= 0xffff;
7821 w32_num_mouse_buttons
= GetSystemMetrics (SM_CMOUSEBUTTONS
);
7826 _DebPrint (const char *fmt
, ...)
7831 va_start (args
, fmt
);
7832 vsprintf (buf
, fmt
, args
);
7835 fprintf (stderr
, "%s", buf
);
7837 OutputDebugString (buf
);
7842 w32_console_toggle_lock_key (int vk_code
, Lisp_Object new_state
)
7844 int cur_state
= (GetKeyState (vk_code
) & 1);
7846 if (NILP (new_state
)
7847 || (NUMBERP (new_state
)
7848 && ((XUINT (new_state
)) & 1) != cur_state
))
7851 faked_key
= vk_code
;
7852 #endif /* WINDOWSNT */
7854 keybd_event ((BYTE
) vk_code
,
7855 (BYTE
) MapVirtualKey (vk_code
, 0),
7856 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
7857 keybd_event ((BYTE
) vk_code
,
7858 (BYTE
) MapVirtualKey (vk_code
, 0),
7859 KEYEVENTF_EXTENDEDKEY
| 0, 0);
7860 keybd_event ((BYTE
) vk_code
,
7861 (BYTE
) MapVirtualKey (vk_code
, 0),
7862 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
7863 cur_state
= !cur_state
;
7869 /* Translate console modifiers to emacs modifiers.
7870 German keyboard support (Kai Morgan Zeise 2/18/95). */
7872 w32_kbd_mods_to_emacs (DWORD mods
, WORD key
)
7876 /* If we recognize right-alt and left-ctrl as AltGr, and it has been
7877 pressed, first remove those modifiers. */
7878 if (!NILP (Vw32_recognize_altgr
)
7879 && (mods
& (RIGHT_ALT_PRESSED
| LEFT_CTRL_PRESSED
))
7880 == (RIGHT_ALT_PRESSED
| LEFT_CTRL_PRESSED
))
7881 mods
&= ~ (RIGHT_ALT_PRESSED
| LEFT_CTRL_PRESSED
);
7883 if (mods
& (RIGHT_ALT_PRESSED
| LEFT_ALT_PRESSED
))
7884 retval
= ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
);
7886 if (mods
& (RIGHT_CTRL_PRESSED
| LEFT_CTRL_PRESSED
))
7888 retval
|= ctrl_modifier
;
7889 if ((mods
& (RIGHT_CTRL_PRESSED
| LEFT_CTRL_PRESSED
))
7890 == (RIGHT_CTRL_PRESSED
| LEFT_CTRL_PRESSED
))
7891 retval
|= meta_modifier
;
7894 if (mods
& LEFT_WIN_PRESSED
)
7895 retval
|= w32_key_to_modifier (VK_LWIN
);
7896 if (mods
& RIGHT_WIN_PRESSED
)
7897 retval
|= w32_key_to_modifier (VK_RWIN
);
7898 if (mods
& APPS_PRESSED
)
7899 retval
|= w32_key_to_modifier (VK_APPS
);
7900 if (mods
& SCROLLLOCK_ON
)
7901 retval
|= w32_key_to_modifier (VK_SCROLL
);
7903 /* Just in case someone wanted the original behavior, make it
7904 optional by setting w32-capslock-is-shiftlock to t. */
7905 if (NILP (Vw32_capslock_is_shiftlock
)
7906 /* Keys that should _not_ be affected by CapsLock. */
7907 && ( (key
== VK_BACK
)
7909 || (key
== VK_CLEAR
)
7910 || (key
== VK_RETURN
)
7911 || (key
== VK_ESCAPE
)
7912 || ((key
>= VK_SPACE
) && (key
<= VK_HELP
))
7913 || ((key
>= VK_NUMPAD0
) && (key
<= VK_F24
))
7914 || ((key
>= VK_NUMPAD_CLEAR
) && (key
<= VK_NUMPAD_DELETE
))
7917 /* Only consider shift state. */
7918 if ((mods
& SHIFT_PRESSED
) != 0)
7919 retval
|= shift_modifier
;
7923 /* Ignore CapsLock state if not enabled. */
7924 if (NILP (Vw32_enable_caps_lock
))
7925 mods
&= ~CAPSLOCK_ON
;
7926 if ((mods
& (SHIFT_PRESSED
| CAPSLOCK_ON
)) != 0)
7927 retval
|= shift_modifier
;
7933 /* The return code indicates key code size. cpID is the codepage to
7934 use for translation to Unicode; -1 means use the current console
7937 w32_kbd_patch_key (KEY_EVENT_RECORD
*event
, int cpId
)
7939 unsigned int key_code
= event
->wVirtualKeyCode
;
7940 unsigned int mods
= event
->dwControlKeyState
;
7942 static BYTE ansi_code
[4];
7943 static int isdead
= 0;
7947 event
->uChar
.AsciiChar
= ansi_code
[2];
7951 if (event
->uChar
.AsciiChar
!= 0)
7954 memset (keystate
, 0, sizeof (keystate
));
7955 keystate
[key_code
] = 0x80;
7956 if (mods
& SHIFT_PRESSED
)
7957 keystate
[VK_SHIFT
] = 0x80;
7958 if (mods
& CAPSLOCK_ON
)
7959 keystate
[VK_CAPITAL
] = 1;
7960 /* If we recognize right-alt and left-ctrl as AltGr, set the key
7961 states accordingly before invoking ToAscii. */
7962 if (!NILP (Vw32_recognize_altgr
)
7963 && (mods
& LEFT_CTRL_PRESSED
) && (mods
& RIGHT_ALT_PRESSED
))
7965 keystate
[VK_CONTROL
] = 0x80;
7966 keystate
[VK_LCONTROL
] = 0x80;
7967 keystate
[VK_MENU
] = 0x80;
7968 keystate
[VK_RMENU
] = 0x80;
7972 /* Because of an OS bug, ToAscii corrupts the stack when called to
7973 convert a dead key in console mode on NT4. Unfortunately, trying
7974 to check for dead keys using MapVirtualKey doesn't work either -
7975 these functions apparently use internal information about keyboard
7976 layout which doesn't get properly updated in console programs when
7977 changing layout (though apparently it gets partly updated,
7978 otherwise ToAscii wouldn't crash). */
7979 if (is_dead_key (event
->wVirtualKeyCode
))
7983 /* On NT, call ToUnicode instead and then convert to the current
7984 console input codepage. */
7985 if (os_subtype
== OS_NT
)
7989 isdead
= ToUnicode (event
->wVirtualKeyCode
, event
->wVirtualScanCode
,
7990 keystate
, buf
, 128, 0);
7993 /* When we are called from the GUI message processing code,
7994 we are passed the current keyboard codepage, a positive
7995 number, to use below. */
7997 cpId
= GetConsoleCP ();
7999 event
->uChar
.UnicodeChar
= buf
[isdead
- 1];
8000 isdead
= WideCharToMultiByte (cpId
, 0, buf
, isdead
,
8001 ansi_code
, 4, NULL
, NULL
);
8008 isdead
= ToAscii (event
->wVirtualKeyCode
, event
->wVirtualScanCode
,
8009 keystate
, (LPWORD
) ansi_code
, 0);
8014 event
->uChar
.AsciiChar
= ansi_code
[0];
8020 w32_sys_ring_bell (struct frame
*f
)
8022 if (sound_type
== 0xFFFFFFFF)
8026 else if (sound_type
== MB_EMACS_SILENT
)
8031 MessageBeep (sound_type
);
8035 /***********************************************************************
8037 ***********************************************************************/
8039 /* Keep this list in the same order as frame_parms in frame.c.
8040 Use 0 for unsupported frame parameters. */
8042 frame_parm_handler w32_frame_parm_handlers
[] =
8046 x_set_background_color
,
8052 x_set_foreground_color
,
8055 x_set_internal_border_width
,
8056 x_set_right_divider_width
,
8057 x_set_bottom_divider_width
,
8058 x_set_menu_bar_lines
,
8060 x_explicitly_set_name
,
8061 x_set_scroll_bar_width
,
8064 x_set_vertical_scroll_bars
,
8066 x_set_tool_bar_lines
,
8067 0, /* x_set_scroll_bar_foreground, */
8068 0, /* x_set_scroll_bar_background, */
8073 0, /* x_set_wait_for_wm, */
8077 0, /* x_set_sticky */
8078 0, /* x_set_tool_bar_position */
8082 syms_of_w32fns (void)
8084 globals_of_w32fns ();
8085 track_mouse_window
= NULL
;
8087 w32_visible_system_caret_hwnd
= NULL
;
8089 DEFSYM (Qsuppress_icon
, "suppress-icon");
8090 DEFSYM (Qundefined_color
, "undefined-color");
8091 DEFSYM (Qcancel_timer
, "cancel-timer");
8092 DEFSYM (Qhyper
, "hyper");
8093 DEFSYM (Qsuper
, "super");
8094 DEFSYM (Qmeta
, "meta");
8095 DEFSYM (Qalt
, "alt");
8096 DEFSYM (Qctrl
, "ctrl");
8097 DEFSYM (Qcontrol
, "control");
8098 DEFSYM (Qshift
, "shift");
8099 DEFSYM (Qfont_param
, "font-parameter");
8100 DEFSYM (Qgeometry
, "geometry");
8101 DEFSYM (Qworkarea
, "workarea");
8102 DEFSYM (Qmm_size
, "mm-size");
8103 DEFSYM (Qframes
, "frames");
8104 /* This is the end of symbol initialization. */
8107 Fput (Qundefined_color
, Qerror_conditions
,
8108 listn (CONSTYPE_PURE
, 2, Qundefined_color
, Qerror
));
8109 Fput (Qundefined_color
, Qerror_message
,
8110 build_pure_c_string ("Undefined color"));
8112 staticpro (&w32_grabbed_keys
);
8113 w32_grabbed_keys
= Qnil
;
8115 DEFVAR_LISP ("w32-color-map", Vw32_color_map
,
8116 doc
: /* An array of color name mappings for Windows. */);
8117 Vw32_color_map
= Qnil
;
8119 DEFVAR_LISP ("w32-pass-alt-to-system", Vw32_pass_alt_to_system
,
8120 doc
: /* Non-nil if Alt key presses are passed on to Windows.
8121 When non-nil, for example, Alt pressed and released and then space will
8122 open the System menu. When nil, Emacs processes the Alt key events, and
8123 then silently swallows them. */);
8124 Vw32_pass_alt_to_system
= Qnil
;
8126 DEFVAR_LISP ("w32-alt-is-meta", Vw32_alt_is_meta
,
8127 doc
: /* Non-nil if the Alt key is to be considered the same as the META key.
8128 When nil, Emacs will translate the Alt key to the ALT modifier, not to META. */);
8129 Vw32_alt_is_meta
= Qt
;
8131 DEFVAR_INT ("w32-quit-key", w32_quit_key
,
8132 doc
: /* If non-zero, the virtual key code for an alternative quit key. */);
8135 DEFVAR_LISP ("w32-pass-lwindow-to-system",
8136 Vw32_pass_lwindow_to_system
,
8137 doc
: /* If non-nil, the left \"Windows\" key is passed on to Windows.
8139 When non-nil, the Start menu is opened by tapping the key.
8140 If you set this to nil, the left \"Windows\" key is processed by Emacs
8141 according to the value of `w32-lwindow-modifier', which see.
8143 Note that some combinations of the left \"Windows\" key with other keys are
8144 caught by Windows at low level, and so binding them in Emacs will have no
8145 effect. For example, <lwindow>-r always pops up the Windows Run dialog,
8146 <lwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
8147 the doc string of `w32-phantom-key-code'. */);
8148 Vw32_pass_lwindow_to_system
= Qt
;
8150 DEFVAR_LISP ("w32-pass-rwindow-to-system",
8151 Vw32_pass_rwindow_to_system
,
8152 doc
: /* If non-nil, the right \"Windows\" key is passed on to Windows.
8154 When non-nil, the Start menu is opened by tapping the key.
8155 If you set this to nil, the right \"Windows\" key is processed by Emacs
8156 according to the value of `w32-rwindow-modifier', which see.
8158 Note that some combinations of the right \"Windows\" key with other keys are
8159 caught by Windows at low level, and so binding them in Emacs will have no
8160 effect. For example, <rwindow>-r always pops up the Windows Run dialog,
8161 <rwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
8162 the doc string of `w32-phantom-key-code'. */);
8163 Vw32_pass_rwindow_to_system
= Qt
;
8165 DEFVAR_LISP ("w32-phantom-key-code",
8166 Vw32_phantom_key_code
,
8167 doc
: /* Virtual key code used to generate \"phantom\" key presses.
8168 Value is a number between 0 and 255.
8170 Phantom key presses are generated in order to stop the system from
8171 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or
8172 `w32-pass-rwindow-to-system' is nil. */);
8173 /* Although 255 is technically not a valid key code, it works and
8174 means that this hack won't interfere with any real key code. */
8175 XSETINT (Vw32_phantom_key_code
, 255);
8177 DEFVAR_LISP ("w32-enable-num-lock",
8178 Vw32_enable_num_lock
,
8179 doc
: /* If non-nil, the Num Lock key acts normally.
8180 Set to nil to handle Num Lock as the `kp-numlock' key. */);
8181 Vw32_enable_num_lock
= Qt
;
8183 DEFVAR_LISP ("w32-enable-caps-lock",
8184 Vw32_enable_caps_lock
,
8185 doc
: /* If non-nil, the Caps Lock key acts normally.
8186 Set to nil to handle Caps Lock as the `capslock' key. */);
8187 Vw32_enable_caps_lock
= Qt
;
8189 DEFVAR_LISP ("w32-scroll-lock-modifier",
8190 Vw32_scroll_lock_modifier
,
8191 doc
: /* Modifier to use for the Scroll Lock ON state.
8192 The value can be hyper, super, meta, alt, control or shift for the
8193 respective modifier, or nil to handle Scroll Lock as the `scroll' key.
8194 Any other value will cause the Scroll Lock key to be ignored. */);
8195 Vw32_scroll_lock_modifier
= Qnil
;
8197 DEFVAR_LISP ("w32-lwindow-modifier",
8198 Vw32_lwindow_modifier
,
8199 doc
: /* Modifier to use for the left \"Windows\" key.
8200 The value can be hyper, super, meta, alt, control or shift for the
8201 respective modifier, or nil to appear as the `lwindow' key.
8202 Any other value will cause the key to be ignored. */);
8203 Vw32_lwindow_modifier
= Qnil
;
8205 DEFVAR_LISP ("w32-rwindow-modifier",
8206 Vw32_rwindow_modifier
,
8207 doc
: /* Modifier to use for the right \"Windows\" key.
8208 The value can be hyper, super, meta, alt, control or shift for the
8209 respective modifier, or nil to appear as the `rwindow' key.
8210 Any other value will cause the key to be ignored. */);
8211 Vw32_rwindow_modifier
= Qnil
;
8213 DEFVAR_LISP ("w32-apps-modifier",
8215 doc
: /* Modifier to use for the \"Apps\" key.
8216 The value can be hyper, super, meta, alt, control or shift for the
8217 respective modifier, or nil to appear as the `apps' key.
8218 Any other value will cause the key to be ignored. */);
8219 Vw32_apps_modifier
= Qnil
;
8221 DEFVAR_BOOL ("w32-enable-synthesized-fonts", w32_enable_synthesized_fonts
,
8222 doc
: /* Non-nil enables selection of artificially italicized and bold fonts. */);
8223 w32_enable_synthesized_fonts
= 0;
8225 DEFVAR_LISP ("w32-enable-palette", Vw32_enable_palette
,
8226 doc
: /* Non-nil enables Windows palette management to map colors exactly. */);
8227 Vw32_enable_palette
= Qt
;
8229 DEFVAR_INT ("w32-mouse-button-tolerance",
8230 w32_mouse_button_tolerance
,
8231 doc
: /* Analogue of double click interval for faking middle mouse events.
8232 The value is the minimum time in milliseconds that must elapse between
8233 left and right button down events before they are considered distinct events.
8234 If both mouse buttons are depressed within this interval, a middle mouse
8235 button down event is generated instead. */);
8236 w32_mouse_button_tolerance
= GetDoubleClickTime () / 2;
8238 DEFVAR_INT ("w32-mouse-move-interval",
8239 w32_mouse_move_interval
,
8240 doc
: /* Minimum interval between mouse move events.
8241 The value is the minimum time in milliseconds that must elapse between
8242 successive mouse move (or scroll bar drag) events before they are
8243 reported as lisp events. */);
8244 w32_mouse_move_interval
= 0;
8246 DEFVAR_BOOL ("w32-pass-extra-mouse-buttons-to-system",
8247 w32_pass_extra_mouse_buttons_to_system
,
8248 doc
: /* If non-nil, the fourth and fifth mouse buttons are passed to Windows.
8249 Recent versions of Windows support mice with up to five buttons.
8250 Since most applications don't support these extra buttons, most mouse
8251 drivers will allow you to map them to functions at the system level.
8252 If this variable is non-nil, Emacs will pass them on, allowing the
8253 system to handle them. */);
8254 w32_pass_extra_mouse_buttons_to_system
= 0;
8256 DEFVAR_BOOL ("w32-pass-multimedia-buttons-to-system",
8257 w32_pass_multimedia_buttons_to_system
,
8258 doc
: /* If non-nil, media buttons are passed to Windows.
8259 Some modern keyboards contain buttons for controlling media players, web
8260 browsers and other applications. Generally these buttons are handled on a
8261 system wide basis, but by setting this to nil they are made available
8262 to Emacs for binding. Depending on your keyboard, additional keys that
8263 may be available are:
8265 browser-back, browser-forward, browser-refresh, browser-stop,
8266 browser-search, browser-favorites, browser-home,
8267 mail, mail-reply, mail-forward, mail-send,
8269 help, find, new, open, close, save, print, undo, redo, copy, cut, paste,
8270 spell-check, correction-list, toggle-dictate-command,
8271 media-next, media-previous, media-stop, media-play-pause, media-select,
8272 media-play, media-pause, media-record, media-fast-forward, media-rewind,
8273 media-channel-up, media-channel-down,
8274 volume-mute, volume-up, volume-down,
8275 mic-volume-mute, mic-volume-down, mic-volume-up, mic-toggle,
8276 bass-down, bass-boost, bass-up, treble-down, treble-up */);
8277 w32_pass_multimedia_buttons_to_system
= 1;
8279 #if 0 /* TODO: Mouse cursor customization. */
8280 DEFVAR_LISP ("x-pointer-shape", Vx_pointer_shape
,
8281 doc
: /* The shape of the pointer when over text.
8282 Changing the value does not affect existing frames
8283 unless you set the mouse color. */);
8284 Vx_pointer_shape
= Qnil
;
8286 Vx_nontext_pointer_shape
= Qnil
;
8288 Vx_mode_pointer_shape
= Qnil
;
8290 DEFVAR_LISP ("x-hourglass-pointer-shape", Vx_hourglass_pointer_shape
,
8291 doc
: /* The shape of the pointer when Emacs is busy.
8292 This variable takes effect when you create a new frame
8293 or when you set the mouse color. */);
8294 Vx_hourglass_pointer_shape
= Qnil
;
8296 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
8297 Vx_sensitive_text_pointer_shape
,
8298 doc
: /* The shape of the pointer when over mouse-sensitive text.
8299 This variable takes effect when you create a new frame
8300 or when you set the mouse color. */);
8301 Vx_sensitive_text_pointer_shape
= Qnil
;
8303 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
8304 Vx_window_horizontal_drag_shape
,
8305 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
8306 This variable takes effect when you create a new frame
8307 or when you set the mouse color. */);
8308 Vx_window_horizontal_drag_shape
= Qnil
;
8310 DEFVAR_LISP ("x-window-vertical-drag-cursor",
8311 Vx_window_vertical_drag_shape
,
8312 doc
: /* Pointer shape to use for indicating a window can be dragged vertically.
8313 This variable takes effect when you create a new frame
8314 or when you set the mouse color. */);
8315 Vx_window_vertical_drag_shape
= Qnil
;
8318 DEFVAR_LISP ("x-cursor-fore-pixel", Vx_cursor_fore_pixel
,
8319 doc
: /* A string indicating the foreground color of the cursor box. */);
8320 Vx_cursor_fore_pixel
= Qnil
;
8322 DEFVAR_LISP ("x-max-tooltip-size", Vx_max_tooltip_size
,
8323 doc
: /* Maximum size for tooltips.
8324 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
8325 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
8327 DEFVAR_LISP ("x-no-window-manager", Vx_no_window_manager
,
8328 doc
: /* Non-nil if no window manager is in use.
8329 Emacs doesn't try to figure this out; this is always nil
8330 unless you set it to something else. */);
8331 /* We don't have any way to find this out, so set it to nil
8332 and maybe the user would like to set it to t. */
8333 Vx_no_window_manager
= Qnil
;
8335 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
8336 Vx_pixel_size_width_font_regexp
,
8337 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
8339 Since Emacs gets width of a font matching with this regexp from
8340 PIXEL_SIZE field of the name, font finding mechanism gets faster for
8341 such a font. This is especially effective for such large fonts as
8342 Chinese, Japanese, and Korean. */);
8343 Vx_pixel_size_width_font_regexp
= Qnil
;
8345 DEFVAR_LISP ("w32-bdf-filename-alist",
8346 Vw32_bdf_filename_alist
,
8347 doc
: /* List of bdf fonts and their corresponding filenames. */);
8348 Vw32_bdf_filename_alist
= Qnil
;
8350 DEFVAR_BOOL ("w32-strict-fontnames",
8351 w32_strict_fontnames
,
8352 doc
: /* Non-nil means only use fonts that are exact matches for those requested.
8353 Default is nil, which allows old fontnames that are not XLFD compliant,
8354 and allows third-party CJK display to work by specifying false charset
8355 fields to trick Emacs into translating to Big5, SJIS etc.
8356 Setting this to t will prevent wrong fonts being selected when
8357 fontsets are automatically created. */);
8358 w32_strict_fontnames
= 0;
8360 DEFVAR_BOOL ("w32-strict-painting",
8361 w32_strict_painting
,
8362 doc
: /* Non-nil means use strict rules for repainting frames.
8363 Set this to nil to get the old behavior for repainting; this should
8364 only be necessary if the default setting causes problems. */);
8365 w32_strict_painting
= 1;
8367 #if 0 /* TODO: Port to W32 */
8368 defsubr (&Sx_change_window_property
);
8369 defsubr (&Sx_delete_window_property
);
8370 defsubr (&Sx_window_property
);
8372 defsubr (&Sxw_display_color_p
);
8373 defsubr (&Sx_display_grayscale_p
);
8374 defsubr (&Sxw_color_defined_p
);
8375 defsubr (&Sxw_color_values
);
8376 defsubr (&Sx_server_max_request_size
);
8377 defsubr (&Sx_server_vendor
);
8378 defsubr (&Sx_server_version
);
8379 defsubr (&Sx_display_pixel_width
);
8380 defsubr (&Sx_display_pixel_height
);
8381 defsubr (&Sx_display_mm_width
);
8382 defsubr (&Sx_display_mm_height
);
8383 defsubr (&Sx_display_screens
);
8384 defsubr (&Sx_display_planes
);
8385 defsubr (&Sx_display_color_cells
);
8386 defsubr (&Sx_display_visual_class
);
8387 defsubr (&Sx_display_backing_store
);
8388 defsubr (&Sx_display_save_under
);
8389 defsubr (&Sx_create_frame
);
8390 defsubr (&Sx_open_connection
);
8391 defsubr (&Sx_close_connection
);
8392 defsubr (&Sx_display_list
);
8393 defsubr (&Sx_synchronize
);
8395 /* W32 specific functions */
8397 defsubr (&Sw32_define_rgb_color
);
8398 defsubr (&Sw32_default_color_map
);
8399 defsubr (&Sw32_display_monitor_attributes_list
);
8400 defsubr (&Sw32_send_sys_command
);
8401 defsubr (&Sw32_shell_execute
);
8402 defsubr (&Sw32_register_hot_key
);
8403 defsubr (&Sw32_unregister_hot_key
);
8404 defsubr (&Sw32_registered_hot_keys
);
8405 defsubr (&Sw32_reconstruct_hot_key
);
8406 defsubr (&Sw32_toggle_lock_key
);
8407 defsubr (&Sw32_window_exists_p
);
8408 defsubr (&Sw32_frame_rect
);
8409 defsubr (&Sw32_battery_status
);
8412 defsubr (&Sfile_system_info
);
8413 defsubr (&Sdefault_printer_name
);
8416 defsubr (&Sset_message_beep
);
8418 hourglass_hwnd
= NULL
;
8420 defsubr (&Sx_show_tip
);
8421 defsubr (&Sx_hide_tip
);
8423 staticpro (&tip_timer
);
8425 staticpro (&tip_frame
);
8427 last_show_tip_args
= Qnil
;
8428 staticpro (&last_show_tip_args
);
8430 defsubr (&Sx_file_dialog
);
8432 defsubr (&Ssystem_move_file_to_trash
);
8438 /* Crashing and reporting backtrace. */
8441 static LONG CALLBACK
my_exception_handler (EXCEPTION_POINTERS
*);
8442 static LPTOP_LEVEL_EXCEPTION_FILTER prev_exception_handler
;
8444 static DWORD except_code
;
8445 static PVOID except_addr
;
8448 /* This handler records the exception code and the address where it
8449 was triggered so that this info could be included in the backtrace.
8450 Without that, the backtrace in some cases has no information
8451 whatsoever about the offending code, and looks as if the top-level
8452 exception handler in the MinGW startup code di the one that
8454 static LONG CALLBACK
8455 my_exception_handler (EXCEPTION_POINTERS
* exception_data
)
8457 except_code
= exception_data
->ExceptionRecord
->ExceptionCode
;
8458 except_addr
= exception_data
->ExceptionRecord
->ExceptionAddress
;
8460 if (prev_exception_handler
)
8461 return prev_exception_handler (exception_data
);
8462 return EXCEPTION_EXECUTE_HANDLER
;
8466 typedef USHORT (WINAPI
* CaptureStackBackTrace_proc
) (ULONG
, ULONG
, PVOID
*,
8469 #define BACKTRACE_LIMIT_MAX 62
8472 w32_backtrace (void **buffer
, int limit
)
8474 static CaptureStackBackTrace_proc s_pfn_CaptureStackBackTrace
= NULL
;
8475 HMODULE hm_kernel32
= NULL
;
8477 if (!s_pfn_CaptureStackBackTrace
)
8479 hm_kernel32
= LoadLibrary ("Kernel32.dll");
8480 s_pfn_CaptureStackBackTrace
=
8481 (CaptureStackBackTrace_proc
) GetProcAddress (hm_kernel32
,
8482 "RtlCaptureStackBackTrace");
8484 if (s_pfn_CaptureStackBackTrace
)
8485 return s_pfn_CaptureStackBackTrace (0, min (BACKTRACE_LIMIT_MAX
, limit
),
8494 button
= MessageBox (NULL
,
8495 "A fatal error has occurred!\n\n"
8496 "Would you like to attach a debugger?\n\n"
8498 "YES -- to debug Emacs, or\n"
8499 "NO -- to abort Emacs and produce a backtrace\n"
8500 " (emacs_backtrace.txt in current directory)."
8502 "\n\n(type \"gdb -p <emacs-PID>\" and\n"
8503 "\"continue\" inside GDB before clicking YES.)"
8505 , "Emacs Abort Dialog",
8506 MB_ICONEXCLAMATION
| MB_TASKMODAL
8507 | MB_SETFOREGROUND
| MB_YESNO
);
8512 exit (2); /* tell the compiler we will never return */
8516 void *stack
[BACKTRACE_LIMIT_MAX
+ 1];
8517 int i
= w32_backtrace (stack
, BACKTRACE_LIMIT_MAX
+ 1);
8521 int errfile_fd
= -1;
8523 char buf
[sizeof ("\r\nException at this address:\r\n\r\n")
8524 /* The type below should really be 'void *', but
8525 INT_BUFSIZE_BOUND cannot handle that without
8526 triggering compiler warnings (under certain
8527 pedantic warning switches), it wants an
8529 + 2 * INT_BUFSIZE_BOUND (intptr_t)];
8533 HANDLE errout
= GetStdHandle (STD_ERROR_HANDLE
);
8536 if (errout
&& errout
!= INVALID_HANDLE_VALUE
)
8537 stderr_fd
= _open_osfhandle ((intptr_t)errout
, O_APPEND
| O_BINARY
);
8540 /* We use %p, not 0x%p, as %p produces a leading "0x" on XP,
8541 but not on Windows 7. addr2line doesn't mind a missing
8542 "0x", but will be confused by an extra one. */
8544 sprintf (buf
, "\r\nException 0x%lx at this address:\r\n%p\r\n",
8545 except_code
, except_addr
);
8549 write (stderr_fd
, buf
, strlen (buf
));
8550 write (stderr_fd
, "\r\nBacktrace:\r\n", 14);
8555 errfile_fd
= _open ("emacs_backtrace.txt", O_RDWR
| O_CREAT
| O_BINARY
, S_IREAD
| S_IWRITE
);
8556 if (errfile_fd
>= 0)
8558 lseek (errfile_fd
, 0L, SEEK_END
);
8560 write (errfile_fd
, buf
, strlen (buf
));
8561 write (errfile_fd
, "\r\nBacktrace:\r\n", 14);
8564 for (j
= 0; j
< i
; j
++)
8566 /* stack[] gives the return addresses, whereas we want
8567 the address of the call, so decrease each address
8568 by approximate size of 1 CALL instruction. */
8569 sprintf (buf
, "%p\r\n", (char *)stack
[j
] - sizeof(void *));
8571 write (stderr_fd
, buf
, strlen (buf
));
8572 if (errfile_fd
>= 0)
8573 write (errfile_fd
, buf
, strlen (buf
));
8575 if (i
== BACKTRACE_LIMIT_MAX
)
8578 write (stderr_fd
, "...\r\n", 5);
8579 if (errfile_fd
>= 0)
8580 write (errfile_fd
, "...\r\n", 5);
8582 if (errfile_fd
>= 0)
8593 /* Initialization. */
8596 globals_of_w32fns is used to initialize those global variables that
8597 must always be initialized on startup even when the global variable
8598 initialized is non zero (see the function main in emacs.c).
8599 globals_of_w32fns is called from syms_of_w32fns when the global
8600 variable initialized is 0 and directly from main when initialized
8604 globals_of_w32fns (void)
8606 HMODULE user32_lib
= GetModuleHandle ("user32.dll");
8608 TrackMouseEvent not available in all versions of Windows, so must load
8609 it dynamically. Do it once, here, instead of every time it is used.
8611 track_mouse_event_fn
= (TrackMouseEvent_Proc
)
8612 GetProcAddress (user32_lib
, "TrackMouseEvent");
8614 monitor_from_point_fn
= (MonitorFromPoint_Proc
)
8615 GetProcAddress (user32_lib
, "MonitorFromPoint");
8616 get_monitor_info_fn
= (GetMonitorInfo_Proc
)
8617 GetProcAddress (user32_lib
, "GetMonitorInfoA");
8618 monitor_from_window_fn
= (MonitorFromWindow_Proc
)
8619 GetProcAddress (user32_lib
, "MonitorFromWindow");
8620 enum_display_monitors_fn
= (EnumDisplayMonitors_Proc
)
8621 GetProcAddress (user32_lib
, "EnumDisplayMonitors");
8624 HMODULE imm32_lib
= GetModuleHandle ("imm32.dll");
8625 get_composition_string_fn
= (ImmGetCompositionString_Proc
)
8626 GetProcAddress (imm32_lib
, "ImmGetCompositionStringW");
8627 get_ime_context_fn
= (ImmGetContext_Proc
)
8628 GetProcAddress (imm32_lib
, "ImmGetContext");
8629 release_ime_context_fn
= (ImmReleaseContext_Proc
)
8630 GetProcAddress (imm32_lib
, "ImmReleaseContext");
8631 set_ime_composition_window_fn
= (ImmSetCompositionWindow_Proc
)
8632 GetProcAddress (imm32_lib
, "ImmSetCompositionWindow");
8638 prev_exception_handler
= SetUnhandledExceptionFilter (my_exception_handler
);
8641 DEFVAR_INT ("w32-ansi-code-page",
8643 doc
: /* The ANSI code page used by the system. */);
8644 w32_ansi_code_page
= GetACP ();
8646 if (os_subtype
== OS_NT
)
8647 w32_unicode_gui
= 1;
8649 w32_unicode_gui
= 0;
8651 /* MessageBox does not work without this when linked to comctl32.dll 6.0. */
8652 InitCommonControls ();
8654 syms_of_w32uniscribe ();
8657 #ifdef NTGUI_UNICODE
8660 ntgui_encode_system (Lisp_Object str
)
8662 Lisp_Object encoded
;
8663 to_unicode (str
, &encoded
);
8667 #endif /* NTGUI_UNICODE */