1 /* Graphical user interface functions for the Microsoft Windows API.
3 Copyright (C) 1989, 1992-2013 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"
54 #endif /* WINDOWSNT */
62 #include "bitmaps/gray.xbm"
77 #ifndef FOF_NO_CONNECTED_ELEMENTS
78 #define FOF_NO_CONNECTED_ELEMENTS 0x2000
81 void syms_of_w32fns (void);
82 void globals_of_w32fns (void);
84 extern void free_frame_menubar (struct frame
*);
85 extern int w32_console_toggle_lock_key (int, Lisp_Object
);
86 extern void w32_menu_display_help (HWND
, HMENU
, UINT
, UINT
);
87 extern void w32_free_menu_strings (HWND
);
88 extern const char *map_w32_filename (const char *, const char **);
89 extern char * w32_strerror (int error_no
);
91 /* If non-NULL, a handle to a frame where to display the hourglass cursor. */
92 static HWND hourglass_hwnd
= NULL
;
95 #define IDC_HAND MAKEINTRESOURCE(32649)
98 Lisp_Object Qsuppress_icon
;
99 Lisp_Object Qundefined_color
;
100 Lisp_Object Qcancel_timer
;
101 Lisp_Object Qfont_param
;
107 Lisp_Object Qcontrol
;
111 /* Prefix for system colors. */
112 #define SYSTEM_COLOR_PREFIX "System"
113 #define SYSTEM_COLOR_PREFIX_LEN (sizeof (SYSTEM_COLOR_PREFIX) - 1)
115 /* State variables for emulating a three button mouse. */
120 static int button_state
= 0;
121 static W32Msg saved_mouse_button_msg
;
122 static unsigned mouse_button_timer
= 0; /* non-zero when timer is active */
123 static W32Msg saved_mouse_move_msg
;
124 static unsigned mouse_move_timer
= 0;
126 /* Window that is tracking the mouse. */
127 static HWND track_mouse_window
;
129 /* Multi-monitor API definitions that are not pulled from the headers
130 since we are compiling for NT 4. */
131 #ifndef MONITOR_DEFAULT_TO_NEAREST
132 #define MONITOR_DEFAULT_TO_NEAREST 2
134 /* MinGW headers define MONITORINFO unconditionally, but MSVC ones don't.
135 To avoid a compile error on one or the other, redefine with a new name. */
144 /* Reportedly, MSVC does not have this in its headers. */
145 #if defined (_MSC_VER) && _WIN32_WINNT < 0x0500
146 DECLARE_HANDLE(HMONITOR
);
149 typedef BOOL (WINAPI
* TrackMouseEvent_Proc
)
150 (IN OUT LPTRACKMOUSEEVENT lpEventTrack
);
151 typedef LONG (WINAPI
* ImmGetCompositionString_Proc
)
152 (IN HIMC context
, IN DWORD index
, OUT LPVOID buffer
, IN DWORD bufLen
);
153 typedef HIMC (WINAPI
* ImmGetContext_Proc
) (IN HWND window
);
154 typedef HWND (WINAPI
* ImmReleaseContext_Proc
) (IN HWND wnd
, IN HIMC context
);
155 typedef HWND (WINAPI
* ImmSetCompositionWindow_Proc
) (IN HIMC context
,
156 IN COMPOSITIONFORM
*form
);
157 typedef HMONITOR (WINAPI
* MonitorFromPoint_Proc
) (IN POINT pt
, IN DWORD flags
);
158 typedef BOOL (WINAPI
* GetMonitorInfo_Proc
)
159 (IN HMONITOR monitor
, OUT
struct MONITOR_INFO
* info
);
161 TrackMouseEvent_Proc track_mouse_event_fn
= NULL
;
162 ImmGetCompositionString_Proc get_composition_string_fn
= NULL
;
163 ImmGetContext_Proc get_ime_context_fn
= NULL
;
164 ImmReleaseContext_Proc release_ime_context_fn
= NULL
;
165 ImmSetCompositionWindow_Proc set_ime_composition_window_fn
= NULL
;
166 MonitorFromPoint_Proc monitor_from_point_fn
= NULL
;
167 GetMonitorInfo_Proc get_monitor_info_fn
= NULL
;
170 #define unicode_append_menu AppendMenuW
171 #else /* !NTGUI_UNICODE */
172 extern AppendMenuW_Proc unicode_append_menu
;
173 #endif /* NTGUI_UNICODE */
175 /* Flag to selectively ignore WM_IME_CHAR messages. */
176 static int ignore_ime_char
= 0;
178 /* W95 mousewheel handler */
179 unsigned int msh_mousewheel
= 0;
182 #define MOUSE_BUTTON_ID 1
183 #define MOUSE_MOVE_ID 2
184 #define MENU_FREE_ID 3
185 /* The delay (milliseconds) before a menu is freed after WM_EXITMENULOOP
187 #define MENU_FREE_DELAY 1000
188 static unsigned menu_free_timer
= 0;
191 static int image_cache_refcount
, dpyinfo_refcount
;
194 static HWND w32_visible_system_caret_hwnd
;
196 static int w32_unicode_gui
;
199 extern HMENU current_popup_menu
;
200 static int menubar_in_use
= 0;
202 /* From w32uniscribe.c */
203 extern void syms_of_w32uniscribe (void);
204 extern int uniscribe_available
;
206 /* Function prototypes for hourglass support. */
207 static void w32_show_hourglass (struct frame
*);
208 static void w32_hide_hourglass (void);
211 /* From w32inevt.c */
212 extern int faked_key
;
213 #endif /* WINDOWSNT */
215 /* This gives us the page size and the size of the allocation unit on NT. */
216 SYSTEM_INFO sysinfo_cache
;
218 /* This gives us version, build, and platform identification. */
219 OSVERSIONINFO osinfo_cache
;
221 DWORD_PTR syspage_mask
= 0;
223 /* The major and minor versions of NT. */
224 int w32_major_version
;
225 int w32_minor_version
;
226 int w32_build_number
;
228 /* Distinguish between Windows NT and Windows 95. */
232 HINSTANCE hinst
= NULL
;
235 static unsigned int sound_type
= 0xFFFFFFFF;
236 #define MB_EMACS_SILENT (0xFFFFFFFF - 1)
238 /* Let the user specify a display with a frame.
239 nil stands for the selected frame--or, if that is not a w32 frame,
240 the first display on the list. */
242 struct w32_display_info
*
243 check_x_display_info (Lisp_Object frame
)
247 struct frame
*sf
= XFRAME (selected_frame
);
249 if (FRAME_W32_P (sf
) && FRAME_LIVE_P (sf
))
250 return FRAME_W32_DISPLAY_INFO (sf
);
252 return &one_w32_display_info
;
254 else if (STRINGP (frame
))
255 return x_display_info_for_name (frame
);
260 CHECK_LIVE_FRAME (frame
);
262 if (! FRAME_W32_P (f
))
263 error ("Non-W32 frame used");
264 return FRAME_W32_DISPLAY_INFO (f
);
268 /* Return the Emacs frame-object corresponding to an w32 window.
269 It could be the frame's main window or an icon window. */
272 x_window_to_frame (struct w32_display_info
*dpyinfo
, HWND wdesc
)
274 Lisp_Object tail
, frame
;
277 FOR_EACH_FRAME (tail
, frame
)
280 if (!FRAME_W32_P (f
) || FRAME_W32_DISPLAY_INFO (f
) != dpyinfo
)
283 if (FRAME_W32_WINDOW (f
) == wdesc
)
290 static Lisp_Object
unwind_create_frame (Lisp_Object
);
291 static Lisp_Object
unwind_create_tip_frame (Lisp_Object
);
292 static void my_create_window (struct frame
*);
293 static void my_create_tip_window (struct frame
*);
295 /* TODO: Native Input Method support; see x_create_im. */
296 void x_set_foreground_color (struct frame
*, Lisp_Object
, Lisp_Object
);
297 void x_set_background_color (struct frame
*, Lisp_Object
, Lisp_Object
);
298 void x_set_mouse_color (struct frame
*, Lisp_Object
, Lisp_Object
);
299 void x_set_cursor_color (struct frame
*, Lisp_Object
, Lisp_Object
);
300 void x_set_border_color (struct frame
*, Lisp_Object
, Lisp_Object
);
301 void x_set_cursor_type (struct frame
*, Lisp_Object
, Lisp_Object
);
302 void x_set_icon_type (struct frame
*, Lisp_Object
, Lisp_Object
);
303 void x_set_icon_name (struct frame
*, Lisp_Object
, Lisp_Object
);
304 void x_explicitly_set_name (struct frame
*, Lisp_Object
, Lisp_Object
);
305 void x_set_menu_bar_lines (struct frame
*, Lisp_Object
, Lisp_Object
);
306 void x_set_title (struct frame
*, Lisp_Object
, Lisp_Object
);
307 void x_set_tool_bar_lines (struct frame
*, Lisp_Object
, Lisp_Object
);
312 /* Store the screen positions of frame F into XPTR and YPTR.
313 These are the positions of the containing window manager window,
314 not Emacs's own window. */
317 x_real_positions (FRAME_PTR f
, int *xptr
, int *yptr
)
322 /* Get the bounds of the WM window. */
323 GetWindowRect (FRAME_W32_WINDOW (f
), &rect
);
328 /* Convert (0, 0) in the client area to screen co-ordinates. */
329 ClientToScreen (FRAME_W32_WINDOW (f
), &pt
);
331 /* Remember x_pixels_diff and y_pixels_diff. */
332 f
->x_pixels_diff
= pt
.x
- rect
.left
;
333 f
->y_pixels_diff
= pt
.y
- rect
.top
;
341 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
,
342 Sw32_define_rgb_color
, 4, 4, 0,
343 doc
: /* Convert RGB numbers to a Windows color reference and associate with NAME.
344 This adds or updates a named color to `w32-color-map', making it
345 available for use. The original entry's RGB ref is returned, or nil
346 if the entry is new. */)
347 (Lisp_Object red
, Lisp_Object green
, Lisp_Object blue
, Lisp_Object name
)
350 Lisp_Object oldrgb
= Qnil
;
354 CHECK_NUMBER (green
);
358 XSETINT (rgb
, RGB (XUINT (red
), XUINT (green
), XUINT (blue
)));
362 /* replace existing entry in w32-color-map or add new entry. */
363 entry
= Fassoc (name
, Vw32_color_map
);
366 entry
= Fcons (name
, rgb
);
367 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
371 oldrgb
= Fcdr (entry
);
372 Fsetcdr (entry
, rgb
);
380 /* The default colors for the w32 color map */
381 typedef struct colormap_t
387 colormap_t w32_color_map
[] =
389 {"snow" , PALETTERGB (255,250,250)},
390 {"ghost white" , PALETTERGB (248,248,255)},
391 {"GhostWhite" , PALETTERGB (248,248,255)},
392 {"white smoke" , PALETTERGB (245,245,245)},
393 {"WhiteSmoke" , PALETTERGB (245,245,245)},
394 {"gainsboro" , PALETTERGB (220,220,220)},
395 {"floral white" , PALETTERGB (255,250,240)},
396 {"FloralWhite" , PALETTERGB (255,250,240)},
397 {"old lace" , PALETTERGB (253,245,230)},
398 {"OldLace" , PALETTERGB (253,245,230)},
399 {"linen" , PALETTERGB (250,240,230)},
400 {"antique white" , PALETTERGB (250,235,215)},
401 {"AntiqueWhite" , PALETTERGB (250,235,215)},
402 {"papaya whip" , PALETTERGB (255,239,213)},
403 {"PapayaWhip" , PALETTERGB (255,239,213)},
404 {"blanched almond" , PALETTERGB (255,235,205)},
405 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
406 {"bisque" , PALETTERGB (255,228,196)},
407 {"peach puff" , PALETTERGB (255,218,185)},
408 {"PeachPuff" , PALETTERGB (255,218,185)},
409 {"navajo white" , PALETTERGB (255,222,173)},
410 {"NavajoWhite" , PALETTERGB (255,222,173)},
411 {"moccasin" , PALETTERGB (255,228,181)},
412 {"cornsilk" , PALETTERGB (255,248,220)},
413 {"ivory" , PALETTERGB (255,255,240)},
414 {"lemon chiffon" , PALETTERGB (255,250,205)},
415 {"LemonChiffon" , PALETTERGB (255,250,205)},
416 {"seashell" , PALETTERGB (255,245,238)},
417 {"honeydew" , PALETTERGB (240,255,240)},
418 {"mint cream" , PALETTERGB (245,255,250)},
419 {"MintCream" , PALETTERGB (245,255,250)},
420 {"azure" , PALETTERGB (240,255,255)},
421 {"alice blue" , PALETTERGB (240,248,255)},
422 {"AliceBlue" , PALETTERGB (240,248,255)},
423 {"lavender" , PALETTERGB (230,230,250)},
424 {"lavender blush" , PALETTERGB (255,240,245)},
425 {"LavenderBlush" , PALETTERGB (255,240,245)},
426 {"misty rose" , PALETTERGB (255,228,225)},
427 {"MistyRose" , PALETTERGB (255,228,225)},
428 {"white" , PALETTERGB (255,255,255)},
429 {"black" , PALETTERGB ( 0, 0, 0)},
430 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
431 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
432 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
433 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
434 {"dim gray" , PALETTERGB (105,105,105)},
435 {"DimGray" , PALETTERGB (105,105,105)},
436 {"dim grey" , PALETTERGB (105,105,105)},
437 {"DimGrey" , PALETTERGB (105,105,105)},
438 {"slate gray" , PALETTERGB (112,128,144)},
439 {"SlateGray" , PALETTERGB (112,128,144)},
440 {"slate grey" , PALETTERGB (112,128,144)},
441 {"SlateGrey" , PALETTERGB (112,128,144)},
442 {"light slate gray" , PALETTERGB (119,136,153)},
443 {"LightSlateGray" , PALETTERGB (119,136,153)},
444 {"light slate grey" , PALETTERGB (119,136,153)},
445 {"LightSlateGrey" , PALETTERGB (119,136,153)},
446 {"gray" , PALETTERGB (190,190,190)},
447 {"grey" , PALETTERGB (190,190,190)},
448 {"light grey" , PALETTERGB (211,211,211)},
449 {"LightGrey" , PALETTERGB (211,211,211)},
450 {"light gray" , PALETTERGB (211,211,211)},
451 {"LightGray" , PALETTERGB (211,211,211)},
452 {"midnight blue" , PALETTERGB ( 25, 25,112)},
453 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
454 {"navy" , PALETTERGB ( 0, 0,128)},
455 {"navy blue" , PALETTERGB ( 0, 0,128)},
456 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
457 {"cornflower blue" , PALETTERGB (100,149,237)},
458 {"CornflowerBlue" , PALETTERGB (100,149,237)},
459 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
460 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
461 {"slate blue" , PALETTERGB (106, 90,205)},
462 {"SlateBlue" , PALETTERGB (106, 90,205)},
463 {"medium slate blue" , PALETTERGB (123,104,238)},
464 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
465 {"light slate blue" , PALETTERGB (132,112,255)},
466 {"LightSlateBlue" , PALETTERGB (132,112,255)},
467 {"medium blue" , PALETTERGB ( 0, 0,205)},
468 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
469 {"royal blue" , PALETTERGB ( 65,105,225)},
470 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
471 {"blue" , PALETTERGB ( 0, 0,255)},
472 {"dodger blue" , PALETTERGB ( 30,144,255)},
473 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
474 {"deep sky blue" , PALETTERGB ( 0,191,255)},
475 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
476 {"sky blue" , PALETTERGB (135,206,235)},
477 {"SkyBlue" , PALETTERGB (135,206,235)},
478 {"light sky blue" , PALETTERGB (135,206,250)},
479 {"LightSkyBlue" , PALETTERGB (135,206,250)},
480 {"steel blue" , PALETTERGB ( 70,130,180)},
481 {"SteelBlue" , PALETTERGB ( 70,130,180)},
482 {"light steel blue" , PALETTERGB (176,196,222)},
483 {"LightSteelBlue" , PALETTERGB (176,196,222)},
484 {"light blue" , PALETTERGB (173,216,230)},
485 {"LightBlue" , PALETTERGB (173,216,230)},
486 {"powder blue" , PALETTERGB (176,224,230)},
487 {"PowderBlue" , PALETTERGB (176,224,230)},
488 {"pale turquoise" , PALETTERGB (175,238,238)},
489 {"PaleTurquoise" , PALETTERGB (175,238,238)},
490 {"dark turquoise" , PALETTERGB ( 0,206,209)},
491 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
492 {"medium turquoise" , PALETTERGB ( 72,209,204)},
493 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
494 {"turquoise" , PALETTERGB ( 64,224,208)},
495 {"cyan" , PALETTERGB ( 0,255,255)},
496 {"light cyan" , PALETTERGB (224,255,255)},
497 {"LightCyan" , PALETTERGB (224,255,255)},
498 {"cadet blue" , PALETTERGB ( 95,158,160)},
499 {"CadetBlue" , PALETTERGB ( 95,158,160)},
500 {"medium aquamarine" , PALETTERGB (102,205,170)},
501 {"MediumAquamarine" , PALETTERGB (102,205,170)},
502 {"aquamarine" , PALETTERGB (127,255,212)},
503 {"dark green" , PALETTERGB ( 0,100, 0)},
504 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
505 {"dark olive green" , PALETTERGB ( 85,107, 47)},
506 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
507 {"dark sea green" , PALETTERGB (143,188,143)},
508 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
509 {"sea green" , PALETTERGB ( 46,139, 87)},
510 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
511 {"medium sea green" , PALETTERGB ( 60,179,113)},
512 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
513 {"light sea green" , PALETTERGB ( 32,178,170)},
514 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
515 {"pale green" , PALETTERGB (152,251,152)},
516 {"PaleGreen" , PALETTERGB (152,251,152)},
517 {"spring green" , PALETTERGB ( 0,255,127)},
518 {"SpringGreen" , PALETTERGB ( 0,255,127)},
519 {"lawn green" , PALETTERGB (124,252, 0)},
520 {"LawnGreen" , PALETTERGB (124,252, 0)},
521 {"green" , PALETTERGB ( 0,255, 0)},
522 {"chartreuse" , PALETTERGB (127,255, 0)},
523 {"medium spring green" , PALETTERGB ( 0,250,154)},
524 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
525 {"green yellow" , PALETTERGB (173,255, 47)},
526 {"GreenYellow" , PALETTERGB (173,255, 47)},
527 {"lime green" , PALETTERGB ( 50,205, 50)},
528 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
529 {"yellow green" , PALETTERGB (154,205, 50)},
530 {"YellowGreen" , PALETTERGB (154,205, 50)},
531 {"forest green" , PALETTERGB ( 34,139, 34)},
532 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
533 {"olive drab" , PALETTERGB (107,142, 35)},
534 {"OliveDrab" , PALETTERGB (107,142, 35)},
535 {"dark khaki" , PALETTERGB (189,183,107)},
536 {"DarkKhaki" , PALETTERGB (189,183,107)},
537 {"khaki" , PALETTERGB (240,230,140)},
538 {"pale goldenrod" , PALETTERGB (238,232,170)},
539 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
540 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
541 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
542 {"light yellow" , PALETTERGB (255,255,224)},
543 {"LightYellow" , PALETTERGB (255,255,224)},
544 {"yellow" , PALETTERGB (255,255, 0)},
545 {"gold" , PALETTERGB (255,215, 0)},
546 {"light goldenrod" , PALETTERGB (238,221,130)},
547 {"LightGoldenrod" , PALETTERGB (238,221,130)},
548 {"goldenrod" , PALETTERGB (218,165, 32)},
549 {"dark goldenrod" , PALETTERGB (184,134, 11)},
550 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
551 {"rosy brown" , PALETTERGB (188,143,143)},
552 {"RosyBrown" , PALETTERGB (188,143,143)},
553 {"indian red" , PALETTERGB (205, 92, 92)},
554 {"IndianRed" , PALETTERGB (205, 92, 92)},
555 {"saddle brown" , PALETTERGB (139, 69, 19)},
556 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
557 {"sienna" , PALETTERGB (160, 82, 45)},
558 {"peru" , PALETTERGB (205,133, 63)},
559 {"burlywood" , PALETTERGB (222,184,135)},
560 {"beige" , PALETTERGB (245,245,220)},
561 {"wheat" , PALETTERGB (245,222,179)},
562 {"sandy brown" , PALETTERGB (244,164, 96)},
563 {"SandyBrown" , PALETTERGB (244,164, 96)},
564 {"tan" , PALETTERGB (210,180,140)},
565 {"chocolate" , PALETTERGB (210,105, 30)},
566 {"firebrick" , PALETTERGB (178,34, 34)},
567 {"brown" , PALETTERGB (165,42, 42)},
568 {"dark salmon" , PALETTERGB (233,150,122)},
569 {"DarkSalmon" , PALETTERGB (233,150,122)},
570 {"salmon" , PALETTERGB (250,128,114)},
571 {"light salmon" , PALETTERGB (255,160,122)},
572 {"LightSalmon" , PALETTERGB (255,160,122)},
573 {"orange" , PALETTERGB (255,165, 0)},
574 {"dark orange" , PALETTERGB (255,140, 0)},
575 {"DarkOrange" , PALETTERGB (255,140, 0)},
576 {"coral" , PALETTERGB (255,127, 80)},
577 {"light coral" , PALETTERGB (240,128,128)},
578 {"LightCoral" , PALETTERGB (240,128,128)},
579 {"tomato" , PALETTERGB (255, 99, 71)},
580 {"orange red" , PALETTERGB (255, 69, 0)},
581 {"OrangeRed" , PALETTERGB (255, 69, 0)},
582 {"red" , PALETTERGB (255, 0, 0)},
583 {"hot pink" , PALETTERGB (255,105,180)},
584 {"HotPink" , PALETTERGB (255,105,180)},
585 {"deep pink" , PALETTERGB (255, 20,147)},
586 {"DeepPink" , PALETTERGB (255, 20,147)},
587 {"pink" , PALETTERGB (255,192,203)},
588 {"light pink" , PALETTERGB (255,182,193)},
589 {"LightPink" , PALETTERGB (255,182,193)},
590 {"pale violet red" , PALETTERGB (219,112,147)},
591 {"PaleVioletRed" , PALETTERGB (219,112,147)},
592 {"maroon" , PALETTERGB (176, 48, 96)},
593 {"medium violet red" , PALETTERGB (199, 21,133)},
594 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
595 {"violet red" , PALETTERGB (208, 32,144)},
596 {"VioletRed" , PALETTERGB (208, 32,144)},
597 {"magenta" , PALETTERGB (255, 0,255)},
598 {"violet" , PALETTERGB (238,130,238)},
599 {"plum" , PALETTERGB (221,160,221)},
600 {"orchid" , PALETTERGB (218,112,214)},
601 {"medium orchid" , PALETTERGB (186, 85,211)},
602 {"MediumOrchid" , PALETTERGB (186, 85,211)},
603 {"dark orchid" , PALETTERGB (153, 50,204)},
604 {"DarkOrchid" , PALETTERGB (153, 50,204)},
605 {"dark violet" , PALETTERGB (148, 0,211)},
606 {"DarkViolet" , PALETTERGB (148, 0,211)},
607 {"blue violet" , PALETTERGB (138, 43,226)},
608 {"BlueViolet" , PALETTERGB (138, 43,226)},
609 {"purple" , PALETTERGB (160, 32,240)},
610 {"medium purple" , PALETTERGB (147,112,219)},
611 {"MediumPurple" , PALETTERGB (147,112,219)},
612 {"thistle" , PALETTERGB (216,191,216)},
613 {"gray0" , PALETTERGB ( 0, 0, 0)},
614 {"grey0" , PALETTERGB ( 0, 0, 0)},
615 {"dark grey" , PALETTERGB (169,169,169)},
616 {"DarkGrey" , PALETTERGB (169,169,169)},
617 {"dark gray" , PALETTERGB (169,169,169)},
618 {"DarkGray" , PALETTERGB (169,169,169)},
619 {"dark blue" , PALETTERGB ( 0, 0,139)},
620 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
621 {"dark cyan" , PALETTERGB ( 0,139,139)},
622 {"DarkCyan" , PALETTERGB ( 0,139,139)},
623 {"dark magenta" , PALETTERGB (139, 0,139)},
624 {"DarkMagenta" , PALETTERGB (139, 0,139)},
625 {"dark red" , PALETTERGB (139, 0, 0)},
626 {"DarkRed" , PALETTERGB (139, 0, 0)},
627 {"light green" , PALETTERGB (144,238,144)},
628 {"LightGreen" , PALETTERGB (144,238,144)},
632 w32_default_color_map (void)
635 colormap_t
*pc
= w32_color_map
;
642 for (i
= 0; i
< sizeof (w32_color_map
) / sizeof (w32_color_map
[0]);
644 cmap
= Fcons (Fcons (build_string (pc
->name
),
645 make_number (pc
->colorref
)),
653 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
654 0, 0, 0, doc
: /* Return the default color map. */)
657 return w32_default_color_map ();
661 w32_color_map_lookup (const char *colorname
)
663 Lisp_Object tail
, ret
= Qnil
;
667 for (tail
= Vw32_color_map
; CONSP (tail
); tail
= XCDR (tail
))
669 register Lisp_Object elt
, tem
;
672 if (!CONSP (elt
)) continue;
676 if (lstrcmpi (SDATA (tem
), colorname
) == 0)
692 add_system_logical_colors_to_map (Lisp_Object
*system_colors
)
696 /* Other registry operations are done with input blocked. */
699 /* Look for "Control Panel/Colors" under User and Machine registry
701 if (RegOpenKeyEx (HKEY_CURRENT_USER
, "Control Panel\\Colors", 0,
702 KEY_READ
, &colors_key
) == ERROR_SUCCESS
703 || RegOpenKeyEx (HKEY_LOCAL_MACHINE
, "Control Panel\\Colors", 0,
704 KEY_READ
, &colors_key
) == ERROR_SUCCESS
)
707 char color_buffer
[64];
708 char full_name_buffer
[MAX_PATH
+ SYSTEM_COLOR_PREFIX_LEN
];
710 DWORD name_size
, color_size
;
711 char *name_buffer
= full_name_buffer
+ SYSTEM_COLOR_PREFIX_LEN
;
713 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
714 color_size
= sizeof (color_buffer
);
716 strcpy (full_name_buffer
, SYSTEM_COLOR_PREFIX
);
718 while (RegEnumValueA (colors_key
, index
, name_buffer
, &name_size
,
719 NULL
, NULL
, color_buffer
, &color_size
)
723 if (sscanf (color_buffer
, " %u %u %u", &r
, &g
, &b
) == 3)
724 *system_colors
= Fcons (Fcons (build_string (full_name_buffer
),
725 make_number (RGB (r
, g
, b
))),
728 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
729 color_size
= sizeof (color_buffer
);
732 RegCloseKey (colors_key
);
740 x_to_w32_color (const char * colorname
)
742 register Lisp_Object ret
= Qnil
;
746 if (colorname
[0] == '#')
748 /* Could be an old-style RGB Device specification. */
749 int size
= strlen (colorname
+ 1);
750 char *color
= alloca (size
+ 1);
752 strcpy (color
, colorname
+ 1);
753 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
761 for (i
= 0; i
< 3; i
++)
767 /* The check for 'x' in the following conditional takes into
768 account the fact that strtol allows a "0x" in front of
769 our numbers, and we don't. */
770 if (!isxdigit (color
[0]) || color
[1] == 'x')
774 value
= strtoul (color
, &end
, 16);
776 if (errno
== ERANGE
|| end
- color
!= size
)
781 value
= value
* 0x10;
792 colorval
|= (value
<< pos
);
797 XSETINT (ret
, colorval
);
804 else if (strnicmp (colorname
, "rgb:", 4) == 0)
812 color
= colorname
+ 4;
813 for (i
= 0; i
< 3; i
++)
818 /* The check for 'x' in the following conditional takes into
819 account the fact that strtol allows a "0x" in front of
820 our numbers, and we don't. */
821 if (!isxdigit (color
[0]) || color
[1] == 'x')
823 value
= strtoul (color
, &end
, 16);
829 value
= value
* 0x10 + value
;
842 if (value
== ULONG_MAX
)
844 colorval
|= (value
<< pos
);
851 XSETINT (ret
, colorval
);
859 else if (strnicmp (colorname
, "rgbi:", 5) == 0)
861 /* This is an RGB Intensity specification. */
868 color
= colorname
+ 5;
869 for (i
= 0; i
< 3; i
++)
875 value
= strtod (color
, &end
);
878 if (value
< 0.0 || value
> 1.0)
880 val
= (UINT
)(0x100 * value
);
881 /* We used 0x100 instead of 0xFF to give a continuous
882 range between 0.0 and 1.0 inclusive. The next statement
883 fixes the 1.0 case. */
886 colorval
|= (val
<< pos
);
893 XSETINT (ret
, colorval
);
901 /* I am not going to attempt to handle any of the CIE color schemes
902 or TekHVC, since I don't know the algorithms for conversion to
905 /* If we fail to lookup the color name in w32_color_map, then check the
906 colorname to see if it can be crudely approximated: If the X color
907 ends in a number (e.g., "darkseagreen2"), strip the number and
908 return the result of looking up the base color name. */
909 ret
= w32_color_map_lookup (colorname
);
912 int len
= strlen (colorname
);
914 if (isdigit (colorname
[len
- 1]))
916 char *ptr
, *approx
= alloca (len
+ 1);
918 strcpy (approx
, colorname
);
919 ptr
= &approx
[len
- 1];
920 while (ptr
> approx
&& isdigit (*ptr
))
923 ret
= w32_color_map_lookup (approx
);
932 w32_regenerate_palette (FRAME_PTR f
)
934 struct w32_palette_entry
* list
;
935 LOGPALETTE
* log_palette
;
936 HPALETTE new_palette
;
939 /* don't bother trying to create palette if not supported */
940 if (! FRAME_W32_DISPLAY_INFO (f
)->has_palette
)
943 log_palette
= (LOGPALETTE
*)
944 alloca (sizeof (LOGPALETTE
) +
945 FRAME_W32_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
946 log_palette
->palVersion
= 0x300;
947 log_palette
->palNumEntries
= FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
949 list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
951 i
< FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
952 i
++, list
= list
->next
)
953 log_palette
->palPalEntry
[i
] = list
->entry
;
955 new_palette
= CreatePalette (log_palette
);
959 if (FRAME_W32_DISPLAY_INFO (f
)->palette
)
960 DeleteObject (FRAME_W32_DISPLAY_INFO (f
)->palette
);
961 FRAME_W32_DISPLAY_INFO (f
)->palette
= new_palette
;
963 /* Realize display palette and garbage all frames. */
964 release_frame_dc (f
, get_frame_dc (f
));
969 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
970 #define SET_W32_COLOR(pe, color) \
973 pe.peRed = GetRValue (color); \
974 pe.peGreen = GetGValue (color); \
975 pe.peBlue = GetBValue (color); \
980 /* Keep these around in case we ever want to track color usage. */
982 w32_map_color (FRAME_PTR f
, COLORREF color
)
984 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
986 if (NILP (Vw32_enable_palette
))
989 /* check if color is already mapped */
992 if (W32_COLOR (list
->entry
) == color
)
1000 /* not already mapped, so add to list and recreate Windows palette */
1001 list
= xmalloc (sizeof (struct w32_palette_entry
));
1002 SET_W32_COLOR (list
->entry
, color
);
1004 list
->next
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1005 FRAME_W32_DISPLAY_INFO (f
)->color_list
= list
;
1006 FRAME_W32_DISPLAY_INFO (f
)->num_colors
++;
1008 /* set flag that palette must be regenerated */
1009 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1013 w32_unmap_color (FRAME_PTR f
, COLORREF color
)
1015 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1016 struct w32_palette_entry
**prev
= &FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1018 if (NILP (Vw32_enable_palette
))
1021 /* check if color is already mapped */
1024 if (W32_COLOR (list
->entry
) == color
)
1026 if (--list
->refcount
== 0)
1030 FRAME_W32_DISPLAY_INFO (f
)->num_colors
--;
1040 /* set flag that palette must be regenerated */
1041 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1046 /* Gamma-correct COLOR on frame F. */
1049 gamma_correct (struct frame
*f
, COLORREF
*color
)
1053 *color
= PALETTERGB (
1054 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1055 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1056 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1061 /* Decide if color named COLOR is valid for the display associated with
1062 the selected frame; if so, return the rgb values in COLOR_DEF.
1063 If ALLOC is nonzero, allocate a new colormap cell. */
1066 w32_defined_color (FRAME_PTR f
, const char *color
, XColor
*color_def
, int alloc
)
1068 register Lisp_Object tem
;
1069 COLORREF w32_color_ref
;
1071 tem
= x_to_w32_color (color
);
1077 /* Apply gamma correction. */
1078 w32_color_ref
= XUINT (tem
);
1079 gamma_correct (f
, &w32_color_ref
);
1080 XSETINT (tem
, w32_color_ref
);
1083 /* Map this color to the palette if it is enabled. */
1084 if (!NILP (Vw32_enable_palette
))
1086 struct w32_palette_entry
* entry
=
1087 one_w32_display_info
.color_list
;
1088 struct w32_palette_entry
** prev
=
1089 &one_w32_display_info
.color_list
;
1091 /* check if color is already mapped */
1094 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1096 prev
= &entry
->next
;
1097 entry
= entry
->next
;
1100 if (entry
== NULL
&& alloc
)
1102 /* not already mapped, so add to list */
1103 entry
= xmalloc (sizeof (struct w32_palette_entry
));
1104 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1107 one_w32_display_info
.num_colors
++;
1109 /* set flag that palette must be regenerated */
1110 one_w32_display_info
.regen_palette
= TRUE
;
1113 /* Ensure COLORREF value is snapped to nearest color in (default)
1114 palette by simulating the PALETTERGB macro. This works whether
1115 or not the display device has a palette. */
1116 w32_color_ref
= XUINT (tem
) | 0x2000000;
1118 color_def
->pixel
= w32_color_ref
;
1119 color_def
->red
= GetRValue (w32_color_ref
) * 256;
1120 color_def
->green
= GetGValue (w32_color_ref
) * 256;
1121 color_def
->blue
= GetBValue (w32_color_ref
) * 256;
1131 /* Given a string ARG naming a color, compute a pixel value from it
1132 suitable for screen F.
1133 If F is not a color screen, return DEF (default) regardless of what
1137 x_decode_color (FRAME_PTR f
, Lisp_Object arg
, int def
)
1143 if (strcmp (SDATA (arg
), "black") == 0)
1144 return BLACK_PIX_DEFAULT (f
);
1145 else if (strcmp (SDATA (arg
), "white") == 0)
1146 return WHITE_PIX_DEFAULT (f
);
1148 if ((FRAME_W32_DISPLAY_INFO (f
)->n_planes
* FRAME_W32_DISPLAY_INFO (f
)->n_cbits
) == 1)
1151 /* w32_defined_color is responsible for coping with failures
1152 by looking for a near-miss. */
1153 if (w32_defined_color (f
, SDATA (arg
), &cdef
, 1))
1156 /* defined_color failed; return an ultimate default. */
1162 /* Functions called only from `x_set_frame_param'
1163 to set individual parameters.
1165 If FRAME_W32_WINDOW (f) is 0,
1166 the frame is being created and its window does not exist yet.
1167 In that case, just record the parameter's new value
1168 in the standard place; do not attempt to change the window. */
1171 x_set_foreground_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1173 struct w32_output
*x
= f
->output_data
.w32
;
1174 PIX_TYPE fg
, old_fg
;
1176 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1177 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
1178 FRAME_FOREGROUND_PIXEL (f
) = fg
;
1180 if (FRAME_W32_WINDOW (f
) != 0)
1182 if (x
->cursor_pixel
== old_fg
)
1184 x
->cursor_pixel
= fg
;
1185 x
->cursor_gc
->background
= fg
;
1188 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
1189 if (FRAME_VISIBLE_P (f
))
1195 x_set_background_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1197 FRAME_BACKGROUND_PIXEL (f
)
1198 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
1200 if (FRAME_W32_WINDOW (f
) != 0)
1202 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
1203 FRAME_BACKGROUND_PIXEL (f
));
1205 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
1207 if (FRAME_VISIBLE_P (f
))
1213 x_set_mouse_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1215 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
1219 if (!EQ (Qnil
, arg
))
1220 f
->output_data
.w32
->mouse_pixel
1221 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1222 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
1224 /* Don't let pointers be invisible. */
1225 if (mask_color
== f
->output_data
.w32
->mouse_pixel
1226 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
1227 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
1229 #if 0 /* TODO : Mouse cursor customization. */
1232 /* It's not okay to crash if the user selects a screwy cursor. */
1233 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
1235 if (!EQ (Qnil
, Vx_pointer_shape
))
1237 CHECK_NUMBER (Vx_pointer_shape
);
1238 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
1241 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1242 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
1244 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
1246 CHECK_NUMBER (Vx_nontext_pointer_shape
);
1247 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1248 XINT (Vx_nontext_pointer_shape
));
1251 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
1252 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1254 if (!EQ (Qnil
, Vx_hourglass_pointer_shape
))
1256 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
1257 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1258 XINT (Vx_hourglass_pointer_shape
));
1261 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
1262 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
1264 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1265 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
1267 CHECK_NUMBER (Vx_mode_pointer_shape
);
1268 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1269 XINT (Vx_mode_pointer_shape
));
1272 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1273 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
1275 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
1277 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
1279 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1280 XINT (Vx_sensitive_text_pointer_shape
));
1283 hand_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
1285 if (!NILP (Vx_window_horizontal_drag_shape
))
1287 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
1288 horizontal_drag_cursor
1289 = XCreateFontCursor (FRAME_X_DISPLAY (f
),
1290 XINT (Vx_window_horizontal_drag_shape
));
1293 horizontal_drag_cursor
1294 = XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_sb_h_double_arrow
);
1296 /* Check and report errors with the above calls. */
1297 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
1298 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
1301 XColor fore_color
, back_color
;
1303 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
1304 back_color
.pixel
= mask_color
;
1305 XQueryColor (FRAME_W32_DISPLAY (f
),
1306 DefaultColormap (FRAME_W32_DISPLAY (f
),
1307 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1309 XQueryColor (FRAME_W32_DISPLAY (f
),
1310 DefaultColormap (FRAME_W32_DISPLAY (f
),
1311 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1313 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
1314 &fore_color
, &back_color
);
1315 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
1316 &fore_color
, &back_color
);
1317 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
1318 &fore_color
, &back_color
);
1319 XRecolorCursor (FRAME_W32_DISPLAY (f
), hand_cursor
,
1320 &fore_color
, &back_color
);
1321 XRecolorCursor (FRAME_W32_DISPLAY (f
), hourglass_cursor
,
1322 &fore_color
, &back_color
);
1325 if (FRAME_W32_WINDOW (f
) != 0)
1326 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
1328 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
1329 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
1330 f
->output_data
.w32
->text_cursor
= cursor
;
1332 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
1333 && f
->output_data
.w32
->nontext_cursor
!= 0)
1334 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
1335 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
1337 if (hourglass_cursor
!= f
->output_data
.w32
->hourglass_cursor
1338 && f
->output_data
.w32
->hourglass_cursor
!= 0)
1339 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hourglass_cursor
);
1340 f
->output_data
.w32
->hourglass_cursor
= hourglass_cursor
;
1342 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
1343 && f
->output_data
.w32
->modeline_cursor
!= 0)
1344 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
1345 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
1347 if (hand_cursor
!= f
->output_data
.w32
->hand_cursor
1348 && f
->output_data
.w32
->hand_cursor
!= 0)
1349 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hand_cursor
);
1350 f
->output_data
.w32
->hand_cursor
= hand_cursor
;
1352 XFlush (FRAME_W32_DISPLAY (f
));
1355 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1360 x_set_cursor_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1362 unsigned long fore_pixel
, pixel
;
1364 if (!NILP (Vx_cursor_fore_pixel
))
1365 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1366 WHITE_PIX_DEFAULT (f
));
1368 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1370 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1372 /* Make sure that the cursor color differs from the background color. */
1373 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
1375 pixel
= f
->output_data
.w32
->mouse_pixel
;
1376 if (pixel
== fore_pixel
)
1377 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1380 f
->output_data
.w32
->cursor_foreground_pixel
= fore_pixel
;
1381 f
->output_data
.w32
->cursor_pixel
= pixel
;
1383 if (FRAME_W32_WINDOW (f
) != 0)
1386 /* Update frame's cursor_gc. */
1387 f
->output_data
.w32
->cursor_gc
->foreground
= fore_pixel
;
1388 f
->output_data
.w32
->cursor_gc
->background
= pixel
;
1392 if (FRAME_VISIBLE_P (f
))
1394 x_update_cursor (f
, 0);
1395 x_update_cursor (f
, 1);
1399 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1402 /* Set the border-color of frame F to pixel value PIX.
1403 Note that this does not fully take effect if done before
1407 x_set_border_pixel (struct frame
*f
, int pix
)
1410 f
->output_data
.w32
->border_pixel
= pix
;
1412 if (FRAME_W32_WINDOW (f
) != 0 && f
->border_width
> 0)
1414 if (FRAME_VISIBLE_P (f
))
1419 /* Set the border-color of frame F to value described by ARG.
1420 ARG can be a string naming a color.
1421 The border-color is used for the border that is drawn by the server.
1422 Note that this does not fully take effect if done before
1423 F has a window; it must be redone when the window is created. */
1426 x_set_border_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1431 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1432 x_set_border_pixel (f
, pix
);
1433 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1438 x_set_cursor_type (FRAME_PTR f
, Lisp_Object arg
, Lisp_Object oldval
)
1440 set_frame_cursor_types (f
, arg
);
1442 /* Make sure the cursor gets redrawn. */
1443 cursor_type_changed
= 1;
1447 x_set_icon_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1451 if (NILP (arg
) && NILP (oldval
))
1454 if (STRINGP (arg
) && STRINGP (oldval
)
1455 && EQ (Fstring_equal (oldval
, arg
), Qt
))
1458 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
1463 result
= x_bitmap_icon (f
, arg
);
1467 error ("No icon window available");
1474 x_set_icon_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1478 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1481 else if (!NILP (arg
) || NILP (oldval
))
1484 fset_icon_name (f
, arg
);
1487 if (f
->output_data
.w32
->icon_bitmap
!= 0)
1492 result
= x_text_icon (f
,
1493 SSDATA ((!NILP (f
->icon_name
)
1502 error ("No icon window available");
1505 /* If the window was unmapped (and its icon was mapped),
1506 the new icon is not mapped, so map the window in its stead. */
1507 if (FRAME_VISIBLE_P (f
))
1509 #ifdef USE_X_TOOLKIT
1510 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
1512 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
1515 XFlush (FRAME_W32_DISPLAY (f
));
1522 x_set_menu_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1526 /* Right now, menu bars don't work properly in minibuf-only frames;
1527 most of the commands try to apply themselves to the minibuffer
1528 frame itself, and get an error because you can't switch buffers
1529 in or split the minibuffer window. */
1530 if (FRAME_MINIBUF_ONLY_P (f
))
1533 if (INTEGERP (value
))
1534 nlines
= XINT (value
);
1538 FRAME_MENU_BAR_LINES (f
) = 0;
1540 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1543 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1544 free_frame_menubar (f
);
1545 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1547 /* Adjust the frame size so that the client (text) dimensions
1548 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
1550 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
1551 do_pending_window_change (0);
1557 /* Set the number of lines used for the tool bar of frame F to VALUE.
1558 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1559 is the old number of tool bar lines. This function changes the
1560 height of all windows on frame F to match the new tool bar height.
1561 The frame's height doesn't change. */
1564 x_set_tool_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1566 int delta
, nlines
, root_height
;
1567 Lisp_Object root_window
;
1569 /* Treat tool bars like menu bars. */
1570 if (FRAME_MINIBUF_ONLY_P (f
))
1573 /* Use VALUE only if an integer >= 0. */
1574 if (INTEGERP (value
) && XINT (value
) >= 0)
1575 nlines
= XFASTINT (value
);
1579 /* Make sure we redisplay all windows in this frame. */
1580 ++windows_or_buffers_changed
;
1582 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
1584 /* Don't resize the tool-bar to more than we have room for. */
1585 root_window
= FRAME_ROOT_WINDOW (f
);
1586 root_height
= WINDOW_TOTAL_LINES (XWINDOW (root_window
));
1587 if (root_height
- delta
< 1)
1589 delta
= root_height
- 1;
1590 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
1593 FRAME_TOOL_BAR_LINES (f
) = nlines
;
1594 resize_frame_windows (f
, FRAME_LINES (f
), 0);
1597 /* We also have to make sure that the internal border at the top of
1598 the frame, below the menu bar or tool bar, is redrawn when the
1599 tool bar disappears. This is so because the internal border is
1600 below the tool bar if one is displayed, but is below the menu bar
1601 if there isn't a tool bar. The tool bar draws into the area
1602 below the menu bar. */
1603 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
1606 clear_current_matrices (f
);
1609 /* If the tool bar gets smaller, the internal border below it
1610 has to be cleared. It was formerly part of the display
1611 of the larger tool bar, and updating windows won't clear it. */
1614 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1615 int width
= FRAME_PIXEL_WIDTH (f
);
1616 int y
= nlines
* FRAME_LINE_HEIGHT (f
);
1620 HDC hdc
= get_frame_dc (f
);
1621 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
1622 release_frame_dc (f
, hdc
);
1626 if (WINDOWP (f
->tool_bar_window
))
1627 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1630 run_window_configuration_change_hook (f
);
1635 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1638 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1639 name; if NAME is a string, set F's name to NAME and set
1640 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1642 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1643 suggesting a new name, which lisp code should override; if
1644 F->explicit_name is set, ignore the new name; otherwise, set it. */
1647 x_set_name (struct frame
*f
, Lisp_Object name
, int explicit)
1649 /* Make sure that requests from lisp code override requests from
1650 Emacs redisplay code. */
1653 /* If we're switching from explicit to implicit, we had better
1654 update the mode lines and thereby update the title. */
1655 if (f
->explicit_name
&& NILP (name
))
1656 update_mode_lines
= 1;
1658 f
->explicit_name
= ! NILP (name
);
1660 else if (f
->explicit_name
)
1663 /* If NAME is nil, set the name to the w32_id_name. */
1666 /* Check for no change needed in this very common case
1667 before we do any consing. */
1668 if (!strcmp (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
,
1671 name
= build_string (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
);
1674 CHECK_STRING (name
);
1676 /* Don't change the name if it's already NAME. */
1677 if (! NILP (Fstring_equal (name
, f
->name
)))
1680 fset_name (f
, name
);
1682 /* For setting the frame title, the title parameter should override
1683 the name parameter. */
1684 if (! NILP (f
->title
))
1687 if (FRAME_W32_WINDOW (f
))
1690 GUI_FN (SetWindowText
) (FRAME_W32_WINDOW (f
),
1691 GUI_SDATA (GUI_ENCODE_SYSTEM (name
)));
1696 /* This function should be called when the user's lisp code has
1697 specified a name for the frame; the name will override any set by the
1700 x_explicitly_set_name (FRAME_PTR f
, Lisp_Object arg
, Lisp_Object oldval
)
1702 x_set_name (f
, arg
, 1);
1705 /* This function should be called by Emacs redisplay code to set the
1706 name; names set this way will never override names set by the user's
1709 x_implicitly_set_name (FRAME_PTR f
, Lisp_Object arg
, Lisp_Object oldval
)
1711 x_set_name (f
, arg
, 0);
1714 /* Change the title of frame F to NAME.
1715 If NAME is nil, use the frame name as the title. */
1718 x_set_title (struct frame
*f
, Lisp_Object name
, Lisp_Object old_name
)
1720 /* Don't change the title if it's already NAME. */
1721 if (EQ (name
, f
->title
))
1724 update_mode_lines
= 1;
1726 fset_title (f
, name
);
1731 if (FRAME_W32_WINDOW (f
))
1734 GUI_FN (SetWindowText
) (FRAME_W32_WINDOW (f
),
1735 GUI_SDATA (GUI_ENCODE_SYSTEM (name
)));
1741 x_set_scroll_bar_default_width (struct frame
*f
)
1743 int wid
= FRAME_COLUMN_WIDTH (f
);
1745 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
1746 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) +
1751 /* Subroutines for creating a frame. */
1754 w32_load_cursor (LPCTSTR name
)
1756 /* Try first to load cursor from application resource. */
1757 Cursor cursor
= LoadImage ((HINSTANCE
) GetModuleHandle (NULL
),
1758 name
, IMAGE_CURSOR
, 0, 0,
1759 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
1762 /* Then try to load a shared predefined cursor. */
1763 cursor
= LoadImage (NULL
, name
, IMAGE_CURSOR
, 0, 0,
1764 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
1769 static LRESULT CALLBACK
w32_wnd_proc (HWND
, UINT
, WPARAM
, LPARAM
);
1771 #define INIT_WINDOW_CLASS(WC) \
1772 (WC).style = CS_HREDRAW | CS_VREDRAW; \
1773 (WC).lpfnWndProc = (WNDPROC) w32_wnd_proc; \
1774 (WC).cbClsExtra = 0; \
1775 (WC).cbWndExtra = WND_EXTRA_BYTES; \
1776 (WC).hInstance = hinst; \
1777 (WC).hIcon = LoadIcon (hinst, EMACS_CLASS); \
1778 (WC).hCursor = w32_load_cursor (IDC_ARROW); \
1779 (WC).hbrBackground = NULL; \
1780 (WC).lpszMenuName = NULL; \
1783 w32_init_class (HINSTANCE hinst
)
1785 if (w32_unicode_gui
)
1788 INIT_WINDOW_CLASS(uwc
);
1789 uwc
.lpszClassName
= L
"Emacs";
1791 return RegisterClassW (&uwc
);
1796 INIT_WINDOW_CLASS(wc
);
1797 wc
.lpszClassName
= EMACS_CLASS
;
1799 return RegisterClassA (&wc
);
1804 w32_createscrollbar (struct frame
*f
, struct scroll_bar
* bar
)
1806 return (CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
1807 /* Position and size of scroll bar. */
1808 XINT (bar
->left
) + VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
1810 XINT (bar
->width
) - VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
1812 FRAME_W32_WINDOW (f
),
1819 w32_createwindow (struct frame
*f
)
1823 Lisp_Object top
= Qunbound
;
1824 Lisp_Object left
= Qunbound
;
1825 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
1827 rect
.left
= rect
.top
= 0;
1828 rect
.right
= FRAME_PIXEL_WIDTH (f
);
1829 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
1831 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
1832 FRAME_EXTERNAL_MENU_BAR (f
));
1834 /* Do first time app init */
1836 w32_init_class (hinst
);
1838 if (f
->size_hint_flags
& USPosition
|| f
->size_hint_flags
& PPosition
)
1840 XSETINT (left
, f
->left_pos
);
1841 XSETINT (top
, f
->top_pos
);
1843 else if (EQ (left
, Qunbound
) && EQ (top
, Qunbound
))
1845 /* When called with RES_TYPE_NUMBER, w32_get_arg will return zero
1846 for anything that is not a number and is not Qunbound. */
1847 left
= x_get_arg (dpyinfo
, Qnil
, Qleft
, "left", "Left", RES_TYPE_NUMBER
);
1848 top
= x_get_arg (dpyinfo
, Qnil
, Qtop
, "top", "Top", RES_TYPE_NUMBER
);
1851 FRAME_W32_WINDOW (f
) = hwnd
1852 = CreateWindow (EMACS_CLASS
,
1854 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
1855 EQ (left
, Qunbound
) ? CW_USEDEFAULT
: XINT (left
),
1856 EQ (top
, Qunbound
) ? CW_USEDEFAULT
: XINT (top
),
1857 rect
.right
- rect
.left
,
1858 rect
.bottom
- rect
.top
,
1866 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
1867 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
1868 SetWindowLong (hwnd
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
1869 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->scroll_bar_actual_width
);
1870 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
1872 /* Enable drag-n-drop. */
1873 DragAcceptFiles (hwnd
, TRUE
);
1875 /* Do this to discard the default setting specified by our parent. */
1876 ShowWindow (hwnd
, SW_HIDE
);
1878 /* Update frame positions. */
1879 GetWindowRect (hwnd
, &rect
);
1880 f
->left_pos
= rect
.left
;
1881 f
->top_pos
= rect
.top
;
1886 my_post_msg (W32Msg
* wmsg
, HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1888 wmsg
->msg
.hwnd
= hwnd
;
1889 wmsg
->msg
.message
= msg
;
1890 wmsg
->msg
.wParam
= wParam
;
1891 wmsg
->msg
.lParam
= lParam
;
1892 wmsg
->msg
.time
= GetMessageTime ();
1897 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
1898 between left and right keys as advertised. We test for this
1899 support dynamically, and set a flag when the support is absent. If
1900 absent, we keep track of the left and right control and alt keys
1901 ourselves. This is particularly necessary on keyboards that rely
1902 upon the AltGr key, which is represented as having the left control
1903 and right alt keys pressed. For these keyboards, we need to know
1904 when the left alt key has been pressed in addition to the AltGr key
1905 so that we can properly support M-AltGr-key sequences (such as M-@
1906 on Swedish keyboards). */
1908 #define EMACS_LCONTROL 0
1909 #define EMACS_RCONTROL 1
1910 #define EMACS_LMENU 2
1911 #define EMACS_RMENU 3
1913 static int modifiers
[4];
1914 static int modifiers_recorded
;
1915 static int modifier_key_support_tested
;
1918 test_modifier_support (unsigned int wparam
)
1922 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
1924 if (wparam
== VK_CONTROL
)
1934 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
1935 modifiers_recorded
= 1;
1937 modifiers_recorded
= 0;
1938 modifier_key_support_tested
= 1;
1942 record_keydown (unsigned int wparam
, unsigned int lparam
)
1946 if (!modifier_key_support_tested
)
1947 test_modifier_support (wparam
);
1949 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
1952 if (wparam
== VK_CONTROL
)
1953 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
1955 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
1961 record_keyup (unsigned int wparam
, unsigned int lparam
)
1965 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
1968 if (wparam
== VK_CONTROL
)
1969 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
1971 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
1976 /* Emacs can lose focus while a modifier key has been pressed. When
1977 it regains focus, be conservative and clear all modifiers since
1978 we cannot reconstruct the left and right modifier state. */
1980 reset_modifiers (void)
1984 if (GetFocus () == NULL
)
1985 /* Emacs doesn't have keyboard focus. Do nothing. */
1988 ctrl
= GetAsyncKeyState (VK_CONTROL
);
1989 alt
= GetAsyncKeyState (VK_MENU
);
1991 if (!(ctrl
& 0x08000))
1992 /* Clear any recorded control modifier state. */
1993 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
1995 if (!(alt
& 0x08000))
1996 /* Clear any recorded alt modifier state. */
1997 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
1999 /* Update the state of all modifier keys, because modifiers used in
2000 hot-key combinations can get stuck on if Emacs loses focus as a
2001 result of a hot-key being pressed. */
2005 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
2007 GetKeyboardState (keystate
);
2008 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
2009 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
2010 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
2011 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
2012 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
2013 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
2014 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
2015 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
2016 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
2017 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
2018 SetKeyboardState (keystate
);
2022 /* Synchronize modifier state with what is reported with the current
2023 keystroke. Even if we cannot distinguish between left and right
2024 modifier keys, we know that, if no modifiers are set, then neither
2025 the left or right modifier should be set. */
2027 sync_modifiers (void)
2029 if (!modifiers_recorded
)
2032 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
2033 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2035 if (!(GetKeyState (VK_MENU
) & 0x8000))
2036 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2040 modifier_set (int vkey
)
2042 /* Warning: The fact that VK_NUMLOCK is not treated as the other 2
2043 toggle keys is not an omission! If you want to add it, you will
2044 have to make changes in the default sub-case of the WM_KEYDOWN
2045 switch, because if the NUMLOCK modifier is set, the code there
2046 will directly convert any key that looks like an ASCII letter,
2047 and also downcase those that look like upper-case ASCII. */
2048 if (vkey
== VK_CAPITAL
)
2050 if (NILP (Vw32_enable_caps_lock
))
2053 return (GetKeyState (vkey
) & 0x1);
2055 if (vkey
== VK_SCROLL
)
2057 if (NILP (Vw32_scroll_lock_modifier
)
2058 /* w32-scroll-lock-modifier can be any non-nil value that is
2059 not one of the modifiers, in which case it shall be ignored. */
2060 || !( EQ (Vw32_scroll_lock_modifier
, Qhyper
)
2061 || EQ (Vw32_scroll_lock_modifier
, Qsuper
)
2062 || EQ (Vw32_scroll_lock_modifier
, Qmeta
)
2063 || EQ (Vw32_scroll_lock_modifier
, Qalt
)
2064 || EQ (Vw32_scroll_lock_modifier
, Qcontrol
)
2065 || EQ (Vw32_scroll_lock_modifier
, Qshift
)))
2068 return (GetKeyState (vkey
) & 0x1);
2071 if (!modifiers_recorded
)
2072 return (GetKeyState (vkey
) & 0x8000);
2077 return modifiers
[EMACS_LCONTROL
];
2079 return modifiers
[EMACS_RCONTROL
];
2081 return modifiers
[EMACS_LMENU
];
2083 return modifiers
[EMACS_RMENU
];
2085 return (GetKeyState (vkey
) & 0x8000);
2088 /* Convert between the modifier bits W32 uses and the modifier bits
2092 w32_key_to_modifier (int key
)
2094 Lisp_Object key_mapping
;
2099 key_mapping
= Vw32_lwindow_modifier
;
2102 key_mapping
= Vw32_rwindow_modifier
;
2105 key_mapping
= Vw32_apps_modifier
;
2108 key_mapping
= Vw32_scroll_lock_modifier
;
2114 /* NB. This code runs in the input thread, asynchronously to the lisp
2115 thread, so we must be careful to ensure access to lisp data is
2116 thread-safe. The following code is safe because the modifier
2117 variable values are updated atomically from lisp and symbols are
2118 not relocated by GC. Also, we don't have to worry about seeing GC
2120 if (EQ (key_mapping
, Qhyper
))
2121 return hyper_modifier
;
2122 if (EQ (key_mapping
, Qsuper
))
2123 return super_modifier
;
2124 if (EQ (key_mapping
, Qmeta
))
2125 return meta_modifier
;
2126 if (EQ (key_mapping
, Qalt
))
2127 return alt_modifier
;
2128 if (EQ (key_mapping
, Qctrl
))
2129 return ctrl_modifier
;
2130 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
2131 return ctrl_modifier
;
2132 if (EQ (key_mapping
, Qshift
))
2133 return shift_modifier
;
2135 /* Don't generate any modifier if not explicitly requested. */
2140 w32_get_modifiers (void)
2142 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
2143 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
2144 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
2145 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
2146 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
2147 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
2148 (modifier_set (VK_MENU
) ?
2149 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
2152 /* We map the VK_* modifiers into console modifier constants
2153 so that we can use the same routines to handle both console
2154 and window input. */
2157 construct_console_modifiers (void)
2162 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
2163 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
2164 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
2165 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
2166 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
2167 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
2168 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
2169 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
2170 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
2171 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
2172 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
2178 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
2182 /* Convert to emacs modifiers. */
2183 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
2189 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
2191 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
2194 if (virt_key
== VK_RETURN
)
2195 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
2197 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
2198 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
2200 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
2201 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
2203 if (virt_key
== VK_CLEAR
)
2204 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
2209 /* List of special key combinations which w32 would normally capture,
2210 but Emacs should grab instead. Not directly visible to lisp, to
2211 simplify synchronization. Each item is an integer encoding a virtual
2212 key code and modifier combination to capture. */
2213 static Lisp_Object w32_grabbed_keys
;
2215 #define HOTKEY(vk, mods) make_number (((vk) & 255) | ((mods) << 8))
2216 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
2217 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
2218 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
2220 #define RAW_HOTKEY_ID(k) ((k) & 0xbfff)
2221 #define RAW_HOTKEY_VK_CODE(k) ((k) & 255)
2222 #define RAW_HOTKEY_MODIFIERS(k) ((k) >> 8)
2224 /* Register hot-keys for reserved key combinations when Emacs has
2225 keyboard focus, since this is the only way Emacs can receive key
2226 combinations like Alt-Tab which are used by the system. */
2229 register_hot_keys (HWND hwnd
)
2231 Lisp_Object keylist
;
2233 /* Use CONSP, since we are called asynchronously. */
2234 for (keylist
= w32_grabbed_keys
; CONSP (keylist
); keylist
= XCDR (keylist
))
2236 Lisp_Object key
= XCAR (keylist
);
2238 /* Deleted entries get set to nil. */
2239 if (!INTEGERP (key
))
2242 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
2243 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
2248 unregister_hot_keys (HWND hwnd
)
2250 Lisp_Object keylist
;
2252 for (keylist
= w32_grabbed_keys
; CONSP (keylist
); keylist
= XCDR (keylist
))
2254 Lisp_Object key
= XCAR (keylist
);
2256 if (!INTEGERP (key
))
2259 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
2265 w32_name_of_message (UINT msg
)
2268 static char buf
[64];
2269 static const struct {
2273 #define M(msg) { msg, # msg }
2281 M (WM_EMACS_CREATEWINDOW
),
2283 M (WM_EMACS_CREATESCROLLBAR
),
2284 M (WM_EMACS_SHOWWINDOW
),
2285 M (WM_EMACS_SETWINDOWPOS
),
2286 M (WM_EMACS_DESTROYWINDOW
),
2287 M (WM_EMACS_TRACKPOPUPMENU
),
2288 M (WM_EMACS_SETFOCUS
),
2289 M (WM_EMACS_SETFOREGROUND
),
2290 M (WM_EMACS_SETLOCALE
),
2291 M (WM_EMACS_SETKEYBOARDLAYOUT
),
2292 M (WM_EMACS_REGISTER_HOT_KEY
),
2293 M (WM_EMACS_UNREGISTER_HOT_KEY
),
2294 M (WM_EMACS_TOGGLE_LOCK_KEY
),
2295 M (WM_EMACS_TRACK_CARET
),
2296 M (WM_EMACS_DESTROY_CARET
),
2297 M (WM_EMACS_SHOW_CARET
),
2298 M (WM_EMACS_HIDE_CARET
),
2299 M (WM_EMACS_SETCURSOR
),
2306 for (i
= 0; msgnames
[i
].name
; ++i
)
2307 if (msgnames
[i
].msg
== msg
)
2308 return msgnames
[i
].name
;
2310 sprintf (buf
, "message 0x%04x", (unsigned)msg
);
2313 #endif /* EMACSDEBUG */
2315 /* Here's an overview of how Emacs input works in GUI sessions on
2316 MS-Windows. (For description of non-GUI input, see the commentary
2317 before w32_console_read_socket in w32inevt.c.)
2319 System messages are read and processed by w32_msg_pump below. This
2320 function runs in a separate thread. It handles a small number of
2321 custom WM_EMACS_* messages (posted by the main thread, look for
2322 PostMessage calls), and dispatches the rest to w32_wnd_proc, which
2323 is the main window procedure for the entire Emacs application.
2325 w32_wnd_proc also runs in the same separate input thread. It
2326 handles some messages, mostly those that need GDI calls, by itself.
2327 For the others, it calls my_post_msg, which inserts the messages
2328 into the input queue serviced by w32_read_socket.
2330 w32_read_socket runs in the main (a.k.a. "Lisp") thread, and is
2331 called synchronously from keyboard.c when it is known or suspected
2332 that some input is available. w32_read_socket either handles
2333 messages immediately, or converts them into Emacs input events and
2334 stuffs them into kbd_buffer, where kbd_buffer_get_event can get at
2335 them and process them when read_char and its callers require
2338 Under Cygwin with the W32 toolkit, the use of /dev/windows with
2339 select(2) takes the place of w32_read_socket.
2343 /* Main message dispatch loop. */
2346 w32_msg_pump (deferred_msg
* msg_buf
)
2352 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
2354 while ((w32_unicode_gui
? GetMessageW
: GetMessageA
) (&msg
, NULL
, 0, 0))
2357 /* DebPrint (("w32_msg_pump: %s time:%u\n", */
2358 /* w32_name_of_message (msg.message), msg.time)); */
2360 if (msg
.hwnd
== NULL
)
2362 switch (msg
.message
)
2365 /* Produced by complete_deferred_msg; just ignore. */
2367 case WM_EMACS_CREATEWINDOW
:
2368 /* Initialize COM for this window. Even though we don't use it,
2369 some third party shell extensions can cause it to be used in
2370 system dialogs, which causes a crash if it is not initialized.
2371 This is a known bug in Windows, which was fixed long ago, but
2372 the patch for XP is not publicly available until XP SP3,
2373 and older versions will never be patched. */
2374 CoInitialize (NULL
);
2375 w32_createwindow ((struct frame
*) msg
.wParam
);
2376 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2379 case WM_EMACS_SETLOCALE
:
2380 SetThreadLocale (msg
.wParam
);
2381 /* Reply is not expected. */
2383 case WM_EMACS_SETKEYBOARDLAYOUT
:
2384 result
= (WPARAM
) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
2385 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2389 case WM_EMACS_REGISTER_HOT_KEY
:
2390 focus_window
= GetFocus ();
2391 if (focus_window
!= NULL
)
2392 RegisterHotKey (focus_window
,
2393 RAW_HOTKEY_ID (msg
.wParam
),
2394 RAW_HOTKEY_MODIFIERS (msg
.wParam
),
2395 RAW_HOTKEY_VK_CODE (msg
.wParam
));
2396 /* Reply is not expected. */
2398 case WM_EMACS_UNREGISTER_HOT_KEY
:
2399 focus_window
= GetFocus ();
2400 if (focus_window
!= NULL
)
2401 UnregisterHotKey (focus_window
, RAW_HOTKEY_ID (msg
.wParam
));
2402 /* Mark item as erased. NB: this code must be
2403 thread-safe. The next line is okay because the cons
2404 cell is never made into garbage and is not relocated by
2406 XSETCAR (XIL ((EMACS_INT
) msg
.lParam
), Qnil
);
2407 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2410 case WM_EMACS_TOGGLE_LOCK_KEY
:
2412 int vk_code
= (int) msg
.wParam
;
2413 int cur_state
= (GetKeyState (vk_code
) & 1);
2414 Lisp_Object new_state
= XIL ((EMACS_INT
) msg
.lParam
);
2416 /* NB: This code must be thread-safe. It is safe to
2417 call NILP because symbols are not relocated by GC,
2418 and pointer here is not touched by GC (so the markbit
2419 can't be set). Numbers are safe because they are
2420 immediate values. */
2421 if (NILP (new_state
)
2422 || (NUMBERP (new_state
)
2423 && ((XUINT (new_state
)) & 1) != cur_state
))
2425 one_w32_display_info
.faked_key
= vk_code
;
2427 keybd_event ((BYTE
) vk_code
,
2428 (BYTE
) MapVirtualKey (vk_code
, 0),
2429 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2430 keybd_event ((BYTE
) vk_code
,
2431 (BYTE
) MapVirtualKey (vk_code
, 0),
2432 KEYEVENTF_EXTENDEDKEY
| 0, 0);
2433 keybd_event ((BYTE
) vk_code
,
2434 (BYTE
) MapVirtualKey (vk_code
, 0),
2435 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2436 cur_state
= !cur_state
;
2438 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2444 /* Broadcast messages make it here, so you need to be looking
2445 for something in particular for this to be useful. */
2447 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
2453 if (w32_unicode_gui
)
2454 DispatchMessageW (&msg
);
2456 DispatchMessageA (&msg
);
2459 /* Exit nested loop when our deferred message has completed. */
2460 if (msg_buf
->completed
)
2465 deferred_msg
* deferred_msg_head
;
2467 static deferred_msg
*
2468 find_deferred_msg (HWND hwnd
, UINT msg
)
2470 deferred_msg
* item
;
2472 /* Don't actually need synchronization for read access, since
2473 modification of single pointer is always atomic. */
2474 /* enter_crit (); */
2476 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2477 if (item
->w32msg
.msg
.hwnd
== hwnd
2478 && item
->w32msg
.msg
.message
== msg
)
2481 /* leave_crit (); */
2487 send_deferred_msg (deferred_msg
* msg_buf
,
2493 /* Only input thread can send deferred messages. */
2494 if (GetCurrentThreadId () != dwWindowsThreadId
)
2497 /* It is an error to send a message that is already deferred. */
2498 if (find_deferred_msg (hwnd
, msg
) != NULL
)
2501 /* Enforced synchronization is not needed because this is the only
2502 function that alters deferred_msg_head, and the following critical
2503 section is guaranteed to only be serially reentered (since only the
2504 input thread can call us). */
2506 /* enter_crit (); */
2508 msg_buf
->completed
= 0;
2509 msg_buf
->next
= deferred_msg_head
;
2510 deferred_msg_head
= msg_buf
;
2511 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
2513 /* leave_crit (); */
2515 /* Start a new nested message loop to process other messages until
2516 this one is completed. */
2517 w32_msg_pump (msg_buf
);
2519 deferred_msg_head
= msg_buf
->next
;
2521 return msg_buf
->result
;
2525 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
2527 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
2529 if (msg_buf
== NULL
)
2530 /* Message may have been canceled, so don't abort. */
2533 msg_buf
->result
= result
;
2534 msg_buf
->completed
= 1;
2536 /* Ensure input thread is woken so it notices the completion. */
2537 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2541 cancel_all_deferred_msgs (void)
2543 deferred_msg
* item
;
2545 /* Don't actually need synchronization for read access, since
2546 modification of single pointer is always atomic. */
2547 /* enter_crit (); */
2549 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2552 item
->completed
= 1;
2555 /* leave_crit (); */
2557 /* Ensure input thread is woken so it notices the completion. */
2558 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2562 w32_msg_worker (void *arg
)
2565 deferred_msg dummy_buf
;
2567 /* Ensure our message queue is created */
2569 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
2571 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2574 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
2575 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
2576 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
2578 /* This is the initial message loop which should only exit when the
2579 application quits. */
2580 w32_msg_pump (&dummy_buf
);
2586 signal_user_input (void)
2588 /* Interrupt any lisp that wants to be interrupted by input. */
2589 if (!NILP (Vthrow_on_input
))
2591 Vquit_flag
= Vthrow_on_input
;
2592 /* Doing a QUIT from this thread is a bad idea, since this
2593 unwinds the stack of the Lisp thread, and the Windows runtime
2594 rightfully barfs. Disabled. */
2596 /* If we're inside a function that wants immediate quits,
2598 if (immediate_quit
&& NILP (Vinhibit_quit
))
2609 post_character_message (HWND hwnd
, UINT msg
,
2610 WPARAM wParam
, LPARAM lParam
,
2615 wmsg
.dwModifiers
= modifiers
;
2617 /* Detect quit_char and set quit-flag directly. Note that we
2618 still need to post a message to ensure the main thread will be
2619 woken up if blocked in sys_select, but we do NOT want to post
2620 the quit_char message itself (because it will usually be as if
2621 the user had typed quit_char twice). Instead, we post a dummy
2622 message that has no particular effect. */
2625 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
2626 c
= make_ctrl_char (c
) & 0377;
2628 || (wmsg
.dwModifiers
== 0
2629 && w32_quit_key
&& wParam
== w32_quit_key
))
2633 /* The choice of message is somewhat arbitrary, as long as
2634 the main thread handler just ignores it. */
2637 /* Interrupt any blocking system calls. */
2640 /* As a safety precaution, forcibly complete any deferred
2641 messages. This is a kludge, but I don't see any particularly
2642 clean way to handle the situation where a deferred message is
2643 "dropped" in the lisp thread, and will thus never be
2644 completed, eg. by the user trying to activate the menubar
2645 when the lisp thread is busy, and then typing C-g when the
2646 menubar doesn't open promptly (with the result that the
2647 menubar never responds at all because the deferred
2648 WM_INITMENU message is never completed). Another problem
2649 situation is when the lisp thread calls SendMessage (to send
2650 a window manager command) when a message has been deferred;
2651 the lisp thread gets blocked indefinitely waiting for the
2652 deferred message to be completed, which itself is waiting for
2653 the lisp thread to respond.
2655 Note that we don't want to block the input thread waiting for
2656 a response from the lisp thread (although that would at least
2657 solve the deadlock problem above), because we want to be able
2658 to receive C-g to interrupt the lisp thread. */
2659 cancel_all_deferred_msgs ();
2662 signal_user_input ();
2665 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2668 /* Main window procedure */
2670 static LRESULT CALLBACK
2671 w32_wnd_proc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2674 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
2676 int windows_translate
;
2679 /* Note that it is okay to call x_window_to_frame, even though we are
2680 not running in the main lisp thread, because frame deletion
2681 requires the lisp thread to synchronize with this thread. Thus, if
2682 a frame struct is returned, it can be used without concern that the
2683 lisp thread might make it disappear while we are using it.
2685 NB. Walking the frame list in this thread is safe (as long as
2686 writes of Lisp_Object slots are atomic, which they are on Windows).
2687 Although delete-frame can destructively modify the frame list while
2688 we are walking it, a garbage collection cannot occur until after
2689 delete-frame has synchronized with this thread.
2691 It is also safe to use functions that make GDI calls, such as
2692 w32_clear_rect, because these functions must obtain a DC handle
2693 from the frame struct using get_frame_dc which is thread-aware. */
2698 f
= x_window_to_frame (dpyinfo
, hwnd
);
2701 HDC hdc
= get_frame_dc (f
);
2702 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
2703 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
2704 release_frame_dc (f
, hdc
);
2706 #if defined (W32_DEBUG_DISPLAY)
2707 DebPrint (("WM_ERASEBKGND (frame %p): erasing %d,%d-%d,%d\n",
2709 wmsg
.rect
.left
, wmsg
.rect
.top
,
2710 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2711 #endif /* W32_DEBUG_DISPLAY */
2714 case WM_PALETTECHANGED
:
2715 /* ignore our own changes */
2716 if ((HWND
)wParam
!= hwnd
)
2718 f
= x_window_to_frame (dpyinfo
, hwnd
);
2720 /* get_frame_dc will realize our palette and force all
2721 frames to be redrawn if needed. */
2722 release_frame_dc (f
, get_frame_dc (f
));
2727 PAINTSTRUCT paintStruct
;
2729 memset (&update_rect
, 0, sizeof (update_rect
));
2731 f
= x_window_to_frame (dpyinfo
, hwnd
);
2734 DebPrint (("WM_PAINT received for unknown window %p\n", hwnd
));
2738 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
2739 fails. Apparently this can happen under some
2741 if (GetUpdateRect (hwnd
, &update_rect
, FALSE
) || !w32_strict_painting
)
2744 BeginPaint (hwnd
, &paintStruct
);
2746 /* The rectangles returned by GetUpdateRect and BeginPaint
2747 do not always match. Play it safe by assuming both areas
2749 UnionRect (&(wmsg
.rect
), &update_rect
, &(paintStruct
.rcPaint
));
2751 #if defined (W32_DEBUG_DISPLAY)
2752 DebPrint (("WM_PAINT (frame %p): painting %d,%d-%d,%d\n",
2754 wmsg
.rect
.left
, wmsg
.rect
.top
,
2755 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2756 DebPrint ((" [update region is %d,%d-%d,%d]\n",
2757 update_rect
.left
, update_rect
.top
,
2758 update_rect
.right
, update_rect
.bottom
));
2760 EndPaint (hwnd
, &paintStruct
);
2763 /* Change the message type to prevent Windows from
2764 combining WM_PAINT messages in the Lisp thread's queue,
2765 since Windows assumes that each message queue is
2766 dedicated to one frame and does not bother checking
2767 that hwnd matches before combining them. */
2768 my_post_msg (&wmsg
, hwnd
, WM_EMACS_PAINT
, wParam
, lParam
);
2773 /* If GetUpdateRect returns 0 (meaning there is no update
2774 region), assume the whole window needs to be repainted. */
2775 GetClientRect (hwnd
, &wmsg
.rect
);
2776 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2780 case WM_INPUTLANGCHANGE
:
2781 /* Inform lisp thread of keyboard layout changes. */
2782 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2784 /* Clear dead keys in the keyboard state; for simplicity only
2785 preserve modifier key states. */
2790 GetKeyboardState (keystate
);
2791 for (i
= 0; i
< 256; i
++)
2808 SetKeyboardState (keystate
);
2813 /* Synchronize hot keys with normal input. */
2814 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
2819 record_keyup (wParam
, lParam
);
2824 /* Ignore keystrokes we fake ourself; see below. */
2825 if (dpyinfo
->faked_key
== wParam
)
2827 dpyinfo
->faked_key
= 0;
2828 /* Make sure TranslateMessage sees them though (as long as
2829 they don't produce WM_CHAR messages). This ensures that
2830 indicator lights are toggled promptly on Windows 9x, for
2832 if (wParam
< 256 && lispy_function_keys
[wParam
])
2834 windows_translate
= 1;
2840 /* Synchronize modifiers with current keystroke. */
2842 record_keydown (wParam
, lParam
);
2843 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
2845 windows_translate
= 0;
2850 if (NILP (Vw32_pass_lwindow_to_system
))
2852 /* Prevent system from acting on keyup (which opens the
2853 Start menu if no other key was pressed) by simulating a
2854 press of Space which we will ignore. */
2855 if (GetAsyncKeyState (wParam
) & 1)
2857 if (NUMBERP (Vw32_phantom_key_code
))
2858 key
= XUINT (Vw32_phantom_key_code
) & 255;
2861 dpyinfo
->faked_key
= key
;
2862 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
2865 if (!NILP (Vw32_lwindow_modifier
))
2869 if (NILP (Vw32_pass_rwindow_to_system
))
2871 if (GetAsyncKeyState (wParam
) & 1)
2873 if (NUMBERP (Vw32_phantom_key_code
))
2874 key
= XUINT (Vw32_phantom_key_code
) & 255;
2877 dpyinfo
->faked_key
= key
;
2878 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
2881 if (!NILP (Vw32_rwindow_modifier
))
2885 if (!NILP (Vw32_apps_modifier
))
2889 if (NILP (Vw32_pass_alt_to_system
))
2890 /* Prevent DefWindowProc from activating the menu bar if an
2891 Alt key is pressed and released by itself. */
2893 windows_translate
= 1;
2896 /* Decide whether to treat as modifier or function key. */
2897 if (NILP (Vw32_enable_caps_lock
))
2898 goto disable_lock_key
;
2899 windows_translate
= 1;
2902 /* Decide whether to treat as modifier or function key. */
2903 if (NILP (Vw32_enable_num_lock
))
2904 goto disable_lock_key
;
2905 windows_translate
= 1;
2908 /* Decide whether to treat as modifier or function key. */
2909 if (NILP (Vw32_scroll_lock_modifier
))
2910 goto disable_lock_key
;
2911 windows_translate
= 1;
2914 /* Ensure the appropriate lock key state (and indicator light)
2915 remains in the same state. We do this by faking another
2916 press of the relevant key. Apparently, this really is the
2917 only way to toggle the state of the indicator lights. */
2918 dpyinfo
->faked_key
= wParam
;
2919 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
2920 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2921 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
2922 KEYEVENTF_EXTENDEDKEY
| 0, 0);
2923 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
2924 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2925 /* Ensure indicator lights are updated promptly on Windows 9x
2926 (TranslateMessage apparently does this), after forwarding
2928 post_character_message (hwnd
, msg
, wParam
, lParam
,
2929 w32_get_key_modifiers (wParam
, lParam
));
2930 windows_translate
= 1;
2934 case VK_PROCESSKEY
: /* Generated by IME. */
2935 windows_translate
= 1;
2938 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
2939 which is confusing for purposes of key binding; convert
2940 VK_CANCEL events into VK_PAUSE events. */
2944 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
2945 for purposes of key binding; convert these back into
2946 VK_NUMLOCK events, at least when we want to see NumLock key
2947 presses. (Note that there is never any possibility that
2948 VK_PAUSE with Ctrl really is C-Pause as per above.) */
2949 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
2950 wParam
= VK_NUMLOCK
;
2953 /* If not defined as a function key, change it to a WM_CHAR message. */
2954 if (wParam
> 255 || !lispy_function_keys
[wParam
])
2956 DWORD modifiers
= construct_console_modifiers ();
2958 if (!NILP (Vw32_recognize_altgr
)
2959 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
2961 /* Always let TranslateMessage handle AltGr key chords;
2962 for some reason, ToAscii doesn't always process AltGr
2963 chords correctly. */
2964 windows_translate
= 1;
2966 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
2968 /* Handle key chords including any modifiers other
2969 than shift directly, in order to preserve as much
2970 modifier information as possible. */
2971 if ('A' <= wParam
&& wParam
<= 'Z')
2973 /* Don't translate modified alphabetic keystrokes,
2974 so the user doesn't need to constantly switch
2975 layout to type control or meta keystrokes when
2976 the normal layout translates alphabetic
2977 characters to non-ascii characters. */
2978 if (!modifier_set (VK_SHIFT
))
2979 wParam
+= ('a' - 'A');
2984 /* Try to handle other keystrokes by determining the
2985 base character (ie. translating the base key plus
2988 KEY_EVENT_RECORD key
;
2990 key
.bKeyDown
= TRUE
;
2991 key
.wRepeatCount
= 1;
2992 key
.wVirtualKeyCode
= wParam
;
2993 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
2994 key
.uChar
.AsciiChar
= 0;
2995 key
.dwControlKeyState
= modifiers
;
2997 add
= w32_kbd_patch_key (&key
, w32_keyboard_codepage
);
2998 /* 0 means an unrecognized keycode, negative means
2999 dead key. Ignore both. */
3002 /* Forward asciified character sequence. */
3003 post_character_message
3005 (unsigned char) key
.uChar
.AsciiChar
, lParam
,
3006 w32_get_key_modifiers (wParam
, lParam
));
3007 w32_kbd_patch_key (&key
, w32_keyboard_codepage
);
3014 /* Let TranslateMessage handle everything else. */
3015 windows_translate
= 1;
3021 if (windows_translate
)
3023 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
3024 windows_msg
.time
= GetMessageTime ();
3025 TranslateMessage (&windows_msg
);
3037 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3038 signal_user_input ();
3039 my_post_msg (&wmsg
, hwnd
, WM_UNICHAR
, wParam
, lParam
);
3043 post_character_message (hwnd
, msg
, wParam
, lParam
,
3044 w32_get_key_modifiers (wParam
, lParam
));
3048 /* WM_UNICHAR looks promising from the docs, but the exact
3049 circumstances in which TranslateMessage sends it is one of those
3050 Microsoft secret API things that EU and US courts are supposed
3051 to have put a stop to already. Spy++ shows it being sent to Notepad
3052 and other MS apps, but never to Emacs.
3054 Some third party IMEs send it in accordance with the official
3055 documentation though, so handle it here.
3057 UNICODE_NOCHAR is used to test for support for this message.
3058 TRUE indicates that the message is supported. */
3059 if (wParam
== UNICODE_NOCHAR
)
3064 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3065 signal_user_input ();
3066 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3071 /* If we can't get the IME result as Unicode, use default processing,
3072 which will at least allow characters decodable in the system locale
3074 if (!get_composition_string_fn
)
3077 else if (!ignore_ime_char
)
3082 HIMC context
= get_ime_context_fn (hwnd
);
3083 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3084 /* Get buffer size. */
3085 size
= get_composition_string_fn (context
, GCS_RESULTSTR
, NULL
, 0);
3086 buffer
= alloca (size
);
3087 size
= get_composition_string_fn (context
, GCS_RESULTSTR
,
3089 release_ime_context_fn (hwnd
, context
);
3091 signal_user_input ();
3092 for (i
= 0; i
< size
/ sizeof (wchar_t); i
++)
3094 my_post_msg (&wmsg
, hwnd
, WM_UNICHAR
, (WPARAM
) buffer
[i
],
3097 /* Ignore the messages for the rest of the
3098 characters in the string that was output above. */
3099 ignore_ime_char
= (size
/ sizeof (wchar_t)) - 1;
3106 case WM_IME_STARTCOMPOSITION
:
3107 if (!set_ime_composition_window_fn
)
3111 COMPOSITIONFORM form
;
3115 f
= x_window_to_frame (dpyinfo
, hwnd
);
3116 w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
3118 form
.dwStyle
= CFS_RECT
;
3119 form
.ptCurrentPos
.x
= w32_system_caret_x
;
3120 form
.ptCurrentPos
.y
= w32_system_caret_y
;
3122 form
.rcArea
.left
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, 0);
3124 #ifdef ENABLE_CHECKING
3125 /* Temporary code to catch crashes in computing form.rcArea.top. */
3126 eassert (FRAMEP (w
->frame
));
3127 eassert (BUFFERP (w
->contents
));
3129 int wmbp
= WINDOW_MENU_BAR_P (w
);
3130 int wtbp
= WINDOW_TOOL_BAR_P (w
);
3131 struct frame
*wf
= WINDOW_XFRAME (w
);
3132 int fibw
= FRAME_INTERNAL_BORDER_WIDTH (wf
);
3133 int wtel
= WINDOW_TOP_EDGE_LINE (w
);
3134 int wflh
= FRAME_LINE_HEIGHT (wf
);
3135 int wwhlp
= WINDOW_WANTS_HEADER_LINE_P (w
);
3136 int chlh
= CURRENT_HEADER_LINE_HEIGHT (w
);
3137 int whlh
= (wwhlp
? chlh
: 0);
3139 form
.rcArea
.top
= ((wmbp
|| wtbp
) ? 0 : fibw
) + wtel
* wflh
+ whlh
;
3142 form
.rcArea
.top
= (WINDOW_TOP_EDGE_Y (w
)
3143 + WINDOW_HEADER_LINE_HEIGHT (w
));
3145 form
.rcArea
.right
= (WINDOW_BOX_RIGHT_EDGE_X (w
)
3146 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
3147 - WINDOW_RIGHT_FRINGE_WIDTH (w
));
3148 form
.rcArea
.bottom
= (WINDOW_BOTTOM_EDGE_Y (w
)
3149 - WINDOW_MODE_LINE_HEIGHT (w
));
3151 context
= get_ime_context_fn (hwnd
);
3156 set_ime_composition_window_fn (context
, &form
);
3157 release_ime_context_fn (hwnd
, context
);
3161 case WM_IME_ENDCOMPOSITION
:
3162 ignore_ime_char
= 0;
3165 /* Simulate middle mouse button events when left and right buttons
3166 are used together, but only if user has two button mouse. */
3167 case WM_LBUTTONDOWN
:
3168 case WM_RBUTTONDOWN
:
3169 if (w32_num_mouse_buttons
> 2)
3170 goto handle_plain_button
;
3173 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
3174 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
3176 if (button_state
& this)
3179 if (button_state
== 0)
3182 button_state
|= this;
3184 if (button_state
& other
)
3186 if (mouse_button_timer
)
3188 KillTimer (hwnd
, mouse_button_timer
);
3189 mouse_button_timer
= 0;
3191 /* Generate middle mouse event instead. */
3192 msg
= WM_MBUTTONDOWN
;
3193 button_state
|= MMOUSE
;
3195 else if (button_state
& MMOUSE
)
3197 /* Ignore button event if we've already generated a
3198 middle mouse down event. This happens if the
3199 user releases and press one of the two buttons
3200 after we've faked a middle mouse event. */
3205 /* Flush out saved message. */
3206 post_msg (&saved_mouse_button_msg
);
3208 wmsg
.dwModifiers
= w32_get_modifiers ();
3209 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3210 signal_user_input ();
3212 /* Clear message buffer. */
3213 saved_mouse_button_msg
.msg
.hwnd
= 0;
3217 /* Hold onto message for now. */
3218 mouse_button_timer
=
3219 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
3220 w32_mouse_button_tolerance
, NULL
);
3221 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
3222 saved_mouse_button_msg
.msg
.message
= msg
;
3223 saved_mouse_button_msg
.msg
.wParam
= wParam
;
3224 saved_mouse_button_msg
.msg
.lParam
= lParam
;
3225 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
3226 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
3233 if (w32_num_mouse_buttons
> 2)
3234 goto handle_plain_button
;
3237 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
3238 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
3240 if ((button_state
& this) == 0)
3243 button_state
&= ~this;
3245 if (button_state
& MMOUSE
)
3247 /* Only generate event when second button is released. */
3248 if ((button_state
& other
) == 0)
3251 button_state
&= ~MMOUSE
;
3253 if (button_state
) emacs_abort ();
3260 /* Flush out saved message if necessary. */
3261 if (saved_mouse_button_msg
.msg
.hwnd
)
3263 post_msg (&saved_mouse_button_msg
);
3266 wmsg
.dwModifiers
= w32_get_modifiers ();
3267 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3268 signal_user_input ();
3270 /* Always clear message buffer and cancel timer. */
3271 saved_mouse_button_msg
.msg
.hwnd
= 0;
3272 KillTimer (hwnd
, mouse_button_timer
);
3273 mouse_button_timer
= 0;
3275 if (button_state
== 0)
3280 case WM_XBUTTONDOWN
:
3282 if (w32_pass_extra_mouse_buttons_to_system
)
3284 /* else fall through and process them. */
3285 case WM_MBUTTONDOWN
:
3287 handle_plain_button
:
3292 /* Ignore middle and extra buttons as long as the menu is active. */
3293 f
= x_window_to_frame (dpyinfo
, hwnd
);
3294 if (f
&& f
->output_data
.w32
->menubar_active
)
3297 if (parse_button (msg
, HIWORD (wParam
), &button
, &up
))
3299 if (up
) ReleaseCapture ();
3300 else SetCapture (hwnd
);
3301 button
= (button
== 0) ? LMOUSE
:
3302 ((button
== 1) ? MMOUSE
: RMOUSE
);
3304 button_state
&= ~button
;
3306 button_state
|= button
;
3310 wmsg
.dwModifiers
= w32_get_modifiers ();
3311 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3312 signal_user_input ();
3314 /* Need to return true for XBUTTON messages, false for others,
3315 to indicate that we processed the message. */
3316 return (msg
== WM_XBUTTONDOWN
|| msg
== WM_XBUTTONUP
);
3319 /* Ignore mouse movements as long as the menu is active. These
3320 movements are processed by the window manager anyway, and
3321 it's wrong to handle them as if they happened on the
3322 underlying frame. */
3323 f
= x_window_to_frame (dpyinfo
, hwnd
);
3324 if (f
&& f
->output_data
.w32
->menubar_active
)
3327 /* If the mouse has just moved into the frame, start tracking
3328 it, so we will be notified when it leaves the frame. Mouse
3329 tracking only works under W98 and NT4 and later. On earlier
3330 versions, there is no way of telling when the mouse leaves the
3331 frame, so we just have to put up with help-echo and mouse
3332 highlighting remaining while the frame is not active. */
3333 if (track_mouse_event_fn
&& !track_mouse_window
3334 /* If the menu bar is active, turning on tracking of mouse
3335 movement events might send these events to the tooltip
3336 frame, if the user happens to move the mouse pointer over
3337 the tooltip. But since we don't process events for
3338 tooltip frames, this causes Windows to present a
3339 hourglass cursor, which is ugly and unexpected. So don't
3340 enable tracking mouse events in this case; they will be
3341 restarted when the menu pops down. (Confusingly, the
3342 menubar_active member of f->output_data.w32, tested
3343 above, is only set when a menu was popped up _not_ from
3344 the frame's menu bar, but via x-popup-menu.) */
3347 TRACKMOUSEEVENT tme
;
3348 tme
.cbSize
= sizeof (tme
);
3349 tme
.dwFlags
= TME_LEAVE
;
3350 tme
.hwndTrack
= hwnd
;
3352 track_mouse_event_fn (&tme
);
3353 track_mouse_window
= hwnd
;
3356 if (w32_mouse_move_interval
<= 0
3357 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
3359 wmsg
.dwModifiers
= w32_get_modifiers ();
3360 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3364 /* Hang onto mouse move and scroll messages for a bit, to avoid
3365 sending such events to Emacs faster than it can process them.
3366 If we get more events before the timer from the first message
3367 expires, we just replace the first message. */
3369 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
3371 SetTimer (hwnd
, MOUSE_MOVE_ID
,
3372 w32_mouse_move_interval
, NULL
);
3374 /* Hold onto message for now. */
3375 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
3376 saved_mouse_move_msg
.msg
.message
= msg
;
3377 saved_mouse_move_msg
.msg
.wParam
= wParam
;
3378 saved_mouse_move_msg
.msg
.lParam
= lParam
;
3379 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
3380 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
3386 wmsg
.dwModifiers
= w32_get_modifiers ();
3387 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3388 signal_user_input ();
3392 if (w32_pass_multimedia_buttons_to_system
)
3394 /* Otherwise, pass to lisp, the same way we do with mousehwheel. */
3395 case WM_MOUSEHWHEEL
:
3396 wmsg
.dwModifiers
= w32_get_modifiers ();
3397 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3398 signal_user_input ();
3399 /* Non-zero must be returned when WM_MOUSEHWHEEL messages are
3400 handled, to prevent the system trying to handle it by faking
3401 scroll bar events. */
3405 /* Flush out saved messages if necessary. */
3406 if (wParam
== mouse_button_timer
)
3408 if (saved_mouse_button_msg
.msg
.hwnd
)
3410 post_msg (&saved_mouse_button_msg
);
3411 signal_user_input ();
3412 saved_mouse_button_msg
.msg
.hwnd
= 0;
3414 KillTimer (hwnd
, mouse_button_timer
);
3415 mouse_button_timer
= 0;
3417 else if (wParam
== mouse_move_timer
)
3419 if (saved_mouse_move_msg
.msg
.hwnd
)
3421 post_msg (&saved_mouse_move_msg
);
3422 saved_mouse_move_msg
.msg
.hwnd
= 0;
3424 KillTimer (hwnd
, mouse_move_timer
);
3425 mouse_move_timer
= 0;
3427 else if (wParam
== menu_free_timer
)
3429 KillTimer (hwnd
, menu_free_timer
);
3430 menu_free_timer
= 0;
3431 f
= x_window_to_frame (dpyinfo
, hwnd
);
3432 /* If a popup menu is active, don't wipe its strings. */
3434 && current_popup_menu
== NULL
)
3436 /* Free memory used by owner-drawn and help-echo strings. */
3437 w32_free_menu_strings (hwnd
);
3439 f
->output_data
.w32
->menubar_active
= 0;
3446 /* Windows doesn't send us focus messages when putting up and
3447 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
3448 The only indication we get that something happened is receiving
3449 this message afterwards. So this is a good time to reset our
3450 keyboard modifiers' state. */
3457 /* We must ensure menu bar is fully constructed and up to date
3458 before allowing user interaction with it. To achieve this
3459 we send this message to the lisp thread and wait for a
3460 reply (whose value is not actually needed) to indicate that
3461 the menu bar is now ready for use, so we can now return.
3463 To remain responsive in the meantime, we enter a nested message
3464 loop that can process all other messages.
3466 However, we skip all this if the message results from calling
3467 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
3468 thread a message because it is blocked on us at this point. We
3469 set menubar_active before calling TrackPopupMenu to indicate
3470 this (there is no possibility of confusion with real menubar
3473 f
= x_window_to_frame (dpyinfo
, hwnd
);
3475 && (f
->output_data
.w32
->menubar_active
3476 /* We can receive this message even in the absence of a
3477 menubar (ie. when the system menu is activated) - in this
3478 case we do NOT want to forward the message, otherwise it
3479 will cause the menubar to suddenly appear when the user
3480 had requested it to be turned off! */
3481 || f
->output_data
.w32
->menubar_widget
== NULL
))
3485 deferred_msg msg_buf
;
3487 /* Detect if message has already been deferred; in this case
3488 we cannot return any sensible value to ignore this. */
3489 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3494 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
3497 case WM_EXITMENULOOP
:
3498 f
= x_window_to_frame (dpyinfo
, hwnd
);
3500 /* If a menu is still active, check again after a short delay,
3501 since Windows often (always?) sends the WM_EXITMENULOOP
3502 before the corresponding WM_COMMAND message.
3503 Don't do this if a popup menu is active, since it is only
3504 menubar menus that require cleaning up in this way.
3506 if (f
&& menubar_in_use
&& current_popup_menu
== NULL
)
3507 menu_free_timer
= SetTimer (hwnd
, MENU_FREE_ID
, MENU_FREE_DELAY
, NULL
);
3509 /* If hourglass cursor should be displayed, display it now. */
3510 if (f
&& f
->output_data
.w32
->hourglass_p
)
3511 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
3516 /* Direct handling of help_echo in menus. Should be safe now
3517 that we generate the help_echo by placing a help event in the
3520 HMENU menu
= (HMENU
) lParam
;
3521 UINT menu_item
= (UINT
) LOWORD (wParam
);
3522 UINT flags
= (UINT
) HIWORD (wParam
);
3524 w32_menu_display_help (hwnd
, menu
, menu_item
, flags
);
3528 case WM_MEASUREITEM
:
3529 f
= x_window_to_frame (dpyinfo
, hwnd
);
3532 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
3534 if (pMis
->CtlType
== ODT_MENU
)
3536 /* Work out dimensions for popup menu titles. */
3537 char * title
= (char *) pMis
->itemData
;
3538 HDC hdc
= GetDC (hwnd
);
3539 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3540 LOGFONT menu_logfont
;
3544 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3545 menu_logfont
.lfWeight
= FW_BOLD
;
3546 menu_font
= CreateFontIndirect (&menu_logfont
);
3547 old_font
= SelectObject (hdc
, menu_font
);
3549 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
3552 if (unicode_append_menu
)
3553 GetTextExtentPoint32W (hdc
, (WCHAR
*) title
,
3554 wcslen ((WCHAR
*) title
),
3557 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
3559 pMis
->itemWidth
= size
.cx
;
3560 if (pMis
->itemHeight
< size
.cy
)
3561 pMis
->itemHeight
= size
.cy
;
3564 pMis
->itemWidth
= 0;
3566 SelectObject (hdc
, old_font
);
3567 DeleteObject (menu_font
);
3568 ReleaseDC (hwnd
, hdc
);
3575 f
= x_window_to_frame (dpyinfo
, hwnd
);
3578 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
3580 if (pDis
->CtlType
== ODT_MENU
)
3582 /* Draw popup menu title. */
3583 char * title
= (char *) pDis
->itemData
;
3586 HDC hdc
= pDis
->hDC
;
3587 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3588 LOGFONT menu_logfont
;
3591 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3592 menu_logfont
.lfWeight
= FW_BOLD
;
3593 menu_font
= CreateFontIndirect (&menu_logfont
);
3594 old_font
= SelectObject (hdc
, menu_font
);
3596 /* Always draw title as if not selected. */
3597 if (unicode_append_menu
)
3600 + GetSystemMetrics (SM_CXMENUCHECK
),
3602 ETO_OPAQUE
, &pDis
->rcItem
,
3604 wcslen ((WCHAR
*) title
), NULL
);
3608 + GetSystemMetrics (SM_CXMENUCHECK
),
3610 ETO_OPAQUE
, &pDis
->rcItem
,
3611 title
, strlen (title
), NULL
);
3613 SelectObject (hdc
, old_font
);
3614 DeleteObject (menu_font
);
3622 /* Still not right - can't distinguish between clicks in the
3623 client area of the frame from clicks forwarded from the scroll
3624 bars - may have to hook WM_NCHITTEST to remember the mouse
3625 position and then check if it is in the client area ourselves. */
3626 case WM_MOUSEACTIVATE
:
3627 /* Discard the mouse click that activates a frame, allowing the
3628 user to click anywhere without changing point (or worse!).
3629 Don't eat mouse clicks on scrollbars though!! */
3630 if (LOWORD (lParam
) == HTCLIENT
)
3631 return MA_ACTIVATEANDEAT
;
3636 /* No longer tracking mouse. */
3637 track_mouse_window
= NULL
;
3639 case WM_ACTIVATEAPP
:
3641 case WM_WINDOWPOSCHANGED
:
3643 /* Inform lisp thread that a frame might have just been obscured
3644 or exposed, so should recheck visibility of all frames. */
3645 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3649 dpyinfo
->faked_key
= 0;
3651 register_hot_keys (hwnd
);
3654 unregister_hot_keys (hwnd
);
3657 /* Relinquish the system caret. */
3658 if (w32_system_caret_hwnd
)
3660 w32_visible_system_caret_hwnd
= NULL
;
3661 w32_system_caret_hwnd
= NULL
;
3667 f
= x_window_to_frame (dpyinfo
, hwnd
);
3668 if (f
&& HIWORD (wParam
) == 0)
3670 if (menu_free_timer
)
3672 KillTimer (hwnd
, menu_free_timer
);
3673 menu_free_timer
= 0;
3679 wmsg
.dwModifiers
= w32_get_modifiers ();
3680 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3688 wmsg
.dwModifiers
= w32_get_modifiers ();
3689 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3692 case WM_WINDOWPOSCHANGING
:
3693 /* Don't restrict the sizing of tip frames. */
3694 if (hwnd
== tip_window
)
3698 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
3700 wp
.length
= sizeof (WINDOWPLACEMENT
);
3701 GetWindowPlacement (hwnd
, &wp
);
3703 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
3710 DWORD internal_border
;
3711 DWORD scrollbar_extra
;
3714 wp
.length
= sizeof (wp
);
3715 GetWindowRect (hwnd
, &wr
);
3719 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
3720 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
3721 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
3722 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
3726 memset (&rect
, 0, sizeof (rect
));
3727 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
3728 GetMenu (hwnd
) != NULL
);
3730 /* Force width and height of client area to be exact
3731 multiples of the character cell dimensions. */
3732 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
3733 - 2 * internal_border
- scrollbar_extra
)
3735 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
3736 - 2 * internal_border
)
3741 /* For right/bottom sizing we can just fix the sizes.
3742 However for top/left sizing we will need to fix the X
3743 and Y positions as well. */
3745 int cx_mintrack
= GetSystemMetrics (SM_CXMINTRACK
);
3746 int cy_mintrack
= GetSystemMetrics (SM_CYMINTRACK
);
3748 lppos
->cx
= max (lppos
->cx
- wdiff
, cx_mintrack
);
3749 lppos
->cy
= max (lppos
->cy
- hdiff
, cy_mintrack
);
3751 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
3752 && (lppos
->flags
& SWP_NOMOVE
) == 0)
3754 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
3761 lppos
->flags
|= SWP_NOMOVE
;
3772 case WM_GETMINMAXINFO
:
3773 /* Hack to allow resizing the Emacs frame above the screen size.
3774 Note that Windows 9x limits coordinates to 16-bits. */
3775 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.x
= 32767;
3776 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.y
= 32767;
3780 if (LOWORD (lParam
) == HTCLIENT
)
3782 f
= x_window_to_frame (dpyinfo
, hwnd
);
3783 if (f
&& f
->output_data
.w32
->hourglass_p
3784 && !menubar_in_use
&& !current_popup_menu
)
3785 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
3787 SetCursor (f
->output_data
.w32
->current_cursor
);
3792 case WM_EMACS_SETCURSOR
:
3794 Cursor cursor
= (Cursor
) wParam
;
3795 f
= x_window_to_frame (dpyinfo
, hwnd
);
3798 f
->output_data
.w32
->current_cursor
= cursor
;
3799 if (!f
->output_data
.w32
->hourglass_p
)
3805 case WM_EMACS_CREATESCROLLBAR
:
3806 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
3807 (struct scroll_bar
*) lParam
);
3809 case WM_EMACS_SHOWWINDOW
:
3810 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
3812 case WM_EMACS_BRINGTOTOP
:
3813 case WM_EMACS_SETFOREGROUND
:
3815 HWND foreground_window
;
3816 DWORD foreground_thread
, retval
;
3818 /* On NT 5.0, and apparently Windows 98, it is necessary to
3819 attach to the thread that currently has focus in order to
3820 pull the focus away from it. */
3821 foreground_window
= GetForegroundWindow ();
3822 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
3823 if (!foreground_window
3824 || foreground_thread
== GetCurrentThreadId ()
3825 || !AttachThreadInput (GetCurrentThreadId (),
3826 foreground_thread
, TRUE
))
3827 foreground_thread
= 0;
3829 retval
= SetForegroundWindow ((HWND
) wParam
);
3830 if (msg
== WM_EMACS_BRINGTOTOP
)
3831 retval
= BringWindowToTop ((HWND
) wParam
);
3833 /* Detach from the previous foreground thread. */
3834 if (foreground_thread
)
3835 AttachThreadInput (GetCurrentThreadId (),
3836 foreground_thread
, FALSE
);
3841 case WM_EMACS_SETWINDOWPOS
:
3843 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
3844 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
3845 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
3848 case WM_EMACS_DESTROYWINDOW
:
3849 DragAcceptFiles ((HWND
) wParam
, FALSE
);
3850 return DestroyWindow ((HWND
) wParam
);
3852 case WM_EMACS_HIDE_CARET
:
3853 return HideCaret (hwnd
);
3855 case WM_EMACS_SHOW_CARET
:
3856 return ShowCaret (hwnd
);
3858 case WM_EMACS_DESTROY_CARET
:
3859 w32_system_caret_hwnd
= NULL
;
3860 w32_visible_system_caret_hwnd
= NULL
;
3861 return DestroyCaret ();
3863 case WM_EMACS_TRACK_CARET
:
3864 /* If there is currently no system caret, create one. */
3865 if (w32_system_caret_hwnd
== NULL
)
3867 /* Use the default caret width, and avoid changing it
3868 unnecessarily, as it confuses screen reader software. */
3869 w32_system_caret_hwnd
= hwnd
;
3870 CreateCaret (hwnd
, NULL
, 0,
3871 w32_system_caret_height
);
3874 if (!SetCaretPos (w32_system_caret_x
, w32_system_caret_y
))
3876 /* Ensure visible caret gets turned on when requested. */
3877 else if (w32_use_visible_system_caret
3878 && w32_visible_system_caret_hwnd
!= hwnd
)
3880 w32_visible_system_caret_hwnd
= hwnd
;
3881 return ShowCaret (hwnd
);
3883 /* Ensure visible caret gets turned off when requested. */
3884 else if (!w32_use_visible_system_caret
3885 && w32_visible_system_caret_hwnd
)
3887 w32_visible_system_caret_hwnd
= NULL
;
3888 return HideCaret (hwnd
);
3893 case WM_EMACS_TRACKPOPUPMENU
:
3898 pos
= (POINT
*)lParam
;
3899 flags
= TPM_CENTERALIGN
;
3900 if (button_state
& LMOUSE
)
3901 flags
|= TPM_LEFTBUTTON
;
3902 else if (button_state
& RMOUSE
)
3903 flags
|= TPM_RIGHTBUTTON
;
3905 /* Remember we did a SetCapture on the initial mouse down event,
3906 so for safety, we make sure the capture is canceled now. */
3910 /* Use menubar_active to indicate that WM_INITMENU is from
3911 TrackPopupMenu below, and should be ignored. */
3912 f
= x_window_to_frame (dpyinfo
, hwnd
);
3914 f
->output_data
.w32
->menubar_active
= 1;
3916 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
3920 /* Eat any mouse messages during popupmenu */
3921 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
3923 /* Get the menu selection, if any */
3924 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
3926 retval
= LOWORD (amsg
.wParam
);
3940 case WM_EMACS_FILENOTIFY
:
3941 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3945 /* Check for messages registered at runtime. */
3946 if (msg
== msh_mousewheel
)
3948 wmsg
.dwModifiers
= w32_get_modifiers ();
3949 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3950 signal_user_input ();
3955 return (w32_unicode_gui
? DefWindowProcW
: DefWindowProcA
) (hwnd
, msg
, wParam
, lParam
);
3958 /* The most common default return code for handled messages is 0. */
3963 my_create_window (struct frame
* f
)
3967 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
3969 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
3973 /* Create a tooltip window. Unlike my_create_window, we do not do this
3974 indirectly via the Window thread, as we do not need to process Window
3975 messages for the tooltip. Creating tooltips indirectly also creates
3976 deadlocks when tooltips are created for menu items. */
3978 my_create_tip_window (struct frame
*f
)
3982 rect
.left
= rect
.top
= 0;
3983 rect
.right
= FRAME_PIXEL_WIDTH (f
);
3984 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
3986 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
3987 FRAME_EXTERNAL_MENU_BAR (f
));
3989 tip_window
= FRAME_W32_WINDOW (f
)
3990 = CreateWindow (EMACS_CLASS
,
3992 f
->output_data
.w32
->dwStyle
,
3995 rect
.right
- rect
.left
,
3996 rect
.bottom
- rect
.top
,
3997 FRAME_W32_WINDOW (SELECTED_FRAME ()), /* owner */
4004 SetWindowLong (tip_window
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
4005 SetWindowLong (tip_window
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
4006 SetWindowLong (tip_window
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
4007 SetWindowLong (tip_window
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
4009 /* Tip frames have no scrollbars. */
4010 SetWindowLong (tip_window
, WND_SCROLLBAR_INDEX
, 0);
4012 /* Do this to discard the default setting specified by our parent. */
4013 ShowWindow (tip_window
, SW_HIDE
);
4018 /* Create and set up the w32 window for frame F. */
4021 w32_window (struct frame
*f
, long window_prompting
, int minibuffer_only
)
4025 /* Use the resource name as the top-level window name
4026 for looking up resources. Make a non-Lisp copy
4027 for the window manager, so GC relocation won't bother it.
4029 Elsewhere we specify the window name for the window manager. */
4032 char *str
= SSDATA (Vx_resource_name
);
4033 f
->namebuf
= xmalloc (strlen (str
) + 1);
4034 strcpy (f
->namebuf
, str
);
4037 my_create_window (f
);
4039 validate_x_resource_name ();
4041 /* x_set_name normally ignores requests to set the name if the
4042 requested name is the same as the current name. This is the one
4043 place where that assumption isn't correct; f->name is set, but
4044 the server hasn't been told. */
4047 int explicit = f
->explicit_name
;
4049 f
->explicit_name
= 0;
4051 fset_name (f
, Qnil
);
4052 x_set_name (f
, name
, explicit);
4057 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
4058 initialize_frame_menubar (f
);
4060 if (FRAME_W32_WINDOW (f
) == 0)
4061 error ("Unable to create window");
4064 /* Handle the icon stuff for this window. Perhaps later we might
4065 want an x_set_icon_position which can be called interactively as
4069 x_icon (struct frame
*f
, Lisp_Object parms
)
4071 Lisp_Object icon_x
, icon_y
;
4072 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
4074 /* Set the position of the icon. Note that Windows 95 groups all
4075 icons in the tray. */
4076 icon_x
= x_get_arg (dpyinfo
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
4077 icon_y
= x_get_arg (dpyinfo
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
4078 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
4080 CHECK_NUMBER (icon_x
);
4081 CHECK_NUMBER (icon_y
);
4083 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
4084 error ("Both left and top icon corners of icon must be specified");
4088 if (! EQ (icon_x
, Qunbound
))
4089 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
4092 /* Start up iconic or window? */
4093 x_wm_set_window_state
4094 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
4098 x_text_icon (f
, SSDATA ((!NILP (f
->icon_name
)
4108 x_make_gc (struct frame
*f
)
4110 XGCValues gc_values
;
4114 /* Create the GC's of this frame.
4115 Note that many default values are used. */
4118 gc_values
.font
= FRAME_FONT (f
);
4120 /* Cursor has cursor-color background, background-color foreground. */
4121 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
4122 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
4123 f
->output_data
.w32
->cursor_gc
4124 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
4125 (GCFont
| GCForeground
| GCBackground
),
4129 f
->output_data
.w32
->white_relief
.gc
= 0;
4130 f
->output_data
.w32
->black_relief
.gc
= 0;
4136 /* Handler for signals raised during x_create_frame and
4137 x_create_tip_frame. FRAME is the frame which is partially
4141 unwind_create_frame (Lisp_Object frame
)
4143 struct frame
*f
= XFRAME (frame
);
4145 /* If frame is ``official'', nothing to do. */
4146 if (NILP (Fmemq (frame
, Vframe_list
)))
4149 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4152 x_free_frame_resources (f
);
4156 /* Check that reference counts are indeed correct. */
4157 eassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
4158 eassert (dpyinfo
->terminal
->image_cache
->refcount
== image_cache_refcount
);
4167 x_default_font_parameter (struct frame
*f
, Lisp_Object parms
)
4169 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4170 Lisp_Object font_param
= x_get_arg (dpyinfo
, parms
, Qfont
, NULL
, NULL
,
4173 if (EQ (font_param
, Qunbound
))
4175 font
= !NILP (font_param
) ? font_param
4176 : x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4178 if (!STRINGP (font
))
4181 static char *names
[]
4182 = { "Courier New-10",
4183 "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1",
4184 "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1",
4188 for (i
= 0; names
[i
]; i
++)
4190 font
= font_open_by_name (f
, build_unibyte_string (names
[i
]));
4195 error ("No suitable font was found");
4197 else if (!NILP (font_param
))
4199 /* Remember the explicit font parameter, so we can re-apply it after
4200 we've applied the `default' face settings. */
4201 x_set_frame_parameters (f
, Fcons (Fcons (Qfont_param
, font_param
), Qnil
));
4203 x_default_parameter (f
, parms
, Qfont
, font
, "font", "Font", RES_TYPE_STRING
);
4206 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
4208 doc
: /* Make a new window, which is called a \"frame\" in Emacs terms.
4209 Return an Emacs frame object.
4210 PARAMETERS is an alist of frame parameters.
4211 If the parameters specify that the frame should not have a minibuffer,
4212 and do not specify a specific minibuffer window to use,
4213 then `default-minibuffer-frame' must be a frame whose minibuffer can
4214 be shared by the new frame.
4216 This function is an internal primitive--use `make-frame' instead. */)
4217 (Lisp_Object parameters
)
4220 Lisp_Object frame
, tem
;
4222 int minibuffer_only
= 0;
4223 long window_prompting
= 0;
4225 ptrdiff_t count
= SPECPDL_INDEX ();
4226 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4227 Lisp_Object display
;
4228 struct w32_display_info
*dpyinfo
= NULL
;
4232 /* Make copy of frame parameters because the original is in pure
4234 parameters
= Fcopy_alist (parameters
);
4236 /* Use this general default value to start with
4237 until we know if this frame has a specified name. */
4238 Vx_resource_name
= Vinvocation_name
;
4240 display
= x_get_arg (dpyinfo
, parameters
, Qterminal
, 0, 0, RES_TYPE_NUMBER
);
4241 if (EQ (display
, Qunbound
))
4242 display
= x_get_arg (dpyinfo
, parameters
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
4243 if (EQ (display
, Qunbound
))
4245 dpyinfo
= check_x_display_info (display
);
4246 kb
= dpyinfo
->terminal
->kboard
;
4248 if (!dpyinfo
->terminal
->name
)
4249 error ("Terminal is not live, can't create new frames on it");
4251 name
= x_get_arg (dpyinfo
, parameters
, Qname
, "name", "Name", RES_TYPE_STRING
);
4253 && ! EQ (name
, Qunbound
)
4255 error ("Invalid frame name--not a string or nil");
4258 Vx_resource_name
= name
;
4260 /* See if parent window is specified. */
4261 parent
= x_get_arg (dpyinfo
, parameters
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
4262 if (EQ (parent
, Qunbound
))
4264 if (! NILP (parent
))
4265 CHECK_NUMBER (parent
);
4267 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
4268 /* No need to protect DISPLAY because that's not used after passing
4269 it to make_frame_without_minibuffer. */
4271 GCPRO4 (parameters
, parent
, name
, frame
);
4272 tem
= x_get_arg (dpyinfo
, parameters
, Qminibuffer
, "minibuffer", "Minibuffer",
4274 if (EQ (tem
, Qnone
) || NILP (tem
))
4275 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
4276 else if (EQ (tem
, Qonly
))
4278 f
= make_minibuffer_frame ();
4279 minibuffer_only
= 1;
4281 else if (WINDOWP (tem
))
4282 f
= make_frame_without_minibuffer (tem
, kb
, display
);
4286 XSETFRAME (frame
, f
);
4288 /* By default, make scrollbars the system standard width. */
4289 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
4291 f
->terminal
= dpyinfo
->terminal
;
4293 f
->output_method
= output_w32
;
4294 f
->output_data
.w32
= xzalloc (sizeof (struct w32_output
));
4295 FRAME_FONTSET (f
) = -1;
4298 (f
, x_get_arg (dpyinfo
, parameters
, Qicon_name
, "iconName", "Title",
4300 if (! STRINGP (f
->icon_name
))
4301 fset_icon_name (f
, Qnil
);
4303 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
4305 /* With FRAME_X_DISPLAY_INFO set up, this unwind-protect is safe. */
4306 record_unwind_protect (unwind_create_frame
, frame
);
4308 image_cache_refcount
=
4309 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
4310 dpyinfo_refcount
= dpyinfo
->reference_count
;
4311 #endif /* GLYPH_DEBUG */
4313 /* Specify the parent under which to make this window. */
4317 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
4318 f
->output_data
.w32
->explicit_parent
= 1;
4322 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4323 f
->output_data
.w32
->explicit_parent
= 0;
4326 /* Set the name; the functions to which we pass f expect the name to
4328 if (EQ (name
, Qunbound
) || NILP (name
))
4330 fset_name (f
, build_string (dpyinfo
->w32_id_name
));
4331 f
->explicit_name
= 0;
4335 fset_name (f
, name
);
4336 f
->explicit_name
= 1;
4337 /* use the frame's title when getting resources for this frame. */
4338 specbind (Qx_resource_name
, name
);
4341 if (uniscribe_available
)
4342 register_font_driver (&uniscribe_font_driver
, f
);
4343 register_font_driver (&w32font_driver
, f
);
4345 x_default_parameter (f
, parameters
, Qfont_backend
, Qnil
,
4346 "fontBackend", "FontBackend", RES_TYPE_STRING
);
4347 /* Extract the window parameters from the supplied values
4348 that are needed to determine window geometry. */
4349 x_default_font_parameter (f
, parameters
);
4350 x_default_parameter (f
, parameters
, Qborder_width
, make_number (2),
4351 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4353 /* We recognize either internalBorderWidth or internalBorder
4354 (which is what xterm calls it). */
4355 if (NILP (Fassq (Qinternal_border_width
, parameters
)))
4359 value
= x_get_arg (dpyinfo
, parameters
, Qinternal_border_width
,
4360 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
4361 if (! EQ (value
, Qunbound
))
4362 parameters
= Fcons (Fcons (Qinternal_border_width
, value
),
4365 /* Default internalBorderWidth to 0 on Windows to match other programs. */
4366 x_default_parameter (f
, parameters
, Qinternal_border_width
, make_number (0),
4367 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
4368 x_default_parameter (f
, parameters
, Qvertical_scroll_bars
, Qright
,
4369 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
4371 /* Also do the stuff which must be set before the window exists. */
4372 x_default_parameter (f
, parameters
, Qforeground_color
, build_string ("black"),
4373 "foreground", "Foreground", RES_TYPE_STRING
);
4374 x_default_parameter (f
, parameters
, Qbackground_color
, build_string ("white"),
4375 "background", "Background", RES_TYPE_STRING
);
4376 x_default_parameter (f
, parameters
, Qmouse_color
, build_string ("black"),
4377 "pointerColor", "Foreground", RES_TYPE_STRING
);
4378 x_default_parameter (f
, parameters
, Qborder_color
, build_string ("black"),
4379 "borderColor", "BorderColor", RES_TYPE_STRING
);
4380 x_default_parameter (f
, parameters
, Qscreen_gamma
, Qnil
,
4381 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
4382 x_default_parameter (f
, parameters
, Qline_spacing
, Qnil
,
4383 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
4384 x_default_parameter (f
, parameters
, Qleft_fringe
, Qnil
,
4385 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
4386 x_default_parameter (f
, parameters
, Qright_fringe
, Qnil
,
4387 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
4389 /* Init faces before x_default_parameter is called for scroll-bar
4390 parameters because that function calls x_set_scroll_bar_width,
4391 which calls change_frame_size, which calls Fset_window_buffer,
4392 which runs hooks, which call Fvertical_motion. At the end, we
4393 end up in init_iterator with a null face cache, which should not
4395 init_frame_faces (f
);
4397 /* The X resources controlling the menu-bar and tool-bar are
4398 processed specially at startup, and reflected in the mode
4399 variables; ignore them here. */
4400 x_default_parameter (f
, parameters
, Qmenu_bar_lines
,
4401 NILP (Vmenu_bar_mode
)
4402 ? make_number (0) : make_number (1),
4403 NULL
, NULL
, RES_TYPE_NUMBER
);
4404 x_default_parameter (f
, parameters
, Qtool_bar_lines
,
4405 NILP (Vtool_bar_mode
)
4406 ? make_number (0) : make_number (1),
4407 NULL
, NULL
, RES_TYPE_NUMBER
);
4409 x_default_parameter (f
, parameters
, Qbuffer_predicate
, Qnil
,
4410 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
4411 x_default_parameter (f
, parameters
, Qtitle
, Qnil
,
4412 "title", "Title", RES_TYPE_STRING
);
4413 x_default_parameter (f
, parameters
, Qfullscreen
, Qnil
,
4414 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
4416 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
4417 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4419 f
->output_data
.w32
->text_cursor
= w32_load_cursor (IDC_IBEAM
);
4420 f
->output_data
.w32
->nontext_cursor
= w32_load_cursor (IDC_ARROW
);
4421 f
->output_data
.w32
->modeline_cursor
= w32_load_cursor (IDC_ARROW
);
4422 f
->output_data
.w32
->hand_cursor
= w32_load_cursor (IDC_HAND
);
4423 f
->output_data
.w32
->hourglass_cursor
= w32_load_cursor (IDC_WAIT
);
4424 f
->output_data
.w32
->horizontal_drag_cursor
= w32_load_cursor (IDC_SIZEWE
);
4426 f
->output_data
.w32
->current_cursor
= f
->output_data
.w32
->nontext_cursor
;
4428 window_prompting
= x_figure_window_size (f
, parameters
, 1);
4430 tem
= x_get_arg (dpyinfo
, parameters
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
4431 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
4433 w32_window (f
, window_prompting
, minibuffer_only
);
4434 x_icon (f
, parameters
);
4438 /* Now consider the frame official. */
4439 f
->terminal
->reference_count
++;
4440 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
4441 Vframe_list
= Fcons (frame
, Vframe_list
);
4443 /* We need to do this after creating the window, so that the
4444 icon-creation functions can say whose icon they're describing. */
4445 x_default_parameter (f
, parameters
, Qicon_type
, Qnil
,
4446 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
4448 x_default_parameter (f
, parameters
, Qauto_raise
, Qnil
,
4449 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4450 x_default_parameter (f
, parameters
, Qauto_lower
, Qnil
,
4451 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4452 x_default_parameter (f
, parameters
, Qcursor_type
, Qbox
,
4453 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4454 x_default_parameter (f
, parameters
, Qscroll_bar_width
, Qnil
,
4455 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
4456 x_default_parameter (f
, parameters
, Qalpha
, Qnil
,
4457 "alpha", "Alpha", RES_TYPE_NUMBER
);
4459 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4460 Change will not be effected unless different from the current
4462 width
= FRAME_COLS (f
);
4463 height
= FRAME_LINES (f
);
4465 FRAME_LINES (f
) = 0;
4466 SET_FRAME_COLS (f
, 0);
4467 change_frame_size (f
, height
, width
, 1, 0, 0);
4469 /* Tell the server what size and position, etc, we want, and how
4470 badly we want them. This should be done after we have the menu
4471 bar so that its size can be taken into account. */
4473 x_wm_set_size_hint (f
, window_prompting
, 0);
4476 /* Make the window appear on the frame and enable display, unless
4477 the caller says not to. However, with explicit parent, Emacs
4478 cannot control visibility, so don't try. */
4479 if (! f
->output_data
.w32
->explicit_parent
)
4481 Lisp_Object visibility
;
4483 visibility
= x_get_arg (dpyinfo
, parameters
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
4484 if (EQ (visibility
, Qunbound
))
4487 if (EQ (visibility
, Qicon
))
4488 x_iconify_frame (f
);
4489 else if (! NILP (visibility
))
4490 x_make_frame_visible (f
);
4492 /* Must have been Qnil. */
4496 /* Initialize `default-minibuffer-frame' in case this is the first
4497 frame on this terminal. */
4498 if (FRAME_HAS_MINIBUF_P (f
)
4499 && (!FRAMEP (KVAR (kb
, Vdefault_minibuffer_frame
))
4500 || !FRAME_LIVE_P (XFRAME (KVAR (kb
, Vdefault_minibuffer_frame
)))))
4501 kset_default_minibuffer_frame (kb
, frame
);
4503 /* All remaining specified parameters, which have not been "used"
4504 by x_get_arg and friends, now go in the misc. alist of the frame. */
4505 for (tem
= parameters
; CONSP (tem
); tem
= XCDR (tem
))
4506 if (CONSP (XCAR (tem
)) && !NILP (XCAR (XCAR (tem
))))
4507 fset_param_alist (f
, Fcons (XCAR (tem
), f
->param_alist
));
4511 /* Make sure windows on this frame appear in calls to next-window
4512 and similar functions. */
4513 Vwindow_list
= Qnil
;
4515 return unbind_to (count
, frame
);
4518 /* FRAME is used only to get a handle on the X display. We don't pass the
4519 display info directly because we're called from frame.c, which doesn't
4520 know about that structure. */
4522 x_get_focus_frame (struct frame
*frame
)
4524 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
4526 if (! dpyinfo
->w32_focus_frame
)
4529 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
4533 DEFUN ("x-focus-frame", Fx_focus_frame
, Sx_focus_frame
, 1, 1, 0,
4534 doc
: /* Give FRAME input focus, raising to foreground if necessary. */)
4537 x_focus_on_frame (decode_window_system_frame (frame
));
4542 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
4543 doc
: /* Internal function called by `color-defined-p', which see.
4544 \(Note that the Nextstep version of this function ignores FRAME.) */)
4545 (Lisp_Object color
, Lisp_Object frame
)
4548 FRAME_PTR f
= decode_window_system_frame (frame
);
4550 CHECK_STRING (color
);
4552 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
4558 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
4559 doc
: /* Internal function called by `color-values', which see. */)
4560 (Lisp_Object color
, Lisp_Object frame
)
4563 FRAME_PTR f
= decode_window_system_frame (frame
);
4565 CHECK_STRING (color
);
4567 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
4568 return list3i ((GetRValue (foo
.pixel
) << 8) | GetRValue (foo
.pixel
),
4569 (GetGValue (foo
.pixel
) << 8) | GetGValue (foo
.pixel
),
4570 (GetBValue (foo
.pixel
) << 8) | GetBValue (foo
.pixel
));
4575 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
4576 doc
: /* Internal function called by `display-color-p', which see. */)
4577 (Lisp_Object display
)
4579 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4581 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
4587 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
,
4588 Sx_display_grayscale_p
, 0, 1, 0,
4589 doc
: /* Return t if DISPLAY supports shades of gray.
4590 Note that color displays do support shades of gray.
4591 The optional argument DISPLAY specifies which display to ask about.
4592 DISPLAY should be either a frame or a display name (a string).
4593 If omitted or nil, that stands for the selected frame's display. */)
4594 (Lisp_Object display
)
4596 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4598 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
4604 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
,
4605 Sx_display_pixel_width
, 0, 1, 0,
4606 doc
: /* Return the width in pixels of DISPLAY.
4607 The optional argument DISPLAY specifies which display to ask about.
4608 DISPLAY should be either a frame or a display name (a string).
4609 If omitted or nil, that stands for the selected frame's display. */)
4610 (Lisp_Object display
)
4612 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4614 return make_number (x_display_pixel_width (dpyinfo
));
4617 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
4618 Sx_display_pixel_height
, 0, 1, 0,
4619 doc
: /* Return the height in pixels of DISPLAY.
4620 The optional argument DISPLAY specifies which display to ask about.
4621 DISPLAY should be either a frame or a display name (a string).
4622 If omitted or nil, that stands for the selected frame's display. */)
4623 (Lisp_Object display
)
4625 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4627 return make_number (x_display_pixel_height (dpyinfo
));
4630 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
4632 doc
: /* Return the number of bitplanes of DISPLAY.
4633 The optional argument DISPLAY specifies which display to ask about.
4634 DISPLAY should be either a frame or a display name (a string).
4635 If omitted or nil, that stands for the selected frame's display. */)
4636 (Lisp_Object display
)
4638 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4640 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
4643 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
4645 doc
: /* Return the number of color cells of DISPLAY.
4646 The optional argument DISPLAY specifies which display to ask about.
4647 DISPLAY should be either a frame or a display name (a string).
4648 If omitted or nil, that stands for the selected frame's display. */)
4649 (Lisp_Object display
)
4651 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4654 /* Don't use NCOLORS: it returns incorrect results under remote
4655 * desktop. We force 24+ bit depths to 24-bit, both to prevent an
4656 * overflow and because probably is more meaningful on Windows
4659 cap
= 1 << min (dpyinfo
->n_planes
* dpyinfo
->n_cbits
, 24);
4660 return make_number (cap
);
4663 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
4664 Sx_server_max_request_size
,
4666 doc
: /* Return the maximum request size of the server of DISPLAY.
4667 The optional argument DISPLAY specifies which display to ask about.
4668 DISPLAY should be either a frame or a display name (a string).
4669 If omitted or nil, that stands for the selected frame's display. */)
4670 (Lisp_Object display
)
4672 return make_number (1);
4675 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
4676 doc
: /* Return the "vendor ID" string of the W32 system (Microsoft).
4677 The optional argument DISPLAY specifies which display to ask about.
4678 DISPLAY should be either a frame or a display name (a string).
4679 If omitted or nil, that stands for the selected frame's display. */)
4680 (Lisp_Object display
)
4682 return build_string ("Microsoft Corp.");
4685 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
4686 doc
: /* Return the version numbers of the server of DISPLAY.
4687 The value is a list of three integers: the major and minor
4688 version numbers of the X Protocol in use, and the distributor-specific
4689 release number. See also the function `x-server-vendor'.
4691 The optional argument DISPLAY specifies which display to ask about.
4692 DISPLAY should be either a frame or a display name (a string).
4693 If omitted or nil, that stands for the selected frame's display. */)
4694 (Lisp_Object display
)
4696 return list3i (w32_major_version
, w32_minor_version
, w32_build_number
);
4699 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
4700 doc
: /* Return the number of screens on the server of DISPLAY.
4701 The optional argument DISPLAY specifies which display to ask about.
4702 DISPLAY should be either a frame or a display name (a string).
4703 If omitted or nil, that stands for the selected frame's display. */)
4704 (Lisp_Object display
)
4706 return make_number (1);
4709 DEFUN ("x-display-mm-height", Fx_display_mm_height
,
4710 Sx_display_mm_height
, 0, 1, 0,
4711 doc
: /* Return the height in millimeters of DISPLAY.
4712 The optional argument DISPLAY specifies which display to ask about.
4713 DISPLAY should be either a frame or a display name (a string).
4714 If omitted or nil, that stands for the selected frame's display. */)
4715 (Lisp_Object display
)
4717 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4721 hdc
= GetDC (dpyinfo
->root_window
);
4723 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
4725 ReleaseDC (dpyinfo
->root_window
, hdc
);
4727 return make_number (cap
);
4730 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
4731 doc
: /* Return the width in millimeters of DISPLAY.
4732 The optional argument DISPLAY specifies which display to ask about.
4733 DISPLAY should be either a frame or a display name (a string).
4734 If omitted or nil, that stands for the selected frame's display. */)
4735 (Lisp_Object display
)
4737 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4742 hdc
= GetDC (dpyinfo
->root_window
);
4744 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
4746 ReleaseDC (dpyinfo
->root_window
, hdc
);
4748 return make_number (cap
);
4751 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
4752 Sx_display_backing_store
, 0, 1, 0,
4753 doc
: /* Return an indication of whether DISPLAY does backing store.
4754 The value may be `always', `when-mapped', or `not-useful'.
4755 The optional argument DISPLAY specifies which display to ask about.
4756 DISPLAY should be either a frame or a display name (a string).
4757 If omitted or nil, that stands for the selected frame's display. */)
4758 (Lisp_Object display
)
4760 return intern ("not-useful");
4763 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
4764 Sx_display_visual_class
, 0, 1, 0,
4765 doc
: /* Return the visual class of DISPLAY.
4766 The value is one of the symbols `static-gray', `gray-scale',
4767 `static-color', `pseudo-color', `true-color', or `direct-color'.
4769 The optional argument DISPLAY specifies which display to ask about.
4770 DISPLAY should be either a frame or a display name (a string).
4771 If omitted or nil, that stands for the selected frame's display. */)
4772 (Lisp_Object display
)
4774 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4775 Lisp_Object result
= Qnil
;
4777 if (dpyinfo
->has_palette
)
4778 result
= intern ("pseudo-color");
4779 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
4780 result
= intern ("static-grey");
4781 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
4782 result
= intern ("static-color");
4783 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
4784 result
= intern ("true-color");
4789 DEFUN ("x-display-save-under", Fx_display_save_under
,
4790 Sx_display_save_under
, 0, 1, 0,
4791 doc
: /* Return t if DISPLAY supports the save-under feature.
4792 The optional argument DISPLAY specifies which display to ask about.
4793 DISPLAY should be either a frame or a display name (a string).
4794 If omitted or nil, that stands for the selected frame's display. */)
4795 (Lisp_Object display
)
4800 DEFUN ("set-message-beep", Fset_message_beep
, Sset_message_beep
, 1, 1, 0,
4801 doc
: /* Set the sound generated when the bell is rung.
4802 SOUND is 'asterisk, 'exclamation, 'hand, 'question, 'ok, or 'silent
4803 to use the corresponding system sound for the bell. The 'silent sound
4804 prevents Emacs from making any sound at all.
4805 SOUND is nil to use the normal beep. */)
4808 CHECK_SYMBOL (sound
);
4811 sound_type
= 0xFFFFFFFF;
4812 else if (EQ (sound
, intern ("asterisk")))
4813 sound_type
= MB_ICONASTERISK
;
4814 else if (EQ (sound
, intern ("exclamation")))
4815 sound_type
= MB_ICONEXCLAMATION
;
4816 else if (EQ (sound
, intern ("hand")))
4817 sound_type
= MB_ICONHAND
;
4818 else if (EQ (sound
, intern ("question")))
4819 sound_type
= MB_ICONQUESTION
;
4820 else if (EQ (sound
, intern ("ok")))
4822 else if (EQ (sound
, intern ("silent")))
4823 sound_type
= MB_EMACS_SILENT
;
4825 sound_type
= 0xFFFFFFFF;
4832 x_pixel_width (register struct frame
*f
)
4834 return FRAME_PIXEL_WIDTH (f
);
4838 x_pixel_height (register struct frame
*f
)
4840 return FRAME_PIXEL_HEIGHT (f
);
4844 x_screen_planes (register struct frame
*f
)
4846 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
4849 /* Return the display structure for the display named NAME.
4850 Open a new connection if necessary. */
4852 struct w32_display_info
*
4853 x_display_info_for_name (Lisp_Object name
)
4856 struct w32_display_info
*dpyinfo
;
4858 CHECK_STRING (name
);
4860 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
4861 dpyinfo
&& !NILP (w32_display_name_list
);
4862 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
4865 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
4870 /* Use this general default value to start with. */
4871 Vx_resource_name
= Vinvocation_name
;
4873 validate_x_resource_name ();
4875 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
4876 SSDATA (Vx_resource_name
));
4879 error ("Cannot connect to server %s", SDATA (name
));
4881 XSETFASTINT (Vwindow_system_version
, w32_major_version
);
4886 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
4887 1, 3, 0, doc
: /* Open a connection to a display server.
4888 DISPLAY is the name of the display to connect to.
4889 Optional second arg XRM-STRING is a string of resources in xrdb format.
4890 If the optional third arg MUST-SUCCEED is non-nil,
4891 terminate Emacs if we can't open the connection.
4892 \(In the Nextstep version, the last two arguments are currently ignored.) */)
4893 (Lisp_Object display
, Lisp_Object xrm_string
, Lisp_Object must_succeed
)
4895 unsigned char *xrm_option
;
4896 struct w32_display_info
*dpyinfo
;
4898 CHECK_STRING (display
);
4900 /* Signal an error in order to encourage correct use from callers.
4901 * If we ever support multiple window systems in the same Emacs,
4902 * we'll need callers to be precise about what window system they
4905 if (strcmp (SSDATA (display
), "w32") != 0)
4906 error ("The name of the display in this Emacs must be \"w32\"");
4908 /* If initialization has already been done, return now to avoid
4909 overwriting critical parts of one_w32_display_info. */
4910 if (window_system_available (NULL
))
4913 if (! NILP (xrm_string
))
4914 CHECK_STRING (xrm_string
);
4917 if (! EQ (Vwindow_system
, intern ("w32")))
4918 error ("Not using Microsoft Windows");
4921 /* Allow color mapping to be defined externally; first look in user's
4922 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
4924 Lisp_Object color_file
;
4925 struct gcpro gcpro1
;
4927 color_file
= build_string ("~/rgb.txt");
4929 GCPRO1 (color_file
);
4931 if (NILP (Ffile_readable_p (color_file
)))
4933 Fexpand_file_name (build_string ("rgb.txt"),
4934 Fsymbol_value (intern ("data-directory")));
4936 Vw32_color_map
= Fx_load_color_file (color_file
);
4940 if (NILP (Vw32_color_map
))
4941 Vw32_color_map
= w32_default_color_map ();
4943 /* Merge in system logical colors. */
4944 add_system_logical_colors_to_map (&Vw32_color_map
);
4946 if (! NILP (xrm_string
))
4947 xrm_option
= SDATA (xrm_string
);
4949 xrm_option
= (unsigned char *) 0;
4951 /* Use this general default value to start with. */
4952 /* First remove .exe suffix from invocation-name - it looks ugly. */
4954 char basename
[ MAX_PATH
], *str
;
4956 strcpy (basename
, SDATA (Vinvocation_name
));
4957 str
= strrchr (basename
, '.');
4959 Vinvocation_name
= build_string (basename
);
4961 Vx_resource_name
= Vinvocation_name
;
4963 validate_x_resource_name ();
4965 /* This is what opens the connection and sets x_current_display.
4966 This also initializes many symbols, such as those used for input. */
4967 dpyinfo
= w32_term_init (display
, xrm_option
,
4968 SSDATA (Vx_resource_name
));
4972 if (!NILP (must_succeed
))
4973 fatal ("Cannot connect to server %s.\n",
4976 error ("Cannot connect to server %s", SDATA (display
));
4979 XSETFASTINT (Vwindow_system_version
, w32_major_version
);
4983 DEFUN ("x-close-connection", Fx_close_connection
,
4984 Sx_close_connection
, 1, 1, 0,
4985 doc
: /* Close the connection to DISPLAY's server.
4986 For DISPLAY, specify either a frame or a display name (a string).
4987 If DISPLAY is nil, that stands for the selected frame's display. */)
4988 (Lisp_Object display
)
4990 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4992 if (dpyinfo
->reference_count
> 0)
4993 error ("Display still has frames on it");
4996 x_destroy_all_bitmaps (dpyinfo
);
4998 x_delete_display (dpyinfo
);
5004 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
5005 doc
: /* Return the list of display names that Emacs has connections to. */)
5008 Lisp_Object tail
, result
;
5011 for (tail
= w32_display_name_list
; CONSP (tail
); tail
= XCDR (tail
))
5012 result
= Fcons (XCAR (XCAR (tail
)), result
);
5017 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
5018 doc
: /* If ON is non-nil, report X errors as soon as the erring request is made.
5019 This function only has an effect on X Windows. With MS Windows, it is
5020 defined but does nothing.
5022 If ON is nil, allow buffering of requests.
5023 Turning on synchronization prohibits the Xlib routines from buffering
5024 requests and seriously degrades performance, but makes debugging much
5026 The optional second argument TERMINAL specifies which display to act on.
5027 TERMINAL should be a terminal object, a frame or a display name (a string).
5028 If TERMINAL is omitted or nil, that stands for the selected frame's display. */)
5029 (Lisp_Object on
, Lisp_Object display
)
5036 /***********************************************************************
5038 ***********************************************************************/
5040 #if 0 /* TODO : port window properties to W32 */
5042 DEFUN ("x-change-window-property", Fx_change_window_property
,
5043 Sx_change_window_property
, 2, 6, 0,
5044 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
5045 PROP must be a string. VALUE may be a string or a list of conses,
5046 numbers and/or strings. If an element in the list is a string, it is
5047 converted to an atom and the value of the Atom is used. If an element
5048 is a cons, it is converted to a 32 bit number where the car is the 16
5049 top bits and the cdr is the lower 16 bits.
5051 FRAME nil or omitted means use the selected frame.
5052 If TYPE is given and non-nil, it is the name of the type of VALUE.
5053 If TYPE is not given or nil, the type is STRING.
5054 FORMAT gives the size in bits of each element if VALUE is a list.
5055 It must be one of 8, 16 or 32.
5056 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
5057 If OUTER-P is non-nil, the property is changed for the outer X window of
5058 FRAME. Default is to change on the edit X window. */)
5059 (Lisp_Object prop
, Lisp_Object value
, Lisp_Object frame
,
5060 Lisp_Object type
, Lisp_Object format
, Lisp_Object outer_p
)
5062 struct frame
*f
= decode_window_system_frame (frame
);
5065 CHECK_STRING (prop
);
5066 CHECK_STRING (value
);
5069 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5070 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5071 prop_atom
, XA_STRING
, 8, PropModeReplace
,
5072 SDATA (value
), SCHARS (value
));
5074 /* Make sure the property is set when we return. */
5075 XFlush (FRAME_W32_DISPLAY (f
));
5082 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
5083 Sx_delete_window_property
, 1, 2, 0,
5084 doc
: /* Remove window property PROP from X window of FRAME.
5085 FRAME nil or omitted means use the selected frame. Value is PROP. */)
5086 (Lisp_Object prop
, Lisp_Object frame
)
5088 struct frame
*f
= decode_window_system_frame (frame
);
5091 CHECK_STRING (prop
);
5093 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5094 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
5096 /* Make sure the property is removed when we return. */
5097 XFlush (FRAME_W32_DISPLAY (f
));
5104 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
5106 doc
: /* Value is the value of window property PROP on FRAME.
5107 If FRAME is nil or omitted, use the selected frame.
5109 On X Windows, the following optional arguments are also accepted:
5110 If TYPE is nil or omitted, get the property as a string.
5111 Otherwise TYPE is the name of the atom that denotes the type expected.
5112 If SOURCE is non-nil, get the property on that window instead of from
5113 FRAME. The number 0 denotes the root window.
5114 If DELETE-P is non-nil, delete the property after retrieving it.
5115 If VECTOR-RET-P is non-nil, don't return a string but a vector of values.
5117 On MS Windows, this function accepts but ignores those optional arguments.
5119 Value is nil if FRAME hasn't a property with name PROP or if PROP has
5120 no value of TYPE (always string in the MS Windows case). */)
5121 (Lisp_Object prop
, Lisp_Object frame
, Lisp_Object type
,
5122 Lisp_Object source
, Lisp_Object delete_p
, Lisp_Object vector_ret_p
)
5124 struct frame
*f
= decode_window_system_frame (frame
);
5127 Lisp_Object prop_value
= Qnil
;
5128 char *tmp_data
= NULL
;
5131 unsigned long actual_size
, bytes_remaining
;
5133 CHECK_STRING (prop
);
5135 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5136 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5137 prop_atom
, 0, 0, False
, XA_STRING
,
5138 &actual_type
, &actual_format
, &actual_size
,
5139 &bytes_remaining
, (unsigned char **) &tmp_data
);
5142 int size
= bytes_remaining
;
5147 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5148 prop_atom
, 0, bytes_remaining
,
5150 &actual_type
, &actual_format
,
5151 &actual_size
, &bytes_remaining
,
5152 (unsigned char **) &tmp_data
);
5154 prop_value
= make_string (tmp_data
, size
);
5169 /***********************************************************************
5171 ***********************************************************************/
5174 w32_note_current_window (void)
5176 struct frame
* f
= SELECTED_FRAME ();
5178 if (!FRAME_W32_P (f
))
5181 hourglass_hwnd
= FRAME_W32_WINDOW (f
);
5185 show_hourglass (struct atimer
*timer
)
5189 hourglass_atimer
= NULL
;
5192 f
= x_window_to_frame (&one_w32_display_info
,
5196 f
->output_data
.w32
->hourglass_p
= 0;
5198 f
= SELECTED_FRAME ();
5200 if (!FRAME_W32_P (f
))
5203 w32_show_hourglass (f
);
5208 hide_hourglass (void)
5211 w32_hide_hourglass ();
5216 /* Display an hourglass cursor. Set the hourglass_p flag in display info
5217 to indicate that an hourglass cursor is shown. */
5220 w32_show_hourglass (struct frame
*f
)
5222 if (!hourglass_shown_p
)
5224 f
->output_data
.w32
->hourglass_p
= 1;
5225 if (!menubar_in_use
&& !current_popup_menu
)
5226 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
5227 hourglass_shown_p
= 1;
5232 /* Hide the hourglass cursor on all frames, if it is currently shown. */
5235 w32_hide_hourglass (void)
5237 if (hourglass_shown_p
)
5239 struct frame
*f
= x_window_to_frame (&one_w32_display_info
,
5242 f
->output_data
.w32
->hourglass_p
= 0;
5244 /* If frame was deleted, restore to selected frame's cursor. */
5245 f
= SELECTED_FRAME ();
5247 if (FRAME_W32_P (f
))
5248 SetCursor (f
->output_data
.w32
->current_cursor
);
5250 /* No cursors on non GUI frames - restore to stock arrow cursor. */
5251 SetCursor (w32_load_cursor (IDC_ARROW
));
5253 hourglass_shown_p
= 0;
5259 /***********************************************************************
5261 ***********************************************************************/
5263 static Lisp_Object
x_create_tip_frame (struct w32_display_info
*,
5264 Lisp_Object
, Lisp_Object
);
5265 static void compute_tip_xy (struct frame
*, Lisp_Object
, Lisp_Object
,
5266 Lisp_Object
, int, int, int *, int *);
5268 /* The frame of a currently visible tooltip. */
5270 Lisp_Object tip_frame
;
5272 /* If non-nil, a timer started that hides the last tooltip when it
5275 Lisp_Object tip_timer
;
5278 /* If non-nil, a vector of 3 elements containing the last args
5279 with which x-show-tip was called. See there. */
5281 Lisp_Object last_show_tip_args
;
5285 unwind_create_tip_frame (Lisp_Object frame
)
5287 Lisp_Object deleted
;
5289 deleted
= unwind_create_frame (frame
);
5290 if (EQ (deleted
, Qt
))
5300 /* Create a frame for a tooltip on the display described by DPYINFO.
5301 PARMS is a list of frame parameters. TEXT is the string to
5302 display in the tip frame. Value is the frame.
5304 Note that functions called here, esp. x_default_parameter can
5305 signal errors, for instance when a specified color name is
5306 undefined. We have to make sure that we're in a consistent state
5307 when this happens. */
5310 x_create_tip_frame (struct w32_display_info
*dpyinfo
,
5311 Lisp_Object parms
, Lisp_Object text
)
5316 long window_prompting
= 0;
5318 ptrdiff_t count
= SPECPDL_INDEX ();
5319 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5321 int face_change_count_before
= face_change_count
;
5323 struct buffer
*old_buffer
;
5325 /* Use this general default value to start with until we know if
5326 this frame has a specified name. */
5327 Vx_resource_name
= Vinvocation_name
;
5329 kb
= dpyinfo
->terminal
->kboard
;
5331 /* The calls to x_get_arg remove elements from PARMS, so copy it to
5332 avoid destructive changes behind our caller's back. */
5333 parms
= Fcopy_alist (parms
);
5335 /* Get the name of the frame to use for resource lookup. */
5336 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
5338 && !EQ (name
, Qunbound
)
5340 error ("Invalid frame name--not a string or nil");
5341 Vx_resource_name
= name
;
5344 GCPRO3 (parms
, name
, frame
);
5345 /* Make a frame without minibuffer nor mode-line. */
5347 f
->wants_modeline
= 0;
5348 XSETFRAME (frame
, f
);
5350 buffer
= Fget_buffer_create (build_string (" *tip*"));
5351 /* Use set_window_buffer instead of Fset_window_buffer (see
5352 discussion of bug#11984, bug#12025, bug#12026). */
5353 set_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, 0, 0);
5354 old_buffer
= current_buffer
;
5355 set_buffer_internal_1 (XBUFFER (buffer
));
5356 bset_truncate_lines (current_buffer
, Qnil
);
5357 specbind (Qinhibit_read_only
, Qt
);
5358 specbind (Qinhibit_modification_hooks
, Qt
);
5361 set_buffer_internal_1 (old_buffer
);
5363 record_unwind_protect (unwind_create_tip_frame
, frame
);
5365 /* By setting the output method, we're essentially saying that
5366 the frame is live, as per FRAME_LIVE_P. If we get a signal
5367 from this point on, x_destroy_window might screw up reference
5369 f
->terminal
= dpyinfo
->terminal
;
5370 f
->output_method
= output_w32
;
5371 f
->output_data
.w32
= xzalloc (sizeof (struct w32_output
));
5373 FRAME_FONTSET (f
) = -1;
5374 fset_icon_name (f
, Qnil
);
5377 image_cache_refcount
=
5378 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
5379 dpyinfo_refcount
= dpyinfo
->reference_count
;
5380 #endif /* GLYPH_DEBUG */
5381 FRAME_KBOARD (f
) = kb
;
5382 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5383 f
->output_data
.w32
->explicit_parent
= 0;
5385 /* Set the name; the functions to which we pass f expect the name to
5387 if (EQ (name
, Qunbound
) || NILP (name
))
5389 fset_name (f
, build_string (dpyinfo
->w32_id_name
));
5390 f
->explicit_name
= 0;
5394 fset_name (f
, name
);
5395 f
->explicit_name
= 1;
5396 /* use the frame's title when getting resources for this frame. */
5397 specbind (Qx_resource_name
, name
);
5400 if (uniscribe_available
)
5401 register_font_driver (&uniscribe_font_driver
, f
);
5402 register_font_driver (&w32font_driver
, f
);
5404 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
5405 "fontBackend", "FontBackend", RES_TYPE_STRING
);
5407 /* Extract the window parameters from the supplied values
5408 that are needed to determine window geometry. */
5409 x_default_font_parameter (f
, parms
);
5411 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
5412 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5413 /* This defaults to 2 in order to match xterm. We recognize either
5414 internalBorderWidth or internalBorder (which is what xterm calls
5416 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5420 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
5421 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
5422 if (! EQ (value
, Qunbound
))
5423 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
5426 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
5427 "internalBorderWidth", "internalBorderWidth",
5430 /* Also do the stuff which must be set before the window exists. */
5431 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
5432 "foreground", "Foreground", RES_TYPE_STRING
);
5433 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
5434 "background", "Background", RES_TYPE_STRING
);
5435 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
5436 "pointerColor", "Foreground", RES_TYPE_STRING
);
5437 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
5438 "cursorColor", "Foreground", RES_TYPE_STRING
);
5439 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
5440 "borderColor", "BorderColor", RES_TYPE_STRING
);
5442 /* Init faces before x_default_parameter is called for scroll-bar
5443 parameters because that function calls x_set_scroll_bar_width,
5444 which calls change_frame_size, which calls Fset_window_buffer,
5445 which runs hooks, which call Fvertical_motion. At the end, we
5446 end up in init_iterator with a null face cache, which should not
5448 init_frame_faces (f
);
5450 f
->output_data
.w32
->dwStyle
= WS_BORDER
| WS_POPUP
| WS_DISABLED
;
5451 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5453 window_prompting
= x_figure_window_size (f
, parms
, 0);
5455 /* No fringes on tip frame. */
5457 f
->left_fringe_width
= 0;
5458 f
->right_fringe_width
= 0;
5461 my_create_tip_window (f
);
5466 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
5467 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5468 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5469 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5470 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5471 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5473 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
5474 Change will not be effected unless different from the current
5476 width
= FRAME_COLS (f
);
5477 height
= FRAME_LINES (f
);
5478 FRAME_LINES (f
) = 0;
5479 SET_FRAME_COLS (f
, 0);
5480 change_frame_size (f
, height
, width
, 1, 0, 0);
5482 /* Add `tooltip' frame parameter's default value. */
5483 if (NILP (Fframe_parameter (frame
, Qtooltip
)))
5484 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qtooltip
, Qt
), Qnil
));
5486 /* Set up faces after all frame parameters are known. This call
5487 also merges in face attributes specified for new frames.
5489 Frame parameters may be changed if .Xdefaults contains
5490 specifications for the default font. For example, if there is an
5491 `Emacs.default.attributeBackground: pink', the `background-color'
5492 attribute of the frame get's set, which let's the internal border
5493 of the tooltip frame appear in pink. Prevent this. */
5495 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
5496 Lisp_Object fg
= Fframe_parameter (frame
, Qforeground_color
);
5497 Lisp_Object colors
= Qnil
;
5499 /* Set tip_frame here, so that */
5501 call2 (Qface_set_after_frame_default
, frame
, Qnil
);
5503 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
5504 colors
= Fcons (Fcons (Qbackground_color
, bg
), colors
);
5505 if (!EQ (fg
, Fframe_parameter (frame
, Qforeground_color
)))
5506 colors
= Fcons (Fcons (Qforeground_color
, fg
), colors
);
5509 Fmodify_frame_parameters (frame
, colors
);
5516 /* Now that the frame is official, it counts as a reference to
5518 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
5519 f
->terminal
->reference_count
++;
5521 /* It is now ok to make the frame official even if we get an error
5522 below. And the frame needs to be on Vframe_list or making it
5523 visible won't work. */
5524 Vframe_list
= Fcons (frame
, Vframe_list
);
5526 /* Setting attributes of faces of the tooltip frame from resources
5527 and similar will increment face_change_count, which leads to the
5528 clearing of all current matrices. Since this isn't necessary
5529 here, avoid it by resetting face_change_count to the value it
5530 had before we created the tip frame. */
5531 face_change_count
= face_change_count_before
;
5533 /* Discard the unwind_protect. */
5534 return unbind_to (count
, frame
);
5538 /* Compute where to display tip frame F. PARMS is the list of frame
5539 parameters for F. DX and DY are specified offsets from the current
5540 location of the mouse. WIDTH and HEIGHT are the width and height
5541 of the tooltip. Return coordinates relative to the root window of
5542 the display in *ROOT_X, and *ROOT_Y. */
5545 compute_tip_xy (struct frame
*f
,
5546 Lisp_Object parms
, Lisp_Object dx
, Lisp_Object dy
,
5547 int width
, int height
, int *root_x
, int *root_y
)
5549 Lisp_Object left
, top
;
5550 int min_x
, min_y
, max_x
, max_y
;
5552 /* User-specified position? */
5553 left
= Fcdr (Fassq (Qleft
, parms
));
5554 top
= Fcdr (Fassq (Qtop
, parms
));
5556 /* Move the tooltip window where the mouse pointer is. Resize and
5558 if (!INTEGERP (left
) || !INTEGERP (top
))
5562 /* Default min and max values. */
5565 max_x
= x_display_pixel_width (FRAME_W32_DISPLAY_INFO (f
));
5566 max_y
= x_display_pixel_height (FRAME_W32_DISPLAY_INFO (f
));
5574 /* If multiple monitor support is available, constrain the tip onto
5575 the current monitor. This improves the above by allowing negative
5576 co-ordinates if monitor positions are such that they are valid, and
5577 snaps a tooltip onto a single monitor if we are close to the edge
5578 where it would otherwise flow onto the other monitor (or into
5579 nothingness if there is a gap in the overlap). */
5580 if (monitor_from_point_fn
&& get_monitor_info_fn
)
5582 struct MONITOR_INFO info
;
5584 = monitor_from_point_fn (pt
, MONITOR_DEFAULT_TO_NEAREST
);
5585 info
.cbSize
= sizeof (info
);
5587 if (get_monitor_info_fn (monitor
, &info
))
5589 min_x
= info
.rcWork
.left
;
5590 min_y
= info
.rcWork
.top
;
5591 max_x
= info
.rcWork
.right
;
5592 max_y
= info
.rcWork
.bottom
;
5598 *root_y
= XINT (top
);
5599 else if (*root_y
+ XINT (dy
) <= min_y
)
5600 *root_y
= min_y
; /* Can happen for negative dy */
5601 else if (*root_y
+ XINT (dy
) + height
<= max_y
)
5602 /* It fits below the pointer */
5603 *root_y
+= XINT (dy
);
5604 else if (height
+ XINT (dy
) + min_y
<= *root_y
)
5605 /* It fits above the pointer. */
5606 *root_y
-= height
+ XINT (dy
);
5608 /* Put it on the top. */
5611 if (INTEGERP (left
))
5612 *root_x
= XINT (left
);
5613 else if (*root_x
+ XINT (dx
) <= min_x
)
5614 *root_x
= 0; /* Can happen for negative dx */
5615 else if (*root_x
+ XINT (dx
) + width
<= max_x
)
5616 /* It fits to the right of the pointer. */
5617 *root_x
+= XINT (dx
);
5618 else if (width
+ XINT (dx
) + min_x
<= *root_x
)
5619 /* It fits to the left of the pointer. */
5620 *root_x
-= width
+ XINT (dx
);
5622 /* Put it left justified on the screen -- it ought to fit that way. */
5627 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
5628 doc
: /* Show STRING in a \"tooltip\" window on frame FRAME.
5629 A tooltip window is a small window displaying a string.
5631 This is an internal function; Lisp code should call `tooltip-show'.
5633 FRAME nil or omitted means use the selected frame.
5635 PARMS is an optional list of frame parameters which can be
5636 used to change the tooltip's appearance.
5638 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
5639 means use the default timeout of 5 seconds.
5641 If the list of frame parameters PARMS contains a `left' parameter,
5642 the tooltip is displayed at that x-position. Otherwise it is
5643 displayed at the mouse position, with offset DX added (default is 5 if
5644 DX isn't specified). Likewise for the y-position; if a `top' frame
5645 parameter is specified, it determines the y-position of the tooltip
5646 window, otherwise it is displayed at the mouse position, with offset
5647 DY added (default is -10).
5649 A tooltip's maximum size is specified by `x-max-tooltip-size'.
5650 Text larger than the specified size is clipped. */)
5651 (Lisp_Object string
, Lisp_Object frame
, Lisp_Object parms
, Lisp_Object timeout
, Lisp_Object dx
, Lisp_Object dy
)
5656 struct buffer
*old_buffer
;
5657 struct text_pos pos
;
5658 int i
, width
, height
, seen_reversed_p
;
5659 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5660 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5661 ptrdiff_t count
= SPECPDL_INDEX ();
5663 specbind (Qinhibit_redisplay
, Qt
);
5665 GCPRO4 (string
, parms
, frame
, timeout
);
5667 CHECK_STRING (string
);
5668 f
= decode_window_system_frame (frame
);
5670 timeout
= make_number (5);
5672 CHECK_NATNUM (timeout
);
5675 dx
= make_number (5);
5680 dy
= make_number (-10);
5684 if (NILP (last_show_tip_args
))
5685 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
5687 if (!NILP (tip_frame
))
5689 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
5690 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
5691 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
5693 if (EQ (frame
, last_frame
)
5694 && !NILP (Fequal (last_string
, string
))
5695 && !NILP (Fequal (last_parms
, parms
)))
5697 struct frame
*f
= XFRAME (tip_frame
);
5699 /* Only DX and DY have changed. */
5700 if (!NILP (tip_timer
))
5702 Lisp_Object timer
= tip_timer
;
5704 call1 (Qcancel_timer
, timer
);
5708 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
5709 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
5711 /* Put tooltip in topmost group and in position. */
5712 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
5713 root_x
, root_y
, 0, 0,
5714 SWP_NOSIZE
| SWP_NOACTIVATE
);
5716 /* Ensure tooltip is on top of other topmost windows (eg menus). */
5717 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
5719 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
5726 /* Hide a previous tip, if any. */
5729 ASET (last_show_tip_args
, 0, string
);
5730 ASET (last_show_tip_args
, 1, frame
);
5731 ASET (last_show_tip_args
, 2, parms
);
5733 /* Add default values to frame parameters. */
5734 if (NILP (Fassq (Qname
, parms
)))
5735 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
5736 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5737 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
5738 if (NILP (Fassq (Qborder_width
, parms
)))
5739 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
5740 if (NILP (Fassq (Qborder_color
, parms
)))
5741 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
5742 if (NILP (Fassq (Qbackground_color
, parms
)))
5743 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
5746 /* Block input until the tip has been fully drawn, to avoid crashes
5747 when drawing tips in menus. */
5750 /* Create a frame for the tooltip, and record it in the global
5751 variable tip_frame. */
5752 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
, string
);
5755 /* Set up the frame's root window. */
5756 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5760 if (CONSP (Vx_max_tooltip_size
)
5761 && INTEGERP (XCAR (Vx_max_tooltip_size
))
5762 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
5763 && INTEGERP (XCDR (Vx_max_tooltip_size
))
5764 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
5766 w
->total_cols
= XFASTINT (XCAR (Vx_max_tooltip_size
));
5767 w
->total_lines
= XFASTINT (XCDR (Vx_max_tooltip_size
));
5772 w
->total_lines
= 40;
5775 FRAME_TOTAL_COLS (f
) = WINDOW_TOTAL_COLS (w
);
5777 w
->pseudo_window_p
= 1;
5779 /* Display the tooltip text in a temporary buffer. */
5780 old_buffer
= current_buffer
;
5781 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->contents
));
5782 bset_truncate_lines (current_buffer
, Qnil
);
5783 clear_glyph_matrix (w
->desired_matrix
);
5784 clear_glyph_matrix (w
->current_matrix
);
5785 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
5786 try_window (FRAME_ROOT_WINDOW (f
), pos
, TRY_WINDOW_IGNORE_FONTS_CHANGE
);
5788 /* Compute width and height of the tooltip. */
5789 width
= height
= seen_reversed_p
= 0;
5790 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5792 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5796 /* Stop at the first empty row at the end. */
5797 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
5800 /* Let the row go over the full width of the frame. */
5801 row
->full_width_p
= 1;
5803 row_width
= row
->pixel_width
;
5804 if (row
->used
[TEXT_AREA
])
5806 if (!row
->reversed_p
)
5808 /* There's a glyph at the end of rows that is used to
5809 place the cursor there. Don't include the width of
5811 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5812 if (INTEGERP (last
->object
))
5813 row_width
-= last
->pixel_width
;
5817 /* There could be a stretch glyph at the beginning of R2L
5818 rows that is produced by extend_face_to_end_of_line.
5819 Don't count that glyph. */
5820 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
5822 if (g
->type
== STRETCH_GLYPH
&& INTEGERP (g
->object
))
5824 row_width
-= g
->pixel_width
;
5825 seen_reversed_p
= 1;
5830 height
+= row
->height
;
5831 width
= max (width
, row_width
);
5834 /* If we've seen partial-length R2L rows, we need to re-adjust the
5835 tool-tip frame width and redisplay it again, to avoid over-wide
5836 tips due to the stretch glyph that extends R2L lines to full
5837 width of the frame. */
5838 if (seen_reversed_p
)
5840 /* w->total_cols and FRAME_TOTAL_COLS want the width in columns,
5842 width
/= WINDOW_FRAME_COLUMN_WIDTH (w
);
5843 w
->total_cols
= width
;
5844 FRAME_TOTAL_COLS (f
) = width
;
5846 w
->pseudo_window_p
= 1;
5847 clear_glyph_matrix (w
->desired_matrix
);
5848 clear_glyph_matrix (w
->current_matrix
);
5849 try_window (FRAME_ROOT_WINDOW (f
), pos
, TRY_WINDOW_IGNORE_FONTS_CHANGE
);
5851 /* Recompute width and height of the tooltip. */
5852 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5854 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5858 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
5860 row
->full_width_p
= 1;
5861 row_width
= row
->pixel_width
;
5862 if (row
->used
[TEXT_AREA
] && !row
->reversed_p
)
5864 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5865 if (INTEGERP (last
->object
))
5866 row_width
-= last
->pixel_width
;
5869 height
+= row
->height
;
5870 width
= max (width
, row_width
);
5874 /* Round up the height to an integral multiple of FRAME_LINE_HEIGHT. */
5875 if (height
% FRAME_LINE_HEIGHT (f
) != 0)
5876 height
+= FRAME_LINE_HEIGHT (f
) - height
% FRAME_LINE_HEIGHT (f
);
5877 /* Add the frame's internal border to the width and height the w32
5878 window should have. */
5879 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5880 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5882 /* Move the tooltip window where the mouse pointer is. Resize and
5884 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
5887 /* Adjust Window size to take border into account. */
5889 rect
.left
= rect
.top
= 0;
5891 rect
.bottom
= height
;
5892 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
5893 FRAME_EXTERNAL_MENU_BAR (f
));
5895 /* Position and size tooltip, and put it in the topmost group.
5896 The add-on of FRAME_COLUMN_WIDTH to the 5th argument is a
5897 peculiarity of w32 display: without it, some fonts cause the
5898 last character of the tip to be truncated or wrapped around to
5900 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
5902 rect
.right
- rect
.left
+ FRAME_COLUMN_WIDTH (f
),
5903 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
);
5905 /* Ensure tooltip is on top of other topmost windows (eg menus). */
5906 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
5908 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
5910 /* Let redisplay know that we have made the frame visible already. */
5911 SET_FRAME_VISIBLE (f
, 1);
5913 ShowWindow (FRAME_W32_WINDOW (f
), SW_SHOWNOACTIVATE
);
5916 /* Draw into the window. */
5917 w
->must_be_updated_p
= 1;
5918 update_single_window (w
, 1);
5922 /* Restore original current buffer. */
5923 set_buffer_internal_1 (old_buffer
);
5924 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5927 /* Let the tip disappear after timeout seconds. */
5928 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
5929 intern ("x-hide-tip"));
5932 return unbind_to (count
, Qnil
);
5936 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
5937 doc
: /* Hide the current tooltip window, if there is any.
5938 Value is t if tooltip was open, nil otherwise. */)
5942 Lisp_Object deleted
, frame
, timer
;
5943 struct gcpro gcpro1
, gcpro2
;
5945 /* Return quickly if nothing to do. */
5946 if (NILP (tip_timer
) && NILP (tip_frame
))
5951 GCPRO2 (frame
, timer
);
5952 tip_frame
= tip_timer
= deleted
= Qnil
;
5954 count
= SPECPDL_INDEX ();
5955 specbind (Qinhibit_redisplay
, Qt
);
5956 specbind (Qinhibit_quit
, Qt
);
5959 call1 (Qcancel_timer
, timer
);
5963 delete_frame (frame
, Qnil
);
5968 return unbind_to (count
, deleted
);
5971 /***********************************************************************
5972 File selection dialog
5973 ***********************************************************************/
5975 #define FILE_NAME_TEXT_FIELD edt1
5976 #define FILE_NAME_COMBO_BOX cmb13
5977 #define FILE_NAME_LIST lst1
5979 /* Callback for altering the behavior of the Open File dialog.
5980 Makes the Filename text field contain "Current Directory" and be
5981 read-only when "Directories" is selected in the filter. This
5982 allows us to work around the fact that the standard Open File
5983 dialog does not support directories. */
5984 static UINT_PTR CALLBACK
5985 file_dialog_callback (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
5987 if (msg
== WM_NOTIFY
)
5989 #ifdef NTGUI_UNICODE
5990 OFNOTIFYW
* notify
= (OFNOTIFYW
*)lParam
;
5991 #else /* !NTGUI_UNICODE */
5992 OFNOTIFYA
* notify
= (OFNOTIFYA
*)lParam
;
5993 #endif /* NTGUI_UNICODE */
5994 /* Detect when the Filter dropdown is changed. */
5995 if (notify
->hdr
.code
== CDN_TYPECHANGE
5996 || notify
->hdr
.code
== CDN_INITDONE
)
5998 HWND dialog
= GetParent (hwnd
);
5999 HWND edit_control
= GetDlgItem (dialog
, FILE_NAME_TEXT_FIELD
);
6000 HWND list
= GetDlgItem (dialog
, FILE_NAME_LIST
);
6002 /* At least on Windows 7, the above attempt to get the window handle
6003 to the File Name Text Field fails. The following code does the
6004 job though. Note that this code is based on my examination of the
6005 window hierarchy using Microsoft Spy++. bk */
6006 if (edit_control
== NULL
)
6008 HWND tmp
= GetDlgItem (dialog
, FILE_NAME_COMBO_BOX
);
6011 tmp
= GetWindow (tmp
, GW_CHILD
);
6013 edit_control
= GetWindow (tmp
, GW_CHILD
);
6017 /* Directories is in index 2. */
6018 if (notify
->lpOFN
->nFilterIndex
== 2)
6020 CommDlg_OpenSave_SetControlText (dialog
, FILE_NAME_TEXT_FIELD
,
6021 GUISTR ("Current Directory"));
6022 EnableWindow (edit_control
, FALSE
);
6023 /* Note that at least on Windows 7, the above call to EnableWindow
6024 disables the window that would ordinarily have focus. If we
6025 do not set focus to some other window here, focus will land in
6026 no man's land and the user will be unable to tab through the
6027 dialog box (pressing tab will only result in a beep).
6028 Avoid that problem by setting focus to the list here. */
6029 if (notify
->hdr
.code
== CDN_INITDONE
)
6034 /* Don't override default filename on init done. */
6035 if (notify
->hdr
.code
== CDN_TYPECHANGE
)
6036 CommDlg_OpenSave_SetControlText (dialog
,
6037 FILE_NAME_TEXT_FIELD
,
6039 EnableWindow (edit_control
, TRUE
);
6046 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
6047 doc
: /* Read file name, prompting with PROMPT in directory DIR.
6048 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
6049 selection box, if specified. If MUSTMATCH is non-nil, the returned file
6050 or directory must exist.
6052 This function is only defined on NS, MS Windows, and X Windows with the
6053 Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
6054 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
6055 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
, Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
6057 /* Filter index: 1: All Files, 2: Directories only */
6058 static const guichar_t filter
[] =
6059 GUISTR ("All Files (*.*)\0*.*\0Directories\0*|*\0");
6061 Lisp_Object filename
= default_filename
;
6062 struct frame
*f
= SELECTED_FRAME ();
6063 BOOL file_opened
= FALSE
;
6064 Lisp_Object orig_dir
= dir
;
6065 Lisp_Object orig_prompt
= prompt
;
6067 /* If we compile with _WIN32_WINNT set to 0x0400 (for NT4
6068 compatibility) we end up with the old file dialogs. Define a big
6069 enough struct for the new dialog to trick GetOpenFileName into
6070 giving us the new dialogs on newer versions of Windows. */
6072 #ifdef NTGUI_UNICODE
6073 OPENFILENAMEW details
;
6074 #else /* !NTGUI_UNICODE */
6075 OPENFILENAMEA details
;
6076 #endif /* NTGUI_UNICODE */
6078 #if _WIN32_WINNT < 0x500 /* < win2k */
6082 #endif /* < win2k */
6085 #ifdef NTGUI_UNICODE
6086 wchar_t filename_buf
[32*1024 + 1]; // NT kernel maximum
6087 OPENFILENAMEW
* file_details
= &new_file_details
.details
;
6088 #else /* not NTGUI_UNICODE */
6089 char filename_buf
[MAX_PATH
+ 1];
6090 OPENFILENAMEA
* file_details
= &new_file_details
.details
;
6091 #endif /* NTGUI_UNICODE */
6093 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
6094 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, filename
);
6097 struct gcpro gcpro1
, gcpro2
;
6098 GCPRO2 (orig_dir
, orig_prompt
); /* There is no GCPRON, N>6. */
6100 /* Note: under NTGUI_UNICODE, we do _NOT_ use ENCODE_FILE: the
6101 system file encoding expected by the platform APIs (e.g. Cygwin's
6102 POSIX implementation) may not be the same as the encoding expected
6103 by the Windows "ANSI" APIs! */
6105 CHECK_STRING (prompt
);
6108 dir
= Fexpand_file_name (dir
, Qnil
);
6110 if (STRINGP (filename
))
6111 filename
= Ffile_name_nondirectory (filename
);
6113 filename
= empty_unibyte_string
;
6116 dir
= Fcygwin_convert_file_name_to_windows (dir
, Qt
);
6117 if (SCHARS (filename
) > 0)
6118 filename
= Fcygwin_convert_file_name_to_windows (filename
, Qnil
);
6122 CHECK_STRING (filename
);
6124 /* The code in file_dialog_callback that attempts to set the text
6125 of the file name edit window when handling the CDN_INITDONE
6126 WM_NOTIFY message does not work. Setting filename to "Current
6127 Directory" in the only_dir_p case here does work however. */
6128 if (SCHARS (filename
) == 0 && ! NILP (only_dir_p
))
6129 filename
= build_string ("Current Directory");
6131 /* Convert the values we've computed so far to system form. */
6132 #ifdef NTGUI_UNICODE
6133 to_unicode (prompt
, &prompt
);
6134 to_unicode (dir
, &dir
);
6135 to_unicode (filename
, &filename
);
6136 #else /* !NTGUI_UNICODE */
6137 prompt
= ENCODE_FILE (prompt
);
6138 dir
= ENCODE_FILE (dir
);
6139 filename
= ENCODE_FILE (filename
);
6141 /* We modify these in-place, so make copies for safety. */
6142 dir
= Fcopy_sequence (dir
);
6143 unixtodos_filename (SDATA (dir
));
6144 filename
= Fcopy_sequence (filename
);
6145 unixtodos_filename (SDATA (filename
));
6146 #endif /* NTGUI_UNICODE */
6148 /* Fill in the structure for the call to GetOpenFileName below.
6149 For NTGUI_UNICODE builds (which run only on NT), we just use
6150 the actual size of the structure. For non-NTGUI_UNICODE
6151 builds, we tell the OS we're using an old version of the
6152 structure if the OS isn't new enough to support the newer
6154 memset (&new_file_details
, 0, sizeof (new_file_details
));
6156 if (w32_major_version
> 4 && w32_major_version
< 95)
6157 file_details
->lStructSize
= sizeof (new_file_details
);
6159 file_details
->lStructSize
= sizeof (*file_details
);
6161 /* Set up the inout parameter for the selected file name. */
6162 if (SBYTES (filename
) + 1 > sizeof (filename_buf
))
6163 report_file_error ("filename too long", default_filename
);
6165 memcpy (filename_buf
, SDATA (filename
), SBYTES (filename
) + 1);
6166 file_details
->lpstrFile
= filename_buf
;
6167 file_details
->nMaxFile
= sizeof (filename_buf
) / sizeof (*filename_buf
);
6169 file_details
->hwndOwner
= FRAME_W32_WINDOW (f
);
6170 /* Undocumented Bug in Common File Dialog:
6171 If a filter is not specified, shell links are not resolved. */
6172 file_details
->lpstrFilter
= filter
;
6173 file_details
->lpstrInitialDir
= (guichar_t
*) SDATA (dir
);
6174 file_details
->lpstrTitle
= (guichar_t
*) SDATA (prompt
);
6175 file_details
->nFilterIndex
= NILP (only_dir_p
) ? 1 : 2;
6176 file_details
->Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
6177 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
6179 if (!NILP (mustmatch
))
6181 /* Require that the path to the parent directory exists. */
6182 file_details
->Flags
|= OFN_PATHMUSTEXIST
;
6183 /* If we are looking for a file, require that it exists. */
6184 if (NILP (only_dir_p
))
6185 file_details
->Flags
|= OFN_FILEMUSTEXIST
;
6189 int count
= SPECPDL_INDEX ();
6190 /* Prevent redisplay. */
6191 specbind (Qinhibit_redisplay
, Qt
);
6193 file_details
->lpfnHook
= file_dialog_callback
;
6195 file_opened
= GUI_FN (GetOpenFileName
) (file_details
);
6197 unbind_to (count
, Qnil
);
6202 /* Get an Emacs string from the value Windows gave us. */
6203 #ifdef NTGUI_UNICODE
6204 filename
= from_unicode_buffer (filename_buf
);
6205 #else /* !NTGUI_UNICODE */
6206 dostounix_filename (filename_buf
, 0);
6207 filename
= DECODE_FILE (build_string (filename_buf
));
6208 #endif /* NTGUI_UNICODE */
6211 filename
= Fcygwin_convert_file_name_from_windows (filename
, Qt
);
6214 /* Strip the dummy filename off the end of the string if we
6215 added it to select a directory. */
6216 if (file_details
->nFilterIndex
== 2)
6218 filename
= Ffile_name_directory (filename
);
6221 /* User canceled the dialog without making a selection. */
6222 else if (!CommDlgExtendedError ())
6224 /* An error occurred, fallback on reading from the mini-buffer. */
6226 filename
= Fcompleting_read (
6228 intern ("read-file-name-internal"),
6239 /* Make "Cancel" equivalent to C-g. */
6240 if (NILP (filename
))
6241 Fsignal (Qquit
, Qnil
);
6243 RETURN_UNGCPRO (filename
);
6248 /* Moving files to the system recycle bin.
6249 Used by `move-file-to-trash' instead of the default moving to ~/.Trash */
6250 DEFUN ("system-move-file-to-trash", Fsystem_move_file_to_trash
,
6251 Ssystem_move_file_to_trash
, 1, 1, 0,
6252 doc
: /* Move file or directory named FILENAME to the recycle bin. */)
6253 (Lisp_Object filename
)
6255 Lisp_Object handler
;
6256 Lisp_Object encoded_file
;
6257 Lisp_Object operation
;
6259 operation
= Qdelete_file
;
6260 if (!NILP (Ffile_directory_p (filename
))
6261 && NILP (Ffile_symlink_p (filename
)))
6263 operation
= intern ("delete-directory");
6264 filename
= Fdirectory_file_name (filename
);
6266 filename
= Fexpand_file_name (filename
, Qnil
);
6268 handler
= Ffind_file_name_handler (filename
, operation
);
6269 if (!NILP (handler
))
6270 return call2 (handler
, operation
, filename
);
6272 encoded_file
= ENCODE_FILE (filename
);
6276 SHFILEOPSTRUCT file_op
;
6277 char tmp_path
[MAX_PATH
+ 1];
6279 path
= map_w32_filename (SDATA (encoded_file
), NULL
);
6281 /* On Windows, write permission is required to delete/move files. */
6282 _chmod (path
, 0666);
6284 memset (tmp_path
, 0, sizeof (tmp_path
));
6285 strcpy (tmp_path
, path
);
6287 memset (&file_op
, 0, sizeof (file_op
));
6288 file_op
.hwnd
= HWND_DESKTOP
;
6289 file_op
.wFunc
= FO_DELETE
;
6290 file_op
.pFrom
= tmp_path
;
6291 file_op
.fFlags
= FOF_SILENT
| FOF_NOCONFIRMATION
| FOF_ALLOWUNDO
6292 | FOF_NOERRORUI
| FOF_NO_CONNECTED_ELEMENTS
;
6293 file_op
.fAnyOperationsAborted
= FALSE
;
6295 if (SHFileOperation (&file_op
) != 0)
6296 report_file_error ("Removing old name", list1 (filename
));
6301 #endif /* WINDOWSNT */
6304 /***********************************************************************
6305 w32 specialized functions
6306 ***********************************************************************/
6308 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
,
6309 Sw32_send_sys_command
, 1, 2, 0,
6310 doc
: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND.
6311 Some useful values for COMMAND are #xf030 to maximize frame (#xf020
6312 to minimize), #xf120 to restore frame to original size, and #xf100
6313 to activate the menubar for keyboard access. #xf140 activates the
6314 screen saver if defined.
6316 If optional parameter FRAME is not specified, use selected frame. */)
6317 (Lisp_Object command
, Lisp_Object frame
)
6319 FRAME_PTR f
= decode_window_system_frame (frame
);
6321 CHECK_NUMBER (command
);
6323 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
6328 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
6329 doc
: /* Get Windows to perform OPERATION on DOCUMENT.
6330 This is a wrapper around the ShellExecute system function, which
6331 invokes the application registered to handle OPERATION for DOCUMENT.
6333 OPERATION is either nil or a string that names a supported operation.
6334 What operations can be used depends on the particular DOCUMENT and its
6335 handler application, but typically it is one of the following common
6338 \"open\" - open DOCUMENT, which could be a file, a directory, or an
6339 executable program. If it is an application, that
6340 application is launched in the current buffer's default
6341 directory. Otherwise, the application associated with
6342 DOCUMENT is launched in the buffer's default directory.
6343 \"print\" - print DOCUMENT, which must be a file
6344 \"explore\" - start the Windows Explorer on DOCUMENT
6345 \"edit\" - launch an editor and open DOCUMENT for editing; which
6346 editor is launched depends on the association for the
6348 \"find\" - initiate search starting from DOCUMENT which must specify
6350 nil - invoke the default OPERATION, or \"open\" if default is
6351 not defined or unavailable
6353 DOCUMENT is typically the name of a document file or a URL, but can
6354 also be a program executable to run, or a directory to open in the
6357 If DOCUMENT is a program executable, the optional third arg PARAMETERS
6358 can be a string containing command line parameters that will be passed
6359 to the program; otherwise, PARAMETERS should be nil or unspecified.
6361 Optional fourth argument SHOW-FLAG can be used to control how the
6362 application will be displayed when it is invoked. If SHOW-FLAG is nil
6363 or unspecified, the application is displayed normally, otherwise it is
6364 an integer representing a ShowWindow flag:
6369 6 - start minimized */)
6370 (Lisp_Object operation
, Lisp_Object document
, Lisp_Object parameters
, Lisp_Object show_flag
)
6372 Lisp_Object current_dir
;
6375 CHECK_STRING (document
);
6377 /* Encode filename, current directory and parameters. */
6378 current_dir
= BVAR (current_buffer
, directory
);
6381 current_dir
= Fcygwin_convert_file_name_to_windows (current_dir
, Qt
);
6382 if (STRINGP (document
))
6383 document
= Fcygwin_convert_file_name_to_windows (document
, Qt
);
6386 current_dir
= GUI_ENCODE_FILE (current_dir
);
6387 if (STRINGP (document
))
6388 document
= GUI_ENCODE_FILE (document
);
6389 if (STRINGP (parameters
))
6390 parameters
= GUI_ENCODE_SYSTEM (parameters
);
6392 if ((int) GUI_FN (ShellExecute
) (NULL
,
6393 (STRINGP (operation
) ?
6394 GUI_SDATA (operation
) : NULL
),
6395 GUI_SDATA (document
),
6396 (STRINGP (parameters
) ?
6397 GUI_SDATA (parameters
) : NULL
),
6398 GUI_SDATA (current_dir
),
6399 (INTEGERP (show_flag
) ?
6400 XINT (show_flag
) : SW_SHOWDEFAULT
))
6403 errstr
= w32_strerror (0);
6404 /* The error string might be encoded in the locale's encoding. */
6405 if (!NILP (Vlocale_coding_system
))
6407 Lisp_Object decoded
=
6408 code_convert_string_norecord (build_unibyte_string (errstr
),
6409 Vlocale_coding_system
, 0);
6410 errstr
= SSDATA (decoded
);
6412 error ("ShellExecute failed: %s", errstr
);
6415 /* Lookup virtual keycode from string representing the name of a
6416 non-ascii keystroke into the corresponding virtual key, using
6417 lispy_function_keys. */
6419 lookup_vk_code (char *key
)
6423 for (i
= 0; i
< 256; i
++)
6424 if (lispy_function_keys
[i
]
6425 && strcmp (lispy_function_keys
[i
], key
) == 0)
6431 /* Convert a one-element vector style key sequence to a hot key
6434 w32_parse_hot_key (Lisp_Object key
)
6436 /* Copied from Fdefine_key and store_in_keymap. */
6437 register Lisp_Object c
;
6441 struct gcpro gcpro1
;
6445 if (ASIZE (key
) != 1)
6452 if (CONSP (c
) && lucid_event_type_list_p (c
))
6453 c
= Fevent_convert_list (c
);
6457 if (! INTEGERP (c
) && ! SYMBOLP (c
))
6458 error ("Key definition is invalid");
6460 /* Work out the base key and the modifiers. */
6463 c
= parse_modifiers (c
);
6464 lisp_modifiers
= XINT (Fcar (Fcdr (c
)));
6468 vk_code
= lookup_vk_code (SDATA (SYMBOL_NAME (c
)));
6470 else if (INTEGERP (c
))
6472 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
6473 /* Many ascii characters are their own virtual key code. */
6474 vk_code
= XINT (c
) & CHARACTERBITS
;
6477 if (vk_code
< 0 || vk_code
> 255)
6480 if ((lisp_modifiers
& meta_modifier
) != 0
6481 && !NILP (Vw32_alt_is_meta
))
6482 lisp_modifiers
|= alt_modifier
;
6484 /* Supply defs missing from mingw32. */
6486 #define MOD_ALT 0x0001
6487 #define MOD_CONTROL 0x0002
6488 #define MOD_SHIFT 0x0004
6489 #define MOD_WIN 0x0008
6492 /* Convert lisp modifiers to Windows hot-key form. */
6493 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
6494 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
6495 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
6496 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
6498 return HOTKEY (vk_code
, w32_modifiers
);
6501 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
,
6502 Sw32_register_hot_key
, 1, 1, 0,
6503 doc
: /* Register KEY as a hot-key combination.
6504 Certain key combinations like Alt-Tab are reserved for system use on
6505 Windows, and therefore are normally intercepted by the system. However,
6506 most of these key combinations can be received by registering them as
6507 hot-keys, overriding their special meaning.
6509 KEY must be a one element key definition in vector form that would be
6510 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta
6511 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper
6512 is always interpreted as the Windows modifier keys.
6514 The return value is the hotkey-id if registered, otherwise nil. */)
6517 key
= w32_parse_hot_key (key
);
6519 if (!NILP (key
) && NILP (Fmemq (key
, w32_grabbed_keys
)))
6521 /* Reuse an empty slot if possible. */
6522 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
6524 /* Safe to add new key to list, even if we have focus. */
6526 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
6528 XSETCAR (item
, key
);
6530 /* Notify input thread about new hot-key definition, so that it
6531 takes effect without needing to switch focus. */
6532 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
6533 (WPARAM
) XLI (key
), 0);
6539 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
,
6540 Sw32_unregister_hot_key
, 1, 1, 0,
6541 doc
: /* Unregister KEY as a hot-key combination. */)
6546 if (!INTEGERP (key
))
6547 key
= w32_parse_hot_key (key
);
6549 item
= Fmemq (key
, w32_grabbed_keys
);
6553 /* Notify input thread about hot-key definition being removed, so
6554 that it takes effect without needing focus switch. */
6555 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
6556 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) XLI (item
)))
6559 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
6566 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
,
6567 Sw32_registered_hot_keys
, 0, 0, 0,
6568 doc
: /* Return list of registered hot-key IDs. */)
6571 return Fdelq (Qnil
, Fcopy_sequence (w32_grabbed_keys
));
6574 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
,
6575 Sw32_reconstruct_hot_key
, 1, 1, 0,
6576 doc
: /* Convert hot-key ID to a lisp key combination.
6577 usage: (w32-reconstruct-hot-key ID) */)
6578 (Lisp_Object hotkeyid
)
6580 int vk_code
, w32_modifiers
;
6583 CHECK_NUMBER (hotkeyid
);
6585 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
6586 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
6588 if (vk_code
< 256 && lispy_function_keys
[vk_code
])
6589 key
= intern (lispy_function_keys
[vk_code
]);
6591 key
= make_number (vk_code
);
6593 key
= Fcons (key
, Qnil
);
6594 if (w32_modifiers
& MOD_SHIFT
)
6595 key
= Fcons (Qshift
, key
);
6596 if (w32_modifiers
& MOD_CONTROL
)
6597 key
= Fcons (Qctrl
, key
);
6598 if (w32_modifiers
& MOD_ALT
)
6599 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
6600 if (w32_modifiers
& MOD_WIN
)
6601 key
= Fcons (Qhyper
, key
);
6606 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
,
6607 Sw32_toggle_lock_key
, 1, 2, 0,
6608 doc
: /* Toggle the state of the lock key KEY.
6609 KEY can be `capslock', `kp-numlock', or `scroll'.
6610 If the optional parameter NEW-STATE is a number, then the state of KEY
6611 is set to off if the low bit of NEW-STATE is zero, otherwise on. */)
6612 (Lisp_Object key
, Lisp_Object new_state
)
6616 if (EQ (key
, intern ("capslock")))
6617 vk_code
= VK_CAPITAL
;
6618 else if (EQ (key
, intern ("kp-numlock")))
6619 vk_code
= VK_NUMLOCK
;
6620 else if (EQ (key
, intern ("scroll")))
6621 vk_code
= VK_SCROLL
;
6625 if (!dwWindowsThreadId
)
6626 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
6628 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
6629 (WPARAM
) vk_code
, (LPARAM
) XLI (new_state
)))
6632 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
6633 return make_number (msg
.wParam
);
6638 DEFUN ("w32-window-exists-p", Fw32_window_exists_p
, Sw32_window_exists_p
,
6640 doc
: /* Return non-nil if a window exists with the specified CLASS and NAME.
6642 This is a direct interface to the Windows API FindWindow function. */)
6643 (Lisp_Object
class, Lisp_Object name
)
6648 CHECK_STRING (class);
6650 CHECK_STRING (name
);
6652 hnd
= FindWindow (STRINGP (class) ? ((LPCTSTR
) SDATA (class)) : NULL
,
6653 STRINGP (name
) ? ((LPCTSTR
) SDATA (name
)) : NULL
);
6659 DEFUN ("w32-battery-status", Fw32_battery_status
, Sw32_battery_status
, 0, 0, 0,
6660 doc
: /* Get power status information from Windows system.
6662 The following %-sequences are provided:
6663 %L AC line status (verbose)
6664 %B Battery status (verbose)
6665 %b Battery status, empty means high, `-' means low,
6666 `!' means critical, and `+' means charging
6667 %p Battery load percentage
6668 %s Remaining time (to charge or discharge) in seconds
6669 %m Remaining time (to charge or discharge) in minutes
6670 %h Remaining time (to charge or discharge) in hours
6671 %t Remaining time (to charge or discharge) in the form `h:min' */)
6674 Lisp_Object status
= Qnil
;
6676 SYSTEM_POWER_STATUS system_status
;
6677 if (GetSystemPowerStatus (&system_status
))
6679 Lisp_Object line_status
, battery_status
, battery_status_symbol
;
6680 Lisp_Object load_percentage
, seconds
, minutes
, hours
, remain
;
6682 long seconds_left
= (long) system_status
.BatteryLifeTime
;
6684 if (system_status
.ACLineStatus
== 0)
6685 line_status
= build_string ("off-line");
6686 else if (system_status
.ACLineStatus
== 1)
6687 line_status
= build_string ("on-line");
6689 line_status
= build_string ("N/A");
6691 if (system_status
.BatteryFlag
& 128)
6693 battery_status
= build_string ("N/A");
6694 battery_status_symbol
= empty_unibyte_string
;
6696 else if (system_status
.BatteryFlag
& 8)
6698 battery_status
= build_string ("charging");
6699 battery_status_symbol
= build_string ("+");
6700 if (system_status
.BatteryFullLifeTime
!= -1L)
6701 seconds_left
= system_status
.BatteryFullLifeTime
- seconds_left
;
6703 else if (system_status
.BatteryFlag
& 4)
6705 battery_status
= build_string ("critical");
6706 battery_status_symbol
= build_string ("!");
6708 else if (system_status
.BatteryFlag
& 2)
6710 battery_status
= build_string ("low");
6711 battery_status_symbol
= build_string ("-");
6713 else if (system_status
.BatteryFlag
& 1)
6715 battery_status
= build_string ("high");
6716 battery_status_symbol
= empty_unibyte_string
;
6720 battery_status
= build_string ("medium");
6721 battery_status_symbol
= empty_unibyte_string
;
6724 if (system_status
.BatteryLifePercent
> 100)
6725 load_percentage
= build_string ("N/A");
6729 snprintf (buffer
, 16, "%d", system_status
.BatteryLifePercent
);
6730 load_percentage
= build_string (buffer
);
6733 if (seconds_left
< 0)
6734 seconds
= minutes
= hours
= remain
= build_string ("N/A");
6740 snprintf (buffer
, 16, "%ld", seconds_left
);
6741 seconds
= build_string (buffer
);
6743 m
= seconds_left
/ 60;
6744 snprintf (buffer
, 16, "%ld", m
);
6745 minutes
= build_string (buffer
);
6747 h
= seconds_left
/ 3600.0;
6748 snprintf (buffer
, 16, "%3.1f", h
);
6749 hours
= build_string (buffer
);
6751 snprintf (buffer
, 16, "%ld:%02ld", m
/ 60, m
% 60);
6752 remain
= build_string (buffer
);
6755 status
= listn (CONSTYPE_HEAP
, 8,
6756 Fcons (make_number ('L'), line_status
),
6757 Fcons (make_number ('B'), battery_status
),
6758 Fcons (make_number ('b'), battery_status_symbol
),
6759 Fcons (make_number ('p'), load_percentage
),
6760 Fcons (make_number ('s'), seconds
),
6761 Fcons (make_number ('m'), minutes
),
6762 Fcons (make_number ('h'), hours
),
6763 Fcons (make_number ('t'), remain
));
6770 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
6771 doc
: /* Return storage information about the file system FILENAME is on.
6772 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
6773 storage of the file system, FREE is the free storage, and AVAIL is the
6774 storage available to a non-superuser. All 3 numbers are in bytes.
6775 If the underlying system call fails, value is nil. */)
6776 (Lisp_Object filename
)
6778 Lisp_Object encoded
, value
;
6780 CHECK_STRING (filename
);
6781 filename
= Fexpand_file_name (filename
, Qnil
);
6782 encoded
= ENCODE_FILE (filename
);
6786 /* Determining the required information on Windows turns out, sadly,
6787 to be more involved than one would hope. The original Windows API
6788 call for this will return bogus information on some systems, but we
6789 must dynamically probe for the replacement api, since that was
6790 added rather late on. */
6792 HMODULE hKernel
= GetModuleHandle ("kernel32");
6793 BOOL (*pfn_GetDiskFreeSpaceEx
)
6794 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
6795 = (void *) GetProcAddress (hKernel
, "GetDiskFreeSpaceEx");
6797 /* On Windows, we may need to specify the root directory of the
6798 volume holding FILENAME. */
6799 char rootname
[MAX_PATH
];
6800 char *name
= SDATA (encoded
);
6802 /* find the root name of the volume if given */
6803 if (isalpha (name
[0]) && name
[1] == ':')
6805 rootname
[0] = name
[0];
6806 rootname
[1] = name
[1];
6810 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
6812 char *str
= rootname
;
6816 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
6826 if (pfn_GetDiskFreeSpaceEx
)
6828 /* Unsigned large integers cannot be cast to double, so
6829 use signed ones instead. */
6830 LARGE_INTEGER availbytes
;
6831 LARGE_INTEGER freebytes
;
6832 LARGE_INTEGER totalbytes
;
6834 if (pfn_GetDiskFreeSpaceEx (rootname
,
6835 (ULARGE_INTEGER
*)&availbytes
,
6836 (ULARGE_INTEGER
*)&totalbytes
,
6837 (ULARGE_INTEGER
*)&freebytes
))
6838 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
6839 make_float ((double) freebytes
.QuadPart
),
6840 make_float ((double) availbytes
.QuadPart
));
6844 DWORD sectors_per_cluster
;
6845 DWORD bytes_per_sector
;
6846 DWORD free_clusters
;
6847 DWORD total_clusters
;
6849 if (GetDiskFreeSpace (rootname
,
6850 §ors_per_cluster
,
6854 value
= list3 (make_float ((double) total_clusters
6855 * sectors_per_cluster
* bytes_per_sector
),
6856 make_float ((double) free_clusters
6857 * sectors_per_cluster
* bytes_per_sector
),
6858 make_float ((double) free_clusters
6859 * sectors_per_cluster
* bytes_per_sector
));
6865 #endif /* WINDOWSNT */
6868 DEFUN ("default-printer-name", Fdefault_printer_name
, Sdefault_printer_name
,
6869 0, 0, 0, doc
: /* Return the name of Windows default printer device. */)
6872 static char pname_buf
[256];
6875 PRINTER_INFO_2
*ppi2
= NULL
;
6876 DWORD dwNeeded
= 0, dwReturned
= 0;
6878 /* Retrieve the default string from Win.ini (the registry).
6879 * String will be in form "printername,drivername,portname".
6880 * This is the most portable way to get the default printer. */
6881 if (GetProfileString ("windows", "device", ",,", pname_buf
, sizeof (pname_buf
)) <= 0)
6883 /* printername precedes first "," character */
6884 strtok (pname_buf
, ",");
6885 /* We want to know more than the printer name */
6886 if (!OpenPrinter (pname_buf
, &hPrn
, NULL
))
6888 GetPrinter (hPrn
, 2, NULL
, 0, &dwNeeded
);
6891 ClosePrinter (hPrn
);
6894 /* Allocate memory for the PRINTER_INFO_2 struct */
6895 ppi2
= xmalloc (dwNeeded
);
6898 ClosePrinter (hPrn
);
6901 /* Call GetPrinter again with big enough memory block. */
6902 err
= GetPrinter (hPrn
, 2, (LPBYTE
)ppi2
, dwNeeded
, &dwReturned
);
6903 ClosePrinter (hPrn
);
6912 if (ppi2
->Attributes
& PRINTER_ATTRIBUTE_SHARED
&& ppi2
->pServerName
)
6914 /* a remote printer */
6915 if (*ppi2
->pServerName
== '\\')
6916 snprintf (pname_buf
, sizeof (pname_buf
), "%s\\%s", ppi2
->pServerName
,
6919 snprintf (pname_buf
, sizeof (pname_buf
), "\\\\%s\\%s", ppi2
->pServerName
,
6921 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
6925 /* a local printer */
6926 strncpy (pname_buf
, ppi2
->pPortName
, sizeof (pname_buf
));
6927 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
6928 /* `pPortName' can include several ports, delimited by ','.
6929 * we only use the first one. */
6930 strtok (pname_buf
, ",");
6935 return build_string (pname_buf
);
6939 /* Equivalent of strerror for W32 error codes. */
6941 w32_strerror (int error_no
)
6943 static char buf
[500];
6947 error_no
= GetLastError ();
6949 ret
= FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
|
6950 FORMAT_MESSAGE_IGNORE_INSERTS
,
6953 0, /* choose most suitable language */
6954 buf
, sizeof (buf
), NULL
);
6956 while (ret
> 0 && (buf
[ret
- 1] == '\n' ||
6957 buf
[ret
- 1] == '\r' ))
6961 sprintf (buf
, "w32 error %u", error_no
);
6966 /* For convenience when debugging. (You cannot call GetLastError
6967 directly from GDB: it will crash, because it uses the __stdcall
6968 calling convention, not the _cdecl convention assumed by GDB.) */
6970 w32_last_error (void)
6972 return GetLastError ();
6975 /* Cache information describing the NT system for later use. */
6977 cache_system_info (void)
6990 /* Cache the module handle of Emacs itself. */
6991 hinst
= GetModuleHandle (NULL
);
6993 /* Cache the version of the operating system. */
6994 version
.data
= GetVersion ();
6995 w32_major_version
= version
.info
.major
;
6996 w32_minor_version
= version
.info
.minor
;
6998 if (version
.info
.platform
& 0x8000)
7003 /* Cache page size, allocation unit, processor type, etc. */
7004 GetSystemInfo (&sysinfo_cache
);
7005 syspage_mask
= (DWORD_PTR
)sysinfo_cache
.dwPageSize
- 1;
7007 /* Cache os info. */
7008 osinfo_cache
.dwOSVersionInfoSize
= sizeof (OSVERSIONINFO
);
7009 GetVersionEx (&osinfo_cache
);
7011 w32_build_number
= osinfo_cache
.dwBuildNumber
;
7012 if (os_subtype
== OS_9X
)
7013 w32_build_number
&= 0xffff;
7015 w32_num_mouse_buttons
= GetSystemMetrics (SM_CMOUSEBUTTONS
);
7020 _DebPrint (const char *fmt
, ...)
7025 va_start (args
, fmt
);
7026 vsprintf (buf
, fmt
, args
);
7029 fprintf (stderr
, "%s", buf
);
7031 OutputDebugString (buf
);
7036 w32_console_toggle_lock_key (int vk_code
, Lisp_Object new_state
)
7038 int cur_state
= (GetKeyState (vk_code
) & 1);
7040 if (NILP (new_state
)
7041 || (NUMBERP (new_state
)
7042 && ((XUINT (new_state
)) & 1) != cur_state
))
7045 faked_key
= vk_code
;
7046 #endif /* WINDOWSNT */
7048 keybd_event ((BYTE
) vk_code
,
7049 (BYTE
) MapVirtualKey (vk_code
, 0),
7050 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
7051 keybd_event ((BYTE
) vk_code
,
7052 (BYTE
) MapVirtualKey (vk_code
, 0),
7053 KEYEVENTF_EXTENDEDKEY
| 0, 0);
7054 keybd_event ((BYTE
) vk_code
,
7055 (BYTE
) MapVirtualKey (vk_code
, 0),
7056 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
7057 cur_state
= !cur_state
;
7063 /* Translate console modifiers to emacs modifiers.
7064 German keyboard support (Kai Morgan Zeise 2/18/95). */
7066 w32_kbd_mods_to_emacs (DWORD mods
, WORD key
)
7070 /* If we recognize right-alt and left-ctrl as AltGr, and it has been
7071 pressed, first remove those modifiers. */
7072 if (!NILP (Vw32_recognize_altgr
)
7073 && (mods
& (RIGHT_ALT_PRESSED
| LEFT_CTRL_PRESSED
))
7074 == (RIGHT_ALT_PRESSED
| LEFT_CTRL_PRESSED
))
7075 mods
&= ~ (RIGHT_ALT_PRESSED
| LEFT_CTRL_PRESSED
);
7077 if (mods
& (RIGHT_ALT_PRESSED
| LEFT_ALT_PRESSED
))
7078 retval
= ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
);
7080 if (mods
& (RIGHT_CTRL_PRESSED
| LEFT_CTRL_PRESSED
))
7082 retval
|= ctrl_modifier
;
7083 if ((mods
& (RIGHT_CTRL_PRESSED
| LEFT_CTRL_PRESSED
))
7084 == (RIGHT_CTRL_PRESSED
| LEFT_CTRL_PRESSED
))
7085 retval
|= meta_modifier
;
7088 if (mods
& LEFT_WIN_PRESSED
)
7089 retval
|= w32_key_to_modifier (VK_LWIN
);
7090 if (mods
& RIGHT_WIN_PRESSED
)
7091 retval
|= w32_key_to_modifier (VK_RWIN
);
7092 if (mods
& APPS_PRESSED
)
7093 retval
|= w32_key_to_modifier (VK_APPS
);
7094 if (mods
& SCROLLLOCK_ON
)
7095 retval
|= w32_key_to_modifier (VK_SCROLL
);
7097 /* Just in case someone wanted the original behavior, make it
7098 optional by setting w32-capslock-is-shiftlock to t. */
7099 if (NILP (Vw32_capslock_is_shiftlock
)
7100 /* Keys that should _not_ be affected by CapsLock. */
7101 && ( (key
== VK_BACK
)
7103 || (key
== VK_CLEAR
)
7104 || (key
== VK_RETURN
)
7105 || (key
== VK_ESCAPE
)
7106 || ((key
>= VK_SPACE
) && (key
<= VK_HELP
))
7107 || ((key
>= VK_NUMPAD0
) && (key
<= VK_F24
))
7108 || ((key
>= VK_NUMPAD_CLEAR
) && (key
<= VK_NUMPAD_DELETE
))
7111 /* Only consider shift state. */
7112 if ((mods
& SHIFT_PRESSED
) != 0)
7113 retval
|= shift_modifier
;
7117 /* Ignore CapsLock state if not enabled. */
7118 if (NILP (Vw32_enable_caps_lock
))
7119 mods
&= ~CAPSLOCK_ON
;
7120 if ((mods
& (SHIFT_PRESSED
| CAPSLOCK_ON
)) != 0)
7121 retval
|= shift_modifier
;
7127 /* The return code indicates key code size. cpID is the codepage to
7128 use for translation to Unicode; -1 means use the current console
7131 w32_kbd_patch_key (KEY_EVENT_RECORD
*event
, int cpId
)
7133 unsigned int key_code
= event
->wVirtualKeyCode
;
7134 unsigned int mods
= event
->dwControlKeyState
;
7136 static BYTE ansi_code
[4];
7137 static int isdead
= 0;
7141 event
->uChar
.AsciiChar
= ansi_code
[2];
7145 if (event
->uChar
.AsciiChar
!= 0)
7148 memset (keystate
, 0, sizeof (keystate
));
7149 keystate
[key_code
] = 0x80;
7150 if (mods
& SHIFT_PRESSED
)
7151 keystate
[VK_SHIFT
] = 0x80;
7152 if (mods
& CAPSLOCK_ON
)
7153 keystate
[VK_CAPITAL
] = 1;
7154 /* If we recognize right-alt and left-ctrl as AltGr, set the key
7155 states accordingly before invoking ToAscii. */
7156 if (!NILP (Vw32_recognize_altgr
)
7157 && (mods
& LEFT_CTRL_PRESSED
) && (mods
& RIGHT_ALT_PRESSED
))
7159 keystate
[VK_CONTROL
] = 0x80;
7160 keystate
[VK_LCONTROL
] = 0x80;
7161 keystate
[VK_MENU
] = 0x80;
7162 keystate
[VK_RMENU
] = 0x80;
7166 /* Because of an OS bug, ToAscii corrupts the stack when called to
7167 convert a dead key in console mode on NT4. Unfortunately, trying
7168 to check for dead keys using MapVirtualKey doesn't work either -
7169 these functions apparently use internal information about keyboard
7170 layout which doesn't get properly updated in console programs when
7171 changing layout (though apparently it gets partly updated,
7172 otherwise ToAscii wouldn't crash). */
7173 if (is_dead_key (event
->wVirtualKeyCode
))
7177 /* On NT, call ToUnicode instead and then convert to the current
7178 console input codepage. */
7179 if (os_subtype
== OS_NT
)
7183 isdead
= ToUnicode (event
->wVirtualKeyCode
, event
->wVirtualScanCode
,
7184 keystate
, buf
, 128, 0);
7187 /* When we are called from the GUI message processing code,
7188 we are passed the current keyboard codepage, a positive
7189 number, to use below. */
7191 cpId
= GetConsoleCP ();
7193 event
->uChar
.UnicodeChar
= buf
[isdead
- 1];
7194 isdead
= WideCharToMultiByte (cpId
, 0, buf
, isdead
,
7195 ansi_code
, 4, NULL
, NULL
);
7202 isdead
= ToAscii (event
->wVirtualKeyCode
, event
->wVirtualScanCode
,
7203 keystate
, (LPWORD
) ansi_code
, 0);
7208 event
->uChar
.AsciiChar
= ansi_code
[0];
7214 w32_sys_ring_bell (struct frame
*f
)
7216 if (sound_type
== 0xFFFFFFFF)
7220 else if (sound_type
== MB_EMACS_SILENT
)
7225 MessageBeep (sound_type
);
7229 /***********************************************************************
7231 ***********************************************************************/
7233 /* Keep this list in the same order as frame_parms in frame.c.
7234 Use 0 for unsupported frame parameters. */
7236 frame_parm_handler w32_frame_parm_handlers
[] =
7240 x_set_background_color
,
7246 x_set_foreground_color
,
7249 x_set_internal_border_width
,
7250 x_set_menu_bar_lines
,
7252 x_explicitly_set_name
,
7253 x_set_scroll_bar_width
,
7256 x_set_vertical_scroll_bars
,
7258 x_set_tool_bar_lines
,
7259 0, /* x_set_scroll_bar_foreground, */
7260 0, /* x_set_scroll_bar_background, */
7265 0, /* x_set_wait_for_wm, */
7269 0, /* x_set_sticky */
7270 0, /* x_set_tool_bar_position */
7274 syms_of_w32fns (void)
7276 globals_of_w32fns ();
7277 track_mouse_window
= NULL
;
7279 w32_visible_system_caret_hwnd
= NULL
;
7281 DEFSYM (Qsuppress_icon
, "suppress-icon");
7282 DEFSYM (Qundefined_color
, "undefined-color");
7283 DEFSYM (Qcancel_timer
, "cancel-timer");
7284 DEFSYM (Qhyper
, "hyper");
7285 DEFSYM (Qsuper
, "super");
7286 DEFSYM (Qmeta
, "meta");
7287 DEFSYM (Qalt
, "alt");
7288 DEFSYM (Qctrl
, "ctrl");
7289 DEFSYM (Qcontrol
, "control");
7290 DEFSYM (Qshift
, "shift");
7291 DEFSYM (Qfont_param
, "font-parameter");
7292 /* This is the end of symbol initialization. */
7295 Fput (Qundefined_color
, Qerror_conditions
,
7296 listn (CONSTYPE_PURE
, 2, Qundefined_color
, Qerror
));
7297 Fput (Qundefined_color
, Qerror_message
,
7298 build_pure_c_string ("Undefined color"));
7300 staticpro (&w32_grabbed_keys
);
7301 w32_grabbed_keys
= Qnil
;
7303 DEFVAR_LISP ("w32-color-map", Vw32_color_map
,
7304 doc
: /* An array of color name mappings for Windows. */);
7305 Vw32_color_map
= Qnil
;
7307 DEFVAR_LISP ("w32-pass-alt-to-system", Vw32_pass_alt_to_system
,
7308 doc
: /* Non-nil if Alt key presses are passed on to Windows.
7309 When non-nil, for example, Alt pressed and released and then space will
7310 open the System menu. When nil, Emacs processes the Alt key events, and
7311 then silently swallows them. */);
7312 Vw32_pass_alt_to_system
= Qnil
;
7314 DEFVAR_LISP ("w32-alt-is-meta", Vw32_alt_is_meta
,
7315 doc
: /* Non-nil if the Alt key is to be considered the same as the META key.
7316 When nil, Emacs will translate the Alt key to the ALT modifier, not to META. */);
7317 Vw32_alt_is_meta
= Qt
;
7319 DEFVAR_INT ("w32-quit-key", w32_quit_key
,
7320 doc
: /* If non-zero, the virtual key code for an alternative quit key. */);
7323 DEFVAR_LISP ("w32-pass-lwindow-to-system",
7324 Vw32_pass_lwindow_to_system
,
7325 doc
: /* If non-nil, the left \"Windows\" key is passed on to Windows.
7327 When non-nil, the Start menu is opened by tapping the key.
7328 If you set this to nil, the left \"Windows\" key is processed by Emacs
7329 according to the value of `w32-lwindow-modifier', which see.
7331 Note that some combinations of the left \"Windows\" key with other keys are
7332 caught by Windows at low level, and so binding them in Emacs will have no
7333 effect. For example, <lwindow>-r always pops up the Windows Run dialog,
7334 <lwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
7335 the doc string of `w32-phantom-key-code'. */);
7336 Vw32_pass_lwindow_to_system
= Qt
;
7338 DEFVAR_LISP ("w32-pass-rwindow-to-system",
7339 Vw32_pass_rwindow_to_system
,
7340 doc
: /* If non-nil, the right \"Windows\" key is passed on to Windows.
7342 When non-nil, the Start menu is opened by tapping the key.
7343 If you set this to nil, the right \"Windows\" key is processed by Emacs
7344 according to the value of `w32-rwindow-modifier', which see.
7346 Note that some combinations of the right \"Windows\" key with other keys are
7347 caught by Windows at low level, and so binding them in Emacs will have no
7348 effect. For example, <rwindow>-r always pops up the Windows Run dialog,
7349 <rwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
7350 the doc string of `w32-phantom-key-code'. */);
7351 Vw32_pass_rwindow_to_system
= Qt
;
7353 DEFVAR_LISP ("w32-phantom-key-code",
7354 Vw32_phantom_key_code
,
7355 doc
: /* Virtual key code used to generate \"phantom\" key presses.
7356 Value is a number between 0 and 255.
7358 Phantom key presses are generated in order to stop the system from
7359 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or
7360 `w32-pass-rwindow-to-system' is nil. */);
7361 /* Although 255 is technically not a valid key code, it works and
7362 means that this hack won't interfere with any real key code. */
7363 XSETINT (Vw32_phantom_key_code
, 255);
7365 DEFVAR_LISP ("w32-enable-num-lock",
7366 Vw32_enable_num_lock
,
7367 doc
: /* If non-nil, the Num Lock key acts normally.
7368 Set to nil to handle Num Lock as the `kp-numlock' key. */);
7369 Vw32_enable_num_lock
= Qt
;
7371 DEFVAR_LISP ("w32-enable-caps-lock",
7372 Vw32_enable_caps_lock
,
7373 doc
: /* If non-nil, the Caps Lock key acts normally.
7374 Set to nil to handle Caps Lock as the `capslock' key. */);
7375 Vw32_enable_caps_lock
= Qt
;
7377 DEFVAR_LISP ("w32-scroll-lock-modifier",
7378 Vw32_scroll_lock_modifier
,
7379 doc
: /* Modifier to use for the Scroll Lock ON state.
7380 The value can be hyper, super, meta, alt, control or shift for the
7381 respective modifier, or nil to handle Scroll Lock as the `scroll' key.
7382 Any other value will cause the Scroll Lock key to be ignored. */);
7383 Vw32_scroll_lock_modifier
= Qnil
;
7385 DEFVAR_LISP ("w32-lwindow-modifier",
7386 Vw32_lwindow_modifier
,
7387 doc
: /* Modifier to use for the left \"Windows\" key.
7388 The value can be hyper, super, meta, alt, control or shift for the
7389 respective modifier, or nil to appear as the `lwindow' key.
7390 Any other value will cause the key to be ignored. */);
7391 Vw32_lwindow_modifier
= Qnil
;
7393 DEFVAR_LISP ("w32-rwindow-modifier",
7394 Vw32_rwindow_modifier
,
7395 doc
: /* Modifier to use for the right \"Windows\" key.
7396 The value can be hyper, super, meta, alt, control or shift for the
7397 respective modifier, or nil to appear as the `rwindow' key.
7398 Any other value will cause the key to be ignored. */);
7399 Vw32_rwindow_modifier
= Qnil
;
7401 DEFVAR_LISP ("w32-apps-modifier",
7403 doc
: /* Modifier to use for the \"Apps\" key.
7404 The value can be hyper, super, meta, alt, control or shift for the
7405 respective modifier, or nil to appear as the `apps' key.
7406 Any other value will cause the key to be ignored. */);
7407 Vw32_apps_modifier
= Qnil
;
7409 DEFVAR_BOOL ("w32-enable-synthesized-fonts", w32_enable_synthesized_fonts
,
7410 doc
: /* Non-nil enables selection of artificially italicized and bold fonts. */);
7411 w32_enable_synthesized_fonts
= 0;
7413 DEFVAR_LISP ("w32-enable-palette", Vw32_enable_palette
,
7414 doc
: /* Non-nil enables Windows palette management to map colors exactly. */);
7415 Vw32_enable_palette
= Qt
;
7417 DEFVAR_INT ("w32-mouse-button-tolerance",
7418 w32_mouse_button_tolerance
,
7419 doc
: /* Analogue of double click interval for faking middle mouse events.
7420 The value is the minimum time in milliseconds that must elapse between
7421 left and right button down events before they are considered distinct events.
7422 If both mouse buttons are depressed within this interval, a middle mouse
7423 button down event is generated instead. */);
7424 w32_mouse_button_tolerance
= GetDoubleClickTime () / 2;
7426 DEFVAR_INT ("w32-mouse-move-interval",
7427 w32_mouse_move_interval
,
7428 doc
: /* Minimum interval between mouse move events.
7429 The value is the minimum time in milliseconds that must elapse between
7430 successive mouse move (or scroll bar drag) events before they are
7431 reported as lisp events. */);
7432 w32_mouse_move_interval
= 0;
7434 DEFVAR_BOOL ("w32-pass-extra-mouse-buttons-to-system",
7435 w32_pass_extra_mouse_buttons_to_system
,
7436 doc
: /* If non-nil, the fourth and fifth mouse buttons are passed to Windows.
7437 Recent versions of Windows support mice with up to five buttons.
7438 Since most applications don't support these extra buttons, most mouse
7439 drivers will allow you to map them to functions at the system level.
7440 If this variable is non-nil, Emacs will pass them on, allowing the
7441 system to handle them. */);
7442 w32_pass_extra_mouse_buttons_to_system
= 0;
7444 DEFVAR_BOOL ("w32-pass-multimedia-buttons-to-system",
7445 w32_pass_multimedia_buttons_to_system
,
7446 doc
: /* If non-nil, media buttons are passed to Windows.
7447 Some modern keyboards contain buttons for controlling media players, web
7448 browsers and other applications. Generally these buttons are handled on a
7449 system wide basis, but by setting this to nil they are made available
7450 to Emacs for binding. Depending on your keyboard, additional keys that
7451 may be available are:
7453 browser-back, browser-forward, browser-refresh, browser-stop,
7454 browser-search, browser-favorites, browser-home,
7455 mail, mail-reply, mail-forward, mail-send,
7457 help, find, new, open, close, save, print, undo, redo, copy, cut, paste,
7458 spell-check, correction-list, toggle-dictate-command,
7459 media-next, media-previous, media-stop, media-play-pause, media-select,
7460 media-play, media-pause, media-record, media-fast-forward, media-rewind,
7461 media-channel-up, media-channel-down,
7462 volume-mute, volume-up, volume-down,
7463 mic-volume-mute, mic-volume-down, mic-volume-up, mic-toggle,
7464 bass-down, bass-boost, bass-up, treble-down, treble-up */);
7465 w32_pass_multimedia_buttons_to_system
= 1;
7467 #if 0 /* TODO: Mouse cursor customization. */
7468 DEFVAR_LISP ("x-pointer-shape", Vx_pointer_shape
,
7469 doc
: /* The shape of the pointer when over text.
7470 Changing the value does not affect existing frames
7471 unless you set the mouse color. */);
7472 Vx_pointer_shape
= Qnil
;
7474 Vx_nontext_pointer_shape
= Qnil
;
7476 Vx_mode_pointer_shape
= Qnil
;
7478 DEFVAR_LISP ("x-hourglass-pointer-shape", Vx_hourglass_pointer_shape
,
7479 doc
: /* The shape of the pointer when Emacs is busy.
7480 This variable takes effect when you create a new frame
7481 or when you set the mouse color. */);
7482 Vx_hourglass_pointer_shape
= Qnil
;
7484 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
7485 Vx_sensitive_text_pointer_shape
,
7486 doc
: /* The shape of the pointer when over mouse-sensitive text.
7487 This variable takes effect when you create a new frame
7488 or when you set the mouse color. */);
7489 Vx_sensitive_text_pointer_shape
= Qnil
;
7491 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
7492 Vx_window_horizontal_drag_shape
,
7493 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
7494 This variable takes effect when you create a new frame
7495 or when you set the mouse color. */);
7496 Vx_window_horizontal_drag_shape
= Qnil
;
7499 DEFVAR_LISP ("x-cursor-fore-pixel", Vx_cursor_fore_pixel
,
7500 doc
: /* A string indicating the foreground color of the cursor box. */);
7501 Vx_cursor_fore_pixel
= Qnil
;
7503 DEFVAR_LISP ("x-max-tooltip-size", Vx_max_tooltip_size
,
7504 doc
: /* Maximum size for tooltips.
7505 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
7506 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
7508 DEFVAR_LISP ("x-no-window-manager", Vx_no_window_manager
,
7509 doc
: /* Non-nil if no window manager is in use.
7510 Emacs doesn't try to figure this out; this is always nil
7511 unless you set it to something else. */);
7512 /* We don't have any way to find this out, so set it to nil
7513 and maybe the user would like to set it to t. */
7514 Vx_no_window_manager
= Qnil
;
7516 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
7517 Vx_pixel_size_width_font_regexp
,
7518 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
7520 Since Emacs gets width of a font matching with this regexp from
7521 PIXEL_SIZE field of the name, font finding mechanism gets faster for
7522 such a font. This is especially effective for such large fonts as
7523 Chinese, Japanese, and Korean. */);
7524 Vx_pixel_size_width_font_regexp
= Qnil
;
7526 DEFVAR_LISP ("w32-bdf-filename-alist",
7527 Vw32_bdf_filename_alist
,
7528 doc
: /* List of bdf fonts and their corresponding filenames. */);
7529 Vw32_bdf_filename_alist
= Qnil
;
7531 DEFVAR_BOOL ("w32-strict-fontnames",
7532 w32_strict_fontnames
,
7533 doc
: /* Non-nil means only use fonts that are exact matches for those requested.
7534 Default is nil, which allows old fontnames that are not XLFD compliant,
7535 and allows third-party CJK display to work by specifying false charset
7536 fields to trick Emacs into translating to Big5, SJIS etc.
7537 Setting this to t will prevent wrong fonts being selected when
7538 fontsets are automatically created. */);
7539 w32_strict_fontnames
= 0;
7541 DEFVAR_BOOL ("w32-strict-painting",
7542 w32_strict_painting
,
7543 doc
: /* Non-nil means use strict rules for repainting frames.
7544 Set this to nil to get the old behavior for repainting; this should
7545 only be necessary if the default setting causes problems. */);
7546 w32_strict_painting
= 1;
7548 #if 0 /* TODO: Port to W32 */
7549 defsubr (&Sx_change_window_property
);
7550 defsubr (&Sx_delete_window_property
);
7551 defsubr (&Sx_window_property
);
7553 defsubr (&Sxw_display_color_p
);
7554 defsubr (&Sx_display_grayscale_p
);
7555 defsubr (&Sxw_color_defined_p
);
7556 defsubr (&Sxw_color_values
);
7557 defsubr (&Sx_server_max_request_size
);
7558 defsubr (&Sx_server_vendor
);
7559 defsubr (&Sx_server_version
);
7560 defsubr (&Sx_display_pixel_width
);
7561 defsubr (&Sx_display_pixel_height
);
7562 defsubr (&Sx_display_mm_width
);
7563 defsubr (&Sx_display_mm_height
);
7564 defsubr (&Sx_display_screens
);
7565 defsubr (&Sx_display_planes
);
7566 defsubr (&Sx_display_color_cells
);
7567 defsubr (&Sx_display_visual_class
);
7568 defsubr (&Sx_display_backing_store
);
7569 defsubr (&Sx_display_save_under
);
7570 defsubr (&Sx_create_frame
);
7571 defsubr (&Sx_open_connection
);
7572 defsubr (&Sx_close_connection
);
7573 defsubr (&Sx_display_list
);
7574 defsubr (&Sx_synchronize
);
7575 defsubr (&Sx_focus_frame
);
7577 /* W32 specific functions */
7579 defsubr (&Sw32_define_rgb_color
);
7580 defsubr (&Sw32_default_color_map
);
7581 defsubr (&Sw32_send_sys_command
);
7582 defsubr (&Sw32_shell_execute
);
7583 defsubr (&Sw32_register_hot_key
);
7584 defsubr (&Sw32_unregister_hot_key
);
7585 defsubr (&Sw32_registered_hot_keys
);
7586 defsubr (&Sw32_reconstruct_hot_key
);
7587 defsubr (&Sw32_toggle_lock_key
);
7588 defsubr (&Sw32_window_exists_p
);
7589 defsubr (&Sw32_battery_status
);
7592 defsubr (&Sfile_system_info
);
7595 defsubr (&Sdefault_printer_name
);
7596 defsubr (&Sset_message_beep
);
7598 hourglass_hwnd
= NULL
;
7600 defsubr (&Sx_show_tip
);
7601 defsubr (&Sx_hide_tip
);
7603 staticpro (&tip_timer
);
7605 staticpro (&tip_frame
);
7607 last_show_tip_args
= Qnil
;
7608 staticpro (&last_show_tip_args
);
7610 defsubr (&Sx_file_dialog
);
7612 defsubr (&Ssystem_move_file_to_trash
);
7618 globals_of_w32fns is used to initialize those global variables that
7619 must always be initialized on startup even when the global variable
7620 initialized is non zero (see the function main in emacs.c).
7621 globals_of_w32fns is called from syms_of_w32fns when the global
7622 variable initialized is 0 and directly from main when initialized
7626 globals_of_w32fns (void)
7628 HMODULE user32_lib
= GetModuleHandle ("user32.dll");
7630 TrackMouseEvent not available in all versions of Windows, so must load
7631 it dynamically. Do it once, here, instead of every time it is used.
7633 track_mouse_event_fn
= (TrackMouseEvent_Proc
)
7634 GetProcAddress (user32_lib
, "TrackMouseEvent");
7636 monitor_from_point_fn
= (MonitorFromPoint_Proc
)
7637 GetProcAddress (user32_lib
, "MonitorFromPoint");
7638 get_monitor_info_fn
= (GetMonitorInfo_Proc
)
7639 GetProcAddress (user32_lib
, "GetMonitorInfoA");
7642 HMODULE imm32_lib
= GetModuleHandle ("imm32.dll");
7643 get_composition_string_fn
= (ImmGetCompositionString_Proc
)
7644 GetProcAddress (imm32_lib
, "ImmGetCompositionStringW");
7645 get_ime_context_fn
= (ImmGetContext_Proc
)
7646 GetProcAddress (imm32_lib
, "ImmGetContext");
7647 release_ime_context_fn
= (ImmReleaseContext_Proc
)
7648 GetProcAddress (imm32_lib
, "ImmReleaseContext");
7649 set_ime_composition_window_fn
= (ImmSetCompositionWindow_Proc
)
7650 GetProcAddress (imm32_lib
, "ImmSetCompositionWindow");
7652 DEFVAR_INT ("w32-ansi-code-page",
7654 doc
: /* The ANSI code page used by the system. */);
7655 w32_ansi_code_page
= GetACP ();
7657 if (os_subtype
== OS_NT
)
7658 w32_unicode_gui
= 1;
7660 w32_unicode_gui
= 0;
7662 /* MessageBox does not work without this when linked to comctl32.dll 6.0. */
7663 InitCommonControls ();
7665 syms_of_w32uniscribe ();
7668 typedef USHORT (WINAPI
* CaptureStackBackTrace_proc
) (ULONG
, ULONG
, PVOID
*,
7671 #define BACKTRACE_LIMIT_MAX 62
7674 w32_backtrace (void **buffer
, int limit
)
7676 static CaptureStackBackTrace_proc s_pfn_CaptureStackBackTrace
= NULL
;
7677 HMODULE hm_kernel32
= NULL
;
7679 if (!s_pfn_CaptureStackBackTrace
)
7681 hm_kernel32
= LoadLibrary ("Kernel32.dll");
7682 s_pfn_CaptureStackBackTrace
=
7683 (CaptureStackBackTrace_proc
) GetProcAddress (hm_kernel32
,
7684 "RtlCaptureStackBackTrace");
7686 if (s_pfn_CaptureStackBackTrace
)
7687 return s_pfn_CaptureStackBackTrace (0, min (BACKTRACE_LIMIT_MAX
, limit
),
7696 button
= MessageBox (NULL
,
7697 "A fatal error has occurred!\n\n"
7698 "Would you like to attach a debugger?\n\n"
7700 "YES -- to debug Emacs, or\n"
7701 "NO -- to abort Emacs and produce a backtrace\n"
7702 " (emacs_backtrace.txt in current directory)."
7704 "\n\n(type \"gdb -p <emacs-PID>\" and\n"
7705 "\"continue\" inside GDB before clicking YES.)"
7707 , "Emacs Abort Dialog",
7708 MB_ICONEXCLAMATION
| MB_TASKMODAL
7709 | MB_SETFOREGROUND
| MB_YESNO
);
7714 exit (2); /* tell the compiler we will never return */
7718 void *stack
[BACKTRACE_LIMIT_MAX
+ 1];
7719 int i
= w32_backtrace (stack
, BACKTRACE_LIMIT_MAX
+ 1);
7726 HANDLE errout
= GetStdHandle (STD_ERROR_HANDLE
);
7729 int errfile_fd
= -1;
7733 if (errout
&& errout
!= INVALID_HANDLE_VALUE
)
7734 stderr_fd
= _open_osfhandle ((intptr_t)errout
, O_APPEND
| O_BINARY
);
7737 write (stderr_fd
, "\r\nBacktrace:\r\n", 14);
7741 errfile_fd
= _open ("emacs_backtrace.txt", O_RDWR
| O_CREAT
| O_BINARY
, S_IREAD
| S_IWRITE
);
7742 if (errfile_fd
>= 0)
7744 lseek (errfile_fd
, 0L, SEEK_END
);
7745 write (errfile_fd
, "\r\nBacktrace:\r\n", 14);
7748 for (j
= 0; j
< i
; j
++)
7750 char buf
[INT_BUFSIZE_BOUND (void *)];
7752 /* stack[] gives the return addresses, whereas we want
7753 the address of the call, so decrease each address
7754 by approximate size of 1 CALL instruction. */
7755 sprintf (buf
, "0x%p\r\n", (char *)stack
[j
] - sizeof(void *));
7757 write (stderr_fd
, buf
, strlen (buf
));
7758 if (errfile_fd
>= 0)
7759 write (errfile_fd
, buf
, strlen (buf
));
7761 if (i
== BACKTRACE_LIMIT_MAX
)
7764 write (stderr_fd
, "...\r\n", 5);
7765 if (errfile_fd
>= 0)
7766 write (errfile_fd
, "...\r\n", 5);
7768 if (errfile_fd
>= 0)
7777 #ifdef NTGUI_UNICODE
7780 ntgui_encode_system (Lisp_Object str
)
7782 Lisp_Object encoded
;
7783 to_unicode (str
, &encoded
);
7787 #endif /* NTGUI_UNICODE */