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
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 */
36 #include "intervals.h"
37 #include "dispextern.h"
39 #include "blockinput.h"
41 #include "character.h"
47 #include "termhooks.h"
50 #include "bitmaps/gray.xbm"
61 #define FILE_NAME_TEXT_FIELD edt1
66 #ifndef FOF_NO_CONNECTED_ELEMENTS
67 #define FOF_NO_CONNECTED_ELEMENTS 0x2000
70 void syms_of_w32fns ();
71 void globals_of_w32fns ();
73 extern void free_frame_menubar ();
74 extern double atof ();
75 extern int w32_console_toggle_lock_key
P_ ((int, Lisp_Object
));
76 extern void w32_menu_display_help
P_ ((HWND
, HMENU
, UINT
, UINT
));
77 extern void w32_free_menu_strings
P_ ((HWND
));
78 extern const char *map_w32_filename
P_ ((const char *, const char **));
82 extern char *lispy_function_keys
[];
84 /* The colormap for converting color names to RGB values */
85 Lisp_Object Vw32_color_map
;
87 /* Non nil if alt key presses are passed on to Windows. */
88 Lisp_Object Vw32_pass_alt_to_system
;
90 /* Non nil if alt key is translated to meta_modifier, nil if it is translated
92 Lisp_Object Vw32_alt_is_meta
;
94 /* If non-zero, the windows virtual key code for an alternative quit key. */
97 /* Non nil if left window key events are passed on to Windows (this only
98 affects whether "tapping" the key opens the Start menu). */
99 Lisp_Object Vw32_pass_lwindow_to_system
;
101 /* Non nil if right window key events are passed on to Windows (this
102 only affects whether "tapping" the key opens the Start menu). */
103 Lisp_Object Vw32_pass_rwindow_to_system
;
105 /* Virtual key code used to generate "phantom" key presses in order
106 to stop system from acting on Windows key events. */
107 Lisp_Object Vw32_phantom_key_code
;
109 /* Modifier associated with the left "Windows" key, or nil to act as a
111 Lisp_Object Vw32_lwindow_modifier
;
113 /* Modifier associated with the right "Windows" key, or nil to act as a
115 Lisp_Object Vw32_rwindow_modifier
;
117 /* Modifier associated with the "Apps" key, or nil to act as a normal
119 Lisp_Object Vw32_apps_modifier
;
121 /* Value is nil if Num Lock acts as a function key. */
122 Lisp_Object Vw32_enable_num_lock
;
124 /* Value is nil if Caps Lock acts as a function key. */
125 Lisp_Object Vw32_enable_caps_lock
;
127 /* Modifier associated with Scroll Lock, or nil to act as a normal key. */
128 Lisp_Object Vw32_scroll_lock_modifier
;
130 /* Switch to control whether we inhibit requests for synthesized bold
131 and italic versions of fonts. */
132 int w32_enable_synthesized_fonts
;
134 /* Enable palette management. */
135 Lisp_Object Vw32_enable_palette
;
137 /* Control how close left/right button down events must be to
138 be converted to a middle button down event. */
139 int w32_mouse_button_tolerance
;
141 /* Minimum interval between mouse movement (and scroll bar drag)
142 events that are passed on to the event loop. */
143 int w32_mouse_move_interval
;
145 /* Flag to indicate if XBUTTON events should be passed on to Windows. */
146 static int w32_pass_extra_mouse_buttons_to_system
;
148 /* Flag to indicate if media keys should be passed on to Windows. */
149 static int w32_pass_multimedia_buttons_to_system
;
151 /* Non nil if no window manager is in use. */
152 Lisp_Object Vx_no_window_manager
;
154 /* Non-zero means we're allowed to display a hourglass pointer. */
156 int display_hourglass_p
;
158 /* If non-zero, a w32 timer that, when it expires, displays an
159 hourglass cursor on all frames. */
160 static unsigned hourglass_timer
= 0;
161 static HWND hourglass_hwnd
= NULL
;
163 /* The background and shape of the mouse pointer, and shape when not
164 over text or in the modeline. */
166 Lisp_Object Vx_pointer_shape
, Vx_nontext_pointer_shape
, Vx_mode_pointer_shape
;
167 Lisp_Object Vx_hourglass_pointer_shape
, Vx_window_horizontal_drag_shape
;
169 /* The shape when over mouse-sensitive text. */
171 Lisp_Object Vx_sensitive_text_pointer_shape
;
174 #define IDC_HAND MAKEINTRESOURCE(32649)
177 /* Color of chars displayed in cursor box. */
179 Lisp_Object Vx_cursor_fore_pixel
;
181 /* Nonzero if using Windows. */
183 static int w32_in_use
;
185 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
187 Lisp_Object Vx_pixel_size_width_font_regexp
;
189 /* Alist of bdf fonts and the files that define them. */
190 Lisp_Object Vw32_bdf_filename_alist
;
192 /* A flag to control whether fonts are matched strictly or not. */
193 static int w32_strict_fontnames
;
195 /* A flag to control whether we should only repaint if GetUpdateRect
196 indicates there is an update region. */
197 static int w32_strict_painting
;
200 Lisp_Object Qsuppress_icon
;
201 Lisp_Object Qundefined_color
;
202 Lisp_Object Qcancel_timer
;
203 Lisp_Object Qfont_param
;
209 Lisp_Object Qcontrol
;
213 /* The ANSI codepage. */
214 int w32_ansi_code_page
;
216 /* Prefix for system colors. */
217 #define SYSTEM_COLOR_PREFIX "System"
218 #define SYSTEM_COLOR_PREFIX_LEN (sizeof (SYSTEM_COLOR_PREFIX) - 1)
220 /* State variables for emulating a three button mouse. */
225 static int button_state
= 0;
226 static W32Msg saved_mouse_button_msg
;
227 static unsigned mouse_button_timer
= 0; /* non-zero when timer is active */
228 static W32Msg saved_mouse_move_msg
;
229 static unsigned mouse_move_timer
= 0;
231 /* Window that is tracking the mouse. */
232 static HWND track_mouse_window
;
234 /* Multi-monitor API definitions that are not pulled from the headers
235 since we are compiling for NT 4. */
236 #ifndef MONITOR_DEFAULT_TO_NEAREST
237 #define MONITOR_DEFAULT_TO_NEAREST 2
239 /* MinGW headers define MONITORINFO unconditionally, but MSVC ones don't.
240 To avoid a compile error on one or the other, redefine with a new name. */
249 typedef BOOL (WINAPI
* TrackMouseEvent_Proc
)
250 (IN OUT LPTRACKMOUSEEVENT lpEventTrack
);
251 typedef LONG (WINAPI
* ImmGetCompositionString_Proc
)
252 (IN HIMC context
, IN DWORD index
, OUT LPVOID buffer
, IN DWORD bufLen
);
253 typedef HIMC (WINAPI
* ImmGetContext_Proc
) (IN HWND window
);
254 typedef HMONITOR (WINAPI
* MonitorFromPoint_Proc
) (IN POINT pt
, IN DWORD flags
);
255 typedef BOOL (WINAPI
* GetMonitorInfo_Proc
)
256 (IN HMONITOR monitor
, OUT
struct MONITOR_INFO
* info
);
258 TrackMouseEvent_Proc track_mouse_event_fn
= NULL
;
259 ClipboardSequence_Proc clipboard_sequence_fn
= NULL
;
260 ImmGetCompositionString_Proc get_composition_string_fn
= NULL
;
261 ImmGetContext_Proc get_ime_context_fn
= NULL
;
262 MonitorFromPoint_Proc monitor_from_point_fn
= NULL
;
263 GetMonitorInfo_Proc get_monitor_info_fn
= NULL
;
265 extern AppendMenuW_Proc unicode_append_menu
;
267 /* Flag to selectively ignore WM_IME_CHAR messages. */
268 static int ignore_ime_char
= 0;
270 /* W95 mousewheel handler */
271 unsigned int msh_mousewheel
= 0;
274 #define MOUSE_BUTTON_ID 1
275 #define MOUSE_MOVE_ID 2
276 #define MENU_FREE_ID 3
277 #define HOURGLASS_ID 4
278 /* The delay (milliseconds) before a menu is freed after WM_EXITMENULOOP
280 #define MENU_FREE_DELAY 1000
281 static unsigned menu_free_timer
= 0;
283 /* The below are defined in frame.c. */
285 extern Lisp_Object Vwindow_system_version
;
288 int image_cache_refcount
, dpyinfo_refcount
;
292 /* From w32term.c. */
293 extern int w32_num_mouse_buttons
;
294 extern Lisp_Object Vw32_recognize_altgr
;
296 extern HWND w32_system_caret_hwnd
;
298 extern int w32_system_caret_height
;
299 extern int w32_system_caret_x
;
300 extern int w32_system_caret_y
;
301 extern int w32_use_visible_system_caret
;
303 static HWND w32_visible_system_caret_hwnd
;
306 extern HMENU current_popup_menu
;
307 static int menubar_in_use
= 0;
309 /* From w32uniscribe.c */
310 extern void syms_of_w32uniscribe ();
311 extern int uniscribe_available
;
313 /* Function prototypes for hourglass support. */
314 static void show_hourglass
P_ ((struct frame
*));
315 static void hide_hourglass
P_ ((void));
319 /* Error if we are not connected to MS-Windows. */
324 error ("MS-Windows not in use or not initialized");
327 /* Nonzero if we can use mouse menus.
328 You should not call this unless HAVE_MENUS is defined. */
336 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
337 and checking validity for W32. */
340 check_x_frame (frame
)
346 frame
= selected_frame
;
347 CHECK_LIVE_FRAME (frame
);
349 if (! FRAME_W32_P (f
))
350 error ("Non-W32 frame used");
354 /* Let the user specify a display with a frame.
355 nil stands for the selected frame--or, if that is not a w32 frame,
356 the first display on the list. */
358 struct w32_display_info
*
359 check_x_display_info (frame
)
364 struct frame
*sf
= XFRAME (selected_frame
);
366 if (FRAME_W32_P (sf
) && FRAME_LIVE_P (sf
))
367 return FRAME_W32_DISPLAY_INFO (sf
);
369 return &one_w32_display_info
;
371 else if (STRINGP (frame
))
372 return x_display_info_for_name (frame
);
377 CHECK_LIVE_FRAME (frame
);
379 if (! FRAME_W32_P (f
))
380 error ("Non-W32 frame used");
381 return FRAME_W32_DISPLAY_INFO (f
);
385 /* Return the Emacs frame-object corresponding to an w32 window.
386 It could be the frame's main window or an icon window. */
388 /* This function can be called during GC, so use GC_xxx type test macros. */
391 x_window_to_frame (dpyinfo
, wdesc
)
392 struct w32_display_info
*dpyinfo
;
395 Lisp_Object tail
, frame
;
398 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
404 if (!FRAME_W32_P (f
) || FRAME_W32_DISPLAY_INFO (f
) != dpyinfo
)
407 if (FRAME_W32_WINDOW (f
) == wdesc
)
414 static Lisp_Object unwind_create_frame
P_ ((Lisp_Object
));
415 static Lisp_Object unwind_create_tip_frame
P_ ((Lisp_Object
));
416 static void my_create_window
P_ ((struct frame
*));
417 static void my_create_tip_window
P_ ((struct frame
*));
419 /* TODO: Native Input Method support; see x_create_im. */
420 void x_set_foreground_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
421 void x_set_background_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
422 void x_set_mouse_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
423 void x_set_cursor_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
424 void x_set_border_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
425 void x_set_cursor_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
426 void x_set_icon_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
427 void x_set_icon_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
428 void x_explicitly_set_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
429 void x_set_menu_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
430 void x_set_title
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
431 void x_set_tool_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
432 static void x_edge_detection
P_ ((struct frame
*, struct image
*, Lisp_Object
,
438 /* Store the screen positions of frame F into XPTR and YPTR.
439 These are the positions of the containing window manager window,
440 not Emacs's own window. */
443 x_real_positions (f
, xptr
, yptr
)
450 /* Get the bounds of the WM window. */
451 GetWindowRect (FRAME_W32_WINDOW (f
), &rect
);
456 /* Convert (0, 0) in the client area to screen co-ordinates. */
457 ClientToScreen (FRAME_W32_WINDOW (f
), &pt
);
459 /* Remember x_pixels_diff and y_pixels_diff. */
460 f
->x_pixels_diff
= pt
.x
- rect
.left
;
461 f
->y_pixels_diff
= pt
.y
- rect
.top
;
469 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
,
470 Sw32_define_rgb_color
, 4, 4, 0,
471 doc
: /* Convert RGB numbers to a Windows color reference and associate with NAME.
472 This adds or updates a named color to `w32-color-map', making it
473 available for use. The original entry's RGB ref is returned, or nil
474 if the entry is new. */)
475 (red
, green
, blue
, name
)
476 Lisp_Object red
, green
, blue
, name
;
479 Lisp_Object oldrgb
= Qnil
;
483 CHECK_NUMBER (green
);
487 XSETINT (rgb
, RGB (XUINT (red
), XUINT (green
), XUINT (blue
)));
491 /* replace existing entry in w32-color-map or add new entry. */
492 entry
= Fassoc (name
, Vw32_color_map
);
495 entry
= Fcons (name
, rgb
);
496 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
500 oldrgb
= Fcdr (entry
);
501 Fsetcdr (entry
, rgb
);
509 DEFUN ("w32-load-color-file", Fw32_load_color_file
,
510 Sw32_load_color_file
, 1, 1, 0,
511 doc
: /* Create an alist of color entries from an external file.
512 Assign this value to `w32-color-map' to replace the existing color map.
514 The file should define one named RGB color per line like so:
516 where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
518 Lisp_Object filename
;
521 Lisp_Object cmap
= Qnil
;
524 CHECK_STRING (filename
);
525 abspath
= Fexpand_file_name (filename
, Qnil
);
527 fp
= fopen (SDATA (filename
), "rt");
531 int red
, green
, blue
;
536 while (fgets (buf
, sizeof (buf
), fp
) != NULL
) {
537 if (sscanf (buf
, "%u %u %u %n", &red
, &green
, &blue
, &num
) == 3)
539 char *name
= buf
+ num
;
540 num
= strlen (name
) - 1;
541 if (name
[num
] == '\n')
543 cmap
= Fcons (Fcons (build_string (name
),
544 make_number (RGB (red
, green
, blue
))),
556 /* The default colors for the w32 color map */
557 typedef struct colormap_t
563 colormap_t w32_color_map
[] =
565 {"snow" , PALETTERGB (255,250,250)},
566 {"ghost white" , PALETTERGB (248,248,255)},
567 {"GhostWhite" , PALETTERGB (248,248,255)},
568 {"white smoke" , PALETTERGB (245,245,245)},
569 {"WhiteSmoke" , PALETTERGB (245,245,245)},
570 {"gainsboro" , PALETTERGB (220,220,220)},
571 {"floral white" , PALETTERGB (255,250,240)},
572 {"FloralWhite" , PALETTERGB (255,250,240)},
573 {"old lace" , PALETTERGB (253,245,230)},
574 {"OldLace" , PALETTERGB (253,245,230)},
575 {"linen" , PALETTERGB (250,240,230)},
576 {"antique white" , PALETTERGB (250,235,215)},
577 {"AntiqueWhite" , PALETTERGB (250,235,215)},
578 {"papaya whip" , PALETTERGB (255,239,213)},
579 {"PapayaWhip" , PALETTERGB (255,239,213)},
580 {"blanched almond" , PALETTERGB (255,235,205)},
581 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
582 {"bisque" , PALETTERGB (255,228,196)},
583 {"peach puff" , PALETTERGB (255,218,185)},
584 {"PeachPuff" , PALETTERGB (255,218,185)},
585 {"navajo white" , PALETTERGB (255,222,173)},
586 {"NavajoWhite" , PALETTERGB (255,222,173)},
587 {"moccasin" , PALETTERGB (255,228,181)},
588 {"cornsilk" , PALETTERGB (255,248,220)},
589 {"ivory" , PALETTERGB (255,255,240)},
590 {"lemon chiffon" , PALETTERGB (255,250,205)},
591 {"LemonChiffon" , PALETTERGB (255,250,205)},
592 {"seashell" , PALETTERGB (255,245,238)},
593 {"honeydew" , PALETTERGB (240,255,240)},
594 {"mint cream" , PALETTERGB (245,255,250)},
595 {"MintCream" , PALETTERGB (245,255,250)},
596 {"azure" , PALETTERGB (240,255,255)},
597 {"alice blue" , PALETTERGB (240,248,255)},
598 {"AliceBlue" , PALETTERGB (240,248,255)},
599 {"lavender" , PALETTERGB (230,230,250)},
600 {"lavender blush" , PALETTERGB (255,240,245)},
601 {"LavenderBlush" , PALETTERGB (255,240,245)},
602 {"misty rose" , PALETTERGB (255,228,225)},
603 {"MistyRose" , PALETTERGB (255,228,225)},
604 {"white" , PALETTERGB (255,255,255)},
605 {"black" , PALETTERGB ( 0, 0, 0)},
606 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
607 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
608 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
609 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
610 {"dim gray" , PALETTERGB (105,105,105)},
611 {"DimGray" , PALETTERGB (105,105,105)},
612 {"dim grey" , PALETTERGB (105,105,105)},
613 {"DimGrey" , PALETTERGB (105,105,105)},
614 {"slate gray" , PALETTERGB (112,128,144)},
615 {"SlateGray" , PALETTERGB (112,128,144)},
616 {"slate grey" , PALETTERGB (112,128,144)},
617 {"SlateGrey" , PALETTERGB (112,128,144)},
618 {"light slate gray" , PALETTERGB (119,136,153)},
619 {"LightSlateGray" , PALETTERGB (119,136,153)},
620 {"light slate grey" , PALETTERGB (119,136,153)},
621 {"LightSlateGrey" , PALETTERGB (119,136,153)},
622 {"gray" , PALETTERGB (190,190,190)},
623 {"grey" , PALETTERGB (190,190,190)},
624 {"light grey" , PALETTERGB (211,211,211)},
625 {"LightGrey" , PALETTERGB (211,211,211)},
626 {"light gray" , PALETTERGB (211,211,211)},
627 {"LightGray" , PALETTERGB (211,211,211)},
628 {"midnight blue" , PALETTERGB ( 25, 25,112)},
629 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
630 {"navy" , PALETTERGB ( 0, 0,128)},
631 {"navy blue" , PALETTERGB ( 0, 0,128)},
632 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
633 {"cornflower blue" , PALETTERGB (100,149,237)},
634 {"CornflowerBlue" , PALETTERGB (100,149,237)},
635 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
636 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
637 {"slate blue" , PALETTERGB (106, 90,205)},
638 {"SlateBlue" , PALETTERGB (106, 90,205)},
639 {"medium slate blue" , PALETTERGB (123,104,238)},
640 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
641 {"light slate blue" , PALETTERGB (132,112,255)},
642 {"LightSlateBlue" , PALETTERGB (132,112,255)},
643 {"medium blue" , PALETTERGB ( 0, 0,205)},
644 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
645 {"royal blue" , PALETTERGB ( 65,105,225)},
646 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
647 {"blue" , PALETTERGB ( 0, 0,255)},
648 {"dodger blue" , PALETTERGB ( 30,144,255)},
649 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
650 {"deep sky blue" , PALETTERGB ( 0,191,255)},
651 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
652 {"sky blue" , PALETTERGB (135,206,235)},
653 {"SkyBlue" , PALETTERGB (135,206,235)},
654 {"light sky blue" , PALETTERGB (135,206,250)},
655 {"LightSkyBlue" , PALETTERGB (135,206,250)},
656 {"steel blue" , PALETTERGB ( 70,130,180)},
657 {"SteelBlue" , PALETTERGB ( 70,130,180)},
658 {"light steel blue" , PALETTERGB (176,196,222)},
659 {"LightSteelBlue" , PALETTERGB (176,196,222)},
660 {"light blue" , PALETTERGB (173,216,230)},
661 {"LightBlue" , PALETTERGB (173,216,230)},
662 {"powder blue" , PALETTERGB (176,224,230)},
663 {"PowderBlue" , PALETTERGB (176,224,230)},
664 {"pale turquoise" , PALETTERGB (175,238,238)},
665 {"PaleTurquoise" , PALETTERGB (175,238,238)},
666 {"dark turquoise" , PALETTERGB ( 0,206,209)},
667 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
668 {"medium turquoise" , PALETTERGB ( 72,209,204)},
669 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
670 {"turquoise" , PALETTERGB ( 64,224,208)},
671 {"cyan" , PALETTERGB ( 0,255,255)},
672 {"light cyan" , PALETTERGB (224,255,255)},
673 {"LightCyan" , PALETTERGB (224,255,255)},
674 {"cadet blue" , PALETTERGB ( 95,158,160)},
675 {"CadetBlue" , PALETTERGB ( 95,158,160)},
676 {"medium aquamarine" , PALETTERGB (102,205,170)},
677 {"MediumAquamarine" , PALETTERGB (102,205,170)},
678 {"aquamarine" , PALETTERGB (127,255,212)},
679 {"dark green" , PALETTERGB ( 0,100, 0)},
680 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
681 {"dark olive green" , PALETTERGB ( 85,107, 47)},
682 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
683 {"dark sea green" , PALETTERGB (143,188,143)},
684 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
685 {"sea green" , PALETTERGB ( 46,139, 87)},
686 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
687 {"medium sea green" , PALETTERGB ( 60,179,113)},
688 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
689 {"light sea green" , PALETTERGB ( 32,178,170)},
690 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
691 {"pale green" , PALETTERGB (152,251,152)},
692 {"PaleGreen" , PALETTERGB (152,251,152)},
693 {"spring green" , PALETTERGB ( 0,255,127)},
694 {"SpringGreen" , PALETTERGB ( 0,255,127)},
695 {"lawn green" , PALETTERGB (124,252, 0)},
696 {"LawnGreen" , PALETTERGB (124,252, 0)},
697 {"green" , PALETTERGB ( 0,255, 0)},
698 {"chartreuse" , PALETTERGB (127,255, 0)},
699 {"medium spring green" , PALETTERGB ( 0,250,154)},
700 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
701 {"green yellow" , PALETTERGB (173,255, 47)},
702 {"GreenYellow" , PALETTERGB (173,255, 47)},
703 {"lime green" , PALETTERGB ( 50,205, 50)},
704 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
705 {"yellow green" , PALETTERGB (154,205, 50)},
706 {"YellowGreen" , PALETTERGB (154,205, 50)},
707 {"forest green" , PALETTERGB ( 34,139, 34)},
708 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
709 {"olive drab" , PALETTERGB (107,142, 35)},
710 {"OliveDrab" , PALETTERGB (107,142, 35)},
711 {"dark khaki" , PALETTERGB (189,183,107)},
712 {"DarkKhaki" , PALETTERGB (189,183,107)},
713 {"khaki" , PALETTERGB (240,230,140)},
714 {"pale goldenrod" , PALETTERGB (238,232,170)},
715 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
716 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
717 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
718 {"light yellow" , PALETTERGB (255,255,224)},
719 {"LightYellow" , PALETTERGB (255,255,224)},
720 {"yellow" , PALETTERGB (255,255, 0)},
721 {"gold" , PALETTERGB (255,215, 0)},
722 {"light goldenrod" , PALETTERGB (238,221,130)},
723 {"LightGoldenrod" , PALETTERGB (238,221,130)},
724 {"goldenrod" , PALETTERGB (218,165, 32)},
725 {"dark goldenrod" , PALETTERGB (184,134, 11)},
726 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
727 {"rosy brown" , PALETTERGB (188,143,143)},
728 {"RosyBrown" , PALETTERGB (188,143,143)},
729 {"indian red" , PALETTERGB (205, 92, 92)},
730 {"IndianRed" , PALETTERGB (205, 92, 92)},
731 {"saddle brown" , PALETTERGB (139, 69, 19)},
732 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
733 {"sienna" , PALETTERGB (160, 82, 45)},
734 {"peru" , PALETTERGB (205,133, 63)},
735 {"burlywood" , PALETTERGB (222,184,135)},
736 {"beige" , PALETTERGB (245,245,220)},
737 {"wheat" , PALETTERGB (245,222,179)},
738 {"sandy brown" , PALETTERGB (244,164, 96)},
739 {"SandyBrown" , PALETTERGB (244,164, 96)},
740 {"tan" , PALETTERGB (210,180,140)},
741 {"chocolate" , PALETTERGB (210,105, 30)},
742 {"firebrick" , PALETTERGB (178,34, 34)},
743 {"brown" , PALETTERGB (165,42, 42)},
744 {"dark salmon" , PALETTERGB (233,150,122)},
745 {"DarkSalmon" , PALETTERGB (233,150,122)},
746 {"salmon" , PALETTERGB (250,128,114)},
747 {"light salmon" , PALETTERGB (255,160,122)},
748 {"LightSalmon" , PALETTERGB (255,160,122)},
749 {"orange" , PALETTERGB (255,165, 0)},
750 {"dark orange" , PALETTERGB (255,140, 0)},
751 {"DarkOrange" , PALETTERGB (255,140, 0)},
752 {"coral" , PALETTERGB (255,127, 80)},
753 {"light coral" , PALETTERGB (240,128,128)},
754 {"LightCoral" , PALETTERGB (240,128,128)},
755 {"tomato" , PALETTERGB (255, 99, 71)},
756 {"orange red" , PALETTERGB (255, 69, 0)},
757 {"OrangeRed" , PALETTERGB (255, 69, 0)},
758 {"red" , PALETTERGB (255, 0, 0)},
759 {"hot pink" , PALETTERGB (255,105,180)},
760 {"HotPink" , PALETTERGB (255,105,180)},
761 {"deep pink" , PALETTERGB (255, 20,147)},
762 {"DeepPink" , PALETTERGB (255, 20,147)},
763 {"pink" , PALETTERGB (255,192,203)},
764 {"light pink" , PALETTERGB (255,182,193)},
765 {"LightPink" , PALETTERGB (255,182,193)},
766 {"pale violet red" , PALETTERGB (219,112,147)},
767 {"PaleVioletRed" , PALETTERGB (219,112,147)},
768 {"maroon" , PALETTERGB (176, 48, 96)},
769 {"medium violet red" , PALETTERGB (199, 21,133)},
770 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
771 {"violet red" , PALETTERGB (208, 32,144)},
772 {"VioletRed" , PALETTERGB (208, 32,144)},
773 {"magenta" , PALETTERGB (255, 0,255)},
774 {"violet" , PALETTERGB (238,130,238)},
775 {"plum" , PALETTERGB (221,160,221)},
776 {"orchid" , PALETTERGB (218,112,214)},
777 {"medium orchid" , PALETTERGB (186, 85,211)},
778 {"MediumOrchid" , PALETTERGB (186, 85,211)},
779 {"dark orchid" , PALETTERGB (153, 50,204)},
780 {"DarkOrchid" , PALETTERGB (153, 50,204)},
781 {"dark violet" , PALETTERGB (148, 0,211)},
782 {"DarkViolet" , PALETTERGB (148, 0,211)},
783 {"blue violet" , PALETTERGB (138, 43,226)},
784 {"BlueViolet" , PALETTERGB (138, 43,226)},
785 {"purple" , PALETTERGB (160, 32,240)},
786 {"medium purple" , PALETTERGB (147,112,219)},
787 {"MediumPurple" , PALETTERGB (147,112,219)},
788 {"thistle" , PALETTERGB (216,191,216)},
789 {"gray0" , PALETTERGB ( 0, 0, 0)},
790 {"grey0" , PALETTERGB ( 0, 0, 0)},
791 {"dark grey" , PALETTERGB (169,169,169)},
792 {"DarkGrey" , PALETTERGB (169,169,169)},
793 {"dark gray" , PALETTERGB (169,169,169)},
794 {"DarkGray" , PALETTERGB (169,169,169)},
795 {"dark blue" , PALETTERGB ( 0, 0,139)},
796 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
797 {"dark cyan" , PALETTERGB ( 0,139,139)},
798 {"DarkCyan" , PALETTERGB ( 0,139,139)},
799 {"dark magenta" , PALETTERGB (139, 0,139)},
800 {"DarkMagenta" , PALETTERGB (139, 0,139)},
801 {"dark red" , PALETTERGB (139, 0, 0)},
802 {"DarkRed" , PALETTERGB (139, 0, 0)},
803 {"light green" , PALETTERGB (144,238,144)},
804 {"LightGreen" , PALETTERGB (144,238,144)},
807 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
808 0, 0, 0, doc
: /* Return the default color map. */)
812 colormap_t
*pc
= w32_color_map
;
819 for (i
= 0; i
< sizeof (w32_color_map
) / sizeof (w32_color_map
[0]);
821 cmap
= Fcons (Fcons (build_string (pc
->name
),
822 make_number (pc
->colorref
)),
840 color
= Frassq (rgb
, Vw32_color_map
);
845 return (Fcar (color
));
851 w32_color_map_lookup (colorname
)
854 Lisp_Object tail
, ret
= Qnil
;
858 for (tail
= Vw32_color_map
; CONSP (tail
); tail
= XCDR (tail
))
860 register Lisp_Object elt
, tem
;
863 if (!CONSP (elt
)) continue;
867 if (lstrcmpi (SDATA (tem
), colorname
) == 0)
884 add_system_logical_colors_to_map (system_colors
)
885 Lisp_Object
*system_colors
;
889 /* Other registry operations are done with input blocked. */
892 /* Look for "Control Panel/Colors" under User and Machine registry
894 if (RegOpenKeyEx (HKEY_CURRENT_USER
, "Control Panel\\Colors", 0,
895 KEY_READ
, &colors_key
) == ERROR_SUCCESS
896 || RegOpenKeyEx (HKEY_LOCAL_MACHINE
, "Control Panel\\Colors", 0,
897 KEY_READ
, &colors_key
) == ERROR_SUCCESS
)
900 char color_buffer
[64];
901 char full_name_buffer
[MAX_PATH
+ SYSTEM_COLOR_PREFIX_LEN
];
903 DWORD name_size
, color_size
;
904 char *name_buffer
= full_name_buffer
+ SYSTEM_COLOR_PREFIX_LEN
;
906 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
907 color_size
= sizeof (color_buffer
);
909 strcpy (full_name_buffer
, SYSTEM_COLOR_PREFIX
);
911 while (RegEnumValueA (colors_key
, index
, name_buffer
, &name_size
,
912 NULL
, NULL
, color_buffer
, &color_size
)
916 if (sscanf (color_buffer
, " %u %u %u", &r
, &g
, &b
) == 3)
917 *system_colors
= Fcons (Fcons (build_string (full_name_buffer
),
918 make_number (RGB (r
, g
, b
))),
921 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
922 color_size
= sizeof (color_buffer
);
925 RegCloseKey (colors_key
);
933 x_to_w32_color (colorname
)
936 register Lisp_Object ret
= Qnil
;
940 if (colorname
[0] == '#')
942 /* Could be an old-style RGB Device specification. */
945 color
= colorname
+ 1;
947 size
= strlen (color
);
948 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
956 for (i
= 0; i
< 3; i
++)
962 /* The check for 'x' in the following conditional takes into
963 account the fact that strtol allows a "0x" in front of
964 our numbers, and we don't. */
965 if (!isxdigit (color
[0]) || color
[1] == 'x')
969 value
= strtoul (color
, &end
, 16);
971 if (errno
== ERANGE
|| end
- color
!= size
)
976 value
= value
* 0x10;
987 colorval
|= (value
<< pos
);
992 XSETINT (ret
, colorval
);
999 else if (strnicmp (colorname
, "rgb:", 4) == 0)
1007 color
= colorname
+ 4;
1008 for (i
= 0; i
< 3; i
++)
1011 unsigned long value
;
1013 /* The check for 'x' in the following conditional takes into
1014 account the fact that strtol allows a "0x" in front of
1015 our numbers, and we don't. */
1016 if (!isxdigit (color
[0]) || color
[1] == 'x')
1018 value
= strtoul (color
, &end
, 16);
1019 if (errno
== ERANGE
)
1021 switch (end
- color
)
1024 value
= value
* 0x10 + value
;
1037 if (value
== ULONG_MAX
)
1039 colorval
|= (value
<< pos
);
1046 XSETINT (ret
, colorval
);
1054 else if (strnicmp (colorname
, "rgbi:", 5) == 0)
1056 /* This is an RGB Intensity specification. */
1063 color
= colorname
+ 5;
1064 for (i
= 0; i
< 3; i
++)
1070 value
= strtod (color
, &end
);
1071 if (errno
== ERANGE
)
1073 if (value
< 0.0 || value
> 1.0)
1075 val
= (UINT
)(0x100 * value
);
1076 /* We used 0x100 instead of 0xFF to give a continuous
1077 range between 0.0 and 1.0 inclusive. The next statement
1078 fixes the 1.0 case. */
1081 colorval
|= (val
<< pos
);
1088 XSETINT (ret
, colorval
);
1096 /* I am not going to attempt to handle any of the CIE color schemes
1097 or TekHVC, since I don't know the algorithms for conversion to
1100 /* If we fail to lookup the color name in w32_color_map, then check the
1101 colorname to see if it can be crudely approximated: If the X color
1102 ends in a number (e.g., "darkseagreen2"), strip the number and
1103 return the result of looking up the base color name. */
1104 ret
= w32_color_map_lookup (colorname
);
1107 int len
= strlen (colorname
);
1109 if (isdigit (colorname
[len
- 1]))
1111 char *ptr
, *approx
= alloca (len
+ 1);
1113 strcpy (approx
, colorname
);
1114 ptr
= &approx
[len
- 1];
1115 while (ptr
> approx
&& isdigit (*ptr
))
1118 ret
= w32_color_map_lookup (approx
);
1127 w32_regenerate_palette (FRAME_PTR f
)
1129 struct w32_palette_entry
* list
;
1130 LOGPALETTE
* log_palette
;
1131 HPALETTE new_palette
;
1134 /* don't bother trying to create palette if not supported */
1135 if (! FRAME_W32_DISPLAY_INFO (f
)->has_palette
)
1138 log_palette
= (LOGPALETTE
*)
1139 alloca (sizeof (LOGPALETTE
) +
1140 FRAME_W32_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
1141 log_palette
->palVersion
= 0x300;
1142 log_palette
->palNumEntries
= FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1144 list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1146 i
< FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1147 i
++, list
= list
->next
)
1148 log_palette
->palPalEntry
[i
] = list
->entry
;
1150 new_palette
= CreatePalette (log_palette
);
1154 if (FRAME_W32_DISPLAY_INFO (f
)->palette
)
1155 DeleteObject (FRAME_W32_DISPLAY_INFO (f
)->palette
);
1156 FRAME_W32_DISPLAY_INFO (f
)->palette
= new_palette
;
1158 /* Realize display palette and garbage all frames. */
1159 release_frame_dc (f
, get_frame_dc (f
));
1164 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
1165 #define SET_W32_COLOR(pe, color) \
1168 pe.peRed = GetRValue (color); \
1169 pe.peGreen = GetGValue (color); \
1170 pe.peBlue = GetBValue (color); \
1175 /* Keep these around in case we ever want to track color usage. */
1177 w32_map_color (FRAME_PTR f
, COLORREF color
)
1179 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1181 if (NILP (Vw32_enable_palette
))
1184 /* check if color is already mapped */
1187 if (W32_COLOR (list
->entry
) == color
)
1195 /* not already mapped, so add to list and recreate Windows palette */
1196 list
= (struct w32_palette_entry
*)
1197 xmalloc (sizeof (struct w32_palette_entry
));
1198 SET_W32_COLOR (list
->entry
, color
);
1200 list
->next
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1201 FRAME_W32_DISPLAY_INFO (f
)->color_list
= list
;
1202 FRAME_W32_DISPLAY_INFO (f
)->num_colors
++;
1204 /* set flag that palette must be regenerated */
1205 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1209 w32_unmap_color (FRAME_PTR f
, COLORREF color
)
1211 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1212 struct w32_palette_entry
**prev
= &FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1214 if (NILP (Vw32_enable_palette
))
1217 /* check if color is already mapped */
1220 if (W32_COLOR (list
->entry
) == color
)
1222 if (--list
->refcount
== 0)
1226 FRAME_W32_DISPLAY_INFO (f
)->num_colors
--;
1236 /* set flag that palette must be regenerated */
1237 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1242 /* Gamma-correct COLOR on frame F. */
1245 gamma_correct (f
, color
)
1251 *color
= PALETTERGB (
1252 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1253 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1254 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1259 /* Decide if color named COLOR is valid for the display associated with
1260 the selected frame; if so, return the rgb values in COLOR_DEF.
1261 If ALLOC is nonzero, allocate a new colormap cell. */
1264 w32_defined_color (f
, color
, color_def
, alloc
)
1270 register Lisp_Object tem
;
1271 COLORREF w32_color_ref
;
1273 tem
= x_to_w32_color (color
);
1279 /* Apply gamma correction. */
1280 w32_color_ref
= XUINT (tem
);
1281 gamma_correct (f
, &w32_color_ref
);
1282 XSETINT (tem
, w32_color_ref
);
1285 /* Map this color to the palette if it is enabled. */
1286 if (!NILP (Vw32_enable_palette
))
1288 struct w32_palette_entry
* entry
=
1289 one_w32_display_info
.color_list
;
1290 struct w32_palette_entry
** prev
=
1291 &one_w32_display_info
.color_list
;
1293 /* check if color is already mapped */
1296 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1298 prev
= &entry
->next
;
1299 entry
= entry
->next
;
1302 if (entry
== NULL
&& alloc
)
1304 /* not already mapped, so add to list */
1305 entry
= (struct w32_palette_entry
*)
1306 xmalloc (sizeof (struct w32_palette_entry
));
1307 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1310 one_w32_display_info
.num_colors
++;
1312 /* set flag that palette must be regenerated */
1313 one_w32_display_info
.regen_palette
= TRUE
;
1316 /* Ensure COLORREF value is snapped to nearest color in (default)
1317 palette by simulating the PALETTERGB macro. This works whether
1318 or not the display device has a palette. */
1319 w32_color_ref
= XUINT (tem
) | 0x2000000;
1321 color_def
->pixel
= w32_color_ref
;
1322 color_def
->red
= GetRValue (w32_color_ref
) * 256;
1323 color_def
->green
= GetGValue (w32_color_ref
) * 256;
1324 color_def
->blue
= GetBValue (w32_color_ref
) * 256;
1334 /* Given a string ARG naming a color, compute a pixel value from it
1335 suitable for screen F.
1336 If F is not a color screen, return DEF (default) regardless of what
1340 x_decode_color (f
, arg
, def
)
1349 if (strcmp (SDATA (arg
), "black") == 0)
1350 return BLACK_PIX_DEFAULT (f
);
1351 else if (strcmp (SDATA (arg
), "white") == 0)
1352 return WHITE_PIX_DEFAULT (f
);
1354 if ((FRAME_W32_DISPLAY_INFO (f
)->n_planes
* FRAME_W32_DISPLAY_INFO (f
)->n_cbits
) == 1)
1357 /* w32_defined_color is responsible for coping with failures
1358 by looking for a near-miss. */
1359 if (w32_defined_color (f
, SDATA (arg
), &cdef
, 1))
1362 /* defined_color failed; return an ultimate default. */
1368 /* Functions called only from `x_set_frame_param'
1369 to set individual parameters.
1371 If FRAME_W32_WINDOW (f) is 0,
1372 the frame is being created and its window does not exist yet.
1373 In that case, just record the parameter's new value
1374 in the standard place; do not attempt to change the window. */
1377 x_set_foreground_color (f
, arg
, oldval
)
1379 Lisp_Object arg
, oldval
;
1381 struct w32_output
*x
= f
->output_data
.w32
;
1382 PIX_TYPE fg
, old_fg
;
1384 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1385 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
1386 FRAME_FOREGROUND_PIXEL (f
) = fg
;
1388 if (FRAME_W32_WINDOW (f
) != 0)
1390 if (x
->cursor_pixel
== old_fg
)
1391 x
->cursor_pixel
= fg
;
1393 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
1394 if (FRAME_VISIBLE_P (f
))
1400 x_set_background_color (f
, arg
, oldval
)
1402 Lisp_Object arg
, oldval
;
1404 FRAME_BACKGROUND_PIXEL (f
)
1405 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
1407 if (FRAME_W32_WINDOW (f
) != 0)
1409 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
1410 FRAME_BACKGROUND_PIXEL (f
));
1412 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
1414 if (FRAME_VISIBLE_P (f
))
1420 x_set_mouse_color (f
, arg
, oldval
)
1422 Lisp_Object arg
, oldval
;
1424 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
1428 if (!EQ (Qnil
, arg
))
1429 f
->output_data
.w32
->mouse_pixel
1430 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1431 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
1433 /* Don't let pointers be invisible. */
1434 if (mask_color
== f
->output_data
.w32
->mouse_pixel
1435 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
1436 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
1438 #if 0 /* TODO : cursor changes */
1441 /* It's not okay to crash if the user selects a screwy cursor. */
1442 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
1444 if (!EQ (Qnil
, Vx_pointer_shape
))
1446 CHECK_NUMBER (Vx_pointer_shape
);
1447 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
1450 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1451 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
1453 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
1455 CHECK_NUMBER (Vx_nontext_pointer_shape
);
1456 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1457 XINT (Vx_nontext_pointer_shape
));
1460 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
1461 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1463 if (!EQ (Qnil
, Vx_hourglass_pointer_shape
))
1465 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
1466 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1467 XINT (Vx_hourglass_pointer_shape
));
1470 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
1471 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
1473 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1474 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
1476 CHECK_NUMBER (Vx_mode_pointer_shape
);
1477 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1478 XINT (Vx_mode_pointer_shape
));
1481 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1482 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
1484 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
1486 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
1488 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1489 XINT (Vx_sensitive_text_pointer_shape
));
1492 hand_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
1494 if (!NILP (Vx_window_horizontal_drag_shape
))
1496 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
1497 horizontal_drag_cursor
1498 = XCreateFontCursor (FRAME_X_DISPLAY (f
),
1499 XINT (Vx_window_horizontal_drag_shape
));
1502 horizontal_drag_cursor
1503 = XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_sb_h_double_arrow
);
1505 /* Check and report errors with the above calls. */
1506 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
1507 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
1510 XColor fore_color
, back_color
;
1512 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
1513 back_color
.pixel
= mask_color
;
1514 XQueryColor (FRAME_W32_DISPLAY (f
),
1515 DefaultColormap (FRAME_W32_DISPLAY (f
),
1516 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1518 XQueryColor (FRAME_W32_DISPLAY (f
),
1519 DefaultColormap (FRAME_W32_DISPLAY (f
),
1520 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1522 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
1523 &fore_color
, &back_color
);
1524 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
1525 &fore_color
, &back_color
);
1526 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
1527 &fore_color
, &back_color
);
1528 XRecolorCursor (FRAME_W32_DISPLAY (f
), hand_cursor
,
1529 &fore_color
, &back_color
);
1530 XRecolorCursor (FRAME_W32_DISPLAY (f
), hourglass_cursor
,
1531 &fore_color
, &back_color
);
1534 if (FRAME_W32_WINDOW (f
) != 0)
1535 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
1537 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
1538 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
1539 f
->output_data
.w32
->text_cursor
= cursor
;
1541 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
1542 && f
->output_data
.w32
->nontext_cursor
!= 0)
1543 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
1544 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
1546 if (hourglass_cursor
!= f
->output_data
.w32
->hourglass_cursor
1547 && f
->output_data
.w32
->hourglass_cursor
!= 0)
1548 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hourglass_cursor
);
1549 f
->output_data
.w32
->hourglass_cursor
= hourglass_cursor
;
1551 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
1552 && f
->output_data
.w32
->modeline_cursor
!= 0)
1553 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
1554 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
1556 if (hand_cursor
!= f
->output_data
.w32
->hand_cursor
1557 && f
->output_data
.w32
->hand_cursor
!= 0)
1558 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hand_cursor
);
1559 f
->output_data
.w32
->hand_cursor
= hand_cursor
;
1561 XFlush (FRAME_W32_DISPLAY (f
));
1564 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1569 x_set_cursor_color (f
, arg
, oldval
)
1571 Lisp_Object arg
, oldval
;
1573 unsigned long fore_pixel
, pixel
;
1575 if (!NILP (Vx_cursor_fore_pixel
))
1576 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1577 WHITE_PIX_DEFAULT (f
));
1579 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1581 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1583 /* Make sure that the cursor color differs from the background color. */
1584 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
1586 pixel
= f
->output_data
.w32
->mouse_pixel
;
1587 if (pixel
== fore_pixel
)
1588 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1591 f
->output_data
.w32
->cursor_foreground_pixel
= fore_pixel
;
1592 f
->output_data
.w32
->cursor_pixel
= pixel
;
1594 if (FRAME_W32_WINDOW (f
) != 0)
1597 /* Update frame's cursor_gc. */
1598 f
->output_data
.w32
->cursor_gc
->foreground
= fore_pixel
;
1599 f
->output_data
.w32
->cursor_gc
->background
= pixel
;
1603 if (FRAME_VISIBLE_P (f
))
1605 x_update_cursor (f
, 0);
1606 x_update_cursor (f
, 1);
1610 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1613 /* Set the border-color of frame F to pixel value PIX.
1614 Note that this does not fully take effect if done before
1618 x_set_border_pixel (f
, pix
)
1623 f
->output_data
.w32
->border_pixel
= pix
;
1625 if (FRAME_W32_WINDOW (f
) != 0 && f
->border_width
> 0)
1627 if (FRAME_VISIBLE_P (f
))
1632 /* Set the border-color of frame F to value described by ARG.
1633 ARG can be a string naming a color.
1634 The border-color is used for the border that is drawn by the server.
1635 Note that this does not fully take effect if done before
1636 F has a window; it must be redone when the window is created. */
1639 x_set_border_color (f
, arg
, oldval
)
1641 Lisp_Object arg
, oldval
;
1646 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1647 x_set_border_pixel (f
, pix
);
1648 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1653 x_set_cursor_type (f
, arg
, oldval
)
1655 Lisp_Object arg
, oldval
;
1657 set_frame_cursor_types (f
, arg
);
1659 /* Make sure the cursor gets redrawn. */
1660 cursor_type_changed
= 1;
1664 x_set_icon_type (f
, arg
, oldval
)
1666 Lisp_Object arg
, oldval
;
1670 if (NILP (arg
) && NILP (oldval
))
1673 if (STRINGP (arg
) && STRINGP (oldval
)
1674 && EQ (Fstring_equal (oldval
, arg
), Qt
))
1677 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
1682 result
= x_bitmap_icon (f
, arg
);
1686 error ("No icon window available");
1693 x_set_icon_name (f
, arg
, oldval
)
1695 Lisp_Object arg
, oldval
;
1699 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1702 else if (!NILP (arg
) || NILP (oldval
))
1708 if (f
->output_data
.w32
->icon_bitmap
!= 0)
1713 result
= x_text_icon (f
,
1714 (char *) SDATA ((!NILP (f
->icon_name
)
1723 error ("No icon window available");
1726 /* If the window was unmapped (and its icon was mapped),
1727 the new icon is not mapped, so map the window in its stead. */
1728 if (FRAME_VISIBLE_P (f
))
1730 #ifdef USE_X_TOOLKIT
1731 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
1733 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
1736 XFlush (FRAME_W32_DISPLAY (f
));
1743 x_set_menu_bar_lines (f
, value
, oldval
)
1745 Lisp_Object value
, oldval
;
1748 int olines
= FRAME_MENU_BAR_LINES (f
);
1750 /* Right now, menu bars don't work properly in minibuf-only frames;
1751 most of the commands try to apply themselves to the minibuffer
1752 frame itself, and get an error because you can't switch buffers
1753 in or split the minibuffer window. */
1754 if (FRAME_MINIBUF_ONLY_P (f
))
1757 if (INTEGERP (value
))
1758 nlines
= XINT (value
);
1762 FRAME_MENU_BAR_LINES (f
) = 0;
1764 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1767 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1768 free_frame_menubar (f
);
1769 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1771 /* Adjust the frame size so that the client (text) dimensions
1772 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
1774 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
1775 do_pending_window_change (0);
1781 /* Set the number of lines used for the tool bar of frame F to VALUE.
1782 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1783 is the old number of tool bar lines. This function changes the
1784 height of all windows on frame F to match the new tool bar height.
1785 The frame's height doesn't change. */
1788 x_set_tool_bar_lines (f
, value
, oldval
)
1790 Lisp_Object value
, oldval
;
1792 int delta
, nlines
, root_height
;
1793 Lisp_Object root_window
;
1795 /* Treat tool bars like menu bars. */
1796 if (FRAME_MINIBUF_ONLY_P (f
))
1799 /* Use VALUE only if an integer >= 0. */
1800 if (INTEGERP (value
) && XINT (value
) >= 0)
1801 nlines
= XFASTINT (value
);
1805 /* Make sure we redisplay all windows in this frame. */
1806 ++windows_or_buffers_changed
;
1808 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
1810 /* Don't resize the tool-bar to more than we have room for. */
1811 root_window
= FRAME_ROOT_WINDOW (f
);
1812 root_height
= WINDOW_TOTAL_LINES (XWINDOW (root_window
));
1813 if (root_height
- delta
< 1)
1815 delta
= root_height
- 1;
1816 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
1819 FRAME_TOOL_BAR_LINES (f
) = nlines
;
1820 change_window_heights (root_window
, delta
);
1823 /* We also have to make sure that the internal border at the top of
1824 the frame, below the menu bar or tool bar, is redrawn when the
1825 tool bar disappears. This is so because the internal border is
1826 below the tool bar if one is displayed, but is below the menu bar
1827 if there isn't a tool bar. The tool bar draws into the area
1828 below the menu bar. */
1829 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
1832 clear_current_matrices (f
);
1835 /* If the tool bar gets smaller, the internal border below it
1836 has to be cleared. It was formerly part of the display
1837 of the larger tool bar, and updating windows won't clear it. */
1840 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1841 int width
= FRAME_PIXEL_WIDTH (f
);
1842 int y
= nlines
* FRAME_LINE_HEIGHT (f
);
1846 HDC hdc
= get_frame_dc (f
);
1847 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
1848 release_frame_dc (f
, hdc
);
1852 if (WINDOWP (f
->tool_bar_window
))
1853 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1858 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1861 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1862 name; if NAME is a string, set F's name to NAME and set
1863 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1865 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1866 suggesting a new name, which lisp code should override; if
1867 F->explicit_name is set, ignore the new name; otherwise, set it. */
1870 x_set_name (f
, name
, explicit)
1875 /* Make sure that requests from lisp code override requests from
1876 Emacs redisplay code. */
1879 /* If we're switching from explicit to implicit, we had better
1880 update the mode lines and thereby update the title. */
1881 if (f
->explicit_name
&& NILP (name
))
1882 update_mode_lines
= 1;
1884 f
->explicit_name
= ! NILP (name
);
1886 else if (f
->explicit_name
)
1889 /* If NAME is nil, set the name to the w32_id_name. */
1892 /* Check for no change needed in this very common case
1893 before we do any consing. */
1894 if (!strcmp (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
,
1897 name
= build_string (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
);
1900 CHECK_STRING (name
);
1902 /* Don't change the name if it's already NAME. */
1903 if (! NILP (Fstring_equal (name
, f
->name
)))
1908 /* For setting the frame title, the title parameter should override
1909 the name parameter. */
1910 if (! NILP (f
->title
))
1913 if (FRAME_W32_WINDOW (f
))
1915 if (STRING_MULTIBYTE (name
))
1916 name
= ENCODE_SYSTEM (name
);
1919 SetWindowText (FRAME_W32_WINDOW (f
), SDATA (name
));
1924 /* This function should be called when the user's lisp code has
1925 specified a name for the frame; the name will override any set by the
1928 x_explicitly_set_name (f
, arg
, oldval
)
1930 Lisp_Object arg
, oldval
;
1932 x_set_name (f
, arg
, 1);
1935 /* This function should be called by Emacs redisplay code to set the
1936 name; names set this way will never override names set by the user's
1939 x_implicitly_set_name (f
, arg
, oldval
)
1941 Lisp_Object arg
, oldval
;
1943 x_set_name (f
, arg
, 0);
1946 /* Change the title of frame F to NAME.
1947 If NAME is nil, use the frame name as the title. */
1950 x_set_title (f
, name
, old_name
)
1952 Lisp_Object name
, old_name
;
1954 /* Don't change the title if it's already NAME. */
1955 if (EQ (name
, f
->title
))
1958 update_mode_lines
= 1;
1965 if (FRAME_W32_WINDOW (f
))
1967 if (STRING_MULTIBYTE (name
))
1968 name
= ENCODE_SYSTEM (name
);
1971 SetWindowText (FRAME_W32_WINDOW (f
), SDATA (name
));
1977 void x_set_scroll_bar_default_width (f
)
1980 int wid
= FRAME_COLUMN_WIDTH (f
);
1982 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
1983 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) +
1988 /* Subroutines for creating a frame. */
1991 w32_load_cursor (LPCTSTR name
)
1993 /* Try first to load cursor from application resource. */
1994 Cursor cursor
= LoadImage ((HINSTANCE
) GetModuleHandle (NULL
),
1995 name
, IMAGE_CURSOR
, 0, 0,
1996 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
1999 /* Then try to load a shared predefined cursor. */
2000 cursor
= LoadImage (NULL
, name
, IMAGE_CURSOR
, 0, 0,
2001 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
2006 extern LRESULT CALLBACK
w32_wnd_proc ();
2009 w32_init_class (hinst
)
2014 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
2015 wc
.lpfnWndProc
= (WNDPROC
) w32_wnd_proc
;
2017 wc
.cbWndExtra
= WND_EXTRA_BYTES
;
2018 wc
.hInstance
= hinst
;
2019 wc
.hIcon
= LoadIcon (hinst
, EMACS_CLASS
);
2020 wc
.hCursor
= w32_load_cursor (IDC_ARROW
);
2021 wc
.hbrBackground
= NULL
; /* GetStockObject (WHITE_BRUSH); */
2022 wc
.lpszMenuName
= NULL
;
2023 wc
.lpszClassName
= EMACS_CLASS
;
2025 return (RegisterClass (&wc
));
2029 w32_createscrollbar (f
, bar
)
2031 struct scroll_bar
* bar
;
2033 return (CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
2034 /* Position and size of scroll bar. */
2035 XINT (bar
->left
) + VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
2037 XINT (bar
->width
) - VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
2039 FRAME_W32_WINDOW (f
),
2046 w32_createwindow (f
)
2051 Lisp_Object top
= Qunbound
;
2052 Lisp_Object left
= Qunbound
;
2053 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
2055 rect
.left
= rect
.top
= 0;
2056 rect
.right
= FRAME_PIXEL_WIDTH (f
);
2057 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
2059 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
2060 FRAME_EXTERNAL_MENU_BAR (f
));
2062 /* Do first time app init */
2066 w32_init_class (hinst
);
2069 if (f
->size_hint_flags
& USPosition
|| f
->size_hint_flags
& PPosition
)
2071 XSETINT (left
, f
->left_pos
);
2072 XSETINT (top
, f
->top_pos
);
2074 else if (EQ (left
, Qunbound
) && EQ (top
, Qunbound
))
2076 /* When called with RES_TYPE_NUMBER, w32_get_arg will return zero
2077 for anything that is not a number and is not Qunbound. */
2078 left
= x_get_arg (dpyinfo
, Qnil
, Qleft
, "left", "Left", RES_TYPE_NUMBER
);
2079 top
= x_get_arg (dpyinfo
, Qnil
, Qtop
, "top", "Top", RES_TYPE_NUMBER
);
2082 FRAME_W32_WINDOW (f
) = hwnd
2083 = CreateWindow (EMACS_CLASS
,
2085 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
2086 EQ (left
, Qunbound
) ? CW_USEDEFAULT
: XINT (left
),
2087 EQ (top
, Qunbound
) ? CW_USEDEFAULT
: XINT (top
),
2088 rect
.right
- rect
.left
,
2089 rect
.bottom
- rect
.top
,
2097 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
2098 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
2099 SetWindowLong (hwnd
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
2100 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->scroll_bar_actual_width
);
2101 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
2103 /* Enable drag-n-drop. */
2104 DragAcceptFiles (hwnd
, TRUE
);
2106 /* Do this to discard the default setting specified by our parent. */
2107 ShowWindow (hwnd
, SW_HIDE
);
2109 /* Update frame positions. */
2110 GetWindowRect (hwnd
, &rect
);
2111 f
->left_pos
= rect
.left
;
2112 f
->top_pos
= rect
.top
;
2117 my_post_msg (wmsg
, hwnd
, msg
, wParam
, lParam
)
2124 wmsg
->msg
.hwnd
= hwnd
;
2125 wmsg
->msg
.message
= msg
;
2126 wmsg
->msg
.wParam
= wParam
;
2127 wmsg
->msg
.lParam
= lParam
;
2128 wmsg
->msg
.time
= GetMessageTime ();
2133 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
2134 between left and right keys as advertised. We test for this
2135 support dynamically, and set a flag when the support is absent. If
2136 absent, we keep track of the left and right control and alt keys
2137 ourselves. This is particularly necessary on keyboards that rely
2138 upon the AltGr key, which is represented as having the left control
2139 and right alt keys pressed. For these keyboards, we need to know
2140 when the left alt key has been pressed in addition to the AltGr key
2141 so that we can properly support M-AltGr-key sequences (such as M-@
2142 on Swedish keyboards). */
2144 #define EMACS_LCONTROL 0
2145 #define EMACS_RCONTROL 1
2146 #define EMACS_LMENU 2
2147 #define EMACS_RMENU 3
2149 static int modifiers
[4];
2150 static int modifiers_recorded
;
2151 static int modifier_key_support_tested
;
2154 test_modifier_support (unsigned int wparam
)
2158 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
2160 if (wparam
== VK_CONTROL
)
2170 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
2171 modifiers_recorded
= 1;
2173 modifiers_recorded
= 0;
2174 modifier_key_support_tested
= 1;
2178 record_keydown (unsigned int wparam
, unsigned int lparam
)
2182 if (!modifier_key_support_tested
)
2183 test_modifier_support (wparam
);
2185 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2188 if (wparam
== VK_CONTROL
)
2189 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2191 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2197 record_keyup (unsigned int wparam
, unsigned int lparam
)
2201 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2204 if (wparam
== VK_CONTROL
)
2205 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2207 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2212 /* Emacs can lose focus while a modifier key has been pressed. When
2213 it regains focus, be conservative and clear all modifiers since
2214 we cannot reconstruct the left and right modifier state. */
2220 if (GetFocus () == NULL
)
2221 /* Emacs doesn't have keyboard focus. Do nothing. */
2224 ctrl
= GetAsyncKeyState (VK_CONTROL
);
2225 alt
= GetAsyncKeyState (VK_MENU
);
2227 if (!(ctrl
& 0x08000))
2228 /* Clear any recorded control modifier state. */
2229 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2231 if (!(alt
& 0x08000))
2232 /* Clear any recorded alt modifier state. */
2233 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2235 /* Update the state of all modifier keys, because modifiers used in
2236 hot-key combinations can get stuck on if Emacs loses focus as a
2237 result of a hot-key being pressed. */
2241 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
2243 GetKeyboardState (keystate
);
2244 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
2245 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
2246 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
2247 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
2248 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
2249 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
2250 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
2251 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
2252 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
2253 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
2254 SetKeyboardState (keystate
);
2258 /* Synchronize modifier state with what is reported with the current
2259 keystroke. Even if we cannot distinguish between left and right
2260 modifier keys, we know that, if no modifiers are set, then neither
2261 the left or right modifier should be set. */
2265 if (!modifiers_recorded
)
2268 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
2269 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2271 if (!(GetKeyState (VK_MENU
) & 0x8000))
2272 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2276 modifier_set (int vkey
)
2278 if (vkey
== VK_CAPITAL
|| vkey
== VK_SCROLL
)
2279 return (GetKeyState (vkey
) & 0x1);
2280 if (!modifiers_recorded
)
2281 return (GetKeyState (vkey
) & 0x8000);
2286 return modifiers
[EMACS_LCONTROL
];
2288 return modifiers
[EMACS_RCONTROL
];
2290 return modifiers
[EMACS_LMENU
];
2292 return modifiers
[EMACS_RMENU
];
2294 return (GetKeyState (vkey
) & 0x8000);
2297 /* Convert between the modifier bits W32 uses and the modifier bits
2301 w32_key_to_modifier (int key
)
2303 Lisp_Object key_mapping
;
2308 key_mapping
= Vw32_lwindow_modifier
;
2311 key_mapping
= Vw32_rwindow_modifier
;
2314 key_mapping
= Vw32_apps_modifier
;
2317 key_mapping
= Vw32_scroll_lock_modifier
;
2323 /* NB. This code runs in the input thread, asychronously to the lisp
2324 thread, so we must be careful to ensure access to lisp data is
2325 thread-safe. The following code is safe because the modifier
2326 variable values are updated atomically from lisp and symbols are
2327 not relocated by GC. Also, we don't have to worry about seeing GC
2329 if (EQ (key_mapping
, Qhyper
))
2330 return hyper_modifier
;
2331 if (EQ (key_mapping
, Qsuper
))
2332 return super_modifier
;
2333 if (EQ (key_mapping
, Qmeta
))
2334 return meta_modifier
;
2335 if (EQ (key_mapping
, Qalt
))
2336 return alt_modifier
;
2337 if (EQ (key_mapping
, Qctrl
))
2338 return ctrl_modifier
;
2339 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
2340 return ctrl_modifier
;
2341 if (EQ (key_mapping
, Qshift
))
2342 return shift_modifier
;
2344 /* Don't generate any modifier if not explicitly requested. */
2349 w32_get_modifiers ()
2351 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
2352 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
2353 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
2354 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
2355 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
2356 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
2357 (modifier_set (VK_MENU
) ?
2358 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
2361 /* We map the VK_* modifiers into console modifier constants
2362 so that we can use the same routines to handle both console
2363 and window input. */
2366 construct_console_modifiers ()
2371 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
2372 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
2373 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
2374 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
2375 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
2376 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
2377 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
2378 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
2379 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
2380 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
2381 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
2387 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
2391 /* Convert to emacs modifiers. */
2392 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
2398 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
2400 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
2403 if (virt_key
== VK_RETURN
)
2404 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
2406 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
2407 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
2409 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
2410 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
2412 if (virt_key
== VK_CLEAR
)
2413 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
2418 /* List of special key combinations which w32 would normally capture,
2419 but Emacs should grab instead. Not directly visible to lisp, to
2420 simplify synchronization. Each item is an integer encoding a virtual
2421 key code and modifier combination to capture. */
2422 static Lisp_Object w32_grabbed_keys
;
2424 #define HOTKEY(vk, mods) make_number (((vk) & 255) | ((mods) << 8))
2425 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
2426 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
2427 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
2429 #define RAW_HOTKEY_ID(k) ((k) & 0xbfff)
2430 #define RAW_HOTKEY_VK_CODE(k) ((k) & 255)
2431 #define RAW_HOTKEY_MODIFIERS(k) ((k) >> 8)
2433 /* Register hot-keys for reserved key combinations when Emacs has
2434 keyboard focus, since this is the only way Emacs can receive key
2435 combinations like Alt-Tab which are used by the system. */
2438 register_hot_keys (hwnd
)
2441 Lisp_Object keylist
;
2443 /* Use CONSP, since we are called asynchronously. */
2444 for (keylist
= w32_grabbed_keys
; CONSP (keylist
); keylist
= XCDR (keylist
))
2446 Lisp_Object key
= XCAR (keylist
);
2448 /* Deleted entries get set to nil. */
2449 if (!INTEGERP (key
))
2452 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
2453 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
2458 unregister_hot_keys (hwnd
)
2461 Lisp_Object keylist
;
2463 for (keylist
= w32_grabbed_keys
; CONSP (keylist
); keylist
= XCDR (keylist
))
2465 Lisp_Object key
= XCAR (keylist
);
2467 if (!INTEGERP (key
))
2470 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
2474 /* Main message dispatch loop. */
2477 w32_msg_pump (deferred_msg
* msg_buf
)
2483 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
2485 while (GetMessage (&msg
, NULL
, 0, 0))
2487 if (msg
.hwnd
== NULL
)
2489 switch (msg
.message
)
2492 /* Produced by complete_deferred_msg; just ignore. */
2494 case WM_EMACS_CREATEWINDOW
:
2495 /* Initialize COM for this window. Even though we don't use it,
2496 some third party shell extensions can cause it to be used in
2497 system dialogs, which causes a crash if it is not initialized.
2498 This is a known bug in Windows, which was fixed long ago, but
2499 the patch for XP is not publically available until XP SP3,
2500 and older versions will never be patched. */
2501 CoInitialize (NULL
);
2502 w32_createwindow ((struct frame
*) msg
.wParam
);
2503 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2506 case WM_EMACS_SETLOCALE
:
2507 SetThreadLocale (msg
.wParam
);
2508 /* Reply is not expected. */
2510 case WM_EMACS_SETKEYBOARDLAYOUT
:
2511 result
= (int) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
2512 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2516 case WM_EMACS_REGISTER_HOT_KEY
:
2517 focus_window
= GetFocus ();
2518 if (focus_window
!= NULL
)
2519 RegisterHotKey (focus_window
,
2520 RAW_HOTKEY_ID (msg
.wParam
),
2521 RAW_HOTKEY_MODIFIERS (msg
.wParam
),
2522 RAW_HOTKEY_VK_CODE (msg
.wParam
));
2523 /* Reply is not expected. */
2525 case WM_EMACS_UNREGISTER_HOT_KEY
:
2526 focus_window
= GetFocus ();
2527 if (focus_window
!= NULL
)
2528 UnregisterHotKey (focus_window
, RAW_HOTKEY_ID (msg
.wParam
));
2529 /* Mark item as erased. NB: this code must be
2530 thread-safe. The next line is okay because the cons
2531 cell is never made into garbage and is not relocated by
2533 XSETCAR ((Lisp_Object
) ((EMACS_INT
) msg
.lParam
), Qnil
);
2534 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2537 case WM_EMACS_TOGGLE_LOCK_KEY
:
2539 int vk_code
= (int) msg
.wParam
;
2540 int cur_state
= (GetKeyState (vk_code
) & 1);
2541 Lisp_Object new_state
= (Lisp_Object
) ((EMACS_INT
) msg
.lParam
);
2543 /* NB: This code must be thread-safe. It is safe to
2544 call NILP because symbols are not relocated by GC,
2545 and pointer here is not touched by GC (so the markbit
2546 can't be set). Numbers are safe because they are
2547 immediate values. */
2548 if (NILP (new_state
)
2549 || (NUMBERP (new_state
)
2550 && ((XUINT (new_state
)) & 1) != cur_state
))
2552 one_w32_display_info
.faked_key
= vk_code
;
2554 keybd_event ((BYTE
) vk_code
,
2555 (BYTE
) MapVirtualKey (vk_code
, 0),
2556 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2557 keybd_event ((BYTE
) vk_code
,
2558 (BYTE
) MapVirtualKey (vk_code
, 0),
2559 KEYEVENTF_EXTENDEDKEY
| 0, 0);
2560 keybd_event ((BYTE
) vk_code
,
2561 (BYTE
) MapVirtualKey (vk_code
, 0),
2562 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2563 cur_state
= !cur_state
;
2565 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2571 /* Broadcast messages make it here, so you need to be looking
2572 for something in particular for this to be useful. */
2574 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
2580 DispatchMessage (&msg
);
2583 /* Exit nested loop when our deferred message has completed. */
2584 if (msg_buf
->completed
)
2589 deferred_msg
* deferred_msg_head
;
2591 static deferred_msg
*
2592 find_deferred_msg (HWND hwnd
, UINT msg
)
2594 deferred_msg
* item
;
2596 /* Don't actually need synchronization for read access, since
2597 modification of single pointer is always atomic. */
2598 /* enter_crit (); */
2600 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2601 if (item
->w32msg
.msg
.hwnd
== hwnd
2602 && item
->w32msg
.msg
.message
== msg
)
2605 /* leave_crit (); */
2611 send_deferred_msg (deferred_msg
* msg_buf
,
2617 /* Only input thread can send deferred messages. */
2618 if (GetCurrentThreadId () != dwWindowsThreadId
)
2621 /* It is an error to send a message that is already deferred. */
2622 if (find_deferred_msg (hwnd
, msg
) != NULL
)
2625 /* Enforced synchronization is not needed because this is the only
2626 function that alters deferred_msg_head, and the following critical
2627 section is guaranteed to only be serially reentered (since only the
2628 input thread can call us). */
2630 /* enter_crit (); */
2632 msg_buf
->completed
= 0;
2633 msg_buf
->next
= deferred_msg_head
;
2634 deferred_msg_head
= msg_buf
;
2635 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
2637 /* leave_crit (); */
2639 /* Start a new nested message loop to process other messages until
2640 this one is completed. */
2641 w32_msg_pump (msg_buf
);
2643 deferred_msg_head
= msg_buf
->next
;
2645 return msg_buf
->result
;
2649 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
2651 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
2653 if (msg_buf
== NULL
)
2654 /* Message may have been cancelled, so don't abort. */
2657 msg_buf
->result
= result
;
2658 msg_buf
->completed
= 1;
2660 /* Ensure input thread is woken so it notices the completion. */
2661 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2665 cancel_all_deferred_msgs ()
2667 deferred_msg
* item
;
2669 /* Don't actually need synchronization for read access, since
2670 modification of single pointer is always atomic. */
2671 /* enter_crit (); */
2673 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2676 item
->completed
= 1;
2679 /* leave_crit (); */
2681 /* Ensure input thread is woken so it notices the completion. */
2682 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2686 w32_msg_worker (void *arg
)
2689 deferred_msg dummy_buf
;
2691 /* Ensure our message queue is created */
2693 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
2695 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2698 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
2699 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
2700 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
2702 /* This is the initial message loop which should only exit when the
2703 application quits. */
2704 w32_msg_pump (&dummy_buf
);
2710 signal_user_input ()
2712 /* Interrupt any lisp that wants to be interrupted by input. */
2713 if (!NILP (Vthrow_on_input
))
2715 Vquit_flag
= Vthrow_on_input
;
2716 /* If we're inside a function that wants immediate quits,
2718 if (immediate_quit
&& NILP (Vinhibit_quit
))
2728 post_character_message (hwnd
, msg
, wParam
, lParam
, modifiers
)
2738 wmsg
.dwModifiers
= modifiers
;
2740 /* Detect quit_char and set quit-flag directly. Note that we
2741 still need to post a message to ensure the main thread will be
2742 woken up if blocked in sys_select, but we do NOT want to post
2743 the quit_char message itself (because it will usually be as if
2744 the user had typed quit_char twice). Instead, we post a dummy
2745 message that has no particular effect. */
2748 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
2749 c
= make_ctrl_char (c
) & 0377;
2751 || (wmsg
.dwModifiers
== 0 &&
2752 w32_quit_key
&& wParam
== w32_quit_key
))
2756 /* The choice of message is somewhat arbitrary, as long as
2757 the main thread handler just ignores it. */
2760 /* Interrupt any blocking system calls. */
2763 /* As a safety precaution, forcibly complete any deferred
2764 messages. This is a kludge, but I don't see any particularly
2765 clean way to handle the situation where a deferred message is
2766 "dropped" in the lisp thread, and will thus never be
2767 completed, eg. by the user trying to activate the menubar
2768 when the lisp thread is busy, and then typing C-g when the
2769 menubar doesn't open promptly (with the result that the
2770 menubar never responds at all because the deferred
2771 WM_INITMENU message is never completed). Another problem
2772 situation is when the lisp thread calls SendMessage (to send
2773 a window manager command) when a message has been deferred;
2774 the lisp thread gets blocked indefinitely waiting for the
2775 deferred message to be completed, which itself is waiting for
2776 the lisp thread to respond.
2778 Note that we don't want to block the input thread waiting for
2779 a reponse from the lisp thread (although that would at least
2780 solve the deadlock problem above), because we want to be able
2781 to receive C-g to interrupt the lisp thread. */
2782 cancel_all_deferred_msgs ();
2785 signal_user_input ();
2788 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2791 /* Main window procedure */
2794 w32_wnd_proc (hwnd
, msg
, wParam
, lParam
)
2801 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
2803 int windows_translate
;
2806 /* Note that it is okay to call x_window_to_frame, even though we are
2807 not running in the main lisp thread, because frame deletion
2808 requires the lisp thread to synchronize with this thread. Thus, if
2809 a frame struct is returned, it can be used without concern that the
2810 lisp thread might make it disappear while we are using it.
2812 NB. Walking the frame list in this thread is safe (as long as
2813 writes of Lisp_Object slots are atomic, which they are on Windows).
2814 Although delete-frame can destructively modify the frame list while
2815 we are walking it, a garbage collection cannot occur until after
2816 delete-frame has synchronized with this thread.
2818 It is also safe to use functions that make GDI calls, such as
2819 w32_clear_rect, because these functions must obtain a DC handle
2820 from the frame struct using get_frame_dc which is thread-aware. */
2825 f
= x_window_to_frame (dpyinfo
, hwnd
);
2828 HDC hdc
= get_frame_dc (f
);
2829 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
2830 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
2831 release_frame_dc (f
, hdc
);
2833 #if defined (W32_DEBUG_DISPLAY)
2834 DebPrint (("WM_ERASEBKGND (frame %p): erasing %d,%d-%d,%d\n",
2836 wmsg
.rect
.left
, wmsg
.rect
.top
,
2837 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2838 #endif /* W32_DEBUG_DISPLAY */
2841 case WM_PALETTECHANGED
:
2842 /* ignore our own changes */
2843 if ((HWND
)wParam
!= hwnd
)
2845 f
= x_window_to_frame (dpyinfo
, hwnd
);
2847 /* get_frame_dc will realize our palette and force all
2848 frames to be redrawn if needed. */
2849 release_frame_dc (f
, get_frame_dc (f
));
2854 PAINTSTRUCT paintStruct
;
2856 bzero (&update_rect
, sizeof (update_rect
));
2858 f
= x_window_to_frame (dpyinfo
, hwnd
);
2861 DebPrint (("WM_PAINT received for unknown window %p\n", hwnd
));
2865 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
2866 fails. Apparently this can happen under some
2868 if (GetUpdateRect (hwnd
, &update_rect
, FALSE
) || !w32_strict_painting
)
2871 BeginPaint (hwnd
, &paintStruct
);
2873 /* The rectangles returned by GetUpdateRect and BeginPaint
2874 do not always match. Play it safe by assuming both areas
2876 UnionRect (&(wmsg
.rect
), &update_rect
, &(paintStruct
.rcPaint
));
2878 #if defined (W32_DEBUG_DISPLAY)
2879 DebPrint (("WM_PAINT (frame %p): painting %d,%d-%d,%d\n",
2881 wmsg
.rect
.left
, wmsg
.rect
.top
,
2882 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2883 DebPrint ((" [update region is %d,%d-%d,%d]\n",
2884 update_rect
.left
, update_rect
.top
,
2885 update_rect
.right
, update_rect
.bottom
));
2887 EndPaint (hwnd
, &paintStruct
);
2890 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2895 /* If GetUpdateRect returns 0 (meaning there is no update
2896 region), assume the whole window needs to be repainted. */
2897 GetClientRect (hwnd
, &wmsg
.rect
);
2898 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2902 case WM_INPUTLANGCHANGE
:
2903 /* Inform lisp thread of keyboard layout changes. */
2904 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2906 /* Clear dead keys in the keyboard state; for simplicity only
2907 preserve modifier key states. */
2912 GetKeyboardState (keystate
);
2913 for (i
= 0; i
< 256; i
++)
2930 SetKeyboardState (keystate
);
2935 /* Synchronize hot keys with normal input. */
2936 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
2941 record_keyup (wParam
, lParam
);
2946 /* Ignore keystrokes we fake ourself; see below. */
2947 if (dpyinfo
->faked_key
== wParam
)
2949 dpyinfo
->faked_key
= 0;
2950 /* Make sure TranslateMessage sees them though (as long as
2951 they don't produce WM_CHAR messages). This ensures that
2952 indicator lights are toggled promptly on Windows 9x, for
2954 if (wParam
< 256 && lispy_function_keys
[wParam
])
2956 windows_translate
= 1;
2962 /* Synchronize modifiers with current keystroke. */
2964 record_keydown (wParam
, lParam
);
2965 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
2967 windows_translate
= 0;
2972 if (NILP (Vw32_pass_lwindow_to_system
))
2974 /* Prevent system from acting on keyup (which opens the
2975 Start menu if no other key was pressed) by simulating a
2976 press of Space which we will ignore. */
2977 if (GetAsyncKeyState (wParam
) & 1)
2979 if (NUMBERP (Vw32_phantom_key_code
))
2980 key
= XUINT (Vw32_phantom_key_code
) & 255;
2983 dpyinfo
->faked_key
= key
;
2984 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
2987 if (!NILP (Vw32_lwindow_modifier
))
2991 if (NILP (Vw32_pass_rwindow_to_system
))
2993 if (GetAsyncKeyState (wParam
) & 1)
2995 if (NUMBERP (Vw32_phantom_key_code
))
2996 key
= XUINT (Vw32_phantom_key_code
) & 255;
2999 dpyinfo
->faked_key
= key
;
3000 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
3003 if (!NILP (Vw32_rwindow_modifier
))
3007 if (!NILP (Vw32_apps_modifier
))
3011 if (NILP (Vw32_pass_alt_to_system
))
3012 /* Prevent DefWindowProc from activating the menu bar if an
3013 Alt key is pressed and released by itself. */
3015 windows_translate
= 1;
3018 /* Decide whether to treat as modifier or function key. */
3019 if (NILP (Vw32_enable_caps_lock
))
3020 goto disable_lock_key
;
3021 windows_translate
= 1;
3024 /* Decide whether to treat as modifier or function key. */
3025 if (NILP (Vw32_enable_num_lock
))
3026 goto disable_lock_key
;
3027 windows_translate
= 1;
3030 /* Decide whether to treat as modifier or function key. */
3031 if (NILP (Vw32_scroll_lock_modifier
))
3032 goto disable_lock_key
;
3033 windows_translate
= 1;
3036 /* Ensure the appropriate lock key state (and indicator light)
3037 remains in the same state. We do this by faking another
3038 press of the relevant key. Apparently, this really is the
3039 only way to toggle the state of the indicator lights. */
3040 dpyinfo
->faked_key
= wParam
;
3041 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3042 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3043 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3044 KEYEVENTF_EXTENDEDKEY
| 0, 0);
3045 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3046 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3047 /* Ensure indicator lights are updated promptly on Windows 9x
3048 (TranslateMessage apparently does this), after forwarding
3050 post_character_message (hwnd
, msg
, wParam
, lParam
,
3051 w32_get_key_modifiers (wParam
, lParam
));
3052 windows_translate
= 1;
3056 case VK_PROCESSKEY
: /* Generated by IME. */
3057 windows_translate
= 1;
3060 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
3061 which is confusing for purposes of key binding; convert
3062 VK_CANCEL events into VK_PAUSE events. */
3066 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
3067 for purposes of key binding; convert these back into
3068 VK_NUMLOCK events, at least when we want to see NumLock key
3069 presses. (Note that there is never any possibility that
3070 VK_PAUSE with Ctrl really is C-Pause as per above.) */
3071 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
3072 wParam
= VK_NUMLOCK
;
3075 /* If not defined as a function key, change it to a WM_CHAR message. */
3076 if (wParam
> 255 || !lispy_function_keys
[wParam
])
3078 DWORD modifiers
= construct_console_modifiers ();
3080 if (!NILP (Vw32_recognize_altgr
)
3081 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
3083 /* Always let TranslateMessage handle AltGr key chords;
3084 for some reason, ToAscii doesn't always process AltGr
3085 chords correctly. */
3086 windows_translate
= 1;
3088 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
3090 /* Handle key chords including any modifiers other
3091 than shift directly, in order to preserve as much
3092 modifier information as possible. */
3093 if ('A' <= wParam
&& wParam
<= 'Z')
3095 /* Don't translate modified alphabetic keystrokes,
3096 so the user doesn't need to constantly switch
3097 layout to type control or meta keystrokes when
3098 the normal layout translates alphabetic
3099 characters to non-ascii characters. */
3100 if (!modifier_set (VK_SHIFT
))
3101 wParam
+= ('a' - 'A');
3106 /* Try to handle other keystrokes by determining the
3107 base character (ie. translating the base key plus
3111 KEY_EVENT_RECORD key
;
3113 key
.bKeyDown
= TRUE
;
3114 key
.wRepeatCount
= 1;
3115 key
.wVirtualKeyCode
= wParam
;
3116 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
3117 key
.uChar
.AsciiChar
= 0;
3118 key
.dwControlKeyState
= modifiers
;
3120 add
= w32_kbd_patch_key (&key
);
3121 /* 0 means an unrecognised keycode, negative means
3122 dead key. Ignore both. */
3125 /* Forward asciified character sequence. */
3126 post_character_message
3128 (unsigned char) key
.uChar
.AsciiChar
, lParam
,
3129 w32_get_key_modifiers (wParam
, lParam
));
3130 w32_kbd_patch_key (&key
);
3137 /* Let TranslateMessage handle everything else. */
3138 windows_translate
= 1;
3144 if (windows_translate
)
3146 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
3147 windows_msg
.time
= GetMessageTime ();
3148 TranslateMessage (&windows_msg
);
3156 post_character_message (hwnd
, msg
, wParam
, lParam
,
3157 w32_get_key_modifiers (wParam
, lParam
));
3161 /* WM_UNICHAR looks promising from the docs, but the exact
3162 circumstances in which TranslateMessage sends it is one of those
3163 Microsoft secret API things that EU and US courts are supposed
3164 to have put a stop to already. Spy++ shows it being sent to Notepad
3165 and other MS apps, but never to Emacs.
3167 Some third party IMEs send it in accordance with the official
3168 documentation though, so handle it here.
3170 UNICODE_NOCHAR is used to test for support for this message.
3171 TRUE indicates that the message is supported. */
3172 if (wParam
== UNICODE_NOCHAR
)
3177 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3178 signal_user_input ();
3179 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3184 /* If we can't get the IME result as unicode, use default processing,
3185 which will at least allow characters decodable in the system locale
3187 if (!get_composition_string_fn
)
3190 else if (!ignore_ime_char
)
3195 HIMC context
= get_ime_context_fn (hwnd
);
3196 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3197 /* Get buffer size. */
3198 size
= get_composition_string_fn (context
, GCS_RESULTSTR
, buffer
, 0);
3199 buffer
= alloca(size
);
3200 size
= get_composition_string_fn (context
, GCS_RESULTSTR
,
3202 signal_user_input ();
3203 for (i
= 0; i
< size
/ sizeof (wchar_t); i
++)
3205 my_post_msg (&wmsg
, hwnd
, WM_UNICHAR
, (WPARAM
) buffer
[i
],
3208 /* We output the whole string above, so ignore following ones
3209 until we are notified of the end of composition. */
3210 ignore_ime_char
= 1;
3214 case WM_IME_ENDCOMPOSITION
:
3215 ignore_ime_char
= 0;
3218 /* Simulate middle mouse button events when left and right buttons
3219 are used together, but only if user has two button mouse. */
3220 case WM_LBUTTONDOWN
:
3221 case WM_RBUTTONDOWN
:
3222 if (w32_num_mouse_buttons
> 2)
3223 goto handle_plain_button
;
3226 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
3227 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
3229 if (button_state
& this)
3232 if (button_state
== 0)
3235 button_state
|= this;
3237 if (button_state
& other
)
3239 if (mouse_button_timer
)
3241 KillTimer (hwnd
, mouse_button_timer
);
3242 mouse_button_timer
= 0;
3244 /* Generate middle mouse event instead. */
3245 msg
= WM_MBUTTONDOWN
;
3246 button_state
|= MMOUSE
;
3248 else if (button_state
& MMOUSE
)
3250 /* Ignore button event if we've already generated a
3251 middle mouse down event. This happens if the
3252 user releases and press one of the two buttons
3253 after we've faked a middle mouse event. */
3258 /* Flush out saved message. */
3259 post_msg (&saved_mouse_button_msg
);
3261 wmsg
.dwModifiers
= w32_get_modifiers ();
3262 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3263 signal_user_input ();
3265 /* Clear message buffer. */
3266 saved_mouse_button_msg
.msg
.hwnd
= 0;
3270 /* Hold onto message for now. */
3271 mouse_button_timer
=
3272 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
3273 w32_mouse_button_tolerance
, NULL
);
3274 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
3275 saved_mouse_button_msg
.msg
.message
= msg
;
3276 saved_mouse_button_msg
.msg
.wParam
= wParam
;
3277 saved_mouse_button_msg
.msg
.lParam
= lParam
;
3278 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
3279 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
3286 if (w32_num_mouse_buttons
> 2)
3287 goto handle_plain_button
;
3290 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
3291 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
3293 if ((button_state
& this) == 0)
3296 button_state
&= ~this;
3298 if (button_state
& MMOUSE
)
3300 /* Only generate event when second button is released. */
3301 if ((button_state
& other
) == 0)
3304 button_state
&= ~MMOUSE
;
3306 if (button_state
) abort ();
3313 /* Flush out saved message if necessary. */
3314 if (saved_mouse_button_msg
.msg
.hwnd
)
3316 post_msg (&saved_mouse_button_msg
);
3319 wmsg
.dwModifiers
= w32_get_modifiers ();
3320 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3321 signal_user_input ();
3323 /* Always clear message buffer and cancel timer. */
3324 saved_mouse_button_msg
.msg
.hwnd
= 0;
3325 KillTimer (hwnd
, mouse_button_timer
);
3326 mouse_button_timer
= 0;
3328 if (button_state
== 0)
3333 case WM_XBUTTONDOWN
:
3335 if (w32_pass_extra_mouse_buttons_to_system
)
3337 /* else fall through and process them. */
3338 case WM_MBUTTONDOWN
:
3340 handle_plain_button
:
3345 /* Ignore middle and extra buttons as long as the menu is active. */
3346 f
= x_window_to_frame (dpyinfo
, hwnd
);
3347 if (f
&& f
->output_data
.w32
->menubar_active
)
3350 if (parse_button (msg
, HIWORD (wParam
), &button
, &up
))
3352 if (up
) ReleaseCapture ();
3353 else SetCapture (hwnd
);
3354 button
= (button
== 0) ? LMOUSE
:
3355 ((button
== 1) ? MMOUSE
: RMOUSE
);
3357 button_state
&= ~button
;
3359 button_state
|= button
;
3363 wmsg
.dwModifiers
= w32_get_modifiers ();
3364 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3365 signal_user_input ();
3367 /* Need to return true for XBUTTON messages, false for others,
3368 to indicate that we processed the message. */
3369 return (msg
== WM_XBUTTONDOWN
|| msg
== WM_XBUTTONUP
);
3372 /* Ignore mouse movements as long as the menu is active. These
3373 movements are processed by the window manager anyway, and
3374 it's wrong to handle them as if they happened on the
3375 underlying frame. */
3376 f
= x_window_to_frame (dpyinfo
, hwnd
);
3377 if (f
&& f
->output_data
.w32
->menubar_active
)
3380 /* If the mouse has just moved into the frame, start tracking
3381 it, so we will be notified when it leaves the frame. Mouse
3382 tracking only works under W98 and NT4 and later. On earlier
3383 versions, there is no way of telling when the mouse leaves the
3384 frame, so we just have to put up with help-echo and mouse
3385 highlighting remaining while the frame is not active. */
3386 if (track_mouse_event_fn
&& !track_mouse_window
)
3388 TRACKMOUSEEVENT tme
;
3389 tme
.cbSize
= sizeof (tme
);
3390 tme
.dwFlags
= TME_LEAVE
;
3391 tme
.hwndTrack
= hwnd
;
3393 track_mouse_event_fn (&tme
);
3394 track_mouse_window
= hwnd
;
3397 if (w32_mouse_move_interval
<= 0
3398 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
3400 wmsg
.dwModifiers
= w32_get_modifiers ();
3401 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3405 /* Hang onto mouse move and scroll messages for a bit, to avoid
3406 sending such events to Emacs faster than it can process them.
3407 If we get more events before the timer from the first message
3408 expires, we just replace the first message. */
3410 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
3412 SetTimer (hwnd
, MOUSE_MOVE_ID
,
3413 w32_mouse_move_interval
, NULL
);
3415 /* Hold onto message for now. */
3416 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
3417 saved_mouse_move_msg
.msg
.message
= msg
;
3418 saved_mouse_move_msg
.msg
.wParam
= wParam
;
3419 saved_mouse_move_msg
.msg
.lParam
= lParam
;
3420 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
3421 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
3427 wmsg
.dwModifiers
= w32_get_modifiers ();
3428 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3429 signal_user_input ();
3433 if (w32_pass_multimedia_buttons_to_system
)
3435 /* Otherwise, pass to lisp, the same way we do with mousehwheel. */
3436 case WM_MOUSEHWHEEL
:
3437 wmsg
.dwModifiers
= w32_get_modifiers ();
3438 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3439 signal_user_input ();
3440 /* Non-zero must be returned when WM_MOUSEHWHEEL messages are
3441 handled, to prevent the system trying to handle it by faking
3442 scroll bar events. */
3446 /* Flush out saved messages if necessary. */
3447 if (wParam
== mouse_button_timer
)
3449 if (saved_mouse_button_msg
.msg
.hwnd
)
3451 post_msg (&saved_mouse_button_msg
);
3452 signal_user_input ();
3453 saved_mouse_button_msg
.msg
.hwnd
= 0;
3455 KillTimer (hwnd
, mouse_button_timer
);
3456 mouse_button_timer
= 0;
3458 else if (wParam
== mouse_move_timer
)
3460 if (saved_mouse_move_msg
.msg
.hwnd
)
3462 post_msg (&saved_mouse_move_msg
);
3463 saved_mouse_move_msg
.msg
.hwnd
= 0;
3465 KillTimer (hwnd
, mouse_move_timer
);
3466 mouse_move_timer
= 0;
3468 else if (wParam
== menu_free_timer
)
3470 KillTimer (hwnd
, menu_free_timer
);
3471 menu_free_timer
= 0;
3472 f
= x_window_to_frame (dpyinfo
, hwnd
);
3473 /* If a popup menu is active, don't wipe its strings. */
3475 && current_popup_menu
== NULL
)
3477 /* Free memory used by owner-drawn and help-echo strings. */
3478 w32_free_menu_strings (hwnd
);
3479 f
->output_data
.w32
->menubar_active
= 0;
3483 else if (wParam
== hourglass_timer
)
3485 KillTimer (hwnd
, hourglass_timer
);
3486 hourglass_timer
= 0;
3487 show_hourglass (x_window_to_frame (dpyinfo
, hwnd
));
3492 /* Windows doesn't send us focus messages when putting up and
3493 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
3494 The only indication we get that something happened is receiving
3495 this message afterwards. So this is a good time to reset our
3496 keyboard modifiers' state. */
3503 /* We must ensure menu bar is fully constructed and up to date
3504 before allowing user interaction with it. To achieve this
3505 we send this message to the lisp thread and wait for a
3506 reply (whose value is not actually needed) to indicate that
3507 the menu bar is now ready for use, so we can now return.
3509 To remain responsive in the meantime, we enter a nested message
3510 loop that can process all other messages.
3512 However, we skip all this if the message results from calling
3513 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
3514 thread a message because it is blocked on us at this point. We
3515 set menubar_active before calling TrackPopupMenu to indicate
3516 this (there is no possibility of confusion with real menubar
3519 f
= x_window_to_frame (dpyinfo
, hwnd
);
3521 && (f
->output_data
.w32
->menubar_active
3522 /* We can receive this message even in the absence of a
3523 menubar (ie. when the system menu is activated) - in this
3524 case we do NOT want to forward the message, otherwise it
3525 will cause the menubar to suddenly appear when the user
3526 had requested it to be turned off! */
3527 || f
->output_data
.w32
->menubar_widget
== NULL
))
3531 deferred_msg msg_buf
;
3533 /* Detect if message has already been deferred; in this case
3534 we cannot return any sensible value to ignore this. */
3535 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3540 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
3543 case WM_EXITMENULOOP
:
3544 f
= x_window_to_frame (dpyinfo
, hwnd
);
3546 /* If a menu is still active, check again after a short delay,
3547 since Windows often (always?) sends the WM_EXITMENULOOP
3548 before the corresponding WM_COMMAND message.
3549 Don't do this if a popup menu is active, since it is only
3550 menubar menus that require cleaning up in this way.
3552 if (f
&& menubar_in_use
&& current_popup_menu
== NULL
)
3553 menu_free_timer
= SetTimer (hwnd
, MENU_FREE_ID
, MENU_FREE_DELAY
, NULL
);
3555 /* If hourglass cursor should be displayed, display it now. */
3556 if (f
&& f
->output_data
.w32
->hourglass_p
)
3557 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
3562 /* Direct handling of help_echo in menus. Should be safe now
3563 that we generate the help_echo by placing a help event in the
3566 HMENU menu
= (HMENU
) lParam
;
3567 UINT menu_item
= (UINT
) LOWORD (wParam
);
3568 UINT flags
= (UINT
) HIWORD (wParam
);
3570 w32_menu_display_help (hwnd
, menu
, menu_item
, flags
);
3574 case WM_MEASUREITEM
:
3575 f
= x_window_to_frame (dpyinfo
, hwnd
);
3578 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
3580 if (pMis
->CtlType
== ODT_MENU
)
3582 /* Work out dimensions for popup menu titles. */
3583 char * title
= (char *) pMis
->itemData
;
3584 HDC hdc
= GetDC (hwnd
);
3585 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3586 LOGFONT menu_logfont
;
3590 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3591 menu_logfont
.lfWeight
= FW_BOLD
;
3592 menu_font
= CreateFontIndirect (&menu_logfont
);
3593 old_font
= SelectObject (hdc
, menu_font
);
3595 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
3598 if (unicode_append_menu
)
3599 GetTextExtentPoint32W (hdc
, (WCHAR
*) title
,
3600 wcslen ((WCHAR
*) title
),
3603 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
3605 pMis
->itemWidth
= size
.cx
;
3606 if (pMis
->itemHeight
< size
.cy
)
3607 pMis
->itemHeight
= size
.cy
;
3610 pMis
->itemWidth
= 0;
3612 SelectObject (hdc
, old_font
);
3613 DeleteObject (menu_font
);
3614 ReleaseDC (hwnd
, hdc
);
3621 f
= x_window_to_frame (dpyinfo
, hwnd
);
3624 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
3626 if (pDis
->CtlType
== ODT_MENU
)
3628 /* Draw popup menu title. */
3629 char * title
= (char *) pDis
->itemData
;
3632 HDC hdc
= pDis
->hDC
;
3633 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3634 LOGFONT menu_logfont
;
3637 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3638 menu_logfont
.lfWeight
= FW_BOLD
;
3639 menu_font
= CreateFontIndirect (&menu_logfont
);
3640 old_font
= SelectObject (hdc
, menu_font
);
3642 /* Always draw title as if not selected. */
3643 if (unicode_append_menu
)
3646 + GetSystemMetrics (SM_CXMENUCHECK
),
3648 ETO_OPAQUE
, &pDis
->rcItem
,
3650 wcslen ((WCHAR
*) title
), NULL
);
3654 + GetSystemMetrics (SM_CXMENUCHECK
),
3656 ETO_OPAQUE
, &pDis
->rcItem
,
3657 title
, strlen (title
), NULL
);
3659 SelectObject (hdc
, old_font
);
3660 DeleteObject (menu_font
);
3668 /* Still not right - can't distinguish between clicks in the
3669 client area of the frame from clicks forwarded from the scroll
3670 bars - may have to hook WM_NCHITTEST to remember the mouse
3671 position and then check if it is in the client area ourselves. */
3672 case WM_MOUSEACTIVATE
:
3673 /* Discard the mouse click that activates a frame, allowing the
3674 user to click anywhere without changing point (or worse!).
3675 Don't eat mouse clicks on scrollbars though!! */
3676 if (LOWORD (lParam
) == HTCLIENT
)
3677 return MA_ACTIVATEANDEAT
;
3682 /* No longer tracking mouse. */
3683 track_mouse_window
= NULL
;
3685 case WM_ACTIVATEAPP
:
3687 case WM_WINDOWPOSCHANGED
:
3689 /* Inform lisp thread that a frame might have just been obscured
3690 or exposed, so should recheck visibility of all frames. */
3691 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3695 dpyinfo
->faked_key
= 0;
3697 register_hot_keys (hwnd
);
3700 unregister_hot_keys (hwnd
);
3703 /* Relinquish the system caret. */
3704 if (w32_system_caret_hwnd
)
3706 w32_visible_system_caret_hwnd
= NULL
;
3707 w32_system_caret_hwnd
= NULL
;
3713 f
= x_window_to_frame (dpyinfo
, hwnd
);
3714 if (f
&& HIWORD (wParam
) == 0)
3716 if (menu_free_timer
)
3718 KillTimer (hwnd
, menu_free_timer
);
3719 menu_free_timer
= 0;
3725 wmsg
.dwModifiers
= w32_get_modifiers ();
3726 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3734 wmsg
.dwModifiers
= w32_get_modifiers ();
3735 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3738 case WM_WINDOWPOSCHANGING
:
3739 /* Don't restrict the sizing of tip frames. */
3740 if (hwnd
== tip_window
)
3744 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
3746 wp
.length
= sizeof (WINDOWPLACEMENT
);
3747 GetWindowPlacement (hwnd
, &wp
);
3749 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
3756 DWORD internal_border
;
3757 DWORD scrollbar_extra
;
3760 wp
.length
= sizeof (wp
);
3761 GetWindowRect (hwnd
, &wr
);
3765 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
3766 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
3767 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
3768 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
3772 memset (&rect
, 0, sizeof (rect
));
3773 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
3774 GetMenu (hwnd
) != NULL
);
3776 /* Force width and height of client area to be exact
3777 multiples of the character cell dimensions. */
3778 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
3779 - 2 * internal_border
- scrollbar_extra
)
3781 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
3782 - 2 * internal_border
)
3787 /* For right/bottom sizing we can just fix the sizes.
3788 However for top/left sizing we will need to fix the X
3789 and Y positions as well. */
3791 int cx_mintrack
= GetSystemMetrics (SM_CXMINTRACK
);
3792 int cy_mintrack
= GetSystemMetrics (SM_CYMINTRACK
);
3794 lppos
->cx
= max (lppos
->cx
- wdiff
, cx_mintrack
);
3795 lppos
->cy
= max (lppos
->cy
- hdiff
, cy_mintrack
);
3797 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
3798 && (lppos
->flags
& SWP_NOMOVE
) == 0)
3800 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
3807 lppos
->flags
|= SWP_NOMOVE
;
3818 case WM_GETMINMAXINFO
:
3819 /* Hack to allow resizing the Emacs frame above the screen size.
3820 Note that Windows 9x limits coordinates to 16-bits. */
3821 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.x
= 32767;
3822 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.y
= 32767;
3826 if (LOWORD (lParam
) == HTCLIENT
)
3828 f
= x_window_to_frame (dpyinfo
, hwnd
);
3829 if (f
->output_data
.w32
->hourglass_p
&& !menubar_in_use
3830 && !current_popup_menu
)
3831 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
3833 SetCursor (f
->output_data
.w32
->current_cursor
);
3838 case WM_EMACS_SETCURSOR
:
3840 Cursor cursor
= (Cursor
) wParam
;
3841 f
= x_window_to_frame (dpyinfo
, hwnd
);
3844 f
->output_data
.w32
->current_cursor
= cursor
;
3845 if (!f
->output_data
.w32
->hourglass_p
)
3851 case WM_EMACS_CREATESCROLLBAR
:
3852 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
3853 (struct scroll_bar
*) lParam
);
3855 case WM_EMACS_SHOWWINDOW
:
3856 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
3858 case WM_EMACS_SETFOREGROUND
:
3860 HWND foreground_window
;
3861 DWORD foreground_thread
, retval
;
3863 /* On NT 5.0, and apparently Windows 98, it is necessary to
3864 attach to the thread that currently has focus in order to
3865 pull the focus away from it. */
3866 foreground_window
= GetForegroundWindow ();
3867 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
3868 if (!foreground_window
3869 || foreground_thread
== GetCurrentThreadId ()
3870 || !AttachThreadInput (GetCurrentThreadId (),
3871 foreground_thread
, TRUE
))
3872 foreground_thread
= 0;
3874 retval
= SetForegroundWindow ((HWND
) wParam
);
3876 /* Detach from the previous foreground thread. */
3877 if (foreground_thread
)
3878 AttachThreadInput (GetCurrentThreadId (),
3879 foreground_thread
, FALSE
);
3884 case WM_EMACS_SETWINDOWPOS
:
3886 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
3887 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
3888 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
3891 case WM_EMACS_DESTROYWINDOW
:
3892 DragAcceptFiles ((HWND
) wParam
, FALSE
);
3893 return DestroyWindow ((HWND
) wParam
);
3895 case WM_EMACS_HIDE_CARET
:
3896 return HideCaret (hwnd
);
3898 case WM_EMACS_SHOW_CARET
:
3899 return ShowCaret (hwnd
);
3901 case WM_EMACS_DESTROY_CARET
:
3902 w32_system_caret_hwnd
= NULL
;
3903 w32_visible_system_caret_hwnd
= NULL
;
3904 return DestroyCaret ();
3906 case WM_EMACS_TRACK_CARET
:
3907 /* If there is currently no system caret, create one. */
3908 if (w32_system_caret_hwnd
== NULL
)
3910 /* Use the default caret width, and avoid changing it
3911 unneccesarily, as it confuses screen reader software. */
3912 w32_system_caret_hwnd
= hwnd
;
3913 CreateCaret (hwnd
, NULL
, 0,
3914 w32_system_caret_height
);
3917 if (!SetCaretPos (w32_system_caret_x
, w32_system_caret_y
))
3919 /* Ensure visible caret gets turned on when requested. */
3920 else if (w32_use_visible_system_caret
3921 && w32_visible_system_caret_hwnd
!= hwnd
)
3923 w32_visible_system_caret_hwnd
= hwnd
;
3924 return ShowCaret (hwnd
);
3926 /* Ensure visible caret gets turned off when requested. */
3927 else if (!w32_use_visible_system_caret
3928 && w32_visible_system_caret_hwnd
)
3930 w32_visible_system_caret_hwnd
= NULL
;
3931 return HideCaret (hwnd
);
3936 case WM_EMACS_TRACKPOPUPMENU
:
3941 pos
= (POINT
*)lParam
;
3942 flags
= TPM_CENTERALIGN
;
3943 if (button_state
& LMOUSE
)
3944 flags
|= TPM_LEFTBUTTON
;
3945 else if (button_state
& RMOUSE
)
3946 flags
|= TPM_RIGHTBUTTON
;
3948 /* Remember we did a SetCapture on the initial mouse down event,
3949 so for safety, we make sure the capture is cancelled now. */
3953 /* Use menubar_active to indicate that WM_INITMENU is from
3954 TrackPopupMenu below, and should be ignored. */
3955 f
= x_window_to_frame (dpyinfo
, hwnd
);
3957 f
->output_data
.w32
->menubar_active
= 1;
3959 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
3963 /* Eat any mouse messages during popupmenu */
3964 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
3966 /* Get the menu selection, if any */
3967 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
3969 retval
= LOWORD (amsg
.wParam
);
3985 /* Check for messages registered at runtime. */
3986 if (msg
== msh_mousewheel
)
3988 wmsg
.dwModifiers
= w32_get_modifiers ();
3989 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3990 signal_user_input ();
3995 return DefWindowProc (hwnd
, msg
, wParam
, lParam
);
3999 /* The most common default return code for handled messages is 0. */
4004 my_create_window (f
)
4009 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
4011 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
4015 /* Create a tooltip window. Unlike my_create_window, we do not do this
4016 indirectly via the Window thread, as we do not need to process Window
4017 messages for the tooltip. Creating tooltips indirectly also creates
4018 deadlocks when tooltips are created for menu items. */
4020 my_create_tip_window (f
)
4025 rect
.left
= rect
.top
= 0;
4026 rect
.right
= FRAME_PIXEL_WIDTH (f
);
4027 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
4029 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
4030 FRAME_EXTERNAL_MENU_BAR (f
));
4032 tip_window
= FRAME_W32_WINDOW (f
)
4033 = CreateWindow (EMACS_CLASS
,
4035 f
->output_data
.w32
->dwStyle
,
4038 rect
.right
- rect
.left
,
4039 rect
.bottom
- rect
.top
,
4040 FRAME_W32_WINDOW (SELECTED_FRAME ()), /* owner */
4047 SetWindowLong (tip_window
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
4048 SetWindowLong (tip_window
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
4049 SetWindowLong (tip_window
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
4050 SetWindowLong (tip_window
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
4052 /* Tip frames have no scrollbars. */
4053 SetWindowLong (tip_window
, WND_SCROLLBAR_INDEX
, 0);
4055 /* Do this to discard the default setting specified by our parent. */
4056 ShowWindow (tip_window
, SW_HIDE
);
4061 /* Create and set up the w32 window for frame F. */
4064 w32_window (f
, window_prompting
, minibuffer_only
)
4066 long window_prompting
;
4067 int minibuffer_only
;
4071 /* Use the resource name as the top-level window name
4072 for looking up resources. Make a non-Lisp copy
4073 for the window manager, so GC relocation won't bother it.
4075 Elsewhere we specify the window name for the window manager. */
4078 char *str
= (char *) SDATA (Vx_resource_name
);
4079 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
4080 strcpy (f
->namebuf
, str
);
4083 my_create_window (f
);
4085 validate_x_resource_name ();
4087 /* x_set_name normally ignores requests to set the name if the
4088 requested name is the same as the current name. This is the one
4089 place where that assumption isn't correct; f->name is set, but
4090 the server hasn't been told. */
4093 int explicit = f
->explicit_name
;
4095 f
->explicit_name
= 0;
4098 x_set_name (f
, name
, explicit);
4103 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
4104 initialize_frame_menubar (f
);
4106 if (FRAME_W32_WINDOW (f
) == 0)
4107 error ("Unable to create window");
4110 /* Handle the icon stuff for this window. Perhaps later we might
4111 want an x_set_icon_position which can be called interactively as
4119 Lisp_Object icon_x
, icon_y
;
4120 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
4122 /* Set the position of the icon. Note that Windows 95 groups all
4123 icons in the tray. */
4124 icon_x
= x_get_arg (dpyinfo
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
4125 icon_y
= x_get_arg (dpyinfo
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
4126 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
4128 CHECK_NUMBER (icon_x
);
4129 CHECK_NUMBER (icon_y
);
4131 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
4132 error ("Both left and top icon corners of icon must be specified");
4136 if (! EQ (icon_x
, Qunbound
))
4137 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
4140 /* Start up iconic or window? */
4141 x_wm_set_window_state
4142 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
4146 x_text_icon (f
, (char *) SDATA ((!NILP (f
->icon_name
)
4159 XGCValues gc_values
;
4163 /* Create the GC's of this frame.
4164 Note that many default values are used. */
4167 gc_values
.font
= FRAME_FONT (f
);
4169 /* Cursor has cursor-color background, background-color foreground. */
4170 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
4171 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
4172 f
->output_data
.w32
->cursor_gc
4173 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
4174 (GCFont
| GCForeground
| GCBackground
),
4178 f
->output_data
.w32
->white_relief
.gc
= 0;
4179 f
->output_data
.w32
->black_relief
.gc
= 0;
4185 /* Handler for signals raised during x_create_frame and
4186 x_create_top_frame. FRAME is the frame which is partially
4190 unwind_create_frame (frame
)
4193 struct frame
*f
= XFRAME (frame
);
4195 /* If frame is ``official'', nothing to do. */
4196 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
4199 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4202 x_free_frame_resources (f
);
4204 /* Check that reference counts are indeed correct. */
4205 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
4206 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
4215 x_default_font_parameter (f
, parms
)
4219 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4220 Lisp_Object font_param
= x_get_arg (dpyinfo
, parms
, Qfont
, NULL
, NULL
,
4223 if (EQ (font_param
, Qunbound
))
4225 font
= !NILP (font_param
) ? font_param
4226 : x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4228 if (!STRINGP (font
))
4231 static char *names
[]
4232 = { "Courier New-10",
4233 "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1",
4234 "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1",
4238 for (i
= 0; names
[i
]; i
++)
4240 font
= font_open_by_name (f
, names
[i
]);
4245 error ("No suitable font was found");
4247 else if (!NILP (font_param
))
4249 /* Remember the explicit font parameter, so we can re-apply it after
4250 we've applied the `default' face settings. */
4251 x_set_frame_parameters (f
, Fcons (Fcons (Qfont_param
, font_param
), Qnil
));
4253 x_default_parameter (f
, parms
, Qfont
, font
, "font", "Font", RES_TYPE_STRING
);
4256 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
4258 doc
: /* Make a new window, which is called a \"frame\" in Emacs terms.
4259 Return an Emacs frame object.
4260 PARAMETERS is an alist of frame parameters.
4261 If the parameters specify that the frame should not have a minibuffer,
4262 and do not specify a specific minibuffer window to use,
4263 then `default-minibuffer-frame' must be a frame whose minibuffer can
4264 be shared by the new frame.
4266 This function is an internal primitive--use `make-frame' instead. */)
4268 Lisp_Object parameters
;
4271 Lisp_Object frame
, tem
;
4273 int minibuffer_only
= 0;
4274 long window_prompting
= 0;
4276 int count
= SPECPDL_INDEX ();
4277 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4278 Lisp_Object display
;
4279 struct w32_display_info
*dpyinfo
= NULL
;
4283 /* Make copy of frame parameters because the original is in pure
4285 parameters
= Fcopy_alist (parameters
);
4287 /* Use this general default value to start with
4288 until we know if this frame has a specified name. */
4289 Vx_resource_name
= Vinvocation_name
;
4291 display
= x_get_arg (dpyinfo
, parameters
, Qterminal
, 0, 0, RES_TYPE_NUMBER
);
4292 if (EQ (display
, Qunbound
))
4293 display
= x_get_arg (dpyinfo
, parameters
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
4294 if (EQ (display
, Qunbound
))
4296 dpyinfo
= check_x_display_info (display
);
4298 kb
= dpyinfo
->terminal
->kboard
;
4300 kb
= &the_only_kboard
;
4303 if (!dpyinfo
->terminal
->name
)
4304 error ("Terminal is not live, can't create new frames on it");
4306 name
= x_get_arg (dpyinfo
, parameters
, Qname
, "name", "Name", RES_TYPE_STRING
);
4308 && ! EQ (name
, Qunbound
)
4310 error ("Invalid frame name--not a string or nil");
4313 Vx_resource_name
= name
;
4315 /* See if parent window is specified. */
4316 parent
= x_get_arg (dpyinfo
, parameters
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
4317 if (EQ (parent
, Qunbound
))
4319 if (! NILP (parent
))
4320 CHECK_NUMBER (parent
);
4322 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
4323 /* No need to protect DISPLAY because that's not used after passing
4324 it to make_frame_without_minibuffer. */
4326 GCPRO4 (parameters
, parent
, name
, frame
);
4327 tem
= x_get_arg (dpyinfo
, parameters
, Qminibuffer
, "minibuffer", "Minibuffer",
4329 if (EQ (tem
, Qnone
) || NILP (tem
))
4330 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
4331 else if (EQ (tem
, Qonly
))
4333 f
= make_minibuffer_frame ();
4334 minibuffer_only
= 1;
4336 else if (WINDOWP (tem
))
4337 f
= make_frame_without_minibuffer (tem
, kb
, display
);
4341 XSETFRAME (frame
, f
);
4343 /* Note that Windows does support scroll bars. */
4344 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
4346 /* By default, make scrollbars the system standard width. */
4347 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
4349 f
->terminal
= dpyinfo
->terminal
;
4350 f
->terminal
->reference_count
++;
4352 f
->output_method
= output_w32
;
4353 f
->output_data
.w32
=
4354 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
4355 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
4356 FRAME_FONTSET (f
) = -1;
4357 record_unwind_protect (unwind_create_frame
, frame
);
4360 = x_get_arg (dpyinfo
, parameters
, Qicon_name
, "iconName", "Title",
4362 if (! STRINGP (f
->icon_name
))
4363 f
->icon_name
= Qnil
;
4365 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
4367 /* With FRAME_X_DISPLAY_INFO set up, this unwind-protect is safe. */
4368 record_unwind_protect (unwind_create_frame
, frame
);
4370 image_cache_refcount
= FRAME_IMAGE_CACHE (f
)->refcount
;
4371 dpyinfo_refcount
= dpyinfo
->reference_count
;
4372 #endif /* GLYPH_DEBUG */
4374 /* Specify the parent under which to make this window. */
4378 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
4379 f
->output_data
.w32
->explicit_parent
= 1;
4383 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4384 f
->output_data
.w32
->explicit_parent
= 0;
4387 /* Set the name; the functions to which we pass f expect the name to
4389 if (EQ (name
, Qunbound
) || NILP (name
))
4391 f
->name
= build_string (dpyinfo
->w32_id_name
);
4392 f
->explicit_name
= 0;
4397 f
->explicit_name
= 1;
4398 /* use the frame's title when getting resources for this frame. */
4399 specbind (Qx_resource_name
, name
);
4402 f
->resx
= dpyinfo
->resx
;
4403 f
->resy
= dpyinfo
->resy
;
4405 if (uniscribe_available
)
4406 register_font_driver (&uniscribe_font_driver
, f
);
4407 register_font_driver (&w32font_driver
, f
);
4409 x_default_parameter (f
, parameters
, Qfont_backend
, Qnil
,
4410 "fontBackend", "FontBackend", RES_TYPE_STRING
);
4411 /* Extract the window parameters from the supplied values
4412 that are needed to determine window geometry. */
4413 x_default_font_parameter (f
, parameters
);
4414 x_default_parameter (f
, parameters
, Qborder_width
, make_number (2),
4415 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4417 /* We recognize either internalBorderWidth or internalBorder
4418 (which is what xterm calls it). */
4419 if (NILP (Fassq (Qinternal_border_width
, parameters
)))
4423 value
= x_get_arg (dpyinfo
, parameters
, Qinternal_border_width
,
4424 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
4425 if (! EQ (value
, Qunbound
))
4426 parameters
= Fcons (Fcons (Qinternal_border_width
, value
),
4429 /* Default internalBorderWidth to 0 on Windows to match other programs. */
4430 x_default_parameter (f
, parameters
, Qinternal_border_width
, make_number (0),
4431 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
4432 x_default_parameter (f
, parameters
, Qvertical_scroll_bars
, Qright
,
4433 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
4435 /* Also do the stuff which must be set before the window exists. */
4436 x_default_parameter (f
, parameters
, Qforeground_color
, build_string ("black"),
4437 "foreground", "Foreground", RES_TYPE_STRING
);
4438 x_default_parameter (f
, parameters
, Qbackground_color
, build_string ("white"),
4439 "background", "Background", RES_TYPE_STRING
);
4440 x_default_parameter (f
, parameters
, Qmouse_color
, build_string ("black"),
4441 "pointerColor", "Foreground", RES_TYPE_STRING
);
4442 x_default_parameter (f
, parameters
, Qcursor_color
, build_string ("black"),
4443 "cursorColor", "Foreground", RES_TYPE_STRING
);
4444 x_default_parameter (f
, parameters
, Qborder_color
, build_string ("black"),
4445 "borderColor", "BorderColor", RES_TYPE_STRING
);
4446 x_default_parameter (f
, parameters
, Qscreen_gamma
, Qnil
,
4447 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
4448 x_default_parameter (f
, parameters
, Qline_spacing
, Qnil
,
4449 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
4450 x_default_parameter (f
, parameters
, Qleft_fringe
, Qnil
,
4451 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
4452 x_default_parameter (f
, parameters
, Qright_fringe
, Qnil
,
4453 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
4456 /* Init faces before x_default_parameter is called for scroll-bar
4457 parameters because that function calls x_set_scroll_bar_width,
4458 which calls change_frame_size, which calls Fset_window_buffer,
4459 which runs hooks, which call Fvertical_motion. At the end, we
4460 end up in init_iterator with a null face cache, which should not
4462 init_frame_faces (f
);
4464 x_default_parameter (f
, parameters
, Qmenu_bar_lines
, make_number (1),
4465 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
4466 x_default_parameter (f
, parameters
, Qtool_bar_lines
, make_number (1),
4467 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
4469 x_default_parameter (f
, parameters
, Qbuffer_predicate
, Qnil
,
4470 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
4471 x_default_parameter (f
, parameters
, Qtitle
, Qnil
,
4472 "title", "Title", RES_TYPE_STRING
);
4473 x_default_parameter (f
, parameters
, Qfullscreen
, Qnil
,
4474 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
4476 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
4477 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4479 f
->output_data
.w32
->text_cursor
= w32_load_cursor (IDC_IBEAM
);
4480 f
->output_data
.w32
->nontext_cursor
= w32_load_cursor (IDC_ARROW
);
4481 f
->output_data
.w32
->modeline_cursor
= w32_load_cursor (IDC_ARROW
);
4482 f
->output_data
.w32
->hand_cursor
= w32_load_cursor (IDC_HAND
);
4483 f
->output_data
.w32
->hourglass_cursor
= w32_load_cursor (IDC_WAIT
);
4484 f
->output_data
.w32
->horizontal_drag_cursor
= w32_load_cursor (IDC_SIZEWE
);
4486 f
->output_data
.w32
->current_cursor
= f
->output_data
.w32
->nontext_cursor
;
4488 window_prompting
= x_figure_window_size (f
, parameters
, 1);
4490 tem
= x_get_arg (dpyinfo
, parameters
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
4491 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
4493 w32_window (f
, window_prompting
, minibuffer_only
);
4494 x_icon (f
, parameters
);
4498 /* Now consider the frame official. */
4499 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
4500 Vframe_list
= Fcons (frame
, Vframe_list
);
4502 /* We need to do this after creating the window, so that the
4503 icon-creation functions can say whose icon they're describing. */
4504 x_default_parameter (f
, parameters
, Qicon_type
, Qnil
,
4505 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
4507 x_default_parameter (f
, parameters
, Qauto_raise
, Qnil
,
4508 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4509 x_default_parameter (f
, parameters
, Qauto_lower
, Qnil
,
4510 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4511 x_default_parameter (f
, parameters
, Qcursor_type
, Qbox
,
4512 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4513 x_default_parameter (f
, parameters
, Qscroll_bar_width
, Qnil
,
4514 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
4515 x_default_parameter (f
, parameters
, Qalpha
, Qnil
,
4516 "alpha", "Alpha", RES_TYPE_NUMBER
);
4518 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4519 Change will not be effected unless different from the current
4521 width
= FRAME_COLS (f
);
4522 height
= FRAME_LINES (f
);
4524 FRAME_LINES (f
) = 0;
4525 SET_FRAME_COLS (f
, 0);
4526 change_frame_size (f
, height
, width
, 1, 0, 0);
4528 /* Tell the server what size and position, etc, we want, and how
4529 badly we want them. This should be done after we have the menu
4530 bar so that its size can be taken into account. */
4532 x_wm_set_size_hint (f
, window_prompting
, 0);
4535 /* Make the window appear on the frame and enable display, unless
4536 the caller says not to. However, with explicit parent, Emacs
4537 cannot control visibility, so don't try. */
4538 if (! f
->output_data
.w32
->explicit_parent
)
4540 Lisp_Object visibility
;
4542 visibility
= x_get_arg (dpyinfo
, parameters
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
4543 if (EQ (visibility
, Qunbound
))
4546 if (EQ (visibility
, Qicon
))
4547 x_iconify_frame (f
);
4548 else if (! NILP (visibility
))
4549 x_make_frame_visible (f
);
4551 /* Must have been Qnil. */
4555 /* Initialize `default-minibuffer-frame' in case this is the first
4556 frame on this terminal. */
4557 if (FRAME_HAS_MINIBUF_P (f
)
4558 && (!FRAMEP (kb
->Vdefault_minibuffer_frame
)
4559 || !FRAME_LIVE_P (XFRAME (kb
->Vdefault_minibuffer_frame
))))
4560 kb
->Vdefault_minibuffer_frame
= frame
;
4562 /* All remaining specified parameters, which have not been "used"
4563 by x_get_arg and friends, now go in the misc. alist of the frame. */
4564 for (tem
= parameters
; CONSP (tem
); tem
= XCDR (tem
))
4565 if (CONSP (XCAR (tem
)) && !NILP (XCAR (XCAR (tem
))))
4566 f
->param_alist
= Fcons (XCAR (tem
), f
->param_alist
);
4570 /* Make sure windows on this frame appear in calls to next-window
4571 and similar functions. */
4572 Vwindow_list
= Qnil
;
4574 return unbind_to (count
, frame
);
4577 /* FRAME is used only to get a handle on the X display. We don't pass the
4578 display info directly because we're called from frame.c, which doesn't
4579 know about that structure. */
4581 x_get_focus_frame (frame
)
4582 struct frame
*frame
;
4584 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
4586 if (! dpyinfo
->w32_focus_frame
)
4589 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
4593 DEFUN ("x-focus-frame", Fx_focus_frame
, Sx_focus_frame
, 1, 1, 0,
4594 doc
: /* Give FRAME input focus, raising to foreground if necessary. */)
4598 x_focus_on_frame (check_x_frame (frame
));
4603 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
4604 doc
: /* Internal function called by `color-defined-p', which see. */)
4606 Lisp_Object color
, frame
;
4609 FRAME_PTR f
= check_x_frame (frame
);
4611 CHECK_STRING (color
);
4613 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
4619 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
4620 doc
: /* Internal function called by `color-values', which see. */)
4622 Lisp_Object color
, frame
;
4625 FRAME_PTR f
= check_x_frame (frame
);
4627 CHECK_STRING (color
);
4629 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
4630 return list3 (make_number ((GetRValue (foo
.pixel
) << 8)
4631 | GetRValue (foo
.pixel
)),
4632 make_number ((GetGValue (foo
.pixel
) << 8)
4633 | GetGValue (foo
.pixel
)),
4634 make_number ((GetBValue (foo
.pixel
) << 8)
4635 | GetBValue (foo
.pixel
)));
4640 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
4641 doc
: /* Internal function called by `display-color-p', which see. */)
4643 Lisp_Object display
;
4645 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4647 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
4653 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
,
4654 Sx_display_grayscale_p
, 0, 1, 0,
4655 doc
: /* Return t if DISPLAY supports shades of gray.
4656 Note that color displays do support shades of gray.
4657 The optional argument DISPLAY specifies which display to ask about.
4658 DISPLAY should be either a frame or a display name (a string).
4659 If omitted or nil, that stands for the selected frame's display. */)
4661 Lisp_Object display
;
4663 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4665 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
4671 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
,
4672 Sx_display_pixel_width
, 0, 1, 0,
4673 doc
: /* Return the width in pixels of DISPLAY.
4674 The optional argument DISPLAY specifies which display to ask about.
4675 DISPLAY should be either a frame or a display name (a string).
4676 If omitted or nil, that stands for the selected frame's display. */)
4678 Lisp_Object display
;
4680 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4682 return make_number (dpyinfo
->width
);
4685 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
4686 Sx_display_pixel_height
, 0, 1, 0,
4687 doc
: /* Return the height in pixels of DISPLAY.
4688 The optional argument DISPLAY specifies which display to ask about.
4689 DISPLAY should be either a frame or a display name (a string).
4690 If omitted or nil, that stands for the selected frame's display. */)
4692 Lisp_Object display
;
4694 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4696 return make_number (dpyinfo
->height
);
4699 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
4701 doc
: /* Return the number of bitplanes of DISPLAY.
4702 The optional argument DISPLAY specifies which display to ask about.
4703 DISPLAY should be either a frame or a display name (a string).
4704 If omitted or nil, that stands for the selected frame's display. */)
4706 Lisp_Object display
;
4708 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4710 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
4713 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
4715 doc
: /* Return the number of color cells of DISPLAY.
4716 The optional argument DISPLAY specifies which display to ask about.
4717 DISPLAY should be either a frame or a display name (a string).
4718 If omitted or nil, that stands for the selected frame's display. */)
4720 Lisp_Object display
;
4722 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4726 hdc
= GetDC (dpyinfo
->root_window
);
4727 if (dpyinfo
->has_palette
)
4728 cap
= GetDeviceCaps (hdc
, SIZEPALETTE
);
4730 cap
= GetDeviceCaps (hdc
, NUMCOLORS
);
4732 /* We force 24+ bit depths to 24-bit, both to prevent an overflow
4733 and because probably is more meaningful on Windows anyway */
4735 cap
= 1 << min (dpyinfo
->n_planes
* dpyinfo
->n_cbits
, 24);
4737 ReleaseDC (dpyinfo
->root_window
, hdc
);
4739 return make_number (cap
);
4742 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
4743 Sx_server_max_request_size
,
4745 doc
: /* Return the maximum request size of the server of DISPLAY.
4746 The optional argument DISPLAY specifies which display to ask about.
4747 DISPLAY should be either a frame or a display name (a string).
4748 If omitted or nil, that stands for the selected frame's display. */)
4750 Lisp_Object display
;
4752 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4754 return make_number (1);
4757 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
4758 doc
: /* Return the "vendor ID" string of the W32 system (Microsoft).
4759 The optional argument DISPLAY specifies which display to ask about.
4760 DISPLAY should be either a frame or a display name (a string).
4761 If omitted or nil, that stands for the selected frame's display. */)
4763 Lisp_Object display
;
4765 return build_string ("Microsoft Corp.");
4768 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
4769 doc
: /* Return the version numbers of the server of DISPLAY.
4770 The value is a list of three integers: the major and minor
4771 version numbers of the X Protocol in use, and the distributor-specific
4772 release number. See also the function `x-server-vendor'.
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. */)
4778 Lisp_Object display
;
4780 return Fcons (make_number (w32_major_version
),
4781 Fcons (make_number (w32_minor_version
),
4782 Fcons (make_number (w32_build_number
), Qnil
)));
4785 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
4786 doc
: /* Return the number of screens on the server of DISPLAY.
4787 The optional argument DISPLAY specifies which display to ask about.
4788 DISPLAY should be either a frame or a display name (a string).
4789 If omitted or nil, that stands for the selected frame's display. */)
4791 Lisp_Object display
;
4793 return make_number (1);
4796 DEFUN ("x-display-mm-height", Fx_display_mm_height
,
4797 Sx_display_mm_height
, 0, 1, 0,
4798 doc
: /* Return the height in millimeters of DISPLAY.
4799 The optional argument DISPLAY specifies which display to ask about.
4800 DISPLAY should be either a frame or a display name (a string).
4801 If omitted or nil, that stands for the selected frame's display. */)
4803 Lisp_Object display
;
4805 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4809 hdc
= GetDC (dpyinfo
->root_window
);
4811 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
4813 ReleaseDC (dpyinfo
->root_window
, hdc
);
4815 return make_number (cap
);
4818 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
4819 doc
: /* Return the width in millimeters of DISPLAY.
4820 The optional argument DISPLAY specifies which display to ask about.
4821 DISPLAY should be either a frame or a display name (a string).
4822 If omitted or nil, that stands for the selected frame's display. */)
4824 Lisp_Object display
;
4826 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4831 hdc
= GetDC (dpyinfo
->root_window
);
4833 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
4835 ReleaseDC (dpyinfo
->root_window
, hdc
);
4837 return make_number (cap
);
4840 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
4841 Sx_display_backing_store
, 0, 1, 0,
4842 doc
: /* Return an indication of whether DISPLAY does backing store.
4843 The value may be `always', `when-mapped', or `not-useful'.
4844 The optional argument DISPLAY specifies which display to ask about.
4845 DISPLAY should be either a frame or a display name (a string).
4846 If omitted or nil, that stands for the selected frame's display. */)
4848 Lisp_Object display
;
4850 return intern ("not-useful");
4853 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
4854 Sx_display_visual_class
, 0, 1, 0,
4855 doc
: /* Return the visual class of DISPLAY.
4856 The value is one of the symbols `static-gray', `gray-scale',
4857 `static-color', `pseudo-color', `true-color', or `direct-color'.
4859 The optional argument DISPLAY specifies which display to ask about.
4860 DISPLAY should be either a frame or a display name (a string).
4861 If omitted or nil, that stands for the selected frame's display. */)
4863 Lisp_Object display
;
4865 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4866 Lisp_Object result
= Qnil
;
4868 if (dpyinfo
->has_palette
)
4869 result
= intern ("pseudo-color");
4870 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
4871 result
= intern ("static-grey");
4872 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
4873 result
= intern ("static-color");
4874 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
4875 result
= intern ("true-color");
4880 DEFUN ("x-display-save-under", Fx_display_save_under
,
4881 Sx_display_save_under
, 0, 1, 0,
4882 doc
: /* Return t if DISPLAY supports the save-under feature.
4883 The optional argument DISPLAY specifies which display to ask about.
4884 DISPLAY should be either a frame or a display name (a string).
4885 If omitted or nil, that stands for the selected frame's display. */)
4887 Lisp_Object display
;
4894 register struct frame
*f
;
4896 return FRAME_PIXEL_WIDTH (f
);
4901 register struct frame
*f
;
4903 return FRAME_PIXEL_HEIGHT (f
);
4908 register struct frame
*f
;
4910 return FRAME_COLUMN_WIDTH (f
);
4915 register struct frame
*f
;
4917 return FRAME_LINE_HEIGHT (f
);
4922 register struct frame
*f
;
4924 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
4927 /* Return the display structure for the display named NAME.
4928 Open a new connection if necessary. */
4930 struct w32_display_info
*
4931 x_display_info_for_name (name
)
4935 struct w32_display_info
*dpyinfo
;
4937 CHECK_STRING (name
);
4939 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
4941 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
4944 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
4949 /* Use this general default value to start with. */
4950 Vx_resource_name
= Vinvocation_name
;
4952 validate_x_resource_name ();
4954 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
4955 (char *) SDATA (Vx_resource_name
));
4958 error ("Cannot connect to server %s", SDATA (name
));
4961 XSETFASTINT (Vwindow_system_version
, 3);
4966 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
4967 1, 3, 0, doc
: /* Open a connection to a server.
4968 DISPLAY is the name of the display to connect to.
4969 Optional second arg XRM-STRING is a string of resources in xrdb format.
4970 If the optional third arg MUST-SUCCEED is non-nil,
4971 terminate Emacs if we can't open the connection. */)
4972 (display
, xrm_string
, must_succeed
)
4973 Lisp_Object display
, xrm_string
, must_succeed
;
4975 unsigned char *xrm_option
;
4976 struct w32_display_info
*dpyinfo
;
4978 /* If initialization has already been done, return now to avoid
4979 overwriting critical parts of one_w32_display_info. */
4983 CHECK_STRING (display
);
4984 if (! NILP (xrm_string
))
4985 CHECK_STRING (xrm_string
);
4988 if (! EQ (Vwindow_system
, intern ("w32")))
4989 error ("Not using Microsoft Windows");
4992 /* Allow color mapping to be defined externally; first look in user's
4993 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
4995 Lisp_Object color_file
;
4996 struct gcpro gcpro1
;
4998 color_file
= build_string ("~/rgb.txt");
5000 GCPRO1 (color_file
);
5002 if (NILP (Ffile_readable_p (color_file
)))
5004 Fexpand_file_name (build_string ("rgb.txt"),
5005 Fsymbol_value (intern ("data-directory")));
5007 Vw32_color_map
= Fw32_load_color_file (color_file
);
5011 if (NILP (Vw32_color_map
))
5012 Vw32_color_map
= Fw32_default_color_map ();
5014 /* Merge in system logical colors. */
5015 add_system_logical_colors_to_map (&Vw32_color_map
);
5017 if (! NILP (xrm_string
))
5018 xrm_option
= (unsigned char *) SDATA (xrm_string
);
5020 xrm_option
= (unsigned char *) 0;
5022 /* Use this general default value to start with. */
5023 /* First remove .exe suffix from invocation-name - it looks ugly. */
5025 char basename
[ MAX_PATH
], *str
;
5027 strcpy (basename
, SDATA (Vinvocation_name
));
5028 str
= strrchr (basename
, '.');
5030 Vinvocation_name
= build_string (basename
);
5032 Vx_resource_name
= Vinvocation_name
;
5034 validate_x_resource_name ();
5036 /* This is what opens the connection and sets x_current_display.
5037 This also initializes many symbols, such as those used for input. */
5038 dpyinfo
= w32_term_init (display
, xrm_option
,
5039 (char *) SDATA (Vx_resource_name
));
5043 if (!NILP (must_succeed
))
5044 fatal ("Cannot connect to server %s.\n",
5047 error ("Cannot connect to server %s", SDATA (display
));
5052 XSETFASTINT (Vwindow_system_version
, 3);
5056 DEFUN ("x-close-connection", Fx_close_connection
,
5057 Sx_close_connection
, 1, 1, 0,
5058 doc
: /* Close the connection to DISPLAY's server.
5059 For DISPLAY, specify either a frame or a display name (a string).
5060 If DISPLAY is nil, that stands for the selected frame's display. */)
5062 Lisp_Object display
;
5064 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
5067 if (dpyinfo
->reference_count
> 0)
5068 error ("Display still has frames on it");
5071 x_destroy_all_bitmaps (dpyinfo
);
5073 x_delete_display (dpyinfo
);
5079 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
5080 doc
: /* Return the list of display names that Emacs has connections to. */)
5083 Lisp_Object tail
, result
;
5086 for (tail
= w32_display_name_list
; CONSP (tail
); tail
= XCDR (tail
))
5087 result
= Fcons (XCAR (XCAR (tail
)), result
);
5092 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
5093 doc
: /* This is a noop on W32 systems. */)
5095 Lisp_Object display
, on
;
5102 /***********************************************************************
5104 ***********************************************************************/
5106 DEFUN ("x-change-window-property", Fx_change_window_property
,
5107 Sx_change_window_property
, 2, 6, 0,
5108 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
5109 VALUE may be a string or a list of conses, numbers and/or strings.
5110 If an element in the list is a string, it is converted to
5111 an Atom and the value of the Atom is used. If an element is a cons,
5112 it is converted to a 32 bit number where the car is the 16 top bits and the
5113 cdr is the lower 16 bits.
5114 FRAME nil or omitted means use the selected frame.
5115 If TYPE is given and non-nil, it is the name of the type of VALUE.
5116 If TYPE is not given or nil, the type is STRING.
5117 FORMAT gives the size in bits of each element if VALUE is a list.
5118 It must be one of 8, 16 or 32.
5119 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
5120 If OUTER_P is non-nil, the property is changed for the outer X window of
5121 FRAME. Default is to change on the edit X window.
5124 (prop
, value
, frame
, type
, format
, outer_p
)
5125 Lisp_Object prop
, value
, frame
, type
, format
, outer_p
;
5127 #if 0 /* TODO : port window properties to W32 */
5128 struct frame
*f
= check_x_frame (frame
);
5131 CHECK_STRING (prop
);
5132 CHECK_STRING (value
);
5135 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5136 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5137 prop_atom
, XA_STRING
, 8, PropModeReplace
,
5138 SDATA (value
), SCHARS (value
));
5140 /* Make sure the property is set when we return. */
5141 XFlush (FRAME_W32_DISPLAY (f
));
5150 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
5151 Sx_delete_window_property
, 1, 2, 0,
5152 doc
: /* Remove window property PROP from X window of FRAME.
5153 FRAME nil or omitted means use the selected frame. Value is PROP. */)
5155 Lisp_Object prop
, frame
;
5157 #if 0 /* TODO : port window properties to W32 */
5159 struct frame
*f
= check_x_frame (frame
);
5162 CHECK_STRING (prop
);
5164 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5165 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
5167 /* Make sure the property is removed when we return. */
5168 XFlush (FRAME_W32_DISPLAY (f
));
5176 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
5178 doc
: /* Value is the value of window property PROP on FRAME.
5179 If FRAME is nil or omitted, use the selected frame. Value is nil
5180 if FRAME hasn't a property with name PROP or if PROP has no string
5183 Lisp_Object prop
, frame
;
5185 #if 0 /* TODO : port window properties to W32 */
5187 struct frame
*f
= check_x_frame (frame
);
5190 Lisp_Object prop_value
= Qnil
;
5191 char *tmp_data
= NULL
;
5194 unsigned long actual_size
, bytes_remaining
;
5196 CHECK_STRING (prop
);
5198 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5199 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5200 prop_atom
, 0, 0, False
, XA_STRING
,
5201 &actual_type
, &actual_format
, &actual_size
,
5202 &bytes_remaining
, (unsigned char **) &tmp_data
);
5205 int size
= bytes_remaining
;
5210 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5211 prop_atom
, 0, bytes_remaining
,
5213 &actual_type
, &actual_format
,
5214 &actual_size
, &bytes_remaining
,
5215 (unsigned char **) &tmp_data
);
5217 prop_value
= make_string (tmp_data
, size
);
5232 /***********************************************************************
5234 ***********************************************************************/
5236 /* Non-zero means an hourglass cursor is currently shown. */
5238 static int hourglass_shown_p
;
5240 /* Number of seconds to wait before displaying an hourglass cursor. */
5242 static Lisp_Object Vhourglass_delay
;
5244 /* Default number of seconds to wait before displaying an hourglass
5247 #define DEFAULT_HOURGLASS_DELAY 1
5249 /* Return non-zero if houglass timer has been started or hourglass is shown. */
5252 hourglass_started ()
5254 return hourglass_shown_p
|| hourglass_timer
;
5257 /* Cancel a currently active hourglass timer, and start a new one. */
5263 int secs
, msecs
= 0;
5264 struct frame
* f
= SELECTED_FRAME ();
5266 /* No cursors on non GUI frames. */
5267 if (!FRAME_W32_P (f
))
5270 cancel_hourglass ();
5272 if (INTEGERP (Vhourglass_delay
)
5273 && XINT (Vhourglass_delay
) > 0)
5274 secs
= XFASTINT (Vhourglass_delay
);
5275 else if (FLOATP (Vhourglass_delay
)
5276 && XFLOAT_DATA (Vhourglass_delay
) > 0)
5279 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
5280 secs
= XFASTINT (tem
);
5281 msecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000;
5284 secs
= DEFAULT_HOURGLASS_DELAY
;
5286 delay
= secs
* 1000 + msecs
;
5287 hourglass_hwnd
= FRAME_W32_WINDOW (f
);
5288 hourglass_timer
= SetTimer (hourglass_hwnd
, HOURGLASS_ID
, delay
, NULL
);
5292 /* Cancel the hourglass cursor timer if active, hide an hourglass
5298 if (hourglass_timer
)
5300 KillTimer (hourglass_hwnd
, hourglass_timer
);
5301 hourglass_timer
= 0;
5304 if (hourglass_shown_p
)
5309 /* Timer function of hourglass_timer.
5311 Display an hourglass cursor. Set the hourglass_p flag in display info
5312 to indicate that an hourglass cursor is shown. */
5318 if (!hourglass_shown_p
)
5320 f
->output_data
.w32
->hourglass_p
= 1;
5321 if (!menubar_in_use
&& !current_popup_menu
)
5322 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
5323 hourglass_shown_p
= 1;
5328 /* Hide the hourglass cursor on all frames, if it is currently shown. */
5333 if (hourglass_shown_p
)
5335 struct frame
*f
= x_window_to_frame (&one_w32_display_info
,
5338 f
->output_data
.w32
->hourglass_p
= 0;
5339 SetCursor (f
->output_data
.w32
->current_cursor
);
5340 hourglass_shown_p
= 0;
5346 /***********************************************************************
5348 ***********************************************************************/
5350 static Lisp_Object x_create_tip_frame
P_ ((struct w32_display_info
*,
5351 Lisp_Object
, Lisp_Object
));
5352 static void compute_tip_xy
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
5353 Lisp_Object
, int, int, int *, int *));
5355 /* The frame of a currently visible tooltip. */
5357 Lisp_Object tip_frame
;
5359 /* If non-nil, a timer started that hides the last tooltip when it
5362 Lisp_Object tip_timer
;
5365 /* If non-nil, a vector of 3 elements containing the last args
5366 with which x-show-tip was called. See there. */
5368 Lisp_Object last_show_tip_args
;
5370 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
5372 Lisp_Object Vx_max_tooltip_size
;
5376 unwind_create_tip_frame (frame
)
5379 Lisp_Object deleted
;
5381 deleted
= unwind_create_frame (frame
);
5382 if (EQ (deleted
, Qt
))
5392 /* Create a frame for a tooltip on the display described by DPYINFO.
5393 PARMS is a list of frame parameters. TEXT is the string to
5394 display in the tip frame. Value is the frame.
5396 Note that functions called here, esp. x_default_parameter can
5397 signal errors, for instance when a specified color name is
5398 undefined. We have to make sure that we're in a consistent state
5399 when this happens. */
5402 x_create_tip_frame (dpyinfo
, parms
, text
)
5403 struct w32_display_info
*dpyinfo
;
5404 Lisp_Object parms
, text
;
5407 Lisp_Object frame
, tem
;
5409 long window_prompting
= 0;
5411 int count
= SPECPDL_INDEX ();
5412 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5414 int face_change_count_before
= face_change_count
;
5416 struct buffer
*old_buffer
;
5420 /* Use this general default value to start with until we know if
5421 this frame has a specified name. */
5422 Vx_resource_name
= Vinvocation_name
;
5425 kb
= dpyinfo
->terminal
->kboard
;
5427 kb
= &the_only_kboard
;
5430 /* Get the name of the frame to use for resource lookup. */
5431 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
5433 && !EQ (name
, Qunbound
)
5435 error ("Invalid frame name--not a string or nil");
5436 Vx_resource_name
= name
;
5439 GCPRO3 (parms
, name
, frame
);
5440 /* Make a frame without minibuffer nor mode-line. */
5442 f
->wants_modeline
= 0;
5443 XSETFRAME (frame
, f
);
5445 buffer
= Fget_buffer_create (build_string (" *tip*"));
5446 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, Qnil
);
5447 old_buffer
= current_buffer
;
5448 set_buffer_internal_1 (XBUFFER (buffer
));
5449 current_buffer
->truncate_lines
= Qnil
;
5450 specbind (Qinhibit_read_only
, Qt
);
5451 specbind (Qinhibit_modification_hooks
, Qt
);
5454 set_buffer_internal_1 (old_buffer
);
5456 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
5457 record_unwind_protect (unwind_create_tip_frame
, frame
);
5459 /* By setting the output method, we're essentially saying that
5460 the frame is live, as per FRAME_LIVE_P. If we get a signal
5461 from this point on, x_destroy_window might screw up reference
5463 f
->terminal
= dpyinfo
->terminal
;
5464 f
->terminal
->reference_count
++;
5465 f
->output_method
= output_w32
;
5466 f
->output_data
.w32
=
5467 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
5468 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
5470 FRAME_FONTSET (f
) = -1;
5471 f
->icon_name
= Qnil
;
5473 #if 0 /* GLYPH_DEBUG TODO: image support. */
5474 image_cache_refcount
= FRAME_IMAGE_CACHE (f
)->refcount
;
5475 dpyinfo_refcount
= dpyinfo
->reference_count
;
5476 #endif /* GLYPH_DEBUG */
5478 FRAME_KBOARD (f
) = kb
;
5480 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5481 f
->output_data
.w32
->explicit_parent
= 0;
5483 /* Set the name; the functions to which we pass f expect the name to
5485 if (EQ (name
, Qunbound
) || NILP (name
))
5487 f
->name
= build_string (dpyinfo
->w32_id_name
);
5488 f
->explicit_name
= 0;
5493 f
->explicit_name
= 1;
5494 /* use the frame's title when getting resources for this frame. */
5495 specbind (Qx_resource_name
, name
);
5498 f
->resx
= dpyinfo
->resx
;
5499 f
->resy
= dpyinfo
->resy
;
5501 /* Perhaps, we must allow frame parameter, say `font-backend',
5502 to specify which font backends to use. */
5503 register_font_driver (&w32font_driver
, f
);
5505 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
5506 "fontBackend", "FontBackend", RES_TYPE_STRING
);
5508 /* Extract the window parameters from the supplied values
5509 that are needed to determine window geometry. */
5510 x_default_font_parameter (f
, parms
);
5512 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
5513 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5514 /* This defaults to 2 in order to match xterm. We recognize either
5515 internalBorderWidth or internalBorder (which is what xterm calls
5517 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5521 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
5522 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
5523 if (! EQ (value
, Qunbound
))
5524 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
5527 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
5528 "internalBorderWidth", "internalBorderWidth",
5531 /* Also do the stuff which must be set before the window exists. */
5532 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
5533 "foreground", "Foreground", RES_TYPE_STRING
);
5534 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
5535 "background", "Background", RES_TYPE_STRING
);
5536 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
5537 "pointerColor", "Foreground", RES_TYPE_STRING
);
5538 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
5539 "cursorColor", "Foreground", RES_TYPE_STRING
);
5540 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
5541 "borderColor", "BorderColor", RES_TYPE_STRING
);
5543 /* Init faces before x_default_parameter is called for scroll-bar
5544 parameters because that function calls x_set_scroll_bar_width,
5545 which calls change_frame_size, which calls Fset_window_buffer,
5546 which runs hooks, which call Fvertical_motion. At the end, we
5547 end up in init_iterator with a null face cache, which should not
5549 init_frame_faces (f
);
5551 f
->output_data
.w32
->dwStyle
= WS_BORDER
| WS_POPUP
| WS_DISABLED
;
5552 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5554 window_prompting
= x_figure_window_size (f
, parms
, 0);
5556 /* No fringes on tip frame. */
5558 f
->left_fringe_width
= 0;
5559 f
->right_fringe_width
= 0;
5562 my_create_tip_window (f
);
5567 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
5568 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5569 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5570 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5571 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5572 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5574 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
5575 Change will not be effected unless different from the current
5577 width
= FRAME_COLS (f
);
5578 height
= FRAME_LINES (f
);
5579 FRAME_LINES (f
) = 0;
5580 SET_FRAME_COLS (f
, 0);
5581 change_frame_size (f
, height
, width
, 1, 0, 0);
5583 /* Add `tooltip' frame parameter's default value. */
5584 if (NILP (Fframe_parameter (frame
, intern ("tooltip"))))
5585 Fmodify_frame_parameters (frame
, Fcons (Fcons (intern ("tooltip"), Qt
),
5588 /* Set up faces after all frame parameters are known. This call
5589 also merges in face attributes specified for new frames.
5591 Frame parameters may be changed if .Xdefaults contains
5592 specifications for the default font. For example, if there is an
5593 `Emacs.default.attributeBackground: pink', the `background-color'
5594 attribute of the frame get's set, which let's the internal border
5595 of the tooltip frame appear in pink. Prevent this. */
5597 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
5599 /* Set tip_frame here, so that */
5601 call2 (Qface_set_after_frame_default
, frame
, Qnil
);
5603 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
5604 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qbackground_color
, bg
),
5612 /* It is now ok to make the frame official even if we get an error
5613 below. And the frame needs to be on Vframe_list or making it
5614 visible won't work. */
5615 Vframe_list
= Fcons (frame
, Vframe_list
);
5617 /* Now that the frame is official, it counts as a reference to
5619 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
5621 /* Setting attributes of faces of the tooltip frame from resources
5622 and similar will increment face_change_count, which leads to the
5623 clearing of all current matrices. Since this isn't necessary
5624 here, avoid it by resetting face_change_count to the value it
5625 had before we created the tip frame. */
5626 face_change_count
= face_change_count_before
;
5628 /* Discard the unwind_protect. */
5629 return unbind_to (count
, frame
);
5633 /* Compute where to display tip frame F. PARMS is the list of frame
5634 parameters for F. DX and DY are specified offsets from the current
5635 location of the mouse. WIDTH and HEIGHT are the width and height
5636 of the tooltip. Return coordinates relative to the root window of
5637 the display in *ROOT_X, and *ROOT_Y. */
5640 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, root_x
, root_y
)
5642 Lisp_Object parms
, dx
, dy
;
5644 int *root_x
, *root_y
;
5646 Lisp_Object left
, top
;
5647 int min_x
, min_y
, max_x
, max_y
;
5649 /* User-specified position? */
5650 left
= Fcdr (Fassq (Qleft
, parms
));
5651 top
= Fcdr (Fassq (Qtop
, parms
));
5653 /* Move the tooltip window where the mouse pointer is. Resize and
5655 if (!INTEGERP (left
) || !INTEGERP (top
))
5659 /* Default min and max values. */
5662 max_x
= FRAME_W32_DISPLAY_INFO (f
)->width
;
5663 max_y
= FRAME_W32_DISPLAY_INFO (f
)->height
;
5671 /* If multiple monitor support is available, constrain the tip onto
5672 the current monitor. This improves the above by allowing negative
5673 co-ordinates if monitor positions are such that they are valid, and
5674 snaps a tooltip onto a single monitor if we are close to the edge
5675 where it would otherwise flow onto the other monitor (or into
5676 nothingness if there is a gap in the overlap). */
5677 if (monitor_from_point_fn
&& get_monitor_info_fn
)
5679 struct MONITOR_INFO info
;
5681 = monitor_from_point_fn (pt
, MONITOR_DEFAULT_TO_NEAREST
);
5682 info
.cbSize
= sizeof (info
);
5684 if (get_monitor_info_fn (monitor
, &info
))
5686 min_x
= info
.rcWork
.left
;
5687 min_y
= info
.rcWork
.top
;
5688 max_x
= info
.rcWork
.right
;
5689 max_y
= info
.rcWork
.bottom
;
5695 *root_y
= XINT (top
);
5696 else if (*root_y
+ XINT (dy
) <= min_y
)
5697 *root_y
= min_y
; /* Can happen for negative dy */
5698 else if (*root_y
+ XINT (dy
) + height
<= max_y
)
5699 /* It fits below the pointer */
5700 *root_y
+= XINT (dy
);
5701 else if (height
+ XINT (dy
) + min_y
<= *root_y
)
5702 /* It fits above the pointer. */
5703 *root_y
-= height
+ XINT (dy
);
5705 /* Put it on the top. */
5708 if (INTEGERP (left
))
5709 *root_x
= XINT (left
);
5710 else if (*root_x
+ XINT (dx
) <= min_x
)
5711 *root_x
= 0; /* Can happen for negative dx */
5712 else if (*root_x
+ XINT (dx
) + width
<= max_x
)
5713 /* It fits to the right of the pointer. */
5714 *root_x
+= XINT (dx
);
5715 else if (width
+ XINT (dx
) + min_x
<= *root_x
)
5716 /* It fits to the left of the pointer. */
5717 *root_x
-= width
+ XINT (dx
);
5719 /* Put it left justified on the screen -- it ought to fit that way. */
5724 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
5725 doc
: /* Show STRING in a \"tooltip\" window on frame FRAME.
5726 A tooltip window is a small window displaying a string.
5728 This is an internal function; Lisp code should call `tooltip-show'.
5730 FRAME nil or omitted means use the selected frame.
5732 PARMS is an optional list of frame parameters which can be
5733 used to change the tooltip's appearance.
5735 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
5736 means use the default timeout of 5 seconds.
5738 If the list of frame parameters PARMS contains a `left' parameter,
5739 the tooltip is displayed at that x-position. Otherwise it is
5740 displayed at the mouse position, with offset DX added (default is 5 if
5741 DX isn't specified). Likewise for the y-position; if a `top' frame
5742 parameter is specified, it determines the y-position of the tooltip
5743 window, otherwise it is displayed at the mouse position, with offset
5744 DY added (default is -10).
5746 A tooltip's maximum size is specified by `x-max-tooltip-size'.
5747 Text larger than the specified size is clipped. */)
5748 (string
, frame
, parms
, timeout
, dx
, dy
)
5749 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
5754 struct buffer
*old_buffer
;
5755 struct text_pos pos
;
5756 int i
, width
, height
;
5757 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5758 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5759 int count
= SPECPDL_INDEX ();
5761 specbind (Qinhibit_redisplay
, Qt
);
5763 GCPRO4 (string
, parms
, frame
, timeout
);
5765 CHECK_STRING (string
);
5766 f
= check_x_frame (frame
);
5768 timeout
= make_number (5);
5770 CHECK_NATNUM (timeout
);
5773 dx
= make_number (5);
5778 dy
= make_number (-10);
5782 if (NILP (last_show_tip_args
))
5783 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
5785 if (!NILP (tip_frame
))
5787 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
5788 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
5789 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
5791 if (EQ (frame
, last_frame
)
5792 && !NILP (Fequal (last_string
, string
))
5793 && !NILP (Fequal (last_parms
, parms
)))
5795 struct frame
*f
= XFRAME (tip_frame
);
5797 /* Only DX and DY have changed. */
5798 if (!NILP (tip_timer
))
5800 Lisp_Object timer
= tip_timer
;
5802 call1 (Qcancel_timer
, timer
);
5806 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
5807 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
5809 /* Put tooltip in topmost group and in position. */
5810 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
5811 root_x
, root_y
, 0, 0,
5812 SWP_NOSIZE
| SWP_NOACTIVATE
);
5814 /* Ensure tooltip is on top of other topmost windows (eg menus). */
5815 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
5817 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
5824 /* Hide a previous tip, if any. */
5827 ASET (last_show_tip_args
, 0, string
);
5828 ASET (last_show_tip_args
, 1, frame
);
5829 ASET (last_show_tip_args
, 2, parms
);
5831 /* Add default values to frame parameters. */
5832 if (NILP (Fassq (Qname
, parms
)))
5833 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
5834 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5835 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
5836 if (NILP (Fassq (Qborder_width
, parms
)))
5837 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
5838 if (NILP (Fassq (Qborder_color
, parms
)))
5839 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
5840 if (NILP (Fassq (Qbackground_color
, parms
)))
5841 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
5844 /* Block input until the tip has been fully drawn, to avoid crashes
5845 when drawing tips in menus. */
5848 /* Create a frame for the tooltip, and record it in the global
5849 variable tip_frame. */
5850 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
, string
);
5853 /* Set up the frame's root window. */
5854 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5855 w
->left_col
= w
->top_line
= make_number (0);
5857 if (CONSP (Vx_max_tooltip_size
)
5858 && INTEGERP (XCAR (Vx_max_tooltip_size
))
5859 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
5860 && INTEGERP (XCDR (Vx_max_tooltip_size
))
5861 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
5863 w
->total_cols
= XCAR (Vx_max_tooltip_size
);
5864 w
->total_lines
= XCDR (Vx_max_tooltip_size
);
5868 w
->total_cols
= make_number (80);
5869 w
->total_lines
= make_number (40);
5872 FRAME_TOTAL_COLS (f
) = XINT (w
->total_cols
);
5874 w
->pseudo_window_p
= 1;
5876 /* Display the tooltip text in a temporary buffer. */
5877 old_buffer
= current_buffer
;
5878 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
5879 current_buffer
->truncate_lines
= Qnil
;
5880 clear_glyph_matrix (w
->desired_matrix
);
5881 clear_glyph_matrix (w
->current_matrix
);
5882 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
5883 try_window (FRAME_ROOT_WINDOW (f
), pos
, 0);
5885 /* Compute width and height of the tooltip. */
5887 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5889 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5893 /* Stop at the first empty row at the end. */
5894 if (!row
->enabled_p
|| !row
->displays_text_p
)
5897 /* Let the row go over the full width of the frame. */
5898 row
->full_width_p
= 1;
5900 #ifdef TODO /* Investigate why some fonts need more width than is
5901 calculated for some tooltips. */
5902 /* There's a glyph at the end of rows that is use to place
5903 the cursor there. Don't include the width of this glyph. */
5904 if (row
->used
[TEXT_AREA
])
5906 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5907 row_width
= row
->pixel_width
- last
->pixel_width
;
5911 row_width
= row
->pixel_width
;
5913 /* TODO: find why tips do not draw along baseline as instructed. */
5914 height
+= row
->height
;
5915 width
= max (width
, row_width
);
5918 /* Add the frame's internal border to the width and height the X
5919 window should have. */
5920 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5921 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5923 /* Move the tooltip window where the mouse pointer is. Resize and
5925 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
5928 /* Adjust Window size to take border into account. */
5930 rect
.left
= rect
.top
= 0;
5932 rect
.bottom
= height
;
5933 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
5934 FRAME_EXTERNAL_MENU_BAR (f
));
5936 /* Position and size tooltip, and put it in the topmost group.
5937 The add-on of 3 to the 5th argument is a kludge: without it,
5938 some fonts cause the last character of the tip to be truncated,
5939 for some obscure reason. */
5940 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
5941 root_x
, root_y
, rect
.right
- rect
.left
+ 3,
5942 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
);
5944 /* Ensure tooltip is on top of other topmost windows (eg menus). */
5945 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
5947 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
5949 /* Let redisplay know that we have made the frame visible already. */
5950 f
->async_visible
= 1;
5952 ShowWindow (FRAME_W32_WINDOW (f
), SW_SHOWNOACTIVATE
);
5955 /* Draw into the window. */
5956 w
->must_be_updated_p
= 1;
5957 update_single_window (w
, 1);
5961 /* Restore original current buffer. */
5962 set_buffer_internal_1 (old_buffer
);
5963 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5966 /* Let the tip disappear after timeout seconds. */
5967 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
5968 intern ("x-hide-tip"));
5971 return unbind_to (count
, Qnil
);
5975 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
5976 doc
: /* Hide the current tooltip window, if there is any.
5977 Value is t if tooltip was open, nil otherwise. */)
5981 Lisp_Object deleted
, frame
, timer
;
5982 struct gcpro gcpro1
, gcpro2
;
5984 /* Return quickly if nothing to do. */
5985 if (NILP (tip_timer
) && NILP (tip_frame
))
5990 GCPRO2 (frame
, timer
);
5991 tip_frame
= tip_timer
= deleted
= Qnil
;
5993 count
= SPECPDL_INDEX ();
5994 specbind (Qinhibit_redisplay
, Qt
);
5995 specbind (Qinhibit_quit
, Qt
);
5998 call1 (Qcancel_timer
, timer
);
6002 Fdelete_frame (frame
, Qnil
);
6007 return unbind_to (count
, deleted
);
6012 /***********************************************************************
6013 File selection dialog
6014 ***********************************************************************/
6015 extern Lisp_Object Qfile_name_history
;
6017 /* Callback for altering the behavior of the Open File dialog.
6018 Makes the Filename text field contain "Current Directory" and be
6019 read-only when "Directories" is selected in the filter. This
6020 allows us to work around the fact that the standard Open File
6021 dialog does not support directories. */
6023 file_dialog_callback (hwnd
, msg
, wParam
, lParam
)
6029 if (msg
== WM_NOTIFY
)
6031 OFNOTIFY
* notify
= (OFNOTIFY
*)lParam
;
6032 /* Detect when the Filter dropdown is changed. */
6033 if (notify
->hdr
.code
== CDN_TYPECHANGE
6034 || notify
->hdr
.code
== CDN_INITDONE
)
6036 HWND dialog
= GetParent (hwnd
);
6037 HWND edit_control
= GetDlgItem (dialog
, FILE_NAME_TEXT_FIELD
);
6039 /* Directories is in index 2. */
6040 if (notify
->lpOFN
->nFilterIndex
== 2)
6042 CommDlg_OpenSave_SetControlText (dialog
, FILE_NAME_TEXT_FIELD
,
6043 "Current Directory");
6044 EnableWindow (edit_control
, FALSE
);
6048 /* Don't override default filename on init done. */
6049 if (notify
->hdr
.code
== CDN_TYPECHANGE
)
6050 CommDlg_OpenSave_SetControlText (dialog
,
6051 FILE_NAME_TEXT_FIELD
, "");
6052 EnableWindow (edit_control
, TRUE
);
6059 /* Since we compile with _WIN32_WINNT set to 0x0400 (for NT4 compatibility)
6060 we end up with the old file dialogs. Define a big enough struct for the
6061 new dialog to trick GetOpenFileName into giving us the new dialogs on
6062 Windows 2000 and XP. */
6065 OPENFILENAME real_details
;
6072 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
6073 doc
: /* Read file name, prompting with PROMPT in directory DIR.
6074 Use a file selection dialog.
6075 Select DEFAULT-FILENAME in the dialog's file selection box, if
6076 specified. Ensure that file exists if MUSTMATCH is non-nil.
6077 If ONLY-DIR-P is non-nil, the user can only select directories. */)
6078 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
)
6079 Lisp_Object prompt
, dir
, default_filename
, mustmatch
, only_dir_p
;
6081 struct frame
*f
= SELECTED_FRAME ();
6082 Lisp_Object file
= Qnil
;
6083 int count
= SPECPDL_INDEX ();
6084 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
6085 char filename
[MAX_PATH
+ 1];
6086 char init_dir
[MAX_PATH
+ 1];
6087 int default_filter_index
= 1; /* 1: All Files, 2: Directories only */
6089 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
6090 CHECK_STRING (prompt
);
6093 /* Create the dialog with PROMPT as title, using DIR as initial
6094 directory and using "*" as pattern. */
6095 dir
= Fexpand_file_name (dir
, Qnil
);
6096 strncpy (init_dir
, SDATA (ENCODE_FILE (dir
)), MAX_PATH
);
6097 init_dir
[MAX_PATH
] = '\0';
6098 unixtodos_filename (init_dir
);
6100 if (STRINGP (default_filename
))
6102 char *file_name_only
;
6103 char *full_path_name
= SDATA (ENCODE_FILE (default_filename
));
6105 unixtodos_filename (full_path_name
);
6107 file_name_only
= strrchr (full_path_name
, '\\');
6108 if (!file_name_only
)
6109 file_name_only
= full_path_name
;
6113 strncpy (filename
, file_name_only
, MAX_PATH
);
6114 filename
[MAX_PATH
] = '\0';
6120 NEWOPENFILENAME new_file_details
;
6121 BOOL file_opened
= FALSE
;
6122 OPENFILENAME
* file_details
= &new_file_details
.real_details
;
6124 /* Prevent redisplay. */
6125 specbind (Qinhibit_redisplay
, Qt
);
6128 bzero (&new_file_details
, sizeof (new_file_details
));
6129 /* Apparently NT4 crashes if you give it an unexpected size.
6130 I'm not sure about Windows 9x, so play it safe. */
6131 if (w32_major_version
> 4 && w32_major_version
< 95)
6132 file_details
->lStructSize
= sizeof (NEWOPENFILENAME
);
6134 file_details
->lStructSize
= sizeof (OPENFILENAME
);
6136 file_details
->hwndOwner
= FRAME_W32_WINDOW (f
);
6137 /* Undocumented Bug in Common File Dialog:
6138 If a filter is not specified, shell links are not resolved. */
6139 file_details
->lpstrFilter
= "All Files (*.*)\0*.*\0Directories\0*|*\0\0";
6140 file_details
->lpstrFile
= filename
;
6141 file_details
->nMaxFile
= sizeof (filename
);
6142 file_details
->lpstrInitialDir
= init_dir
;
6143 file_details
->lpstrTitle
= SDATA (prompt
);
6145 if (! NILP (only_dir_p
))
6146 default_filter_index
= 2;
6148 file_details
->nFilterIndex
= default_filter_index
;
6150 file_details
->Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
6151 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
6152 if (!NILP (mustmatch
))
6154 /* Require that the path to the parent directory exists. */
6155 file_details
->Flags
|= OFN_PATHMUSTEXIST
;
6156 /* If we are looking for a file, require that it exists. */
6157 if (NILP (only_dir_p
))
6158 file_details
->Flags
|= OFN_FILEMUSTEXIST
;
6161 file_details
->lpfnHook
= (LPOFNHOOKPROC
) file_dialog_callback
;
6163 file_opened
= GetOpenFileName (file_details
);
6169 dostounix_filename (filename
);
6171 if (file_details
->nFilterIndex
== 2)
6173 /* "Directories" selected - strip dummy file name. */
6174 char * last
= strrchr (filename
, '/');
6178 file
= DECODE_FILE (build_string (filename
));
6180 /* User cancelled the dialog without making a selection. */
6181 else if (!CommDlgExtendedError ())
6183 /* An error occurred, fallback on reading from the mini-buffer. */
6185 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
6186 dir
, mustmatch
, dir
, Qfile_name_history
,
6187 default_filename
, Qnil
);
6189 file
= unbind_to (count
, file
);
6194 /* Make "Cancel" equivalent to C-g. */
6196 Fsignal (Qquit
, Qnil
);
6198 return unbind_to (count
, file
);
6202 /* Moving files to the system recycle bin.
6203 Used by `move-file-to-trash' instead of the default moving to ~/.Trash */
6204 DEFUN ("system-move-file-to-trash", Fsystem_move_file_to_trash
,
6205 Ssystem_move_file_to_trash
, 1, 1, 0,
6206 doc
: /* Move file or directory named FILENAME to the recycle bin. */)
6208 Lisp_Object filename
;
6210 Lisp_Object handler
;
6211 Lisp_Object encoded_file
;
6212 Lisp_Object operation
;
6214 operation
= Qdelete_file
;
6215 if (!NILP (Ffile_directory_p (filename
))
6216 && NILP (Ffile_symlink_p (filename
)))
6218 operation
= Qdelete_directory
;
6219 filename
= Fdirectory_file_name (filename
);
6221 filename
= Fexpand_file_name (filename
, Qnil
);
6223 handler
= Ffind_file_name_handler (filename
, operation
);
6224 if (!NILP (handler
))
6225 return call2 (handler
, operation
, filename
);
6227 encoded_file
= ENCODE_FILE (filename
);
6231 SHFILEOPSTRUCT file_op
;
6232 char tmp_path
[MAX_PATH
+ 1];
6234 path
= map_w32_filename (SDATA (encoded_file
), NULL
);
6236 /* On Windows, write permission is required to delete/move files. */
6237 _chmod (path
, 0666);
6239 bzero (tmp_path
, sizeof (tmp_path
));
6240 strcpy (tmp_path
, path
);
6242 bzero (&file_op
, sizeof (file_op
));
6243 file_op
.hwnd
= HWND_DESKTOP
;
6244 file_op
.wFunc
= FO_DELETE
;
6245 file_op
.pFrom
= tmp_path
;
6246 file_op
.fFlags
= FOF_SILENT
| FOF_NOCONFIRMATION
| FOF_ALLOWUNDO
6247 | FOF_NOERRORUI
| FOF_NO_CONNECTED_ELEMENTS
;
6248 file_op
.fAnyOperationsAborted
= FALSE
;
6250 if (SHFileOperation (&file_op
) != 0)
6251 report_file_error ("Removing old name", list1 (filename
));
6257 /***********************************************************************
6258 w32 specialized functions
6259 ***********************************************************************/
6261 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
,
6262 Sw32_send_sys_command
, 1, 2, 0,
6263 doc
: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND.
6264 Some useful values for COMMAND are #xf030 to maximize frame (#xf020
6265 to minimize), #xf120 to restore frame to original size, and #xf100
6266 to activate the menubar for keyboard access. #xf140 activates the
6267 screen saver if defined.
6269 If optional parameter FRAME is not specified, use selected frame. */)
6271 Lisp_Object command
, frame
;
6273 FRAME_PTR f
= check_x_frame (frame
);
6275 CHECK_NUMBER (command
);
6277 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
6282 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
6283 doc
: /* Get Windows to perform OPERATION on DOCUMENT.
6284 This is a wrapper around the ShellExecute system function, which
6285 invokes the application registered to handle OPERATION for DOCUMENT.
6287 OPERATION is either nil or a string that names a supported operation.
6288 What operations can be used depends on the particular DOCUMENT and its
6289 handler application, but typically it is one of the following common
6292 \"open\" - open DOCUMENT, which could be a file, a directory, or an
6293 executable program. If it is an application, that
6294 application is launched in the current buffer's default
6295 directory. Otherwise, the application associated with
6296 DOCUMENT is launched in the buffer's default directory.
6297 \"print\" - print DOCUMENT, which must be a file
6298 \"explore\" - start the Windows Explorer on DOCUMENT
6299 \"edit\" - launch an editor and open DOCUMENT for editing; which
6300 editor is launched depends on the association for the
6302 \"find\" - initiate search starting from DOCUMENT which must specify
6304 nil - invoke the default OPERATION, or \"open\" if default is
6305 not defined or unavailable
6307 DOCUMENT is typically the name of a document file or a URL, but can
6308 also be a program executable to run, or a directory to open in the
6311 If DOCUMENT is a program executable, the optional third arg PARAMETERS
6312 can be a string containing command line parameters that will be passed
6313 to the program; otherwise, PARAMETERS should be nil or unspecified.
6315 Optional fourth argument SHOW-FLAG can be used to control how the
6316 application will be displayed when it is invoked. If SHOW-FLAG is nil
6317 or unspecified, the application is displayed normally, otherwise it is
6318 an integer representing a ShowWindow flag:
6323 6 - start minimized */)
6324 (operation
, document
, parameters
, show_flag
)
6325 Lisp_Object operation
, document
, parameters
, show_flag
;
6327 Lisp_Object current_dir
;
6329 CHECK_STRING (document
);
6331 /* Encode filename, current directory and parameters. */
6332 current_dir
= ENCODE_FILE (current_buffer
->directory
);
6333 document
= ENCODE_FILE (document
);
6334 if (STRINGP (parameters
))
6335 parameters
= ENCODE_SYSTEM (parameters
);
6337 if ((int) ShellExecute (NULL
,
6338 (STRINGP (operation
) ?
6339 SDATA (operation
) : NULL
),
6341 (STRINGP (parameters
) ?
6342 SDATA (parameters
) : NULL
),
6343 SDATA (current_dir
),
6344 (INTEGERP (show_flag
) ?
6345 XINT (show_flag
) : SW_SHOWDEFAULT
))
6348 error ("ShellExecute failed: %s", w32_strerror (0));
6351 /* Lookup virtual keycode from string representing the name of a
6352 non-ascii keystroke into the corresponding virtual key, using
6353 lispy_function_keys. */
6355 lookup_vk_code (char *key
)
6359 for (i
= 0; i
< 256; i
++)
6360 if (lispy_function_keys
[i
]
6361 && strcmp (lispy_function_keys
[i
], key
) == 0)
6367 /* Convert a one-element vector style key sequence to a hot key
6370 w32_parse_hot_key (key
)
6373 /* Copied from Fdefine_key and store_in_keymap. */
6374 register Lisp_Object c
;
6378 struct gcpro gcpro1
;
6382 if (XFASTINT (Flength (key
)) != 1)
6387 c
= Faref (key
, make_number (0));
6389 if (CONSP (c
) && lucid_event_type_list_p (c
))
6390 c
= Fevent_convert_list (c
);
6394 if (! INTEGERP (c
) && ! SYMBOLP (c
))
6395 error ("Key definition is invalid");
6397 /* Work out the base key and the modifiers. */
6400 c
= parse_modifiers (c
);
6401 lisp_modifiers
= XINT (Fcar (Fcdr (c
)));
6405 vk_code
= lookup_vk_code (SDATA (SYMBOL_NAME (c
)));
6407 else if (INTEGERP (c
))
6409 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
6410 /* Many ascii characters are their own virtual key code. */
6411 vk_code
= XINT (c
) & CHARACTERBITS
;
6414 if (vk_code
< 0 || vk_code
> 255)
6417 if ((lisp_modifiers
& meta_modifier
) != 0
6418 && !NILP (Vw32_alt_is_meta
))
6419 lisp_modifiers
|= alt_modifier
;
6421 /* Supply defs missing from mingw32. */
6423 #define MOD_ALT 0x0001
6424 #define MOD_CONTROL 0x0002
6425 #define MOD_SHIFT 0x0004
6426 #define MOD_WIN 0x0008
6429 /* Convert lisp modifiers to Windows hot-key form. */
6430 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
6431 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
6432 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
6433 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
6435 return HOTKEY (vk_code
, w32_modifiers
);
6438 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
,
6439 Sw32_register_hot_key
, 1, 1, 0,
6440 doc
: /* Register KEY as a hot-key combination.
6441 Certain key combinations like Alt-Tab are reserved for system use on
6442 Windows, and therefore are normally intercepted by the system. However,
6443 most of these key combinations can be received by registering them as
6444 hot-keys, overriding their special meaning.
6446 KEY must be a one element key definition in vector form that would be
6447 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta
6448 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper
6449 is always interpreted as the Windows modifier keys.
6451 The return value is the hotkey-id if registered, otherwise nil. */)
6455 key
= w32_parse_hot_key (key
);
6457 if (!NILP (key
) && NILP (Fmemq (key
, w32_grabbed_keys
)))
6459 /* Reuse an empty slot if possible. */
6460 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
6462 /* Safe to add new key to list, even if we have focus. */
6464 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
6466 XSETCAR (item
, key
);
6468 /* Notify input thread about new hot-key definition, so that it
6469 takes effect without needing to switch focus. */
6470 #ifdef USE_LISP_UNION_TYPE
6471 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
6474 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
6482 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
,
6483 Sw32_unregister_hot_key
, 1, 1, 0,
6484 doc
: /* Unregister KEY as a hot-key combination. */)
6490 if (!INTEGERP (key
))
6491 key
= w32_parse_hot_key (key
);
6493 item
= Fmemq (key
, w32_grabbed_keys
);
6497 /* Notify input thread about hot-key definition being removed, so
6498 that it takes effect without needing focus switch. */
6499 #ifdef USE_LISP_UNION_TYPE
6500 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
6501 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
.i
))
6503 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
6504 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
))
6508 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
6515 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
,
6516 Sw32_registered_hot_keys
, 0, 0, 0,
6517 doc
: /* Return list of registered hot-key IDs. */)
6520 return Fdelq (Qnil
, Fcopy_sequence (w32_grabbed_keys
));
6523 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
,
6524 Sw32_reconstruct_hot_key
, 1, 1, 0,
6525 doc
: /* Convert hot-key ID to a lisp key combination.
6526 usage: (w32-reconstruct-hot-key ID) */)
6528 Lisp_Object hotkeyid
;
6530 int vk_code
, w32_modifiers
;
6533 CHECK_NUMBER (hotkeyid
);
6535 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
6536 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
6538 if (vk_code
< 256 && lispy_function_keys
[vk_code
])
6539 key
= intern (lispy_function_keys
[vk_code
]);
6541 key
= make_number (vk_code
);
6543 key
= Fcons (key
, Qnil
);
6544 if (w32_modifiers
& MOD_SHIFT
)
6545 key
= Fcons (Qshift
, key
);
6546 if (w32_modifiers
& MOD_CONTROL
)
6547 key
= Fcons (Qctrl
, key
);
6548 if (w32_modifiers
& MOD_ALT
)
6549 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
6550 if (w32_modifiers
& MOD_WIN
)
6551 key
= Fcons (Qhyper
, key
);
6556 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
,
6557 Sw32_toggle_lock_key
, 1, 2, 0,
6558 doc
: /* Toggle the state of the lock key KEY.
6559 KEY can be `capslock', `kp-numlock', or `scroll'.
6560 If the optional parameter NEW-STATE is a number, then the state of KEY
6561 is set to off if the low bit of NEW-STATE is zero, otherwise on. */)
6563 Lisp_Object key
, new_state
;
6567 if (EQ (key
, intern ("capslock")))
6568 vk_code
= VK_CAPITAL
;
6569 else if (EQ (key
, intern ("kp-numlock")))
6570 vk_code
= VK_NUMLOCK
;
6571 else if (EQ (key
, intern ("scroll")))
6572 vk_code
= VK_SCROLL
;
6576 if (!dwWindowsThreadId
)
6577 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
6579 #ifdef USE_LISP_UNION_TYPE
6580 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
6581 (WPARAM
) vk_code
, (LPARAM
) new_state
.i
))
6583 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
6584 (WPARAM
) vk_code
, (LPARAM
) new_state
))
6588 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
6589 return make_number (msg
.wParam
);
6594 DEFUN ("w32-window-exists-p", Fw32_window_exists_p
, Sw32_window_exists_p
,
6596 doc
: /* Return non-nil if a window exists with the specified CLASS and NAME.
6598 This is a direct interface to the Windows API FindWindow function. */)
6600 Lisp_Object
class, name
;
6605 CHECK_STRING (class);
6607 CHECK_STRING (name
);
6609 hnd
= FindWindow (STRINGP (class) ? ((LPCTSTR
) SDATA (class)) : NULL
,
6610 STRINGP (name
) ? ((LPCTSTR
) SDATA (name
)) : NULL
);
6616 DEFUN ("w32-battery-status", Fw32_battery_status
, Sw32_battery_status
, 0, 0, 0,
6617 doc
: /* Get power status information from Windows system.
6619 The following %-sequences are provided:
6620 %L AC line status (verbose)
6621 %B Battery status (verbose)
6622 %b Battery status, empty means high, `-' means low,
6623 `!' means critical, and `+' means charging
6624 %p Battery load percentage
6625 %s Remaining time (to charge or discharge) in seconds
6626 %m Remaining time (to charge or discharge) in minutes
6627 %h Remaining time (to charge or discharge) in hours
6628 %t Remaining time (to charge or discharge) in the form `h:min' */)
6631 Lisp_Object status
= Qnil
;
6633 SYSTEM_POWER_STATUS system_status
;
6634 if (GetSystemPowerStatus (&system_status
))
6636 Lisp_Object line_status
, battery_status
, battery_status_symbol
;
6637 Lisp_Object load_percentage
, seconds
, minutes
, hours
, remain
;
6638 Lisp_Object sequences
[8];
6640 long seconds_left
= (long) system_status
.BatteryLifeTime
;
6642 if (system_status
.ACLineStatus
== 0)
6643 line_status
= build_string ("off-line");
6644 else if (system_status
.ACLineStatus
== 1)
6645 line_status
= build_string ("on-line");
6647 line_status
= build_string ("N/A");
6649 if (system_status
.BatteryFlag
& 128)
6651 battery_status
= build_string ("N/A");
6652 battery_status_symbol
= build_string ("");
6654 else if (system_status
.BatteryFlag
& 8)
6656 battery_status
= build_string ("charging");
6657 battery_status_symbol
= build_string ("+");
6658 if (system_status
.BatteryFullLifeTime
!= -1L)
6659 seconds_left
= system_status
.BatteryFullLifeTime
- seconds_left
;
6661 else if (system_status
.BatteryFlag
& 4)
6663 battery_status
= build_string ("critical");
6664 battery_status_symbol
= build_string ("!");
6666 else if (system_status
.BatteryFlag
& 2)
6668 battery_status
= build_string ("low");
6669 battery_status_symbol
= build_string ("-");
6671 else if (system_status
.BatteryFlag
& 1)
6673 battery_status
= build_string ("high");
6674 battery_status_symbol
= build_string ("");
6678 battery_status
= build_string ("medium");
6679 battery_status_symbol
= build_string ("");
6682 if (system_status
.BatteryLifePercent
> 100)
6683 load_percentage
= build_string ("N/A");
6687 _snprintf (buffer
, 16, "%d", system_status
.BatteryLifePercent
);
6688 load_percentage
= build_string (buffer
);
6691 if (seconds_left
< 0)
6692 seconds
= minutes
= hours
= remain
= build_string ("N/A");
6698 _snprintf (buffer
, 16, "%ld", seconds_left
);
6699 seconds
= build_string (buffer
);
6701 m
= seconds_left
/ 60;
6702 _snprintf (buffer
, 16, "%ld", m
);
6703 minutes
= build_string (buffer
);
6705 h
= seconds_left
/ 3600.0;
6706 _snprintf (buffer
, 16, "%3.1f", h
);
6707 hours
= build_string (buffer
);
6709 _snprintf (buffer
, 16, "%ld:%02ld", m
/ 60, m
% 60);
6710 remain
= build_string (buffer
);
6712 sequences
[0] = Fcons (make_number ('L'), line_status
);
6713 sequences
[1] = Fcons (make_number ('B'), battery_status
);
6714 sequences
[2] = Fcons (make_number ('b'), battery_status_symbol
);
6715 sequences
[3] = Fcons (make_number ('p'), load_percentage
);
6716 sequences
[4] = Fcons (make_number ('s'), seconds
);
6717 sequences
[5] = Fcons (make_number ('m'), minutes
);
6718 sequences
[6] = Fcons (make_number ('h'), hours
);
6719 sequences
[7] = Fcons (make_number ('t'), remain
);
6721 status
= Flist (8, sequences
);
6727 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
6728 doc
: /* Return storage information about the file system FILENAME is on.
6729 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
6730 storage of the file system, FREE is the free storage, and AVAIL is the
6731 storage available to a non-superuser. All 3 numbers are in bytes.
6732 If the underlying system call fails, value is nil. */)
6734 Lisp_Object filename
;
6736 Lisp_Object encoded
, value
;
6738 CHECK_STRING (filename
);
6739 filename
= Fexpand_file_name (filename
, Qnil
);
6740 encoded
= ENCODE_FILE (filename
);
6744 /* Determining the required information on Windows turns out, sadly,
6745 to be more involved than one would hope. The original Win32 api
6746 call for this will return bogus information on some systems, but we
6747 must dynamically probe for the replacement api, since that was
6748 added rather late on. */
6750 HMODULE hKernel
= GetModuleHandle ("kernel32");
6751 BOOL (*pfn_GetDiskFreeSpaceEx
)
6752 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
6753 = (void *) GetProcAddress (hKernel
, "GetDiskFreeSpaceEx");
6755 /* On Windows, we may need to specify the root directory of the
6756 volume holding FILENAME. */
6757 char rootname
[MAX_PATH
];
6758 char *name
= SDATA (encoded
);
6760 /* find the root name of the volume if given */
6761 if (isalpha (name
[0]) && name
[1] == ':')
6763 rootname
[0] = name
[0];
6764 rootname
[1] = name
[1];
6768 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
6770 char *str
= rootname
;
6774 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
6784 if (pfn_GetDiskFreeSpaceEx
)
6786 /* Unsigned large integers cannot be cast to double, so
6787 use signed ones instead. */
6788 LARGE_INTEGER availbytes
;
6789 LARGE_INTEGER freebytes
;
6790 LARGE_INTEGER totalbytes
;
6792 if (pfn_GetDiskFreeSpaceEx (rootname
,
6793 (ULARGE_INTEGER
*)&availbytes
,
6794 (ULARGE_INTEGER
*)&totalbytes
,
6795 (ULARGE_INTEGER
*)&freebytes
))
6796 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
6797 make_float ((double) freebytes
.QuadPart
),
6798 make_float ((double) availbytes
.QuadPart
));
6802 DWORD sectors_per_cluster
;
6803 DWORD bytes_per_sector
;
6804 DWORD free_clusters
;
6805 DWORD total_clusters
;
6807 if (GetDiskFreeSpace (rootname
,
6808 §ors_per_cluster
,
6812 value
= list3 (make_float ((double) total_clusters
6813 * sectors_per_cluster
* bytes_per_sector
),
6814 make_float ((double) free_clusters
6815 * sectors_per_cluster
* bytes_per_sector
),
6816 make_float ((double) free_clusters
6817 * sectors_per_cluster
* bytes_per_sector
));
6824 DEFUN ("default-printer-name", Fdefault_printer_name
, Sdefault_printer_name
,
6825 0, 0, 0, doc
: /* Return the name of Windows default printer device. */)
6828 static char pname_buf
[256];
6831 PRINTER_INFO_2
*ppi2
= NULL
;
6832 DWORD dwNeeded
= 0, dwReturned
= 0;
6834 /* Retrieve the default string from Win.ini (the registry).
6835 * String will be in form "printername,drivername,portname".
6836 * This is the most portable way to get the default printer. */
6837 if (GetProfileString ("windows", "device", ",,", pname_buf
, sizeof (pname_buf
)) <= 0)
6839 /* printername precedes first "," character */
6840 strtok (pname_buf
, ",");
6841 /* We want to know more than the printer name */
6842 if (!OpenPrinter (pname_buf
, &hPrn
, NULL
))
6844 GetPrinter (hPrn
, 2, NULL
, 0, &dwNeeded
);
6847 ClosePrinter (hPrn
);
6850 /* Allocate memory for the PRINTER_INFO_2 struct */
6851 ppi2
= (PRINTER_INFO_2
*) xmalloc (dwNeeded
);
6854 ClosePrinter (hPrn
);
6857 /* Call GetPrinter again with big enouth memory block */
6858 err
= GetPrinter (hPrn
, 2, (LPBYTE
)ppi2
, dwNeeded
, &dwReturned
);
6859 ClosePrinter (hPrn
);
6868 if (ppi2
->Attributes
& PRINTER_ATTRIBUTE_SHARED
&& ppi2
->pServerName
)
6870 /* a remote printer */
6871 if (*ppi2
->pServerName
== '\\')
6872 _snprintf (pname_buf
, sizeof (pname_buf
), "%s\\%s", ppi2
->pServerName
,
6875 _snprintf (pname_buf
, sizeof (pname_buf
), "\\\\%s\\%s", ppi2
->pServerName
,
6877 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
6881 /* a local printer */
6882 strncpy (pname_buf
, ppi2
->pPortName
, sizeof (pname_buf
));
6883 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
6884 /* `pPortName' can include several ports, delimited by ','.
6885 * we only use the first one. */
6886 strtok (pname_buf
, ",");
6891 return build_string (pname_buf
);
6894 /***********************************************************************
6896 ***********************************************************************/
6898 /* Keep this list in the same order as frame_parms in frame.c.
6899 Use 0 for unsupported frame parameters. */
6901 frame_parm_handler w32_frame_parm_handlers
[] =
6905 x_set_background_color
,
6911 x_set_foreground_color
,
6914 x_set_internal_border_width
,
6915 x_set_menu_bar_lines
,
6917 x_explicitly_set_name
,
6918 x_set_scroll_bar_width
,
6921 x_set_vertical_scroll_bars
,
6923 x_set_tool_bar_lines
,
6924 0, /* x_set_scroll_bar_foreground, */
6925 0, /* x_set_scroll_bar_background, */
6930 0, /* x_set_wait_for_wm, */
6939 globals_of_w32fns ();
6940 /* This is zero if not using MS-Windows. */
6942 track_mouse_window
= NULL
;
6944 w32_visible_system_caret_hwnd
= NULL
;
6946 DEFSYM (Qnone
, "none");
6947 DEFSYM (Qsuppress_icon
, "suppress-icon");
6948 DEFSYM (Qundefined_color
, "undefined-color");
6949 DEFSYM (Qcancel_timer
, "cancel-timer");
6950 DEFSYM (Qhyper
, "hyper");
6951 DEFSYM (Qsuper
, "super");
6952 DEFSYM (Qmeta
, "meta");
6953 DEFSYM (Qalt
, "alt");
6954 DEFSYM (Qctrl
, "ctrl");
6955 DEFSYM (Qcontrol
, "control");
6956 DEFSYM (Qshift
, "shift");
6957 DEFSYM (Qfont_param
, "font-parameter");
6958 /* This is the end of symbol initialization. */
6960 /* Text property `display' should be nonsticky by default. */
6961 Vtext_property_default_nonsticky
6962 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
6965 Fput (Qundefined_color
, Qerror_conditions
,
6966 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
6967 Fput (Qundefined_color
, Qerror_message
,
6968 build_string ("Undefined color"));
6970 staticpro (&w32_grabbed_keys
);
6971 w32_grabbed_keys
= Qnil
;
6973 DEFVAR_LISP ("w32-color-map", &Vw32_color_map
,
6974 doc
: /* An array of color name mappings for Windows. */);
6975 Vw32_color_map
= Qnil
;
6977 DEFVAR_LISP ("w32-pass-alt-to-system", &Vw32_pass_alt_to_system
,
6978 doc
: /* Non-nil if Alt key presses are passed on to Windows.
6979 When non-nil, for example, Alt pressed and released and then space will
6980 open the System menu. When nil, Emacs processes the Alt key events, and
6981 then silently swallows them. */);
6982 Vw32_pass_alt_to_system
= Qnil
;
6984 DEFVAR_LISP ("w32-alt-is-meta", &Vw32_alt_is_meta
,
6985 doc
: /* Non-nil if the Alt key is to be considered the same as the META key.
6986 When nil, Emacs will translate the Alt key to the ALT modifier, not to META. */);
6987 Vw32_alt_is_meta
= Qt
;
6989 DEFVAR_INT ("w32-quit-key", &w32_quit_key
,
6990 doc
: /* If non-zero, the virtual key code for an alternative quit key. */);
6993 DEFVAR_LISP ("w32-pass-lwindow-to-system",
6994 &Vw32_pass_lwindow_to_system
,
6995 doc
: /* If non-nil, the left \"Windows\" key is passed on to Windows.
6997 When non-nil, the Start menu is opened by tapping the key.
6998 If you set this to nil, the left \"Windows\" key is processed by Emacs
6999 according to the value of `w32-lwindow-modifier', which see.
7001 Note that some combinations of the left \"Windows\" key with other keys are
7002 caught by Windows at low level, and so binding them in Emacs will have no
7003 effect. For example, <lwindow>-r always pops up the Windows Run dialog,
7004 <lwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
7005 the doc string of `w32-phantom-key-code'. */);
7006 Vw32_pass_lwindow_to_system
= Qt
;
7008 DEFVAR_LISP ("w32-pass-rwindow-to-system",
7009 &Vw32_pass_rwindow_to_system
,
7010 doc
: /* If non-nil, the right \"Windows\" key is passed on to Windows.
7012 When non-nil, the Start menu is opened by tapping the key.
7013 If you set this to nil, the right \"Windows\" key is processed by Emacs
7014 according to the value of `w32-rwindow-modifier', which see.
7016 Note that some combinations of the right \"Windows\" key with other keys are
7017 caught by Windows at low level, and so binding them in Emacs will have no
7018 effect. For example, <rwindow>-r always pops up the Windows Run dialog,
7019 <rwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
7020 the doc string of `w32-phantom-key-code'. */);
7021 Vw32_pass_rwindow_to_system
= Qt
;
7023 DEFVAR_LISP ("w32-phantom-key-code",
7024 &Vw32_phantom_key_code
,
7025 doc
: /* Virtual key code used to generate \"phantom\" key presses.
7026 Value is a number between 0 and 255.
7028 Phantom key presses are generated in order to stop the system from
7029 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or
7030 `w32-pass-rwindow-to-system' is nil. */);
7031 /* Although 255 is technically not a valid key code, it works and
7032 means that this hack won't interfere with any real key code. */
7033 XSETINT (Vw32_phantom_key_code
, 255);
7035 DEFVAR_LISP ("w32-enable-num-lock",
7036 &Vw32_enable_num_lock
,
7037 doc
: /* If non-nil, the Num Lock key acts normally.
7038 Set to nil to handle Num Lock as the `kp-numlock' key. */);
7039 Vw32_enable_num_lock
= Qt
;
7041 DEFVAR_LISP ("w32-enable-caps-lock",
7042 &Vw32_enable_caps_lock
,
7043 doc
: /* If non-nil, the Caps Lock key acts normally.
7044 Set to nil to handle Caps Lock as the `capslock' key. */);
7045 Vw32_enable_caps_lock
= Qt
;
7047 DEFVAR_LISP ("w32-scroll-lock-modifier",
7048 &Vw32_scroll_lock_modifier
,
7049 doc
: /* Modifier to use for the Scroll Lock ON state.
7050 The value can be hyper, super, meta, alt, control or shift for the
7051 respective modifier, or nil to handle Scroll Lock as the `scroll' key.
7052 Any other value will cause the Scroll Lock key to be ignored. */);
7053 Vw32_scroll_lock_modifier
= Qt
;
7055 DEFVAR_LISP ("w32-lwindow-modifier",
7056 &Vw32_lwindow_modifier
,
7057 doc
: /* Modifier to use for the left \"Windows\" key.
7058 The value can be hyper, super, meta, alt, control or shift for the
7059 respective modifier, or nil to appear as the `lwindow' key.
7060 Any other value will cause the key to be ignored. */);
7061 Vw32_lwindow_modifier
= Qnil
;
7063 DEFVAR_LISP ("w32-rwindow-modifier",
7064 &Vw32_rwindow_modifier
,
7065 doc
: /* Modifier to use for the right \"Windows\" key.
7066 The value can be hyper, super, meta, alt, control or shift for the
7067 respective modifier, or nil to appear as the `rwindow' key.
7068 Any other value will cause the key to be ignored. */);
7069 Vw32_rwindow_modifier
= Qnil
;
7071 DEFVAR_LISP ("w32-apps-modifier",
7072 &Vw32_apps_modifier
,
7073 doc
: /* Modifier to use for the \"Apps\" key.
7074 The value can be hyper, super, meta, alt, control or shift for the
7075 respective modifier, or nil to appear as the `apps' key.
7076 Any other value will cause the key to be ignored. */);
7077 Vw32_apps_modifier
= Qnil
;
7079 DEFVAR_BOOL ("w32-enable-synthesized-fonts", &w32_enable_synthesized_fonts
,
7080 doc
: /* Non-nil enables selection of artificially italicized and bold fonts. */);
7081 w32_enable_synthesized_fonts
= 0;
7083 DEFVAR_LISP ("w32-enable-palette", &Vw32_enable_palette
,
7084 doc
: /* Non-nil enables Windows palette management to map colors exactly. */);
7085 Vw32_enable_palette
= Qt
;
7087 DEFVAR_INT ("w32-mouse-button-tolerance",
7088 &w32_mouse_button_tolerance
,
7089 doc
: /* Analogue of double click interval for faking middle mouse events.
7090 The value is the minimum time in milliseconds that must elapse between
7091 left and right button down events before they are considered distinct events.
7092 If both mouse buttons are depressed within this interval, a middle mouse
7093 button down event is generated instead. */);
7094 w32_mouse_button_tolerance
= GetDoubleClickTime () / 2;
7096 DEFVAR_INT ("w32-mouse-move-interval",
7097 &w32_mouse_move_interval
,
7098 doc
: /* Minimum interval between mouse move events.
7099 The value is the minimum time in milliseconds that must elapse between
7100 successive mouse move (or scroll bar drag) events before they are
7101 reported as lisp events. */);
7102 w32_mouse_move_interval
= 0;
7104 DEFVAR_BOOL ("w32-pass-extra-mouse-buttons-to-system",
7105 &w32_pass_extra_mouse_buttons_to_system
,
7106 doc
: /* If non-nil, the fourth and fifth mouse buttons are passed to Windows.
7107 Recent versions of Windows support mice with up to five buttons.
7108 Since most applications don't support these extra buttons, most mouse
7109 drivers will allow you to map them to functions at the system level.
7110 If this variable is non-nil, Emacs will pass them on, allowing the
7111 system to handle them. */);
7112 w32_pass_extra_mouse_buttons_to_system
= 0;
7114 DEFVAR_BOOL ("w32-pass-multimedia-buttons-to-system",
7115 &w32_pass_multimedia_buttons_to_system
,
7116 doc
: /* If non-nil, media buttons are passed to Windows.
7117 Some modern keyboards contain buttons for controlling media players, web
7118 browsers and other applications. Generally these buttons are handled on a
7119 system wide basis, but by setting this to nil they are made available
7120 to Emacs for binding. Depending on your keyboard, additional keys that
7121 may be available are:
7123 browser-back, browser-forward, browser-refresh, browser-stop,
7124 browser-search, browser-favorites, browser-home,
7125 mail, mail-reply, mail-forward, mail-send,
7127 help, find, new, open, close, save, print, undo, redo, copy, cut, paste,
7128 spell-check, correction-list, toggle-dictate-command,
7129 media-next, media-previous, media-stop, media-play-pause, media-select,
7130 media-play, media-pause, media-record, media-fast-forward, media-rewind,
7131 media-channel-up, media-channel-down,
7132 volume-mute, volume-up, volume-down,
7133 mic-volume-mute, mic-volume-down, mic-volume-up, mic-toggle,
7134 bass-down, bass-boost, bass-up, treble-down, treble-up */);
7135 w32_pass_multimedia_buttons_to_system
= 1;
7137 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
7138 doc
: /* The shape of the pointer when over text.
7139 Changing the value does not affect existing frames
7140 unless you set the mouse color. */);
7141 Vx_pointer_shape
= Qnil
;
7143 Vx_nontext_pointer_shape
= Qnil
;
7145 Vx_mode_pointer_shape
= Qnil
;
7147 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
7148 doc
: /* The shape of the pointer when Emacs is busy.
7149 This variable takes effect when you create a new frame
7150 or when you set the mouse color. */);
7151 Vx_hourglass_pointer_shape
= Qnil
;
7153 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
7154 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
7155 display_hourglass_p
= 1;
7157 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
7158 doc
: /* *Seconds to wait before displaying an hourglass pointer.
7159 Value must be an integer or float. */);
7160 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
7162 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
7163 &Vx_sensitive_text_pointer_shape
,
7164 doc
: /* The shape of the pointer when over mouse-sensitive text.
7165 This variable takes effect when you create a new frame
7166 or when you set the mouse color. */);
7167 Vx_sensitive_text_pointer_shape
= Qnil
;
7169 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
7170 &Vx_window_horizontal_drag_shape
,
7171 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
7172 This variable takes effect when you create a new frame
7173 or when you set the mouse color. */);
7174 Vx_window_horizontal_drag_shape
= Qnil
;
7176 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
7177 doc
: /* A string indicating the foreground color of the cursor box. */);
7178 Vx_cursor_fore_pixel
= Qnil
;
7180 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size
,
7181 doc
: /* Maximum size for tooltips.
7182 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
7183 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
7185 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
7186 doc
: /* Non-nil if no window manager is in use.
7187 Emacs doesn't try to figure this out; this is always nil
7188 unless you set it to something else. */);
7189 /* We don't have any way to find this out, so set it to nil
7190 and maybe the user would like to set it to t. */
7191 Vx_no_window_manager
= Qnil
;
7193 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
7194 &Vx_pixel_size_width_font_regexp
,
7195 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
7197 Since Emacs gets width of a font matching with this regexp from
7198 PIXEL_SIZE field of the name, font finding mechanism gets faster for
7199 such a font. This is especially effective for such large fonts as
7200 Chinese, Japanese, and Korean. */);
7201 Vx_pixel_size_width_font_regexp
= Qnil
;
7203 DEFVAR_LISP ("w32-bdf-filename-alist",
7204 &Vw32_bdf_filename_alist
,
7205 doc
: /* List of bdf fonts and their corresponding filenames. */);
7206 Vw32_bdf_filename_alist
= Qnil
;
7208 DEFVAR_BOOL ("w32-strict-fontnames",
7209 &w32_strict_fontnames
,
7210 doc
: /* Non-nil means only use fonts that are exact matches for those requested.
7211 Default is nil, which allows old fontnames that are not XLFD compliant,
7212 and allows third-party CJK display to work by specifying false charset
7213 fields to trick Emacs into translating to Big5, SJIS etc.
7214 Setting this to t will prevent wrong fonts being selected when
7215 fontsets are automatically created. */);
7216 w32_strict_fontnames
= 0;
7218 DEFVAR_BOOL ("w32-strict-painting",
7219 &w32_strict_painting
,
7220 doc
: /* Non-nil means use strict rules for repainting frames.
7221 Set this to nil to get the old behavior for repainting; this should
7222 only be necessary if the default setting causes problems. */);
7223 w32_strict_painting
= 1;
7225 #if 0 /* TODO: Port to W32 */
7226 defsubr (&Sx_change_window_property
);
7227 defsubr (&Sx_delete_window_property
);
7228 defsubr (&Sx_window_property
);
7230 defsubr (&Sxw_display_color_p
);
7231 defsubr (&Sx_display_grayscale_p
);
7232 defsubr (&Sxw_color_defined_p
);
7233 defsubr (&Sxw_color_values
);
7234 defsubr (&Sx_server_max_request_size
);
7235 defsubr (&Sx_server_vendor
);
7236 defsubr (&Sx_server_version
);
7237 defsubr (&Sx_display_pixel_width
);
7238 defsubr (&Sx_display_pixel_height
);
7239 defsubr (&Sx_display_mm_width
);
7240 defsubr (&Sx_display_mm_height
);
7241 defsubr (&Sx_display_screens
);
7242 defsubr (&Sx_display_planes
);
7243 defsubr (&Sx_display_color_cells
);
7244 defsubr (&Sx_display_visual_class
);
7245 defsubr (&Sx_display_backing_store
);
7246 defsubr (&Sx_display_save_under
);
7247 defsubr (&Sx_create_frame
);
7248 defsubr (&Sx_open_connection
);
7249 defsubr (&Sx_close_connection
);
7250 defsubr (&Sx_display_list
);
7251 defsubr (&Sx_synchronize
);
7252 defsubr (&Sx_focus_frame
);
7254 /* W32 specific functions */
7256 defsubr (&Sw32_define_rgb_color
);
7257 defsubr (&Sw32_default_color_map
);
7258 defsubr (&Sw32_load_color_file
);
7259 defsubr (&Sw32_send_sys_command
);
7260 defsubr (&Sw32_shell_execute
);
7261 defsubr (&Sw32_register_hot_key
);
7262 defsubr (&Sw32_unregister_hot_key
);
7263 defsubr (&Sw32_registered_hot_keys
);
7264 defsubr (&Sw32_reconstruct_hot_key
);
7265 defsubr (&Sw32_toggle_lock_key
);
7266 defsubr (&Sw32_window_exists_p
);
7267 defsubr (&Sw32_battery_status
);
7269 defsubr (&Sfile_system_info
);
7270 defsubr (&Sdefault_printer_name
);
7272 check_window_system_func
= check_w32
;
7275 hourglass_timer
= 0;
7276 hourglass_hwnd
= NULL
;
7277 hourglass_shown_p
= 0;
7278 defsubr (&Sx_show_tip
);
7279 defsubr (&Sx_hide_tip
);
7281 staticpro (&tip_timer
);
7283 staticpro (&tip_frame
);
7285 last_show_tip_args
= Qnil
;
7286 staticpro (&last_show_tip_args
);
7288 defsubr (&Sx_file_dialog
);
7289 defsubr (&Ssystem_move_file_to_trash
);
7294 globals_of_w32fns is used to initialize those global variables that
7295 must always be initialized on startup even when the global variable
7296 initialized is non zero (see the function main in emacs.c).
7297 globals_of_w32fns is called from syms_of_w32fns when the global
7298 variable initialized is 0 and directly from main when initialized
7302 globals_of_w32fns ()
7304 HMODULE user32_lib
= GetModuleHandle ("user32.dll");
7306 TrackMouseEvent not available in all versions of Windows, so must load
7307 it dynamically. Do it once, here, instead of every time it is used.
7309 track_mouse_event_fn
= (TrackMouseEvent_Proc
)
7310 GetProcAddress (user32_lib
, "TrackMouseEvent");
7311 /* ditto for GetClipboardSequenceNumber. */
7312 clipboard_sequence_fn
= (ClipboardSequence_Proc
)
7313 GetProcAddress (user32_lib
, "GetClipboardSequenceNumber");
7315 monitor_from_point_fn
= (MonitorFromPoint_Proc
)
7316 GetProcAddress (user32_lib
, "MonitorFromPoint");
7317 get_monitor_info_fn
= (GetMonitorInfo_Proc
)
7318 GetProcAddress (user32_lib
, "GetMonitorInfoA");
7321 HMODULE imm32_lib
= GetModuleHandle ("imm32.dll");
7322 get_composition_string_fn
= (ImmGetCompositionString_Proc
)
7323 GetProcAddress (imm32_lib
, "ImmGetCompositionStringW");
7324 get_ime_context_fn
= (ImmGetContext_Proc
)
7325 GetProcAddress (imm32_lib
, "ImmGetContext");
7327 DEFVAR_INT ("w32-ansi-code-page",
7328 &w32_ansi_code_page
,
7329 doc
: /* The ANSI code page used by the system. */);
7330 w32_ansi_code_page
= GetACP ();
7332 /* MessageBox does not work without this when linked to comctl32.dll 6.0. */
7333 InitCommonControls ();
7335 syms_of_w32uniscribe ();
7344 button
= MessageBox (NULL
,
7345 "A fatal error has occurred!\n\n"
7346 "Would you like to attach a debugger?\n\n"
7347 "Select YES to debug, NO to abort Emacs"
7349 "\n\n(type \"gdb -p <emacs-PID>\" and\n"
7350 "\"continue\" inside GDB before clicking YES.)"
7352 , "Emacs Abort Dialog",
7353 MB_ICONEXCLAMATION
| MB_TASKMODAL
7354 | MB_SETFOREGROUND
| MB_YESNO
);
7359 exit (2); /* tell the compiler we will never return */
7367 /* For convenience when debugging. */
7371 return GetLastError ();
7374 /* arch-tag: 707589ab-b9be-4638-8cdd-74629cc9b446
7375 (do not change this comment) */