1 /* Graphical user interface functions for the Microsoft W32 API.
3 Copyright (C) 1989, 1992-2011 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 /* Added by Kevin Gallo */
36 #include "intervals.h"
37 #include "dispextern.h"
39 #include "blockinput.h"
41 #include "character.h"
47 #include "termhooks.h"
51 #include "bitmaps/gray.xbm"
62 #define FILE_NAME_TEXT_FIELD edt1
63 #define FILE_NAME_COMBO_BOX cmb13
64 #define FILE_NAME_LIST lst1
69 #ifndef FOF_NO_CONNECTED_ELEMENTS
70 #define FOF_NO_CONNECTED_ELEMENTS 0x2000
73 void syms_of_w32fns (void);
74 void globals_of_w32fns (void);
76 extern void free_frame_menubar (struct frame
*);
77 extern double atof (const char *);
78 extern int w32_console_toggle_lock_key (int, Lisp_Object
);
79 extern void w32_menu_display_help (HWND
, HMENU
, UINT
, UINT
);
80 extern void w32_free_menu_strings (HWND
);
81 extern const char *map_w32_filename (const char *, const char **);
83 /* If non-zero, a w32 timer that, when it expires, displays an
84 hourglass cursor on all frames. */
85 static unsigned hourglass_timer
= 0;
86 static HWND hourglass_hwnd
= NULL
;
89 #define IDC_HAND MAKEINTRESOURCE(32649)
92 /* Nonzero if using Windows. */
94 static int w32_in_use
;
97 Lisp_Object Qsuppress_icon
;
98 Lisp_Object Qundefined_color
;
99 Lisp_Object Qcancel_timer
;
100 Lisp_Object Qfont_param
;
106 Lisp_Object Qcontrol
;
110 /* Prefix for system colors. */
111 #define SYSTEM_COLOR_PREFIX "System"
112 #define SYSTEM_COLOR_PREFIX_LEN (sizeof (SYSTEM_COLOR_PREFIX) - 1)
114 /* State variables for emulating a three button mouse. */
119 static int button_state
= 0;
120 static W32Msg saved_mouse_button_msg
;
121 static unsigned mouse_button_timer
= 0; /* non-zero when timer is active */
122 static W32Msg saved_mouse_move_msg
;
123 static unsigned mouse_move_timer
= 0;
125 /* Window that is tracking the mouse. */
126 static HWND track_mouse_window
;
128 /* Multi-monitor API definitions that are not pulled from the headers
129 since we are compiling for NT 4. */
130 #ifndef MONITOR_DEFAULT_TO_NEAREST
131 #define MONITOR_DEFAULT_TO_NEAREST 2
133 /* MinGW headers define MONITORINFO unconditionally, but MSVC ones don't.
134 To avoid a compile error on one or the other, redefine with a new name. */
143 /* Reportedly, VS 6 does not have this in its headers. */
144 #if defined (_MSC_VER) && _MSC_VER < 1300
145 DECLARE_HANDLE(HMONITOR
);
148 typedef BOOL (WINAPI
* TrackMouseEvent_Proc
)
149 (IN OUT LPTRACKMOUSEEVENT lpEventTrack
);
150 typedef LONG (WINAPI
* ImmGetCompositionString_Proc
)
151 (IN HIMC context
, IN DWORD index
, OUT LPVOID buffer
, IN DWORD bufLen
);
152 typedef HIMC (WINAPI
* ImmGetContext_Proc
) (IN HWND window
);
153 typedef HWND (WINAPI
* ImmReleaseContext_Proc
) (IN HWND wnd
, IN HIMC context
);
154 typedef HWND (WINAPI
* ImmSetCompositionWindow_Proc
) (IN HIMC context
,
155 IN COMPOSITIONFORM
*form
);
156 typedef HMONITOR (WINAPI
* MonitorFromPoint_Proc
) (IN POINT pt
, IN DWORD flags
);
157 typedef BOOL (WINAPI
* GetMonitorInfo_Proc
)
158 (IN HMONITOR monitor
, OUT
struct MONITOR_INFO
* info
);
160 TrackMouseEvent_Proc track_mouse_event_fn
= NULL
;
161 ImmGetCompositionString_Proc get_composition_string_fn
= NULL
;
162 ImmGetContext_Proc get_ime_context_fn
= NULL
;
163 ImmReleaseContext_Proc release_ime_context_fn
= NULL
;
164 ImmSetCompositionWindow_Proc set_ime_composition_window_fn
= NULL
;
165 MonitorFromPoint_Proc monitor_from_point_fn
= NULL
;
166 GetMonitorInfo_Proc get_monitor_info_fn
= NULL
;
168 extern AppendMenuW_Proc unicode_append_menu
;
170 /* Flag to selectively ignore WM_IME_CHAR messages. */
171 static int ignore_ime_char
= 0;
173 /* W95 mousewheel handler */
174 unsigned int msh_mousewheel
= 0;
177 #define MOUSE_BUTTON_ID 1
178 #define MOUSE_MOVE_ID 2
179 #define MENU_FREE_ID 3
180 #define HOURGLASS_ID 4
181 /* The delay (milliseconds) before a menu is freed after WM_EXITMENULOOP
183 #define MENU_FREE_DELAY 1000
184 static unsigned menu_free_timer
= 0;
187 int image_cache_refcount
, dpyinfo_refcount
;
190 static HWND w32_visible_system_caret_hwnd
;
193 extern HMENU current_popup_menu
;
194 static int menubar_in_use
= 0;
196 /* From w32uniscribe.c */
197 extern void syms_of_w32uniscribe (void);
198 extern int uniscribe_available
;
200 /* Function prototypes for hourglass support. */
201 static void w32_show_hourglass (struct frame
*);
202 static void w32_hide_hourglass (void);
206 /* Error if we are not connected to MS-Windows. */
211 error ("MS-Windows not in use or not initialized");
214 /* Nonzero if we can use mouse menus.
215 You should not call this unless HAVE_MENUS is defined. */
223 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
224 and checking validity for W32. */
227 check_x_frame (Lisp_Object frame
)
232 frame
= selected_frame
;
233 CHECK_LIVE_FRAME (frame
);
235 if (! FRAME_W32_P (f
))
236 error ("Non-W32 frame used");
240 /* Let the user specify a display with a frame.
241 nil stands for the selected frame--or, if that is not a w32 frame,
242 the first display on the list. */
244 struct w32_display_info
*
245 check_x_display_info (Lisp_Object frame
)
249 struct frame
*sf
= XFRAME (selected_frame
);
251 if (FRAME_W32_P (sf
) && FRAME_LIVE_P (sf
))
252 return FRAME_W32_DISPLAY_INFO (sf
);
254 return &one_w32_display_info
;
256 else if (STRINGP (frame
))
257 return x_display_info_for_name (frame
);
262 CHECK_LIVE_FRAME (frame
);
264 if (! FRAME_W32_P (f
))
265 error ("Non-W32 frame used");
266 return FRAME_W32_DISPLAY_INFO (f
);
270 /* Return the Emacs frame-object corresponding to an w32 window.
271 It could be the frame's main window or an icon window. */
273 /* This function can be called during GC, so use GC_xxx type test macros. */
276 x_window_to_frame (struct w32_display_info
*dpyinfo
, HWND wdesc
)
278 Lisp_Object tail
, frame
;
281 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
287 if (!FRAME_W32_P (f
) || FRAME_W32_DISPLAY_INFO (f
) != dpyinfo
)
290 if (FRAME_W32_WINDOW (f
) == wdesc
)
297 static Lisp_Object
unwind_create_frame (Lisp_Object
);
298 static Lisp_Object
unwind_create_tip_frame (Lisp_Object
);
299 static void my_create_window (struct frame
*);
300 static void my_create_tip_window (struct frame
*);
302 /* TODO: Native Input Method support; see x_create_im. */
303 void x_set_foreground_color (struct frame
*, Lisp_Object
, Lisp_Object
);
304 void x_set_background_color (struct frame
*, Lisp_Object
, Lisp_Object
);
305 void x_set_mouse_color (struct frame
*, Lisp_Object
, Lisp_Object
);
306 void x_set_cursor_color (struct frame
*, Lisp_Object
, Lisp_Object
);
307 void x_set_border_color (struct frame
*, Lisp_Object
, Lisp_Object
);
308 void x_set_cursor_type (struct frame
*, Lisp_Object
, Lisp_Object
);
309 void x_set_icon_type (struct frame
*, Lisp_Object
, Lisp_Object
);
310 void x_set_icon_name (struct frame
*, Lisp_Object
, Lisp_Object
);
311 void x_explicitly_set_name (struct frame
*, Lisp_Object
, Lisp_Object
);
312 void x_set_menu_bar_lines (struct frame
*, Lisp_Object
, Lisp_Object
);
313 void x_set_title (struct frame
*, Lisp_Object
, Lisp_Object
);
314 void x_set_tool_bar_lines (struct frame
*, Lisp_Object
, Lisp_Object
);
319 /* Store the screen positions of frame F into XPTR and YPTR.
320 These are the positions of the containing window manager window,
321 not Emacs's own window. */
324 x_real_positions (FRAME_PTR f
, int *xptr
, int *yptr
)
329 /* Get the bounds of the WM window. */
330 GetWindowRect (FRAME_W32_WINDOW (f
), &rect
);
335 /* Convert (0, 0) in the client area to screen co-ordinates. */
336 ClientToScreen (FRAME_W32_WINDOW (f
), &pt
);
338 /* Remember x_pixels_diff and y_pixels_diff. */
339 f
->x_pixels_diff
= pt
.x
- rect
.left
;
340 f
->y_pixels_diff
= pt
.y
- rect
.top
;
348 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
,
349 Sw32_define_rgb_color
, 4, 4, 0,
350 doc
: /* Convert RGB numbers to a Windows color reference and associate with NAME.
351 This adds or updates a named color to `w32-color-map', making it
352 available for use. The original entry's RGB ref is returned, or nil
353 if the entry is new. */)
354 (Lisp_Object red
, Lisp_Object green
, Lisp_Object blue
, Lisp_Object name
)
357 Lisp_Object oldrgb
= Qnil
;
361 CHECK_NUMBER (green
);
365 XSETINT (rgb
, RGB (XUINT (red
), XUINT (green
), XUINT (blue
)));
369 /* replace existing entry in w32-color-map or add new entry. */
370 entry
= Fassoc (name
, Vw32_color_map
);
373 entry
= Fcons (name
, rgb
);
374 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
378 oldrgb
= Fcdr (entry
);
379 Fsetcdr (entry
, rgb
);
387 /* The default colors for the w32 color map */
388 typedef struct colormap_t
394 colormap_t w32_color_map
[] =
396 {"snow" , PALETTERGB (255,250,250)},
397 {"ghost white" , PALETTERGB (248,248,255)},
398 {"GhostWhite" , PALETTERGB (248,248,255)},
399 {"white smoke" , PALETTERGB (245,245,245)},
400 {"WhiteSmoke" , PALETTERGB (245,245,245)},
401 {"gainsboro" , PALETTERGB (220,220,220)},
402 {"floral white" , PALETTERGB (255,250,240)},
403 {"FloralWhite" , PALETTERGB (255,250,240)},
404 {"old lace" , PALETTERGB (253,245,230)},
405 {"OldLace" , PALETTERGB (253,245,230)},
406 {"linen" , PALETTERGB (250,240,230)},
407 {"antique white" , PALETTERGB (250,235,215)},
408 {"AntiqueWhite" , PALETTERGB (250,235,215)},
409 {"papaya whip" , PALETTERGB (255,239,213)},
410 {"PapayaWhip" , PALETTERGB (255,239,213)},
411 {"blanched almond" , PALETTERGB (255,235,205)},
412 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
413 {"bisque" , PALETTERGB (255,228,196)},
414 {"peach puff" , PALETTERGB (255,218,185)},
415 {"PeachPuff" , PALETTERGB (255,218,185)},
416 {"navajo white" , PALETTERGB (255,222,173)},
417 {"NavajoWhite" , PALETTERGB (255,222,173)},
418 {"moccasin" , PALETTERGB (255,228,181)},
419 {"cornsilk" , PALETTERGB (255,248,220)},
420 {"ivory" , PALETTERGB (255,255,240)},
421 {"lemon chiffon" , PALETTERGB (255,250,205)},
422 {"LemonChiffon" , PALETTERGB (255,250,205)},
423 {"seashell" , PALETTERGB (255,245,238)},
424 {"honeydew" , PALETTERGB (240,255,240)},
425 {"mint cream" , PALETTERGB (245,255,250)},
426 {"MintCream" , PALETTERGB (245,255,250)},
427 {"azure" , PALETTERGB (240,255,255)},
428 {"alice blue" , PALETTERGB (240,248,255)},
429 {"AliceBlue" , PALETTERGB (240,248,255)},
430 {"lavender" , PALETTERGB (230,230,250)},
431 {"lavender blush" , PALETTERGB (255,240,245)},
432 {"LavenderBlush" , PALETTERGB (255,240,245)},
433 {"misty rose" , PALETTERGB (255,228,225)},
434 {"MistyRose" , PALETTERGB (255,228,225)},
435 {"white" , PALETTERGB (255,255,255)},
436 {"black" , PALETTERGB ( 0, 0, 0)},
437 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
438 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
439 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
440 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
441 {"dim gray" , PALETTERGB (105,105,105)},
442 {"DimGray" , PALETTERGB (105,105,105)},
443 {"dim grey" , PALETTERGB (105,105,105)},
444 {"DimGrey" , PALETTERGB (105,105,105)},
445 {"slate gray" , PALETTERGB (112,128,144)},
446 {"SlateGray" , PALETTERGB (112,128,144)},
447 {"slate grey" , PALETTERGB (112,128,144)},
448 {"SlateGrey" , PALETTERGB (112,128,144)},
449 {"light slate gray" , PALETTERGB (119,136,153)},
450 {"LightSlateGray" , PALETTERGB (119,136,153)},
451 {"light slate grey" , PALETTERGB (119,136,153)},
452 {"LightSlateGrey" , PALETTERGB (119,136,153)},
453 {"gray" , PALETTERGB (190,190,190)},
454 {"grey" , PALETTERGB (190,190,190)},
455 {"light grey" , PALETTERGB (211,211,211)},
456 {"LightGrey" , PALETTERGB (211,211,211)},
457 {"light gray" , PALETTERGB (211,211,211)},
458 {"LightGray" , PALETTERGB (211,211,211)},
459 {"midnight blue" , PALETTERGB ( 25, 25,112)},
460 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
461 {"navy" , PALETTERGB ( 0, 0,128)},
462 {"navy blue" , PALETTERGB ( 0, 0,128)},
463 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
464 {"cornflower blue" , PALETTERGB (100,149,237)},
465 {"CornflowerBlue" , PALETTERGB (100,149,237)},
466 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
467 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
468 {"slate blue" , PALETTERGB (106, 90,205)},
469 {"SlateBlue" , PALETTERGB (106, 90,205)},
470 {"medium slate blue" , PALETTERGB (123,104,238)},
471 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
472 {"light slate blue" , PALETTERGB (132,112,255)},
473 {"LightSlateBlue" , PALETTERGB (132,112,255)},
474 {"medium blue" , PALETTERGB ( 0, 0,205)},
475 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
476 {"royal blue" , PALETTERGB ( 65,105,225)},
477 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
478 {"blue" , PALETTERGB ( 0, 0,255)},
479 {"dodger blue" , PALETTERGB ( 30,144,255)},
480 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
481 {"deep sky blue" , PALETTERGB ( 0,191,255)},
482 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
483 {"sky blue" , PALETTERGB (135,206,235)},
484 {"SkyBlue" , PALETTERGB (135,206,235)},
485 {"light sky blue" , PALETTERGB (135,206,250)},
486 {"LightSkyBlue" , PALETTERGB (135,206,250)},
487 {"steel blue" , PALETTERGB ( 70,130,180)},
488 {"SteelBlue" , PALETTERGB ( 70,130,180)},
489 {"light steel blue" , PALETTERGB (176,196,222)},
490 {"LightSteelBlue" , PALETTERGB (176,196,222)},
491 {"light blue" , PALETTERGB (173,216,230)},
492 {"LightBlue" , PALETTERGB (173,216,230)},
493 {"powder blue" , PALETTERGB (176,224,230)},
494 {"PowderBlue" , PALETTERGB (176,224,230)},
495 {"pale turquoise" , PALETTERGB (175,238,238)},
496 {"PaleTurquoise" , PALETTERGB (175,238,238)},
497 {"dark turquoise" , PALETTERGB ( 0,206,209)},
498 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
499 {"medium turquoise" , PALETTERGB ( 72,209,204)},
500 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
501 {"turquoise" , PALETTERGB ( 64,224,208)},
502 {"cyan" , PALETTERGB ( 0,255,255)},
503 {"light cyan" , PALETTERGB (224,255,255)},
504 {"LightCyan" , PALETTERGB (224,255,255)},
505 {"cadet blue" , PALETTERGB ( 95,158,160)},
506 {"CadetBlue" , PALETTERGB ( 95,158,160)},
507 {"medium aquamarine" , PALETTERGB (102,205,170)},
508 {"MediumAquamarine" , PALETTERGB (102,205,170)},
509 {"aquamarine" , PALETTERGB (127,255,212)},
510 {"dark green" , PALETTERGB ( 0,100, 0)},
511 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
512 {"dark olive green" , PALETTERGB ( 85,107, 47)},
513 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
514 {"dark sea green" , PALETTERGB (143,188,143)},
515 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
516 {"sea green" , PALETTERGB ( 46,139, 87)},
517 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
518 {"medium sea green" , PALETTERGB ( 60,179,113)},
519 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
520 {"light sea green" , PALETTERGB ( 32,178,170)},
521 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
522 {"pale green" , PALETTERGB (152,251,152)},
523 {"PaleGreen" , PALETTERGB (152,251,152)},
524 {"spring green" , PALETTERGB ( 0,255,127)},
525 {"SpringGreen" , PALETTERGB ( 0,255,127)},
526 {"lawn green" , PALETTERGB (124,252, 0)},
527 {"LawnGreen" , PALETTERGB (124,252, 0)},
528 {"green" , PALETTERGB ( 0,255, 0)},
529 {"chartreuse" , PALETTERGB (127,255, 0)},
530 {"medium spring green" , PALETTERGB ( 0,250,154)},
531 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
532 {"green yellow" , PALETTERGB (173,255, 47)},
533 {"GreenYellow" , PALETTERGB (173,255, 47)},
534 {"lime green" , PALETTERGB ( 50,205, 50)},
535 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
536 {"yellow green" , PALETTERGB (154,205, 50)},
537 {"YellowGreen" , PALETTERGB (154,205, 50)},
538 {"forest green" , PALETTERGB ( 34,139, 34)},
539 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
540 {"olive drab" , PALETTERGB (107,142, 35)},
541 {"OliveDrab" , PALETTERGB (107,142, 35)},
542 {"dark khaki" , PALETTERGB (189,183,107)},
543 {"DarkKhaki" , PALETTERGB (189,183,107)},
544 {"khaki" , PALETTERGB (240,230,140)},
545 {"pale goldenrod" , PALETTERGB (238,232,170)},
546 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
547 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
548 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
549 {"light yellow" , PALETTERGB (255,255,224)},
550 {"LightYellow" , PALETTERGB (255,255,224)},
551 {"yellow" , PALETTERGB (255,255, 0)},
552 {"gold" , PALETTERGB (255,215, 0)},
553 {"light goldenrod" , PALETTERGB (238,221,130)},
554 {"LightGoldenrod" , PALETTERGB (238,221,130)},
555 {"goldenrod" , PALETTERGB (218,165, 32)},
556 {"dark goldenrod" , PALETTERGB (184,134, 11)},
557 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
558 {"rosy brown" , PALETTERGB (188,143,143)},
559 {"RosyBrown" , PALETTERGB (188,143,143)},
560 {"indian red" , PALETTERGB (205, 92, 92)},
561 {"IndianRed" , PALETTERGB (205, 92, 92)},
562 {"saddle brown" , PALETTERGB (139, 69, 19)},
563 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
564 {"sienna" , PALETTERGB (160, 82, 45)},
565 {"peru" , PALETTERGB (205,133, 63)},
566 {"burlywood" , PALETTERGB (222,184,135)},
567 {"beige" , PALETTERGB (245,245,220)},
568 {"wheat" , PALETTERGB (245,222,179)},
569 {"sandy brown" , PALETTERGB (244,164, 96)},
570 {"SandyBrown" , PALETTERGB (244,164, 96)},
571 {"tan" , PALETTERGB (210,180,140)},
572 {"chocolate" , PALETTERGB (210,105, 30)},
573 {"firebrick" , PALETTERGB (178,34, 34)},
574 {"brown" , PALETTERGB (165,42, 42)},
575 {"dark salmon" , PALETTERGB (233,150,122)},
576 {"DarkSalmon" , PALETTERGB (233,150,122)},
577 {"salmon" , PALETTERGB (250,128,114)},
578 {"light salmon" , PALETTERGB (255,160,122)},
579 {"LightSalmon" , PALETTERGB (255,160,122)},
580 {"orange" , PALETTERGB (255,165, 0)},
581 {"dark orange" , PALETTERGB (255,140, 0)},
582 {"DarkOrange" , PALETTERGB (255,140, 0)},
583 {"coral" , PALETTERGB (255,127, 80)},
584 {"light coral" , PALETTERGB (240,128,128)},
585 {"LightCoral" , PALETTERGB (240,128,128)},
586 {"tomato" , PALETTERGB (255, 99, 71)},
587 {"orange red" , PALETTERGB (255, 69, 0)},
588 {"OrangeRed" , PALETTERGB (255, 69, 0)},
589 {"red" , PALETTERGB (255, 0, 0)},
590 {"hot pink" , PALETTERGB (255,105,180)},
591 {"HotPink" , PALETTERGB (255,105,180)},
592 {"deep pink" , PALETTERGB (255, 20,147)},
593 {"DeepPink" , PALETTERGB (255, 20,147)},
594 {"pink" , PALETTERGB (255,192,203)},
595 {"light pink" , PALETTERGB (255,182,193)},
596 {"LightPink" , PALETTERGB (255,182,193)},
597 {"pale violet red" , PALETTERGB (219,112,147)},
598 {"PaleVioletRed" , PALETTERGB (219,112,147)},
599 {"maroon" , PALETTERGB (176, 48, 96)},
600 {"medium violet red" , PALETTERGB (199, 21,133)},
601 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
602 {"violet red" , PALETTERGB (208, 32,144)},
603 {"VioletRed" , PALETTERGB (208, 32,144)},
604 {"magenta" , PALETTERGB (255, 0,255)},
605 {"violet" , PALETTERGB (238,130,238)},
606 {"plum" , PALETTERGB (221,160,221)},
607 {"orchid" , PALETTERGB (218,112,214)},
608 {"medium orchid" , PALETTERGB (186, 85,211)},
609 {"MediumOrchid" , PALETTERGB (186, 85,211)},
610 {"dark orchid" , PALETTERGB (153, 50,204)},
611 {"DarkOrchid" , PALETTERGB (153, 50,204)},
612 {"dark violet" , PALETTERGB (148, 0,211)},
613 {"DarkViolet" , PALETTERGB (148, 0,211)},
614 {"blue violet" , PALETTERGB (138, 43,226)},
615 {"BlueViolet" , PALETTERGB (138, 43,226)},
616 {"purple" , PALETTERGB (160, 32,240)},
617 {"medium purple" , PALETTERGB (147,112,219)},
618 {"MediumPurple" , PALETTERGB (147,112,219)},
619 {"thistle" , PALETTERGB (216,191,216)},
620 {"gray0" , PALETTERGB ( 0, 0, 0)},
621 {"grey0" , PALETTERGB ( 0, 0, 0)},
622 {"dark grey" , PALETTERGB (169,169,169)},
623 {"DarkGrey" , PALETTERGB (169,169,169)},
624 {"dark gray" , PALETTERGB (169,169,169)},
625 {"DarkGray" , PALETTERGB (169,169,169)},
626 {"dark blue" , PALETTERGB ( 0, 0,139)},
627 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
628 {"dark cyan" , PALETTERGB ( 0,139,139)},
629 {"DarkCyan" , PALETTERGB ( 0,139,139)},
630 {"dark magenta" , PALETTERGB (139, 0,139)},
631 {"DarkMagenta" , PALETTERGB (139, 0,139)},
632 {"dark red" , PALETTERGB (139, 0, 0)},
633 {"DarkRed" , PALETTERGB (139, 0, 0)},
634 {"light green" , PALETTERGB (144,238,144)},
635 {"LightGreen" , PALETTERGB (144,238,144)},
638 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
639 0, 0, 0, doc
: /* Return the default color map. */)
643 colormap_t
*pc
= w32_color_map
;
650 for (i
= 0; i
< sizeof (w32_color_map
) / sizeof (w32_color_map
[0]);
652 cmap
= Fcons (Fcons (build_string (pc
->name
),
653 make_number (pc
->colorref
)),
662 w32_color_map_lookup (char *colorname
)
664 Lisp_Object tail
, ret
= Qnil
;
668 for (tail
= Vw32_color_map
; CONSP (tail
); tail
= XCDR (tail
))
670 register Lisp_Object elt
, tem
;
673 if (!CONSP (elt
)) continue;
677 if (lstrcmpi (SDATA (tem
), colorname
) == 0)
694 add_system_logical_colors_to_map (Lisp_Object
*system_colors
)
698 /* Other registry operations are done with input blocked. */
701 /* Look for "Control Panel/Colors" under User and Machine registry
703 if (RegOpenKeyEx (HKEY_CURRENT_USER
, "Control Panel\\Colors", 0,
704 KEY_READ
, &colors_key
) == ERROR_SUCCESS
705 || RegOpenKeyEx (HKEY_LOCAL_MACHINE
, "Control Panel\\Colors", 0,
706 KEY_READ
, &colors_key
) == ERROR_SUCCESS
)
709 char color_buffer
[64];
710 char full_name_buffer
[MAX_PATH
+ SYSTEM_COLOR_PREFIX_LEN
];
712 DWORD name_size
, color_size
;
713 char *name_buffer
= full_name_buffer
+ SYSTEM_COLOR_PREFIX_LEN
;
715 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
716 color_size
= sizeof (color_buffer
);
718 strcpy (full_name_buffer
, SYSTEM_COLOR_PREFIX
);
720 while (RegEnumValueA (colors_key
, index
, name_buffer
, &name_size
,
721 NULL
, NULL
, color_buffer
, &color_size
)
725 if (sscanf (color_buffer
, " %u %u %u", &r
, &g
, &b
) == 3)
726 *system_colors
= Fcons (Fcons (build_string (full_name_buffer
),
727 make_number (RGB (r
, g
, b
))),
730 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
731 color_size
= sizeof (color_buffer
);
734 RegCloseKey (colors_key
);
742 x_to_w32_color (char * colorname
)
744 register Lisp_Object ret
= Qnil
;
748 if (colorname
[0] == '#')
750 /* Could be an old-style RGB Device specification. */
753 color
= colorname
+ 1;
755 size
= strlen (color
);
756 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
764 for (i
= 0; i
< 3; i
++)
770 /* The check for 'x' in the following conditional takes into
771 account the fact that strtol allows a "0x" in front of
772 our numbers, and we don't. */
773 if (!isxdigit (color
[0]) || color
[1] == 'x')
777 value
= strtoul (color
, &end
, 16);
779 if (errno
== ERANGE
|| end
- color
!= size
)
784 value
= value
* 0x10;
795 colorval
|= (value
<< pos
);
800 XSETINT (ret
, colorval
);
807 else if (strnicmp (colorname
, "rgb:", 4) == 0)
815 color
= colorname
+ 4;
816 for (i
= 0; i
< 3; i
++)
821 /* The check for 'x' in the following conditional takes into
822 account the fact that strtol allows a "0x" in front of
823 our numbers, and we don't. */
824 if (!isxdigit (color
[0]) || color
[1] == 'x')
826 value
= strtoul (color
, &end
, 16);
832 value
= value
* 0x10 + value
;
845 if (value
== ULONG_MAX
)
847 colorval
|= (value
<< pos
);
854 XSETINT (ret
, colorval
);
862 else if (strnicmp (colorname
, "rgbi:", 5) == 0)
864 /* This is an RGB Intensity specification. */
871 color
= colorname
+ 5;
872 for (i
= 0; i
< 3; i
++)
878 value
= strtod (color
, &end
);
881 if (value
< 0.0 || value
> 1.0)
883 val
= (UINT
)(0x100 * value
);
884 /* We used 0x100 instead of 0xFF to give a continuous
885 range between 0.0 and 1.0 inclusive. The next statement
886 fixes the 1.0 case. */
889 colorval
|= (val
<< pos
);
896 XSETINT (ret
, colorval
);
904 /* I am not going to attempt to handle any of the CIE color schemes
905 or TekHVC, since I don't know the algorithms for conversion to
908 /* If we fail to lookup the color name in w32_color_map, then check the
909 colorname to see if it can be crudely approximated: If the X color
910 ends in a number (e.g., "darkseagreen2"), strip the number and
911 return the result of looking up the base color name. */
912 ret
= w32_color_map_lookup (colorname
);
915 int len
= strlen (colorname
);
917 if (isdigit (colorname
[len
- 1]))
919 char *ptr
, *approx
= alloca (len
+ 1);
921 strcpy (approx
, colorname
);
922 ptr
= &approx
[len
- 1];
923 while (ptr
> approx
&& isdigit (*ptr
))
926 ret
= w32_color_map_lookup (approx
);
935 w32_regenerate_palette (FRAME_PTR f
)
937 struct w32_palette_entry
* list
;
938 LOGPALETTE
* log_palette
;
939 HPALETTE new_palette
;
942 /* don't bother trying to create palette if not supported */
943 if (! FRAME_W32_DISPLAY_INFO (f
)->has_palette
)
946 log_palette
= (LOGPALETTE
*)
947 alloca (sizeof (LOGPALETTE
) +
948 FRAME_W32_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
949 log_palette
->palVersion
= 0x300;
950 log_palette
->palNumEntries
= FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
952 list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
954 i
< FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
955 i
++, list
= list
->next
)
956 log_palette
->palPalEntry
[i
] = list
->entry
;
958 new_palette
= CreatePalette (log_palette
);
962 if (FRAME_W32_DISPLAY_INFO (f
)->palette
)
963 DeleteObject (FRAME_W32_DISPLAY_INFO (f
)->palette
);
964 FRAME_W32_DISPLAY_INFO (f
)->palette
= new_palette
;
966 /* Realize display palette and garbage all frames. */
967 release_frame_dc (f
, get_frame_dc (f
));
972 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
973 #define SET_W32_COLOR(pe, color) \
976 pe.peRed = GetRValue (color); \
977 pe.peGreen = GetGValue (color); \
978 pe.peBlue = GetBValue (color); \
983 /* Keep these around in case we ever want to track color usage. */
985 w32_map_color (FRAME_PTR f
, COLORREF color
)
987 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
989 if (NILP (Vw32_enable_palette
))
992 /* check if color is already mapped */
995 if (W32_COLOR (list
->entry
) == color
)
1003 /* not already mapped, so add to list and recreate Windows palette */
1004 list
= (struct w32_palette_entry
*)
1005 xmalloc (sizeof (struct w32_palette_entry
));
1006 SET_W32_COLOR (list
->entry
, color
);
1008 list
->next
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1009 FRAME_W32_DISPLAY_INFO (f
)->color_list
= list
;
1010 FRAME_W32_DISPLAY_INFO (f
)->num_colors
++;
1012 /* set flag that palette must be regenerated */
1013 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1017 w32_unmap_color (FRAME_PTR f
, COLORREF color
)
1019 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1020 struct w32_palette_entry
**prev
= &FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1022 if (NILP (Vw32_enable_palette
))
1025 /* check if color is already mapped */
1028 if (W32_COLOR (list
->entry
) == color
)
1030 if (--list
->refcount
== 0)
1034 FRAME_W32_DISPLAY_INFO (f
)->num_colors
--;
1044 /* set flag that palette must be regenerated */
1045 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1050 /* Gamma-correct COLOR on frame F. */
1053 gamma_correct (struct frame
*f
, COLORREF
*color
)
1057 *color
= PALETTERGB (
1058 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1059 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1060 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1065 /* Decide if color named COLOR is valid for the display associated with
1066 the selected frame; if so, return the rgb values in COLOR_DEF.
1067 If ALLOC is nonzero, allocate a new colormap cell. */
1070 w32_defined_color (FRAME_PTR f
, char *color
, XColor
*color_def
, int alloc
)
1072 register Lisp_Object tem
;
1073 COLORREF w32_color_ref
;
1075 tem
= x_to_w32_color (color
);
1081 /* Apply gamma correction. */
1082 w32_color_ref
= XUINT (tem
);
1083 gamma_correct (f
, &w32_color_ref
);
1084 XSETINT (tem
, w32_color_ref
);
1087 /* Map this color to the palette if it is enabled. */
1088 if (!NILP (Vw32_enable_palette
))
1090 struct w32_palette_entry
* entry
=
1091 one_w32_display_info
.color_list
;
1092 struct w32_palette_entry
** prev
=
1093 &one_w32_display_info
.color_list
;
1095 /* check if color is already mapped */
1098 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1100 prev
= &entry
->next
;
1101 entry
= entry
->next
;
1104 if (entry
== NULL
&& alloc
)
1106 /* not already mapped, so add to list */
1107 entry
= (struct w32_palette_entry
*)
1108 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
))
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 change_window_heights (root_window
, delta
);
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
);
1637 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1640 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1641 name; if NAME is a string, set F's name to NAME and set
1642 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1644 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1645 suggesting a new name, which lisp code should override; if
1646 F->explicit_name is set, ignore the new name; otherwise, set it. */
1649 x_set_name (struct frame
*f
, Lisp_Object name
, int explicit)
1651 /* Make sure that requests from lisp code override requests from
1652 Emacs redisplay code. */
1655 /* If we're switching from explicit to implicit, we had better
1656 update the mode lines and thereby update the title. */
1657 if (f
->explicit_name
&& NILP (name
))
1658 update_mode_lines
= 1;
1660 f
->explicit_name
= ! NILP (name
);
1662 else if (f
->explicit_name
)
1665 /* If NAME is nil, set the name to the w32_id_name. */
1668 /* Check for no change needed in this very common case
1669 before we do any consing. */
1670 if (!strcmp (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
,
1673 name
= build_string (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
);
1676 CHECK_STRING (name
);
1678 /* Don't change the name if it's already NAME. */
1679 if (! NILP (Fstring_equal (name
, f
->name
)))
1684 /* For setting the frame title, the title parameter should override
1685 the name parameter. */
1686 if (! NILP (f
->title
))
1689 if (FRAME_W32_WINDOW (f
))
1691 if (STRING_MULTIBYTE (name
))
1692 name
= ENCODE_SYSTEM (name
);
1695 SetWindowText (FRAME_W32_WINDOW (f
), SDATA (name
));
1700 /* This function should be called when the user's lisp code has
1701 specified a name for the frame; the name will override any set by the
1704 x_explicitly_set_name (FRAME_PTR f
, Lisp_Object arg
, Lisp_Object oldval
)
1706 x_set_name (f
, arg
, 1);
1709 /* This function should be called by Emacs redisplay code to set the
1710 name; names set this way will never override names set by the user's
1713 x_implicitly_set_name (FRAME_PTR f
, Lisp_Object arg
, Lisp_Object oldval
)
1715 x_set_name (f
, arg
, 0);
1718 /* Change the title of frame F to NAME.
1719 If NAME is nil, use the frame name as the title. */
1722 x_set_title (struct frame
*f
, Lisp_Object name
, Lisp_Object old_name
)
1724 /* Don't change the title if it's already NAME. */
1725 if (EQ (name
, f
->title
))
1728 update_mode_lines
= 1;
1735 if (FRAME_W32_WINDOW (f
))
1737 if (STRING_MULTIBYTE (name
))
1738 name
= ENCODE_SYSTEM (name
);
1741 SetWindowText (FRAME_W32_WINDOW (f
), SDATA (name
));
1747 x_set_scroll_bar_default_width (struct frame
*f
)
1749 int wid
= FRAME_COLUMN_WIDTH (f
);
1751 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
1752 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) +
1757 /* Subroutines for creating a frame. */
1760 w32_load_cursor (LPCTSTR name
)
1762 /* Try first to load cursor from application resource. */
1763 Cursor cursor
= LoadImage ((HINSTANCE
) GetModuleHandle (NULL
),
1764 name
, IMAGE_CURSOR
, 0, 0,
1765 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
1768 /* Then try to load a shared predefined cursor. */
1769 cursor
= LoadImage (NULL
, name
, IMAGE_CURSOR
, 0, 0,
1770 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
1775 static LRESULT CALLBACK
w32_wnd_proc (HWND
, UINT
, WPARAM
, LPARAM
);
1778 w32_init_class (HINSTANCE hinst
)
1782 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
1783 wc
.lpfnWndProc
= (WNDPROC
) w32_wnd_proc
;
1785 wc
.cbWndExtra
= WND_EXTRA_BYTES
;
1786 wc
.hInstance
= hinst
;
1787 wc
.hIcon
= LoadIcon (hinst
, EMACS_CLASS
);
1788 wc
.hCursor
= w32_load_cursor (IDC_ARROW
);
1789 wc
.hbrBackground
= NULL
; /* GetStockObject (WHITE_BRUSH); */
1790 wc
.lpszMenuName
= NULL
;
1791 wc
.lpszClassName
= EMACS_CLASS
;
1793 return (RegisterClass (&wc
));
1797 w32_createscrollbar (struct frame
*f
, struct scroll_bar
* bar
)
1799 return (CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
1800 /* Position and size of scroll bar. */
1801 XINT (bar
->left
) + VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
1803 XINT (bar
->width
) - VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
1805 FRAME_W32_WINDOW (f
),
1812 w32_createwindow (struct frame
*f
)
1816 Lisp_Object top
= Qunbound
;
1817 Lisp_Object left
= Qunbound
;
1818 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
1820 rect
.left
= rect
.top
= 0;
1821 rect
.right
= FRAME_PIXEL_WIDTH (f
);
1822 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
1824 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
1825 FRAME_EXTERNAL_MENU_BAR (f
));
1827 /* Do first time app init */
1831 w32_init_class (hinst
);
1834 if (f
->size_hint_flags
& USPosition
|| f
->size_hint_flags
& PPosition
)
1836 XSETINT (left
, f
->left_pos
);
1837 XSETINT (top
, f
->top_pos
);
1839 else if (EQ (left
, Qunbound
) && EQ (top
, Qunbound
))
1841 /* When called with RES_TYPE_NUMBER, w32_get_arg will return zero
1842 for anything that is not a number and is not Qunbound. */
1843 left
= x_get_arg (dpyinfo
, Qnil
, Qleft
, "left", "Left", RES_TYPE_NUMBER
);
1844 top
= x_get_arg (dpyinfo
, Qnil
, Qtop
, "top", "Top", RES_TYPE_NUMBER
);
1847 FRAME_W32_WINDOW (f
) = hwnd
1848 = CreateWindow (EMACS_CLASS
,
1850 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
1851 EQ (left
, Qunbound
) ? CW_USEDEFAULT
: XINT (left
),
1852 EQ (top
, Qunbound
) ? CW_USEDEFAULT
: XINT (top
),
1853 rect
.right
- rect
.left
,
1854 rect
.bottom
- rect
.top
,
1862 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
1863 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
1864 SetWindowLong (hwnd
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
1865 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->scroll_bar_actual_width
);
1866 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
1868 /* Enable drag-n-drop. */
1869 DragAcceptFiles (hwnd
, TRUE
);
1871 /* Do this to discard the default setting specified by our parent. */
1872 ShowWindow (hwnd
, SW_HIDE
);
1874 /* Update frame positions. */
1875 GetWindowRect (hwnd
, &rect
);
1876 f
->left_pos
= rect
.left
;
1877 f
->top_pos
= rect
.top
;
1882 my_post_msg (W32Msg
* wmsg
, HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1884 wmsg
->msg
.hwnd
= hwnd
;
1885 wmsg
->msg
.message
= msg
;
1886 wmsg
->msg
.wParam
= wParam
;
1887 wmsg
->msg
.lParam
= lParam
;
1888 wmsg
->msg
.time
= GetMessageTime ();
1893 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
1894 between left and right keys as advertised. We test for this
1895 support dynamically, and set a flag when the support is absent. If
1896 absent, we keep track of the left and right control and alt keys
1897 ourselves. This is particularly necessary on keyboards that rely
1898 upon the AltGr key, which is represented as having the left control
1899 and right alt keys pressed. For these keyboards, we need to know
1900 when the left alt key has been pressed in addition to the AltGr key
1901 so that we can properly support M-AltGr-key sequences (such as M-@
1902 on Swedish keyboards). */
1904 #define EMACS_LCONTROL 0
1905 #define EMACS_RCONTROL 1
1906 #define EMACS_LMENU 2
1907 #define EMACS_RMENU 3
1909 static int modifiers
[4];
1910 static int modifiers_recorded
;
1911 static int modifier_key_support_tested
;
1914 test_modifier_support (unsigned int wparam
)
1918 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
1920 if (wparam
== VK_CONTROL
)
1930 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
1931 modifiers_recorded
= 1;
1933 modifiers_recorded
= 0;
1934 modifier_key_support_tested
= 1;
1938 record_keydown (unsigned int wparam
, unsigned int lparam
)
1942 if (!modifier_key_support_tested
)
1943 test_modifier_support (wparam
);
1945 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
1948 if (wparam
== VK_CONTROL
)
1949 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
1951 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
1957 record_keyup (unsigned int wparam
, unsigned int lparam
)
1961 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
1964 if (wparam
== VK_CONTROL
)
1965 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
1967 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
1972 /* Emacs can lose focus while a modifier key has been pressed. When
1973 it regains focus, be conservative and clear all modifiers since
1974 we cannot reconstruct the left and right modifier state. */
1976 reset_modifiers (void)
1980 if (GetFocus () == NULL
)
1981 /* Emacs doesn't have keyboard focus. Do nothing. */
1984 ctrl
= GetAsyncKeyState (VK_CONTROL
);
1985 alt
= GetAsyncKeyState (VK_MENU
);
1987 if (!(ctrl
& 0x08000))
1988 /* Clear any recorded control modifier state. */
1989 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
1991 if (!(alt
& 0x08000))
1992 /* Clear any recorded alt modifier state. */
1993 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
1995 /* Update the state of all modifier keys, because modifiers used in
1996 hot-key combinations can get stuck on if Emacs loses focus as a
1997 result of a hot-key being pressed. */
2001 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
2003 GetKeyboardState (keystate
);
2004 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
2005 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
2006 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
2007 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
2008 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
2009 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
2010 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
2011 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
2012 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
2013 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
2014 SetKeyboardState (keystate
);
2018 /* Synchronize modifier state with what is reported with the current
2019 keystroke. Even if we cannot distinguish between left and right
2020 modifier keys, we know that, if no modifiers are set, then neither
2021 the left or right modifier should be set. */
2023 sync_modifiers (void)
2025 if (!modifiers_recorded
)
2028 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
2029 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2031 if (!(GetKeyState (VK_MENU
) & 0x8000))
2032 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2036 modifier_set (int vkey
)
2038 if (vkey
== VK_CAPITAL
|| vkey
== VK_SCROLL
)
2039 return (GetKeyState (vkey
) & 0x1);
2040 if (!modifiers_recorded
)
2041 return (GetKeyState (vkey
) & 0x8000);
2046 return modifiers
[EMACS_LCONTROL
];
2048 return modifiers
[EMACS_RCONTROL
];
2050 return modifiers
[EMACS_LMENU
];
2052 return modifiers
[EMACS_RMENU
];
2054 return (GetKeyState (vkey
) & 0x8000);
2057 /* Convert between the modifier bits W32 uses and the modifier bits
2061 w32_key_to_modifier (int key
)
2063 Lisp_Object key_mapping
;
2068 key_mapping
= Vw32_lwindow_modifier
;
2071 key_mapping
= Vw32_rwindow_modifier
;
2074 key_mapping
= Vw32_apps_modifier
;
2077 key_mapping
= Vw32_scroll_lock_modifier
;
2083 /* NB. This code runs in the input thread, asychronously to the lisp
2084 thread, so we must be careful to ensure access to lisp data is
2085 thread-safe. The following code is safe because the modifier
2086 variable values are updated atomically from lisp and symbols are
2087 not relocated by GC. Also, we don't have to worry about seeing GC
2089 if (EQ (key_mapping
, Qhyper
))
2090 return hyper_modifier
;
2091 if (EQ (key_mapping
, Qsuper
))
2092 return super_modifier
;
2093 if (EQ (key_mapping
, Qmeta
))
2094 return meta_modifier
;
2095 if (EQ (key_mapping
, Qalt
))
2096 return alt_modifier
;
2097 if (EQ (key_mapping
, Qctrl
))
2098 return ctrl_modifier
;
2099 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
2100 return ctrl_modifier
;
2101 if (EQ (key_mapping
, Qshift
))
2102 return shift_modifier
;
2104 /* Don't generate any modifier if not explicitly requested. */
2109 w32_get_modifiers (void)
2111 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
2112 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
2113 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
2114 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
2115 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
2116 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
2117 (modifier_set (VK_MENU
) ?
2118 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
2121 /* We map the VK_* modifiers into console modifier constants
2122 so that we can use the same routines to handle both console
2123 and window input. */
2126 construct_console_modifiers (void)
2131 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
2132 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
2133 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
2134 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
2135 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
2136 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
2137 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
2138 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
2139 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
2140 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
2141 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
2147 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
2151 /* Convert to emacs modifiers. */
2152 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
2158 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
2160 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
2163 if (virt_key
== VK_RETURN
)
2164 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
2166 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
2167 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
2169 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
2170 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
2172 if (virt_key
== VK_CLEAR
)
2173 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
2178 /* List of special key combinations which w32 would normally capture,
2179 but Emacs should grab instead. Not directly visible to lisp, to
2180 simplify synchronization. Each item is an integer encoding a virtual
2181 key code and modifier combination to capture. */
2182 static Lisp_Object w32_grabbed_keys
;
2184 #define HOTKEY(vk, mods) make_number (((vk) & 255) | ((mods) << 8))
2185 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
2186 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
2187 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
2189 #define RAW_HOTKEY_ID(k) ((k) & 0xbfff)
2190 #define RAW_HOTKEY_VK_CODE(k) ((k) & 255)
2191 #define RAW_HOTKEY_MODIFIERS(k) ((k) >> 8)
2193 /* Register hot-keys for reserved key combinations when Emacs has
2194 keyboard focus, since this is the only way Emacs can receive key
2195 combinations like Alt-Tab which are used by the system. */
2198 register_hot_keys (HWND hwnd
)
2200 Lisp_Object keylist
;
2202 /* Use CONSP, since we are called asynchronously. */
2203 for (keylist
= w32_grabbed_keys
; CONSP (keylist
); keylist
= XCDR (keylist
))
2205 Lisp_Object key
= XCAR (keylist
);
2207 /* Deleted entries get set to nil. */
2208 if (!INTEGERP (key
))
2211 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
2212 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
2217 unregister_hot_keys (HWND hwnd
)
2219 Lisp_Object keylist
;
2221 for (keylist
= w32_grabbed_keys
; CONSP (keylist
); keylist
= XCDR (keylist
))
2223 Lisp_Object key
= XCAR (keylist
);
2225 if (!INTEGERP (key
))
2228 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
2232 /* Main message dispatch loop. */
2235 w32_msg_pump (deferred_msg
* msg_buf
)
2241 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
2243 while (GetMessage (&msg
, NULL
, 0, 0))
2245 if (msg
.hwnd
== NULL
)
2247 switch (msg
.message
)
2250 /* Produced by complete_deferred_msg; just ignore. */
2252 case WM_EMACS_CREATEWINDOW
:
2253 /* Initialize COM for this window. Even though we don't use it,
2254 some third party shell extensions can cause it to be used in
2255 system dialogs, which causes a crash if it is not initialized.
2256 This is a known bug in Windows, which was fixed long ago, but
2257 the patch for XP is not publically available until XP SP3,
2258 and older versions will never be patched. */
2259 CoInitialize (NULL
);
2260 w32_createwindow ((struct frame
*) msg
.wParam
);
2261 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2264 case WM_EMACS_SETLOCALE
:
2265 SetThreadLocale (msg
.wParam
);
2266 /* Reply is not expected. */
2268 case WM_EMACS_SETKEYBOARDLAYOUT
:
2269 result
= (int) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
2270 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2274 case WM_EMACS_REGISTER_HOT_KEY
:
2275 focus_window
= GetFocus ();
2276 if (focus_window
!= NULL
)
2277 RegisterHotKey (focus_window
,
2278 RAW_HOTKEY_ID (msg
.wParam
),
2279 RAW_HOTKEY_MODIFIERS (msg
.wParam
),
2280 RAW_HOTKEY_VK_CODE (msg
.wParam
));
2281 /* Reply is not expected. */
2283 case WM_EMACS_UNREGISTER_HOT_KEY
:
2284 focus_window
= GetFocus ();
2285 if (focus_window
!= NULL
)
2286 UnregisterHotKey (focus_window
, RAW_HOTKEY_ID (msg
.wParam
));
2287 /* Mark item as erased. NB: this code must be
2288 thread-safe. The next line is okay because the cons
2289 cell is never made into garbage and is not relocated by
2291 XSETCAR ((Lisp_Object
) ((EMACS_INT
) msg
.lParam
), Qnil
);
2292 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2295 case WM_EMACS_TOGGLE_LOCK_KEY
:
2297 int vk_code
= (int) msg
.wParam
;
2298 int cur_state
= (GetKeyState (vk_code
) & 1);
2299 Lisp_Object new_state
= (Lisp_Object
) ((EMACS_INT
) msg
.lParam
);
2301 /* NB: This code must be thread-safe. It is safe to
2302 call NILP because symbols are not relocated by GC,
2303 and pointer here is not touched by GC (so the markbit
2304 can't be set). Numbers are safe because they are
2305 immediate values. */
2306 if (NILP (new_state
)
2307 || (NUMBERP (new_state
)
2308 && ((XUINT (new_state
)) & 1) != cur_state
))
2310 one_w32_display_info
.faked_key
= vk_code
;
2312 keybd_event ((BYTE
) vk_code
,
2313 (BYTE
) MapVirtualKey (vk_code
, 0),
2314 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2315 keybd_event ((BYTE
) vk_code
,
2316 (BYTE
) MapVirtualKey (vk_code
, 0),
2317 KEYEVENTF_EXTENDEDKEY
| 0, 0);
2318 keybd_event ((BYTE
) vk_code
,
2319 (BYTE
) MapVirtualKey (vk_code
, 0),
2320 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2321 cur_state
= !cur_state
;
2323 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2329 /* Broadcast messages make it here, so you need to be looking
2330 for something in particular for this to be useful. */
2332 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
2338 DispatchMessage (&msg
);
2341 /* Exit nested loop when our deferred message has completed. */
2342 if (msg_buf
->completed
)
2347 deferred_msg
* deferred_msg_head
;
2349 static deferred_msg
*
2350 find_deferred_msg (HWND hwnd
, UINT msg
)
2352 deferred_msg
* item
;
2354 /* Don't actually need synchronization for read access, since
2355 modification of single pointer is always atomic. */
2356 /* enter_crit (); */
2358 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2359 if (item
->w32msg
.msg
.hwnd
== hwnd
2360 && item
->w32msg
.msg
.message
== msg
)
2363 /* leave_crit (); */
2369 send_deferred_msg (deferred_msg
* msg_buf
,
2375 /* Only input thread can send deferred messages. */
2376 if (GetCurrentThreadId () != dwWindowsThreadId
)
2379 /* It is an error to send a message that is already deferred. */
2380 if (find_deferred_msg (hwnd
, msg
) != NULL
)
2383 /* Enforced synchronization is not needed because this is the only
2384 function that alters deferred_msg_head, and the following critical
2385 section is guaranteed to only be serially reentered (since only the
2386 input thread can call us). */
2388 /* enter_crit (); */
2390 msg_buf
->completed
= 0;
2391 msg_buf
->next
= deferred_msg_head
;
2392 deferred_msg_head
= msg_buf
;
2393 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
2395 /* leave_crit (); */
2397 /* Start a new nested message loop to process other messages until
2398 this one is completed. */
2399 w32_msg_pump (msg_buf
);
2401 deferred_msg_head
= msg_buf
->next
;
2403 return msg_buf
->result
;
2407 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
2409 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
2411 if (msg_buf
== NULL
)
2412 /* Message may have been cancelled, so don't abort. */
2415 msg_buf
->result
= result
;
2416 msg_buf
->completed
= 1;
2418 /* Ensure input thread is woken so it notices the completion. */
2419 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2423 cancel_all_deferred_msgs (void)
2425 deferred_msg
* item
;
2427 /* Don't actually need synchronization for read access, since
2428 modification of single pointer is always atomic. */
2429 /* enter_crit (); */
2431 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2434 item
->completed
= 1;
2437 /* leave_crit (); */
2439 /* Ensure input thread is woken so it notices the completion. */
2440 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2444 w32_msg_worker (void *arg
)
2447 deferred_msg dummy_buf
;
2449 /* Ensure our message queue is created */
2451 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
2453 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2456 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
2457 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
2458 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
2460 /* This is the initial message loop which should only exit when the
2461 application quits. */
2462 w32_msg_pump (&dummy_buf
);
2468 signal_user_input (void)
2470 /* Interrupt any lisp that wants to be interrupted by input. */
2471 if (!NILP (Vthrow_on_input
))
2473 Vquit_flag
= Vthrow_on_input
;
2474 /* If we're inside a function that wants immediate quits,
2476 if (immediate_quit
&& NILP (Vinhibit_quit
))
2486 post_character_message (HWND hwnd
, UINT msg
,
2487 WPARAM wParam
, LPARAM lParam
,
2492 wmsg
.dwModifiers
= modifiers
;
2494 /* Detect quit_char and set quit-flag directly. Note that we
2495 still need to post a message to ensure the main thread will be
2496 woken up if blocked in sys_select, but we do NOT want to post
2497 the quit_char message itself (because it will usually be as if
2498 the user had typed quit_char twice). Instead, we post a dummy
2499 message that has no particular effect. */
2502 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
2503 c
= make_ctrl_char (c
) & 0377;
2505 || (wmsg
.dwModifiers
== 0 &&
2506 w32_quit_key
&& wParam
== w32_quit_key
))
2510 /* The choice of message is somewhat arbitrary, as long as
2511 the main thread handler just ignores it. */
2514 /* Interrupt any blocking system calls. */
2517 /* As a safety precaution, forcibly complete any deferred
2518 messages. This is a kludge, but I don't see any particularly
2519 clean way to handle the situation where a deferred message is
2520 "dropped" in the lisp thread, and will thus never be
2521 completed, eg. by the user trying to activate the menubar
2522 when the lisp thread is busy, and then typing C-g when the
2523 menubar doesn't open promptly (with the result that the
2524 menubar never responds at all because the deferred
2525 WM_INITMENU message is never completed). Another problem
2526 situation is when the lisp thread calls SendMessage (to send
2527 a window manager command) when a message has been deferred;
2528 the lisp thread gets blocked indefinitely waiting for the
2529 deferred message to be completed, which itself is waiting for
2530 the lisp thread to respond.
2532 Note that we don't want to block the input thread waiting for
2533 a reponse from the lisp thread (although that would at least
2534 solve the deadlock problem above), because we want to be able
2535 to receive C-g to interrupt the lisp thread. */
2536 cancel_all_deferred_msgs ();
2539 signal_user_input ();
2542 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2545 /* Main window procedure */
2547 static LRESULT CALLBACK
2548 w32_wnd_proc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2551 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
2553 int windows_translate
;
2556 /* Note that it is okay to call x_window_to_frame, even though we are
2557 not running in the main lisp thread, because frame deletion
2558 requires the lisp thread to synchronize with this thread. Thus, if
2559 a frame struct is returned, it can be used without concern that the
2560 lisp thread might make it disappear while we are using it.
2562 NB. Walking the frame list in this thread is safe (as long as
2563 writes of Lisp_Object slots are atomic, which they are on Windows).
2564 Although delete-frame can destructively modify the frame list while
2565 we are walking it, a garbage collection cannot occur until after
2566 delete-frame has synchronized with this thread.
2568 It is also safe to use functions that make GDI calls, such as
2569 w32_clear_rect, because these functions must obtain a DC handle
2570 from the frame struct using get_frame_dc which is thread-aware. */
2575 f
= x_window_to_frame (dpyinfo
, hwnd
);
2578 HDC hdc
= get_frame_dc (f
);
2579 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
2580 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
2581 release_frame_dc (f
, hdc
);
2583 #if defined (W32_DEBUG_DISPLAY)
2584 DebPrint (("WM_ERASEBKGND (frame %p): erasing %d,%d-%d,%d\n",
2586 wmsg
.rect
.left
, wmsg
.rect
.top
,
2587 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2588 #endif /* W32_DEBUG_DISPLAY */
2591 case WM_PALETTECHANGED
:
2592 /* ignore our own changes */
2593 if ((HWND
)wParam
!= hwnd
)
2595 f
= x_window_to_frame (dpyinfo
, hwnd
);
2597 /* get_frame_dc will realize our palette and force all
2598 frames to be redrawn if needed. */
2599 release_frame_dc (f
, get_frame_dc (f
));
2604 PAINTSTRUCT paintStruct
;
2606 memset (&update_rect
, 0, sizeof (update_rect
));
2608 f
= x_window_to_frame (dpyinfo
, hwnd
);
2611 DebPrint (("WM_PAINT received for unknown window %p\n", hwnd
));
2615 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
2616 fails. Apparently this can happen under some
2618 if (GetUpdateRect (hwnd
, &update_rect
, FALSE
) || !w32_strict_painting
)
2621 BeginPaint (hwnd
, &paintStruct
);
2623 /* The rectangles returned by GetUpdateRect and BeginPaint
2624 do not always match. Play it safe by assuming both areas
2626 UnionRect (&(wmsg
.rect
), &update_rect
, &(paintStruct
.rcPaint
));
2628 #if defined (W32_DEBUG_DISPLAY)
2629 DebPrint (("WM_PAINT (frame %p): painting %d,%d-%d,%d\n",
2631 wmsg
.rect
.left
, wmsg
.rect
.top
,
2632 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2633 DebPrint ((" [update region is %d,%d-%d,%d]\n",
2634 update_rect
.left
, update_rect
.top
,
2635 update_rect
.right
, update_rect
.bottom
));
2637 EndPaint (hwnd
, &paintStruct
);
2640 /* Change the message type to prevent Windows from
2641 combining WM_PAINT messages in the Lisp thread's queue,
2642 since Windows assumes that each message queue is
2643 dedicated to one frame and does not bother checking
2644 that hwnd matches before combining them. */
2645 my_post_msg (&wmsg
, hwnd
, WM_EMACS_PAINT
, wParam
, lParam
);
2650 /* If GetUpdateRect returns 0 (meaning there is no update
2651 region), assume the whole window needs to be repainted. */
2652 GetClientRect (hwnd
, &wmsg
.rect
);
2653 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2657 case WM_INPUTLANGCHANGE
:
2658 /* Inform lisp thread of keyboard layout changes. */
2659 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2661 /* Clear dead keys in the keyboard state; for simplicity only
2662 preserve modifier key states. */
2667 GetKeyboardState (keystate
);
2668 for (i
= 0; i
< 256; i
++)
2685 SetKeyboardState (keystate
);
2690 /* Synchronize hot keys with normal input. */
2691 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
2696 record_keyup (wParam
, lParam
);
2701 /* Ignore keystrokes we fake ourself; see below. */
2702 if (dpyinfo
->faked_key
== wParam
)
2704 dpyinfo
->faked_key
= 0;
2705 /* Make sure TranslateMessage sees them though (as long as
2706 they don't produce WM_CHAR messages). This ensures that
2707 indicator lights are toggled promptly on Windows 9x, for
2709 if (wParam
< 256 && lispy_function_keys
[wParam
])
2711 windows_translate
= 1;
2717 /* Synchronize modifiers with current keystroke. */
2719 record_keydown (wParam
, lParam
);
2720 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
2722 windows_translate
= 0;
2727 if (NILP (Vw32_pass_lwindow_to_system
))
2729 /* Prevent system from acting on keyup (which opens the
2730 Start menu if no other key was pressed) by simulating a
2731 press of Space which we will ignore. */
2732 if (GetAsyncKeyState (wParam
) & 1)
2734 if (NUMBERP (Vw32_phantom_key_code
))
2735 key
= XUINT (Vw32_phantom_key_code
) & 255;
2738 dpyinfo
->faked_key
= key
;
2739 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
2742 if (!NILP (Vw32_lwindow_modifier
))
2746 if (NILP (Vw32_pass_rwindow_to_system
))
2748 if (GetAsyncKeyState (wParam
) & 1)
2750 if (NUMBERP (Vw32_phantom_key_code
))
2751 key
= XUINT (Vw32_phantom_key_code
) & 255;
2754 dpyinfo
->faked_key
= key
;
2755 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
2758 if (!NILP (Vw32_rwindow_modifier
))
2762 if (!NILP (Vw32_apps_modifier
))
2766 if (NILP (Vw32_pass_alt_to_system
))
2767 /* Prevent DefWindowProc from activating the menu bar if an
2768 Alt key is pressed and released by itself. */
2770 windows_translate
= 1;
2773 /* Decide whether to treat as modifier or function key. */
2774 if (NILP (Vw32_enable_caps_lock
))
2775 goto disable_lock_key
;
2776 windows_translate
= 1;
2779 /* Decide whether to treat as modifier or function key. */
2780 if (NILP (Vw32_enable_num_lock
))
2781 goto disable_lock_key
;
2782 windows_translate
= 1;
2785 /* Decide whether to treat as modifier or function key. */
2786 if (NILP (Vw32_scroll_lock_modifier
))
2787 goto disable_lock_key
;
2788 windows_translate
= 1;
2791 /* Ensure the appropriate lock key state (and indicator light)
2792 remains in the same state. We do this by faking another
2793 press of the relevant key. Apparently, this really is the
2794 only way to toggle the state of the indicator lights. */
2795 dpyinfo
->faked_key
= wParam
;
2796 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
2797 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2798 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
2799 KEYEVENTF_EXTENDEDKEY
| 0, 0);
2800 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
2801 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2802 /* Ensure indicator lights are updated promptly on Windows 9x
2803 (TranslateMessage apparently does this), after forwarding
2805 post_character_message (hwnd
, msg
, wParam
, lParam
,
2806 w32_get_key_modifiers (wParam
, lParam
));
2807 windows_translate
= 1;
2811 case VK_PROCESSKEY
: /* Generated by IME. */
2812 windows_translate
= 1;
2815 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
2816 which is confusing for purposes of key binding; convert
2817 VK_CANCEL events into VK_PAUSE events. */
2821 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
2822 for purposes of key binding; convert these back into
2823 VK_NUMLOCK events, at least when we want to see NumLock key
2824 presses. (Note that there is never any possibility that
2825 VK_PAUSE with Ctrl really is C-Pause as per above.) */
2826 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
2827 wParam
= VK_NUMLOCK
;
2830 /* If not defined as a function key, change it to a WM_CHAR message. */
2831 if (wParam
> 255 || !lispy_function_keys
[wParam
])
2833 DWORD modifiers
= construct_console_modifiers ();
2835 if (!NILP (Vw32_recognize_altgr
)
2836 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
2838 /* Always let TranslateMessage handle AltGr key chords;
2839 for some reason, ToAscii doesn't always process AltGr
2840 chords correctly. */
2841 windows_translate
= 1;
2843 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
2845 /* Handle key chords including any modifiers other
2846 than shift directly, in order to preserve as much
2847 modifier information as possible. */
2848 if ('A' <= wParam
&& wParam
<= 'Z')
2850 /* Don't translate modified alphabetic keystrokes,
2851 so the user doesn't need to constantly switch
2852 layout to type control or meta keystrokes when
2853 the normal layout translates alphabetic
2854 characters to non-ascii characters. */
2855 if (!modifier_set (VK_SHIFT
))
2856 wParam
+= ('a' - 'A');
2861 /* Try to handle other keystrokes by determining the
2862 base character (ie. translating the base key plus
2866 KEY_EVENT_RECORD key
;
2868 key
.bKeyDown
= TRUE
;
2869 key
.wRepeatCount
= 1;
2870 key
.wVirtualKeyCode
= wParam
;
2871 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
2872 key
.uChar
.AsciiChar
= 0;
2873 key
.dwControlKeyState
= modifiers
;
2875 add
= w32_kbd_patch_key (&key
);
2876 /* 0 means an unrecognised keycode, negative means
2877 dead key. Ignore both. */
2880 /* Forward asciified character sequence. */
2881 post_character_message
2883 (unsigned char) key
.uChar
.AsciiChar
, lParam
,
2884 w32_get_key_modifiers (wParam
, lParam
));
2885 w32_kbd_patch_key (&key
);
2892 /* Let TranslateMessage handle everything else. */
2893 windows_translate
= 1;
2899 if (windows_translate
)
2901 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
2902 windows_msg
.time
= GetMessageTime ();
2903 TranslateMessage (&windows_msg
);
2911 post_character_message (hwnd
, msg
, wParam
, lParam
,
2912 w32_get_key_modifiers (wParam
, lParam
));
2916 /* WM_UNICHAR looks promising from the docs, but the exact
2917 circumstances in which TranslateMessage sends it is one of those
2918 Microsoft secret API things that EU and US courts are supposed
2919 to have put a stop to already. Spy++ shows it being sent to Notepad
2920 and other MS apps, but never to Emacs.
2922 Some third party IMEs send it in accordance with the official
2923 documentation though, so handle it here.
2925 UNICODE_NOCHAR is used to test for support for this message.
2926 TRUE indicates that the message is supported. */
2927 if (wParam
== UNICODE_NOCHAR
)
2932 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
2933 signal_user_input ();
2934 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2939 /* If we can't get the IME result as unicode, use default processing,
2940 which will at least allow characters decodable in the system locale
2942 if (!get_composition_string_fn
)
2945 else if (!ignore_ime_char
)
2950 HIMC context
= get_ime_context_fn (hwnd
);
2951 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
2952 /* Get buffer size. */
2953 size
= get_composition_string_fn (context
, GCS_RESULTSTR
, NULL
, 0);
2954 buffer
= alloca (size
);
2955 size
= get_composition_string_fn (context
, GCS_RESULTSTR
,
2957 release_ime_context_fn (hwnd
, context
);
2959 signal_user_input ();
2960 for (i
= 0; i
< size
/ sizeof (wchar_t); i
++)
2962 my_post_msg (&wmsg
, hwnd
, WM_UNICHAR
, (WPARAM
) buffer
[i
],
2965 /* Ignore the messages for the rest of the
2966 characters in the string that was output above. */
2967 ignore_ime_char
= (size
/ sizeof (wchar_t)) - 1;
2974 case WM_IME_STARTCOMPOSITION
:
2975 if (!set_ime_composition_window_fn
)
2979 COMPOSITIONFORM form
;
2983 f
= x_window_to_frame (dpyinfo
, hwnd
);
2984 w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
2986 form
.dwStyle
= CFS_RECT
;
2987 form
.ptCurrentPos
.x
= w32_system_caret_x
;
2988 form
.ptCurrentPos
.y
= w32_system_caret_y
;
2990 form
.rcArea
.left
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, 0);
2991 form
.rcArea
.top
= (WINDOW_TOP_EDGE_Y (w
)
2992 + WINDOW_HEADER_LINE_HEIGHT (w
));
2993 form
.rcArea
.right
= (WINDOW_BOX_RIGHT_EDGE_X (w
)
2994 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
2995 - WINDOW_RIGHT_FRINGE_WIDTH (w
));
2996 form
.rcArea
.bottom
= (WINDOW_BOTTOM_EDGE_Y (w
)
2997 - WINDOW_MODE_LINE_HEIGHT (w
));
2999 context
= get_ime_context_fn (hwnd
);
3004 set_ime_composition_window_fn (context
, &form
);
3005 release_ime_context_fn (hwnd
, context
);
3009 case WM_IME_ENDCOMPOSITION
:
3010 ignore_ime_char
= 0;
3013 /* Simulate middle mouse button events when left and right buttons
3014 are used together, but only if user has two button mouse. */
3015 case WM_LBUTTONDOWN
:
3016 case WM_RBUTTONDOWN
:
3017 if (w32_num_mouse_buttons
> 2)
3018 goto handle_plain_button
;
3021 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
3022 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
3024 if (button_state
& this)
3027 if (button_state
== 0)
3030 button_state
|= this;
3032 if (button_state
& other
)
3034 if (mouse_button_timer
)
3036 KillTimer (hwnd
, mouse_button_timer
);
3037 mouse_button_timer
= 0;
3039 /* Generate middle mouse event instead. */
3040 msg
= WM_MBUTTONDOWN
;
3041 button_state
|= MMOUSE
;
3043 else if (button_state
& MMOUSE
)
3045 /* Ignore button event if we've already generated a
3046 middle mouse down event. This happens if the
3047 user releases and press one of the two buttons
3048 after we've faked a middle mouse event. */
3053 /* Flush out saved message. */
3054 post_msg (&saved_mouse_button_msg
);
3056 wmsg
.dwModifiers
= w32_get_modifiers ();
3057 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3058 signal_user_input ();
3060 /* Clear message buffer. */
3061 saved_mouse_button_msg
.msg
.hwnd
= 0;
3065 /* Hold onto message for now. */
3066 mouse_button_timer
=
3067 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
3068 w32_mouse_button_tolerance
, NULL
);
3069 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
3070 saved_mouse_button_msg
.msg
.message
= msg
;
3071 saved_mouse_button_msg
.msg
.wParam
= wParam
;
3072 saved_mouse_button_msg
.msg
.lParam
= lParam
;
3073 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
3074 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
3081 if (w32_num_mouse_buttons
> 2)
3082 goto handle_plain_button
;
3085 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
3086 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
3088 if ((button_state
& this) == 0)
3091 button_state
&= ~this;
3093 if (button_state
& MMOUSE
)
3095 /* Only generate event when second button is released. */
3096 if ((button_state
& other
) == 0)
3099 button_state
&= ~MMOUSE
;
3101 if (button_state
) abort ();
3108 /* Flush out saved message if necessary. */
3109 if (saved_mouse_button_msg
.msg
.hwnd
)
3111 post_msg (&saved_mouse_button_msg
);
3114 wmsg
.dwModifiers
= w32_get_modifiers ();
3115 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3116 signal_user_input ();
3118 /* Always clear message buffer and cancel timer. */
3119 saved_mouse_button_msg
.msg
.hwnd
= 0;
3120 KillTimer (hwnd
, mouse_button_timer
);
3121 mouse_button_timer
= 0;
3123 if (button_state
== 0)
3128 case WM_XBUTTONDOWN
:
3130 if (w32_pass_extra_mouse_buttons_to_system
)
3132 /* else fall through and process them. */
3133 case WM_MBUTTONDOWN
:
3135 handle_plain_button
:
3140 /* Ignore middle and extra buttons as long as the menu is active. */
3141 f
= x_window_to_frame (dpyinfo
, hwnd
);
3142 if (f
&& f
->output_data
.w32
->menubar_active
)
3145 if (parse_button (msg
, HIWORD (wParam
), &button
, &up
))
3147 if (up
) ReleaseCapture ();
3148 else SetCapture (hwnd
);
3149 button
= (button
== 0) ? LMOUSE
:
3150 ((button
== 1) ? MMOUSE
: RMOUSE
);
3152 button_state
&= ~button
;
3154 button_state
|= button
;
3158 wmsg
.dwModifiers
= w32_get_modifiers ();
3159 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3160 signal_user_input ();
3162 /* Need to return true for XBUTTON messages, false for others,
3163 to indicate that we processed the message. */
3164 return (msg
== WM_XBUTTONDOWN
|| msg
== WM_XBUTTONUP
);
3167 /* Ignore mouse movements as long as the menu is active. These
3168 movements are processed by the window manager anyway, and
3169 it's wrong to handle them as if they happened on the
3170 underlying frame. */
3171 f
= x_window_to_frame (dpyinfo
, hwnd
);
3172 if (f
&& f
->output_data
.w32
->menubar_active
)
3175 /* If the mouse has just moved into the frame, start tracking
3176 it, so we will be notified when it leaves the frame. Mouse
3177 tracking only works under W98 and NT4 and later. On earlier
3178 versions, there is no way of telling when the mouse leaves the
3179 frame, so we just have to put up with help-echo and mouse
3180 highlighting remaining while the frame is not active. */
3181 if (track_mouse_event_fn
&& !track_mouse_window
)
3183 TRACKMOUSEEVENT tme
;
3184 tme
.cbSize
= sizeof (tme
);
3185 tme
.dwFlags
= TME_LEAVE
;
3186 tme
.hwndTrack
= hwnd
;
3188 track_mouse_event_fn (&tme
);
3189 track_mouse_window
= hwnd
;
3192 if (w32_mouse_move_interval
<= 0
3193 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
3195 wmsg
.dwModifiers
= w32_get_modifiers ();
3196 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3200 /* Hang onto mouse move and scroll messages for a bit, to avoid
3201 sending such events to Emacs faster than it can process them.
3202 If we get more events before the timer from the first message
3203 expires, we just replace the first message. */
3205 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
3207 SetTimer (hwnd
, MOUSE_MOVE_ID
,
3208 w32_mouse_move_interval
, NULL
);
3210 /* Hold onto message for now. */
3211 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
3212 saved_mouse_move_msg
.msg
.message
= msg
;
3213 saved_mouse_move_msg
.msg
.wParam
= wParam
;
3214 saved_mouse_move_msg
.msg
.lParam
= lParam
;
3215 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
3216 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
3222 wmsg
.dwModifiers
= w32_get_modifiers ();
3223 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3224 signal_user_input ();
3228 if (w32_pass_multimedia_buttons_to_system
)
3230 /* Otherwise, pass to lisp, the same way we do with mousehwheel. */
3231 case WM_MOUSEHWHEEL
:
3232 wmsg
.dwModifiers
= w32_get_modifiers ();
3233 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3234 signal_user_input ();
3235 /* Non-zero must be returned when WM_MOUSEHWHEEL messages are
3236 handled, to prevent the system trying to handle it by faking
3237 scroll bar events. */
3241 /* Flush out saved messages if necessary. */
3242 if (wParam
== mouse_button_timer
)
3244 if (saved_mouse_button_msg
.msg
.hwnd
)
3246 post_msg (&saved_mouse_button_msg
);
3247 signal_user_input ();
3248 saved_mouse_button_msg
.msg
.hwnd
= 0;
3250 KillTimer (hwnd
, mouse_button_timer
);
3251 mouse_button_timer
= 0;
3253 else if (wParam
== mouse_move_timer
)
3255 if (saved_mouse_move_msg
.msg
.hwnd
)
3257 post_msg (&saved_mouse_move_msg
);
3258 saved_mouse_move_msg
.msg
.hwnd
= 0;
3260 KillTimer (hwnd
, mouse_move_timer
);
3261 mouse_move_timer
= 0;
3263 else if (wParam
== menu_free_timer
)
3265 KillTimer (hwnd
, menu_free_timer
);
3266 menu_free_timer
= 0;
3267 f
= x_window_to_frame (dpyinfo
, hwnd
);
3268 /* If a popup menu is active, don't wipe its strings. */
3270 && current_popup_menu
== NULL
)
3272 /* Free memory used by owner-drawn and help-echo strings. */
3273 w32_free_menu_strings (hwnd
);
3274 f
->output_data
.w32
->menubar_active
= 0;
3278 else if (wParam
== hourglass_timer
)
3280 KillTimer (hwnd
, hourglass_timer
);
3281 hourglass_timer
= 0;
3282 w32_show_hourglass (x_window_to_frame (dpyinfo
, hwnd
));
3287 /* Windows doesn't send us focus messages when putting up and
3288 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
3289 The only indication we get that something happened is receiving
3290 this message afterwards. So this is a good time to reset our
3291 keyboard modifiers' state. */
3298 /* We must ensure menu bar is fully constructed and up to date
3299 before allowing user interaction with it. To achieve this
3300 we send this message to the lisp thread and wait for a
3301 reply (whose value is not actually needed) to indicate that
3302 the menu bar is now ready for use, so we can now return.
3304 To remain responsive in the meantime, we enter a nested message
3305 loop that can process all other messages.
3307 However, we skip all this if the message results from calling
3308 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
3309 thread a message because it is blocked on us at this point. We
3310 set menubar_active before calling TrackPopupMenu to indicate
3311 this (there is no possibility of confusion with real menubar
3314 f
= x_window_to_frame (dpyinfo
, hwnd
);
3316 && (f
->output_data
.w32
->menubar_active
3317 /* We can receive this message even in the absence of a
3318 menubar (ie. when the system menu is activated) - in this
3319 case we do NOT want to forward the message, otherwise it
3320 will cause the menubar to suddenly appear when the user
3321 had requested it to be turned off! */
3322 || f
->output_data
.w32
->menubar_widget
== NULL
))
3326 deferred_msg msg_buf
;
3328 /* Detect if message has already been deferred; in this case
3329 we cannot return any sensible value to ignore this. */
3330 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3335 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
3338 case WM_EXITMENULOOP
:
3339 f
= x_window_to_frame (dpyinfo
, hwnd
);
3341 /* If a menu is still active, check again after a short delay,
3342 since Windows often (always?) sends the WM_EXITMENULOOP
3343 before the corresponding WM_COMMAND message.
3344 Don't do this if a popup menu is active, since it is only
3345 menubar menus that require cleaning up in this way.
3347 if (f
&& menubar_in_use
&& current_popup_menu
== NULL
)
3348 menu_free_timer
= SetTimer (hwnd
, MENU_FREE_ID
, MENU_FREE_DELAY
, NULL
);
3350 /* If hourglass cursor should be displayed, display it now. */
3351 if (f
&& f
->output_data
.w32
->hourglass_p
)
3352 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
3357 /* Direct handling of help_echo in menus. Should be safe now
3358 that we generate the help_echo by placing a help event in the
3361 HMENU menu
= (HMENU
) lParam
;
3362 UINT menu_item
= (UINT
) LOWORD (wParam
);
3363 UINT flags
= (UINT
) HIWORD (wParam
);
3365 w32_menu_display_help (hwnd
, menu
, menu_item
, flags
);
3369 case WM_MEASUREITEM
:
3370 f
= x_window_to_frame (dpyinfo
, hwnd
);
3373 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
3375 if (pMis
->CtlType
== ODT_MENU
)
3377 /* Work out dimensions for popup menu titles. */
3378 char * title
= (char *) pMis
->itemData
;
3379 HDC hdc
= GetDC (hwnd
);
3380 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3381 LOGFONT menu_logfont
;
3385 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3386 menu_logfont
.lfWeight
= FW_BOLD
;
3387 menu_font
= CreateFontIndirect (&menu_logfont
);
3388 old_font
= SelectObject (hdc
, menu_font
);
3390 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
3393 if (unicode_append_menu
)
3394 GetTextExtentPoint32W (hdc
, (WCHAR
*) title
,
3395 wcslen ((WCHAR
*) title
),
3398 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
3400 pMis
->itemWidth
= size
.cx
;
3401 if (pMis
->itemHeight
< size
.cy
)
3402 pMis
->itemHeight
= size
.cy
;
3405 pMis
->itemWidth
= 0;
3407 SelectObject (hdc
, old_font
);
3408 DeleteObject (menu_font
);
3409 ReleaseDC (hwnd
, hdc
);
3416 f
= x_window_to_frame (dpyinfo
, hwnd
);
3419 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
3421 if (pDis
->CtlType
== ODT_MENU
)
3423 /* Draw popup menu title. */
3424 char * title
= (char *) pDis
->itemData
;
3427 HDC hdc
= pDis
->hDC
;
3428 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3429 LOGFONT menu_logfont
;
3432 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3433 menu_logfont
.lfWeight
= FW_BOLD
;
3434 menu_font
= CreateFontIndirect (&menu_logfont
);
3435 old_font
= SelectObject (hdc
, menu_font
);
3437 /* Always draw title as if not selected. */
3438 if (unicode_append_menu
)
3441 + GetSystemMetrics (SM_CXMENUCHECK
),
3443 ETO_OPAQUE
, &pDis
->rcItem
,
3445 wcslen ((WCHAR
*) title
), NULL
);
3449 + GetSystemMetrics (SM_CXMENUCHECK
),
3451 ETO_OPAQUE
, &pDis
->rcItem
,
3452 title
, strlen (title
), NULL
);
3454 SelectObject (hdc
, old_font
);
3455 DeleteObject (menu_font
);
3463 /* Still not right - can't distinguish between clicks in the
3464 client area of the frame from clicks forwarded from the scroll
3465 bars - may have to hook WM_NCHITTEST to remember the mouse
3466 position and then check if it is in the client area ourselves. */
3467 case WM_MOUSEACTIVATE
:
3468 /* Discard the mouse click that activates a frame, allowing the
3469 user to click anywhere without changing point (or worse!).
3470 Don't eat mouse clicks on scrollbars though!! */
3471 if (LOWORD (lParam
) == HTCLIENT
)
3472 return MA_ACTIVATEANDEAT
;
3477 /* No longer tracking mouse. */
3478 track_mouse_window
= NULL
;
3480 case WM_ACTIVATEAPP
:
3482 case WM_WINDOWPOSCHANGED
:
3484 /* Inform lisp thread that a frame might have just been obscured
3485 or exposed, so should recheck visibility of all frames. */
3486 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3490 dpyinfo
->faked_key
= 0;
3492 register_hot_keys (hwnd
);
3495 unregister_hot_keys (hwnd
);
3498 /* Relinquish the system caret. */
3499 if (w32_system_caret_hwnd
)
3501 w32_visible_system_caret_hwnd
= NULL
;
3502 w32_system_caret_hwnd
= NULL
;
3508 f
= x_window_to_frame (dpyinfo
, hwnd
);
3509 if (f
&& HIWORD (wParam
) == 0)
3511 if (menu_free_timer
)
3513 KillTimer (hwnd
, menu_free_timer
);
3514 menu_free_timer
= 0;
3520 wmsg
.dwModifiers
= w32_get_modifiers ();
3521 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3529 wmsg
.dwModifiers
= w32_get_modifiers ();
3530 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3533 case WM_WINDOWPOSCHANGING
:
3534 /* Don't restrict the sizing of tip frames. */
3535 if (hwnd
== tip_window
)
3539 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
3541 wp
.length
= sizeof (WINDOWPLACEMENT
);
3542 GetWindowPlacement (hwnd
, &wp
);
3544 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
3551 DWORD internal_border
;
3552 DWORD scrollbar_extra
;
3555 wp
.length
= sizeof (wp
);
3556 GetWindowRect (hwnd
, &wr
);
3560 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
3561 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
3562 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
3563 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
3567 memset (&rect
, 0, sizeof (rect
));
3568 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
3569 GetMenu (hwnd
) != NULL
);
3571 /* Force width and height of client area to be exact
3572 multiples of the character cell dimensions. */
3573 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
3574 - 2 * internal_border
- scrollbar_extra
)
3576 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
3577 - 2 * internal_border
)
3582 /* For right/bottom sizing we can just fix the sizes.
3583 However for top/left sizing we will need to fix the X
3584 and Y positions as well. */
3586 int cx_mintrack
= GetSystemMetrics (SM_CXMINTRACK
);
3587 int cy_mintrack
= GetSystemMetrics (SM_CYMINTRACK
);
3589 lppos
->cx
= max (lppos
->cx
- wdiff
, cx_mintrack
);
3590 lppos
->cy
= max (lppos
->cy
- hdiff
, cy_mintrack
);
3592 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
3593 && (lppos
->flags
& SWP_NOMOVE
) == 0)
3595 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
3602 lppos
->flags
|= SWP_NOMOVE
;
3613 case WM_GETMINMAXINFO
:
3614 /* Hack to allow resizing the Emacs frame above the screen size.
3615 Note that Windows 9x limits coordinates to 16-bits. */
3616 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.x
= 32767;
3617 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.y
= 32767;
3621 if (LOWORD (lParam
) == HTCLIENT
)
3623 f
= x_window_to_frame (dpyinfo
, hwnd
);
3624 if (f
->output_data
.w32
->hourglass_p
&& !menubar_in_use
3625 && !current_popup_menu
)
3626 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
3628 SetCursor (f
->output_data
.w32
->current_cursor
);
3633 case WM_EMACS_SETCURSOR
:
3635 Cursor cursor
= (Cursor
) wParam
;
3636 f
= x_window_to_frame (dpyinfo
, hwnd
);
3639 f
->output_data
.w32
->current_cursor
= cursor
;
3640 if (!f
->output_data
.w32
->hourglass_p
)
3646 case WM_EMACS_CREATESCROLLBAR
:
3647 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
3648 (struct scroll_bar
*) lParam
);
3650 case WM_EMACS_SHOWWINDOW
:
3651 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
3653 case WM_EMACS_SETFOREGROUND
:
3655 HWND foreground_window
;
3656 DWORD foreground_thread
, retval
;
3658 /* On NT 5.0, and apparently Windows 98, it is necessary to
3659 attach to the thread that currently has focus in order to
3660 pull the focus away from it. */
3661 foreground_window
= GetForegroundWindow ();
3662 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
3663 if (!foreground_window
3664 || foreground_thread
== GetCurrentThreadId ()
3665 || !AttachThreadInput (GetCurrentThreadId (),
3666 foreground_thread
, TRUE
))
3667 foreground_thread
= 0;
3669 retval
= SetForegroundWindow ((HWND
) wParam
);
3671 /* Detach from the previous foreground thread. */
3672 if (foreground_thread
)
3673 AttachThreadInput (GetCurrentThreadId (),
3674 foreground_thread
, FALSE
);
3679 case WM_EMACS_SETWINDOWPOS
:
3681 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
3682 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
3683 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
3686 case WM_EMACS_DESTROYWINDOW
:
3687 DragAcceptFiles ((HWND
) wParam
, FALSE
);
3688 return DestroyWindow ((HWND
) wParam
);
3690 case WM_EMACS_HIDE_CARET
:
3691 return HideCaret (hwnd
);
3693 case WM_EMACS_SHOW_CARET
:
3694 return ShowCaret (hwnd
);
3696 case WM_EMACS_DESTROY_CARET
:
3697 w32_system_caret_hwnd
= NULL
;
3698 w32_visible_system_caret_hwnd
= NULL
;
3699 return DestroyCaret ();
3701 case WM_EMACS_TRACK_CARET
:
3702 /* If there is currently no system caret, create one. */
3703 if (w32_system_caret_hwnd
== NULL
)
3705 /* Use the default caret width, and avoid changing it
3706 unneccesarily, as it confuses screen reader software. */
3707 w32_system_caret_hwnd
= hwnd
;
3708 CreateCaret (hwnd
, NULL
, 0,
3709 w32_system_caret_height
);
3712 if (!SetCaretPos (w32_system_caret_x
, w32_system_caret_y
))
3714 /* Ensure visible caret gets turned on when requested. */
3715 else if (w32_use_visible_system_caret
3716 && w32_visible_system_caret_hwnd
!= hwnd
)
3718 w32_visible_system_caret_hwnd
= hwnd
;
3719 return ShowCaret (hwnd
);
3721 /* Ensure visible caret gets turned off when requested. */
3722 else if (!w32_use_visible_system_caret
3723 && w32_visible_system_caret_hwnd
)
3725 w32_visible_system_caret_hwnd
= NULL
;
3726 return HideCaret (hwnd
);
3731 case WM_EMACS_TRACKPOPUPMENU
:
3736 pos
= (POINT
*)lParam
;
3737 flags
= TPM_CENTERALIGN
;
3738 if (button_state
& LMOUSE
)
3739 flags
|= TPM_LEFTBUTTON
;
3740 else if (button_state
& RMOUSE
)
3741 flags
|= TPM_RIGHTBUTTON
;
3743 /* Remember we did a SetCapture on the initial mouse down event,
3744 so for safety, we make sure the capture is cancelled now. */
3748 /* Use menubar_active to indicate that WM_INITMENU is from
3749 TrackPopupMenu below, and should be ignored. */
3750 f
= x_window_to_frame (dpyinfo
, hwnd
);
3752 f
->output_data
.w32
->menubar_active
= 1;
3754 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
3758 /* Eat any mouse messages during popupmenu */
3759 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
3761 /* Get the menu selection, if any */
3762 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
3764 retval
= LOWORD (amsg
.wParam
);
3780 /* Check for messages registered at runtime. */
3781 if (msg
== msh_mousewheel
)
3783 wmsg
.dwModifiers
= w32_get_modifiers ();
3784 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3785 signal_user_input ();
3790 return DefWindowProc (hwnd
, msg
, wParam
, lParam
);
3793 /* The most common default return code for handled messages is 0. */
3798 my_create_window (struct frame
* f
)
3802 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
3804 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
3808 /* Create a tooltip window. Unlike my_create_window, we do not do this
3809 indirectly via the Window thread, as we do not need to process Window
3810 messages for the tooltip. Creating tooltips indirectly also creates
3811 deadlocks when tooltips are created for menu items. */
3813 my_create_tip_window (struct frame
*f
)
3817 rect
.left
= rect
.top
= 0;
3818 rect
.right
= FRAME_PIXEL_WIDTH (f
);
3819 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
3821 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
3822 FRAME_EXTERNAL_MENU_BAR (f
));
3824 tip_window
= FRAME_W32_WINDOW (f
)
3825 = CreateWindow (EMACS_CLASS
,
3827 f
->output_data
.w32
->dwStyle
,
3830 rect
.right
- rect
.left
,
3831 rect
.bottom
- rect
.top
,
3832 FRAME_W32_WINDOW (SELECTED_FRAME ()), /* owner */
3839 SetWindowLong (tip_window
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
3840 SetWindowLong (tip_window
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
3841 SetWindowLong (tip_window
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
3842 SetWindowLong (tip_window
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
3844 /* Tip frames have no scrollbars. */
3845 SetWindowLong (tip_window
, WND_SCROLLBAR_INDEX
, 0);
3847 /* Do this to discard the default setting specified by our parent. */
3848 ShowWindow (tip_window
, SW_HIDE
);
3853 /* Create and set up the w32 window for frame F. */
3856 w32_window (struct frame
*f
, long window_prompting
, int minibuffer_only
)
3860 /* Use the resource name as the top-level window name
3861 for looking up resources. Make a non-Lisp copy
3862 for the window manager, so GC relocation won't bother it.
3864 Elsewhere we specify the window name for the window manager. */
3867 char *str
= SSDATA (Vx_resource_name
);
3868 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
3869 strcpy (f
->namebuf
, str
);
3872 my_create_window (f
);
3874 validate_x_resource_name ();
3876 /* x_set_name normally ignores requests to set the name if the
3877 requested name is the same as the current name. This is the one
3878 place where that assumption isn't correct; f->name is set, but
3879 the server hasn't been told. */
3882 int explicit = f
->explicit_name
;
3884 f
->explicit_name
= 0;
3887 x_set_name (f
, name
, explicit);
3892 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
3893 initialize_frame_menubar (f
);
3895 if (FRAME_W32_WINDOW (f
) == 0)
3896 error ("Unable to create window");
3899 /* Handle the icon stuff for this window. Perhaps later we might
3900 want an x_set_icon_position which can be called interactively as
3904 x_icon (struct frame
*f
, Lisp_Object parms
)
3906 Lisp_Object icon_x
, icon_y
;
3907 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
3909 /* Set the position of the icon. Note that Windows 95 groups all
3910 icons in the tray. */
3911 icon_x
= x_get_arg (dpyinfo
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
3912 icon_y
= x_get_arg (dpyinfo
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
3913 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
3915 CHECK_NUMBER (icon_x
);
3916 CHECK_NUMBER (icon_y
);
3918 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
3919 error ("Both left and top icon corners of icon must be specified");
3923 if (! EQ (icon_x
, Qunbound
))
3924 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
3927 /* Start up iconic or window? */
3928 x_wm_set_window_state
3929 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
3933 x_text_icon (f
, SSDATA ((!NILP (f
->icon_name
)
3943 x_make_gc (struct frame
*f
)
3945 XGCValues gc_values
;
3949 /* Create the GC's of this frame.
3950 Note that many default values are used. */
3953 gc_values
.font
= FRAME_FONT (f
);
3955 /* Cursor has cursor-color background, background-color foreground. */
3956 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
3957 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
3958 f
->output_data
.w32
->cursor_gc
3959 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
3960 (GCFont
| GCForeground
| GCBackground
),
3964 f
->output_data
.w32
->white_relief
.gc
= 0;
3965 f
->output_data
.w32
->black_relief
.gc
= 0;
3971 /* Handler for signals raised during x_create_frame and
3972 x_create_top_frame. FRAME is the frame which is partially
3976 unwind_create_frame (Lisp_Object frame
)
3978 struct frame
*f
= XFRAME (frame
);
3980 /* If frame is ``official'', nothing to do. */
3981 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
3984 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
3987 x_free_frame_resources (f
);
3990 /* Check that reference counts are indeed correct. */
3991 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
3992 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
4001 x_default_font_parameter (struct frame
*f
, Lisp_Object parms
)
4003 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4004 Lisp_Object font_param
= x_get_arg (dpyinfo
, parms
, Qfont
, NULL
, NULL
,
4007 if (EQ (font_param
, Qunbound
))
4009 font
= !NILP (font_param
) ? font_param
4010 : x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4012 if (!STRINGP (font
))
4015 static char *names
[]
4016 = { "Courier New-10",
4017 "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1",
4018 "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1",
4022 for (i
= 0; names
[i
]; i
++)
4024 font
= font_open_by_name (f
, names
[i
]);
4029 error ("No suitable font was found");
4031 else if (!NILP (font_param
))
4033 /* Remember the explicit font parameter, so we can re-apply it after
4034 we've applied the `default' face settings. */
4035 x_set_frame_parameters (f
, Fcons (Fcons (Qfont_param
, font_param
), Qnil
));
4037 x_default_parameter (f
, parms
, Qfont
, font
, "font", "Font", RES_TYPE_STRING
);
4040 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
4042 doc
: /* Make a new window, which is called a \"frame\" in Emacs terms.
4043 Return an Emacs frame object.
4044 PARAMETERS is an alist of frame parameters.
4045 If the parameters specify that the frame should not have a minibuffer,
4046 and do not specify a specific minibuffer window to use,
4047 then `default-minibuffer-frame' must be a frame whose minibuffer can
4048 be shared by the new frame.
4050 This function is an internal primitive--use `make-frame' instead. */)
4051 (Lisp_Object parameters
)
4054 Lisp_Object frame
, tem
;
4056 int minibuffer_only
= 0;
4057 long window_prompting
= 0;
4059 int count
= SPECPDL_INDEX ();
4060 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4061 Lisp_Object display
;
4062 struct w32_display_info
*dpyinfo
= NULL
;
4066 /* Make copy of frame parameters because the original is in pure
4068 parameters
= Fcopy_alist (parameters
);
4070 /* Use this general default value to start with
4071 until we know if this frame has a specified name. */
4072 Vx_resource_name
= Vinvocation_name
;
4074 display
= x_get_arg (dpyinfo
, parameters
, Qterminal
, 0, 0, RES_TYPE_NUMBER
);
4075 if (EQ (display
, Qunbound
))
4076 display
= x_get_arg (dpyinfo
, parameters
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
4077 if (EQ (display
, Qunbound
))
4079 dpyinfo
= check_x_display_info (display
);
4080 kb
= dpyinfo
->terminal
->kboard
;
4082 if (!dpyinfo
->terminal
->name
)
4083 error ("Terminal is not live, can't create new frames on it");
4085 name
= x_get_arg (dpyinfo
, parameters
, Qname
, "name", "Name", RES_TYPE_STRING
);
4087 && ! EQ (name
, Qunbound
)
4089 error ("Invalid frame name--not a string or nil");
4092 Vx_resource_name
= name
;
4094 /* See if parent window is specified. */
4095 parent
= x_get_arg (dpyinfo
, parameters
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
4096 if (EQ (parent
, Qunbound
))
4098 if (! NILP (parent
))
4099 CHECK_NUMBER (parent
);
4101 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
4102 /* No need to protect DISPLAY because that's not used after passing
4103 it to make_frame_without_minibuffer. */
4105 GCPRO4 (parameters
, parent
, name
, frame
);
4106 tem
= x_get_arg (dpyinfo
, parameters
, Qminibuffer
, "minibuffer", "Minibuffer",
4108 if (EQ (tem
, Qnone
) || NILP (tem
))
4109 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
4110 else if (EQ (tem
, Qonly
))
4112 f
= make_minibuffer_frame ();
4113 minibuffer_only
= 1;
4115 else if (WINDOWP (tem
))
4116 f
= make_frame_without_minibuffer (tem
, kb
, display
);
4120 XSETFRAME (frame
, f
);
4122 /* Note that Windows does support scroll bars. */
4123 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
4125 /* By default, make scrollbars the system standard width. */
4126 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
4128 f
->terminal
= dpyinfo
->terminal
;
4129 f
->terminal
->reference_count
++;
4131 f
->output_method
= output_w32
;
4132 f
->output_data
.w32
=
4133 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
4134 memset (f
->output_data
.w32
, 0, sizeof (struct w32_output
));
4135 FRAME_FONTSET (f
) = -1;
4138 = x_get_arg (dpyinfo
, parameters
, Qicon_name
, "iconName", "Title",
4140 if (! STRINGP (f
->icon_name
))
4141 f
->icon_name
= Qnil
;
4143 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
4145 /* With FRAME_X_DISPLAY_INFO set up, this unwind-protect is safe. */
4146 record_unwind_protect (unwind_create_frame
, frame
);
4148 image_cache_refcount
= FRAME_IMAGE_CACHE (f
)->refcount
;
4149 dpyinfo_refcount
= dpyinfo
->reference_count
;
4150 #endif /* GLYPH_DEBUG */
4152 /* Specify the parent under which to make this window. */
4156 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
4157 f
->output_data
.w32
->explicit_parent
= 1;
4161 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4162 f
->output_data
.w32
->explicit_parent
= 0;
4165 /* Set the name; the functions to which we pass f expect the name to
4167 if (EQ (name
, Qunbound
) || NILP (name
))
4169 f
->name
= build_string (dpyinfo
->w32_id_name
);
4170 f
->explicit_name
= 0;
4175 f
->explicit_name
= 1;
4176 /* use the frame's title when getting resources for this frame. */
4177 specbind (Qx_resource_name
, name
);
4180 f
->resx
= dpyinfo
->resx
;
4181 f
->resy
= dpyinfo
->resy
;
4183 if (uniscribe_available
)
4184 register_font_driver (&uniscribe_font_driver
, f
);
4185 register_font_driver (&w32font_driver
, f
);
4187 x_default_parameter (f
, parameters
, Qfont_backend
, Qnil
,
4188 "fontBackend", "FontBackend", RES_TYPE_STRING
);
4189 /* Extract the window parameters from the supplied values
4190 that are needed to determine window geometry. */
4191 x_default_font_parameter (f
, parameters
);
4192 x_default_parameter (f
, parameters
, Qborder_width
, make_number (2),
4193 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4195 /* We recognize either internalBorderWidth or internalBorder
4196 (which is what xterm calls it). */
4197 if (NILP (Fassq (Qinternal_border_width
, parameters
)))
4201 value
= x_get_arg (dpyinfo
, parameters
, Qinternal_border_width
,
4202 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
4203 if (! EQ (value
, Qunbound
))
4204 parameters
= Fcons (Fcons (Qinternal_border_width
, value
),
4207 /* Default internalBorderWidth to 0 on Windows to match other programs. */
4208 x_default_parameter (f
, parameters
, Qinternal_border_width
, make_number (0),
4209 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
4210 x_default_parameter (f
, parameters
, Qvertical_scroll_bars
, Qright
,
4211 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
4213 /* Also do the stuff which must be set before the window exists. */
4214 x_default_parameter (f
, parameters
, Qforeground_color
, build_string ("black"),
4215 "foreground", "Foreground", RES_TYPE_STRING
);
4216 x_default_parameter (f
, parameters
, Qbackground_color
, build_string ("white"),
4217 "background", "Background", RES_TYPE_STRING
);
4218 x_default_parameter (f
, parameters
, Qmouse_color
, build_string ("black"),
4219 "pointerColor", "Foreground", RES_TYPE_STRING
);
4220 x_default_parameter (f
, parameters
, Qborder_color
, build_string ("black"),
4221 "borderColor", "BorderColor", RES_TYPE_STRING
);
4222 x_default_parameter (f
, parameters
, Qscreen_gamma
, Qnil
,
4223 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
4224 x_default_parameter (f
, parameters
, Qline_spacing
, Qnil
,
4225 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
4226 x_default_parameter (f
, parameters
, Qleft_fringe
, Qnil
,
4227 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
4228 x_default_parameter (f
, parameters
, Qright_fringe
, Qnil
,
4229 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
4231 /* Init faces before x_default_parameter is called for scroll-bar
4232 parameters because that function calls x_set_scroll_bar_width,
4233 which calls change_frame_size, which calls Fset_window_buffer,
4234 which runs hooks, which call Fvertical_motion. At the end, we
4235 end up in init_iterator with a null face cache, which should not
4237 init_frame_faces (f
);
4239 /* The X resources controlling the menu-bar and tool-bar are
4240 processed specially at startup, and reflected in the mode
4241 variables; ignore them here. */
4242 x_default_parameter (f
, parameters
, Qmenu_bar_lines
,
4243 NILP (Vmenu_bar_mode
)
4244 ? make_number (0) : make_number (1),
4245 NULL
, NULL
, RES_TYPE_NUMBER
);
4246 x_default_parameter (f
, parameters
, Qtool_bar_lines
,
4247 NILP (Vtool_bar_mode
)
4248 ? make_number (0) : make_number (1),
4249 NULL
, NULL
, RES_TYPE_NUMBER
);
4251 x_default_parameter (f
, parameters
, Qbuffer_predicate
, Qnil
,
4252 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
4253 x_default_parameter (f
, parameters
, Qtitle
, Qnil
,
4254 "title", "Title", RES_TYPE_STRING
);
4255 x_default_parameter (f
, parameters
, Qfullscreen
, Qnil
,
4256 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
4258 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
4259 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4261 f
->output_data
.w32
->text_cursor
= w32_load_cursor (IDC_IBEAM
);
4262 f
->output_data
.w32
->nontext_cursor
= w32_load_cursor (IDC_ARROW
);
4263 f
->output_data
.w32
->modeline_cursor
= w32_load_cursor (IDC_ARROW
);
4264 f
->output_data
.w32
->hand_cursor
= w32_load_cursor (IDC_HAND
);
4265 f
->output_data
.w32
->hourglass_cursor
= w32_load_cursor (IDC_WAIT
);
4266 f
->output_data
.w32
->horizontal_drag_cursor
= w32_load_cursor (IDC_SIZEWE
);
4268 f
->output_data
.w32
->current_cursor
= f
->output_data
.w32
->nontext_cursor
;
4270 window_prompting
= x_figure_window_size (f
, parameters
, 1);
4272 tem
= x_get_arg (dpyinfo
, parameters
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
4273 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
4275 w32_window (f
, window_prompting
, minibuffer_only
);
4276 x_icon (f
, parameters
);
4280 /* Now consider the frame official. */
4281 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
4282 Vframe_list
= Fcons (frame
, Vframe_list
);
4284 /* We need to do this after creating the window, so that the
4285 icon-creation functions can say whose icon they're describing. */
4286 x_default_parameter (f
, parameters
, Qicon_type
, Qnil
,
4287 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
4289 x_default_parameter (f
, parameters
, Qauto_raise
, Qnil
,
4290 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4291 x_default_parameter (f
, parameters
, Qauto_lower
, Qnil
,
4292 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4293 x_default_parameter (f
, parameters
, Qcursor_type
, Qbox
,
4294 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4295 x_default_parameter (f
, parameters
, Qscroll_bar_width
, Qnil
,
4296 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
4297 x_default_parameter (f
, parameters
, Qalpha
, Qnil
,
4298 "alpha", "Alpha", RES_TYPE_NUMBER
);
4300 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4301 Change will not be effected unless different from the current
4303 width
= FRAME_COLS (f
);
4304 height
= FRAME_LINES (f
);
4306 FRAME_LINES (f
) = 0;
4307 SET_FRAME_COLS (f
, 0);
4308 change_frame_size (f
, height
, width
, 1, 0, 0);
4310 /* Tell the server what size and position, etc, we want, and how
4311 badly we want them. This should be done after we have the menu
4312 bar so that its size can be taken into account. */
4314 x_wm_set_size_hint (f
, window_prompting
, 0);
4317 /* Make the window appear on the frame and enable display, unless
4318 the caller says not to. However, with explicit parent, Emacs
4319 cannot control visibility, so don't try. */
4320 if (! f
->output_data
.w32
->explicit_parent
)
4322 Lisp_Object visibility
;
4324 visibility
= x_get_arg (dpyinfo
, parameters
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
4325 if (EQ (visibility
, Qunbound
))
4328 if (EQ (visibility
, Qicon
))
4329 x_iconify_frame (f
);
4330 else if (! NILP (visibility
))
4331 x_make_frame_visible (f
);
4333 /* Must have been Qnil. */
4337 /* Initialize `default-minibuffer-frame' in case this is the first
4338 frame on this terminal. */
4339 if (FRAME_HAS_MINIBUF_P (f
)
4340 && (!FRAMEP (KVAR (kb
, Vdefault_minibuffer_frame
))
4341 || !FRAME_LIVE_P (XFRAME (KVAR (kb
, Vdefault_minibuffer_frame
)))))
4342 KVAR (kb
, Vdefault_minibuffer_frame
) = frame
;
4344 /* All remaining specified parameters, which have not been "used"
4345 by x_get_arg and friends, now go in the misc. alist of the frame. */
4346 for (tem
= parameters
; CONSP (tem
); tem
= XCDR (tem
))
4347 if (CONSP (XCAR (tem
)) && !NILP (XCAR (XCAR (tem
))))
4348 f
->param_alist
= Fcons (XCAR (tem
), f
->param_alist
);
4352 /* Make sure windows on this frame appear in calls to next-window
4353 and similar functions. */
4354 Vwindow_list
= Qnil
;
4356 return unbind_to (count
, frame
);
4359 /* FRAME is used only to get a handle on the X display. We don't pass the
4360 display info directly because we're called from frame.c, which doesn't
4361 know about that structure. */
4363 x_get_focus_frame (struct frame
*frame
)
4365 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
4367 if (! dpyinfo
->w32_focus_frame
)
4370 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
4374 DEFUN ("x-focus-frame", Fx_focus_frame
, Sx_focus_frame
, 1, 1, 0,
4375 doc
: /* Give FRAME input focus, raising to foreground if necessary. */)
4378 x_focus_on_frame (check_x_frame (frame
));
4383 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
4384 doc
: /* Internal function called by `color-defined-p', which see.
4385 \(Note that the Nextstep version of this function ignores FRAME.) */)
4386 (Lisp_Object color
, Lisp_Object frame
)
4389 FRAME_PTR f
= check_x_frame (frame
);
4391 CHECK_STRING (color
);
4393 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
4399 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
4400 doc
: /* Internal function called by `color-values', which see. */)
4401 (Lisp_Object color
, Lisp_Object frame
)
4404 FRAME_PTR f
= check_x_frame (frame
);
4406 CHECK_STRING (color
);
4408 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
4409 return list3 (make_number ((GetRValue (foo
.pixel
) << 8)
4410 | GetRValue (foo
.pixel
)),
4411 make_number ((GetGValue (foo
.pixel
) << 8)
4412 | GetGValue (foo
.pixel
)),
4413 make_number ((GetBValue (foo
.pixel
) << 8)
4414 | GetBValue (foo
.pixel
)));
4419 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
4420 doc
: /* Internal function called by `display-color-p', which see. */)
4421 (Lisp_Object display
)
4423 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4425 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
4431 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
,
4432 Sx_display_grayscale_p
, 0, 1, 0,
4433 doc
: /* Return t if DISPLAY supports shades of gray.
4434 Note that color displays do support shades of gray.
4435 The optional argument DISPLAY specifies which display to ask about.
4436 DISPLAY should be either a frame or a display name (a string).
4437 If omitted or nil, that stands for the selected frame's display. */)
4438 (Lisp_Object display
)
4440 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4442 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
4448 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
,
4449 Sx_display_pixel_width
, 0, 1, 0,
4450 doc
: /* Return the width in pixels of DISPLAY.
4451 The optional argument DISPLAY specifies which display to ask about.
4452 DISPLAY should be either a frame or a display name (a string).
4453 If omitted or nil, that stands for the selected frame's display. */)
4454 (Lisp_Object display
)
4456 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4458 return make_number (x_display_pixel_width (dpyinfo
));
4461 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
4462 Sx_display_pixel_height
, 0, 1, 0,
4463 doc
: /* Return the height in pixels of DISPLAY.
4464 The optional argument DISPLAY specifies which display to ask about.
4465 DISPLAY should be either a frame or a display name (a string).
4466 If omitted or nil, that stands for the selected frame's display. */)
4467 (Lisp_Object display
)
4469 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4471 return make_number (x_display_pixel_height (dpyinfo
));
4474 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
4476 doc
: /* Return the number of bitplanes of DISPLAY.
4477 The optional argument DISPLAY specifies which display to ask about.
4478 DISPLAY should be either a frame or a display name (a string).
4479 If omitted or nil, that stands for the selected frame's display. */)
4480 (Lisp_Object display
)
4482 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4484 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
4487 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
4489 doc
: /* Return the number of color cells of DISPLAY.
4490 The optional argument DISPLAY specifies which display to ask about.
4491 DISPLAY should be either a frame or a display name (a string).
4492 If omitted or nil, that stands for the selected frame's display. */)
4493 (Lisp_Object display
)
4495 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4499 hdc
= GetDC (dpyinfo
->root_window
);
4500 if (dpyinfo
->has_palette
)
4501 cap
= GetDeviceCaps (hdc
, SIZEPALETTE
);
4503 cap
= GetDeviceCaps (hdc
, NUMCOLORS
);
4505 /* We force 24+ bit depths to 24-bit, both to prevent an overflow
4506 and because probably is more meaningful on Windows anyway */
4508 cap
= 1 << min (dpyinfo
->n_planes
* dpyinfo
->n_cbits
, 24);
4510 ReleaseDC (dpyinfo
->root_window
, hdc
);
4512 return make_number (cap
);
4515 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
4516 Sx_server_max_request_size
,
4518 doc
: /* Return the maximum request size of the server of DISPLAY.
4519 The optional argument DISPLAY specifies which display to ask about.
4520 DISPLAY should be either a frame or a display name (a string).
4521 If omitted or nil, that stands for the selected frame's display. */)
4522 (Lisp_Object display
)
4524 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4526 return make_number (1);
4529 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
4530 doc
: /* Return the "vendor ID" string of the W32 system (Microsoft).
4531 The optional argument DISPLAY specifies which display to ask about.
4532 DISPLAY should be either a frame or a display name (a string).
4533 If omitted or nil, that stands for the selected frame's display. */)
4534 (Lisp_Object display
)
4536 return build_string ("Microsoft Corp.");
4539 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
4540 doc
: /* Return the version numbers of the server of DISPLAY.
4541 The value is a list of three integers: the major and minor
4542 version numbers of the X Protocol in use, and the distributor-specific
4543 release number. See also the function `x-server-vendor'.
4545 The optional argument DISPLAY specifies which display to ask about.
4546 DISPLAY should be either a frame or a display name (a string).
4547 If omitted or nil, that stands for the selected frame's display. */)
4548 (Lisp_Object display
)
4550 return Fcons (make_number (w32_major_version
),
4551 Fcons (make_number (w32_minor_version
),
4552 Fcons (make_number (w32_build_number
), Qnil
)));
4555 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
4556 doc
: /* Return the number of screens on the server of DISPLAY.
4557 The optional argument DISPLAY specifies which display to ask about.
4558 DISPLAY should be either a frame or a display name (a string).
4559 If omitted or nil, that stands for the selected frame's display. */)
4560 (Lisp_Object display
)
4562 return make_number (1);
4565 DEFUN ("x-display-mm-height", Fx_display_mm_height
,
4566 Sx_display_mm_height
, 0, 1, 0,
4567 doc
: /* Return the height in millimeters of DISPLAY.
4568 The optional argument DISPLAY specifies which display to ask about.
4569 DISPLAY should be either a frame or a display name (a string).
4570 If omitted or nil, that stands for the selected frame's display. */)
4571 (Lisp_Object display
)
4573 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4577 hdc
= GetDC (dpyinfo
->root_window
);
4579 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
4581 ReleaseDC (dpyinfo
->root_window
, hdc
);
4583 return make_number (cap
);
4586 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
4587 doc
: /* Return the width in millimeters of DISPLAY.
4588 The optional argument DISPLAY specifies which display to ask about.
4589 DISPLAY should be either a frame or a display name (a string).
4590 If omitted or nil, that stands for the selected frame's display. */)
4591 (Lisp_Object display
)
4593 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4598 hdc
= GetDC (dpyinfo
->root_window
);
4600 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
4602 ReleaseDC (dpyinfo
->root_window
, hdc
);
4604 return make_number (cap
);
4607 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
4608 Sx_display_backing_store
, 0, 1, 0,
4609 doc
: /* Return an indication of whether DISPLAY does backing store.
4610 The value may be `always', `when-mapped', or `not-useful'.
4611 The optional argument DISPLAY specifies which display to ask about.
4612 DISPLAY should be either a frame or a display name (a string).
4613 If omitted or nil, that stands for the selected frame's display. */)
4614 (Lisp_Object display
)
4616 return intern ("not-useful");
4619 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
4620 Sx_display_visual_class
, 0, 1, 0,
4621 doc
: /* Return the visual class of DISPLAY.
4622 The value is one of the symbols `static-gray', `gray-scale',
4623 `static-color', `pseudo-color', `true-color', or `direct-color'.
4625 The optional argument DISPLAY specifies which display to ask about.
4626 DISPLAY should be either a frame or a display name (a string).
4627 If omitted or nil, that stands for the selected frame's display. */)
4628 (Lisp_Object display
)
4630 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4631 Lisp_Object result
= Qnil
;
4633 if (dpyinfo
->has_palette
)
4634 result
= intern ("pseudo-color");
4635 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
4636 result
= intern ("static-grey");
4637 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
4638 result
= intern ("static-color");
4639 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
4640 result
= intern ("true-color");
4645 DEFUN ("x-display-save-under", Fx_display_save_under
,
4646 Sx_display_save_under
, 0, 1, 0,
4647 doc
: /* Return t if DISPLAY supports the save-under feature.
4648 The optional argument DISPLAY specifies which display to ask about.
4649 DISPLAY should be either a frame or a display name (a string).
4650 If omitted or nil, that stands for the selected frame's display. */)
4651 (Lisp_Object display
)
4657 x_pixel_width (register struct frame
*f
)
4659 return FRAME_PIXEL_WIDTH (f
);
4663 x_pixel_height (register struct frame
*f
)
4665 return FRAME_PIXEL_HEIGHT (f
);
4669 x_char_width (register struct frame
*f
)
4671 return FRAME_COLUMN_WIDTH (f
);
4675 x_char_height (register struct frame
*f
)
4677 return FRAME_LINE_HEIGHT (f
);
4681 x_screen_planes (register struct frame
*f
)
4683 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
4686 /* Return the display structure for the display named NAME.
4687 Open a new connection if necessary. */
4689 struct w32_display_info
*
4690 x_display_info_for_name (Lisp_Object name
)
4693 struct w32_display_info
*dpyinfo
;
4695 CHECK_STRING (name
);
4697 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
4699 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
4702 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
4707 /* Use this general default value to start with. */
4708 Vx_resource_name
= Vinvocation_name
;
4710 validate_x_resource_name ();
4712 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
4713 SSDATA (Vx_resource_name
));
4716 error ("Cannot connect to server %s", SDATA (name
));
4719 XSETFASTINT (Vwindow_system_version
, w32_major_version
);
4724 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
4725 1, 3, 0, doc
: /* Open a connection to a display server.
4726 DISPLAY is the name of the display to connect to.
4727 Optional second arg XRM-STRING is a string of resources in xrdb format.
4728 If the optional third arg MUST-SUCCEED is non-nil,
4729 terminate Emacs if we can't open the connection.
4730 \(In the Nextstep version, the last two arguments are currently ignored.) */)
4731 (Lisp_Object display
, Lisp_Object xrm_string
, Lisp_Object must_succeed
)
4733 unsigned char *xrm_option
;
4734 struct w32_display_info
*dpyinfo
;
4736 /* If initialization has already been done, return now to avoid
4737 overwriting critical parts of one_w32_display_info. */
4741 CHECK_STRING (display
);
4742 if (! NILP (xrm_string
))
4743 CHECK_STRING (xrm_string
);
4746 if (! EQ (Vwindow_system
, intern ("w32")))
4747 error ("Not using Microsoft Windows");
4750 /* Allow color mapping to be defined externally; first look in user's
4751 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
4753 Lisp_Object color_file
;
4754 struct gcpro gcpro1
;
4756 color_file
= build_string ("~/rgb.txt");
4758 GCPRO1 (color_file
);
4760 if (NILP (Ffile_readable_p (color_file
)))
4762 Fexpand_file_name (build_string ("rgb.txt"),
4763 Fsymbol_value (intern ("data-directory")));
4765 Vw32_color_map
= Fx_load_color_file (color_file
);
4769 if (NILP (Vw32_color_map
))
4770 Vw32_color_map
= Fw32_default_color_map ();
4772 /* Merge in system logical colors. */
4773 add_system_logical_colors_to_map (&Vw32_color_map
);
4775 if (! NILP (xrm_string
))
4776 xrm_option
= SDATA (xrm_string
);
4778 xrm_option
= (unsigned char *) 0;
4780 /* Use this general default value to start with. */
4781 /* First remove .exe suffix from invocation-name - it looks ugly. */
4783 char basename
[ MAX_PATH
], *str
;
4785 strcpy (basename
, SDATA (Vinvocation_name
));
4786 str
= strrchr (basename
, '.');
4788 Vinvocation_name
= build_string (basename
);
4790 Vx_resource_name
= Vinvocation_name
;
4792 validate_x_resource_name ();
4794 /* This is what opens the connection and sets x_current_display.
4795 This also initializes many symbols, such as those used for input. */
4796 dpyinfo
= w32_term_init (display
, xrm_option
,
4797 SSDATA (Vx_resource_name
));
4801 if (!NILP (must_succeed
))
4802 fatal ("Cannot connect to server %s.\n",
4805 error ("Cannot connect to server %s", SDATA (display
));
4810 XSETFASTINT (Vwindow_system_version
, w32_major_version
);
4814 DEFUN ("x-close-connection", Fx_close_connection
,
4815 Sx_close_connection
, 1, 1, 0,
4816 doc
: /* Close the connection to DISPLAY's server.
4817 For DISPLAY, specify either a frame or a display name (a string).
4818 If DISPLAY is nil, that stands for the selected frame's display. */)
4819 (Lisp_Object display
)
4821 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4823 if (dpyinfo
->reference_count
> 0)
4824 error ("Display still has frames on it");
4827 x_destroy_all_bitmaps (dpyinfo
);
4829 x_delete_display (dpyinfo
);
4835 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
4836 doc
: /* Return the list of display names that Emacs has connections to. */)
4839 Lisp_Object tail
, result
;
4842 for (tail
= w32_display_name_list
; CONSP (tail
); tail
= XCDR (tail
))
4843 result
= Fcons (XCAR (XCAR (tail
)), result
);
4848 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
4849 doc
: /* If ON is non-nil, report X errors as soon as the erring request is made.
4850 This function only has an effect on X Windows. With MS Windows, it is
4851 defined but does nothing.
4853 If ON is nil, allow buffering of requests.
4854 Turning on synchronization prohibits the Xlib routines from buffering
4855 requests and seriously degrades performance, but makes debugging much
4857 The optional second argument TERMINAL specifies which display to act on.
4858 TERMINAL should be a terminal object, a frame or a display name (a string).
4859 If TERMINAL is omitted or nil, that stands for the selected frame's display. */)
4860 (Lisp_Object on
, Lisp_Object display
)
4867 /***********************************************************************
4869 ***********************************************************************/
4871 DEFUN ("x-change-window-property", Fx_change_window_property
,
4872 Sx_change_window_property
, 2, 6, 0,
4873 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
4874 PROP must be a string. VALUE may be a string or a list of conses,
4875 numbers and/or strings. If an element in the list is a string, it is
4876 converted to an atom and the value of the Atom is used. If an element
4877 is a cons, it is converted to a 32 bit number where the car is the 16
4878 top bits and the cdr is the lower 16 bits.
4880 FRAME nil or omitted means use the selected frame.
4881 If TYPE is given and non-nil, it is the name of the type of VALUE.
4882 If TYPE is not given or nil, the type is STRING.
4883 FORMAT gives the size in bits of each element if VALUE is a list.
4884 It must be one of 8, 16 or 32.
4885 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
4886 If OUTER_P is non-nil, the property is changed for the outer X window of
4887 FRAME. Default is to change on the edit X window. */)
4888 (Lisp_Object prop
, Lisp_Object value
, Lisp_Object frame
, Lisp_Object type
, Lisp_Object format
, Lisp_Object outer_p
)
4890 #if 0 /* TODO : port window properties to W32 */
4891 struct frame
*f
= check_x_frame (frame
);
4894 CHECK_STRING (prop
);
4895 CHECK_STRING (value
);
4898 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
4899 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
4900 prop_atom
, XA_STRING
, 8, PropModeReplace
,
4901 SDATA (value
), SCHARS (value
));
4903 /* Make sure the property is set when we return. */
4904 XFlush (FRAME_W32_DISPLAY (f
));
4913 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
4914 Sx_delete_window_property
, 1, 2, 0,
4915 doc
: /* Remove window property PROP from X window of FRAME.
4916 FRAME nil or omitted means use the selected frame. Value is PROP. */)
4917 (Lisp_Object prop
, Lisp_Object frame
)
4919 #if 0 /* TODO : port window properties to W32 */
4921 struct frame
*f
= check_x_frame (frame
);
4924 CHECK_STRING (prop
);
4926 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
4927 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
4929 /* Make sure the property is removed when we return. */
4930 XFlush (FRAME_W32_DISPLAY (f
));
4938 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
4940 doc
: /* Value is the value of window property PROP on FRAME.
4941 If FRAME is nil or omitted, use the selected frame.
4943 On MS Windows, this function only accepts the PROP and FRAME arguments.
4945 On X Windows, the following optional arguments are also accepted:
4946 If TYPE is nil or omitted, get the property as a string.
4947 Otherwise TYPE is the name of the atom that denotes the type expected.
4948 If SOURCE is non-nil, get the property on that window instead of from
4949 FRAME. The number 0 denotes the root window.
4950 If DELETE_P is non-nil, delete the property after retreiving it.
4951 If VECTOR_RET_P is non-nil, don't return a string but a vector of values.
4953 Value is nil if FRAME hasn't a property with name PROP or if PROP has
4954 no value of TYPE (always string in the MS Windows case). */)
4955 (Lisp_Object prop
, Lisp_Object frame
)
4957 #if 0 /* TODO : port window properties to W32 */
4959 struct frame
*f
= check_x_frame (frame
);
4962 Lisp_Object prop_value
= Qnil
;
4963 char *tmp_data
= NULL
;
4966 unsigned long actual_size
, bytes_remaining
;
4968 CHECK_STRING (prop
);
4970 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
4971 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
4972 prop_atom
, 0, 0, False
, XA_STRING
,
4973 &actual_type
, &actual_format
, &actual_size
,
4974 &bytes_remaining
, (unsigned char **) &tmp_data
);
4977 int size
= bytes_remaining
;
4982 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
4983 prop_atom
, 0, bytes_remaining
,
4985 &actual_type
, &actual_format
,
4986 &actual_size
, &bytes_remaining
,
4987 (unsigned char **) &tmp_data
);
4989 prop_value
= make_string (tmp_data
, size
);
5004 /***********************************************************************
5006 ***********************************************************************/
5008 /* Default number of seconds to wait before displaying an hourglass
5009 cursor. Duplicated from xdisp.c, but cannot use the version there
5010 due to lack of atimers on w32. */
5011 #define DEFAULT_HOURGLASS_DELAY 1
5012 /* Return non-zero if houglass timer has been started or hourglass is shown. */
5013 /* PENDING: if W32 can use atimers (atimer.[hc]) then the common impl in
5014 xdisp.c could be used. */
5017 hourglass_started (void)
5019 return hourglass_shown_p
|| hourglass_timer
;
5022 /* Cancel a currently active hourglass timer, and start a new one. */
5025 start_hourglass (void)
5028 int secs
, msecs
= 0;
5029 struct frame
* f
= SELECTED_FRAME ();
5031 /* No cursors on non GUI frames. */
5032 if (!FRAME_W32_P (f
))
5035 cancel_hourglass ();
5037 if (INTEGERP (Vhourglass_delay
)
5038 && XINT (Vhourglass_delay
) > 0)
5039 secs
= XFASTINT (Vhourglass_delay
);
5040 else if (FLOATP (Vhourglass_delay
)
5041 && XFLOAT_DATA (Vhourglass_delay
) > 0)
5044 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
5045 secs
= XFASTINT (tem
);
5046 msecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000;
5049 secs
= DEFAULT_HOURGLASS_DELAY
;
5051 delay
= secs
* 1000 + msecs
;
5052 hourglass_hwnd
= FRAME_W32_WINDOW (f
);
5053 hourglass_timer
= SetTimer (hourglass_hwnd
, HOURGLASS_ID
, delay
, NULL
);
5057 /* Cancel the hourglass cursor timer if active, hide an hourglass
5061 cancel_hourglass (void)
5063 if (hourglass_timer
)
5065 KillTimer (hourglass_hwnd
, hourglass_timer
);
5066 hourglass_timer
= 0;
5069 if (hourglass_shown_p
)
5070 w32_hide_hourglass ();
5074 /* Timer function of hourglass_timer.
5076 Display an hourglass cursor. Set the hourglass_p flag in display info
5077 to indicate that an hourglass cursor is shown. */
5080 w32_show_hourglass (struct frame
*f
)
5082 if (!hourglass_shown_p
)
5084 f
->output_data
.w32
->hourglass_p
= 1;
5085 if (!menubar_in_use
&& !current_popup_menu
)
5086 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
5087 hourglass_shown_p
= 1;
5092 /* Hide the hourglass cursor on all frames, if it is currently shown. */
5095 w32_hide_hourglass (void)
5097 if (hourglass_shown_p
)
5099 struct frame
*f
= x_window_to_frame (&one_w32_display_info
,
5102 f
->output_data
.w32
->hourglass_p
= 0;
5104 /* If frame was deleted, restore to selected frame's cursor. */
5105 f
= SELECTED_FRAME ();
5107 if (FRAME_W32_P (f
))
5108 SetCursor (f
->output_data
.w32
->current_cursor
);
5110 /* No cursors on non GUI frames - restore to stock arrow cursor. */
5111 SetCursor (w32_load_cursor (IDC_ARROW
));
5113 hourglass_shown_p
= 0;
5119 /***********************************************************************
5121 ***********************************************************************/
5123 static Lisp_Object
x_create_tip_frame (struct w32_display_info
*,
5124 Lisp_Object
, Lisp_Object
);
5125 static void compute_tip_xy (struct frame
*, Lisp_Object
, Lisp_Object
,
5126 Lisp_Object
, int, int, int *, int *);
5128 /* The frame of a currently visible tooltip. */
5130 Lisp_Object tip_frame
;
5132 /* If non-nil, a timer started that hides the last tooltip when it
5135 Lisp_Object tip_timer
;
5138 /* If non-nil, a vector of 3 elements containing the last args
5139 with which x-show-tip was called. See there. */
5141 Lisp_Object last_show_tip_args
;
5145 unwind_create_tip_frame (Lisp_Object frame
)
5147 Lisp_Object deleted
;
5149 deleted
= unwind_create_frame (frame
);
5150 if (EQ (deleted
, Qt
))
5160 /* Create a frame for a tooltip on the display described by DPYINFO.
5161 PARMS is a list of frame parameters. TEXT is the string to
5162 display in the tip frame. Value is the frame.
5164 Note that functions called here, esp. x_default_parameter can
5165 signal errors, for instance when a specified color name is
5166 undefined. We have to make sure that we're in a consistent state
5167 when this happens. */
5170 x_create_tip_frame (struct w32_display_info
*dpyinfo
,
5171 Lisp_Object parms
, Lisp_Object text
)
5174 Lisp_Object frame
, tem
;
5176 long window_prompting
= 0;
5178 int count
= SPECPDL_INDEX ();
5179 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5181 int face_change_count_before
= face_change_count
;
5183 struct buffer
*old_buffer
;
5187 /* Use this general default value to start with until we know if
5188 this frame has a specified name. */
5189 Vx_resource_name
= Vinvocation_name
;
5191 kb
= dpyinfo
->terminal
->kboard
;
5193 /* The calls to x_get_arg remove elements from PARMS, so copy it to
5194 avoid destructive changes behind our caller's back. */
5195 parms
= Fcopy_alist (parms
);
5197 /* Get the name of the frame to use for resource lookup. */
5198 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
5200 && !EQ (name
, Qunbound
)
5202 error ("Invalid frame name--not a string or nil");
5203 Vx_resource_name
= name
;
5206 GCPRO3 (parms
, name
, frame
);
5207 /* Make a frame without minibuffer nor mode-line. */
5209 f
->wants_modeline
= 0;
5210 XSETFRAME (frame
, f
);
5212 buffer
= Fget_buffer_create (build_string (" *tip*"));
5213 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, Qnil
);
5214 old_buffer
= current_buffer
;
5215 set_buffer_internal_1 (XBUFFER (buffer
));
5216 BVAR (current_buffer
, truncate_lines
) = Qnil
;
5217 specbind (Qinhibit_read_only
, Qt
);
5218 specbind (Qinhibit_modification_hooks
, Qt
);
5221 set_buffer_internal_1 (old_buffer
);
5223 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
5224 record_unwind_protect (unwind_create_tip_frame
, frame
);
5226 /* By setting the output method, we're essentially saying that
5227 the frame is live, as per FRAME_LIVE_P. If we get a signal
5228 from this point on, x_destroy_window might screw up reference
5230 f
->terminal
= dpyinfo
->terminal
;
5231 f
->terminal
->reference_count
++;
5232 f
->output_method
= output_w32
;
5233 f
->output_data
.w32
=
5234 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
5235 memset (f
->output_data
.w32
, 0, sizeof (struct w32_output
));
5237 FRAME_FONTSET (f
) = -1;
5238 f
->icon_name
= Qnil
;
5241 image_cache_refcount
= FRAME_IMAGE_CACHE (f
)->refcount
;
5242 dpyinfo_refcount
= dpyinfo
->reference_count
;
5243 #endif /* GLYPH_DEBUG */
5244 FRAME_KBOARD (f
) = kb
;
5245 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5246 f
->output_data
.w32
->explicit_parent
= 0;
5248 /* Set the name; the functions to which we pass f expect the name to
5250 if (EQ (name
, Qunbound
) || NILP (name
))
5252 f
->name
= build_string (dpyinfo
->w32_id_name
);
5253 f
->explicit_name
= 0;
5258 f
->explicit_name
= 1;
5259 /* use the frame's title when getting resources for this frame. */
5260 specbind (Qx_resource_name
, name
);
5263 f
->resx
= dpyinfo
->resx
;
5264 f
->resy
= dpyinfo
->resy
;
5266 if (uniscribe_available
)
5267 register_font_driver (&uniscribe_font_driver
, f
);
5268 register_font_driver (&w32font_driver
, f
);
5270 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
5271 "fontBackend", "FontBackend", RES_TYPE_STRING
);
5273 /* Extract the window parameters from the supplied values
5274 that are needed to determine window geometry. */
5275 x_default_font_parameter (f
, parms
);
5277 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
5278 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5279 /* This defaults to 2 in order to match xterm. We recognize either
5280 internalBorderWidth or internalBorder (which is what xterm calls
5282 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5286 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
5287 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
5288 if (! EQ (value
, Qunbound
))
5289 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
5292 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
5293 "internalBorderWidth", "internalBorderWidth",
5296 /* Also do the stuff which must be set before the window exists. */
5297 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
5298 "foreground", "Foreground", RES_TYPE_STRING
);
5299 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
5300 "background", "Background", RES_TYPE_STRING
);
5301 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
5302 "pointerColor", "Foreground", RES_TYPE_STRING
);
5303 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
5304 "cursorColor", "Foreground", RES_TYPE_STRING
);
5305 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
5306 "borderColor", "BorderColor", RES_TYPE_STRING
);
5308 /* Init faces before x_default_parameter is called for scroll-bar
5309 parameters because that function calls x_set_scroll_bar_width,
5310 which calls change_frame_size, which calls Fset_window_buffer,
5311 which runs hooks, which call Fvertical_motion. At the end, we
5312 end up in init_iterator with a null face cache, which should not
5314 init_frame_faces (f
);
5316 f
->output_data
.w32
->dwStyle
= WS_BORDER
| WS_POPUP
| WS_DISABLED
;
5317 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5319 window_prompting
= x_figure_window_size (f
, parms
, 0);
5321 /* No fringes on tip frame. */
5323 f
->left_fringe_width
= 0;
5324 f
->right_fringe_width
= 0;
5327 my_create_tip_window (f
);
5332 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
5333 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5334 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5335 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5336 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5337 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5339 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
5340 Change will not be effected unless different from the current
5342 width
= FRAME_COLS (f
);
5343 height
= FRAME_LINES (f
);
5344 FRAME_LINES (f
) = 0;
5345 SET_FRAME_COLS (f
, 0);
5346 change_frame_size (f
, height
, width
, 1, 0, 0);
5348 /* Add `tooltip' frame parameter's default value. */
5349 if (NILP (Fframe_parameter (frame
, Qtooltip
)))
5350 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qtooltip
, Qt
), Qnil
));
5352 /* Set up faces after all frame parameters are known. This call
5353 also merges in face attributes specified for new frames.
5355 Frame parameters may be changed if .Xdefaults contains
5356 specifications for the default font. For example, if there is an
5357 `Emacs.default.attributeBackground: pink', the `background-color'
5358 attribute of the frame get's set, which let's the internal border
5359 of the tooltip frame appear in pink. Prevent this. */
5361 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
5362 Lisp_Object fg
= Fframe_parameter (frame
, Qforeground_color
);
5363 Lisp_Object colors
= Qnil
;
5365 /* Set tip_frame here, so that */
5367 call2 (Qface_set_after_frame_default
, frame
, Qnil
);
5369 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
5370 colors
= Fcons (Fcons (Qbackground_color
, bg
), colors
);
5371 if (!EQ (fg
, Fframe_parameter (frame
, Qforeground_color
)))
5372 colors
= Fcons (Fcons (Qforeground_color
, fg
), colors
);
5375 Fmodify_frame_parameters (frame
, colors
);
5382 /* It is now ok to make the frame official even if we get an error
5383 below. And the frame needs to be on Vframe_list or making it
5384 visible won't work. */
5385 Vframe_list
= Fcons (frame
, Vframe_list
);
5387 /* Now that the frame is official, it counts as a reference to
5389 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
5391 /* Setting attributes of faces of the tooltip frame from resources
5392 and similar will increment face_change_count, which leads to the
5393 clearing of all current matrices. Since this isn't necessary
5394 here, avoid it by resetting face_change_count to the value it
5395 had before we created the tip frame. */
5396 face_change_count
= face_change_count_before
;
5398 /* Discard the unwind_protect. */
5399 return unbind_to (count
, frame
);
5403 /* Compute where to display tip frame F. PARMS is the list of frame
5404 parameters for F. DX and DY are specified offsets from the current
5405 location of the mouse. WIDTH and HEIGHT are the width and height
5406 of the tooltip. Return coordinates relative to the root window of
5407 the display in *ROOT_X, and *ROOT_Y. */
5410 compute_tip_xy (struct frame
*f
,
5411 Lisp_Object parms
, Lisp_Object dx
, Lisp_Object dy
,
5412 int width
, int height
, int *root_x
, int *root_y
)
5414 Lisp_Object left
, top
;
5415 int min_x
, min_y
, max_x
, max_y
;
5417 /* User-specified position? */
5418 left
= Fcdr (Fassq (Qleft
, parms
));
5419 top
= Fcdr (Fassq (Qtop
, parms
));
5421 /* Move the tooltip window where the mouse pointer is. Resize and
5423 if (!INTEGERP (left
) || !INTEGERP (top
))
5427 /* Default min and max values. */
5430 max_x
= x_display_pixel_width (FRAME_W32_DISPLAY_INFO (f
));
5431 max_y
= x_display_pixel_height (FRAME_W32_DISPLAY_INFO (f
));
5439 /* If multiple monitor support is available, constrain the tip onto
5440 the current monitor. This improves the above by allowing negative
5441 co-ordinates if monitor positions are such that they are valid, and
5442 snaps a tooltip onto a single monitor if we are close to the edge
5443 where it would otherwise flow onto the other monitor (or into
5444 nothingness if there is a gap in the overlap). */
5445 if (monitor_from_point_fn
&& get_monitor_info_fn
)
5447 struct MONITOR_INFO info
;
5449 = monitor_from_point_fn (pt
, MONITOR_DEFAULT_TO_NEAREST
);
5450 info
.cbSize
= sizeof (info
);
5452 if (get_monitor_info_fn (monitor
, &info
))
5454 min_x
= info
.rcWork
.left
;
5455 min_y
= info
.rcWork
.top
;
5456 max_x
= info
.rcWork
.right
;
5457 max_y
= info
.rcWork
.bottom
;
5463 *root_y
= XINT (top
);
5464 else if (*root_y
+ XINT (dy
) <= min_y
)
5465 *root_y
= min_y
; /* Can happen for negative dy */
5466 else if (*root_y
+ XINT (dy
) + height
<= max_y
)
5467 /* It fits below the pointer */
5468 *root_y
+= XINT (dy
);
5469 else if (height
+ XINT (dy
) + min_y
<= *root_y
)
5470 /* It fits above the pointer. */
5471 *root_y
-= height
+ XINT (dy
);
5473 /* Put it on the top. */
5476 if (INTEGERP (left
))
5477 *root_x
= XINT (left
);
5478 else if (*root_x
+ XINT (dx
) <= min_x
)
5479 *root_x
= 0; /* Can happen for negative dx */
5480 else if (*root_x
+ XINT (dx
) + width
<= max_x
)
5481 /* It fits to the right of the pointer. */
5482 *root_x
+= XINT (dx
);
5483 else if (width
+ XINT (dx
) + min_x
<= *root_x
)
5484 /* It fits to the left of the pointer. */
5485 *root_x
-= width
+ XINT (dx
);
5487 /* Put it left justified on the screen -- it ought to fit that way. */
5492 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
5493 doc
: /* Show STRING in a \"tooltip\" window on frame FRAME.
5494 A tooltip window is a small window displaying a string.
5496 This is an internal function; Lisp code should call `tooltip-show'.
5498 FRAME nil or omitted means use the selected frame.
5500 PARMS is an optional list of frame parameters which can be
5501 used to change the tooltip's appearance.
5503 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
5504 means use the default timeout of 5 seconds.
5506 If the list of frame parameters PARMS contains a `left' parameter,
5507 the tooltip is displayed at that x-position. Otherwise it is
5508 displayed at the mouse position, with offset DX added (default is 5 if
5509 DX isn't specified). Likewise for the y-position; if a `top' frame
5510 parameter is specified, it determines the y-position of the tooltip
5511 window, otherwise it is displayed at the mouse position, with offset
5512 DY added (default is -10).
5514 A tooltip's maximum size is specified by `x-max-tooltip-size'.
5515 Text larger than the specified size is clipped. */)
5516 (Lisp_Object string
, Lisp_Object frame
, Lisp_Object parms
, Lisp_Object timeout
, Lisp_Object dx
, Lisp_Object dy
)
5521 struct buffer
*old_buffer
;
5522 struct text_pos pos
;
5523 int i
, width
, height
, seen_reversed_p
;
5524 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5525 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5526 int count
= SPECPDL_INDEX ();
5528 specbind (Qinhibit_redisplay
, Qt
);
5530 GCPRO4 (string
, parms
, frame
, timeout
);
5532 CHECK_STRING (string
);
5533 f
= check_x_frame (frame
);
5535 timeout
= make_number (5);
5537 CHECK_NATNUM (timeout
);
5540 dx
= make_number (5);
5545 dy
= make_number (-10);
5549 if (NILP (last_show_tip_args
))
5550 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
5552 if (!NILP (tip_frame
))
5554 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
5555 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
5556 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
5558 if (EQ (frame
, last_frame
)
5559 && !NILP (Fequal (last_string
, string
))
5560 && !NILP (Fequal (last_parms
, parms
)))
5562 struct frame
*f
= XFRAME (tip_frame
);
5564 /* Only DX and DY have changed. */
5565 if (!NILP (tip_timer
))
5567 Lisp_Object timer
= tip_timer
;
5569 call1 (Qcancel_timer
, timer
);
5573 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
5574 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
5576 /* Put tooltip in topmost group and in position. */
5577 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
5578 root_x
, root_y
, 0, 0,
5579 SWP_NOSIZE
| SWP_NOACTIVATE
);
5581 /* Ensure tooltip is on top of other topmost windows (eg menus). */
5582 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
5584 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
5591 /* Hide a previous tip, if any. */
5594 ASET (last_show_tip_args
, 0, string
);
5595 ASET (last_show_tip_args
, 1, frame
);
5596 ASET (last_show_tip_args
, 2, parms
);
5598 /* Add default values to frame parameters. */
5599 if (NILP (Fassq (Qname
, parms
)))
5600 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
5601 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5602 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
5603 if (NILP (Fassq (Qborder_width
, parms
)))
5604 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
5605 if (NILP (Fassq (Qborder_color
, parms
)))
5606 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
5607 if (NILP (Fassq (Qbackground_color
, parms
)))
5608 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
5611 /* Block input until the tip has been fully drawn, to avoid crashes
5612 when drawing tips in menus. */
5615 /* Create a frame for the tooltip, and record it in the global
5616 variable tip_frame. */
5617 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
, string
);
5620 /* Set up the frame's root window. */
5621 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5622 w
->left_col
= w
->top_line
= make_number (0);
5624 if (CONSP (Vx_max_tooltip_size
)
5625 && INTEGERP (XCAR (Vx_max_tooltip_size
))
5626 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
5627 && INTEGERP (XCDR (Vx_max_tooltip_size
))
5628 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
5630 w
->total_cols
= XCAR (Vx_max_tooltip_size
);
5631 w
->total_lines
= XCDR (Vx_max_tooltip_size
);
5635 w
->total_cols
= make_number (80);
5636 w
->total_lines
= make_number (40);
5639 FRAME_TOTAL_COLS (f
) = XINT (w
->total_cols
);
5641 w
->pseudo_window_p
= 1;
5643 /* Display the tooltip text in a temporary buffer. */
5644 old_buffer
= current_buffer
;
5645 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
5646 BVAR (current_buffer
, truncate_lines
) = Qnil
;
5647 clear_glyph_matrix (w
->desired_matrix
);
5648 clear_glyph_matrix (w
->current_matrix
);
5649 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
5650 try_window (FRAME_ROOT_WINDOW (f
), pos
, TRY_WINDOW_IGNORE_FONTS_CHANGE
);
5652 /* Compute width and height of the tooltip. */
5653 width
= height
= seen_reversed_p
= 0;
5654 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5656 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5660 /* Stop at the first empty row at the end. */
5661 if (!row
->enabled_p
|| !row
->displays_text_p
)
5664 /* Let the row go over the full width of the frame. */
5665 row
->full_width_p
= 1;
5667 row_width
= row
->pixel_width
;
5668 if (row
->used
[TEXT_AREA
])
5670 if (!row
->reversed_p
)
5672 /* There's a glyph at the end of rows that is used to
5673 place the cursor there. Don't include the width of
5675 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5676 if (INTEGERP (last
->object
))
5677 row_width
-= last
->pixel_width
;
5681 /* There could be a stretch glyph at the beginning of R2L
5682 rows that is produced by extend_face_to_end_of_line.
5683 Don't count that glyph. */
5684 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
5686 if (g
->type
== STRETCH_GLYPH
&& INTEGERP (g
->object
))
5688 row_width
-= g
->pixel_width
;
5689 seen_reversed_p
= 1;
5694 height
+= row
->height
;
5695 width
= max (width
, row_width
);
5698 /* If we've seen partial-length R2L rows, we need to re-adjust the
5699 tool-tip frame width and redisplay it again, to avoid over-wide
5700 tips due to the stretch glyph that extends R2L lines to full
5701 width of the frame. */
5702 if (seen_reversed_p
)
5704 /* w->total_cols and FRAME_TOTAL_COLS want the width in columns,
5706 width
/= WINDOW_FRAME_COLUMN_WIDTH (w
);
5707 w
->total_cols
= make_number (width
);
5708 FRAME_TOTAL_COLS (f
) = width
;
5710 w
->pseudo_window_p
= 1;
5711 clear_glyph_matrix (w
->desired_matrix
);
5712 clear_glyph_matrix (w
->current_matrix
);
5713 try_window (FRAME_ROOT_WINDOW (f
), pos
, TRY_WINDOW_IGNORE_FONTS_CHANGE
);
5715 /* Recompute width and height of the tooltip. */
5716 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5718 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5722 if (!row
->enabled_p
|| !row
->displays_text_p
)
5724 row
->full_width_p
= 1;
5725 row_width
= row
->pixel_width
;
5726 if (row
->used
[TEXT_AREA
] && !row
->reversed_p
)
5728 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5729 if (INTEGERP (last
->object
))
5730 row_width
-= last
->pixel_width
;
5733 height
+= row
->height
;
5734 width
= max (width
, row_width
);
5738 /* Round up the height to an integral multiple of FRAME_LINE_HEIGHT. */
5739 if (height
% FRAME_LINE_HEIGHT (f
) != 0)
5740 height
+= FRAME_LINE_HEIGHT (f
) - height
% FRAME_LINE_HEIGHT (f
);
5741 /* Add the frame's internal border to the width and height the w32
5742 window should have. */
5743 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5744 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5746 /* Move the tooltip window where the mouse pointer is. Resize and
5748 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
5751 /* Adjust Window size to take border into account. */
5753 rect
.left
= rect
.top
= 0;
5755 rect
.bottom
= height
;
5756 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
5757 FRAME_EXTERNAL_MENU_BAR (f
));
5759 /* Position and size tooltip, and put it in the topmost group.
5760 The add-on of FRAME_COLUMN_WIDTH to the 5th argument is a
5761 peculiarity of w32 display: without it, some fonts cause the
5762 last character of the tip to be truncated or wrapped around to
5764 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
5766 rect
.right
- rect
.left
+ FRAME_COLUMN_WIDTH (f
),
5767 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
);
5769 /* Ensure tooltip is on top of other topmost windows (eg menus). */
5770 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
5772 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
5774 /* Let redisplay know that we have made the frame visible already. */
5775 f
->async_visible
= 1;
5777 ShowWindow (FRAME_W32_WINDOW (f
), SW_SHOWNOACTIVATE
);
5780 /* Draw into the window. */
5781 w
->must_be_updated_p
= 1;
5782 update_single_window (w
, 1);
5786 /* Restore original current buffer. */
5787 set_buffer_internal_1 (old_buffer
);
5788 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5791 /* Let the tip disappear after timeout seconds. */
5792 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
5793 intern ("x-hide-tip"));
5796 return unbind_to (count
, Qnil
);
5800 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
5801 doc
: /* Hide the current tooltip window, if there is any.
5802 Value is t if tooltip was open, nil otherwise. */)
5806 Lisp_Object deleted
, frame
, timer
;
5807 struct gcpro gcpro1
, gcpro2
;
5809 /* Return quickly if nothing to do. */
5810 if (NILP (tip_timer
) && NILP (tip_frame
))
5815 GCPRO2 (frame
, timer
);
5816 tip_frame
= tip_timer
= deleted
= Qnil
;
5818 count
= SPECPDL_INDEX ();
5819 specbind (Qinhibit_redisplay
, Qt
);
5820 specbind (Qinhibit_quit
, Qt
);
5823 call1 (Qcancel_timer
, timer
);
5827 delete_frame (frame
, Qnil
);
5832 return unbind_to (count
, deleted
);
5837 /***********************************************************************
5838 File selection dialog
5839 ***********************************************************************/
5841 /* Callback for altering the behavior of the Open File dialog.
5842 Makes the Filename text field contain "Current Directory" and be
5843 read-only when "Directories" is selected in the filter. This
5844 allows us to work around the fact that the standard Open File
5845 dialog does not support directories. */
5846 static UINT CALLBACK
5847 file_dialog_callback (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
5849 if (msg
== WM_NOTIFY
)
5851 OFNOTIFY
* notify
= (OFNOTIFY
*)lParam
;
5852 /* Detect when the Filter dropdown is changed. */
5853 if (notify
->hdr
.code
== CDN_TYPECHANGE
5854 || notify
->hdr
.code
== CDN_INITDONE
)
5856 HWND dialog
= GetParent (hwnd
);
5857 HWND edit_control
= GetDlgItem (dialog
, FILE_NAME_TEXT_FIELD
);
5858 HWND list
= GetDlgItem (dialog
, FILE_NAME_LIST
);
5860 /* At least on Windows 7, the above attempt to get the window handle
5861 to the File Name Text Field fails. The following code does the
5862 job though. Note that this code is based on my examination of the
5863 window hierarchy using Microsoft Spy++. bk */
5864 if (edit_control
== NULL
)
5866 HWND tmp
= GetDlgItem (dialog
, FILE_NAME_COMBO_BOX
);
5869 tmp
= GetWindow (tmp
, GW_CHILD
);
5871 edit_control
= GetWindow (tmp
, GW_CHILD
);
5875 /* Directories is in index 2. */
5876 if (notify
->lpOFN
->nFilterIndex
== 2)
5878 CommDlg_OpenSave_SetControlText (dialog
, FILE_NAME_TEXT_FIELD
,
5879 "Current Directory");
5880 EnableWindow (edit_control
, FALSE
);
5881 /* Note that at least on Windows 7, the above call to EnableWindow
5882 disables the window that would ordinarily have focus. If we
5883 do not set focus to some other window here, focus will land in
5884 no man's land and the user will be unable to tab through the
5885 dialog box (pressing tab will only result in a beep).
5886 Avoid that problem by setting focus to the list here. */
5887 if (notify
->hdr
.code
== CDN_INITDONE
)
5892 /* Don't override default filename on init done. */
5893 if (notify
->hdr
.code
== CDN_TYPECHANGE
)
5894 CommDlg_OpenSave_SetControlText (dialog
,
5895 FILE_NAME_TEXT_FIELD
, "");
5896 EnableWindow (edit_control
, TRUE
);
5903 /* Since we compile with _WIN32_WINNT set to 0x0400 (for NT4 compatibility)
5904 we end up with the old file dialogs. Define a big enough struct for the
5905 new dialog to trick GetOpenFileName into giving us the new dialogs on
5906 Windows 2000 and XP. */
5909 OPENFILENAME real_details
;
5916 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
5917 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5918 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5919 selection box, if specified. If MUSTMATCH is non-nil, the returned file
5920 or directory must exist.
5922 This function is only defined on MS Windows, and X Windows with the
5923 Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
5924 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
5925 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
, Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
5927 struct frame
*f
= SELECTED_FRAME ();
5928 Lisp_Object file
= Qnil
;
5929 int count
= SPECPDL_INDEX ();
5930 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
5931 char filename
[MAX_PATH
+ 1];
5932 char init_dir
[MAX_PATH
+ 1];
5933 int default_filter_index
= 1; /* 1: All Files, 2: Directories only */
5935 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
5936 CHECK_STRING (prompt
);
5939 /* Create the dialog with PROMPT as title, using DIR as initial
5940 directory and using "*" as pattern. */
5941 dir
= Fexpand_file_name (dir
, Qnil
);
5942 strncpy (init_dir
, SDATA (ENCODE_FILE (dir
)), MAX_PATH
);
5943 init_dir
[MAX_PATH
] = '\0';
5944 unixtodos_filename (init_dir
);
5946 if (STRINGP (default_filename
))
5948 char *file_name_only
;
5949 char *full_path_name
= SDATA (ENCODE_FILE (default_filename
));
5951 unixtodos_filename (full_path_name
);
5953 file_name_only
= strrchr (full_path_name
, '\\');
5954 if (!file_name_only
)
5955 file_name_only
= full_path_name
;
5959 strncpy (filename
, file_name_only
, MAX_PATH
);
5960 filename
[MAX_PATH
] = '\0';
5965 /* The code in file_dialog_callback that attempts to set the text
5966 of the file name edit window when handling the CDN_INITDONE
5967 WM_NOTIFY message does not work. Setting filename to "Current
5968 Directory" in the only_dir_p case here does work however. */
5969 if (filename
[0] == 0 && ! NILP (only_dir_p
))
5970 strcpy (filename
, "Current Directory");
5973 NEWOPENFILENAME new_file_details
;
5974 BOOL file_opened
= FALSE
;
5975 OPENFILENAME
* file_details
= &new_file_details
.real_details
;
5977 /* Prevent redisplay. */
5978 specbind (Qinhibit_redisplay
, Qt
);
5981 memset (&new_file_details
, 0, sizeof (new_file_details
));
5982 /* Apparently NT4 crashes if you give it an unexpected size.
5983 I'm not sure about Windows 9x, so play it safe. */
5984 if (w32_major_version
> 4 && w32_major_version
< 95)
5985 file_details
->lStructSize
= sizeof (NEWOPENFILENAME
);
5987 file_details
->lStructSize
= sizeof (OPENFILENAME
);
5989 file_details
->hwndOwner
= FRAME_W32_WINDOW (f
);
5990 /* Undocumented Bug in Common File Dialog:
5991 If a filter is not specified, shell links are not resolved. */
5992 file_details
->lpstrFilter
= "All Files (*.*)\0*.*\0Directories\0*|*\0\0";
5993 file_details
->lpstrFile
= filename
;
5994 file_details
->nMaxFile
= sizeof (filename
);
5995 file_details
->lpstrInitialDir
= init_dir
;
5996 file_details
->lpstrTitle
= SDATA (prompt
);
5998 if (! NILP (only_dir_p
))
5999 default_filter_index
= 2;
6001 file_details
->nFilterIndex
= default_filter_index
;
6003 file_details
->Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
6004 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
6005 if (!NILP (mustmatch
))
6007 /* Require that the path to the parent directory exists. */
6008 file_details
->Flags
|= OFN_PATHMUSTEXIST
;
6009 /* If we are looking for a file, require that it exists. */
6010 if (NILP (only_dir_p
))
6011 file_details
->Flags
|= OFN_FILEMUSTEXIST
;
6014 file_details
->lpfnHook
= (LPOFNHOOKPROC
) file_dialog_callback
;
6016 file_opened
= GetOpenFileName (file_details
);
6022 dostounix_filename (filename
);
6024 if (file_details
->nFilterIndex
== 2)
6026 /* "Directories" selected - strip dummy file name. */
6027 char * last
= strrchr (filename
, '/');
6031 file
= DECODE_FILE (build_string (filename
));
6033 /* User cancelled the dialog without making a selection. */
6034 else if (!CommDlgExtendedError ())
6036 /* An error occurred, fallback on reading from the mini-buffer. */
6038 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
6039 dir
, mustmatch
, dir
, Qfile_name_history
,
6040 default_filename
, Qnil
);
6042 file
= unbind_to (count
, file
);
6047 /* Make "Cancel" equivalent to C-g. */
6049 Fsignal (Qquit
, Qnil
);
6051 return unbind_to (count
, file
);
6055 /* Moving files to the system recycle bin.
6056 Used by `move-file-to-trash' instead of the default moving to ~/.Trash */
6057 DEFUN ("system-move-file-to-trash", Fsystem_move_file_to_trash
,
6058 Ssystem_move_file_to_trash
, 1, 1, 0,
6059 doc
: /* Move file or directory named FILENAME to the recycle bin. */)
6060 (Lisp_Object filename
)
6062 Lisp_Object handler
;
6063 Lisp_Object encoded_file
;
6064 Lisp_Object operation
;
6066 operation
= Qdelete_file
;
6067 if (!NILP (Ffile_directory_p (filename
))
6068 && NILP (Ffile_symlink_p (filename
)))
6070 operation
= intern ("delete-directory");
6071 filename
= Fdirectory_file_name (filename
);
6073 filename
= Fexpand_file_name (filename
, Qnil
);
6075 handler
= Ffind_file_name_handler (filename
, operation
);
6076 if (!NILP (handler
))
6077 return call2 (handler
, operation
, filename
);
6079 encoded_file
= ENCODE_FILE (filename
);
6083 SHFILEOPSTRUCT file_op
;
6084 char tmp_path
[MAX_PATH
+ 1];
6086 path
= map_w32_filename (SDATA (encoded_file
), NULL
);
6088 /* On Windows, write permission is required to delete/move files. */
6089 _chmod (path
, 0666);
6091 memset (tmp_path
, 0, sizeof (tmp_path
));
6092 strcpy (tmp_path
, path
);
6094 memset (&file_op
, 0, sizeof (file_op
));
6095 file_op
.hwnd
= HWND_DESKTOP
;
6096 file_op
.wFunc
= FO_DELETE
;
6097 file_op
.pFrom
= tmp_path
;
6098 file_op
.fFlags
= FOF_SILENT
| FOF_NOCONFIRMATION
| FOF_ALLOWUNDO
6099 | FOF_NOERRORUI
| FOF_NO_CONNECTED_ELEMENTS
;
6100 file_op
.fAnyOperationsAborted
= FALSE
;
6102 if (SHFileOperation (&file_op
) != 0)
6103 report_file_error ("Removing old name", list1 (filename
));
6109 /***********************************************************************
6110 w32 specialized functions
6111 ***********************************************************************/
6113 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
,
6114 Sw32_send_sys_command
, 1, 2, 0,
6115 doc
: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND.
6116 Some useful values for COMMAND are #xf030 to maximize frame (#xf020
6117 to minimize), #xf120 to restore frame to original size, and #xf100
6118 to activate the menubar for keyboard access. #xf140 activates the
6119 screen saver if defined.
6121 If optional parameter FRAME is not specified, use selected frame. */)
6122 (Lisp_Object command
, Lisp_Object frame
)
6124 FRAME_PTR f
= check_x_frame (frame
);
6126 CHECK_NUMBER (command
);
6128 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
6133 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
6134 doc
: /* Get Windows to perform OPERATION on DOCUMENT.
6135 This is a wrapper around the ShellExecute system function, which
6136 invokes the application registered to handle OPERATION for DOCUMENT.
6138 OPERATION is either nil or a string that names a supported operation.
6139 What operations can be used depends on the particular DOCUMENT and its
6140 handler application, but typically it is one of the following common
6143 \"open\" - open DOCUMENT, which could be a file, a directory, or an
6144 executable program. If it is an application, that
6145 application is launched in the current buffer's default
6146 directory. Otherwise, the application associated with
6147 DOCUMENT is launched in the buffer's default directory.
6148 \"print\" - print DOCUMENT, which must be a file
6149 \"explore\" - start the Windows Explorer on DOCUMENT
6150 \"edit\" - launch an editor and open DOCUMENT for editing; which
6151 editor is launched depends on the association for the
6153 \"find\" - initiate search starting from DOCUMENT which must specify
6155 nil - invoke the default OPERATION, or \"open\" if default is
6156 not defined or unavailable
6158 DOCUMENT is typically the name of a document file or a URL, but can
6159 also be a program executable to run, or a directory to open in the
6162 If DOCUMENT is a program executable, the optional third arg PARAMETERS
6163 can be a string containing command line parameters that will be passed
6164 to the program; otherwise, PARAMETERS should be nil or unspecified.
6166 Optional fourth argument SHOW-FLAG can be used to control how the
6167 application will be displayed when it is invoked. If SHOW-FLAG is nil
6168 or unspecified, the application is displayed normally, otherwise it is
6169 an integer representing a ShowWindow flag:
6174 6 - start minimized */)
6175 (Lisp_Object operation
, Lisp_Object document
, Lisp_Object parameters
, Lisp_Object show_flag
)
6177 Lisp_Object current_dir
;
6180 CHECK_STRING (document
);
6182 /* Encode filename, current directory and parameters. */
6183 current_dir
= ENCODE_FILE (BVAR (current_buffer
, directory
));
6184 document
= ENCODE_FILE (document
);
6185 if (STRINGP (parameters
))
6186 parameters
= ENCODE_SYSTEM (parameters
);
6188 if ((int) ShellExecute (NULL
,
6189 (STRINGP (operation
) ?
6190 SDATA (operation
) : NULL
),
6192 (STRINGP (parameters
) ?
6193 SDATA (parameters
) : NULL
),
6194 SDATA (current_dir
),
6195 (INTEGERP (show_flag
) ?
6196 XINT (show_flag
) : SW_SHOWDEFAULT
))
6199 errstr
= w32_strerror (0);
6200 /* The error string might be encoded in the locale's encoding. */
6201 if (!NILP (Vlocale_coding_system
))
6203 Lisp_Object decoded
=
6204 code_convert_string_norecord (make_unibyte_string (errstr
,
6206 Vlocale_coding_system
, 0);
6207 errstr
= SSDATA (decoded
);
6209 error ("ShellExecute failed: %s", errstr
);
6212 /* Lookup virtual keycode from string representing the name of a
6213 non-ascii keystroke into the corresponding virtual key, using
6214 lispy_function_keys. */
6216 lookup_vk_code (char *key
)
6220 for (i
= 0; i
< 256; i
++)
6221 if (lispy_function_keys
[i
]
6222 && strcmp (lispy_function_keys
[i
], key
) == 0)
6228 /* Convert a one-element vector style key sequence to a hot key
6231 w32_parse_hot_key (Lisp_Object key
)
6233 /* Copied from Fdefine_key and store_in_keymap. */
6234 register Lisp_Object c
;
6238 struct gcpro gcpro1
;
6242 if (XFASTINT (Flength (key
)) != 1)
6247 c
= Faref (key
, make_number (0));
6249 if (CONSP (c
) && lucid_event_type_list_p (c
))
6250 c
= Fevent_convert_list (c
);
6254 if (! INTEGERP (c
) && ! SYMBOLP (c
))
6255 error ("Key definition is invalid");
6257 /* Work out the base key and the modifiers. */
6260 c
= parse_modifiers (c
);
6261 lisp_modifiers
= XINT (Fcar (Fcdr (c
)));
6265 vk_code
= lookup_vk_code (SDATA (SYMBOL_NAME (c
)));
6267 else if (INTEGERP (c
))
6269 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
6270 /* Many ascii characters are their own virtual key code. */
6271 vk_code
= XINT (c
) & CHARACTERBITS
;
6274 if (vk_code
< 0 || vk_code
> 255)
6277 if ((lisp_modifiers
& meta_modifier
) != 0
6278 && !NILP (Vw32_alt_is_meta
))
6279 lisp_modifiers
|= alt_modifier
;
6281 /* Supply defs missing from mingw32. */
6283 #define MOD_ALT 0x0001
6284 #define MOD_CONTROL 0x0002
6285 #define MOD_SHIFT 0x0004
6286 #define MOD_WIN 0x0008
6289 /* Convert lisp modifiers to Windows hot-key form. */
6290 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
6291 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
6292 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
6293 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
6295 return HOTKEY (vk_code
, w32_modifiers
);
6298 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
,
6299 Sw32_register_hot_key
, 1, 1, 0,
6300 doc
: /* Register KEY as a hot-key combination.
6301 Certain key combinations like Alt-Tab are reserved for system use on
6302 Windows, and therefore are normally intercepted by the system. However,
6303 most of these key combinations can be received by registering them as
6304 hot-keys, overriding their special meaning.
6306 KEY must be a one element key definition in vector form that would be
6307 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta
6308 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper
6309 is always interpreted as the Windows modifier keys.
6311 The return value is the hotkey-id if registered, otherwise nil. */)
6314 key
= w32_parse_hot_key (key
);
6316 if (!NILP (key
) && NILP (Fmemq (key
, w32_grabbed_keys
)))
6318 /* Reuse an empty slot if possible. */
6319 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
6321 /* Safe to add new key to list, even if we have focus. */
6323 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
6325 XSETCAR (item
, key
);
6327 /* Notify input thread about new hot-key definition, so that it
6328 takes effect without needing to switch focus. */
6329 #ifdef USE_LISP_UNION_TYPE
6330 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
6333 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
6341 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
,
6342 Sw32_unregister_hot_key
, 1, 1, 0,
6343 doc
: /* Unregister KEY as a hot-key combination. */)
6348 if (!INTEGERP (key
))
6349 key
= w32_parse_hot_key (key
);
6351 item
= Fmemq (key
, w32_grabbed_keys
);
6355 /* Notify input thread about hot-key definition being removed, so
6356 that it takes effect without needing focus switch. */
6357 #ifdef USE_LISP_UNION_TYPE
6358 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
6359 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
.i
))
6361 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
6362 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
))
6366 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
6373 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
,
6374 Sw32_registered_hot_keys
, 0, 0, 0,
6375 doc
: /* Return list of registered hot-key IDs. */)
6378 return Fdelq (Qnil
, Fcopy_sequence (w32_grabbed_keys
));
6381 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
,
6382 Sw32_reconstruct_hot_key
, 1, 1, 0,
6383 doc
: /* Convert hot-key ID to a lisp key combination.
6384 usage: (w32-reconstruct-hot-key ID) */)
6385 (Lisp_Object hotkeyid
)
6387 int vk_code
, w32_modifiers
;
6390 CHECK_NUMBER (hotkeyid
);
6392 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
6393 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
6395 if (vk_code
< 256 && lispy_function_keys
[vk_code
])
6396 key
= intern (lispy_function_keys
[vk_code
]);
6398 key
= make_number (vk_code
);
6400 key
= Fcons (key
, Qnil
);
6401 if (w32_modifiers
& MOD_SHIFT
)
6402 key
= Fcons (Qshift
, key
);
6403 if (w32_modifiers
& MOD_CONTROL
)
6404 key
= Fcons (Qctrl
, key
);
6405 if (w32_modifiers
& MOD_ALT
)
6406 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
6407 if (w32_modifiers
& MOD_WIN
)
6408 key
= Fcons (Qhyper
, key
);
6413 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
,
6414 Sw32_toggle_lock_key
, 1, 2, 0,
6415 doc
: /* Toggle the state of the lock key KEY.
6416 KEY can be `capslock', `kp-numlock', or `scroll'.
6417 If the optional parameter NEW-STATE is a number, then the state of KEY
6418 is set to off if the low bit of NEW-STATE is zero, otherwise on. */)
6419 (Lisp_Object key
, Lisp_Object new_state
)
6423 if (EQ (key
, intern ("capslock")))
6424 vk_code
= VK_CAPITAL
;
6425 else if (EQ (key
, intern ("kp-numlock")))
6426 vk_code
= VK_NUMLOCK
;
6427 else if (EQ (key
, intern ("scroll")))
6428 vk_code
= VK_SCROLL
;
6432 if (!dwWindowsThreadId
)
6433 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
6435 #ifdef USE_LISP_UNION_TYPE
6436 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
6437 (WPARAM
) vk_code
, (LPARAM
) new_state
.i
))
6439 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
6440 (WPARAM
) vk_code
, (LPARAM
) new_state
))
6444 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
6445 return make_number (msg
.wParam
);
6450 DEFUN ("w32-window-exists-p", Fw32_window_exists_p
, Sw32_window_exists_p
,
6452 doc
: /* Return non-nil if a window exists with the specified CLASS and NAME.
6454 This is a direct interface to the Windows API FindWindow function. */)
6455 (Lisp_Object
class, Lisp_Object name
)
6460 CHECK_STRING (class);
6462 CHECK_STRING (name
);
6464 hnd
= FindWindow (STRINGP (class) ? ((LPCTSTR
) SDATA (class)) : NULL
,
6465 STRINGP (name
) ? ((LPCTSTR
) SDATA (name
)) : NULL
);
6471 DEFUN ("w32-battery-status", Fw32_battery_status
, Sw32_battery_status
, 0, 0, 0,
6472 doc
: /* Get power status information from Windows system.
6474 The following %-sequences are provided:
6475 %L AC line status (verbose)
6476 %B Battery status (verbose)
6477 %b Battery status, empty means high, `-' means low,
6478 `!' means critical, and `+' means charging
6479 %p Battery load percentage
6480 %s Remaining time (to charge or discharge) in seconds
6481 %m Remaining time (to charge or discharge) in minutes
6482 %h Remaining time (to charge or discharge) in hours
6483 %t Remaining time (to charge or discharge) in the form `h:min' */)
6486 Lisp_Object status
= Qnil
;
6488 SYSTEM_POWER_STATUS system_status
;
6489 if (GetSystemPowerStatus (&system_status
))
6491 Lisp_Object line_status
, battery_status
, battery_status_symbol
;
6492 Lisp_Object load_percentage
, seconds
, minutes
, hours
, remain
;
6493 Lisp_Object sequences
[8];
6495 long seconds_left
= (long) system_status
.BatteryLifeTime
;
6497 if (system_status
.ACLineStatus
== 0)
6498 line_status
= build_string ("off-line");
6499 else if (system_status
.ACLineStatus
== 1)
6500 line_status
= build_string ("on-line");
6502 line_status
= build_string ("N/A");
6504 if (system_status
.BatteryFlag
& 128)
6506 battery_status
= build_string ("N/A");
6507 battery_status_symbol
= empty_unibyte_string
;
6509 else if (system_status
.BatteryFlag
& 8)
6511 battery_status
= build_string ("charging");
6512 battery_status_symbol
= build_string ("+");
6513 if (system_status
.BatteryFullLifeTime
!= -1L)
6514 seconds_left
= system_status
.BatteryFullLifeTime
- seconds_left
;
6516 else if (system_status
.BatteryFlag
& 4)
6518 battery_status
= build_string ("critical");
6519 battery_status_symbol
= build_string ("!");
6521 else if (system_status
.BatteryFlag
& 2)
6523 battery_status
= build_string ("low");
6524 battery_status_symbol
= build_string ("-");
6526 else if (system_status
.BatteryFlag
& 1)
6528 battery_status
= build_string ("high");
6529 battery_status_symbol
= empty_unibyte_string
;
6533 battery_status
= build_string ("medium");
6534 battery_status_symbol
= empty_unibyte_string
;
6537 if (system_status
.BatteryLifePercent
> 100)
6538 load_percentage
= build_string ("N/A");
6542 _snprintf (buffer
, 16, "%d", system_status
.BatteryLifePercent
);
6543 load_percentage
= build_string (buffer
);
6546 if (seconds_left
< 0)
6547 seconds
= minutes
= hours
= remain
= build_string ("N/A");
6553 _snprintf (buffer
, 16, "%ld", seconds_left
);
6554 seconds
= build_string (buffer
);
6556 m
= seconds_left
/ 60;
6557 _snprintf (buffer
, 16, "%ld", m
);
6558 minutes
= build_string (buffer
);
6560 h
= seconds_left
/ 3600.0;
6561 _snprintf (buffer
, 16, "%3.1f", h
);
6562 hours
= build_string (buffer
);
6564 _snprintf (buffer
, 16, "%ld:%02ld", m
/ 60, m
% 60);
6565 remain
= build_string (buffer
);
6567 sequences
[0] = Fcons (make_number ('L'), line_status
);
6568 sequences
[1] = Fcons (make_number ('B'), battery_status
);
6569 sequences
[2] = Fcons (make_number ('b'), battery_status_symbol
);
6570 sequences
[3] = Fcons (make_number ('p'), load_percentage
);
6571 sequences
[4] = Fcons (make_number ('s'), seconds
);
6572 sequences
[5] = Fcons (make_number ('m'), minutes
);
6573 sequences
[6] = Fcons (make_number ('h'), hours
);
6574 sequences
[7] = Fcons (make_number ('t'), remain
);
6576 status
= Flist (8, sequences
);
6582 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
6583 doc
: /* Return storage information about the file system FILENAME is on.
6584 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
6585 storage of the file system, FREE is the free storage, and AVAIL is the
6586 storage available to a non-superuser. All 3 numbers are in bytes.
6587 If the underlying system call fails, value is nil. */)
6588 (Lisp_Object filename
)
6590 Lisp_Object encoded
, value
;
6592 CHECK_STRING (filename
);
6593 filename
= Fexpand_file_name (filename
, Qnil
);
6594 encoded
= ENCODE_FILE (filename
);
6598 /* Determining the required information on Windows turns out, sadly,
6599 to be more involved than one would hope. The original Win32 api
6600 call for this will return bogus information on some systems, but we
6601 must dynamically probe for the replacement api, since that was
6602 added rather late on. */
6604 HMODULE hKernel
= GetModuleHandle ("kernel32");
6605 BOOL (*pfn_GetDiskFreeSpaceEx
)
6606 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
6607 = (void *) GetProcAddress (hKernel
, "GetDiskFreeSpaceEx");
6609 /* On Windows, we may need to specify the root directory of the
6610 volume holding FILENAME. */
6611 char rootname
[MAX_PATH
];
6612 char *name
= SDATA (encoded
);
6614 /* find the root name of the volume if given */
6615 if (isalpha (name
[0]) && name
[1] == ':')
6617 rootname
[0] = name
[0];
6618 rootname
[1] = name
[1];
6622 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
6624 char *str
= rootname
;
6628 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
6638 if (pfn_GetDiskFreeSpaceEx
)
6640 /* Unsigned large integers cannot be cast to double, so
6641 use signed ones instead. */
6642 LARGE_INTEGER availbytes
;
6643 LARGE_INTEGER freebytes
;
6644 LARGE_INTEGER totalbytes
;
6646 if (pfn_GetDiskFreeSpaceEx (rootname
,
6647 (ULARGE_INTEGER
*)&availbytes
,
6648 (ULARGE_INTEGER
*)&totalbytes
,
6649 (ULARGE_INTEGER
*)&freebytes
))
6650 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
6651 make_float ((double) freebytes
.QuadPart
),
6652 make_float ((double) availbytes
.QuadPart
));
6656 DWORD sectors_per_cluster
;
6657 DWORD bytes_per_sector
;
6658 DWORD free_clusters
;
6659 DWORD total_clusters
;
6661 if (GetDiskFreeSpace (rootname
,
6662 §ors_per_cluster
,
6666 value
= list3 (make_float ((double) total_clusters
6667 * sectors_per_cluster
* bytes_per_sector
),
6668 make_float ((double) free_clusters
6669 * sectors_per_cluster
* bytes_per_sector
),
6670 make_float ((double) free_clusters
6671 * sectors_per_cluster
* bytes_per_sector
));
6678 DEFUN ("default-printer-name", Fdefault_printer_name
, Sdefault_printer_name
,
6679 0, 0, 0, doc
: /* Return the name of Windows default printer device. */)
6682 static char pname_buf
[256];
6685 PRINTER_INFO_2
*ppi2
= NULL
;
6686 DWORD dwNeeded
= 0, dwReturned
= 0;
6688 /* Retrieve the default string from Win.ini (the registry).
6689 * String will be in form "printername,drivername,portname".
6690 * This is the most portable way to get the default printer. */
6691 if (GetProfileString ("windows", "device", ",,", pname_buf
, sizeof (pname_buf
)) <= 0)
6693 /* printername precedes first "," character */
6694 strtok (pname_buf
, ",");
6695 /* We want to know more than the printer name */
6696 if (!OpenPrinter (pname_buf
, &hPrn
, NULL
))
6698 GetPrinter (hPrn
, 2, NULL
, 0, &dwNeeded
);
6701 ClosePrinter (hPrn
);
6704 /* Allocate memory for the PRINTER_INFO_2 struct */
6705 ppi2
= (PRINTER_INFO_2
*) xmalloc (dwNeeded
);
6708 ClosePrinter (hPrn
);
6711 /* Call GetPrinter again with big enouth memory block */
6712 err
= GetPrinter (hPrn
, 2, (LPBYTE
)ppi2
, dwNeeded
, &dwReturned
);
6713 ClosePrinter (hPrn
);
6722 if (ppi2
->Attributes
& PRINTER_ATTRIBUTE_SHARED
&& ppi2
->pServerName
)
6724 /* a remote printer */
6725 if (*ppi2
->pServerName
== '\\')
6726 _snprintf (pname_buf
, sizeof (pname_buf
), "%s\\%s", ppi2
->pServerName
,
6729 _snprintf (pname_buf
, sizeof (pname_buf
), "\\\\%s\\%s", ppi2
->pServerName
,
6731 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
6735 /* a local printer */
6736 strncpy (pname_buf
, ppi2
->pPortName
, sizeof (pname_buf
));
6737 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
6738 /* `pPortName' can include several ports, delimited by ','.
6739 * we only use the first one. */
6740 strtok (pname_buf
, ",");
6745 return build_string (pname_buf
);
6748 /***********************************************************************
6750 ***********************************************************************/
6752 /* Keep this list in the same order as frame_parms in frame.c.
6753 Use 0 for unsupported frame parameters. */
6755 frame_parm_handler w32_frame_parm_handlers
[] =
6759 x_set_background_color
,
6765 x_set_foreground_color
,
6768 x_set_internal_border_width
,
6769 x_set_menu_bar_lines
,
6771 x_explicitly_set_name
,
6772 x_set_scroll_bar_width
,
6775 x_set_vertical_scroll_bars
,
6777 x_set_tool_bar_lines
,
6778 0, /* x_set_scroll_bar_foreground, */
6779 0, /* x_set_scroll_bar_background, */
6784 0, /* x_set_wait_for_wm, */
6788 0, /* x_set_sticky */
6789 0, /* x_set_tool_bar_position */
6793 syms_of_w32fns (void)
6795 globals_of_w32fns ();
6796 /* This is zero if not using MS-Windows. */
6798 track_mouse_window
= NULL
;
6800 w32_visible_system_caret_hwnd
= NULL
;
6802 DEFSYM (Qnone
, "none");
6803 DEFSYM (Qsuppress_icon
, "suppress-icon");
6804 DEFSYM (Qundefined_color
, "undefined-color");
6805 DEFSYM (Qcancel_timer
, "cancel-timer");
6806 DEFSYM (Qhyper
, "hyper");
6807 DEFSYM (Qsuper
, "super");
6808 DEFSYM (Qmeta
, "meta");
6809 DEFSYM (Qalt
, "alt");
6810 DEFSYM (Qctrl
, "ctrl");
6811 DEFSYM (Qcontrol
, "control");
6812 DEFSYM (Qshift
, "shift");
6813 DEFSYM (Qfont_param
, "font-parameter");
6814 /* This is the end of symbol initialization. */
6816 /* Text property `display' should be nonsticky by default. */
6817 Vtext_property_default_nonsticky
6818 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
6821 Fput (Qundefined_color
, Qerror_conditions
,
6822 pure_cons (Qundefined_color
, pure_cons (Qerror
, Qnil
)));
6823 Fput (Qundefined_color
, Qerror_message
,
6824 make_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
;
7123 hourglass_timer
= 0;
7124 hourglass_hwnd
= NULL
;
7126 defsubr (&Sx_show_tip
);
7127 defsubr (&Sx_hide_tip
);
7129 staticpro (&tip_timer
);
7131 staticpro (&tip_frame
);
7133 last_show_tip_args
= Qnil
;
7134 staticpro (&last_show_tip_args
);
7136 defsubr (&Sx_file_dialog
);
7137 defsubr (&Ssystem_move_file_to_trash
);
7142 globals_of_w32fns is used to initialize those global variables that
7143 must always be initialized on startup even when the global variable
7144 initialized is non zero (see the function main in emacs.c).
7145 globals_of_w32fns is called from syms_of_w32fns when the global
7146 variable initialized is 0 and directly from main when initialized
7150 globals_of_w32fns (void)
7152 HMODULE user32_lib
= GetModuleHandle ("user32.dll");
7154 TrackMouseEvent not available in all versions of Windows, so must load
7155 it dynamically. Do it once, here, instead of every time it is used.
7157 track_mouse_event_fn
= (TrackMouseEvent_Proc
)
7158 GetProcAddress (user32_lib
, "TrackMouseEvent");
7160 monitor_from_point_fn
= (MonitorFromPoint_Proc
)
7161 GetProcAddress (user32_lib
, "MonitorFromPoint");
7162 get_monitor_info_fn
= (GetMonitorInfo_Proc
)
7163 GetProcAddress (user32_lib
, "GetMonitorInfoA");
7166 HMODULE imm32_lib
= GetModuleHandle ("imm32.dll");
7167 get_composition_string_fn
= (ImmGetCompositionString_Proc
)
7168 GetProcAddress (imm32_lib
, "ImmGetCompositionStringW");
7169 get_ime_context_fn
= (ImmGetContext_Proc
)
7170 GetProcAddress (imm32_lib
, "ImmGetContext");
7171 release_ime_context_fn
= (ImmReleaseContext_Proc
)
7172 GetProcAddress (imm32_lib
, "ImmReleaseContext");
7173 set_ime_composition_window_fn
= (ImmSetCompositionWindow_Proc
)
7174 GetProcAddress (imm32_lib
, "ImmSetCompositionWindow");
7176 DEFVAR_INT ("w32-ansi-code-page",
7178 doc
: /* The ANSI code page used by the system. */);
7179 w32_ansi_code_page
= GetACP ();
7181 /* MessageBox does not work without this when linked to comctl32.dll 6.0. */
7182 InitCommonControls ();
7184 syms_of_w32uniscribe ();
7193 button
= MessageBox (NULL
,
7194 "A fatal error has occurred!\n\n"
7195 "Would you like to attach a debugger?\n\n"
7196 "Select YES to debug, NO to abort Emacs"
7198 "\n\n(type \"gdb -p <emacs-PID>\" and\n"
7199 "\"continue\" inside GDB before clicking YES.)"
7201 , "Emacs Abort Dialog",
7202 MB_ICONEXCLAMATION
| MB_TASKMODAL
7203 | MB_SETFOREGROUND
| MB_YESNO
);
7208 exit (2); /* tell the compiler we will never return */
7216 /* For convenience when debugging. */
7218 w32_last_error (void)
7220 return GetLastError ();