1 /* Graphical user interface functions for the Microsoft W32 API.
2 Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 /* Added by Kevin Gallo */
37 #include "intervals.h"
38 #include "dispextern.h"
40 #include "blockinput.h"
42 #include "character.h"
48 #include "termhooks.h"
52 #include "bitmaps/gray.xbm"
63 #define FILE_NAME_TEXT_FIELD edt1
68 #ifndef FOF_NO_CONNECTED_ELEMENTS
69 #define FOF_NO_CONNECTED_ELEMENTS 0x2000
72 void syms_of_w32fns (void);
73 void globals_of_w32fns (void);
75 extern void free_frame_menubar (struct frame
*);
76 extern double atof (const char *);
77 extern int w32_console_toggle_lock_key (int, Lisp_Object
);
78 extern void w32_menu_display_help (HWND
, HMENU
, UINT
, UINT
);
79 extern void w32_free_menu_strings (HWND
);
80 extern const char *map_w32_filename (const char *, const char **);
84 extern char *lispy_function_keys
[];
86 /* The colormap for converting color names to RGB values */
87 Lisp_Object Vw32_color_map
;
89 /* Non nil if alt key presses are passed on to Windows. */
90 Lisp_Object Vw32_pass_alt_to_system
;
92 /* Non nil if alt key is translated to meta_modifier, nil if it is translated
94 Lisp_Object Vw32_alt_is_meta
;
96 /* If non-zero, the windows virtual key code for an alternative quit key. */
99 /* Non nil if left window key events are passed on to Windows (this only
100 affects whether "tapping" the key opens the Start menu). */
101 Lisp_Object Vw32_pass_lwindow_to_system
;
103 /* Non nil if right window key events are passed on to Windows (this
104 only affects whether "tapping" the key opens the Start menu). */
105 Lisp_Object Vw32_pass_rwindow_to_system
;
107 /* Virtual key code used to generate "phantom" key presses in order
108 to stop system from acting on Windows key events. */
109 Lisp_Object Vw32_phantom_key_code
;
111 /* Modifier associated with the left "Windows" key, or nil to act as a
113 Lisp_Object Vw32_lwindow_modifier
;
115 /* Modifier associated with the right "Windows" key, or nil to act as a
117 Lisp_Object Vw32_rwindow_modifier
;
119 /* Modifier associated with the "Apps" key, or nil to act as a normal
121 Lisp_Object Vw32_apps_modifier
;
123 /* Value is nil if Num Lock acts as a function key. */
124 Lisp_Object Vw32_enable_num_lock
;
126 /* Value is nil if Caps Lock acts as a function key. */
127 Lisp_Object Vw32_enable_caps_lock
;
129 /* Modifier associated with Scroll Lock, or nil to act as a normal key. */
130 Lisp_Object Vw32_scroll_lock_modifier
;
132 /* Switch to control whether we inhibit requests for synthesized bold
133 and italic versions of fonts. */
134 int w32_enable_synthesized_fonts
;
136 /* Enable palette management. */
137 Lisp_Object Vw32_enable_palette
;
139 /* Control how close left/right button down events must be to
140 be converted to a middle button down event. */
141 int w32_mouse_button_tolerance
;
143 /* Minimum interval between mouse movement (and scroll bar drag)
144 events that are passed on to the event loop. */
145 int w32_mouse_move_interval
;
147 /* Flag to indicate if XBUTTON events should be passed on to Windows. */
148 static int w32_pass_extra_mouse_buttons_to_system
;
150 /* Flag to indicate if media keys should be passed on to Windows. */
151 static int w32_pass_multimedia_buttons_to_system
;
153 /* Non nil if no window manager is in use. */
154 Lisp_Object Vx_no_window_manager
;
156 /* If non-zero, a w32 timer that, when it expires, displays an
157 hourglass cursor on all frames. */
158 static unsigned hourglass_timer
= 0;
159 static HWND hourglass_hwnd
= NULL
;
161 #if 0 /* TODO: Mouse cursor customization. */
162 /* The background and shape of the mouse pointer, and shape when not
163 over text or in the modeline. */
164 Lisp_Object Vx_pointer_shape
, Vx_nontext_pointer_shape
, Vx_mode_pointer_shape
;
165 Lisp_Object Vx_hourglass_pointer_shape
, Vx_window_horizontal_drag_shape
;
167 /* The shape when over mouse-sensitive text. */
169 Lisp_Object Vx_sensitive_text_pointer_shape
;
173 #define IDC_HAND MAKEINTRESOURCE(32649)
176 /* Color of chars displayed in cursor box. */
177 Lisp_Object Vx_cursor_fore_pixel
;
179 /* Nonzero if using Windows. */
181 static int w32_in_use
;
183 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
185 Lisp_Object Vx_pixel_size_width_font_regexp
;
187 /* Alist of bdf fonts and the files that define them. */
188 Lisp_Object Vw32_bdf_filename_alist
;
190 /* A flag to control whether fonts are matched strictly or not. */
191 static int w32_strict_fontnames
;
193 /* A flag to control whether we should only repaint if GetUpdateRect
194 indicates there is an update region. */
195 static int w32_strict_painting
;
198 Lisp_Object Qsuppress_icon
;
199 Lisp_Object Qundefined_color
;
200 Lisp_Object Qcancel_timer
;
201 Lisp_Object Qfont_param
;
207 Lisp_Object Qcontrol
;
211 /* The ANSI codepage. */
212 int w32_ansi_code_page
;
214 /* Prefix for system colors. */
215 #define SYSTEM_COLOR_PREFIX "System"
216 #define SYSTEM_COLOR_PREFIX_LEN (sizeof (SYSTEM_COLOR_PREFIX) - 1)
218 /* State variables for emulating a three button mouse. */
223 static int button_state
= 0;
224 static W32Msg saved_mouse_button_msg
;
225 static unsigned mouse_button_timer
= 0; /* non-zero when timer is active */
226 static W32Msg saved_mouse_move_msg
;
227 static unsigned mouse_move_timer
= 0;
229 /* Window that is tracking the mouse. */
230 static HWND track_mouse_window
;
232 /* Multi-monitor API definitions that are not pulled from the headers
233 since we are compiling for NT 4. */
234 #ifndef MONITOR_DEFAULT_TO_NEAREST
235 #define MONITOR_DEFAULT_TO_NEAREST 2
237 /* MinGW headers define MONITORINFO unconditionally, but MSVC ones don't.
238 To avoid a compile error on one or the other, redefine with a new name. */
247 /* Reportedly, VS 6 does not have this in its headers. */
248 #if defined(_MSC_VER) && _MSC_VER < 1300
249 DECLARE_HANDLE(HMONITOR
);
252 typedef BOOL (WINAPI
* TrackMouseEvent_Proc
)
253 (IN OUT LPTRACKMOUSEEVENT lpEventTrack
);
254 typedef LONG (WINAPI
* ImmGetCompositionString_Proc
)
255 (IN HIMC context
, IN DWORD index
, OUT LPVOID buffer
, IN DWORD bufLen
);
256 typedef HIMC (WINAPI
* ImmGetContext_Proc
) (IN HWND window
);
257 typedef HWND (WINAPI
* ImmReleaseContext_Proc
) (IN HWND wnd
, IN HIMC context
);
258 typedef HWND (WINAPI
* ImmSetCompositionWindow_Proc
) (IN HIMC context
,
259 IN COMPOSITIONFORM
*form
);
260 typedef HMONITOR (WINAPI
* MonitorFromPoint_Proc
) (IN POINT pt
, IN DWORD flags
);
261 typedef BOOL (WINAPI
* GetMonitorInfo_Proc
)
262 (IN HMONITOR monitor
, OUT
struct MONITOR_INFO
* info
);
264 TrackMouseEvent_Proc track_mouse_event_fn
= NULL
;
265 ClipboardSequence_Proc clipboard_sequence_fn
= NULL
;
266 ImmGetCompositionString_Proc get_composition_string_fn
= NULL
;
267 ImmGetContext_Proc get_ime_context_fn
= NULL
;
268 ImmReleaseContext_Proc release_ime_context_fn
= NULL
;
269 ImmSetCompositionWindow_Proc set_ime_composition_window_fn
= NULL
;
270 MonitorFromPoint_Proc monitor_from_point_fn
= NULL
;
271 GetMonitorInfo_Proc get_monitor_info_fn
= NULL
;
273 extern AppendMenuW_Proc unicode_append_menu
;
275 /* Flag to selectively ignore WM_IME_CHAR messages. */
276 static int ignore_ime_char
= 0;
278 /* W95 mousewheel handler */
279 unsigned int msh_mousewheel
= 0;
282 #define MOUSE_BUTTON_ID 1
283 #define MOUSE_MOVE_ID 2
284 #define MENU_FREE_ID 3
285 #define HOURGLASS_ID 4
286 /* The delay (milliseconds) before a menu is freed after WM_EXITMENULOOP
288 #define MENU_FREE_DELAY 1000
289 static unsigned menu_free_timer
= 0;
293 extern Lisp_Object Vwindow_system_version
;
295 /* The below are defined in frame.c. */
297 extern Lisp_Object Vmenu_bar_mode
, Vtool_bar_mode
;
298 extern Lisp_Object Vwindow_system_version
;
299 extern Lisp_Object Qtooltip
;
302 int image_cache_refcount
, dpyinfo_refcount
;
306 /* From w32term.c. */
307 extern int w32_num_mouse_buttons
;
308 extern Lisp_Object Vw32_recognize_altgr
;
310 extern HWND w32_system_caret_hwnd
;
312 extern int w32_system_caret_height
;
313 extern int w32_system_caret_x
;
314 extern int w32_system_caret_y
;
315 extern int w32_use_visible_system_caret
;
317 static HWND w32_visible_system_caret_hwnd
;
320 extern HMENU current_popup_menu
;
321 static int menubar_in_use
= 0;
323 /* From w32uniscribe.c */
324 extern void syms_of_w32uniscribe (void);
325 extern int uniscribe_available
;
327 /* Function prototypes for hourglass support. */
328 static void w32_show_hourglass (struct frame
*);
329 static void w32_hide_hourglass (void);
333 /* Error if we are not connected to MS-Windows. */
338 error ("MS-Windows not in use or not initialized");
341 /* Nonzero if we can use mouse menus.
342 You should not call this unless HAVE_MENUS is defined. */
350 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
351 and checking validity for W32. */
354 check_x_frame (Lisp_Object frame
)
359 frame
= selected_frame
;
360 CHECK_LIVE_FRAME (frame
);
362 if (! FRAME_W32_P (f
))
363 error ("Non-W32 frame used");
367 /* Let the user specify a display with a frame.
368 nil stands for the selected frame--or, if that is not a w32 frame,
369 the first display on the list. */
371 struct w32_display_info
*
372 check_x_display_info (Lisp_Object frame
)
376 struct frame
*sf
= XFRAME (selected_frame
);
378 if (FRAME_W32_P (sf
) && FRAME_LIVE_P (sf
))
379 return FRAME_W32_DISPLAY_INFO (sf
);
381 return &one_w32_display_info
;
383 else if (STRINGP (frame
))
384 return x_display_info_for_name (frame
);
389 CHECK_LIVE_FRAME (frame
);
391 if (! FRAME_W32_P (f
))
392 error ("Non-W32 frame used");
393 return FRAME_W32_DISPLAY_INFO (f
);
397 /* Return the Emacs frame-object corresponding to an w32 window.
398 It could be the frame's main window or an icon window. */
400 /* This function can be called during GC, so use GC_xxx type test macros. */
403 x_window_to_frame (struct w32_display_info
*dpyinfo
, HWND wdesc
)
405 Lisp_Object tail
, frame
;
408 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
414 if (!FRAME_W32_P (f
) || FRAME_W32_DISPLAY_INFO (f
) != dpyinfo
)
417 if (FRAME_W32_WINDOW (f
) == wdesc
)
424 static Lisp_Object
unwind_create_frame (Lisp_Object
);
425 static Lisp_Object
unwind_create_tip_frame (Lisp_Object
);
426 static void my_create_window (struct frame
*);
427 static void my_create_tip_window (struct frame
*);
429 /* TODO: Native Input Method support; see x_create_im. */
430 void x_set_foreground_color (struct frame
*, Lisp_Object
, Lisp_Object
);
431 void x_set_background_color (struct frame
*, Lisp_Object
, Lisp_Object
);
432 void x_set_mouse_color (struct frame
*, Lisp_Object
, Lisp_Object
);
433 void x_set_cursor_color (struct frame
*, Lisp_Object
, Lisp_Object
);
434 void x_set_border_color (struct frame
*, Lisp_Object
, Lisp_Object
);
435 void x_set_cursor_type (struct frame
*, Lisp_Object
, Lisp_Object
);
436 void x_set_icon_type (struct frame
*, Lisp_Object
, Lisp_Object
);
437 void x_set_icon_name (struct frame
*, Lisp_Object
, Lisp_Object
);
438 void x_explicitly_set_name (struct frame
*, Lisp_Object
, Lisp_Object
);
439 void x_set_menu_bar_lines (struct frame
*, Lisp_Object
, Lisp_Object
);
440 void x_set_title (struct frame
*, Lisp_Object
, Lisp_Object
);
441 void x_set_tool_bar_lines (struct frame
*, Lisp_Object
, Lisp_Object
);
446 /* Store the screen positions of frame F into XPTR and YPTR.
447 These are the positions of the containing window manager window,
448 not Emacs's own window. */
451 x_real_positions (FRAME_PTR f
, int *xptr
, int *yptr
)
456 /* Get the bounds of the WM window. */
457 GetWindowRect (FRAME_W32_WINDOW (f
), &rect
);
462 /* Convert (0, 0) in the client area to screen co-ordinates. */
463 ClientToScreen (FRAME_W32_WINDOW (f
), &pt
);
465 /* Remember x_pixels_diff and y_pixels_diff. */
466 f
->x_pixels_diff
= pt
.x
- rect
.left
;
467 f
->y_pixels_diff
= pt
.y
- rect
.top
;
475 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
,
476 Sw32_define_rgb_color
, 4, 4, 0,
477 doc
: /* Convert RGB numbers to a Windows color reference and associate with NAME.
478 This adds or updates a named color to `w32-color-map', making it
479 available for use. The original entry's RGB ref is returned, or nil
480 if the entry is new. */)
481 (Lisp_Object red
, Lisp_Object green
, Lisp_Object blue
, Lisp_Object name
)
484 Lisp_Object oldrgb
= Qnil
;
488 CHECK_NUMBER (green
);
492 XSETINT (rgb
, RGB (XUINT (red
), XUINT (green
), XUINT (blue
)));
496 /* replace existing entry in w32-color-map or add new entry. */
497 entry
= Fassoc (name
, Vw32_color_map
);
500 entry
= Fcons (name
, rgb
);
501 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
505 oldrgb
= Fcdr (entry
);
506 Fsetcdr (entry
, rgb
);
514 /* The default colors for the w32 color map */
515 typedef struct colormap_t
521 colormap_t w32_color_map
[] =
523 {"snow" , PALETTERGB (255,250,250)},
524 {"ghost white" , PALETTERGB (248,248,255)},
525 {"GhostWhite" , PALETTERGB (248,248,255)},
526 {"white smoke" , PALETTERGB (245,245,245)},
527 {"WhiteSmoke" , PALETTERGB (245,245,245)},
528 {"gainsboro" , PALETTERGB (220,220,220)},
529 {"floral white" , PALETTERGB (255,250,240)},
530 {"FloralWhite" , PALETTERGB (255,250,240)},
531 {"old lace" , PALETTERGB (253,245,230)},
532 {"OldLace" , PALETTERGB (253,245,230)},
533 {"linen" , PALETTERGB (250,240,230)},
534 {"antique white" , PALETTERGB (250,235,215)},
535 {"AntiqueWhite" , PALETTERGB (250,235,215)},
536 {"papaya whip" , PALETTERGB (255,239,213)},
537 {"PapayaWhip" , PALETTERGB (255,239,213)},
538 {"blanched almond" , PALETTERGB (255,235,205)},
539 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
540 {"bisque" , PALETTERGB (255,228,196)},
541 {"peach puff" , PALETTERGB (255,218,185)},
542 {"PeachPuff" , PALETTERGB (255,218,185)},
543 {"navajo white" , PALETTERGB (255,222,173)},
544 {"NavajoWhite" , PALETTERGB (255,222,173)},
545 {"moccasin" , PALETTERGB (255,228,181)},
546 {"cornsilk" , PALETTERGB (255,248,220)},
547 {"ivory" , PALETTERGB (255,255,240)},
548 {"lemon chiffon" , PALETTERGB (255,250,205)},
549 {"LemonChiffon" , PALETTERGB (255,250,205)},
550 {"seashell" , PALETTERGB (255,245,238)},
551 {"honeydew" , PALETTERGB (240,255,240)},
552 {"mint cream" , PALETTERGB (245,255,250)},
553 {"MintCream" , PALETTERGB (245,255,250)},
554 {"azure" , PALETTERGB (240,255,255)},
555 {"alice blue" , PALETTERGB (240,248,255)},
556 {"AliceBlue" , PALETTERGB (240,248,255)},
557 {"lavender" , PALETTERGB (230,230,250)},
558 {"lavender blush" , PALETTERGB (255,240,245)},
559 {"LavenderBlush" , PALETTERGB (255,240,245)},
560 {"misty rose" , PALETTERGB (255,228,225)},
561 {"MistyRose" , PALETTERGB (255,228,225)},
562 {"white" , PALETTERGB (255,255,255)},
563 {"black" , PALETTERGB ( 0, 0, 0)},
564 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
565 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
566 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
567 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
568 {"dim gray" , PALETTERGB (105,105,105)},
569 {"DimGray" , PALETTERGB (105,105,105)},
570 {"dim grey" , PALETTERGB (105,105,105)},
571 {"DimGrey" , PALETTERGB (105,105,105)},
572 {"slate gray" , PALETTERGB (112,128,144)},
573 {"SlateGray" , PALETTERGB (112,128,144)},
574 {"slate grey" , PALETTERGB (112,128,144)},
575 {"SlateGrey" , PALETTERGB (112,128,144)},
576 {"light slate gray" , PALETTERGB (119,136,153)},
577 {"LightSlateGray" , PALETTERGB (119,136,153)},
578 {"light slate grey" , PALETTERGB (119,136,153)},
579 {"LightSlateGrey" , PALETTERGB (119,136,153)},
580 {"gray" , PALETTERGB (190,190,190)},
581 {"grey" , PALETTERGB (190,190,190)},
582 {"light grey" , PALETTERGB (211,211,211)},
583 {"LightGrey" , PALETTERGB (211,211,211)},
584 {"light gray" , PALETTERGB (211,211,211)},
585 {"LightGray" , PALETTERGB (211,211,211)},
586 {"midnight blue" , PALETTERGB ( 25, 25,112)},
587 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
588 {"navy" , PALETTERGB ( 0, 0,128)},
589 {"navy blue" , PALETTERGB ( 0, 0,128)},
590 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
591 {"cornflower blue" , PALETTERGB (100,149,237)},
592 {"CornflowerBlue" , PALETTERGB (100,149,237)},
593 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
594 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
595 {"slate blue" , PALETTERGB (106, 90,205)},
596 {"SlateBlue" , PALETTERGB (106, 90,205)},
597 {"medium slate blue" , PALETTERGB (123,104,238)},
598 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
599 {"light slate blue" , PALETTERGB (132,112,255)},
600 {"LightSlateBlue" , PALETTERGB (132,112,255)},
601 {"medium blue" , PALETTERGB ( 0, 0,205)},
602 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
603 {"royal blue" , PALETTERGB ( 65,105,225)},
604 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
605 {"blue" , PALETTERGB ( 0, 0,255)},
606 {"dodger blue" , PALETTERGB ( 30,144,255)},
607 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
608 {"deep sky blue" , PALETTERGB ( 0,191,255)},
609 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
610 {"sky blue" , PALETTERGB (135,206,235)},
611 {"SkyBlue" , PALETTERGB (135,206,235)},
612 {"light sky blue" , PALETTERGB (135,206,250)},
613 {"LightSkyBlue" , PALETTERGB (135,206,250)},
614 {"steel blue" , PALETTERGB ( 70,130,180)},
615 {"SteelBlue" , PALETTERGB ( 70,130,180)},
616 {"light steel blue" , PALETTERGB (176,196,222)},
617 {"LightSteelBlue" , PALETTERGB (176,196,222)},
618 {"light blue" , PALETTERGB (173,216,230)},
619 {"LightBlue" , PALETTERGB (173,216,230)},
620 {"powder blue" , PALETTERGB (176,224,230)},
621 {"PowderBlue" , PALETTERGB (176,224,230)},
622 {"pale turquoise" , PALETTERGB (175,238,238)},
623 {"PaleTurquoise" , PALETTERGB (175,238,238)},
624 {"dark turquoise" , PALETTERGB ( 0,206,209)},
625 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
626 {"medium turquoise" , PALETTERGB ( 72,209,204)},
627 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
628 {"turquoise" , PALETTERGB ( 64,224,208)},
629 {"cyan" , PALETTERGB ( 0,255,255)},
630 {"light cyan" , PALETTERGB (224,255,255)},
631 {"LightCyan" , PALETTERGB (224,255,255)},
632 {"cadet blue" , PALETTERGB ( 95,158,160)},
633 {"CadetBlue" , PALETTERGB ( 95,158,160)},
634 {"medium aquamarine" , PALETTERGB (102,205,170)},
635 {"MediumAquamarine" , PALETTERGB (102,205,170)},
636 {"aquamarine" , PALETTERGB (127,255,212)},
637 {"dark green" , PALETTERGB ( 0,100, 0)},
638 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
639 {"dark olive green" , PALETTERGB ( 85,107, 47)},
640 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
641 {"dark sea green" , PALETTERGB (143,188,143)},
642 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
643 {"sea green" , PALETTERGB ( 46,139, 87)},
644 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
645 {"medium sea green" , PALETTERGB ( 60,179,113)},
646 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
647 {"light sea green" , PALETTERGB ( 32,178,170)},
648 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
649 {"pale green" , PALETTERGB (152,251,152)},
650 {"PaleGreen" , PALETTERGB (152,251,152)},
651 {"spring green" , PALETTERGB ( 0,255,127)},
652 {"SpringGreen" , PALETTERGB ( 0,255,127)},
653 {"lawn green" , PALETTERGB (124,252, 0)},
654 {"LawnGreen" , PALETTERGB (124,252, 0)},
655 {"green" , PALETTERGB ( 0,255, 0)},
656 {"chartreuse" , PALETTERGB (127,255, 0)},
657 {"medium spring green" , PALETTERGB ( 0,250,154)},
658 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
659 {"green yellow" , PALETTERGB (173,255, 47)},
660 {"GreenYellow" , PALETTERGB (173,255, 47)},
661 {"lime green" , PALETTERGB ( 50,205, 50)},
662 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
663 {"yellow green" , PALETTERGB (154,205, 50)},
664 {"YellowGreen" , PALETTERGB (154,205, 50)},
665 {"forest green" , PALETTERGB ( 34,139, 34)},
666 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
667 {"olive drab" , PALETTERGB (107,142, 35)},
668 {"OliveDrab" , PALETTERGB (107,142, 35)},
669 {"dark khaki" , PALETTERGB (189,183,107)},
670 {"DarkKhaki" , PALETTERGB (189,183,107)},
671 {"khaki" , PALETTERGB (240,230,140)},
672 {"pale goldenrod" , PALETTERGB (238,232,170)},
673 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
674 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
675 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
676 {"light yellow" , PALETTERGB (255,255,224)},
677 {"LightYellow" , PALETTERGB (255,255,224)},
678 {"yellow" , PALETTERGB (255,255, 0)},
679 {"gold" , PALETTERGB (255,215, 0)},
680 {"light goldenrod" , PALETTERGB (238,221,130)},
681 {"LightGoldenrod" , PALETTERGB (238,221,130)},
682 {"goldenrod" , PALETTERGB (218,165, 32)},
683 {"dark goldenrod" , PALETTERGB (184,134, 11)},
684 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
685 {"rosy brown" , PALETTERGB (188,143,143)},
686 {"RosyBrown" , PALETTERGB (188,143,143)},
687 {"indian red" , PALETTERGB (205, 92, 92)},
688 {"IndianRed" , PALETTERGB (205, 92, 92)},
689 {"saddle brown" , PALETTERGB (139, 69, 19)},
690 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
691 {"sienna" , PALETTERGB (160, 82, 45)},
692 {"peru" , PALETTERGB (205,133, 63)},
693 {"burlywood" , PALETTERGB (222,184,135)},
694 {"beige" , PALETTERGB (245,245,220)},
695 {"wheat" , PALETTERGB (245,222,179)},
696 {"sandy brown" , PALETTERGB (244,164, 96)},
697 {"SandyBrown" , PALETTERGB (244,164, 96)},
698 {"tan" , PALETTERGB (210,180,140)},
699 {"chocolate" , PALETTERGB (210,105, 30)},
700 {"firebrick" , PALETTERGB (178,34, 34)},
701 {"brown" , PALETTERGB (165,42, 42)},
702 {"dark salmon" , PALETTERGB (233,150,122)},
703 {"DarkSalmon" , PALETTERGB (233,150,122)},
704 {"salmon" , PALETTERGB (250,128,114)},
705 {"light salmon" , PALETTERGB (255,160,122)},
706 {"LightSalmon" , PALETTERGB (255,160,122)},
707 {"orange" , PALETTERGB (255,165, 0)},
708 {"dark orange" , PALETTERGB (255,140, 0)},
709 {"DarkOrange" , PALETTERGB (255,140, 0)},
710 {"coral" , PALETTERGB (255,127, 80)},
711 {"light coral" , PALETTERGB (240,128,128)},
712 {"LightCoral" , PALETTERGB (240,128,128)},
713 {"tomato" , PALETTERGB (255, 99, 71)},
714 {"orange red" , PALETTERGB (255, 69, 0)},
715 {"OrangeRed" , PALETTERGB (255, 69, 0)},
716 {"red" , PALETTERGB (255, 0, 0)},
717 {"hot pink" , PALETTERGB (255,105,180)},
718 {"HotPink" , PALETTERGB (255,105,180)},
719 {"deep pink" , PALETTERGB (255, 20,147)},
720 {"DeepPink" , PALETTERGB (255, 20,147)},
721 {"pink" , PALETTERGB (255,192,203)},
722 {"light pink" , PALETTERGB (255,182,193)},
723 {"LightPink" , PALETTERGB (255,182,193)},
724 {"pale violet red" , PALETTERGB (219,112,147)},
725 {"PaleVioletRed" , PALETTERGB (219,112,147)},
726 {"maroon" , PALETTERGB (176, 48, 96)},
727 {"medium violet red" , PALETTERGB (199, 21,133)},
728 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
729 {"violet red" , PALETTERGB (208, 32,144)},
730 {"VioletRed" , PALETTERGB (208, 32,144)},
731 {"magenta" , PALETTERGB (255, 0,255)},
732 {"violet" , PALETTERGB (238,130,238)},
733 {"plum" , PALETTERGB (221,160,221)},
734 {"orchid" , PALETTERGB (218,112,214)},
735 {"medium orchid" , PALETTERGB (186, 85,211)},
736 {"MediumOrchid" , PALETTERGB (186, 85,211)},
737 {"dark orchid" , PALETTERGB (153, 50,204)},
738 {"DarkOrchid" , PALETTERGB (153, 50,204)},
739 {"dark violet" , PALETTERGB (148, 0,211)},
740 {"DarkViolet" , PALETTERGB (148, 0,211)},
741 {"blue violet" , PALETTERGB (138, 43,226)},
742 {"BlueViolet" , PALETTERGB (138, 43,226)},
743 {"purple" , PALETTERGB (160, 32,240)},
744 {"medium purple" , PALETTERGB (147,112,219)},
745 {"MediumPurple" , PALETTERGB (147,112,219)},
746 {"thistle" , PALETTERGB (216,191,216)},
747 {"gray0" , PALETTERGB ( 0, 0, 0)},
748 {"grey0" , PALETTERGB ( 0, 0, 0)},
749 {"dark grey" , PALETTERGB (169,169,169)},
750 {"DarkGrey" , PALETTERGB (169,169,169)},
751 {"dark gray" , PALETTERGB (169,169,169)},
752 {"DarkGray" , PALETTERGB (169,169,169)},
753 {"dark blue" , PALETTERGB ( 0, 0,139)},
754 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
755 {"dark cyan" , PALETTERGB ( 0,139,139)},
756 {"DarkCyan" , PALETTERGB ( 0,139,139)},
757 {"dark magenta" , PALETTERGB (139, 0,139)},
758 {"DarkMagenta" , PALETTERGB (139, 0,139)},
759 {"dark red" , PALETTERGB (139, 0, 0)},
760 {"DarkRed" , PALETTERGB (139, 0, 0)},
761 {"light green" , PALETTERGB (144,238,144)},
762 {"LightGreen" , PALETTERGB (144,238,144)},
765 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
766 0, 0, 0, doc
: /* Return the default color map. */)
770 colormap_t
*pc
= w32_color_map
;
777 for (i
= 0; i
< sizeof (w32_color_map
) / sizeof (w32_color_map
[0]);
779 cmap
= Fcons (Fcons (build_string (pc
->name
),
780 make_number (pc
->colorref
)),
789 w32_color_map_lookup (char *colorname
)
791 Lisp_Object tail
, ret
= Qnil
;
795 for (tail
= Vw32_color_map
; CONSP (tail
); tail
= XCDR (tail
))
797 register Lisp_Object elt
, tem
;
800 if (!CONSP (elt
)) continue;
804 if (lstrcmpi (SDATA (tem
), colorname
) == 0)
821 add_system_logical_colors_to_map (Lisp_Object
*system_colors
)
825 /* Other registry operations are done with input blocked. */
828 /* Look for "Control Panel/Colors" under User and Machine registry
830 if (RegOpenKeyEx (HKEY_CURRENT_USER
, "Control Panel\\Colors", 0,
831 KEY_READ
, &colors_key
) == ERROR_SUCCESS
832 || RegOpenKeyEx (HKEY_LOCAL_MACHINE
, "Control Panel\\Colors", 0,
833 KEY_READ
, &colors_key
) == ERROR_SUCCESS
)
836 char color_buffer
[64];
837 char full_name_buffer
[MAX_PATH
+ SYSTEM_COLOR_PREFIX_LEN
];
839 DWORD name_size
, color_size
;
840 char *name_buffer
= full_name_buffer
+ SYSTEM_COLOR_PREFIX_LEN
;
842 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
843 color_size
= sizeof (color_buffer
);
845 strcpy (full_name_buffer
, SYSTEM_COLOR_PREFIX
);
847 while (RegEnumValueA (colors_key
, index
, name_buffer
, &name_size
,
848 NULL
, NULL
, color_buffer
, &color_size
)
852 if (sscanf (color_buffer
, " %u %u %u", &r
, &g
, &b
) == 3)
853 *system_colors
= Fcons (Fcons (build_string (full_name_buffer
),
854 make_number (RGB (r
, g
, b
))),
857 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
858 color_size
= sizeof (color_buffer
);
861 RegCloseKey (colors_key
);
869 x_to_w32_color (char * colorname
)
871 register Lisp_Object ret
= Qnil
;
875 if (colorname
[0] == '#')
877 /* Could be an old-style RGB Device specification. */
880 color
= colorname
+ 1;
882 size
= strlen (color
);
883 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
891 for (i
= 0; i
< 3; i
++)
897 /* The check for 'x' in the following conditional takes into
898 account the fact that strtol allows a "0x" in front of
899 our numbers, and we don't. */
900 if (!isxdigit (color
[0]) || color
[1] == 'x')
904 value
= strtoul (color
, &end
, 16);
906 if (errno
== ERANGE
|| end
- color
!= size
)
911 value
= value
* 0x10;
922 colorval
|= (value
<< pos
);
927 XSETINT (ret
, colorval
);
934 else if (strnicmp (colorname
, "rgb:", 4) == 0)
942 color
= colorname
+ 4;
943 for (i
= 0; i
< 3; i
++)
948 /* The check for 'x' in the following conditional takes into
949 account the fact that strtol allows a "0x" in front of
950 our numbers, and we don't. */
951 if (!isxdigit (color
[0]) || color
[1] == 'x')
953 value
= strtoul (color
, &end
, 16);
959 value
= value
* 0x10 + value
;
972 if (value
== ULONG_MAX
)
974 colorval
|= (value
<< pos
);
981 XSETINT (ret
, colorval
);
989 else if (strnicmp (colorname
, "rgbi:", 5) == 0)
991 /* This is an RGB Intensity specification. */
998 color
= colorname
+ 5;
999 for (i
= 0; i
< 3; i
++)
1005 value
= strtod (color
, &end
);
1006 if (errno
== ERANGE
)
1008 if (value
< 0.0 || value
> 1.0)
1010 val
= (UINT
)(0x100 * value
);
1011 /* We used 0x100 instead of 0xFF to give a continuous
1012 range between 0.0 and 1.0 inclusive. The next statement
1013 fixes the 1.0 case. */
1016 colorval
|= (val
<< pos
);
1023 XSETINT (ret
, colorval
);
1031 /* I am not going to attempt to handle any of the CIE color schemes
1032 or TekHVC, since I don't know the algorithms for conversion to
1035 /* If we fail to lookup the color name in w32_color_map, then check the
1036 colorname to see if it can be crudely approximated: If the X color
1037 ends in a number (e.g., "darkseagreen2"), strip the number and
1038 return the result of looking up the base color name. */
1039 ret
= w32_color_map_lookup (colorname
);
1042 int len
= strlen (colorname
);
1044 if (isdigit (colorname
[len
- 1]))
1046 char *ptr
, *approx
= alloca (len
+ 1);
1048 strcpy (approx
, colorname
);
1049 ptr
= &approx
[len
- 1];
1050 while (ptr
> approx
&& isdigit (*ptr
))
1053 ret
= w32_color_map_lookup (approx
);
1062 w32_regenerate_palette (FRAME_PTR f
)
1064 struct w32_palette_entry
* list
;
1065 LOGPALETTE
* log_palette
;
1066 HPALETTE new_palette
;
1069 /* don't bother trying to create palette if not supported */
1070 if (! FRAME_W32_DISPLAY_INFO (f
)->has_palette
)
1073 log_palette
= (LOGPALETTE
*)
1074 alloca (sizeof (LOGPALETTE
) +
1075 FRAME_W32_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
1076 log_palette
->palVersion
= 0x300;
1077 log_palette
->palNumEntries
= FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1079 list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1081 i
< FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1082 i
++, list
= list
->next
)
1083 log_palette
->palPalEntry
[i
] = list
->entry
;
1085 new_palette
= CreatePalette (log_palette
);
1089 if (FRAME_W32_DISPLAY_INFO (f
)->palette
)
1090 DeleteObject (FRAME_W32_DISPLAY_INFO (f
)->palette
);
1091 FRAME_W32_DISPLAY_INFO (f
)->palette
= new_palette
;
1093 /* Realize display palette and garbage all frames. */
1094 release_frame_dc (f
, get_frame_dc (f
));
1099 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
1100 #define SET_W32_COLOR(pe, color) \
1103 pe.peRed = GetRValue (color); \
1104 pe.peGreen = GetGValue (color); \
1105 pe.peBlue = GetBValue (color); \
1110 /* Keep these around in case we ever want to track color usage. */
1112 w32_map_color (FRAME_PTR f
, COLORREF color
)
1114 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1116 if (NILP (Vw32_enable_palette
))
1119 /* check if color is already mapped */
1122 if (W32_COLOR (list
->entry
) == color
)
1130 /* not already mapped, so add to list and recreate Windows palette */
1131 list
= (struct w32_palette_entry
*)
1132 xmalloc (sizeof (struct w32_palette_entry
));
1133 SET_W32_COLOR (list
->entry
, color
);
1135 list
->next
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1136 FRAME_W32_DISPLAY_INFO (f
)->color_list
= list
;
1137 FRAME_W32_DISPLAY_INFO (f
)->num_colors
++;
1139 /* set flag that palette must be regenerated */
1140 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1144 w32_unmap_color (FRAME_PTR f
, COLORREF color
)
1146 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1147 struct w32_palette_entry
**prev
= &FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1149 if (NILP (Vw32_enable_palette
))
1152 /* check if color is already mapped */
1155 if (W32_COLOR (list
->entry
) == color
)
1157 if (--list
->refcount
== 0)
1161 FRAME_W32_DISPLAY_INFO (f
)->num_colors
--;
1171 /* set flag that palette must be regenerated */
1172 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1177 /* Gamma-correct COLOR on frame F. */
1180 gamma_correct (struct frame
*f
, COLORREF
*color
)
1184 *color
= PALETTERGB (
1185 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1186 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1187 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1192 /* Decide if color named COLOR is valid for the display associated with
1193 the selected frame; if so, return the rgb values in COLOR_DEF.
1194 If ALLOC is nonzero, allocate a new colormap cell. */
1197 w32_defined_color (FRAME_PTR f
, char *color
, XColor
*color_def
, int alloc
)
1199 register Lisp_Object tem
;
1200 COLORREF w32_color_ref
;
1202 tem
= x_to_w32_color (color
);
1208 /* Apply gamma correction. */
1209 w32_color_ref
= XUINT (tem
);
1210 gamma_correct (f
, &w32_color_ref
);
1211 XSETINT (tem
, w32_color_ref
);
1214 /* Map this color to the palette if it is enabled. */
1215 if (!NILP (Vw32_enable_palette
))
1217 struct w32_palette_entry
* entry
=
1218 one_w32_display_info
.color_list
;
1219 struct w32_palette_entry
** prev
=
1220 &one_w32_display_info
.color_list
;
1222 /* check if color is already mapped */
1225 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1227 prev
= &entry
->next
;
1228 entry
= entry
->next
;
1231 if (entry
== NULL
&& alloc
)
1233 /* not already mapped, so add to list */
1234 entry
= (struct w32_palette_entry
*)
1235 xmalloc (sizeof (struct w32_palette_entry
));
1236 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1239 one_w32_display_info
.num_colors
++;
1241 /* set flag that palette must be regenerated */
1242 one_w32_display_info
.regen_palette
= TRUE
;
1245 /* Ensure COLORREF value is snapped to nearest color in (default)
1246 palette by simulating the PALETTERGB macro. This works whether
1247 or not the display device has a palette. */
1248 w32_color_ref
= XUINT (tem
) | 0x2000000;
1250 color_def
->pixel
= w32_color_ref
;
1251 color_def
->red
= GetRValue (w32_color_ref
) * 256;
1252 color_def
->green
= GetGValue (w32_color_ref
) * 256;
1253 color_def
->blue
= GetBValue (w32_color_ref
) * 256;
1263 /* Given a string ARG naming a color, compute a pixel value from it
1264 suitable for screen F.
1265 If F is not a color screen, return DEF (default) regardless of what
1269 x_decode_color (FRAME_PTR f
, Lisp_Object arg
, int def
)
1275 if (strcmp (SDATA (arg
), "black") == 0)
1276 return BLACK_PIX_DEFAULT (f
);
1277 else if (strcmp (SDATA (arg
), "white") == 0)
1278 return WHITE_PIX_DEFAULT (f
);
1280 if ((FRAME_W32_DISPLAY_INFO (f
)->n_planes
* FRAME_W32_DISPLAY_INFO (f
)->n_cbits
) == 1)
1283 /* w32_defined_color is responsible for coping with failures
1284 by looking for a near-miss. */
1285 if (w32_defined_color (f
, SDATA (arg
), &cdef
, 1))
1288 /* defined_color failed; return an ultimate default. */
1294 /* Functions called only from `x_set_frame_param'
1295 to set individual parameters.
1297 If FRAME_W32_WINDOW (f) is 0,
1298 the frame is being created and its window does not exist yet.
1299 In that case, just record the parameter's new value
1300 in the standard place; do not attempt to change the window. */
1303 x_set_foreground_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1305 struct w32_output
*x
= f
->output_data
.w32
;
1306 PIX_TYPE fg
, old_fg
;
1308 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1309 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
1310 FRAME_FOREGROUND_PIXEL (f
) = fg
;
1312 if (FRAME_W32_WINDOW (f
) != 0)
1314 if (x
->cursor_pixel
== old_fg
)
1316 x
->cursor_pixel
= fg
;
1317 x
->cursor_gc
->background
= fg
;
1320 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
1321 if (FRAME_VISIBLE_P (f
))
1327 x_set_background_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1329 FRAME_BACKGROUND_PIXEL (f
)
1330 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
1332 if (FRAME_W32_WINDOW (f
) != 0)
1334 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
1335 FRAME_BACKGROUND_PIXEL (f
));
1337 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
1339 if (FRAME_VISIBLE_P (f
))
1345 x_set_mouse_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1347 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
1351 if (!EQ (Qnil
, arg
))
1352 f
->output_data
.w32
->mouse_pixel
1353 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1354 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
1356 /* Don't let pointers be invisible. */
1357 if (mask_color
== f
->output_data
.w32
->mouse_pixel
1358 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
1359 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
1361 #if 0 /* TODO : Mouse cursor customization. */
1364 /* It's not okay to crash if the user selects a screwy cursor. */
1365 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
1367 if (!EQ (Qnil
, Vx_pointer_shape
))
1369 CHECK_NUMBER (Vx_pointer_shape
);
1370 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
1373 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1374 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
1376 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
1378 CHECK_NUMBER (Vx_nontext_pointer_shape
);
1379 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1380 XINT (Vx_nontext_pointer_shape
));
1383 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
1384 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1386 if (!EQ (Qnil
, Vx_hourglass_pointer_shape
))
1388 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
1389 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1390 XINT (Vx_hourglass_pointer_shape
));
1393 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
1394 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
1396 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1397 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
1399 CHECK_NUMBER (Vx_mode_pointer_shape
);
1400 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1401 XINT (Vx_mode_pointer_shape
));
1404 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1405 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
1407 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
1409 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
1411 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1412 XINT (Vx_sensitive_text_pointer_shape
));
1415 hand_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
1417 if (!NILP (Vx_window_horizontal_drag_shape
))
1419 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
1420 horizontal_drag_cursor
1421 = XCreateFontCursor (FRAME_X_DISPLAY (f
),
1422 XINT (Vx_window_horizontal_drag_shape
));
1425 horizontal_drag_cursor
1426 = XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_sb_h_double_arrow
);
1428 /* Check and report errors with the above calls. */
1429 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
1430 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
1433 XColor fore_color
, back_color
;
1435 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
1436 back_color
.pixel
= mask_color
;
1437 XQueryColor (FRAME_W32_DISPLAY (f
),
1438 DefaultColormap (FRAME_W32_DISPLAY (f
),
1439 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1441 XQueryColor (FRAME_W32_DISPLAY (f
),
1442 DefaultColormap (FRAME_W32_DISPLAY (f
),
1443 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1445 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
1446 &fore_color
, &back_color
);
1447 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
1448 &fore_color
, &back_color
);
1449 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
1450 &fore_color
, &back_color
);
1451 XRecolorCursor (FRAME_W32_DISPLAY (f
), hand_cursor
,
1452 &fore_color
, &back_color
);
1453 XRecolorCursor (FRAME_W32_DISPLAY (f
), hourglass_cursor
,
1454 &fore_color
, &back_color
);
1457 if (FRAME_W32_WINDOW (f
) != 0)
1458 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
1460 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
1461 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
1462 f
->output_data
.w32
->text_cursor
= cursor
;
1464 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
1465 && f
->output_data
.w32
->nontext_cursor
!= 0)
1466 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
1467 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
1469 if (hourglass_cursor
!= f
->output_data
.w32
->hourglass_cursor
1470 && f
->output_data
.w32
->hourglass_cursor
!= 0)
1471 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hourglass_cursor
);
1472 f
->output_data
.w32
->hourglass_cursor
= hourglass_cursor
;
1474 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
1475 && f
->output_data
.w32
->modeline_cursor
!= 0)
1476 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
1477 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
1479 if (hand_cursor
!= f
->output_data
.w32
->hand_cursor
1480 && f
->output_data
.w32
->hand_cursor
!= 0)
1481 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hand_cursor
);
1482 f
->output_data
.w32
->hand_cursor
= hand_cursor
;
1484 XFlush (FRAME_W32_DISPLAY (f
));
1487 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1492 x_set_cursor_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1494 unsigned long fore_pixel
, pixel
;
1496 if (!NILP (Vx_cursor_fore_pixel
))
1497 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1498 WHITE_PIX_DEFAULT (f
));
1500 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1502 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1504 /* Make sure that the cursor color differs from the background color. */
1505 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
1507 pixel
= f
->output_data
.w32
->mouse_pixel
;
1508 if (pixel
== fore_pixel
)
1509 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1512 f
->output_data
.w32
->cursor_foreground_pixel
= fore_pixel
;
1513 f
->output_data
.w32
->cursor_pixel
= pixel
;
1515 if (FRAME_W32_WINDOW (f
) != 0)
1518 /* Update frame's cursor_gc. */
1519 f
->output_data
.w32
->cursor_gc
->foreground
= fore_pixel
;
1520 f
->output_data
.w32
->cursor_gc
->background
= pixel
;
1524 if (FRAME_VISIBLE_P (f
))
1526 x_update_cursor (f
, 0);
1527 x_update_cursor (f
, 1);
1531 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1534 /* Set the border-color of frame F to pixel value PIX.
1535 Note that this does not fully take effect if done before
1539 x_set_border_pixel (struct frame
*f
, int pix
)
1542 f
->output_data
.w32
->border_pixel
= pix
;
1544 if (FRAME_W32_WINDOW (f
) != 0 && f
->border_width
> 0)
1546 if (FRAME_VISIBLE_P (f
))
1551 /* Set the border-color of frame F to value described by ARG.
1552 ARG can be a string naming a color.
1553 The border-color is used for the border that is drawn by the server.
1554 Note that this does not fully take effect if done before
1555 F has a window; it must be redone when the window is created. */
1558 x_set_border_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1563 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1564 x_set_border_pixel (f
, pix
);
1565 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1570 x_set_cursor_type (FRAME_PTR f
, Lisp_Object arg
, Lisp_Object oldval
)
1572 set_frame_cursor_types (f
, arg
);
1574 /* Make sure the cursor gets redrawn. */
1575 cursor_type_changed
= 1;
1579 x_set_icon_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1583 if (NILP (arg
) && NILP (oldval
))
1586 if (STRINGP (arg
) && STRINGP (oldval
)
1587 && EQ (Fstring_equal (oldval
, arg
), Qt
))
1590 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
1595 result
= x_bitmap_icon (f
, arg
);
1599 error ("No icon window available");
1606 x_set_icon_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1610 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1613 else if (!NILP (arg
) || NILP (oldval
))
1619 if (f
->output_data
.w32
->icon_bitmap
!= 0)
1624 result
= x_text_icon (f
,
1625 (char *) SDATA ((!NILP (f
->icon_name
)
1634 error ("No icon window available");
1637 /* If the window was unmapped (and its icon was mapped),
1638 the new icon is not mapped, so map the window in its stead. */
1639 if (FRAME_VISIBLE_P (f
))
1641 #ifdef USE_X_TOOLKIT
1642 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
1644 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
1647 XFlush (FRAME_W32_DISPLAY (f
));
1654 x_set_menu_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1657 int olines
= FRAME_MENU_BAR_LINES (f
);
1659 /* Right now, menu bars don't work properly in minibuf-only frames;
1660 most of the commands try to apply themselves to the minibuffer
1661 frame itself, and get an error because you can't switch buffers
1662 in or split the minibuffer window. */
1663 if (FRAME_MINIBUF_ONLY_P (f
))
1666 if (INTEGERP (value
))
1667 nlines
= XINT (value
);
1671 FRAME_MENU_BAR_LINES (f
) = 0;
1673 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1676 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1677 free_frame_menubar (f
);
1678 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1680 /* Adjust the frame size so that the client (text) dimensions
1681 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
1683 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
1684 do_pending_window_change (0);
1690 /* Set the number of lines used for the tool bar of frame F to VALUE.
1691 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1692 is the old number of tool bar lines. This function changes the
1693 height of all windows on frame F to match the new tool bar height.
1694 The frame's height doesn't change. */
1697 x_set_tool_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1699 int delta
, nlines
, root_height
;
1700 Lisp_Object root_window
;
1702 /* Treat tool bars like menu bars. */
1703 if (FRAME_MINIBUF_ONLY_P (f
))
1706 /* Use VALUE only if an integer >= 0. */
1707 if (INTEGERP (value
) && XINT (value
) >= 0)
1708 nlines
= XFASTINT (value
);
1712 /* Make sure we redisplay all windows in this frame. */
1713 ++windows_or_buffers_changed
;
1715 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
1717 /* Don't resize the tool-bar to more than we have room for. */
1718 root_window
= FRAME_ROOT_WINDOW (f
);
1719 root_height
= WINDOW_TOTAL_LINES (XWINDOW (root_window
));
1720 if (root_height
- delta
< 1)
1722 delta
= root_height
- 1;
1723 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
1726 FRAME_TOOL_BAR_LINES (f
) = nlines
;
1727 resize_frame_windows (f
, FRAME_LINES (f
), 0);
1730 /* We also have to make sure that the internal border at the top of
1731 the frame, below the menu bar or tool bar, is redrawn when the
1732 tool bar disappears. This is so because the internal border is
1733 below the tool bar if one is displayed, but is below the menu bar
1734 if there isn't a tool bar. The tool bar draws into the area
1735 below the menu bar. */
1736 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
1739 clear_current_matrices (f
);
1742 /* If the tool bar gets smaller, the internal border below it
1743 has to be cleared. It was formerly part of the display
1744 of the larger tool bar, and updating windows won't clear it. */
1747 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1748 int width
= FRAME_PIXEL_WIDTH (f
);
1749 int y
= nlines
* FRAME_LINE_HEIGHT (f
);
1753 HDC hdc
= get_frame_dc (f
);
1754 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
1755 release_frame_dc (f
, hdc
);
1759 if (WINDOWP (f
->tool_bar_window
))
1760 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1763 run_window_configuration_change_hook (f
);
1768 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1771 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1772 name; if NAME is a string, set F's name to NAME and set
1773 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1775 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1776 suggesting a new name, which lisp code should override; if
1777 F->explicit_name is set, ignore the new name; otherwise, set it. */
1780 x_set_name (struct frame
*f
, Lisp_Object name
, int explicit)
1782 /* Make sure that requests from lisp code override requests from
1783 Emacs redisplay code. */
1786 /* If we're switching from explicit to implicit, we had better
1787 update the mode lines and thereby update the title. */
1788 if (f
->explicit_name
&& NILP (name
))
1789 update_mode_lines
= 1;
1791 f
->explicit_name
= ! NILP (name
);
1793 else if (f
->explicit_name
)
1796 /* If NAME is nil, set the name to the w32_id_name. */
1799 /* Check for no change needed in this very common case
1800 before we do any consing. */
1801 if (!strcmp (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
,
1804 name
= build_string (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
);
1807 CHECK_STRING (name
);
1809 /* Don't change the name if it's already NAME. */
1810 if (! NILP (Fstring_equal (name
, f
->name
)))
1815 /* For setting the frame title, the title parameter should override
1816 the name parameter. */
1817 if (! NILP (f
->title
))
1820 if (FRAME_W32_WINDOW (f
))
1822 if (STRING_MULTIBYTE (name
))
1823 name
= ENCODE_SYSTEM (name
);
1826 SetWindowText (FRAME_W32_WINDOW (f
), SDATA (name
));
1831 /* This function should be called when the user's lisp code has
1832 specified a name for the frame; the name will override any set by the
1835 x_explicitly_set_name (FRAME_PTR f
, Lisp_Object arg
, Lisp_Object oldval
)
1837 x_set_name (f
, arg
, 1);
1840 /* This function should be called by Emacs redisplay code to set the
1841 name; names set this way will never override names set by the user's
1844 x_implicitly_set_name (FRAME_PTR f
, Lisp_Object arg
, Lisp_Object oldval
)
1846 x_set_name (f
, arg
, 0);
1849 /* Change the title of frame F to NAME.
1850 If NAME is nil, use the frame name as the title. */
1853 x_set_title (struct frame
*f
, Lisp_Object name
, Lisp_Object old_name
)
1855 /* Don't change the title if it's already NAME. */
1856 if (EQ (name
, f
->title
))
1859 update_mode_lines
= 1;
1866 if (FRAME_W32_WINDOW (f
))
1868 if (STRING_MULTIBYTE (name
))
1869 name
= ENCODE_SYSTEM (name
);
1872 SetWindowText (FRAME_W32_WINDOW (f
), SDATA (name
));
1879 x_set_scroll_bar_default_width (struct frame
*f
)
1881 int wid
= FRAME_COLUMN_WIDTH (f
);
1883 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
1884 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) +
1889 /* Subroutines for creating a frame. */
1892 w32_load_cursor (LPCTSTR name
)
1894 /* Try first to load cursor from application resource. */
1895 Cursor cursor
= LoadImage ((HINSTANCE
) GetModuleHandle (NULL
),
1896 name
, IMAGE_CURSOR
, 0, 0,
1897 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
1900 /* Then try to load a shared predefined cursor. */
1901 cursor
= LoadImage (NULL
, name
, IMAGE_CURSOR
, 0, 0,
1902 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
1907 extern LRESULT CALLBACK
w32_wnd_proc (HWND
, UINT
, WPARAM
, LPARAM
);
1910 w32_init_class (HINSTANCE hinst
)
1914 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
1915 wc
.lpfnWndProc
= (WNDPROC
) w32_wnd_proc
;
1917 wc
.cbWndExtra
= WND_EXTRA_BYTES
;
1918 wc
.hInstance
= hinst
;
1919 wc
.hIcon
= LoadIcon (hinst
, EMACS_CLASS
);
1920 wc
.hCursor
= w32_load_cursor (IDC_ARROW
);
1921 wc
.hbrBackground
= NULL
; /* GetStockObject (WHITE_BRUSH); */
1922 wc
.lpszMenuName
= NULL
;
1923 wc
.lpszClassName
= EMACS_CLASS
;
1925 return (RegisterClass (&wc
));
1929 w32_createscrollbar (struct frame
*f
, struct scroll_bar
* bar
)
1931 return (CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
1932 /* Position and size of scroll bar. */
1933 XINT (bar
->left
) + VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
1935 XINT (bar
->width
) - VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
1937 FRAME_W32_WINDOW (f
),
1944 w32_createwindow (struct frame
*f
)
1948 Lisp_Object top
= Qunbound
;
1949 Lisp_Object left
= Qunbound
;
1950 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
1952 rect
.left
= rect
.top
= 0;
1953 rect
.right
= FRAME_PIXEL_WIDTH (f
);
1954 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
1956 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
1957 FRAME_EXTERNAL_MENU_BAR (f
));
1959 /* Do first time app init */
1963 w32_init_class (hinst
);
1966 if (f
->size_hint_flags
& USPosition
|| f
->size_hint_flags
& PPosition
)
1968 XSETINT (left
, f
->left_pos
);
1969 XSETINT (top
, f
->top_pos
);
1971 else if (EQ (left
, Qunbound
) && EQ (top
, Qunbound
))
1973 /* When called with RES_TYPE_NUMBER, w32_get_arg will return zero
1974 for anything that is not a number and is not Qunbound. */
1975 left
= x_get_arg (dpyinfo
, Qnil
, Qleft
, "left", "Left", RES_TYPE_NUMBER
);
1976 top
= x_get_arg (dpyinfo
, Qnil
, Qtop
, "top", "Top", RES_TYPE_NUMBER
);
1979 FRAME_W32_WINDOW (f
) = hwnd
1980 = CreateWindow (EMACS_CLASS
,
1982 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
1983 EQ (left
, Qunbound
) ? CW_USEDEFAULT
: XINT (left
),
1984 EQ (top
, Qunbound
) ? CW_USEDEFAULT
: XINT (top
),
1985 rect
.right
- rect
.left
,
1986 rect
.bottom
- rect
.top
,
1994 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
1995 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
1996 SetWindowLong (hwnd
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
1997 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->scroll_bar_actual_width
);
1998 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
2000 /* Enable drag-n-drop. */
2001 DragAcceptFiles (hwnd
, TRUE
);
2003 /* Do this to discard the default setting specified by our parent. */
2004 ShowWindow (hwnd
, SW_HIDE
);
2006 /* Update frame positions. */
2007 GetWindowRect (hwnd
, &rect
);
2008 f
->left_pos
= rect
.left
;
2009 f
->top_pos
= rect
.top
;
2014 my_post_msg (W32Msg
* wmsg
, HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2016 wmsg
->msg
.hwnd
= hwnd
;
2017 wmsg
->msg
.message
= msg
;
2018 wmsg
->msg
.wParam
= wParam
;
2019 wmsg
->msg
.lParam
= lParam
;
2020 wmsg
->msg
.time
= GetMessageTime ();
2025 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
2026 between left and right keys as advertised. We test for this
2027 support dynamically, and set a flag when the support is absent. If
2028 absent, we keep track of the left and right control and alt keys
2029 ourselves. This is particularly necessary on keyboards that rely
2030 upon the AltGr key, which is represented as having the left control
2031 and right alt keys pressed. For these keyboards, we need to know
2032 when the left alt key has been pressed in addition to the AltGr key
2033 so that we can properly support M-AltGr-key sequences (such as M-@
2034 on Swedish keyboards). */
2036 #define EMACS_LCONTROL 0
2037 #define EMACS_RCONTROL 1
2038 #define EMACS_LMENU 2
2039 #define EMACS_RMENU 3
2041 static int modifiers
[4];
2042 static int modifiers_recorded
;
2043 static int modifier_key_support_tested
;
2046 test_modifier_support (unsigned int wparam
)
2050 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
2052 if (wparam
== VK_CONTROL
)
2062 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
2063 modifiers_recorded
= 1;
2065 modifiers_recorded
= 0;
2066 modifier_key_support_tested
= 1;
2070 record_keydown (unsigned int wparam
, unsigned int lparam
)
2074 if (!modifier_key_support_tested
)
2075 test_modifier_support (wparam
);
2077 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2080 if (wparam
== VK_CONTROL
)
2081 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2083 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2089 record_keyup (unsigned int wparam
, unsigned int lparam
)
2093 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2096 if (wparam
== VK_CONTROL
)
2097 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2099 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2104 /* Emacs can lose focus while a modifier key has been pressed. When
2105 it regains focus, be conservative and clear all modifiers since
2106 we cannot reconstruct the left and right modifier state. */
2108 reset_modifiers (void)
2112 if (GetFocus () == NULL
)
2113 /* Emacs doesn't have keyboard focus. Do nothing. */
2116 ctrl
= GetAsyncKeyState (VK_CONTROL
);
2117 alt
= GetAsyncKeyState (VK_MENU
);
2119 if (!(ctrl
& 0x08000))
2120 /* Clear any recorded control modifier state. */
2121 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2123 if (!(alt
& 0x08000))
2124 /* Clear any recorded alt modifier state. */
2125 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2127 /* Update the state of all modifier keys, because modifiers used in
2128 hot-key combinations can get stuck on if Emacs loses focus as a
2129 result of a hot-key being pressed. */
2133 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
2135 GetKeyboardState (keystate
);
2136 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
2137 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
2138 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
2139 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
2140 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
2141 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
2142 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
2143 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
2144 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
2145 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
2146 SetKeyboardState (keystate
);
2150 /* Synchronize modifier state with what is reported with the current
2151 keystroke. Even if we cannot distinguish between left and right
2152 modifier keys, we know that, if no modifiers are set, then neither
2153 the left or right modifier should be set. */
2155 sync_modifiers (void)
2157 if (!modifiers_recorded
)
2160 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
2161 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2163 if (!(GetKeyState (VK_MENU
) & 0x8000))
2164 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2168 modifier_set (int vkey
)
2170 if (vkey
== VK_CAPITAL
|| vkey
== VK_SCROLL
)
2171 return (GetKeyState (vkey
) & 0x1);
2172 if (!modifiers_recorded
)
2173 return (GetKeyState (vkey
) & 0x8000);
2178 return modifiers
[EMACS_LCONTROL
];
2180 return modifiers
[EMACS_RCONTROL
];
2182 return modifiers
[EMACS_LMENU
];
2184 return modifiers
[EMACS_RMENU
];
2186 return (GetKeyState (vkey
) & 0x8000);
2189 /* Convert between the modifier bits W32 uses and the modifier bits
2193 w32_key_to_modifier (int key
)
2195 Lisp_Object key_mapping
;
2200 key_mapping
= Vw32_lwindow_modifier
;
2203 key_mapping
= Vw32_rwindow_modifier
;
2206 key_mapping
= Vw32_apps_modifier
;
2209 key_mapping
= Vw32_scroll_lock_modifier
;
2215 /* NB. This code runs in the input thread, asychronously to the lisp
2216 thread, so we must be careful to ensure access to lisp data is
2217 thread-safe. The following code is safe because the modifier
2218 variable values are updated atomically from lisp and symbols are
2219 not relocated by GC. Also, we don't have to worry about seeing GC
2221 if (EQ (key_mapping
, Qhyper
))
2222 return hyper_modifier
;
2223 if (EQ (key_mapping
, Qsuper
))
2224 return super_modifier
;
2225 if (EQ (key_mapping
, Qmeta
))
2226 return meta_modifier
;
2227 if (EQ (key_mapping
, Qalt
))
2228 return alt_modifier
;
2229 if (EQ (key_mapping
, Qctrl
))
2230 return ctrl_modifier
;
2231 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
2232 return ctrl_modifier
;
2233 if (EQ (key_mapping
, Qshift
))
2234 return shift_modifier
;
2236 /* Don't generate any modifier if not explicitly requested. */
2241 w32_get_modifiers (void)
2243 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
2244 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
2245 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
2246 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
2247 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
2248 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
2249 (modifier_set (VK_MENU
) ?
2250 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
2253 /* We map the VK_* modifiers into console modifier constants
2254 so that we can use the same routines to handle both console
2255 and window input. */
2258 construct_console_modifiers (void)
2263 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
2264 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
2265 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
2266 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
2267 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
2268 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
2269 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
2270 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
2271 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
2272 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
2273 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
2279 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
2283 /* Convert to emacs modifiers. */
2284 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
2290 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
2292 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
2295 if (virt_key
== VK_RETURN
)
2296 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
2298 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
2299 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
2301 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
2302 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
2304 if (virt_key
== VK_CLEAR
)
2305 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
2310 /* List of special key combinations which w32 would normally capture,
2311 but Emacs should grab instead. Not directly visible to lisp, to
2312 simplify synchronization. Each item is an integer encoding a virtual
2313 key code and modifier combination to capture. */
2314 static Lisp_Object w32_grabbed_keys
;
2316 #define HOTKEY(vk, mods) make_number (((vk) & 255) | ((mods) << 8))
2317 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
2318 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
2319 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
2321 #define RAW_HOTKEY_ID(k) ((k) & 0xbfff)
2322 #define RAW_HOTKEY_VK_CODE(k) ((k) & 255)
2323 #define RAW_HOTKEY_MODIFIERS(k) ((k) >> 8)
2325 /* Register hot-keys for reserved key combinations when Emacs has
2326 keyboard focus, since this is the only way Emacs can receive key
2327 combinations like Alt-Tab which are used by the system. */
2330 register_hot_keys (HWND hwnd
)
2332 Lisp_Object keylist
;
2334 /* Use CONSP, since we are called asynchronously. */
2335 for (keylist
= w32_grabbed_keys
; CONSP (keylist
); keylist
= XCDR (keylist
))
2337 Lisp_Object key
= XCAR (keylist
);
2339 /* Deleted entries get set to nil. */
2340 if (!INTEGERP (key
))
2343 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
2344 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
2349 unregister_hot_keys (HWND hwnd
)
2351 Lisp_Object keylist
;
2353 for (keylist
= w32_grabbed_keys
; CONSP (keylist
); keylist
= XCDR (keylist
))
2355 Lisp_Object key
= XCAR (keylist
);
2357 if (!INTEGERP (key
))
2360 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
2364 /* Main message dispatch loop. */
2367 w32_msg_pump (deferred_msg
* msg_buf
)
2373 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
2375 while (GetMessage (&msg
, NULL
, 0, 0))
2377 if (msg
.hwnd
== NULL
)
2379 switch (msg
.message
)
2382 /* Produced by complete_deferred_msg; just ignore. */
2384 case WM_EMACS_CREATEWINDOW
:
2385 /* Initialize COM for this window. Even though we don't use it,
2386 some third party shell extensions can cause it to be used in
2387 system dialogs, which causes a crash if it is not initialized.
2388 This is a known bug in Windows, which was fixed long ago, but
2389 the patch for XP is not publically available until XP SP3,
2390 and older versions will never be patched. */
2391 CoInitialize (NULL
);
2392 w32_createwindow ((struct frame
*) msg
.wParam
);
2393 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2396 case WM_EMACS_SETLOCALE
:
2397 SetThreadLocale (msg
.wParam
);
2398 /* Reply is not expected. */
2400 case WM_EMACS_SETKEYBOARDLAYOUT
:
2401 result
= (int) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
2402 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2406 case WM_EMACS_REGISTER_HOT_KEY
:
2407 focus_window
= GetFocus ();
2408 if (focus_window
!= NULL
)
2409 RegisterHotKey (focus_window
,
2410 RAW_HOTKEY_ID (msg
.wParam
),
2411 RAW_HOTKEY_MODIFIERS (msg
.wParam
),
2412 RAW_HOTKEY_VK_CODE (msg
.wParam
));
2413 /* Reply is not expected. */
2415 case WM_EMACS_UNREGISTER_HOT_KEY
:
2416 focus_window
= GetFocus ();
2417 if (focus_window
!= NULL
)
2418 UnregisterHotKey (focus_window
, RAW_HOTKEY_ID (msg
.wParam
));
2419 /* Mark item as erased. NB: this code must be
2420 thread-safe. The next line is okay because the cons
2421 cell is never made into garbage and is not relocated by
2423 XSETCAR ((Lisp_Object
) ((EMACS_INT
) msg
.lParam
), Qnil
);
2424 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2427 case WM_EMACS_TOGGLE_LOCK_KEY
:
2429 int vk_code
= (int) msg
.wParam
;
2430 int cur_state
= (GetKeyState (vk_code
) & 1);
2431 Lisp_Object new_state
= (Lisp_Object
) ((EMACS_INT
) msg
.lParam
);
2433 /* NB: This code must be thread-safe. It is safe to
2434 call NILP because symbols are not relocated by GC,
2435 and pointer here is not touched by GC (so the markbit
2436 can't be set). Numbers are safe because they are
2437 immediate values. */
2438 if (NILP (new_state
)
2439 || (NUMBERP (new_state
)
2440 && ((XUINT (new_state
)) & 1) != cur_state
))
2442 one_w32_display_info
.faked_key
= vk_code
;
2444 keybd_event ((BYTE
) vk_code
,
2445 (BYTE
) MapVirtualKey (vk_code
, 0),
2446 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2447 keybd_event ((BYTE
) vk_code
,
2448 (BYTE
) MapVirtualKey (vk_code
, 0),
2449 KEYEVENTF_EXTENDEDKEY
| 0, 0);
2450 keybd_event ((BYTE
) vk_code
,
2451 (BYTE
) MapVirtualKey (vk_code
, 0),
2452 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2453 cur_state
= !cur_state
;
2455 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2461 /* Broadcast messages make it here, so you need to be looking
2462 for something in particular for this to be useful. */
2464 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
2470 DispatchMessage (&msg
);
2473 /* Exit nested loop when our deferred message has completed. */
2474 if (msg_buf
->completed
)
2479 deferred_msg
* deferred_msg_head
;
2481 static deferred_msg
*
2482 find_deferred_msg (HWND hwnd
, UINT msg
)
2484 deferred_msg
* item
;
2486 /* Don't actually need synchronization for read access, since
2487 modification of single pointer is always atomic. */
2488 /* enter_crit (); */
2490 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2491 if (item
->w32msg
.msg
.hwnd
== hwnd
2492 && item
->w32msg
.msg
.message
== msg
)
2495 /* leave_crit (); */
2501 send_deferred_msg (deferred_msg
* msg_buf
,
2507 /* Only input thread can send deferred messages. */
2508 if (GetCurrentThreadId () != dwWindowsThreadId
)
2511 /* It is an error to send a message that is already deferred. */
2512 if (find_deferred_msg (hwnd
, msg
) != NULL
)
2515 /* Enforced synchronization is not needed because this is the only
2516 function that alters deferred_msg_head, and the following critical
2517 section is guaranteed to only be serially reentered (since only the
2518 input thread can call us). */
2520 /* enter_crit (); */
2522 msg_buf
->completed
= 0;
2523 msg_buf
->next
= deferred_msg_head
;
2524 deferred_msg_head
= msg_buf
;
2525 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
2527 /* leave_crit (); */
2529 /* Start a new nested message loop to process other messages until
2530 this one is completed. */
2531 w32_msg_pump (msg_buf
);
2533 deferred_msg_head
= msg_buf
->next
;
2535 return msg_buf
->result
;
2539 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
2541 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
2543 if (msg_buf
== NULL
)
2544 /* Message may have been cancelled, so don't abort. */
2547 msg_buf
->result
= result
;
2548 msg_buf
->completed
= 1;
2550 /* Ensure input thread is woken so it notices the completion. */
2551 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2555 cancel_all_deferred_msgs (void)
2557 deferred_msg
* item
;
2559 /* Don't actually need synchronization for read access, since
2560 modification of single pointer is always atomic. */
2561 /* enter_crit (); */
2563 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2566 item
->completed
= 1;
2569 /* leave_crit (); */
2571 /* Ensure input thread is woken so it notices the completion. */
2572 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2576 w32_msg_worker (void *arg
)
2579 deferred_msg dummy_buf
;
2581 /* Ensure our message queue is created */
2583 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
2585 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2588 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
2589 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
2590 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
2592 /* This is the initial message loop which should only exit when the
2593 application quits. */
2594 w32_msg_pump (&dummy_buf
);
2600 signal_user_input (void)
2602 /* Interrupt any lisp that wants to be interrupted by input. */
2603 if (!NILP (Vthrow_on_input
))
2605 Vquit_flag
= Vthrow_on_input
;
2606 /* If we're inside a function that wants immediate quits,
2608 if (immediate_quit
&& NILP (Vinhibit_quit
))
2618 post_character_message (HWND hwnd
, UINT msg
,
2619 WPARAM wParam
, LPARAM lParam
,
2624 wmsg
.dwModifiers
= modifiers
;
2626 /* Detect quit_char and set quit-flag directly. Note that we
2627 still need to post a message to ensure the main thread will be
2628 woken up if blocked in sys_select, but we do NOT want to post
2629 the quit_char message itself (because it will usually be as if
2630 the user had typed quit_char twice). Instead, we post a dummy
2631 message that has no particular effect. */
2634 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
2635 c
= make_ctrl_char (c
) & 0377;
2637 || (wmsg
.dwModifiers
== 0 &&
2638 w32_quit_key
&& wParam
== w32_quit_key
))
2642 /* The choice of message is somewhat arbitrary, as long as
2643 the main thread handler just ignores it. */
2646 /* Interrupt any blocking system calls. */
2649 /* As a safety precaution, forcibly complete any deferred
2650 messages. This is a kludge, but I don't see any particularly
2651 clean way to handle the situation where a deferred message is
2652 "dropped" in the lisp thread, and will thus never be
2653 completed, eg. by the user trying to activate the menubar
2654 when the lisp thread is busy, and then typing C-g when the
2655 menubar doesn't open promptly (with the result that the
2656 menubar never responds at all because the deferred
2657 WM_INITMENU message is never completed). Another problem
2658 situation is when the lisp thread calls SendMessage (to send
2659 a window manager command) when a message has been deferred;
2660 the lisp thread gets blocked indefinitely waiting for the
2661 deferred message to be completed, which itself is waiting for
2662 the lisp thread to respond.
2664 Note that we don't want to block the input thread waiting for
2665 a reponse from the lisp thread (although that would at least
2666 solve the deadlock problem above), because we want to be able
2667 to receive C-g to interrupt the lisp thread. */
2668 cancel_all_deferred_msgs ();
2671 signal_user_input ();
2674 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2677 /* Main window procedure */
2680 w32_wnd_proc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2683 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
2685 int windows_translate
;
2688 /* Note that it is okay to call x_window_to_frame, even though we are
2689 not running in the main lisp thread, because frame deletion
2690 requires the lisp thread to synchronize with this thread. Thus, if
2691 a frame struct is returned, it can be used without concern that the
2692 lisp thread might make it disappear while we are using it.
2694 NB. Walking the frame list in this thread is safe (as long as
2695 writes of Lisp_Object slots are atomic, which they are on Windows).
2696 Although delete-frame can destructively modify the frame list while
2697 we are walking it, a garbage collection cannot occur until after
2698 delete-frame has synchronized with this thread.
2700 It is also safe to use functions that make GDI calls, such as
2701 w32_clear_rect, because these functions must obtain a DC handle
2702 from the frame struct using get_frame_dc which is thread-aware. */
2707 f
= x_window_to_frame (dpyinfo
, hwnd
);
2710 HDC hdc
= get_frame_dc (f
);
2711 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
2712 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
2713 release_frame_dc (f
, hdc
);
2715 #if defined (W32_DEBUG_DISPLAY)
2716 DebPrint (("WM_ERASEBKGND (frame %p): erasing %d,%d-%d,%d\n",
2718 wmsg
.rect
.left
, wmsg
.rect
.top
,
2719 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2720 #endif /* W32_DEBUG_DISPLAY */
2723 case WM_PALETTECHANGED
:
2724 /* ignore our own changes */
2725 if ((HWND
)wParam
!= hwnd
)
2727 f
= x_window_to_frame (dpyinfo
, hwnd
);
2729 /* get_frame_dc will realize our palette and force all
2730 frames to be redrawn if needed. */
2731 release_frame_dc (f
, get_frame_dc (f
));
2736 PAINTSTRUCT paintStruct
;
2738 memset (&update_rect
, 0, sizeof (update_rect
));
2740 f
= x_window_to_frame (dpyinfo
, hwnd
);
2743 DebPrint (("WM_PAINT received for unknown window %p\n", hwnd
));
2747 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
2748 fails. Apparently this can happen under some
2750 if (GetUpdateRect (hwnd
, &update_rect
, FALSE
) || !w32_strict_painting
)
2753 BeginPaint (hwnd
, &paintStruct
);
2755 /* The rectangles returned by GetUpdateRect and BeginPaint
2756 do not always match. Play it safe by assuming both areas
2758 UnionRect (&(wmsg
.rect
), &update_rect
, &(paintStruct
.rcPaint
));
2760 #if defined (W32_DEBUG_DISPLAY)
2761 DebPrint (("WM_PAINT (frame %p): painting %d,%d-%d,%d\n",
2763 wmsg
.rect
.left
, wmsg
.rect
.top
,
2764 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2765 DebPrint ((" [update region is %d,%d-%d,%d]\n",
2766 update_rect
.left
, update_rect
.top
,
2767 update_rect
.right
, update_rect
.bottom
));
2769 EndPaint (hwnd
, &paintStruct
);
2772 /* Change the message type to prevent Windows from
2773 combining WM_PAINT messages in the Lisp thread's queue,
2774 since Windows assumes that each message queue is
2775 dedicated to one frame and does not bother checking
2776 that hwnd matches before combining them. */
2777 my_post_msg (&wmsg
, hwnd
, WM_EMACS_PAINT
, wParam
, lParam
);
2782 /* If GetUpdateRect returns 0 (meaning there is no update
2783 region), assume the whole window needs to be repainted. */
2784 GetClientRect (hwnd
, &wmsg
.rect
);
2785 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2789 case WM_INPUTLANGCHANGE
:
2790 /* Inform lisp thread of keyboard layout changes. */
2791 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2793 /* Clear dead keys in the keyboard state; for simplicity only
2794 preserve modifier key states. */
2799 GetKeyboardState (keystate
);
2800 for (i
= 0; i
< 256; i
++)
2817 SetKeyboardState (keystate
);
2822 /* Synchronize hot keys with normal input. */
2823 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
2828 record_keyup (wParam
, lParam
);
2833 /* Ignore keystrokes we fake ourself; see below. */
2834 if (dpyinfo
->faked_key
== wParam
)
2836 dpyinfo
->faked_key
= 0;
2837 /* Make sure TranslateMessage sees them though (as long as
2838 they don't produce WM_CHAR messages). This ensures that
2839 indicator lights are toggled promptly on Windows 9x, for
2841 if (wParam
< 256 && lispy_function_keys
[wParam
])
2843 windows_translate
= 1;
2849 /* Synchronize modifiers with current keystroke. */
2851 record_keydown (wParam
, lParam
);
2852 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
2854 windows_translate
= 0;
2859 if (NILP (Vw32_pass_lwindow_to_system
))
2861 /* Prevent system from acting on keyup (which opens the
2862 Start menu if no other key was pressed) by simulating a
2863 press of Space which we will ignore. */
2864 if (GetAsyncKeyState (wParam
) & 1)
2866 if (NUMBERP (Vw32_phantom_key_code
))
2867 key
= XUINT (Vw32_phantom_key_code
) & 255;
2870 dpyinfo
->faked_key
= key
;
2871 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
2874 if (!NILP (Vw32_lwindow_modifier
))
2878 if (NILP (Vw32_pass_rwindow_to_system
))
2880 if (GetAsyncKeyState (wParam
) & 1)
2882 if (NUMBERP (Vw32_phantom_key_code
))
2883 key
= XUINT (Vw32_phantom_key_code
) & 255;
2886 dpyinfo
->faked_key
= key
;
2887 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
2890 if (!NILP (Vw32_rwindow_modifier
))
2894 if (!NILP (Vw32_apps_modifier
))
2898 if (NILP (Vw32_pass_alt_to_system
))
2899 /* Prevent DefWindowProc from activating the menu bar if an
2900 Alt key is pressed and released by itself. */
2902 windows_translate
= 1;
2905 /* Decide whether to treat as modifier or function key. */
2906 if (NILP (Vw32_enable_caps_lock
))
2907 goto disable_lock_key
;
2908 windows_translate
= 1;
2911 /* Decide whether to treat as modifier or function key. */
2912 if (NILP (Vw32_enable_num_lock
))
2913 goto disable_lock_key
;
2914 windows_translate
= 1;
2917 /* Decide whether to treat as modifier or function key. */
2918 if (NILP (Vw32_scroll_lock_modifier
))
2919 goto disable_lock_key
;
2920 windows_translate
= 1;
2923 /* Ensure the appropriate lock key state (and indicator light)
2924 remains in the same state. We do this by faking another
2925 press of the relevant key. Apparently, this really is the
2926 only way to toggle the state of the indicator lights. */
2927 dpyinfo
->faked_key
= wParam
;
2928 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
2929 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2930 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
2931 KEYEVENTF_EXTENDEDKEY
| 0, 0);
2932 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
2933 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2934 /* Ensure indicator lights are updated promptly on Windows 9x
2935 (TranslateMessage apparently does this), after forwarding
2937 post_character_message (hwnd
, msg
, wParam
, lParam
,
2938 w32_get_key_modifiers (wParam
, lParam
));
2939 windows_translate
= 1;
2943 case VK_PROCESSKEY
: /* Generated by IME. */
2944 windows_translate
= 1;
2947 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
2948 which is confusing for purposes of key binding; convert
2949 VK_CANCEL events into VK_PAUSE events. */
2953 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
2954 for purposes of key binding; convert these back into
2955 VK_NUMLOCK events, at least when we want to see NumLock key
2956 presses. (Note that there is never any possibility that
2957 VK_PAUSE with Ctrl really is C-Pause as per above.) */
2958 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
2959 wParam
= VK_NUMLOCK
;
2962 /* If not defined as a function key, change it to a WM_CHAR message. */
2963 if (wParam
> 255 || !lispy_function_keys
[wParam
])
2965 DWORD modifiers
= construct_console_modifiers ();
2967 if (!NILP (Vw32_recognize_altgr
)
2968 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
2970 /* Always let TranslateMessage handle AltGr key chords;
2971 for some reason, ToAscii doesn't always process AltGr
2972 chords correctly. */
2973 windows_translate
= 1;
2975 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
2977 /* Handle key chords including any modifiers other
2978 than shift directly, in order to preserve as much
2979 modifier information as possible. */
2980 if ('A' <= wParam
&& wParam
<= 'Z')
2982 /* Don't translate modified alphabetic keystrokes,
2983 so the user doesn't need to constantly switch
2984 layout to type control or meta keystrokes when
2985 the normal layout translates alphabetic
2986 characters to non-ascii characters. */
2987 if (!modifier_set (VK_SHIFT
))
2988 wParam
+= ('a' - 'A');
2993 /* Try to handle other keystrokes by determining the
2994 base character (ie. translating the base key plus
2998 KEY_EVENT_RECORD key
;
3000 key
.bKeyDown
= TRUE
;
3001 key
.wRepeatCount
= 1;
3002 key
.wVirtualKeyCode
= wParam
;
3003 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
3004 key
.uChar
.AsciiChar
= 0;
3005 key
.dwControlKeyState
= modifiers
;
3007 add
= w32_kbd_patch_key (&key
);
3008 /* 0 means an unrecognised keycode, negative means
3009 dead key. Ignore both. */
3012 /* Forward asciified character sequence. */
3013 post_character_message
3015 (unsigned char) key
.uChar
.AsciiChar
, lParam
,
3016 w32_get_key_modifiers (wParam
, lParam
));
3017 w32_kbd_patch_key (&key
);
3024 /* Let TranslateMessage handle everything else. */
3025 windows_translate
= 1;
3031 if (windows_translate
)
3033 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
3034 windows_msg
.time
= GetMessageTime ();
3035 TranslateMessage (&windows_msg
);
3043 post_character_message (hwnd
, msg
, wParam
, lParam
,
3044 w32_get_key_modifiers (wParam
, lParam
));
3048 /* WM_UNICHAR looks promising from the docs, but the exact
3049 circumstances in which TranslateMessage sends it is one of those
3050 Microsoft secret API things that EU and US courts are supposed
3051 to have put a stop to already. Spy++ shows it being sent to Notepad
3052 and other MS apps, but never to Emacs.
3054 Some third party IMEs send it in accordance with the official
3055 documentation though, so handle it here.
3057 UNICODE_NOCHAR is used to test for support for this message.
3058 TRUE indicates that the message is supported. */
3059 if (wParam
== UNICODE_NOCHAR
)
3064 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3065 signal_user_input ();
3066 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3071 /* If we can't get the IME result as unicode, use default processing,
3072 which will at least allow characters decodable in the system locale
3074 if (!get_composition_string_fn
)
3077 else if (!ignore_ime_char
)
3082 HIMC context
= get_ime_context_fn (hwnd
);
3083 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3084 /* Get buffer size. */
3085 size
= get_composition_string_fn (context
, GCS_RESULTSTR
, buffer
, 0);
3086 buffer
= alloca (size
);
3087 size
= get_composition_string_fn (context
, GCS_RESULTSTR
,
3089 release_ime_context_fn (hwnd
, context
);
3091 signal_user_input ();
3092 for (i
= 0; i
< size
/ sizeof (wchar_t); i
++)
3094 my_post_msg (&wmsg
, hwnd
, WM_UNICHAR
, (WPARAM
) buffer
[i
],
3097 /* Ignore the messages for the rest of the
3098 characters in the string that was output above. */
3099 ignore_ime_char
= (size
/ sizeof (wchar_t)) - 1;
3106 case WM_IME_STARTCOMPOSITION
:
3107 if (!set_ime_composition_window_fn
)
3111 COMPOSITIONFORM form
;
3118 f
= x_window_to_frame (dpyinfo
, hwnd
);
3119 w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
3121 form
.dwStyle
= CFS_RECT
;
3122 form
.ptCurrentPos
.x
= w32_system_caret_x
;
3123 form
.ptCurrentPos
.y
= w32_system_caret_y
;
3125 form
.rcArea
.left
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, 0);
3126 form
.rcArea
.top
= (WINDOW_TOP_EDGE_Y (w
)
3127 + WINDOW_HEADER_LINE_HEIGHT (w
));
3128 form
.rcArea
.right
= (WINDOW_BOX_RIGHT_EDGE_X (w
)
3129 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
3130 - WINDOW_RIGHT_FRINGE_WIDTH (w
));
3131 form
.rcArea
.bottom
= (WINDOW_BOTTOM_EDGE_Y (w
)
3132 - WINDOW_MODE_LINE_HEIGHT (w
));
3134 context
= get_ime_context_fn (hwnd
);
3135 set_ime_composition_window_fn (context
, &form
);
3136 release_ime_context_fn (hwnd
, context
);
3140 case WM_IME_ENDCOMPOSITION
:
3141 ignore_ime_char
= 0;
3144 /* Simulate middle mouse button events when left and right buttons
3145 are used together, but only if user has two button mouse. */
3146 case WM_LBUTTONDOWN
:
3147 case WM_RBUTTONDOWN
:
3148 if (w32_num_mouse_buttons
> 2)
3149 goto handle_plain_button
;
3152 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
3153 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
3155 if (button_state
& this)
3158 if (button_state
== 0)
3161 button_state
|= this;
3163 if (button_state
& other
)
3165 if (mouse_button_timer
)
3167 KillTimer (hwnd
, mouse_button_timer
);
3168 mouse_button_timer
= 0;
3170 /* Generate middle mouse event instead. */
3171 msg
= WM_MBUTTONDOWN
;
3172 button_state
|= MMOUSE
;
3174 else if (button_state
& MMOUSE
)
3176 /* Ignore button event if we've already generated a
3177 middle mouse down event. This happens if the
3178 user releases and press one of the two buttons
3179 after we've faked a middle mouse event. */
3184 /* Flush out saved message. */
3185 post_msg (&saved_mouse_button_msg
);
3187 wmsg
.dwModifiers
= w32_get_modifiers ();
3188 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3189 signal_user_input ();
3191 /* Clear message buffer. */
3192 saved_mouse_button_msg
.msg
.hwnd
= 0;
3196 /* Hold onto message for now. */
3197 mouse_button_timer
=
3198 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
3199 w32_mouse_button_tolerance
, NULL
);
3200 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
3201 saved_mouse_button_msg
.msg
.message
= msg
;
3202 saved_mouse_button_msg
.msg
.wParam
= wParam
;
3203 saved_mouse_button_msg
.msg
.lParam
= lParam
;
3204 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
3205 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
3212 if (w32_num_mouse_buttons
> 2)
3213 goto handle_plain_button
;
3216 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
3217 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
3219 if ((button_state
& this) == 0)
3222 button_state
&= ~this;
3224 if (button_state
& MMOUSE
)
3226 /* Only generate event when second button is released. */
3227 if ((button_state
& other
) == 0)
3230 button_state
&= ~MMOUSE
;
3232 if (button_state
) abort ();
3239 /* Flush out saved message if necessary. */
3240 if (saved_mouse_button_msg
.msg
.hwnd
)
3242 post_msg (&saved_mouse_button_msg
);
3245 wmsg
.dwModifiers
= w32_get_modifiers ();
3246 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3247 signal_user_input ();
3249 /* Always clear message buffer and cancel timer. */
3250 saved_mouse_button_msg
.msg
.hwnd
= 0;
3251 KillTimer (hwnd
, mouse_button_timer
);
3252 mouse_button_timer
= 0;
3254 if (button_state
== 0)
3259 case WM_XBUTTONDOWN
:
3261 if (w32_pass_extra_mouse_buttons_to_system
)
3263 /* else fall through and process them. */
3264 case WM_MBUTTONDOWN
:
3266 handle_plain_button
:
3271 /* Ignore middle and extra buttons as long as the menu is active. */
3272 f
= x_window_to_frame (dpyinfo
, hwnd
);
3273 if (f
&& f
->output_data
.w32
->menubar_active
)
3276 if (parse_button (msg
, HIWORD (wParam
), &button
, &up
))
3278 if (up
) ReleaseCapture ();
3279 else SetCapture (hwnd
);
3280 button
= (button
== 0) ? LMOUSE
:
3281 ((button
== 1) ? MMOUSE
: RMOUSE
);
3283 button_state
&= ~button
;
3285 button_state
|= button
;
3289 wmsg
.dwModifiers
= w32_get_modifiers ();
3290 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3291 signal_user_input ();
3293 /* Need to return true for XBUTTON messages, false for others,
3294 to indicate that we processed the message. */
3295 return (msg
== WM_XBUTTONDOWN
|| msg
== WM_XBUTTONUP
);
3298 /* Ignore mouse movements as long as the menu is active. These
3299 movements are processed by the window manager anyway, and
3300 it's wrong to handle them as if they happened on the
3301 underlying frame. */
3302 f
= x_window_to_frame (dpyinfo
, hwnd
);
3303 if (f
&& f
->output_data
.w32
->menubar_active
)
3306 /* If the mouse has just moved into the frame, start tracking
3307 it, so we will be notified when it leaves the frame. Mouse
3308 tracking only works under W98 and NT4 and later. On earlier
3309 versions, there is no way of telling when the mouse leaves the
3310 frame, so we just have to put up with help-echo and mouse
3311 highlighting remaining while the frame is not active. */
3312 if (track_mouse_event_fn
&& !track_mouse_window
)
3314 TRACKMOUSEEVENT tme
;
3315 tme
.cbSize
= sizeof (tme
);
3316 tme
.dwFlags
= TME_LEAVE
;
3317 tme
.hwndTrack
= hwnd
;
3319 track_mouse_event_fn (&tme
);
3320 track_mouse_window
= hwnd
;
3323 if (w32_mouse_move_interval
<= 0
3324 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
3326 wmsg
.dwModifiers
= w32_get_modifiers ();
3327 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3331 /* Hang onto mouse move and scroll messages for a bit, to avoid
3332 sending such events to Emacs faster than it can process them.
3333 If we get more events before the timer from the first message
3334 expires, we just replace the first message. */
3336 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
3338 SetTimer (hwnd
, MOUSE_MOVE_ID
,
3339 w32_mouse_move_interval
, NULL
);
3341 /* Hold onto message for now. */
3342 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
3343 saved_mouse_move_msg
.msg
.message
= msg
;
3344 saved_mouse_move_msg
.msg
.wParam
= wParam
;
3345 saved_mouse_move_msg
.msg
.lParam
= lParam
;
3346 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
3347 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
3353 wmsg
.dwModifiers
= w32_get_modifiers ();
3354 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3355 signal_user_input ();
3359 if (w32_pass_multimedia_buttons_to_system
)
3361 /* Otherwise, pass to lisp, the same way we do with mousehwheel. */
3362 case WM_MOUSEHWHEEL
:
3363 wmsg
.dwModifiers
= w32_get_modifiers ();
3364 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3365 signal_user_input ();
3366 /* Non-zero must be returned when WM_MOUSEHWHEEL messages are
3367 handled, to prevent the system trying to handle it by faking
3368 scroll bar events. */
3372 /* Flush out saved messages if necessary. */
3373 if (wParam
== mouse_button_timer
)
3375 if (saved_mouse_button_msg
.msg
.hwnd
)
3377 post_msg (&saved_mouse_button_msg
);
3378 signal_user_input ();
3379 saved_mouse_button_msg
.msg
.hwnd
= 0;
3381 KillTimer (hwnd
, mouse_button_timer
);
3382 mouse_button_timer
= 0;
3384 else if (wParam
== mouse_move_timer
)
3386 if (saved_mouse_move_msg
.msg
.hwnd
)
3388 post_msg (&saved_mouse_move_msg
);
3389 saved_mouse_move_msg
.msg
.hwnd
= 0;
3391 KillTimer (hwnd
, mouse_move_timer
);
3392 mouse_move_timer
= 0;
3394 else if (wParam
== menu_free_timer
)
3396 KillTimer (hwnd
, menu_free_timer
);
3397 menu_free_timer
= 0;
3398 f
= x_window_to_frame (dpyinfo
, hwnd
);
3399 /* If a popup menu is active, don't wipe its strings. */
3401 && current_popup_menu
== NULL
)
3403 /* Free memory used by owner-drawn and help-echo strings. */
3404 w32_free_menu_strings (hwnd
);
3405 f
->output_data
.w32
->menubar_active
= 0;
3409 else if (wParam
== hourglass_timer
)
3411 KillTimer (hwnd
, hourglass_timer
);
3412 hourglass_timer
= 0;
3413 w32_show_hourglass (x_window_to_frame (dpyinfo
, hwnd
));
3418 /* Windows doesn't send us focus messages when putting up and
3419 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
3420 The only indication we get that something happened is receiving
3421 this message afterwards. So this is a good time to reset our
3422 keyboard modifiers' state. */
3429 /* We must ensure menu bar is fully constructed and up to date
3430 before allowing user interaction with it. To achieve this
3431 we send this message to the lisp thread and wait for a
3432 reply (whose value is not actually needed) to indicate that
3433 the menu bar is now ready for use, so we can now return.
3435 To remain responsive in the meantime, we enter a nested message
3436 loop that can process all other messages.
3438 However, we skip all this if the message results from calling
3439 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
3440 thread a message because it is blocked on us at this point. We
3441 set menubar_active before calling TrackPopupMenu to indicate
3442 this (there is no possibility of confusion with real menubar
3445 f
= x_window_to_frame (dpyinfo
, hwnd
);
3447 && (f
->output_data
.w32
->menubar_active
3448 /* We can receive this message even in the absence of a
3449 menubar (ie. when the system menu is activated) - in this
3450 case we do NOT want to forward the message, otherwise it
3451 will cause the menubar to suddenly appear when the user
3452 had requested it to be turned off! */
3453 || f
->output_data
.w32
->menubar_widget
== NULL
))
3457 deferred_msg msg_buf
;
3459 /* Detect if message has already been deferred; in this case
3460 we cannot return any sensible value to ignore this. */
3461 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3466 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
3469 case WM_EXITMENULOOP
:
3470 f
= x_window_to_frame (dpyinfo
, hwnd
);
3472 /* If a menu is still active, check again after a short delay,
3473 since Windows often (always?) sends the WM_EXITMENULOOP
3474 before the corresponding WM_COMMAND message.
3475 Don't do this if a popup menu is active, since it is only
3476 menubar menus that require cleaning up in this way.
3478 if (f
&& menubar_in_use
&& current_popup_menu
== NULL
)
3479 menu_free_timer
= SetTimer (hwnd
, MENU_FREE_ID
, MENU_FREE_DELAY
, NULL
);
3481 /* If hourglass cursor should be displayed, display it now. */
3482 if (f
&& f
->output_data
.w32
->hourglass_p
)
3483 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
3488 /* Direct handling of help_echo in menus. Should be safe now
3489 that we generate the help_echo by placing a help event in the
3492 HMENU menu
= (HMENU
) lParam
;
3493 UINT menu_item
= (UINT
) LOWORD (wParam
);
3494 UINT flags
= (UINT
) HIWORD (wParam
);
3496 w32_menu_display_help (hwnd
, menu
, menu_item
, flags
);
3500 case WM_MEASUREITEM
:
3501 f
= x_window_to_frame (dpyinfo
, hwnd
);
3504 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
3506 if (pMis
->CtlType
== ODT_MENU
)
3508 /* Work out dimensions for popup menu titles. */
3509 char * title
= (char *) pMis
->itemData
;
3510 HDC hdc
= GetDC (hwnd
);
3511 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3512 LOGFONT menu_logfont
;
3516 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3517 menu_logfont
.lfWeight
= FW_BOLD
;
3518 menu_font
= CreateFontIndirect (&menu_logfont
);
3519 old_font
= SelectObject (hdc
, menu_font
);
3521 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
3524 if (unicode_append_menu
)
3525 GetTextExtentPoint32W (hdc
, (WCHAR
*) title
,
3526 wcslen ((WCHAR
*) title
),
3529 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
3531 pMis
->itemWidth
= size
.cx
;
3532 if (pMis
->itemHeight
< size
.cy
)
3533 pMis
->itemHeight
= size
.cy
;
3536 pMis
->itemWidth
= 0;
3538 SelectObject (hdc
, old_font
);
3539 DeleteObject (menu_font
);
3540 ReleaseDC (hwnd
, hdc
);
3547 f
= x_window_to_frame (dpyinfo
, hwnd
);
3550 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
3552 if (pDis
->CtlType
== ODT_MENU
)
3554 /* Draw popup menu title. */
3555 char * title
= (char *) pDis
->itemData
;
3558 HDC hdc
= pDis
->hDC
;
3559 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3560 LOGFONT menu_logfont
;
3563 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3564 menu_logfont
.lfWeight
= FW_BOLD
;
3565 menu_font
= CreateFontIndirect (&menu_logfont
);
3566 old_font
= SelectObject (hdc
, menu_font
);
3568 /* Always draw title as if not selected. */
3569 if (unicode_append_menu
)
3572 + GetSystemMetrics (SM_CXMENUCHECK
),
3574 ETO_OPAQUE
, &pDis
->rcItem
,
3576 wcslen ((WCHAR
*) title
), NULL
);
3580 + GetSystemMetrics (SM_CXMENUCHECK
),
3582 ETO_OPAQUE
, &pDis
->rcItem
,
3583 title
, strlen (title
), NULL
);
3585 SelectObject (hdc
, old_font
);
3586 DeleteObject (menu_font
);
3594 /* Still not right - can't distinguish between clicks in the
3595 client area of the frame from clicks forwarded from the scroll
3596 bars - may have to hook WM_NCHITTEST to remember the mouse
3597 position and then check if it is in the client area ourselves. */
3598 case WM_MOUSEACTIVATE
:
3599 /* Discard the mouse click that activates a frame, allowing the
3600 user to click anywhere without changing point (or worse!).
3601 Don't eat mouse clicks on scrollbars though!! */
3602 if (LOWORD (lParam
) == HTCLIENT
)
3603 return MA_ACTIVATEANDEAT
;
3608 /* No longer tracking mouse. */
3609 track_mouse_window
= NULL
;
3611 case WM_ACTIVATEAPP
:
3613 case WM_WINDOWPOSCHANGED
:
3615 /* Inform lisp thread that a frame might have just been obscured
3616 or exposed, so should recheck visibility of all frames. */
3617 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3621 dpyinfo
->faked_key
= 0;
3623 register_hot_keys (hwnd
);
3626 unregister_hot_keys (hwnd
);
3629 /* Relinquish the system caret. */
3630 if (w32_system_caret_hwnd
)
3632 w32_visible_system_caret_hwnd
= NULL
;
3633 w32_system_caret_hwnd
= NULL
;
3639 f
= x_window_to_frame (dpyinfo
, hwnd
);
3640 if (f
&& HIWORD (wParam
) == 0)
3642 if (menu_free_timer
)
3644 KillTimer (hwnd
, menu_free_timer
);
3645 menu_free_timer
= 0;
3651 wmsg
.dwModifiers
= w32_get_modifiers ();
3652 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3660 wmsg
.dwModifiers
= w32_get_modifiers ();
3661 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3664 case WM_WINDOWPOSCHANGING
:
3665 /* Don't restrict the sizing of tip frames. */
3666 if (hwnd
== tip_window
)
3670 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
3672 wp
.length
= sizeof (WINDOWPLACEMENT
);
3673 GetWindowPlacement (hwnd
, &wp
);
3675 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
3682 DWORD internal_border
;
3683 DWORD scrollbar_extra
;
3686 wp
.length
= sizeof (wp
);
3687 GetWindowRect (hwnd
, &wr
);
3691 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
3692 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
3693 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
3694 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
3698 memset (&rect
, 0, sizeof (rect
));
3699 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
3700 GetMenu (hwnd
) != NULL
);
3702 /* Force width and height of client area to be exact
3703 multiples of the character cell dimensions. */
3704 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
3705 - 2 * internal_border
- scrollbar_extra
)
3707 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
3708 - 2 * internal_border
)
3713 /* For right/bottom sizing we can just fix the sizes.
3714 However for top/left sizing we will need to fix the X
3715 and Y positions as well. */
3717 int cx_mintrack
= GetSystemMetrics (SM_CXMINTRACK
);
3718 int cy_mintrack
= GetSystemMetrics (SM_CYMINTRACK
);
3720 lppos
->cx
= max (lppos
->cx
- wdiff
, cx_mintrack
);
3721 lppos
->cy
= max (lppos
->cy
- hdiff
, cy_mintrack
);
3723 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
3724 && (lppos
->flags
& SWP_NOMOVE
) == 0)
3726 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
3733 lppos
->flags
|= SWP_NOMOVE
;
3744 case WM_GETMINMAXINFO
:
3745 /* Hack to allow resizing the Emacs frame above the screen size.
3746 Note that Windows 9x limits coordinates to 16-bits. */
3747 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.x
= 32767;
3748 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.y
= 32767;
3752 if (LOWORD (lParam
) == HTCLIENT
)
3754 f
= x_window_to_frame (dpyinfo
, hwnd
);
3755 if (f
->output_data
.w32
->hourglass_p
&& !menubar_in_use
3756 && !current_popup_menu
)
3757 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
3759 SetCursor (f
->output_data
.w32
->current_cursor
);
3764 case WM_EMACS_SETCURSOR
:
3766 Cursor cursor
= (Cursor
) wParam
;
3767 f
= x_window_to_frame (dpyinfo
, hwnd
);
3770 f
->output_data
.w32
->current_cursor
= cursor
;
3771 if (!f
->output_data
.w32
->hourglass_p
)
3777 case WM_EMACS_CREATESCROLLBAR
:
3778 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
3779 (struct scroll_bar
*) lParam
);
3781 case WM_EMACS_SHOWWINDOW
:
3782 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
3784 case WM_EMACS_SETFOREGROUND
:
3786 HWND foreground_window
;
3787 DWORD foreground_thread
, retval
;
3789 /* On NT 5.0, and apparently Windows 98, it is necessary to
3790 attach to the thread that currently has focus in order to
3791 pull the focus away from it. */
3792 foreground_window
= GetForegroundWindow ();
3793 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
3794 if (!foreground_window
3795 || foreground_thread
== GetCurrentThreadId ()
3796 || !AttachThreadInput (GetCurrentThreadId (),
3797 foreground_thread
, TRUE
))
3798 foreground_thread
= 0;
3800 retval
= SetForegroundWindow ((HWND
) wParam
);
3802 /* Detach from the previous foreground thread. */
3803 if (foreground_thread
)
3804 AttachThreadInput (GetCurrentThreadId (),
3805 foreground_thread
, FALSE
);
3810 case WM_EMACS_SETWINDOWPOS
:
3812 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
3813 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
3814 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
3817 case WM_EMACS_DESTROYWINDOW
:
3818 DragAcceptFiles ((HWND
) wParam
, FALSE
);
3819 return DestroyWindow ((HWND
) wParam
);
3821 case WM_EMACS_HIDE_CARET
:
3822 return HideCaret (hwnd
);
3824 case WM_EMACS_SHOW_CARET
:
3825 return ShowCaret (hwnd
);
3827 case WM_EMACS_DESTROY_CARET
:
3828 w32_system_caret_hwnd
= NULL
;
3829 w32_visible_system_caret_hwnd
= NULL
;
3830 return DestroyCaret ();
3832 case WM_EMACS_TRACK_CARET
:
3833 /* If there is currently no system caret, create one. */
3834 if (w32_system_caret_hwnd
== NULL
)
3836 /* Use the default caret width, and avoid changing it
3837 unneccesarily, as it confuses screen reader software. */
3838 w32_system_caret_hwnd
= hwnd
;
3839 CreateCaret (hwnd
, NULL
, 0,
3840 w32_system_caret_height
);
3843 if (!SetCaretPos (w32_system_caret_x
, w32_system_caret_y
))
3845 /* Ensure visible caret gets turned on when requested. */
3846 else if (w32_use_visible_system_caret
3847 && w32_visible_system_caret_hwnd
!= hwnd
)
3849 w32_visible_system_caret_hwnd
= hwnd
;
3850 return ShowCaret (hwnd
);
3852 /* Ensure visible caret gets turned off when requested. */
3853 else if (!w32_use_visible_system_caret
3854 && w32_visible_system_caret_hwnd
)
3856 w32_visible_system_caret_hwnd
= NULL
;
3857 return HideCaret (hwnd
);
3862 case WM_EMACS_TRACKPOPUPMENU
:
3867 pos
= (POINT
*)lParam
;
3868 flags
= TPM_CENTERALIGN
;
3869 if (button_state
& LMOUSE
)
3870 flags
|= TPM_LEFTBUTTON
;
3871 else if (button_state
& RMOUSE
)
3872 flags
|= TPM_RIGHTBUTTON
;
3874 /* Remember we did a SetCapture on the initial mouse down event,
3875 so for safety, we make sure the capture is cancelled now. */
3879 /* Use menubar_active to indicate that WM_INITMENU is from
3880 TrackPopupMenu below, and should be ignored. */
3881 f
= x_window_to_frame (dpyinfo
, hwnd
);
3883 f
->output_data
.w32
->menubar_active
= 1;
3885 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
3889 /* Eat any mouse messages during popupmenu */
3890 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
3892 /* Get the menu selection, if any */
3893 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
3895 retval
= LOWORD (amsg
.wParam
);
3911 /* Check for messages registered at runtime. */
3912 if (msg
== msh_mousewheel
)
3914 wmsg
.dwModifiers
= w32_get_modifiers ();
3915 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3916 signal_user_input ();
3921 return DefWindowProc (hwnd
, msg
, wParam
, lParam
);
3925 /* The most common default return code for handled messages is 0. */
3930 my_create_window (struct frame
* f
)
3934 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
3936 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
3940 /* Create a tooltip window. Unlike my_create_window, we do not do this
3941 indirectly via the Window thread, as we do not need to process Window
3942 messages for the tooltip. Creating tooltips indirectly also creates
3943 deadlocks when tooltips are created for menu items. */
3945 my_create_tip_window (struct frame
*f
)
3949 rect
.left
= rect
.top
= 0;
3950 rect
.right
= FRAME_PIXEL_WIDTH (f
);
3951 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
3953 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
3954 FRAME_EXTERNAL_MENU_BAR (f
));
3956 tip_window
= FRAME_W32_WINDOW (f
)
3957 = CreateWindow (EMACS_CLASS
,
3959 f
->output_data
.w32
->dwStyle
,
3962 rect
.right
- rect
.left
,
3963 rect
.bottom
- rect
.top
,
3964 FRAME_W32_WINDOW (SELECTED_FRAME ()), /* owner */
3971 SetWindowLong (tip_window
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
3972 SetWindowLong (tip_window
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
3973 SetWindowLong (tip_window
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
3974 SetWindowLong (tip_window
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
3976 /* Tip frames have no scrollbars. */
3977 SetWindowLong (tip_window
, WND_SCROLLBAR_INDEX
, 0);
3979 /* Do this to discard the default setting specified by our parent. */
3980 ShowWindow (tip_window
, SW_HIDE
);
3985 /* Create and set up the w32 window for frame F. */
3988 w32_window (struct frame
*f
, long window_prompting
, int minibuffer_only
)
3992 /* Use the resource name as the top-level window name
3993 for looking up resources. Make a non-Lisp copy
3994 for the window manager, so GC relocation won't bother it.
3996 Elsewhere we specify the window name for the window manager. */
3999 char *str
= (char *) SDATA (Vx_resource_name
);
4000 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
4001 strcpy (f
->namebuf
, str
);
4004 my_create_window (f
);
4006 validate_x_resource_name ();
4008 /* x_set_name normally ignores requests to set the name if the
4009 requested name is the same as the current name. This is the one
4010 place where that assumption isn't correct; f->name is set, but
4011 the server hasn't been told. */
4014 int explicit = f
->explicit_name
;
4016 f
->explicit_name
= 0;
4019 x_set_name (f
, name
, explicit);
4024 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
4025 initialize_frame_menubar (f
);
4027 if (FRAME_W32_WINDOW (f
) == 0)
4028 error ("Unable to create window");
4031 /* Handle the icon stuff for this window. Perhaps later we might
4032 want an x_set_icon_position which can be called interactively as
4036 x_icon (struct frame
*f
, Lisp_Object parms
)
4038 Lisp_Object icon_x
, icon_y
;
4039 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
4041 /* Set the position of the icon. Note that Windows 95 groups all
4042 icons in the tray. */
4043 icon_x
= x_get_arg (dpyinfo
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
4044 icon_y
= x_get_arg (dpyinfo
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
4045 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
4047 CHECK_NUMBER (icon_x
);
4048 CHECK_NUMBER (icon_y
);
4050 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
4051 error ("Both left and top icon corners of icon must be specified");
4055 if (! EQ (icon_x
, Qunbound
))
4056 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
4059 /* Start up iconic or window? */
4060 x_wm_set_window_state
4061 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
4065 x_text_icon (f
, (char *) SDATA ((!NILP (f
->icon_name
)
4075 x_make_gc (struct frame
*f
)
4077 XGCValues gc_values
;
4081 /* Create the GC's of this frame.
4082 Note that many default values are used. */
4085 gc_values
.font
= FRAME_FONT (f
);
4087 /* Cursor has cursor-color background, background-color foreground. */
4088 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
4089 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
4090 f
->output_data
.w32
->cursor_gc
4091 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
4092 (GCFont
| GCForeground
| GCBackground
),
4096 f
->output_data
.w32
->white_relief
.gc
= 0;
4097 f
->output_data
.w32
->black_relief
.gc
= 0;
4103 /* Handler for signals raised during x_create_frame and
4104 x_create_top_frame. FRAME is the frame which is partially
4108 unwind_create_frame (Lisp_Object frame
)
4110 struct frame
*f
= XFRAME (frame
);
4112 /* If frame is ``official'', nothing to do. */
4113 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
4116 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4119 x_free_frame_resources (f
);
4122 /* Check that reference counts are indeed correct. */
4123 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
4124 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
4133 x_default_font_parameter (struct frame
*f
, Lisp_Object parms
)
4135 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4136 Lisp_Object font_param
= x_get_arg (dpyinfo
, parms
, Qfont
, NULL
, NULL
,
4139 if (EQ (font_param
, Qunbound
))
4141 font
= !NILP (font_param
) ? font_param
4142 : x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4144 if (!STRINGP (font
))
4147 static char *names
[]
4148 = { "Courier New-10",
4149 "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1",
4150 "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1",
4154 for (i
= 0; names
[i
]; i
++)
4156 font
= font_open_by_name (f
, names
[i
]);
4161 error ("No suitable font was found");
4163 else if (!NILP (font_param
))
4165 /* Remember the explicit font parameter, so we can re-apply it after
4166 we've applied the `default' face settings. */
4167 x_set_frame_parameters (f
, Fcons (Fcons (Qfont_param
, font_param
), Qnil
));
4169 x_default_parameter (f
, parms
, Qfont
, font
, "font", "Font", RES_TYPE_STRING
);
4172 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
4174 doc
: /* Make a new window, which is called a \"frame\" in Emacs terms.
4175 Return an Emacs frame object.
4176 PARAMETERS is an alist of frame parameters.
4177 If the parameters specify that the frame should not have a minibuffer,
4178 and do not specify a specific minibuffer window to use,
4179 then `default-minibuffer-frame' must be a frame whose minibuffer can
4180 be shared by the new frame.
4182 This function is an internal primitive--use `make-frame' instead. */)
4183 (Lisp_Object parameters
)
4186 Lisp_Object frame
, tem
;
4188 int minibuffer_only
= 0;
4189 long window_prompting
= 0;
4191 int count
= SPECPDL_INDEX ();
4192 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4193 Lisp_Object display
;
4194 struct w32_display_info
*dpyinfo
= NULL
;
4198 /* Make copy of frame parameters because the original is in pure
4200 parameters
= Fcopy_alist (parameters
);
4202 /* Use this general default value to start with
4203 until we know if this frame has a specified name. */
4204 Vx_resource_name
= Vinvocation_name
;
4206 display
= x_get_arg (dpyinfo
, parameters
, Qterminal
, 0, 0, RES_TYPE_NUMBER
);
4207 if (EQ (display
, Qunbound
))
4208 display
= x_get_arg (dpyinfo
, parameters
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
4209 if (EQ (display
, Qunbound
))
4211 dpyinfo
= check_x_display_info (display
);
4212 kb
= dpyinfo
->terminal
->kboard
;
4214 if (!dpyinfo
->terminal
->name
)
4215 error ("Terminal is not live, can't create new frames on it");
4217 name
= x_get_arg (dpyinfo
, parameters
, Qname
, "name", "Name", RES_TYPE_STRING
);
4219 && ! EQ (name
, Qunbound
)
4221 error ("Invalid frame name--not a string or nil");
4224 Vx_resource_name
= name
;
4226 /* See if parent window is specified. */
4227 parent
= x_get_arg (dpyinfo
, parameters
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
4228 if (EQ (parent
, Qunbound
))
4230 if (! NILP (parent
))
4231 CHECK_NUMBER (parent
);
4233 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
4234 /* No need to protect DISPLAY because that's not used after passing
4235 it to make_frame_without_minibuffer. */
4237 GCPRO4 (parameters
, parent
, name
, frame
);
4238 tem
= x_get_arg (dpyinfo
, parameters
, Qminibuffer
, "minibuffer", "Minibuffer",
4240 if (EQ (tem
, Qnone
) || NILP (tem
))
4241 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
4242 else if (EQ (tem
, Qonly
))
4244 f
= make_minibuffer_frame ();
4245 minibuffer_only
= 1;
4247 else if (WINDOWP (tem
))
4248 f
= make_frame_without_minibuffer (tem
, kb
, display
);
4252 XSETFRAME (frame
, f
);
4254 /* Note that Windows does support scroll bars. */
4255 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
4257 /* By default, make scrollbars the system standard width. */
4258 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
4260 f
->terminal
= dpyinfo
->terminal
;
4261 f
->terminal
->reference_count
++;
4263 f
->output_method
= output_w32
;
4264 f
->output_data
.w32
=
4265 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
4266 memset (f
->output_data
.w32
, 0, sizeof (struct w32_output
));
4267 FRAME_FONTSET (f
) = -1;
4270 = x_get_arg (dpyinfo
, parameters
, Qicon_name
, "iconName", "Title",
4272 if (! STRINGP (f
->icon_name
))
4273 f
->icon_name
= Qnil
;
4275 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
4277 /* With FRAME_X_DISPLAY_INFO set up, this unwind-protect is safe. */
4278 record_unwind_protect (unwind_create_frame
, frame
);
4280 image_cache_refcount
= FRAME_IMAGE_CACHE (f
)->refcount
;
4281 dpyinfo_refcount
= dpyinfo
->reference_count
;
4282 #endif /* GLYPH_DEBUG */
4284 /* Specify the parent under which to make this window. */
4288 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
4289 f
->output_data
.w32
->explicit_parent
= 1;
4293 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4294 f
->output_data
.w32
->explicit_parent
= 0;
4297 /* Set the name; the functions to which we pass f expect the name to
4299 if (EQ (name
, Qunbound
) || NILP (name
))
4301 f
->name
= build_string (dpyinfo
->w32_id_name
);
4302 f
->explicit_name
= 0;
4307 f
->explicit_name
= 1;
4308 /* use the frame's title when getting resources for this frame. */
4309 specbind (Qx_resource_name
, name
);
4312 f
->resx
= dpyinfo
->resx
;
4313 f
->resy
= dpyinfo
->resy
;
4315 if (uniscribe_available
)
4316 register_font_driver (&uniscribe_font_driver
, f
);
4317 register_font_driver (&w32font_driver
, f
);
4319 x_default_parameter (f
, parameters
, Qfont_backend
, Qnil
,
4320 "fontBackend", "FontBackend", RES_TYPE_STRING
);
4321 /* Extract the window parameters from the supplied values
4322 that are needed to determine window geometry. */
4323 x_default_font_parameter (f
, parameters
);
4324 x_default_parameter (f
, parameters
, Qborder_width
, make_number (2),
4325 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4327 /* We recognize either internalBorderWidth or internalBorder
4328 (which is what xterm calls it). */
4329 if (NILP (Fassq (Qinternal_border_width
, parameters
)))
4333 value
= x_get_arg (dpyinfo
, parameters
, Qinternal_border_width
,
4334 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
4335 if (! EQ (value
, Qunbound
))
4336 parameters
= Fcons (Fcons (Qinternal_border_width
, value
),
4339 /* Default internalBorderWidth to 0 on Windows to match other programs. */
4340 x_default_parameter (f
, parameters
, Qinternal_border_width
, make_number (0),
4341 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
4342 x_default_parameter (f
, parameters
, Qvertical_scroll_bars
, Qright
,
4343 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
4345 /* Also do the stuff which must be set before the window exists. */
4346 x_default_parameter (f
, parameters
, Qforeground_color
, build_string ("black"),
4347 "foreground", "Foreground", RES_TYPE_STRING
);
4348 x_default_parameter (f
, parameters
, Qbackground_color
, build_string ("white"),
4349 "background", "Background", RES_TYPE_STRING
);
4350 x_default_parameter (f
, parameters
, Qmouse_color
, build_string ("black"),
4351 "pointerColor", "Foreground", RES_TYPE_STRING
);
4352 x_default_parameter (f
, parameters
, Qcursor_color
, build_string ("black"),
4353 "cursorColor", "Foreground", RES_TYPE_STRING
);
4354 x_default_parameter (f
, parameters
, Qborder_color
, build_string ("black"),
4355 "borderColor", "BorderColor", RES_TYPE_STRING
);
4356 x_default_parameter (f
, parameters
, Qscreen_gamma
, Qnil
,
4357 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
4358 x_default_parameter (f
, parameters
, Qline_spacing
, Qnil
,
4359 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
4360 x_default_parameter (f
, parameters
, Qleft_fringe
, Qnil
,
4361 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
4362 x_default_parameter (f
, parameters
, Qright_fringe
, Qnil
,
4363 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
4366 /* Init faces before x_default_parameter is called for scroll-bar
4367 parameters because that function calls x_set_scroll_bar_width,
4368 which calls change_frame_size, which calls Fset_window_buffer,
4369 which runs hooks, which call Fvertical_motion. At the end, we
4370 end up in init_iterator with a null face cache, which should not
4372 init_frame_faces (f
);
4374 /* The X resources controlling the menu-bar and tool-bar are
4375 processed specially at startup, and reflected in the mode
4376 variables; ignore them here. */
4377 x_default_parameter (f
, parameters
, Qmenu_bar_lines
,
4378 NILP (Vmenu_bar_mode
)
4379 ? make_number (0) : make_number (1),
4380 NULL
, NULL
, RES_TYPE_NUMBER
);
4381 x_default_parameter (f
, parameters
, Qtool_bar_lines
,
4382 NILP (Vtool_bar_mode
)
4383 ? make_number (0) : make_number (1),
4384 NULL
, NULL
, RES_TYPE_NUMBER
);
4386 x_default_parameter (f
, parameters
, Qbuffer_predicate
, Qnil
,
4387 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
4388 x_default_parameter (f
, parameters
, Qtitle
, Qnil
,
4389 "title", "Title", RES_TYPE_STRING
);
4390 x_default_parameter (f
, parameters
, Qfullscreen
, Qnil
,
4391 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
4393 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
4394 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4396 f
->output_data
.w32
->text_cursor
= w32_load_cursor (IDC_IBEAM
);
4397 f
->output_data
.w32
->nontext_cursor
= w32_load_cursor (IDC_ARROW
);
4398 f
->output_data
.w32
->modeline_cursor
= w32_load_cursor (IDC_ARROW
);
4399 f
->output_data
.w32
->hand_cursor
= w32_load_cursor (IDC_HAND
);
4400 f
->output_data
.w32
->hourglass_cursor
= w32_load_cursor (IDC_WAIT
);
4401 f
->output_data
.w32
->horizontal_drag_cursor
= w32_load_cursor (IDC_SIZEWE
);
4403 f
->output_data
.w32
->current_cursor
= f
->output_data
.w32
->nontext_cursor
;
4405 window_prompting
= x_figure_window_size (f
, parameters
, 1);
4407 tem
= x_get_arg (dpyinfo
, parameters
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
4408 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
4410 w32_window (f
, window_prompting
, minibuffer_only
);
4411 x_icon (f
, parameters
);
4415 /* Now consider the frame official. */
4416 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
4417 Vframe_list
= Fcons (frame
, Vframe_list
);
4419 /* We need to do this after creating the window, so that the
4420 icon-creation functions can say whose icon they're describing. */
4421 x_default_parameter (f
, parameters
, Qicon_type
, Qnil
,
4422 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
4424 x_default_parameter (f
, parameters
, Qauto_raise
, Qnil
,
4425 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4426 x_default_parameter (f
, parameters
, Qauto_lower
, Qnil
,
4427 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4428 x_default_parameter (f
, parameters
, Qcursor_type
, Qbox
,
4429 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4430 x_default_parameter (f
, parameters
, Qscroll_bar_width
, Qnil
,
4431 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
4432 x_default_parameter (f
, parameters
, Qalpha
, Qnil
,
4433 "alpha", "Alpha", RES_TYPE_NUMBER
);
4435 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4436 Change will not be effected unless different from the current
4438 width
= FRAME_COLS (f
);
4439 height
= FRAME_LINES (f
);
4441 FRAME_LINES (f
) = 0;
4442 SET_FRAME_COLS (f
, 0);
4443 change_frame_size (f
, height
, width
, 1, 0, 0);
4445 /* Tell the server what size and position, etc, we want, and how
4446 badly we want them. This should be done after we have the menu
4447 bar so that its size can be taken into account. */
4449 x_wm_set_size_hint (f
, window_prompting
, 0);
4452 /* Make the window appear on the frame and enable display, unless
4453 the caller says not to. However, with explicit parent, Emacs
4454 cannot control visibility, so don't try. */
4455 if (! f
->output_data
.w32
->explicit_parent
)
4457 Lisp_Object visibility
;
4459 visibility
= x_get_arg (dpyinfo
, parameters
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
4460 if (EQ (visibility
, Qunbound
))
4463 if (EQ (visibility
, Qicon
))
4464 x_iconify_frame (f
);
4465 else if (! NILP (visibility
))
4466 x_make_frame_visible (f
);
4468 /* Must have been Qnil. */
4472 /* Initialize `default-minibuffer-frame' in case this is the first
4473 frame on this terminal. */
4474 if (FRAME_HAS_MINIBUF_P (f
)
4475 && (!FRAMEP (kb
->Vdefault_minibuffer_frame
)
4476 || !FRAME_LIVE_P (XFRAME (kb
->Vdefault_minibuffer_frame
))))
4477 kb
->Vdefault_minibuffer_frame
= frame
;
4479 /* All remaining specified parameters, which have not been "used"
4480 by x_get_arg and friends, now go in the misc. alist of the frame. */
4481 for (tem
= parameters
; CONSP (tem
); tem
= XCDR (tem
))
4482 if (CONSP (XCAR (tem
)) && !NILP (XCAR (XCAR (tem
))))
4483 f
->param_alist
= Fcons (XCAR (tem
), f
->param_alist
);
4487 /* Make sure windows on this frame appear in calls to next-window
4488 and similar functions. */
4489 Vwindow_list
= Qnil
;
4491 return unbind_to (count
, frame
);
4494 /* FRAME is used only to get a handle on the X display. We don't pass the
4495 display info directly because we're called from frame.c, which doesn't
4496 know about that structure. */
4498 x_get_focus_frame (struct frame
*frame
)
4500 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
4502 if (! dpyinfo
->w32_focus_frame
)
4505 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
4509 DEFUN ("x-focus-frame", Fx_focus_frame
, Sx_focus_frame
, 1, 1, 0,
4510 doc
: /* Give FRAME input focus, raising to foreground if necessary. */)
4513 x_focus_on_frame (check_x_frame (frame
));
4518 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
4519 doc
: /* Internal function called by `color-defined-p', which see. */)
4520 (Lisp_Object color
, Lisp_Object frame
)
4523 FRAME_PTR f
= check_x_frame (frame
);
4525 CHECK_STRING (color
);
4527 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
4533 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
4534 doc
: /* Internal function called by `color-values', which see. */)
4535 (Lisp_Object color
, Lisp_Object frame
)
4538 FRAME_PTR f
= check_x_frame (frame
);
4540 CHECK_STRING (color
);
4542 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
4543 return list3 (make_number ((GetRValue (foo
.pixel
) << 8)
4544 | GetRValue (foo
.pixel
)),
4545 make_number ((GetGValue (foo
.pixel
) << 8)
4546 | GetGValue (foo
.pixel
)),
4547 make_number ((GetBValue (foo
.pixel
) << 8)
4548 | GetBValue (foo
.pixel
)));
4553 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
4554 doc
: /* Internal function called by `display-color-p', which see. */)
4555 (Lisp_Object display
)
4557 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4559 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
4565 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
,
4566 Sx_display_grayscale_p
, 0, 1, 0,
4567 doc
: /* Return t if DISPLAY supports shades of gray.
4568 Note that color displays do support shades of gray.
4569 The optional argument DISPLAY specifies which display to ask about.
4570 DISPLAY should be either a frame or a display name (a string).
4571 If omitted or nil, that stands for the selected frame's display. */)
4572 (Lisp_Object display
)
4574 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4576 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
4582 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
,
4583 Sx_display_pixel_width
, 0, 1, 0,
4584 doc
: /* Return the width in pixels of DISPLAY.
4585 The optional argument DISPLAY specifies which display to ask about.
4586 DISPLAY should be either a frame or a display name (a string).
4587 If omitted or nil, that stands for the selected frame's display. */)
4588 (Lisp_Object display
)
4590 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4592 return make_number (x_display_pixel_width (dpyinfo
));
4595 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
4596 Sx_display_pixel_height
, 0, 1, 0,
4597 doc
: /* Return the height in pixels of DISPLAY.
4598 The optional argument DISPLAY specifies which display to ask about.
4599 DISPLAY should be either a frame or a display name (a string).
4600 If omitted or nil, that stands for the selected frame's display. */)
4601 (Lisp_Object display
)
4603 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4605 return make_number (x_display_pixel_height (dpyinfo
));
4608 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
4610 doc
: /* Return the number of bitplanes of DISPLAY.
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 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4618 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
4621 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
4623 doc
: /* Return the number of color cells of DISPLAY.
4624 The optional argument DISPLAY specifies which display to ask about.
4625 DISPLAY should be either a frame or a display name (a string).
4626 If omitted or nil, that stands for the selected frame's display. */)
4627 (Lisp_Object display
)
4629 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4633 hdc
= GetDC (dpyinfo
->root_window
);
4634 if (dpyinfo
->has_palette
)
4635 cap
= GetDeviceCaps (hdc
, SIZEPALETTE
);
4637 cap
= GetDeviceCaps (hdc
, NUMCOLORS
);
4639 /* We force 24+ bit depths to 24-bit, both to prevent an overflow
4640 and because probably is more meaningful on Windows anyway */
4642 cap
= 1 << min (dpyinfo
->n_planes
* dpyinfo
->n_cbits
, 24);
4644 ReleaseDC (dpyinfo
->root_window
, hdc
);
4646 return make_number (cap
);
4649 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
4650 Sx_server_max_request_size
,
4652 doc
: /* Return the maximum request size of the server of DISPLAY.
4653 The optional argument DISPLAY specifies which display to ask about.
4654 DISPLAY should be either a frame or a display name (a string).
4655 If omitted or nil, that stands for the selected frame's display. */)
4656 (Lisp_Object display
)
4658 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4660 return make_number (1);
4663 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
4664 doc
: /* Return the "vendor ID" string of the W32 system (Microsoft).
4665 The optional argument DISPLAY specifies which display to ask about.
4666 DISPLAY should be either a frame or a display name (a string).
4667 If omitted or nil, that stands for the selected frame's display. */)
4668 (Lisp_Object display
)
4670 return build_string ("Microsoft Corp.");
4673 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
4674 doc
: /* Return the version numbers of the server of DISPLAY.
4675 The value is a list of three integers: the major and minor
4676 version numbers of the X Protocol in use, and the distributor-specific
4677 release number. See also the function `x-server-vendor'.
4679 The optional argument DISPLAY specifies which display to ask about.
4680 DISPLAY should be either a frame or a display name (a string).
4681 If omitted or nil, that stands for the selected frame's display. */)
4682 (Lisp_Object display
)
4684 return Fcons (make_number (w32_major_version
),
4685 Fcons (make_number (w32_minor_version
),
4686 Fcons (make_number (w32_build_number
), Qnil
)));
4689 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
4690 doc
: /* Return the number of screens on the server of DISPLAY.
4691 The optional argument DISPLAY specifies which display to ask about.
4692 DISPLAY should be either a frame or a display name (a string).
4693 If omitted or nil, that stands for the selected frame's display. */)
4694 (Lisp_Object display
)
4696 return make_number (1);
4699 DEFUN ("x-display-mm-height", Fx_display_mm_height
,
4700 Sx_display_mm_height
, 0, 1, 0,
4701 doc
: /* Return the height in millimeters of DISPLAY.
4702 The optional argument DISPLAY specifies which display to ask about.
4703 DISPLAY should be either a frame or a display name (a string).
4704 If omitted or nil, that stands for the selected frame's display. */)
4705 (Lisp_Object display
)
4707 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4711 hdc
= GetDC (dpyinfo
->root_window
);
4713 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
4715 ReleaseDC (dpyinfo
->root_window
, hdc
);
4717 return make_number (cap
);
4720 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
4721 doc
: /* Return the width in millimeters of DISPLAY.
4722 The optional argument DISPLAY specifies which display to ask about.
4723 DISPLAY should be either a frame or a display name (a string).
4724 If omitted or nil, that stands for the selected frame's display. */)
4725 (Lisp_Object display
)
4727 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4732 hdc
= GetDC (dpyinfo
->root_window
);
4734 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
4736 ReleaseDC (dpyinfo
->root_window
, hdc
);
4738 return make_number (cap
);
4741 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
4742 Sx_display_backing_store
, 0, 1, 0,
4743 doc
: /* Return an indication of whether DISPLAY does backing store.
4744 The value may be `always', `when-mapped', or `not-useful'.
4745 The optional argument DISPLAY specifies which display to ask about.
4746 DISPLAY should be either a frame or a display name (a string).
4747 If omitted or nil, that stands for the selected frame's display. */)
4748 (Lisp_Object display
)
4750 return intern ("not-useful");
4753 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
4754 Sx_display_visual_class
, 0, 1, 0,
4755 doc
: /* Return the visual class of DISPLAY.
4756 The value is one of the symbols `static-gray', `gray-scale',
4757 `static-color', `pseudo-color', `true-color', or `direct-color'.
4759 The optional argument DISPLAY specifies which display to ask about.
4760 DISPLAY should be either a frame or a display name (a string).
4761 If omitted or nil, that stands for the selected frame's display. */)
4762 (Lisp_Object display
)
4764 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4765 Lisp_Object result
= Qnil
;
4767 if (dpyinfo
->has_palette
)
4768 result
= intern ("pseudo-color");
4769 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
4770 result
= intern ("static-grey");
4771 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
4772 result
= intern ("static-color");
4773 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
4774 result
= intern ("true-color");
4779 DEFUN ("x-display-save-under", Fx_display_save_under
,
4780 Sx_display_save_under
, 0, 1, 0,
4781 doc
: /* Return t if DISPLAY supports the save-under feature.
4782 The optional argument DISPLAY specifies which display to ask about.
4783 DISPLAY should be either a frame or a display name (a string).
4784 If omitted or nil, that stands for the selected frame's display. */)
4785 (Lisp_Object display
)
4791 x_pixel_width (register struct frame
*f
)
4793 return FRAME_PIXEL_WIDTH (f
);
4797 x_pixel_height (register struct frame
*f
)
4799 return FRAME_PIXEL_HEIGHT (f
);
4803 x_char_width (register struct frame
*f
)
4805 return FRAME_COLUMN_WIDTH (f
);
4809 x_char_height (register struct frame
*f
)
4811 return FRAME_LINE_HEIGHT (f
);
4815 x_screen_planes (register struct frame
*f
)
4817 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
4820 /* Return the display structure for the display named NAME.
4821 Open a new connection if necessary. */
4823 struct w32_display_info
*
4824 x_display_info_for_name (Lisp_Object name
)
4827 struct w32_display_info
*dpyinfo
;
4829 CHECK_STRING (name
);
4831 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
4833 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
4836 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
4841 /* Use this general default value to start with. */
4842 Vx_resource_name
= Vinvocation_name
;
4844 validate_x_resource_name ();
4846 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
4847 (char *) SDATA (Vx_resource_name
));
4850 error ("Cannot connect to server %s", SDATA (name
));
4853 XSETFASTINT (Vwindow_system_version
, w32_major_version
);
4858 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
4859 1, 3, 0, doc
: /* Open a connection to a server.
4860 DISPLAY is the name of the display to connect to.
4861 Optional second arg XRM-STRING is a string of resources in xrdb format.
4862 If the optional third arg MUST-SUCCEED is non-nil,
4863 terminate Emacs if we can't open the connection. */)
4864 (Lisp_Object display
, Lisp_Object xrm_string
, Lisp_Object must_succeed
)
4866 unsigned char *xrm_option
;
4867 struct w32_display_info
*dpyinfo
;
4869 /* If initialization has already been done, return now to avoid
4870 overwriting critical parts of one_w32_display_info. */
4874 CHECK_STRING (display
);
4875 if (! NILP (xrm_string
))
4876 CHECK_STRING (xrm_string
);
4879 if (! EQ (Vwindow_system
, intern ("w32")))
4880 error ("Not using Microsoft Windows");
4883 /* Allow color mapping to be defined externally; first look in user's
4884 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
4886 Lisp_Object color_file
;
4887 struct gcpro gcpro1
;
4889 color_file
= build_string ("~/rgb.txt");
4891 GCPRO1 (color_file
);
4893 if (NILP (Ffile_readable_p (color_file
)))
4895 Fexpand_file_name (build_string ("rgb.txt"),
4896 Fsymbol_value (intern ("data-directory")));
4898 Vw32_color_map
= Fx_load_color_file (color_file
);
4902 if (NILP (Vw32_color_map
))
4903 Vw32_color_map
= Fw32_default_color_map ();
4905 /* Merge in system logical colors. */
4906 add_system_logical_colors_to_map (&Vw32_color_map
);
4908 if (! NILP (xrm_string
))
4909 xrm_option
= (unsigned char *) SDATA (xrm_string
);
4911 xrm_option
= (unsigned char *) 0;
4913 /* Use this general default value to start with. */
4914 /* First remove .exe suffix from invocation-name - it looks ugly. */
4916 char basename
[ MAX_PATH
], *str
;
4918 strcpy (basename
, SDATA (Vinvocation_name
));
4919 str
= strrchr (basename
, '.');
4921 Vinvocation_name
= build_string (basename
);
4923 Vx_resource_name
= Vinvocation_name
;
4925 validate_x_resource_name ();
4927 /* This is what opens the connection and sets x_current_display.
4928 This also initializes many symbols, such as those used for input. */
4929 dpyinfo
= w32_term_init (display
, xrm_option
,
4930 (char *) SDATA (Vx_resource_name
));
4934 if (!NILP (must_succeed
))
4935 fatal ("Cannot connect to server %s.\n",
4938 error ("Cannot connect to server %s", SDATA (display
));
4943 XSETFASTINT (Vwindow_system_version
, w32_major_version
);
4947 DEFUN ("x-close-connection", Fx_close_connection
,
4948 Sx_close_connection
, 1, 1, 0,
4949 doc
: /* Close the connection to DISPLAY's server.
4950 For DISPLAY, specify either a frame or a display name (a string).
4951 If DISPLAY is nil, that stands for the selected frame's display. */)
4952 (Lisp_Object display
)
4954 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4957 if (dpyinfo
->reference_count
> 0)
4958 error ("Display still has frames on it");
4961 x_destroy_all_bitmaps (dpyinfo
);
4963 x_delete_display (dpyinfo
);
4969 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
4970 doc
: /* Return the list of display names that Emacs has connections to. */)
4973 Lisp_Object tail
, result
;
4976 for (tail
= w32_display_name_list
; CONSP (tail
); tail
= XCDR (tail
))
4977 result
= Fcons (XCAR (XCAR (tail
)), result
);
4982 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
4983 doc
: /* This is a noop on W32 systems. */)
4984 (Lisp_Object on
, Lisp_Object display
)
4991 /***********************************************************************
4993 ***********************************************************************/
4995 DEFUN ("x-change-window-property", Fx_change_window_property
,
4996 Sx_change_window_property
, 2, 6, 0,
4997 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
4998 VALUE may be a string or a list of conses, numbers and/or strings.
4999 If an element in the list is a string, it is converted to
5000 an Atom and the value of the Atom is used. If an element is a cons,
5001 it is converted to a 32 bit number where the car is the 16 top bits and the
5002 cdr is the lower 16 bits.
5003 FRAME nil or omitted means use the selected frame.
5004 If TYPE is given and non-nil, it is the name of the type of VALUE.
5005 If TYPE is not given or nil, the type is STRING.
5006 FORMAT gives the size in bits of each element if VALUE is a list.
5007 It must be one of 8, 16 or 32.
5008 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
5009 If OUTER_P is non-nil, the property is changed for the outer X window of
5010 FRAME. Default is to change on the edit X window.
5013 (Lisp_Object prop
, Lisp_Object value
, Lisp_Object frame
, Lisp_Object type
, Lisp_Object format
, Lisp_Object outer_p
)
5015 #if 0 /* TODO : port window properties to W32 */
5016 struct frame
*f
= check_x_frame (frame
);
5019 CHECK_STRING (prop
);
5020 CHECK_STRING (value
);
5023 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5024 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5025 prop_atom
, XA_STRING
, 8, PropModeReplace
,
5026 SDATA (value
), SCHARS (value
));
5028 /* Make sure the property is set when we return. */
5029 XFlush (FRAME_W32_DISPLAY (f
));
5038 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
5039 Sx_delete_window_property
, 1, 2, 0,
5040 doc
: /* Remove window property PROP from X window of FRAME.
5041 FRAME nil or omitted means use the selected frame. Value is PROP. */)
5042 (Lisp_Object prop
, Lisp_Object frame
)
5044 #if 0 /* TODO : port window properties to W32 */
5046 struct frame
*f
= check_x_frame (frame
);
5049 CHECK_STRING (prop
);
5051 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5052 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
5054 /* Make sure the property is removed when we return. */
5055 XFlush (FRAME_W32_DISPLAY (f
));
5063 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
5065 doc
: /* Value is the value of window property PROP on FRAME.
5066 If FRAME is nil or omitted, use the selected frame. Value is nil
5067 if FRAME hasn't a property with name PROP or if PROP has no string
5069 (Lisp_Object prop
, Lisp_Object frame
)
5071 #if 0 /* TODO : port window properties to W32 */
5073 struct frame
*f
= check_x_frame (frame
);
5076 Lisp_Object prop_value
= Qnil
;
5077 char *tmp_data
= NULL
;
5080 unsigned long actual_size
, bytes_remaining
;
5082 CHECK_STRING (prop
);
5084 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5085 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5086 prop_atom
, 0, 0, False
, XA_STRING
,
5087 &actual_type
, &actual_format
, &actual_size
,
5088 &bytes_remaining
, (unsigned char **) &tmp_data
);
5091 int size
= bytes_remaining
;
5096 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5097 prop_atom
, 0, bytes_remaining
,
5099 &actual_type
, &actual_format
,
5100 &actual_size
, &bytes_remaining
,
5101 (unsigned char **) &tmp_data
);
5103 prop_value
= make_string (tmp_data
, size
);
5118 /***********************************************************************
5120 ***********************************************************************/
5122 /* Default number of seconds to wait before displaying an hourglass
5123 cursor. Duplicated from xdisp.c, but cannot use the version there
5124 due to lack of atimers on w32. */
5125 #define DEFAULT_HOURGLASS_DELAY 1
5126 extern Lisp_Object Vhourglass_delay
;
5128 /* Return non-zero if houglass timer has been started or hourglass is shown. */
5129 /* PENDING: if W32 can use atimers (atimer.[hc]) then the common impl in
5130 xdisp.c could be used. */
5133 hourglass_started (void)
5135 return hourglass_shown_p
|| hourglass_timer
;
5138 /* Cancel a currently active hourglass timer, and start a new one. */
5141 start_hourglass (void)
5144 int secs
, msecs
= 0;
5145 struct frame
* f
= SELECTED_FRAME ();
5147 /* No cursors on non GUI frames. */
5148 if (!FRAME_W32_P (f
))
5151 cancel_hourglass ();
5153 if (INTEGERP (Vhourglass_delay
)
5154 && XINT (Vhourglass_delay
) > 0)
5155 secs
= XFASTINT (Vhourglass_delay
);
5156 else if (FLOATP (Vhourglass_delay
)
5157 && XFLOAT_DATA (Vhourglass_delay
) > 0)
5160 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
5161 secs
= XFASTINT (tem
);
5162 msecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000;
5165 secs
= DEFAULT_HOURGLASS_DELAY
;
5167 delay
= secs
* 1000 + msecs
;
5168 hourglass_hwnd
= FRAME_W32_WINDOW (f
);
5169 hourglass_timer
= SetTimer (hourglass_hwnd
, HOURGLASS_ID
, delay
, NULL
);
5173 /* Cancel the hourglass cursor timer if active, hide an hourglass
5177 cancel_hourglass (void)
5179 if (hourglass_timer
)
5181 KillTimer (hourglass_hwnd
, hourglass_timer
);
5182 hourglass_timer
= 0;
5185 if (hourglass_shown_p
)
5186 w32_hide_hourglass ();
5190 /* Timer function of hourglass_timer.
5192 Display an hourglass cursor. Set the hourglass_p flag in display info
5193 to indicate that an hourglass cursor is shown. */
5196 w32_show_hourglass (struct frame
*f
)
5198 if (!hourglass_shown_p
)
5200 f
->output_data
.w32
->hourglass_p
= 1;
5201 if (!menubar_in_use
&& !current_popup_menu
)
5202 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
5203 hourglass_shown_p
= 1;
5208 /* Hide the hourglass cursor on all frames, if it is currently shown. */
5211 w32_hide_hourglass (void)
5213 if (hourglass_shown_p
)
5215 struct frame
*f
= x_window_to_frame (&one_w32_display_info
,
5218 f
->output_data
.w32
->hourglass_p
= 0;
5220 /* If frame was deleted, restore to selected frame's cursor. */
5221 f
= SELECTED_FRAME ();
5223 if (FRAME_W32_P (f
))
5224 SetCursor (f
->output_data
.w32
->current_cursor
);
5226 /* No cursors on non GUI frames - restore to stock arrow cursor. */
5227 SetCursor (w32_load_cursor (IDC_ARROW
));
5229 hourglass_shown_p
= 0;
5235 /***********************************************************************
5237 ***********************************************************************/
5239 static Lisp_Object
x_create_tip_frame (struct w32_display_info
*,
5240 Lisp_Object
, Lisp_Object
);
5241 static void compute_tip_xy (struct frame
*, Lisp_Object
, Lisp_Object
,
5242 Lisp_Object
, int, int, int *, int *);
5244 /* The frame of a currently visible tooltip. */
5246 Lisp_Object tip_frame
;
5248 /* If non-nil, a timer started that hides the last tooltip when it
5251 Lisp_Object tip_timer
;
5254 /* If non-nil, a vector of 3 elements containing the last args
5255 with which x-show-tip was called. See there. */
5257 Lisp_Object last_show_tip_args
;
5259 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
5261 Lisp_Object Vx_max_tooltip_size
;
5265 unwind_create_tip_frame (Lisp_Object frame
)
5267 Lisp_Object deleted
;
5269 deleted
= unwind_create_frame (frame
);
5270 if (EQ (deleted
, Qt
))
5280 /* Create a frame for a tooltip on the display described by DPYINFO.
5281 PARMS is a list of frame parameters. TEXT is the string to
5282 display in the tip frame. Value is the frame.
5284 Note that functions called here, esp. x_default_parameter can
5285 signal errors, for instance when a specified color name is
5286 undefined. We have to make sure that we're in a consistent state
5287 when this happens. */
5290 x_create_tip_frame (struct w32_display_info
*dpyinfo
,
5291 Lisp_Object parms
, Lisp_Object text
)
5294 Lisp_Object frame
, tem
;
5296 long window_prompting
= 0;
5298 int count
= SPECPDL_INDEX ();
5299 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5301 int face_change_count_before
= face_change_count
;
5303 struct buffer
*old_buffer
;
5307 /* Use this general default value to start with until we know if
5308 this frame has a specified name. */
5309 Vx_resource_name
= Vinvocation_name
;
5311 kb
= dpyinfo
->terminal
->kboard
;
5313 /* The calls to x_get_arg remove elements from PARMS, so copy it to
5314 avoid destructive changes behind our caller's back. */
5315 parms
= Fcopy_alist (parms
);
5317 /* Get the name of the frame to use for resource lookup. */
5318 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
5320 && !EQ (name
, Qunbound
)
5322 error ("Invalid frame name--not a string or nil");
5323 Vx_resource_name
= name
;
5326 GCPRO3 (parms
, name
, frame
);
5327 /* Make a frame without minibuffer nor mode-line. */
5329 f
->wants_modeline
= 0;
5330 XSETFRAME (frame
, f
);
5332 buffer
= Fget_buffer_create (build_string (" *tip*"));
5333 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, Qnil
);
5334 old_buffer
= current_buffer
;
5335 set_buffer_internal_1 (XBUFFER (buffer
));
5336 current_buffer
->truncate_lines
= Qnil
;
5337 specbind (Qinhibit_read_only
, Qt
);
5338 specbind (Qinhibit_modification_hooks
, Qt
);
5341 set_buffer_internal_1 (old_buffer
);
5343 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
5344 record_unwind_protect (unwind_create_tip_frame
, frame
);
5346 /* By setting the output method, we're essentially saying that
5347 the frame is live, as per FRAME_LIVE_P. If we get a signal
5348 from this point on, x_destroy_window might screw up reference
5350 f
->terminal
= dpyinfo
->terminal
;
5351 f
->terminal
->reference_count
++;
5352 f
->output_method
= output_w32
;
5353 f
->output_data
.w32
=
5354 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
5355 memset (f
->output_data
.w32
, 0, sizeof (struct w32_output
));
5357 FRAME_FONTSET (f
) = -1;
5358 f
->icon_name
= Qnil
;
5361 image_cache_refcount
= FRAME_IMAGE_CACHE (f
)->refcount
;
5362 dpyinfo_refcount
= dpyinfo
->reference_count
;
5363 #endif /* GLYPH_DEBUG */
5364 FRAME_KBOARD (f
) = kb
;
5365 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5366 f
->output_data
.w32
->explicit_parent
= 0;
5368 /* Set the name; the functions to which we pass f expect the name to
5370 if (EQ (name
, Qunbound
) || NILP (name
))
5372 f
->name
= build_string (dpyinfo
->w32_id_name
);
5373 f
->explicit_name
= 0;
5378 f
->explicit_name
= 1;
5379 /* use the frame's title when getting resources for this frame. */
5380 specbind (Qx_resource_name
, name
);
5383 f
->resx
= dpyinfo
->resx
;
5384 f
->resy
= dpyinfo
->resy
;
5386 if (uniscribe_available
)
5387 register_font_driver (&uniscribe_font_driver
, f
);
5388 register_font_driver (&w32font_driver
, f
);
5390 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
5391 "fontBackend", "FontBackend", RES_TYPE_STRING
);
5393 /* Extract the window parameters from the supplied values
5394 that are needed to determine window geometry. */
5395 x_default_font_parameter (f
, parms
);
5397 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
5398 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5399 /* This defaults to 2 in order to match xterm. We recognize either
5400 internalBorderWidth or internalBorder (which is what xterm calls
5402 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5406 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
5407 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
5408 if (! EQ (value
, Qunbound
))
5409 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
5412 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
5413 "internalBorderWidth", "internalBorderWidth",
5416 /* Also do the stuff which must be set before the window exists. */
5417 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
5418 "foreground", "Foreground", RES_TYPE_STRING
);
5419 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
5420 "background", "Background", RES_TYPE_STRING
);
5421 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
5422 "pointerColor", "Foreground", RES_TYPE_STRING
);
5423 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
5424 "cursorColor", "Foreground", RES_TYPE_STRING
);
5425 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
5426 "borderColor", "BorderColor", RES_TYPE_STRING
);
5428 /* Init faces before x_default_parameter is called for scroll-bar
5429 parameters because that function calls x_set_scroll_bar_width,
5430 which calls change_frame_size, which calls Fset_window_buffer,
5431 which runs hooks, which call Fvertical_motion. At the end, we
5432 end up in init_iterator with a null face cache, which should not
5434 init_frame_faces (f
);
5436 f
->output_data
.w32
->dwStyle
= WS_BORDER
| WS_POPUP
| WS_DISABLED
;
5437 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5439 window_prompting
= x_figure_window_size (f
, parms
, 0);
5441 /* No fringes on tip frame. */
5443 f
->left_fringe_width
= 0;
5444 f
->right_fringe_width
= 0;
5447 my_create_tip_window (f
);
5452 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
5453 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5454 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5455 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5456 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5457 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5459 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
5460 Change will not be effected unless different from the current
5462 width
= FRAME_COLS (f
);
5463 height
= FRAME_LINES (f
);
5464 FRAME_LINES (f
) = 0;
5465 SET_FRAME_COLS (f
, 0);
5466 change_frame_size (f
, height
, width
, 1, 0, 0);
5468 /* Add `tooltip' frame parameter's default value. */
5469 if (NILP (Fframe_parameter (frame
, Qtooltip
)))
5470 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qtooltip
, Qt
), Qnil
));
5472 /* Set up faces after all frame parameters are known. This call
5473 also merges in face attributes specified for new frames.
5475 Frame parameters may be changed if .Xdefaults contains
5476 specifications for the default font. For example, if there is an
5477 `Emacs.default.attributeBackground: pink', the `background-color'
5478 attribute of the frame get's set, which let's the internal border
5479 of the tooltip frame appear in pink. Prevent this. */
5481 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
5482 Lisp_Object fg
= Fframe_parameter (frame
, Qforeground_color
);
5483 Lisp_Object colors
= Qnil
;
5485 /* Set tip_frame here, so that */
5487 call2 (Qface_set_after_frame_default
, frame
, Qnil
);
5489 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
5490 colors
= Fcons (Fcons (Qbackground_color
, bg
), colors
);
5491 if (!EQ (fg
, Fframe_parameter (frame
, Qforeground_color
)))
5492 colors
= Fcons (Fcons (Qforeground_color
, fg
), colors
);
5495 Fmodify_frame_parameters (frame
, colors
);
5502 /* It is now ok to make the frame official even if we get an error
5503 below. And the frame needs to be on Vframe_list or making it
5504 visible won't work. */
5505 Vframe_list
= Fcons (frame
, Vframe_list
);
5507 /* Now that the frame is official, it counts as a reference to
5509 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
5511 /* Setting attributes of faces of the tooltip frame from resources
5512 and similar will increment face_change_count, which leads to the
5513 clearing of all current matrices. Since this isn't necessary
5514 here, avoid it by resetting face_change_count to the value it
5515 had before we created the tip frame. */
5516 face_change_count
= face_change_count_before
;
5518 /* Discard the unwind_protect. */
5519 return unbind_to (count
, frame
);
5523 /* Compute where to display tip frame F. PARMS is the list of frame
5524 parameters for F. DX and DY are specified offsets from the current
5525 location of the mouse. WIDTH and HEIGHT are the width and height
5526 of the tooltip. Return coordinates relative to the root window of
5527 the display in *ROOT_X, and *ROOT_Y. */
5530 compute_tip_xy (struct frame
*f
,
5531 Lisp_Object parms
, Lisp_Object dx
, Lisp_Object dy
,
5532 int width
, int height
, int *root_x
, int *root_y
)
5534 Lisp_Object left
, top
;
5535 int min_x
, min_y
, max_x
, max_y
;
5537 /* User-specified position? */
5538 left
= Fcdr (Fassq (Qleft
, parms
));
5539 top
= Fcdr (Fassq (Qtop
, parms
));
5541 /* Move the tooltip window where the mouse pointer is. Resize and
5543 if (!INTEGERP (left
) || !INTEGERP (top
))
5547 /* Default min and max values. */
5550 max_x
= x_display_pixel_width (FRAME_W32_DISPLAY_INFO (f
));
5551 max_y
= x_display_pixel_height (FRAME_W32_DISPLAY_INFO (f
));
5559 /* If multiple monitor support is available, constrain the tip onto
5560 the current monitor. This improves the above by allowing negative
5561 co-ordinates if monitor positions are such that they are valid, and
5562 snaps a tooltip onto a single monitor if we are close to the edge
5563 where it would otherwise flow onto the other monitor (or into
5564 nothingness if there is a gap in the overlap). */
5565 if (monitor_from_point_fn
&& get_monitor_info_fn
)
5567 struct MONITOR_INFO info
;
5569 = monitor_from_point_fn (pt
, MONITOR_DEFAULT_TO_NEAREST
);
5570 info
.cbSize
= sizeof (info
);
5572 if (get_monitor_info_fn (monitor
, &info
))
5574 min_x
= info
.rcWork
.left
;
5575 min_y
= info
.rcWork
.top
;
5576 max_x
= info
.rcWork
.right
;
5577 max_y
= info
.rcWork
.bottom
;
5583 *root_y
= XINT (top
);
5584 else if (*root_y
+ XINT (dy
) <= min_y
)
5585 *root_y
= min_y
; /* Can happen for negative dy */
5586 else if (*root_y
+ XINT (dy
) + height
<= max_y
)
5587 /* It fits below the pointer */
5588 *root_y
+= XINT (dy
);
5589 else if (height
+ XINT (dy
) + min_y
<= *root_y
)
5590 /* It fits above the pointer. */
5591 *root_y
-= height
+ XINT (dy
);
5593 /* Put it on the top. */
5596 if (INTEGERP (left
))
5597 *root_x
= XINT (left
);
5598 else if (*root_x
+ XINT (dx
) <= min_x
)
5599 *root_x
= 0; /* Can happen for negative dx */
5600 else if (*root_x
+ XINT (dx
) + width
<= max_x
)
5601 /* It fits to the right of the pointer. */
5602 *root_x
+= XINT (dx
);
5603 else if (width
+ XINT (dx
) + min_x
<= *root_x
)
5604 /* It fits to the left of the pointer. */
5605 *root_x
-= width
+ XINT (dx
);
5607 /* Put it left justified on the screen -- it ought to fit that way. */
5612 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
5613 doc
: /* Show STRING in a \"tooltip\" window on frame FRAME.
5614 A tooltip window is a small window displaying a string.
5616 This is an internal function; Lisp code should call `tooltip-show'.
5618 FRAME nil or omitted means use the selected frame.
5620 PARMS is an optional list of frame parameters which can be
5621 used to change the tooltip's appearance.
5623 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
5624 means use the default timeout of 5 seconds.
5626 If the list of frame parameters PARMS contains a `left' parameter,
5627 the tooltip is displayed at that x-position. Otherwise it is
5628 displayed at the mouse position, with offset DX added (default is 5 if
5629 DX isn't specified). Likewise for the y-position; if a `top' frame
5630 parameter is specified, it determines the y-position of the tooltip
5631 window, otherwise it is displayed at the mouse position, with offset
5632 DY added (default is -10).
5634 A tooltip's maximum size is specified by `x-max-tooltip-size'.
5635 Text larger than the specified size is clipped. */)
5636 (Lisp_Object string
, Lisp_Object frame
, Lisp_Object parms
, Lisp_Object timeout
, Lisp_Object dx
, Lisp_Object dy
)
5641 struct buffer
*old_buffer
;
5642 struct text_pos pos
;
5643 int i
, width
, height
;
5644 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5645 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5646 int count
= SPECPDL_INDEX ();
5648 specbind (Qinhibit_redisplay
, Qt
);
5650 GCPRO4 (string
, parms
, frame
, timeout
);
5652 CHECK_STRING (string
);
5653 f
= check_x_frame (frame
);
5655 timeout
= make_number (5);
5657 CHECK_NATNUM (timeout
);
5660 dx
= make_number (5);
5665 dy
= make_number (-10);
5669 if (NILP (last_show_tip_args
))
5670 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
5672 if (!NILP (tip_frame
))
5674 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
5675 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
5676 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
5678 if (EQ (frame
, last_frame
)
5679 && !NILP (Fequal (last_string
, string
))
5680 && !NILP (Fequal (last_parms
, parms
)))
5682 struct frame
*f
= XFRAME (tip_frame
);
5684 /* Only DX and DY have changed. */
5685 if (!NILP (tip_timer
))
5687 Lisp_Object timer
= tip_timer
;
5689 call1 (Qcancel_timer
, timer
);
5693 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
5694 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
5696 /* Put tooltip in topmost group and in position. */
5697 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
5698 root_x
, root_y
, 0, 0,
5699 SWP_NOSIZE
| SWP_NOACTIVATE
);
5701 /* Ensure tooltip is on top of other topmost windows (eg menus). */
5702 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
5704 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
5711 /* Hide a previous tip, if any. */
5714 ASET (last_show_tip_args
, 0, string
);
5715 ASET (last_show_tip_args
, 1, frame
);
5716 ASET (last_show_tip_args
, 2, parms
);
5718 /* Add default values to frame parameters. */
5719 if (NILP (Fassq (Qname
, parms
)))
5720 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
5721 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5722 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
5723 if (NILP (Fassq (Qborder_width
, parms
)))
5724 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
5725 if (NILP (Fassq (Qborder_color
, parms
)))
5726 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
5727 if (NILP (Fassq (Qbackground_color
, parms
)))
5728 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
5731 /* Block input until the tip has been fully drawn, to avoid crashes
5732 when drawing tips in menus. */
5735 /* Create a frame for the tooltip, and record it in the global
5736 variable tip_frame. */
5737 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
, string
);
5740 /* Set up the frame's root window. */
5741 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5742 w
->left_col
= w
->top_line
= make_number (0);
5744 if (CONSP (Vx_max_tooltip_size
)
5745 && INTEGERP (XCAR (Vx_max_tooltip_size
))
5746 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
5747 && INTEGERP (XCDR (Vx_max_tooltip_size
))
5748 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
5750 w
->total_cols
= XCAR (Vx_max_tooltip_size
);
5751 w
->total_lines
= XCDR (Vx_max_tooltip_size
);
5755 w
->total_cols
= make_number (80);
5756 w
->total_lines
= make_number (40);
5759 FRAME_TOTAL_COLS (f
) = XINT (w
->total_cols
);
5761 w
->pseudo_window_p
= 1;
5763 /* Display the tooltip text in a temporary buffer. */
5764 old_buffer
= current_buffer
;
5765 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
5766 current_buffer
->truncate_lines
= Qnil
;
5767 clear_glyph_matrix (w
->desired_matrix
);
5768 clear_glyph_matrix (w
->current_matrix
);
5769 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
5770 try_window (FRAME_ROOT_WINDOW (f
), pos
, 0);
5772 /* Compute width and height of the tooltip. */
5774 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5776 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5780 /* Stop at the first empty row at the end. */
5781 if (!row
->enabled_p
|| !row
->displays_text_p
)
5784 /* Let the row go over the full width of the frame. */
5785 row
->full_width_p
= 1;
5787 #ifdef TODO /* Investigate why some fonts need more width than is
5788 calculated for some tooltips. */
5789 /* There's a glyph at the end of rows that is use to place
5790 the cursor there. Don't include the width of this glyph. */
5791 if (row
->used
[TEXT_AREA
])
5793 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5794 row_width
= row
->pixel_width
- last
->pixel_width
;
5798 row_width
= row
->pixel_width
;
5800 /* TODO: find why tips do not draw along baseline as instructed. */
5801 height
+= row
->height
;
5802 width
= max (width
, row_width
);
5805 /* Add the frame's internal border to the width and height the X
5806 window should have. */
5807 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5808 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5810 /* Move the tooltip window where the mouse pointer is. Resize and
5812 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
5815 /* Adjust Window size to take border into account. */
5817 rect
.left
= rect
.top
= 0;
5819 rect
.bottom
= height
;
5820 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
5821 FRAME_EXTERNAL_MENU_BAR (f
));
5823 /* Position and size tooltip, and put it in the topmost group.
5824 The add-on of 3 to the 5th argument is a kludge: without it,
5825 some fonts cause the last character of the tip to be truncated,
5826 for some obscure reason. */
5827 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
5828 root_x
, root_y
, rect
.right
- rect
.left
+ 3,
5829 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
);
5831 /* Ensure tooltip is on top of other topmost windows (eg menus). */
5832 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
5834 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
5836 /* Let redisplay know that we have made the frame visible already. */
5837 f
->async_visible
= 1;
5839 ShowWindow (FRAME_W32_WINDOW (f
), SW_SHOWNOACTIVATE
);
5842 /* Draw into the window. */
5843 w
->must_be_updated_p
= 1;
5844 update_single_window (w
, 1);
5848 /* Restore original current buffer. */
5849 set_buffer_internal_1 (old_buffer
);
5850 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5853 /* Let the tip disappear after timeout seconds. */
5854 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
5855 intern ("x-hide-tip"));
5858 return unbind_to (count
, Qnil
);
5862 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
5863 doc
: /* Hide the current tooltip window, if there is any.
5864 Value is t if tooltip was open, nil otherwise. */)
5868 Lisp_Object deleted
, frame
, timer
;
5869 struct gcpro gcpro1
, gcpro2
;
5871 /* Return quickly if nothing to do. */
5872 if (NILP (tip_timer
) && NILP (tip_frame
))
5877 GCPRO2 (frame
, timer
);
5878 tip_frame
= tip_timer
= deleted
= Qnil
;
5880 count
= SPECPDL_INDEX ();
5881 specbind (Qinhibit_redisplay
, Qt
);
5882 specbind (Qinhibit_quit
, Qt
);
5885 call1 (Qcancel_timer
, timer
);
5889 delete_frame (frame
, Qnil
);
5894 return unbind_to (count
, deleted
);
5897 /***********************************************************************
5898 File selection dialog
5899 ***********************************************************************/
5900 extern Lisp_Object Qfile_name_history
;
5902 /* Callback for altering the behavior of the Open File dialog.
5903 Makes the Filename text field contain "Current Directory" and be
5904 read-only when "Directories" is selected in the filter. This
5905 allows us to work around the fact that the standard Open File
5906 dialog does not support directories. */
5908 file_dialog_callback (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
5910 if (msg
== WM_NOTIFY
)
5912 OFNOTIFY
* notify
= (OFNOTIFY
*)lParam
;
5913 /* Detect when the Filter dropdown is changed. */
5914 if (notify
->hdr
.code
== CDN_TYPECHANGE
5915 || notify
->hdr
.code
== CDN_INITDONE
)
5917 HWND dialog
= GetParent (hwnd
);
5918 HWND edit_control
= GetDlgItem (dialog
, FILE_NAME_TEXT_FIELD
);
5920 /* Directories is in index 2. */
5921 if (notify
->lpOFN
->nFilterIndex
== 2)
5923 CommDlg_OpenSave_SetControlText (dialog
, FILE_NAME_TEXT_FIELD
,
5924 "Current Directory");
5925 EnableWindow (edit_control
, FALSE
);
5929 /* Don't override default filename on init done. */
5930 if (notify
->hdr
.code
== CDN_TYPECHANGE
)
5931 CommDlg_OpenSave_SetControlText (dialog
,
5932 FILE_NAME_TEXT_FIELD
, "");
5933 EnableWindow (edit_control
, TRUE
);
5940 /* Since we compile with _WIN32_WINNT set to 0x0400 (for NT4 compatibility)
5941 we end up with the old file dialogs. Define a big enough struct for the
5942 new dialog to trick GetOpenFileName into giving us the new dialogs on
5943 Windows 2000 and XP. */
5946 OPENFILENAME real_details
;
5953 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
5954 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5955 Use a file selection dialog.
5956 Select DEFAULT-FILENAME in the dialog's file selection box, if
5957 specified. Ensure that file exists if MUSTMATCH is non-nil.
5958 If ONLY-DIR-P is non-nil, the user can only select directories. */)
5959 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
, Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
5961 struct frame
*f
= SELECTED_FRAME ();
5962 Lisp_Object file
= Qnil
;
5963 int count
= SPECPDL_INDEX ();
5964 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
5965 char filename
[MAX_PATH
+ 1];
5966 char init_dir
[MAX_PATH
+ 1];
5967 int default_filter_index
= 1; /* 1: All Files, 2: Directories only */
5969 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
5970 CHECK_STRING (prompt
);
5973 /* Create the dialog with PROMPT as title, using DIR as initial
5974 directory and using "*" as pattern. */
5975 dir
= Fexpand_file_name (dir
, Qnil
);
5976 strncpy (init_dir
, SDATA (ENCODE_FILE (dir
)), MAX_PATH
);
5977 init_dir
[MAX_PATH
] = '\0';
5978 unixtodos_filename (init_dir
);
5980 if (STRINGP (default_filename
))
5982 char *file_name_only
;
5983 char *full_path_name
= SDATA (ENCODE_FILE (default_filename
));
5985 unixtodos_filename (full_path_name
);
5987 file_name_only
= strrchr (full_path_name
, '\\');
5988 if (!file_name_only
)
5989 file_name_only
= full_path_name
;
5993 strncpy (filename
, file_name_only
, MAX_PATH
);
5994 filename
[MAX_PATH
] = '\0';
6000 NEWOPENFILENAME new_file_details
;
6001 BOOL file_opened
= FALSE
;
6002 OPENFILENAME
* file_details
= &new_file_details
.real_details
;
6004 /* Prevent redisplay. */
6005 specbind (Qinhibit_redisplay
, Qt
);
6008 memset (&new_file_details
, 0, sizeof (new_file_details
));
6009 /* Apparently NT4 crashes if you give it an unexpected size.
6010 I'm not sure about Windows 9x, so play it safe. */
6011 if (w32_major_version
> 4 && w32_major_version
< 95)
6012 file_details
->lStructSize
= sizeof (NEWOPENFILENAME
);
6014 file_details
->lStructSize
= sizeof (OPENFILENAME
);
6016 file_details
->hwndOwner
= FRAME_W32_WINDOW (f
);
6017 /* Undocumented Bug in Common File Dialog:
6018 If a filter is not specified, shell links are not resolved. */
6019 file_details
->lpstrFilter
= "All Files (*.*)\0*.*\0Directories\0*|*\0\0";
6020 file_details
->lpstrFile
= filename
;
6021 file_details
->nMaxFile
= sizeof (filename
);
6022 file_details
->lpstrInitialDir
= init_dir
;
6023 file_details
->lpstrTitle
= SDATA (prompt
);
6025 if (! NILP (only_dir_p
))
6026 default_filter_index
= 2;
6028 file_details
->nFilterIndex
= default_filter_index
;
6030 file_details
->Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
6031 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
6032 if (!NILP (mustmatch
))
6034 /* Require that the path to the parent directory exists. */
6035 file_details
->Flags
|= OFN_PATHMUSTEXIST
;
6036 /* If we are looking for a file, require that it exists. */
6037 if (NILP (only_dir_p
))
6038 file_details
->Flags
|= OFN_FILEMUSTEXIST
;
6041 file_details
->lpfnHook
= (LPOFNHOOKPROC
) file_dialog_callback
;
6043 file_opened
= GetOpenFileName (file_details
);
6049 dostounix_filename (filename
);
6051 if (file_details
->nFilterIndex
== 2)
6053 /* "Directories" selected - strip dummy file name. */
6054 char * last
= strrchr (filename
, '/');
6058 file
= DECODE_FILE (build_string (filename
));
6060 /* User cancelled the dialog without making a selection. */
6061 else if (!CommDlgExtendedError ())
6063 /* An error occurred, fallback on reading from the mini-buffer. */
6065 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
6066 dir
, mustmatch
, dir
, Qfile_name_history
,
6067 default_filename
, Qnil
);
6069 file
= unbind_to (count
, file
);
6074 /* Make "Cancel" equivalent to C-g. */
6076 Fsignal (Qquit
, Qnil
);
6078 return unbind_to (count
, file
);
6082 /* Moving files to the system recycle bin.
6083 Used by `move-file-to-trash' instead of the default moving to ~/.Trash */
6084 DEFUN ("system-move-file-to-trash", Fsystem_move_file_to_trash
,
6085 Ssystem_move_file_to_trash
, 1, 1, 0,
6086 doc
: /* Move file or directory named FILENAME to the recycle bin. */)
6087 (Lisp_Object filename
)
6089 Lisp_Object handler
;
6090 Lisp_Object encoded_file
;
6091 Lisp_Object operation
;
6093 operation
= Qdelete_file
;
6094 if (!NILP (Ffile_directory_p (filename
))
6095 && NILP (Ffile_symlink_p (filename
)))
6097 operation
= intern ("delete-directory");
6098 filename
= Fdirectory_file_name (filename
);
6100 filename
= Fexpand_file_name (filename
, Qnil
);
6102 handler
= Ffind_file_name_handler (filename
, operation
);
6103 if (!NILP (handler
))
6104 return call2 (handler
, operation
, filename
);
6106 encoded_file
= ENCODE_FILE (filename
);
6110 SHFILEOPSTRUCT file_op
;
6111 char tmp_path
[MAX_PATH
+ 1];
6113 path
= map_w32_filename (SDATA (encoded_file
), NULL
);
6115 /* On Windows, write permission is required to delete/move files. */
6116 _chmod (path
, 0666);
6118 memset (tmp_path
, 0, sizeof (tmp_path
));
6119 strcpy (tmp_path
, path
);
6121 memset (&file_op
, 0, sizeof (file_op
));
6122 file_op
.hwnd
= HWND_DESKTOP
;
6123 file_op
.wFunc
= FO_DELETE
;
6124 file_op
.pFrom
= tmp_path
;
6125 file_op
.fFlags
= FOF_SILENT
| FOF_NOCONFIRMATION
| FOF_ALLOWUNDO
6126 | FOF_NOERRORUI
| FOF_NO_CONNECTED_ELEMENTS
;
6127 file_op
.fAnyOperationsAborted
= FALSE
;
6129 if (SHFileOperation (&file_op
) != 0)
6130 report_file_error ("Removing old name", list1 (filename
));
6136 /***********************************************************************
6137 w32 specialized functions
6138 ***********************************************************************/
6140 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
,
6141 Sw32_send_sys_command
, 1, 2, 0,
6142 doc
: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND.
6143 Some useful values for COMMAND are #xf030 to maximize frame (#xf020
6144 to minimize), #xf120 to restore frame to original size, and #xf100
6145 to activate the menubar for keyboard access. #xf140 activates the
6146 screen saver if defined.
6148 If optional parameter FRAME is not specified, use selected frame. */)
6149 (Lisp_Object command
, Lisp_Object frame
)
6151 FRAME_PTR f
= check_x_frame (frame
);
6153 CHECK_NUMBER (command
);
6155 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
6160 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
6161 doc
: /* Get Windows to perform OPERATION on DOCUMENT.
6162 This is a wrapper around the ShellExecute system function, which
6163 invokes the application registered to handle OPERATION for DOCUMENT.
6165 OPERATION is either nil or a string that names a supported operation.
6166 What operations can be used depends on the particular DOCUMENT and its
6167 handler application, but typically it is one of the following common
6170 \"open\" - open DOCUMENT, which could be a file, a directory, or an
6171 executable program. If it is an application, that
6172 application is launched in the current buffer's default
6173 directory. Otherwise, the application associated with
6174 DOCUMENT is launched in the buffer's default directory.
6175 \"print\" - print DOCUMENT, which must be a file
6176 \"explore\" - start the Windows Explorer on DOCUMENT
6177 \"edit\" - launch an editor and open DOCUMENT for editing; which
6178 editor is launched depends on the association for the
6180 \"find\" - initiate search starting from DOCUMENT which must specify
6182 nil - invoke the default OPERATION, or \"open\" if default is
6183 not defined or unavailable
6185 DOCUMENT is typically the name of a document file or a URL, but can
6186 also be a program executable to run, or a directory to open in the
6189 If DOCUMENT is a program executable, the optional third arg PARAMETERS
6190 can be a string containing command line parameters that will be passed
6191 to the program; otherwise, PARAMETERS should be nil or unspecified.
6193 Optional fourth argument SHOW-FLAG can be used to control how the
6194 application will be displayed when it is invoked. If SHOW-FLAG is nil
6195 or unspecified, the application is displayed normally, otherwise it is
6196 an integer representing a ShowWindow flag:
6201 6 - start minimized */)
6202 (Lisp_Object operation
, Lisp_Object document
, Lisp_Object parameters
, Lisp_Object show_flag
)
6204 Lisp_Object current_dir
;
6207 CHECK_STRING (document
);
6209 /* Encode filename, current directory and parameters. */
6210 current_dir
= ENCODE_FILE (current_buffer
->directory
);
6211 document
= ENCODE_FILE (document
);
6212 if (STRINGP (parameters
))
6213 parameters
= ENCODE_SYSTEM (parameters
);
6215 if ((int) ShellExecute (NULL
,
6216 (STRINGP (operation
) ?
6217 SDATA (operation
) : NULL
),
6219 (STRINGP (parameters
) ?
6220 SDATA (parameters
) : NULL
),
6221 SDATA (current_dir
),
6222 (INTEGERP (show_flag
) ?
6223 XINT (show_flag
) : SW_SHOWDEFAULT
))
6226 errstr
= w32_strerror (0);
6227 /* The error string might be encoded in the locale's encoding. */
6228 if (!NILP (Vlocale_coding_system
))
6230 Lisp_Object decoded
=
6231 code_convert_string_norecord (make_unibyte_string (errstr
,
6233 Vlocale_coding_system
, 0);
6234 errstr
= (char *)SDATA (decoded
);
6236 error ("ShellExecute failed: %s", errstr
);
6239 /* Lookup virtual keycode from string representing the name of a
6240 non-ascii keystroke into the corresponding virtual key, using
6241 lispy_function_keys. */
6243 lookup_vk_code (char *key
)
6247 for (i
= 0; i
< 256; i
++)
6248 if (lispy_function_keys
[i
]
6249 && strcmp (lispy_function_keys
[i
], key
) == 0)
6255 /* Convert a one-element vector style key sequence to a hot key
6258 w32_parse_hot_key (Lisp_Object key
)
6260 /* Copied from Fdefine_key and store_in_keymap. */
6261 register Lisp_Object c
;
6265 struct gcpro gcpro1
;
6269 if (XFASTINT (Flength (key
)) != 1)
6274 c
= Faref (key
, make_number (0));
6276 if (CONSP (c
) && lucid_event_type_list_p (c
))
6277 c
= Fevent_convert_list (c
);
6281 if (! INTEGERP (c
) && ! SYMBOLP (c
))
6282 error ("Key definition is invalid");
6284 /* Work out the base key and the modifiers. */
6287 c
= parse_modifiers (c
);
6288 lisp_modifiers
= XINT (Fcar (Fcdr (c
)));
6292 vk_code
= lookup_vk_code (SDATA (SYMBOL_NAME (c
)));
6294 else if (INTEGERP (c
))
6296 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
6297 /* Many ascii characters are their own virtual key code. */
6298 vk_code
= XINT (c
) & CHARACTERBITS
;
6301 if (vk_code
< 0 || vk_code
> 255)
6304 if ((lisp_modifiers
& meta_modifier
) != 0
6305 && !NILP (Vw32_alt_is_meta
))
6306 lisp_modifiers
|= alt_modifier
;
6308 /* Supply defs missing from mingw32. */
6310 #define MOD_ALT 0x0001
6311 #define MOD_CONTROL 0x0002
6312 #define MOD_SHIFT 0x0004
6313 #define MOD_WIN 0x0008
6316 /* Convert lisp modifiers to Windows hot-key form. */
6317 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
6318 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
6319 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
6320 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
6322 return HOTKEY (vk_code
, w32_modifiers
);
6325 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
,
6326 Sw32_register_hot_key
, 1, 1, 0,
6327 doc
: /* Register KEY as a hot-key combination.
6328 Certain key combinations like Alt-Tab are reserved for system use on
6329 Windows, and therefore are normally intercepted by the system. However,
6330 most of these key combinations can be received by registering them as
6331 hot-keys, overriding their special meaning.
6333 KEY must be a one element key definition in vector form that would be
6334 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta
6335 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper
6336 is always interpreted as the Windows modifier keys.
6338 The return value is the hotkey-id if registered, otherwise nil. */)
6341 key
= w32_parse_hot_key (key
);
6343 if (!NILP (key
) && NILP (Fmemq (key
, w32_grabbed_keys
)))
6345 /* Reuse an empty slot if possible. */
6346 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
6348 /* Safe to add new key to list, even if we have focus. */
6350 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
6352 XSETCAR (item
, key
);
6354 /* Notify input thread about new hot-key definition, so that it
6355 takes effect without needing to switch focus. */
6356 #ifdef USE_LISP_UNION_TYPE
6357 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
6360 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
6368 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
,
6369 Sw32_unregister_hot_key
, 1, 1, 0,
6370 doc
: /* Unregister KEY as a hot-key combination. */)
6375 if (!INTEGERP (key
))
6376 key
= w32_parse_hot_key (key
);
6378 item
= Fmemq (key
, w32_grabbed_keys
);
6382 /* Notify input thread about hot-key definition being removed, so
6383 that it takes effect without needing focus switch. */
6384 #ifdef USE_LISP_UNION_TYPE
6385 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
6386 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
.i
))
6388 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
6389 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
))
6393 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
6400 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
,
6401 Sw32_registered_hot_keys
, 0, 0, 0,
6402 doc
: /* Return list of registered hot-key IDs. */)
6405 return Fdelq (Qnil
, Fcopy_sequence (w32_grabbed_keys
));
6408 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
,
6409 Sw32_reconstruct_hot_key
, 1, 1, 0,
6410 doc
: /* Convert hot-key ID to a lisp key combination.
6411 usage: (w32-reconstruct-hot-key ID) */)
6412 (Lisp_Object hotkeyid
)
6414 int vk_code
, w32_modifiers
;
6417 CHECK_NUMBER (hotkeyid
);
6419 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
6420 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
6422 if (vk_code
< 256 && lispy_function_keys
[vk_code
])
6423 key
= intern (lispy_function_keys
[vk_code
]);
6425 key
= make_number (vk_code
);
6427 key
= Fcons (key
, Qnil
);
6428 if (w32_modifiers
& MOD_SHIFT
)
6429 key
= Fcons (Qshift
, key
);
6430 if (w32_modifiers
& MOD_CONTROL
)
6431 key
= Fcons (Qctrl
, key
);
6432 if (w32_modifiers
& MOD_ALT
)
6433 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
6434 if (w32_modifiers
& MOD_WIN
)
6435 key
= Fcons (Qhyper
, key
);
6440 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
,
6441 Sw32_toggle_lock_key
, 1, 2, 0,
6442 doc
: /* Toggle the state of the lock key KEY.
6443 KEY can be `capslock', `kp-numlock', or `scroll'.
6444 If the optional parameter NEW-STATE is a number, then the state of KEY
6445 is set to off if the low bit of NEW-STATE is zero, otherwise on. */)
6446 (Lisp_Object key
, Lisp_Object new_state
)
6450 if (EQ (key
, intern ("capslock")))
6451 vk_code
= VK_CAPITAL
;
6452 else if (EQ (key
, intern ("kp-numlock")))
6453 vk_code
= VK_NUMLOCK
;
6454 else if (EQ (key
, intern ("scroll")))
6455 vk_code
= VK_SCROLL
;
6459 if (!dwWindowsThreadId
)
6460 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
6462 #ifdef USE_LISP_UNION_TYPE
6463 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
6464 (WPARAM
) vk_code
, (LPARAM
) new_state
.i
))
6466 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
6467 (WPARAM
) vk_code
, (LPARAM
) new_state
))
6471 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
6472 return make_number (msg
.wParam
);
6477 DEFUN ("w32-window-exists-p", Fw32_window_exists_p
, Sw32_window_exists_p
,
6479 doc
: /* Return non-nil if a window exists with the specified CLASS and NAME.
6481 This is a direct interface to the Windows API FindWindow function. */)
6482 (Lisp_Object
class, Lisp_Object name
)
6487 CHECK_STRING (class);
6489 CHECK_STRING (name
);
6491 hnd
= FindWindow (STRINGP (class) ? ((LPCTSTR
) SDATA (class)) : NULL
,
6492 STRINGP (name
) ? ((LPCTSTR
) SDATA (name
)) : NULL
);
6498 DEFUN ("w32-battery-status", Fw32_battery_status
, Sw32_battery_status
, 0, 0, 0,
6499 doc
: /* Get power status information from Windows system.
6501 The following %-sequences are provided:
6502 %L AC line status (verbose)
6503 %B Battery status (verbose)
6504 %b Battery status, empty means high, `-' means low,
6505 `!' means critical, and `+' means charging
6506 %p Battery load percentage
6507 %s Remaining time (to charge or discharge) in seconds
6508 %m Remaining time (to charge or discharge) in minutes
6509 %h Remaining time (to charge or discharge) in hours
6510 %t Remaining time (to charge or discharge) in the form `h:min' */)
6513 Lisp_Object status
= Qnil
;
6515 SYSTEM_POWER_STATUS system_status
;
6516 if (GetSystemPowerStatus (&system_status
))
6518 Lisp_Object line_status
, battery_status
, battery_status_symbol
;
6519 Lisp_Object load_percentage
, seconds
, minutes
, hours
, remain
;
6520 Lisp_Object sequences
[8];
6522 long seconds_left
= (long) system_status
.BatteryLifeTime
;
6524 if (system_status
.ACLineStatus
== 0)
6525 line_status
= build_string ("off-line");
6526 else if (system_status
.ACLineStatus
== 1)
6527 line_status
= build_string ("on-line");
6529 line_status
= build_string ("N/A");
6531 if (system_status
.BatteryFlag
& 128)
6533 battery_status
= build_string ("N/A");
6534 battery_status_symbol
= empty_unibyte_string
;
6536 else if (system_status
.BatteryFlag
& 8)
6538 battery_status
= build_string ("charging");
6539 battery_status_symbol
= build_string ("+");
6540 if (system_status
.BatteryFullLifeTime
!= -1L)
6541 seconds_left
= system_status
.BatteryFullLifeTime
- seconds_left
;
6543 else if (system_status
.BatteryFlag
& 4)
6545 battery_status
= build_string ("critical");
6546 battery_status_symbol
= build_string ("!");
6548 else if (system_status
.BatteryFlag
& 2)
6550 battery_status
= build_string ("low");
6551 battery_status_symbol
= build_string ("-");
6553 else if (system_status
.BatteryFlag
& 1)
6555 battery_status
= build_string ("high");
6556 battery_status_symbol
= empty_unibyte_string
;
6560 battery_status
= build_string ("medium");
6561 battery_status_symbol
= empty_unibyte_string
;
6564 if (system_status
.BatteryLifePercent
> 100)
6565 load_percentage
= build_string ("N/A");
6569 _snprintf (buffer
, 16, "%d", system_status
.BatteryLifePercent
);
6570 load_percentage
= build_string (buffer
);
6573 if (seconds_left
< 0)
6574 seconds
= minutes
= hours
= remain
= build_string ("N/A");
6580 _snprintf (buffer
, 16, "%ld", seconds_left
);
6581 seconds
= build_string (buffer
);
6583 m
= seconds_left
/ 60;
6584 _snprintf (buffer
, 16, "%ld", m
);
6585 minutes
= build_string (buffer
);
6587 h
= seconds_left
/ 3600.0;
6588 _snprintf (buffer
, 16, "%3.1f", h
);
6589 hours
= build_string (buffer
);
6591 _snprintf (buffer
, 16, "%ld:%02ld", m
/ 60, m
% 60);
6592 remain
= build_string (buffer
);
6594 sequences
[0] = Fcons (make_number ('L'), line_status
);
6595 sequences
[1] = Fcons (make_number ('B'), battery_status
);
6596 sequences
[2] = Fcons (make_number ('b'), battery_status_symbol
);
6597 sequences
[3] = Fcons (make_number ('p'), load_percentage
);
6598 sequences
[4] = Fcons (make_number ('s'), seconds
);
6599 sequences
[5] = Fcons (make_number ('m'), minutes
);
6600 sequences
[6] = Fcons (make_number ('h'), hours
);
6601 sequences
[7] = Fcons (make_number ('t'), remain
);
6603 status
= Flist (8, sequences
);
6609 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
6610 doc
: /* Return storage information about the file system FILENAME is on.
6611 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
6612 storage of the file system, FREE is the free storage, and AVAIL is the
6613 storage available to a non-superuser. All 3 numbers are in bytes.
6614 If the underlying system call fails, value is nil. */)
6615 (Lisp_Object filename
)
6617 Lisp_Object encoded
, value
;
6619 CHECK_STRING (filename
);
6620 filename
= Fexpand_file_name (filename
, Qnil
);
6621 encoded
= ENCODE_FILE (filename
);
6625 /* Determining the required information on Windows turns out, sadly,
6626 to be more involved than one would hope. The original Win32 api
6627 call for this will return bogus information on some systems, but we
6628 must dynamically probe for the replacement api, since that was
6629 added rather late on. */
6631 HMODULE hKernel
= GetModuleHandle ("kernel32");
6632 BOOL (*pfn_GetDiskFreeSpaceEx
)
6633 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
6634 = (void *) GetProcAddress (hKernel
, "GetDiskFreeSpaceEx");
6636 /* On Windows, we may need to specify the root directory of the
6637 volume holding FILENAME. */
6638 char rootname
[MAX_PATH
];
6639 char *name
= SDATA (encoded
);
6641 /* find the root name of the volume if given */
6642 if (isalpha (name
[0]) && name
[1] == ':')
6644 rootname
[0] = name
[0];
6645 rootname
[1] = name
[1];
6649 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
6651 char *str
= rootname
;
6655 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
6665 if (pfn_GetDiskFreeSpaceEx
)
6667 /* Unsigned large integers cannot be cast to double, so
6668 use signed ones instead. */
6669 LARGE_INTEGER availbytes
;
6670 LARGE_INTEGER freebytes
;
6671 LARGE_INTEGER totalbytes
;
6673 if (pfn_GetDiskFreeSpaceEx (rootname
,
6674 (ULARGE_INTEGER
*)&availbytes
,
6675 (ULARGE_INTEGER
*)&totalbytes
,
6676 (ULARGE_INTEGER
*)&freebytes
))
6677 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
6678 make_float ((double) freebytes
.QuadPart
),
6679 make_float ((double) availbytes
.QuadPart
));
6683 DWORD sectors_per_cluster
;
6684 DWORD bytes_per_sector
;
6685 DWORD free_clusters
;
6686 DWORD total_clusters
;
6688 if (GetDiskFreeSpace (rootname
,
6689 §ors_per_cluster
,
6693 value
= list3 (make_float ((double) total_clusters
6694 * sectors_per_cluster
* bytes_per_sector
),
6695 make_float ((double) free_clusters
6696 * sectors_per_cluster
* bytes_per_sector
),
6697 make_float ((double) free_clusters
6698 * sectors_per_cluster
* bytes_per_sector
));
6705 DEFUN ("default-printer-name", Fdefault_printer_name
, Sdefault_printer_name
,
6706 0, 0, 0, doc
: /* Return the name of Windows default printer device. */)
6709 static char pname_buf
[256];
6712 PRINTER_INFO_2
*ppi2
= NULL
;
6713 DWORD dwNeeded
= 0, dwReturned
= 0;
6715 /* Retrieve the default string from Win.ini (the registry).
6716 * String will be in form "printername,drivername,portname".
6717 * This is the most portable way to get the default printer. */
6718 if (GetProfileString ("windows", "device", ",,", pname_buf
, sizeof (pname_buf
)) <= 0)
6720 /* printername precedes first "," character */
6721 strtok (pname_buf
, ",");
6722 /* We want to know more than the printer name */
6723 if (!OpenPrinter (pname_buf
, &hPrn
, NULL
))
6725 GetPrinter (hPrn
, 2, NULL
, 0, &dwNeeded
);
6728 ClosePrinter (hPrn
);
6731 /* Allocate memory for the PRINTER_INFO_2 struct */
6732 ppi2
= (PRINTER_INFO_2
*) xmalloc (dwNeeded
);
6735 ClosePrinter (hPrn
);
6738 /* Call GetPrinter again with big enouth memory block */
6739 err
= GetPrinter (hPrn
, 2, (LPBYTE
)ppi2
, dwNeeded
, &dwReturned
);
6740 ClosePrinter (hPrn
);
6749 if (ppi2
->Attributes
& PRINTER_ATTRIBUTE_SHARED
&& ppi2
->pServerName
)
6751 /* a remote printer */
6752 if (*ppi2
->pServerName
== '\\')
6753 _snprintf (pname_buf
, sizeof (pname_buf
), "%s\\%s", ppi2
->pServerName
,
6756 _snprintf (pname_buf
, sizeof (pname_buf
), "\\\\%s\\%s", ppi2
->pServerName
,
6758 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
6762 /* a local printer */
6763 strncpy (pname_buf
, ppi2
->pPortName
, sizeof (pname_buf
));
6764 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
6765 /* `pPortName' can include several ports, delimited by ','.
6766 * we only use the first one. */
6767 strtok (pname_buf
, ",");
6772 return build_string (pname_buf
);
6775 /***********************************************************************
6777 ***********************************************************************/
6779 /* Keep this list in the same order as frame_parms in frame.c.
6780 Use 0 for unsupported frame parameters. */
6782 frame_parm_handler w32_frame_parm_handlers
[] =
6786 x_set_background_color
,
6792 x_set_foreground_color
,
6795 x_set_internal_border_width
,
6796 x_set_menu_bar_lines
,
6798 x_explicitly_set_name
,
6799 x_set_scroll_bar_width
,
6802 x_set_vertical_scroll_bars
,
6804 x_set_tool_bar_lines
,
6805 0, /* x_set_scroll_bar_foreground, */
6806 0, /* x_set_scroll_bar_background, */
6811 0, /* x_set_wait_for_wm, */
6815 0, /* x_set_sticky */
6819 syms_of_w32fns (void)
6821 globals_of_w32fns ();
6822 /* This is zero if not using MS-Windows. */
6824 track_mouse_window
= NULL
;
6826 w32_visible_system_caret_hwnd
= NULL
;
6828 DEFSYM (Qnone
, "none");
6829 DEFSYM (Qsuppress_icon
, "suppress-icon");
6830 DEFSYM (Qundefined_color
, "undefined-color");
6831 DEFSYM (Qcancel_timer
, "cancel-timer");
6832 DEFSYM (Qhyper
, "hyper");
6833 DEFSYM (Qsuper
, "super");
6834 DEFSYM (Qmeta
, "meta");
6835 DEFSYM (Qalt
, "alt");
6836 DEFSYM (Qctrl
, "ctrl");
6837 DEFSYM (Qcontrol
, "control");
6838 DEFSYM (Qshift
, "shift");
6839 DEFSYM (Qfont_param
, "font-parameter");
6840 /* This is the end of symbol initialization. */
6842 /* Text property `display' should be nonsticky by default. */
6843 Vtext_property_default_nonsticky
6844 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
6847 Fput (Qundefined_color
, Qerror_conditions
,
6848 pure_cons (Qundefined_color
, pure_cons (Qerror
, Qnil
)));
6849 Fput (Qundefined_color
, Qerror_message
,
6850 make_pure_c_string ("Undefined color"));
6852 staticpro (&w32_grabbed_keys
);
6853 w32_grabbed_keys
= Qnil
;
6855 DEFVAR_LISP ("w32-color-map", &Vw32_color_map
,
6856 doc
: /* An array of color name mappings for Windows. */);
6857 Vw32_color_map
= Qnil
;
6859 DEFVAR_LISP ("w32-pass-alt-to-system", &Vw32_pass_alt_to_system
,
6860 doc
: /* Non-nil if Alt key presses are passed on to Windows.
6861 When non-nil, for example, Alt pressed and released and then space will
6862 open the System menu. When nil, Emacs processes the Alt key events, and
6863 then silently swallows them. */);
6864 Vw32_pass_alt_to_system
= Qnil
;
6866 DEFVAR_LISP ("w32-alt-is-meta", &Vw32_alt_is_meta
,
6867 doc
: /* Non-nil if the Alt key is to be considered the same as the META key.
6868 When nil, Emacs will translate the Alt key to the ALT modifier, not to META. */);
6869 Vw32_alt_is_meta
= Qt
;
6871 DEFVAR_INT ("w32-quit-key", &w32_quit_key
,
6872 doc
: /* If non-zero, the virtual key code for an alternative quit key. */);
6875 DEFVAR_LISP ("w32-pass-lwindow-to-system",
6876 &Vw32_pass_lwindow_to_system
,
6877 doc
: /* If non-nil, the left \"Windows\" key is passed on to Windows.
6879 When non-nil, the Start menu is opened by tapping the key.
6880 If you set this to nil, the left \"Windows\" key is processed by Emacs
6881 according to the value of `w32-lwindow-modifier', which see.
6883 Note that some combinations of the left \"Windows\" key with other keys are
6884 caught by Windows at low level, and so binding them in Emacs will have no
6885 effect. For example, <lwindow>-r always pops up the Windows Run dialog,
6886 <lwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
6887 the doc string of `w32-phantom-key-code'. */);
6888 Vw32_pass_lwindow_to_system
= Qt
;
6890 DEFVAR_LISP ("w32-pass-rwindow-to-system",
6891 &Vw32_pass_rwindow_to_system
,
6892 doc
: /* If non-nil, the right \"Windows\" key is passed on to Windows.
6894 When non-nil, the Start menu is opened by tapping the key.
6895 If you set this to nil, the right \"Windows\" key is processed by Emacs
6896 according to the value of `w32-rwindow-modifier', which see.
6898 Note that some combinations of the right \"Windows\" key with other keys are
6899 caught by Windows at low level, and so binding them in Emacs will have no
6900 effect. For example, <rwindow>-r always pops up the Windows Run dialog,
6901 <rwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
6902 the doc string of `w32-phantom-key-code'. */);
6903 Vw32_pass_rwindow_to_system
= Qt
;
6905 DEFVAR_LISP ("w32-phantom-key-code",
6906 &Vw32_phantom_key_code
,
6907 doc
: /* Virtual key code used to generate \"phantom\" key presses.
6908 Value is a number between 0 and 255.
6910 Phantom key presses are generated in order to stop the system from
6911 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or
6912 `w32-pass-rwindow-to-system' is nil. */);
6913 /* Although 255 is technically not a valid key code, it works and
6914 means that this hack won't interfere with any real key code. */
6915 XSETINT (Vw32_phantom_key_code
, 255);
6917 DEFVAR_LISP ("w32-enable-num-lock",
6918 &Vw32_enable_num_lock
,
6919 doc
: /* If non-nil, the Num Lock key acts normally.
6920 Set to nil to handle Num Lock as the `kp-numlock' key. */);
6921 Vw32_enable_num_lock
= Qt
;
6923 DEFVAR_LISP ("w32-enable-caps-lock",
6924 &Vw32_enable_caps_lock
,
6925 doc
: /* If non-nil, the Caps Lock key acts normally.
6926 Set to nil to handle Caps Lock as the `capslock' key. */);
6927 Vw32_enable_caps_lock
= Qt
;
6929 DEFVAR_LISP ("w32-scroll-lock-modifier",
6930 &Vw32_scroll_lock_modifier
,
6931 doc
: /* Modifier to use for the Scroll Lock ON state.
6932 The value can be hyper, super, meta, alt, control or shift for the
6933 respective modifier, or nil to handle Scroll Lock as the `scroll' key.
6934 Any other value will cause the Scroll Lock key to be ignored. */);
6935 Vw32_scroll_lock_modifier
= Qnil
;
6937 DEFVAR_LISP ("w32-lwindow-modifier",
6938 &Vw32_lwindow_modifier
,
6939 doc
: /* Modifier to use for the left \"Windows\" key.
6940 The value can be hyper, super, meta, alt, control or shift for the
6941 respective modifier, or nil to appear as the `lwindow' key.
6942 Any other value will cause the key to be ignored. */);
6943 Vw32_lwindow_modifier
= Qnil
;
6945 DEFVAR_LISP ("w32-rwindow-modifier",
6946 &Vw32_rwindow_modifier
,
6947 doc
: /* Modifier to use for the right \"Windows\" key.
6948 The value can be hyper, super, meta, alt, control or shift for the
6949 respective modifier, or nil to appear as the `rwindow' key.
6950 Any other value will cause the key to be ignored. */);
6951 Vw32_rwindow_modifier
= Qnil
;
6953 DEFVAR_LISP ("w32-apps-modifier",
6954 &Vw32_apps_modifier
,
6955 doc
: /* Modifier to use for the \"Apps\" key.
6956 The value can be hyper, super, meta, alt, control or shift for the
6957 respective modifier, or nil to appear as the `apps' key.
6958 Any other value will cause the key to be ignored. */);
6959 Vw32_apps_modifier
= Qnil
;
6961 DEFVAR_BOOL ("w32-enable-synthesized-fonts", &w32_enable_synthesized_fonts
,
6962 doc
: /* Non-nil enables selection of artificially italicized and bold fonts. */);
6963 w32_enable_synthesized_fonts
= 0;
6965 DEFVAR_LISP ("w32-enable-palette", &Vw32_enable_palette
,
6966 doc
: /* Non-nil enables Windows palette management to map colors exactly. */);
6967 Vw32_enable_palette
= Qt
;
6969 DEFVAR_INT ("w32-mouse-button-tolerance",
6970 &w32_mouse_button_tolerance
,
6971 doc
: /* Analogue of double click interval for faking middle mouse events.
6972 The value is the minimum time in milliseconds that must elapse between
6973 left and right button down events before they are considered distinct events.
6974 If both mouse buttons are depressed within this interval, a middle mouse
6975 button down event is generated instead. */);
6976 w32_mouse_button_tolerance
= GetDoubleClickTime () / 2;
6978 DEFVAR_INT ("w32-mouse-move-interval",
6979 &w32_mouse_move_interval
,
6980 doc
: /* Minimum interval between mouse move events.
6981 The value is the minimum time in milliseconds that must elapse between
6982 successive mouse move (or scroll bar drag) events before they are
6983 reported as lisp events. */);
6984 w32_mouse_move_interval
= 0;
6986 DEFVAR_BOOL ("w32-pass-extra-mouse-buttons-to-system",
6987 &w32_pass_extra_mouse_buttons_to_system
,
6988 doc
: /* If non-nil, the fourth and fifth mouse buttons are passed to Windows.
6989 Recent versions of Windows support mice with up to five buttons.
6990 Since most applications don't support these extra buttons, most mouse
6991 drivers will allow you to map them to functions at the system level.
6992 If this variable is non-nil, Emacs will pass them on, allowing the
6993 system to handle them. */);
6994 w32_pass_extra_mouse_buttons_to_system
= 0;
6996 DEFVAR_BOOL ("w32-pass-multimedia-buttons-to-system",
6997 &w32_pass_multimedia_buttons_to_system
,
6998 doc
: /* If non-nil, media buttons are passed to Windows.
6999 Some modern keyboards contain buttons for controlling media players, web
7000 browsers and other applications. Generally these buttons are handled on a
7001 system wide basis, but by setting this to nil they are made available
7002 to Emacs for binding. Depending on your keyboard, additional keys that
7003 may be available are:
7005 browser-back, browser-forward, browser-refresh, browser-stop,
7006 browser-search, browser-favorites, browser-home,
7007 mail, mail-reply, mail-forward, mail-send,
7009 help, find, new, open, close, save, print, undo, redo, copy, cut, paste,
7010 spell-check, correction-list, toggle-dictate-command,
7011 media-next, media-previous, media-stop, media-play-pause, media-select,
7012 media-play, media-pause, media-record, media-fast-forward, media-rewind,
7013 media-channel-up, media-channel-down,
7014 volume-mute, volume-up, volume-down,
7015 mic-volume-mute, mic-volume-down, mic-volume-up, mic-toggle,
7016 bass-down, bass-boost, bass-up, treble-down, treble-up */);
7017 w32_pass_multimedia_buttons_to_system
= 1;
7019 #if 0 /* TODO: Mouse cursor customization. */
7020 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
7021 doc
: /* The shape of the pointer when over text.
7022 Changing the value does not affect existing frames
7023 unless you set the mouse color. */);
7024 Vx_pointer_shape
= Qnil
;
7026 Vx_nontext_pointer_shape
= Qnil
;
7028 Vx_mode_pointer_shape
= Qnil
;
7030 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
7031 doc
: /* The shape of the pointer when Emacs is busy.
7032 This variable takes effect when you create a new frame
7033 or when you set the mouse color. */);
7034 Vx_hourglass_pointer_shape
= Qnil
;
7036 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
7037 &Vx_sensitive_text_pointer_shape
,
7038 doc
: /* The shape of the pointer when over mouse-sensitive text.
7039 This variable takes effect when you create a new frame
7040 or when you set the mouse color. */);
7041 Vx_sensitive_text_pointer_shape
= Qnil
;
7043 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
7044 &Vx_window_horizontal_drag_shape
,
7045 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
7046 This variable takes effect when you create a new frame
7047 or when you set the mouse color. */);
7048 Vx_window_horizontal_drag_shape
= Qnil
;
7051 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
7052 doc
: /* A string indicating the foreground color of the cursor box. */);
7053 Vx_cursor_fore_pixel
= Qnil
;
7055 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size
,
7056 doc
: /* Maximum size for tooltips.
7057 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
7058 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
7060 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
7061 doc
: /* Non-nil if no window manager is in use.
7062 Emacs doesn't try to figure this out; this is always nil
7063 unless you set it to something else. */);
7064 /* We don't have any way to find this out, so set it to nil
7065 and maybe the user would like to set it to t. */
7066 Vx_no_window_manager
= Qnil
;
7068 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
7069 &Vx_pixel_size_width_font_regexp
,
7070 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
7072 Since Emacs gets width of a font matching with this regexp from
7073 PIXEL_SIZE field of the name, font finding mechanism gets faster for
7074 such a font. This is especially effective for such large fonts as
7075 Chinese, Japanese, and Korean. */);
7076 Vx_pixel_size_width_font_regexp
= Qnil
;
7078 DEFVAR_LISP ("w32-bdf-filename-alist",
7079 &Vw32_bdf_filename_alist
,
7080 doc
: /* List of bdf fonts and their corresponding filenames. */);
7081 Vw32_bdf_filename_alist
= Qnil
;
7083 DEFVAR_BOOL ("w32-strict-fontnames",
7084 &w32_strict_fontnames
,
7085 doc
: /* Non-nil means only use fonts that are exact matches for those requested.
7086 Default is nil, which allows old fontnames that are not XLFD compliant,
7087 and allows third-party CJK display to work by specifying false charset
7088 fields to trick Emacs into translating to Big5, SJIS etc.
7089 Setting this to t will prevent wrong fonts being selected when
7090 fontsets are automatically created. */);
7091 w32_strict_fontnames
= 0;
7093 DEFVAR_BOOL ("w32-strict-painting",
7094 &w32_strict_painting
,
7095 doc
: /* Non-nil means use strict rules for repainting frames.
7096 Set this to nil to get the old behavior for repainting; this should
7097 only be necessary if the default setting causes problems. */);
7098 w32_strict_painting
= 1;
7100 #if 0 /* TODO: Port to W32 */
7101 defsubr (&Sx_change_window_property
);
7102 defsubr (&Sx_delete_window_property
);
7103 defsubr (&Sx_window_property
);
7105 defsubr (&Sxw_display_color_p
);
7106 defsubr (&Sx_display_grayscale_p
);
7107 defsubr (&Sxw_color_defined_p
);
7108 defsubr (&Sxw_color_values
);
7109 defsubr (&Sx_server_max_request_size
);
7110 defsubr (&Sx_server_vendor
);
7111 defsubr (&Sx_server_version
);
7112 defsubr (&Sx_display_pixel_width
);
7113 defsubr (&Sx_display_pixel_height
);
7114 defsubr (&Sx_display_mm_width
);
7115 defsubr (&Sx_display_mm_height
);
7116 defsubr (&Sx_display_screens
);
7117 defsubr (&Sx_display_planes
);
7118 defsubr (&Sx_display_color_cells
);
7119 defsubr (&Sx_display_visual_class
);
7120 defsubr (&Sx_display_backing_store
);
7121 defsubr (&Sx_display_save_under
);
7122 defsubr (&Sx_create_frame
);
7123 defsubr (&Sx_open_connection
);
7124 defsubr (&Sx_close_connection
);
7125 defsubr (&Sx_display_list
);
7126 defsubr (&Sx_synchronize
);
7127 defsubr (&Sx_focus_frame
);
7129 /* W32 specific functions */
7131 defsubr (&Sw32_define_rgb_color
);
7132 defsubr (&Sw32_default_color_map
);
7133 defsubr (&Sw32_send_sys_command
);
7134 defsubr (&Sw32_shell_execute
);
7135 defsubr (&Sw32_register_hot_key
);
7136 defsubr (&Sw32_unregister_hot_key
);
7137 defsubr (&Sw32_registered_hot_keys
);
7138 defsubr (&Sw32_reconstruct_hot_key
);
7139 defsubr (&Sw32_toggle_lock_key
);
7140 defsubr (&Sw32_window_exists_p
);
7141 defsubr (&Sw32_battery_status
);
7143 defsubr (&Sfile_system_info
);
7144 defsubr (&Sdefault_printer_name
);
7146 check_window_system_func
= check_w32
;
7149 hourglass_timer
= 0;
7150 hourglass_hwnd
= NULL
;
7152 defsubr (&Sx_show_tip
);
7153 defsubr (&Sx_hide_tip
);
7155 staticpro (&tip_timer
);
7157 staticpro (&tip_frame
);
7159 last_show_tip_args
= Qnil
;
7160 staticpro (&last_show_tip_args
);
7162 defsubr (&Sx_file_dialog
);
7163 defsubr (&Ssystem_move_file_to_trash
);
7168 globals_of_w32fns is used to initialize those global variables that
7169 must always be initialized on startup even when the global variable
7170 initialized is non zero (see the function main in emacs.c).
7171 globals_of_w32fns is called from syms_of_w32fns when the global
7172 variable initialized is 0 and directly from main when initialized
7176 globals_of_w32fns (void)
7178 HMODULE user32_lib
= GetModuleHandle ("user32.dll");
7180 TrackMouseEvent not available in all versions of Windows, so must load
7181 it dynamically. Do it once, here, instead of every time it is used.
7183 track_mouse_event_fn
= (TrackMouseEvent_Proc
)
7184 GetProcAddress (user32_lib
, "TrackMouseEvent");
7185 /* ditto for GetClipboardSequenceNumber. */
7186 clipboard_sequence_fn
= (ClipboardSequence_Proc
)
7187 GetProcAddress (user32_lib
, "GetClipboardSequenceNumber");
7189 monitor_from_point_fn
= (MonitorFromPoint_Proc
)
7190 GetProcAddress (user32_lib
, "MonitorFromPoint");
7191 get_monitor_info_fn
= (GetMonitorInfo_Proc
)
7192 GetProcAddress (user32_lib
, "GetMonitorInfoA");
7195 HMODULE imm32_lib
= GetModuleHandle ("imm32.dll");
7196 get_composition_string_fn
= (ImmGetCompositionString_Proc
)
7197 GetProcAddress (imm32_lib
, "ImmGetCompositionStringW");
7198 get_ime_context_fn
= (ImmGetContext_Proc
)
7199 GetProcAddress (imm32_lib
, "ImmGetContext");
7200 release_ime_context_fn
= (ImmReleaseContext_Proc
)
7201 GetProcAddress (imm32_lib
, "ImmReleaseContext");
7202 set_ime_composition_window_fn
= (ImmSetCompositionWindow_Proc
)
7203 GetProcAddress (imm32_lib
, "ImmSetCompositionWindow");
7205 DEFVAR_INT ("w32-ansi-code-page",
7206 &w32_ansi_code_page
,
7207 doc
: /* The ANSI code page used by the system. */);
7208 w32_ansi_code_page
= GetACP ();
7210 /* MessageBox does not work without this when linked to comctl32.dll 6.0. */
7211 InitCommonControls ();
7213 syms_of_w32uniscribe ();
7222 button
= MessageBox (NULL
,
7223 "A fatal error has occurred!\n\n"
7224 "Would you like to attach a debugger?\n\n"
7225 "Select YES to debug, NO to abort Emacs"
7227 "\n\n(type \"gdb -p <emacs-PID>\" and\n"
7228 "\"continue\" inside GDB before clicking YES.)"
7230 , "Emacs Abort Dialog",
7231 MB_ICONEXCLAMATION
| MB_TASKMODAL
7232 | MB_SETFOREGROUND
| MB_YESNO
);
7237 exit (2); /* tell the compiler we will never return */
7245 /* For convenience when debugging. */
7247 w32_last_error (void)
7249 return GetLastError ();
7252 /* arch-tag: 707589ab-b9be-4638-8cdd-74629cc9b446
7253 (do not change this comment) */