1 /* Graphical user interface functions for the Microsoft Windows API.
3 Copyright (C) 1989, 1992-2012 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 double atof (const char *);
86 extern int w32_console_toggle_lock_key (int, Lisp_Object
);
87 extern void w32_menu_display_help (HWND
, HMENU
, UINT
, UINT
);
88 extern void w32_free_menu_strings (HWND
);
89 extern const char *map_w32_filename (const char *, const char **);
90 extern char * w32_strerror (int error_no
);
92 /* If non-NULL, a handle to a frame where to display the hourglass cursor. */
93 static HWND hourglass_hwnd
= NULL
;
96 #define IDC_HAND MAKEINTRESOURCE(32649)
99 /* Nonzero if using Windows. */
101 static int w32_in_use
;
103 Lisp_Object Qsuppress_icon
;
104 Lisp_Object Qundefined_color
;
105 Lisp_Object Qcancel_timer
;
106 Lisp_Object Qfont_param
;
112 Lisp_Object Qcontrol
;
116 /* Prefix for system colors. */
117 #define SYSTEM_COLOR_PREFIX "System"
118 #define SYSTEM_COLOR_PREFIX_LEN (sizeof (SYSTEM_COLOR_PREFIX) - 1)
120 /* State variables for emulating a three button mouse. */
125 static int button_state
= 0;
126 static W32Msg saved_mouse_button_msg
;
127 static unsigned mouse_button_timer
= 0; /* non-zero when timer is active */
128 static W32Msg saved_mouse_move_msg
;
129 static unsigned mouse_move_timer
= 0;
131 /* Window that is tracking the mouse. */
132 static HWND track_mouse_window
;
134 /* Multi-monitor API definitions that are not pulled from the headers
135 since we are compiling for NT 4. */
136 #ifndef MONITOR_DEFAULT_TO_NEAREST
137 #define MONITOR_DEFAULT_TO_NEAREST 2
139 /* MinGW headers define MONITORINFO unconditionally, but MSVC ones don't.
140 To avoid a compile error on one or the other, redefine with a new name. */
149 /* Reportedly, MSVC does not have this in its headers. */
150 #if defined (_MSC_VER) && _WIN32_WINNT < 0x0500
151 DECLARE_HANDLE(HMONITOR
);
154 typedef BOOL (WINAPI
* TrackMouseEvent_Proc
)
155 (IN OUT LPTRACKMOUSEEVENT lpEventTrack
);
156 typedef LONG (WINAPI
* ImmGetCompositionString_Proc
)
157 (IN HIMC context
, IN DWORD index
, OUT LPVOID buffer
, IN DWORD bufLen
);
158 typedef HIMC (WINAPI
* ImmGetContext_Proc
) (IN HWND window
);
159 typedef HWND (WINAPI
* ImmReleaseContext_Proc
) (IN HWND wnd
, IN HIMC context
);
160 typedef HWND (WINAPI
* ImmSetCompositionWindow_Proc
) (IN HIMC context
,
161 IN COMPOSITIONFORM
*form
);
162 typedef HMONITOR (WINAPI
* MonitorFromPoint_Proc
) (IN POINT pt
, IN DWORD flags
);
163 typedef BOOL (WINAPI
* GetMonitorInfo_Proc
)
164 (IN HMONITOR monitor
, OUT
struct MONITOR_INFO
* info
);
166 TrackMouseEvent_Proc track_mouse_event_fn
= NULL
;
167 ImmGetCompositionString_Proc get_composition_string_fn
= NULL
;
168 ImmGetContext_Proc get_ime_context_fn
= NULL
;
169 ImmReleaseContext_Proc release_ime_context_fn
= NULL
;
170 ImmSetCompositionWindow_Proc set_ime_composition_window_fn
= NULL
;
171 MonitorFromPoint_Proc monitor_from_point_fn
= NULL
;
172 GetMonitorInfo_Proc get_monitor_info_fn
= NULL
;
175 #define unicode_append_menu AppendMenuW
176 #else /* !NTGUI_UNICODE */
177 extern AppendMenuW_Proc unicode_append_menu
;
178 #endif /* NTGUI_UNICODE */
180 /* Flag to selectively ignore WM_IME_CHAR messages. */
181 static int ignore_ime_char
= 0;
183 /* W95 mousewheel handler */
184 unsigned int msh_mousewheel
= 0;
187 #define MOUSE_BUTTON_ID 1
188 #define MOUSE_MOVE_ID 2
189 #define MENU_FREE_ID 3
190 /* The delay (milliseconds) before a menu is freed after WM_EXITMENULOOP
192 #define MENU_FREE_DELAY 1000
193 static unsigned menu_free_timer
= 0;
196 static int image_cache_refcount
, dpyinfo_refcount
;
199 static HWND w32_visible_system_caret_hwnd
;
201 static int w32_unicode_gui
;
204 extern HMENU current_popup_menu
;
205 static int menubar_in_use
= 0;
207 /* From w32uniscribe.c */
208 extern void syms_of_w32uniscribe (void);
209 extern int uniscribe_available
;
211 /* Function prototypes for hourglass support. */
212 static void w32_show_hourglass (struct frame
*);
213 static void w32_hide_hourglass (void);
216 /* From w32inevt.c */
217 extern int faked_key
;
218 #endif /* WINDOWSNT */
220 /* This gives us the page size and the size of the allocation unit on NT. */
221 SYSTEM_INFO sysinfo_cache
;
223 /* This gives us version, build, and platform identification. */
224 OSVERSIONINFO osinfo_cache
;
226 unsigned long syspage_mask
= 0;
228 /* The major and minor versions of NT. */
229 int w32_major_version
;
230 int w32_minor_version
;
231 int w32_build_number
;
233 /* Distinguish between Windows NT and Windows 95. */
237 HINSTANCE hinst
= NULL
;
240 static unsigned int sound_type
= 0xFFFFFFFF;
241 #define MB_EMACS_SILENT (0xFFFFFFFF - 1)
244 /* Error if we are not connected to MS-Windows. */
249 error ("MS-Windows not in use or not initialized");
252 /* Nonzero if we can use mouse menus.
253 You should not call this unless HAVE_MENUS is defined. */
261 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
262 and checking validity for W32. */
265 check_x_frame (Lisp_Object frame
)
267 struct frame
*f
= decode_live_frame (frame
);
269 if (! FRAME_W32_P (f
))
270 error ("Non-W32 frame used");
274 /* Let the user specify a display with a frame.
275 nil stands for the selected frame--or, if that is not a w32 frame,
276 the first display on the list. */
278 struct w32_display_info
*
279 check_x_display_info (Lisp_Object frame
)
283 struct frame
*sf
= XFRAME (selected_frame
);
285 if (FRAME_W32_P (sf
) && FRAME_LIVE_P (sf
))
286 return FRAME_W32_DISPLAY_INFO (sf
);
288 return &one_w32_display_info
;
290 else if (STRINGP (frame
))
291 return x_display_info_for_name (frame
);
296 CHECK_LIVE_FRAME (frame
);
298 if (! FRAME_W32_P (f
))
299 error ("Non-W32 frame used");
300 return FRAME_W32_DISPLAY_INFO (f
);
304 /* Return the Emacs frame-object corresponding to an w32 window.
305 It could be the frame's main window or an icon window. */
307 /* This function can be called during GC, so use GC_xxx type test macros. */
310 x_window_to_frame (struct w32_display_info
*dpyinfo
, HWND wdesc
)
312 Lisp_Object tail
, frame
;
315 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
321 if (!FRAME_W32_P (f
) || FRAME_W32_DISPLAY_INFO (f
) != dpyinfo
)
324 if (FRAME_W32_WINDOW (f
) == wdesc
)
331 static Lisp_Object
unwind_create_frame (Lisp_Object
);
332 static Lisp_Object
unwind_create_tip_frame (Lisp_Object
);
333 static void my_create_window (struct frame
*);
334 static void my_create_tip_window (struct frame
*);
336 /* TODO: Native Input Method support; see x_create_im. */
337 void x_set_foreground_color (struct frame
*, Lisp_Object
, Lisp_Object
);
338 void x_set_background_color (struct frame
*, Lisp_Object
, Lisp_Object
);
339 void x_set_mouse_color (struct frame
*, Lisp_Object
, Lisp_Object
);
340 void x_set_cursor_color (struct frame
*, Lisp_Object
, Lisp_Object
);
341 void x_set_border_color (struct frame
*, Lisp_Object
, Lisp_Object
);
342 void x_set_cursor_type (struct frame
*, Lisp_Object
, Lisp_Object
);
343 void x_set_icon_type (struct frame
*, Lisp_Object
, Lisp_Object
);
344 void x_set_icon_name (struct frame
*, Lisp_Object
, Lisp_Object
);
345 void x_explicitly_set_name (struct frame
*, Lisp_Object
, Lisp_Object
);
346 void x_set_menu_bar_lines (struct frame
*, Lisp_Object
, Lisp_Object
);
347 void x_set_title (struct frame
*, Lisp_Object
, Lisp_Object
);
348 void x_set_tool_bar_lines (struct frame
*, Lisp_Object
, Lisp_Object
);
353 /* Store the screen positions of frame F into XPTR and YPTR.
354 These are the positions of the containing window manager window,
355 not Emacs's own window. */
358 x_real_positions (FRAME_PTR f
, int *xptr
, int *yptr
)
363 /* Get the bounds of the WM window. */
364 GetWindowRect (FRAME_W32_WINDOW (f
), &rect
);
369 /* Convert (0, 0) in the client area to screen co-ordinates. */
370 ClientToScreen (FRAME_W32_WINDOW (f
), &pt
);
372 /* Remember x_pixels_diff and y_pixels_diff. */
373 f
->x_pixels_diff
= pt
.x
- rect
.left
;
374 f
->y_pixels_diff
= pt
.y
- rect
.top
;
382 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
,
383 Sw32_define_rgb_color
, 4, 4, 0,
384 doc
: /* Convert RGB numbers to a Windows color reference and associate with NAME.
385 This adds or updates a named color to `w32-color-map', making it
386 available for use. The original entry's RGB ref is returned, or nil
387 if the entry is new. */)
388 (Lisp_Object red
, Lisp_Object green
, Lisp_Object blue
, Lisp_Object name
)
391 Lisp_Object oldrgb
= Qnil
;
395 CHECK_NUMBER (green
);
399 XSETINT (rgb
, RGB (XUINT (red
), XUINT (green
), XUINT (blue
)));
403 /* replace existing entry in w32-color-map or add new entry. */
404 entry
= Fassoc (name
, Vw32_color_map
);
407 entry
= Fcons (name
, rgb
);
408 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
412 oldrgb
= Fcdr (entry
);
413 Fsetcdr (entry
, rgb
);
421 /* The default colors for the w32 color map */
422 typedef struct colormap_t
428 colormap_t w32_color_map
[] =
430 {"snow" , PALETTERGB (255,250,250)},
431 {"ghost white" , PALETTERGB (248,248,255)},
432 {"GhostWhite" , PALETTERGB (248,248,255)},
433 {"white smoke" , PALETTERGB (245,245,245)},
434 {"WhiteSmoke" , PALETTERGB (245,245,245)},
435 {"gainsboro" , PALETTERGB (220,220,220)},
436 {"floral white" , PALETTERGB (255,250,240)},
437 {"FloralWhite" , PALETTERGB (255,250,240)},
438 {"old lace" , PALETTERGB (253,245,230)},
439 {"OldLace" , PALETTERGB (253,245,230)},
440 {"linen" , PALETTERGB (250,240,230)},
441 {"antique white" , PALETTERGB (250,235,215)},
442 {"AntiqueWhite" , PALETTERGB (250,235,215)},
443 {"papaya whip" , PALETTERGB (255,239,213)},
444 {"PapayaWhip" , PALETTERGB (255,239,213)},
445 {"blanched almond" , PALETTERGB (255,235,205)},
446 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
447 {"bisque" , PALETTERGB (255,228,196)},
448 {"peach puff" , PALETTERGB (255,218,185)},
449 {"PeachPuff" , PALETTERGB (255,218,185)},
450 {"navajo white" , PALETTERGB (255,222,173)},
451 {"NavajoWhite" , PALETTERGB (255,222,173)},
452 {"moccasin" , PALETTERGB (255,228,181)},
453 {"cornsilk" , PALETTERGB (255,248,220)},
454 {"ivory" , PALETTERGB (255,255,240)},
455 {"lemon chiffon" , PALETTERGB (255,250,205)},
456 {"LemonChiffon" , PALETTERGB (255,250,205)},
457 {"seashell" , PALETTERGB (255,245,238)},
458 {"honeydew" , PALETTERGB (240,255,240)},
459 {"mint cream" , PALETTERGB (245,255,250)},
460 {"MintCream" , PALETTERGB (245,255,250)},
461 {"azure" , PALETTERGB (240,255,255)},
462 {"alice blue" , PALETTERGB (240,248,255)},
463 {"AliceBlue" , PALETTERGB (240,248,255)},
464 {"lavender" , PALETTERGB (230,230,250)},
465 {"lavender blush" , PALETTERGB (255,240,245)},
466 {"LavenderBlush" , PALETTERGB (255,240,245)},
467 {"misty rose" , PALETTERGB (255,228,225)},
468 {"MistyRose" , PALETTERGB (255,228,225)},
469 {"white" , PALETTERGB (255,255,255)},
470 {"black" , PALETTERGB ( 0, 0, 0)},
471 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
472 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
473 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
474 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
475 {"dim gray" , PALETTERGB (105,105,105)},
476 {"DimGray" , PALETTERGB (105,105,105)},
477 {"dim grey" , PALETTERGB (105,105,105)},
478 {"DimGrey" , PALETTERGB (105,105,105)},
479 {"slate gray" , PALETTERGB (112,128,144)},
480 {"SlateGray" , PALETTERGB (112,128,144)},
481 {"slate grey" , PALETTERGB (112,128,144)},
482 {"SlateGrey" , PALETTERGB (112,128,144)},
483 {"light slate gray" , PALETTERGB (119,136,153)},
484 {"LightSlateGray" , PALETTERGB (119,136,153)},
485 {"light slate grey" , PALETTERGB (119,136,153)},
486 {"LightSlateGrey" , PALETTERGB (119,136,153)},
487 {"gray" , PALETTERGB (190,190,190)},
488 {"grey" , PALETTERGB (190,190,190)},
489 {"light grey" , PALETTERGB (211,211,211)},
490 {"LightGrey" , PALETTERGB (211,211,211)},
491 {"light gray" , PALETTERGB (211,211,211)},
492 {"LightGray" , PALETTERGB (211,211,211)},
493 {"midnight blue" , PALETTERGB ( 25, 25,112)},
494 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
495 {"navy" , PALETTERGB ( 0, 0,128)},
496 {"navy blue" , PALETTERGB ( 0, 0,128)},
497 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
498 {"cornflower blue" , PALETTERGB (100,149,237)},
499 {"CornflowerBlue" , PALETTERGB (100,149,237)},
500 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
501 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
502 {"slate blue" , PALETTERGB (106, 90,205)},
503 {"SlateBlue" , PALETTERGB (106, 90,205)},
504 {"medium slate blue" , PALETTERGB (123,104,238)},
505 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
506 {"light slate blue" , PALETTERGB (132,112,255)},
507 {"LightSlateBlue" , PALETTERGB (132,112,255)},
508 {"medium blue" , PALETTERGB ( 0, 0,205)},
509 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
510 {"royal blue" , PALETTERGB ( 65,105,225)},
511 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
512 {"blue" , PALETTERGB ( 0, 0,255)},
513 {"dodger blue" , PALETTERGB ( 30,144,255)},
514 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
515 {"deep sky blue" , PALETTERGB ( 0,191,255)},
516 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
517 {"sky blue" , PALETTERGB (135,206,235)},
518 {"SkyBlue" , PALETTERGB (135,206,235)},
519 {"light sky blue" , PALETTERGB (135,206,250)},
520 {"LightSkyBlue" , PALETTERGB (135,206,250)},
521 {"steel blue" , PALETTERGB ( 70,130,180)},
522 {"SteelBlue" , PALETTERGB ( 70,130,180)},
523 {"light steel blue" , PALETTERGB (176,196,222)},
524 {"LightSteelBlue" , PALETTERGB (176,196,222)},
525 {"light blue" , PALETTERGB (173,216,230)},
526 {"LightBlue" , PALETTERGB (173,216,230)},
527 {"powder blue" , PALETTERGB (176,224,230)},
528 {"PowderBlue" , PALETTERGB (176,224,230)},
529 {"pale turquoise" , PALETTERGB (175,238,238)},
530 {"PaleTurquoise" , PALETTERGB (175,238,238)},
531 {"dark turquoise" , PALETTERGB ( 0,206,209)},
532 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
533 {"medium turquoise" , PALETTERGB ( 72,209,204)},
534 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
535 {"turquoise" , PALETTERGB ( 64,224,208)},
536 {"cyan" , PALETTERGB ( 0,255,255)},
537 {"light cyan" , PALETTERGB (224,255,255)},
538 {"LightCyan" , PALETTERGB (224,255,255)},
539 {"cadet blue" , PALETTERGB ( 95,158,160)},
540 {"CadetBlue" , PALETTERGB ( 95,158,160)},
541 {"medium aquamarine" , PALETTERGB (102,205,170)},
542 {"MediumAquamarine" , PALETTERGB (102,205,170)},
543 {"aquamarine" , PALETTERGB (127,255,212)},
544 {"dark green" , PALETTERGB ( 0,100, 0)},
545 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
546 {"dark olive green" , PALETTERGB ( 85,107, 47)},
547 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
548 {"dark sea green" , PALETTERGB (143,188,143)},
549 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
550 {"sea green" , PALETTERGB ( 46,139, 87)},
551 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
552 {"medium sea green" , PALETTERGB ( 60,179,113)},
553 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
554 {"light sea green" , PALETTERGB ( 32,178,170)},
555 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
556 {"pale green" , PALETTERGB (152,251,152)},
557 {"PaleGreen" , PALETTERGB (152,251,152)},
558 {"spring green" , PALETTERGB ( 0,255,127)},
559 {"SpringGreen" , PALETTERGB ( 0,255,127)},
560 {"lawn green" , PALETTERGB (124,252, 0)},
561 {"LawnGreen" , PALETTERGB (124,252, 0)},
562 {"green" , PALETTERGB ( 0,255, 0)},
563 {"chartreuse" , PALETTERGB (127,255, 0)},
564 {"medium spring green" , PALETTERGB ( 0,250,154)},
565 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
566 {"green yellow" , PALETTERGB (173,255, 47)},
567 {"GreenYellow" , PALETTERGB (173,255, 47)},
568 {"lime green" , PALETTERGB ( 50,205, 50)},
569 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
570 {"yellow green" , PALETTERGB (154,205, 50)},
571 {"YellowGreen" , PALETTERGB (154,205, 50)},
572 {"forest green" , PALETTERGB ( 34,139, 34)},
573 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
574 {"olive drab" , PALETTERGB (107,142, 35)},
575 {"OliveDrab" , PALETTERGB (107,142, 35)},
576 {"dark khaki" , PALETTERGB (189,183,107)},
577 {"DarkKhaki" , PALETTERGB (189,183,107)},
578 {"khaki" , PALETTERGB (240,230,140)},
579 {"pale goldenrod" , PALETTERGB (238,232,170)},
580 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
581 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
582 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
583 {"light yellow" , PALETTERGB (255,255,224)},
584 {"LightYellow" , PALETTERGB (255,255,224)},
585 {"yellow" , PALETTERGB (255,255, 0)},
586 {"gold" , PALETTERGB (255,215, 0)},
587 {"light goldenrod" , PALETTERGB (238,221,130)},
588 {"LightGoldenrod" , PALETTERGB (238,221,130)},
589 {"goldenrod" , PALETTERGB (218,165, 32)},
590 {"dark goldenrod" , PALETTERGB (184,134, 11)},
591 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
592 {"rosy brown" , PALETTERGB (188,143,143)},
593 {"RosyBrown" , PALETTERGB (188,143,143)},
594 {"indian red" , PALETTERGB (205, 92, 92)},
595 {"IndianRed" , PALETTERGB (205, 92, 92)},
596 {"saddle brown" , PALETTERGB (139, 69, 19)},
597 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
598 {"sienna" , PALETTERGB (160, 82, 45)},
599 {"peru" , PALETTERGB (205,133, 63)},
600 {"burlywood" , PALETTERGB (222,184,135)},
601 {"beige" , PALETTERGB (245,245,220)},
602 {"wheat" , PALETTERGB (245,222,179)},
603 {"sandy brown" , PALETTERGB (244,164, 96)},
604 {"SandyBrown" , PALETTERGB (244,164, 96)},
605 {"tan" , PALETTERGB (210,180,140)},
606 {"chocolate" , PALETTERGB (210,105, 30)},
607 {"firebrick" , PALETTERGB (178,34, 34)},
608 {"brown" , PALETTERGB (165,42, 42)},
609 {"dark salmon" , PALETTERGB (233,150,122)},
610 {"DarkSalmon" , PALETTERGB (233,150,122)},
611 {"salmon" , PALETTERGB (250,128,114)},
612 {"light salmon" , PALETTERGB (255,160,122)},
613 {"LightSalmon" , PALETTERGB (255,160,122)},
614 {"orange" , PALETTERGB (255,165, 0)},
615 {"dark orange" , PALETTERGB (255,140, 0)},
616 {"DarkOrange" , PALETTERGB (255,140, 0)},
617 {"coral" , PALETTERGB (255,127, 80)},
618 {"light coral" , PALETTERGB (240,128,128)},
619 {"LightCoral" , PALETTERGB (240,128,128)},
620 {"tomato" , PALETTERGB (255, 99, 71)},
621 {"orange red" , PALETTERGB (255, 69, 0)},
622 {"OrangeRed" , PALETTERGB (255, 69, 0)},
623 {"red" , PALETTERGB (255, 0, 0)},
624 {"hot pink" , PALETTERGB (255,105,180)},
625 {"HotPink" , PALETTERGB (255,105,180)},
626 {"deep pink" , PALETTERGB (255, 20,147)},
627 {"DeepPink" , PALETTERGB (255, 20,147)},
628 {"pink" , PALETTERGB (255,192,203)},
629 {"light pink" , PALETTERGB (255,182,193)},
630 {"LightPink" , PALETTERGB (255,182,193)},
631 {"pale violet red" , PALETTERGB (219,112,147)},
632 {"PaleVioletRed" , PALETTERGB (219,112,147)},
633 {"maroon" , PALETTERGB (176, 48, 96)},
634 {"medium violet red" , PALETTERGB (199, 21,133)},
635 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
636 {"violet red" , PALETTERGB (208, 32,144)},
637 {"VioletRed" , PALETTERGB (208, 32,144)},
638 {"magenta" , PALETTERGB (255, 0,255)},
639 {"violet" , PALETTERGB (238,130,238)},
640 {"plum" , PALETTERGB (221,160,221)},
641 {"orchid" , PALETTERGB (218,112,214)},
642 {"medium orchid" , PALETTERGB (186, 85,211)},
643 {"MediumOrchid" , PALETTERGB (186, 85,211)},
644 {"dark orchid" , PALETTERGB (153, 50,204)},
645 {"DarkOrchid" , PALETTERGB (153, 50,204)},
646 {"dark violet" , PALETTERGB (148, 0,211)},
647 {"DarkViolet" , PALETTERGB (148, 0,211)},
648 {"blue violet" , PALETTERGB (138, 43,226)},
649 {"BlueViolet" , PALETTERGB (138, 43,226)},
650 {"purple" , PALETTERGB (160, 32,240)},
651 {"medium purple" , PALETTERGB (147,112,219)},
652 {"MediumPurple" , PALETTERGB (147,112,219)},
653 {"thistle" , PALETTERGB (216,191,216)},
654 {"gray0" , PALETTERGB ( 0, 0, 0)},
655 {"grey0" , PALETTERGB ( 0, 0, 0)},
656 {"dark grey" , PALETTERGB (169,169,169)},
657 {"DarkGrey" , PALETTERGB (169,169,169)},
658 {"dark gray" , PALETTERGB (169,169,169)},
659 {"DarkGray" , PALETTERGB (169,169,169)},
660 {"dark blue" , PALETTERGB ( 0, 0,139)},
661 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
662 {"dark cyan" , PALETTERGB ( 0,139,139)},
663 {"DarkCyan" , PALETTERGB ( 0,139,139)},
664 {"dark magenta" , PALETTERGB (139, 0,139)},
665 {"DarkMagenta" , PALETTERGB (139, 0,139)},
666 {"dark red" , PALETTERGB (139, 0, 0)},
667 {"DarkRed" , PALETTERGB (139, 0, 0)},
668 {"light green" , PALETTERGB (144,238,144)},
669 {"LightGreen" , PALETTERGB (144,238,144)},
673 w32_default_color_map (void)
676 colormap_t
*pc
= w32_color_map
;
683 for (i
= 0; i
< sizeof (w32_color_map
) / sizeof (w32_color_map
[0]);
685 cmap
= Fcons (Fcons (build_string (pc
->name
),
686 make_number (pc
->colorref
)),
694 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
695 0, 0, 0, doc
: /* Return the default color map. */)
698 return w32_default_color_map ();
702 w32_color_map_lookup (const char *colorname
)
704 Lisp_Object tail
, ret
= Qnil
;
708 for (tail
= Vw32_color_map
; CONSP (tail
); tail
= XCDR (tail
))
710 register Lisp_Object elt
, tem
;
713 if (!CONSP (elt
)) continue;
717 if (lstrcmpi (SDATA (tem
), colorname
) == 0)
733 add_system_logical_colors_to_map (Lisp_Object
*system_colors
)
737 /* Other registry operations are done with input blocked. */
740 /* Look for "Control Panel/Colors" under User and Machine registry
742 if (RegOpenKeyEx (HKEY_CURRENT_USER
, "Control Panel\\Colors", 0,
743 KEY_READ
, &colors_key
) == ERROR_SUCCESS
744 || RegOpenKeyEx (HKEY_LOCAL_MACHINE
, "Control Panel\\Colors", 0,
745 KEY_READ
, &colors_key
) == ERROR_SUCCESS
)
748 char color_buffer
[64];
749 char full_name_buffer
[MAX_PATH
+ SYSTEM_COLOR_PREFIX_LEN
];
751 DWORD name_size
, color_size
;
752 char *name_buffer
= full_name_buffer
+ SYSTEM_COLOR_PREFIX_LEN
;
754 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
755 color_size
= sizeof (color_buffer
);
757 strcpy (full_name_buffer
, SYSTEM_COLOR_PREFIX
);
759 while (RegEnumValueA (colors_key
, index
, name_buffer
, &name_size
,
760 NULL
, NULL
, color_buffer
, &color_size
)
764 if (sscanf (color_buffer
, " %u %u %u", &r
, &g
, &b
) == 3)
765 *system_colors
= Fcons (Fcons (build_string (full_name_buffer
),
766 make_number (RGB (r
, g
, b
))),
769 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
770 color_size
= sizeof (color_buffer
);
773 RegCloseKey (colors_key
);
781 x_to_w32_color (const char * colorname
)
783 register Lisp_Object ret
= Qnil
;
787 if (colorname
[0] == '#')
789 /* Could be an old-style RGB Device specification. */
790 int size
= strlen (colorname
+ 1);
791 char *color
= alloca (size
+ 1);
793 strcpy (color
, colorname
+ 1);
794 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
802 for (i
= 0; i
< 3; i
++)
808 /* The check for 'x' in the following conditional takes into
809 account the fact that strtol allows a "0x" in front of
810 our numbers, and we don't. */
811 if (!isxdigit (color
[0]) || color
[1] == 'x')
815 value
= strtoul (color
, &end
, 16);
817 if (errno
== ERANGE
|| end
- color
!= size
)
822 value
= value
* 0x10;
833 colorval
|= (value
<< pos
);
838 XSETINT (ret
, colorval
);
845 else if (strnicmp (colorname
, "rgb:", 4) == 0)
853 color
= colorname
+ 4;
854 for (i
= 0; i
< 3; i
++)
859 /* The check for 'x' in the following conditional takes into
860 account the fact that strtol allows a "0x" in front of
861 our numbers, and we don't. */
862 if (!isxdigit (color
[0]) || color
[1] == 'x')
864 value
= strtoul (color
, &end
, 16);
870 value
= value
* 0x10 + value
;
883 if (value
== ULONG_MAX
)
885 colorval
|= (value
<< pos
);
892 XSETINT (ret
, colorval
);
900 else if (strnicmp (colorname
, "rgbi:", 5) == 0)
902 /* This is an RGB Intensity specification. */
909 color
= colorname
+ 5;
910 for (i
= 0; i
< 3; i
++)
916 value
= strtod (color
, &end
);
919 if (value
< 0.0 || value
> 1.0)
921 val
= (UINT
)(0x100 * value
);
922 /* We used 0x100 instead of 0xFF to give a continuous
923 range between 0.0 and 1.0 inclusive. The next statement
924 fixes the 1.0 case. */
927 colorval
|= (val
<< pos
);
934 XSETINT (ret
, colorval
);
942 /* I am not going to attempt to handle any of the CIE color schemes
943 or TekHVC, since I don't know the algorithms for conversion to
946 /* If we fail to lookup the color name in w32_color_map, then check the
947 colorname to see if it can be crudely approximated: If the X color
948 ends in a number (e.g., "darkseagreen2"), strip the number and
949 return the result of looking up the base color name. */
950 ret
= w32_color_map_lookup (colorname
);
953 int len
= strlen (colorname
);
955 if (isdigit (colorname
[len
- 1]))
957 char *ptr
, *approx
= alloca (len
+ 1);
959 strcpy (approx
, colorname
);
960 ptr
= &approx
[len
- 1];
961 while (ptr
> approx
&& isdigit (*ptr
))
964 ret
= w32_color_map_lookup (approx
);
973 w32_regenerate_palette (FRAME_PTR f
)
975 struct w32_palette_entry
* list
;
976 LOGPALETTE
* log_palette
;
977 HPALETTE new_palette
;
980 /* don't bother trying to create palette if not supported */
981 if (! FRAME_W32_DISPLAY_INFO (f
)->has_palette
)
984 log_palette
= (LOGPALETTE
*)
985 alloca (sizeof (LOGPALETTE
) +
986 FRAME_W32_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
987 log_palette
->palVersion
= 0x300;
988 log_palette
->palNumEntries
= FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
990 list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
992 i
< FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
993 i
++, list
= list
->next
)
994 log_palette
->palPalEntry
[i
] = list
->entry
;
996 new_palette
= CreatePalette (log_palette
);
1000 if (FRAME_W32_DISPLAY_INFO (f
)->palette
)
1001 DeleteObject (FRAME_W32_DISPLAY_INFO (f
)->palette
);
1002 FRAME_W32_DISPLAY_INFO (f
)->palette
= new_palette
;
1004 /* Realize display palette and garbage all frames. */
1005 release_frame_dc (f
, get_frame_dc (f
));
1010 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
1011 #define SET_W32_COLOR(pe, color) \
1014 pe.peRed = GetRValue (color); \
1015 pe.peGreen = GetGValue (color); \
1016 pe.peBlue = GetBValue (color); \
1021 /* Keep these around in case we ever want to track color usage. */
1023 w32_map_color (FRAME_PTR f
, COLORREF color
)
1025 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1027 if (NILP (Vw32_enable_palette
))
1030 /* check if color is already mapped */
1033 if (W32_COLOR (list
->entry
) == color
)
1041 /* not already mapped, so add to list and recreate Windows palette */
1042 list
= xmalloc (sizeof (struct w32_palette_entry
));
1043 SET_W32_COLOR (list
->entry
, color
);
1045 list
->next
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1046 FRAME_W32_DISPLAY_INFO (f
)->color_list
= list
;
1047 FRAME_W32_DISPLAY_INFO (f
)->num_colors
++;
1049 /* set flag that palette must be regenerated */
1050 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1054 w32_unmap_color (FRAME_PTR f
, COLORREF color
)
1056 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1057 struct w32_palette_entry
**prev
= &FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1059 if (NILP (Vw32_enable_palette
))
1062 /* check if color is already mapped */
1065 if (W32_COLOR (list
->entry
) == color
)
1067 if (--list
->refcount
== 0)
1071 FRAME_W32_DISPLAY_INFO (f
)->num_colors
--;
1081 /* set flag that palette must be regenerated */
1082 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1087 /* Gamma-correct COLOR on frame F. */
1090 gamma_correct (struct frame
*f
, COLORREF
*color
)
1094 *color
= PALETTERGB (
1095 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1096 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1097 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1102 /* Decide if color named COLOR is valid for the display associated with
1103 the selected frame; if so, return the rgb values in COLOR_DEF.
1104 If ALLOC is nonzero, allocate a new colormap cell. */
1107 w32_defined_color (FRAME_PTR f
, const char *color
, XColor
*color_def
, int alloc
)
1109 register Lisp_Object tem
;
1110 COLORREF w32_color_ref
;
1112 tem
= x_to_w32_color (color
);
1118 /* Apply gamma correction. */
1119 w32_color_ref
= XUINT (tem
);
1120 gamma_correct (f
, &w32_color_ref
);
1121 XSETINT (tem
, w32_color_ref
);
1124 /* Map this color to the palette if it is enabled. */
1125 if (!NILP (Vw32_enable_palette
))
1127 struct w32_palette_entry
* entry
=
1128 one_w32_display_info
.color_list
;
1129 struct w32_palette_entry
** prev
=
1130 &one_w32_display_info
.color_list
;
1132 /* check if color is already mapped */
1135 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1137 prev
= &entry
->next
;
1138 entry
= entry
->next
;
1141 if (entry
== NULL
&& alloc
)
1143 /* not already mapped, so add to list */
1144 entry
= xmalloc (sizeof (struct w32_palette_entry
));
1145 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1148 one_w32_display_info
.num_colors
++;
1150 /* set flag that palette must be regenerated */
1151 one_w32_display_info
.regen_palette
= TRUE
;
1154 /* Ensure COLORREF value is snapped to nearest color in (default)
1155 palette by simulating the PALETTERGB macro. This works whether
1156 or not the display device has a palette. */
1157 w32_color_ref
= XUINT (tem
) | 0x2000000;
1159 color_def
->pixel
= w32_color_ref
;
1160 color_def
->red
= GetRValue (w32_color_ref
) * 256;
1161 color_def
->green
= GetGValue (w32_color_ref
) * 256;
1162 color_def
->blue
= GetBValue (w32_color_ref
) * 256;
1172 /* Given a string ARG naming a color, compute a pixel value from it
1173 suitable for screen F.
1174 If F is not a color screen, return DEF (default) regardless of what
1178 x_decode_color (FRAME_PTR f
, Lisp_Object arg
, int def
)
1184 if (strcmp (SDATA (arg
), "black") == 0)
1185 return BLACK_PIX_DEFAULT (f
);
1186 else if (strcmp (SDATA (arg
), "white") == 0)
1187 return WHITE_PIX_DEFAULT (f
);
1189 if ((FRAME_W32_DISPLAY_INFO (f
)->n_planes
* FRAME_W32_DISPLAY_INFO (f
)->n_cbits
) == 1)
1192 /* w32_defined_color is responsible for coping with failures
1193 by looking for a near-miss. */
1194 if (w32_defined_color (f
, SDATA (arg
), &cdef
, 1))
1197 /* defined_color failed; return an ultimate default. */
1203 /* Functions called only from `x_set_frame_param'
1204 to set individual parameters.
1206 If FRAME_W32_WINDOW (f) is 0,
1207 the frame is being created and its window does not exist yet.
1208 In that case, just record the parameter's new value
1209 in the standard place; do not attempt to change the window. */
1212 x_set_foreground_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1214 struct w32_output
*x
= f
->output_data
.w32
;
1215 PIX_TYPE fg
, old_fg
;
1217 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1218 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
1219 FRAME_FOREGROUND_PIXEL (f
) = fg
;
1221 if (FRAME_W32_WINDOW (f
) != 0)
1223 if (x
->cursor_pixel
== old_fg
)
1225 x
->cursor_pixel
= fg
;
1226 x
->cursor_gc
->background
= fg
;
1229 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
1230 if (FRAME_VISIBLE_P (f
))
1236 x_set_background_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1238 FRAME_BACKGROUND_PIXEL (f
)
1239 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
1241 if (FRAME_W32_WINDOW (f
) != 0)
1243 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
1244 FRAME_BACKGROUND_PIXEL (f
));
1246 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
1248 if (FRAME_VISIBLE_P (f
))
1254 x_set_mouse_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1256 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
1260 if (!EQ (Qnil
, arg
))
1261 f
->output_data
.w32
->mouse_pixel
1262 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1263 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
1265 /* Don't let pointers be invisible. */
1266 if (mask_color
== f
->output_data
.w32
->mouse_pixel
1267 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
1268 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
1270 #if 0 /* TODO : Mouse cursor customization. */
1273 /* It's not okay to crash if the user selects a screwy cursor. */
1274 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
1276 if (!EQ (Qnil
, Vx_pointer_shape
))
1278 CHECK_NUMBER (Vx_pointer_shape
);
1279 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
1282 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1283 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
1285 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
1287 CHECK_NUMBER (Vx_nontext_pointer_shape
);
1288 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1289 XINT (Vx_nontext_pointer_shape
));
1292 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
1293 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1295 if (!EQ (Qnil
, Vx_hourglass_pointer_shape
))
1297 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
1298 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1299 XINT (Vx_hourglass_pointer_shape
));
1302 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
1303 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
1305 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1306 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
1308 CHECK_NUMBER (Vx_mode_pointer_shape
);
1309 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1310 XINT (Vx_mode_pointer_shape
));
1313 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1314 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
1316 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
1318 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
1320 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1321 XINT (Vx_sensitive_text_pointer_shape
));
1324 hand_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
1326 if (!NILP (Vx_window_horizontal_drag_shape
))
1328 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
1329 horizontal_drag_cursor
1330 = XCreateFontCursor (FRAME_X_DISPLAY (f
),
1331 XINT (Vx_window_horizontal_drag_shape
));
1334 horizontal_drag_cursor
1335 = XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_sb_h_double_arrow
);
1337 /* Check and report errors with the above calls. */
1338 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
1339 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
1342 XColor fore_color
, back_color
;
1344 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
1345 back_color
.pixel
= mask_color
;
1346 XQueryColor (FRAME_W32_DISPLAY (f
),
1347 DefaultColormap (FRAME_W32_DISPLAY (f
),
1348 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1350 XQueryColor (FRAME_W32_DISPLAY (f
),
1351 DefaultColormap (FRAME_W32_DISPLAY (f
),
1352 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1354 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
1355 &fore_color
, &back_color
);
1356 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
1357 &fore_color
, &back_color
);
1358 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
1359 &fore_color
, &back_color
);
1360 XRecolorCursor (FRAME_W32_DISPLAY (f
), hand_cursor
,
1361 &fore_color
, &back_color
);
1362 XRecolorCursor (FRAME_W32_DISPLAY (f
), hourglass_cursor
,
1363 &fore_color
, &back_color
);
1366 if (FRAME_W32_WINDOW (f
) != 0)
1367 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
1369 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
1370 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
1371 f
->output_data
.w32
->text_cursor
= cursor
;
1373 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
1374 && f
->output_data
.w32
->nontext_cursor
!= 0)
1375 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
1376 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
1378 if (hourglass_cursor
!= f
->output_data
.w32
->hourglass_cursor
1379 && f
->output_data
.w32
->hourglass_cursor
!= 0)
1380 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hourglass_cursor
);
1381 f
->output_data
.w32
->hourglass_cursor
= hourglass_cursor
;
1383 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
1384 && f
->output_data
.w32
->modeline_cursor
!= 0)
1385 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
1386 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
1388 if (hand_cursor
!= f
->output_data
.w32
->hand_cursor
1389 && f
->output_data
.w32
->hand_cursor
!= 0)
1390 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hand_cursor
);
1391 f
->output_data
.w32
->hand_cursor
= hand_cursor
;
1393 XFlush (FRAME_W32_DISPLAY (f
));
1396 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1401 x_set_cursor_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1403 unsigned long fore_pixel
, pixel
;
1405 if (!NILP (Vx_cursor_fore_pixel
))
1406 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1407 WHITE_PIX_DEFAULT (f
));
1409 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1411 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1413 /* Make sure that the cursor color differs from the background color. */
1414 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
1416 pixel
= f
->output_data
.w32
->mouse_pixel
;
1417 if (pixel
== fore_pixel
)
1418 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1421 f
->output_data
.w32
->cursor_foreground_pixel
= fore_pixel
;
1422 f
->output_data
.w32
->cursor_pixel
= pixel
;
1424 if (FRAME_W32_WINDOW (f
) != 0)
1427 /* Update frame's cursor_gc. */
1428 f
->output_data
.w32
->cursor_gc
->foreground
= fore_pixel
;
1429 f
->output_data
.w32
->cursor_gc
->background
= pixel
;
1433 if (FRAME_VISIBLE_P (f
))
1435 x_update_cursor (f
, 0);
1436 x_update_cursor (f
, 1);
1440 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1443 /* Set the border-color of frame F to pixel value PIX.
1444 Note that this does not fully take effect if done before
1448 x_set_border_pixel (struct frame
*f
, int pix
)
1451 f
->output_data
.w32
->border_pixel
= pix
;
1453 if (FRAME_W32_WINDOW (f
) != 0 && f
->border_width
> 0)
1455 if (FRAME_VISIBLE_P (f
))
1460 /* Set the border-color of frame F to value described by ARG.
1461 ARG can be a string naming a color.
1462 The border-color is used for the border that is drawn by the server.
1463 Note that this does not fully take effect if done before
1464 F has a window; it must be redone when the window is created. */
1467 x_set_border_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1472 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1473 x_set_border_pixel (f
, pix
);
1474 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1479 x_set_cursor_type (FRAME_PTR f
, Lisp_Object arg
, Lisp_Object oldval
)
1481 set_frame_cursor_types (f
, arg
);
1483 /* Make sure the cursor gets redrawn. */
1484 cursor_type_changed
= 1;
1488 x_set_icon_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1492 if (NILP (arg
) && NILP (oldval
))
1495 if (STRINGP (arg
) && STRINGP (oldval
)
1496 && EQ (Fstring_equal (oldval
, arg
), Qt
))
1499 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
1504 result
= x_bitmap_icon (f
, arg
);
1508 error ("No icon window available");
1515 x_set_icon_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1519 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1522 else if (!NILP (arg
) || NILP (oldval
))
1525 fset_icon_name (f
, arg
);
1528 if (f
->output_data
.w32
->icon_bitmap
!= 0)
1533 result
= x_text_icon (f
,
1534 SSDATA ((!NILP (f
->icon_name
)
1543 error ("No icon window available");
1546 /* If the window was unmapped (and its icon was mapped),
1547 the new icon is not mapped, so map the window in its stead. */
1548 if (FRAME_VISIBLE_P (f
))
1550 #ifdef USE_X_TOOLKIT
1551 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
1553 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
1556 XFlush (FRAME_W32_DISPLAY (f
));
1563 x_set_menu_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1567 /* Right now, menu bars don't work properly in minibuf-only frames;
1568 most of the commands try to apply themselves to the minibuffer
1569 frame itself, and get an error because you can't switch buffers
1570 in or split the minibuffer window. */
1571 if (FRAME_MINIBUF_ONLY_P (f
))
1574 if (INTEGERP (value
))
1575 nlines
= XINT (value
);
1579 FRAME_MENU_BAR_LINES (f
) = 0;
1581 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1584 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1585 free_frame_menubar (f
);
1586 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1588 /* Adjust the frame size so that the client (text) dimensions
1589 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
1591 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
1592 do_pending_window_change (0);
1598 /* Set the number of lines used for the tool bar of frame F to VALUE.
1599 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1600 is the old number of tool bar lines. This function changes the
1601 height of all windows on frame F to match the new tool bar height.
1602 The frame's height doesn't change. */
1605 x_set_tool_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1607 int delta
, nlines
, root_height
;
1608 Lisp_Object root_window
;
1610 /* Treat tool bars like menu bars. */
1611 if (FRAME_MINIBUF_ONLY_P (f
))
1614 /* Use VALUE only if an integer >= 0. */
1615 if (INTEGERP (value
) && XINT (value
) >= 0)
1616 nlines
= XFASTINT (value
);
1620 /* Make sure we redisplay all windows in this frame. */
1621 ++windows_or_buffers_changed
;
1623 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
1625 /* Don't resize the tool-bar to more than we have room for. */
1626 root_window
= FRAME_ROOT_WINDOW (f
);
1627 root_height
= WINDOW_TOTAL_LINES (XWINDOW (root_window
));
1628 if (root_height
- delta
< 1)
1630 delta
= root_height
- 1;
1631 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
1634 FRAME_TOOL_BAR_LINES (f
) = nlines
;
1635 resize_frame_windows (f
, FRAME_LINES (f
), 0);
1638 /* We also have to make sure that the internal border at the top of
1639 the frame, below the menu bar or tool bar, is redrawn when the
1640 tool bar disappears. This is so because the internal border is
1641 below the tool bar if one is displayed, but is below the menu bar
1642 if there isn't a tool bar. The tool bar draws into the area
1643 below the menu bar. */
1644 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
1647 clear_current_matrices (f
);
1650 /* If the tool bar gets smaller, the internal border below it
1651 has to be cleared. It was formerly part of the display
1652 of the larger tool bar, and updating windows won't clear it. */
1655 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1656 int width
= FRAME_PIXEL_WIDTH (f
);
1657 int y
= nlines
* FRAME_LINE_HEIGHT (f
);
1661 HDC hdc
= get_frame_dc (f
);
1662 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
1663 release_frame_dc (f
, hdc
);
1667 if (WINDOWP (f
->tool_bar_window
))
1668 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1671 run_window_configuration_change_hook (f
);
1676 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1679 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1680 name; if NAME is a string, set F's name to NAME and set
1681 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1683 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1684 suggesting a new name, which lisp code should override; if
1685 F->explicit_name is set, ignore the new name; otherwise, set it. */
1688 x_set_name (struct frame
*f
, Lisp_Object name
, int explicit)
1690 /* Make sure that requests from lisp code override requests from
1691 Emacs redisplay code. */
1694 /* If we're switching from explicit to implicit, we had better
1695 update the mode lines and thereby update the title. */
1696 if (f
->explicit_name
&& NILP (name
))
1697 update_mode_lines
= 1;
1699 f
->explicit_name
= ! NILP (name
);
1701 else if (f
->explicit_name
)
1704 /* If NAME is nil, set the name to the w32_id_name. */
1707 /* Check for no change needed in this very common case
1708 before we do any consing. */
1709 if (!strcmp (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
,
1712 name
= build_string (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
);
1715 CHECK_STRING (name
);
1717 /* Don't change the name if it's already NAME. */
1718 if (! NILP (Fstring_equal (name
, f
->name
)))
1721 fset_name (f
, name
);
1723 /* For setting the frame title, the title parameter should override
1724 the name parameter. */
1725 if (! NILP (f
->title
))
1728 if (FRAME_W32_WINDOW (f
))
1730 if (STRING_MULTIBYTE (name
))
1731 name
= ENCODE_SYSTEM (name
);
1734 SetWindowText (FRAME_W32_WINDOW (f
), SDATA (name
));
1739 /* This function should be called when the user's lisp code has
1740 specified a name for the frame; the name will override any set by the
1743 x_explicitly_set_name (FRAME_PTR f
, Lisp_Object arg
, Lisp_Object oldval
)
1745 x_set_name (f
, arg
, 1);
1748 /* This function should be called by Emacs redisplay code to set the
1749 name; names set this way will never override names set by the user's
1752 x_implicitly_set_name (FRAME_PTR f
, Lisp_Object arg
, Lisp_Object oldval
)
1754 x_set_name (f
, arg
, 0);
1757 /* Change the title of frame F to NAME.
1758 If NAME is nil, use the frame name as the title. */
1761 x_set_title (struct frame
*f
, Lisp_Object name
, Lisp_Object old_name
)
1763 /* Don't change the title if it's already NAME. */
1764 if (EQ (name
, f
->title
))
1767 update_mode_lines
= 1;
1769 fset_title (f
, name
);
1774 if (FRAME_W32_WINDOW (f
))
1776 if (STRING_MULTIBYTE (name
))
1777 name
= ENCODE_SYSTEM (name
);
1780 SetWindowText (FRAME_W32_WINDOW (f
), SDATA (name
));
1786 x_set_scroll_bar_default_width (struct frame
*f
)
1788 int wid
= FRAME_COLUMN_WIDTH (f
);
1790 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
1791 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) +
1796 /* Subroutines for creating a frame. */
1799 w32_load_cursor (LPCTSTR name
)
1801 /* Try first to load cursor from application resource. */
1802 Cursor cursor
= LoadImage ((HINSTANCE
) GetModuleHandle (NULL
),
1803 name
, IMAGE_CURSOR
, 0, 0,
1804 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
1807 /* Then try to load a shared predefined cursor. */
1808 cursor
= LoadImage (NULL
, name
, IMAGE_CURSOR
, 0, 0,
1809 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
1814 static LRESULT CALLBACK
w32_wnd_proc (HWND
, UINT
, WPARAM
, LPARAM
);
1816 #define INIT_WINDOW_CLASS(WC) \
1817 (WC).style = CS_HREDRAW | CS_VREDRAW; \
1818 (WC).lpfnWndProc = (WNDPROC) w32_wnd_proc; \
1819 (WC).cbClsExtra = 0; \
1820 (WC).cbWndExtra = WND_EXTRA_BYTES; \
1821 (WC).hInstance = hinst; \
1822 (WC).hIcon = LoadIcon (hinst, EMACS_CLASS); \
1823 (WC).hCursor = w32_load_cursor (IDC_ARROW); \
1824 (WC).hbrBackground = NULL; \
1825 (WC).lpszMenuName = NULL; \
1828 w32_init_class (HINSTANCE hinst
)
1831 if (w32_unicode_gui
)
1834 INIT_WINDOW_CLASS(uwc
);
1835 uwc
.lpszClassName
= L
"Emacs";
1837 return RegisterClassW (&uwc
);
1842 INIT_WINDOW_CLASS(wc
);
1843 wc
.lpszClassName
= EMACS_CLASS
;
1845 return RegisterClassA (&wc
);
1850 w32_createscrollbar (struct frame
*f
, struct scroll_bar
* bar
)
1852 return (CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
1853 /* Position and size of scroll bar. */
1854 XINT (bar
->left
) + VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
1856 XINT (bar
->width
) - VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
1858 FRAME_W32_WINDOW (f
),
1865 w32_createwindow (struct frame
*f
)
1869 Lisp_Object top
= Qunbound
;
1870 Lisp_Object left
= Qunbound
;
1871 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
1873 rect
.left
= rect
.top
= 0;
1874 rect
.right
= FRAME_PIXEL_WIDTH (f
);
1875 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
1877 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
1878 FRAME_EXTERNAL_MENU_BAR (f
));
1880 /* Do first time app init */
1882 w32_init_class (hinst
);
1884 if (f
->size_hint_flags
& USPosition
|| f
->size_hint_flags
& PPosition
)
1886 XSETINT (left
, f
->left_pos
);
1887 XSETINT (top
, f
->top_pos
);
1889 else if (EQ (left
, Qunbound
) && EQ (top
, Qunbound
))
1891 /* When called with RES_TYPE_NUMBER, w32_get_arg will return zero
1892 for anything that is not a number and is not Qunbound. */
1893 left
= x_get_arg (dpyinfo
, Qnil
, Qleft
, "left", "Left", RES_TYPE_NUMBER
);
1894 top
= x_get_arg (dpyinfo
, Qnil
, Qtop
, "top", "Top", RES_TYPE_NUMBER
);
1897 FRAME_W32_WINDOW (f
) = hwnd
1898 = CreateWindow (EMACS_CLASS
,
1900 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
1901 EQ (left
, Qunbound
) ? CW_USEDEFAULT
: XINT (left
),
1902 EQ (top
, Qunbound
) ? CW_USEDEFAULT
: XINT (top
),
1903 rect
.right
- rect
.left
,
1904 rect
.bottom
- rect
.top
,
1912 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
1913 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
1914 SetWindowLong (hwnd
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
1915 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->scroll_bar_actual_width
);
1916 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
1918 /* Enable drag-n-drop. */
1919 DragAcceptFiles (hwnd
, TRUE
);
1921 /* Do this to discard the default setting specified by our parent. */
1922 ShowWindow (hwnd
, SW_HIDE
);
1924 /* Update frame positions. */
1925 GetWindowRect (hwnd
, &rect
);
1926 f
->left_pos
= rect
.left
;
1927 f
->top_pos
= rect
.top
;
1932 my_post_msg (W32Msg
* wmsg
, HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1934 wmsg
->msg
.hwnd
= hwnd
;
1935 wmsg
->msg
.message
= msg
;
1936 wmsg
->msg
.wParam
= wParam
;
1937 wmsg
->msg
.lParam
= lParam
;
1938 wmsg
->msg
.time
= GetMessageTime ();
1943 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
1944 between left and right keys as advertised. We test for this
1945 support dynamically, and set a flag when the support is absent. If
1946 absent, we keep track of the left and right control and alt keys
1947 ourselves. This is particularly necessary on keyboards that rely
1948 upon the AltGr key, which is represented as having the left control
1949 and right alt keys pressed. For these keyboards, we need to know
1950 when the left alt key has been pressed in addition to the AltGr key
1951 so that we can properly support M-AltGr-key sequences (such as M-@
1952 on Swedish keyboards). */
1954 #define EMACS_LCONTROL 0
1955 #define EMACS_RCONTROL 1
1956 #define EMACS_LMENU 2
1957 #define EMACS_RMENU 3
1959 static int modifiers
[4];
1960 static int modifiers_recorded
;
1961 static int modifier_key_support_tested
;
1964 test_modifier_support (unsigned int wparam
)
1968 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
1970 if (wparam
== VK_CONTROL
)
1980 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
1981 modifiers_recorded
= 1;
1983 modifiers_recorded
= 0;
1984 modifier_key_support_tested
= 1;
1988 record_keydown (unsigned int wparam
, unsigned int lparam
)
1992 if (!modifier_key_support_tested
)
1993 test_modifier_support (wparam
);
1995 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
1998 if (wparam
== VK_CONTROL
)
1999 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2001 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2007 record_keyup (unsigned int wparam
, unsigned int lparam
)
2011 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2014 if (wparam
== VK_CONTROL
)
2015 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2017 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2022 /* Emacs can lose focus while a modifier key has been pressed. When
2023 it regains focus, be conservative and clear all modifiers since
2024 we cannot reconstruct the left and right modifier state. */
2026 reset_modifiers (void)
2030 if (GetFocus () == NULL
)
2031 /* Emacs doesn't have keyboard focus. Do nothing. */
2034 ctrl
= GetAsyncKeyState (VK_CONTROL
);
2035 alt
= GetAsyncKeyState (VK_MENU
);
2037 if (!(ctrl
& 0x08000))
2038 /* Clear any recorded control modifier state. */
2039 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2041 if (!(alt
& 0x08000))
2042 /* Clear any recorded alt modifier state. */
2043 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2045 /* Update the state of all modifier keys, because modifiers used in
2046 hot-key combinations can get stuck on if Emacs loses focus as a
2047 result of a hot-key being pressed. */
2051 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
2053 GetKeyboardState (keystate
);
2054 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
2055 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
2056 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
2057 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
2058 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
2059 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
2060 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
2061 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
2062 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
2063 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
2064 SetKeyboardState (keystate
);
2068 /* Synchronize modifier state with what is reported with the current
2069 keystroke. Even if we cannot distinguish between left and right
2070 modifier keys, we know that, if no modifiers are set, then neither
2071 the left or right modifier should be set. */
2073 sync_modifiers (void)
2075 if (!modifiers_recorded
)
2078 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
2079 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2081 if (!(GetKeyState (VK_MENU
) & 0x8000))
2082 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2086 modifier_set (int vkey
)
2088 if (vkey
== VK_CAPITAL
|| vkey
== VK_SCROLL
)
2089 return (GetKeyState (vkey
) & 0x1);
2090 if (!modifiers_recorded
)
2091 return (GetKeyState (vkey
) & 0x8000);
2096 return modifiers
[EMACS_LCONTROL
];
2098 return modifiers
[EMACS_RCONTROL
];
2100 return modifiers
[EMACS_LMENU
];
2102 return modifiers
[EMACS_RMENU
];
2104 return (GetKeyState (vkey
) & 0x8000);
2107 /* Convert between the modifier bits W32 uses and the modifier bits
2111 w32_key_to_modifier (int key
)
2113 Lisp_Object key_mapping
;
2118 key_mapping
= Vw32_lwindow_modifier
;
2121 key_mapping
= Vw32_rwindow_modifier
;
2124 key_mapping
= Vw32_apps_modifier
;
2127 key_mapping
= Vw32_scroll_lock_modifier
;
2133 /* NB. This code runs in the input thread, asynchronously to the lisp
2134 thread, so we must be careful to ensure access to lisp data is
2135 thread-safe. The following code is safe because the modifier
2136 variable values are updated atomically from lisp and symbols are
2137 not relocated by GC. Also, we don't have to worry about seeing GC
2139 if (EQ (key_mapping
, Qhyper
))
2140 return hyper_modifier
;
2141 if (EQ (key_mapping
, Qsuper
))
2142 return super_modifier
;
2143 if (EQ (key_mapping
, Qmeta
))
2144 return meta_modifier
;
2145 if (EQ (key_mapping
, Qalt
))
2146 return alt_modifier
;
2147 if (EQ (key_mapping
, Qctrl
))
2148 return ctrl_modifier
;
2149 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
2150 return ctrl_modifier
;
2151 if (EQ (key_mapping
, Qshift
))
2152 return shift_modifier
;
2154 /* Don't generate any modifier if not explicitly requested. */
2159 w32_get_modifiers (void)
2161 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
2162 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
2163 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
2164 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
2165 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
2166 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
2167 (modifier_set (VK_MENU
) ?
2168 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
2171 /* We map the VK_* modifiers into console modifier constants
2172 so that we can use the same routines to handle both console
2173 and window input. */
2176 construct_console_modifiers (void)
2181 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
2182 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
2183 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
2184 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
2185 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
2186 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
2187 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
2188 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
2189 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
2190 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
2191 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
2197 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
2201 /* Convert to emacs modifiers. */
2202 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
2208 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
2210 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
2213 if (virt_key
== VK_RETURN
)
2214 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
2216 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
2217 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
2219 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
2220 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
2222 if (virt_key
== VK_CLEAR
)
2223 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
2228 /* List of special key combinations which w32 would normally capture,
2229 but Emacs should grab instead. Not directly visible to lisp, to
2230 simplify synchronization. Each item is an integer encoding a virtual
2231 key code and modifier combination to capture. */
2232 static Lisp_Object w32_grabbed_keys
;
2234 #define HOTKEY(vk, mods) make_number (((vk) & 255) | ((mods) << 8))
2235 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
2236 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
2237 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
2239 #define RAW_HOTKEY_ID(k) ((k) & 0xbfff)
2240 #define RAW_HOTKEY_VK_CODE(k) ((k) & 255)
2241 #define RAW_HOTKEY_MODIFIERS(k) ((k) >> 8)
2243 /* Register hot-keys for reserved key combinations when Emacs has
2244 keyboard focus, since this is the only way Emacs can receive key
2245 combinations like Alt-Tab which are used by the system. */
2248 register_hot_keys (HWND hwnd
)
2250 Lisp_Object keylist
;
2252 /* Use CONSP, since we are called asynchronously. */
2253 for (keylist
= w32_grabbed_keys
; CONSP (keylist
); keylist
= XCDR (keylist
))
2255 Lisp_Object key
= XCAR (keylist
);
2257 /* Deleted entries get set to nil. */
2258 if (!INTEGERP (key
))
2261 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
2262 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
2267 unregister_hot_keys (HWND hwnd
)
2269 Lisp_Object keylist
;
2271 for (keylist
= w32_grabbed_keys
; CONSP (keylist
); keylist
= XCDR (keylist
))
2273 Lisp_Object key
= XCAR (keylist
);
2275 if (!INTEGERP (key
))
2278 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
2284 w32_name_of_message (UINT msg
)
2287 static char buf
[64];
2288 static const struct {
2292 #define M(msg) { msg, # msg }
2300 M (WM_EMACS_CREATEWINDOW
),
2302 M (WM_EMACS_CREATESCROLLBAR
),
2303 M (WM_EMACS_SHOWWINDOW
),
2304 M (WM_EMACS_SETWINDOWPOS
),
2305 M (WM_EMACS_DESTROYWINDOW
),
2306 M (WM_EMACS_TRACKPOPUPMENU
),
2307 M (WM_EMACS_SETFOCUS
),
2308 M (WM_EMACS_SETFOREGROUND
),
2309 M (WM_EMACS_SETLOCALE
),
2310 M (WM_EMACS_SETKEYBOARDLAYOUT
),
2311 M (WM_EMACS_REGISTER_HOT_KEY
),
2312 M (WM_EMACS_UNREGISTER_HOT_KEY
),
2313 M (WM_EMACS_TOGGLE_LOCK_KEY
),
2314 M (WM_EMACS_TRACK_CARET
),
2315 M (WM_EMACS_DESTROY_CARET
),
2316 M (WM_EMACS_SHOW_CARET
),
2317 M (WM_EMACS_HIDE_CARET
),
2318 M (WM_EMACS_SETCURSOR
),
2325 for (i
= 0; msgnames
[i
].name
; ++i
)
2326 if (msgnames
[i
].msg
== msg
)
2327 return msgnames
[i
].name
;
2329 sprintf (buf
, "message 0x%04x", (unsigned)msg
);
2332 #endif /* EMACSDEBUG */
2334 /* Here's an overview of how Emacs input works in GUI sessions on
2335 MS-Windows. (For description of non-GUI input, see the commentary
2336 before w32_console_read_socket in w32inevt.c.)
2338 System messages are read and processed by w32_msg_pump below. This
2339 function runs in a separate thread. It handles a small number of
2340 custom WM_EMACS_* messages (posted by the main thread, look for
2341 PostMessage calls), and dispatches the rest to w32_wnd_proc, which
2342 is the main window procedure for the entire Emacs application.
2344 w32_wnd_proc also runs in the same separate input thread. It
2345 handles some messages, mostly those that need GDI calls, by itself.
2346 For the others, it calls my_post_msg, which inserts the messages
2347 into the input queue serviced by w32_read_socket.
2349 w32_read_socket runs in the main (a.k.a. "Lisp") thread, and is
2350 called synchronously from keyboard.c when it is known or suspected
2351 that some input is available. w32_read_socket either handles
2352 messages immediately, or converts them into Emacs input events and
2353 stuffs them into kbd_buffer, where kbd_buffer_get_event can get at
2354 them and process them when read_char and its callers require
2357 Under Cygwin with the W32 toolkit, the use of /dev/windows with
2358 select(2) takes the place of w32_read_socket.
2362 /* Main message dispatch loop. */
2365 w32_msg_pump (deferred_msg
* msg_buf
)
2371 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
2373 while ((w32_unicode_gui
? GetMessageW
: GetMessageA
) (&msg
, NULL
, 0, 0))
2376 /* DebPrint (("w32_msg_pump: %s time:%u\n", */
2377 /* w32_name_of_message (msg.message), msg.time)); */
2379 if (msg
.hwnd
== NULL
)
2381 switch (msg
.message
)
2384 /* Produced by complete_deferred_msg; just ignore. */
2386 case WM_EMACS_CREATEWINDOW
:
2387 /* Initialize COM for this window. Even though we don't use it,
2388 some third party shell extensions can cause it to be used in
2389 system dialogs, which causes a crash if it is not initialized.
2390 This is a known bug in Windows, which was fixed long ago, but
2391 the patch for XP is not publicly available until XP SP3,
2392 and older versions will never be patched. */
2393 CoInitialize (NULL
);
2394 w32_createwindow ((struct frame
*) msg
.wParam
);
2395 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2398 case WM_EMACS_SETLOCALE
:
2399 SetThreadLocale (msg
.wParam
);
2400 /* Reply is not expected. */
2402 case WM_EMACS_SETKEYBOARDLAYOUT
:
2403 result
= (WPARAM
) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
2404 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2408 case WM_EMACS_REGISTER_HOT_KEY
:
2409 focus_window
= GetFocus ();
2410 if (focus_window
!= NULL
)
2411 RegisterHotKey (focus_window
,
2412 RAW_HOTKEY_ID (msg
.wParam
),
2413 RAW_HOTKEY_MODIFIERS (msg
.wParam
),
2414 RAW_HOTKEY_VK_CODE (msg
.wParam
));
2415 /* Reply is not expected. */
2417 case WM_EMACS_UNREGISTER_HOT_KEY
:
2418 focus_window
= GetFocus ();
2419 if (focus_window
!= NULL
)
2420 UnregisterHotKey (focus_window
, RAW_HOTKEY_ID (msg
.wParam
));
2421 /* Mark item as erased. NB: this code must be
2422 thread-safe. The next line is okay because the cons
2423 cell is never made into garbage and is not relocated by
2425 XSETCAR (XIL ((EMACS_INT
) msg
.lParam
), Qnil
);
2426 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2429 case WM_EMACS_TOGGLE_LOCK_KEY
:
2431 int vk_code
= (int) msg
.wParam
;
2432 int cur_state
= (GetKeyState (vk_code
) & 1);
2433 Lisp_Object new_state
= XIL ((EMACS_INT
) msg
.lParam
);
2435 /* NB: This code must be thread-safe. It is safe to
2436 call NILP because symbols are not relocated by GC,
2437 and pointer here is not touched by GC (so the markbit
2438 can't be set). Numbers are safe because they are
2439 immediate values. */
2440 if (NILP (new_state
)
2441 || (NUMBERP (new_state
)
2442 && ((XUINT (new_state
)) & 1) != cur_state
))
2444 one_w32_display_info
.faked_key
= vk_code
;
2446 keybd_event ((BYTE
) vk_code
,
2447 (BYTE
) MapVirtualKey (vk_code
, 0),
2448 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2449 keybd_event ((BYTE
) vk_code
,
2450 (BYTE
) MapVirtualKey (vk_code
, 0),
2451 KEYEVENTF_EXTENDEDKEY
| 0, 0);
2452 keybd_event ((BYTE
) vk_code
,
2453 (BYTE
) MapVirtualKey (vk_code
, 0),
2454 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2455 cur_state
= !cur_state
;
2457 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2463 /* Broadcast messages make it here, so you need to be looking
2464 for something in particular for this to be useful. */
2466 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
2472 if (w32_unicode_gui
)
2473 DispatchMessageW (&msg
);
2475 DispatchMessageA (&msg
);
2478 /* Exit nested loop when our deferred message has completed. */
2479 if (msg_buf
->completed
)
2484 deferred_msg
* deferred_msg_head
;
2486 static deferred_msg
*
2487 find_deferred_msg (HWND hwnd
, UINT msg
)
2489 deferred_msg
* item
;
2491 /* Don't actually need synchronization for read access, since
2492 modification of single pointer is always atomic. */
2493 /* enter_crit (); */
2495 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2496 if (item
->w32msg
.msg
.hwnd
== hwnd
2497 && item
->w32msg
.msg
.message
== msg
)
2500 /* leave_crit (); */
2506 send_deferred_msg (deferred_msg
* msg_buf
,
2512 /* Only input thread can send deferred messages. */
2513 if (GetCurrentThreadId () != dwWindowsThreadId
)
2516 /* It is an error to send a message that is already deferred. */
2517 if (find_deferred_msg (hwnd
, msg
) != NULL
)
2520 /* Enforced synchronization is not needed because this is the only
2521 function that alters deferred_msg_head, and the following critical
2522 section is guaranteed to only be serially reentered (since only the
2523 input thread can call us). */
2525 /* enter_crit (); */
2527 msg_buf
->completed
= 0;
2528 msg_buf
->next
= deferred_msg_head
;
2529 deferred_msg_head
= msg_buf
;
2530 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
2532 /* leave_crit (); */
2534 /* Start a new nested message loop to process other messages until
2535 this one is completed. */
2536 w32_msg_pump (msg_buf
);
2538 deferred_msg_head
= msg_buf
->next
;
2540 return msg_buf
->result
;
2544 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
2546 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
2548 if (msg_buf
== NULL
)
2549 /* Message may have been canceled, so don't abort. */
2552 msg_buf
->result
= result
;
2553 msg_buf
->completed
= 1;
2555 /* Ensure input thread is woken so it notices the completion. */
2556 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2560 cancel_all_deferred_msgs (void)
2562 deferred_msg
* item
;
2564 /* Don't actually need synchronization for read access, since
2565 modification of single pointer is always atomic. */
2566 /* enter_crit (); */
2568 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2571 item
->completed
= 1;
2574 /* leave_crit (); */
2576 /* Ensure input thread is woken so it notices the completion. */
2577 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2581 w32_msg_worker (void *arg
)
2584 deferred_msg dummy_buf
;
2586 /* Ensure our message queue is created */
2588 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
2590 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2593 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
2594 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
2595 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
2597 /* This is the initial message loop which should only exit when the
2598 application quits. */
2599 w32_msg_pump (&dummy_buf
);
2605 signal_user_input (void)
2607 /* Interrupt any lisp that wants to be interrupted by input. */
2608 if (!NILP (Vthrow_on_input
))
2610 Vquit_flag
= Vthrow_on_input
;
2611 /* Doing a QUIT from this thread is a bad idea, since this
2612 unwinds the stack of the Lisp thread, and the Windows runtime
2613 rightfully barfs. Disabled. */
2615 /* If we're inside a function that wants immediate quits,
2617 if (immediate_quit
&& NILP (Vinhibit_quit
))
2628 post_character_message (HWND hwnd
, UINT msg
,
2629 WPARAM wParam
, LPARAM lParam
,
2634 wmsg
.dwModifiers
= modifiers
;
2636 /* Detect quit_char and set quit-flag directly. Note that we
2637 still need to post a message to ensure the main thread will be
2638 woken up if blocked in sys_select, but we do NOT want to post
2639 the quit_char message itself (because it will usually be as if
2640 the user had typed quit_char twice). Instead, we post a dummy
2641 message that has no particular effect. */
2644 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
2645 c
= make_ctrl_char (c
) & 0377;
2647 || (wmsg
.dwModifiers
== 0
2648 && w32_quit_key
&& wParam
== w32_quit_key
))
2652 /* The choice of message is somewhat arbitrary, as long as
2653 the main thread handler just ignores it. */
2656 /* Interrupt any blocking system calls. */
2659 /* As a safety precaution, forcibly complete any deferred
2660 messages. This is a kludge, but I don't see any particularly
2661 clean way to handle the situation where a deferred message is
2662 "dropped" in the lisp thread, and will thus never be
2663 completed, eg. by the user trying to activate the menubar
2664 when the lisp thread is busy, and then typing C-g when the
2665 menubar doesn't open promptly (with the result that the
2666 menubar never responds at all because the deferred
2667 WM_INITMENU message is never completed). Another problem
2668 situation is when the lisp thread calls SendMessage (to send
2669 a window manager command) when a message has been deferred;
2670 the lisp thread gets blocked indefinitely waiting for the
2671 deferred message to be completed, which itself is waiting for
2672 the lisp thread to respond.
2674 Note that we don't want to block the input thread waiting for
2675 a response from the lisp thread (although that would at least
2676 solve the deadlock problem above), because we want to be able
2677 to receive C-g to interrupt the lisp thread. */
2678 cancel_all_deferred_msgs ();
2681 signal_user_input ();
2684 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2687 /* Main window procedure */
2689 static LRESULT CALLBACK
2690 w32_wnd_proc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2693 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
2695 int windows_translate
;
2698 /* Note that it is okay to call x_window_to_frame, even though we are
2699 not running in the main lisp thread, because frame deletion
2700 requires the lisp thread to synchronize with this thread. Thus, if
2701 a frame struct is returned, it can be used without concern that the
2702 lisp thread might make it disappear while we are using it.
2704 NB. Walking the frame list in this thread is safe (as long as
2705 writes of Lisp_Object slots are atomic, which they are on Windows).
2706 Although delete-frame can destructively modify the frame list while
2707 we are walking it, a garbage collection cannot occur until after
2708 delete-frame has synchronized with this thread.
2710 It is also safe to use functions that make GDI calls, such as
2711 w32_clear_rect, because these functions must obtain a DC handle
2712 from the frame struct using get_frame_dc which is thread-aware. */
2717 f
= x_window_to_frame (dpyinfo
, hwnd
);
2720 HDC hdc
= get_frame_dc (f
);
2721 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
2722 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
2723 release_frame_dc (f
, hdc
);
2725 #if defined (W32_DEBUG_DISPLAY)
2726 DebPrint (("WM_ERASEBKGND (frame %p): erasing %d,%d-%d,%d\n",
2728 wmsg
.rect
.left
, wmsg
.rect
.top
,
2729 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2730 #endif /* W32_DEBUG_DISPLAY */
2733 case WM_PALETTECHANGED
:
2734 /* ignore our own changes */
2735 if ((HWND
)wParam
!= hwnd
)
2737 f
= x_window_to_frame (dpyinfo
, hwnd
);
2739 /* get_frame_dc will realize our palette and force all
2740 frames to be redrawn if needed. */
2741 release_frame_dc (f
, get_frame_dc (f
));
2746 PAINTSTRUCT paintStruct
;
2748 memset (&update_rect
, 0, sizeof (update_rect
));
2750 f
= x_window_to_frame (dpyinfo
, hwnd
);
2753 DebPrint (("WM_PAINT received for unknown window %p\n", hwnd
));
2757 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
2758 fails. Apparently this can happen under some
2760 if (GetUpdateRect (hwnd
, &update_rect
, FALSE
) || !w32_strict_painting
)
2763 BeginPaint (hwnd
, &paintStruct
);
2765 /* The rectangles returned by GetUpdateRect and BeginPaint
2766 do not always match. Play it safe by assuming both areas
2768 UnionRect (&(wmsg
.rect
), &update_rect
, &(paintStruct
.rcPaint
));
2770 #if defined (W32_DEBUG_DISPLAY)
2771 DebPrint (("WM_PAINT (frame %p): painting %d,%d-%d,%d\n",
2773 wmsg
.rect
.left
, wmsg
.rect
.top
,
2774 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2775 DebPrint ((" [update region is %d,%d-%d,%d]\n",
2776 update_rect
.left
, update_rect
.top
,
2777 update_rect
.right
, update_rect
.bottom
));
2779 EndPaint (hwnd
, &paintStruct
);
2782 /* Change the message type to prevent Windows from
2783 combining WM_PAINT messages in the Lisp thread's queue,
2784 since Windows assumes that each message queue is
2785 dedicated to one frame and does not bother checking
2786 that hwnd matches before combining them. */
2787 my_post_msg (&wmsg
, hwnd
, WM_EMACS_PAINT
, wParam
, lParam
);
2792 /* If GetUpdateRect returns 0 (meaning there is no update
2793 region), assume the whole window needs to be repainted. */
2794 GetClientRect (hwnd
, &wmsg
.rect
);
2795 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2799 case WM_INPUTLANGCHANGE
:
2800 /* Inform lisp thread of keyboard layout changes. */
2801 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2803 /* Clear dead keys in the keyboard state; for simplicity only
2804 preserve modifier key states. */
2809 GetKeyboardState (keystate
);
2810 for (i
= 0; i
< 256; i
++)
2827 SetKeyboardState (keystate
);
2832 /* Synchronize hot keys with normal input. */
2833 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
2838 record_keyup (wParam
, lParam
);
2843 /* Ignore keystrokes we fake ourself; see below. */
2844 if (dpyinfo
->faked_key
== wParam
)
2846 dpyinfo
->faked_key
= 0;
2847 /* Make sure TranslateMessage sees them though (as long as
2848 they don't produce WM_CHAR messages). This ensures that
2849 indicator lights are toggled promptly on Windows 9x, for
2851 if (wParam
< 256 && lispy_function_keys
[wParam
])
2853 windows_translate
= 1;
2859 /* Synchronize modifiers with current keystroke. */
2861 record_keydown (wParam
, lParam
);
2862 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
2864 windows_translate
= 0;
2869 if (NILP (Vw32_pass_lwindow_to_system
))
2871 /* Prevent system from acting on keyup (which opens the
2872 Start menu if no other key was pressed) by simulating a
2873 press of Space which we will ignore. */
2874 if (GetAsyncKeyState (wParam
) & 1)
2876 if (NUMBERP (Vw32_phantom_key_code
))
2877 key
= XUINT (Vw32_phantom_key_code
) & 255;
2880 dpyinfo
->faked_key
= key
;
2881 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
2884 if (!NILP (Vw32_lwindow_modifier
))
2888 if (NILP (Vw32_pass_rwindow_to_system
))
2890 if (GetAsyncKeyState (wParam
) & 1)
2892 if (NUMBERP (Vw32_phantom_key_code
))
2893 key
= XUINT (Vw32_phantom_key_code
) & 255;
2896 dpyinfo
->faked_key
= key
;
2897 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
2900 if (!NILP (Vw32_rwindow_modifier
))
2904 if (!NILP (Vw32_apps_modifier
))
2908 if (NILP (Vw32_pass_alt_to_system
))
2909 /* Prevent DefWindowProc from activating the menu bar if an
2910 Alt key is pressed and released by itself. */
2912 windows_translate
= 1;
2915 /* Decide whether to treat as modifier or function key. */
2916 if (NILP (Vw32_enable_caps_lock
))
2917 goto disable_lock_key
;
2918 windows_translate
= 1;
2921 /* Decide whether to treat as modifier or function key. */
2922 if (NILP (Vw32_enable_num_lock
))
2923 goto disable_lock_key
;
2924 windows_translate
= 1;
2927 /* Decide whether to treat as modifier or function key. */
2928 if (NILP (Vw32_scroll_lock_modifier
))
2929 goto disable_lock_key
;
2930 windows_translate
= 1;
2933 /* Ensure the appropriate lock key state (and indicator light)
2934 remains in the same state. We do this by faking another
2935 press of the relevant key. Apparently, this really is the
2936 only way to toggle the state of the indicator lights. */
2937 dpyinfo
->faked_key
= wParam
;
2938 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
2939 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2940 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
2941 KEYEVENTF_EXTENDEDKEY
| 0, 0);
2942 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
2943 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2944 /* Ensure indicator lights are updated promptly on Windows 9x
2945 (TranslateMessage apparently does this), after forwarding
2947 post_character_message (hwnd
, msg
, wParam
, lParam
,
2948 w32_get_key_modifiers (wParam
, lParam
));
2949 windows_translate
= 1;
2953 case VK_PROCESSKEY
: /* Generated by IME. */
2954 windows_translate
= 1;
2957 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
2958 which is confusing for purposes of key binding; convert
2959 VK_CANCEL events into VK_PAUSE events. */
2963 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
2964 for purposes of key binding; convert these back into
2965 VK_NUMLOCK events, at least when we want to see NumLock key
2966 presses. (Note that there is never any possibility that
2967 VK_PAUSE with Ctrl really is C-Pause as per above.) */
2968 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
2969 wParam
= VK_NUMLOCK
;
2972 /* If not defined as a function key, change it to a WM_CHAR message. */
2973 if (wParam
> 255 || !lispy_function_keys
[wParam
])
2975 DWORD modifiers
= construct_console_modifiers ();
2977 if (!NILP (Vw32_recognize_altgr
)
2978 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
2980 /* Always let TranslateMessage handle AltGr key chords;
2981 for some reason, ToAscii doesn't always process AltGr
2982 chords correctly. */
2983 windows_translate
= 1;
2985 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
2987 /* Handle key chords including any modifiers other
2988 than shift directly, in order to preserve as much
2989 modifier information as possible. */
2990 if ('A' <= wParam
&& wParam
<= 'Z')
2992 /* Don't translate modified alphabetic keystrokes,
2993 so the user doesn't need to constantly switch
2994 layout to type control or meta keystrokes when
2995 the normal layout translates alphabetic
2996 characters to non-ascii characters. */
2997 if (!modifier_set (VK_SHIFT
))
2998 wParam
+= ('a' - 'A');
3003 /* Try to handle other keystrokes by determining the
3004 base character (ie. translating the base key plus
3007 KEY_EVENT_RECORD key
;
3009 key
.bKeyDown
= TRUE
;
3010 key
.wRepeatCount
= 1;
3011 key
.wVirtualKeyCode
= wParam
;
3012 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
3013 key
.uChar
.AsciiChar
= 0;
3014 key
.dwControlKeyState
= modifiers
;
3016 add
= w32_kbd_patch_key (&key
, w32_keyboard_codepage
);
3017 /* 0 means an unrecognized keycode, negative means
3018 dead key. Ignore both. */
3021 /* Forward asciified character sequence. */
3022 post_character_message
3024 (unsigned char) key
.uChar
.AsciiChar
, lParam
,
3025 w32_get_key_modifiers (wParam
, lParam
));
3026 w32_kbd_patch_key (&key
, w32_keyboard_codepage
);
3033 /* Let TranslateMessage handle everything else. */
3034 windows_translate
= 1;
3040 if (windows_translate
)
3042 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
3043 windows_msg
.time
= GetMessageTime ();
3044 TranslateMessage (&windows_msg
);
3056 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3057 signal_user_input ();
3058 my_post_msg (&wmsg
, hwnd
, WM_UNICHAR
, wParam
, lParam
);
3062 post_character_message (hwnd
, msg
, wParam
, lParam
,
3063 w32_get_key_modifiers (wParam
, lParam
));
3067 /* WM_UNICHAR looks promising from the docs, but the exact
3068 circumstances in which TranslateMessage sends it is one of those
3069 Microsoft secret API things that EU and US courts are supposed
3070 to have put a stop to already. Spy++ shows it being sent to Notepad
3071 and other MS apps, but never to Emacs.
3073 Some third party IMEs send it in accordance with the official
3074 documentation though, so handle it here.
3076 UNICODE_NOCHAR is used to test for support for this message.
3077 TRUE indicates that the message is supported. */
3078 if (wParam
== UNICODE_NOCHAR
)
3083 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3084 signal_user_input ();
3085 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3090 /* If we can't get the IME result as Unicode, use default processing,
3091 which will at least allow characters decodable in the system locale
3093 if (!get_composition_string_fn
)
3096 else if (!ignore_ime_char
)
3101 HIMC context
= get_ime_context_fn (hwnd
);
3102 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3103 /* Get buffer size. */
3104 size
= get_composition_string_fn (context
, GCS_RESULTSTR
, NULL
, 0);
3105 buffer
= alloca (size
);
3106 size
= get_composition_string_fn (context
, GCS_RESULTSTR
,
3108 release_ime_context_fn (hwnd
, context
);
3110 signal_user_input ();
3111 for (i
= 0; i
< size
/ sizeof (wchar_t); i
++)
3113 my_post_msg (&wmsg
, hwnd
, WM_UNICHAR
, (WPARAM
) buffer
[i
],
3116 /* Ignore the messages for the rest of the
3117 characters in the string that was output above. */
3118 ignore_ime_char
= (size
/ sizeof (wchar_t)) - 1;
3125 case WM_IME_STARTCOMPOSITION
:
3126 if (!set_ime_composition_window_fn
)
3130 COMPOSITIONFORM form
;
3134 f
= x_window_to_frame (dpyinfo
, hwnd
);
3135 w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
3137 form
.dwStyle
= CFS_RECT
;
3138 form
.ptCurrentPos
.x
= w32_system_caret_x
;
3139 form
.ptCurrentPos
.y
= w32_system_caret_y
;
3141 form
.rcArea
.left
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, 0);
3142 form
.rcArea
.top
= (WINDOW_TOP_EDGE_Y (w
)
3143 + WINDOW_HEADER_LINE_HEIGHT (w
));
3144 form
.rcArea
.right
= (WINDOW_BOX_RIGHT_EDGE_X (w
)
3145 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
3146 - WINDOW_RIGHT_FRINGE_WIDTH (w
));
3147 form
.rcArea
.bottom
= (WINDOW_BOTTOM_EDGE_Y (w
)
3148 - WINDOW_MODE_LINE_HEIGHT (w
));
3150 context
= get_ime_context_fn (hwnd
);
3155 set_ime_composition_window_fn (context
, &form
);
3156 release_ime_context_fn (hwnd
, context
);
3160 case WM_IME_ENDCOMPOSITION
:
3161 ignore_ime_char
= 0;
3164 /* Simulate middle mouse button events when left and right buttons
3165 are used together, but only if user has two button mouse. */
3166 case WM_LBUTTONDOWN
:
3167 case WM_RBUTTONDOWN
:
3168 if (w32_num_mouse_buttons
> 2)
3169 goto handle_plain_button
;
3172 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
3173 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
3175 if (button_state
& this)
3178 if (button_state
== 0)
3181 button_state
|= this;
3183 if (button_state
& other
)
3185 if (mouse_button_timer
)
3187 KillTimer (hwnd
, mouse_button_timer
);
3188 mouse_button_timer
= 0;
3190 /* Generate middle mouse event instead. */
3191 msg
= WM_MBUTTONDOWN
;
3192 button_state
|= MMOUSE
;
3194 else if (button_state
& MMOUSE
)
3196 /* Ignore button event if we've already generated a
3197 middle mouse down event. This happens if the
3198 user releases and press one of the two buttons
3199 after we've faked a middle mouse event. */
3204 /* Flush out saved message. */
3205 post_msg (&saved_mouse_button_msg
);
3207 wmsg
.dwModifiers
= w32_get_modifiers ();
3208 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3209 signal_user_input ();
3211 /* Clear message buffer. */
3212 saved_mouse_button_msg
.msg
.hwnd
= 0;
3216 /* Hold onto message for now. */
3217 mouse_button_timer
=
3218 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
3219 w32_mouse_button_tolerance
, NULL
);
3220 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
3221 saved_mouse_button_msg
.msg
.message
= msg
;
3222 saved_mouse_button_msg
.msg
.wParam
= wParam
;
3223 saved_mouse_button_msg
.msg
.lParam
= lParam
;
3224 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
3225 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
3232 if (w32_num_mouse_buttons
> 2)
3233 goto handle_plain_button
;
3236 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
3237 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
3239 if ((button_state
& this) == 0)
3242 button_state
&= ~this;
3244 if (button_state
& MMOUSE
)
3246 /* Only generate event when second button is released. */
3247 if ((button_state
& other
) == 0)
3250 button_state
&= ~MMOUSE
;
3252 if (button_state
) emacs_abort ();
3259 /* Flush out saved message if necessary. */
3260 if (saved_mouse_button_msg
.msg
.hwnd
)
3262 post_msg (&saved_mouse_button_msg
);
3265 wmsg
.dwModifiers
= w32_get_modifiers ();
3266 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3267 signal_user_input ();
3269 /* Always clear message buffer and cancel timer. */
3270 saved_mouse_button_msg
.msg
.hwnd
= 0;
3271 KillTimer (hwnd
, mouse_button_timer
);
3272 mouse_button_timer
= 0;
3274 if (button_state
== 0)
3279 case WM_XBUTTONDOWN
:
3281 if (w32_pass_extra_mouse_buttons_to_system
)
3283 /* else fall through and process them. */
3284 case WM_MBUTTONDOWN
:
3286 handle_plain_button
:
3291 /* Ignore middle and extra buttons as long as the menu is active. */
3292 f
= x_window_to_frame (dpyinfo
, hwnd
);
3293 if (f
&& f
->output_data
.w32
->menubar_active
)
3296 if (parse_button (msg
, HIWORD (wParam
), &button
, &up
))
3298 if (up
) ReleaseCapture ();
3299 else SetCapture (hwnd
);
3300 button
= (button
== 0) ? LMOUSE
:
3301 ((button
== 1) ? MMOUSE
: RMOUSE
);
3303 button_state
&= ~button
;
3305 button_state
|= button
;
3309 wmsg
.dwModifiers
= w32_get_modifiers ();
3310 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3311 signal_user_input ();
3313 /* Need to return true for XBUTTON messages, false for others,
3314 to indicate that we processed the message. */
3315 return (msg
== WM_XBUTTONDOWN
|| msg
== WM_XBUTTONUP
);
3318 /* Ignore mouse movements as long as the menu is active. These
3319 movements are processed by the window manager anyway, and
3320 it's wrong to handle them as if they happened on the
3321 underlying frame. */
3322 f
= x_window_to_frame (dpyinfo
, hwnd
);
3323 if (f
&& f
->output_data
.w32
->menubar_active
)
3326 /* If the mouse has just moved into the frame, start tracking
3327 it, so we will be notified when it leaves the frame. Mouse
3328 tracking only works under W98 and NT4 and later. On earlier
3329 versions, there is no way of telling when the mouse leaves the
3330 frame, so we just have to put up with help-echo and mouse
3331 highlighting remaining while the frame is not active. */
3332 if (track_mouse_event_fn
&& !track_mouse_window
3333 /* If the menu bar is active, turning on tracking of mouse
3334 movement events might send these events to the tooltip
3335 frame, if the user happens to move the mouse pointer over
3336 the tooltip. But since we don't process events for
3337 tooltip frames, this causes Windows to present a
3338 hourglass cursor, which is ugly and unexpected. So don't
3339 enable tracking mouse events in this case; they will be
3340 restarted when the menu pops down. (Confusingly, the
3341 menubar_active member of f->output_data.w32, tested
3342 above, is only set when a menu was popped up _not_ from
3343 the frame's menu bar, but via x-popup-menu.) */
3346 TRACKMOUSEEVENT tme
;
3347 tme
.cbSize
= sizeof (tme
);
3348 tme
.dwFlags
= TME_LEAVE
;
3349 tme
.hwndTrack
= hwnd
;
3351 track_mouse_event_fn (&tme
);
3352 track_mouse_window
= hwnd
;
3355 if (w32_mouse_move_interval
<= 0
3356 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
3358 wmsg
.dwModifiers
= w32_get_modifiers ();
3359 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3363 /* Hang onto mouse move and scroll messages for a bit, to avoid
3364 sending such events to Emacs faster than it can process them.
3365 If we get more events before the timer from the first message
3366 expires, we just replace the first message. */
3368 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
3370 SetTimer (hwnd
, MOUSE_MOVE_ID
,
3371 w32_mouse_move_interval
, NULL
);
3373 /* Hold onto message for now. */
3374 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
3375 saved_mouse_move_msg
.msg
.message
= msg
;
3376 saved_mouse_move_msg
.msg
.wParam
= wParam
;
3377 saved_mouse_move_msg
.msg
.lParam
= lParam
;
3378 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
3379 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
3385 wmsg
.dwModifiers
= w32_get_modifiers ();
3386 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3387 signal_user_input ();
3391 if (w32_pass_multimedia_buttons_to_system
)
3393 /* Otherwise, pass to lisp, the same way we do with mousehwheel. */
3394 case WM_MOUSEHWHEEL
:
3395 wmsg
.dwModifiers
= w32_get_modifiers ();
3396 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3397 signal_user_input ();
3398 /* Non-zero must be returned when WM_MOUSEHWHEEL messages are
3399 handled, to prevent the system trying to handle it by faking
3400 scroll bar events. */
3404 /* Flush out saved messages if necessary. */
3405 if (wParam
== mouse_button_timer
)
3407 if (saved_mouse_button_msg
.msg
.hwnd
)
3409 post_msg (&saved_mouse_button_msg
);
3410 signal_user_input ();
3411 saved_mouse_button_msg
.msg
.hwnd
= 0;
3413 KillTimer (hwnd
, mouse_button_timer
);
3414 mouse_button_timer
= 0;
3416 else if (wParam
== mouse_move_timer
)
3418 if (saved_mouse_move_msg
.msg
.hwnd
)
3420 post_msg (&saved_mouse_move_msg
);
3421 saved_mouse_move_msg
.msg
.hwnd
= 0;
3423 KillTimer (hwnd
, mouse_move_timer
);
3424 mouse_move_timer
= 0;
3426 else if (wParam
== menu_free_timer
)
3428 KillTimer (hwnd
, menu_free_timer
);
3429 menu_free_timer
= 0;
3430 f
= x_window_to_frame (dpyinfo
, hwnd
);
3431 /* If a popup menu is active, don't wipe its strings. */
3433 && current_popup_menu
== NULL
)
3435 /* Free memory used by owner-drawn and help-echo strings. */
3436 w32_free_menu_strings (hwnd
);
3438 f
->output_data
.w32
->menubar_active
= 0;
3445 /* Windows doesn't send us focus messages when putting up and
3446 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
3447 The only indication we get that something happened is receiving
3448 this message afterwards. So this is a good time to reset our
3449 keyboard modifiers' state. */
3456 /* We must ensure menu bar is fully constructed and up to date
3457 before allowing user interaction with it. To achieve this
3458 we send this message to the lisp thread and wait for a
3459 reply (whose value is not actually needed) to indicate that
3460 the menu bar is now ready for use, so we can now return.
3462 To remain responsive in the meantime, we enter a nested message
3463 loop that can process all other messages.
3465 However, we skip all this if the message results from calling
3466 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
3467 thread a message because it is blocked on us at this point. We
3468 set menubar_active before calling TrackPopupMenu to indicate
3469 this (there is no possibility of confusion with real menubar
3472 f
= x_window_to_frame (dpyinfo
, hwnd
);
3474 && (f
->output_data
.w32
->menubar_active
3475 /* We can receive this message even in the absence of a
3476 menubar (ie. when the system menu is activated) - in this
3477 case we do NOT want to forward the message, otherwise it
3478 will cause the menubar to suddenly appear when the user
3479 had requested it to be turned off! */
3480 || f
->output_data
.w32
->menubar_widget
== NULL
))
3484 deferred_msg msg_buf
;
3486 /* Detect if message has already been deferred; in this case
3487 we cannot return any sensible value to ignore this. */
3488 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3493 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
3496 case WM_EXITMENULOOP
:
3497 f
= x_window_to_frame (dpyinfo
, hwnd
);
3499 /* If a menu is still active, check again after a short delay,
3500 since Windows often (always?) sends the WM_EXITMENULOOP
3501 before the corresponding WM_COMMAND message.
3502 Don't do this if a popup menu is active, since it is only
3503 menubar menus that require cleaning up in this way.
3505 if (f
&& menubar_in_use
&& current_popup_menu
== NULL
)
3506 menu_free_timer
= SetTimer (hwnd
, MENU_FREE_ID
, MENU_FREE_DELAY
, NULL
);
3508 /* If hourglass cursor should be displayed, display it now. */
3509 if (f
&& f
->output_data
.w32
->hourglass_p
)
3510 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
3515 /* Direct handling of help_echo in menus. Should be safe now
3516 that we generate the help_echo by placing a help event in the
3519 HMENU menu
= (HMENU
) lParam
;
3520 UINT menu_item
= (UINT
) LOWORD (wParam
);
3521 UINT flags
= (UINT
) HIWORD (wParam
);
3523 w32_menu_display_help (hwnd
, menu
, menu_item
, flags
);
3527 case WM_MEASUREITEM
:
3528 f
= x_window_to_frame (dpyinfo
, hwnd
);
3531 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
3533 if (pMis
->CtlType
== ODT_MENU
)
3535 /* Work out dimensions for popup menu titles. */
3536 char * title
= (char *) pMis
->itemData
;
3537 HDC hdc
= GetDC (hwnd
);
3538 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3539 LOGFONT menu_logfont
;
3543 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3544 menu_logfont
.lfWeight
= FW_BOLD
;
3545 menu_font
= CreateFontIndirect (&menu_logfont
);
3546 old_font
= SelectObject (hdc
, menu_font
);
3548 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
3551 if (unicode_append_menu
)
3552 GetTextExtentPoint32W (hdc
, (WCHAR
*) title
,
3553 wcslen ((WCHAR
*) title
),
3556 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
3558 pMis
->itemWidth
= size
.cx
;
3559 if (pMis
->itemHeight
< size
.cy
)
3560 pMis
->itemHeight
= size
.cy
;
3563 pMis
->itemWidth
= 0;
3565 SelectObject (hdc
, old_font
);
3566 DeleteObject (menu_font
);
3567 ReleaseDC (hwnd
, hdc
);
3574 f
= x_window_to_frame (dpyinfo
, hwnd
);
3577 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
3579 if (pDis
->CtlType
== ODT_MENU
)
3581 /* Draw popup menu title. */
3582 char * title
= (char *) pDis
->itemData
;
3585 HDC hdc
= pDis
->hDC
;
3586 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3587 LOGFONT menu_logfont
;
3590 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3591 menu_logfont
.lfWeight
= FW_BOLD
;
3592 menu_font
= CreateFontIndirect (&menu_logfont
);
3593 old_font
= SelectObject (hdc
, menu_font
);
3595 /* Always draw title as if not selected. */
3596 if (unicode_append_menu
)
3599 + GetSystemMetrics (SM_CXMENUCHECK
),
3601 ETO_OPAQUE
, &pDis
->rcItem
,
3603 wcslen ((WCHAR
*) title
), NULL
);
3607 + GetSystemMetrics (SM_CXMENUCHECK
),
3609 ETO_OPAQUE
, &pDis
->rcItem
,
3610 title
, strlen (title
), NULL
);
3612 SelectObject (hdc
, old_font
);
3613 DeleteObject (menu_font
);
3621 /* Still not right - can't distinguish between clicks in the
3622 client area of the frame from clicks forwarded from the scroll
3623 bars - may have to hook WM_NCHITTEST to remember the mouse
3624 position and then check if it is in the client area ourselves. */
3625 case WM_MOUSEACTIVATE
:
3626 /* Discard the mouse click that activates a frame, allowing the
3627 user to click anywhere without changing point (or worse!).
3628 Don't eat mouse clicks on scrollbars though!! */
3629 if (LOWORD (lParam
) == HTCLIENT
)
3630 return MA_ACTIVATEANDEAT
;
3635 /* No longer tracking mouse. */
3636 track_mouse_window
= NULL
;
3638 case WM_ACTIVATEAPP
:
3640 case WM_WINDOWPOSCHANGED
:
3642 /* Inform lisp thread that a frame might have just been obscured
3643 or exposed, so should recheck visibility of all frames. */
3644 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3648 dpyinfo
->faked_key
= 0;
3650 register_hot_keys (hwnd
);
3653 unregister_hot_keys (hwnd
);
3656 /* Relinquish the system caret. */
3657 if (w32_system_caret_hwnd
)
3659 w32_visible_system_caret_hwnd
= NULL
;
3660 w32_system_caret_hwnd
= NULL
;
3666 f
= x_window_to_frame (dpyinfo
, hwnd
);
3667 if (f
&& HIWORD (wParam
) == 0)
3669 if (menu_free_timer
)
3671 KillTimer (hwnd
, menu_free_timer
);
3672 menu_free_timer
= 0;
3678 wmsg
.dwModifiers
= w32_get_modifiers ();
3679 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3687 wmsg
.dwModifiers
= w32_get_modifiers ();
3688 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3691 case WM_WINDOWPOSCHANGING
:
3692 /* Don't restrict the sizing of tip frames. */
3693 if (hwnd
== tip_window
)
3697 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
3699 wp
.length
= sizeof (WINDOWPLACEMENT
);
3700 GetWindowPlacement (hwnd
, &wp
);
3702 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
3709 DWORD internal_border
;
3710 DWORD scrollbar_extra
;
3713 wp
.length
= sizeof (wp
);
3714 GetWindowRect (hwnd
, &wr
);
3718 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
3719 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
3720 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
3721 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
3725 memset (&rect
, 0, sizeof (rect
));
3726 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
3727 GetMenu (hwnd
) != NULL
);
3729 /* Force width and height of client area to be exact
3730 multiples of the character cell dimensions. */
3731 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
3732 - 2 * internal_border
- scrollbar_extra
)
3734 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
3735 - 2 * internal_border
)
3740 /* For right/bottom sizing we can just fix the sizes.
3741 However for top/left sizing we will need to fix the X
3742 and Y positions as well. */
3744 int cx_mintrack
= GetSystemMetrics (SM_CXMINTRACK
);
3745 int cy_mintrack
= GetSystemMetrics (SM_CYMINTRACK
);
3747 lppos
->cx
= max (lppos
->cx
- wdiff
, cx_mintrack
);
3748 lppos
->cy
= max (lppos
->cy
- hdiff
, cy_mintrack
);
3750 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
3751 && (lppos
->flags
& SWP_NOMOVE
) == 0)
3753 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
3760 lppos
->flags
|= SWP_NOMOVE
;
3771 case WM_GETMINMAXINFO
:
3772 /* Hack to allow resizing the Emacs frame above the screen size.
3773 Note that Windows 9x limits coordinates to 16-bits. */
3774 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.x
= 32767;
3775 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.y
= 32767;
3779 if (LOWORD (lParam
) == HTCLIENT
)
3781 f
= x_window_to_frame (dpyinfo
, hwnd
);
3782 if (f
&& f
->output_data
.w32
->hourglass_p
3783 && !menubar_in_use
&& !current_popup_menu
)
3784 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
3786 SetCursor (f
->output_data
.w32
->current_cursor
);
3791 case WM_EMACS_SETCURSOR
:
3793 Cursor cursor
= (Cursor
) wParam
;
3794 f
= x_window_to_frame (dpyinfo
, hwnd
);
3797 f
->output_data
.w32
->current_cursor
= cursor
;
3798 if (!f
->output_data
.w32
->hourglass_p
)
3804 case WM_EMACS_CREATESCROLLBAR
:
3805 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
3806 (struct scroll_bar
*) lParam
);
3808 case WM_EMACS_SHOWWINDOW
:
3809 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
3811 case WM_EMACS_BRINGTOTOP
:
3812 case WM_EMACS_SETFOREGROUND
:
3814 HWND foreground_window
;
3815 DWORD foreground_thread
, retval
;
3817 /* On NT 5.0, and apparently Windows 98, it is necessary to
3818 attach to the thread that currently has focus in order to
3819 pull the focus away from it. */
3820 foreground_window
= GetForegroundWindow ();
3821 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
3822 if (!foreground_window
3823 || foreground_thread
== GetCurrentThreadId ()
3824 || !AttachThreadInput (GetCurrentThreadId (),
3825 foreground_thread
, TRUE
))
3826 foreground_thread
= 0;
3828 retval
= SetForegroundWindow ((HWND
) wParam
);
3829 if (msg
== WM_EMACS_BRINGTOTOP
)
3830 retval
= BringWindowToTop ((HWND
) wParam
);
3832 /* Detach from the previous foreground thread. */
3833 if (foreground_thread
)
3834 AttachThreadInput (GetCurrentThreadId (),
3835 foreground_thread
, FALSE
);
3840 case WM_EMACS_SETWINDOWPOS
:
3842 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
3843 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
3844 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
3847 case WM_EMACS_DESTROYWINDOW
:
3848 DragAcceptFiles ((HWND
) wParam
, FALSE
);
3849 return DestroyWindow ((HWND
) wParam
);
3851 case WM_EMACS_HIDE_CARET
:
3852 return HideCaret (hwnd
);
3854 case WM_EMACS_SHOW_CARET
:
3855 return ShowCaret (hwnd
);
3857 case WM_EMACS_DESTROY_CARET
:
3858 w32_system_caret_hwnd
= NULL
;
3859 w32_visible_system_caret_hwnd
= NULL
;
3860 return DestroyCaret ();
3862 case WM_EMACS_TRACK_CARET
:
3863 /* If there is currently no system caret, create one. */
3864 if (w32_system_caret_hwnd
== NULL
)
3866 /* Use the default caret width, and avoid changing it
3867 unnecessarily, as it confuses screen reader software. */
3868 w32_system_caret_hwnd
= hwnd
;
3869 CreateCaret (hwnd
, NULL
, 0,
3870 w32_system_caret_height
);
3873 if (!SetCaretPos (w32_system_caret_x
, w32_system_caret_y
))
3875 /* Ensure visible caret gets turned on when requested. */
3876 else if (w32_use_visible_system_caret
3877 && w32_visible_system_caret_hwnd
!= hwnd
)
3879 w32_visible_system_caret_hwnd
= hwnd
;
3880 return ShowCaret (hwnd
);
3882 /* Ensure visible caret gets turned off when requested. */
3883 else if (!w32_use_visible_system_caret
3884 && w32_visible_system_caret_hwnd
)
3886 w32_visible_system_caret_hwnd
= NULL
;
3887 return HideCaret (hwnd
);
3892 case WM_EMACS_TRACKPOPUPMENU
:
3897 pos
= (POINT
*)lParam
;
3898 flags
= TPM_CENTERALIGN
;
3899 if (button_state
& LMOUSE
)
3900 flags
|= TPM_LEFTBUTTON
;
3901 else if (button_state
& RMOUSE
)
3902 flags
|= TPM_RIGHTBUTTON
;
3904 /* Remember we did a SetCapture on the initial mouse down event,
3905 so for safety, we make sure the capture is canceled now. */
3909 /* Use menubar_active to indicate that WM_INITMENU is from
3910 TrackPopupMenu below, and should be ignored. */
3911 f
= x_window_to_frame (dpyinfo
, hwnd
);
3913 f
->output_data
.w32
->menubar_active
= 1;
3915 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
3919 /* Eat any mouse messages during popupmenu */
3920 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
3922 /* Get the menu selection, if any */
3923 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
3925 retval
= LOWORD (amsg
.wParam
);
3941 /* Check for messages registered at runtime. */
3942 if (msg
== msh_mousewheel
)
3944 wmsg
.dwModifiers
= w32_get_modifiers ();
3945 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3946 signal_user_input ();
3951 return (w32_unicode_gui
? DefWindowProcW
: DefWindowProcA
) (hwnd
, msg
, wParam
, lParam
);
3954 /* The most common default return code for handled messages is 0. */
3959 my_create_window (struct frame
* f
)
3963 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
3965 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
3969 /* Create a tooltip window. Unlike my_create_window, we do not do this
3970 indirectly via the Window thread, as we do not need to process Window
3971 messages for the tooltip. Creating tooltips indirectly also creates
3972 deadlocks when tooltips are created for menu items. */
3974 my_create_tip_window (struct frame
*f
)
3978 rect
.left
= rect
.top
= 0;
3979 rect
.right
= FRAME_PIXEL_WIDTH (f
);
3980 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
3982 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
3983 FRAME_EXTERNAL_MENU_BAR (f
));
3985 tip_window
= FRAME_W32_WINDOW (f
)
3986 = CreateWindow (EMACS_CLASS
,
3988 f
->output_data
.w32
->dwStyle
,
3991 rect
.right
- rect
.left
,
3992 rect
.bottom
- rect
.top
,
3993 FRAME_W32_WINDOW (SELECTED_FRAME ()), /* owner */
4000 SetWindowLong (tip_window
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
4001 SetWindowLong (tip_window
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
4002 SetWindowLong (tip_window
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
4003 SetWindowLong (tip_window
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
4005 /* Tip frames have no scrollbars. */
4006 SetWindowLong (tip_window
, WND_SCROLLBAR_INDEX
, 0);
4008 /* Do this to discard the default setting specified by our parent. */
4009 ShowWindow (tip_window
, SW_HIDE
);
4014 /* Create and set up the w32 window for frame F. */
4017 w32_window (struct frame
*f
, long window_prompting
, int minibuffer_only
)
4021 /* Use the resource name as the top-level window name
4022 for looking up resources. Make a non-Lisp copy
4023 for the window manager, so GC relocation won't bother it.
4025 Elsewhere we specify the window name for the window manager. */
4028 char *str
= SSDATA (Vx_resource_name
);
4029 f
->namebuf
= xmalloc (strlen (str
) + 1);
4030 strcpy (f
->namebuf
, str
);
4033 my_create_window (f
);
4035 validate_x_resource_name ();
4037 /* x_set_name normally ignores requests to set the name if the
4038 requested name is the same as the current name. This is the one
4039 place where that assumption isn't correct; f->name is set, but
4040 the server hasn't been told. */
4043 int explicit = f
->explicit_name
;
4045 f
->explicit_name
= 0;
4047 fset_name (f
, Qnil
);
4048 x_set_name (f
, name
, explicit);
4053 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
4054 initialize_frame_menubar (f
);
4056 if (FRAME_W32_WINDOW (f
) == 0)
4057 error ("Unable to create window");
4060 /* Handle the icon stuff for this window. Perhaps later we might
4061 want an x_set_icon_position which can be called interactively as
4065 x_icon (struct frame
*f
, Lisp_Object parms
)
4067 Lisp_Object icon_x
, icon_y
;
4068 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
4070 /* Set the position of the icon. Note that Windows 95 groups all
4071 icons in the tray. */
4072 icon_x
= x_get_arg (dpyinfo
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
4073 icon_y
= x_get_arg (dpyinfo
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
4074 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
4076 CHECK_NUMBER (icon_x
);
4077 CHECK_NUMBER (icon_y
);
4079 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
4080 error ("Both left and top icon corners of icon must be specified");
4084 if (! EQ (icon_x
, Qunbound
))
4085 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
4088 /* Start up iconic or window? */
4089 x_wm_set_window_state
4090 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
4094 x_text_icon (f
, SSDATA ((!NILP (f
->icon_name
)
4104 x_make_gc (struct frame
*f
)
4106 XGCValues gc_values
;
4110 /* Create the GC's of this frame.
4111 Note that many default values are used. */
4114 gc_values
.font
= FRAME_FONT (f
);
4116 /* Cursor has cursor-color background, background-color foreground. */
4117 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
4118 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
4119 f
->output_data
.w32
->cursor_gc
4120 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
4121 (GCFont
| GCForeground
| GCBackground
),
4125 f
->output_data
.w32
->white_relief
.gc
= 0;
4126 f
->output_data
.w32
->black_relief
.gc
= 0;
4132 /* Handler for signals raised during x_create_frame and
4133 x_create_tip_frame. FRAME is the frame which is partially
4137 unwind_create_frame (Lisp_Object frame
)
4139 struct frame
*f
= XFRAME (frame
);
4141 /* If frame is ``official'', nothing to do. */
4142 if (NILP (Fmemq (frame
, Vframe_list
)))
4145 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4148 x_free_frame_resources (f
);
4152 /* Check that reference counts are indeed correct. */
4153 eassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
4154 eassert (dpyinfo
->terminal
->image_cache
->refcount
== image_cache_refcount
);
4163 x_default_font_parameter (struct frame
*f
, Lisp_Object parms
)
4165 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4166 Lisp_Object font_param
= x_get_arg (dpyinfo
, parms
, Qfont
, NULL
, NULL
,
4169 if (EQ (font_param
, Qunbound
))
4171 font
= !NILP (font_param
) ? font_param
4172 : x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4174 if (!STRINGP (font
))
4177 static char *names
[]
4178 = { "Courier New-10",
4179 "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1",
4180 "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1",
4184 for (i
= 0; names
[i
]; i
++)
4186 font
= font_open_by_name (f
, build_unibyte_string (names
[i
]));
4191 error ("No suitable font was found");
4193 else if (!NILP (font_param
))
4195 /* Remember the explicit font parameter, so we can re-apply it after
4196 we've applied the `default' face settings. */
4197 x_set_frame_parameters (f
, Fcons (Fcons (Qfont_param
, font_param
), Qnil
));
4199 x_default_parameter (f
, parms
, Qfont
, font
, "font", "Font", RES_TYPE_STRING
);
4202 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
4204 doc
: /* Make a new window, which is called a \"frame\" in Emacs terms.
4205 Return an Emacs frame object.
4206 PARAMETERS is an alist of frame parameters.
4207 If the parameters specify that the frame should not have a minibuffer,
4208 and do not specify a specific minibuffer window to use,
4209 then `default-minibuffer-frame' must be a frame whose minibuffer can
4210 be shared by the new frame.
4212 This function is an internal primitive--use `make-frame' instead. */)
4213 (Lisp_Object parameters
)
4216 Lisp_Object frame
, tem
;
4218 int minibuffer_only
= 0;
4219 long window_prompting
= 0;
4221 ptrdiff_t count
= SPECPDL_INDEX ();
4222 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4223 Lisp_Object display
;
4224 struct w32_display_info
*dpyinfo
= NULL
;
4228 /* Make copy of frame parameters because the original is in pure
4230 parameters
= Fcopy_alist (parameters
);
4232 /* Use this general default value to start with
4233 until we know if this frame has a specified name. */
4234 Vx_resource_name
= Vinvocation_name
;
4236 display
= x_get_arg (dpyinfo
, parameters
, Qterminal
, 0, 0, RES_TYPE_NUMBER
);
4237 if (EQ (display
, Qunbound
))
4238 display
= x_get_arg (dpyinfo
, parameters
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
4239 if (EQ (display
, Qunbound
))
4241 dpyinfo
= check_x_display_info (display
);
4242 kb
= dpyinfo
->terminal
->kboard
;
4244 if (!dpyinfo
->terminal
->name
)
4245 error ("Terminal is not live, can't create new frames on it");
4247 name
= x_get_arg (dpyinfo
, parameters
, Qname
, "name", "Name", RES_TYPE_STRING
);
4249 && ! EQ (name
, Qunbound
)
4251 error ("Invalid frame name--not a string or nil");
4254 Vx_resource_name
= name
;
4256 /* See if parent window is specified. */
4257 parent
= x_get_arg (dpyinfo
, parameters
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
4258 if (EQ (parent
, Qunbound
))
4260 if (! NILP (parent
))
4261 CHECK_NUMBER (parent
);
4263 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
4264 /* No need to protect DISPLAY because that's not used after passing
4265 it to make_frame_without_minibuffer. */
4267 GCPRO4 (parameters
, parent
, name
, frame
);
4268 tem
= x_get_arg (dpyinfo
, parameters
, Qminibuffer
, "minibuffer", "Minibuffer",
4270 if (EQ (tem
, Qnone
) || NILP (tem
))
4271 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
4272 else if (EQ (tem
, Qonly
))
4274 f
= make_minibuffer_frame ();
4275 minibuffer_only
= 1;
4277 else if (WINDOWP (tem
))
4278 f
= make_frame_without_minibuffer (tem
, kb
, display
);
4282 XSETFRAME (frame
, f
);
4284 /* By default, make scrollbars the system standard width. */
4285 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
4287 f
->terminal
= dpyinfo
->terminal
;
4289 f
->output_method
= output_w32
;
4290 f
->output_data
.w32
= xzalloc (sizeof (struct w32_output
));
4291 FRAME_FONTSET (f
) = -1;
4294 (f
, x_get_arg (dpyinfo
, parameters
, Qicon_name
, "iconName", "Title",
4296 if (! STRINGP (f
->icon_name
))
4297 fset_icon_name (f
, Qnil
);
4299 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
4301 /* With FRAME_X_DISPLAY_INFO set up, this unwind-protect is safe. */
4302 record_unwind_protect (unwind_create_frame
, frame
);
4304 image_cache_refcount
=
4305 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
4306 dpyinfo_refcount
= dpyinfo
->reference_count
;
4307 #endif /* GLYPH_DEBUG */
4309 /* Specify the parent under which to make this window. */
4313 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
4314 f
->output_data
.w32
->explicit_parent
= 1;
4318 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4319 f
->output_data
.w32
->explicit_parent
= 0;
4322 /* Set the name; the functions to which we pass f expect the name to
4324 if (EQ (name
, Qunbound
) || NILP (name
))
4326 fset_name (f
, build_string (dpyinfo
->w32_id_name
));
4327 f
->explicit_name
= 0;
4331 fset_name (f
, name
);
4332 f
->explicit_name
= 1;
4333 /* use the frame's title when getting resources for this frame. */
4334 specbind (Qx_resource_name
, name
);
4337 f
->resx
= dpyinfo
->resx
;
4338 f
->resy
= dpyinfo
->resy
;
4340 if (uniscribe_available
)
4341 register_font_driver (&uniscribe_font_driver
, f
);
4342 register_font_driver (&w32font_driver
, f
);
4344 x_default_parameter (f
, parameters
, Qfont_backend
, Qnil
,
4345 "fontBackend", "FontBackend", RES_TYPE_STRING
);
4346 /* Extract the window parameters from the supplied values
4347 that are needed to determine window geometry. */
4348 x_default_font_parameter (f
, parameters
);
4349 x_default_parameter (f
, parameters
, Qborder_width
, make_number (2),
4350 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4352 /* We recognize either internalBorderWidth or internalBorder
4353 (which is what xterm calls it). */
4354 if (NILP (Fassq (Qinternal_border_width
, parameters
)))
4358 value
= x_get_arg (dpyinfo
, parameters
, Qinternal_border_width
,
4359 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
4360 if (! EQ (value
, Qunbound
))
4361 parameters
= Fcons (Fcons (Qinternal_border_width
, value
),
4364 /* Default internalBorderWidth to 0 on Windows to match other programs. */
4365 x_default_parameter (f
, parameters
, Qinternal_border_width
, make_number (0),
4366 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
4367 x_default_parameter (f
, parameters
, Qvertical_scroll_bars
, Qright
,
4368 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
4370 /* Also do the stuff which must be set before the window exists. */
4371 x_default_parameter (f
, parameters
, Qforeground_color
, build_string ("black"),
4372 "foreground", "Foreground", RES_TYPE_STRING
);
4373 x_default_parameter (f
, parameters
, Qbackground_color
, build_string ("white"),
4374 "background", "Background", RES_TYPE_STRING
);
4375 x_default_parameter (f
, parameters
, Qmouse_color
, build_string ("black"),
4376 "pointerColor", "Foreground", RES_TYPE_STRING
);
4377 x_default_parameter (f
, parameters
, Qborder_color
, build_string ("black"),
4378 "borderColor", "BorderColor", RES_TYPE_STRING
);
4379 x_default_parameter (f
, parameters
, Qscreen_gamma
, Qnil
,
4380 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
4381 x_default_parameter (f
, parameters
, Qline_spacing
, Qnil
,
4382 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
4383 x_default_parameter (f
, parameters
, Qleft_fringe
, Qnil
,
4384 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
4385 x_default_parameter (f
, parameters
, Qright_fringe
, Qnil
,
4386 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
4388 /* Init faces before x_default_parameter is called for scroll-bar
4389 parameters because that function calls x_set_scroll_bar_width,
4390 which calls change_frame_size, which calls Fset_window_buffer,
4391 which runs hooks, which call Fvertical_motion. At the end, we
4392 end up in init_iterator with a null face cache, which should not
4394 init_frame_faces (f
);
4396 /* The X resources controlling the menu-bar and tool-bar are
4397 processed specially at startup, and reflected in the mode
4398 variables; ignore them here. */
4399 x_default_parameter (f
, parameters
, Qmenu_bar_lines
,
4400 NILP (Vmenu_bar_mode
)
4401 ? make_number (0) : make_number (1),
4402 NULL
, NULL
, RES_TYPE_NUMBER
);
4403 x_default_parameter (f
, parameters
, Qtool_bar_lines
,
4404 NILP (Vtool_bar_mode
)
4405 ? make_number (0) : make_number (1),
4406 NULL
, NULL
, RES_TYPE_NUMBER
);
4408 x_default_parameter (f
, parameters
, Qbuffer_predicate
, Qnil
,
4409 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
4410 x_default_parameter (f
, parameters
, Qtitle
, Qnil
,
4411 "title", "Title", RES_TYPE_STRING
);
4412 x_default_parameter (f
, parameters
, Qfullscreen
, Qnil
,
4413 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
4415 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
4416 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4418 f
->output_data
.w32
->text_cursor
= w32_load_cursor (IDC_IBEAM
);
4419 f
->output_data
.w32
->nontext_cursor
= w32_load_cursor (IDC_ARROW
);
4420 f
->output_data
.w32
->modeline_cursor
= w32_load_cursor (IDC_ARROW
);
4421 f
->output_data
.w32
->hand_cursor
= w32_load_cursor (IDC_HAND
);
4422 f
->output_data
.w32
->hourglass_cursor
= w32_load_cursor (IDC_WAIT
);
4423 f
->output_data
.w32
->horizontal_drag_cursor
= w32_load_cursor (IDC_SIZEWE
);
4425 f
->output_data
.w32
->current_cursor
= f
->output_data
.w32
->nontext_cursor
;
4427 window_prompting
= x_figure_window_size (f
, parameters
, 1);
4429 tem
= x_get_arg (dpyinfo
, parameters
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
4430 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
4432 w32_window (f
, window_prompting
, minibuffer_only
);
4433 x_icon (f
, parameters
);
4437 /* Now consider the frame official. */
4438 f
->terminal
->reference_count
++;
4439 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
4440 Vframe_list
= Fcons (frame
, Vframe_list
);
4442 /* We need to do this after creating the window, so that the
4443 icon-creation functions can say whose icon they're describing. */
4444 x_default_parameter (f
, parameters
, Qicon_type
, Qnil
,
4445 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
4447 x_default_parameter (f
, parameters
, Qauto_raise
, Qnil
,
4448 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4449 x_default_parameter (f
, parameters
, Qauto_lower
, Qnil
,
4450 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4451 x_default_parameter (f
, parameters
, Qcursor_type
, Qbox
,
4452 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4453 x_default_parameter (f
, parameters
, Qscroll_bar_width
, Qnil
,
4454 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
4455 x_default_parameter (f
, parameters
, Qalpha
, Qnil
,
4456 "alpha", "Alpha", RES_TYPE_NUMBER
);
4458 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4459 Change will not be effected unless different from the current
4461 width
= FRAME_COLS (f
);
4462 height
= FRAME_LINES (f
);
4464 FRAME_LINES (f
) = 0;
4465 SET_FRAME_COLS (f
, 0);
4466 change_frame_size (f
, height
, width
, 1, 0, 0);
4468 /* Tell the server what size and position, etc, we want, and how
4469 badly we want them. This should be done after we have the menu
4470 bar so that its size can be taken into account. */
4472 x_wm_set_size_hint (f
, window_prompting
, 0);
4475 /* Make the window appear on the frame and enable display, unless
4476 the caller says not to. However, with explicit parent, Emacs
4477 cannot control visibility, so don't try. */
4478 if (! f
->output_data
.w32
->explicit_parent
)
4480 Lisp_Object visibility
;
4482 visibility
= x_get_arg (dpyinfo
, parameters
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
4483 if (EQ (visibility
, Qunbound
))
4486 if (EQ (visibility
, Qicon
))
4487 x_iconify_frame (f
);
4488 else if (! NILP (visibility
))
4489 x_make_frame_visible (f
);
4491 /* Must have been Qnil. */
4495 /* Initialize `default-minibuffer-frame' in case this is the first
4496 frame on this terminal. */
4497 if (FRAME_HAS_MINIBUF_P (f
)
4498 && (!FRAMEP (KVAR (kb
, Vdefault_minibuffer_frame
))
4499 || !FRAME_LIVE_P (XFRAME (KVAR (kb
, Vdefault_minibuffer_frame
)))))
4500 kset_default_minibuffer_frame (kb
, frame
);
4502 /* All remaining specified parameters, which have not been "used"
4503 by x_get_arg and friends, now go in the misc. alist of the frame. */
4504 for (tem
= parameters
; CONSP (tem
); tem
= XCDR (tem
))
4505 if (CONSP (XCAR (tem
)) && !NILP (XCAR (XCAR (tem
))))
4506 fset_param_alist (f
, Fcons (XCAR (tem
), f
->param_alist
));
4510 /* Make sure windows on this frame appear in calls to next-window
4511 and similar functions. */
4512 Vwindow_list
= Qnil
;
4514 return unbind_to (count
, frame
);
4517 /* FRAME is used only to get a handle on the X display. We don't pass the
4518 display info directly because we're called from frame.c, which doesn't
4519 know about that structure. */
4521 x_get_focus_frame (struct frame
*frame
)
4523 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
4525 if (! dpyinfo
->w32_focus_frame
)
4528 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
4532 DEFUN ("x-focus-frame", Fx_focus_frame
, Sx_focus_frame
, 1, 1, 0,
4533 doc
: /* Give FRAME input focus, raising to foreground if necessary. */)
4536 x_focus_on_frame (check_x_frame (frame
));
4541 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
4542 doc
: /* Internal function called by `color-defined-p', which see.
4543 \(Note that the Nextstep version of this function ignores FRAME.) */)
4544 (Lisp_Object color
, Lisp_Object frame
)
4547 FRAME_PTR f
= check_x_frame (frame
);
4549 CHECK_STRING (color
);
4551 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
4557 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
4558 doc
: /* Internal function called by `color-values', which see. */)
4559 (Lisp_Object color
, Lisp_Object frame
)
4562 FRAME_PTR f
= check_x_frame (frame
);
4564 CHECK_STRING (color
);
4566 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
4567 return list3 (make_number ((GetRValue (foo
.pixel
) << 8)
4568 | GetRValue (foo
.pixel
)),
4569 make_number ((GetGValue (foo
.pixel
) << 8)
4570 | GetGValue (foo
.pixel
)),
4571 make_number ((GetBValue (foo
.pixel
) << 8)
4572 | GetBValue (foo
.pixel
)));
4577 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
4578 doc
: /* Internal function called by `display-color-p', which see. */)
4579 (Lisp_Object display
)
4581 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4583 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
4589 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
,
4590 Sx_display_grayscale_p
, 0, 1, 0,
4591 doc
: /* Return t if DISPLAY supports shades of gray.
4592 Note that color displays do support shades of gray.
4593 The optional argument DISPLAY specifies which display to ask about.
4594 DISPLAY should be either a frame or a display name (a string).
4595 If omitted or nil, that stands for the selected frame's display. */)
4596 (Lisp_Object display
)
4598 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4600 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
4606 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
,
4607 Sx_display_pixel_width
, 0, 1, 0,
4608 doc
: /* Return the width in pixels of DISPLAY.
4609 The optional argument DISPLAY specifies which display to ask about.
4610 DISPLAY should be either a frame or a display name (a string).
4611 If omitted or nil, that stands for the selected frame's display. */)
4612 (Lisp_Object display
)
4614 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4616 return make_number (x_display_pixel_width (dpyinfo
));
4619 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
4620 Sx_display_pixel_height
, 0, 1, 0,
4621 doc
: /* Return the height in pixels of DISPLAY.
4622 The optional argument DISPLAY specifies which display to ask about.
4623 DISPLAY should be either a frame or a display name (a string).
4624 If omitted or nil, that stands for the selected frame's display. */)
4625 (Lisp_Object display
)
4627 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4629 return make_number (x_display_pixel_height (dpyinfo
));
4632 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
4634 doc
: /* Return the number of bitplanes of DISPLAY.
4635 The optional argument DISPLAY specifies which display to ask about.
4636 DISPLAY should be either a frame or a display name (a string).
4637 If omitted or nil, that stands for the selected frame's display. */)
4638 (Lisp_Object display
)
4640 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4642 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
4645 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
4647 doc
: /* Return the number of color cells of DISPLAY.
4648 The optional argument DISPLAY specifies which display to ask about.
4649 DISPLAY should be either a frame or a display name (a string).
4650 If omitted or nil, that stands for the selected frame's display. */)
4651 (Lisp_Object display
)
4653 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4656 /* Don't use NCOLORS: it returns incorrect results under remote
4657 * desktop. We force 24+ bit depths to 24-bit, both to prevent an
4658 * overflow and because probably is more meaningful on Windows
4661 cap
= 1 << min (dpyinfo
->n_planes
* dpyinfo
->n_cbits
, 24);
4662 return make_number (cap
);
4665 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
4666 Sx_server_max_request_size
,
4668 doc
: /* Return the maximum request size of the server of DISPLAY.
4669 The optional argument DISPLAY specifies which display to ask about.
4670 DISPLAY should be either a frame or a display name (a string).
4671 If omitted or nil, that stands for the selected frame's display. */)
4672 (Lisp_Object display
)
4674 return make_number (1);
4677 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
4678 doc
: /* Return the "vendor ID" string of the W32 system (Microsoft).
4679 The optional argument DISPLAY specifies which display to ask about.
4680 DISPLAY should be either a frame or a display name (a string).
4681 If omitted or nil, that stands for the selected frame's display. */)
4682 (Lisp_Object display
)
4684 return build_string ("Microsoft Corp.");
4687 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
4688 doc
: /* Return the version numbers of the server of DISPLAY.
4689 The value is a list of three integers: the major and minor
4690 version numbers of the X Protocol in use, and the distributor-specific
4691 release number. See also the function `x-server-vendor'.
4693 The optional argument DISPLAY specifies which display to ask about.
4694 DISPLAY should be either a frame or a display name (a string).
4695 If omitted or nil, that stands for the selected frame's display. */)
4696 (Lisp_Object display
)
4698 return Fcons (make_number (w32_major_version
),
4699 Fcons (make_number (w32_minor_version
),
4700 Fcons (make_number (w32_build_number
), Qnil
)));
4703 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
4704 doc
: /* Return the number of screens on the server of DISPLAY.
4705 The optional argument DISPLAY specifies which display to ask about.
4706 DISPLAY should be either a frame or a display name (a string).
4707 If omitted or nil, that stands for the selected frame's display. */)
4708 (Lisp_Object display
)
4710 return make_number (1);
4713 DEFUN ("x-display-mm-height", Fx_display_mm_height
,
4714 Sx_display_mm_height
, 0, 1, 0,
4715 doc
: /* Return the height in millimeters of DISPLAY.
4716 The optional argument DISPLAY specifies which display to ask about.
4717 DISPLAY should be either a frame or a display name (a string).
4718 If omitted or nil, that stands for the selected frame's display. */)
4719 (Lisp_Object display
)
4721 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4725 hdc
= GetDC (dpyinfo
->root_window
);
4727 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
4729 ReleaseDC (dpyinfo
->root_window
, hdc
);
4731 return make_number (cap
);
4734 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
4735 doc
: /* Return the width in millimeters of DISPLAY.
4736 The optional argument DISPLAY specifies which display to ask about.
4737 DISPLAY should be either a frame or a display name (a string).
4738 If omitted or nil, that stands for the selected frame's display. */)
4739 (Lisp_Object display
)
4741 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4746 hdc
= GetDC (dpyinfo
->root_window
);
4748 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
4750 ReleaseDC (dpyinfo
->root_window
, hdc
);
4752 return make_number (cap
);
4755 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
4756 Sx_display_backing_store
, 0, 1, 0,
4757 doc
: /* Return an indication of whether DISPLAY does backing store.
4758 The value may be `always', `when-mapped', or `not-useful'.
4759 The optional argument DISPLAY specifies which display to ask about.
4760 DISPLAY should be either a frame or a display name (a string).
4761 If omitted or nil, that stands for the selected frame's display. */)
4762 (Lisp_Object display
)
4764 return intern ("not-useful");
4767 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
4768 Sx_display_visual_class
, 0, 1, 0,
4769 doc
: /* Return the visual class of DISPLAY.
4770 The value is one of the symbols `static-gray', `gray-scale',
4771 `static-color', `pseudo-color', `true-color', or `direct-color'.
4773 The optional argument DISPLAY specifies which display to ask about.
4774 DISPLAY should be either a frame or a display name (a string).
4775 If omitted or nil, that stands for the selected frame's display. */)
4776 (Lisp_Object display
)
4778 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4779 Lisp_Object result
= Qnil
;
4781 if (dpyinfo
->has_palette
)
4782 result
= intern ("pseudo-color");
4783 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
4784 result
= intern ("static-grey");
4785 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
4786 result
= intern ("static-color");
4787 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
4788 result
= intern ("true-color");
4793 DEFUN ("x-display-save-under", Fx_display_save_under
,
4794 Sx_display_save_under
, 0, 1, 0,
4795 doc
: /* Return t if DISPLAY supports the save-under feature.
4796 The optional argument DISPLAY specifies which display to ask about.
4797 DISPLAY should be either a frame or a display name (a string).
4798 If omitted or nil, that stands for the selected frame's display. */)
4799 (Lisp_Object display
)
4804 DEFUN ("set-message-beep", Fset_message_beep
, Sset_message_beep
, 1, 1, 0,
4805 doc
: /* Set the sound generated when the bell is rung.
4806 SOUND is 'asterisk, 'exclamation, 'hand, 'question, 'ok, or 'silent
4807 to use the corresponding system sound for the bell. The 'silent sound
4808 prevents Emacs from making any sound at all.
4809 SOUND is nil to use the normal beep. */)
4812 CHECK_SYMBOL (sound
);
4815 sound_type
= 0xFFFFFFFF;
4816 else if (EQ (sound
, intern ("asterisk")))
4817 sound_type
= MB_ICONASTERISK
;
4818 else if (EQ (sound
, intern ("exclamation")))
4819 sound_type
= MB_ICONEXCLAMATION
;
4820 else if (EQ (sound
, intern ("hand")))
4821 sound_type
= MB_ICONHAND
;
4822 else if (EQ (sound
, intern ("question")))
4823 sound_type
= MB_ICONQUESTION
;
4824 else if (EQ (sound
, intern ("ok")))
4826 else if (EQ (sound
, intern ("silent")))
4827 sound_type
= MB_EMACS_SILENT
;
4829 sound_type
= 0xFFFFFFFF;
4836 x_pixel_width (register struct frame
*f
)
4838 return FRAME_PIXEL_WIDTH (f
);
4842 x_pixel_height (register struct frame
*f
)
4844 return FRAME_PIXEL_HEIGHT (f
);
4848 x_char_width (register struct frame
*f
)
4850 return FRAME_COLUMN_WIDTH (f
);
4854 x_char_height (register struct frame
*f
)
4856 return FRAME_LINE_HEIGHT (f
);
4860 x_screen_planes (register struct frame
*f
)
4862 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
4865 /* Return the display structure for the display named NAME.
4866 Open a new connection if necessary. */
4868 struct w32_display_info
*
4869 x_display_info_for_name (Lisp_Object name
)
4872 struct w32_display_info
*dpyinfo
;
4874 CHECK_STRING (name
);
4876 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
4877 dpyinfo
&& !NILP (w32_display_name_list
);
4878 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
4881 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
4886 /* Use this general default value to start with. */
4887 Vx_resource_name
= Vinvocation_name
;
4889 validate_x_resource_name ();
4891 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
4892 SSDATA (Vx_resource_name
));
4895 error ("Cannot connect to server %s", SDATA (name
));
4898 XSETFASTINT (Vwindow_system_version
, w32_major_version
);
4903 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
4904 1, 3, 0, doc
: /* Open a connection to a display server.
4905 DISPLAY is the name of the display to connect to.
4906 Optional second arg XRM-STRING is a string of resources in xrdb format.
4907 If the optional third arg MUST-SUCCEED is non-nil,
4908 terminate Emacs if we can't open the connection.
4909 \(In the Nextstep version, the last two arguments are currently ignored.) */)
4910 (Lisp_Object display
, Lisp_Object xrm_string
, Lisp_Object must_succeed
)
4912 unsigned char *xrm_option
;
4913 struct w32_display_info
*dpyinfo
;
4915 CHECK_STRING (display
);
4917 /* Signal an error in order to encourage correct use from callers.
4918 * If we ever support multiple window systems in the same Emacs,
4919 * we'll need callers to be precise about what window system they
4922 if (strcmp (SSDATA (display
), "w32") != 0)
4923 error ("The name of the display in this Emacs must be \"w32\"");
4925 /* If initialization has already been done, return now to avoid
4926 overwriting critical parts of one_w32_display_info. */
4930 if (! NILP (xrm_string
))
4931 CHECK_STRING (xrm_string
);
4934 if (! EQ (Vwindow_system
, intern ("w32")))
4935 error ("Not using Microsoft Windows");
4938 /* Allow color mapping to be defined externally; first look in user's
4939 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
4941 Lisp_Object color_file
;
4942 struct gcpro gcpro1
;
4944 color_file
= build_string ("~/rgb.txt");
4946 GCPRO1 (color_file
);
4948 if (NILP (Ffile_readable_p (color_file
)))
4950 Fexpand_file_name (build_string ("rgb.txt"),
4951 Fsymbol_value (intern ("data-directory")));
4953 Vw32_color_map
= Fx_load_color_file (color_file
);
4957 if (NILP (Vw32_color_map
))
4958 Vw32_color_map
= w32_default_color_map ();
4960 /* Merge in system logical colors. */
4961 add_system_logical_colors_to_map (&Vw32_color_map
);
4963 if (! NILP (xrm_string
))
4964 xrm_option
= SDATA (xrm_string
);
4966 xrm_option
= (unsigned char *) 0;
4968 /* Use this general default value to start with. */
4969 /* First remove .exe suffix from invocation-name - it looks ugly. */
4971 char basename
[ MAX_PATH
], *str
;
4973 strcpy (basename
, SDATA (Vinvocation_name
));
4974 str
= strrchr (basename
, '.');
4976 Vinvocation_name
= build_string (basename
);
4978 Vx_resource_name
= Vinvocation_name
;
4980 validate_x_resource_name ();
4982 /* This is what opens the connection and sets x_current_display.
4983 This also initializes many symbols, such as those used for input. */
4984 dpyinfo
= w32_term_init (display
, xrm_option
,
4985 SSDATA (Vx_resource_name
));
4989 if (!NILP (must_succeed
))
4990 fatal ("Cannot connect to server %s.\n",
4993 error ("Cannot connect to server %s", SDATA (display
));
4998 XSETFASTINT (Vwindow_system_version
, w32_major_version
);
5002 DEFUN ("x-close-connection", Fx_close_connection
,
5003 Sx_close_connection
, 1, 1, 0,
5004 doc
: /* Close the connection to DISPLAY's server.
5005 For DISPLAY, specify either a frame or a display name (a string).
5006 If DISPLAY is nil, that stands for the selected frame's display. */)
5007 (Lisp_Object display
)
5009 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
5011 if (dpyinfo
->reference_count
> 0)
5012 error ("Display still has frames on it");
5015 x_destroy_all_bitmaps (dpyinfo
);
5017 x_delete_display (dpyinfo
);
5023 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
5024 doc
: /* Return the list of display names that Emacs has connections to. */)
5027 Lisp_Object tail
, result
;
5030 for (tail
= w32_display_name_list
; CONSP (tail
); tail
= XCDR (tail
))
5031 result
= Fcons (XCAR (XCAR (tail
)), result
);
5036 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
5037 doc
: /* If ON is non-nil, report X errors as soon as the erring request is made.
5038 This function only has an effect on X Windows. With MS Windows, it is
5039 defined but does nothing.
5041 If ON is nil, allow buffering of requests.
5042 Turning on synchronization prohibits the Xlib routines from buffering
5043 requests and seriously degrades performance, but makes debugging much
5045 The optional second argument TERMINAL specifies which display to act on.
5046 TERMINAL should be a terminal object, a frame or a display name (a string).
5047 If TERMINAL is omitted or nil, that stands for the selected frame's display. */)
5048 (Lisp_Object on
, Lisp_Object display
)
5055 /***********************************************************************
5057 ***********************************************************************/
5059 #if 0 /* TODO : port window properties to W32 */
5061 DEFUN ("x-change-window-property", Fx_change_window_property
,
5062 Sx_change_window_property
, 2, 6, 0,
5063 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
5064 PROP must be a string. VALUE may be a string or a list of conses,
5065 numbers and/or strings. If an element in the list is a string, it is
5066 converted to an atom and the value of the Atom is used. If an element
5067 is a cons, it is converted to a 32 bit number where the car is the 16
5068 top bits and the cdr is the lower 16 bits.
5070 FRAME nil or omitted means use the selected frame.
5071 If TYPE is given and non-nil, it is the name of the type of VALUE.
5072 If TYPE is not given or nil, the type is STRING.
5073 FORMAT gives the size in bits of each element if VALUE is a list.
5074 It must be one of 8, 16 or 32.
5075 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
5076 If OUTER-P is non-nil, the property is changed for the outer X window of
5077 FRAME. Default is to change on the edit X window. */)
5078 (Lisp_Object prop
, Lisp_Object value
, Lisp_Object frame
,
5079 Lisp_Object type
, Lisp_Object format
, Lisp_Object outer_p
)
5081 struct frame
*f
= check_x_frame (frame
);
5084 CHECK_STRING (prop
);
5085 CHECK_STRING (value
);
5088 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5089 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5090 prop_atom
, XA_STRING
, 8, PropModeReplace
,
5091 SDATA (value
), SCHARS (value
));
5093 /* Make sure the property is set when we return. */
5094 XFlush (FRAME_W32_DISPLAY (f
));
5101 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
5102 Sx_delete_window_property
, 1, 2, 0,
5103 doc
: /* Remove window property PROP from X window of FRAME.
5104 FRAME nil or omitted means use the selected frame. Value is PROP. */)
5105 (Lisp_Object prop
, Lisp_Object frame
)
5107 struct frame
*f
= check_x_frame (frame
);
5110 CHECK_STRING (prop
);
5112 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5113 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
5115 /* Make sure the property is removed when we return. */
5116 XFlush (FRAME_W32_DISPLAY (f
));
5123 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
5125 doc
: /* Value is the value of window property PROP on FRAME.
5126 If FRAME is nil or omitted, use the selected frame.
5128 On X Windows, the following optional arguments are also accepted:
5129 If TYPE is nil or omitted, get the property as a string.
5130 Otherwise TYPE is the name of the atom that denotes the type expected.
5131 If SOURCE is non-nil, get the property on that window instead of from
5132 FRAME. The number 0 denotes the root window.
5133 If DELETE-P is non-nil, delete the property after retrieving it.
5134 If VECTOR-RET-P is non-nil, don't return a string but a vector of values.
5136 On MS Windows, this function accepts but ignores those optional arguments.
5138 Value is nil if FRAME hasn't a property with name PROP or if PROP has
5139 no value of TYPE (always string in the MS Windows case). */)
5140 (Lisp_Object prop
, Lisp_Object frame
, Lisp_Object type
,
5141 Lisp_Object source
, Lisp_Object delete_p
, Lisp_Object vector_ret_p
)
5143 struct frame
*f
= check_x_frame (frame
);
5146 Lisp_Object prop_value
= Qnil
;
5147 char *tmp_data
= NULL
;
5150 unsigned long actual_size
, bytes_remaining
;
5152 CHECK_STRING (prop
);
5154 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5155 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5156 prop_atom
, 0, 0, False
, XA_STRING
,
5157 &actual_type
, &actual_format
, &actual_size
,
5158 &bytes_remaining
, (unsigned char **) &tmp_data
);
5161 int size
= bytes_remaining
;
5166 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5167 prop_atom
, 0, bytes_remaining
,
5169 &actual_type
, &actual_format
,
5170 &actual_size
, &bytes_remaining
,
5171 (unsigned char **) &tmp_data
);
5173 prop_value
= make_string (tmp_data
, size
);
5188 /***********************************************************************
5190 ***********************************************************************/
5193 w32_note_current_window (void)
5195 struct frame
* f
= SELECTED_FRAME ();
5197 if (!FRAME_W32_P (f
))
5200 hourglass_hwnd
= FRAME_W32_WINDOW (f
);
5204 show_hourglass (struct atimer
*timer
)
5208 hourglass_atimer
= NULL
;
5211 f
= x_window_to_frame (&one_w32_display_info
,
5215 f
->output_data
.w32
->hourglass_p
= 0;
5217 f
= SELECTED_FRAME ();
5219 if (!FRAME_W32_P (f
))
5222 w32_show_hourglass (f
);
5227 hide_hourglass (void)
5230 w32_hide_hourglass ();
5235 /* Display an hourglass cursor. Set the hourglass_p flag in display info
5236 to indicate that an hourglass cursor is shown. */
5239 w32_show_hourglass (struct frame
*f
)
5241 if (!hourglass_shown_p
)
5243 f
->output_data
.w32
->hourglass_p
= 1;
5244 if (!menubar_in_use
&& !current_popup_menu
)
5245 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
5246 hourglass_shown_p
= 1;
5251 /* Hide the hourglass cursor on all frames, if it is currently shown. */
5254 w32_hide_hourglass (void)
5256 if (hourglass_shown_p
)
5258 struct frame
*f
= x_window_to_frame (&one_w32_display_info
,
5261 f
->output_data
.w32
->hourglass_p
= 0;
5263 /* If frame was deleted, restore to selected frame's cursor. */
5264 f
= SELECTED_FRAME ();
5266 if (FRAME_W32_P (f
))
5267 SetCursor (f
->output_data
.w32
->current_cursor
);
5269 /* No cursors on non GUI frames - restore to stock arrow cursor. */
5270 SetCursor (w32_load_cursor (IDC_ARROW
));
5272 hourglass_shown_p
= 0;
5278 /***********************************************************************
5280 ***********************************************************************/
5282 static Lisp_Object
x_create_tip_frame (struct w32_display_info
*,
5283 Lisp_Object
, Lisp_Object
);
5284 static void compute_tip_xy (struct frame
*, Lisp_Object
, Lisp_Object
,
5285 Lisp_Object
, int, int, int *, int *);
5287 /* The frame of a currently visible tooltip. */
5289 Lisp_Object tip_frame
;
5291 /* If non-nil, a timer started that hides the last tooltip when it
5294 Lisp_Object tip_timer
;
5297 /* If non-nil, a vector of 3 elements containing the last args
5298 with which x-show-tip was called. See there. */
5300 Lisp_Object last_show_tip_args
;
5304 unwind_create_tip_frame (Lisp_Object frame
)
5306 Lisp_Object deleted
;
5308 deleted
= unwind_create_frame (frame
);
5309 if (EQ (deleted
, Qt
))
5319 /* Create a frame for a tooltip on the display described by DPYINFO.
5320 PARMS is a list of frame parameters. TEXT is the string to
5321 display in the tip frame. Value is the frame.
5323 Note that functions called here, esp. x_default_parameter can
5324 signal errors, for instance when a specified color name is
5325 undefined. We have to make sure that we're in a consistent state
5326 when this happens. */
5329 x_create_tip_frame (struct w32_display_info
*dpyinfo
,
5330 Lisp_Object parms
, Lisp_Object text
)
5335 long window_prompting
= 0;
5337 ptrdiff_t count
= SPECPDL_INDEX ();
5338 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5340 int face_change_count_before
= face_change_count
;
5342 struct buffer
*old_buffer
;
5346 /* Use this general default value to start with until we know if
5347 this frame has a specified name. */
5348 Vx_resource_name
= Vinvocation_name
;
5350 kb
= dpyinfo
->terminal
->kboard
;
5352 /* The calls to x_get_arg remove elements from PARMS, so copy it to
5353 avoid destructive changes behind our caller's back. */
5354 parms
= Fcopy_alist (parms
);
5356 /* Get the name of the frame to use for resource lookup. */
5357 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
5359 && !EQ (name
, Qunbound
)
5361 error ("Invalid frame name--not a string or nil");
5362 Vx_resource_name
= name
;
5365 GCPRO3 (parms
, name
, frame
);
5366 /* Make a frame without minibuffer nor mode-line. */
5368 f
->wants_modeline
= 0;
5369 XSETFRAME (frame
, f
);
5371 buffer
= Fget_buffer_create (build_string (" *tip*"));
5372 /* Use set_window_buffer instead of Fset_window_buffer (see
5373 discussion of bug#11984, bug#12025, bug#12026). */
5374 set_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, 0, 0);
5375 old_buffer
= current_buffer
;
5376 set_buffer_internal_1 (XBUFFER (buffer
));
5377 bset_truncate_lines (current_buffer
, Qnil
);
5378 specbind (Qinhibit_read_only
, Qt
);
5379 specbind (Qinhibit_modification_hooks
, Qt
);
5382 set_buffer_internal_1 (old_buffer
);
5384 record_unwind_protect (unwind_create_tip_frame
, frame
);
5386 /* By setting the output method, we're essentially saying that
5387 the frame is live, as per FRAME_LIVE_P. If we get a signal
5388 from this point on, x_destroy_window might screw up reference
5390 f
->terminal
= dpyinfo
->terminal
;
5391 f
->output_method
= output_w32
;
5392 f
->output_data
.w32
= xzalloc (sizeof (struct w32_output
));
5394 FRAME_FONTSET (f
) = -1;
5395 fset_icon_name (f
, Qnil
);
5398 image_cache_refcount
=
5399 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
5400 dpyinfo_refcount
= dpyinfo
->reference_count
;
5401 #endif /* GLYPH_DEBUG */
5402 FRAME_KBOARD (f
) = kb
;
5403 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5404 f
->output_data
.w32
->explicit_parent
= 0;
5406 /* Set the name; the functions to which we pass f expect the name to
5408 if (EQ (name
, Qunbound
) || NILP (name
))
5410 fset_name (f
, build_string (dpyinfo
->w32_id_name
));
5411 f
->explicit_name
= 0;
5415 fset_name (f
, name
);
5416 f
->explicit_name
= 1;
5417 /* use the frame's title when getting resources for this frame. */
5418 specbind (Qx_resource_name
, name
);
5421 f
->resx
= dpyinfo
->resx
;
5422 f
->resy
= dpyinfo
->resy
;
5424 if (uniscribe_available
)
5425 register_font_driver (&uniscribe_font_driver
, f
);
5426 register_font_driver (&w32font_driver
, f
);
5428 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
5429 "fontBackend", "FontBackend", RES_TYPE_STRING
);
5431 /* Extract the window parameters from the supplied values
5432 that are needed to determine window geometry. */
5433 x_default_font_parameter (f
, parms
);
5435 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
5436 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5437 /* This defaults to 2 in order to match xterm. We recognize either
5438 internalBorderWidth or internalBorder (which is what xterm calls
5440 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5444 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
5445 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
5446 if (! EQ (value
, Qunbound
))
5447 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
5450 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
5451 "internalBorderWidth", "internalBorderWidth",
5454 /* Also do the stuff which must be set before the window exists. */
5455 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
5456 "foreground", "Foreground", RES_TYPE_STRING
);
5457 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
5458 "background", "Background", RES_TYPE_STRING
);
5459 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
5460 "pointerColor", "Foreground", RES_TYPE_STRING
);
5461 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
5462 "cursorColor", "Foreground", RES_TYPE_STRING
);
5463 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
5464 "borderColor", "BorderColor", RES_TYPE_STRING
);
5466 /* Init faces before x_default_parameter is called for scroll-bar
5467 parameters because that function calls x_set_scroll_bar_width,
5468 which calls change_frame_size, which calls Fset_window_buffer,
5469 which runs hooks, which call Fvertical_motion. At the end, we
5470 end up in init_iterator with a null face cache, which should not
5472 init_frame_faces (f
);
5474 f
->output_data
.w32
->dwStyle
= WS_BORDER
| WS_POPUP
| WS_DISABLED
;
5475 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5477 window_prompting
= x_figure_window_size (f
, parms
, 0);
5479 /* No fringes on tip frame. */
5481 f
->left_fringe_width
= 0;
5482 f
->right_fringe_width
= 0;
5485 my_create_tip_window (f
);
5490 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
5491 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5492 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5493 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5494 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5495 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5497 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
5498 Change will not be effected unless different from the current
5500 width
= FRAME_COLS (f
);
5501 height
= FRAME_LINES (f
);
5502 FRAME_LINES (f
) = 0;
5503 SET_FRAME_COLS (f
, 0);
5504 change_frame_size (f
, height
, width
, 1, 0, 0);
5506 /* Add `tooltip' frame parameter's default value. */
5507 if (NILP (Fframe_parameter (frame
, Qtooltip
)))
5508 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qtooltip
, Qt
), Qnil
));
5510 /* Set up faces after all frame parameters are known. This call
5511 also merges in face attributes specified for new frames.
5513 Frame parameters may be changed if .Xdefaults contains
5514 specifications for the default font. For example, if there is an
5515 `Emacs.default.attributeBackground: pink', the `background-color'
5516 attribute of the frame get's set, which let's the internal border
5517 of the tooltip frame appear in pink. Prevent this. */
5519 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
5520 Lisp_Object fg
= Fframe_parameter (frame
, Qforeground_color
);
5521 Lisp_Object colors
= Qnil
;
5523 /* Set tip_frame here, so that */
5525 call2 (Qface_set_after_frame_default
, frame
, Qnil
);
5527 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
5528 colors
= Fcons (Fcons (Qbackground_color
, bg
), colors
);
5529 if (!EQ (fg
, Fframe_parameter (frame
, Qforeground_color
)))
5530 colors
= Fcons (Fcons (Qforeground_color
, fg
), colors
);
5533 Fmodify_frame_parameters (frame
, colors
);
5540 /* Now that the frame is official, it counts as a reference to
5542 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
5543 f
->terminal
->reference_count
++;
5545 /* It is now ok to make the frame official even if we get an error
5546 below. And the frame needs to be on Vframe_list or making it
5547 visible won't work. */
5548 Vframe_list
= Fcons (frame
, Vframe_list
);
5550 /* Setting attributes of faces of the tooltip frame from resources
5551 and similar will increment face_change_count, which leads to the
5552 clearing of all current matrices. Since this isn't necessary
5553 here, avoid it by resetting face_change_count to the value it
5554 had before we created the tip frame. */
5555 face_change_count
= face_change_count_before
;
5557 /* Discard the unwind_protect. */
5558 return unbind_to (count
, frame
);
5562 /* Compute where to display tip frame F. PARMS is the list of frame
5563 parameters for F. DX and DY are specified offsets from the current
5564 location of the mouse. WIDTH and HEIGHT are the width and height
5565 of the tooltip. Return coordinates relative to the root window of
5566 the display in *ROOT_X, and *ROOT_Y. */
5569 compute_tip_xy (struct frame
*f
,
5570 Lisp_Object parms
, Lisp_Object dx
, Lisp_Object dy
,
5571 int width
, int height
, int *root_x
, int *root_y
)
5573 Lisp_Object left
, top
;
5574 int min_x
, min_y
, max_x
, max_y
;
5576 /* User-specified position? */
5577 left
= Fcdr (Fassq (Qleft
, parms
));
5578 top
= Fcdr (Fassq (Qtop
, parms
));
5580 /* Move the tooltip window where the mouse pointer is. Resize and
5582 if (!INTEGERP (left
) || !INTEGERP (top
))
5586 /* Default min and max values. */
5589 max_x
= x_display_pixel_width (FRAME_W32_DISPLAY_INFO (f
));
5590 max_y
= x_display_pixel_height (FRAME_W32_DISPLAY_INFO (f
));
5598 /* If multiple monitor support is available, constrain the tip onto
5599 the current monitor. This improves the above by allowing negative
5600 co-ordinates if monitor positions are such that they are valid, and
5601 snaps a tooltip onto a single monitor if we are close to the edge
5602 where it would otherwise flow onto the other monitor (or into
5603 nothingness if there is a gap in the overlap). */
5604 if (monitor_from_point_fn
&& get_monitor_info_fn
)
5606 struct MONITOR_INFO info
;
5608 = monitor_from_point_fn (pt
, MONITOR_DEFAULT_TO_NEAREST
);
5609 info
.cbSize
= sizeof (info
);
5611 if (get_monitor_info_fn (monitor
, &info
))
5613 min_x
= info
.rcWork
.left
;
5614 min_y
= info
.rcWork
.top
;
5615 max_x
= info
.rcWork
.right
;
5616 max_y
= info
.rcWork
.bottom
;
5622 *root_y
= XINT (top
);
5623 else if (*root_y
+ XINT (dy
) <= min_y
)
5624 *root_y
= min_y
; /* Can happen for negative dy */
5625 else if (*root_y
+ XINT (dy
) + height
<= max_y
)
5626 /* It fits below the pointer */
5627 *root_y
+= XINT (dy
);
5628 else if (height
+ XINT (dy
) + min_y
<= *root_y
)
5629 /* It fits above the pointer. */
5630 *root_y
-= height
+ XINT (dy
);
5632 /* Put it on the top. */
5635 if (INTEGERP (left
))
5636 *root_x
= XINT (left
);
5637 else if (*root_x
+ XINT (dx
) <= min_x
)
5638 *root_x
= 0; /* Can happen for negative dx */
5639 else if (*root_x
+ XINT (dx
) + width
<= max_x
)
5640 /* It fits to the right of the pointer. */
5641 *root_x
+= XINT (dx
);
5642 else if (width
+ XINT (dx
) + min_x
<= *root_x
)
5643 /* It fits to the left of the pointer. */
5644 *root_x
-= width
+ XINT (dx
);
5646 /* Put it left justified on the screen -- it ought to fit that way. */
5651 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
5652 doc
: /* Show STRING in a \"tooltip\" window on frame FRAME.
5653 A tooltip window is a small window displaying a string.
5655 This is an internal function; Lisp code should call `tooltip-show'.
5657 FRAME nil or omitted means use the selected frame.
5659 PARMS is an optional list of frame parameters which can be
5660 used to change the tooltip's appearance.
5662 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
5663 means use the default timeout of 5 seconds.
5665 If the list of frame parameters PARMS contains a `left' parameter,
5666 the tooltip is displayed at that x-position. Otherwise it is
5667 displayed at the mouse position, with offset DX added (default is 5 if
5668 DX isn't specified). Likewise for the y-position; if a `top' frame
5669 parameter is specified, it determines the y-position of the tooltip
5670 window, otherwise it is displayed at the mouse position, with offset
5671 DY added (default is -10).
5673 A tooltip's maximum size is specified by `x-max-tooltip-size'.
5674 Text larger than the specified size is clipped. */)
5675 (Lisp_Object string
, Lisp_Object frame
, Lisp_Object parms
, Lisp_Object timeout
, Lisp_Object dx
, Lisp_Object dy
)
5680 struct buffer
*old_buffer
;
5681 struct text_pos pos
;
5682 int i
, width
, height
, seen_reversed_p
;
5683 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5684 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5685 ptrdiff_t count
= SPECPDL_INDEX ();
5687 specbind (Qinhibit_redisplay
, Qt
);
5689 GCPRO4 (string
, parms
, frame
, timeout
);
5691 CHECK_STRING (string
);
5692 f
= check_x_frame (frame
);
5694 timeout
= make_number (5);
5696 CHECK_NATNUM (timeout
);
5699 dx
= make_number (5);
5704 dy
= make_number (-10);
5708 if (NILP (last_show_tip_args
))
5709 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
5711 if (!NILP (tip_frame
))
5713 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
5714 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
5715 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
5717 if (EQ (frame
, last_frame
)
5718 && !NILP (Fequal (last_string
, string
))
5719 && !NILP (Fequal (last_parms
, parms
)))
5721 struct frame
*f
= XFRAME (tip_frame
);
5723 /* Only DX and DY have changed. */
5724 if (!NILP (tip_timer
))
5726 Lisp_Object timer
= tip_timer
;
5728 call1 (Qcancel_timer
, timer
);
5732 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
5733 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
5735 /* Put tooltip in topmost group and in position. */
5736 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
5737 root_x
, root_y
, 0, 0,
5738 SWP_NOSIZE
| SWP_NOACTIVATE
);
5740 /* Ensure tooltip is on top of other topmost windows (eg menus). */
5741 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
5743 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
5750 /* Hide a previous tip, if any. */
5753 ASET (last_show_tip_args
, 0, string
);
5754 ASET (last_show_tip_args
, 1, frame
);
5755 ASET (last_show_tip_args
, 2, parms
);
5757 /* Add default values to frame parameters. */
5758 if (NILP (Fassq (Qname
, parms
)))
5759 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
5760 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5761 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
5762 if (NILP (Fassq (Qborder_width
, parms
)))
5763 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
5764 if (NILP (Fassq (Qborder_color
, parms
)))
5765 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
5766 if (NILP (Fassq (Qbackground_color
, parms
)))
5767 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
5770 /* Block input until the tip has been fully drawn, to avoid crashes
5771 when drawing tips in menus. */
5774 /* Create a frame for the tooltip, and record it in the global
5775 variable tip_frame. */
5776 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
, string
);
5779 /* Set up the frame's root window. */
5780 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5781 wset_left_col (w
, make_number (0));
5782 wset_top_line (w
, make_number (0));
5784 if (CONSP (Vx_max_tooltip_size
)
5785 && INTEGERP (XCAR (Vx_max_tooltip_size
))
5786 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
5787 && INTEGERP (XCDR (Vx_max_tooltip_size
))
5788 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
5790 wset_total_cols (w
, XCAR (Vx_max_tooltip_size
));
5791 wset_total_lines (w
, XCDR (Vx_max_tooltip_size
));
5795 wset_total_cols (w
, make_number (80));
5796 wset_total_lines (w
, make_number (40));
5799 FRAME_TOTAL_COLS (f
) = XINT (w
->total_cols
);
5801 w
->pseudo_window_p
= 1;
5803 /* Display the tooltip text in a temporary buffer. */
5804 old_buffer
= current_buffer
;
5805 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
5806 bset_truncate_lines (current_buffer
, Qnil
);
5807 clear_glyph_matrix (w
->desired_matrix
);
5808 clear_glyph_matrix (w
->current_matrix
);
5809 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
5810 try_window (FRAME_ROOT_WINDOW (f
), pos
, TRY_WINDOW_IGNORE_FONTS_CHANGE
);
5812 /* Compute width and height of the tooltip. */
5813 width
= height
= seen_reversed_p
= 0;
5814 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5816 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5820 /* Stop at the first empty row at the end. */
5821 if (!row
->enabled_p
|| !row
->displays_text_p
)
5824 /* Let the row go over the full width of the frame. */
5825 row
->full_width_p
= 1;
5827 row_width
= row
->pixel_width
;
5828 if (row
->used
[TEXT_AREA
])
5830 if (!row
->reversed_p
)
5832 /* There's a glyph at the end of rows that is used to
5833 place the cursor there. Don't include the width of
5835 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5836 if (INTEGERP (last
->object
))
5837 row_width
-= last
->pixel_width
;
5841 /* There could be a stretch glyph at the beginning of R2L
5842 rows that is produced by extend_face_to_end_of_line.
5843 Don't count that glyph. */
5844 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
5846 if (g
->type
== STRETCH_GLYPH
&& INTEGERP (g
->object
))
5848 row_width
-= g
->pixel_width
;
5849 seen_reversed_p
= 1;
5854 height
+= row
->height
;
5855 width
= max (width
, row_width
);
5858 /* If we've seen partial-length R2L rows, we need to re-adjust the
5859 tool-tip frame width and redisplay it again, to avoid over-wide
5860 tips due to the stretch glyph that extends R2L lines to full
5861 width of the frame. */
5862 if (seen_reversed_p
)
5864 /* w->total_cols and FRAME_TOTAL_COLS want the width in columns,
5866 width
/= WINDOW_FRAME_COLUMN_WIDTH (w
);
5867 wset_total_cols (w
, make_number (width
));
5868 FRAME_TOTAL_COLS (f
) = width
;
5870 w
->pseudo_window_p
= 1;
5871 clear_glyph_matrix (w
->desired_matrix
);
5872 clear_glyph_matrix (w
->current_matrix
);
5873 try_window (FRAME_ROOT_WINDOW (f
), pos
, TRY_WINDOW_IGNORE_FONTS_CHANGE
);
5875 /* Recompute width and height of the tooltip. */
5876 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5878 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5882 if (!row
->enabled_p
|| !row
->displays_text_p
)
5884 row
->full_width_p
= 1;
5885 row_width
= row
->pixel_width
;
5886 if (row
->used
[TEXT_AREA
] && !row
->reversed_p
)
5888 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5889 if (INTEGERP (last
->object
))
5890 row_width
-= last
->pixel_width
;
5893 height
+= row
->height
;
5894 width
= max (width
, row_width
);
5898 /* Round up the height to an integral multiple of FRAME_LINE_HEIGHT. */
5899 if (height
% FRAME_LINE_HEIGHT (f
) != 0)
5900 height
+= FRAME_LINE_HEIGHT (f
) - height
% FRAME_LINE_HEIGHT (f
);
5901 /* Add the frame's internal border to the width and height the w32
5902 window should have. */
5903 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5904 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5906 /* Move the tooltip window where the mouse pointer is. Resize and
5908 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
5911 /* Adjust Window size to take border into account. */
5913 rect
.left
= rect
.top
= 0;
5915 rect
.bottom
= height
;
5916 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
5917 FRAME_EXTERNAL_MENU_BAR (f
));
5919 /* Position and size tooltip, and put it in the topmost group.
5920 The add-on of FRAME_COLUMN_WIDTH to the 5th argument is a
5921 peculiarity of w32 display: without it, some fonts cause the
5922 last character of the tip to be truncated or wrapped around to
5924 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
5926 rect
.right
- rect
.left
+ FRAME_COLUMN_WIDTH (f
),
5927 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
);
5929 /* Ensure tooltip is on top of other topmost windows (eg menus). */
5930 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
5932 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
5934 /* Let redisplay know that we have made the frame visible already. */
5935 f
->async_visible
= 1;
5937 ShowWindow (FRAME_W32_WINDOW (f
), SW_SHOWNOACTIVATE
);
5940 /* Draw into the window. */
5941 w
->must_be_updated_p
= 1;
5942 update_single_window (w
, 1);
5946 /* Restore original current buffer. */
5947 set_buffer_internal_1 (old_buffer
);
5948 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5951 /* Let the tip disappear after timeout seconds. */
5952 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
5953 intern ("x-hide-tip"));
5956 return unbind_to (count
, Qnil
);
5960 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
5961 doc
: /* Hide the current tooltip window, if there is any.
5962 Value is t if tooltip was open, nil otherwise. */)
5966 Lisp_Object deleted
, frame
, timer
;
5967 struct gcpro gcpro1
, gcpro2
;
5969 /* Return quickly if nothing to do. */
5970 if (NILP (tip_timer
) && NILP (tip_frame
))
5975 GCPRO2 (frame
, timer
);
5976 tip_frame
= tip_timer
= deleted
= Qnil
;
5978 count
= SPECPDL_INDEX ();
5979 specbind (Qinhibit_redisplay
, Qt
);
5980 specbind (Qinhibit_quit
, Qt
);
5983 call1 (Qcancel_timer
, timer
);
5987 delete_frame (frame
, Qnil
);
5992 return unbind_to (count
, deleted
);
5995 /***********************************************************************
5996 File selection dialog
5997 ***********************************************************************/
5999 #define FILE_NAME_TEXT_FIELD edt1
6000 #define FILE_NAME_COMBO_BOX cmb13
6001 #define FILE_NAME_LIST lst1
6003 #ifdef NTGUI_UNICODE
6004 #define GUISTR(x) (L ## x)
6005 typedef wchar_t guichar_t
;
6006 #else /* !NTGUI_UNICODE */
6008 typedef char guichar_t
;
6009 #endif /* NTGUI_UNICODE */
6011 /* Callback for altering the behavior of the Open File dialog.
6012 Makes the Filename text field contain "Current Directory" and be
6013 read-only when "Directories" is selected in the filter. This
6014 allows us to work around the fact that the standard Open File
6015 dialog does not support directories. */
6016 static UINT CALLBACK
6017 file_dialog_callback (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
6019 if (msg
== WM_NOTIFY
)
6021 #ifdef NTGUI_UNICODE
6022 OFNOTIFYW
* notify
= (OFNOTIFYW
*)lParam
;
6023 #else /* !NTGUI_UNICODE */
6024 OFNOTIFYA
* notify
= (OFNOTIFYA
*)lParam
;
6025 #endif /* NTGUI_UNICODE */
6026 /* Detect when the Filter dropdown is changed. */
6027 if (notify
->hdr
.code
== CDN_TYPECHANGE
6028 || notify
->hdr
.code
== CDN_INITDONE
)
6030 HWND dialog
= GetParent (hwnd
);
6031 HWND edit_control
= GetDlgItem (dialog
, FILE_NAME_TEXT_FIELD
);
6032 HWND list
= GetDlgItem (dialog
, FILE_NAME_LIST
);
6034 /* At least on Windows 7, the above attempt to get the window handle
6035 to the File Name Text Field fails. The following code does the
6036 job though. Note that this code is based on my examination of the
6037 window hierarchy using Microsoft Spy++. bk */
6038 if (edit_control
== NULL
)
6040 HWND tmp
= GetDlgItem (dialog
, FILE_NAME_COMBO_BOX
);
6043 tmp
= GetWindow (tmp
, GW_CHILD
);
6045 edit_control
= GetWindow (tmp
, GW_CHILD
);
6049 /* Directories is in index 2. */
6050 if (notify
->lpOFN
->nFilterIndex
== 2)
6052 CommDlg_OpenSave_SetControlText (dialog
, FILE_NAME_TEXT_FIELD
,
6053 GUISTR ("Current Directory"));
6054 EnableWindow (edit_control
, FALSE
);
6055 /* Note that at least on Windows 7, the above call to EnableWindow
6056 disables the window that would ordinarily have focus. If we
6057 do not set focus to some other window here, focus will land in
6058 no man's land and the user will be unable to tab through the
6059 dialog box (pressing tab will only result in a beep).
6060 Avoid that problem by setting focus to the list here. */
6061 if (notify
->hdr
.code
== CDN_INITDONE
)
6066 /* Don't override default filename on init done. */
6067 if (notify
->hdr
.code
== CDN_TYPECHANGE
)
6068 CommDlg_OpenSave_SetControlText (dialog
,
6069 FILE_NAME_TEXT_FIELD
,
6071 EnableWindow (edit_control
, TRUE
);
6078 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
6079 doc
: /* Read file name, prompting with PROMPT in directory DIR.
6080 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
6081 selection box, if specified. If MUSTMATCH is non-nil, the returned file
6082 or directory must exist.
6084 This function is only defined on NS, MS Windows, and X Windows with the
6085 Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
6086 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
6087 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
, Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
6089 /* Filter index: 1: All Files, 2: Directories only */
6090 static const guichar_t filter
[] =
6091 GUISTR ("All Files (*.*)\0*.*\0Directories\0*|*\0");
6093 Lisp_Object filename
= default_filename
;
6094 struct frame
*f
= SELECTED_FRAME ();
6095 BOOL file_opened
= FALSE
;
6096 Lisp_Object orig_dir
= dir
;
6097 Lisp_Object orig_prompt
= prompt
;
6099 /* If we compile with _WIN32_WINNT set to 0x0400 (for NT4
6100 compatibility) we end up with the old file dialogs. Define a big
6101 enough struct for the new dialog to trick GetOpenFileName into
6102 giving us the new dialogs on newer versions of Windows. */
6104 #ifdef NTGUI_UNICODE
6105 OPENFILENAMEW details
;
6106 #else /* !NTGUI_UNICODE */
6107 OPENFILENAMEA details
;
6108 #endif /* NTGUI_UNICODE */
6110 #if _WIN32_WINNT < 0x500 /* < win2k */
6114 #endif /* < win2k */
6117 #ifdef NTGUI_UNICODE
6118 wchar_t filename_buf
[32*1024 + 1]; // NT kernel maximum
6119 OPENFILENAMEW
* file_details
= &new_file_details
.details
;
6120 #else /* not NTGUI_UNICODE */
6121 char filename_buf
[MAX_PATH
+ 1];
6122 OPENFILENAMEA
* file_details
= &new_file_details
.details
;
6123 #endif /* NTGUI_UNICODE */
6125 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
6126 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, filename
);
6129 struct gcpro gcpro1
, gcpro2
;
6130 GCPRO2 (orig_dir
, orig_prompt
); /* There is no GCPRON, N>6. */
6132 /* Note: under NTGUI_UNICODE, we do _NOT_ use ENCODE_FILE: the
6133 system file encoding expected by the platform APIs (e.g. Cygwin's
6134 POSIX implementation) may not be the same as the encoding expected
6135 by the Windows "ANSI" APIs! */
6137 CHECK_STRING (prompt
);
6140 dir
= Fexpand_file_name (dir
, Qnil
);
6142 if (STRINGP (filename
))
6143 filename
= Ffile_name_nondirectory (filename
);
6145 filename
= empty_unibyte_string
;
6148 dir
= Fcygwin_convert_path_to_windows (dir
, Qt
);
6149 if (SCHARS (filename
) > 0)
6150 filename
= Fcygwin_convert_path_to_windows (filename
, Qnil
);
6154 CHECK_STRING (filename
);
6156 /* The code in file_dialog_callback that attempts to set the text
6157 of the file name edit window when handling the CDN_INITDONE
6158 WM_NOTIFY message does not work. Setting filename to "Current
6159 Directory" in the only_dir_p case here does work however. */
6160 if (SCHARS (filename
) == 0 && ! NILP (only_dir_p
))
6161 filename
= build_string ("Current Directory");
6163 /* Convert the values we've computed so far to system form. */
6164 #ifdef NTGUI_UNICODE
6165 to_unicode (prompt
, &prompt
);
6166 to_unicode (dir
, &dir
);
6167 to_unicode (filename
, &filename
);
6168 #else /* !NTGUI_UNICODE */
6169 prompt
= ENCODE_FILE (prompt
);
6170 dir
= ENCODE_FILE (dir
);
6171 filename
= ENCODE_FILE (filename
);
6173 /* We modify these in-place, so make copies for safety. */
6174 dir
= Fcopy_sequence (dir
);
6175 unixtodos_filename (SDATA (dir
));
6176 filename
= Fcopy_sequence (filename
);
6177 unixtodos_filename (SDATA (filename
));
6178 #endif /* NTGUI_UNICODE */
6180 /* Fill in the structure for the call to GetOpenFileName below.
6181 For NTGUI_UNICODE builds (which run only on NT), we just use
6182 the actual size of the structure. For non-NTGUI_UNICODE
6183 builds, we tell the OS we're using an old version of the
6184 structure if the OS isn't new enough to support the newer
6186 memset (&new_file_details
, 0, sizeof (new_file_details
));
6188 if (w32_major_version
> 4 && w32_major_version
< 95)
6189 file_details
->lStructSize
= sizeof (new_file_details
);
6191 file_details
->lStructSize
= sizeof (*file_details
);
6193 /* Set up the inout parameter for the selected file name. */
6194 if (SBYTES (filename
) + 1 > sizeof (filename_buf
))
6195 report_file_error ("filename too long", default_filename
);
6197 memcpy (filename_buf
, SDATA (filename
), SBYTES (filename
) + 1);
6198 file_details
->lpstrFile
= filename_buf
;
6199 file_details
->nMaxFile
= sizeof (filename_buf
) / sizeof (*filename_buf
);
6201 file_details
->hwndOwner
= FRAME_W32_WINDOW (f
);
6202 /* Undocumented Bug in Common File Dialog:
6203 If a filter is not specified, shell links are not resolved. */
6204 file_details
->lpstrFilter
= filter
;
6205 file_details
->lpstrInitialDir
= (guichar_t
*) SDATA (dir
);
6206 file_details
->lpstrTitle
= (guichar_t
*) SDATA (prompt
);
6207 file_details
->nFilterIndex
= NILP (only_dir_p
) ? 1 : 2;
6208 file_details
->Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
6209 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
6211 if (!NILP (mustmatch
))
6213 /* Require that the path to the parent directory exists. */
6214 file_details
->Flags
|= OFN_PATHMUSTEXIST
;
6215 /* If we are looking for a file, require that it exists. */
6216 if (NILP (only_dir_p
))
6217 file_details
->Flags
|= OFN_FILEMUSTEXIST
;
6221 int count
= SPECPDL_INDEX ();
6222 /* Prevent redisplay. */
6223 specbind (Qinhibit_redisplay
, Qt
);
6225 file_details
->lpfnHook
= file_dialog_callback
;
6227 #ifdef NTGUI_UNICODE
6228 file_opened
= GetOpenFileNameW (file_details
);
6229 #else /* !NTGUI_UNICODE */
6230 file_opened
= GetOpenFileNameA (file_details
);
6231 #endif /* NTGUI_UNICODE */
6233 unbind_to (count
, Qnil
);
6238 /* Get an Emacs string from the value Windows gave us. */
6239 #ifdef NTGUI_UNICODE
6240 filename
= from_unicode (
6241 make_unibyte_string (
6242 (char*) filename_buf
,
6243 /* we get one of the two final 0 bytes for free. */
6244 1 + sizeof (wchar_t) * wcslen (filename_buf
)));
6245 #else /* !NTGUI_UNICODE */
6246 dostounix_filename (filename_buf
);
6247 filename
= DECODE_FILE (build_string (filename_buf
));
6248 #endif /* NTGUI_UNICODE */
6251 filename
= Fcygwin_convert_path_from_windows (filename
, Qt
);
6254 /* Strip the dummy filename off the end of the string if we
6255 added it to select a directory. */
6256 if (file_details
->nFilterIndex
== 2)
6258 filename
= Ffile_name_directory (filename
);
6261 /* User canceled the dialog without making a selection. */
6262 else if (!CommDlgExtendedError ())
6264 /* An error occurred, fallback on reading from the mini-buffer. */
6266 filename
= Fcompleting_read (
6268 intern ("read-file-name-internal"),
6279 /* Make "Cancel" equivalent to C-g. */
6280 if (NILP (filename
))
6281 Fsignal (Qquit
, Qnil
);
6283 RETURN_UNGCPRO (filename
);
6288 /* Moving files to the system recycle bin.
6289 Used by `move-file-to-trash' instead of the default moving to ~/.Trash */
6290 DEFUN ("system-move-file-to-trash", Fsystem_move_file_to_trash
,
6291 Ssystem_move_file_to_trash
, 1, 1, 0,
6292 doc
: /* Move file or directory named FILENAME to the recycle bin. */)
6293 (Lisp_Object filename
)
6295 Lisp_Object handler
;
6296 Lisp_Object encoded_file
;
6297 Lisp_Object operation
;
6299 operation
= Qdelete_file
;
6300 if (!NILP (Ffile_directory_p (filename
))
6301 && NILP (Ffile_symlink_p (filename
)))
6303 operation
= intern ("delete-directory");
6304 filename
= Fdirectory_file_name (filename
);
6306 filename
= Fexpand_file_name (filename
, Qnil
);
6308 handler
= Ffind_file_name_handler (filename
, operation
);
6309 if (!NILP (handler
))
6310 return call2 (handler
, operation
, filename
);
6312 encoded_file
= ENCODE_FILE (filename
);
6316 SHFILEOPSTRUCT file_op
;
6317 char tmp_path
[MAX_PATH
+ 1];
6319 path
= map_w32_filename (SDATA (encoded_file
), NULL
);
6321 /* On Windows, write permission is required to delete/move files. */
6322 _chmod (path
, 0666);
6324 memset (tmp_path
, 0, sizeof (tmp_path
));
6325 strcpy (tmp_path
, path
);
6327 memset (&file_op
, 0, sizeof (file_op
));
6328 file_op
.hwnd
= HWND_DESKTOP
;
6329 file_op
.wFunc
= FO_DELETE
;
6330 file_op
.pFrom
= tmp_path
;
6331 file_op
.fFlags
= FOF_SILENT
| FOF_NOCONFIRMATION
| FOF_ALLOWUNDO
6332 | FOF_NOERRORUI
| FOF_NO_CONNECTED_ELEMENTS
;
6333 file_op
.fAnyOperationsAborted
= FALSE
;
6335 if (SHFileOperation (&file_op
) != 0)
6336 report_file_error ("Removing old name", list1 (filename
));
6341 #endif /* WINDOWSNT */
6344 /***********************************************************************
6345 w32 specialized functions
6346 ***********************************************************************/
6348 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
,
6349 Sw32_send_sys_command
, 1, 2, 0,
6350 doc
: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND.
6351 Some useful values for COMMAND are #xf030 to maximize frame (#xf020
6352 to minimize), #xf120 to restore frame to original size, and #xf100
6353 to activate the menubar for keyboard access. #xf140 activates the
6354 screen saver if defined.
6356 If optional parameter FRAME is not specified, use selected frame. */)
6357 (Lisp_Object command
, Lisp_Object frame
)
6359 FRAME_PTR f
= check_x_frame (frame
);
6361 CHECK_NUMBER (command
);
6363 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
6368 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
6369 doc
: /* Get Windows to perform OPERATION on DOCUMENT.
6370 This is a wrapper around the ShellExecute system function, which
6371 invokes the application registered to handle OPERATION for DOCUMENT.
6373 OPERATION is either nil or a string that names a supported operation.
6374 What operations can be used depends on the particular DOCUMENT and its
6375 handler application, but typically it is one of the following common
6378 \"open\" - open DOCUMENT, which could be a file, a directory, or an
6379 executable program. If it is an application, that
6380 application is launched in the current buffer's default
6381 directory. Otherwise, the application associated with
6382 DOCUMENT is launched in the buffer's default directory.
6383 \"print\" - print DOCUMENT, which must be a file
6384 \"explore\" - start the Windows Explorer on DOCUMENT
6385 \"edit\" - launch an editor and open DOCUMENT for editing; which
6386 editor is launched depends on the association for the
6388 \"find\" - initiate search starting from DOCUMENT which must specify
6390 nil - invoke the default OPERATION, or \"open\" if default is
6391 not defined or unavailable
6393 DOCUMENT is typically the name of a document file or a URL, but can
6394 also be a program executable to run, or a directory to open in the
6397 If DOCUMENT is a program executable, the optional third arg PARAMETERS
6398 can be a string containing command line parameters that will be passed
6399 to the program; otherwise, PARAMETERS should be nil or unspecified.
6401 Optional fourth argument SHOW-FLAG can be used to control how the
6402 application will be displayed when it is invoked. If SHOW-FLAG is nil
6403 or unspecified, the application is displayed normally, otherwise it is
6404 an integer representing a ShowWindow flag:
6409 6 - start minimized */)
6410 (Lisp_Object operation
, Lisp_Object document
, Lisp_Object parameters
, Lisp_Object show_flag
)
6412 Lisp_Object current_dir
;
6415 CHECK_STRING (document
);
6417 /* Encode filename, current directory and parameters. */
6418 current_dir
= ENCODE_FILE (BVAR (current_buffer
, directory
));
6419 document
= ENCODE_FILE (document
);
6420 if (STRINGP (parameters
))
6421 parameters
= ENCODE_SYSTEM (parameters
);
6423 if ((int) ShellExecute (NULL
,
6424 (STRINGP (operation
) ?
6425 SDATA (operation
) : NULL
),
6427 (STRINGP (parameters
) ?
6428 SDATA (parameters
) : NULL
),
6429 SDATA (current_dir
),
6430 (INTEGERP (show_flag
) ?
6431 XINT (show_flag
) : SW_SHOWDEFAULT
))
6434 errstr
= w32_strerror (0);
6435 /* The error string might be encoded in the locale's encoding. */
6436 if (!NILP (Vlocale_coding_system
))
6438 Lisp_Object decoded
=
6439 code_convert_string_norecord (build_unibyte_string (errstr
),
6440 Vlocale_coding_system
, 0);
6441 errstr
= SSDATA (decoded
);
6443 error ("ShellExecute failed: %s", errstr
);
6446 /* Lookup virtual keycode from string representing the name of a
6447 non-ascii keystroke into the corresponding virtual key, using
6448 lispy_function_keys. */
6450 lookup_vk_code (char *key
)
6454 for (i
= 0; i
< 256; i
++)
6455 if (lispy_function_keys
[i
]
6456 && strcmp (lispy_function_keys
[i
], key
) == 0)
6462 /* Convert a one-element vector style key sequence to a hot key
6465 w32_parse_hot_key (Lisp_Object key
)
6467 /* Copied from Fdefine_key and store_in_keymap. */
6468 register Lisp_Object c
;
6472 struct gcpro gcpro1
;
6476 if (XFASTINT (Flength (key
)) != 1)
6481 c
= Faref (key
, make_number (0));
6483 if (CONSP (c
) && lucid_event_type_list_p (c
))
6484 c
= Fevent_convert_list (c
);
6488 if (! INTEGERP (c
) && ! SYMBOLP (c
))
6489 error ("Key definition is invalid");
6491 /* Work out the base key and the modifiers. */
6494 c
= parse_modifiers (c
);
6495 lisp_modifiers
= XINT (Fcar (Fcdr (c
)));
6499 vk_code
= lookup_vk_code (SDATA (SYMBOL_NAME (c
)));
6501 else if (INTEGERP (c
))
6503 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
6504 /* Many ascii characters are their own virtual key code. */
6505 vk_code
= XINT (c
) & CHARACTERBITS
;
6508 if (vk_code
< 0 || vk_code
> 255)
6511 if ((lisp_modifiers
& meta_modifier
) != 0
6512 && !NILP (Vw32_alt_is_meta
))
6513 lisp_modifiers
|= alt_modifier
;
6515 /* Supply defs missing from mingw32. */
6517 #define MOD_ALT 0x0001
6518 #define MOD_CONTROL 0x0002
6519 #define MOD_SHIFT 0x0004
6520 #define MOD_WIN 0x0008
6523 /* Convert lisp modifiers to Windows hot-key form. */
6524 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
6525 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
6526 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
6527 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
6529 return HOTKEY (vk_code
, w32_modifiers
);
6532 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
,
6533 Sw32_register_hot_key
, 1, 1, 0,
6534 doc
: /* Register KEY as a hot-key combination.
6535 Certain key combinations like Alt-Tab are reserved for system use on
6536 Windows, and therefore are normally intercepted by the system. However,
6537 most of these key combinations can be received by registering them as
6538 hot-keys, overriding their special meaning.
6540 KEY must be a one element key definition in vector form that would be
6541 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta
6542 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper
6543 is always interpreted as the Windows modifier keys.
6545 The return value is the hotkey-id if registered, otherwise nil. */)
6548 key
= w32_parse_hot_key (key
);
6550 if (!NILP (key
) && NILP (Fmemq (key
, w32_grabbed_keys
)))
6552 /* Reuse an empty slot if possible. */
6553 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
6555 /* Safe to add new key to list, even if we have focus. */
6557 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
6559 XSETCAR (item
, key
);
6561 /* Notify input thread about new hot-key definition, so that it
6562 takes effect without needing to switch focus. */
6563 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
6564 (WPARAM
) XLI (key
), 0);
6570 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
,
6571 Sw32_unregister_hot_key
, 1, 1, 0,
6572 doc
: /* Unregister KEY as a hot-key combination. */)
6577 if (!INTEGERP (key
))
6578 key
= w32_parse_hot_key (key
);
6580 item
= Fmemq (key
, w32_grabbed_keys
);
6584 /* Notify input thread about hot-key definition being removed, so
6585 that it takes effect without needing focus switch. */
6586 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
6587 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) XLI (item
)))
6590 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
6597 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
,
6598 Sw32_registered_hot_keys
, 0, 0, 0,
6599 doc
: /* Return list of registered hot-key IDs. */)
6602 return Fdelq (Qnil
, Fcopy_sequence (w32_grabbed_keys
));
6605 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
,
6606 Sw32_reconstruct_hot_key
, 1, 1, 0,
6607 doc
: /* Convert hot-key ID to a lisp key combination.
6608 usage: (w32-reconstruct-hot-key ID) */)
6609 (Lisp_Object hotkeyid
)
6611 int vk_code
, w32_modifiers
;
6614 CHECK_NUMBER (hotkeyid
);
6616 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
6617 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
6619 if (vk_code
< 256 && lispy_function_keys
[vk_code
])
6620 key
= intern (lispy_function_keys
[vk_code
]);
6622 key
= make_number (vk_code
);
6624 key
= Fcons (key
, Qnil
);
6625 if (w32_modifiers
& MOD_SHIFT
)
6626 key
= Fcons (Qshift
, key
);
6627 if (w32_modifiers
& MOD_CONTROL
)
6628 key
= Fcons (Qctrl
, key
);
6629 if (w32_modifiers
& MOD_ALT
)
6630 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
6631 if (w32_modifiers
& MOD_WIN
)
6632 key
= Fcons (Qhyper
, key
);
6637 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
,
6638 Sw32_toggle_lock_key
, 1, 2, 0,
6639 doc
: /* Toggle the state of the lock key KEY.
6640 KEY can be `capslock', `kp-numlock', or `scroll'.
6641 If the optional parameter NEW-STATE is a number, then the state of KEY
6642 is set to off if the low bit of NEW-STATE is zero, otherwise on. */)
6643 (Lisp_Object key
, Lisp_Object new_state
)
6647 if (EQ (key
, intern ("capslock")))
6648 vk_code
= VK_CAPITAL
;
6649 else if (EQ (key
, intern ("kp-numlock")))
6650 vk_code
= VK_NUMLOCK
;
6651 else if (EQ (key
, intern ("scroll")))
6652 vk_code
= VK_SCROLL
;
6656 if (!dwWindowsThreadId
)
6657 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
6659 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
6660 (WPARAM
) vk_code
, (LPARAM
) XLI (new_state
)))
6663 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
6664 return make_number (msg
.wParam
);
6669 DEFUN ("w32-window-exists-p", Fw32_window_exists_p
, Sw32_window_exists_p
,
6671 doc
: /* Return non-nil if a window exists with the specified CLASS and NAME.
6673 This is a direct interface to the Windows API FindWindow function. */)
6674 (Lisp_Object
class, Lisp_Object name
)
6679 CHECK_STRING (class);
6681 CHECK_STRING (name
);
6683 hnd
= FindWindow (STRINGP (class) ? ((LPCTSTR
) SDATA (class)) : NULL
,
6684 STRINGP (name
) ? ((LPCTSTR
) SDATA (name
)) : NULL
);
6690 DEFUN ("w32-battery-status", Fw32_battery_status
, Sw32_battery_status
, 0, 0, 0,
6691 doc
: /* Get power status information from Windows system.
6693 The following %-sequences are provided:
6694 %L AC line status (verbose)
6695 %B Battery status (verbose)
6696 %b Battery status, empty means high, `-' means low,
6697 `!' means critical, and `+' means charging
6698 %p Battery load percentage
6699 %s Remaining time (to charge or discharge) in seconds
6700 %m Remaining time (to charge or discharge) in minutes
6701 %h Remaining time (to charge or discharge) in hours
6702 %t Remaining time (to charge or discharge) in the form `h:min' */)
6705 Lisp_Object status
= Qnil
;
6707 SYSTEM_POWER_STATUS system_status
;
6708 if (GetSystemPowerStatus (&system_status
))
6710 Lisp_Object line_status
, battery_status
, battery_status_symbol
;
6711 Lisp_Object load_percentage
, seconds
, minutes
, hours
, remain
;
6713 long seconds_left
= (long) system_status
.BatteryLifeTime
;
6715 if (system_status
.ACLineStatus
== 0)
6716 line_status
= build_string ("off-line");
6717 else if (system_status
.ACLineStatus
== 1)
6718 line_status
= build_string ("on-line");
6720 line_status
= build_string ("N/A");
6722 if (system_status
.BatteryFlag
& 128)
6724 battery_status
= build_string ("N/A");
6725 battery_status_symbol
= empty_unibyte_string
;
6727 else if (system_status
.BatteryFlag
& 8)
6729 battery_status
= build_string ("charging");
6730 battery_status_symbol
= build_string ("+");
6731 if (system_status
.BatteryFullLifeTime
!= -1L)
6732 seconds_left
= system_status
.BatteryFullLifeTime
- seconds_left
;
6734 else if (system_status
.BatteryFlag
& 4)
6736 battery_status
= build_string ("critical");
6737 battery_status_symbol
= build_string ("!");
6739 else if (system_status
.BatteryFlag
& 2)
6741 battery_status
= build_string ("low");
6742 battery_status_symbol
= build_string ("-");
6744 else if (system_status
.BatteryFlag
& 1)
6746 battery_status
= build_string ("high");
6747 battery_status_symbol
= empty_unibyte_string
;
6751 battery_status
= build_string ("medium");
6752 battery_status_symbol
= empty_unibyte_string
;
6755 if (system_status
.BatteryLifePercent
> 100)
6756 load_percentage
= build_string ("N/A");
6760 snprintf (buffer
, 16, "%d", system_status
.BatteryLifePercent
);
6761 load_percentage
= build_string (buffer
);
6764 if (seconds_left
< 0)
6765 seconds
= minutes
= hours
= remain
= build_string ("N/A");
6771 snprintf (buffer
, 16, "%ld", seconds_left
);
6772 seconds
= build_string (buffer
);
6774 m
= seconds_left
/ 60;
6775 snprintf (buffer
, 16, "%ld", m
);
6776 minutes
= build_string (buffer
);
6778 h
= seconds_left
/ 3600.0;
6779 snprintf (buffer
, 16, "%3.1f", h
);
6780 hours
= build_string (buffer
);
6782 snprintf (buffer
, 16, "%ld:%02ld", m
/ 60, m
% 60);
6783 remain
= build_string (buffer
);
6786 status
= listn (CONSTYPE_HEAP
, 8,
6787 Fcons (make_number ('L'), line_status
),
6788 Fcons (make_number ('B'), battery_status
),
6789 Fcons (make_number ('b'), battery_status_symbol
),
6790 Fcons (make_number ('p'), load_percentage
),
6791 Fcons (make_number ('s'), seconds
),
6792 Fcons (make_number ('m'), minutes
),
6793 Fcons (make_number ('h'), hours
),
6794 Fcons (make_number ('t'), remain
));
6800 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
6801 doc
: /* Return storage information about the file system FILENAME is on.
6802 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
6803 storage of the file system, FREE is the free storage, and AVAIL is the
6804 storage available to a non-superuser. All 3 numbers are in bytes.
6805 If the underlying system call fails, value is nil. */)
6806 (Lisp_Object filename
)
6808 Lisp_Object encoded
, value
;
6810 CHECK_STRING (filename
);
6811 filename
= Fexpand_file_name (filename
, Qnil
);
6812 encoded
= ENCODE_FILE (filename
);
6816 /* Determining the required information on Windows turns out, sadly,
6817 to be more involved than one would hope. The original Windows API
6818 call for this will return bogus information on some systems, but we
6819 must dynamically probe for the replacement api, since that was
6820 added rather late on. */
6822 HMODULE hKernel
= GetModuleHandle ("kernel32");
6823 BOOL (*pfn_GetDiskFreeSpaceEx
)
6824 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
6825 = (void *) GetProcAddress (hKernel
, "GetDiskFreeSpaceEx");
6827 /* On Windows, we may need to specify the root directory of the
6828 volume holding FILENAME. */
6829 char rootname
[MAX_PATH
];
6830 char *name
= SDATA (encoded
);
6832 /* find the root name of the volume if given */
6833 if (isalpha (name
[0]) && name
[1] == ':')
6835 rootname
[0] = name
[0];
6836 rootname
[1] = name
[1];
6840 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
6842 char *str
= rootname
;
6846 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
6856 if (pfn_GetDiskFreeSpaceEx
)
6858 /* Unsigned large integers cannot be cast to double, so
6859 use signed ones instead. */
6860 LARGE_INTEGER availbytes
;
6861 LARGE_INTEGER freebytes
;
6862 LARGE_INTEGER totalbytes
;
6864 if (pfn_GetDiskFreeSpaceEx (rootname
,
6865 (ULARGE_INTEGER
*)&availbytes
,
6866 (ULARGE_INTEGER
*)&totalbytes
,
6867 (ULARGE_INTEGER
*)&freebytes
))
6868 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
6869 make_float ((double) freebytes
.QuadPart
),
6870 make_float ((double) availbytes
.QuadPart
));
6874 DWORD sectors_per_cluster
;
6875 DWORD bytes_per_sector
;
6876 DWORD free_clusters
;
6877 DWORD total_clusters
;
6879 if (GetDiskFreeSpace (rootname
,
6880 §ors_per_cluster
,
6884 value
= list3 (make_float ((double) total_clusters
6885 * sectors_per_cluster
* bytes_per_sector
),
6886 make_float ((double) free_clusters
6887 * sectors_per_cluster
* bytes_per_sector
),
6888 make_float ((double) free_clusters
6889 * sectors_per_cluster
* bytes_per_sector
));
6896 DEFUN ("default-printer-name", Fdefault_printer_name
, Sdefault_printer_name
,
6897 0, 0, 0, doc
: /* Return the name of Windows default printer device. */)
6900 static char pname_buf
[256];
6903 PRINTER_INFO_2
*ppi2
= NULL
;
6904 DWORD dwNeeded
= 0, dwReturned
= 0;
6906 /* Retrieve the default string from Win.ini (the registry).
6907 * String will be in form "printername,drivername,portname".
6908 * This is the most portable way to get the default printer. */
6909 if (GetProfileString ("windows", "device", ",,", pname_buf
, sizeof (pname_buf
)) <= 0)
6911 /* printername precedes first "," character */
6912 strtok (pname_buf
, ",");
6913 /* We want to know more than the printer name */
6914 if (!OpenPrinter (pname_buf
, &hPrn
, NULL
))
6916 GetPrinter (hPrn
, 2, NULL
, 0, &dwNeeded
);
6919 ClosePrinter (hPrn
);
6922 /* Allocate memory for the PRINTER_INFO_2 struct */
6923 ppi2
= xmalloc (dwNeeded
);
6926 ClosePrinter (hPrn
);
6929 /* Call GetPrinter again with big enough memory block. */
6930 err
= GetPrinter (hPrn
, 2, (LPBYTE
)ppi2
, dwNeeded
, &dwReturned
);
6931 ClosePrinter (hPrn
);
6940 if (ppi2
->Attributes
& PRINTER_ATTRIBUTE_SHARED
&& ppi2
->pServerName
)
6942 /* a remote printer */
6943 if (*ppi2
->pServerName
== '\\')
6944 snprintf (pname_buf
, sizeof (pname_buf
), "%s\\%s", ppi2
->pServerName
,
6947 snprintf (pname_buf
, sizeof (pname_buf
), "\\\\%s\\%s", ppi2
->pServerName
,
6949 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
6953 /* a local printer */
6954 strncpy (pname_buf
, ppi2
->pPortName
, sizeof (pname_buf
));
6955 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
6956 /* `pPortName' can include several ports, delimited by ','.
6957 * we only use the first one. */
6958 strtok (pname_buf
, ",");
6963 return build_string (pname_buf
);
6967 /* Equivalent of strerror for W32 error codes. */
6969 w32_strerror (int error_no
)
6971 static char buf
[500];
6975 error_no
= GetLastError ();
6977 ret
= FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
|
6978 FORMAT_MESSAGE_IGNORE_INSERTS
,
6981 0, /* choose most suitable language */
6982 buf
, sizeof (buf
), NULL
);
6984 while (ret
> 0 && (buf
[ret
- 1] == '\n' ||
6985 buf
[ret
- 1] == '\r' ))
6989 sprintf (buf
, "w32 error %u", error_no
);
6994 /* For convenience when debugging. (You cannot call GetLastError
6995 directly from GDB: it will crash, because it uses the __stdcall
6996 calling convention, not the _cdecl convention assumed by GDB.) */
6998 w32_last_error (void)
7000 return GetLastError ();
7003 /* Cache information describing the NT system for later use. */
7005 cache_system_info (void)
7018 /* Cache the version of the operating system. */
7019 version
.data
= GetVersion ();
7020 w32_major_version
= version
.info
.major
;
7021 w32_minor_version
= version
.info
.minor
;
7023 if (version
.info
.platform
& 0x8000)
7028 /* Cache page size, allocation unit, processor type, etc. */
7029 GetSystemInfo (&sysinfo_cache
);
7030 syspage_mask
= sysinfo_cache
.dwPageSize
- 1;
7032 /* Cache os info. */
7033 osinfo_cache
.dwOSVersionInfoSize
= sizeof (OSVERSIONINFO
);
7034 GetVersionEx (&osinfo_cache
);
7036 w32_build_number
= osinfo_cache
.dwBuildNumber
;
7037 if (os_subtype
== OS_9X
)
7038 w32_build_number
&= 0xffff;
7040 w32_num_mouse_buttons
= GetSystemMetrics (SM_CMOUSEBUTTONS
);
7045 _DebPrint (const char *fmt
, ...)
7050 va_start (args
, fmt
);
7051 vsprintf (buf
, fmt
, args
);
7054 fprintf (stderr
, "%s", buf
);
7056 OutputDebugString (buf
);
7061 w32_console_toggle_lock_key (int vk_code
, Lisp_Object new_state
)
7063 int cur_state
= (GetKeyState (vk_code
) & 1);
7065 if (NILP (new_state
)
7066 || (NUMBERP (new_state
)
7067 && ((XUINT (new_state
)) & 1) != cur_state
))
7070 faked_key
= vk_code
;
7071 #endif /* WINDOWSNT */
7073 keybd_event ((BYTE
) vk_code
,
7074 (BYTE
) MapVirtualKey (vk_code
, 0),
7075 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
7076 keybd_event ((BYTE
) vk_code
,
7077 (BYTE
) MapVirtualKey (vk_code
, 0),
7078 KEYEVENTF_EXTENDEDKEY
| 0, 0);
7079 keybd_event ((BYTE
) vk_code
,
7080 (BYTE
) MapVirtualKey (vk_code
, 0),
7081 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
7082 cur_state
= !cur_state
;
7088 /* Translate console modifiers to emacs modifiers.
7089 German keyboard support (Kai Morgan Zeise 2/18/95). */
7091 w32_kbd_mods_to_emacs (DWORD mods
, WORD key
)
7095 /* If we recognize right-alt and left-ctrl as AltGr, and it has been
7096 pressed, first remove those modifiers. */
7097 if (!NILP (Vw32_recognize_altgr
)
7098 && (mods
& (RIGHT_ALT_PRESSED
| LEFT_CTRL_PRESSED
))
7099 == (RIGHT_ALT_PRESSED
| LEFT_CTRL_PRESSED
))
7100 mods
&= ~ (RIGHT_ALT_PRESSED
| LEFT_CTRL_PRESSED
);
7102 if (mods
& (RIGHT_ALT_PRESSED
| LEFT_ALT_PRESSED
))
7103 retval
= ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
);
7105 if (mods
& (RIGHT_CTRL_PRESSED
| LEFT_CTRL_PRESSED
))
7107 retval
|= ctrl_modifier
;
7108 if ((mods
& (RIGHT_CTRL_PRESSED
| LEFT_CTRL_PRESSED
))
7109 == (RIGHT_CTRL_PRESSED
| LEFT_CTRL_PRESSED
))
7110 retval
|= meta_modifier
;
7113 if (mods
& LEFT_WIN_PRESSED
)
7114 retval
|= w32_key_to_modifier (VK_LWIN
);
7115 if (mods
& RIGHT_WIN_PRESSED
)
7116 retval
|= w32_key_to_modifier (VK_RWIN
);
7117 if (mods
& APPS_PRESSED
)
7118 retval
|= w32_key_to_modifier (VK_APPS
);
7119 if (mods
& SCROLLLOCK_ON
)
7120 retval
|= w32_key_to_modifier (VK_SCROLL
);
7122 /* Just in case someone wanted the original behavior, make it
7123 optional by setting w32-capslock-is-shiftlock to t. */
7124 if (NILP (Vw32_capslock_is_shiftlock
)
7125 /* Keys that should _not_ be affected by CapsLock. */
7126 && ( (key
== VK_BACK
)
7128 || (key
== VK_CLEAR
)
7129 || (key
== VK_RETURN
)
7130 || (key
== VK_ESCAPE
)
7131 || ((key
>= VK_SPACE
) && (key
<= VK_HELP
))
7132 || ((key
>= VK_NUMPAD0
) && (key
<= VK_F24
))
7133 || ((key
>= VK_NUMPAD_CLEAR
) && (key
<= VK_NUMPAD_DELETE
))
7136 /* Only consider shift state. */
7137 if ((mods
& SHIFT_PRESSED
) != 0)
7138 retval
|= shift_modifier
;
7142 /* Ignore CapsLock state if not enabled. */
7143 if (NILP (Vw32_enable_caps_lock
))
7144 mods
&= ~CAPSLOCK_ON
;
7145 if ((mods
& (SHIFT_PRESSED
| CAPSLOCK_ON
)) != 0)
7146 retval
|= shift_modifier
;
7152 /* The return code indicates key code size. cpID is the codepage to
7153 use for translation to Unicode; -1 means use the current console
7156 w32_kbd_patch_key (KEY_EVENT_RECORD
*event
, int cpId
)
7158 unsigned int key_code
= event
->wVirtualKeyCode
;
7159 unsigned int mods
= event
->dwControlKeyState
;
7161 static BYTE ansi_code
[4];
7162 static int isdead
= 0;
7166 event
->uChar
.AsciiChar
= ansi_code
[2];
7170 if (event
->uChar
.AsciiChar
!= 0)
7173 memset (keystate
, 0, sizeof (keystate
));
7174 keystate
[key_code
] = 0x80;
7175 if (mods
& SHIFT_PRESSED
)
7176 keystate
[VK_SHIFT
] = 0x80;
7177 if (mods
& CAPSLOCK_ON
)
7178 keystate
[VK_CAPITAL
] = 1;
7179 /* If we recognize right-alt and left-ctrl as AltGr, set the key
7180 states accordingly before invoking ToAscii. */
7181 if (!NILP (Vw32_recognize_altgr
)
7182 && (mods
& LEFT_CTRL_PRESSED
) && (mods
& RIGHT_ALT_PRESSED
))
7184 keystate
[VK_CONTROL
] = 0x80;
7185 keystate
[VK_LCONTROL
] = 0x80;
7186 keystate
[VK_MENU
] = 0x80;
7187 keystate
[VK_RMENU
] = 0x80;
7191 /* Because of an OS bug, ToAscii corrupts the stack when called to
7192 convert a dead key in console mode on NT4. Unfortunately, trying
7193 to check for dead keys using MapVirtualKey doesn't work either -
7194 these functions apparently use internal information about keyboard
7195 layout which doesn't get properly updated in console programs when
7196 changing layout (though apparently it gets partly updated,
7197 otherwise ToAscii wouldn't crash). */
7198 if (is_dead_key (event
->wVirtualKeyCode
))
7202 /* On NT, call ToUnicode instead and then convert to the current
7203 console input codepage. */
7204 if (os_subtype
== OS_NT
)
7208 isdead
= ToUnicode (event
->wVirtualKeyCode
, event
->wVirtualScanCode
,
7209 keystate
, buf
, 128, 0);
7212 /* When we are called from the GUI message processing code,
7213 we are passed the current keyboard codepage, a positive
7214 number, to use below. */
7216 cpId
= GetConsoleCP ();
7218 event
->uChar
.UnicodeChar
= buf
[isdead
- 1];
7219 isdead
= WideCharToMultiByte (cpId
, 0, buf
, isdead
,
7220 ansi_code
, 4, NULL
, NULL
);
7227 isdead
= ToAscii (event
->wVirtualKeyCode
, event
->wVirtualScanCode
,
7228 keystate
, (LPWORD
) ansi_code
, 0);
7233 event
->uChar
.AsciiChar
= ansi_code
[0];
7239 w32_sys_ring_bell (struct frame
*f
)
7241 if (sound_type
== 0xFFFFFFFF)
7245 else if (sound_type
== MB_EMACS_SILENT
)
7250 MessageBeep (sound_type
);
7254 /***********************************************************************
7256 ***********************************************************************/
7258 /* Keep this list in the same order as frame_parms in frame.c.
7259 Use 0 for unsupported frame parameters. */
7261 frame_parm_handler w32_frame_parm_handlers
[] =
7265 x_set_background_color
,
7271 x_set_foreground_color
,
7274 x_set_internal_border_width
,
7275 x_set_menu_bar_lines
,
7277 x_explicitly_set_name
,
7278 x_set_scroll_bar_width
,
7281 x_set_vertical_scroll_bars
,
7283 x_set_tool_bar_lines
,
7284 0, /* x_set_scroll_bar_foreground, */
7285 0, /* x_set_scroll_bar_background, */
7290 0, /* x_set_wait_for_wm, */
7294 0, /* x_set_sticky */
7295 0, /* x_set_tool_bar_position */
7299 syms_of_w32fns (void)
7301 globals_of_w32fns ();
7302 /* This is zero if not using MS-Windows. */
7304 track_mouse_window
= NULL
;
7306 w32_visible_system_caret_hwnd
= NULL
;
7308 DEFSYM (Qsuppress_icon
, "suppress-icon");
7309 DEFSYM (Qundefined_color
, "undefined-color");
7310 DEFSYM (Qcancel_timer
, "cancel-timer");
7311 DEFSYM (Qhyper
, "hyper");
7312 DEFSYM (Qsuper
, "super");
7313 DEFSYM (Qmeta
, "meta");
7314 DEFSYM (Qalt
, "alt");
7315 DEFSYM (Qctrl
, "ctrl");
7316 DEFSYM (Qcontrol
, "control");
7317 DEFSYM (Qshift
, "shift");
7318 DEFSYM (Qfont_param
, "font-parameter");
7319 /* This is the end of symbol initialization. */
7322 Fput (Qundefined_color
, Qerror_conditions
,
7323 listn (CONSTYPE_PURE
, 2, Qundefined_color
, Qerror
));
7324 Fput (Qundefined_color
, Qerror_message
,
7325 build_pure_c_string ("Undefined color"));
7327 staticpro (&w32_grabbed_keys
);
7328 w32_grabbed_keys
= Qnil
;
7330 DEFVAR_LISP ("w32-color-map", Vw32_color_map
,
7331 doc
: /* An array of color name mappings for Windows. */);
7332 Vw32_color_map
= Qnil
;
7334 DEFVAR_LISP ("w32-pass-alt-to-system", Vw32_pass_alt_to_system
,
7335 doc
: /* Non-nil if Alt key presses are passed on to Windows.
7336 When non-nil, for example, Alt pressed and released and then space will
7337 open the System menu. When nil, Emacs processes the Alt key events, and
7338 then silently swallows them. */);
7339 Vw32_pass_alt_to_system
= Qnil
;
7341 DEFVAR_LISP ("w32-alt-is-meta", Vw32_alt_is_meta
,
7342 doc
: /* Non-nil if the Alt key is to be considered the same as the META key.
7343 When nil, Emacs will translate the Alt key to the ALT modifier, not to META. */);
7344 Vw32_alt_is_meta
= Qt
;
7346 DEFVAR_INT ("w32-quit-key", w32_quit_key
,
7347 doc
: /* If non-zero, the virtual key code for an alternative quit key. */);
7350 DEFVAR_LISP ("w32-pass-lwindow-to-system",
7351 Vw32_pass_lwindow_to_system
,
7352 doc
: /* If non-nil, the left \"Windows\" key is passed on to Windows.
7354 When non-nil, the Start menu is opened by tapping the key.
7355 If you set this to nil, the left \"Windows\" key is processed by Emacs
7356 according to the value of `w32-lwindow-modifier', which see.
7358 Note that some combinations of the left \"Windows\" key with other keys are
7359 caught by Windows at low level, and so binding them in Emacs will have no
7360 effect. For example, <lwindow>-r always pops up the Windows Run dialog,
7361 <lwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
7362 the doc string of `w32-phantom-key-code'. */);
7363 Vw32_pass_lwindow_to_system
= Qt
;
7365 DEFVAR_LISP ("w32-pass-rwindow-to-system",
7366 Vw32_pass_rwindow_to_system
,
7367 doc
: /* If non-nil, the right \"Windows\" key is passed on to Windows.
7369 When non-nil, the Start menu is opened by tapping the key.
7370 If you set this to nil, the right \"Windows\" key is processed by Emacs
7371 according to the value of `w32-rwindow-modifier', which see.
7373 Note that some combinations of the right \"Windows\" key with other keys are
7374 caught by Windows at low level, and so binding them in Emacs will have no
7375 effect. For example, <rwindow>-r always pops up the Windows Run dialog,
7376 <rwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
7377 the doc string of `w32-phantom-key-code'. */);
7378 Vw32_pass_rwindow_to_system
= Qt
;
7380 DEFVAR_LISP ("w32-phantom-key-code",
7381 Vw32_phantom_key_code
,
7382 doc
: /* Virtual key code used to generate \"phantom\" key presses.
7383 Value is a number between 0 and 255.
7385 Phantom key presses are generated in order to stop the system from
7386 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or
7387 `w32-pass-rwindow-to-system' is nil. */);
7388 /* Although 255 is technically not a valid key code, it works and
7389 means that this hack won't interfere with any real key code. */
7390 XSETINT (Vw32_phantom_key_code
, 255);
7392 DEFVAR_LISP ("w32-enable-num-lock",
7393 Vw32_enable_num_lock
,
7394 doc
: /* If non-nil, the Num Lock key acts normally.
7395 Set to nil to handle Num Lock as the `kp-numlock' key. */);
7396 Vw32_enable_num_lock
= Qt
;
7398 DEFVAR_LISP ("w32-enable-caps-lock",
7399 Vw32_enable_caps_lock
,
7400 doc
: /* If non-nil, the Caps Lock key acts normally.
7401 Set to nil to handle Caps Lock as the `capslock' key. */);
7402 Vw32_enable_caps_lock
= Qt
;
7404 DEFVAR_LISP ("w32-scroll-lock-modifier",
7405 Vw32_scroll_lock_modifier
,
7406 doc
: /* Modifier to use for the Scroll Lock ON state.
7407 The value can be hyper, super, meta, alt, control or shift for the
7408 respective modifier, or nil to handle Scroll Lock as the `scroll' key.
7409 Any other value will cause the Scroll Lock key to be ignored. */);
7410 Vw32_scroll_lock_modifier
= Qnil
;
7412 DEFVAR_LISP ("w32-lwindow-modifier",
7413 Vw32_lwindow_modifier
,
7414 doc
: /* Modifier to use for the left \"Windows\" key.
7415 The value can be hyper, super, meta, alt, control or shift for the
7416 respective modifier, or nil to appear as the `lwindow' key.
7417 Any other value will cause the key to be ignored. */);
7418 Vw32_lwindow_modifier
= Qnil
;
7420 DEFVAR_LISP ("w32-rwindow-modifier",
7421 Vw32_rwindow_modifier
,
7422 doc
: /* Modifier to use for the right \"Windows\" key.
7423 The value can be hyper, super, meta, alt, control or shift for the
7424 respective modifier, or nil to appear as the `rwindow' key.
7425 Any other value will cause the key to be ignored. */);
7426 Vw32_rwindow_modifier
= Qnil
;
7428 DEFVAR_LISP ("w32-apps-modifier",
7430 doc
: /* Modifier to use for the \"Apps\" key.
7431 The value can be hyper, super, meta, alt, control or shift for the
7432 respective modifier, or nil to appear as the `apps' key.
7433 Any other value will cause the key to be ignored. */);
7434 Vw32_apps_modifier
= Qnil
;
7436 DEFVAR_BOOL ("w32-enable-synthesized-fonts", w32_enable_synthesized_fonts
,
7437 doc
: /* Non-nil enables selection of artificially italicized and bold fonts. */);
7438 w32_enable_synthesized_fonts
= 0;
7440 DEFVAR_LISP ("w32-enable-palette", Vw32_enable_palette
,
7441 doc
: /* Non-nil enables Windows palette management to map colors exactly. */);
7442 Vw32_enable_palette
= Qt
;
7444 DEFVAR_INT ("w32-mouse-button-tolerance",
7445 w32_mouse_button_tolerance
,
7446 doc
: /* Analogue of double click interval for faking middle mouse events.
7447 The value is the minimum time in milliseconds that must elapse between
7448 left and right button down events before they are considered distinct events.
7449 If both mouse buttons are depressed within this interval, a middle mouse
7450 button down event is generated instead. */);
7451 w32_mouse_button_tolerance
= GetDoubleClickTime () / 2;
7453 DEFVAR_INT ("w32-mouse-move-interval",
7454 w32_mouse_move_interval
,
7455 doc
: /* Minimum interval between mouse move events.
7456 The value is the minimum time in milliseconds that must elapse between
7457 successive mouse move (or scroll bar drag) events before they are
7458 reported as lisp events. */);
7459 w32_mouse_move_interval
= 0;
7461 DEFVAR_BOOL ("w32-pass-extra-mouse-buttons-to-system",
7462 w32_pass_extra_mouse_buttons_to_system
,
7463 doc
: /* If non-nil, the fourth and fifth mouse buttons are passed to Windows.
7464 Recent versions of Windows support mice with up to five buttons.
7465 Since most applications don't support these extra buttons, most mouse
7466 drivers will allow you to map them to functions at the system level.
7467 If this variable is non-nil, Emacs will pass them on, allowing the
7468 system to handle them. */);
7469 w32_pass_extra_mouse_buttons_to_system
= 0;
7471 DEFVAR_BOOL ("w32-pass-multimedia-buttons-to-system",
7472 w32_pass_multimedia_buttons_to_system
,
7473 doc
: /* If non-nil, media buttons are passed to Windows.
7474 Some modern keyboards contain buttons for controlling media players, web
7475 browsers and other applications. Generally these buttons are handled on a
7476 system wide basis, but by setting this to nil they are made available
7477 to Emacs for binding. Depending on your keyboard, additional keys that
7478 may be available are:
7480 browser-back, browser-forward, browser-refresh, browser-stop,
7481 browser-search, browser-favorites, browser-home,
7482 mail, mail-reply, mail-forward, mail-send,
7484 help, find, new, open, close, save, print, undo, redo, copy, cut, paste,
7485 spell-check, correction-list, toggle-dictate-command,
7486 media-next, media-previous, media-stop, media-play-pause, media-select,
7487 media-play, media-pause, media-record, media-fast-forward, media-rewind,
7488 media-channel-up, media-channel-down,
7489 volume-mute, volume-up, volume-down,
7490 mic-volume-mute, mic-volume-down, mic-volume-up, mic-toggle,
7491 bass-down, bass-boost, bass-up, treble-down, treble-up */);
7492 w32_pass_multimedia_buttons_to_system
= 1;
7494 #if 0 /* TODO: Mouse cursor customization. */
7495 DEFVAR_LISP ("x-pointer-shape", Vx_pointer_shape
,
7496 doc
: /* The shape of the pointer when over text.
7497 Changing the value does not affect existing frames
7498 unless you set the mouse color. */);
7499 Vx_pointer_shape
= Qnil
;
7501 Vx_nontext_pointer_shape
= Qnil
;
7503 Vx_mode_pointer_shape
= Qnil
;
7505 DEFVAR_LISP ("x-hourglass-pointer-shape", Vx_hourglass_pointer_shape
,
7506 doc
: /* The shape of the pointer when Emacs is busy.
7507 This variable takes effect when you create a new frame
7508 or when you set the mouse color. */);
7509 Vx_hourglass_pointer_shape
= Qnil
;
7511 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
7512 Vx_sensitive_text_pointer_shape
,
7513 doc
: /* The shape of the pointer when over mouse-sensitive text.
7514 This variable takes effect when you create a new frame
7515 or when you set the mouse color. */);
7516 Vx_sensitive_text_pointer_shape
= Qnil
;
7518 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
7519 Vx_window_horizontal_drag_shape
,
7520 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
7521 This variable takes effect when you create a new frame
7522 or when you set the mouse color. */);
7523 Vx_window_horizontal_drag_shape
= Qnil
;
7526 DEFVAR_LISP ("x-cursor-fore-pixel", Vx_cursor_fore_pixel
,
7527 doc
: /* A string indicating the foreground color of the cursor box. */);
7528 Vx_cursor_fore_pixel
= Qnil
;
7530 DEFVAR_LISP ("x-max-tooltip-size", Vx_max_tooltip_size
,
7531 doc
: /* Maximum size for tooltips.
7532 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
7533 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
7535 DEFVAR_LISP ("x-no-window-manager", Vx_no_window_manager
,
7536 doc
: /* Non-nil if no window manager is in use.
7537 Emacs doesn't try to figure this out; this is always nil
7538 unless you set it to something else. */);
7539 /* We don't have any way to find this out, so set it to nil
7540 and maybe the user would like to set it to t. */
7541 Vx_no_window_manager
= Qnil
;
7543 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
7544 Vx_pixel_size_width_font_regexp
,
7545 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
7547 Since Emacs gets width of a font matching with this regexp from
7548 PIXEL_SIZE field of the name, font finding mechanism gets faster for
7549 such a font. This is especially effective for such large fonts as
7550 Chinese, Japanese, and Korean. */);
7551 Vx_pixel_size_width_font_regexp
= Qnil
;
7553 DEFVAR_LISP ("w32-bdf-filename-alist",
7554 Vw32_bdf_filename_alist
,
7555 doc
: /* List of bdf fonts and their corresponding filenames. */);
7556 Vw32_bdf_filename_alist
= Qnil
;
7558 DEFVAR_BOOL ("w32-strict-fontnames",
7559 w32_strict_fontnames
,
7560 doc
: /* Non-nil means only use fonts that are exact matches for those requested.
7561 Default is nil, which allows old fontnames that are not XLFD compliant,
7562 and allows third-party CJK display to work by specifying false charset
7563 fields to trick Emacs into translating to Big5, SJIS etc.
7564 Setting this to t will prevent wrong fonts being selected when
7565 fontsets are automatically created. */);
7566 w32_strict_fontnames
= 0;
7568 DEFVAR_BOOL ("w32-strict-painting",
7569 w32_strict_painting
,
7570 doc
: /* Non-nil means use strict rules for repainting frames.
7571 Set this to nil to get the old behavior for repainting; this should
7572 only be necessary if the default setting causes problems. */);
7573 w32_strict_painting
= 1;
7575 #if 0 /* TODO: Port to W32 */
7576 defsubr (&Sx_change_window_property
);
7577 defsubr (&Sx_delete_window_property
);
7578 defsubr (&Sx_window_property
);
7580 defsubr (&Sxw_display_color_p
);
7581 defsubr (&Sx_display_grayscale_p
);
7582 defsubr (&Sxw_color_defined_p
);
7583 defsubr (&Sxw_color_values
);
7584 defsubr (&Sx_server_max_request_size
);
7585 defsubr (&Sx_server_vendor
);
7586 defsubr (&Sx_server_version
);
7587 defsubr (&Sx_display_pixel_width
);
7588 defsubr (&Sx_display_pixel_height
);
7589 defsubr (&Sx_display_mm_width
);
7590 defsubr (&Sx_display_mm_height
);
7591 defsubr (&Sx_display_screens
);
7592 defsubr (&Sx_display_planes
);
7593 defsubr (&Sx_display_color_cells
);
7594 defsubr (&Sx_display_visual_class
);
7595 defsubr (&Sx_display_backing_store
);
7596 defsubr (&Sx_display_save_under
);
7597 defsubr (&Sx_create_frame
);
7598 defsubr (&Sx_open_connection
);
7599 defsubr (&Sx_close_connection
);
7600 defsubr (&Sx_display_list
);
7601 defsubr (&Sx_synchronize
);
7602 defsubr (&Sx_focus_frame
);
7604 /* W32 specific functions */
7606 defsubr (&Sw32_define_rgb_color
);
7607 defsubr (&Sw32_default_color_map
);
7608 defsubr (&Sw32_send_sys_command
);
7609 defsubr (&Sw32_shell_execute
);
7610 defsubr (&Sw32_register_hot_key
);
7611 defsubr (&Sw32_unregister_hot_key
);
7612 defsubr (&Sw32_registered_hot_keys
);
7613 defsubr (&Sw32_reconstruct_hot_key
);
7614 defsubr (&Sw32_toggle_lock_key
);
7615 defsubr (&Sw32_window_exists_p
);
7616 defsubr (&Sw32_battery_status
);
7618 defsubr (&Sfile_system_info
);
7619 defsubr (&Sdefault_printer_name
);
7620 defsubr (&Sset_message_beep
);
7622 check_window_system_func
= check_w32
;
7624 hourglass_hwnd
= NULL
;
7626 defsubr (&Sx_show_tip
);
7627 defsubr (&Sx_hide_tip
);
7629 staticpro (&tip_timer
);
7631 staticpro (&tip_frame
);
7633 last_show_tip_args
= Qnil
;
7634 staticpro (&last_show_tip_args
);
7636 defsubr (&Sx_file_dialog
);
7638 defsubr (&Ssystem_move_file_to_trash
);
7644 globals_of_w32fns is used to initialize those global variables that
7645 must always be initialized on startup even when the global variable
7646 initialized is non zero (see the function main in emacs.c).
7647 globals_of_w32fns is called from syms_of_w32fns when the global
7648 variable initialized is 0 and directly from main when initialized
7652 globals_of_w32fns (void)
7654 HMODULE user32_lib
= GetModuleHandle ("user32.dll");
7656 TrackMouseEvent not available in all versions of Windows, so must load
7657 it dynamically. Do it once, here, instead of every time it is used.
7659 track_mouse_event_fn
= (TrackMouseEvent_Proc
)
7660 GetProcAddress (user32_lib
, "TrackMouseEvent");
7662 monitor_from_point_fn
= (MonitorFromPoint_Proc
)
7663 GetProcAddress (user32_lib
, "MonitorFromPoint");
7664 get_monitor_info_fn
= (GetMonitorInfo_Proc
)
7665 GetProcAddress (user32_lib
, "GetMonitorInfoA");
7668 HMODULE imm32_lib
= GetModuleHandle ("imm32.dll");
7669 get_composition_string_fn
= (ImmGetCompositionString_Proc
)
7670 GetProcAddress (imm32_lib
, "ImmGetCompositionStringW");
7671 get_ime_context_fn
= (ImmGetContext_Proc
)
7672 GetProcAddress (imm32_lib
, "ImmGetContext");
7673 release_ime_context_fn
= (ImmReleaseContext_Proc
)
7674 GetProcAddress (imm32_lib
, "ImmReleaseContext");
7675 set_ime_composition_window_fn
= (ImmSetCompositionWindow_Proc
)
7676 GetProcAddress (imm32_lib
, "ImmSetCompositionWindow");
7678 DEFVAR_INT ("w32-ansi-code-page",
7680 doc
: /* The ANSI code page used by the system. */);
7681 w32_ansi_code_page
= GetACP ();
7683 if (os_subtype
== OS_NT
)
7684 w32_unicode_gui
= 1;
7686 w32_unicode_gui
= 0;
7688 /* MessageBox does not work without this when linked to comctl32.dll 6.0. */
7689 InitCommonControls ();
7691 syms_of_w32uniscribe ();
7694 typedef USHORT (WINAPI
* CaptureStackBackTrace_proc
) (ULONG
, ULONG
, PVOID
*,
7697 #define BACKTRACE_LIMIT_MAX 62
7700 w32_backtrace (void **buffer
, int limit
)
7702 static CaptureStackBackTrace_proc s_pfn_CaptureStackBackTrace
= NULL
;
7703 HMODULE hm_kernel32
= NULL
;
7705 if (!s_pfn_CaptureStackBackTrace
)
7707 hm_kernel32
= LoadLibrary ("Kernel32.dll");
7708 s_pfn_CaptureStackBackTrace
=
7709 (CaptureStackBackTrace_proc
) GetProcAddress (hm_kernel32
,
7710 "RtlCaptureStackBackTrace");
7712 if (s_pfn_CaptureStackBackTrace
)
7713 return s_pfn_CaptureStackBackTrace (0, min (BACKTRACE_LIMIT_MAX
, limit
),
7722 button
= MessageBox (NULL
,
7723 "A fatal error has occurred!\n\n"
7724 "Would you like to attach a debugger?\n\n"
7726 "YES -- to debug Emacs, or\n"
7727 "NO -- to abort Emacs and produce a backtrace\n"
7728 " (emacs_backtrace.txt in current directory)."
7730 "\n\n(type \"gdb -p <emacs-PID>\" and\n"
7731 "\"continue\" inside GDB before clicking YES.)"
7733 , "Emacs Abort Dialog",
7734 MB_ICONEXCLAMATION
| MB_TASKMODAL
7735 | MB_SETFOREGROUND
| MB_YESNO
);
7740 exit (2); /* tell the compiler we will never return */
7744 void *stack
[BACKTRACE_LIMIT_MAX
+ 1];
7745 int i
= w32_backtrace (stack
, BACKTRACE_LIMIT_MAX
+ 1);
7752 HANDLE errout
= GetStdHandle (STD_ERROR_HANDLE
);
7755 int errfile_fd
= -1;
7759 if (errout
&& errout
!= INVALID_HANDLE_VALUE
)
7760 stderr_fd
= _open_osfhandle ((intptr_t)errout
, O_APPEND
| O_BINARY
);
7763 write (stderr_fd
, "\r\nBacktrace:\r\n", 14);
7764 errfile_fd
= _open ("emacs_backtrace.txt", O_RDWR
| O_CREAT
| O_BINARY
, S_IREAD
| S_IWRITE
);
7765 if (errfile_fd
>= 0)
7767 lseek (errfile_fd
, 0L, SEEK_END
);
7768 write (errfile_fd
, "\r\nBacktrace:\r\n", 14);
7771 for (j
= 0; j
< i
; j
++)
7773 char buf
[INT_BUFSIZE_BOUND (void *)];
7775 /* stack[] gives the return addresses, whereas we want
7776 the address of the call, so decrease each address
7777 by approximate size of 1 CALL instruction. */
7778 sprintf (buf
, "0x%p\r\n", stack
[j
] - sizeof(void *));
7780 write (stderr_fd
, buf
, strlen (buf
));
7781 if (errfile_fd
>= 0)
7782 write (errfile_fd
, buf
, strlen (buf
));
7784 if (i
== BACKTRACE_LIMIT_MAX
)
7787 write (stderr_fd
, "...\r\n", 5);
7788 if (errfile_fd
>= 0)
7789 write (errfile_fd
, "...\r\n", 5);
7791 if (errfile_fd
>= 0)