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 */
34 #include "character.h"
36 #include "intervals.h"
37 #include "dispextern.h"
39 #include "blockinput.h"
46 #include "termhooks.h"
50 #include "bitmaps/gray.xbm"
61 #define FILE_NAME_TEXT_FIELD edt1
62 #define FILE_NAME_COMBO_BOX cmb13
63 #define FILE_NAME_LIST lst1
68 #ifndef FOF_NO_CONNECTED_ELEMENTS
69 #define FOF_NO_CONNECTED_ELEMENTS 0x2000
72 void syms_of_w32fns (void);
73 void globals_of_w32fns (void);
75 extern void free_frame_menubar (struct frame
*);
76 extern double atof (const char *);
77 extern int w32_console_toggle_lock_key (int, Lisp_Object
);
78 extern void w32_menu_display_help (HWND
, HMENU
, UINT
, UINT
);
79 extern void w32_free_menu_strings (HWND
);
80 extern const char *map_w32_filename (const char *, const char **);
82 /* If non-NULL, a handle to a frame where to display the hourglass cursor. */
83 static HWND hourglass_hwnd
= NULL
;
86 #define IDC_HAND MAKEINTRESOURCE(32649)
89 /* Nonzero if using Windows. */
91 static int w32_in_use
;
93 Lisp_Object Qsuppress_icon
;
94 Lisp_Object Qundefined_color
;
95 Lisp_Object Qcancel_timer
;
96 Lisp_Object Qfont_param
;
102 Lisp_Object Qcontrol
;
106 /* Prefix for system colors. */
107 #define SYSTEM_COLOR_PREFIX "System"
108 #define SYSTEM_COLOR_PREFIX_LEN (sizeof (SYSTEM_COLOR_PREFIX) - 1)
110 /* State variables for emulating a three button mouse. */
115 static int button_state
= 0;
116 static W32Msg saved_mouse_button_msg
;
117 static unsigned mouse_button_timer
= 0; /* non-zero when timer is active */
118 static W32Msg saved_mouse_move_msg
;
119 static unsigned mouse_move_timer
= 0;
121 /* Window that is tracking the mouse. */
122 static HWND track_mouse_window
;
124 /* Multi-monitor API definitions that are not pulled from the headers
125 since we are compiling for NT 4. */
126 #ifndef MONITOR_DEFAULT_TO_NEAREST
127 #define MONITOR_DEFAULT_TO_NEAREST 2
129 /* MinGW headers define MONITORINFO unconditionally, but MSVC ones don't.
130 To avoid a compile error on one or the other, redefine with a new name. */
139 /* Reportedly, MSVC does not have this in its headers. */
140 #if defined (_MSC_VER) && _WIN32_WINNT < 0x0500
141 DECLARE_HANDLE(HMONITOR
);
144 typedef BOOL (WINAPI
* TrackMouseEvent_Proc
)
145 (IN OUT LPTRACKMOUSEEVENT lpEventTrack
);
146 typedef LONG (WINAPI
* ImmGetCompositionString_Proc
)
147 (IN HIMC context
, IN DWORD index
, OUT LPVOID buffer
, IN DWORD bufLen
);
148 typedef HIMC (WINAPI
* ImmGetContext_Proc
) (IN HWND window
);
149 typedef HWND (WINAPI
* ImmReleaseContext_Proc
) (IN HWND wnd
, IN HIMC context
);
150 typedef HWND (WINAPI
* ImmSetCompositionWindow_Proc
) (IN HIMC context
,
151 IN COMPOSITIONFORM
*form
);
152 typedef HMONITOR (WINAPI
* MonitorFromPoint_Proc
) (IN POINT pt
, IN DWORD flags
);
153 typedef BOOL (WINAPI
* GetMonitorInfo_Proc
)
154 (IN HMONITOR monitor
, OUT
struct MONITOR_INFO
* info
);
156 TrackMouseEvent_Proc track_mouse_event_fn
= NULL
;
157 ImmGetCompositionString_Proc get_composition_string_fn
= NULL
;
158 ImmGetContext_Proc get_ime_context_fn
= NULL
;
159 ImmReleaseContext_Proc release_ime_context_fn
= NULL
;
160 ImmSetCompositionWindow_Proc set_ime_composition_window_fn
= NULL
;
161 MonitorFromPoint_Proc monitor_from_point_fn
= NULL
;
162 GetMonitorInfo_Proc get_monitor_info_fn
= NULL
;
164 extern AppendMenuW_Proc unicode_append_menu
;
166 /* Flag to selectively ignore WM_IME_CHAR messages. */
167 static int ignore_ime_char
= 0;
169 /* W95 mousewheel handler */
170 unsigned int msh_mousewheel
= 0;
173 #define MOUSE_BUTTON_ID 1
174 #define MOUSE_MOVE_ID 2
175 #define MENU_FREE_ID 3
176 /* The delay (milliseconds) before a menu is freed after WM_EXITMENULOOP
178 #define MENU_FREE_DELAY 1000
179 static unsigned menu_free_timer
= 0;
182 static int image_cache_refcount
, dpyinfo_refcount
;
185 static HWND w32_visible_system_caret_hwnd
;
187 static int w32_unicode_gui
;
190 extern HMENU current_popup_menu
;
191 static int menubar_in_use
= 0;
193 /* From w32uniscribe.c */
194 extern void syms_of_w32uniscribe (void);
195 extern int uniscribe_available
;
197 /* Function prototypes for hourglass support. */
198 static void w32_show_hourglass (struct frame
*);
199 static void w32_hide_hourglass (void);
203 /* Error if we are not connected to MS-Windows. */
208 error ("MS-Windows not in use or not initialized");
211 /* Nonzero if we can use mouse menus.
212 You should not call this unless HAVE_MENUS is defined. */
220 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
221 and checking validity for W32. */
224 check_x_frame (Lisp_Object frame
)
229 frame
= selected_frame
;
230 CHECK_LIVE_FRAME (frame
);
232 if (! FRAME_W32_P (f
))
233 error ("Non-W32 frame used");
237 /* Let the user specify a display with a frame.
238 nil stands for the selected frame--or, if that is not a w32 frame,
239 the first display on the list. */
241 struct w32_display_info
*
242 check_x_display_info (Lisp_Object frame
)
246 struct frame
*sf
= XFRAME (selected_frame
);
248 if (FRAME_W32_P (sf
) && FRAME_LIVE_P (sf
))
249 return FRAME_W32_DISPLAY_INFO (sf
);
251 return &one_w32_display_info
;
253 else if (STRINGP (frame
))
254 return x_display_info_for_name (frame
);
259 CHECK_LIVE_FRAME (frame
);
261 if (! FRAME_W32_P (f
))
262 error ("Non-W32 frame used");
263 return FRAME_W32_DISPLAY_INFO (f
);
267 /* Return the Emacs frame-object corresponding to an w32 window.
268 It could be the frame's main window or an icon window. */
270 /* This function can be called during GC, so use GC_xxx type test macros. */
273 x_window_to_frame (struct w32_display_info
*dpyinfo
, HWND wdesc
)
275 Lisp_Object tail
, frame
;
278 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
284 if (!FRAME_W32_P (f
) || FRAME_W32_DISPLAY_INFO (f
) != dpyinfo
)
287 if (FRAME_W32_WINDOW (f
) == wdesc
)
294 static Lisp_Object
unwind_create_frame (Lisp_Object
);
295 static Lisp_Object
unwind_create_tip_frame (Lisp_Object
);
296 static void my_create_window (struct frame
*);
297 static void my_create_tip_window (struct frame
*);
299 /* TODO: Native Input Method support; see x_create_im. */
300 void x_set_foreground_color (struct frame
*, Lisp_Object
, Lisp_Object
);
301 void x_set_background_color (struct frame
*, Lisp_Object
, Lisp_Object
);
302 void x_set_mouse_color (struct frame
*, Lisp_Object
, Lisp_Object
);
303 void x_set_cursor_color (struct frame
*, Lisp_Object
, Lisp_Object
);
304 void x_set_border_color (struct frame
*, Lisp_Object
, Lisp_Object
);
305 void x_set_cursor_type (struct frame
*, Lisp_Object
, Lisp_Object
);
306 void x_set_icon_type (struct frame
*, Lisp_Object
, Lisp_Object
);
307 void x_set_icon_name (struct frame
*, Lisp_Object
, Lisp_Object
);
308 void x_explicitly_set_name (struct frame
*, Lisp_Object
, Lisp_Object
);
309 void x_set_menu_bar_lines (struct frame
*, Lisp_Object
, Lisp_Object
);
310 void x_set_title (struct frame
*, Lisp_Object
, Lisp_Object
);
311 void x_set_tool_bar_lines (struct frame
*, Lisp_Object
, Lisp_Object
);
316 /* Store the screen positions of frame F into XPTR and YPTR.
317 These are the positions of the containing window manager window,
318 not Emacs's own window. */
321 x_real_positions (FRAME_PTR f
, int *xptr
, int *yptr
)
326 /* Get the bounds of the WM window. */
327 GetWindowRect (FRAME_W32_WINDOW (f
), &rect
);
332 /* Convert (0, 0) in the client area to screen co-ordinates. */
333 ClientToScreen (FRAME_W32_WINDOW (f
), &pt
);
335 /* Remember x_pixels_diff and y_pixels_diff. */
336 f
->x_pixels_diff
= pt
.x
- rect
.left
;
337 f
->y_pixels_diff
= pt
.y
- rect
.top
;
345 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
,
346 Sw32_define_rgb_color
, 4, 4, 0,
347 doc
: /* Convert RGB numbers to a Windows color reference and associate with NAME.
348 This adds or updates a named color to `w32-color-map', making it
349 available for use. The original entry's RGB ref is returned, or nil
350 if the entry is new. */)
351 (Lisp_Object red
, Lisp_Object green
, Lisp_Object blue
, Lisp_Object name
)
354 Lisp_Object oldrgb
= Qnil
;
358 CHECK_NUMBER (green
);
362 XSETINT (rgb
, RGB (XUINT (red
), XUINT (green
), XUINT (blue
)));
366 /* replace existing entry in w32-color-map or add new entry. */
367 entry
= Fassoc (name
, Vw32_color_map
);
370 entry
= Fcons (name
, rgb
);
371 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
375 oldrgb
= Fcdr (entry
);
376 Fsetcdr (entry
, rgb
);
384 /* The default colors for the w32 color map */
385 typedef struct colormap_t
391 colormap_t w32_color_map
[] =
393 {"snow" , PALETTERGB (255,250,250)},
394 {"ghost white" , PALETTERGB (248,248,255)},
395 {"GhostWhite" , PALETTERGB (248,248,255)},
396 {"white smoke" , PALETTERGB (245,245,245)},
397 {"WhiteSmoke" , PALETTERGB (245,245,245)},
398 {"gainsboro" , PALETTERGB (220,220,220)},
399 {"floral white" , PALETTERGB (255,250,240)},
400 {"FloralWhite" , PALETTERGB (255,250,240)},
401 {"old lace" , PALETTERGB (253,245,230)},
402 {"OldLace" , PALETTERGB (253,245,230)},
403 {"linen" , PALETTERGB (250,240,230)},
404 {"antique white" , PALETTERGB (250,235,215)},
405 {"AntiqueWhite" , PALETTERGB (250,235,215)},
406 {"papaya whip" , PALETTERGB (255,239,213)},
407 {"PapayaWhip" , PALETTERGB (255,239,213)},
408 {"blanched almond" , PALETTERGB (255,235,205)},
409 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
410 {"bisque" , PALETTERGB (255,228,196)},
411 {"peach puff" , PALETTERGB (255,218,185)},
412 {"PeachPuff" , PALETTERGB (255,218,185)},
413 {"navajo white" , PALETTERGB (255,222,173)},
414 {"NavajoWhite" , PALETTERGB (255,222,173)},
415 {"moccasin" , PALETTERGB (255,228,181)},
416 {"cornsilk" , PALETTERGB (255,248,220)},
417 {"ivory" , PALETTERGB (255,255,240)},
418 {"lemon chiffon" , PALETTERGB (255,250,205)},
419 {"LemonChiffon" , PALETTERGB (255,250,205)},
420 {"seashell" , PALETTERGB (255,245,238)},
421 {"honeydew" , PALETTERGB (240,255,240)},
422 {"mint cream" , PALETTERGB (245,255,250)},
423 {"MintCream" , PALETTERGB (245,255,250)},
424 {"azure" , PALETTERGB (240,255,255)},
425 {"alice blue" , PALETTERGB (240,248,255)},
426 {"AliceBlue" , PALETTERGB (240,248,255)},
427 {"lavender" , PALETTERGB (230,230,250)},
428 {"lavender blush" , PALETTERGB (255,240,245)},
429 {"LavenderBlush" , PALETTERGB (255,240,245)},
430 {"misty rose" , PALETTERGB (255,228,225)},
431 {"MistyRose" , PALETTERGB (255,228,225)},
432 {"white" , PALETTERGB (255,255,255)},
433 {"black" , PALETTERGB ( 0, 0, 0)},
434 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
435 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
436 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
437 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
438 {"dim gray" , PALETTERGB (105,105,105)},
439 {"DimGray" , PALETTERGB (105,105,105)},
440 {"dim grey" , PALETTERGB (105,105,105)},
441 {"DimGrey" , PALETTERGB (105,105,105)},
442 {"slate gray" , PALETTERGB (112,128,144)},
443 {"SlateGray" , PALETTERGB (112,128,144)},
444 {"slate grey" , PALETTERGB (112,128,144)},
445 {"SlateGrey" , PALETTERGB (112,128,144)},
446 {"light slate gray" , PALETTERGB (119,136,153)},
447 {"LightSlateGray" , PALETTERGB (119,136,153)},
448 {"light slate grey" , PALETTERGB (119,136,153)},
449 {"LightSlateGrey" , PALETTERGB (119,136,153)},
450 {"gray" , PALETTERGB (190,190,190)},
451 {"grey" , PALETTERGB (190,190,190)},
452 {"light grey" , PALETTERGB (211,211,211)},
453 {"LightGrey" , PALETTERGB (211,211,211)},
454 {"light gray" , PALETTERGB (211,211,211)},
455 {"LightGray" , PALETTERGB (211,211,211)},
456 {"midnight blue" , PALETTERGB ( 25, 25,112)},
457 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
458 {"navy" , PALETTERGB ( 0, 0,128)},
459 {"navy blue" , PALETTERGB ( 0, 0,128)},
460 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
461 {"cornflower blue" , PALETTERGB (100,149,237)},
462 {"CornflowerBlue" , PALETTERGB (100,149,237)},
463 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
464 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
465 {"slate blue" , PALETTERGB (106, 90,205)},
466 {"SlateBlue" , PALETTERGB (106, 90,205)},
467 {"medium slate blue" , PALETTERGB (123,104,238)},
468 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
469 {"light slate blue" , PALETTERGB (132,112,255)},
470 {"LightSlateBlue" , PALETTERGB (132,112,255)},
471 {"medium blue" , PALETTERGB ( 0, 0,205)},
472 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
473 {"royal blue" , PALETTERGB ( 65,105,225)},
474 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
475 {"blue" , PALETTERGB ( 0, 0,255)},
476 {"dodger blue" , PALETTERGB ( 30,144,255)},
477 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
478 {"deep sky blue" , PALETTERGB ( 0,191,255)},
479 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
480 {"sky blue" , PALETTERGB (135,206,235)},
481 {"SkyBlue" , PALETTERGB (135,206,235)},
482 {"light sky blue" , PALETTERGB (135,206,250)},
483 {"LightSkyBlue" , PALETTERGB (135,206,250)},
484 {"steel blue" , PALETTERGB ( 70,130,180)},
485 {"SteelBlue" , PALETTERGB ( 70,130,180)},
486 {"light steel blue" , PALETTERGB (176,196,222)},
487 {"LightSteelBlue" , PALETTERGB (176,196,222)},
488 {"light blue" , PALETTERGB (173,216,230)},
489 {"LightBlue" , PALETTERGB (173,216,230)},
490 {"powder blue" , PALETTERGB (176,224,230)},
491 {"PowderBlue" , PALETTERGB (176,224,230)},
492 {"pale turquoise" , PALETTERGB (175,238,238)},
493 {"PaleTurquoise" , PALETTERGB (175,238,238)},
494 {"dark turquoise" , PALETTERGB ( 0,206,209)},
495 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
496 {"medium turquoise" , PALETTERGB ( 72,209,204)},
497 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
498 {"turquoise" , PALETTERGB ( 64,224,208)},
499 {"cyan" , PALETTERGB ( 0,255,255)},
500 {"light cyan" , PALETTERGB (224,255,255)},
501 {"LightCyan" , PALETTERGB (224,255,255)},
502 {"cadet blue" , PALETTERGB ( 95,158,160)},
503 {"CadetBlue" , PALETTERGB ( 95,158,160)},
504 {"medium aquamarine" , PALETTERGB (102,205,170)},
505 {"MediumAquamarine" , PALETTERGB (102,205,170)},
506 {"aquamarine" , PALETTERGB (127,255,212)},
507 {"dark green" , PALETTERGB ( 0,100, 0)},
508 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
509 {"dark olive green" , PALETTERGB ( 85,107, 47)},
510 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
511 {"dark sea green" , PALETTERGB (143,188,143)},
512 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
513 {"sea green" , PALETTERGB ( 46,139, 87)},
514 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
515 {"medium sea green" , PALETTERGB ( 60,179,113)},
516 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
517 {"light sea green" , PALETTERGB ( 32,178,170)},
518 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
519 {"pale green" , PALETTERGB (152,251,152)},
520 {"PaleGreen" , PALETTERGB (152,251,152)},
521 {"spring green" , PALETTERGB ( 0,255,127)},
522 {"SpringGreen" , PALETTERGB ( 0,255,127)},
523 {"lawn green" , PALETTERGB (124,252, 0)},
524 {"LawnGreen" , PALETTERGB (124,252, 0)},
525 {"green" , PALETTERGB ( 0,255, 0)},
526 {"chartreuse" , PALETTERGB (127,255, 0)},
527 {"medium spring green" , PALETTERGB ( 0,250,154)},
528 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
529 {"green yellow" , PALETTERGB (173,255, 47)},
530 {"GreenYellow" , PALETTERGB (173,255, 47)},
531 {"lime green" , PALETTERGB ( 50,205, 50)},
532 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
533 {"yellow green" , PALETTERGB (154,205, 50)},
534 {"YellowGreen" , PALETTERGB (154,205, 50)},
535 {"forest green" , PALETTERGB ( 34,139, 34)},
536 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
537 {"olive drab" , PALETTERGB (107,142, 35)},
538 {"OliveDrab" , PALETTERGB (107,142, 35)},
539 {"dark khaki" , PALETTERGB (189,183,107)},
540 {"DarkKhaki" , PALETTERGB (189,183,107)},
541 {"khaki" , PALETTERGB (240,230,140)},
542 {"pale goldenrod" , PALETTERGB (238,232,170)},
543 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
544 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
545 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
546 {"light yellow" , PALETTERGB (255,255,224)},
547 {"LightYellow" , PALETTERGB (255,255,224)},
548 {"yellow" , PALETTERGB (255,255, 0)},
549 {"gold" , PALETTERGB (255,215, 0)},
550 {"light goldenrod" , PALETTERGB (238,221,130)},
551 {"LightGoldenrod" , PALETTERGB (238,221,130)},
552 {"goldenrod" , PALETTERGB (218,165, 32)},
553 {"dark goldenrod" , PALETTERGB (184,134, 11)},
554 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
555 {"rosy brown" , PALETTERGB (188,143,143)},
556 {"RosyBrown" , PALETTERGB (188,143,143)},
557 {"indian red" , PALETTERGB (205, 92, 92)},
558 {"IndianRed" , PALETTERGB (205, 92, 92)},
559 {"saddle brown" , PALETTERGB (139, 69, 19)},
560 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
561 {"sienna" , PALETTERGB (160, 82, 45)},
562 {"peru" , PALETTERGB (205,133, 63)},
563 {"burlywood" , PALETTERGB (222,184,135)},
564 {"beige" , PALETTERGB (245,245,220)},
565 {"wheat" , PALETTERGB (245,222,179)},
566 {"sandy brown" , PALETTERGB (244,164, 96)},
567 {"SandyBrown" , PALETTERGB (244,164, 96)},
568 {"tan" , PALETTERGB (210,180,140)},
569 {"chocolate" , PALETTERGB (210,105, 30)},
570 {"firebrick" , PALETTERGB (178,34, 34)},
571 {"brown" , PALETTERGB (165,42, 42)},
572 {"dark salmon" , PALETTERGB (233,150,122)},
573 {"DarkSalmon" , PALETTERGB (233,150,122)},
574 {"salmon" , PALETTERGB (250,128,114)},
575 {"light salmon" , PALETTERGB (255,160,122)},
576 {"LightSalmon" , PALETTERGB (255,160,122)},
577 {"orange" , PALETTERGB (255,165, 0)},
578 {"dark orange" , PALETTERGB (255,140, 0)},
579 {"DarkOrange" , PALETTERGB (255,140, 0)},
580 {"coral" , PALETTERGB (255,127, 80)},
581 {"light coral" , PALETTERGB (240,128,128)},
582 {"LightCoral" , PALETTERGB (240,128,128)},
583 {"tomato" , PALETTERGB (255, 99, 71)},
584 {"orange red" , PALETTERGB (255, 69, 0)},
585 {"OrangeRed" , PALETTERGB (255, 69, 0)},
586 {"red" , PALETTERGB (255, 0, 0)},
587 {"hot pink" , PALETTERGB (255,105,180)},
588 {"HotPink" , PALETTERGB (255,105,180)},
589 {"deep pink" , PALETTERGB (255, 20,147)},
590 {"DeepPink" , PALETTERGB (255, 20,147)},
591 {"pink" , PALETTERGB (255,192,203)},
592 {"light pink" , PALETTERGB (255,182,193)},
593 {"LightPink" , PALETTERGB (255,182,193)},
594 {"pale violet red" , PALETTERGB (219,112,147)},
595 {"PaleVioletRed" , PALETTERGB (219,112,147)},
596 {"maroon" , PALETTERGB (176, 48, 96)},
597 {"medium violet red" , PALETTERGB (199, 21,133)},
598 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
599 {"violet red" , PALETTERGB (208, 32,144)},
600 {"VioletRed" , PALETTERGB (208, 32,144)},
601 {"magenta" , PALETTERGB (255, 0,255)},
602 {"violet" , PALETTERGB (238,130,238)},
603 {"plum" , PALETTERGB (221,160,221)},
604 {"orchid" , PALETTERGB (218,112,214)},
605 {"medium orchid" , PALETTERGB (186, 85,211)},
606 {"MediumOrchid" , PALETTERGB (186, 85,211)},
607 {"dark orchid" , PALETTERGB (153, 50,204)},
608 {"DarkOrchid" , PALETTERGB (153, 50,204)},
609 {"dark violet" , PALETTERGB (148, 0,211)},
610 {"DarkViolet" , PALETTERGB (148, 0,211)},
611 {"blue violet" , PALETTERGB (138, 43,226)},
612 {"BlueViolet" , PALETTERGB (138, 43,226)},
613 {"purple" , PALETTERGB (160, 32,240)},
614 {"medium purple" , PALETTERGB (147,112,219)},
615 {"MediumPurple" , PALETTERGB (147,112,219)},
616 {"thistle" , PALETTERGB (216,191,216)},
617 {"gray0" , PALETTERGB ( 0, 0, 0)},
618 {"grey0" , PALETTERGB ( 0, 0, 0)},
619 {"dark grey" , PALETTERGB (169,169,169)},
620 {"DarkGrey" , PALETTERGB (169,169,169)},
621 {"dark gray" , PALETTERGB (169,169,169)},
622 {"DarkGray" , PALETTERGB (169,169,169)},
623 {"dark blue" , PALETTERGB ( 0, 0,139)},
624 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
625 {"dark cyan" , PALETTERGB ( 0,139,139)},
626 {"DarkCyan" , PALETTERGB ( 0,139,139)},
627 {"dark magenta" , PALETTERGB (139, 0,139)},
628 {"DarkMagenta" , PALETTERGB (139, 0,139)},
629 {"dark red" , PALETTERGB (139, 0, 0)},
630 {"DarkRed" , PALETTERGB (139, 0, 0)},
631 {"light green" , PALETTERGB (144,238,144)},
632 {"LightGreen" , PALETTERGB (144,238,144)},
636 w32_default_color_map (void)
639 colormap_t
*pc
= w32_color_map
;
646 for (i
= 0; i
< sizeof (w32_color_map
) / sizeof (w32_color_map
[0]);
648 cmap
= Fcons (Fcons (build_string (pc
->name
),
649 make_number (pc
->colorref
)),
657 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
658 0, 0, 0, doc
: /* Return the default color map. */)
661 return w32_default_color_map ();
665 w32_color_map_lookup (char *colorname
)
667 Lisp_Object tail
, ret
= Qnil
;
671 for (tail
= Vw32_color_map
; CONSP (tail
); tail
= XCDR (tail
))
673 register Lisp_Object elt
, tem
;
676 if (!CONSP (elt
)) continue;
680 if (lstrcmpi (SDATA (tem
), colorname
) == 0)
696 add_system_logical_colors_to_map (Lisp_Object
*system_colors
)
700 /* Other registry operations are done with input blocked. */
703 /* Look for "Control Panel/Colors" under User and Machine registry
705 if (RegOpenKeyEx (HKEY_CURRENT_USER
, "Control Panel\\Colors", 0,
706 KEY_READ
, &colors_key
) == ERROR_SUCCESS
707 || RegOpenKeyEx (HKEY_LOCAL_MACHINE
, "Control Panel\\Colors", 0,
708 KEY_READ
, &colors_key
) == ERROR_SUCCESS
)
711 char color_buffer
[64];
712 char full_name_buffer
[MAX_PATH
+ SYSTEM_COLOR_PREFIX_LEN
];
714 DWORD name_size
, color_size
;
715 char *name_buffer
= full_name_buffer
+ SYSTEM_COLOR_PREFIX_LEN
;
717 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
718 color_size
= sizeof (color_buffer
);
720 strcpy (full_name_buffer
, SYSTEM_COLOR_PREFIX
);
722 while (RegEnumValueA (colors_key
, index
, name_buffer
, &name_size
,
723 NULL
, NULL
, color_buffer
, &color_size
)
727 if (sscanf (color_buffer
, " %u %u %u", &r
, &g
, &b
) == 3)
728 *system_colors
= Fcons (Fcons (build_string (full_name_buffer
),
729 make_number (RGB (r
, g
, b
))),
732 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
733 color_size
= sizeof (color_buffer
);
736 RegCloseKey (colors_key
);
744 x_to_w32_color (char * colorname
)
746 register Lisp_Object ret
= Qnil
;
750 if (colorname
[0] == '#')
752 /* Could be an old-style RGB Device specification. */
755 color
= colorname
+ 1;
757 size
= strlen (color
);
758 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
766 for (i
= 0; i
< 3; i
++)
772 /* The check for 'x' in the following conditional takes into
773 account the fact that strtol allows a "0x" in front of
774 our numbers, and we don't. */
775 if (!isxdigit (color
[0]) || color
[1] == 'x')
779 value
= strtoul (color
, &end
, 16);
781 if (errno
== ERANGE
|| end
- color
!= size
)
786 value
= value
* 0x10;
797 colorval
|= (value
<< pos
);
802 XSETINT (ret
, colorval
);
809 else if (strnicmp (colorname
, "rgb:", 4) == 0)
817 color
= colorname
+ 4;
818 for (i
= 0; i
< 3; i
++)
823 /* The check for 'x' in the following conditional takes into
824 account the fact that strtol allows a "0x" in front of
825 our numbers, and we don't. */
826 if (!isxdigit (color
[0]) || color
[1] == 'x')
828 value
= strtoul (color
, &end
, 16);
834 value
= value
* 0x10 + value
;
847 if (value
== ULONG_MAX
)
849 colorval
|= (value
<< pos
);
856 XSETINT (ret
, colorval
);
864 else if (strnicmp (colorname
, "rgbi:", 5) == 0)
866 /* This is an RGB Intensity specification. */
873 color
= colorname
+ 5;
874 for (i
= 0; i
< 3; i
++)
880 value
= strtod (color
, &end
);
883 if (value
< 0.0 || value
> 1.0)
885 val
= (UINT
)(0x100 * value
);
886 /* We used 0x100 instead of 0xFF to give a continuous
887 range between 0.0 and 1.0 inclusive. The next statement
888 fixes the 1.0 case. */
891 colorval
|= (val
<< pos
);
898 XSETINT (ret
, colorval
);
906 /* I am not going to attempt to handle any of the CIE color schemes
907 or TekHVC, since I don't know the algorithms for conversion to
910 /* If we fail to lookup the color name in w32_color_map, then check the
911 colorname to see if it can be crudely approximated: If the X color
912 ends in a number (e.g., "darkseagreen2"), strip the number and
913 return the result of looking up the base color name. */
914 ret
= w32_color_map_lookup (colorname
);
917 int len
= strlen (colorname
);
919 if (isdigit (colorname
[len
- 1]))
921 char *ptr
, *approx
= alloca (len
+ 1);
923 strcpy (approx
, colorname
);
924 ptr
= &approx
[len
- 1];
925 while (ptr
> approx
&& isdigit (*ptr
))
928 ret
= w32_color_map_lookup (approx
);
937 w32_regenerate_palette (FRAME_PTR f
)
939 struct w32_palette_entry
* list
;
940 LOGPALETTE
* log_palette
;
941 HPALETTE new_palette
;
944 /* don't bother trying to create palette if not supported */
945 if (! FRAME_W32_DISPLAY_INFO (f
)->has_palette
)
948 log_palette
= (LOGPALETTE
*)
949 alloca (sizeof (LOGPALETTE
) +
950 FRAME_W32_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
951 log_palette
->palVersion
= 0x300;
952 log_palette
->palNumEntries
= FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
954 list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
956 i
< FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
957 i
++, list
= list
->next
)
958 log_palette
->palPalEntry
[i
] = list
->entry
;
960 new_palette
= CreatePalette (log_palette
);
964 if (FRAME_W32_DISPLAY_INFO (f
)->palette
)
965 DeleteObject (FRAME_W32_DISPLAY_INFO (f
)->palette
);
966 FRAME_W32_DISPLAY_INFO (f
)->palette
= new_palette
;
968 /* Realize display palette and garbage all frames. */
969 release_frame_dc (f
, get_frame_dc (f
));
974 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
975 #define SET_W32_COLOR(pe, color) \
978 pe.peRed = GetRValue (color); \
979 pe.peGreen = GetGValue (color); \
980 pe.peBlue = GetBValue (color); \
985 /* Keep these around in case we ever want to track color usage. */
987 w32_map_color (FRAME_PTR f
, COLORREF color
)
989 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
991 if (NILP (Vw32_enable_palette
))
994 /* check if color is already mapped */
997 if (W32_COLOR (list
->entry
) == color
)
1005 /* not already mapped, so add to list and recreate Windows palette */
1006 list
= xmalloc (sizeof (struct w32_palette_entry
));
1007 SET_W32_COLOR (list
->entry
, color
);
1009 list
->next
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1010 FRAME_W32_DISPLAY_INFO (f
)->color_list
= list
;
1011 FRAME_W32_DISPLAY_INFO (f
)->num_colors
++;
1013 /* set flag that palette must be regenerated */
1014 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1018 w32_unmap_color (FRAME_PTR f
, COLORREF color
)
1020 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1021 struct w32_palette_entry
**prev
= &FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1023 if (NILP (Vw32_enable_palette
))
1026 /* check if color is already mapped */
1029 if (W32_COLOR (list
->entry
) == color
)
1031 if (--list
->refcount
== 0)
1035 FRAME_W32_DISPLAY_INFO (f
)->num_colors
--;
1045 /* set flag that palette must be regenerated */
1046 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1051 /* Gamma-correct COLOR on frame F. */
1054 gamma_correct (struct frame
*f
, COLORREF
*color
)
1058 *color
= PALETTERGB (
1059 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1060 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1061 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1066 /* Decide if color named COLOR is valid for the display associated with
1067 the selected frame; if so, return the rgb values in COLOR_DEF.
1068 If ALLOC is nonzero, allocate a new colormap cell. */
1071 w32_defined_color (FRAME_PTR f
, char *color
, XColor
*color_def
, int alloc
)
1073 register Lisp_Object tem
;
1074 COLORREF w32_color_ref
;
1076 tem
= x_to_w32_color (color
);
1082 /* Apply gamma correction. */
1083 w32_color_ref
= XUINT (tem
);
1084 gamma_correct (f
, &w32_color_ref
);
1085 XSETINT (tem
, w32_color_ref
);
1088 /* Map this color to the palette if it is enabled. */
1089 if (!NILP (Vw32_enable_palette
))
1091 struct w32_palette_entry
* entry
=
1092 one_w32_display_info
.color_list
;
1093 struct w32_palette_entry
** prev
=
1094 &one_w32_display_info
.color_list
;
1096 /* check if color is already mapped */
1099 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1101 prev
= &entry
->next
;
1102 entry
= entry
->next
;
1105 if (entry
== NULL
&& alloc
)
1107 /* not already mapped, so add to list */
1108 entry
= xmalloc (sizeof (struct w32_palette_entry
));
1109 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1112 one_w32_display_info
.num_colors
++;
1114 /* set flag that palette must be regenerated */
1115 one_w32_display_info
.regen_palette
= TRUE
;
1118 /* Ensure COLORREF value is snapped to nearest color in (default)
1119 palette by simulating the PALETTERGB macro. This works whether
1120 or not the display device has a palette. */
1121 w32_color_ref
= XUINT (tem
) | 0x2000000;
1123 color_def
->pixel
= w32_color_ref
;
1124 color_def
->red
= GetRValue (w32_color_ref
) * 256;
1125 color_def
->green
= GetGValue (w32_color_ref
) * 256;
1126 color_def
->blue
= GetBValue (w32_color_ref
) * 256;
1136 /* Given a string ARG naming a color, compute a pixel value from it
1137 suitable for screen F.
1138 If F is not a color screen, return DEF (default) regardless of what
1142 x_decode_color (FRAME_PTR f
, Lisp_Object arg
, int def
)
1148 if (strcmp (SDATA (arg
), "black") == 0)
1149 return BLACK_PIX_DEFAULT (f
);
1150 else if (strcmp (SDATA (arg
), "white") == 0)
1151 return WHITE_PIX_DEFAULT (f
);
1153 if ((FRAME_W32_DISPLAY_INFO (f
)->n_planes
* FRAME_W32_DISPLAY_INFO (f
)->n_cbits
) == 1)
1156 /* w32_defined_color is responsible for coping with failures
1157 by looking for a near-miss. */
1158 if (w32_defined_color (f
, SDATA (arg
), &cdef
, 1))
1161 /* defined_color failed; return an ultimate default. */
1167 /* Functions called only from `x_set_frame_param'
1168 to set individual parameters.
1170 If FRAME_W32_WINDOW (f) is 0,
1171 the frame is being created and its window does not exist yet.
1172 In that case, just record the parameter's new value
1173 in the standard place; do not attempt to change the window. */
1176 x_set_foreground_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1178 struct w32_output
*x
= f
->output_data
.w32
;
1179 PIX_TYPE fg
, old_fg
;
1181 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1182 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
1183 FRAME_FOREGROUND_PIXEL (f
) = fg
;
1185 if (FRAME_W32_WINDOW (f
) != 0)
1187 if (x
->cursor_pixel
== old_fg
)
1189 x
->cursor_pixel
= fg
;
1190 x
->cursor_gc
->background
= fg
;
1193 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
1194 if (FRAME_VISIBLE_P (f
))
1200 x_set_background_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1202 FRAME_BACKGROUND_PIXEL (f
)
1203 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
1205 if (FRAME_W32_WINDOW (f
) != 0)
1207 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
1208 FRAME_BACKGROUND_PIXEL (f
));
1210 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
1212 if (FRAME_VISIBLE_P (f
))
1218 x_set_mouse_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1220 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
1224 if (!EQ (Qnil
, arg
))
1225 f
->output_data
.w32
->mouse_pixel
1226 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1227 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
1229 /* Don't let pointers be invisible. */
1230 if (mask_color
== f
->output_data
.w32
->mouse_pixel
1231 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
1232 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
1234 #if 0 /* TODO : Mouse cursor customization. */
1237 /* It's not okay to crash if the user selects a screwy cursor. */
1238 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
1240 if (!EQ (Qnil
, Vx_pointer_shape
))
1242 CHECK_NUMBER (Vx_pointer_shape
);
1243 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
1246 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1247 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
1249 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
1251 CHECK_NUMBER (Vx_nontext_pointer_shape
);
1252 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1253 XINT (Vx_nontext_pointer_shape
));
1256 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
1257 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1259 if (!EQ (Qnil
, Vx_hourglass_pointer_shape
))
1261 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
1262 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1263 XINT (Vx_hourglass_pointer_shape
));
1266 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
1267 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
1269 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1270 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
1272 CHECK_NUMBER (Vx_mode_pointer_shape
);
1273 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1274 XINT (Vx_mode_pointer_shape
));
1277 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1278 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
1280 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
1282 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
1284 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1285 XINT (Vx_sensitive_text_pointer_shape
));
1288 hand_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
1290 if (!NILP (Vx_window_horizontal_drag_shape
))
1292 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
1293 horizontal_drag_cursor
1294 = XCreateFontCursor (FRAME_X_DISPLAY (f
),
1295 XINT (Vx_window_horizontal_drag_shape
));
1298 horizontal_drag_cursor
1299 = XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_sb_h_double_arrow
);
1301 /* Check and report errors with the above calls. */
1302 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
1303 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
1306 XColor fore_color
, back_color
;
1308 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
1309 back_color
.pixel
= mask_color
;
1310 XQueryColor (FRAME_W32_DISPLAY (f
),
1311 DefaultColormap (FRAME_W32_DISPLAY (f
),
1312 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1314 XQueryColor (FRAME_W32_DISPLAY (f
),
1315 DefaultColormap (FRAME_W32_DISPLAY (f
),
1316 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1318 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
1319 &fore_color
, &back_color
);
1320 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
1321 &fore_color
, &back_color
);
1322 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
1323 &fore_color
, &back_color
);
1324 XRecolorCursor (FRAME_W32_DISPLAY (f
), hand_cursor
,
1325 &fore_color
, &back_color
);
1326 XRecolorCursor (FRAME_W32_DISPLAY (f
), hourglass_cursor
,
1327 &fore_color
, &back_color
);
1330 if (FRAME_W32_WINDOW (f
) != 0)
1331 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
1333 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
1334 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
1335 f
->output_data
.w32
->text_cursor
= cursor
;
1337 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
1338 && f
->output_data
.w32
->nontext_cursor
!= 0)
1339 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
1340 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
1342 if (hourglass_cursor
!= f
->output_data
.w32
->hourglass_cursor
1343 && f
->output_data
.w32
->hourglass_cursor
!= 0)
1344 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hourglass_cursor
);
1345 f
->output_data
.w32
->hourglass_cursor
= hourglass_cursor
;
1347 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
1348 && f
->output_data
.w32
->modeline_cursor
!= 0)
1349 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
1350 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
1352 if (hand_cursor
!= f
->output_data
.w32
->hand_cursor
1353 && f
->output_data
.w32
->hand_cursor
!= 0)
1354 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hand_cursor
);
1355 f
->output_data
.w32
->hand_cursor
= hand_cursor
;
1357 XFlush (FRAME_W32_DISPLAY (f
));
1360 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1365 x_set_cursor_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1367 unsigned long fore_pixel
, pixel
;
1369 if (!NILP (Vx_cursor_fore_pixel
))
1370 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1371 WHITE_PIX_DEFAULT (f
));
1373 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1375 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1377 /* Make sure that the cursor color differs from the background color. */
1378 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
1380 pixel
= f
->output_data
.w32
->mouse_pixel
;
1381 if (pixel
== fore_pixel
)
1382 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1385 f
->output_data
.w32
->cursor_foreground_pixel
= fore_pixel
;
1386 f
->output_data
.w32
->cursor_pixel
= pixel
;
1388 if (FRAME_W32_WINDOW (f
) != 0)
1391 /* Update frame's cursor_gc. */
1392 f
->output_data
.w32
->cursor_gc
->foreground
= fore_pixel
;
1393 f
->output_data
.w32
->cursor_gc
->background
= pixel
;
1397 if (FRAME_VISIBLE_P (f
))
1399 x_update_cursor (f
, 0);
1400 x_update_cursor (f
, 1);
1404 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1407 /* Set the border-color of frame F to pixel value PIX.
1408 Note that this does not fully take effect if done before
1412 x_set_border_pixel (struct frame
*f
, int pix
)
1415 f
->output_data
.w32
->border_pixel
= pix
;
1417 if (FRAME_W32_WINDOW (f
) != 0 && f
->border_width
> 0)
1419 if (FRAME_VISIBLE_P (f
))
1424 /* Set the border-color of frame F to value described by ARG.
1425 ARG can be a string naming a color.
1426 The border-color is used for the border that is drawn by the server.
1427 Note that this does not fully take effect if done before
1428 F has a window; it must be redone when the window is created. */
1431 x_set_border_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1436 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1437 x_set_border_pixel (f
, pix
);
1438 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1443 x_set_cursor_type (FRAME_PTR f
, Lisp_Object arg
, Lisp_Object oldval
)
1445 set_frame_cursor_types (f
, arg
);
1447 /* Make sure the cursor gets redrawn. */
1448 cursor_type_changed
= 1;
1452 x_set_icon_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1456 if (NILP (arg
) && NILP (oldval
))
1459 if (STRINGP (arg
) && STRINGP (oldval
)
1460 && EQ (Fstring_equal (oldval
, arg
), Qt
))
1463 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
1468 result
= x_bitmap_icon (f
, arg
);
1472 error ("No icon window available");
1479 x_set_icon_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1483 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1486 else if (!NILP (arg
) || NILP (oldval
))
1489 fset_icon_name (f
, arg
);
1492 if (f
->output_data
.w32
->icon_bitmap
!= 0)
1497 result
= x_text_icon (f
,
1498 SSDATA ((!NILP (f
->icon_name
)
1507 error ("No icon window available");
1510 /* If the window was unmapped (and its icon was mapped),
1511 the new icon is not mapped, so map the window in its stead. */
1512 if (FRAME_VISIBLE_P (f
))
1514 #ifdef USE_X_TOOLKIT
1515 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
1517 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
1520 XFlush (FRAME_W32_DISPLAY (f
));
1527 x_set_menu_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1531 /* Right now, menu bars don't work properly in minibuf-only frames;
1532 most of the commands try to apply themselves to the minibuffer
1533 frame itself, and get an error because you can't switch buffers
1534 in or split the minibuffer window. */
1535 if (FRAME_MINIBUF_ONLY_P (f
))
1538 if (INTEGERP (value
))
1539 nlines
= XINT (value
);
1543 FRAME_MENU_BAR_LINES (f
) = 0;
1545 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1548 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1549 free_frame_menubar (f
);
1550 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1552 /* Adjust the frame size so that the client (text) dimensions
1553 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
1555 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
1556 do_pending_window_change (0);
1562 /* Set the number of lines used for the tool bar of frame F to VALUE.
1563 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1564 is the old number of tool bar lines. This function changes the
1565 height of all windows on frame F to match the new tool bar height.
1566 The frame's height doesn't change. */
1569 x_set_tool_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1571 int delta
, nlines
, root_height
;
1572 Lisp_Object root_window
;
1574 /* Treat tool bars like menu bars. */
1575 if (FRAME_MINIBUF_ONLY_P (f
))
1578 /* Use VALUE only if an integer >= 0. */
1579 if (INTEGERP (value
) && XINT (value
) >= 0)
1580 nlines
= XFASTINT (value
);
1584 /* Make sure we redisplay all windows in this frame. */
1585 ++windows_or_buffers_changed
;
1587 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
1589 /* Don't resize the tool-bar to more than we have room for. */
1590 root_window
= FRAME_ROOT_WINDOW (f
);
1591 root_height
= WINDOW_TOTAL_LINES (XWINDOW (root_window
));
1592 if (root_height
- delta
< 1)
1594 delta
= root_height
- 1;
1595 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
1598 FRAME_TOOL_BAR_LINES (f
) = nlines
;
1599 resize_frame_windows (f
, FRAME_LINES (f
), 0);
1602 /* We also have to make sure that the internal border at the top of
1603 the frame, below the menu bar or tool bar, is redrawn when the
1604 tool bar disappears. This is so because the internal border is
1605 below the tool bar if one is displayed, but is below the menu bar
1606 if there isn't a tool bar. The tool bar draws into the area
1607 below the menu bar. */
1608 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
1611 clear_current_matrices (f
);
1614 /* If the tool bar gets smaller, the internal border below it
1615 has to be cleared. It was formerly part of the display
1616 of the larger tool bar, and updating windows won't clear it. */
1619 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1620 int width
= FRAME_PIXEL_WIDTH (f
);
1621 int y
= nlines
* FRAME_LINE_HEIGHT (f
);
1625 HDC hdc
= get_frame_dc (f
);
1626 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
1627 release_frame_dc (f
, hdc
);
1631 if (WINDOWP (f
->tool_bar_window
))
1632 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1635 run_window_configuration_change_hook (f
);
1640 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1643 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1644 name; if NAME is a string, set F's name to NAME and set
1645 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1647 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1648 suggesting a new name, which lisp code should override; if
1649 F->explicit_name is set, ignore the new name; otherwise, set it. */
1652 x_set_name (struct frame
*f
, Lisp_Object name
, int explicit)
1654 /* Make sure that requests from lisp code override requests from
1655 Emacs redisplay code. */
1658 /* If we're switching from explicit to implicit, we had better
1659 update the mode lines and thereby update the title. */
1660 if (f
->explicit_name
&& NILP (name
))
1661 update_mode_lines
= 1;
1663 f
->explicit_name
= ! NILP (name
);
1665 else if (f
->explicit_name
)
1668 /* If NAME is nil, set the name to the w32_id_name. */
1671 /* Check for no change needed in this very common case
1672 before we do any consing. */
1673 if (!strcmp (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
,
1676 name
= build_string (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
);
1679 CHECK_STRING (name
);
1681 /* Don't change the name if it's already NAME. */
1682 if (! NILP (Fstring_equal (name
, f
->name
)))
1685 fset_name (f
, name
);
1687 /* For setting the frame title, the title parameter should override
1688 the name parameter. */
1689 if (! NILP (f
->title
))
1692 if (FRAME_W32_WINDOW (f
))
1694 if (STRING_MULTIBYTE (name
))
1695 name
= ENCODE_SYSTEM (name
);
1698 SetWindowText (FRAME_W32_WINDOW (f
), SDATA (name
));
1703 /* This function should be called when the user's lisp code has
1704 specified a name for the frame; the name will override any set by the
1707 x_explicitly_set_name (FRAME_PTR f
, Lisp_Object arg
, Lisp_Object oldval
)
1709 x_set_name (f
, arg
, 1);
1712 /* This function should be called by Emacs redisplay code to set the
1713 name; names set this way will never override names set by the user's
1716 x_implicitly_set_name (FRAME_PTR f
, Lisp_Object arg
, Lisp_Object oldval
)
1718 x_set_name (f
, arg
, 0);
1721 /* Change the title of frame F to NAME.
1722 If NAME is nil, use the frame name as the title. */
1725 x_set_title (struct frame
*f
, Lisp_Object name
, Lisp_Object old_name
)
1727 /* Don't change the title if it's already NAME. */
1728 if (EQ (name
, f
->title
))
1731 update_mode_lines
= 1;
1733 fset_title (f
, name
);
1738 if (FRAME_W32_WINDOW (f
))
1740 if (STRING_MULTIBYTE (name
))
1741 name
= ENCODE_SYSTEM (name
);
1744 SetWindowText (FRAME_W32_WINDOW (f
), SDATA (name
));
1750 x_set_scroll_bar_default_width (struct frame
*f
)
1752 int wid
= FRAME_COLUMN_WIDTH (f
);
1754 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
1755 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) +
1760 /* Subroutines for creating a frame. */
1763 w32_load_cursor (LPCTSTR name
)
1765 /* Try first to load cursor from application resource. */
1766 Cursor cursor
= LoadImage ((HINSTANCE
) GetModuleHandle (NULL
),
1767 name
, IMAGE_CURSOR
, 0, 0,
1768 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
1771 /* Then try to load a shared predefined cursor. */
1772 cursor
= LoadImage (NULL
, name
, IMAGE_CURSOR
, 0, 0,
1773 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
1778 static LRESULT CALLBACK
w32_wnd_proc (HWND
, UINT
, WPARAM
, LPARAM
);
1780 #define INIT_WINDOW_CLASS(WC) \
1781 (WC).style = CS_HREDRAW | CS_VREDRAW; \
1782 (WC).lpfnWndProc = (WNDPROC) w32_wnd_proc; \
1783 (WC).cbClsExtra = 0; \
1784 (WC).cbWndExtra = WND_EXTRA_BYTES; \
1785 (WC).hInstance = hinst; \
1786 (WC).hIcon = LoadIcon (hinst, EMACS_CLASS); \
1787 (WC).hCursor = w32_load_cursor (IDC_ARROW); \
1788 (WC).hbrBackground = NULL; \
1789 (WC).lpszMenuName = NULL; \
1792 w32_init_class (HINSTANCE hinst
)
1795 if (w32_unicode_gui
)
1798 INIT_WINDOW_CLASS(uwc
);
1799 uwc
.lpszClassName
= L
"Emacs";
1801 return RegisterClassW (&uwc
);
1806 INIT_WINDOW_CLASS(wc
);
1807 wc
.lpszClassName
= EMACS_CLASS
;
1809 return RegisterClassA (&wc
);
1814 w32_createscrollbar (struct frame
*f
, struct scroll_bar
* bar
)
1816 return (CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
1817 /* Position and size of scroll bar. */
1818 XINT (bar
->left
) + VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
1820 XINT (bar
->width
) - VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
1822 FRAME_W32_WINDOW (f
),
1829 w32_createwindow (struct frame
*f
)
1833 Lisp_Object top
= Qunbound
;
1834 Lisp_Object left
= Qunbound
;
1835 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
1837 rect
.left
= rect
.top
= 0;
1838 rect
.right
= FRAME_PIXEL_WIDTH (f
);
1839 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
1841 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
1842 FRAME_EXTERNAL_MENU_BAR (f
));
1844 /* Do first time app init */
1848 w32_init_class (hinst
);
1851 if (f
->size_hint_flags
& USPosition
|| f
->size_hint_flags
& PPosition
)
1853 XSETINT (left
, f
->left_pos
);
1854 XSETINT (top
, f
->top_pos
);
1856 else if (EQ (left
, Qunbound
) && EQ (top
, Qunbound
))
1858 /* When called with RES_TYPE_NUMBER, w32_get_arg will return zero
1859 for anything that is not a number and is not Qunbound. */
1860 left
= x_get_arg (dpyinfo
, Qnil
, Qleft
, "left", "Left", RES_TYPE_NUMBER
);
1861 top
= x_get_arg (dpyinfo
, Qnil
, Qtop
, "top", "Top", RES_TYPE_NUMBER
);
1864 FRAME_W32_WINDOW (f
) = hwnd
1865 = CreateWindow (EMACS_CLASS
,
1867 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
1868 EQ (left
, Qunbound
) ? CW_USEDEFAULT
: XINT (left
),
1869 EQ (top
, Qunbound
) ? CW_USEDEFAULT
: XINT (top
),
1870 rect
.right
- rect
.left
,
1871 rect
.bottom
- rect
.top
,
1879 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
1880 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
1881 SetWindowLong (hwnd
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
1882 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->scroll_bar_actual_width
);
1883 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
1885 /* Enable drag-n-drop. */
1886 DragAcceptFiles (hwnd
, TRUE
);
1888 /* Do this to discard the default setting specified by our parent. */
1889 ShowWindow (hwnd
, SW_HIDE
);
1891 /* Update frame positions. */
1892 GetWindowRect (hwnd
, &rect
);
1893 f
->left_pos
= rect
.left
;
1894 f
->top_pos
= rect
.top
;
1899 my_post_msg (W32Msg
* wmsg
, HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1901 wmsg
->msg
.hwnd
= hwnd
;
1902 wmsg
->msg
.message
= msg
;
1903 wmsg
->msg
.wParam
= wParam
;
1904 wmsg
->msg
.lParam
= lParam
;
1905 wmsg
->msg
.time
= GetMessageTime ();
1910 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
1911 between left and right keys as advertised. We test for this
1912 support dynamically, and set a flag when the support is absent. If
1913 absent, we keep track of the left and right control and alt keys
1914 ourselves. This is particularly necessary on keyboards that rely
1915 upon the AltGr key, which is represented as having the left control
1916 and right alt keys pressed. For these keyboards, we need to know
1917 when the left alt key has been pressed in addition to the AltGr key
1918 so that we can properly support M-AltGr-key sequences (such as M-@
1919 on Swedish keyboards). */
1921 #define EMACS_LCONTROL 0
1922 #define EMACS_RCONTROL 1
1923 #define EMACS_LMENU 2
1924 #define EMACS_RMENU 3
1926 static int modifiers
[4];
1927 static int modifiers_recorded
;
1928 static int modifier_key_support_tested
;
1931 test_modifier_support (unsigned int wparam
)
1935 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
1937 if (wparam
== VK_CONTROL
)
1947 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
1948 modifiers_recorded
= 1;
1950 modifiers_recorded
= 0;
1951 modifier_key_support_tested
= 1;
1955 record_keydown (unsigned int wparam
, unsigned int lparam
)
1959 if (!modifier_key_support_tested
)
1960 test_modifier_support (wparam
);
1962 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
1965 if (wparam
== VK_CONTROL
)
1966 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
1968 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
1974 record_keyup (unsigned int wparam
, unsigned int lparam
)
1978 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
1981 if (wparam
== VK_CONTROL
)
1982 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
1984 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
1989 /* Emacs can lose focus while a modifier key has been pressed. When
1990 it regains focus, be conservative and clear all modifiers since
1991 we cannot reconstruct the left and right modifier state. */
1993 reset_modifiers (void)
1997 if (GetFocus () == NULL
)
1998 /* Emacs doesn't have keyboard focus. Do nothing. */
2001 ctrl
= GetAsyncKeyState (VK_CONTROL
);
2002 alt
= GetAsyncKeyState (VK_MENU
);
2004 if (!(ctrl
& 0x08000))
2005 /* Clear any recorded control modifier state. */
2006 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2008 if (!(alt
& 0x08000))
2009 /* Clear any recorded alt modifier state. */
2010 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2012 /* Update the state of all modifier keys, because modifiers used in
2013 hot-key combinations can get stuck on if Emacs loses focus as a
2014 result of a hot-key being pressed. */
2018 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
2020 GetKeyboardState (keystate
);
2021 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
2022 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
2023 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
2024 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
2025 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
2026 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
2027 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
2028 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
2029 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
2030 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
2031 SetKeyboardState (keystate
);
2035 /* Synchronize modifier state with what is reported with the current
2036 keystroke. Even if we cannot distinguish between left and right
2037 modifier keys, we know that, if no modifiers are set, then neither
2038 the left or right modifier should be set. */
2040 sync_modifiers (void)
2042 if (!modifiers_recorded
)
2045 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
2046 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2048 if (!(GetKeyState (VK_MENU
) & 0x8000))
2049 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2053 modifier_set (int vkey
)
2055 if (vkey
== VK_CAPITAL
|| vkey
== VK_SCROLL
)
2056 return (GetKeyState (vkey
) & 0x1);
2057 if (!modifiers_recorded
)
2058 return (GetKeyState (vkey
) & 0x8000);
2063 return modifiers
[EMACS_LCONTROL
];
2065 return modifiers
[EMACS_RCONTROL
];
2067 return modifiers
[EMACS_LMENU
];
2069 return modifiers
[EMACS_RMENU
];
2071 return (GetKeyState (vkey
) & 0x8000);
2074 /* Convert between the modifier bits W32 uses and the modifier bits
2078 w32_key_to_modifier (int key
)
2080 Lisp_Object key_mapping
;
2085 key_mapping
= Vw32_lwindow_modifier
;
2088 key_mapping
= Vw32_rwindow_modifier
;
2091 key_mapping
= Vw32_apps_modifier
;
2094 key_mapping
= Vw32_scroll_lock_modifier
;
2100 /* NB. This code runs in the input thread, asynchronously to the lisp
2101 thread, so we must be careful to ensure access to lisp data is
2102 thread-safe. The following code is safe because the modifier
2103 variable values are updated atomically from lisp and symbols are
2104 not relocated by GC. Also, we don't have to worry about seeing GC
2106 if (EQ (key_mapping
, Qhyper
))
2107 return hyper_modifier
;
2108 if (EQ (key_mapping
, Qsuper
))
2109 return super_modifier
;
2110 if (EQ (key_mapping
, Qmeta
))
2111 return meta_modifier
;
2112 if (EQ (key_mapping
, Qalt
))
2113 return alt_modifier
;
2114 if (EQ (key_mapping
, Qctrl
))
2115 return ctrl_modifier
;
2116 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
2117 return ctrl_modifier
;
2118 if (EQ (key_mapping
, Qshift
))
2119 return shift_modifier
;
2121 /* Don't generate any modifier if not explicitly requested. */
2126 w32_get_modifiers (void)
2128 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
2129 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
2130 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
2131 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
2132 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
2133 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
2134 (modifier_set (VK_MENU
) ?
2135 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
2138 /* We map the VK_* modifiers into console modifier constants
2139 so that we can use the same routines to handle both console
2140 and window input. */
2143 construct_console_modifiers (void)
2148 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
2149 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
2150 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
2151 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
2152 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
2153 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
2154 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
2155 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
2156 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
2157 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
2158 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
2164 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
2168 /* Convert to emacs modifiers. */
2169 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
2175 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
2177 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
2180 if (virt_key
== VK_RETURN
)
2181 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
2183 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
2184 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
2186 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
2187 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
2189 if (virt_key
== VK_CLEAR
)
2190 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
2195 /* List of special key combinations which w32 would normally capture,
2196 but Emacs should grab instead. Not directly visible to lisp, to
2197 simplify synchronization. Each item is an integer encoding a virtual
2198 key code and modifier combination to capture. */
2199 static Lisp_Object w32_grabbed_keys
;
2201 #define HOTKEY(vk, mods) make_number (((vk) & 255) | ((mods) << 8))
2202 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
2203 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
2204 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
2206 #define RAW_HOTKEY_ID(k) ((k) & 0xbfff)
2207 #define RAW_HOTKEY_VK_CODE(k) ((k) & 255)
2208 #define RAW_HOTKEY_MODIFIERS(k) ((k) >> 8)
2210 /* Register hot-keys for reserved key combinations when Emacs has
2211 keyboard focus, since this is the only way Emacs can receive key
2212 combinations like Alt-Tab which are used by the system. */
2215 register_hot_keys (HWND hwnd
)
2217 Lisp_Object keylist
;
2219 /* Use CONSP, since we are called asynchronously. */
2220 for (keylist
= w32_grabbed_keys
; CONSP (keylist
); keylist
= XCDR (keylist
))
2222 Lisp_Object key
= XCAR (keylist
);
2224 /* Deleted entries get set to nil. */
2225 if (!INTEGERP (key
))
2228 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
2229 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
2234 unregister_hot_keys (HWND hwnd
)
2236 Lisp_Object keylist
;
2238 for (keylist
= w32_grabbed_keys
; CONSP (keylist
); keylist
= XCDR (keylist
))
2240 Lisp_Object key
= XCAR (keylist
);
2242 if (!INTEGERP (key
))
2245 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
2249 /* Here's an overview of how Emacs input works on MS-Windows.
2251 System messages are read and processed by w32_msg_pump below. This
2252 function runs in a separate thread. It handles a small number of
2253 custom WM_EMACS_* messages (posted by the main thread, look for
2254 PostMessage calls), and dispatches the rest to w32_wnd_proc, which
2255 is the main window procedure for the entire Emacs application.
2257 w32_wnd_proc also runs in the same separate input thread. It
2258 handles some messages, mostly those that need GDI calls, by itself.
2259 For the others, it calls my_post_msg, which inserts the messages
2260 into the input queue serviced by w32_read_socket.
2262 w32_read_socket runs in the main (a.k.a. "Lisp") thread, and is
2263 called synchronously from keyboard.c when it is known or suspected
2264 that some input is available. w32_read_socket either handles
2265 messages immediately, or converts them into Emacs input events and
2266 stuffs them into kbd_buffer, where kbd_buffer_get_event can get at
2267 them and process them when read_char and its callers require
2270 /* Main message dispatch loop. */
2273 w32_msg_pump (deferred_msg
* msg_buf
)
2279 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
2281 while ((w32_unicode_gui
? GetMessageW
: GetMessageA
) (&msg
, NULL
, 0, 0))
2283 if (msg
.hwnd
== NULL
)
2285 switch (msg
.message
)
2288 /* Produced by complete_deferred_msg; just ignore. */
2290 case WM_EMACS_CREATEWINDOW
:
2291 /* Initialize COM for this window. Even though we don't use it,
2292 some third party shell extensions can cause it to be used in
2293 system dialogs, which causes a crash if it is not initialized.
2294 This is a known bug in Windows, which was fixed long ago, but
2295 the patch for XP is not publicly available until XP SP3,
2296 and older versions will never be patched. */
2297 CoInitialize (NULL
);
2298 w32_createwindow ((struct frame
*) msg
.wParam
);
2299 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2302 case WM_EMACS_SETLOCALE
:
2303 SetThreadLocale (msg
.wParam
);
2304 /* Reply is not expected. */
2306 case WM_EMACS_SETKEYBOARDLAYOUT
:
2307 result
= (WPARAM
) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
2308 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2312 case WM_EMACS_REGISTER_HOT_KEY
:
2313 focus_window
= GetFocus ();
2314 if (focus_window
!= NULL
)
2315 RegisterHotKey (focus_window
,
2316 RAW_HOTKEY_ID (msg
.wParam
),
2317 RAW_HOTKEY_MODIFIERS (msg
.wParam
),
2318 RAW_HOTKEY_VK_CODE (msg
.wParam
));
2319 /* Reply is not expected. */
2321 case WM_EMACS_UNREGISTER_HOT_KEY
:
2322 focus_window
= GetFocus ();
2323 if (focus_window
!= NULL
)
2324 UnregisterHotKey (focus_window
, RAW_HOTKEY_ID (msg
.wParam
));
2325 /* Mark item as erased. NB: this code must be
2326 thread-safe. The next line is okay because the cons
2327 cell is never made into garbage and is not relocated by
2329 XSETCAR ((Lisp_Object
) ((EMACS_INT
) msg
.lParam
), Qnil
);
2330 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2333 case WM_EMACS_TOGGLE_LOCK_KEY
:
2335 int vk_code
= (int) msg
.wParam
;
2336 int cur_state
= (GetKeyState (vk_code
) & 1);
2337 Lisp_Object new_state
= (Lisp_Object
) ((EMACS_INT
) msg
.lParam
);
2339 /* NB: This code must be thread-safe. It is safe to
2340 call NILP because symbols are not relocated by GC,
2341 and pointer here is not touched by GC (so the markbit
2342 can't be set). Numbers are safe because they are
2343 immediate values. */
2344 if (NILP (new_state
)
2345 || (NUMBERP (new_state
)
2346 && ((XUINT (new_state
)) & 1) != cur_state
))
2348 one_w32_display_info
.faked_key
= vk_code
;
2350 keybd_event ((BYTE
) vk_code
,
2351 (BYTE
) MapVirtualKey (vk_code
, 0),
2352 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2353 keybd_event ((BYTE
) vk_code
,
2354 (BYTE
) MapVirtualKey (vk_code
, 0),
2355 KEYEVENTF_EXTENDEDKEY
| 0, 0);
2356 keybd_event ((BYTE
) vk_code
,
2357 (BYTE
) MapVirtualKey (vk_code
, 0),
2358 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2359 cur_state
= !cur_state
;
2361 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2367 /* Broadcast messages make it here, so you need to be looking
2368 for something in particular for this to be useful. */
2370 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
2376 if (w32_unicode_gui
)
2377 DispatchMessageW (&msg
);
2379 DispatchMessageA (&msg
);
2382 /* Exit nested loop when our deferred message has completed. */
2383 if (msg_buf
->completed
)
2388 deferred_msg
* deferred_msg_head
;
2390 static deferred_msg
*
2391 find_deferred_msg (HWND hwnd
, UINT msg
)
2393 deferred_msg
* item
;
2395 /* Don't actually need synchronization for read access, since
2396 modification of single pointer is always atomic. */
2397 /* enter_crit (); */
2399 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2400 if (item
->w32msg
.msg
.hwnd
== hwnd
2401 && item
->w32msg
.msg
.message
== msg
)
2404 /* leave_crit (); */
2410 send_deferred_msg (deferred_msg
* msg_buf
,
2416 /* Only input thread can send deferred messages. */
2417 if (GetCurrentThreadId () != dwWindowsThreadId
)
2420 /* It is an error to send a message that is already deferred. */
2421 if (find_deferred_msg (hwnd
, msg
) != NULL
)
2424 /* Enforced synchronization is not needed because this is the only
2425 function that alters deferred_msg_head, and the following critical
2426 section is guaranteed to only be serially reentered (since only the
2427 input thread can call us). */
2429 /* enter_crit (); */
2431 msg_buf
->completed
= 0;
2432 msg_buf
->next
= deferred_msg_head
;
2433 deferred_msg_head
= msg_buf
;
2434 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
2436 /* leave_crit (); */
2438 /* Start a new nested message loop to process other messages until
2439 this one is completed. */
2440 w32_msg_pump (msg_buf
);
2442 deferred_msg_head
= msg_buf
->next
;
2444 return msg_buf
->result
;
2448 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
2450 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
2452 if (msg_buf
== NULL
)
2453 /* Message may have been canceled, so don't abort. */
2456 msg_buf
->result
= result
;
2457 msg_buf
->completed
= 1;
2459 /* Ensure input thread is woken so it notices the completion. */
2460 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2464 cancel_all_deferred_msgs (void)
2466 deferred_msg
* item
;
2468 /* Don't actually need synchronization for read access, since
2469 modification of single pointer is always atomic. */
2470 /* enter_crit (); */
2472 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2475 item
->completed
= 1;
2478 /* leave_crit (); */
2480 /* Ensure input thread is woken so it notices the completion. */
2481 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2485 w32_msg_worker (void *arg
)
2488 deferred_msg dummy_buf
;
2490 /* Ensure our message queue is created */
2492 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
2494 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2497 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
2498 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
2499 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
2501 /* This is the initial message loop which should only exit when the
2502 application quits. */
2503 w32_msg_pump (&dummy_buf
);
2509 signal_user_input (void)
2511 /* Interrupt any lisp that wants to be interrupted by input. */
2512 if (!NILP (Vthrow_on_input
))
2514 Vquit_flag
= Vthrow_on_input
;
2515 /* Doing a QUIT from this thread is a bad idea, since this
2516 unwinds the stack of the Lisp thread, and the Windows runtime
2517 rightfully barfs. Disabled. */
2519 /* If we're inside a function that wants immediate quits,
2521 if (immediate_quit
&& NILP (Vinhibit_quit
))
2532 post_character_message (HWND hwnd
, UINT msg
,
2533 WPARAM wParam
, LPARAM lParam
,
2538 wmsg
.dwModifiers
= modifiers
;
2540 /* Detect quit_char and set quit-flag directly. Note that we
2541 still need to post a message to ensure the main thread will be
2542 woken up if blocked in sys_select, but we do NOT want to post
2543 the quit_char message itself (because it will usually be as if
2544 the user had typed quit_char twice). Instead, we post a dummy
2545 message that has no particular effect. */
2548 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
2549 c
= make_ctrl_char (c
) & 0377;
2551 || (wmsg
.dwModifiers
== 0
2552 && w32_quit_key
&& wParam
== w32_quit_key
))
2556 /* The choice of message is somewhat arbitrary, as long as
2557 the main thread handler just ignores it. */
2560 /* Interrupt any blocking system calls. */
2563 /* As a safety precaution, forcibly complete any deferred
2564 messages. This is a kludge, but I don't see any particularly
2565 clean way to handle the situation where a deferred message is
2566 "dropped" in the lisp thread, and will thus never be
2567 completed, eg. by the user trying to activate the menubar
2568 when the lisp thread is busy, and then typing C-g when the
2569 menubar doesn't open promptly (with the result that the
2570 menubar never responds at all because the deferred
2571 WM_INITMENU message is never completed). Another problem
2572 situation is when the lisp thread calls SendMessage (to send
2573 a window manager command) when a message has been deferred;
2574 the lisp thread gets blocked indefinitely waiting for the
2575 deferred message to be completed, which itself is waiting for
2576 the lisp thread to respond.
2578 Note that we don't want to block the input thread waiting for
2579 a response from the lisp thread (although that would at least
2580 solve the deadlock problem above), because we want to be able
2581 to receive C-g to interrupt the lisp thread. */
2582 cancel_all_deferred_msgs ();
2585 signal_user_input ();
2588 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2591 /* Main window procedure */
2593 static LRESULT CALLBACK
2594 w32_wnd_proc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2597 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
2599 int windows_translate
;
2602 /* Note that it is okay to call x_window_to_frame, even though we are
2603 not running in the main lisp thread, because frame deletion
2604 requires the lisp thread to synchronize with this thread. Thus, if
2605 a frame struct is returned, it can be used without concern that the
2606 lisp thread might make it disappear while we are using it.
2608 NB. Walking the frame list in this thread is safe (as long as
2609 writes of Lisp_Object slots are atomic, which they are on Windows).
2610 Although delete-frame can destructively modify the frame list while
2611 we are walking it, a garbage collection cannot occur until after
2612 delete-frame has synchronized with this thread.
2614 It is also safe to use functions that make GDI calls, such as
2615 w32_clear_rect, because these functions must obtain a DC handle
2616 from the frame struct using get_frame_dc which is thread-aware. */
2621 f
= x_window_to_frame (dpyinfo
, hwnd
);
2624 HDC hdc
= get_frame_dc (f
);
2625 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
2626 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
2627 release_frame_dc (f
, hdc
);
2629 #if defined (W32_DEBUG_DISPLAY)
2630 DebPrint (("WM_ERASEBKGND (frame %p): erasing %d,%d-%d,%d\n",
2632 wmsg
.rect
.left
, wmsg
.rect
.top
,
2633 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2634 #endif /* W32_DEBUG_DISPLAY */
2637 case WM_PALETTECHANGED
:
2638 /* ignore our own changes */
2639 if ((HWND
)wParam
!= hwnd
)
2641 f
= x_window_to_frame (dpyinfo
, hwnd
);
2643 /* get_frame_dc will realize our palette and force all
2644 frames to be redrawn if needed. */
2645 release_frame_dc (f
, get_frame_dc (f
));
2650 PAINTSTRUCT paintStruct
;
2652 memset (&update_rect
, 0, sizeof (update_rect
));
2654 f
= x_window_to_frame (dpyinfo
, hwnd
);
2657 DebPrint (("WM_PAINT received for unknown window %p\n", hwnd
));
2661 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
2662 fails. Apparently this can happen under some
2664 if (GetUpdateRect (hwnd
, &update_rect
, FALSE
) || !w32_strict_painting
)
2667 BeginPaint (hwnd
, &paintStruct
);
2669 /* The rectangles returned by GetUpdateRect and BeginPaint
2670 do not always match. Play it safe by assuming both areas
2672 UnionRect (&(wmsg
.rect
), &update_rect
, &(paintStruct
.rcPaint
));
2674 #if defined (W32_DEBUG_DISPLAY)
2675 DebPrint (("WM_PAINT (frame %p): painting %d,%d-%d,%d\n",
2677 wmsg
.rect
.left
, wmsg
.rect
.top
,
2678 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2679 DebPrint ((" [update region is %d,%d-%d,%d]\n",
2680 update_rect
.left
, update_rect
.top
,
2681 update_rect
.right
, update_rect
.bottom
));
2683 EndPaint (hwnd
, &paintStruct
);
2686 /* Change the message type to prevent Windows from
2687 combining WM_PAINT messages in the Lisp thread's queue,
2688 since Windows assumes that each message queue is
2689 dedicated to one frame and does not bother checking
2690 that hwnd matches before combining them. */
2691 my_post_msg (&wmsg
, hwnd
, WM_EMACS_PAINT
, wParam
, lParam
);
2696 /* If GetUpdateRect returns 0 (meaning there is no update
2697 region), assume the whole window needs to be repainted. */
2698 GetClientRect (hwnd
, &wmsg
.rect
);
2699 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2703 case WM_INPUTLANGCHANGE
:
2704 /* Inform lisp thread of keyboard layout changes. */
2705 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2707 /* Clear dead keys in the keyboard state; for simplicity only
2708 preserve modifier key states. */
2713 GetKeyboardState (keystate
);
2714 for (i
= 0; i
< 256; i
++)
2731 SetKeyboardState (keystate
);
2736 /* Synchronize hot keys with normal input. */
2737 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
2742 record_keyup (wParam
, lParam
);
2747 /* Ignore keystrokes we fake ourself; see below. */
2748 if (dpyinfo
->faked_key
== wParam
)
2750 dpyinfo
->faked_key
= 0;
2751 /* Make sure TranslateMessage sees them though (as long as
2752 they don't produce WM_CHAR messages). This ensures that
2753 indicator lights are toggled promptly on Windows 9x, for
2755 if (wParam
< 256 && lispy_function_keys
[wParam
])
2757 windows_translate
= 1;
2763 /* Synchronize modifiers with current keystroke. */
2765 record_keydown (wParam
, lParam
);
2766 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
2768 windows_translate
= 0;
2773 if (NILP (Vw32_pass_lwindow_to_system
))
2775 /* Prevent system from acting on keyup (which opens the
2776 Start menu if no other key was pressed) by simulating a
2777 press of Space which we will ignore. */
2778 if (GetAsyncKeyState (wParam
) & 1)
2780 if (NUMBERP (Vw32_phantom_key_code
))
2781 key
= XUINT (Vw32_phantom_key_code
) & 255;
2784 dpyinfo
->faked_key
= key
;
2785 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
2788 if (!NILP (Vw32_lwindow_modifier
))
2792 if (NILP (Vw32_pass_rwindow_to_system
))
2794 if (GetAsyncKeyState (wParam
) & 1)
2796 if (NUMBERP (Vw32_phantom_key_code
))
2797 key
= XUINT (Vw32_phantom_key_code
) & 255;
2800 dpyinfo
->faked_key
= key
;
2801 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
2804 if (!NILP (Vw32_rwindow_modifier
))
2808 if (!NILP (Vw32_apps_modifier
))
2812 if (NILP (Vw32_pass_alt_to_system
))
2813 /* Prevent DefWindowProc from activating the menu bar if an
2814 Alt key is pressed and released by itself. */
2816 windows_translate
= 1;
2819 /* Decide whether to treat as modifier or function key. */
2820 if (NILP (Vw32_enable_caps_lock
))
2821 goto disable_lock_key
;
2822 windows_translate
= 1;
2825 /* Decide whether to treat as modifier or function key. */
2826 if (NILP (Vw32_enable_num_lock
))
2827 goto disable_lock_key
;
2828 windows_translate
= 1;
2831 /* Decide whether to treat as modifier or function key. */
2832 if (NILP (Vw32_scroll_lock_modifier
))
2833 goto disable_lock_key
;
2834 windows_translate
= 1;
2837 /* Ensure the appropriate lock key state (and indicator light)
2838 remains in the same state. We do this by faking another
2839 press of the relevant key. Apparently, this really is the
2840 only way to toggle the state of the indicator lights. */
2841 dpyinfo
->faked_key
= wParam
;
2842 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
2843 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2844 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
2845 KEYEVENTF_EXTENDEDKEY
| 0, 0);
2846 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
2847 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2848 /* Ensure indicator lights are updated promptly on Windows 9x
2849 (TranslateMessage apparently does this), after forwarding
2851 post_character_message (hwnd
, msg
, wParam
, lParam
,
2852 w32_get_key_modifiers (wParam
, lParam
));
2853 windows_translate
= 1;
2857 case VK_PROCESSKEY
: /* Generated by IME. */
2858 windows_translate
= 1;
2861 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
2862 which is confusing for purposes of key binding; convert
2863 VK_CANCEL events into VK_PAUSE events. */
2867 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
2868 for purposes of key binding; convert these back into
2869 VK_NUMLOCK events, at least when we want to see NumLock key
2870 presses. (Note that there is never any possibility that
2871 VK_PAUSE with Ctrl really is C-Pause as per above.) */
2872 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
2873 wParam
= VK_NUMLOCK
;
2876 /* If not defined as a function key, change it to a WM_CHAR message. */
2877 if (wParam
> 255 || !lispy_function_keys
[wParam
])
2879 DWORD modifiers
= construct_console_modifiers ();
2881 if (!NILP (Vw32_recognize_altgr
)
2882 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
2884 /* Always let TranslateMessage handle AltGr key chords;
2885 for some reason, ToAscii doesn't always process AltGr
2886 chords correctly. */
2887 windows_translate
= 1;
2889 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
2891 /* Handle key chords including any modifiers other
2892 than shift directly, in order to preserve as much
2893 modifier information as possible. */
2894 if ('A' <= wParam
&& wParam
<= 'Z')
2896 /* Don't translate modified alphabetic keystrokes,
2897 so the user doesn't need to constantly switch
2898 layout to type control or meta keystrokes when
2899 the normal layout translates alphabetic
2900 characters to non-ascii characters. */
2901 if (!modifier_set (VK_SHIFT
))
2902 wParam
+= ('a' - 'A');
2907 /* Try to handle other keystrokes by determining the
2908 base character (ie. translating the base key plus
2911 KEY_EVENT_RECORD key
;
2913 key
.bKeyDown
= TRUE
;
2914 key
.wRepeatCount
= 1;
2915 key
.wVirtualKeyCode
= wParam
;
2916 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
2917 key
.uChar
.AsciiChar
= 0;
2918 key
.dwControlKeyState
= modifiers
;
2920 add
= w32_kbd_patch_key (&key
, w32_keyboard_codepage
);
2921 /* 0 means an unrecognized keycode, negative means
2922 dead key. Ignore both. */
2925 /* Forward asciified character sequence. */
2926 post_character_message
2928 (unsigned char) key
.uChar
.AsciiChar
, lParam
,
2929 w32_get_key_modifiers (wParam
, lParam
));
2930 w32_kbd_patch_key (&key
, w32_keyboard_codepage
);
2937 /* Let TranslateMessage handle everything else. */
2938 windows_translate
= 1;
2944 if (windows_translate
)
2946 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
2947 windows_msg
.time
= GetMessageTime ();
2948 TranslateMessage (&windows_msg
);
2960 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
2961 signal_user_input ();
2962 my_post_msg (&wmsg
, hwnd
, WM_UNICHAR
, wParam
, lParam
);
2966 post_character_message (hwnd
, msg
, wParam
, lParam
,
2967 w32_get_key_modifiers (wParam
, lParam
));
2971 /* WM_UNICHAR looks promising from the docs, but the exact
2972 circumstances in which TranslateMessage sends it is one of those
2973 Microsoft secret API things that EU and US courts are supposed
2974 to have put a stop to already. Spy++ shows it being sent to Notepad
2975 and other MS apps, but never to Emacs.
2977 Some third party IMEs send it in accordance with the official
2978 documentation though, so handle it here.
2980 UNICODE_NOCHAR is used to test for support for this message.
2981 TRUE indicates that the message is supported. */
2982 if (wParam
== UNICODE_NOCHAR
)
2987 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
2988 signal_user_input ();
2989 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2994 /* If we can't get the IME result as Unicode, use default processing,
2995 which will at least allow characters decodable in the system locale
2997 if (!get_composition_string_fn
)
3000 else if (!ignore_ime_char
)
3005 HIMC context
= get_ime_context_fn (hwnd
);
3006 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3007 /* Get buffer size. */
3008 size
= get_composition_string_fn (context
, GCS_RESULTSTR
, NULL
, 0);
3009 buffer
= alloca (size
);
3010 size
= get_composition_string_fn (context
, GCS_RESULTSTR
,
3012 release_ime_context_fn (hwnd
, context
);
3014 signal_user_input ();
3015 for (i
= 0; i
< size
/ sizeof (wchar_t); i
++)
3017 my_post_msg (&wmsg
, hwnd
, WM_UNICHAR
, (WPARAM
) buffer
[i
],
3020 /* Ignore the messages for the rest of the
3021 characters in the string that was output above. */
3022 ignore_ime_char
= (size
/ sizeof (wchar_t)) - 1;
3029 case WM_IME_STARTCOMPOSITION
:
3030 if (!set_ime_composition_window_fn
)
3034 COMPOSITIONFORM form
;
3038 f
= x_window_to_frame (dpyinfo
, hwnd
);
3039 w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
3041 form
.dwStyle
= CFS_RECT
;
3042 form
.ptCurrentPos
.x
= w32_system_caret_x
;
3043 form
.ptCurrentPos
.y
= w32_system_caret_y
;
3045 form
.rcArea
.left
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, 0);
3046 form
.rcArea
.top
= (WINDOW_TOP_EDGE_Y (w
)
3047 + WINDOW_HEADER_LINE_HEIGHT (w
));
3048 form
.rcArea
.right
= (WINDOW_BOX_RIGHT_EDGE_X (w
)
3049 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
3050 - WINDOW_RIGHT_FRINGE_WIDTH (w
));
3051 form
.rcArea
.bottom
= (WINDOW_BOTTOM_EDGE_Y (w
)
3052 - WINDOW_MODE_LINE_HEIGHT (w
));
3054 context
= get_ime_context_fn (hwnd
);
3059 set_ime_composition_window_fn (context
, &form
);
3060 release_ime_context_fn (hwnd
, context
);
3064 case WM_IME_ENDCOMPOSITION
:
3065 ignore_ime_char
= 0;
3068 /* Simulate middle mouse button events when left and right buttons
3069 are used together, but only if user has two button mouse. */
3070 case WM_LBUTTONDOWN
:
3071 case WM_RBUTTONDOWN
:
3072 if (w32_num_mouse_buttons
> 2)
3073 goto handle_plain_button
;
3076 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
3077 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
3079 if (button_state
& this)
3082 if (button_state
== 0)
3085 button_state
|= this;
3087 if (button_state
& other
)
3089 if (mouse_button_timer
)
3091 KillTimer (hwnd
, mouse_button_timer
);
3092 mouse_button_timer
= 0;
3094 /* Generate middle mouse event instead. */
3095 msg
= WM_MBUTTONDOWN
;
3096 button_state
|= MMOUSE
;
3098 else if (button_state
& MMOUSE
)
3100 /* Ignore button event if we've already generated a
3101 middle mouse down event. This happens if the
3102 user releases and press one of the two buttons
3103 after we've faked a middle mouse event. */
3108 /* Flush out saved message. */
3109 post_msg (&saved_mouse_button_msg
);
3111 wmsg
.dwModifiers
= w32_get_modifiers ();
3112 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3113 signal_user_input ();
3115 /* Clear message buffer. */
3116 saved_mouse_button_msg
.msg
.hwnd
= 0;
3120 /* Hold onto message for now. */
3121 mouse_button_timer
=
3122 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
3123 w32_mouse_button_tolerance
, NULL
);
3124 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
3125 saved_mouse_button_msg
.msg
.message
= msg
;
3126 saved_mouse_button_msg
.msg
.wParam
= wParam
;
3127 saved_mouse_button_msg
.msg
.lParam
= lParam
;
3128 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
3129 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
3136 if (w32_num_mouse_buttons
> 2)
3137 goto handle_plain_button
;
3140 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
3141 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
3143 if ((button_state
& this) == 0)
3146 button_state
&= ~this;
3148 if (button_state
& MMOUSE
)
3150 /* Only generate event when second button is released. */
3151 if ((button_state
& other
) == 0)
3154 button_state
&= ~MMOUSE
;
3156 if (button_state
) emacs_abort ();
3163 /* Flush out saved message if necessary. */
3164 if (saved_mouse_button_msg
.msg
.hwnd
)
3166 post_msg (&saved_mouse_button_msg
);
3169 wmsg
.dwModifiers
= w32_get_modifiers ();
3170 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3171 signal_user_input ();
3173 /* Always clear message buffer and cancel timer. */
3174 saved_mouse_button_msg
.msg
.hwnd
= 0;
3175 KillTimer (hwnd
, mouse_button_timer
);
3176 mouse_button_timer
= 0;
3178 if (button_state
== 0)
3183 case WM_XBUTTONDOWN
:
3185 if (w32_pass_extra_mouse_buttons_to_system
)
3187 /* else fall through and process them. */
3188 case WM_MBUTTONDOWN
:
3190 handle_plain_button
:
3195 /* Ignore middle and extra buttons as long as the menu is active. */
3196 f
= x_window_to_frame (dpyinfo
, hwnd
);
3197 if (f
&& f
->output_data
.w32
->menubar_active
)
3200 if (parse_button (msg
, HIWORD (wParam
), &button
, &up
))
3202 if (up
) ReleaseCapture ();
3203 else SetCapture (hwnd
);
3204 button
= (button
== 0) ? LMOUSE
:
3205 ((button
== 1) ? MMOUSE
: RMOUSE
);
3207 button_state
&= ~button
;
3209 button_state
|= button
;
3213 wmsg
.dwModifiers
= w32_get_modifiers ();
3214 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3215 signal_user_input ();
3217 /* Need to return true for XBUTTON messages, false for others,
3218 to indicate that we processed the message. */
3219 return (msg
== WM_XBUTTONDOWN
|| msg
== WM_XBUTTONUP
);
3222 /* Ignore mouse movements as long as the menu is active. These
3223 movements are processed by the window manager anyway, and
3224 it's wrong to handle them as if they happened on the
3225 underlying frame. */
3226 f
= x_window_to_frame (dpyinfo
, hwnd
);
3227 if (f
&& f
->output_data
.w32
->menubar_active
)
3230 /* If the mouse has just moved into the frame, start tracking
3231 it, so we will be notified when it leaves the frame. Mouse
3232 tracking only works under W98 and NT4 and later. On earlier
3233 versions, there is no way of telling when the mouse leaves the
3234 frame, so we just have to put up with help-echo and mouse
3235 highlighting remaining while the frame is not active. */
3236 if (track_mouse_event_fn
&& !track_mouse_window
)
3238 TRACKMOUSEEVENT tme
;
3239 tme
.cbSize
= sizeof (tme
);
3240 tme
.dwFlags
= TME_LEAVE
;
3241 tme
.hwndTrack
= hwnd
;
3243 track_mouse_event_fn (&tme
);
3244 track_mouse_window
= hwnd
;
3247 if (w32_mouse_move_interval
<= 0
3248 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
3250 wmsg
.dwModifiers
= w32_get_modifiers ();
3251 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3255 /* Hang onto mouse move and scroll messages for a bit, to avoid
3256 sending such events to Emacs faster than it can process them.
3257 If we get more events before the timer from the first message
3258 expires, we just replace the first message. */
3260 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
3262 SetTimer (hwnd
, MOUSE_MOVE_ID
,
3263 w32_mouse_move_interval
, NULL
);
3265 /* Hold onto message for now. */
3266 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
3267 saved_mouse_move_msg
.msg
.message
= msg
;
3268 saved_mouse_move_msg
.msg
.wParam
= wParam
;
3269 saved_mouse_move_msg
.msg
.lParam
= lParam
;
3270 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
3271 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
3277 wmsg
.dwModifiers
= w32_get_modifiers ();
3278 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3279 signal_user_input ();
3283 if (w32_pass_multimedia_buttons_to_system
)
3285 /* Otherwise, pass to lisp, the same way we do with mousehwheel. */
3286 case WM_MOUSEHWHEEL
:
3287 wmsg
.dwModifiers
= w32_get_modifiers ();
3288 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3289 signal_user_input ();
3290 /* Non-zero must be returned when WM_MOUSEHWHEEL messages are
3291 handled, to prevent the system trying to handle it by faking
3292 scroll bar events. */
3296 /* Flush out saved messages if necessary. */
3297 if (wParam
== mouse_button_timer
)
3299 if (saved_mouse_button_msg
.msg
.hwnd
)
3301 post_msg (&saved_mouse_button_msg
);
3302 signal_user_input ();
3303 saved_mouse_button_msg
.msg
.hwnd
= 0;
3305 KillTimer (hwnd
, mouse_button_timer
);
3306 mouse_button_timer
= 0;
3308 else if (wParam
== mouse_move_timer
)
3310 if (saved_mouse_move_msg
.msg
.hwnd
)
3312 post_msg (&saved_mouse_move_msg
);
3313 saved_mouse_move_msg
.msg
.hwnd
= 0;
3315 KillTimer (hwnd
, mouse_move_timer
);
3316 mouse_move_timer
= 0;
3318 else if (wParam
== menu_free_timer
)
3320 KillTimer (hwnd
, menu_free_timer
);
3321 menu_free_timer
= 0;
3322 f
= x_window_to_frame (dpyinfo
, hwnd
);
3323 /* If a popup menu is active, don't wipe its strings. */
3325 && current_popup_menu
== NULL
)
3327 /* Free memory used by owner-drawn and help-echo strings. */
3328 w32_free_menu_strings (hwnd
);
3330 f
->output_data
.w32
->menubar_active
= 0;
3337 /* Windows doesn't send us focus messages when putting up and
3338 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
3339 The only indication we get that something happened is receiving
3340 this message afterwards. So this is a good time to reset our
3341 keyboard modifiers' state. */
3348 /* We must ensure menu bar is fully constructed and up to date
3349 before allowing user interaction with it. To achieve this
3350 we send this message to the lisp thread and wait for a
3351 reply (whose value is not actually needed) to indicate that
3352 the menu bar is now ready for use, so we can now return.
3354 To remain responsive in the meantime, we enter a nested message
3355 loop that can process all other messages.
3357 However, we skip all this if the message results from calling
3358 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
3359 thread a message because it is blocked on us at this point. We
3360 set menubar_active before calling TrackPopupMenu to indicate
3361 this (there is no possibility of confusion with real menubar
3364 f
= x_window_to_frame (dpyinfo
, hwnd
);
3366 && (f
->output_data
.w32
->menubar_active
3367 /* We can receive this message even in the absence of a
3368 menubar (ie. when the system menu is activated) - in this
3369 case we do NOT want to forward the message, otherwise it
3370 will cause the menubar to suddenly appear when the user
3371 had requested it to be turned off! */
3372 || f
->output_data
.w32
->menubar_widget
== NULL
))
3376 deferred_msg msg_buf
;
3378 /* Detect if message has already been deferred; in this case
3379 we cannot return any sensible value to ignore this. */
3380 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3385 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
3388 case WM_EXITMENULOOP
:
3389 f
= x_window_to_frame (dpyinfo
, hwnd
);
3391 /* If a menu is still active, check again after a short delay,
3392 since Windows often (always?) sends the WM_EXITMENULOOP
3393 before the corresponding WM_COMMAND message.
3394 Don't do this if a popup menu is active, since it is only
3395 menubar menus that require cleaning up in this way.
3397 if (f
&& menubar_in_use
&& current_popup_menu
== NULL
)
3398 menu_free_timer
= SetTimer (hwnd
, MENU_FREE_ID
, MENU_FREE_DELAY
, NULL
);
3400 /* If hourglass cursor should be displayed, display it now. */
3401 if (f
&& f
->output_data
.w32
->hourglass_p
)
3402 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
3407 /* Direct handling of help_echo in menus. Should be safe now
3408 that we generate the help_echo by placing a help event in the
3411 HMENU menu
= (HMENU
) lParam
;
3412 UINT menu_item
= (UINT
) LOWORD (wParam
);
3413 UINT flags
= (UINT
) HIWORD (wParam
);
3415 w32_menu_display_help (hwnd
, menu
, menu_item
, flags
);
3419 case WM_MEASUREITEM
:
3420 f
= x_window_to_frame (dpyinfo
, hwnd
);
3423 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
3425 if (pMis
->CtlType
== ODT_MENU
)
3427 /* Work out dimensions for popup menu titles. */
3428 char * title
= (char *) pMis
->itemData
;
3429 HDC hdc
= GetDC (hwnd
);
3430 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3431 LOGFONT menu_logfont
;
3435 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3436 menu_logfont
.lfWeight
= FW_BOLD
;
3437 menu_font
= CreateFontIndirect (&menu_logfont
);
3438 old_font
= SelectObject (hdc
, menu_font
);
3440 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
3443 if (unicode_append_menu
)
3444 GetTextExtentPoint32W (hdc
, (WCHAR
*) title
,
3445 wcslen ((WCHAR
*) title
),
3448 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
3450 pMis
->itemWidth
= size
.cx
;
3451 if (pMis
->itemHeight
< size
.cy
)
3452 pMis
->itemHeight
= size
.cy
;
3455 pMis
->itemWidth
= 0;
3457 SelectObject (hdc
, old_font
);
3458 DeleteObject (menu_font
);
3459 ReleaseDC (hwnd
, hdc
);
3466 f
= x_window_to_frame (dpyinfo
, hwnd
);
3469 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
3471 if (pDis
->CtlType
== ODT_MENU
)
3473 /* Draw popup menu title. */
3474 char * title
= (char *) pDis
->itemData
;
3477 HDC hdc
= pDis
->hDC
;
3478 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3479 LOGFONT menu_logfont
;
3482 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3483 menu_logfont
.lfWeight
= FW_BOLD
;
3484 menu_font
= CreateFontIndirect (&menu_logfont
);
3485 old_font
= SelectObject (hdc
, menu_font
);
3487 /* Always draw title as if not selected. */
3488 if (unicode_append_menu
)
3491 + GetSystemMetrics (SM_CXMENUCHECK
),
3493 ETO_OPAQUE
, &pDis
->rcItem
,
3495 wcslen ((WCHAR
*) title
), NULL
);
3499 + GetSystemMetrics (SM_CXMENUCHECK
),
3501 ETO_OPAQUE
, &pDis
->rcItem
,
3502 title
, strlen (title
), NULL
);
3504 SelectObject (hdc
, old_font
);
3505 DeleteObject (menu_font
);
3513 /* Still not right - can't distinguish between clicks in the
3514 client area of the frame from clicks forwarded from the scroll
3515 bars - may have to hook WM_NCHITTEST to remember the mouse
3516 position and then check if it is in the client area ourselves. */
3517 case WM_MOUSEACTIVATE
:
3518 /* Discard the mouse click that activates a frame, allowing the
3519 user to click anywhere without changing point (or worse!).
3520 Don't eat mouse clicks on scrollbars though!! */
3521 if (LOWORD (lParam
) == HTCLIENT
)
3522 return MA_ACTIVATEANDEAT
;
3527 /* No longer tracking mouse. */
3528 track_mouse_window
= NULL
;
3530 case WM_ACTIVATEAPP
:
3532 case WM_WINDOWPOSCHANGED
:
3534 /* Inform lisp thread that a frame might have just been obscured
3535 or exposed, so should recheck visibility of all frames. */
3536 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3540 dpyinfo
->faked_key
= 0;
3542 register_hot_keys (hwnd
);
3545 unregister_hot_keys (hwnd
);
3548 /* Relinquish the system caret. */
3549 if (w32_system_caret_hwnd
)
3551 w32_visible_system_caret_hwnd
= NULL
;
3552 w32_system_caret_hwnd
= NULL
;
3558 f
= x_window_to_frame (dpyinfo
, hwnd
);
3559 if (f
&& HIWORD (wParam
) == 0)
3561 if (menu_free_timer
)
3563 KillTimer (hwnd
, menu_free_timer
);
3564 menu_free_timer
= 0;
3570 wmsg
.dwModifiers
= w32_get_modifiers ();
3571 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3579 wmsg
.dwModifiers
= w32_get_modifiers ();
3580 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3583 case WM_WINDOWPOSCHANGING
:
3584 /* Don't restrict the sizing of tip frames. */
3585 if (hwnd
== tip_window
)
3589 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
3591 wp
.length
= sizeof (WINDOWPLACEMENT
);
3592 GetWindowPlacement (hwnd
, &wp
);
3594 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
3601 DWORD internal_border
;
3602 DWORD scrollbar_extra
;
3605 wp
.length
= sizeof (wp
);
3606 GetWindowRect (hwnd
, &wr
);
3610 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
3611 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
3612 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
3613 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
3617 memset (&rect
, 0, sizeof (rect
));
3618 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
3619 GetMenu (hwnd
) != NULL
);
3621 /* Force width and height of client area to be exact
3622 multiples of the character cell dimensions. */
3623 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
3624 - 2 * internal_border
- scrollbar_extra
)
3626 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
3627 - 2 * internal_border
)
3632 /* For right/bottom sizing we can just fix the sizes.
3633 However for top/left sizing we will need to fix the X
3634 and Y positions as well. */
3636 int cx_mintrack
= GetSystemMetrics (SM_CXMINTRACK
);
3637 int cy_mintrack
= GetSystemMetrics (SM_CYMINTRACK
);
3639 lppos
->cx
= max (lppos
->cx
- wdiff
, cx_mintrack
);
3640 lppos
->cy
= max (lppos
->cy
- hdiff
, cy_mintrack
);
3642 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
3643 && (lppos
->flags
& SWP_NOMOVE
) == 0)
3645 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
3652 lppos
->flags
|= SWP_NOMOVE
;
3663 case WM_GETMINMAXINFO
:
3664 /* Hack to allow resizing the Emacs frame above the screen size.
3665 Note that Windows 9x limits coordinates to 16-bits. */
3666 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.x
= 32767;
3667 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.y
= 32767;
3671 if (LOWORD (lParam
) == HTCLIENT
)
3673 f
= x_window_to_frame (dpyinfo
, hwnd
);
3674 if (f
&& f
->output_data
.w32
->hourglass_p
3675 && !menubar_in_use
&& !current_popup_menu
)
3676 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
3678 SetCursor (f
->output_data
.w32
->current_cursor
);
3683 case WM_EMACS_SETCURSOR
:
3685 Cursor cursor
= (Cursor
) wParam
;
3686 f
= x_window_to_frame (dpyinfo
, hwnd
);
3689 f
->output_data
.w32
->current_cursor
= cursor
;
3690 if (!f
->output_data
.w32
->hourglass_p
)
3696 case WM_EMACS_CREATESCROLLBAR
:
3697 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
3698 (struct scroll_bar
*) lParam
);
3700 case WM_EMACS_SHOWWINDOW
:
3701 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
3703 case WM_EMACS_BRINGTOTOP
:
3704 case WM_EMACS_SETFOREGROUND
:
3706 HWND foreground_window
;
3707 DWORD foreground_thread
, retval
;
3709 /* On NT 5.0, and apparently Windows 98, it is necessary to
3710 attach to the thread that currently has focus in order to
3711 pull the focus away from it. */
3712 foreground_window
= GetForegroundWindow ();
3713 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
3714 if (!foreground_window
3715 || foreground_thread
== GetCurrentThreadId ()
3716 || !AttachThreadInput (GetCurrentThreadId (),
3717 foreground_thread
, TRUE
))
3718 foreground_thread
= 0;
3720 retval
= SetForegroundWindow ((HWND
) wParam
);
3721 if (msg
== WM_EMACS_BRINGTOTOP
)
3722 retval
= BringWindowToTop ((HWND
) wParam
);
3724 /* Detach from the previous foreground thread. */
3725 if (foreground_thread
)
3726 AttachThreadInput (GetCurrentThreadId (),
3727 foreground_thread
, FALSE
);
3732 case WM_EMACS_SETWINDOWPOS
:
3734 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
3735 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
3736 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
3739 case WM_EMACS_DESTROYWINDOW
:
3740 DragAcceptFiles ((HWND
) wParam
, FALSE
);
3741 return DestroyWindow ((HWND
) wParam
);
3743 case WM_EMACS_HIDE_CARET
:
3744 return HideCaret (hwnd
);
3746 case WM_EMACS_SHOW_CARET
:
3747 return ShowCaret (hwnd
);
3749 case WM_EMACS_DESTROY_CARET
:
3750 w32_system_caret_hwnd
= NULL
;
3751 w32_visible_system_caret_hwnd
= NULL
;
3752 return DestroyCaret ();
3754 case WM_EMACS_TRACK_CARET
:
3755 /* If there is currently no system caret, create one. */
3756 if (w32_system_caret_hwnd
== NULL
)
3758 /* Use the default caret width, and avoid changing it
3759 unnecessarily, as it confuses screen reader software. */
3760 w32_system_caret_hwnd
= hwnd
;
3761 CreateCaret (hwnd
, NULL
, 0,
3762 w32_system_caret_height
);
3765 if (!SetCaretPos (w32_system_caret_x
, w32_system_caret_y
))
3767 /* Ensure visible caret gets turned on when requested. */
3768 else if (w32_use_visible_system_caret
3769 && w32_visible_system_caret_hwnd
!= hwnd
)
3771 w32_visible_system_caret_hwnd
= hwnd
;
3772 return ShowCaret (hwnd
);
3774 /* Ensure visible caret gets turned off when requested. */
3775 else if (!w32_use_visible_system_caret
3776 && w32_visible_system_caret_hwnd
)
3778 w32_visible_system_caret_hwnd
= NULL
;
3779 return HideCaret (hwnd
);
3784 case WM_EMACS_TRACKPOPUPMENU
:
3789 pos
= (POINT
*)lParam
;
3790 flags
= TPM_CENTERALIGN
;
3791 if (button_state
& LMOUSE
)
3792 flags
|= TPM_LEFTBUTTON
;
3793 else if (button_state
& RMOUSE
)
3794 flags
|= TPM_RIGHTBUTTON
;
3796 /* Remember we did a SetCapture on the initial mouse down event,
3797 so for safety, we make sure the capture is canceled now. */
3801 /* Use menubar_active to indicate that WM_INITMENU is from
3802 TrackPopupMenu below, and should be ignored. */
3803 f
= x_window_to_frame (dpyinfo
, hwnd
);
3805 f
->output_data
.w32
->menubar_active
= 1;
3807 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
3811 /* Eat any mouse messages during popupmenu */
3812 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
3814 /* Get the menu selection, if any */
3815 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
3817 retval
= LOWORD (amsg
.wParam
);
3833 /* Check for messages registered at runtime. */
3834 if (msg
== msh_mousewheel
)
3836 wmsg
.dwModifiers
= w32_get_modifiers ();
3837 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3838 signal_user_input ();
3843 return (w32_unicode_gui
? DefWindowProcW
: DefWindowProcA
) (hwnd
, msg
, wParam
, lParam
);
3846 /* The most common default return code for handled messages is 0. */
3851 my_create_window (struct frame
* f
)
3855 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
3857 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
3861 /* Create a tooltip window. Unlike my_create_window, we do not do this
3862 indirectly via the Window thread, as we do not need to process Window
3863 messages for the tooltip. Creating tooltips indirectly also creates
3864 deadlocks when tooltips are created for menu items. */
3866 my_create_tip_window (struct frame
*f
)
3870 rect
.left
= rect
.top
= 0;
3871 rect
.right
= FRAME_PIXEL_WIDTH (f
);
3872 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
3874 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
3875 FRAME_EXTERNAL_MENU_BAR (f
));
3877 tip_window
= FRAME_W32_WINDOW (f
)
3878 = CreateWindow (EMACS_CLASS
,
3880 f
->output_data
.w32
->dwStyle
,
3883 rect
.right
- rect
.left
,
3884 rect
.bottom
- rect
.top
,
3885 FRAME_W32_WINDOW (SELECTED_FRAME ()), /* owner */
3892 SetWindowLong (tip_window
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
3893 SetWindowLong (tip_window
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
3894 SetWindowLong (tip_window
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
3895 SetWindowLong (tip_window
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
3897 /* Tip frames have no scrollbars. */
3898 SetWindowLong (tip_window
, WND_SCROLLBAR_INDEX
, 0);
3900 /* Do this to discard the default setting specified by our parent. */
3901 ShowWindow (tip_window
, SW_HIDE
);
3906 /* Create and set up the w32 window for frame F. */
3909 w32_window (struct frame
*f
, long window_prompting
, int minibuffer_only
)
3913 /* Use the resource name as the top-level window name
3914 for looking up resources. Make a non-Lisp copy
3915 for the window manager, so GC relocation won't bother it.
3917 Elsewhere we specify the window name for the window manager. */
3920 char *str
= SSDATA (Vx_resource_name
);
3921 f
->namebuf
= xmalloc (strlen (str
) + 1);
3922 strcpy (f
->namebuf
, str
);
3925 my_create_window (f
);
3927 validate_x_resource_name ();
3929 /* x_set_name normally ignores requests to set the name if the
3930 requested name is the same as the current name. This is the one
3931 place where that assumption isn't correct; f->name is set, but
3932 the server hasn't been told. */
3935 int explicit = f
->explicit_name
;
3937 f
->explicit_name
= 0;
3939 fset_name (f
, Qnil
);
3940 x_set_name (f
, name
, explicit);
3945 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
3946 initialize_frame_menubar (f
);
3948 if (FRAME_W32_WINDOW (f
) == 0)
3949 error ("Unable to create window");
3952 /* Handle the icon stuff for this window. Perhaps later we might
3953 want an x_set_icon_position which can be called interactively as
3957 x_icon (struct frame
*f
, Lisp_Object parms
)
3959 Lisp_Object icon_x
, icon_y
;
3960 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
3962 /* Set the position of the icon. Note that Windows 95 groups all
3963 icons in the tray. */
3964 icon_x
= x_get_arg (dpyinfo
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
3965 icon_y
= x_get_arg (dpyinfo
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
3966 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
3968 CHECK_NUMBER (icon_x
);
3969 CHECK_NUMBER (icon_y
);
3971 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
3972 error ("Both left and top icon corners of icon must be specified");
3976 if (! EQ (icon_x
, Qunbound
))
3977 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
3980 /* Start up iconic or window? */
3981 x_wm_set_window_state
3982 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
3986 x_text_icon (f
, SSDATA ((!NILP (f
->icon_name
)
3996 x_make_gc (struct frame
*f
)
3998 XGCValues gc_values
;
4002 /* Create the GC's of this frame.
4003 Note that many default values are used. */
4006 gc_values
.font
= FRAME_FONT (f
);
4008 /* Cursor has cursor-color background, background-color foreground. */
4009 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
4010 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
4011 f
->output_data
.w32
->cursor_gc
4012 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
4013 (GCFont
| GCForeground
| GCBackground
),
4017 f
->output_data
.w32
->white_relief
.gc
= 0;
4018 f
->output_data
.w32
->black_relief
.gc
= 0;
4024 /* Handler for signals raised during x_create_frame and
4025 x_create_tip_frame. FRAME is the frame which is partially
4029 unwind_create_frame (Lisp_Object frame
)
4031 struct frame
*f
= XFRAME (frame
);
4033 /* If frame is ``official'', nothing to do. */
4034 if (NILP (Fmemq (frame
, Vframe_list
)))
4037 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4040 x_free_frame_resources (f
);
4044 /* Check that reference counts are indeed correct. */
4045 eassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
4046 eassert (dpyinfo
->terminal
->image_cache
->refcount
== image_cache_refcount
);
4055 x_default_font_parameter (struct frame
*f
, Lisp_Object parms
)
4057 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4058 Lisp_Object font_param
= x_get_arg (dpyinfo
, parms
, Qfont
, NULL
, NULL
,
4061 if (EQ (font_param
, Qunbound
))
4063 font
= !NILP (font_param
) ? font_param
4064 : x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4066 if (!STRINGP (font
))
4069 static char *names
[]
4070 = { "Courier New-10",
4071 "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1",
4072 "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1",
4076 for (i
= 0; names
[i
]; i
++)
4078 font
= font_open_by_name (f
, build_unibyte_string (names
[i
]));
4083 error ("No suitable font was found");
4085 else if (!NILP (font_param
))
4087 /* Remember the explicit font parameter, so we can re-apply it after
4088 we've applied the `default' face settings. */
4089 x_set_frame_parameters (f
, Fcons (Fcons (Qfont_param
, font_param
), Qnil
));
4091 x_default_parameter (f
, parms
, Qfont
, font
, "font", "Font", RES_TYPE_STRING
);
4094 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
4096 doc
: /* Make a new window, which is called a \"frame\" in Emacs terms.
4097 Return an Emacs frame object.
4098 PARAMETERS is an alist of frame parameters.
4099 If the parameters specify that the frame should not have a minibuffer,
4100 and do not specify a specific minibuffer window to use,
4101 then `default-minibuffer-frame' must be a frame whose minibuffer can
4102 be shared by the new frame.
4104 This function is an internal primitive--use `make-frame' instead. */)
4105 (Lisp_Object parameters
)
4108 Lisp_Object frame
, tem
;
4110 int minibuffer_only
= 0;
4111 long window_prompting
= 0;
4113 ptrdiff_t count
= SPECPDL_INDEX ();
4114 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4115 Lisp_Object display
;
4116 struct w32_display_info
*dpyinfo
= NULL
;
4120 /* Make copy of frame parameters because the original is in pure
4122 parameters
= Fcopy_alist (parameters
);
4124 /* Use this general default value to start with
4125 until we know if this frame has a specified name. */
4126 Vx_resource_name
= Vinvocation_name
;
4128 display
= x_get_arg (dpyinfo
, parameters
, Qterminal
, 0, 0, RES_TYPE_NUMBER
);
4129 if (EQ (display
, Qunbound
))
4130 display
= x_get_arg (dpyinfo
, parameters
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
4131 if (EQ (display
, Qunbound
))
4133 dpyinfo
= check_x_display_info (display
);
4134 kb
= dpyinfo
->terminal
->kboard
;
4136 if (!dpyinfo
->terminal
->name
)
4137 error ("Terminal is not live, can't create new frames on it");
4139 name
= x_get_arg (dpyinfo
, parameters
, Qname
, "name", "Name", RES_TYPE_STRING
);
4141 && ! EQ (name
, Qunbound
)
4143 error ("Invalid frame name--not a string or nil");
4146 Vx_resource_name
= name
;
4148 /* See if parent window is specified. */
4149 parent
= x_get_arg (dpyinfo
, parameters
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
4150 if (EQ (parent
, Qunbound
))
4152 if (! NILP (parent
))
4153 CHECK_NUMBER (parent
);
4155 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
4156 /* No need to protect DISPLAY because that's not used after passing
4157 it to make_frame_without_minibuffer. */
4159 GCPRO4 (parameters
, parent
, name
, frame
);
4160 tem
= x_get_arg (dpyinfo
, parameters
, Qminibuffer
, "minibuffer", "Minibuffer",
4162 if (EQ (tem
, Qnone
) || NILP (tem
))
4163 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
4164 else if (EQ (tem
, Qonly
))
4166 f
= make_minibuffer_frame ();
4167 minibuffer_only
= 1;
4169 else if (WINDOWP (tem
))
4170 f
= make_frame_without_minibuffer (tem
, kb
, display
);
4174 XSETFRAME (frame
, f
);
4176 /* Note that Windows does support scroll bars. */
4177 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
4179 /* By default, make scrollbars the system standard width. */
4180 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
4182 f
->terminal
= dpyinfo
->terminal
;
4184 f
->output_method
= output_w32
;
4185 f
->output_data
.w32
= xzalloc (sizeof (struct w32_output
));
4186 FRAME_FONTSET (f
) = -1;
4189 (f
, x_get_arg (dpyinfo
, parameters
, Qicon_name
, "iconName", "Title",
4191 if (! STRINGP (f
->icon_name
))
4192 fset_icon_name (f
, Qnil
);
4194 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
4196 /* With FRAME_X_DISPLAY_INFO set up, this unwind-protect is safe. */
4197 record_unwind_protect (unwind_create_frame
, frame
);
4199 image_cache_refcount
=
4200 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
4201 dpyinfo_refcount
= dpyinfo
->reference_count
;
4202 #endif /* GLYPH_DEBUG */
4204 /* Specify the parent under which to make this window. */
4208 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
4209 f
->output_data
.w32
->explicit_parent
= 1;
4213 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4214 f
->output_data
.w32
->explicit_parent
= 0;
4217 /* Set the name; the functions to which we pass f expect the name to
4219 if (EQ (name
, Qunbound
) || NILP (name
))
4221 fset_name (f
, build_string (dpyinfo
->w32_id_name
));
4222 f
->explicit_name
= 0;
4226 fset_name (f
, name
);
4227 f
->explicit_name
= 1;
4228 /* use the frame's title when getting resources for this frame. */
4229 specbind (Qx_resource_name
, name
);
4232 f
->resx
= dpyinfo
->resx
;
4233 f
->resy
= dpyinfo
->resy
;
4235 if (uniscribe_available
)
4236 register_font_driver (&uniscribe_font_driver
, f
);
4237 register_font_driver (&w32font_driver
, f
);
4239 x_default_parameter (f
, parameters
, Qfont_backend
, Qnil
,
4240 "fontBackend", "FontBackend", RES_TYPE_STRING
);
4241 /* Extract the window parameters from the supplied values
4242 that are needed to determine window geometry. */
4243 x_default_font_parameter (f
, parameters
);
4244 x_default_parameter (f
, parameters
, Qborder_width
, make_number (2),
4245 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4247 /* We recognize either internalBorderWidth or internalBorder
4248 (which is what xterm calls it). */
4249 if (NILP (Fassq (Qinternal_border_width
, parameters
)))
4253 value
= x_get_arg (dpyinfo
, parameters
, Qinternal_border_width
,
4254 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
4255 if (! EQ (value
, Qunbound
))
4256 parameters
= Fcons (Fcons (Qinternal_border_width
, value
),
4259 /* Default internalBorderWidth to 0 on Windows to match other programs. */
4260 x_default_parameter (f
, parameters
, Qinternal_border_width
, make_number (0),
4261 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
4262 x_default_parameter (f
, parameters
, Qvertical_scroll_bars
, Qright
,
4263 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
4265 /* Also do the stuff which must be set before the window exists. */
4266 x_default_parameter (f
, parameters
, Qforeground_color
, build_string ("black"),
4267 "foreground", "Foreground", RES_TYPE_STRING
);
4268 x_default_parameter (f
, parameters
, Qbackground_color
, build_string ("white"),
4269 "background", "Background", RES_TYPE_STRING
);
4270 x_default_parameter (f
, parameters
, Qmouse_color
, build_string ("black"),
4271 "pointerColor", "Foreground", RES_TYPE_STRING
);
4272 x_default_parameter (f
, parameters
, Qborder_color
, build_string ("black"),
4273 "borderColor", "BorderColor", RES_TYPE_STRING
);
4274 x_default_parameter (f
, parameters
, Qscreen_gamma
, Qnil
,
4275 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
4276 x_default_parameter (f
, parameters
, Qline_spacing
, Qnil
,
4277 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
4278 x_default_parameter (f
, parameters
, Qleft_fringe
, Qnil
,
4279 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
4280 x_default_parameter (f
, parameters
, Qright_fringe
, Qnil
,
4281 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
4283 /* Init faces before x_default_parameter is called for scroll-bar
4284 parameters because that function calls x_set_scroll_bar_width,
4285 which calls change_frame_size, which calls Fset_window_buffer,
4286 which runs hooks, which call Fvertical_motion. At the end, we
4287 end up in init_iterator with a null face cache, which should not
4289 init_frame_faces (f
);
4291 /* The X resources controlling the menu-bar and tool-bar are
4292 processed specially at startup, and reflected in the mode
4293 variables; ignore them here. */
4294 x_default_parameter (f
, parameters
, Qmenu_bar_lines
,
4295 NILP (Vmenu_bar_mode
)
4296 ? make_number (0) : make_number (1),
4297 NULL
, NULL
, RES_TYPE_NUMBER
);
4298 x_default_parameter (f
, parameters
, Qtool_bar_lines
,
4299 NILP (Vtool_bar_mode
)
4300 ? make_number (0) : make_number (1),
4301 NULL
, NULL
, RES_TYPE_NUMBER
);
4303 x_default_parameter (f
, parameters
, Qbuffer_predicate
, Qnil
,
4304 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
4305 x_default_parameter (f
, parameters
, Qtitle
, Qnil
,
4306 "title", "Title", RES_TYPE_STRING
);
4307 x_default_parameter (f
, parameters
, Qfullscreen
, Qnil
,
4308 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
4310 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
4311 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4313 f
->output_data
.w32
->text_cursor
= w32_load_cursor (IDC_IBEAM
);
4314 f
->output_data
.w32
->nontext_cursor
= w32_load_cursor (IDC_ARROW
);
4315 f
->output_data
.w32
->modeline_cursor
= w32_load_cursor (IDC_ARROW
);
4316 f
->output_data
.w32
->hand_cursor
= w32_load_cursor (IDC_HAND
);
4317 f
->output_data
.w32
->hourglass_cursor
= w32_load_cursor (IDC_WAIT
);
4318 f
->output_data
.w32
->horizontal_drag_cursor
= w32_load_cursor (IDC_SIZEWE
);
4320 f
->output_data
.w32
->current_cursor
= f
->output_data
.w32
->nontext_cursor
;
4322 window_prompting
= x_figure_window_size (f
, parameters
, 1);
4324 tem
= x_get_arg (dpyinfo
, parameters
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
4325 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
4327 w32_window (f
, window_prompting
, minibuffer_only
);
4328 x_icon (f
, parameters
);
4332 /* Now consider the frame official. */
4333 f
->terminal
->reference_count
++;
4334 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
4335 Vframe_list
= Fcons (frame
, Vframe_list
);
4337 /* We need to do this after creating the window, so that the
4338 icon-creation functions can say whose icon they're describing. */
4339 x_default_parameter (f
, parameters
, Qicon_type
, Qnil
,
4340 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
4342 x_default_parameter (f
, parameters
, Qauto_raise
, Qnil
,
4343 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4344 x_default_parameter (f
, parameters
, Qauto_lower
, Qnil
,
4345 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4346 x_default_parameter (f
, parameters
, Qcursor_type
, Qbox
,
4347 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4348 x_default_parameter (f
, parameters
, Qscroll_bar_width
, Qnil
,
4349 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
4350 x_default_parameter (f
, parameters
, Qalpha
, Qnil
,
4351 "alpha", "Alpha", RES_TYPE_NUMBER
);
4353 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4354 Change will not be effected unless different from the current
4356 width
= FRAME_COLS (f
);
4357 height
= FRAME_LINES (f
);
4359 FRAME_LINES (f
) = 0;
4360 SET_FRAME_COLS (f
, 0);
4361 change_frame_size (f
, height
, width
, 1, 0, 0);
4363 /* Tell the server what size and position, etc, we want, and how
4364 badly we want them. This should be done after we have the menu
4365 bar so that its size can be taken into account. */
4367 x_wm_set_size_hint (f
, window_prompting
, 0);
4370 /* Make the window appear on the frame and enable display, unless
4371 the caller says not to. However, with explicit parent, Emacs
4372 cannot control visibility, so don't try. */
4373 if (! f
->output_data
.w32
->explicit_parent
)
4375 Lisp_Object visibility
;
4377 visibility
= x_get_arg (dpyinfo
, parameters
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
4378 if (EQ (visibility
, Qunbound
))
4381 if (EQ (visibility
, Qicon
))
4382 x_iconify_frame (f
);
4383 else if (! NILP (visibility
))
4384 x_make_frame_visible (f
);
4386 /* Must have been Qnil. */
4390 /* Initialize `default-minibuffer-frame' in case this is the first
4391 frame on this terminal. */
4392 if (FRAME_HAS_MINIBUF_P (f
)
4393 && (!FRAMEP (KVAR (kb
, Vdefault_minibuffer_frame
))
4394 || !FRAME_LIVE_P (XFRAME (KVAR (kb
, Vdefault_minibuffer_frame
)))))
4395 kset_default_minibuffer_frame (kb
, frame
);
4397 /* All remaining specified parameters, which have not been "used"
4398 by x_get_arg and friends, now go in the misc. alist of the frame. */
4399 for (tem
= parameters
; CONSP (tem
); tem
= XCDR (tem
))
4400 if (CONSP (XCAR (tem
)) && !NILP (XCAR (XCAR (tem
))))
4401 fset_param_alist (f
, Fcons (XCAR (tem
), f
->param_alist
));
4405 /* Make sure windows on this frame appear in calls to next-window
4406 and similar functions. */
4407 Vwindow_list
= Qnil
;
4409 return unbind_to (count
, frame
);
4412 /* FRAME is used only to get a handle on the X display. We don't pass the
4413 display info directly because we're called from frame.c, which doesn't
4414 know about that structure. */
4416 x_get_focus_frame (struct frame
*frame
)
4418 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
4420 if (! dpyinfo
->w32_focus_frame
)
4423 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
4427 DEFUN ("x-focus-frame", Fx_focus_frame
, Sx_focus_frame
, 1, 1, 0,
4428 doc
: /* Give FRAME input focus, raising to foreground if necessary. */)
4431 x_focus_on_frame (check_x_frame (frame
));
4436 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
4437 doc
: /* Internal function called by `color-defined-p', which see.
4438 \(Note that the Nextstep version of this function ignores FRAME.) */)
4439 (Lisp_Object color
, Lisp_Object frame
)
4442 FRAME_PTR f
= check_x_frame (frame
);
4444 CHECK_STRING (color
);
4446 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
4452 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
4453 doc
: /* Internal function called by `color-values', which see. */)
4454 (Lisp_Object color
, Lisp_Object frame
)
4457 FRAME_PTR f
= check_x_frame (frame
);
4459 CHECK_STRING (color
);
4461 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
4462 return list3 (make_number ((GetRValue (foo
.pixel
) << 8)
4463 | GetRValue (foo
.pixel
)),
4464 make_number ((GetGValue (foo
.pixel
) << 8)
4465 | GetGValue (foo
.pixel
)),
4466 make_number ((GetBValue (foo
.pixel
) << 8)
4467 | GetBValue (foo
.pixel
)));
4472 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
4473 doc
: /* Internal function called by `display-color-p', which see. */)
4474 (Lisp_Object display
)
4476 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4478 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
4484 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
,
4485 Sx_display_grayscale_p
, 0, 1, 0,
4486 doc
: /* Return t if DISPLAY supports shades of gray.
4487 Note that color displays do support shades of gray.
4488 The optional argument DISPLAY specifies which display to ask about.
4489 DISPLAY should be either a frame or a display name (a string).
4490 If omitted or nil, that stands for the selected frame's display. */)
4491 (Lisp_Object display
)
4493 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4495 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
4501 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
,
4502 Sx_display_pixel_width
, 0, 1, 0,
4503 doc
: /* Return the width in pixels of DISPLAY.
4504 The optional argument DISPLAY specifies which display to ask about.
4505 DISPLAY should be either a frame or a display name (a string).
4506 If omitted or nil, that stands for the selected frame's display. */)
4507 (Lisp_Object display
)
4509 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4511 return make_number (x_display_pixel_width (dpyinfo
));
4514 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
4515 Sx_display_pixel_height
, 0, 1, 0,
4516 doc
: /* Return the height in pixels of DISPLAY.
4517 The optional argument DISPLAY specifies which display to ask about.
4518 DISPLAY should be either a frame or a display name (a string).
4519 If omitted or nil, that stands for the selected frame's display. */)
4520 (Lisp_Object display
)
4522 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4524 return make_number (x_display_pixel_height (dpyinfo
));
4527 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
4529 doc
: /* Return the number of bitplanes of DISPLAY.
4530 The optional argument DISPLAY specifies which display to ask about.
4531 DISPLAY should be either a frame or a display name (a string).
4532 If omitted or nil, that stands for the selected frame's display. */)
4533 (Lisp_Object display
)
4535 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4537 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
4540 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
4542 doc
: /* Return the number of color cells of DISPLAY.
4543 The optional argument DISPLAY specifies which display to ask about.
4544 DISPLAY should be either a frame or a display name (a string).
4545 If omitted or nil, that stands for the selected frame's display. */)
4546 (Lisp_Object display
)
4548 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4552 hdc
= GetDC (dpyinfo
->root_window
);
4553 if (dpyinfo
->has_palette
)
4554 cap
= GetDeviceCaps (hdc
, SIZEPALETTE
);
4556 cap
= GetDeviceCaps (hdc
, NUMCOLORS
);
4558 /* We force 24+ bit depths to 24-bit, both to prevent an overflow
4559 and because probably is more meaningful on Windows anyway */
4561 cap
= 1 << min (dpyinfo
->n_planes
* dpyinfo
->n_cbits
, 24);
4563 ReleaseDC (dpyinfo
->root_window
, hdc
);
4565 return make_number (cap
);
4568 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
4569 Sx_server_max_request_size
,
4571 doc
: /* Return the maximum request size of the server of DISPLAY.
4572 The optional argument DISPLAY specifies which display to ask about.
4573 DISPLAY should be either a frame or a display name (a string).
4574 If omitted or nil, that stands for the selected frame's display. */)
4575 (Lisp_Object display
)
4577 return make_number (1);
4580 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
4581 doc
: /* Return the "vendor ID" string of the W32 system (Microsoft).
4582 The optional argument DISPLAY specifies which display to ask about.
4583 DISPLAY should be either a frame or a display name (a string).
4584 If omitted or nil, that stands for the selected frame's display. */)
4585 (Lisp_Object display
)
4587 return build_string ("Microsoft Corp.");
4590 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
4591 doc
: /* Return the version numbers of the server of DISPLAY.
4592 The value is a list of three integers: the major and minor
4593 version numbers of the X Protocol in use, and the distributor-specific
4594 release number. See also the function `x-server-vendor'.
4596 The optional argument DISPLAY specifies which display to ask about.
4597 DISPLAY should be either a frame or a display name (a string).
4598 If omitted or nil, that stands for the selected frame's display. */)
4599 (Lisp_Object display
)
4601 return Fcons (make_number (w32_major_version
),
4602 Fcons (make_number (w32_minor_version
),
4603 Fcons (make_number (w32_build_number
), Qnil
)));
4606 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
4607 doc
: /* Return the number of screens on the server of DISPLAY.
4608 The optional argument DISPLAY specifies which display to ask about.
4609 DISPLAY should be either a frame or a display name (a string).
4610 If omitted or nil, that stands for the selected frame's display. */)
4611 (Lisp_Object display
)
4613 return make_number (1);
4616 DEFUN ("x-display-mm-height", Fx_display_mm_height
,
4617 Sx_display_mm_height
, 0, 1, 0,
4618 doc
: /* Return the height in millimeters of DISPLAY.
4619 The optional argument DISPLAY specifies which display to ask about.
4620 DISPLAY should be either a frame or a display name (a string).
4621 If omitted or nil, that stands for the selected frame's display. */)
4622 (Lisp_Object display
)
4624 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4628 hdc
= GetDC (dpyinfo
->root_window
);
4630 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
4632 ReleaseDC (dpyinfo
->root_window
, hdc
);
4634 return make_number (cap
);
4637 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
4638 doc
: /* Return the width in millimeters of DISPLAY.
4639 The optional argument DISPLAY specifies which display to ask about.
4640 DISPLAY should be either a frame or a display name (a string).
4641 If omitted or nil, that stands for the selected frame's display. */)
4642 (Lisp_Object display
)
4644 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4649 hdc
= GetDC (dpyinfo
->root_window
);
4651 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
4653 ReleaseDC (dpyinfo
->root_window
, hdc
);
4655 return make_number (cap
);
4658 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
4659 Sx_display_backing_store
, 0, 1, 0,
4660 doc
: /* Return an indication of whether DISPLAY does backing store.
4661 The value may be `always', `when-mapped', or `not-useful'.
4662 The optional argument DISPLAY specifies which display to ask about.
4663 DISPLAY should be either a frame or a display name (a string).
4664 If omitted or nil, that stands for the selected frame's display. */)
4665 (Lisp_Object display
)
4667 return intern ("not-useful");
4670 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
4671 Sx_display_visual_class
, 0, 1, 0,
4672 doc
: /* Return the visual class of DISPLAY.
4673 The value is one of the symbols `static-gray', `gray-scale',
4674 `static-color', `pseudo-color', `true-color', or `direct-color'.
4676 The optional argument DISPLAY specifies which display to ask about.
4677 DISPLAY should be either a frame or a display name (a string).
4678 If omitted or nil, that stands for the selected frame's display. */)
4679 (Lisp_Object display
)
4681 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4682 Lisp_Object result
= Qnil
;
4684 if (dpyinfo
->has_palette
)
4685 result
= intern ("pseudo-color");
4686 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
4687 result
= intern ("static-grey");
4688 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
4689 result
= intern ("static-color");
4690 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
4691 result
= intern ("true-color");
4696 DEFUN ("x-display-save-under", Fx_display_save_under
,
4697 Sx_display_save_under
, 0, 1, 0,
4698 doc
: /* Return t if DISPLAY supports the save-under feature.
4699 The optional argument DISPLAY specifies which display to ask about.
4700 DISPLAY should be either a frame or a display name (a string).
4701 If omitted or nil, that stands for the selected frame's display. */)
4702 (Lisp_Object display
)
4708 x_pixel_width (register struct frame
*f
)
4710 return FRAME_PIXEL_WIDTH (f
);
4714 x_pixel_height (register struct frame
*f
)
4716 return FRAME_PIXEL_HEIGHT (f
);
4720 x_char_width (register struct frame
*f
)
4722 return FRAME_COLUMN_WIDTH (f
);
4726 x_char_height (register struct frame
*f
)
4728 return FRAME_LINE_HEIGHT (f
);
4732 x_screen_planes (register struct frame
*f
)
4734 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
4737 /* Return the display structure for the display named NAME.
4738 Open a new connection if necessary. */
4740 struct w32_display_info
*
4741 x_display_info_for_name (Lisp_Object name
)
4744 struct w32_display_info
*dpyinfo
;
4746 CHECK_STRING (name
);
4748 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
4749 dpyinfo
&& !NILP (w32_display_name_list
);
4750 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
4753 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
4758 /* Use this general default value to start with. */
4759 Vx_resource_name
= Vinvocation_name
;
4761 validate_x_resource_name ();
4763 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
4764 SSDATA (Vx_resource_name
));
4767 error ("Cannot connect to server %s", SDATA (name
));
4770 XSETFASTINT (Vwindow_system_version
, w32_major_version
);
4775 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
4776 1, 3, 0, doc
: /* Open a connection to a display server.
4777 DISPLAY is the name of the display to connect to.
4778 Optional second arg XRM-STRING is a string of resources in xrdb format.
4779 If the optional third arg MUST-SUCCEED is non-nil,
4780 terminate Emacs if we can't open the connection.
4781 \(In the Nextstep version, the last two arguments are currently ignored.) */)
4782 (Lisp_Object display
, Lisp_Object xrm_string
, Lisp_Object must_succeed
)
4784 unsigned char *xrm_option
;
4785 struct w32_display_info
*dpyinfo
;
4787 /* If initialization has already been done, return now to avoid
4788 overwriting critical parts of one_w32_display_info. */
4792 CHECK_STRING (display
);
4793 if (! NILP (xrm_string
))
4794 CHECK_STRING (xrm_string
);
4797 if (! EQ (Vwindow_system
, intern ("w32")))
4798 error ("Not using Microsoft Windows");
4801 /* Allow color mapping to be defined externally; first look in user's
4802 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
4804 Lisp_Object color_file
;
4805 struct gcpro gcpro1
;
4807 color_file
= build_string ("~/rgb.txt");
4809 GCPRO1 (color_file
);
4811 if (NILP (Ffile_readable_p (color_file
)))
4813 Fexpand_file_name (build_string ("rgb.txt"),
4814 Fsymbol_value (intern ("data-directory")));
4816 Vw32_color_map
= Fx_load_color_file (color_file
);
4820 if (NILP (Vw32_color_map
))
4821 Vw32_color_map
= w32_default_color_map ();
4823 /* Merge in system logical colors. */
4824 add_system_logical_colors_to_map (&Vw32_color_map
);
4826 if (! NILP (xrm_string
))
4827 xrm_option
= SDATA (xrm_string
);
4829 xrm_option
= (unsigned char *) 0;
4831 /* Use this general default value to start with. */
4832 /* First remove .exe suffix from invocation-name - it looks ugly. */
4834 char basename
[ MAX_PATH
], *str
;
4836 strcpy (basename
, SDATA (Vinvocation_name
));
4837 str
= strrchr (basename
, '.');
4839 Vinvocation_name
= build_string (basename
);
4841 Vx_resource_name
= Vinvocation_name
;
4843 validate_x_resource_name ();
4845 /* This is what opens the connection and sets x_current_display.
4846 This also initializes many symbols, such as those used for input. */
4847 dpyinfo
= w32_term_init (display
, xrm_option
,
4848 SSDATA (Vx_resource_name
));
4852 if (!NILP (must_succeed
))
4853 fatal ("Cannot connect to server %s.\n",
4856 error ("Cannot connect to server %s", SDATA (display
));
4861 XSETFASTINT (Vwindow_system_version
, w32_major_version
);
4865 DEFUN ("x-close-connection", Fx_close_connection
,
4866 Sx_close_connection
, 1, 1, 0,
4867 doc
: /* Close the connection to DISPLAY's server.
4868 For DISPLAY, specify either a frame or a display name (a string).
4869 If DISPLAY is nil, that stands for the selected frame's display. */)
4870 (Lisp_Object display
)
4872 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4874 if (dpyinfo
->reference_count
> 0)
4875 error ("Display still has frames on it");
4878 x_destroy_all_bitmaps (dpyinfo
);
4880 x_delete_display (dpyinfo
);
4886 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
4887 doc
: /* Return the list of display names that Emacs has connections to. */)
4890 Lisp_Object tail
, result
;
4893 for (tail
= w32_display_name_list
; CONSP (tail
); tail
= XCDR (tail
))
4894 result
= Fcons (XCAR (XCAR (tail
)), result
);
4899 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
4900 doc
: /* If ON is non-nil, report X errors as soon as the erring request is made.
4901 This function only has an effect on X Windows. With MS Windows, it is
4902 defined but does nothing.
4904 If ON is nil, allow buffering of requests.
4905 Turning on synchronization prohibits the Xlib routines from buffering
4906 requests and seriously degrades performance, but makes debugging much
4908 The optional second argument TERMINAL specifies which display to act on.
4909 TERMINAL should be a terminal object, a frame or a display name (a string).
4910 If TERMINAL is omitted or nil, that stands for the selected frame's display. */)
4911 (Lisp_Object on
, Lisp_Object display
)
4918 /***********************************************************************
4920 ***********************************************************************/
4922 #if 0 /* TODO : port window properties to W32 */
4924 DEFUN ("x-change-window-property", Fx_change_window_property
,
4925 Sx_change_window_property
, 2, 6, 0,
4926 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
4927 PROP must be a string. VALUE may be a string or a list of conses,
4928 numbers and/or strings. If an element in the list is a string, it is
4929 converted to an atom and the value of the Atom is used. If an element
4930 is a cons, it is converted to a 32 bit number where the car is the 16
4931 top bits and the cdr is the lower 16 bits.
4933 FRAME nil or omitted means use the selected frame.
4934 If TYPE is given and non-nil, it is the name of the type of VALUE.
4935 If TYPE is not given or nil, the type is STRING.
4936 FORMAT gives the size in bits of each element if VALUE is a list.
4937 It must be one of 8, 16 or 32.
4938 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
4939 If OUTER-P is non-nil, the property is changed for the outer X window of
4940 FRAME. Default is to change on the edit X window. */)
4941 (Lisp_Object prop
, Lisp_Object value
, Lisp_Object frame
,
4942 Lisp_Object type
, Lisp_Object format
, Lisp_Object outer_p
)
4944 struct frame
*f
= check_x_frame (frame
);
4947 CHECK_STRING (prop
);
4948 CHECK_STRING (value
);
4951 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
4952 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
4953 prop_atom
, XA_STRING
, 8, PropModeReplace
,
4954 SDATA (value
), SCHARS (value
));
4956 /* Make sure the property is set when we return. */
4957 XFlush (FRAME_W32_DISPLAY (f
));
4964 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
4965 Sx_delete_window_property
, 1, 2, 0,
4966 doc
: /* Remove window property PROP from X window of FRAME.
4967 FRAME nil or omitted means use the selected frame. Value is PROP. */)
4968 (Lisp_Object prop
, Lisp_Object frame
)
4970 struct frame
*f
= check_x_frame (frame
);
4973 CHECK_STRING (prop
);
4975 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
4976 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
4978 /* Make sure the property is removed when we return. */
4979 XFlush (FRAME_W32_DISPLAY (f
));
4986 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
4988 doc
: /* Value is the value of window property PROP on FRAME.
4989 If FRAME is nil or omitted, use the selected frame.
4991 On X Windows, the following optional arguments are also accepted:
4992 If TYPE is nil or omitted, get the property as a string.
4993 Otherwise TYPE is the name of the atom that denotes the type expected.
4994 If SOURCE is non-nil, get the property on that window instead of from
4995 FRAME. The number 0 denotes the root window.
4996 If DELETE-P is non-nil, delete the property after retrieving it.
4997 If VECTOR-RET-P is non-nil, don't return a string but a vector of values.
4999 On MS Windows, this function accepts but ignores those optional arguments.
5001 Value is nil if FRAME hasn't a property with name PROP or if PROP has
5002 no value of TYPE (always string in the MS Windows case). */)
5003 (Lisp_Object prop
, Lisp_Object frame
, Lisp_Object type
,
5004 Lisp_Object source
, Lisp_Object delete_p
, Lisp_Object vector_ret_p
)
5006 struct frame
*f
= check_x_frame (frame
);
5009 Lisp_Object prop_value
= Qnil
;
5010 char *tmp_data
= NULL
;
5013 unsigned long actual_size
, bytes_remaining
;
5015 CHECK_STRING (prop
);
5017 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5018 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5019 prop_atom
, 0, 0, False
, XA_STRING
,
5020 &actual_type
, &actual_format
, &actual_size
,
5021 &bytes_remaining
, (unsigned char **) &tmp_data
);
5024 int size
= bytes_remaining
;
5029 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5030 prop_atom
, 0, bytes_remaining
,
5032 &actual_type
, &actual_format
,
5033 &actual_size
, &bytes_remaining
,
5034 (unsigned char **) &tmp_data
);
5036 prop_value
= make_string (tmp_data
, size
);
5051 /***********************************************************************
5053 ***********************************************************************/
5056 w32_note_current_window (void)
5058 struct frame
* f
= SELECTED_FRAME ();
5060 if (!FRAME_W32_P (f
))
5063 hourglass_hwnd
= FRAME_W32_WINDOW (f
);
5067 show_hourglass (struct atimer
*timer
)
5071 hourglass_atimer
= NULL
;
5074 f
= x_window_to_frame (&one_w32_display_info
,
5078 f
->output_data
.w32
->hourglass_p
= 0;
5080 f
= SELECTED_FRAME ();
5082 if (!FRAME_W32_P (f
))
5085 w32_show_hourglass (f
);
5090 hide_hourglass (void)
5093 w32_hide_hourglass ();
5098 /* Display an hourglass cursor. Set the hourglass_p flag in display info
5099 to indicate that an hourglass cursor is shown. */
5102 w32_show_hourglass (struct frame
*f
)
5104 if (!hourglass_shown_p
)
5106 f
->output_data
.w32
->hourglass_p
= 1;
5107 if (!menubar_in_use
&& !current_popup_menu
)
5108 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
5109 hourglass_shown_p
= 1;
5114 /* Hide the hourglass cursor on all frames, if it is currently shown. */
5117 w32_hide_hourglass (void)
5119 if (hourglass_shown_p
)
5121 struct frame
*f
= x_window_to_frame (&one_w32_display_info
,
5124 f
->output_data
.w32
->hourglass_p
= 0;
5126 /* If frame was deleted, restore to selected frame's cursor. */
5127 f
= SELECTED_FRAME ();
5129 if (FRAME_W32_P (f
))
5130 SetCursor (f
->output_data
.w32
->current_cursor
);
5132 /* No cursors on non GUI frames - restore to stock arrow cursor. */
5133 SetCursor (w32_load_cursor (IDC_ARROW
));
5135 hourglass_shown_p
= 0;
5141 /***********************************************************************
5143 ***********************************************************************/
5145 static Lisp_Object
x_create_tip_frame (struct w32_display_info
*,
5146 Lisp_Object
, Lisp_Object
);
5147 static void compute_tip_xy (struct frame
*, Lisp_Object
, Lisp_Object
,
5148 Lisp_Object
, int, int, int *, int *);
5150 /* The frame of a currently visible tooltip. */
5152 Lisp_Object tip_frame
;
5154 /* If non-nil, a timer started that hides the last tooltip when it
5157 Lisp_Object tip_timer
;
5160 /* If non-nil, a vector of 3 elements containing the last args
5161 with which x-show-tip was called. See there. */
5163 Lisp_Object last_show_tip_args
;
5167 unwind_create_tip_frame (Lisp_Object frame
)
5169 Lisp_Object deleted
;
5171 deleted
= unwind_create_frame (frame
);
5172 if (EQ (deleted
, Qt
))
5182 /* Create a frame for a tooltip on the display described by DPYINFO.
5183 PARMS is a list of frame parameters. TEXT is the string to
5184 display in the tip frame. Value is the frame.
5186 Note that functions called here, esp. x_default_parameter can
5187 signal errors, for instance when a specified color name is
5188 undefined. We have to make sure that we're in a consistent state
5189 when this happens. */
5192 x_create_tip_frame (struct w32_display_info
*dpyinfo
,
5193 Lisp_Object parms
, Lisp_Object text
)
5198 long window_prompting
= 0;
5200 ptrdiff_t count
= SPECPDL_INDEX ();
5201 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5203 int face_change_count_before
= face_change_count
;
5205 struct buffer
*old_buffer
;
5209 /* Use this general default value to start with until we know if
5210 this frame has a specified name. */
5211 Vx_resource_name
= Vinvocation_name
;
5213 kb
= dpyinfo
->terminal
->kboard
;
5215 /* The calls to x_get_arg remove elements from PARMS, so copy it to
5216 avoid destructive changes behind our caller's back. */
5217 parms
= Fcopy_alist (parms
);
5219 /* Get the name of the frame to use for resource lookup. */
5220 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
5222 && !EQ (name
, Qunbound
)
5224 error ("Invalid frame name--not a string or nil");
5225 Vx_resource_name
= name
;
5228 GCPRO3 (parms
, name
, frame
);
5229 /* Make a frame without minibuffer nor mode-line. */
5231 f
->wants_modeline
= 0;
5232 XSETFRAME (frame
, f
);
5234 buffer
= Fget_buffer_create (build_string (" *tip*"));
5235 /* Use set_window_buffer instead of Fset_window_buffer (see
5236 discussion of bug#11984, bug#12025, bug#12026). */
5237 set_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, 0, 0);
5238 old_buffer
= current_buffer
;
5239 set_buffer_internal_1 (XBUFFER (buffer
));
5240 bset_truncate_lines (current_buffer
, Qnil
);
5241 specbind (Qinhibit_read_only
, Qt
);
5242 specbind (Qinhibit_modification_hooks
, Qt
);
5245 set_buffer_internal_1 (old_buffer
);
5247 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
5248 record_unwind_protect (unwind_create_tip_frame
, frame
);
5250 /* By setting the output method, we're essentially saying that
5251 the frame is live, as per FRAME_LIVE_P. If we get a signal
5252 from this point on, x_destroy_window might screw up reference
5254 f
->terminal
= dpyinfo
->terminal
;
5255 f
->output_method
= output_w32
;
5256 f
->output_data
.w32
= xzalloc (sizeof (struct w32_output
));
5258 FRAME_FONTSET (f
) = -1;
5259 fset_icon_name (f
, Qnil
);
5262 image_cache_refcount
=
5263 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
5264 dpyinfo_refcount
= dpyinfo
->reference_count
;
5265 #endif /* GLYPH_DEBUG */
5266 FRAME_KBOARD (f
) = kb
;
5267 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5268 f
->output_data
.w32
->explicit_parent
= 0;
5270 /* Set the name; the functions to which we pass f expect the name to
5272 if (EQ (name
, Qunbound
) || NILP (name
))
5274 fset_name (f
, build_string (dpyinfo
->w32_id_name
));
5275 f
->explicit_name
= 0;
5279 fset_name (f
, name
);
5280 f
->explicit_name
= 1;
5281 /* use the frame's title when getting resources for this frame. */
5282 specbind (Qx_resource_name
, name
);
5285 f
->resx
= dpyinfo
->resx
;
5286 f
->resy
= dpyinfo
->resy
;
5288 if (uniscribe_available
)
5289 register_font_driver (&uniscribe_font_driver
, f
);
5290 register_font_driver (&w32font_driver
, f
);
5292 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
5293 "fontBackend", "FontBackend", RES_TYPE_STRING
);
5295 /* Extract the window parameters from the supplied values
5296 that are needed to determine window geometry. */
5297 x_default_font_parameter (f
, parms
);
5299 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
5300 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5301 /* This defaults to 2 in order to match xterm. We recognize either
5302 internalBorderWidth or internalBorder (which is what xterm calls
5304 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5308 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
5309 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
5310 if (! EQ (value
, Qunbound
))
5311 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
5314 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
5315 "internalBorderWidth", "internalBorderWidth",
5318 /* Also do the stuff which must be set before the window exists. */
5319 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
5320 "foreground", "Foreground", RES_TYPE_STRING
);
5321 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
5322 "background", "Background", RES_TYPE_STRING
);
5323 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
5324 "pointerColor", "Foreground", RES_TYPE_STRING
);
5325 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
5326 "cursorColor", "Foreground", RES_TYPE_STRING
);
5327 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
5328 "borderColor", "BorderColor", RES_TYPE_STRING
);
5330 /* Init faces before x_default_parameter is called for scroll-bar
5331 parameters because that function calls x_set_scroll_bar_width,
5332 which calls change_frame_size, which calls Fset_window_buffer,
5333 which runs hooks, which call Fvertical_motion. At the end, we
5334 end up in init_iterator with a null face cache, which should not
5336 init_frame_faces (f
);
5338 f
->output_data
.w32
->dwStyle
= WS_BORDER
| WS_POPUP
| WS_DISABLED
;
5339 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5341 window_prompting
= x_figure_window_size (f
, parms
, 0);
5343 /* No fringes on tip frame. */
5345 f
->left_fringe_width
= 0;
5346 f
->right_fringe_width
= 0;
5349 my_create_tip_window (f
);
5354 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
5355 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5356 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5357 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5358 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5359 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5361 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
5362 Change will not be effected unless different from the current
5364 width
= FRAME_COLS (f
);
5365 height
= FRAME_LINES (f
);
5366 FRAME_LINES (f
) = 0;
5367 SET_FRAME_COLS (f
, 0);
5368 change_frame_size (f
, height
, width
, 1, 0, 0);
5370 /* Add `tooltip' frame parameter's default value. */
5371 if (NILP (Fframe_parameter (frame
, Qtooltip
)))
5372 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qtooltip
, Qt
), Qnil
));
5374 /* Set up faces after all frame parameters are known. This call
5375 also merges in face attributes specified for new frames.
5377 Frame parameters may be changed if .Xdefaults contains
5378 specifications for the default font. For example, if there is an
5379 `Emacs.default.attributeBackground: pink', the `background-color'
5380 attribute of the frame get's set, which let's the internal border
5381 of the tooltip frame appear in pink. Prevent this. */
5383 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
5384 Lisp_Object fg
= Fframe_parameter (frame
, Qforeground_color
);
5385 Lisp_Object colors
= Qnil
;
5387 /* Set tip_frame here, so that */
5389 call2 (Qface_set_after_frame_default
, frame
, Qnil
);
5391 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
5392 colors
= Fcons (Fcons (Qbackground_color
, bg
), colors
);
5393 if (!EQ (fg
, Fframe_parameter (frame
, Qforeground_color
)))
5394 colors
= Fcons (Fcons (Qforeground_color
, fg
), colors
);
5397 Fmodify_frame_parameters (frame
, colors
);
5404 /* Now that the frame is official, it counts as a reference to
5406 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
5407 f
->terminal
->reference_count
++;
5409 /* It is now ok to make the frame official even if we get an error
5410 below. And the frame needs to be on Vframe_list or making it
5411 visible won't work. */
5412 Vframe_list
= Fcons (frame
, Vframe_list
);
5414 /* Setting attributes of faces of the tooltip frame from resources
5415 and similar will increment face_change_count, which leads to the
5416 clearing of all current matrices. Since this isn't necessary
5417 here, avoid it by resetting face_change_count to the value it
5418 had before we created the tip frame. */
5419 face_change_count
= face_change_count_before
;
5421 /* Discard the unwind_protect. */
5422 return unbind_to (count
, frame
);
5426 /* Compute where to display tip frame F. PARMS is the list of frame
5427 parameters for F. DX and DY are specified offsets from the current
5428 location of the mouse. WIDTH and HEIGHT are the width and height
5429 of the tooltip. Return coordinates relative to the root window of
5430 the display in *ROOT_X, and *ROOT_Y. */
5433 compute_tip_xy (struct frame
*f
,
5434 Lisp_Object parms
, Lisp_Object dx
, Lisp_Object dy
,
5435 int width
, int height
, int *root_x
, int *root_y
)
5437 Lisp_Object left
, top
;
5438 int min_x
, min_y
, max_x
, max_y
;
5440 /* User-specified position? */
5441 left
= Fcdr (Fassq (Qleft
, parms
));
5442 top
= Fcdr (Fassq (Qtop
, parms
));
5444 /* Move the tooltip window where the mouse pointer is. Resize and
5446 if (!INTEGERP (left
) || !INTEGERP (top
))
5450 /* Default min and max values. */
5453 max_x
= x_display_pixel_width (FRAME_W32_DISPLAY_INFO (f
));
5454 max_y
= x_display_pixel_height (FRAME_W32_DISPLAY_INFO (f
));
5462 /* If multiple monitor support is available, constrain the tip onto
5463 the current monitor. This improves the above by allowing negative
5464 co-ordinates if monitor positions are such that they are valid, and
5465 snaps a tooltip onto a single monitor if we are close to the edge
5466 where it would otherwise flow onto the other monitor (or into
5467 nothingness if there is a gap in the overlap). */
5468 if (monitor_from_point_fn
&& get_monitor_info_fn
)
5470 struct MONITOR_INFO info
;
5472 = monitor_from_point_fn (pt
, MONITOR_DEFAULT_TO_NEAREST
);
5473 info
.cbSize
= sizeof (info
);
5475 if (get_monitor_info_fn (monitor
, &info
))
5477 min_x
= info
.rcWork
.left
;
5478 min_y
= info
.rcWork
.top
;
5479 max_x
= info
.rcWork
.right
;
5480 max_y
= info
.rcWork
.bottom
;
5486 *root_y
= XINT (top
);
5487 else if (*root_y
+ XINT (dy
) <= min_y
)
5488 *root_y
= min_y
; /* Can happen for negative dy */
5489 else if (*root_y
+ XINT (dy
) + height
<= max_y
)
5490 /* It fits below the pointer */
5491 *root_y
+= XINT (dy
);
5492 else if (height
+ XINT (dy
) + min_y
<= *root_y
)
5493 /* It fits above the pointer. */
5494 *root_y
-= height
+ XINT (dy
);
5496 /* Put it on the top. */
5499 if (INTEGERP (left
))
5500 *root_x
= XINT (left
);
5501 else if (*root_x
+ XINT (dx
) <= min_x
)
5502 *root_x
= 0; /* Can happen for negative dx */
5503 else if (*root_x
+ XINT (dx
) + width
<= max_x
)
5504 /* It fits to the right of the pointer. */
5505 *root_x
+= XINT (dx
);
5506 else if (width
+ XINT (dx
) + min_x
<= *root_x
)
5507 /* It fits to the left of the pointer. */
5508 *root_x
-= width
+ XINT (dx
);
5510 /* Put it left justified on the screen -- it ought to fit that way. */
5515 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
5516 doc
: /* Show STRING in a \"tooltip\" window on frame FRAME.
5517 A tooltip window is a small window displaying a string.
5519 This is an internal function; Lisp code should call `tooltip-show'.
5521 FRAME nil or omitted means use the selected frame.
5523 PARMS is an optional list of frame parameters which can be
5524 used to change the tooltip's appearance.
5526 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
5527 means use the default timeout of 5 seconds.
5529 If the list of frame parameters PARMS contains a `left' parameter,
5530 the tooltip is displayed at that x-position. Otherwise it is
5531 displayed at the mouse position, with offset DX added (default is 5 if
5532 DX isn't specified). Likewise for the y-position; if a `top' frame
5533 parameter is specified, it determines the y-position of the tooltip
5534 window, otherwise it is displayed at the mouse position, with offset
5535 DY added (default is -10).
5537 A tooltip's maximum size is specified by `x-max-tooltip-size'.
5538 Text larger than the specified size is clipped. */)
5539 (Lisp_Object string
, Lisp_Object frame
, Lisp_Object parms
, Lisp_Object timeout
, Lisp_Object dx
, Lisp_Object dy
)
5544 struct buffer
*old_buffer
;
5545 struct text_pos pos
;
5546 int i
, width
, height
, seen_reversed_p
;
5547 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5548 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5549 ptrdiff_t count
= SPECPDL_INDEX ();
5551 specbind (Qinhibit_redisplay
, Qt
);
5553 GCPRO4 (string
, parms
, frame
, timeout
);
5555 CHECK_STRING (string
);
5556 f
= check_x_frame (frame
);
5558 timeout
= make_number (5);
5560 CHECK_NATNUM (timeout
);
5563 dx
= make_number (5);
5568 dy
= make_number (-10);
5572 if (NILP (last_show_tip_args
))
5573 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
5575 if (!NILP (tip_frame
))
5577 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
5578 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
5579 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
5581 if (EQ (frame
, last_frame
)
5582 && !NILP (Fequal (last_string
, string
))
5583 && !NILP (Fequal (last_parms
, parms
)))
5585 struct frame
*f
= XFRAME (tip_frame
);
5587 /* Only DX and DY have changed. */
5588 if (!NILP (tip_timer
))
5590 Lisp_Object timer
= tip_timer
;
5592 call1 (Qcancel_timer
, timer
);
5596 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
5597 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
5599 /* Put tooltip in topmost group and in position. */
5600 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
5601 root_x
, root_y
, 0, 0,
5602 SWP_NOSIZE
| SWP_NOACTIVATE
);
5604 /* Ensure tooltip is on top of other topmost windows (eg menus). */
5605 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
5607 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
5614 /* Hide a previous tip, if any. */
5617 ASET (last_show_tip_args
, 0, string
);
5618 ASET (last_show_tip_args
, 1, frame
);
5619 ASET (last_show_tip_args
, 2, parms
);
5621 /* Add default values to frame parameters. */
5622 if (NILP (Fassq (Qname
, parms
)))
5623 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
5624 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5625 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
5626 if (NILP (Fassq (Qborder_width
, parms
)))
5627 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
5628 if (NILP (Fassq (Qborder_color
, parms
)))
5629 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
5630 if (NILP (Fassq (Qbackground_color
, parms
)))
5631 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
5634 /* Block input until the tip has been fully drawn, to avoid crashes
5635 when drawing tips in menus. */
5638 /* Create a frame for the tooltip, and record it in the global
5639 variable tip_frame. */
5640 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
, string
);
5643 /* Set up the frame's root window. */
5644 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5645 wset_left_col (w
, make_number (0));
5646 wset_top_line (w
, make_number (0));
5648 if (CONSP (Vx_max_tooltip_size
)
5649 && INTEGERP (XCAR (Vx_max_tooltip_size
))
5650 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
5651 && INTEGERP (XCDR (Vx_max_tooltip_size
))
5652 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
5654 wset_total_cols (w
, XCAR (Vx_max_tooltip_size
));
5655 wset_total_lines (w
, XCDR (Vx_max_tooltip_size
));
5659 wset_total_cols (w
, make_number (80));
5660 wset_total_lines (w
, make_number (40));
5663 FRAME_TOTAL_COLS (f
) = XINT (w
->total_cols
);
5665 w
->pseudo_window_p
= 1;
5667 /* Display the tooltip text in a temporary buffer. */
5668 old_buffer
= current_buffer
;
5669 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
5670 bset_truncate_lines (current_buffer
, Qnil
);
5671 clear_glyph_matrix (w
->desired_matrix
);
5672 clear_glyph_matrix (w
->current_matrix
);
5673 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
5674 try_window (FRAME_ROOT_WINDOW (f
), pos
, TRY_WINDOW_IGNORE_FONTS_CHANGE
);
5676 /* Compute width and height of the tooltip. */
5677 width
= height
= seen_reversed_p
= 0;
5678 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5680 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5684 /* Stop at the first empty row at the end. */
5685 if (!row
->enabled_p
|| !row
->displays_text_p
)
5688 /* Let the row go over the full width of the frame. */
5689 row
->full_width_p
= 1;
5691 row_width
= row
->pixel_width
;
5692 if (row
->used
[TEXT_AREA
])
5694 if (!row
->reversed_p
)
5696 /* There's a glyph at the end of rows that is used to
5697 place the cursor there. Don't include the width of
5699 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5700 if (INTEGERP (last
->object
))
5701 row_width
-= last
->pixel_width
;
5705 /* There could be a stretch glyph at the beginning of R2L
5706 rows that is produced by extend_face_to_end_of_line.
5707 Don't count that glyph. */
5708 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
5710 if (g
->type
== STRETCH_GLYPH
&& INTEGERP (g
->object
))
5712 row_width
-= g
->pixel_width
;
5713 seen_reversed_p
= 1;
5718 height
+= row
->height
;
5719 width
= max (width
, row_width
);
5722 /* If we've seen partial-length R2L rows, we need to re-adjust the
5723 tool-tip frame width and redisplay it again, to avoid over-wide
5724 tips due to the stretch glyph that extends R2L lines to full
5725 width of the frame. */
5726 if (seen_reversed_p
)
5728 /* w->total_cols and FRAME_TOTAL_COLS want the width in columns,
5730 width
/= WINDOW_FRAME_COLUMN_WIDTH (w
);
5731 wset_total_cols (w
, make_number (width
));
5732 FRAME_TOTAL_COLS (f
) = width
;
5734 w
->pseudo_window_p
= 1;
5735 clear_glyph_matrix (w
->desired_matrix
);
5736 clear_glyph_matrix (w
->current_matrix
);
5737 try_window (FRAME_ROOT_WINDOW (f
), pos
, TRY_WINDOW_IGNORE_FONTS_CHANGE
);
5739 /* Recompute width and height of the tooltip. */
5740 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5742 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5746 if (!row
->enabled_p
|| !row
->displays_text_p
)
5748 row
->full_width_p
= 1;
5749 row_width
= row
->pixel_width
;
5750 if (row
->used
[TEXT_AREA
] && !row
->reversed_p
)
5752 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5753 if (INTEGERP (last
->object
))
5754 row_width
-= last
->pixel_width
;
5757 height
+= row
->height
;
5758 width
= max (width
, row_width
);
5762 /* Round up the height to an integral multiple of FRAME_LINE_HEIGHT. */
5763 if (height
% FRAME_LINE_HEIGHT (f
) != 0)
5764 height
+= FRAME_LINE_HEIGHT (f
) - height
% FRAME_LINE_HEIGHT (f
);
5765 /* Add the frame's internal border to the width and height the w32
5766 window should have. */
5767 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5768 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5770 /* Move the tooltip window where the mouse pointer is. Resize and
5772 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
5775 /* Adjust Window size to take border into account. */
5777 rect
.left
= rect
.top
= 0;
5779 rect
.bottom
= height
;
5780 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
5781 FRAME_EXTERNAL_MENU_BAR (f
));
5783 /* Position and size tooltip, and put it in the topmost group.
5784 The add-on of FRAME_COLUMN_WIDTH to the 5th argument is a
5785 peculiarity of w32 display: without it, some fonts cause the
5786 last character of the tip to be truncated or wrapped around to
5788 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
5790 rect
.right
- rect
.left
+ FRAME_COLUMN_WIDTH (f
),
5791 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
);
5793 /* Ensure tooltip is on top of other topmost windows (eg menus). */
5794 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
5796 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
5798 /* Let redisplay know that we have made the frame visible already. */
5799 f
->async_visible
= 1;
5801 ShowWindow (FRAME_W32_WINDOW (f
), SW_SHOWNOACTIVATE
);
5804 /* Draw into the window. */
5805 w
->must_be_updated_p
= 1;
5806 update_single_window (w
, 1);
5810 /* Restore original current buffer. */
5811 set_buffer_internal_1 (old_buffer
);
5812 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5815 /* Let the tip disappear after timeout seconds. */
5816 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
5817 intern ("x-hide-tip"));
5820 return unbind_to (count
, Qnil
);
5824 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
5825 doc
: /* Hide the current tooltip window, if there is any.
5826 Value is t if tooltip was open, nil otherwise. */)
5830 Lisp_Object deleted
, frame
, timer
;
5831 struct gcpro gcpro1
, gcpro2
;
5833 /* Return quickly if nothing to do. */
5834 if (NILP (tip_timer
) && NILP (tip_frame
))
5839 GCPRO2 (frame
, timer
);
5840 tip_frame
= tip_timer
= deleted
= Qnil
;
5842 count
= SPECPDL_INDEX ();
5843 specbind (Qinhibit_redisplay
, Qt
);
5844 specbind (Qinhibit_quit
, Qt
);
5847 call1 (Qcancel_timer
, timer
);
5851 delete_frame (frame
, Qnil
);
5856 return unbind_to (count
, deleted
);
5859 /***********************************************************************
5860 File selection dialog
5861 ***********************************************************************/
5863 /* Callback for altering the behavior of the Open File dialog.
5864 Makes the Filename text field contain "Current Directory" and be
5865 read-only when "Directories" is selected in the filter. This
5866 allows us to work around the fact that the standard Open File
5867 dialog does not support directories. */
5868 static UINT CALLBACK
5869 file_dialog_callback (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
5871 if (msg
== WM_NOTIFY
)
5873 OFNOTIFY
* notify
= (OFNOTIFY
*)lParam
;
5874 /* Detect when the Filter dropdown is changed. */
5875 if (notify
->hdr
.code
== CDN_TYPECHANGE
5876 || notify
->hdr
.code
== CDN_INITDONE
)
5878 HWND dialog
= GetParent (hwnd
);
5879 HWND edit_control
= GetDlgItem (dialog
, FILE_NAME_TEXT_FIELD
);
5880 HWND list
= GetDlgItem (dialog
, FILE_NAME_LIST
);
5882 /* At least on Windows 7, the above attempt to get the window handle
5883 to the File Name Text Field fails. The following code does the
5884 job though. Note that this code is based on my examination of the
5885 window hierarchy using Microsoft Spy++. bk */
5886 if (edit_control
== NULL
)
5888 HWND tmp
= GetDlgItem (dialog
, FILE_NAME_COMBO_BOX
);
5891 tmp
= GetWindow (tmp
, GW_CHILD
);
5893 edit_control
= GetWindow (tmp
, GW_CHILD
);
5897 /* Directories is in index 2. */
5898 if (notify
->lpOFN
->nFilterIndex
== 2)
5900 CommDlg_OpenSave_SetControlText (dialog
, FILE_NAME_TEXT_FIELD
,
5901 "Current Directory");
5902 EnableWindow (edit_control
, FALSE
);
5903 /* Note that at least on Windows 7, the above call to EnableWindow
5904 disables the window that would ordinarily have focus. If we
5905 do not set focus to some other window here, focus will land in
5906 no man's land and the user will be unable to tab through the
5907 dialog box (pressing tab will only result in a beep).
5908 Avoid that problem by setting focus to the list here. */
5909 if (notify
->hdr
.code
== CDN_INITDONE
)
5914 /* Don't override default filename on init done. */
5915 if (notify
->hdr
.code
== CDN_TYPECHANGE
)
5916 CommDlg_OpenSave_SetControlText (dialog
,
5917 FILE_NAME_TEXT_FIELD
, "");
5918 EnableWindow (edit_control
, TRUE
);
5925 /* Since we compile with _WIN32_WINNT set to 0x0400 (for NT4 compatibility)
5926 we end up with the old file dialogs. Define a big enough struct for the
5927 new dialog to trick GetOpenFileName into giving us the new dialogs on
5928 Windows 2000 and XP. */
5931 OPENFILENAME real_details
;
5938 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
5939 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5940 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5941 selection box, if specified. If MUSTMATCH is non-nil, the returned file
5942 or directory must exist.
5944 This function is only defined on NS, MS Windows, and X Windows with the
5945 Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
5946 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
5947 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
, Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
5949 struct frame
*f
= SELECTED_FRAME ();
5950 Lisp_Object file
= Qnil
;
5951 ptrdiff_t count
= SPECPDL_INDEX ();
5952 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
5953 char filename
[MAX_PATH
+ 1];
5954 char init_dir
[MAX_PATH
+ 1];
5955 int default_filter_index
= 1; /* 1: All Files, 2: Directories only */
5957 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
5958 CHECK_STRING (prompt
);
5961 /* Create the dialog with PROMPT as title, using DIR as initial
5962 directory and using "*" as pattern. */
5963 dir
= Fexpand_file_name (dir
, Qnil
);
5964 strncpy (init_dir
, SDATA (ENCODE_FILE (dir
)), MAX_PATH
);
5965 init_dir
[MAX_PATH
] = '\0';
5966 unixtodos_filename (init_dir
);
5968 if (STRINGP (default_filename
))
5970 char *file_name_only
;
5971 char *full_path_name
= SDATA (ENCODE_FILE (default_filename
));
5973 unixtodos_filename (full_path_name
);
5975 file_name_only
= strrchr (full_path_name
, '\\');
5976 if (!file_name_only
)
5977 file_name_only
= full_path_name
;
5981 strncpy (filename
, file_name_only
, MAX_PATH
);
5982 filename
[MAX_PATH
] = '\0';
5987 /* The code in file_dialog_callback that attempts to set the text
5988 of the file name edit window when handling the CDN_INITDONE
5989 WM_NOTIFY message does not work. Setting filename to "Current
5990 Directory" in the only_dir_p case here does work however. */
5991 if (filename
[0] == 0 && ! NILP (only_dir_p
))
5992 strcpy (filename
, "Current Directory");
5995 NEWOPENFILENAME new_file_details
;
5996 BOOL file_opened
= FALSE
;
5997 OPENFILENAME
* file_details
= &new_file_details
.real_details
;
5999 /* Prevent redisplay. */
6000 specbind (Qinhibit_redisplay
, Qt
);
6003 memset (&new_file_details
, 0, sizeof (new_file_details
));
6004 /* Apparently NT4 crashes if you give it an unexpected size.
6005 I'm not sure about Windows 9x, so play it safe. */
6006 if (w32_major_version
> 4 && w32_major_version
< 95)
6007 file_details
->lStructSize
= sizeof (NEWOPENFILENAME
);
6009 file_details
->lStructSize
= sizeof (OPENFILENAME
);
6011 file_details
->hwndOwner
= FRAME_W32_WINDOW (f
);
6012 /* Undocumented Bug in Common File Dialog:
6013 If a filter is not specified, shell links are not resolved. */
6014 file_details
->lpstrFilter
= "All Files (*.*)\0*.*\0Directories\0*|*\0\0";
6015 file_details
->lpstrFile
= filename
;
6016 file_details
->nMaxFile
= sizeof (filename
);
6017 file_details
->lpstrInitialDir
= init_dir
;
6018 file_details
->lpstrTitle
= SDATA (prompt
);
6020 if (! NILP (only_dir_p
))
6021 default_filter_index
= 2;
6023 file_details
->nFilterIndex
= default_filter_index
;
6025 file_details
->Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
6026 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
6027 if (!NILP (mustmatch
))
6029 /* Require that the path to the parent directory exists. */
6030 file_details
->Flags
|= OFN_PATHMUSTEXIST
;
6031 /* If we are looking for a file, require that it exists. */
6032 if (NILP (only_dir_p
))
6033 file_details
->Flags
|= OFN_FILEMUSTEXIST
;
6036 file_details
->lpfnHook
= (LPOFNHOOKPROC
) file_dialog_callback
;
6038 file_opened
= GetOpenFileName (file_details
);
6044 dostounix_filename (filename
);
6046 if (file_details
->nFilterIndex
== 2)
6048 /* "Directories" selected - strip dummy file name. */
6049 char * last
= strrchr (filename
, '/');
6053 file
= DECODE_FILE (build_string (filename
));
6055 /* User canceled the dialog without making a selection. */
6056 else if (!CommDlgExtendedError ())
6058 /* An error occurred, fallback on reading from the mini-buffer. */
6060 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
6061 dir
, mustmatch
, dir
, Qfile_name_history
,
6062 default_filename
, Qnil
);
6064 file
= unbind_to (count
, file
);
6069 /* Make "Cancel" equivalent to C-g. */
6071 Fsignal (Qquit
, Qnil
);
6073 return unbind_to (count
, file
);
6077 /* Moving files to the system recycle bin.
6078 Used by `move-file-to-trash' instead of the default moving to ~/.Trash */
6079 DEFUN ("system-move-file-to-trash", Fsystem_move_file_to_trash
,
6080 Ssystem_move_file_to_trash
, 1, 1, 0,
6081 doc
: /* Move file or directory named FILENAME to the recycle bin. */)
6082 (Lisp_Object filename
)
6084 Lisp_Object handler
;
6085 Lisp_Object encoded_file
;
6086 Lisp_Object operation
;
6088 operation
= Qdelete_file
;
6089 if (!NILP (Ffile_directory_p (filename
))
6090 && NILP (Ffile_symlink_p (filename
)))
6092 operation
= intern ("delete-directory");
6093 filename
= Fdirectory_file_name (filename
);
6095 filename
= Fexpand_file_name (filename
, Qnil
);
6097 handler
= Ffind_file_name_handler (filename
, operation
);
6098 if (!NILP (handler
))
6099 return call2 (handler
, operation
, filename
);
6101 encoded_file
= ENCODE_FILE (filename
);
6105 SHFILEOPSTRUCT file_op
;
6106 char tmp_path
[MAX_PATH
+ 1];
6108 path
= map_w32_filename (SDATA (encoded_file
), NULL
);
6110 /* On Windows, write permission is required to delete/move files. */
6111 _chmod (path
, 0666);
6113 memset (tmp_path
, 0, sizeof (tmp_path
));
6114 strcpy (tmp_path
, path
);
6116 memset (&file_op
, 0, sizeof (file_op
));
6117 file_op
.hwnd
= HWND_DESKTOP
;
6118 file_op
.wFunc
= FO_DELETE
;
6119 file_op
.pFrom
= tmp_path
;
6120 file_op
.fFlags
= FOF_SILENT
| FOF_NOCONFIRMATION
| FOF_ALLOWUNDO
6121 | FOF_NOERRORUI
| FOF_NO_CONNECTED_ELEMENTS
;
6122 file_op
.fAnyOperationsAborted
= FALSE
;
6124 if (SHFileOperation (&file_op
) != 0)
6125 report_file_error ("Removing old name", list1 (filename
));
6131 /***********************************************************************
6132 w32 specialized functions
6133 ***********************************************************************/
6135 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
,
6136 Sw32_send_sys_command
, 1, 2, 0,
6137 doc
: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND.
6138 Some useful values for COMMAND are #xf030 to maximize frame (#xf020
6139 to minimize), #xf120 to restore frame to original size, and #xf100
6140 to activate the menubar for keyboard access. #xf140 activates the
6141 screen saver if defined.
6143 If optional parameter FRAME is not specified, use selected frame. */)
6144 (Lisp_Object command
, Lisp_Object frame
)
6146 FRAME_PTR f
= check_x_frame (frame
);
6148 CHECK_NUMBER (command
);
6150 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
6155 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
6156 doc
: /* Get Windows to perform OPERATION on DOCUMENT.
6157 This is a wrapper around the ShellExecute system function, which
6158 invokes the application registered to handle OPERATION for DOCUMENT.
6160 OPERATION is either nil or a string that names a supported operation.
6161 What operations can be used depends on the particular DOCUMENT and its
6162 handler application, but typically it is one of the following common
6165 \"open\" - open DOCUMENT, which could be a file, a directory, or an
6166 executable program. If it is an application, that
6167 application is launched in the current buffer's default
6168 directory. Otherwise, the application associated with
6169 DOCUMENT is launched in the buffer's default directory.
6170 \"print\" - print DOCUMENT, which must be a file
6171 \"explore\" - start the Windows Explorer on DOCUMENT
6172 \"edit\" - launch an editor and open DOCUMENT for editing; which
6173 editor is launched depends on the association for the
6175 \"find\" - initiate search starting from DOCUMENT which must specify
6177 nil - invoke the default OPERATION, or \"open\" if default is
6178 not defined or unavailable
6180 DOCUMENT is typically the name of a document file or a URL, but can
6181 also be a program executable to run, or a directory to open in the
6184 If DOCUMENT is a program executable, the optional third arg PARAMETERS
6185 can be a string containing command line parameters that will be passed
6186 to the program; otherwise, PARAMETERS should be nil or unspecified.
6188 Optional fourth argument SHOW-FLAG can be used to control how the
6189 application will be displayed when it is invoked. If SHOW-FLAG is nil
6190 or unspecified, the application is displayed normally, otherwise it is
6191 an integer representing a ShowWindow flag:
6196 6 - start minimized */)
6197 (Lisp_Object operation
, Lisp_Object document
, Lisp_Object parameters
, Lisp_Object show_flag
)
6199 Lisp_Object current_dir
;
6202 CHECK_STRING (document
);
6204 /* Encode filename, current directory and parameters. */
6205 current_dir
= ENCODE_FILE (BVAR (current_buffer
, directory
));
6206 document
= ENCODE_FILE (document
);
6207 if (STRINGP (parameters
))
6208 parameters
= ENCODE_SYSTEM (parameters
);
6210 if ((int) ShellExecute (NULL
,
6211 (STRINGP (operation
) ?
6212 SDATA (operation
) : NULL
),
6214 (STRINGP (parameters
) ?
6215 SDATA (parameters
) : NULL
),
6216 SDATA (current_dir
),
6217 (INTEGERP (show_flag
) ?
6218 XINT (show_flag
) : SW_SHOWDEFAULT
))
6221 errstr
= w32_strerror (0);
6222 /* The error string might be encoded in the locale's encoding. */
6223 if (!NILP (Vlocale_coding_system
))
6225 Lisp_Object decoded
=
6226 code_convert_string_norecord (build_unibyte_string (errstr
),
6227 Vlocale_coding_system
, 0);
6228 errstr
= SSDATA (decoded
);
6230 error ("ShellExecute failed: %s", errstr
);
6233 /* Lookup virtual keycode from string representing the name of a
6234 non-ascii keystroke into the corresponding virtual key, using
6235 lispy_function_keys. */
6237 lookup_vk_code (char *key
)
6241 for (i
= 0; i
< 256; i
++)
6242 if (lispy_function_keys
[i
]
6243 && strcmp (lispy_function_keys
[i
], key
) == 0)
6249 /* Convert a one-element vector style key sequence to a hot key
6252 w32_parse_hot_key (Lisp_Object key
)
6254 /* Copied from Fdefine_key and store_in_keymap. */
6255 register Lisp_Object c
;
6259 struct gcpro gcpro1
;
6263 if (XFASTINT (Flength (key
)) != 1)
6268 c
= Faref (key
, make_number (0));
6270 if (CONSP (c
) && lucid_event_type_list_p (c
))
6271 c
= Fevent_convert_list (c
);
6275 if (! INTEGERP (c
) && ! SYMBOLP (c
))
6276 error ("Key definition is invalid");
6278 /* Work out the base key and the modifiers. */
6281 c
= parse_modifiers (c
);
6282 lisp_modifiers
= XINT (Fcar (Fcdr (c
)));
6286 vk_code
= lookup_vk_code (SDATA (SYMBOL_NAME (c
)));
6288 else if (INTEGERP (c
))
6290 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
6291 /* Many ascii characters are their own virtual key code. */
6292 vk_code
= XINT (c
) & CHARACTERBITS
;
6295 if (vk_code
< 0 || vk_code
> 255)
6298 if ((lisp_modifiers
& meta_modifier
) != 0
6299 && !NILP (Vw32_alt_is_meta
))
6300 lisp_modifiers
|= alt_modifier
;
6302 /* Supply defs missing from mingw32. */
6304 #define MOD_ALT 0x0001
6305 #define MOD_CONTROL 0x0002
6306 #define MOD_SHIFT 0x0004
6307 #define MOD_WIN 0x0008
6310 /* Convert lisp modifiers to Windows hot-key form. */
6311 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
6312 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
6313 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
6314 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
6316 return HOTKEY (vk_code
, w32_modifiers
);
6319 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
,
6320 Sw32_register_hot_key
, 1, 1, 0,
6321 doc
: /* Register KEY as a hot-key combination.
6322 Certain key combinations like Alt-Tab are reserved for system use on
6323 Windows, and therefore are normally intercepted by the system. However,
6324 most of these key combinations can be received by registering them as
6325 hot-keys, overriding their special meaning.
6327 KEY must be a one element key definition in vector form that would be
6328 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta
6329 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper
6330 is always interpreted as the Windows modifier keys.
6332 The return value is the hotkey-id if registered, otherwise nil. */)
6335 key
= w32_parse_hot_key (key
);
6337 if (!NILP (key
) && NILP (Fmemq (key
, w32_grabbed_keys
)))
6339 /* Reuse an empty slot if possible. */
6340 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
6342 /* Safe to add new key to list, even if we have focus. */
6344 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
6346 XSETCAR (item
, key
);
6348 /* Notify input thread about new hot-key definition, so that it
6349 takes effect without needing to switch focus. */
6350 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
6351 (WPARAM
) XLI (key
), 0);
6357 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
,
6358 Sw32_unregister_hot_key
, 1, 1, 0,
6359 doc
: /* Unregister KEY as a hot-key combination. */)
6364 if (!INTEGERP (key
))
6365 key
= w32_parse_hot_key (key
);
6367 item
= Fmemq (key
, w32_grabbed_keys
);
6371 /* Notify input thread about hot-key definition being removed, so
6372 that it takes effect without needing focus switch. */
6373 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
6374 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) XLI (item
)))
6377 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
6384 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
,
6385 Sw32_registered_hot_keys
, 0, 0, 0,
6386 doc
: /* Return list of registered hot-key IDs. */)
6389 return Fdelq (Qnil
, Fcopy_sequence (w32_grabbed_keys
));
6392 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
,
6393 Sw32_reconstruct_hot_key
, 1, 1, 0,
6394 doc
: /* Convert hot-key ID to a lisp key combination.
6395 usage: (w32-reconstruct-hot-key ID) */)
6396 (Lisp_Object hotkeyid
)
6398 int vk_code
, w32_modifiers
;
6401 CHECK_NUMBER (hotkeyid
);
6403 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
6404 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
6406 if (vk_code
< 256 && lispy_function_keys
[vk_code
])
6407 key
= intern (lispy_function_keys
[vk_code
]);
6409 key
= make_number (vk_code
);
6411 key
= Fcons (key
, Qnil
);
6412 if (w32_modifiers
& MOD_SHIFT
)
6413 key
= Fcons (Qshift
, key
);
6414 if (w32_modifiers
& MOD_CONTROL
)
6415 key
= Fcons (Qctrl
, key
);
6416 if (w32_modifiers
& MOD_ALT
)
6417 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
6418 if (w32_modifiers
& MOD_WIN
)
6419 key
= Fcons (Qhyper
, key
);
6424 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
,
6425 Sw32_toggle_lock_key
, 1, 2, 0,
6426 doc
: /* Toggle the state of the lock key KEY.
6427 KEY can be `capslock', `kp-numlock', or `scroll'.
6428 If the optional parameter NEW-STATE is a number, then the state of KEY
6429 is set to off if the low bit of NEW-STATE is zero, otherwise on. */)
6430 (Lisp_Object key
, Lisp_Object new_state
)
6434 if (EQ (key
, intern ("capslock")))
6435 vk_code
= VK_CAPITAL
;
6436 else if (EQ (key
, intern ("kp-numlock")))
6437 vk_code
= VK_NUMLOCK
;
6438 else if (EQ (key
, intern ("scroll")))
6439 vk_code
= VK_SCROLL
;
6443 if (!dwWindowsThreadId
)
6444 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
6446 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
6447 (WPARAM
) vk_code
, (LPARAM
) XLI (new_state
)))
6450 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
6451 return make_number (msg
.wParam
);
6456 DEFUN ("w32-window-exists-p", Fw32_window_exists_p
, Sw32_window_exists_p
,
6458 doc
: /* Return non-nil if a window exists with the specified CLASS and NAME.
6460 This is a direct interface to the Windows API FindWindow function. */)
6461 (Lisp_Object
class, Lisp_Object name
)
6466 CHECK_STRING (class);
6468 CHECK_STRING (name
);
6470 hnd
= FindWindow (STRINGP (class) ? ((LPCTSTR
) SDATA (class)) : NULL
,
6471 STRINGP (name
) ? ((LPCTSTR
) SDATA (name
)) : NULL
);
6477 DEFUN ("w32-battery-status", Fw32_battery_status
, Sw32_battery_status
, 0, 0, 0,
6478 doc
: /* Get power status information from Windows system.
6480 The following %-sequences are provided:
6481 %L AC line status (verbose)
6482 %B Battery status (verbose)
6483 %b Battery status, empty means high, `-' means low,
6484 `!' means critical, and `+' means charging
6485 %p Battery load percentage
6486 %s Remaining time (to charge or discharge) in seconds
6487 %m Remaining time (to charge or discharge) in minutes
6488 %h Remaining time (to charge or discharge) in hours
6489 %t Remaining time (to charge or discharge) in the form `h:min' */)
6492 Lisp_Object status
= Qnil
;
6494 SYSTEM_POWER_STATUS system_status
;
6495 if (GetSystemPowerStatus (&system_status
))
6497 Lisp_Object line_status
, battery_status
, battery_status_symbol
;
6498 Lisp_Object load_percentage
, seconds
, minutes
, hours
, remain
;
6500 long seconds_left
= (long) system_status
.BatteryLifeTime
;
6502 if (system_status
.ACLineStatus
== 0)
6503 line_status
= build_string ("off-line");
6504 else if (system_status
.ACLineStatus
== 1)
6505 line_status
= build_string ("on-line");
6507 line_status
= build_string ("N/A");
6509 if (system_status
.BatteryFlag
& 128)
6511 battery_status
= build_string ("N/A");
6512 battery_status_symbol
= empty_unibyte_string
;
6514 else if (system_status
.BatteryFlag
& 8)
6516 battery_status
= build_string ("charging");
6517 battery_status_symbol
= build_string ("+");
6518 if (system_status
.BatteryFullLifeTime
!= -1L)
6519 seconds_left
= system_status
.BatteryFullLifeTime
- seconds_left
;
6521 else if (system_status
.BatteryFlag
& 4)
6523 battery_status
= build_string ("critical");
6524 battery_status_symbol
= build_string ("!");
6526 else if (system_status
.BatteryFlag
& 2)
6528 battery_status
= build_string ("low");
6529 battery_status_symbol
= build_string ("-");
6531 else if (system_status
.BatteryFlag
& 1)
6533 battery_status
= build_string ("high");
6534 battery_status_symbol
= empty_unibyte_string
;
6538 battery_status
= build_string ("medium");
6539 battery_status_symbol
= empty_unibyte_string
;
6542 if (system_status
.BatteryLifePercent
> 100)
6543 load_percentage
= build_string ("N/A");
6547 _snprintf (buffer
, 16, "%d", system_status
.BatteryLifePercent
);
6548 load_percentage
= build_string (buffer
);
6551 if (seconds_left
< 0)
6552 seconds
= minutes
= hours
= remain
= build_string ("N/A");
6558 _snprintf (buffer
, 16, "%ld", seconds_left
);
6559 seconds
= build_string (buffer
);
6561 m
= seconds_left
/ 60;
6562 _snprintf (buffer
, 16, "%ld", m
);
6563 minutes
= build_string (buffer
);
6565 h
= seconds_left
/ 3600.0;
6566 _snprintf (buffer
, 16, "%3.1f", h
);
6567 hours
= build_string (buffer
);
6569 _snprintf (buffer
, 16, "%ld:%02ld", m
/ 60, m
% 60);
6570 remain
= build_string (buffer
);
6573 status
= listn (CONSTYPE_HEAP
, 8,
6574 Fcons (make_number ('L'), line_status
),
6575 Fcons (make_number ('B'), battery_status
),
6576 Fcons (make_number ('b'), battery_status_symbol
),
6577 Fcons (make_number ('p'), load_percentage
),
6578 Fcons (make_number ('s'), seconds
),
6579 Fcons (make_number ('m'), minutes
),
6580 Fcons (make_number ('h'), hours
),
6581 Fcons (make_number ('t'), remain
));
6587 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
6588 doc
: /* Return storage information about the file system FILENAME is on.
6589 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
6590 storage of the file system, FREE is the free storage, and AVAIL is the
6591 storage available to a non-superuser. All 3 numbers are in bytes.
6592 If the underlying system call fails, value is nil. */)
6593 (Lisp_Object filename
)
6595 Lisp_Object encoded
, value
;
6597 CHECK_STRING (filename
);
6598 filename
= Fexpand_file_name (filename
, Qnil
);
6599 encoded
= ENCODE_FILE (filename
);
6603 /* Determining the required information on Windows turns out, sadly,
6604 to be more involved than one would hope. The original Windows API
6605 call for this will return bogus information on some systems, but we
6606 must dynamically probe for the replacement api, since that was
6607 added rather late on. */
6609 HMODULE hKernel
= GetModuleHandle ("kernel32");
6610 BOOL (*pfn_GetDiskFreeSpaceEx
)
6611 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
6612 = (void *) GetProcAddress (hKernel
, "GetDiskFreeSpaceEx");
6614 /* On Windows, we may need to specify the root directory of the
6615 volume holding FILENAME. */
6616 char rootname
[MAX_PATH
];
6617 char *name
= SDATA (encoded
);
6619 /* find the root name of the volume if given */
6620 if (isalpha (name
[0]) && name
[1] == ':')
6622 rootname
[0] = name
[0];
6623 rootname
[1] = name
[1];
6627 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
6629 char *str
= rootname
;
6633 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
6643 if (pfn_GetDiskFreeSpaceEx
)
6645 /* Unsigned large integers cannot be cast to double, so
6646 use signed ones instead. */
6647 LARGE_INTEGER availbytes
;
6648 LARGE_INTEGER freebytes
;
6649 LARGE_INTEGER totalbytes
;
6651 if (pfn_GetDiskFreeSpaceEx (rootname
,
6652 (ULARGE_INTEGER
*)&availbytes
,
6653 (ULARGE_INTEGER
*)&totalbytes
,
6654 (ULARGE_INTEGER
*)&freebytes
))
6655 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
6656 make_float ((double) freebytes
.QuadPart
),
6657 make_float ((double) availbytes
.QuadPart
));
6661 DWORD sectors_per_cluster
;
6662 DWORD bytes_per_sector
;
6663 DWORD free_clusters
;
6664 DWORD total_clusters
;
6666 if (GetDiskFreeSpace (rootname
,
6667 §ors_per_cluster
,
6671 value
= list3 (make_float ((double) total_clusters
6672 * sectors_per_cluster
* bytes_per_sector
),
6673 make_float ((double) free_clusters
6674 * sectors_per_cluster
* bytes_per_sector
),
6675 make_float ((double) free_clusters
6676 * sectors_per_cluster
* bytes_per_sector
));
6683 DEFUN ("default-printer-name", Fdefault_printer_name
, Sdefault_printer_name
,
6684 0, 0, 0, doc
: /* Return the name of Windows default printer device. */)
6687 static char pname_buf
[256];
6690 PRINTER_INFO_2
*ppi2
= NULL
;
6691 DWORD dwNeeded
= 0, dwReturned
= 0;
6693 /* Retrieve the default string from Win.ini (the registry).
6694 * String will be in form "printername,drivername,portname".
6695 * This is the most portable way to get the default printer. */
6696 if (GetProfileString ("windows", "device", ",,", pname_buf
, sizeof (pname_buf
)) <= 0)
6698 /* printername precedes first "," character */
6699 strtok (pname_buf
, ",");
6700 /* We want to know more than the printer name */
6701 if (!OpenPrinter (pname_buf
, &hPrn
, NULL
))
6703 GetPrinter (hPrn
, 2, NULL
, 0, &dwNeeded
);
6706 ClosePrinter (hPrn
);
6709 /* Allocate memory for the PRINTER_INFO_2 struct */
6710 ppi2
= xmalloc (dwNeeded
);
6713 ClosePrinter (hPrn
);
6716 /* Call GetPrinter again with big enough memory block. */
6717 err
= GetPrinter (hPrn
, 2, (LPBYTE
)ppi2
, dwNeeded
, &dwReturned
);
6718 ClosePrinter (hPrn
);
6727 if (ppi2
->Attributes
& PRINTER_ATTRIBUTE_SHARED
&& ppi2
->pServerName
)
6729 /* a remote printer */
6730 if (*ppi2
->pServerName
== '\\')
6731 _snprintf (pname_buf
, sizeof (pname_buf
), "%s\\%s", ppi2
->pServerName
,
6734 _snprintf (pname_buf
, sizeof (pname_buf
), "\\\\%s\\%s", ppi2
->pServerName
,
6736 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
6740 /* a local printer */
6741 strncpy (pname_buf
, ppi2
->pPortName
, sizeof (pname_buf
));
6742 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
6743 /* `pPortName' can include several ports, delimited by ','.
6744 * we only use the first one. */
6745 strtok (pname_buf
, ",");
6750 return build_string (pname_buf
);
6753 /***********************************************************************
6755 ***********************************************************************/
6757 /* Keep this list in the same order as frame_parms in frame.c.
6758 Use 0 for unsupported frame parameters. */
6760 frame_parm_handler w32_frame_parm_handlers
[] =
6764 x_set_background_color
,
6770 x_set_foreground_color
,
6773 x_set_internal_border_width
,
6774 x_set_menu_bar_lines
,
6776 x_explicitly_set_name
,
6777 x_set_scroll_bar_width
,
6780 x_set_vertical_scroll_bars
,
6782 x_set_tool_bar_lines
,
6783 0, /* x_set_scroll_bar_foreground, */
6784 0, /* x_set_scroll_bar_background, */
6789 0, /* x_set_wait_for_wm, */
6793 0, /* x_set_sticky */
6794 0, /* x_set_tool_bar_position */
6798 syms_of_w32fns (void)
6800 globals_of_w32fns ();
6801 /* This is zero if not using MS-Windows. */
6803 track_mouse_window
= NULL
;
6805 w32_visible_system_caret_hwnd
= NULL
;
6807 DEFSYM (Qsuppress_icon
, "suppress-icon");
6808 DEFSYM (Qundefined_color
, "undefined-color");
6809 DEFSYM (Qcancel_timer
, "cancel-timer");
6810 DEFSYM (Qhyper
, "hyper");
6811 DEFSYM (Qsuper
, "super");
6812 DEFSYM (Qmeta
, "meta");
6813 DEFSYM (Qalt
, "alt");
6814 DEFSYM (Qctrl
, "ctrl");
6815 DEFSYM (Qcontrol
, "control");
6816 DEFSYM (Qshift
, "shift");
6817 DEFSYM (Qfont_param
, "font-parameter");
6818 /* This is the end of symbol initialization. */
6821 Fput (Qundefined_color
, Qerror_conditions
,
6822 listn (CONSTYPE_PURE
, 2, Qundefined_color
, Qerror
));
6823 Fput (Qundefined_color
, Qerror_message
,
6824 build_pure_c_string ("Undefined color"));
6826 staticpro (&w32_grabbed_keys
);
6827 w32_grabbed_keys
= Qnil
;
6829 DEFVAR_LISP ("w32-color-map", Vw32_color_map
,
6830 doc
: /* An array of color name mappings for Windows. */);
6831 Vw32_color_map
= Qnil
;
6833 DEFVAR_LISP ("w32-pass-alt-to-system", Vw32_pass_alt_to_system
,
6834 doc
: /* Non-nil if Alt key presses are passed on to Windows.
6835 When non-nil, for example, Alt pressed and released and then space will
6836 open the System menu. When nil, Emacs processes the Alt key events, and
6837 then silently swallows them. */);
6838 Vw32_pass_alt_to_system
= Qnil
;
6840 DEFVAR_LISP ("w32-alt-is-meta", Vw32_alt_is_meta
,
6841 doc
: /* Non-nil if the Alt key is to be considered the same as the META key.
6842 When nil, Emacs will translate the Alt key to the ALT modifier, not to META. */);
6843 Vw32_alt_is_meta
= Qt
;
6845 DEFVAR_INT ("w32-quit-key", w32_quit_key
,
6846 doc
: /* If non-zero, the virtual key code for an alternative quit key. */);
6849 DEFVAR_LISP ("w32-pass-lwindow-to-system",
6850 Vw32_pass_lwindow_to_system
,
6851 doc
: /* If non-nil, the left \"Windows\" key is passed on to Windows.
6853 When non-nil, the Start menu is opened by tapping the key.
6854 If you set this to nil, the left \"Windows\" key is processed by Emacs
6855 according to the value of `w32-lwindow-modifier', which see.
6857 Note that some combinations of the left \"Windows\" key with other keys are
6858 caught by Windows at low level, and so binding them in Emacs will have no
6859 effect. For example, <lwindow>-r always pops up the Windows Run dialog,
6860 <lwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
6861 the doc string of `w32-phantom-key-code'. */);
6862 Vw32_pass_lwindow_to_system
= Qt
;
6864 DEFVAR_LISP ("w32-pass-rwindow-to-system",
6865 Vw32_pass_rwindow_to_system
,
6866 doc
: /* If non-nil, the right \"Windows\" key is passed on to Windows.
6868 When non-nil, the Start menu is opened by tapping the key.
6869 If you set this to nil, the right \"Windows\" key is processed by Emacs
6870 according to the value of `w32-rwindow-modifier', which see.
6872 Note that some combinations of the right \"Windows\" key with other keys are
6873 caught by Windows at low level, and so binding them in Emacs will have no
6874 effect. For example, <rwindow>-r always pops up the Windows Run dialog,
6875 <rwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
6876 the doc string of `w32-phantom-key-code'. */);
6877 Vw32_pass_rwindow_to_system
= Qt
;
6879 DEFVAR_LISP ("w32-phantom-key-code",
6880 Vw32_phantom_key_code
,
6881 doc
: /* Virtual key code used to generate \"phantom\" key presses.
6882 Value is a number between 0 and 255.
6884 Phantom key presses are generated in order to stop the system from
6885 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or
6886 `w32-pass-rwindow-to-system' is nil. */);
6887 /* Although 255 is technically not a valid key code, it works and
6888 means that this hack won't interfere with any real key code. */
6889 XSETINT (Vw32_phantom_key_code
, 255);
6891 DEFVAR_LISP ("w32-enable-num-lock",
6892 Vw32_enable_num_lock
,
6893 doc
: /* If non-nil, the Num Lock key acts normally.
6894 Set to nil to handle Num Lock as the `kp-numlock' key. */);
6895 Vw32_enable_num_lock
= Qt
;
6897 DEFVAR_LISP ("w32-enable-caps-lock",
6898 Vw32_enable_caps_lock
,
6899 doc
: /* If non-nil, the Caps Lock key acts normally.
6900 Set to nil to handle Caps Lock as the `capslock' key. */);
6901 Vw32_enable_caps_lock
= Qt
;
6903 DEFVAR_LISP ("w32-scroll-lock-modifier",
6904 Vw32_scroll_lock_modifier
,
6905 doc
: /* Modifier to use for the Scroll Lock ON state.
6906 The value can be hyper, super, meta, alt, control or shift for the
6907 respective modifier, or nil to handle Scroll Lock as the `scroll' key.
6908 Any other value will cause the Scroll Lock key to be ignored. */);
6909 Vw32_scroll_lock_modifier
= Qnil
;
6911 DEFVAR_LISP ("w32-lwindow-modifier",
6912 Vw32_lwindow_modifier
,
6913 doc
: /* Modifier to use for the left \"Windows\" key.
6914 The value can be hyper, super, meta, alt, control or shift for the
6915 respective modifier, or nil to appear as the `lwindow' key.
6916 Any other value will cause the key to be ignored. */);
6917 Vw32_lwindow_modifier
= Qnil
;
6919 DEFVAR_LISP ("w32-rwindow-modifier",
6920 Vw32_rwindow_modifier
,
6921 doc
: /* Modifier to use for the right \"Windows\" key.
6922 The value can be hyper, super, meta, alt, control or shift for the
6923 respective modifier, or nil to appear as the `rwindow' key.
6924 Any other value will cause the key to be ignored. */);
6925 Vw32_rwindow_modifier
= Qnil
;
6927 DEFVAR_LISP ("w32-apps-modifier",
6929 doc
: /* Modifier to use for the \"Apps\" key.
6930 The value can be hyper, super, meta, alt, control or shift for the
6931 respective modifier, or nil to appear as the `apps' key.
6932 Any other value will cause the key to be ignored. */);
6933 Vw32_apps_modifier
= Qnil
;
6935 DEFVAR_BOOL ("w32-enable-synthesized-fonts", w32_enable_synthesized_fonts
,
6936 doc
: /* Non-nil enables selection of artificially italicized and bold fonts. */);
6937 w32_enable_synthesized_fonts
= 0;
6939 DEFVAR_LISP ("w32-enable-palette", Vw32_enable_palette
,
6940 doc
: /* Non-nil enables Windows palette management to map colors exactly. */);
6941 Vw32_enable_palette
= Qt
;
6943 DEFVAR_INT ("w32-mouse-button-tolerance",
6944 w32_mouse_button_tolerance
,
6945 doc
: /* Analogue of double click interval for faking middle mouse events.
6946 The value is the minimum time in milliseconds that must elapse between
6947 left and right button down events before they are considered distinct events.
6948 If both mouse buttons are depressed within this interval, a middle mouse
6949 button down event is generated instead. */);
6950 w32_mouse_button_tolerance
= GetDoubleClickTime () / 2;
6952 DEFVAR_INT ("w32-mouse-move-interval",
6953 w32_mouse_move_interval
,
6954 doc
: /* Minimum interval between mouse move events.
6955 The value is the minimum time in milliseconds that must elapse between
6956 successive mouse move (or scroll bar drag) events before they are
6957 reported as lisp events. */);
6958 w32_mouse_move_interval
= 0;
6960 DEFVAR_BOOL ("w32-pass-extra-mouse-buttons-to-system",
6961 w32_pass_extra_mouse_buttons_to_system
,
6962 doc
: /* If non-nil, the fourth and fifth mouse buttons are passed to Windows.
6963 Recent versions of Windows support mice with up to five buttons.
6964 Since most applications don't support these extra buttons, most mouse
6965 drivers will allow you to map them to functions at the system level.
6966 If this variable is non-nil, Emacs will pass them on, allowing the
6967 system to handle them. */);
6968 w32_pass_extra_mouse_buttons_to_system
= 0;
6970 DEFVAR_BOOL ("w32-pass-multimedia-buttons-to-system",
6971 w32_pass_multimedia_buttons_to_system
,
6972 doc
: /* If non-nil, media buttons are passed to Windows.
6973 Some modern keyboards contain buttons for controlling media players, web
6974 browsers and other applications. Generally these buttons are handled on a
6975 system wide basis, but by setting this to nil they are made available
6976 to Emacs for binding. Depending on your keyboard, additional keys that
6977 may be available are:
6979 browser-back, browser-forward, browser-refresh, browser-stop,
6980 browser-search, browser-favorites, browser-home,
6981 mail, mail-reply, mail-forward, mail-send,
6983 help, find, new, open, close, save, print, undo, redo, copy, cut, paste,
6984 spell-check, correction-list, toggle-dictate-command,
6985 media-next, media-previous, media-stop, media-play-pause, media-select,
6986 media-play, media-pause, media-record, media-fast-forward, media-rewind,
6987 media-channel-up, media-channel-down,
6988 volume-mute, volume-up, volume-down,
6989 mic-volume-mute, mic-volume-down, mic-volume-up, mic-toggle,
6990 bass-down, bass-boost, bass-up, treble-down, treble-up */);
6991 w32_pass_multimedia_buttons_to_system
= 1;
6993 #if 0 /* TODO: Mouse cursor customization. */
6994 DEFVAR_LISP ("x-pointer-shape", Vx_pointer_shape
,
6995 doc
: /* The shape of the pointer when over text.
6996 Changing the value does not affect existing frames
6997 unless you set the mouse color. */);
6998 Vx_pointer_shape
= Qnil
;
7000 Vx_nontext_pointer_shape
= Qnil
;
7002 Vx_mode_pointer_shape
= Qnil
;
7004 DEFVAR_LISP ("x-hourglass-pointer-shape", Vx_hourglass_pointer_shape
,
7005 doc
: /* The shape of the pointer when Emacs is busy.
7006 This variable takes effect when you create a new frame
7007 or when you set the mouse color. */);
7008 Vx_hourglass_pointer_shape
= Qnil
;
7010 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
7011 Vx_sensitive_text_pointer_shape
,
7012 doc
: /* The shape of the pointer when over mouse-sensitive text.
7013 This variable takes effect when you create a new frame
7014 or when you set the mouse color. */);
7015 Vx_sensitive_text_pointer_shape
= Qnil
;
7017 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
7018 Vx_window_horizontal_drag_shape
,
7019 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
7020 This variable takes effect when you create a new frame
7021 or when you set the mouse color. */);
7022 Vx_window_horizontal_drag_shape
= Qnil
;
7025 DEFVAR_LISP ("x-cursor-fore-pixel", Vx_cursor_fore_pixel
,
7026 doc
: /* A string indicating the foreground color of the cursor box. */);
7027 Vx_cursor_fore_pixel
= Qnil
;
7029 DEFVAR_LISP ("x-max-tooltip-size", Vx_max_tooltip_size
,
7030 doc
: /* Maximum size for tooltips.
7031 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
7032 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
7034 DEFVAR_LISP ("x-no-window-manager", Vx_no_window_manager
,
7035 doc
: /* Non-nil if no window manager is in use.
7036 Emacs doesn't try to figure this out; this is always nil
7037 unless you set it to something else. */);
7038 /* We don't have any way to find this out, so set it to nil
7039 and maybe the user would like to set it to t. */
7040 Vx_no_window_manager
= Qnil
;
7042 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
7043 Vx_pixel_size_width_font_regexp
,
7044 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
7046 Since Emacs gets width of a font matching with this regexp from
7047 PIXEL_SIZE field of the name, font finding mechanism gets faster for
7048 such a font. This is especially effective for such large fonts as
7049 Chinese, Japanese, and Korean. */);
7050 Vx_pixel_size_width_font_regexp
= Qnil
;
7052 DEFVAR_LISP ("w32-bdf-filename-alist",
7053 Vw32_bdf_filename_alist
,
7054 doc
: /* List of bdf fonts and their corresponding filenames. */);
7055 Vw32_bdf_filename_alist
= Qnil
;
7057 DEFVAR_BOOL ("w32-strict-fontnames",
7058 w32_strict_fontnames
,
7059 doc
: /* Non-nil means only use fonts that are exact matches for those requested.
7060 Default is nil, which allows old fontnames that are not XLFD compliant,
7061 and allows third-party CJK display to work by specifying false charset
7062 fields to trick Emacs into translating to Big5, SJIS etc.
7063 Setting this to t will prevent wrong fonts being selected when
7064 fontsets are automatically created. */);
7065 w32_strict_fontnames
= 0;
7067 DEFVAR_BOOL ("w32-strict-painting",
7068 w32_strict_painting
,
7069 doc
: /* Non-nil means use strict rules for repainting frames.
7070 Set this to nil to get the old behavior for repainting; this should
7071 only be necessary if the default setting causes problems. */);
7072 w32_strict_painting
= 1;
7074 #if 0 /* TODO: Port to W32 */
7075 defsubr (&Sx_change_window_property
);
7076 defsubr (&Sx_delete_window_property
);
7077 defsubr (&Sx_window_property
);
7079 defsubr (&Sxw_display_color_p
);
7080 defsubr (&Sx_display_grayscale_p
);
7081 defsubr (&Sxw_color_defined_p
);
7082 defsubr (&Sxw_color_values
);
7083 defsubr (&Sx_server_max_request_size
);
7084 defsubr (&Sx_server_vendor
);
7085 defsubr (&Sx_server_version
);
7086 defsubr (&Sx_display_pixel_width
);
7087 defsubr (&Sx_display_pixel_height
);
7088 defsubr (&Sx_display_mm_width
);
7089 defsubr (&Sx_display_mm_height
);
7090 defsubr (&Sx_display_screens
);
7091 defsubr (&Sx_display_planes
);
7092 defsubr (&Sx_display_color_cells
);
7093 defsubr (&Sx_display_visual_class
);
7094 defsubr (&Sx_display_backing_store
);
7095 defsubr (&Sx_display_save_under
);
7096 defsubr (&Sx_create_frame
);
7097 defsubr (&Sx_open_connection
);
7098 defsubr (&Sx_close_connection
);
7099 defsubr (&Sx_display_list
);
7100 defsubr (&Sx_synchronize
);
7101 defsubr (&Sx_focus_frame
);
7103 /* W32 specific functions */
7105 defsubr (&Sw32_define_rgb_color
);
7106 defsubr (&Sw32_default_color_map
);
7107 defsubr (&Sw32_send_sys_command
);
7108 defsubr (&Sw32_shell_execute
);
7109 defsubr (&Sw32_register_hot_key
);
7110 defsubr (&Sw32_unregister_hot_key
);
7111 defsubr (&Sw32_registered_hot_keys
);
7112 defsubr (&Sw32_reconstruct_hot_key
);
7113 defsubr (&Sw32_toggle_lock_key
);
7114 defsubr (&Sw32_window_exists_p
);
7115 defsubr (&Sw32_battery_status
);
7117 defsubr (&Sfile_system_info
);
7118 defsubr (&Sdefault_printer_name
);
7120 check_window_system_func
= check_w32
;
7122 hourglass_hwnd
= NULL
;
7124 defsubr (&Sx_show_tip
);
7125 defsubr (&Sx_hide_tip
);
7127 staticpro (&tip_timer
);
7129 staticpro (&tip_frame
);
7131 last_show_tip_args
= Qnil
;
7132 staticpro (&last_show_tip_args
);
7134 defsubr (&Sx_file_dialog
);
7135 defsubr (&Ssystem_move_file_to_trash
);
7140 globals_of_w32fns is used to initialize those global variables that
7141 must always be initialized on startup even when the global variable
7142 initialized is non zero (see the function main in emacs.c).
7143 globals_of_w32fns is called from syms_of_w32fns when the global
7144 variable initialized is 0 and directly from main when initialized
7148 globals_of_w32fns (void)
7150 HMODULE user32_lib
= GetModuleHandle ("user32.dll");
7152 TrackMouseEvent not available in all versions of Windows, so must load
7153 it dynamically. Do it once, here, instead of every time it is used.
7155 track_mouse_event_fn
= (TrackMouseEvent_Proc
)
7156 GetProcAddress (user32_lib
, "TrackMouseEvent");
7158 monitor_from_point_fn
= (MonitorFromPoint_Proc
)
7159 GetProcAddress (user32_lib
, "MonitorFromPoint");
7160 get_monitor_info_fn
= (GetMonitorInfo_Proc
)
7161 GetProcAddress (user32_lib
, "GetMonitorInfoA");
7164 HMODULE imm32_lib
= GetModuleHandle ("imm32.dll");
7165 get_composition_string_fn
= (ImmGetCompositionString_Proc
)
7166 GetProcAddress (imm32_lib
, "ImmGetCompositionStringW");
7167 get_ime_context_fn
= (ImmGetContext_Proc
)
7168 GetProcAddress (imm32_lib
, "ImmGetContext");
7169 release_ime_context_fn
= (ImmReleaseContext_Proc
)
7170 GetProcAddress (imm32_lib
, "ImmReleaseContext");
7171 set_ime_composition_window_fn
= (ImmSetCompositionWindow_Proc
)
7172 GetProcAddress (imm32_lib
, "ImmSetCompositionWindow");
7174 DEFVAR_INT ("w32-ansi-code-page",
7176 doc
: /* The ANSI code page used by the system. */);
7177 w32_ansi_code_page
= GetACP ();
7179 if (os_subtype
== OS_NT
)
7180 w32_unicode_gui
= 1;
7182 w32_unicode_gui
= 0;
7184 /* MessageBox does not work without this when linked to comctl32.dll 6.0. */
7185 InitCommonControls ();
7187 syms_of_w32uniscribe ();
7194 button
= MessageBox (NULL
,
7195 "A fatal error has occurred!\n\n"
7196 "Would you like to attach a debugger?\n\n"
7197 "Select YES to debug, NO to abort Emacs"
7199 "\n\n(type \"gdb -p <emacs-PID>\" and\n"
7200 "\"continue\" inside GDB before clicking YES.)"
7202 , "Emacs Abort Dialog",
7203 MB_ICONEXCLAMATION
| MB_TASKMODAL
7204 | MB_SETFOREGROUND
| MB_YESNO
);
7209 exit (2); /* tell the compiler we will never return */
7217 /* For convenience when debugging. */
7219 w32_last_error (void)
7221 return GetLastError ();