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
);
442 static void x_edge_detection (struct frame
*, struct image
*, Lisp_Object
,
448 /* Store the screen positions of frame F into XPTR and YPTR.
449 These are the positions of the containing window manager window,
450 not Emacs's own window. */
453 x_real_positions (FRAME_PTR f
, int *xptr
, int *yptr
)
458 /* Get the bounds of the WM window. */
459 GetWindowRect (FRAME_W32_WINDOW (f
), &rect
);
464 /* Convert (0, 0) in the client area to screen co-ordinates. */
465 ClientToScreen (FRAME_W32_WINDOW (f
), &pt
);
467 /* Remember x_pixels_diff and y_pixels_diff. */
468 f
->x_pixels_diff
= pt
.x
- rect
.left
;
469 f
->y_pixels_diff
= pt
.y
- rect
.top
;
477 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
,
478 Sw32_define_rgb_color
, 4, 4, 0,
479 doc
: /* Convert RGB numbers to a Windows color reference and associate with NAME.
480 This adds or updates a named color to `w32-color-map', making it
481 available for use. The original entry's RGB ref is returned, or nil
482 if the entry is new. */)
483 (Lisp_Object red
, Lisp_Object green
, Lisp_Object blue
, Lisp_Object name
)
486 Lisp_Object oldrgb
= Qnil
;
490 CHECK_NUMBER (green
);
494 XSETINT (rgb
, RGB (XUINT (red
), XUINT (green
), XUINT (blue
)));
498 /* replace existing entry in w32-color-map or add new entry. */
499 entry
= Fassoc (name
, Vw32_color_map
);
502 entry
= Fcons (name
, rgb
);
503 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
507 oldrgb
= Fcdr (entry
);
508 Fsetcdr (entry
, rgb
);
516 /* The default colors for the w32 color map */
517 typedef struct colormap_t
523 colormap_t w32_color_map
[] =
525 {"snow" , PALETTERGB (255,250,250)},
526 {"ghost white" , PALETTERGB (248,248,255)},
527 {"GhostWhite" , PALETTERGB (248,248,255)},
528 {"white smoke" , PALETTERGB (245,245,245)},
529 {"WhiteSmoke" , PALETTERGB (245,245,245)},
530 {"gainsboro" , PALETTERGB (220,220,220)},
531 {"floral white" , PALETTERGB (255,250,240)},
532 {"FloralWhite" , PALETTERGB (255,250,240)},
533 {"old lace" , PALETTERGB (253,245,230)},
534 {"OldLace" , PALETTERGB (253,245,230)},
535 {"linen" , PALETTERGB (250,240,230)},
536 {"antique white" , PALETTERGB (250,235,215)},
537 {"AntiqueWhite" , PALETTERGB (250,235,215)},
538 {"papaya whip" , PALETTERGB (255,239,213)},
539 {"PapayaWhip" , PALETTERGB (255,239,213)},
540 {"blanched almond" , PALETTERGB (255,235,205)},
541 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
542 {"bisque" , PALETTERGB (255,228,196)},
543 {"peach puff" , PALETTERGB (255,218,185)},
544 {"PeachPuff" , PALETTERGB (255,218,185)},
545 {"navajo white" , PALETTERGB (255,222,173)},
546 {"NavajoWhite" , PALETTERGB (255,222,173)},
547 {"moccasin" , PALETTERGB (255,228,181)},
548 {"cornsilk" , PALETTERGB (255,248,220)},
549 {"ivory" , PALETTERGB (255,255,240)},
550 {"lemon chiffon" , PALETTERGB (255,250,205)},
551 {"LemonChiffon" , PALETTERGB (255,250,205)},
552 {"seashell" , PALETTERGB (255,245,238)},
553 {"honeydew" , PALETTERGB (240,255,240)},
554 {"mint cream" , PALETTERGB (245,255,250)},
555 {"MintCream" , PALETTERGB (245,255,250)},
556 {"azure" , PALETTERGB (240,255,255)},
557 {"alice blue" , PALETTERGB (240,248,255)},
558 {"AliceBlue" , PALETTERGB (240,248,255)},
559 {"lavender" , PALETTERGB (230,230,250)},
560 {"lavender blush" , PALETTERGB (255,240,245)},
561 {"LavenderBlush" , PALETTERGB (255,240,245)},
562 {"misty rose" , PALETTERGB (255,228,225)},
563 {"MistyRose" , PALETTERGB (255,228,225)},
564 {"white" , PALETTERGB (255,255,255)},
565 {"black" , PALETTERGB ( 0, 0, 0)},
566 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
567 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
568 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
569 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
570 {"dim gray" , PALETTERGB (105,105,105)},
571 {"DimGray" , PALETTERGB (105,105,105)},
572 {"dim grey" , PALETTERGB (105,105,105)},
573 {"DimGrey" , PALETTERGB (105,105,105)},
574 {"slate gray" , PALETTERGB (112,128,144)},
575 {"SlateGray" , PALETTERGB (112,128,144)},
576 {"slate grey" , PALETTERGB (112,128,144)},
577 {"SlateGrey" , PALETTERGB (112,128,144)},
578 {"light slate gray" , PALETTERGB (119,136,153)},
579 {"LightSlateGray" , PALETTERGB (119,136,153)},
580 {"light slate grey" , PALETTERGB (119,136,153)},
581 {"LightSlateGrey" , PALETTERGB (119,136,153)},
582 {"gray" , PALETTERGB (190,190,190)},
583 {"grey" , PALETTERGB (190,190,190)},
584 {"light grey" , PALETTERGB (211,211,211)},
585 {"LightGrey" , PALETTERGB (211,211,211)},
586 {"light gray" , PALETTERGB (211,211,211)},
587 {"LightGray" , PALETTERGB (211,211,211)},
588 {"midnight blue" , PALETTERGB ( 25, 25,112)},
589 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
590 {"navy" , PALETTERGB ( 0, 0,128)},
591 {"navy blue" , PALETTERGB ( 0, 0,128)},
592 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
593 {"cornflower blue" , PALETTERGB (100,149,237)},
594 {"CornflowerBlue" , PALETTERGB (100,149,237)},
595 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
596 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
597 {"slate blue" , PALETTERGB (106, 90,205)},
598 {"SlateBlue" , PALETTERGB (106, 90,205)},
599 {"medium slate blue" , PALETTERGB (123,104,238)},
600 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
601 {"light slate blue" , PALETTERGB (132,112,255)},
602 {"LightSlateBlue" , PALETTERGB (132,112,255)},
603 {"medium blue" , PALETTERGB ( 0, 0,205)},
604 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
605 {"royal blue" , PALETTERGB ( 65,105,225)},
606 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
607 {"blue" , PALETTERGB ( 0, 0,255)},
608 {"dodger blue" , PALETTERGB ( 30,144,255)},
609 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
610 {"deep sky blue" , PALETTERGB ( 0,191,255)},
611 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
612 {"sky blue" , PALETTERGB (135,206,235)},
613 {"SkyBlue" , PALETTERGB (135,206,235)},
614 {"light sky blue" , PALETTERGB (135,206,250)},
615 {"LightSkyBlue" , PALETTERGB (135,206,250)},
616 {"steel blue" , PALETTERGB ( 70,130,180)},
617 {"SteelBlue" , PALETTERGB ( 70,130,180)},
618 {"light steel blue" , PALETTERGB (176,196,222)},
619 {"LightSteelBlue" , PALETTERGB (176,196,222)},
620 {"light blue" , PALETTERGB (173,216,230)},
621 {"LightBlue" , PALETTERGB (173,216,230)},
622 {"powder blue" , PALETTERGB (176,224,230)},
623 {"PowderBlue" , PALETTERGB (176,224,230)},
624 {"pale turquoise" , PALETTERGB (175,238,238)},
625 {"PaleTurquoise" , PALETTERGB (175,238,238)},
626 {"dark turquoise" , PALETTERGB ( 0,206,209)},
627 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
628 {"medium turquoise" , PALETTERGB ( 72,209,204)},
629 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
630 {"turquoise" , PALETTERGB ( 64,224,208)},
631 {"cyan" , PALETTERGB ( 0,255,255)},
632 {"light cyan" , PALETTERGB (224,255,255)},
633 {"LightCyan" , PALETTERGB (224,255,255)},
634 {"cadet blue" , PALETTERGB ( 95,158,160)},
635 {"CadetBlue" , PALETTERGB ( 95,158,160)},
636 {"medium aquamarine" , PALETTERGB (102,205,170)},
637 {"MediumAquamarine" , PALETTERGB (102,205,170)},
638 {"aquamarine" , PALETTERGB (127,255,212)},
639 {"dark green" , PALETTERGB ( 0,100, 0)},
640 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
641 {"dark olive green" , PALETTERGB ( 85,107, 47)},
642 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
643 {"dark sea green" , PALETTERGB (143,188,143)},
644 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
645 {"sea green" , PALETTERGB ( 46,139, 87)},
646 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
647 {"medium sea green" , PALETTERGB ( 60,179,113)},
648 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
649 {"light sea green" , PALETTERGB ( 32,178,170)},
650 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
651 {"pale green" , PALETTERGB (152,251,152)},
652 {"PaleGreen" , PALETTERGB (152,251,152)},
653 {"spring green" , PALETTERGB ( 0,255,127)},
654 {"SpringGreen" , PALETTERGB ( 0,255,127)},
655 {"lawn green" , PALETTERGB (124,252, 0)},
656 {"LawnGreen" , PALETTERGB (124,252, 0)},
657 {"green" , PALETTERGB ( 0,255, 0)},
658 {"chartreuse" , PALETTERGB (127,255, 0)},
659 {"medium spring green" , PALETTERGB ( 0,250,154)},
660 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
661 {"green yellow" , PALETTERGB (173,255, 47)},
662 {"GreenYellow" , PALETTERGB (173,255, 47)},
663 {"lime green" , PALETTERGB ( 50,205, 50)},
664 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
665 {"yellow green" , PALETTERGB (154,205, 50)},
666 {"YellowGreen" , PALETTERGB (154,205, 50)},
667 {"forest green" , PALETTERGB ( 34,139, 34)},
668 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
669 {"olive drab" , PALETTERGB (107,142, 35)},
670 {"OliveDrab" , PALETTERGB (107,142, 35)},
671 {"dark khaki" , PALETTERGB (189,183,107)},
672 {"DarkKhaki" , PALETTERGB (189,183,107)},
673 {"khaki" , PALETTERGB (240,230,140)},
674 {"pale goldenrod" , PALETTERGB (238,232,170)},
675 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
676 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
677 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
678 {"light yellow" , PALETTERGB (255,255,224)},
679 {"LightYellow" , PALETTERGB (255,255,224)},
680 {"yellow" , PALETTERGB (255,255, 0)},
681 {"gold" , PALETTERGB (255,215, 0)},
682 {"light goldenrod" , PALETTERGB (238,221,130)},
683 {"LightGoldenrod" , PALETTERGB (238,221,130)},
684 {"goldenrod" , PALETTERGB (218,165, 32)},
685 {"dark goldenrod" , PALETTERGB (184,134, 11)},
686 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
687 {"rosy brown" , PALETTERGB (188,143,143)},
688 {"RosyBrown" , PALETTERGB (188,143,143)},
689 {"indian red" , PALETTERGB (205, 92, 92)},
690 {"IndianRed" , PALETTERGB (205, 92, 92)},
691 {"saddle brown" , PALETTERGB (139, 69, 19)},
692 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
693 {"sienna" , PALETTERGB (160, 82, 45)},
694 {"peru" , PALETTERGB (205,133, 63)},
695 {"burlywood" , PALETTERGB (222,184,135)},
696 {"beige" , PALETTERGB (245,245,220)},
697 {"wheat" , PALETTERGB (245,222,179)},
698 {"sandy brown" , PALETTERGB (244,164, 96)},
699 {"SandyBrown" , PALETTERGB (244,164, 96)},
700 {"tan" , PALETTERGB (210,180,140)},
701 {"chocolate" , PALETTERGB (210,105, 30)},
702 {"firebrick" , PALETTERGB (178,34, 34)},
703 {"brown" , PALETTERGB (165,42, 42)},
704 {"dark salmon" , PALETTERGB (233,150,122)},
705 {"DarkSalmon" , PALETTERGB (233,150,122)},
706 {"salmon" , PALETTERGB (250,128,114)},
707 {"light salmon" , PALETTERGB (255,160,122)},
708 {"LightSalmon" , PALETTERGB (255,160,122)},
709 {"orange" , PALETTERGB (255,165, 0)},
710 {"dark orange" , PALETTERGB (255,140, 0)},
711 {"DarkOrange" , PALETTERGB (255,140, 0)},
712 {"coral" , PALETTERGB (255,127, 80)},
713 {"light coral" , PALETTERGB (240,128,128)},
714 {"LightCoral" , PALETTERGB (240,128,128)},
715 {"tomato" , PALETTERGB (255, 99, 71)},
716 {"orange red" , PALETTERGB (255, 69, 0)},
717 {"OrangeRed" , PALETTERGB (255, 69, 0)},
718 {"red" , PALETTERGB (255, 0, 0)},
719 {"hot pink" , PALETTERGB (255,105,180)},
720 {"HotPink" , PALETTERGB (255,105,180)},
721 {"deep pink" , PALETTERGB (255, 20,147)},
722 {"DeepPink" , PALETTERGB (255, 20,147)},
723 {"pink" , PALETTERGB (255,192,203)},
724 {"light pink" , PALETTERGB (255,182,193)},
725 {"LightPink" , PALETTERGB (255,182,193)},
726 {"pale violet red" , PALETTERGB (219,112,147)},
727 {"PaleVioletRed" , PALETTERGB (219,112,147)},
728 {"maroon" , PALETTERGB (176, 48, 96)},
729 {"medium violet red" , PALETTERGB (199, 21,133)},
730 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
731 {"violet red" , PALETTERGB (208, 32,144)},
732 {"VioletRed" , PALETTERGB (208, 32,144)},
733 {"magenta" , PALETTERGB (255, 0,255)},
734 {"violet" , PALETTERGB (238,130,238)},
735 {"plum" , PALETTERGB (221,160,221)},
736 {"orchid" , PALETTERGB (218,112,214)},
737 {"medium orchid" , PALETTERGB (186, 85,211)},
738 {"MediumOrchid" , PALETTERGB (186, 85,211)},
739 {"dark orchid" , PALETTERGB (153, 50,204)},
740 {"DarkOrchid" , PALETTERGB (153, 50,204)},
741 {"dark violet" , PALETTERGB (148, 0,211)},
742 {"DarkViolet" , PALETTERGB (148, 0,211)},
743 {"blue violet" , PALETTERGB (138, 43,226)},
744 {"BlueViolet" , PALETTERGB (138, 43,226)},
745 {"purple" , PALETTERGB (160, 32,240)},
746 {"medium purple" , PALETTERGB (147,112,219)},
747 {"MediumPurple" , PALETTERGB (147,112,219)},
748 {"thistle" , PALETTERGB (216,191,216)},
749 {"gray0" , PALETTERGB ( 0, 0, 0)},
750 {"grey0" , PALETTERGB ( 0, 0, 0)},
751 {"dark grey" , PALETTERGB (169,169,169)},
752 {"DarkGrey" , PALETTERGB (169,169,169)},
753 {"dark gray" , PALETTERGB (169,169,169)},
754 {"DarkGray" , PALETTERGB (169,169,169)},
755 {"dark blue" , PALETTERGB ( 0, 0,139)},
756 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
757 {"dark cyan" , PALETTERGB ( 0,139,139)},
758 {"DarkCyan" , PALETTERGB ( 0,139,139)},
759 {"dark magenta" , PALETTERGB (139, 0,139)},
760 {"DarkMagenta" , PALETTERGB (139, 0,139)},
761 {"dark red" , PALETTERGB (139, 0, 0)},
762 {"DarkRed" , PALETTERGB (139, 0, 0)},
763 {"light green" , PALETTERGB (144,238,144)},
764 {"LightGreen" , PALETTERGB (144,238,144)},
767 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
768 0, 0, 0, doc
: /* Return the default color map. */)
772 colormap_t
*pc
= w32_color_map
;
779 for (i
= 0; i
< sizeof (w32_color_map
) / sizeof (w32_color_map
[0]);
781 cmap
= Fcons (Fcons (build_string (pc
->name
),
782 make_number (pc
->colorref
)),
791 w32_to_x_color (Lisp_Object rgb
)
799 color
= Frassq (rgb
, Vw32_color_map
);
804 return (Fcar (color
));
810 w32_color_map_lookup (char *colorname
)
812 Lisp_Object tail
, ret
= Qnil
;
816 for (tail
= Vw32_color_map
; CONSP (tail
); tail
= XCDR (tail
))
818 register Lisp_Object elt
, tem
;
821 if (!CONSP (elt
)) continue;
825 if (lstrcmpi (SDATA (tem
), colorname
) == 0)
842 add_system_logical_colors_to_map (Lisp_Object
*system_colors
)
846 /* Other registry operations are done with input blocked. */
849 /* Look for "Control Panel/Colors" under User and Machine registry
851 if (RegOpenKeyEx (HKEY_CURRENT_USER
, "Control Panel\\Colors", 0,
852 KEY_READ
, &colors_key
) == ERROR_SUCCESS
853 || RegOpenKeyEx (HKEY_LOCAL_MACHINE
, "Control Panel\\Colors", 0,
854 KEY_READ
, &colors_key
) == ERROR_SUCCESS
)
857 char color_buffer
[64];
858 char full_name_buffer
[MAX_PATH
+ SYSTEM_COLOR_PREFIX_LEN
];
860 DWORD name_size
, color_size
;
861 char *name_buffer
= full_name_buffer
+ SYSTEM_COLOR_PREFIX_LEN
;
863 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
864 color_size
= sizeof (color_buffer
);
866 strcpy (full_name_buffer
, SYSTEM_COLOR_PREFIX
);
868 while (RegEnumValueA (colors_key
, index
, name_buffer
, &name_size
,
869 NULL
, NULL
, color_buffer
, &color_size
)
873 if (sscanf (color_buffer
, " %u %u %u", &r
, &g
, &b
) == 3)
874 *system_colors
= Fcons (Fcons (build_string (full_name_buffer
),
875 make_number (RGB (r
, g
, b
))),
878 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
879 color_size
= sizeof (color_buffer
);
882 RegCloseKey (colors_key
);
890 x_to_w32_color (char * colorname
)
892 register Lisp_Object ret
= Qnil
;
896 if (colorname
[0] == '#')
898 /* Could be an old-style RGB Device specification. */
901 color
= colorname
+ 1;
903 size
= strlen (color
);
904 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
912 for (i
= 0; i
< 3; i
++)
918 /* The check for 'x' in the following conditional takes into
919 account the fact that strtol allows a "0x" in front of
920 our numbers, and we don't. */
921 if (!isxdigit (color
[0]) || color
[1] == 'x')
925 value
= strtoul (color
, &end
, 16);
927 if (errno
== ERANGE
|| end
- color
!= size
)
932 value
= value
* 0x10;
943 colorval
|= (value
<< pos
);
948 XSETINT (ret
, colorval
);
955 else if (strnicmp (colorname
, "rgb:", 4) == 0)
963 color
= colorname
+ 4;
964 for (i
= 0; i
< 3; i
++)
969 /* The check for 'x' in the following conditional takes into
970 account the fact that strtol allows a "0x" in front of
971 our numbers, and we don't. */
972 if (!isxdigit (color
[0]) || color
[1] == 'x')
974 value
= strtoul (color
, &end
, 16);
980 value
= value
* 0x10 + value
;
993 if (value
== ULONG_MAX
)
995 colorval
|= (value
<< pos
);
1002 XSETINT (ret
, colorval
);
1010 else if (strnicmp (colorname
, "rgbi:", 5) == 0)
1012 /* This is an RGB Intensity specification. */
1019 color
= colorname
+ 5;
1020 for (i
= 0; i
< 3; i
++)
1026 value
= strtod (color
, &end
);
1027 if (errno
== ERANGE
)
1029 if (value
< 0.0 || value
> 1.0)
1031 val
= (UINT
)(0x100 * value
);
1032 /* We used 0x100 instead of 0xFF to give a continuous
1033 range between 0.0 and 1.0 inclusive. The next statement
1034 fixes the 1.0 case. */
1037 colorval
|= (val
<< pos
);
1044 XSETINT (ret
, colorval
);
1052 /* I am not going to attempt to handle any of the CIE color schemes
1053 or TekHVC, since I don't know the algorithms for conversion to
1056 /* If we fail to lookup the color name in w32_color_map, then check the
1057 colorname to see if it can be crudely approximated: If the X color
1058 ends in a number (e.g., "darkseagreen2"), strip the number and
1059 return the result of looking up the base color name. */
1060 ret
= w32_color_map_lookup (colorname
);
1063 int len
= strlen (colorname
);
1065 if (isdigit (colorname
[len
- 1]))
1067 char *ptr
, *approx
= alloca (len
+ 1);
1069 strcpy (approx
, colorname
);
1070 ptr
= &approx
[len
- 1];
1071 while (ptr
> approx
&& isdigit (*ptr
))
1074 ret
= w32_color_map_lookup (approx
);
1083 w32_regenerate_palette (FRAME_PTR f
)
1085 struct w32_palette_entry
* list
;
1086 LOGPALETTE
* log_palette
;
1087 HPALETTE new_palette
;
1090 /* don't bother trying to create palette if not supported */
1091 if (! FRAME_W32_DISPLAY_INFO (f
)->has_palette
)
1094 log_palette
= (LOGPALETTE
*)
1095 alloca (sizeof (LOGPALETTE
) +
1096 FRAME_W32_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
1097 log_palette
->palVersion
= 0x300;
1098 log_palette
->palNumEntries
= FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1100 list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1102 i
< FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1103 i
++, list
= list
->next
)
1104 log_palette
->palPalEntry
[i
] = list
->entry
;
1106 new_palette
= CreatePalette (log_palette
);
1110 if (FRAME_W32_DISPLAY_INFO (f
)->palette
)
1111 DeleteObject (FRAME_W32_DISPLAY_INFO (f
)->palette
);
1112 FRAME_W32_DISPLAY_INFO (f
)->palette
= new_palette
;
1114 /* Realize display palette and garbage all frames. */
1115 release_frame_dc (f
, get_frame_dc (f
));
1120 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
1121 #define SET_W32_COLOR(pe, color) \
1124 pe.peRed = GetRValue (color); \
1125 pe.peGreen = GetGValue (color); \
1126 pe.peBlue = GetBValue (color); \
1131 /* Keep these around in case we ever want to track color usage. */
1133 w32_map_color (FRAME_PTR f
, COLORREF color
)
1135 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1137 if (NILP (Vw32_enable_palette
))
1140 /* check if color is already mapped */
1143 if (W32_COLOR (list
->entry
) == color
)
1151 /* not already mapped, so add to list and recreate Windows palette */
1152 list
= (struct w32_palette_entry
*)
1153 xmalloc (sizeof (struct w32_palette_entry
));
1154 SET_W32_COLOR (list
->entry
, color
);
1156 list
->next
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1157 FRAME_W32_DISPLAY_INFO (f
)->color_list
= list
;
1158 FRAME_W32_DISPLAY_INFO (f
)->num_colors
++;
1160 /* set flag that palette must be regenerated */
1161 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1165 w32_unmap_color (FRAME_PTR f
, COLORREF color
)
1167 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1168 struct w32_palette_entry
**prev
= &FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1170 if (NILP (Vw32_enable_palette
))
1173 /* check if color is already mapped */
1176 if (W32_COLOR (list
->entry
) == color
)
1178 if (--list
->refcount
== 0)
1182 FRAME_W32_DISPLAY_INFO (f
)->num_colors
--;
1192 /* set flag that palette must be regenerated */
1193 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1198 /* Gamma-correct COLOR on frame F. */
1201 gamma_correct (struct frame
*f
, COLORREF
*color
)
1205 *color
= PALETTERGB (
1206 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1207 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1208 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1213 /* Decide if color named COLOR is valid for the display associated with
1214 the selected frame; if so, return the rgb values in COLOR_DEF.
1215 If ALLOC is nonzero, allocate a new colormap cell. */
1218 w32_defined_color (FRAME_PTR f
, char *color
, XColor
*color_def
, int alloc
)
1220 register Lisp_Object tem
;
1221 COLORREF w32_color_ref
;
1223 tem
= x_to_w32_color (color
);
1229 /* Apply gamma correction. */
1230 w32_color_ref
= XUINT (tem
);
1231 gamma_correct (f
, &w32_color_ref
);
1232 XSETINT (tem
, w32_color_ref
);
1235 /* Map this color to the palette if it is enabled. */
1236 if (!NILP (Vw32_enable_palette
))
1238 struct w32_palette_entry
* entry
=
1239 one_w32_display_info
.color_list
;
1240 struct w32_palette_entry
** prev
=
1241 &one_w32_display_info
.color_list
;
1243 /* check if color is already mapped */
1246 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1248 prev
= &entry
->next
;
1249 entry
= entry
->next
;
1252 if (entry
== NULL
&& alloc
)
1254 /* not already mapped, so add to list */
1255 entry
= (struct w32_palette_entry
*)
1256 xmalloc (sizeof (struct w32_palette_entry
));
1257 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1260 one_w32_display_info
.num_colors
++;
1262 /* set flag that palette must be regenerated */
1263 one_w32_display_info
.regen_palette
= TRUE
;
1266 /* Ensure COLORREF value is snapped to nearest color in (default)
1267 palette by simulating the PALETTERGB macro. This works whether
1268 or not the display device has a palette. */
1269 w32_color_ref
= XUINT (tem
) | 0x2000000;
1271 color_def
->pixel
= w32_color_ref
;
1272 color_def
->red
= GetRValue (w32_color_ref
) * 256;
1273 color_def
->green
= GetGValue (w32_color_ref
) * 256;
1274 color_def
->blue
= GetBValue (w32_color_ref
) * 256;
1284 /* Given a string ARG naming a color, compute a pixel value from it
1285 suitable for screen F.
1286 If F is not a color screen, return DEF (default) regardless of what
1290 x_decode_color (FRAME_PTR f
, Lisp_Object arg
, int def
)
1296 if (strcmp (SDATA (arg
), "black") == 0)
1297 return BLACK_PIX_DEFAULT (f
);
1298 else if (strcmp (SDATA (arg
), "white") == 0)
1299 return WHITE_PIX_DEFAULT (f
);
1301 if ((FRAME_W32_DISPLAY_INFO (f
)->n_planes
* FRAME_W32_DISPLAY_INFO (f
)->n_cbits
) == 1)
1304 /* w32_defined_color is responsible for coping with failures
1305 by looking for a near-miss. */
1306 if (w32_defined_color (f
, SDATA (arg
), &cdef
, 1))
1309 /* defined_color failed; return an ultimate default. */
1315 /* Functions called only from `x_set_frame_param'
1316 to set individual parameters.
1318 If FRAME_W32_WINDOW (f) is 0,
1319 the frame is being created and its window does not exist yet.
1320 In that case, just record the parameter's new value
1321 in the standard place; do not attempt to change the window. */
1324 x_set_foreground_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1326 struct w32_output
*x
= f
->output_data
.w32
;
1327 PIX_TYPE fg
, old_fg
;
1329 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1330 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
1331 FRAME_FOREGROUND_PIXEL (f
) = fg
;
1333 if (FRAME_W32_WINDOW (f
) != 0)
1335 if (x
->cursor_pixel
== old_fg
)
1336 x
->cursor_pixel
= fg
;
1338 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
1339 if (FRAME_VISIBLE_P (f
))
1345 x_set_background_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1347 FRAME_BACKGROUND_PIXEL (f
)
1348 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
1350 if (FRAME_W32_WINDOW (f
) != 0)
1352 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
1353 FRAME_BACKGROUND_PIXEL (f
));
1355 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
1357 if (FRAME_VISIBLE_P (f
))
1363 x_set_mouse_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1365 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
1369 if (!EQ (Qnil
, arg
))
1370 f
->output_data
.w32
->mouse_pixel
1371 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1372 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
1374 /* Don't let pointers be invisible. */
1375 if (mask_color
== f
->output_data
.w32
->mouse_pixel
1376 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
1377 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
1379 #if 0 /* TODO : Mouse cursor customization. */
1382 /* It's not okay to crash if the user selects a screwy cursor. */
1383 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
1385 if (!EQ (Qnil
, Vx_pointer_shape
))
1387 CHECK_NUMBER (Vx_pointer_shape
);
1388 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
1391 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1392 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
1394 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
1396 CHECK_NUMBER (Vx_nontext_pointer_shape
);
1397 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1398 XINT (Vx_nontext_pointer_shape
));
1401 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
1402 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1404 if (!EQ (Qnil
, Vx_hourglass_pointer_shape
))
1406 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
1407 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1408 XINT (Vx_hourglass_pointer_shape
));
1411 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
1412 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
1414 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1415 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
1417 CHECK_NUMBER (Vx_mode_pointer_shape
);
1418 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1419 XINT (Vx_mode_pointer_shape
));
1422 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1423 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
1425 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
1427 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
1429 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1430 XINT (Vx_sensitive_text_pointer_shape
));
1433 hand_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
1435 if (!NILP (Vx_window_horizontal_drag_shape
))
1437 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
1438 horizontal_drag_cursor
1439 = XCreateFontCursor (FRAME_X_DISPLAY (f
),
1440 XINT (Vx_window_horizontal_drag_shape
));
1443 horizontal_drag_cursor
1444 = XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_sb_h_double_arrow
);
1446 /* Check and report errors with the above calls. */
1447 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
1448 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
1451 XColor fore_color
, back_color
;
1453 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
1454 back_color
.pixel
= mask_color
;
1455 XQueryColor (FRAME_W32_DISPLAY (f
),
1456 DefaultColormap (FRAME_W32_DISPLAY (f
),
1457 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1459 XQueryColor (FRAME_W32_DISPLAY (f
),
1460 DefaultColormap (FRAME_W32_DISPLAY (f
),
1461 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1463 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
1464 &fore_color
, &back_color
);
1465 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
1466 &fore_color
, &back_color
);
1467 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
1468 &fore_color
, &back_color
);
1469 XRecolorCursor (FRAME_W32_DISPLAY (f
), hand_cursor
,
1470 &fore_color
, &back_color
);
1471 XRecolorCursor (FRAME_W32_DISPLAY (f
), hourglass_cursor
,
1472 &fore_color
, &back_color
);
1475 if (FRAME_W32_WINDOW (f
) != 0)
1476 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
1478 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
1479 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
1480 f
->output_data
.w32
->text_cursor
= cursor
;
1482 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
1483 && f
->output_data
.w32
->nontext_cursor
!= 0)
1484 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
1485 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
1487 if (hourglass_cursor
!= f
->output_data
.w32
->hourglass_cursor
1488 && f
->output_data
.w32
->hourglass_cursor
!= 0)
1489 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hourglass_cursor
);
1490 f
->output_data
.w32
->hourglass_cursor
= hourglass_cursor
;
1492 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
1493 && f
->output_data
.w32
->modeline_cursor
!= 0)
1494 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
1495 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
1497 if (hand_cursor
!= f
->output_data
.w32
->hand_cursor
1498 && f
->output_data
.w32
->hand_cursor
!= 0)
1499 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hand_cursor
);
1500 f
->output_data
.w32
->hand_cursor
= hand_cursor
;
1502 XFlush (FRAME_W32_DISPLAY (f
));
1505 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1510 x_set_cursor_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1512 unsigned long fore_pixel
, pixel
;
1514 if (!NILP (Vx_cursor_fore_pixel
))
1515 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1516 WHITE_PIX_DEFAULT (f
));
1518 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1520 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1522 /* Make sure that the cursor color differs from the background color. */
1523 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
1525 pixel
= f
->output_data
.w32
->mouse_pixel
;
1526 if (pixel
== fore_pixel
)
1527 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1530 f
->output_data
.w32
->cursor_foreground_pixel
= fore_pixel
;
1531 f
->output_data
.w32
->cursor_pixel
= pixel
;
1533 if (FRAME_W32_WINDOW (f
) != 0)
1536 /* Update frame's cursor_gc. */
1537 f
->output_data
.w32
->cursor_gc
->foreground
= fore_pixel
;
1538 f
->output_data
.w32
->cursor_gc
->background
= pixel
;
1542 if (FRAME_VISIBLE_P (f
))
1544 x_update_cursor (f
, 0);
1545 x_update_cursor (f
, 1);
1549 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1552 /* Set the border-color of frame F to pixel value PIX.
1553 Note that this does not fully take effect if done before
1557 x_set_border_pixel (struct frame
*f
, int pix
)
1560 f
->output_data
.w32
->border_pixel
= pix
;
1562 if (FRAME_W32_WINDOW (f
) != 0 && f
->border_width
> 0)
1564 if (FRAME_VISIBLE_P (f
))
1569 /* Set the border-color of frame F to value described by ARG.
1570 ARG can be a string naming a color.
1571 The border-color is used for the border that is drawn by the server.
1572 Note that this does not fully take effect if done before
1573 F has a window; it must be redone when the window is created. */
1576 x_set_border_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1581 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1582 x_set_border_pixel (f
, pix
);
1583 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1588 x_set_cursor_type (FRAME_PTR f
, Lisp_Object arg
, Lisp_Object oldval
)
1590 set_frame_cursor_types (f
, arg
);
1592 /* Make sure the cursor gets redrawn. */
1593 cursor_type_changed
= 1;
1597 x_set_icon_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1601 if (NILP (arg
) && NILP (oldval
))
1604 if (STRINGP (arg
) && STRINGP (oldval
)
1605 && EQ (Fstring_equal (oldval
, arg
), Qt
))
1608 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
1613 result
= x_bitmap_icon (f
, arg
);
1617 error ("No icon window available");
1624 x_set_icon_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1628 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1631 else if (!NILP (arg
) || NILP (oldval
))
1637 if (f
->output_data
.w32
->icon_bitmap
!= 0)
1642 result
= x_text_icon (f
,
1643 (char *) SDATA ((!NILP (f
->icon_name
)
1652 error ("No icon window available");
1655 /* If the window was unmapped (and its icon was mapped),
1656 the new icon is not mapped, so map the window in its stead. */
1657 if (FRAME_VISIBLE_P (f
))
1659 #ifdef USE_X_TOOLKIT
1660 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
1662 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
1665 XFlush (FRAME_W32_DISPLAY (f
));
1672 x_set_menu_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1675 int olines
= FRAME_MENU_BAR_LINES (f
);
1677 /* Right now, menu bars don't work properly in minibuf-only frames;
1678 most of the commands try to apply themselves to the minibuffer
1679 frame itself, and get an error because you can't switch buffers
1680 in or split the minibuffer window. */
1681 if (FRAME_MINIBUF_ONLY_P (f
))
1684 if (INTEGERP (value
))
1685 nlines
= XINT (value
);
1689 FRAME_MENU_BAR_LINES (f
) = 0;
1691 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1694 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1695 free_frame_menubar (f
);
1696 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1698 /* Adjust the frame size so that the client (text) dimensions
1699 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
1701 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
1702 do_pending_window_change (0);
1708 /* Set the number of lines used for the tool bar of frame F to VALUE.
1709 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1710 is the old number of tool bar lines. This function changes the
1711 height of all windows on frame F to match the new tool bar height.
1712 The frame's height doesn't change. */
1715 x_set_tool_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1717 int delta
, nlines
, root_height
;
1718 Lisp_Object root_window
;
1720 /* Treat tool bars like menu bars. */
1721 if (FRAME_MINIBUF_ONLY_P (f
))
1724 /* Use VALUE only if an integer >= 0. */
1725 if (INTEGERP (value
) && XINT (value
) >= 0)
1726 nlines
= XFASTINT (value
);
1730 /* Make sure we redisplay all windows in this frame. */
1731 ++windows_or_buffers_changed
;
1733 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
1735 /* Don't resize the tool-bar to more than we have room for. */
1736 root_window
= FRAME_ROOT_WINDOW (f
);
1737 root_height
= WINDOW_TOTAL_LINES (XWINDOW (root_window
));
1738 if (root_height
- delta
< 1)
1740 delta
= root_height
- 1;
1741 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
1744 FRAME_TOOL_BAR_LINES (f
) = nlines
;
1745 change_window_heights (root_window
, delta
);
1748 /* We also have to make sure that the internal border at the top of
1749 the frame, below the menu bar or tool bar, is redrawn when the
1750 tool bar disappears. This is so because the internal border is
1751 below the tool bar if one is displayed, but is below the menu bar
1752 if there isn't a tool bar. The tool bar draws into the area
1753 below the menu bar. */
1754 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
1757 clear_current_matrices (f
);
1760 /* If the tool bar gets smaller, the internal border below it
1761 has to be cleared. It was formerly part of the display
1762 of the larger tool bar, and updating windows won't clear it. */
1765 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1766 int width
= FRAME_PIXEL_WIDTH (f
);
1767 int y
= nlines
* FRAME_LINE_HEIGHT (f
);
1771 HDC hdc
= get_frame_dc (f
);
1772 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
1773 release_frame_dc (f
, hdc
);
1777 if (WINDOWP (f
->tool_bar_window
))
1778 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1783 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1786 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1787 name; if NAME is a string, set F's name to NAME and set
1788 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1790 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1791 suggesting a new name, which lisp code should override; if
1792 F->explicit_name is set, ignore the new name; otherwise, set it. */
1795 x_set_name (struct frame
*f
, Lisp_Object name
, int explicit)
1797 /* Make sure that requests from lisp code override requests from
1798 Emacs redisplay code. */
1801 /* If we're switching from explicit to implicit, we had better
1802 update the mode lines and thereby update the title. */
1803 if (f
->explicit_name
&& NILP (name
))
1804 update_mode_lines
= 1;
1806 f
->explicit_name
= ! NILP (name
);
1808 else if (f
->explicit_name
)
1811 /* If NAME is nil, set the name to the w32_id_name. */
1814 /* Check for no change needed in this very common case
1815 before we do any consing. */
1816 if (!strcmp (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
,
1819 name
= build_string (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
);
1822 CHECK_STRING (name
);
1824 /* Don't change the name if it's already NAME. */
1825 if (! NILP (Fstring_equal (name
, f
->name
)))
1830 /* For setting the frame title, the title parameter should override
1831 the name parameter. */
1832 if (! NILP (f
->title
))
1835 if (FRAME_W32_WINDOW (f
))
1837 if (STRING_MULTIBYTE (name
))
1838 name
= ENCODE_SYSTEM (name
);
1841 SetWindowText (FRAME_W32_WINDOW (f
), SDATA (name
));
1846 /* This function should be called when the user's lisp code has
1847 specified a name for the frame; the name will override any set by the
1850 x_explicitly_set_name (FRAME_PTR f
, Lisp_Object arg
, Lisp_Object oldval
)
1852 x_set_name (f
, arg
, 1);
1855 /* This function should be called by Emacs redisplay code to set the
1856 name; names set this way will never override names set by the user's
1859 x_implicitly_set_name (FRAME_PTR f
, Lisp_Object arg
, Lisp_Object oldval
)
1861 x_set_name (f
, arg
, 0);
1864 /* Change the title of frame F to NAME.
1865 If NAME is nil, use the frame name as the title. */
1868 x_set_title (struct frame
*f
, Lisp_Object name
, Lisp_Object old_name
)
1870 /* Don't change the title if it's already NAME. */
1871 if (EQ (name
, f
->title
))
1874 update_mode_lines
= 1;
1881 if (FRAME_W32_WINDOW (f
))
1883 if (STRING_MULTIBYTE (name
))
1884 name
= ENCODE_SYSTEM (name
);
1887 SetWindowText (FRAME_W32_WINDOW (f
), SDATA (name
));
1894 x_set_scroll_bar_default_width (struct frame
*f
)
1896 int wid
= FRAME_COLUMN_WIDTH (f
);
1898 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
1899 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) +
1904 /* Subroutines for creating a frame. */
1907 w32_load_cursor (LPCTSTR name
)
1909 /* Try first to load cursor from application resource. */
1910 Cursor cursor
= LoadImage ((HINSTANCE
) GetModuleHandle (NULL
),
1911 name
, IMAGE_CURSOR
, 0, 0,
1912 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
1915 /* Then try to load a shared predefined cursor. */
1916 cursor
= LoadImage (NULL
, name
, IMAGE_CURSOR
, 0, 0,
1917 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
1922 extern LRESULT CALLBACK
w32_wnd_proc (HWND
, UINT
, WPARAM
, LPARAM
);
1925 w32_init_class (HINSTANCE hinst
)
1929 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
1930 wc
.lpfnWndProc
= (WNDPROC
) w32_wnd_proc
;
1932 wc
.cbWndExtra
= WND_EXTRA_BYTES
;
1933 wc
.hInstance
= hinst
;
1934 wc
.hIcon
= LoadIcon (hinst
, EMACS_CLASS
);
1935 wc
.hCursor
= w32_load_cursor (IDC_ARROW
);
1936 wc
.hbrBackground
= NULL
; /* GetStockObject (WHITE_BRUSH); */
1937 wc
.lpszMenuName
= NULL
;
1938 wc
.lpszClassName
= EMACS_CLASS
;
1940 return (RegisterClass (&wc
));
1944 w32_createscrollbar (struct frame
*f
, struct scroll_bar
* bar
)
1946 return (CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
1947 /* Position and size of scroll bar. */
1948 XINT (bar
->left
) + VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
1950 XINT (bar
->width
) - VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
1952 FRAME_W32_WINDOW (f
),
1959 w32_createwindow (struct frame
*f
)
1963 Lisp_Object top
= Qunbound
;
1964 Lisp_Object left
= Qunbound
;
1965 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
1967 rect
.left
= rect
.top
= 0;
1968 rect
.right
= FRAME_PIXEL_WIDTH (f
);
1969 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
1971 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
1972 FRAME_EXTERNAL_MENU_BAR (f
));
1974 /* Do first time app init */
1978 w32_init_class (hinst
);
1981 if (f
->size_hint_flags
& USPosition
|| f
->size_hint_flags
& PPosition
)
1983 XSETINT (left
, f
->left_pos
);
1984 XSETINT (top
, f
->top_pos
);
1986 else if (EQ (left
, Qunbound
) && EQ (top
, Qunbound
))
1988 /* When called with RES_TYPE_NUMBER, w32_get_arg will return zero
1989 for anything that is not a number and is not Qunbound. */
1990 left
= x_get_arg (dpyinfo
, Qnil
, Qleft
, "left", "Left", RES_TYPE_NUMBER
);
1991 top
= x_get_arg (dpyinfo
, Qnil
, Qtop
, "top", "Top", RES_TYPE_NUMBER
);
1994 FRAME_W32_WINDOW (f
) = hwnd
1995 = CreateWindow (EMACS_CLASS
,
1997 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
1998 EQ (left
, Qunbound
) ? CW_USEDEFAULT
: XINT (left
),
1999 EQ (top
, Qunbound
) ? CW_USEDEFAULT
: XINT (top
),
2000 rect
.right
- rect
.left
,
2001 rect
.bottom
- rect
.top
,
2009 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
2010 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
2011 SetWindowLong (hwnd
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
2012 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->scroll_bar_actual_width
);
2013 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
2015 /* Enable drag-n-drop. */
2016 DragAcceptFiles (hwnd
, TRUE
);
2018 /* Do this to discard the default setting specified by our parent. */
2019 ShowWindow (hwnd
, SW_HIDE
);
2021 /* Update frame positions. */
2022 GetWindowRect (hwnd
, &rect
);
2023 f
->left_pos
= rect
.left
;
2024 f
->top_pos
= rect
.top
;
2029 my_post_msg (W32Msg
* wmsg
, HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2031 wmsg
->msg
.hwnd
= hwnd
;
2032 wmsg
->msg
.message
= msg
;
2033 wmsg
->msg
.wParam
= wParam
;
2034 wmsg
->msg
.lParam
= lParam
;
2035 wmsg
->msg
.time
= GetMessageTime ();
2040 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
2041 between left and right keys as advertised. We test for this
2042 support dynamically, and set a flag when the support is absent. If
2043 absent, we keep track of the left and right control and alt keys
2044 ourselves. This is particularly necessary on keyboards that rely
2045 upon the AltGr key, which is represented as having the left control
2046 and right alt keys pressed. For these keyboards, we need to know
2047 when the left alt key has been pressed in addition to the AltGr key
2048 so that we can properly support M-AltGr-key sequences (such as M-@
2049 on Swedish keyboards). */
2051 #define EMACS_LCONTROL 0
2052 #define EMACS_RCONTROL 1
2053 #define EMACS_LMENU 2
2054 #define EMACS_RMENU 3
2056 static int modifiers
[4];
2057 static int modifiers_recorded
;
2058 static int modifier_key_support_tested
;
2061 test_modifier_support (unsigned int wparam
)
2065 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
2067 if (wparam
== VK_CONTROL
)
2077 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
2078 modifiers_recorded
= 1;
2080 modifiers_recorded
= 0;
2081 modifier_key_support_tested
= 1;
2085 record_keydown (unsigned int wparam
, unsigned int lparam
)
2089 if (!modifier_key_support_tested
)
2090 test_modifier_support (wparam
);
2092 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2095 if (wparam
== VK_CONTROL
)
2096 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2098 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2104 record_keyup (unsigned int wparam
, unsigned int lparam
)
2108 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2111 if (wparam
== VK_CONTROL
)
2112 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2114 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2119 /* Emacs can lose focus while a modifier key has been pressed. When
2120 it regains focus, be conservative and clear all modifiers since
2121 we cannot reconstruct the left and right modifier state. */
2123 reset_modifiers (void)
2127 if (GetFocus () == NULL
)
2128 /* Emacs doesn't have keyboard focus. Do nothing. */
2131 ctrl
= GetAsyncKeyState (VK_CONTROL
);
2132 alt
= GetAsyncKeyState (VK_MENU
);
2134 if (!(ctrl
& 0x08000))
2135 /* Clear any recorded control modifier state. */
2136 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2138 if (!(alt
& 0x08000))
2139 /* Clear any recorded alt modifier state. */
2140 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2142 /* Update the state of all modifier keys, because modifiers used in
2143 hot-key combinations can get stuck on if Emacs loses focus as a
2144 result of a hot-key being pressed. */
2148 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
2150 GetKeyboardState (keystate
);
2151 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
2152 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
2153 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
2154 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
2155 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
2156 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
2157 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
2158 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
2159 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
2160 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
2161 SetKeyboardState (keystate
);
2165 /* Synchronize modifier state with what is reported with the current
2166 keystroke. Even if we cannot distinguish between left and right
2167 modifier keys, we know that, if no modifiers are set, then neither
2168 the left or right modifier should be set. */
2170 sync_modifiers (void)
2172 if (!modifiers_recorded
)
2175 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
2176 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2178 if (!(GetKeyState (VK_MENU
) & 0x8000))
2179 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2183 modifier_set (int vkey
)
2185 if (vkey
== VK_CAPITAL
|| vkey
== VK_SCROLL
)
2186 return (GetKeyState (vkey
) & 0x1);
2187 if (!modifiers_recorded
)
2188 return (GetKeyState (vkey
) & 0x8000);
2193 return modifiers
[EMACS_LCONTROL
];
2195 return modifiers
[EMACS_RCONTROL
];
2197 return modifiers
[EMACS_LMENU
];
2199 return modifiers
[EMACS_RMENU
];
2201 return (GetKeyState (vkey
) & 0x8000);
2204 /* Convert between the modifier bits W32 uses and the modifier bits
2208 w32_key_to_modifier (int key
)
2210 Lisp_Object key_mapping
;
2215 key_mapping
= Vw32_lwindow_modifier
;
2218 key_mapping
= Vw32_rwindow_modifier
;
2221 key_mapping
= Vw32_apps_modifier
;
2224 key_mapping
= Vw32_scroll_lock_modifier
;
2230 /* NB. This code runs in the input thread, asychronously to the lisp
2231 thread, so we must be careful to ensure access to lisp data is
2232 thread-safe. The following code is safe because the modifier
2233 variable values are updated atomically from lisp and symbols are
2234 not relocated by GC. Also, we don't have to worry about seeing GC
2236 if (EQ (key_mapping
, Qhyper
))
2237 return hyper_modifier
;
2238 if (EQ (key_mapping
, Qsuper
))
2239 return super_modifier
;
2240 if (EQ (key_mapping
, Qmeta
))
2241 return meta_modifier
;
2242 if (EQ (key_mapping
, Qalt
))
2243 return alt_modifier
;
2244 if (EQ (key_mapping
, Qctrl
))
2245 return ctrl_modifier
;
2246 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
2247 return ctrl_modifier
;
2248 if (EQ (key_mapping
, Qshift
))
2249 return shift_modifier
;
2251 /* Don't generate any modifier if not explicitly requested. */
2256 w32_get_modifiers (void)
2258 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
2259 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
2260 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
2261 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
2262 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
2263 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
2264 (modifier_set (VK_MENU
) ?
2265 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
2268 /* We map the VK_* modifiers into console modifier constants
2269 so that we can use the same routines to handle both console
2270 and window input. */
2273 construct_console_modifiers (void)
2278 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
2279 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
2280 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
2281 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
2282 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
2283 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
2284 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
2285 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
2286 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
2287 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
2288 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
2294 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
2298 /* Convert to emacs modifiers. */
2299 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
2305 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
2307 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
2310 if (virt_key
== VK_RETURN
)
2311 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
2313 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
2314 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
2316 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
2317 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
2319 if (virt_key
== VK_CLEAR
)
2320 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
2325 /* List of special key combinations which w32 would normally capture,
2326 but Emacs should grab instead. Not directly visible to lisp, to
2327 simplify synchronization. Each item is an integer encoding a virtual
2328 key code and modifier combination to capture. */
2329 static Lisp_Object w32_grabbed_keys
;
2331 #define HOTKEY(vk, mods) make_number (((vk) & 255) | ((mods) << 8))
2332 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
2333 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
2334 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
2336 #define RAW_HOTKEY_ID(k) ((k) & 0xbfff)
2337 #define RAW_HOTKEY_VK_CODE(k) ((k) & 255)
2338 #define RAW_HOTKEY_MODIFIERS(k) ((k) >> 8)
2340 /* Register hot-keys for reserved key combinations when Emacs has
2341 keyboard focus, since this is the only way Emacs can receive key
2342 combinations like Alt-Tab which are used by the system. */
2345 register_hot_keys (HWND hwnd
)
2347 Lisp_Object keylist
;
2349 /* Use CONSP, since we are called asynchronously. */
2350 for (keylist
= w32_grabbed_keys
; CONSP (keylist
); keylist
= XCDR (keylist
))
2352 Lisp_Object key
= XCAR (keylist
);
2354 /* Deleted entries get set to nil. */
2355 if (!INTEGERP (key
))
2358 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
2359 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
2364 unregister_hot_keys (HWND hwnd
)
2366 Lisp_Object keylist
;
2368 for (keylist
= w32_grabbed_keys
; CONSP (keylist
); keylist
= XCDR (keylist
))
2370 Lisp_Object key
= XCAR (keylist
);
2372 if (!INTEGERP (key
))
2375 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
2379 /* Main message dispatch loop. */
2382 w32_msg_pump (deferred_msg
* msg_buf
)
2388 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
2390 while (GetMessage (&msg
, NULL
, 0, 0))
2392 if (msg
.hwnd
== NULL
)
2394 switch (msg
.message
)
2397 /* Produced by complete_deferred_msg; just ignore. */
2399 case WM_EMACS_CREATEWINDOW
:
2400 /* Initialize COM for this window. Even though we don't use it,
2401 some third party shell extensions can cause it to be used in
2402 system dialogs, which causes a crash if it is not initialized.
2403 This is a known bug in Windows, which was fixed long ago, but
2404 the patch for XP is not publically available until XP SP3,
2405 and older versions will never be patched. */
2406 CoInitialize (NULL
);
2407 w32_createwindow ((struct frame
*) msg
.wParam
);
2408 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2411 case WM_EMACS_SETLOCALE
:
2412 SetThreadLocale (msg
.wParam
);
2413 /* Reply is not expected. */
2415 case WM_EMACS_SETKEYBOARDLAYOUT
:
2416 result
= (int) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
2417 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2421 case WM_EMACS_REGISTER_HOT_KEY
:
2422 focus_window
= GetFocus ();
2423 if (focus_window
!= NULL
)
2424 RegisterHotKey (focus_window
,
2425 RAW_HOTKEY_ID (msg
.wParam
),
2426 RAW_HOTKEY_MODIFIERS (msg
.wParam
),
2427 RAW_HOTKEY_VK_CODE (msg
.wParam
));
2428 /* Reply is not expected. */
2430 case WM_EMACS_UNREGISTER_HOT_KEY
:
2431 focus_window
= GetFocus ();
2432 if (focus_window
!= NULL
)
2433 UnregisterHotKey (focus_window
, RAW_HOTKEY_ID (msg
.wParam
));
2434 /* Mark item as erased. NB: this code must be
2435 thread-safe. The next line is okay because the cons
2436 cell is never made into garbage and is not relocated by
2438 XSETCAR ((Lisp_Object
) ((EMACS_INT
) msg
.lParam
), Qnil
);
2439 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2442 case WM_EMACS_TOGGLE_LOCK_KEY
:
2444 int vk_code
= (int) msg
.wParam
;
2445 int cur_state
= (GetKeyState (vk_code
) & 1);
2446 Lisp_Object new_state
= (Lisp_Object
) ((EMACS_INT
) msg
.lParam
);
2448 /* NB: This code must be thread-safe. It is safe to
2449 call NILP because symbols are not relocated by GC,
2450 and pointer here is not touched by GC (so the markbit
2451 can't be set). Numbers are safe because they are
2452 immediate values. */
2453 if (NILP (new_state
)
2454 || (NUMBERP (new_state
)
2455 && ((XUINT (new_state
)) & 1) != cur_state
))
2457 one_w32_display_info
.faked_key
= vk_code
;
2459 keybd_event ((BYTE
) vk_code
,
2460 (BYTE
) MapVirtualKey (vk_code
, 0),
2461 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2462 keybd_event ((BYTE
) vk_code
,
2463 (BYTE
) MapVirtualKey (vk_code
, 0),
2464 KEYEVENTF_EXTENDEDKEY
| 0, 0);
2465 keybd_event ((BYTE
) vk_code
,
2466 (BYTE
) MapVirtualKey (vk_code
, 0),
2467 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2468 cur_state
= !cur_state
;
2470 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2476 /* Broadcast messages make it here, so you need to be looking
2477 for something in particular for this to be useful. */
2479 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
2485 DispatchMessage (&msg
);
2488 /* Exit nested loop when our deferred message has completed. */
2489 if (msg_buf
->completed
)
2494 deferred_msg
* deferred_msg_head
;
2496 static deferred_msg
*
2497 find_deferred_msg (HWND hwnd
, UINT msg
)
2499 deferred_msg
* item
;
2501 /* Don't actually need synchronization for read access, since
2502 modification of single pointer is always atomic. */
2503 /* enter_crit (); */
2505 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2506 if (item
->w32msg
.msg
.hwnd
== hwnd
2507 && item
->w32msg
.msg
.message
== msg
)
2510 /* leave_crit (); */
2516 send_deferred_msg (deferred_msg
* msg_buf
,
2522 /* Only input thread can send deferred messages. */
2523 if (GetCurrentThreadId () != dwWindowsThreadId
)
2526 /* It is an error to send a message that is already deferred. */
2527 if (find_deferred_msg (hwnd
, msg
) != NULL
)
2530 /* Enforced synchronization is not needed because this is the only
2531 function that alters deferred_msg_head, and the following critical
2532 section is guaranteed to only be serially reentered (since only the
2533 input thread can call us). */
2535 /* enter_crit (); */
2537 msg_buf
->completed
= 0;
2538 msg_buf
->next
= deferred_msg_head
;
2539 deferred_msg_head
= msg_buf
;
2540 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
2542 /* leave_crit (); */
2544 /* Start a new nested message loop to process other messages until
2545 this one is completed. */
2546 w32_msg_pump (msg_buf
);
2548 deferred_msg_head
= msg_buf
->next
;
2550 return msg_buf
->result
;
2554 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
2556 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
2558 if (msg_buf
== NULL
)
2559 /* Message may have been cancelled, so don't abort. */
2562 msg_buf
->result
= result
;
2563 msg_buf
->completed
= 1;
2565 /* Ensure input thread is woken so it notices the completion. */
2566 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2570 cancel_all_deferred_msgs (void)
2572 deferred_msg
* item
;
2574 /* Don't actually need synchronization for read access, since
2575 modification of single pointer is always atomic. */
2576 /* enter_crit (); */
2578 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2581 item
->completed
= 1;
2584 /* leave_crit (); */
2586 /* Ensure input thread is woken so it notices the completion. */
2587 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2591 w32_msg_worker (void *arg
)
2594 deferred_msg dummy_buf
;
2596 /* Ensure our message queue is created */
2598 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
2600 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2603 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
2604 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
2605 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
2607 /* This is the initial message loop which should only exit when the
2608 application quits. */
2609 w32_msg_pump (&dummy_buf
);
2615 signal_user_input (void)
2617 /* Interrupt any lisp that wants to be interrupted by input. */
2618 if (!NILP (Vthrow_on_input
))
2620 Vquit_flag
= Vthrow_on_input
;
2621 /* If we're inside a function that wants immediate quits,
2623 if (immediate_quit
&& NILP (Vinhibit_quit
))
2633 post_character_message (HWND hwnd
, UINT msg
,
2634 WPARAM wParam
, LPARAM lParam
,
2639 wmsg
.dwModifiers
= modifiers
;
2641 /* Detect quit_char and set quit-flag directly. Note that we
2642 still need to post a message to ensure the main thread will be
2643 woken up if blocked in sys_select, but we do NOT want to post
2644 the quit_char message itself (because it will usually be as if
2645 the user had typed quit_char twice). Instead, we post a dummy
2646 message that has no particular effect. */
2649 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
2650 c
= make_ctrl_char (c
) & 0377;
2652 || (wmsg
.dwModifiers
== 0 &&
2653 w32_quit_key
&& wParam
== w32_quit_key
))
2657 /* The choice of message is somewhat arbitrary, as long as
2658 the main thread handler just ignores it. */
2661 /* Interrupt any blocking system calls. */
2664 /* As a safety precaution, forcibly complete any deferred
2665 messages. This is a kludge, but I don't see any particularly
2666 clean way to handle the situation where a deferred message is
2667 "dropped" in the lisp thread, and will thus never be
2668 completed, eg. by the user trying to activate the menubar
2669 when the lisp thread is busy, and then typing C-g when the
2670 menubar doesn't open promptly (with the result that the
2671 menubar never responds at all because the deferred
2672 WM_INITMENU message is never completed). Another problem
2673 situation is when the lisp thread calls SendMessage (to send
2674 a window manager command) when a message has been deferred;
2675 the lisp thread gets blocked indefinitely waiting for the
2676 deferred message to be completed, which itself is waiting for
2677 the lisp thread to respond.
2679 Note that we don't want to block the input thread waiting for
2680 a reponse from the lisp thread (although that would at least
2681 solve the deadlock problem above), because we want to be able
2682 to receive C-g to interrupt the lisp thread. */
2683 cancel_all_deferred_msgs ();
2686 signal_user_input ();
2689 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2692 /* Main window procedure */
2695 w32_wnd_proc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2698 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
2700 int windows_translate
;
2703 /* Note that it is okay to call x_window_to_frame, even though we are
2704 not running in the main lisp thread, because frame deletion
2705 requires the lisp thread to synchronize with this thread. Thus, if
2706 a frame struct is returned, it can be used without concern that the
2707 lisp thread might make it disappear while we are using it.
2709 NB. Walking the frame list in this thread is safe (as long as
2710 writes of Lisp_Object slots are atomic, which they are on Windows).
2711 Although delete-frame can destructively modify the frame list while
2712 we are walking it, a garbage collection cannot occur until after
2713 delete-frame has synchronized with this thread.
2715 It is also safe to use functions that make GDI calls, such as
2716 w32_clear_rect, because these functions must obtain a DC handle
2717 from the frame struct using get_frame_dc which is thread-aware. */
2722 f
= x_window_to_frame (dpyinfo
, hwnd
);
2725 HDC hdc
= get_frame_dc (f
);
2726 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
2727 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
2728 release_frame_dc (f
, hdc
);
2730 #if defined (W32_DEBUG_DISPLAY)
2731 DebPrint (("WM_ERASEBKGND (frame %p): erasing %d,%d-%d,%d\n",
2733 wmsg
.rect
.left
, wmsg
.rect
.top
,
2734 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2735 #endif /* W32_DEBUG_DISPLAY */
2738 case WM_PALETTECHANGED
:
2739 /* ignore our own changes */
2740 if ((HWND
)wParam
!= hwnd
)
2742 f
= x_window_to_frame (dpyinfo
, hwnd
);
2744 /* get_frame_dc will realize our palette and force all
2745 frames to be redrawn if needed. */
2746 release_frame_dc (f
, get_frame_dc (f
));
2751 PAINTSTRUCT paintStruct
;
2753 memset (&update_rect
, 0, sizeof (update_rect
));
2755 f
= x_window_to_frame (dpyinfo
, hwnd
);
2758 DebPrint (("WM_PAINT received for unknown window %p\n", hwnd
));
2762 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
2763 fails. Apparently this can happen under some
2765 if (GetUpdateRect (hwnd
, &update_rect
, FALSE
) || !w32_strict_painting
)
2768 BeginPaint (hwnd
, &paintStruct
);
2770 /* The rectangles returned by GetUpdateRect and BeginPaint
2771 do not always match. Play it safe by assuming both areas
2773 UnionRect (&(wmsg
.rect
), &update_rect
, &(paintStruct
.rcPaint
));
2775 #if defined (W32_DEBUG_DISPLAY)
2776 DebPrint (("WM_PAINT (frame %p): painting %d,%d-%d,%d\n",
2778 wmsg
.rect
.left
, wmsg
.rect
.top
,
2779 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2780 DebPrint ((" [update region is %d,%d-%d,%d]\n",
2781 update_rect
.left
, update_rect
.top
,
2782 update_rect
.right
, update_rect
.bottom
));
2784 EndPaint (hwnd
, &paintStruct
);
2787 /* Change the message type to prevent Windows from
2788 combining WM_PAINT messages in the Lisp thread's queue,
2789 since Windows assumes that each message queue is
2790 dedicated to one frame and does not bother checking
2791 that hwnd matches before combining them. */
2792 my_post_msg (&wmsg
, hwnd
, WM_EMACS_PAINT
, wParam
, lParam
);
2797 /* If GetUpdateRect returns 0 (meaning there is no update
2798 region), assume the whole window needs to be repainted. */
2799 GetClientRect (hwnd
, &wmsg
.rect
);
2800 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2804 case WM_INPUTLANGCHANGE
:
2805 /* Inform lisp thread of keyboard layout changes. */
2806 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2808 /* Clear dead keys in the keyboard state; for simplicity only
2809 preserve modifier key states. */
2814 GetKeyboardState (keystate
);
2815 for (i
= 0; i
< 256; i
++)
2832 SetKeyboardState (keystate
);
2837 /* Synchronize hot keys with normal input. */
2838 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
2843 record_keyup (wParam
, lParam
);
2848 /* Ignore keystrokes we fake ourself; see below. */
2849 if (dpyinfo
->faked_key
== wParam
)
2851 dpyinfo
->faked_key
= 0;
2852 /* Make sure TranslateMessage sees them though (as long as
2853 they don't produce WM_CHAR messages). This ensures that
2854 indicator lights are toggled promptly on Windows 9x, for
2856 if (wParam
< 256 && lispy_function_keys
[wParam
])
2858 windows_translate
= 1;
2864 /* Synchronize modifiers with current keystroke. */
2866 record_keydown (wParam
, lParam
);
2867 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
2869 windows_translate
= 0;
2874 if (NILP (Vw32_pass_lwindow_to_system
))
2876 /* Prevent system from acting on keyup (which opens the
2877 Start menu if no other key was pressed) by simulating a
2878 press of Space which we will ignore. */
2879 if (GetAsyncKeyState (wParam
) & 1)
2881 if (NUMBERP (Vw32_phantom_key_code
))
2882 key
= XUINT (Vw32_phantom_key_code
) & 255;
2885 dpyinfo
->faked_key
= key
;
2886 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
2889 if (!NILP (Vw32_lwindow_modifier
))
2893 if (NILP (Vw32_pass_rwindow_to_system
))
2895 if (GetAsyncKeyState (wParam
) & 1)
2897 if (NUMBERP (Vw32_phantom_key_code
))
2898 key
= XUINT (Vw32_phantom_key_code
) & 255;
2901 dpyinfo
->faked_key
= key
;
2902 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
2905 if (!NILP (Vw32_rwindow_modifier
))
2909 if (!NILP (Vw32_apps_modifier
))
2913 if (NILP (Vw32_pass_alt_to_system
))
2914 /* Prevent DefWindowProc from activating the menu bar if an
2915 Alt key is pressed and released by itself. */
2917 windows_translate
= 1;
2920 /* Decide whether to treat as modifier or function key. */
2921 if (NILP (Vw32_enable_caps_lock
))
2922 goto disable_lock_key
;
2923 windows_translate
= 1;
2926 /* Decide whether to treat as modifier or function key. */
2927 if (NILP (Vw32_enable_num_lock
))
2928 goto disable_lock_key
;
2929 windows_translate
= 1;
2932 /* Decide whether to treat as modifier or function key. */
2933 if (NILP (Vw32_scroll_lock_modifier
))
2934 goto disable_lock_key
;
2935 windows_translate
= 1;
2938 /* Ensure the appropriate lock key state (and indicator light)
2939 remains in the same state. We do this by faking another
2940 press of the relevant key. Apparently, this really is the
2941 only way to toggle the state of the indicator lights. */
2942 dpyinfo
->faked_key
= wParam
;
2943 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
2944 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2945 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
2946 KEYEVENTF_EXTENDEDKEY
| 0, 0);
2947 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
2948 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2949 /* Ensure indicator lights are updated promptly on Windows 9x
2950 (TranslateMessage apparently does this), after forwarding
2952 post_character_message (hwnd
, msg
, wParam
, lParam
,
2953 w32_get_key_modifiers (wParam
, lParam
));
2954 windows_translate
= 1;
2958 case VK_PROCESSKEY
: /* Generated by IME. */
2959 windows_translate
= 1;
2962 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
2963 which is confusing for purposes of key binding; convert
2964 VK_CANCEL events into VK_PAUSE events. */
2968 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
2969 for purposes of key binding; convert these back into
2970 VK_NUMLOCK events, at least when we want to see NumLock key
2971 presses. (Note that there is never any possibility that
2972 VK_PAUSE with Ctrl really is C-Pause as per above.) */
2973 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
2974 wParam
= VK_NUMLOCK
;
2977 /* If not defined as a function key, change it to a WM_CHAR message. */
2978 if (wParam
> 255 || !lispy_function_keys
[wParam
])
2980 DWORD modifiers
= construct_console_modifiers ();
2982 if (!NILP (Vw32_recognize_altgr
)
2983 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
2985 /* Always let TranslateMessage handle AltGr key chords;
2986 for some reason, ToAscii doesn't always process AltGr
2987 chords correctly. */
2988 windows_translate
= 1;
2990 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
2992 /* Handle key chords including any modifiers other
2993 than shift directly, in order to preserve as much
2994 modifier information as possible. */
2995 if ('A' <= wParam
&& wParam
<= 'Z')
2997 /* Don't translate modified alphabetic keystrokes,
2998 so the user doesn't need to constantly switch
2999 layout to type control or meta keystrokes when
3000 the normal layout translates alphabetic
3001 characters to non-ascii characters. */
3002 if (!modifier_set (VK_SHIFT
))
3003 wParam
+= ('a' - 'A');
3008 /* Try to handle other keystrokes by determining the
3009 base character (ie. translating the base key plus
3013 KEY_EVENT_RECORD key
;
3015 key
.bKeyDown
= TRUE
;
3016 key
.wRepeatCount
= 1;
3017 key
.wVirtualKeyCode
= wParam
;
3018 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
3019 key
.uChar
.AsciiChar
= 0;
3020 key
.dwControlKeyState
= modifiers
;
3022 add
= w32_kbd_patch_key (&key
);
3023 /* 0 means an unrecognised keycode, negative means
3024 dead key. Ignore both. */
3027 /* Forward asciified character sequence. */
3028 post_character_message
3030 (unsigned char) key
.uChar
.AsciiChar
, lParam
,
3031 w32_get_key_modifiers (wParam
, lParam
));
3032 w32_kbd_patch_key (&key
);
3039 /* Let TranslateMessage handle everything else. */
3040 windows_translate
= 1;
3046 if (windows_translate
)
3048 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
3049 windows_msg
.time
= GetMessageTime ();
3050 TranslateMessage (&windows_msg
);
3058 post_character_message (hwnd
, msg
, wParam
, lParam
,
3059 w32_get_key_modifiers (wParam
, lParam
));
3063 /* WM_UNICHAR looks promising from the docs, but the exact
3064 circumstances in which TranslateMessage sends it is one of those
3065 Microsoft secret API things that EU and US courts are supposed
3066 to have put a stop to already. Spy++ shows it being sent to Notepad
3067 and other MS apps, but never to Emacs.
3069 Some third party IMEs send it in accordance with the official
3070 documentation though, so handle it here.
3072 UNICODE_NOCHAR is used to test for support for this message.
3073 TRUE indicates that the message is supported. */
3074 if (wParam
== UNICODE_NOCHAR
)
3079 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3080 signal_user_input ();
3081 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3086 /* If we can't get the IME result as unicode, use default processing,
3087 which will at least allow characters decodable in the system locale
3089 if (!get_composition_string_fn
)
3092 else if (!ignore_ime_char
)
3097 HIMC context
= get_ime_context_fn (hwnd
);
3098 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3099 /* Get buffer size. */
3100 size
= get_composition_string_fn (context
, GCS_RESULTSTR
, buffer
, 0);
3101 buffer
= alloca (size
);
3102 size
= get_composition_string_fn (context
, GCS_RESULTSTR
,
3104 release_ime_context_fn (hwnd
, context
);
3106 signal_user_input ();
3107 for (i
= 0; i
< size
/ sizeof (wchar_t); i
++)
3109 my_post_msg (&wmsg
, hwnd
, WM_UNICHAR
, (WPARAM
) buffer
[i
],
3112 /* Ignore the messages for the rest of the
3113 characters in the string that was output above. */
3114 ignore_ime_char
= (size
/ sizeof (wchar_t)) - 1;
3121 case WM_IME_STARTCOMPOSITION
:
3122 if (!set_ime_composition_window_fn
)
3126 COMPOSITIONFORM form
;
3133 f
= x_window_to_frame (dpyinfo
, hwnd
);
3134 w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
3136 form
.dwStyle
= CFS_RECT
;
3137 form
.ptCurrentPos
.x
= w32_system_caret_x
;
3138 form
.ptCurrentPos
.y
= w32_system_caret_y
;
3140 form
.rcArea
.left
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, 0);
3141 form
.rcArea
.top
= (WINDOW_TOP_EDGE_Y (w
)
3142 + WINDOW_HEADER_LINE_HEIGHT (w
));
3143 form
.rcArea
.right
= (WINDOW_BOX_RIGHT_EDGE_X (w
)
3144 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
3145 - WINDOW_RIGHT_FRINGE_WIDTH (w
));
3146 form
.rcArea
.bottom
= (WINDOW_BOTTOM_EDGE_Y (w
)
3147 - WINDOW_MODE_LINE_HEIGHT (w
));
3149 context
= get_ime_context_fn (hwnd
);
3150 set_ime_composition_window_fn (context
, &form
);
3151 release_ime_context_fn (hwnd
, context
);
3155 case WM_IME_ENDCOMPOSITION
:
3156 ignore_ime_char
= 0;
3159 /* Simulate middle mouse button events when left and right buttons
3160 are used together, but only if user has two button mouse. */
3161 case WM_LBUTTONDOWN
:
3162 case WM_RBUTTONDOWN
:
3163 if (w32_num_mouse_buttons
> 2)
3164 goto handle_plain_button
;
3167 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
3168 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
3170 if (button_state
& this)
3173 if (button_state
== 0)
3176 button_state
|= this;
3178 if (button_state
& other
)
3180 if (mouse_button_timer
)
3182 KillTimer (hwnd
, mouse_button_timer
);
3183 mouse_button_timer
= 0;
3185 /* Generate middle mouse event instead. */
3186 msg
= WM_MBUTTONDOWN
;
3187 button_state
|= MMOUSE
;
3189 else if (button_state
& MMOUSE
)
3191 /* Ignore button event if we've already generated a
3192 middle mouse down event. This happens if the
3193 user releases and press one of the two buttons
3194 after we've faked a middle mouse event. */
3199 /* Flush out saved message. */
3200 post_msg (&saved_mouse_button_msg
);
3202 wmsg
.dwModifiers
= w32_get_modifiers ();
3203 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3204 signal_user_input ();
3206 /* Clear message buffer. */
3207 saved_mouse_button_msg
.msg
.hwnd
= 0;
3211 /* Hold onto message for now. */
3212 mouse_button_timer
=
3213 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
3214 w32_mouse_button_tolerance
, NULL
);
3215 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
3216 saved_mouse_button_msg
.msg
.message
= msg
;
3217 saved_mouse_button_msg
.msg
.wParam
= wParam
;
3218 saved_mouse_button_msg
.msg
.lParam
= lParam
;
3219 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
3220 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
3227 if (w32_num_mouse_buttons
> 2)
3228 goto handle_plain_button
;
3231 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
3232 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
3234 if ((button_state
& this) == 0)
3237 button_state
&= ~this;
3239 if (button_state
& MMOUSE
)
3241 /* Only generate event when second button is released. */
3242 if ((button_state
& other
) == 0)
3245 button_state
&= ~MMOUSE
;
3247 if (button_state
) abort ();
3254 /* Flush out saved message if necessary. */
3255 if (saved_mouse_button_msg
.msg
.hwnd
)
3257 post_msg (&saved_mouse_button_msg
);
3260 wmsg
.dwModifiers
= w32_get_modifiers ();
3261 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3262 signal_user_input ();
3264 /* Always clear message buffer and cancel timer. */
3265 saved_mouse_button_msg
.msg
.hwnd
= 0;
3266 KillTimer (hwnd
, mouse_button_timer
);
3267 mouse_button_timer
= 0;
3269 if (button_state
== 0)
3274 case WM_XBUTTONDOWN
:
3276 if (w32_pass_extra_mouse_buttons_to_system
)
3278 /* else fall through and process them. */
3279 case WM_MBUTTONDOWN
:
3281 handle_plain_button
:
3286 /* Ignore middle and extra buttons as long as the menu is active. */
3287 f
= x_window_to_frame (dpyinfo
, hwnd
);
3288 if (f
&& f
->output_data
.w32
->menubar_active
)
3291 if (parse_button (msg
, HIWORD (wParam
), &button
, &up
))
3293 if (up
) ReleaseCapture ();
3294 else SetCapture (hwnd
);
3295 button
= (button
== 0) ? LMOUSE
:
3296 ((button
== 1) ? MMOUSE
: RMOUSE
);
3298 button_state
&= ~button
;
3300 button_state
|= button
;
3304 wmsg
.dwModifiers
= w32_get_modifiers ();
3305 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3306 signal_user_input ();
3308 /* Need to return true for XBUTTON messages, false for others,
3309 to indicate that we processed the message. */
3310 return (msg
== WM_XBUTTONDOWN
|| msg
== WM_XBUTTONUP
);
3313 /* Ignore mouse movements as long as the menu is active. These
3314 movements are processed by the window manager anyway, and
3315 it's wrong to handle them as if they happened on the
3316 underlying frame. */
3317 f
= x_window_to_frame (dpyinfo
, hwnd
);
3318 if (f
&& f
->output_data
.w32
->menubar_active
)
3321 /* If the mouse has just moved into the frame, start tracking
3322 it, so we will be notified when it leaves the frame. Mouse
3323 tracking only works under W98 and NT4 and later. On earlier
3324 versions, there is no way of telling when the mouse leaves the
3325 frame, so we just have to put up with help-echo and mouse
3326 highlighting remaining while the frame is not active. */
3327 if (track_mouse_event_fn
&& !track_mouse_window
)
3329 TRACKMOUSEEVENT tme
;
3330 tme
.cbSize
= sizeof (tme
);
3331 tme
.dwFlags
= TME_LEAVE
;
3332 tme
.hwndTrack
= hwnd
;
3334 track_mouse_event_fn (&tme
);
3335 track_mouse_window
= hwnd
;
3338 if (w32_mouse_move_interval
<= 0
3339 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
3341 wmsg
.dwModifiers
= w32_get_modifiers ();
3342 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3346 /* Hang onto mouse move and scroll messages for a bit, to avoid
3347 sending such events to Emacs faster than it can process them.
3348 If we get more events before the timer from the first message
3349 expires, we just replace the first message. */
3351 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
3353 SetTimer (hwnd
, MOUSE_MOVE_ID
,
3354 w32_mouse_move_interval
, NULL
);
3356 /* Hold onto message for now. */
3357 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
3358 saved_mouse_move_msg
.msg
.message
= msg
;
3359 saved_mouse_move_msg
.msg
.wParam
= wParam
;
3360 saved_mouse_move_msg
.msg
.lParam
= lParam
;
3361 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
3362 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
3368 wmsg
.dwModifiers
= w32_get_modifiers ();
3369 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3370 signal_user_input ();
3374 if (w32_pass_multimedia_buttons_to_system
)
3376 /* Otherwise, pass to lisp, the same way we do with mousehwheel. */
3377 case WM_MOUSEHWHEEL
:
3378 wmsg
.dwModifiers
= w32_get_modifiers ();
3379 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3380 signal_user_input ();
3381 /* Non-zero must be returned when WM_MOUSEHWHEEL messages are
3382 handled, to prevent the system trying to handle it by faking
3383 scroll bar events. */
3387 /* Flush out saved messages if necessary. */
3388 if (wParam
== mouse_button_timer
)
3390 if (saved_mouse_button_msg
.msg
.hwnd
)
3392 post_msg (&saved_mouse_button_msg
);
3393 signal_user_input ();
3394 saved_mouse_button_msg
.msg
.hwnd
= 0;
3396 KillTimer (hwnd
, mouse_button_timer
);
3397 mouse_button_timer
= 0;
3399 else if (wParam
== mouse_move_timer
)
3401 if (saved_mouse_move_msg
.msg
.hwnd
)
3403 post_msg (&saved_mouse_move_msg
);
3404 saved_mouse_move_msg
.msg
.hwnd
= 0;
3406 KillTimer (hwnd
, mouse_move_timer
);
3407 mouse_move_timer
= 0;
3409 else if (wParam
== menu_free_timer
)
3411 KillTimer (hwnd
, menu_free_timer
);
3412 menu_free_timer
= 0;
3413 f
= x_window_to_frame (dpyinfo
, hwnd
);
3414 /* If a popup menu is active, don't wipe its strings. */
3416 && current_popup_menu
== NULL
)
3418 /* Free memory used by owner-drawn and help-echo strings. */
3419 w32_free_menu_strings (hwnd
);
3420 f
->output_data
.w32
->menubar_active
= 0;
3424 else if (wParam
== hourglass_timer
)
3426 KillTimer (hwnd
, hourglass_timer
);
3427 hourglass_timer
= 0;
3428 w32_show_hourglass (x_window_to_frame (dpyinfo
, hwnd
));
3433 /* Windows doesn't send us focus messages when putting up and
3434 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
3435 The only indication we get that something happened is receiving
3436 this message afterwards. So this is a good time to reset our
3437 keyboard modifiers' state. */
3444 /* We must ensure menu bar is fully constructed and up to date
3445 before allowing user interaction with it. To achieve this
3446 we send this message to the lisp thread and wait for a
3447 reply (whose value is not actually needed) to indicate that
3448 the menu bar is now ready for use, so we can now return.
3450 To remain responsive in the meantime, we enter a nested message
3451 loop that can process all other messages.
3453 However, we skip all this if the message results from calling
3454 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
3455 thread a message because it is blocked on us at this point. We
3456 set menubar_active before calling TrackPopupMenu to indicate
3457 this (there is no possibility of confusion with real menubar
3460 f
= x_window_to_frame (dpyinfo
, hwnd
);
3462 && (f
->output_data
.w32
->menubar_active
3463 /* We can receive this message even in the absence of a
3464 menubar (ie. when the system menu is activated) - in this
3465 case we do NOT want to forward the message, otherwise it
3466 will cause the menubar to suddenly appear when the user
3467 had requested it to be turned off! */
3468 || f
->output_data
.w32
->menubar_widget
== NULL
))
3472 deferred_msg msg_buf
;
3474 /* Detect if message has already been deferred; in this case
3475 we cannot return any sensible value to ignore this. */
3476 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3481 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
3484 case WM_EXITMENULOOP
:
3485 f
= x_window_to_frame (dpyinfo
, hwnd
);
3487 /* If a menu is still active, check again after a short delay,
3488 since Windows often (always?) sends the WM_EXITMENULOOP
3489 before the corresponding WM_COMMAND message.
3490 Don't do this if a popup menu is active, since it is only
3491 menubar menus that require cleaning up in this way.
3493 if (f
&& menubar_in_use
&& current_popup_menu
== NULL
)
3494 menu_free_timer
= SetTimer (hwnd
, MENU_FREE_ID
, MENU_FREE_DELAY
, NULL
);
3496 /* If hourglass cursor should be displayed, display it now. */
3497 if (f
&& f
->output_data
.w32
->hourglass_p
)
3498 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
3503 /* Direct handling of help_echo in menus. Should be safe now
3504 that we generate the help_echo by placing a help event in the
3507 HMENU menu
= (HMENU
) lParam
;
3508 UINT menu_item
= (UINT
) LOWORD (wParam
);
3509 UINT flags
= (UINT
) HIWORD (wParam
);
3511 w32_menu_display_help (hwnd
, menu
, menu_item
, flags
);
3515 case WM_MEASUREITEM
:
3516 f
= x_window_to_frame (dpyinfo
, hwnd
);
3519 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
3521 if (pMis
->CtlType
== ODT_MENU
)
3523 /* Work out dimensions for popup menu titles. */
3524 char * title
= (char *) pMis
->itemData
;
3525 HDC hdc
= GetDC (hwnd
);
3526 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3527 LOGFONT menu_logfont
;
3531 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3532 menu_logfont
.lfWeight
= FW_BOLD
;
3533 menu_font
= CreateFontIndirect (&menu_logfont
);
3534 old_font
= SelectObject (hdc
, menu_font
);
3536 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
3539 if (unicode_append_menu
)
3540 GetTextExtentPoint32W (hdc
, (WCHAR
*) title
,
3541 wcslen ((WCHAR
*) title
),
3544 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
3546 pMis
->itemWidth
= size
.cx
;
3547 if (pMis
->itemHeight
< size
.cy
)
3548 pMis
->itemHeight
= size
.cy
;
3551 pMis
->itemWidth
= 0;
3553 SelectObject (hdc
, old_font
);
3554 DeleteObject (menu_font
);
3555 ReleaseDC (hwnd
, hdc
);
3562 f
= x_window_to_frame (dpyinfo
, hwnd
);
3565 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
3567 if (pDis
->CtlType
== ODT_MENU
)
3569 /* Draw popup menu title. */
3570 char * title
= (char *) pDis
->itemData
;
3573 HDC hdc
= pDis
->hDC
;
3574 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3575 LOGFONT menu_logfont
;
3578 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3579 menu_logfont
.lfWeight
= FW_BOLD
;
3580 menu_font
= CreateFontIndirect (&menu_logfont
);
3581 old_font
= SelectObject (hdc
, menu_font
);
3583 /* Always draw title as if not selected. */
3584 if (unicode_append_menu
)
3587 + GetSystemMetrics (SM_CXMENUCHECK
),
3589 ETO_OPAQUE
, &pDis
->rcItem
,
3591 wcslen ((WCHAR
*) title
), NULL
);
3595 + GetSystemMetrics (SM_CXMENUCHECK
),
3597 ETO_OPAQUE
, &pDis
->rcItem
,
3598 title
, strlen (title
), NULL
);
3600 SelectObject (hdc
, old_font
);
3601 DeleteObject (menu_font
);
3609 /* Still not right - can't distinguish between clicks in the
3610 client area of the frame from clicks forwarded from the scroll
3611 bars - may have to hook WM_NCHITTEST to remember the mouse
3612 position and then check if it is in the client area ourselves. */
3613 case WM_MOUSEACTIVATE
:
3614 /* Discard the mouse click that activates a frame, allowing the
3615 user to click anywhere without changing point (or worse!).
3616 Don't eat mouse clicks on scrollbars though!! */
3617 if (LOWORD (lParam
) == HTCLIENT
)
3618 return MA_ACTIVATEANDEAT
;
3623 /* No longer tracking mouse. */
3624 track_mouse_window
= NULL
;
3626 case WM_ACTIVATEAPP
:
3628 case WM_WINDOWPOSCHANGED
:
3630 /* Inform lisp thread that a frame might have just been obscured
3631 or exposed, so should recheck visibility of all frames. */
3632 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3636 dpyinfo
->faked_key
= 0;
3638 register_hot_keys (hwnd
);
3641 unregister_hot_keys (hwnd
);
3644 /* Relinquish the system caret. */
3645 if (w32_system_caret_hwnd
)
3647 w32_visible_system_caret_hwnd
= NULL
;
3648 w32_system_caret_hwnd
= NULL
;
3654 f
= x_window_to_frame (dpyinfo
, hwnd
);
3655 if (f
&& HIWORD (wParam
) == 0)
3657 if (menu_free_timer
)
3659 KillTimer (hwnd
, menu_free_timer
);
3660 menu_free_timer
= 0;
3666 wmsg
.dwModifiers
= w32_get_modifiers ();
3667 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3675 wmsg
.dwModifiers
= w32_get_modifiers ();
3676 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3679 case WM_WINDOWPOSCHANGING
:
3680 /* Don't restrict the sizing of tip frames. */
3681 if (hwnd
== tip_window
)
3685 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
3687 wp
.length
= sizeof (WINDOWPLACEMENT
);
3688 GetWindowPlacement (hwnd
, &wp
);
3690 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
3697 DWORD internal_border
;
3698 DWORD scrollbar_extra
;
3701 wp
.length
= sizeof (wp
);
3702 GetWindowRect (hwnd
, &wr
);
3706 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
3707 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
3708 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
3709 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
3713 memset (&rect
, 0, sizeof (rect
));
3714 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
3715 GetMenu (hwnd
) != NULL
);
3717 /* Force width and height of client area to be exact
3718 multiples of the character cell dimensions. */
3719 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
3720 - 2 * internal_border
- scrollbar_extra
)
3722 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
3723 - 2 * internal_border
)
3728 /* For right/bottom sizing we can just fix the sizes.
3729 However for top/left sizing we will need to fix the X
3730 and Y positions as well. */
3732 int cx_mintrack
= GetSystemMetrics (SM_CXMINTRACK
);
3733 int cy_mintrack
= GetSystemMetrics (SM_CYMINTRACK
);
3735 lppos
->cx
= max (lppos
->cx
- wdiff
, cx_mintrack
);
3736 lppos
->cy
= max (lppos
->cy
- hdiff
, cy_mintrack
);
3738 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
3739 && (lppos
->flags
& SWP_NOMOVE
) == 0)
3741 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
3748 lppos
->flags
|= SWP_NOMOVE
;
3759 case WM_GETMINMAXINFO
:
3760 /* Hack to allow resizing the Emacs frame above the screen size.
3761 Note that Windows 9x limits coordinates to 16-bits. */
3762 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.x
= 32767;
3763 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.y
= 32767;
3767 if (LOWORD (lParam
) == HTCLIENT
)
3769 f
= x_window_to_frame (dpyinfo
, hwnd
);
3770 if (f
->output_data
.w32
->hourglass_p
&& !menubar_in_use
3771 && !current_popup_menu
)
3772 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
3774 SetCursor (f
->output_data
.w32
->current_cursor
);
3779 case WM_EMACS_SETCURSOR
:
3781 Cursor cursor
= (Cursor
) wParam
;
3782 f
= x_window_to_frame (dpyinfo
, hwnd
);
3785 f
->output_data
.w32
->current_cursor
= cursor
;
3786 if (!f
->output_data
.w32
->hourglass_p
)
3792 case WM_EMACS_CREATESCROLLBAR
:
3793 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
3794 (struct scroll_bar
*) lParam
);
3796 case WM_EMACS_SHOWWINDOW
:
3797 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
3799 case WM_EMACS_SETFOREGROUND
:
3801 HWND foreground_window
;
3802 DWORD foreground_thread
, retval
;
3804 /* On NT 5.0, and apparently Windows 98, it is necessary to
3805 attach to the thread that currently has focus in order to
3806 pull the focus away from it. */
3807 foreground_window
= GetForegroundWindow ();
3808 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
3809 if (!foreground_window
3810 || foreground_thread
== GetCurrentThreadId ()
3811 || !AttachThreadInput (GetCurrentThreadId (),
3812 foreground_thread
, TRUE
))
3813 foreground_thread
= 0;
3815 retval
= SetForegroundWindow ((HWND
) wParam
);
3817 /* Detach from the previous foreground thread. */
3818 if (foreground_thread
)
3819 AttachThreadInput (GetCurrentThreadId (),
3820 foreground_thread
, FALSE
);
3825 case WM_EMACS_SETWINDOWPOS
:
3827 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
3828 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
3829 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
3832 case WM_EMACS_DESTROYWINDOW
:
3833 DragAcceptFiles ((HWND
) wParam
, FALSE
);
3834 return DestroyWindow ((HWND
) wParam
);
3836 case WM_EMACS_HIDE_CARET
:
3837 return HideCaret (hwnd
);
3839 case WM_EMACS_SHOW_CARET
:
3840 return ShowCaret (hwnd
);
3842 case WM_EMACS_DESTROY_CARET
:
3843 w32_system_caret_hwnd
= NULL
;
3844 w32_visible_system_caret_hwnd
= NULL
;
3845 return DestroyCaret ();
3847 case WM_EMACS_TRACK_CARET
:
3848 /* If there is currently no system caret, create one. */
3849 if (w32_system_caret_hwnd
== NULL
)
3851 /* Use the default caret width, and avoid changing it
3852 unneccesarily, as it confuses screen reader software. */
3853 w32_system_caret_hwnd
= hwnd
;
3854 CreateCaret (hwnd
, NULL
, 0,
3855 w32_system_caret_height
);
3858 if (!SetCaretPos (w32_system_caret_x
, w32_system_caret_y
))
3860 /* Ensure visible caret gets turned on when requested. */
3861 else if (w32_use_visible_system_caret
3862 && w32_visible_system_caret_hwnd
!= hwnd
)
3864 w32_visible_system_caret_hwnd
= hwnd
;
3865 return ShowCaret (hwnd
);
3867 /* Ensure visible caret gets turned off when requested. */
3868 else if (!w32_use_visible_system_caret
3869 && w32_visible_system_caret_hwnd
)
3871 w32_visible_system_caret_hwnd
= NULL
;
3872 return HideCaret (hwnd
);
3877 case WM_EMACS_TRACKPOPUPMENU
:
3882 pos
= (POINT
*)lParam
;
3883 flags
= TPM_CENTERALIGN
;
3884 if (button_state
& LMOUSE
)
3885 flags
|= TPM_LEFTBUTTON
;
3886 else if (button_state
& RMOUSE
)
3887 flags
|= TPM_RIGHTBUTTON
;
3889 /* Remember we did a SetCapture on the initial mouse down event,
3890 so for safety, we make sure the capture is cancelled now. */
3894 /* Use menubar_active to indicate that WM_INITMENU is from
3895 TrackPopupMenu below, and should be ignored. */
3896 f
= x_window_to_frame (dpyinfo
, hwnd
);
3898 f
->output_data
.w32
->menubar_active
= 1;
3900 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
3904 /* Eat any mouse messages during popupmenu */
3905 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
3907 /* Get the menu selection, if any */
3908 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
3910 retval
= LOWORD (amsg
.wParam
);
3926 /* Check for messages registered at runtime. */
3927 if (msg
== msh_mousewheel
)
3929 wmsg
.dwModifiers
= w32_get_modifiers ();
3930 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3931 signal_user_input ();
3936 return DefWindowProc (hwnd
, msg
, wParam
, lParam
);
3940 /* The most common default return code for handled messages is 0. */
3945 my_create_window (struct frame
* f
)
3949 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
3951 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
3955 /* Create a tooltip window. Unlike my_create_window, we do not do this
3956 indirectly via the Window thread, as we do not need to process Window
3957 messages for the tooltip. Creating tooltips indirectly also creates
3958 deadlocks when tooltips are created for menu items. */
3960 my_create_tip_window (struct frame
*f
)
3964 rect
.left
= rect
.top
= 0;
3965 rect
.right
= FRAME_PIXEL_WIDTH (f
);
3966 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
3968 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
3969 FRAME_EXTERNAL_MENU_BAR (f
));
3971 tip_window
= FRAME_W32_WINDOW (f
)
3972 = CreateWindow (EMACS_CLASS
,
3974 f
->output_data
.w32
->dwStyle
,
3977 rect
.right
- rect
.left
,
3978 rect
.bottom
- rect
.top
,
3979 FRAME_W32_WINDOW (SELECTED_FRAME ()), /* owner */
3986 SetWindowLong (tip_window
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
3987 SetWindowLong (tip_window
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
3988 SetWindowLong (tip_window
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
3989 SetWindowLong (tip_window
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
3991 /* Tip frames have no scrollbars. */
3992 SetWindowLong (tip_window
, WND_SCROLLBAR_INDEX
, 0);
3994 /* Do this to discard the default setting specified by our parent. */
3995 ShowWindow (tip_window
, SW_HIDE
);
4000 /* Create and set up the w32 window for frame F. */
4003 w32_window (struct frame
*f
, long window_prompting
, int minibuffer_only
)
4007 /* Use the resource name as the top-level window name
4008 for looking up resources. Make a non-Lisp copy
4009 for the window manager, so GC relocation won't bother it.
4011 Elsewhere we specify the window name for the window manager. */
4014 char *str
= (char *) SDATA (Vx_resource_name
);
4015 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
4016 strcpy (f
->namebuf
, str
);
4019 my_create_window (f
);
4021 validate_x_resource_name ();
4023 /* x_set_name normally ignores requests to set the name if the
4024 requested name is the same as the current name. This is the one
4025 place where that assumption isn't correct; f->name is set, but
4026 the server hasn't been told. */
4029 int explicit = f
->explicit_name
;
4031 f
->explicit_name
= 0;
4034 x_set_name (f
, name
, explicit);
4039 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
4040 initialize_frame_menubar (f
);
4042 if (FRAME_W32_WINDOW (f
) == 0)
4043 error ("Unable to create window");
4046 /* Handle the icon stuff for this window. Perhaps later we might
4047 want an x_set_icon_position which can be called interactively as
4051 x_icon (struct frame
*f
, Lisp_Object parms
)
4053 Lisp_Object icon_x
, icon_y
;
4054 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
4056 /* Set the position of the icon. Note that Windows 95 groups all
4057 icons in the tray. */
4058 icon_x
= x_get_arg (dpyinfo
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
4059 icon_y
= x_get_arg (dpyinfo
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
4060 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
4062 CHECK_NUMBER (icon_x
);
4063 CHECK_NUMBER (icon_y
);
4065 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
4066 error ("Both left and top icon corners of icon must be specified");
4070 if (! EQ (icon_x
, Qunbound
))
4071 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
4074 /* Start up iconic or window? */
4075 x_wm_set_window_state
4076 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
4080 x_text_icon (f
, (char *) SDATA ((!NILP (f
->icon_name
)
4090 x_make_gc (struct frame
*f
)
4092 XGCValues gc_values
;
4096 /* Create the GC's of this frame.
4097 Note that many default values are used. */
4100 gc_values
.font
= FRAME_FONT (f
);
4102 /* Cursor has cursor-color background, background-color foreground. */
4103 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
4104 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
4105 f
->output_data
.w32
->cursor_gc
4106 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
4107 (GCFont
| GCForeground
| GCBackground
),
4111 f
->output_data
.w32
->white_relief
.gc
= 0;
4112 f
->output_data
.w32
->black_relief
.gc
= 0;
4118 /* Handler for signals raised during x_create_frame and
4119 x_create_top_frame. FRAME is the frame which is partially
4123 unwind_create_frame (Lisp_Object frame
)
4125 struct frame
*f
= XFRAME (frame
);
4127 /* If frame is ``official'', nothing to do. */
4128 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
4131 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4134 x_free_frame_resources (f
);
4137 /* Check that reference counts are indeed correct. */
4138 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
4139 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
4148 x_default_font_parameter (struct frame
*f
, Lisp_Object parms
)
4150 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4151 Lisp_Object font_param
= x_get_arg (dpyinfo
, parms
, Qfont
, NULL
, NULL
,
4154 if (EQ (font_param
, Qunbound
))
4156 font
= !NILP (font_param
) ? font_param
4157 : x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4159 if (!STRINGP (font
))
4162 static char *names
[]
4163 = { "Courier New-10",
4164 "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1",
4165 "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1",
4169 for (i
= 0; names
[i
]; i
++)
4171 font
= font_open_by_name (f
, names
[i
]);
4176 error ("No suitable font was found");
4178 else if (!NILP (font_param
))
4180 /* Remember the explicit font parameter, so we can re-apply it after
4181 we've applied the `default' face settings. */
4182 x_set_frame_parameters (f
, Fcons (Fcons (Qfont_param
, font_param
), Qnil
));
4184 x_default_parameter (f
, parms
, Qfont
, font
, "font", "Font", RES_TYPE_STRING
);
4187 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
4189 doc
: /* Make a new window, which is called a \"frame\" in Emacs terms.
4190 Return an Emacs frame object.
4191 PARAMETERS is an alist of frame parameters.
4192 If the parameters specify that the frame should not have a minibuffer,
4193 and do not specify a specific minibuffer window to use,
4194 then `default-minibuffer-frame' must be a frame whose minibuffer can
4195 be shared by the new frame.
4197 This function is an internal primitive--use `make-frame' instead. */)
4198 (Lisp_Object parameters
)
4201 Lisp_Object frame
, tem
;
4203 int minibuffer_only
= 0;
4204 long window_prompting
= 0;
4206 int count
= SPECPDL_INDEX ();
4207 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4208 Lisp_Object display
;
4209 struct w32_display_info
*dpyinfo
= NULL
;
4213 /* Make copy of frame parameters because the original is in pure
4215 parameters
= Fcopy_alist (parameters
);
4217 /* Use this general default value to start with
4218 until we know if this frame has a specified name. */
4219 Vx_resource_name
= Vinvocation_name
;
4221 display
= x_get_arg (dpyinfo
, parameters
, Qterminal
, 0, 0, RES_TYPE_NUMBER
);
4222 if (EQ (display
, Qunbound
))
4223 display
= x_get_arg (dpyinfo
, parameters
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
4224 if (EQ (display
, Qunbound
))
4226 dpyinfo
= check_x_display_info (display
);
4227 kb
= dpyinfo
->terminal
->kboard
;
4229 if (!dpyinfo
->terminal
->name
)
4230 error ("Terminal is not live, can't create new frames on it");
4232 name
= x_get_arg (dpyinfo
, parameters
, Qname
, "name", "Name", RES_TYPE_STRING
);
4234 && ! EQ (name
, Qunbound
)
4236 error ("Invalid frame name--not a string or nil");
4239 Vx_resource_name
= name
;
4241 /* See if parent window is specified. */
4242 parent
= x_get_arg (dpyinfo
, parameters
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
4243 if (EQ (parent
, Qunbound
))
4245 if (! NILP (parent
))
4246 CHECK_NUMBER (parent
);
4248 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
4249 /* No need to protect DISPLAY because that's not used after passing
4250 it to make_frame_without_minibuffer. */
4252 GCPRO4 (parameters
, parent
, name
, frame
);
4253 tem
= x_get_arg (dpyinfo
, parameters
, Qminibuffer
, "minibuffer", "Minibuffer",
4255 if (EQ (tem
, Qnone
) || NILP (tem
))
4256 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
4257 else if (EQ (tem
, Qonly
))
4259 f
= make_minibuffer_frame ();
4260 minibuffer_only
= 1;
4262 else if (WINDOWP (tem
))
4263 f
= make_frame_without_minibuffer (tem
, kb
, display
);
4267 XSETFRAME (frame
, f
);
4269 /* Note that Windows does support scroll bars. */
4270 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
4272 /* By default, make scrollbars the system standard width. */
4273 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
4275 f
->terminal
= dpyinfo
->terminal
;
4276 f
->terminal
->reference_count
++;
4278 f
->output_method
= output_w32
;
4279 f
->output_data
.w32
=
4280 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
4281 memset (f
->output_data
.w32
, 0, sizeof (struct w32_output
));
4282 FRAME_FONTSET (f
) = -1;
4285 = x_get_arg (dpyinfo
, parameters
, Qicon_name
, "iconName", "Title",
4287 if (! STRINGP (f
->icon_name
))
4288 f
->icon_name
= Qnil
;
4290 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
4292 /* With FRAME_X_DISPLAY_INFO set up, this unwind-protect is safe. */
4293 record_unwind_protect (unwind_create_frame
, frame
);
4295 image_cache_refcount
= FRAME_IMAGE_CACHE (f
)->refcount
;
4296 dpyinfo_refcount
= dpyinfo
->reference_count
;
4297 #endif /* GLYPH_DEBUG */
4299 /* Specify the parent under which to make this window. */
4303 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
4304 f
->output_data
.w32
->explicit_parent
= 1;
4308 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4309 f
->output_data
.w32
->explicit_parent
= 0;
4312 /* Set the name; the functions to which we pass f expect the name to
4314 if (EQ (name
, Qunbound
) || NILP (name
))
4316 f
->name
= build_string (dpyinfo
->w32_id_name
);
4317 f
->explicit_name
= 0;
4322 f
->explicit_name
= 1;
4323 /* use the frame's title when getting resources for this frame. */
4324 specbind (Qx_resource_name
, name
);
4327 f
->resx
= dpyinfo
->resx
;
4328 f
->resy
= dpyinfo
->resy
;
4330 if (uniscribe_available
)
4331 register_font_driver (&uniscribe_font_driver
, f
);
4332 register_font_driver (&w32font_driver
, f
);
4334 x_default_parameter (f
, parameters
, Qfont_backend
, Qnil
,
4335 "fontBackend", "FontBackend", RES_TYPE_STRING
);
4336 /* Extract the window parameters from the supplied values
4337 that are needed to determine window geometry. */
4338 x_default_font_parameter (f
, parameters
);
4339 x_default_parameter (f
, parameters
, Qborder_width
, make_number (2),
4340 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4342 /* We recognize either internalBorderWidth or internalBorder
4343 (which is what xterm calls it). */
4344 if (NILP (Fassq (Qinternal_border_width
, parameters
)))
4348 value
= x_get_arg (dpyinfo
, parameters
, Qinternal_border_width
,
4349 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
4350 if (! EQ (value
, Qunbound
))
4351 parameters
= Fcons (Fcons (Qinternal_border_width
, value
),
4354 /* Default internalBorderWidth to 0 on Windows to match other programs. */
4355 x_default_parameter (f
, parameters
, Qinternal_border_width
, make_number (0),
4356 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
4357 x_default_parameter (f
, parameters
, Qvertical_scroll_bars
, Qright
,
4358 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
4360 /* Also do the stuff which must be set before the window exists. */
4361 x_default_parameter (f
, parameters
, Qforeground_color
, build_string ("black"),
4362 "foreground", "Foreground", RES_TYPE_STRING
);
4363 x_default_parameter (f
, parameters
, Qbackground_color
, build_string ("white"),
4364 "background", "Background", RES_TYPE_STRING
);
4365 x_default_parameter (f
, parameters
, Qmouse_color
, build_string ("black"),
4366 "pointerColor", "Foreground", RES_TYPE_STRING
);
4367 x_default_parameter (f
, parameters
, Qcursor_color
, build_string ("black"),
4368 "cursorColor", "Foreground", RES_TYPE_STRING
);
4369 x_default_parameter (f
, parameters
, Qborder_color
, build_string ("black"),
4370 "borderColor", "BorderColor", RES_TYPE_STRING
);
4371 x_default_parameter (f
, parameters
, Qscreen_gamma
, Qnil
,
4372 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
4373 x_default_parameter (f
, parameters
, Qline_spacing
, Qnil
,
4374 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
4375 x_default_parameter (f
, parameters
, Qleft_fringe
, Qnil
,
4376 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
4377 x_default_parameter (f
, parameters
, Qright_fringe
, Qnil
,
4378 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
4381 /* Init faces before x_default_parameter is called for scroll-bar
4382 parameters because that function calls x_set_scroll_bar_width,
4383 which calls change_frame_size, which calls Fset_window_buffer,
4384 which runs hooks, which call Fvertical_motion. At the end, we
4385 end up in init_iterator with a null face cache, which should not
4387 init_frame_faces (f
);
4389 /* The X resources controlling the menu-bar and tool-bar are
4390 processed specially at startup, and reflected in the mode
4391 variables; ignore them here. */
4392 x_default_parameter (f
, parameters
, Qmenu_bar_lines
,
4393 NILP (Vmenu_bar_mode
)
4394 ? make_number (0) : make_number (1),
4395 NULL
, NULL
, RES_TYPE_NUMBER
);
4396 x_default_parameter (f
, parameters
, Qtool_bar_lines
,
4397 NILP (Vtool_bar_mode
)
4398 ? make_number (0) : make_number (1),
4399 NULL
, NULL
, RES_TYPE_NUMBER
);
4401 x_default_parameter (f
, parameters
, Qbuffer_predicate
, Qnil
,
4402 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
4403 x_default_parameter (f
, parameters
, Qtitle
, Qnil
,
4404 "title", "Title", RES_TYPE_STRING
);
4405 x_default_parameter (f
, parameters
, Qfullscreen
, Qnil
,
4406 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
4408 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
4409 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4411 f
->output_data
.w32
->text_cursor
= w32_load_cursor (IDC_IBEAM
);
4412 f
->output_data
.w32
->nontext_cursor
= w32_load_cursor (IDC_ARROW
);
4413 f
->output_data
.w32
->modeline_cursor
= w32_load_cursor (IDC_ARROW
);
4414 f
->output_data
.w32
->hand_cursor
= w32_load_cursor (IDC_HAND
);
4415 f
->output_data
.w32
->hourglass_cursor
= w32_load_cursor (IDC_WAIT
);
4416 f
->output_data
.w32
->horizontal_drag_cursor
= w32_load_cursor (IDC_SIZEWE
);
4418 f
->output_data
.w32
->current_cursor
= f
->output_data
.w32
->nontext_cursor
;
4420 window_prompting
= x_figure_window_size (f
, parameters
, 1);
4422 tem
= x_get_arg (dpyinfo
, parameters
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
4423 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
4425 w32_window (f
, window_prompting
, minibuffer_only
);
4426 x_icon (f
, parameters
);
4430 /* Now consider the frame official. */
4431 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
4432 Vframe_list
= Fcons (frame
, Vframe_list
);
4434 /* We need to do this after creating the window, so that the
4435 icon-creation functions can say whose icon they're describing. */
4436 x_default_parameter (f
, parameters
, Qicon_type
, Qnil
,
4437 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
4439 x_default_parameter (f
, parameters
, Qauto_raise
, Qnil
,
4440 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4441 x_default_parameter (f
, parameters
, Qauto_lower
, Qnil
,
4442 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4443 x_default_parameter (f
, parameters
, Qcursor_type
, Qbox
,
4444 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4445 x_default_parameter (f
, parameters
, Qscroll_bar_width
, Qnil
,
4446 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
4447 x_default_parameter (f
, parameters
, Qalpha
, Qnil
,
4448 "alpha", "Alpha", RES_TYPE_NUMBER
);
4450 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4451 Change will not be effected unless different from the current
4453 width
= FRAME_COLS (f
);
4454 height
= FRAME_LINES (f
);
4456 FRAME_LINES (f
) = 0;
4457 SET_FRAME_COLS (f
, 0);
4458 change_frame_size (f
, height
, width
, 1, 0, 0);
4460 /* Tell the server what size and position, etc, we want, and how
4461 badly we want them. This should be done after we have the menu
4462 bar so that its size can be taken into account. */
4464 x_wm_set_size_hint (f
, window_prompting
, 0);
4467 /* Make the window appear on the frame and enable display, unless
4468 the caller says not to. However, with explicit parent, Emacs
4469 cannot control visibility, so don't try. */
4470 if (! f
->output_data
.w32
->explicit_parent
)
4472 Lisp_Object visibility
;
4474 visibility
= x_get_arg (dpyinfo
, parameters
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
4475 if (EQ (visibility
, Qunbound
))
4478 if (EQ (visibility
, Qicon
))
4479 x_iconify_frame (f
);
4480 else if (! NILP (visibility
))
4481 x_make_frame_visible (f
);
4483 /* Must have been Qnil. */
4487 /* Initialize `default-minibuffer-frame' in case this is the first
4488 frame on this terminal. */
4489 if (FRAME_HAS_MINIBUF_P (f
)
4490 && (!FRAMEP (kb
->Vdefault_minibuffer_frame
)
4491 || !FRAME_LIVE_P (XFRAME (kb
->Vdefault_minibuffer_frame
))))
4492 kb
->Vdefault_minibuffer_frame
= frame
;
4494 /* All remaining specified parameters, which have not been "used"
4495 by x_get_arg and friends, now go in the misc. alist of the frame. */
4496 for (tem
= parameters
; CONSP (tem
); tem
= XCDR (tem
))
4497 if (CONSP (XCAR (tem
)) && !NILP (XCAR (XCAR (tem
))))
4498 f
->param_alist
= Fcons (XCAR (tem
), f
->param_alist
);
4502 /* Make sure windows on this frame appear in calls to next-window
4503 and similar functions. */
4504 Vwindow_list
= Qnil
;
4506 return unbind_to (count
, frame
);
4509 /* FRAME is used only to get a handle on the X display. We don't pass the
4510 display info directly because we're called from frame.c, which doesn't
4511 know about that structure. */
4513 x_get_focus_frame (struct frame
*frame
)
4515 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
4517 if (! dpyinfo
->w32_focus_frame
)
4520 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
4524 DEFUN ("x-focus-frame", Fx_focus_frame
, Sx_focus_frame
, 1, 1, 0,
4525 doc
: /* Give FRAME input focus, raising to foreground if necessary. */)
4528 x_focus_on_frame (check_x_frame (frame
));
4533 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
4534 doc
: /* Internal function called by `color-defined-p', 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))
4548 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
4549 doc
: /* Internal function called by `color-values', which see. */)
4550 (Lisp_Object color
, Lisp_Object frame
)
4553 FRAME_PTR f
= check_x_frame (frame
);
4555 CHECK_STRING (color
);
4557 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
4558 return list3 (make_number ((GetRValue (foo
.pixel
) << 8)
4559 | GetRValue (foo
.pixel
)),
4560 make_number ((GetGValue (foo
.pixel
) << 8)
4561 | GetGValue (foo
.pixel
)),
4562 make_number ((GetBValue (foo
.pixel
) << 8)
4563 | GetBValue (foo
.pixel
)));
4568 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
4569 doc
: /* Internal function called by `display-color-p', which see. */)
4570 (Lisp_Object display
)
4572 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4574 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
4580 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
,
4581 Sx_display_grayscale_p
, 0, 1, 0,
4582 doc
: /* Return t if DISPLAY supports shades of gray.
4583 Note that color displays do support shades of gray.
4584 The optional argument DISPLAY specifies which display to ask about.
4585 DISPLAY should be either a frame or a display name (a string).
4586 If omitted or nil, that stands for the selected frame's display. */)
4587 (Lisp_Object display
)
4589 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4591 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
4597 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
,
4598 Sx_display_pixel_width
, 0, 1, 0,
4599 doc
: /* Return the width in pixels of DISPLAY.
4600 The optional argument DISPLAY specifies which display to ask about.
4601 DISPLAY should be either a frame or a display name (a string).
4602 If omitted or nil, that stands for the selected frame's display. */)
4603 (Lisp_Object display
)
4605 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4607 return make_number (x_display_pixel_width (dpyinfo
));
4610 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
4611 Sx_display_pixel_height
, 0, 1, 0,
4612 doc
: /* Return the height in pixels of DISPLAY.
4613 The optional argument DISPLAY specifies which display to ask about.
4614 DISPLAY should be either a frame or a display name (a string).
4615 If omitted or nil, that stands for the selected frame's display. */)
4616 (Lisp_Object display
)
4618 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4620 return make_number (x_display_pixel_height (dpyinfo
));
4623 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
4625 doc
: /* Return the number of bitplanes of DISPLAY.
4626 The optional argument DISPLAY specifies which display to ask about.
4627 DISPLAY should be either a frame or a display name (a string).
4628 If omitted or nil, that stands for the selected frame's display. */)
4629 (Lisp_Object display
)
4631 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4633 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
4636 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
4638 doc
: /* Return the number of color cells of DISPLAY.
4639 The optional argument DISPLAY specifies which display to ask about.
4640 DISPLAY should be either a frame or a display name (a string).
4641 If omitted or nil, that stands for the selected frame's display. */)
4642 (Lisp_Object display
)
4644 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4648 hdc
= GetDC (dpyinfo
->root_window
);
4649 if (dpyinfo
->has_palette
)
4650 cap
= GetDeviceCaps (hdc
, SIZEPALETTE
);
4652 cap
= GetDeviceCaps (hdc
, NUMCOLORS
);
4654 /* We force 24+ bit depths to 24-bit, both to prevent an overflow
4655 and because probably is more meaningful on Windows anyway */
4657 cap
= 1 << min (dpyinfo
->n_planes
* dpyinfo
->n_cbits
, 24);
4659 ReleaseDC (dpyinfo
->root_window
, hdc
);
4661 return make_number (cap
);
4664 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
4665 Sx_server_max_request_size
,
4667 doc
: /* Return the maximum request size of the server of DISPLAY.
4668 The optional argument DISPLAY specifies which display to ask about.
4669 DISPLAY should be either a frame or a display name (a string).
4670 If omitted or nil, that stands for the selected frame's display. */)
4671 (Lisp_Object display
)
4673 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4675 return make_number (1);
4678 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
4679 doc
: /* Return the "vendor ID" string of the W32 system (Microsoft).
4680 The optional argument DISPLAY specifies which display to ask about.
4681 DISPLAY should be either a frame or a display name (a string).
4682 If omitted or nil, that stands for the selected frame's display. */)
4683 (Lisp_Object display
)
4685 return build_string ("Microsoft Corp.");
4688 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
4689 doc
: /* Return the version numbers of the server of DISPLAY.
4690 The value is a list of three integers: the major and minor
4691 version numbers of the X Protocol in use, and the distributor-specific
4692 release number. See also the function `x-server-vendor'.
4694 The optional argument DISPLAY specifies which display to ask about.
4695 DISPLAY should be either a frame or a display name (a string).
4696 If omitted or nil, that stands for the selected frame's display. */)
4697 (Lisp_Object display
)
4699 return Fcons (make_number (w32_major_version
),
4700 Fcons (make_number (w32_minor_version
),
4701 Fcons (make_number (w32_build_number
), Qnil
)));
4704 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
4705 doc
: /* Return the number of screens on the server of DISPLAY.
4706 The optional argument DISPLAY specifies which display to ask about.
4707 DISPLAY should be either a frame or a display name (a string).
4708 If omitted or nil, that stands for the selected frame's display. */)
4709 (Lisp_Object display
)
4711 return make_number (1);
4714 DEFUN ("x-display-mm-height", Fx_display_mm_height
,
4715 Sx_display_mm_height
, 0, 1, 0,
4716 doc
: /* Return the height in millimeters of DISPLAY.
4717 The optional argument DISPLAY specifies which display to ask about.
4718 DISPLAY should be either a frame or a display name (a string).
4719 If omitted or nil, that stands for the selected frame's display. */)
4720 (Lisp_Object display
)
4722 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4726 hdc
= GetDC (dpyinfo
->root_window
);
4728 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
4730 ReleaseDC (dpyinfo
->root_window
, hdc
);
4732 return make_number (cap
);
4735 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
4736 doc
: /* Return the width in millimeters of DISPLAY.
4737 The optional argument DISPLAY specifies which display to ask about.
4738 DISPLAY should be either a frame or a display name (a string).
4739 If omitted or nil, that stands for the selected frame's display. */)
4740 (Lisp_Object display
)
4742 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4747 hdc
= GetDC (dpyinfo
->root_window
);
4749 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
4751 ReleaseDC (dpyinfo
->root_window
, hdc
);
4753 return make_number (cap
);
4756 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
4757 Sx_display_backing_store
, 0, 1, 0,
4758 doc
: /* Return an indication of whether DISPLAY does backing store.
4759 The value may be `always', `when-mapped', or `not-useful'.
4760 The optional argument DISPLAY specifies which display to ask about.
4761 DISPLAY should be either a frame or a display name (a string).
4762 If omitted or nil, that stands for the selected frame's display. */)
4763 (Lisp_Object display
)
4765 return intern ("not-useful");
4768 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
4769 Sx_display_visual_class
, 0, 1, 0,
4770 doc
: /* Return the visual class of DISPLAY.
4771 The value is one of the symbols `static-gray', `gray-scale',
4772 `static-color', `pseudo-color', `true-color', or `direct-color'.
4774 The optional argument DISPLAY specifies which display to ask about.
4775 DISPLAY should be either a frame or a display name (a string).
4776 If omitted or nil, that stands for the selected frame's display. */)
4777 (Lisp_Object display
)
4779 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4780 Lisp_Object result
= Qnil
;
4782 if (dpyinfo
->has_palette
)
4783 result
= intern ("pseudo-color");
4784 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
4785 result
= intern ("static-grey");
4786 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
4787 result
= intern ("static-color");
4788 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
4789 result
= intern ("true-color");
4794 DEFUN ("x-display-save-under", Fx_display_save_under
,
4795 Sx_display_save_under
, 0, 1, 0,
4796 doc
: /* Return t if DISPLAY supports the save-under feature.
4797 The optional argument DISPLAY specifies which display to ask about.
4798 DISPLAY should be either a frame or a display name (a string).
4799 If omitted or nil, that stands for the selected frame's display. */)
4800 (Lisp_Object display
)
4806 x_pixel_width (register struct frame
*f
)
4808 return FRAME_PIXEL_WIDTH (f
);
4812 x_pixel_height (register struct frame
*f
)
4814 return FRAME_PIXEL_HEIGHT (f
);
4818 x_char_width (register struct frame
*f
)
4820 return FRAME_COLUMN_WIDTH (f
);
4824 x_char_height (register struct frame
*f
)
4826 return FRAME_LINE_HEIGHT (f
);
4830 x_screen_planes (register struct frame
*f
)
4832 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
4835 /* Return the display structure for the display named NAME.
4836 Open a new connection if necessary. */
4838 struct w32_display_info
*
4839 x_display_info_for_name (Lisp_Object name
)
4842 struct w32_display_info
*dpyinfo
;
4844 CHECK_STRING (name
);
4846 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
4848 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
4851 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
4856 /* Use this general default value to start with. */
4857 Vx_resource_name
= Vinvocation_name
;
4859 validate_x_resource_name ();
4861 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
4862 (char *) SDATA (Vx_resource_name
));
4865 error ("Cannot connect to server %s", SDATA (name
));
4868 XSETFASTINT (Vwindow_system_version
, w32_major_version
);
4873 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
4874 1, 3, 0, doc
: /* Open a connection to a server.
4875 DISPLAY is the name of the display to connect to.
4876 Optional second arg XRM-STRING is a string of resources in xrdb format.
4877 If the optional third arg MUST-SUCCEED is non-nil,
4878 terminate Emacs if we can't open the connection. */)
4879 (Lisp_Object display
, Lisp_Object xrm_string
, Lisp_Object must_succeed
)
4881 unsigned char *xrm_option
;
4882 struct w32_display_info
*dpyinfo
;
4884 /* If initialization has already been done, return now to avoid
4885 overwriting critical parts of one_w32_display_info. */
4889 CHECK_STRING (display
);
4890 if (! NILP (xrm_string
))
4891 CHECK_STRING (xrm_string
);
4894 if (! EQ (Vwindow_system
, intern ("w32")))
4895 error ("Not using Microsoft Windows");
4898 /* Allow color mapping to be defined externally; first look in user's
4899 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
4901 Lisp_Object color_file
;
4902 struct gcpro gcpro1
;
4904 color_file
= build_string ("~/rgb.txt");
4906 GCPRO1 (color_file
);
4908 if (NILP (Ffile_readable_p (color_file
)))
4910 Fexpand_file_name (build_string ("rgb.txt"),
4911 Fsymbol_value (intern ("data-directory")));
4913 Vw32_color_map
= Fx_load_color_file (color_file
);
4917 if (NILP (Vw32_color_map
))
4918 Vw32_color_map
= Fw32_default_color_map ();
4920 /* Merge in system logical colors. */
4921 add_system_logical_colors_to_map (&Vw32_color_map
);
4923 if (! NILP (xrm_string
))
4924 xrm_option
= (unsigned char *) SDATA (xrm_string
);
4926 xrm_option
= (unsigned char *) 0;
4928 /* Use this general default value to start with. */
4929 /* First remove .exe suffix from invocation-name - it looks ugly. */
4931 char basename
[ MAX_PATH
], *str
;
4933 strcpy (basename
, SDATA (Vinvocation_name
));
4934 str
= strrchr (basename
, '.');
4936 Vinvocation_name
= build_string (basename
);
4938 Vx_resource_name
= Vinvocation_name
;
4940 validate_x_resource_name ();
4942 /* This is what opens the connection and sets x_current_display.
4943 This also initializes many symbols, such as those used for input. */
4944 dpyinfo
= w32_term_init (display
, xrm_option
,
4945 (char *) SDATA (Vx_resource_name
));
4949 if (!NILP (must_succeed
))
4950 fatal ("Cannot connect to server %s.\n",
4953 error ("Cannot connect to server %s", SDATA (display
));
4958 XSETFASTINT (Vwindow_system_version
, w32_major_version
);
4962 DEFUN ("x-close-connection", Fx_close_connection
,
4963 Sx_close_connection
, 1, 1, 0,
4964 doc
: /* Close the connection to DISPLAY's server.
4965 For DISPLAY, specify either a frame or a display name (a string).
4966 If DISPLAY is nil, that stands for the selected frame's display. */)
4967 (Lisp_Object display
)
4969 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4972 if (dpyinfo
->reference_count
> 0)
4973 error ("Display still has frames on it");
4976 x_destroy_all_bitmaps (dpyinfo
);
4978 x_delete_display (dpyinfo
);
4984 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
4985 doc
: /* Return the list of display names that Emacs has connections to. */)
4988 Lisp_Object tail
, result
;
4991 for (tail
= w32_display_name_list
; CONSP (tail
); tail
= XCDR (tail
))
4992 result
= Fcons (XCAR (XCAR (tail
)), result
);
4997 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
4998 doc
: /* This is a noop on W32 systems. */)
4999 (Lisp_Object on
, Lisp_Object display
)
5006 /***********************************************************************
5008 ***********************************************************************/
5010 DEFUN ("x-change-window-property", Fx_change_window_property
,
5011 Sx_change_window_property
, 2, 6, 0,
5012 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
5013 VALUE may be a string or a list of conses, numbers and/or strings.
5014 If an element in the list is a string, it is converted to
5015 an Atom and the value of the Atom is used. If an element is a cons,
5016 it is converted to a 32 bit number where the car is the 16 top bits and the
5017 cdr is the lower 16 bits.
5018 FRAME nil or omitted means use the selected frame.
5019 If TYPE is given and non-nil, it is the name of the type of VALUE.
5020 If TYPE is not given or nil, the type is STRING.
5021 FORMAT gives the size in bits of each element if VALUE is a list.
5022 It must be one of 8, 16 or 32.
5023 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
5024 If OUTER_P is non-nil, the property is changed for the outer X window of
5025 FRAME. Default is to change on the edit X window.
5028 (Lisp_Object prop
, Lisp_Object value
, Lisp_Object frame
, Lisp_Object type
, Lisp_Object format
, Lisp_Object outer_p
)
5030 #if 0 /* TODO : port window properties to W32 */
5031 struct frame
*f
= check_x_frame (frame
);
5034 CHECK_STRING (prop
);
5035 CHECK_STRING (value
);
5038 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5039 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5040 prop_atom
, XA_STRING
, 8, PropModeReplace
,
5041 SDATA (value
), SCHARS (value
));
5043 /* Make sure the property is set when we return. */
5044 XFlush (FRAME_W32_DISPLAY (f
));
5053 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
5054 Sx_delete_window_property
, 1, 2, 0,
5055 doc
: /* Remove window property PROP from X window of FRAME.
5056 FRAME nil or omitted means use the selected frame. Value is PROP. */)
5057 (Lisp_Object prop
, Lisp_Object frame
)
5059 #if 0 /* TODO : port window properties to W32 */
5061 struct frame
*f
= check_x_frame (frame
);
5064 CHECK_STRING (prop
);
5066 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5067 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
5069 /* Make sure the property is removed when we return. */
5070 XFlush (FRAME_W32_DISPLAY (f
));
5078 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
5080 doc
: /* Value is the value of window property PROP on FRAME.
5081 If FRAME is nil or omitted, use the selected frame. Value is nil
5082 if FRAME hasn't a property with name PROP or if PROP has no string
5084 (Lisp_Object prop
, Lisp_Object frame
)
5086 #if 0 /* TODO : port window properties to W32 */
5088 struct frame
*f
= check_x_frame (frame
);
5091 Lisp_Object prop_value
= Qnil
;
5092 char *tmp_data
= NULL
;
5095 unsigned long actual_size
, bytes_remaining
;
5097 CHECK_STRING (prop
);
5099 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5100 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5101 prop_atom
, 0, 0, False
, XA_STRING
,
5102 &actual_type
, &actual_format
, &actual_size
,
5103 &bytes_remaining
, (unsigned char **) &tmp_data
);
5106 int size
= bytes_remaining
;
5111 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5112 prop_atom
, 0, bytes_remaining
,
5114 &actual_type
, &actual_format
,
5115 &actual_size
, &bytes_remaining
,
5116 (unsigned char **) &tmp_data
);
5118 prop_value
= make_string (tmp_data
, size
);
5133 /***********************************************************************
5135 ***********************************************************************/
5137 /* Default number of seconds to wait before displaying an hourglass
5138 cursor. Duplicated from xdisp.c, but cannot use the version there
5139 due to lack of atimers on w32. */
5140 #define DEFAULT_HOURGLASS_DELAY 1
5141 extern Lisp_Object Vhourglass_delay
;
5143 /* Return non-zero if houglass timer has been started or hourglass is shown. */
5144 /* PENDING: if W32 can use atimers (atimer.[hc]) then the common impl in
5145 xdisp.c could be used. */
5148 hourglass_started (void)
5150 return hourglass_shown_p
|| hourglass_timer
;
5153 /* Cancel a currently active hourglass timer, and start a new one. */
5156 start_hourglass (void)
5159 int secs
, msecs
= 0;
5160 struct frame
* f
= SELECTED_FRAME ();
5162 /* No cursors on non GUI frames. */
5163 if (!FRAME_W32_P (f
))
5166 cancel_hourglass ();
5168 if (INTEGERP (Vhourglass_delay
)
5169 && XINT (Vhourglass_delay
) > 0)
5170 secs
= XFASTINT (Vhourglass_delay
);
5171 else if (FLOATP (Vhourglass_delay
)
5172 && XFLOAT_DATA (Vhourglass_delay
) > 0)
5175 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
5176 secs
= XFASTINT (tem
);
5177 msecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000;
5180 secs
= DEFAULT_HOURGLASS_DELAY
;
5182 delay
= secs
* 1000 + msecs
;
5183 hourglass_hwnd
= FRAME_W32_WINDOW (f
);
5184 hourglass_timer
= SetTimer (hourglass_hwnd
, HOURGLASS_ID
, delay
, NULL
);
5188 /* Cancel the hourglass cursor timer if active, hide an hourglass
5192 cancel_hourglass (void)
5194 if (hourglass_timer
)
5196 KillTimer (hourglass_hwnd
, hourglass_timer
);
5197 hourglass_timer
= 0;
5200 if (hourglass_shown_p
)
5201 w32_hide_hourglass ();
5205 /* Timer function of hourglass_timer.
5207 Display an hourglass cursor. Set the hourglass_p flag in display info
5208 to indicate that an hourglass cursor is shown. */
5211 w32_show_hourglass (struct frame
*f
)
5213 if (!hourglass_shown_p
)
5215 f
->output_data
.w32
->hourglass_p
= 1;
5216 if (!menubar_in_use
&& !current_popup_menu
)
5217 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
5218 hourglass_shown_p
= 1;
5223 /* Hide the hourglass cursor on all frames, if it is currently shown. */
5226 w32_hide_hourglass (void)
5228 if (hourglass_shown_p
)
5230 struct frame
*f
= x_window_to_frame (&one_w32_display_info
,
5233 f
->output_data
.w32
->hourglass_p
= 0;
5235 /* If frame was deleted, restore to selected frame's cursor. */
5236 f
= SELECTED_FRAME ();
5238 if (FRAME_W32_P (f
))
5239 SetCursor (f
->output_data
.w32
->current_cursor
);
5241 /* No cursors on non GUI frames - restore to stock arrow cursor. */
5242 SetCursor (w32_load_cursor (IDC_ARROW
));
5244 hourglass_shown_p
= 0;
5250 /***********************************************************************
5252 ***********************************************************************/
5254 static Lisp_Object
x_create_tip_frame (struct w32_display_info
*,
5255 Lisp_Object
, Lisp_Object
);
5256 static void compute_tip_xy (struct frame
*, Lisp_Object
, Lisp_Object
,
5257 Lisp_Object
, int, int, int *, int *);
5259 /* The frame of a currently visible tooltip. */
5261 Lisp_Object tip_frame
;
5263 /* If non-nil, a timer started that hides the last tooltip when it
5266 Lisp_Object tip_timer
;
5269 /* If non-nil, a vector of 3 elements containing the last args
5270 with which x-show-tip was called. See there. */
5272 Lisp_Object last_show_tip_args
;
5274 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
5276 Lisp_Object Vx_max_tooltip_size
;
5280 unwind_create_tip_frame (Lisp_Object frame
)
5282 Lisp_Object deleted
;
5284 deleted
= unwind_create_frame (frame
);
5285 if (EQ (deleted
, Qt
))
5295 /* Create a frame for a tooltip on the display described by DPYINFO.
5296 PARMS is a list of frame parameters. TEXT is the string to
5297 display in the tip frame. Value is the frame.
5299 Note that functions called here, esp. x_default_parameter can
5300 signal errors, for instance when a specified color name is
5301 undefined. We have to make sure that we're in a consistent state
5302 when this happens. */
5305 x_create_tip_frame (struct w32_display_info
*dpyinfo
,
5306 Lisp_Object parms
, Lisp_Object text
)
5309 Lisp_Object frame
, tem
;
5311 long window_prompting
= 0;
5313 int count
= SPECPDL_INDEX ();
5314 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5316 int face_change_count_before
= face_change_count
;
5318 struct buffer
*old_buffer
;
5322 /* Use this general default value to start with until we know if
5323 this frame has a specified name. */
5324 Vx_resource_name
= Vinvocation_name
;
5326 kb
= dpyinfo
->terminal
->kboard
;
5328 /* The calls to x_get_arg remove elements from PARMS, so copy it to
5329 avoid destructive changes behind our caller's back. */
5330 parms
= Fcopy_alist (parms
);
5332 /* Get the name of the frame to use for resource lookup. */
5333 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
5335 && !EQ (name
, Qunbound
)
5337 error ("Invalid frame name--not a string or nil");
5338 Vx_resource_name
= name
;
5341 GCPRO3 (parms
, name
, frame
);
5342 /* Make a frame without minibuffer nor mode-line. */
5344 f
->wants_modeline
= 0;
5345 XSETFRAME (frame
, f
);
5347 buffer
= Fget_buffer_create (build_string (" *tip*"));
5348 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, Qnil
);
5349 old_buffer
= current_buffer
;
5350 set_buffer_internal_1 (XBUFFER (buffer
));
5351 current_buffer
->truncate_lines
= Qnil
;
5352 specbind (Qinhibit_read_only
, Qt
);
5353 specbind (Qinhibit_modification_hooks
, Qt
);
5356 set_buffer_internal_1 (old_buffer
);
5358 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
5359 record_unwind_protect (unwind_create_tip_frame
, frame
);
5361 /* By setting the output method, we're essentially saying that
5362 the frame is live, as per FRAME_LIVE_P. If we get a signal
5363 from this point on, x_destroy_window might screw up reference
5365 f
->terminal
= dpyinfo
->terminal
;
5366 f
->terminal
->reference_count
++;
5367 f
->output_method
= output_w32
;
5368 f
->output_data
.w32
=
5369 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
5370 memset (f
->output_data
.w32
, 0, sizeof (struct w32_output
));
5372 FRAME_FONTSET (f
) = -1;
5373 f
->icon_name
= Qnil
;
5376 image_cache_refcount
= FRAME_IMAGE_CACHE (f
)->refcount
;
5377 dpyinfo_refcount
= dpyinfo
->reference_count
;
5378 #endif /* GLYPH_DEBUG */
5379 FRAME_KBOARD (f
) = kb
;
5380 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5381 f
->output_data
.w32
->explicit_parent
= 0;
5383 /* Set the name; the functions to which we pass f expect the name to
5385 if (EQ (name
, Qunbound
) || NILP (name
))
5387 f
->name
= build_string (dpyinfo
->w32_id_name
);
5388 f
->explicit_name
= 0;
5393 f
->explicit_name
= 1;
5394 /* use the frame's title when getting resources for this frame. */
5395 specbind (Qx_resource_name
, name
);
5398 f
->resx
= dpyinfo
->resx
;
5399 f
->resy
= dpyinfo
->resy
;
5401 if (uniscribe_available
)
5402 register_font_driver (&uniscribe_font_driver
, f
);
5403 register_font_driver (&w32font_driver
, f
);
5405 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
5406 "fontBackend", "FontBackend", RES_TYPE_STRING
);
5408 /* Extract the window parameters from the supplied values
5409 that are needed to determine window geometry. */
5410 x_default_font_parameter (f
, parms
);
5412 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
5413 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5414 /* This defaults to 2 in order to match xterm. We recognize either
5415 internalBorderWidth or internalBorder (which is what xterm calls
5417 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5421 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
5422 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
5423 if (! EQ (value
, Qunbound
))
5424 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
5427 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
5428 "internalBorderWidth", "internalBorderWidth",
5431 /* Also do the stuff which must be set before the window exists. */
5432 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
5433 "foreground", "Foreground", RES_TYPE_STRING
);
5434 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
5435 "background", "Background", RES_TYPE_STRING
);
5436 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
5437 "pointerColor", "Foreground", RES_TYPE_STRING
);
5438 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
5439 "cursorColor", "Foreground", RES_TYPE_STRING
);
5440 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
5441 "borderColor", "BorderColor", RES_TYPE_STRING
);
5443 /* Init faces before x_default_parameter is called for scroll-bar
5444 parameters because that function calls x_set_scroll_bar_width,
5445 which calls change_frame_size, which calls Fset_window_buffer,
5446 which runs hooks, which call Fvertical_motion. At the end, we
5447 end up in init_iterator with a null face cache, which should not
5449 init_frame_faces (f
);
5451 f
->output_data
.w32
->dwStyle
= WS_BORDER
| WS_POPUP
| WS_DISABLED
;
5452 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5454 window_prompting
= x_figure_window_size (f
, parms
, 0);
5456 /* No fringes on tip frame. */
5458 f
->left_fringe_width
= 0;
5459 f
->right_fringe_width
= 0;
5462 my_create_tip_window (f
);
5467 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
5468 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5469 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5470 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5471 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5472 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5474 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
5475 Change will not be effected unless different from the current
5477 width
= FRAME_COLS (f
);
5478 height
= FRAME_LINES (f
);
5479 FRAME_LINES (f
) = 0;
5480 SET_FRAME_COLS (f
, 0);
5481 change_frame_size (f
, height
, width
, 1, 0, 0);
5483 /* Add `tooltip' frame parameter's default value. */
5484 if (NILP (Fframe_parameter (frame
, Qtooltip
)))
5485 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qtooltip
, Qt
), Qnil
));
5487 /* Set up faces after all frame parameters are known. This call
5488 also merges in face attributes specified for new frames.
5490 Frame parameters may be changed if .Xdefaults contains
5491 specifications for the default font. For example, if there is an
5492 `Emacs.default.attributeBackground: pink', the `background-color'
5493 attribute of the frame get's set, which let's the internal border
5494 of the tooltip frame appear in pink. Prevent this. */
5496 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
5497 Lisp_Object fg
= Fframe_parameter (frame
, Qforeground_color
);
5498 Lisp_Object colors
= Qnil
;
5500 /* Set tip_frame here, so that */
5502 call2 (Qface_set_after_frame_default
, frame
, Qnil
);
5504 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
5505 colors
= Fcons (Fcons (Qbackground_color
, bg
), colors
);
5506 if (!EQ (fg
, Fframe_parameter (frame
, Qforeground_color
)))
5507 colors
= Fcons (Fcons (Qforeground_color
, fg
), colors
);
5510 Fmodify_frame_parameters (frame
, colors
);
5517 /* It is now ok to make the frame official even if we get an error
5518 below. And the frame needs to be on Vframe_list or making it
5519 visible won't work. */
5520 Vframe_list
= Fcons (frame
, Vframe_list
);
5522 /* Now that the frame is official, it counts as a reference to
5524 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
5526 /* Setting attributes of faces of the tooltip frame from resources
5527 and similar will increment face_change_count, which leads to the
5528 clearing of all current matrices. Since this isn't necessary
5529 here, avoid it by resetting face_change_count to the value it
5530 had before we created the tip frame. */
5531 face_change_count
= face_change_count_before
;
5533 /* Discard the unwind_protect. */
5534 return unbind_to (count
, frame
);
5538 /* Compute where to display tip frame F. PARMS is the list of frame
5539 parameters for F. DX and DY are specified offsets from the current
5540 location of the mouse. WIDTH and HEIGHT are the width and height
5541 of the tooltip. Return coordinates relative to the root window of
5542 the display in *ROOT_X, and *ROOT_Y. */
5545 compute_tip_xy (struct frame
*f
,
5546 Lisp_Object parms
, Lisp_Object dx
, Lisp_Object dy
,
5547 int width
, int height
, int *root_x
, int *root_y
)
5549 Lisp_Object left
, top
;
5550 int min_x
, min_y
, max_x
, max_y
;
5552 /* User-specified position? */
5553 left
= Fcdr (Fassq (Qleft
, parms
));
5554 top
= Fcdr (Fassq (Qtop
, parms
));
5556 /* Move the tooltip window where the mouse pointer is. Resize and
5558 if (!INTEGERP (left
) || !INTEGERP (top
))
5562 /* Default min and max values. */
5565 max_x
= x_display_pixel_width (FRAME_W32_DISPLAY_INFO (f
));
5566 max_y
= x_display_pixel_height (FRAME_W32_DISPLAY_INFO (f
));
5574 /* If multiple monitor support is available, constrain the tip onto
5575 the current monitor. This improves the above by allowing negative
5576 co-ordinates if monitor positions are such that they are valid, and
5577 snaps a tooltip onto a single monitor if we are close to the edge
5578 where it would otherwise flow onto the other monitor (or into
5579 nothingness if there is a gap in the overlap). */
5580 if (monitor_from_point_fn
&& get_monitor_info_fn
)
5582 struct MONITOR_INFO info
;
5584 = monitor_from_point_fn (pt
, MONITOR_DEFAULT_TO_NEAREST
);
5585 info
.cbSize
= sizeof (info
);
5587 if (get_monitor_info_fn (monitor
, &info
))
5589 min_x
= info
.rcWork
.left
;
5590 min_y
= info
.rcWork
.top
;
5591 max_x
= info
.rcWork
.right
;
5592 max_y
= info
.rcWork
.bottom
;
5598 *root_y
= XINT (top
);
5599 else if (*root_y
+ XINT (dy
) <= min_y
)
5600 *root_y
= min_y
; /* Can happen for negative dy */
5601 else if (*root_y
+ XINT (dy
) + height
<= max_y
)
5602 /* It fits below the pointer */
5603 *root_y
+= XINT (dy
);
5604 else if (height
+ XINT (dy
) + min_y
<= *root_y
)
5605 /* It fits above the pointer. */
5606 *root_y
-= height
+ XINT (dy
);
5608 /* Put it on the top. */
5611 if (INTEGERP (left
))
5612 *root_x
= XINT (left
);
5613 else if (*root_x
+ XINT (dx
) <= min_x
)
5614 *root_x
= 0; /* Can happen for negative dx */
5615 else if (*root_x
+ XINT (dx
) + width
<= max_x
)
5616 /* It fits to the right of the pointer. */
5617 *root_x
+= XINT (dx
);
5618 else if (width
+ XINT (dx
) + min_x
<= *root_x
)
5619 /* It fits to the left of the pointer. */
5620 *root_x
-= width
+ XINT (dx
);
5622 /* Put it left justified on the screen -- it ought to fit that way. */
5627 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
5628 doc
: /* Show STRING in a \"tooltip\" window on frame FRAME.
5629 A tooltip window is a small window displaying a string.
5631 This is an internal function; Lisp code should call `tooltip-show'.
5633 FRAME nil or omitted means use the selected frame.
5635 PARMS is an optional list of frame parameters which can be
5636 used to change the tooltip's appearance.
5638 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
5639 means use the default timeout of 5 seconds.
5641 If the list of frame parameters PARMS contains a `left' parameter,
5642 the tooltip is displayed at that x-position. Otherwise it is
5643 displayed at the mouse position, with offset DX added (default is 5 if
5644 DX isn't specified). Likewise for the y-position; if a `top' frame
5645 parameter is specified, it determines the y-position of the tooltip
5646 window, otherwise it is displayed at the mouse position, with offset
5647 DY added (default is -10).
5649 A tooltip's maximum size is specified by `x-max-tooltip-size'.
5650 Text larger than the specified size is clipped. */)
5651 (Lisp_Object string
, Lisp_Object frame
, Lisp_Object parms
, Lisp_Object timeout
, Lisp_Object dx
, Lisp_Object dy
)
5656 struct buffer
*old_buffer
;
5657 struct text_pos pos
;
5658 int i
, width
, height
;
5659 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5660 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5661 int count
= SPECPDL_INDEX ();
5663 specbind (Qinhibit_redisplay
, Qt
);
5665 GCPRO4 (string
, parms
, frame
, timeout
);
5667 CHECK_STRING (string
);
5668 f
= check_x_frame (frame
);
5670 timeout
= make_number (5);
5672 CHECK_NATNUM (timeout
);
5675 dx
= make_number (5);
5680 dy
= make_number (-10);
5684 if (NILP (last_show_tip_args
))
5685 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
5687 if (!NILP (tip_frame
))
5689 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
5690 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
5691 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
5693 if (EQ (frame
, last_frame
)
5694 && !NILP (Fequal (last_string
, string
))
5695 && !NILP (Fequal (last_parms
, parms
)))
5697 struct frame
*f
= XFRAME (tip_frame
);
5699 /* Only DX and DY have changed. */
5700 if (!NILP (tip_timer
))
5702 Lisp_Object timer
= tip_timer
;
5704 call1 (Qcancel_timer
, timer
);
5708 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
5709 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
5711 /* Put tooltip in topmost group and in position. */
5712 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
5713 root_x
, root_y
, 0, 0,
5714 SWP_NOSIZE
| SWP_NOACTIVATE
);
5716 /* Ensure tooltip is on top of other topmost windows (eg menus). */
5717 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
5719 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
5726 /* Hide a previous tip, if any. */
5729 ASET (last_show_tip_args
, 0, string
);
5730 ASET (last_show_tip_args
, 1, frame
);
5731 ASET (last_show_tip_args
, 2, parms
);
5733 /* Add default values to frame parameters. */
5734 if (NILP (Fassq (Qname
, parms
)))
5735 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
5736 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5737 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
5738 if (NILP (Fassq (Qborder_width
, parms
)))
5739 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
5740 if (NILP (Fassq (Qborder_color
, parms
)))
5741 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
5742 if (NILP (Fassq (Qbackground_color
, parms
)))
5743 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
5746 /* Block input until the tip has been fully drawn, to avoid crashes
5747 when drawing tips in menus. */
5750 /* Create a frame for the tooltip, and record it in the global
5751 variable tip_frame. */
5752 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
, string
);
5755 /* Set up the frame's root window. */
5756 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5757 w
->left_col
= w
->top_line
= make_number (0);
5759 if (CONSP (Vx_max_tooltip_size
)
5760 && INTEGERP (XCAR (Vx_max_tooltip_size
))
5761 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
5762 && INTEGERP (XCDR (Vx_max_tooltip_size
))
5763 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
5765 w
->total_cols
= XCAR (Vx_max_tooltip_size
);
5766 w
->total_lines
= XCDR (Vx_max_tooltip_size
);
5770 w
->total_cols
= make_number (80);
5771 w
->total_lines
= make_number (40);
5774 FRAME_TOTAL_COLS (f
) = XINT (w
->total_cols
);
5776 w
->pseudo_window_p
= 1;
5778 /* Display the tooltip text in a temporary buffer. */
5779 old_buffer
= current_buffer
;
5780 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
5781 current_buffer
->truncate_lines
= Qnil
;
5782 clear_glyph_matrix (w
->desired_matrix
);
5783 clear_glyph_matrix (w
->current_matrix
);
5784 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
5785 try_window (FRAME_ROOT_WINDOW (f
), pos
, 0);
5787 /* Compute width and height of the tooltip. */
5789 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5791 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5795 /* Stop at the first empty row at the end. */
5796 if (!row
->enabled_p
|| !row
->displays_text_p
)
5799 /* Let the row go over the full width of the frame. */
5800 row
->full_width_p
= 1;
5802 #ifdef TODO /* Investigate why some fonts need more width than is
5803 calculated for some tooltips. */
5804 /* There's a glyph at the end of rows that is use to place
5805 the cursor there. Don't include the width of this glyph. */
5806 if (row
->used
[TEXT_AREA
])
5808 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5809 row_width
= row
->pixel_width
- last
->pixel_width
;
5813 row_width
= row
->pixel_width
;
5815 /* TODO: find why tips do not draw along baseline as instructed. */
5816 height
+= row
->height
;
5817 width
= max (width
, row_width
);
5820 /* Add the frame's internal border to the width and height the X
5821 window should have. */
5822 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5823 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5825 /* Move the tooltip window where the mouse pointer is. Resize and
5827 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
5830 /* Adjust Window size to take border into account. */
5832 rect
.left
= rect
.top
= 0;
5834 rect
.bottom
= height
;
5835 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
5836 FRAME_EXTERNAL_MENU_BAR (f
));
5838 /* Position and size tooltip, and put it in the topmost group.
5839 The add-on of 3 to the 5th argument is a kludge: without it,
5840 some fonts cause the last character of the tip to be truncated,
5841 for some obscure reason. */
5842 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
5843 root_x
, root_y
, rect
.right
- rect
.left
+ 3,
5844 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
);
5846 /* Ensure tooltip is on top of other topmost windows (eg menus). */
5847 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
5849 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
5851 /* Let redisplay know that we have made the frame visible already. */
5852 f
->async_visible
= 1;
5854 ShowWindow (FRAME_W32_WINDOW (f
), SW_SHOWNOACTIVATE
);
5857 /* Draw into the window. */
5858 w
->must_be_updated_p
= 1;
5859 update_single_window (w
, 1);
5863 /* Restore original current buffer. */
5864 set_buffer_internal_1 (old_buffer
);
5865 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5868 /* Let the tip disappear after timeout seconds. */
5869 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
5870 intern ("x-hide-tip"));
5873 return unbind_to (count
, Qnil
);
5877 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
5878 doc
: /* Hide the current tooltip window, if there is any.
5879 Value is t if tooltip was open, nil otherwise. */)
5883 Lisp_Object deleted
, frame
, timer
;
5884 struct gcpro gcpro1
, gcpro2
;
5886 /* Return quickly if nothing to do. */
5887 if (NILP (tip_timer
) && NILP (tip_frame
))
5892 GCPRO2 (frame
, timer
);
5893 tip_frame
= tip_timer
= deleted
= Qnil
;
5895 count
= SPECPDL_INDEX ();
5896 specbind (Qinhibit_redisplay
, Qt
);
5897 specbind (Qinhibit_quit
, Qt
);
5900 call1 (Qcancel_timer
, timer
);
5904 delete_frame (frame
, Qnil
);
5909 return unbind_to (count
, deleted
);
5914 /***********************************************************************
5915 File selection dialog
5916 ***********************************************************************/
5917 extern Lisp_Object Qfile_name_history
;
5919 /* Callback for altering the behavior of the Open File dialog.
5920 Makes the Filename text field contain "Current Directory" and be
5921 read-only when "Directories" is selected in the filter. This
5922 allows us to work around the fact that the standard Open File
5923 dialog does not support directories. */
5925 file_dialog_callback (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
5927 if (msg
== WM_NOTIFY
)
5929 OFNOTIFY
* notify
= (OFNOTIFY
*)lParam
;
5930 /* Detect when the Filter dropdown is changed. */
5931 if (notify
->hdr
.code
== CDN_TYPECHANGE
5932 || notify
->hdr
.code
== CDN_INITDONE
)
5934 HWND dialog
= GetParent (hwnd
);
5935 HWND edit_control
= GetDlgItem (dialog
, FILE_NAME_TEXT_FIELD
);
5937 /* Directories is in index 2. */
5938 if (notify
->lpOFN
->nFilterIndex
== 2)
5940 CommDlg_OpenSave_SetControlText (dialog
, FILE_NAME_TEXT_FIELD
,
5941 "Current Directory");
5942 EnableWindow (edit_control
, FALSE
);
5946 /* Don't override default filename on init done. */
5947 if (notify
->hdr
.code
== CDN_TYPECHANGE
)
5948 CommDlg_OpenSave_SetControlText (dialog
,
5949 FILE_NAME_TEXT_FIELD
, "");
5950 EnableWindow (edit_control
, TRUE
);
5957 /* Since we compile with _WIN32_WINNT set to 0x0400 (for NT4 compatibility)
5958 we end up with the old file dialogs. Define a big enough struct for the
5959 new dialog to trick GetOpenFileName into giving us the new dialogs on
5960 Windows 2000 and XP. */
5963 OPENFILENAME real_details
;
5970 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
5971 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5972 Use a file selection dialog.
5973 Select DEFAULT-FILENAME in the dialog's file selection box, if
5974 specified. Ensure that file exists if MUSTMATCH is non-nil.
5975 If ONLY-DIR-P is non-nil, the user can only select directories. */)
5976 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
, Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
5978 struct frame
*f
= SELECTED_FRAME ();
5979 Lisp_Object file
= Qnil
;
5980 int count
= SPECPDL_INDEX ();
5981 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
5982 char filename
[MAX_PATH
+ 1];
5983 char init_dir
[MAX_PATH
+ 1];
5984 int default_filter_index
= 1; /* 1: All Files, 2: Directories only */
5986 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
5987 CHECK_STRING (prompt
);
5990 /* Create the dialog with PROMPT as title, using DIR as initial
5991 directory and using "*" as pattern. */
5992 dir
= Fexpand_file_name (dir
, Qnil
);
5993 strncpy (init_dir
, SDATA (ENCODE_FILE (dir
)), MAX_PATH
);
5994 init_dir
[MAX_PATH
] = '\0';
5995 unixtodos_filename (init_dir
);
5997 if (STRINGP (default_filename
))
5999 char *file_name_only
;
6000 char *full_path_name
= SDATA (ENCODE_FILE (default_filename
));
6002 unixtodos_filename (full_path_name
);
6004 file_name_only
= strrchr (full_path_name
, '\\');
6005 if (!file_name_only
)
6006 file_name_only
= full_path_name
;
6010 strncpy (filename
, file_name_only
, MAX_PATH
);
6011 filename
[MAX_PATH
] = '\0';
6017 NEWOPENFILENAME new_file_details
;
6018 BOOL file_opened
= FALSE
;
6019 OPENFILENAME
* file_details
= &new_file_details
.real_details
;
6021 /* Prevent redisplay. */
6022 specbind (Qinhibit_redisplay
, Qt
);
6025 memset (&new_file_details
, 0, sizeof (new_file_details
));
6026 /* Apparently NT4 crashes if you give it an unexpected size.
6027 I'm not sure about Windows 9x, so play it safe. */
6028 if (w32_major_version
> 4 && w32_major_version
< 95)
6029 file_details
->lStructSize
= sizeof (NEWOPENFILENAME
);
6031 file_details
->lStructSize
= sizeof (OPENFILENAME
);
6033 file_details
->hwndOwner
= FRAME_W32_WINDOW (f
);
6034 /* Undocumented Bug in Common File Dialog:
6035 If a filter is not specified, shell links are not resolved. */
6036 file_details
->lpstrFilter
= "All Files (*.*)\0*.*\0Directories\0*|*\0\0";
6037 file_details
->lpstrFile
= filename
;
6038 file_details
->nMaxFile
= sizeof (filename
);
6039 file_details
->lpstrInitialDir
= init_dir
;
6040 file_details
->lpstrTitle
= SDATA (prompt
);
6042 if (! NILP (only_dir_p
))
6043 default_filter_index
= 2;
6045 file_details
->nFilterIndex
= default_filter_index
;
6047 file_details
->Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
6048 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
6049 if (!NILP (mustmatch
))
6051 /* Require that the path to the parent directory exists. */
6052 file_details
->Flags
|= OFN_PATHMUSTEXIST
;
6053 /* If we are looking for a file, require that it exists. */
6054 if (NILP (only_dir_p
))
6055 file_details
->Flags
|= OFN_FILEMUSTEXIST
;
6058 file_details
->lpfnHook
= (LPOFNHOOKPROC
) file_dialog_callback
;
6060 file_opened
= GetOpenFileName (file_details
);
6066 dostounix_filename (filename
);
6068 if (file_details
->nFilterIndex
== 2)
6070 /* "Directories" selected - strip dummy file name. */
6071 char * last
= strrchr (filename
, '/');
6075 file
= DECODE_FILE (build_string (filename
));
6077 /* User cancelled the dialog without making a selection. */
6078 else if (!CommDlgExtendedError ())
6080 /* An error occurred, fallback on reading from the mini-buffer. */
6082 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
6083 dir
, mustmatch
, dir
, Qfile_name_history
,
6084 default_filename
, Qnil
);
6086 file
= unbind_to (count
, file
);
6091 /* Make "Cancel" equivalent to C-g. */
6093 Fsignal (Qquit
, Qnil
);
6095 return unbind_to (count
, file
);
6099 /* Moving files to the system recycle bin.
6100 Used by `move-file-to-trash' instead of the default moving to ~/.Trash */
6101 DEFUN ("system-move-file-to-trash", Fsystem_move_file_to_trash
,
6102 Ssystem_move_file_to_trash
, 1, 1, 0,
6103 doc
: /* Move file or directory named FILENAME to the recycle bin. */)
6104 (Lisp_Object filename
)
6106 Lisp_Object handler
;
6107 Lisp_Object encoded_file
;
6108 Lisp_Object operation
;
6110 operation
= Qdelete_file
;
6111 if (!NILP (Ffile_directory_p (filename
))
6112 && NILP (Ffile_symlink_p (filename
)))
6114 operation
= intern ("delete-directory");
6115 filename
= Fdirectory_file_name (filename
);
6117 filename
= Fexpand_file_name (filename
, Qnil
);
6119 handler
= Ffind_file_name_handler (filename
, operation
);
6120 if (!NILP (handler
))
6121 return call2 (handler
, operation
, filename
);
6123 encoded_file
= ENCODE_FILE (filename
);
6127 SHFILEOPSTRUCT file_op
;
6128 char tmp_path
[MAX_PATH
+ 1];
6130 path
= map_w32_filename (SDATA (encoded_file
), NULL
);
6132 /* On Windows, write permission is required to delete/move files. */
6133 _chmod (path
, 0666);
6135 memset (tmp_path
, 0, sizeof (tmp_path
));
6136 strcpy (tmp_path
, path
);
6138 memset (&file_op
, 0, sizeof (file_op
));
6139 file_op
.hwnd
= HWND_DESKTOP
;
6140 file_op
.wFunc
= FO_DELETE
;
6141 file_op
.pFrom
= tmp_path
;
6142 file_op
.fFlags
= FOF_SILENT
| FOF_NOCONFIRMATION
| FOF_ALLOWUNDO
6143 | FOF_NOERRORUI
| FOF_NO_CONNECTED_ELEMENTS
;
6144 file_op
.fAnyOperationsAborted
= FALSE
;
6146 if (SHFileOperation (&file_op
) != 0)
6147 report_file_error ("Removing old name", list1 (filename
));
6153 /***********************************************************************
6154 w32 specialized functions
6155 ***********************************************************************/
6157 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
,
6158 Sw32_send_sys_command
, 1, 2, 0,
6159 doc
: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND.
6160 Some useful values for COMMAND are #xf030 to maximize frame (#xf020
6161 to minimize), #xf120 to restore frame to original size, and #xf100
6162 to activate the menubar for keyboard access. #xf140 activates the
6163 screen saver if defined.
6165 If optional parameter FRAME is not specified, use selected frame. */)
6166 (Lisp_Object command
, Lisp_Object frame
)
6168 FRAME_PTR f
= check_x_frame (frame
);
6170 CHECK_NUMBER (command
);
6172 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
6177 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
6178 doc
: /* Get Windows to perform OPERATION on DOCUMENT.
6179 This is a wrapper around the ShellExecute system function, which
6180 invokes the application registered to handle OPERATION for DOCUMENT.
6182 OPERATION is either nil or a string that names a supported operation.
6183 What operations can be used depends on the particular DOCUMENT and its
6184 handler application, but typically it is one of the following common
6187 \"open\" - open DOCUMENT, which could be a file, a directory, or an
6188 executable program. If it is an application, that
6189 application is launched in the current buffer's default
6190 directory. Otherwise, the application associated with
6191 DOCUMENT is launched in the buffer's default directory.
6192 \"print\" - print DOCUMENT, which must be a file
6193 \"explore\" - start the Windows Explorer on DOCUMENT
6194 \"edit\" - launch an editor and open DOCUMENT for editing; which
6195 editor is launched depends on the association for the
6197 \"find\" - initiate search starting from DOCUMENT which must specify
6199 nil - invoke the default OPERATION, or \"open\" if default is
6200 not defined or unavailable
6202 DOCUMENT is typically the name of a document file or a URL, but can
6203 also be a program executable to run, or a directory to open in the
6206 If DOCUMENT is a program executable, the optional third arg PARAMETERS
6207 can be a string containing command line parameters that will be passed
6208 to the program; otherwise, PARAMETERS should be nil or unspecified.
6210 Optional fourth argument SHOW-FLAG can be used to control how the
6211 application will be displayed when it is invoked. If SHOW-FLAG is nil
6212 or unspecified, the application is displayed normally, otherwise it is
6213 an integer representing a ShowWindow flag:
6218 6 - start minimized */)
6219 (Lisp_Object operation
, Lisp_Object document
, Lisp_Object parameters
, Lisp_Object show_flag
)
6221 Lisp_Object current_dir
;
6224 CHECK_STRING (document
);
6226 /* Encode filename, current directory and parameters. */
6227 current_dir
= ENCODE_FILE (current_buffer
->directory
);
6228 document
= ENCODE_FILE (document
);
6229 if (STRINGP (parameters
))
6230 parameters
= ENCODE_SYSTEM (parameters
);
6232 if ((int) ShellExecute (NULL
,
6233 (STRINGP (operation
) ?
6234 SDATA (operation
) : NULL
),
6236 (STRINGP (parameters
) ?
6237 SDATA (parameters
) : NULL
),
6238 SDATA (current_dir
),
6239 (INTEGERP (show_flag
) ?
6240 XINT (show_flag
) : SW_SHOWDEFAULT
))
6243 errstr
= w32_strerror (0);
6244 /* The error string might be encoded in the locale's encoding. */
6245 if (!NILP (Vlocale_coding_system
))
6247 Lisp_Object decoded
=
6248 code_convert_string_norecord (make_unibyte_string (errstr
,
6250 Vlocale_coding_system
, 0);
6251 errstr
= (char *)SDATA (decoded
);
6253 error ("ShellExecute failed: %s", errstr
);
6256 /* Lookup virtual keycode from string representing the name of a
6257 non-ascii keystroke into the corresponding virtual key, using
6258 lispy_function_keys. */
6260 lookup_vk_code (char *key
)
6264 for (i
= 0; i
< 256; i
++)
6265 if (lispy_function_keys
[i
]
6266 && strcmp (lispy_function_keys
[i
], key
) == 0)
6272 /* Convert a one-element vector style key sequence to a hot key
6275 w32_parse_hot_key (Lisp_Object key
)
6277 /* Copied from Fdefine_key and store_in_keymap. */
6278 register Lisp_Object c
;
6282 struct gcpro gcpro1
;
6286 if (XFASTINT (Flength (key
)) != 1)
6291 c
= Faref (key
, make_number (0));
6293 if (CONSP (c
) && lucid_event_type_list_p (c
))
6294 c
= Fevent_convert_list (c
);
6298 if (! INTEGERP (c
) && ! SYMBOLP (c
))
6299 error ("Key definition is invalid");
6301 /* Work out the base key and the modifiers. */
6304 c
= parse_modifiers (c
);
6305 lisp_modifiers
= XINT (Fcar (Fcdr (c
)));
6309 vk_code
= lookup_vk_code (SDATA (SYMBOL_NAME (c
)));
6311 else if (INTEGERP (c
))
6313 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
6314 /* Many ascii characters are their own virtual key code. */
6315 vk_code
= XINT (c
) & CHARACTERBITS
;
6318 if (vk_code
< 0 || vk_code
> 255)
6321 if ((lisp_modifiers
& meta_modifier
) != 0
6322 && !NILP (Vw32_alt_is_meta
))
6323 lisp_modifiers
|= alt_modifier
;
6325 /* Supply defs missing from mingw32. */
6327 #define MOD_ALT 0x0001
6328 #define MOD_CONTROL 0x0002
6329 #define MOD_SHIFT 0x0004
6330 #define MOD_WIN 0x0008
6333 /* Convert lisp modifiers to Windows hot-key form. */
6334 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
6335 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
6336 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
6337 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
6339 return HOTKEY (vk_code
, w32_modifiers
);
6342 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
,
6343 Sw32_register_hot_key
, 1, 1, 0,
6344 doc
: /* Register KEY as a hot-key combination.
6345 Certain key combinations like Alt-Tab are reserved for system use on
6346 Windows, and therefore are normally intercepted by the system. However,
6347 most of these key combinations can be received by registering them as
6348 hot-keys, overriding their special meaning.
6350 KEY must be a one element key definition in vector form that would be
6351 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta
6352 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper
6353 is always interpreted as the Windows modifier keys.
6355 The return value is the hotkey-id if registered, otherwise nil. */)
6358 key
= w32_parse_hot_key (key
);
6360 if (!NILP (key
) && NILP (Fmemq (key
, w32_grabbed_keys
)))
6362 /* Reuse an empty slot if possible. */
6363 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
6365 /* Safe to add new key to list, even if we have focus. */
6367 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
6369 XSETCAR (item
, key
);
6371 /* Notify input thread about new hot-key definition, so that it
6372 takes effect without needing to switch focus. */
6373 #ifdef USE_LISP_UNION_TYPE
6374 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
6377 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
6385 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
,
6386 Sw32_unregister_hot_key
, 1, 1, 0,
6387 doc
: /* Unregister KEY as a hot-key combination. */)
6392 if (!INTEGERP (key
))
6393 key
= w32_parse_hot_key (key
);
6395 item
= Fmemq (key
, w32_grabbed_keys
);
6399 /* Notify input thread about hot-key definition being removed, so
6400 that it takes effect without needing focus switch. */
6401 #ifdef USE_LISP_UNION_TYPE
6402 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
6403 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
.i
))
6405 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
6406 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
))
6410 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
6417 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
,
6418 Sw32_registered_hot_keys
, 0, 0, 0,
6419 doc
: /* Return list of registered hot-key IDs. */)
6422 return Fdelq (Qnil
, Fcopy_sequence (w32_grabbed_keys
));
6425 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
,
6426 Sw32_reconstruct_hot_key
, 1, 1, 0,
6427 doc
: /* Convert hot-key ID to a lisp key combination.
6428 usage: (w32-reconstruct-hot-key ID) */)
6429 (Lisp_Object hotkeyid
)
6431 int vk_code
, w32_modifiers
;
6434 CHECK_NUMBER (hotkeyid
);
6436 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
6437 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
6439 if (vk_code
< 256 && lispy_function_keys
[vk_code
])
6440 key
= intern (lispy_function_keys
[vk_code
]);
6442 key
= make_number (vk_code
);
6444 key
= Fcons (key
, Qnil
);
6445 if (w32_modifiers
& MOD_SHIFT
)
6446 key
= Fcons (Qshift
, key
);
6447 if (w32_modifiers
& MOD_CONTROL
)
6448 key
= Fcons (Qctrl
, key
);
6449 if (w32_modifiers
& MOD_ALT
)
6450 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
6451 if (w32_modifiers
& MOD_WIN
)
6452 key
= Fcons (Qhyper
, key
);
6457 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
,
6458 Sw32_toggle_lock_key
, 1, 2, 0,
6459 doc
: /* Toggle the state of the lock key KEY.
6460 KEY can be `capslock', `kp-numlock', or `scroll'.
6461 If the optional parameter NEW-STATE is a number, then the state of KEY
6462 is set to off if the low bit of NEW-STATE is zero, otherwise on. */)
6463 (Lisp_Object key
, Lisp_Object new_state
)
6467 if (EQ (key
, intern ("capslock")))
6468 vk_code
= VK_CAPITAL
;
6469 else if (EQ (key
, intern ("kp-numlock")))
6470 vk_code
= VK_NUMLOCK
;
6471 else if (EQ (key
, intern ("scroll")))
6472 vk_code
= VK_SCROLL
;
6476 if (!dwWindowsThreadId
)
6477 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
6479 #ifdef USE_LISP_UNION_TYPE
6480 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
6481 (WPARAM
) vk_code
, (LPARAM
) new_state
.i
))
6483 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
6484 (WPARAM
) vk_code
, (LPARAM
) new_state
))
6488 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
6489 return make_number (msg
.wParam
);
6494 DEFUN ("w32-window-exists-p", Fw32_window_exists_p
, Sw32_window_exists_p
,
6496 doc
: /* Return non-nil if a window exists with the specified CLASS and NAME.
6498 This is a direct interface to the Windows API FindWindow function. */)
6499 (Lisp_Object
class, Lisp_Object name
)
6504 CHECK_STRING (class);
6506 CHECK_STRING (name
);
6508 hnd
= FindWindow (STRINGP (class) ? ((LPCTSTR
) SDATA (class)) : NULL
,
6509 STRINGP (name
) ? ((LPCTSTR
) SDATA (name
)) : NULL
);
6515 DEFUN ("w32-battery-status", Fw32_battery_status
, Sw32_battery_status
, 0, 0, 0,
6516 doc
: /* Get power status information from Windows system.
6518 The following %-sequences are provided:
6519 %L AC line status (verbose)
6520 %B Battery status (verbose)
6521 %b Battery status, empty means high, `-' means low,
6522 `!' means critical, and `+' means charging
6523 %p Battery load percentage
6524 %s Remaining time (to charge or discharge) in seconds
6525 %m Remaining time (to charge or discharge) in minutes
6526 %h Remaining time (to charge or discharge) in hours
6527 %t Remaining time (to charge or discharge) in the form `h:min' */)
6530 Lisp_Object status
= Qnil
;
6532 SYSTEM_POWER_STATUS system_status
;
6533 if (GetSystemPowerStatus (&system_status
))
6535 Lisp_Object line_status
, battery_status
, battery_status_symbol
;
6536 Lisp_Object load_percentage
, seconds
, minutes
, hours
, remain
;
6537 Lisp_Object sequences
[8];
6539 long seconds_left
= (long) system_status
.BatteryLifeTime
;
6541 if (system_status
.ACLineStatus
== 0)
6542 line_status
= build_string ("off-line");
6543 else if (system_status
.ACLineStatus
== 1)
6544 line_status
= build_string ("on-line");
6546 line_status
= build_string ("N/A");
6548 if (system_status
.BatteryFlag
& 128)
6550 battery_status
= build_string ("N/A");
6551 battery_status_symbol
= empty_unibyte_string
;
6553 else if (system_status
.BatteryFlag
& 8)
6555 battery_status
= build_string ("charging");
6556 battery_status_symbol
= build_string ("+");
6557 if (system_status
.BatteryFullLifeTime
!= -1L)
6558 seconds_left
= system_status
.BatteryFullLifeTime
- seconds_left
;
6560 else if (system_status
.BatteryFlag
& 4)
6562 battery_status
= build_string ("critical");
6563 battery_status_symbol
= build_string ("!");
6565 else if (system_status
.BatteryFlag
& 2)
6567 battery_status
= build_string ("low");
6568 battery_status_symbol
= build_string ("-");
6570 else if (system_status
.BatteryFlag
& 1)
6572 battery_status
= build_string ("high");
6573 battery_status_symbol
= empty_unibyte_string
;
6577 battery_status
= build_string ("medium");
6578 battery_status_symbol
= empty_unibyte_string
;
6581 if (system_status
.BatteryLifePercent
> 100)
6582 load_percentage
= build_string ("N/A");
6586 _snprintf (buffer
, 16, "%d", system_status
.BatteryLifePercent
);
6587 load_percentage
= build_string (buffer
);
6590 if (seconds_left
< 0)
6591 seconds
= minutes
= hours
= remain
= build_string ("N/A");
6597 _snprintf (buffer
, 16, "%ld", seconds_left
);
6598 seconds
= build_string (buffer
);
6600 m
= seconds_left
/ 60;
6601 _snprintf (buffer
, 16, "%ld", m
);
6602 minutes
= build_string (buffer
);
6604 h
= seconds_left
/ 3600.0;
6605 _snprintf (buffer
, 16, "%3.1f", h
);
6606 hours
= build_string (buffer
);
6608 _snprintf (buffer
, 16, "%ld:%02ld", m
/ 60, m
% 60);
6609 remain
= build_string (buffer
);
6611 sequences
[0] = Fcons (make_number ('L'), line_status
);
6612 sequences
[1] = Fcons (make_number ('B'), battery_status
);
6613 sequences
[2] = Fcons (make_number ('b'), battery_status_symbol
);
6614 sequences
[3] = Fcons (make_number ('p'), load_percentage
);
6615 sequences
[4] = Fcons (make_number ('s'), seconds
);
6616 sequences
[5] = Fcons (make_number ('m'), minutes
);
6617 sequences
[6] = Fcons (make_number ('h'), hours
);
6618 sequences
[7] = Fcons (make_number ('t'), remain
);
6620 status
= Flist (8, sequences
);
6626 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
6627 doc
: /* Return storage information about the file system FILENAME is on.
6628 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
6629 storage of the file system, FREE is the free storage, and AVAIL is the
6630 storage available to a non-superuser. All 3 numbers are in bytes.
6631 If the underlying system call fails, value is nil. */)
6632 (Lisp_Object filename
)
6634 Lisp_Object encoded
, value
;
6636 CHECK_STRING (filename
);
6637 filename
= Fexpand_file_name (filename
, Qnil
);
6638 encoded
= ENCODE_FILE (filename
);
6642 /* Determining the required information on Windows turns out, sadly,
6643 to be more involved than one would hope. The original Win32 api
6644 call for this will return bogus information on some systems, but we
6645 must dynamically probe for the replacement api, since that was
6646 added rather late on. */
6648 HMODULE hKernel
= GetModuleHandle ("kernel32");
6649 BOOL (*pfn_GetDiskFreeSpaceEx
)
6650 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
6651 = (void *) GetProcAddress (hKernel
, "GetDiskFreeSpaceEx");
6653 /* On Windows, we may need to specify the root directory of the
6654 volume holding FILENAME. */
6655 char rootname
[MAX_PATH
];
6656 char *name
= SDATA (encoded
);
6658 /* find the root name of the volume if given */
6659 if (isalpha (name
[0]) && name
[1] == ':')
6661 rootname
[0] = name
[0];
6662 rootname
[1] = name
[1];
6666 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
6668 char *str
= rootname
;
6672 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
6682 if (pfn_GetDiskFreeSpaceEx
)
6684 /* Unsigned large integers cannot be cast to double, so
6685 use signed ones instead. */
6686 LARGE_INTEGER availbytes
;
6687 LARGE_INTEGER freebytes
;
6688 LARGE_INTEGER totalbytes
;
6690 if (pfn_GetDiskFreeSpaceEx (rootname
,
6691 (ULARGE_INTEGER
*)&availbytes
,
6692 (ULARGE_INTEGER
*)&totalbytes
,
6693 (ULARGE_INTEGER
*)&freebytes
))
6694 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
6695 make_float ((double) freebytes
.QuadPart
),
6696 make_float ((double) availbytes
.QuadPart
));
6700 DWORD sectors_per_cluster
;
6701 DWORD bytes_per_sector
;
6702 DWORD free_clusters
;
6703 DWORD total_clusters
;
6705 if (GetDiskFreeSpace (rootname
,
6706 §ors_per_cluster
,
6710 value
= list3 (make_float ((double) total_clusters
6711 * sectors_per_cluster
* bytes_per_sector
),
6712 make_float ((double) free_clusters
6713 * sectors_per_cluster
* bytes_per_sector
),
6714 make_float ((double) free_clusters
6715 * sectors_per_cluster
* bytes_per_sector
));
6722 DEFUN ("default-printer-name", Fdefault_printer_name
, Sdefault_printer_name
,
6723 0, 0, 0, doc
: /* Return the name of Windows default printer device. */)
6726 static char pname_buf
[256];
6729 PRINTER_INFO_2
*ppi2
= NULL
;
6730 DWORD dwNeeded
= 0, dwReturned
= 0;
6732 /* Retrieve the default string from Win.ini (the registry).
6733 * String will be in form "printername,drivername,portname".
6734 * This is the most portable way to get the default printer. */
6735 if (GetProfileString ("windows", "device", ",,", pname_buf
, sizeof (pname_buf
)) <= 0)
6737 /* printername precedes first "," character */
6738 strtok (pname_buf
, ",");
6739 /* We want to know more than the printer name */
6740 if (!OpenPrinter (pname_buf
, &hPrn
, NULL
))
6742 GetPrinter (hPrn
, 2, NULL
, 0, &dwNeeded
);
6745 ClosePrinter (hPrn
);
6748 /* Allocate memory for the PRINTER_INFO_2 struct */
6749 ppi2
= (PRINTER_INFO_2
*) xmalloc (dwNeeded
);
6752 ClosePrinter (hPrn
);
6755 /* Call GetPrinter again with big enouth memory block */
6756 err
= GetPrinter (hPrn
, 2, (LPBYTE
)ppi2
, dwNeeded
, &dwReturned
);
6757 ClosePrinter (hPrn
);
6766 if (ppi2
->Attributes
& PRINTER_ATTRIBUTE_SHARED
&& ppi2
->pServerName
)
6768 /* a remote printer */
6769 if (*ppi2
->pServerName
== '\\')
6770 _snprintf (pname_buf
, sizeof (pname_buf
), "%s\\%s", ppi2
->pServerName
,
6773 _snprintf (pname_buf
, sizeof (pname_buf
), "\\\\%s\\%s", ppi2
->pServerName
,
6775 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
6779 /* a local printer */
6780 strncpy (pname_buf
, ppi2
->pPortName
, sizeof (pname_buf
));
6781 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
6782 /* `pPortName' can include several ports, delimited by ','.
6783 * we only use the first one. */
6784 strtok (pname_buf
, ",");
6789 return build_string (pname_buf
);
6792 /***********************************************************************
6794 ***********************************************************************/
6796 /* Keep this list in the same order as frame_parms in frame.c.
6797 Use 0 for unsupported frame parameters. */
6799 frame_parm_handler w32_frame_parm_handlers
[] =
6803 x_set_background_color
,
6809 x_set_foreground_color
,
6812 x_set_internal_border_width
,
6813 x_set_menu_bar_lines
,
6815 x_explicitly_set_name
,
6816 x_set_scroll_bar_width
,
6819 x_set_vertical_scroll_bars
,
6821 x_set_tool_bar_lines
,
6822 0, /* x_set_scroll_bar_foreground, */
6823 0, /* x_set_scroll_bar_background, */
6828 0, /* x_set_wait_for_wm, */
6832 0, /* x_set_sticky */
6836 syms_of_w32fns (void)
6838 globals_of_w32fns ();
6839 /* This is zero if not using MS-Windows. */
6841 track_mouse_window
= NULL
;
6843 w32_visible_system_caret_hwnd
= NULL
;
6845 DEFSYM (Qnone
, "none");
6846 DEFSYM (Qsuppress_icon
, "suppress-icon");
6847 DEFSYM (Qundefined_color
, "undefined-color");
6848 DEFSYM (Qcancel_timer
, "cancel-timer");
6849 DEFSYM (Qhyper
, "hyper");
6850 DEFSYM (Qsuper
, "super");
6851 DEFSYM (Qmeta
, "meta");
6852 DEFSYM (Qalt
, "alt");
6853 DEFSYM (Qctrl
, "ctrl");
6854 DEFSYM (Qcontrol
, "control");
6855 DEFSYM (Qshift
, "shift");
6856 DEFSYM (Qfont_param
, "font-parameter");
6857 /* This is the end of symbol initialization. */
6859 /* Text property `display' should be nonsticky by default. */
6860 Vtext_property_default_nonsticky
6861 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
6864 Fput (Qundefined_color
, Qerror_conditions
,
6865 pure_cons (Qundefined_color
, pure_cons (Qerror
, Qnil
)));
6866 Fput (Qundefined_color
, Qerror_message
,
6867 make_pure_c_string ("Undefined color"));
6869 staticpro (&w32_grabbed_keys
);
6870 w32_grabbed_keys
= Qnil
;
6872 DEFVAR_LISP ("w32-color-map", &Vw32_color_map
,
6873 doc
: /* An array of color name mappings for Windows. */);
6874 Vw32_color_map
= Qnil
;
6876 DEFVAR_LISP ("w32-pass-alt-to-system", &Vw32_pass_alt_to_system
,
6877 doc
: /* Non-nil if Alt key presses are passed on to Windows.
6878 When non-nil, for example, Alt pressed and released and then space will
6879 open the System menu. When nil, Emacs processes the Alt key events, and
6880 then silently swallows them. */);
6881 Vw32_pass_alt_to_system
= Qnil
;
6883 DEFVAR_LISP ("w32-alt-is-meta", &Vw32_alt_is_meta
,
6884 doc
: /* Non-nil if the Alt key is to be considered the same as the META key.
6885 When nil, Emacs will translate the Alt key to the ALT modifier, not to META. */);
6886 Vw32_alt_is_meta
= Qt
;
6888 DEFVAR_INT ("w32-quit-key", &w32_quit_key
,
6889 doc
: /* If non-zero, the virtual key code for an alternative quit key. */);
6892 DEFVAR_LISP ("w32-pass-lwindow-to-system",
6893 &Vw32_pass_lwindow_to_system
,
6894 doc
: /* If non-nil, the left \"Windows\" key is passed on to Windows.
6896 When non-nil, the Start menu is opened by tapping the key.
6897 If you set this to nil, the left \"Windows\" key is processed by Emacs
6898 according to the value of `w32-lwindow-modifier', which see.
6900 Note that some combinations of the left \"Windows\" key with other keys are
6901 caught by Windows at low level, and so binding them in Emacs will have no
6902 effect. For example, <lwindow>-r always pops up the Windows Run dialog,
6903 <lwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
6904 the doc string of `w32-phantom-key-code'. */);
6905 Vw32_pass_lwindow_to_system
= Qt
;
6907 DEFVAR_LISP ("w32-pass-rwindow-to-system",
6908 &Vw32_pass_rwindow_to_system
,
6909 doc
: /* If non-nil, the right \"Windows\" key is passed on to Windows.
6911 When non-nil, the Start menu is opened by tapping the key.
6912 If you set this to nil, the right \"Windows\" key is processed by Emacs
6913 according to the value of `w32-rwindow-modifier', which see.
6915 Note that some combinations of the right \"Windows\" key with other keys are
6916 caught by Windows at low level, and so binding them in Emacs will have no
6917 effect. For example, <rwindow>-r always pops up the Windows Run dialog,
6918 <rwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
6919 the doc string of `w32-phantom-key-code'. */);
6920 Vw32_pass_rwindow_to_system
= Qt
;
6922 DEFVAR_LISP ("w32-phantom-key-code",
6923 &Vw32_phantom_key_code
,
6924 doc
: /* Virtual key code used to generate \"phantom\" key presses.
6925 Value is a number between 0 and 255.
6927 Phantom key presses are generated in order to stop the system from
6928 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or
6929 `w32-pass-rwindow-to-system' is nil. */);
6930 /* Although 255 is technically not a valid key code, it works and
6931 means that this hack won't interfere with any real key code. */
6932 XSETINT (Vw32_phantom_key_code
, 255);
6934 DEFVAR_LISP ("w32-enable-num-lock",
6935 &Vw32_enable_num_lock
,
6936 doc
: /* If non-nil, the Num Lock key acts normally.
6937 Set to nil to handle Num Lock as the `kp-numlock' key. */);
6938 Vw32_enable_num_lock
= Qt
;
6940 DEFVAR_LISP ("w32-enable-caps-lock",
6941 &Vw32_enable_caps_lock
,
6942 doc
: /* If non-nil, the Caps Lock key acts normally.
6943 Set to nil to handle Caps Lock as the `capslock' key. */);
6944 Vw32_enable_caps_lock
= Qt
;
6946 DEFVAR_LISP ("w32-scroll-lock-modifier",
6947 &Vw32_scroll_lock_modifier
,
6948 doc
: /* Modifier to use for the Scroll Lock ON state.
6949 The value can be hyper, super, meta, alt, control or shift for the
6950 respective modifier, or nil to handle Scroll Lock as the `scroll' key.
6951 Any other value will cause the Scroll Lock key to be ignored. */);
6952 Vw32_scroll_lock_modifier
= Qnil
;
6954 DEFVAR_LISP ("w32-lwindow-modifier",
6955 &Vw32_lwindow_modifier
,
6956 doc
: /* Modifier to use for the left \"Windows\" key.
6957 The value can be hyper, super, meta, alt, control or shift for the
6958 respective modifier, or nil to appear as the `lwindow' key.
6959 Any other value will cause the key to be ignored. */);
6960 Vw32_lwindow_modifier
= Qnil
;
6962 DEFVAR_LISP ("w32-rwindow-modifier",
6963 &Vw32_rwindow_modifier
,
6964 doc
: /* Modifier to use for the right \"Windows\" key.
6965 The value can be hyper, super, meta, alt, control or shift for the
6966 respective modifier, or nil to appear as the `rwindow' key.
6967 Any other value will cause the key to be ignored. */);
6968 Vw32_rwindow_modifier
= Qnil
;
6970 DEFVAR_LISP ("w32-apps-modifier",
6971 &Vw32_apps_modifier
,
6972 doc
: /* Modifier to use for the \"Apps\" key.
6973 The value can be hyper, super, meta, alt, control or shift for the
6974 respective modifier, or nil to appear as the `apps' key.
6975 Any other value will cause the key to be ignored. */);
6976 Vw32_apps_modifier
= Qnil
;
6978 DEFVAR_BOOL ("w32-enable-synthesized-fonts", &w32_enable_synthesized_fonts
,
6979 doc
: /* Non-nil enables selection of artificially italicized and bold fonts. */);
6980 w32_enable_synthesized_fonts
= 0;
6982 DEFVAR_LISP ("w32-enable-palette", &Vw32_enable_palette
,
6983 doc
: /* Non-nil enables Windows palette management to map colors exactly. */);
6984 Vw32_enable_palette
= Qt
;
6986 DEFVAR_INT ("w32-mouse-button-tolerance",
6987 &w32_mouse_button_tolerance
,
6988 doc
: /* Analogue of double click interval for faking middle mouse events.
6989 The value is the minimum time in milliseconds that must elapse between
6990 left and right button down events before they are considered distinct events.
6991 If both mouse buttons are depressed within this interval, a middle mouse
6992 button down event is generated instead. */);
6993 w32_mouse_button_tolerance
= GetDoubleClickTime () / 2;
6995 DEFVAR_INT ("w32-mouse-move-interval",
6996 &w32_mouse_move_interval
,
6997 doc
: /* Minimum interval between mouse move events.
6998 The value is the minimum time in milliseconds that must elapse between
6999 successive mouse move (or scroll bar drag) events before they are
7000 reported as lisp events. */);
7001 w32_mouse_move_interval
= 0;
7003 DEFVAR_BOOL ("w32-pass-extra-mouse-buttons-to-system",
7004 &w32_pass_extra_mouse_buttons_to_system
,
7005 doc
: /* If non-nil, the fourth and fifth mouse buttons are passed to Windows.
7006 Recent versions of Windows support mice with up to five buttons.
7007 Since most applications don't support these extra buttons, most mouse
7008 drivers will allow you to map them to functions at the system level.
7009 If this variable is non-nil, Emacs will pass them on, allowing the
7010 system to handle them. */);
7011 w32_pass_extra_mouse_buttons_to_system
= 0;
7013 DEFVAR_BOOL ("w32-pass-multimedia-buttons-to-system",
7014 &w32_pass_multimedia_buttons_to_system
,
7015 doc
: /* If non-nil, media buttons are passed to Windows.
7016 Some modern keyboards contain buttons for controlling media players, web
7017 browsers and other applications. Generally these buttons are handled on a
7018 system wide basis, but by setting this to nil they are made available
7019 to Emacs for binding. Depending on your keyboard, additional keys that
7020 may be available are:
7022 browser-back, browser-forward, browser-refresh, browser-stop,
7023 browser-search, browser-favorites, browser-home,
7024 mail, mail-reply, mail-forward, mail-send,
7026 help, find, new, open, close, save, print, undo, redo, copy, cut, paste,
7027 spell-check, correction-list, toggle-dictate-command,
7028 media-next, media-previous, media-stop, media-play-pause, media-select,
7029 media-play, media-pause, media-record, media-fast-forward, media-rewind,
7030 media-channel-up, media-channel-down,
7031 volume-mute, volume-up, volume-down,
7032 mic-volume-mute, mic-volume-down, mic-volume-up, mic-toggle,
7033 bass-down, bass-boost, bass-up, treble-down, treble-up */);
7034 w32_pass_multimedia_buttons_to_system
= 1;
7036 #if 0 /* TODO: Mouse cursor customization. */
7037 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
7038 doc
: /* The shape of the pointer when over text.
7039 Changing the value does not affect existing frames
7040 unless you set the mouse color. */);
7041 Vx_pointer_shape
= Qnil
;
7043 Vx_nontext_pointer_shape
= Qnil
;
7045 Vx_mode_pointer_shape
= Qnil
;
7047 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
7048 doc
: /* The shape of the pointer when Emacs is busy.
7049 This variable takes effect when you create a new frame
7050 or when you set the mouse color. */);
7051 Vx_hourglass_pointer_shape
= Qnil
;
7053 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
7054 &Vx_sensitive_text_pointer_shape
,
7055 doc
: /* The shape of the pointer when over mouse-sensitive text.
7056 This variable takes effect when you create a new frame
7057 or when you set the mouse color. */);
7058 Vx_sensitive_text_pointer_shape
= Qnil
;
7060 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
7061 &Vx_window_horizontal_drag_shape
,
7062 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
7063 This variable takes effect when you create a new frame
7064 or when you set the mouse color. */);
7065 Vx_window_horizontal_drag_shape
= Qnil
;
7068 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
7069 doc
: /* A string indicating the foreground color of the cursor box. */);
7070 Vx_cursor_fore_pixel
= Qnil
;
7072 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size
,
7073 doc
: /* Maximum size for tooltips.
7074 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
7075 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
7077 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
7078 doc
: /* Non-nil if no window manager is in use.
7079 Emacs doesn't try to figure this out; this is always nil
7080 unless you set it to something else. */);
7081 /* We don't have any way to find this out, so set it to nil
7082 and maybe the user would like to set it to t. */
7083 Vx_no_window_manager
= Qnil
;
7085 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
7086 &Vx_pixel_size_width_font_regexp
,
7087 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
7089 Since Emacs gets width of a font matching with this regexp from
7090 PIXEL_SIZE field of the name, font finding mechanism gets faster for
7091 such a font. This is especially effective for such large fonts as
7092 Chinese, Japanese, and Korean. */);
7093 Vx_pixel_size_width_font_regexp
= Qnil
;
7095 DEFVAR_LISP ("w32-bdf-filename-alist",
7096 &Vw32_bdf_filename_alist
,
7097 doc
: /* List of bdf fonts and their corresponding filenames. */);
7098 Vw32_bdf_filename_alist
= Qnil
;
7100 DEFVAR_BOOL ("w32-strict-fontnames",
7101 &w32_strict_fontnames
,
7102 doc
: /* Non-nil means only use fonts that are exact matches for those requested.
7103 Default is nil, which allows old fontnames that are not XLFD compliant,
7104 and allows third-party CJK display to work by specifying false charset
7105 fields to trick Emacs into translating to Big5, SJIS etc.
7106 Setting this to t will prevent wrong fonts being selected when
7107 fontsets are automatically created. */);
7108 w32_strict_fontnames
= 0;
7110 DEFVAR_BOOL ("w32-strict-painting",
7111 &w32_strict_painting
,
7112 doc
: /* Non-nil means use strict rules for repainting frames.
7113 Set this to nil to get the old behavior for repainting; this should
7114 only be necessary if the default setting causes problems. */);
7115 w32_strict_painting
= 1;
7117 #if 0 /* TODO: Port to W32 */
7118 defsubr (&Sx_change_window_property
);
7119 defsubr (&Sx_delete_window_property
);
7120 defsubr (&Sx_window_property
);
7122 defsubr (&Sxw_display_color_p
);
7123 defsubr (&Sx_display_grayscale_p
);
7124 defsubr (&Sxw_color_defined_p
);
7125 defsubr (&Sxw_color_values
);
7126 defsubr (&Sx_server_max_request_size
);
7127 defsubr (&Sx_server_vendor
);
7128 defsubr (&Sx_server_version
);
7129 defsubr (&Sx_display_pixel_width
);
7130 defsubr (&Sx_display_pixel_height
);
7131 defsubr (&Sx_display_mm_width
);
7132 defsubr (&Sx_display_mm_height
);
7133 defsubr (&Sx_display_screens
);
7134 defsubr (&Sx_display_planes
);
7135 defsubr (&Sx_display_color_cells
);
7136 defsubr (&Sx_display_visual_class
);
7137 defsubr (&Sx_display_backing_store
);
7138 defsubr (&Sx_display_save_under
);
7139 defsubr (&Sx_create_frame
);
7140 defsubr (&Sx_open_connection
);
7141 defsubr (&Sx_close_connection
);
7142 defsubr (&Sx_display_list
);
7143 defsubr (&Sx_synchronize
);
7144 defsubr (&Sx_focus_frame
);
7146 /* W32 specific functions */
7148 defsubr (&Sw32_define_rgb_color
);
7149 defsubr (&Sw32_default_color_map
);
7150 defsubr (&Sw32_send_sys_command
);
7151 defsubr (&Sw32_shell_execute
);
7152 defsubr (&Sw32_register_hot_key
);
7153 defsubr (&Sw32_unregister_hot_key
);
7154 defsubr (&Sw32_registered_hot_keys
);
7155 defsubr (&Sw32_reconstruct_hot_key
);
7156 defsubr (&Sw32_toggle_lock_key
);
7157 defsubr (&Sw32_window_exists_p
);
7158 defsubr (&Sw32_battery_status
);
7160 defsubr (&Sfile_system_info
);
7161 defsubr (&Sdefault_printer_name
);
7163 check_window_system_func
= check_w32
;
7166 hourglass_timer
= 0;
7167 hourglass_hwnd
= NULL
;
7169 defsubr (&Sx_show_tip
);
7170 defsubr (&Sx_hide_tip
);
7172 staticpro (&tip_timer
);
7174 staticpro (&tip_frame
);
7176 last_show_tip_args
= Qnil
;
7177 staticpro (&last_show_tip_args
);
7179 defsubr (&Sx_file_dialog
);
7180 defsubr (&Ssystem_move_file_to_trash
);
7185 globals_of_w32fns is used to initialize those global variables that
7186 must always be initialized on startup even when the global variable
7187 initialized is non zero (see the function main in emacs.c).
7188 globals_of_w32fns is called from syms_of_w32fns when the global
7189 variable initialized is 0 and directly from main when initialized
7193 globals_of_w32fns (void)
7195 HMODULE user32_lib
= GetModuleHandle ("user32.dll");
7197 TrackMouseEvent not available in all versions of Windows, so must load
7198 it dynamically. Do it once, here, instead of every time it is used.
7200 track_mouse_event_fn
= (TrackMouseEvent_Proc
)
7201 GetProcAddress (user32_lib
, "TrackMouseEvent");
7202 /* ditto for GetClipboardSequenceNumber. */
7203 clipboard_sequence_fn
= (ClipboardSequence_Proc
)
7204 GetProcAddress (user32_lib
, "GetClipboardSequenceNumber");
7206 monitor_from_point_fn
= (MonitorFromPoint_Proc
)
7207 GetProcAddress (user32_lib
, "MonitorFromPoint");
7208 get_monitor_info_fn
= (GetMonitorInfo_Proc
)
7209 GetProcAddress (user32_lib
, "GetMonitorInfoA");
7212 HMODULE imm32_lib
= GetModuleHandle ("imm32.dll");
7213 get_composition_string_fn
= (ImmGetCompositionString_Proc
)
7214 GetProcAddress (imm32_lib
, "ImmGetCompositionStringW");
7215 get_ime_context_fn
= (ImmGetContext_Proc
)
7216 GetProcAddress (imm32_lib
, "ImmGetContext");
7217 release_ime_context_fn
= (ImmReleaseContext_Proc
)
7218 GetProcAddress (imm32_lib
, "ImmReleaseContext");
7219 set_ime_composition_window_fn
= (ImmSetCompositionWindow_Proc
)
7220 GetProcAddress (imm32_lib
, "ImmSetCompositionWindow");
7222 DEFVAR_INT ("w32-ansi-code-page",
7223 &w32_ansi_code_page
,
7224 doc
: /* The ANSI code page used by the system. */);
7225 w32_ansi_code_page
= GetACP ();
7227 /* MessageBox does not work without this when linked to comctl32.dll 6.0. */
7228 InitCommonControls ();
7230 syms_of_w32uniscribe ();
7239 button
= MessageBox (NULL
,
7240 "A fatal error has occurred!\n\n"
7241 "Would you like to attach a debugger?\n\n"
7242 "Select YES to debug, NO to abort Emacs"
7244 "\n\n(type \"gdb -p <emacs-PID>\" and\n"
7245 "\"continue\" inside GDB before clicking YES.)"
7247 , "Emacs Abort Dialog",
7248 MB_ICONEXCLAMATION
| MB_TASKMODAL
7249 | MB_SETFOREGROUND
| MB_YESNO
);
7254 exit (2); /* tell the compiler we will never return */
7262 /* For convenience when debugging. */
7264 w32_last_error (void)
7266 return GetLastError ();
7269 /* arch-tag: 707589ab-b9be-4638-8cdd-74629cc9b446
7270 (do not change this comment) */