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 of creating a frame. */
1991 /* Return the value of parameter PARAM.
1993 First search ALIST, then Vdefault_frame_alist, then the X defaults
1994 database, using ATTRIBUTE as the attribute name and CLASS as its class.
1996 Convert the resource to the type specified by desired_type.
1998 If no default is specified, return Qunbound. If you call
1999 w32_get_arg, make sure you deal with Qunbound in a reasonable way,
2000 and don't let it get stored in any Lisp-visible variables! */
2003 w32_get_arg (alist
, param
, attribute
, class, type
)
2004 Lisp_Object alist
, param
;
2007 enum resource_types type
;
2009 return x_get_arg (check_x_display_info (Qnil
),
2010 alist
, param
, attribute
, class, type
);
2015 w32_load_cursor (LPCTSTR name
)
2017 /* Try first to load cursor from application resource. */
2018 Cursor cursor
= LoadImage ((HINSTANCE
) GetModuleHandle (NULL
),
2019 name
, IMAGE_CURSOR
, 0, 0,
2020 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
2023 /* Then try to load a shared predefined cursor. */
2024 cursor
= LoadImage (NULL
, name
, IMAGE_CURSOR
, 0, 0,
2025 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
2030 extern LRESULT CALLBACK
w32_wnd_proc ();
2033 w32_init_class (hinst
)
2038 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
2039 wc
.lpfnWndProc
= (WNDPROC
) w32_wnd_proc
;
2041 wc
.cbWndExtra
= WND_EXTRA_BYTES
;
2042 wc
.hInstance
= hinst
;
2043 wc
.hIcon
= LoadIcon (hinst
, EMACS_CLASS
);
2044 wc
.hCursor
= w32_load_cursor (IDC_ARROW
);
2045 wc
.hbrBackground
= NULL
; /* GetStockObject (WHITE_BRUSH); */
2046 wc
.lpszMenuName
= NULL
;
2047 wc
.lpszClassName
= EMACS_CLASS
;
2049 return (RegisterClass (&wc
));
2053 w32_createscrollbar (f
, bar
)
2055 struct scroll_bar
* bar
;
2057 return (CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
2058 /* Position and size of scroll bar. */
2059 XINT (bar
->left
) + VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
2061 XINT (bar
->width
) - VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
2063 FRAME_W32_WINDOW (f
),
2070 w32_createwindow (f
)
2075 Lisp_Object top
= Qunbound
;
2076 Lisp_Object left
= Qunbound
;
2078 rect
.left
= rect
.top
= 0;
2079 rect
.right
= FRAME_PIXEL_WIDTH (f
);
2080 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
2082 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
2083 FRAME_EXTERNAL_MENU_BAR (f
));
2085 /* Do first time app init */
2089 w32_init_class (hinst
);
2092 if (f
->size_hint_flags
& USPosition
|| f
->size_hint_flags
& PPosition
)
2094 XSETINT (left
, f
->left_pos
);
2095 XSETINT (top
, f
->top_pos
);
2097 else if (EQ (left
, Qunbound
) && EQ (top
, Qunbound
))
2099 /* When called with RES_TYPE_NUMBER, w32_get_arg will return zero
2100 for anything that is not a number and is not Qunbound. */
2101 left
= w32_get_arg (Qnil
, Qleft
, "left", "Left", RES_TYPE_NUMBER
);
2102 top
= w32_get_arg (Qnil
, Qtop
, "top", "Top", RES_TYPE_NUMBER
);
2105 FRAME_W32_WINDOW (f
) = hwnd
2106 = CreateWindow (EMACS_CLASS
,
2108 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
2109 EQ (left
, Qunbound
) ? CW_USEDEFAULT
: XINT (left
),
2110 EQ (top
, Qunbound
) ? CW_USEDEFAULT
: XINT (top
),
2111 rect
.right
- rect
.left
,
2112 rect
.bottom
- rect
.top
,
2120 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
2121 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
2122 SetWindowLong (hwnd
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
2123 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->scroll_bar_actual_width
);
2124 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
2126 /* Enable drag-n-drop. */
2127 DragAcceptFiles (hwnd
, TRUE
);
2129 /* Do this to discard the default setting specified by our parent. */
2130 ShowWindow (hwnd
, SW_HIDE
);
2132 /* Update frame positions. */
2133 GetWindowRect (hwnd
, &rect
);
2134 f
->left_pos
= rect
.left
;
2135 f
->top_pos
= rect
.top
;
2140 my_post_msg (wmsg
, hwnd
, msg
, wParam
, lParam
)
2147 wmsg
->msg
.hwnd
= hwnd
;
2148 wmsg
->msg
.message
= msg
;
2149 wmsg
->msg
.wParam
= wParam
;
2150 wmsg
->msg
.lParam
= lParam
;
2151 wmsg
->msg
.time
= GetMessageTime ();
2156 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
2157 between left and right keys as advertised. We test for this
2158 support dynamically, and set a flag when the support is absent. If
2159 absent, we keep track of the left and right control and alt keys
2160 ourselves. This is particularly necessary on keyboards that rely
2161 upon the AltGr key, which is represented as having the left control
2162 and right alt keys pressed. For these keyboards, we need to know
2163 when the left alt key has been pressed in addition to the AltGr key
2164 so that we can properly support M-AltGr-key sequences (such as M-@
2165 on Swedish keyboards). */
2167 #define EMACS_LCONTROL 0
2168 #define EMACS_RCONTROL 1
2169 #define EMACS_LMENU 2
2170 #define EMACS_RMENU 3
2172 static int modifiers
[4];
2173 static int modifiers_recorded
;
2174 static int modifier_key_support_tested
;
2177 test_modifier_support (unsigned int wparam
)
2181 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
2183 if (wparam
== VK_CONTROL
)
2193 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
2194 modifiers_recorded
= 1;
2196 modifiers_recorded
= 0;
2197 modifier_key_support_tested
= 1;
2201 record_keydown (unsigned int wparam
, unsigned int lparam
)
2205 if (!modifier_key_support_tested
)
2206 test_modifier_support (wparam
);
2208 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2211 if (wparam
== VK_CONTROL
)
2212 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2214 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2220 record_keyup (unsigned int wparam
, unsigned int lparam
)
2224 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2227 if (wparam
== VK_CONTROL
)
2228 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2230 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2235 /* Emacs can lose focus while a modifier key has been pressed. When
2236 it regains focus, be conservative and clear all modifiers since
2237 we cannot reconstruct the left and right modifier state. */
2243 if (GetFocus () == NULL
)
2244 /* Emacs doesn't have keyboard focus. Do nothing. */
2247 ctrl
= GetAsyncKeyState (VK_CONTROL
);
2248 alt
= GetAsyncKeyState (VK_MENU
);
2250 if (!(ctrl
& 0x08000))
2251 /* Clear any recorded control modifier state. */
2252 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2254 if (!(alt
& 0x08000))
2255 /* Clear any recorded alt modifier state. */
2256 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2258 /* Update the state of all modifier keys, because modifiers used in
2259 hot-key combinations can get stuck on if Emacs loses focus as a
2260 result of a hot-key being pressed. */
2264 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
2266 GetKeyboardState (keystate
);
2267 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
2268 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
2269 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
2270 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
2271 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
2272 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
2273 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
2274 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
2275 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
2276 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
2277 SetKeyboardState (keystate
);
2281 /* Synchronize modifier state with what is reported with the current
2282 keystroke. Even if we cannot distinguish between left and right
2283 modifier keys, we know that, if no modifiers are set, then neither
2284 the left or right modifier should be set. */
2288 if (!modifiers_recorded
)
2291 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
2292 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2294 if (!(GetKeyState (VK_MENU
) & 0x8000))
2295 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2299 modifier_set (int vkey
)
2301 if (vkey
== VK_CAPITAL
|| vkey
== VK_SCROLL
)
2302 return (GetKeyState (vkey
) & 0x1);
2303 if (!modifiers_recorded
)
2304 return (GetKeyState (vkey
) & 0x8000);
2309 return modifiers
[EMACS_LCONTROL
];
2311 return modifiers
[EMACS_RCONTROL
];
2313 return modifiers
[EMACS_LMENU
];
2315 return modifiers
[EMACS_RMENU
];
2317 return (GetKeyState (vkey
) & 0x8000);
2320 /* Convert between the modifier bits W32 uses and the modifier bits
2324 w32_key_to_modifier (int key
)
2326 Lisp_Object key_mapping
;
2331 key_mapping
= Vw32_lwindow_modifier
;
2334 key_mapping
= Vw32_rwindow_modifier
;
2337 key_mapping
= Vw32_apps_modifier
;
2340 key_mapping
= Vw32_scroll_lock_modifier
;
2346 /* NB. This code runs in the input thread, asychronously to the lisp
2347 thread, so we must be careful to ensure access to lisp data is
2348 thread-safe. The following code is safe because the modifier
2349 variable values are updated atomically from lisp and symbols are
2350 not relocated by GC. Also, we don't have to worry about seeing GC
2352 if (EQ (key_mapping
, Qhyper
))
2353 return hyper_modifier
;
2354 if (EQ (key_mapping
, Qsuper
))
2355 return super_modifier
;
2356 if (EQ (key_mapping
, Qmeta
))
2357 return meta_modifier
;
2358 if (EQ (key_mapping
, Qalt
))
2359 return alt_modifier
;
2360 if (EQ (key_mapping
, Qctrl
))
2361 return ctrl_modifier
;
2362 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
2363 return ctrl_modifier
;
2364 if (EQ (key_mapping
, Qshift
))
2365 return shift_modifier
;
2367 /* Don't generate any modifier if not explicitly requested. */
2372 w32_get_modifiers ()
2374 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
2375 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
2376 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
2377 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
2378 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
2379 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
2380 (modifier_set (VK_MENU
) ?
2381 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
2384 /* We map the VK_* modifiers into console modifier constants
2385 so that we can use the same routines to handle both console
2386 and window input. */
2389 construct_console_modifiers ()
2394 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
2395 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
2396 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
2397 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
2398 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
2399 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
2400 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
2401 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
2402 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
2403 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
2404 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
2410 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
2414 /* Convert to emacs modifiers. */
2415 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
2421 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
2423 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
2426 if (virt_key
== VK_RETURN
)
2427 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
2429 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
2430 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
2432 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
2433 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
2435 if (virt_key
== VK_CLEAR
)
2436 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
2441 /* List of special key combinations which w32 would normally capture,
2442 but Emacs should grab instead. Not directly visible to lisp, to
2443 simplify synchronization. Each item is an integer encoding a virtual
2444 key code and modifier combination to capture. */
2445 static Lisp_Object w32_grabbed_keys
;
2447 #define HOTKEY(vk, mods) make_number (((vk) & 255) | ((mods) << 8))
2448 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
2449 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
2450 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
2452 #define RAW_HOTKEY_ID(k) ((k) & 0xbfff)
2453 #define RAW_HOTKEY_VK_CODE(k) ((k) & 255)
2454 #define RAW_HOTKEY_MODIFIERS(k) ((k) >> 8)
2456 /* Register hot-keys for reserved key combinations when Emacs has
2457 keyboard focus, since this is the only way Emacs can receive key
2458 combinations like Alt-Tab which are used by the system. */
2461 register_hot_keys (hwnd
)
2464 Lisp_Object keylist
;
2466 /* Use CONSP, since we are called asynchronously. */
2467 for (keylist
= w32_grabbed_keys
; CONSP (keylist
); keylist
= XCDR (keylist
))
2469 Lisp_Object key
= XCAR (keylist
);
2471 /* Deleted entries get set to nil. */
2472 if (!INTEGERP (key
))
2475 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
2476 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
2481 unregister_hot_keys (hwnd
)
2484 Lisp_Object keylist
;
2486 for (keylist
= w32_grabbed_keys
; CONSP (keylist
); keylist
= XCDR (keylist
))
2488 Lisp_Object key
= XCAR (keylist
);
2490 if (!INTEGERP (key
))
2493 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
2497 /* Main message dispatch loop. */
2500 w32_msg_pump (deferred_msg
* msg_buf
)
2506 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
2508 while (GetMessage (&msg
, NULL
, 0, 0))
2510 if (msg
.hwnd
== NULL
)
2512 switch (msg
.message
)
2515 /* Produced by complete_deferred_msg; just ignore. */
2517 case WM_EMACS_CREATEWINDOW
:
2518 /* Initialize COM for this window. Even though we don't use it,
2519 some third party shell extensions can cause it to be used in
2520 system dialogs, which causes a crash if it is not initialized.
2521 This is a known bug in Windows, which was fixed long ago, but
2522 the patch for XP is not publically available until XP SP3,
2523 and older versions will never be patched. */
2524 CoInitialize (NULL
);
2525 w32_createwindow ((struct frame
*) msg
.wParam
);
2526 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2529 case WM_EMACS_SETLOCALE
:
2530 SetThreadLocale (msg
.wParam
);
2531 /* Reply is not expected. */
2533 case WM_EMACS_SETKEYBOARDLAYOUT
:
2534 result
= (int) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
2535 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2539 case WM_EMACS_REGISTER_HOT_KEY
:
2540 focus_window
= GetFocus ();
2541 if (focus_window
!= NULL
)
2542 RegisterHotKey (focus_window
,
2543 RAW_HOTKEY_ID (msg
.wParam
),
2544 RAW_HOTKEY_MODIFIERS (msg
.wParam
),
2545 RAW_HOTKEY_VK_CODE (msg
.wParam
));
2546 /* Reply is not expected. */
2548 case WM_EMACS_UNREGISTER_HOT_KEY
:
2549 focus_window
= GetFocus ();
2550 if (focus_window
!= NULL
)
2551 UnregisterHotKey (focus_window
, RAW_HOTKEY_ID (msg
.wParam
));
2552 /* Mark item as erased. NB: this code must be
2553 thread-safe. The next line is okay because the cons
2554 cell is never made into garbage and is not relocated by
2556 XSETCAR ((Lisp_Object
) ((EMACS_INT
) msg
.lParam
), Qnil
);
2557 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2560 case WM_EMACS_TOGGLE_LOCK_KEY
:
2562 int vk_code
= (int) msg
.wParam
;
2563 int cur_state
= (GetKeyState (vk_code
) & 1);
2564 Lisp_Object new_state
= (Lisp_Object
) ((EMACS_INT
) msg
.lParam
);
2566 /* NB: This code must be thread-safe. It is safe to
2567 call NILP because symbols are not relocated by GC,
2568 and pointer here is not touched by GC (so the markbit
2569 can't be set). Numbers are safe because they are
2570 immediate values. */
2571 if (NILP (new_state
)
2572 || (NUMBERP (new_state
)
2573 && ((XUINT (new_state
)) & 1) != cur_state
))
2575 one_w32_display_info
.faked_key
= vk_code
;
2577 keybd_event ((BYTE
) vk_code
,
2578 (BYTE
) MapVirtualKey (vk_code
, 0),
2579 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2580 keybd_event ((BYTE
) vk_code
,
2581 (BYTE
) MapVirtualKey (vk_code
, 0),
2582 KEYEVENTF_EXTENDEDKEY
| 0, 0);
2583 keybd_event ((BYTE
) vk_code
,
2584 (BYTE
) MapVirtualKey (vk_code
, 0),
2585 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2586 cur_state
= !cur_state
;
2588 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2594 /* Broadcast messages make it here, so you need to be looking
2595 for something in particular for this to be useful. */
2597 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
2603 DispatchMessage (&msg
);
2606 /* Exit nested loop when our deferred message has completed. */
2607 if (msg_buf
->completed
)
2612 deferred_msg
* deferred_msg_head
;
2614 static deferred_msg
*
2615 find_deferred_msg (HWND hwnd
, UINT msg
)
2617 deferred_msg
* item
;
2619 /* Don't actually need synchronization for read access, since
2620 modification of single pointer is always atomic. */
2621 /* enter_crit (); */
2623 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2624 if (item
->w32msg
.msg
.hwnd
== hwnd
2625 && item
->w32msg
.msg
.message
== msg
)
2628 /* leave_crit (); */
2634 send_deferred_msg (deferred_msg
* msg_buf
,
2640 /* Only input thread can send deferred messages. */
2641 if (GetCurrentThreadId () != dwWindowsThreadId
)
2644 /* It is an error to send a message that is already deferred. */
2645 if (find_deferred_msg (hwnd
, msg
) != NULL
)
2648 /* Enforced synchronization is not needed because this is the only
2649 function that alters deferred_msg_head, and the following critical
2650 section is guaranteed to only be serially reentered (since only the
2651 input thread can call us). */
2653 /* enter_crit (); */
2655 msg_buf
->completed
= 0;
2656 msg_buf
->next
= deferred_msg_head
;
2657 deferred_msg_head
= msg_buf
;
2658 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
2660 /* leave_crit (); */
2662 /* Start a new nested message loop to process other messages until
2663 this one is completed. */
2664 w32_msg_pump (msg_buf
);
2666 deferred_msg_head
= msg_buf
->next
;
2668 return msg_buf
->result
;
2672 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
2674 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
2676 if (msg_buf
== NULL
)
2677 /* Message may have been cancelled, so don't abort. */
2680 msg_buf
->result
= result
;
2681 msg_buf
->completed
= 1;
2683 /* Ensure input thread is woken so it notices the completion. */
2684 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2688 cancel_all_deferred_msgs ()
2690 deferred_msg
* item
;
2692 /* Don't actually need synchronization for read access, since
2693 modification of single pointer is always atomic. */
2694 /* enter_crit (); */
2696 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2699 item
->completed
= 1;
2702 /* leave_crit (); */
2704 /* Ensure input thread is woken so it notices the completion. */
2705 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2709 w32_msg_worker (void *arg
)
2712 deferred_msg dummy_buf
;
2714 /* Ensure our message queue is created */
2716 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
2718 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2721 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
2722 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
2723 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
2725 /* This is the initial message loop which should only exit when the
2726 application quits. */
2727 w32_msg_pump (&dummy_buf
);
2733 signal_user_input ()
2735 /* Interrupt any lisp that wants to be interrupted by input. */
2736 if (!NILP (Vthrow_on_input
))
2738 Vquit_flag
= Vthrow_on_input
;
2739 /* If we're inside a function that wants immediate quits,
2741 if (immediate_quit
&& NILP (Vinhibit_quit
))
2751 post_character_message (hwnd
, msg
, wParam
, lParam
, modifiers
)
2761 wmsg
.dwModifiers
= modifiers
;
2763 /* Detect quit_char and set quit-flag directly. Note that we
2764 still need to post a message to ensure the main thread will be
2765 woken up if blocked in sys_select, but we do NOT want to post
2766 the quit_char message itself (because it will usually be as if
2767 the user had typed quit_char twice). Instead, we post a dummy
2768 message that has no particular effect. */
2771 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
2772 c
= make_ctrl_char (c
) & 0377;
2774 || (wmsg
.dwModifiers
== 0 &&
2775 w32_quit_key
&& wParam
== w32_quit_key
))
2779 /* The choice of message is somewhat arbitrary, as long as
2780 the main thread handler just ignores it. */
2783 /* Interrupt any blocking system calls. */
2786 /* As a safety precaution, forcibly complete any deferred
2787 messages. This is a kludge, but I don't see any particularly
2788 clean way to handle the situation where a deferred message is
2789 "dropped" in the lisp thread, and will thus never be
2790 completed, eg. by the user trying to activate the menubar
2791 when the lisp thread is busy, and then typing C-g when the
2792 menubar doesn't open promptly (with the result that the
2793 menubar never responds at all because the deferred
2794 WM_INITMENU message is never completed). Another problem
2795 situation is when the lisp thread calls SendMessage (to send
2796 a window manager command) when a message has been deferred;
2797 the lisp thread gets blocked indefinitely waiting for the
2798 deferred message to be completed, which itself is waiting for
2799 the lisp thread to respond.
2801 Note that we don't want to block the input thread waiting for
2802 a reponse from the lisp thread (although that would at least
2803 solve the deadlock problem above), because we want to be able
2804 to receive C-g to interrupt the lisp thread. */
2805 cancel_all_deferred_msgs ();
2808 signal_user_input ();
2811 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2814 /* Main window procedure */
2817 w32_wnd_proc (hwnd
, msg
, wParam
, lParam
)
2824 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
2826 int windows_translate
;
2829 /* Note that it is okay to call x_window_to_frame, even though we are
2830 not running in the main lisp thread, because frame deletion
2831 requires the lisp thread to synchronize with this thread. Thus, if
2832 a frame struct is returned, it can be used without concern that the
2833 lisp thread might make it disappear while we are using it.
2835 NB. Walking the frame list in this thread is safe (as long as
2836 writes of Lisp_Object slots are atomic, which they are on Windows).
2837 Although delete-frame can destructively modify the frame list while
2838 we are walking it, a garbage collection cannot occur until after
2839 delete-frame has synchronized with this thread.
2841 It is also safe to use functions that make GDI calls, such as
2842 w32_clear_rect, because these functions must obtain a DC handle
2843 from the frame struct using get_frame_dc which is thread-aware. */
2848 f
= x_window_to_frame (dpyinfo
, hwnd
);
2851 HDC hdc
= get_frame_dc (f
);
2852 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
2853 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
2854 release_frame_dc (f
, hdc
);
2856 #if defined (W32_DEBUG_DISPLAY)
2857 DebPrint (("WM_ERASEBKGND (frame %p): erasing %d,%d-%d,%d\n",
2859 wmsg
.rect
.left
, wmsg
.rect
.top
,
2860 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2861 #endif /* W32_DEBUG_DISPLAY */
2864 case WM_PALETTECHANGED
:
2865 /* ignore our own changes */
2866 if ((HWND
)wParam
!= hwnd
)
2868 f
= x_window_to_frame (dpyinfo
, hwnd
);
2870 /* get_frame_dc will realize our palette and force all
2871 frames to be redrawn if needed. */
2872 release_frame_dc (f
, get_frame_dc (f
));
2877 PAINTSTRUCT paintStruct
;
2879 bzero (&update_rect
, sizeof (update_rect
));
2881 f
= x_window_to_frame (dpyinfo
, hwnd
);
2884 DebPrint (("WM_PAINT received for unknown window %p\n", hwnd
));
2888 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
2889 fails. Apparently this can happen under some
2891 if (GetUpdateRect (hwnd
, &update_rect
, FALSE
) || !w32_strict_painting
)
2894 BeginPaint (hwnd
, &paintStruct
);
2896 /* The rectangles returned by GetUpdateRect and BeginPaint
2897 do not always match. Play it safe by assuming both areas
2899 UnionRect (&(wmsg
.rect
), &update_rect
, &(paintStruct
.rcPaint
));
2901 #if defined (W32_DEBUG_DISPLAY)
2902 DebPrint (("WM_PAINT (frame %p): painting %d,%d-%d,%d\n",
2904 wmsg
.rect
.left
, wmsg
.rect
.top
,
2905 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2906 DebPrint ((" [update region is %d,%d-%d,%d]\n",
2907 update_rect
.left
, update_rect
.top
,
2908 update_rect
.right
, update_rect
.bottom
));
2910 EndPaint (hwnd
, &paintStruct
);
2913 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2918 /* If GetUpdateRect returns 0 (meaning there is no update
2919 region), assume the whole window needs to be repainted. */
2920 GetClientRect (hwnd
, &wmsg
.rect
);
2921 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2925 case WM_INPUTLANGCHANGE
:
2926 /* Inform lisp thread of keyboard layout changes. */
2927 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2929 /* Clear dead keys in the keyboard state; for simplicity only
2930 preserve modifier key states. */
2935 GetKeyboardState (keystate
);
2936 for (i
= 0; i
< 256; i
++)
2953 SetKeyboardState (keystate
);
2958 /* Synchronize hot keys with normal input. */
2959 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
2964 record_keyup (wParam
, lParam
);
2969 /* Ignore keystrokes we fake ourself; see below. */
2970 if (dpyinfo
->faked_key
== wParam
)
2972 dpyinfo
->faked_key
= 0;
2973 /* Make sure TranslateMessage sees them though (as long as
2974 they don't produce WM_CHAR messages). This ensures that
2975 indicator lights are toggled promptly on Windows 9x, for
2977 if (wParam
< 256 && lispy_function_keys
[wParam
])
2979 windows_translate
= 1;
2985 /* Synchronize modifiers with current keystroke. */
2987 record_keydown (wParam
, lParam
);
2988 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
2990 windows_translate
= 0;
2995 if (NILP (Vw32_pass_lwindow_to_system
))
2997 /* Prevent system from acting on keyup (which opens the
2998 Start menu if no other key was pressed) by simulating a
2999 press of Space which we will ignore. */
3000 if (GetAsyncKeyState (wParam
) & 1)
3002 if (NUMBERP (Vw32_phantom_key_code
))
3003 key
= XUINT (Vw32_phantom_key_code
) & 255;
3006 dpyinfo
->faked_key
= key
;
3007 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
3010 if (!NILP (Vw32_lwindow_modifier
))
3014 if (NILP (Vw32_pass_rwindow_to_system
))
3016 if (GetAsyncKeyState (wParam
) & 1)
3018 if (NUMBERP (Vw32_phantom_key_code
))
3019 key
= XUINT (Vw32_phantom_key_code
) & 255;
3022 dpyinfo
->faked_key
= key
;
3023 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
3026 if (!NILP (Vw32_rwindow_modifier
))
3030 if (!NILP (Vw32_apps_modifier
))
3034 if (NILP (Vw32_pass_alt_to_system
))
3035 /* Prevent DefWindowProc from activating the menu bar if an
3036 Alt key is pressed and released by itself. */
3038 windows_translate
= 1;
3041 /* Decide whether to treat as modifier or function key. */
3042 if (NILP (Vw32_enable_caps_lock
))
3043 goto disable_lock_key
;
3044 windows_translate
= 1;
3047 /* Decide whether to treat as modifier or function key. */
3048 if (NILP (Vw32_enable_num_lock
))
3049 goto disable_lock_key
;
3050 windows_translate
= 1;
3053 /* Decide whether to treat as modifier or function key. */
3054 if (NILP (Vw32_scroll_lock_modifier
))
3055 goto disable_lock_key
;
3056 windows_translate
= 1;
3059 /* Ensure the appropriate lock key state (and indicator light)
3060 remains in the same state. We do this by faking another
3061 press of the relevant key. Apparently, this really is the
3062 only way to toggle the state of the indicator lights. */
3063 dpyinfo
->faked_key
= wParam
;
3064 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3065 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3066 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3067 KEYEVENTF_EXTENDEDKEY
| 0, 0);
3068 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3069 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3070 /* Ensure indicator lights are updated promptly on Windows 9x
3071 (TranslateMessage apparently does this), after forwarding
3073 post_character_message (hwnd
, msg
, wParam
, lParam
,
3074 w32_get_key_modifiers (wParam
, lParam
));
3075 windows_translate
= 1;
3079 case VK_PROCESSKEY
: /* Generated by IME. */
3080 windows_translate
= 1;
3083 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
3084 which is confusing for purposes of key binding; convert
3085 VK_CANCEL events into VK_PAUSE events. */
3089 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
3090 for purposes of key binding; convert these back into
3091 VK_NUMLOCK events, at least when we want to see NumLock key
3092 presses. (Note that there is never any possibility that
3093 VK_PAUSE with Ctrl really is C-Pause as per above.) */
3094 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
3095 wParam
= VK_NUMLOCK
;
3098 /* If not defined as a function key, change it to a WM_CHAR message. */
3099 if (wParam
> 255 || !lispy_function_keys
[wParam
])
3101 DWORD modifiers
= construct_console_modifiers ();
3103 if (!NILP (Vw32_recognize_altgr
)
3104 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
3106 /* Always let TranslateMessage handle AltGr key chords;
3107 for some reason, ToAscii doesn't always process AltGr
3108 chords correctly. */
3109 windows_translate
= 1;
3111 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
3113 /* Handle key chords including any modifiers other
3114 than shift directly, in order to preserve as much
3115 modifier information as possible. */
3116 if ('A' <= wParam
&& wParam
<= 'Z')
3118 /* Don't translate modified alphabetic keystrokes,
3119 so the user doesn't need to constantly switch
3120 layout to type control or meta keystrokes when
3121 the normal layout translates alphabetic
3122 characters to non-ascii characters. */
3123 if (!modifier_set (VK_SHIFT
))
3124 wParam
+= ('a' - 'A');
3129 /* Try to handle other keystrokes by determining the
3130 base character (ie. translating the base key plus
3134 KEY_EVENT_RECORD key
;
3136 key
.bKeyDown
= TRUE
;
3137 key
.wRepeatCount
= 1;
3138 key
.wVirtualKeyCode
= wParam
;
3139 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
3140 key
.uChar
.AsciiChar
= 0;
3141 key
.dwControlKeyState
= modifiers
;
3143 add
= w32_kbd_patch_key (&key
);
3144 /* 0 means an unrecognised keycode, negative means
3145 dead key. Ignore both. */
3148 /* Forward asciified character sequence. */
3149 post_character_message
3151 (unsigned char) key
.uChar
.AsciiChar
, lParam
,
3152 w32_get_key_modifiers (wParam
, lParam
));
3153 w32_kbd_patch_key (&key
);
3160 /* Let TranslateMessage handle everything else. */
3161 windows_translate
= 1;
3167 if (windows_translate
)
3169 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
3170 windows_msg
.time
= GetMessageTime ();
3171 TranslateMessage (&windows_msg
);
3179 post_character_message (hwnd
, msg
, wParam
, lParam
,
3180 w32_get_key_modifiers (wParam
, lParam
));
3184 /* WM_UNICHAR looks promising from the docs, but the exact
3185 circumstances in which TranslateMessage sends it is one of those
3186 Microsoft secret API things that EU and US courts are supposed
3187 to have put a stop to already. Spy++ shows it being sent to Notepad
3188 and other MS apps, but never to Emacs.
3190 Some third party IMEs send it in accordance with the official
3191 documentation though, so handle it here.
3193 UNICODE_NOCHAR is used to test for support for this message.
3194 TRUE indicates that the message is supported. */
3195 if (wParam
== UNICODE_NOCHAR
)
3200 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3201 signal_user_input ();
3202 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3207 /* If we can't get the IME result as unicode, use default processing,
3208 which will at least allow characters decodable in the system locale
3210 if (!get_composition_string_fn
)
3213 else if (!ignore_ime_char
)
3218 HIMC context
= get_ime_context_fn (hwnd
);
3219 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3220 /* Get buffer size. */
3221 size
= get_composition_string_fn (context
, GCS_RESULTSTR
, buffer
, 0);
3222 buffer
= alloca(size
);
3223 size
= get_composition_string_fn (context
, GCS_RESULTSTR
,
3225 signal_user_input ();
3226 for (i
= 0; i
< size
/ sizeof (wchar_t); i
++)
3228 my_post_msg (&wmsg
, hwnd
, WM_UNICHAR
, (WPARAM
) buffer
[i
],
3231 /* We output the whole string above, so ignore following ones
3232 until we are notified of the end of composition. */
3233 ignore_ime_char
= 1;
3237 case WM_IME_ENDCOMPOSITION
:
3238 ignore_ime_char
= 0;
3241 /* Simulate middle mouse button events when left and right buttons
3242 are used together, but only if user has two button mouse. */
3243 case WM_LBUTTONDOWN
:
3244 case WM_RBUTTONDOWN
:
3245 if (w32_num_mouse_buttons
> 2)
3246 goto handle_plain_button
;
3249 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
3250 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
3252 if (button_state
& this)
3255 if (button_state
== 0)
3258 button_state
|= this;
3260 if (button_state
& other
)
3262 if (mouse_button_timer
)
3264 KillTimer (hwnd
, mouse_button_timer
);
3265 mouse_button_timer
= 0;
3267 /* Generate middle mouse event instead. */
3268 msg
= WM_MBUTTONDOWN
;
3269 button_state
|= MMOUSE
;
3271 else if (button_state
& MMOUSE
)
3273 /* Ignore button event if we've already generated a
3274 middle mouse down event. This happens if the
3275 user releases and press one of the two buttons
3276 after we've faked a middle mouse event. */
3281 /* Flush out saved message. */
3282 post_msg (&saved_mouse_button_msg
);
3284 wmsg
.dwModifiers
= w32_get_modifiers ();
3285 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3286 signal_user_input ();
3288 /* Clear message buffer. */
3289 saved_mouse_button_msg
.msg
.hwnd
= 0;
3293 /* Hold onto message for now. */
3294 mouse_button_timer
=
3295 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
3296 w32_mouse_button_tolerance
, NULL
);
3297 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
3298 saved_mouse_button_msg
.msg
.message
= msg
;
3299 saved_mouse_button_msg
.msg
.wParam
= wParam
;
3300 saved_mouse_button_msg
.msg
.lParam
= lParam
;
3301 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
3302 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
3309 if (w32_num_mouse_buttons
> 2)
3310 goto handle_plain_button
;
3313 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
3314 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
3316 if ((button_state
& this) == 0)
3319 button_state
&= ~this;
3321 if (button_state
& MMOUSE
)
3323 /* Only generate event when second button is released. */
3324 if ((button_state
& other
) == 0)
3327 button_state
&= ~MMOUSE
;
3329 if (button_state
) abort ();
3336 /* Flush out saved message if necessary. */
3337 if (saved_mouse_button_msg
.msg
.hwnd
)
3339 post_msg (&saved_mouse_button_msg
);
3342 wmsg
.dwModifiers
= w32_get_modifiers ();
3343 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3344 signal_user_input ();
3346 /* Always clear message buffer and cancel timer. */
3347 saved_mouse_button_msg
.msg
.hwnd
= 0;
3348 KillTimer (hwnd
, mouse_button_timer
);
3349 mouse_button_timer
= 0;
3351 if (button_state
== 0)
3356 case WM_XBUTTONDOWN
:
3358 if (w32_pass_extra_mouse_buttons_to_system
)
3360 /* else fall through and process them. */
3361 case WM_MBUTTONDOWN
:
3363 handle_plain_button
:
3368 /* Ignore middle and extra buttons as long as the menu is active. */
3369 f
= x_window_to_frame (dpyinfo
, hwnd
);
3370 if (f
&& f
->output_data
.w32
->menubar_active
)
3373 if (parse_button (msg
, HIWORD (wParam
), &button
, &up
))
3375 if (up
) ReleaseCapture ();
3376 else SetCapture (hwnd
);
3377 button
= (button
== 0) ? LMOUSE
:
3378 ((button
== 1) ? MMOUSE
: RMOUSE
);
3380 button_state
&= ~button
;
3382 button_state
|= button
;
3386 wmsg
.dwModifiers
= w32_get_modifiers ();
3387 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3388 signal_user_input ();
3390 /* Need to return true for XBUTTON messages, false for others,
3391 to indicate that we processed the message. */
3392 return (msg
== WM_XBUTTONDOWN
|| msg
== WM_XBUTTONUP
);
3395 /* Ignore mouse movements as long as the menu is active. These
3396 movements are processed by the window manager anyway, and
3397 it's wrong to handle them as if they happened on the
3398 underlying frame. */
3399 f
= x_window_to_frame (dpyinfo
, hwnd
);
3400 if (f
&& f
->output_data
.w32
->menubar_active
)
3403 /* If the mouse has just moved into the frame, start tracking
3404 it, so we will be notified when it leaves the frame. Mouse
3405 tracking only works under W98 and NT4 and later. On earlier
3406 versions, there is no way of telling when the mouse leaves the
3407 frame, so we just have to put up with help-echo and mouse
3408 highlighting remaining while the frame is not active. */
3409 if (track_mouse_event_fn
&& !track_mouse_window
)
3411 TRACKMOUSEEVENT tme
;
3412 tme
.cbSize
= sizeof (tme
);
3413 tme
.dwFlags
= TME_LEAVE
;
3414 tme
.hwndTrack
= hwnd
;
3416 track_mouse_event_fn (&tme
);
3417 track_mouse_window
= hwnd
;
3420 if (w32_mouse_move_interval
<= 0
3421 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
3423 wmsg
.dwModifiers
= w32_get_modifiers ();
3424 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3428 /* Hang onto mouse move and scroll messages for a bit, to avoid
3429 sending such events to Emacs faster than it can process them.
3430 If we get more events before the timer from the first message
3431 expires, we just replace the first message. */
3433 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
3435 SetTimer (hwnd
, MOUSE_MOVE_ID
,
3436 w32_mouse_move_interval
, NULL
);
3438 /* Hold onto message for now. */
3439 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
3440 saved_mouse_move_msg
.msg
.message
= msg
;
3441 saved_mouse_move_msg
.msg
.wParam
= wParam
;
3442 saved_mouse_move_msg
.msg
.lParam
= lParam
;
3443 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
3444 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
3450 wmsg
.dwModifiers
= w32_get_modifiers ();
3451 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3452 signal_user_input ();
3456 if (w32_pass_multimedia_buttons_to_system
)
3458 /* Otherwise, pass to lisp, the same way we do with mousehwheel. */
3459 case WM_MOUSEHWHEEL
:
3460 wmsg
.dwModifiers
= w32_get_modifiers ();
3461 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3462 signal_user_input ();
3463 /* Non-zero must be returned when WM_MOUSEHWHEEL messages are
3464 handled, to prevent the system trying to handle it by faking
3465 scroll bar events. */
3469 /* Flush out saved messages if necessary. */
3470 if (wParam
== mouse_button_timer
)
3472 if (saved_mouse_button_msg
.msg
.hwnd
)
3474 post_msg (&saved_mouse_button_msg
);
3475 signal_user_input ();
3476 saved_mouse_button_msg
.msg
.hwnd
= 0;
3478 KillTimer (hwnd
, mouse_button_timer
);
3479 mouse_button_timer
= 0;
3481 else if (wParam
== mouse_move_timer
)
3483 if (saved_mouse_move_msg
.msg
.hwnd
)
3485 post_msg (&saved_mouse_move_msg
);
3486 saved_mouse_move_msg
.msg
.hwnd
= 0;
3488 KillTimer (hwnd
, mouse_move_timer
);
3489 mouse_move_timer
= 0;
3491 else if (wParam
== menu_free_timer
)
3493 KillTimer (hwnd
, menu_free_timer
);
3494 menu_free_timer
= 0;
3495 f
= x_window_to_frame (dpyinfo
, hwnd
);
3496 /* If a popup menu is active, don't wipe its strings. */
3498 && current_popup_menu
== NULL
)
3500 /* Free memory used by owner-drawn and help-echo strings. */
3501 w32_free_menu_strings (hwnd
);
3502 f
->output_data
.w32
->menubar_active
= 0;
3506 else if (wParam
== hourglass_timer
)
3508 KillTimer (hwnd
, hourglass_timer
);
3509 hourglass_timer
= 0;
3510 show_hourglass (x_window_to_frame (dpyinfo
, hwnd
));
3515 /* Windows doesn't send us focus messages when putting up and
3516 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
3517 The only indication we get that something happened is receiving
3518 this message afterwards. So this is a good time to reset our
3519 keyboard modifiers' state. */
3526 /* We must ensure menu bar is fully constructed and up to date
3527 before allowing user interaction with it. To achieve this
3528 we send this message to the lisp thread and wait for a
3529 reply (whose value is not actually needed) to indicate that
3530 the menu bar is now ready for use, so we can now return.
3532 To remain responsive in the meantime, we enter a nested message
3533 loop that can process all other messages.
3535 However, we skip all this if the message results from calling
3536 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
3537 thread a message because it is blocked on us at this point. We
3538 set menubar_active before calling TrackPopupMenu to indicate
3539 this (there is no possibility of confusion with real menubar
3542 f
= x_window_to_frame (dpyinfo
, hwnd
);
3544 && (f
->output_data
.w32
->menubar_active
3545 /* We can receive this message even in the absence of a
3546 menubar (ie. when the system menu is activated) - in this
3547 case we do NOT want to forward the message, otherwise it
3548 will cause the menubar to suddenly appear when the user
3549 had requested it to be turned off! */
3550 || f
->output_data
.w32
->menubar_widget
== NULL
))
3554 deferred_msg msg_buf
;
3556 /* Detect if message has already been deferred; in this case
3557 we cannot return any sensible value to ignore this. */
3558 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3563 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
3566 case WM_EXITMENULOOP
:
3567 f
= x_window_to_frame (dpyinfo
, hwnd
);
3569 /* If a menu is still active, check again after a short delay,
3570 since Windows often (always?) sends the WM_EXITMENULOOP
3571 before the corresponding WM_COMMAND message.
3572 Don't do this if a popup menu is active, since it is only
3573 menubar menus that require cleaning up in this way.
3575 if (f
&& menubar_in_use
&& current_popup_menu
== NULL
)
3576 menu_free_timer
= SetTimer (hwnd
, MENU_FREE_ID
, MENU_FREE_DELAY
, NULL
);
3578 /* If hourglass cursor should be displayed, display it now. */
3579 if (f
&& f
->output_data
.w32
->hourglass_p
)
3580 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
3585 /* Direct handling of help_echo in menus. Should be safe now
3586 that we generate the help_echo by placing a help event in the
3589 HMENU menu
= (HMENU
) lParam
;
3590 UINT menu_item
= (UINT
) LOWORD (wParam
);
3591 UINT flags
= (UINT
) HIWORD (wParam
);
3593 w32_menu_display_help (hwnd
, menu
, menu_item
, flags
);
3597 case WM_MEASUREITEM
:
3598 f
= x_window_to_frame (dpyinfo
, hwnd
);
3601 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
3603 if (pMis
->CtlType
== ODT_MENU
)
3605 /* Work out dimensions for popup menu titles. */
3606 char * title
= (char *) pMis
->itemData
;
3607 HDC hdc
= GetDC (hwnd
);
3608 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3609 LOGFONT menu_logfont
;
3613 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3614 menu_logfont
.lfWeight
= FW_BOLD
;
3615 menu_font
= CreateFontIndirect (&menu_logfont
);
3616 old_font
= SelectObject (hdc
, menu_font
);
3618 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
3621 if (unicode_append_menu
)
3622 GetTextExtentPoint32W (hdc
, (WCHAR
*) title
,
3623 wcslen ((WCHAR
*) title
),
3626 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
3628 pMis
->itemWidth
= size
.cx
;
3629 if (pMis
->itemHeight
< size
.cy
)
3630 pMis
->itemHeight
= size
.cy
;
3633 pMis
->itemWidth
= 0;
3635 SelectObject (hdc
, old_font
);
3636 DeleteObject (menu_font
);
3637 ReleaseDC (hwnd
, hdc
);
3644 f
= x_window_to_frame (dpyinfo
, hwnd
);
3647 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
3649 if (pDis
->CtlType
== ODT_MENU
)
3651 /* Draw popup menu title. */
3652 char * title
= (char *) pDis
->itemData
;
3655 HDC hdc
= pDis
->hDC
;
3656 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3657 LOGFONT menu_logfont
;
3660 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3661 menu_logfont
.lfWeight
= FW_BOLD
;
3662 menu_font
= CreateFontIndirect (&menu_logfont
);
3663 old_font
= SelectObject (hdc
, menu_font
);
3665 /* Always draw title as if not selected. */
3666 if (unicode_append_menu
)
3669 + GetSystemMetrics (SM_CXMENUCHECK
),
3671 ETO_OPAQUE
, &pDis
->rcItem
,
3673 wcslen ((WCHAR
*) title
), NULL
);
3677 + GetSystemMetrics (SM_CXMENUCHECK
),
3679 ETO_OPAQUE
, &pDis
->rcItem
,
3680 title
, strlen (title
), NULL
);
3682 SelectObject (hdc
, old_font
);
3683 DeleteObject (menu_font
);
3691 /* Still not right - can't distinguish between clicks in the
3692 client area of the frame from clicks forwarded from the scroll
3693 bars - may have to hook WM_NCHITTEST to remember the mouse
3694 position and then check if it is in the client area ourselves. */
3695 case WM_MOUSEACTIVATE
:
3696 /* Discard the mouse click that activates a frame, allowing the
3697 user to click anywhere without changing point (or worse!).
3698 Don't eat mouse clicks on scrollbars though!! */
3699 if (LOWORD (lParam
) == HTCLIENT
)
3700 return MA_ACTIVATEANDEAT
;
3705 /* No longer tracking mouse. */
3706 track_mouse_window
= NULL
;
3708 case WM_ACTIVATEAPP
:
3710 case WM_WINDOWPOSCHANGED
:
3712 /* Inform lisp thread that a frame might have just been obscured
3713 or exposed, so should recheck visibility of all frames. */
3714 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3718 dpyinfo
->faked_key
= 0;
3720 register_hot_keys (hwnd
);
3723 unregister_hot_keys (hwnd
);
3726 /* Relinquish the system caret. */
3727 if (w32_system_caret_hwnd
)
3729 w32_visible_system_caret_hwnd
= NULL
;
3730 w32_system_caret_hwnd
= NULL
;
3736 f
= x_window_to_frame (dpyinfo
, hwnd
);
3737 if (f
&& HIWORD (wParam
) == 0)
3739 if (menu_free_timer
)
3741 KillTimer (hwnd
, menu_free_timer
);
3742 menu_free_timer
= 0;
3748 wmsg
.dwModifiers
= w32_get_modifiers ();
3749 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3757 wmsg
.dwModifiers
= w32_get_modifiers ();
3758 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3761 case WM_WINDOWPOSCHANGING
:
3762 /* Don't restrict the sizing of tip frames. */
3763 if (hwnd
== tip_window
)
3767 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
3769 wp
.length
= sizeof (WINDOWPLACEMENT
);
3770 GetWindowPlacement (hwnd
, &wp
);
3772 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
3779 DWORD internal_border
;
3780 DWORD scrollbar_extra
;
3783 wp
.length
= sizeof (wp
);
3784 GetWindowRect (hwnd
, &wr
);
3788 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
3789 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
3790 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
3791 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
3795 memset (&rect
, 0, sizeof (rect
));
3796 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
3797 GetMenu (hwnd
) != NULL
);
3799 /* Force width and height of client area to be exact
3800 multiples of the character cell dimensions. */
3801 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
3802 - 2 * internal_border
- scrollbar_extra
)
3804 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
3805 - 2 * internal_border
)
3810 /* For right/bottom sizing we can just fix the sizes.
3811 However for top/left sizing we will need to fix the X
3812 and Y positions as well. */
3814 int cx_mintrack
= GetSystemMetrics (SM_CXMINTRACK
);
3815 int cy_mintrack
= GetSystemMetrics (SM_CYMINTRACK
);
3817 lppos
->cx
= max (lppos
->cx
- wdiff
, cx_mintrack
);
3818 lppos
->cy
= max (lppos
->cy
- hdiff
, cy_mintrack
);
3820 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
3821 && (lppos
->flags
& SWP_NOMOVE
) == 0)
3823 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
3830 lppos
->flags
|= SWP_NOMOVE
;
3841 case WM_GETMINMAXINFO
:
3842 /* Hack to allow resizing the Emacs frame above the screen size.
3843 Note that Windows 9x limits coordinates to 16-bits. */
3844 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.x
= 32767;
3845 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.y
= 32767;
3849 if (LOWORD (lParam
) == HTCLIENT
)
3851 f
= x_window_to_frame (dpyinfo
, hwnd
);
3852 if (f
->output_data
.w32
->hourglass_p
&& !menubar_in_use
3853 && !current_popup_menu
)
3854 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
3856 SetCursor (f
->output_data
.w32
->current_cursor
);
3861 case WM_EMACS_SETCURSOR
:
3863 Cursor cursor
= (Cursor
) wParam
;
3864 f
= x_window_to_frame (dpyinfo
, hwnd
);
3867 f
->output_data
.w32
->current_cursor
= cursor
;
3868 if (!f
->output_data
.w32
->hourglass_p
)
3874 case WM_EMACS_CREATESCROLLBAR
:
3875 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
3876 (struct scroll_bar
*) lParam
);
3878 case WM_EMACS_SHOWWINDOW
:
3879 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
3881 case WM_EMACS_SETFOREGROUND
:
3883 HWND foreground_window
;
3884 DWORD foreground_thread
, retval
;
3886 /* On NT 5.0, and apparently Windows 98, it is necessary to
3887 attach to the thread that currently has focus in order to
3888 pull the focus away from it. */
3889 foreground_window
= GetForegroundWindow ();
3890 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
3891 if (!foreground_window
3892 || foreground_thread
== GetCurrentThreadId ()
3893 || !AttachThreadInput (GetCurrentThreadId (),
3894 foreground_thread
, TRUE
))
3895 foreground_thread
= 0;
3897 retval
= SetForegroundWindow ((HWND
) wParam
);
3899 /* Detach from the previous foreground thread. */
3900 if (foreground_thread
)
3901 AttachThreadInput (GetCurrentThreadId (),
3902 foreground_thread
, FALSE
);
3907 case WM_EMACS_SETWINDOWPOS
:
3909 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
3910 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
3911 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
3914 case WM_EMACS_DESTROYWINDOW
:
3915 DragAcceptFiles ((HWND
) wParam
, FALSE
);
3916 return DestroyWindow ((HWND
) wParam
);
3918 case WM_EMACS_HIDE_CARET
:
3919 return HideCaret (hwnd
);
3921 case WM_EMACS_SHOW_CARET
:
3922 return ShowCaret (hwnd
);
3924 case WM_EMACS_DESTROY_CARET
:
3925 w32_system_caret_hwnd
= NULL
;
3926 w32_visible_system_caret_hwnd
= NULL
;
3927 return DestroyCaret ();
3929 case WM_EMACS_TRACK_CARET
:
3930 /* If there is currently no system caret, create one. */
3931 if (w32_system_caret_hwnd
== NULL
)
3933 /* Use the default caret width, and avoid changing it
3934 unneccesarily, as it confuses screen reader software. */
3935 w32_system_caret_hwnd
= hwnd
;
3936 CreateCaret (hwnd
, NULL
, 0,
3937 w32_system_caret_height
);
3940 if (!SetCaretPos (w32_system_caret_x
, w32_system_caret_y
))
3942 /* Ensure visible caret gets turned on when requested. */
3943 else if (w32_use_visible_system_caret
3944 && w32_visible_system_caret_hwnd
!= hwnd
)
3946 w32_visible_system_caret_hwnd
= hwnd
;
3947 return ShowCaret (hwnd
);
3949 /* Ensure visible caret gets turned off when requested. */
3950 else if (!w32_use_visible_system_caret
3951 && w32_visible_system_caret_hwnd
)
3953 w32_visible_system_caret_hwnd
= NULL
;
3954 return HideCaret (hwnd
);
3959 case WM_EMACS_TRACKPOPUPMENU
:
3964 pos
= (POINT
*)lParam
;
3965 flags
= TPM_CENTERALIGN
;
3966 if (button_state
& LMOUSE
)
3967 flags
|= TPM_LEFTBUTTON
;
3968 else if (button_state
& RMOUSE
)
3969 flags
|= TPM_RIGHTBUTTON
;
3971 /* Remember we did a SetCapture on the initial mouse down event,
3972 so for safety, we make sure the capture is cancelled now. */
3976 /* Use menubar_active to indicate that WM_INITMENU is from
3977 TrackPopupMenu below, and should be ignored. */
3978 f
= x_window_to_frame (dpyinfo
, hwnd
);
3980 f
->output_data
.w32
->menubar_active
= 1;
3982 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
3986 /* Eat any mouse messages during popupmenu */
3987 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
3989 /* Get the menu selection, if any */
3990 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
3992 retval
= LOWORD (amsg
.wParam
);
4008 /* Check for messages registered at runtime. */
4009 if (msg
== msh_mousewheel
)
4011 wmsg
.dwModifiers
= w32_get_modifiers ();
4012 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4013 signal_user_input ();
4018 return DefWindowProc (hwnd
, msg
, wParam
, lParam
);
4022 /* The most common default return code for handled messages is 0. */
4027 my_create_window (f
)
4032 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
4034 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
4038 /* Create a tooltip window. Unlike my_create_window, we do not do this
4039 indirectly via the Window thread, as we do not need to process Window
4040 messages for the tooltip. Creating tooltips indirectly also creates
4041 deadlocks when tooltips are created for menu items. */
4043 my_create_tip_window (f
)
4048 rect
.left
= rect
.top
= 0;
4049 rect
.right
= FRAME_PIXEL_WIDTH (f
);
4050 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
4052 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
4053 FRAME_EXTERNAL_MENU_BAR (f
));
4055 tip_window
= FRAME_W32_WINDOW (f
)
4056 = CreateWindow (EMACS_CLASS
,
4058 f
->output_data
.w32
->dwStyle
,
4061 rect
.right
- rect
.left
,
4062 rect
.bottom
- rect
.top
,
4063 FRAME_W32_WINDOW (SELECTED_FRAME ()), /* owner */
4070 SetWindowLong (tip_window
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
4071 SetWindowLong (tip_window
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
4072 SetWindowLong (tip_window
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
4073 SetWindowLong (tip_window
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
4075 /* Tip frames have no scrollbars. */
4076 SetWindowLong (tip_window
, WND_SCROLLBAR_INDEX
, 0);
4078 /* Do this to discard the default setting specified by our parent. */
4079 ShowWindow (tip_window
, SW_HIDE
);
4084 /* Create and set up the w32 window for frame F. */
4087 w32_window (f
, window_prompting
, minibuffer_only
)
4089 long window_prompting
;
4090 int minibuffer_only
;
4094 /* Use the resource name as the top-level window name
4095 for looking up resources. Make a non-Lisp copy
4096 for the window manager, so GC relocation won't bother it.
4098 Elsewhere we specify the window name for the window manager. */
4101 char *str
= (char *) SDATA (Vx_resource_name
);
4102 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
4103 strcpy (f
->namebuf
, str
);
4106 my_create_window (f
);
4108 validate_x_resource_name ();
4110 /* x_set_name normally ignores requests to set the name if the
4111 requested name is the same as the current name. This is the one
4112 place where that assumption isn't correct; f->name is set, but
4113 the server hasn't been told. */
4116 int explicit = f
->explicit_name
;
4118 f
->explicit_name
= 0;
4121 x_set_name (f
, name
, explicit);
4126 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
4127 initialize_frame_menubar (f
);
4129 if (FRAME_W32_WINDOW (f
) == 0)
4130 error ("Unable to create window");
4133 /* Handle the icon stuff for this window. Perhaps later we might
4134 want an x_set_icon_position which can be called interactively as
4142 Lisp_Object icon_x
, icon_y
;
4144 /* Set the position of the icon. Note that Windows 95 groups all
4145 icons in the tray. */
4146 icon_x
= w32_get_arg (parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
4147 icon_y
= w32_get_arg (parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
4148 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
4150 CHECK_NUMBER (icon_x
);
4151 CHECK_NUMBER (icon_y
);
4153 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
4154 error ("Both left and top icon corners of icon must be specified");
4158 if (! EQ (icon_x
, Qunbound
))
4159 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
4162 /* Start up iconic or window? */
4163 x_wm_set_window_state
4164 (f
, (EQ (w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
4168 x_text_icon (f
, (char *) SDATA ((!NILP (f
->icon_name
)
4181 XGCValues gc_values
;
4185 /* Create the GC's of this frame.
4186 Note that many default values are used. */
4189 gc_values
.font
= FRAME_FONT (f
);
4191 /* Cursor has cursor-color background, background-color foreground. */
4192 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
4193 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
4194 f
->output_data
.w32
->cursor_gc
4195 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
4196 (GCFont
| GCForeground
| GCBackground
),
4200 f
->output_data
.w32
->white_relief
.gc
= 0;
4201 f
->output_data
.w32
->black_relief
.gc
= 0;
4207 /* Handler for signals raised during x_create_frame and
4208 x_create_top_frame. FRAME is the frame which is partially
4212 unwind_create_frame (frame
)
4215 struct frame
*f
= XFRAME (frame
);
4217 /* If frame is ``official'', nothing to do. */
4218 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
4221 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4224 x_free_frame_resources (f
);
4226 /* Check that reference counts are indeed correct. */
4227 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
4228 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
4237 x_default_font_parameter (f
, parms
)
4241 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4242 Lisp_Object font_param
= x_get_arg (dpyinfo
, parms
, Qfont
, NULL
, NULL
,
4245 if (EQ (font_param
, Qunbound
))
4247 font
= !NILP (font_param
) ? font_param
4248 : x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4250 if (!STRINGP (font
))
4253 static char *names
[]
4254 = { "Courier New-10",
4255 "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1",
4256 "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1",
4260 for (i
= 0; names
[i
]; i
++)
4262 font
= font_open_by_name (f
, names
[i
]);
4267 error ("No suitable font was found");
4269 else if (!NILP (font_param
))
4271 /* Remember the explicit font parameter, so we can re-apply it after
4272 we've applied the `default' face settings. */
4273 x_set_frame_parameters (f
, Fcons (Fcons (Qfont_param
, font_param
), Qnil
));
4275 x_default_parameter (f
, parms
, Qfont
, font
, "font", "Font", RES_TYPE_STRING
);
4278 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
4280 doc
: /* Make a new window, which is called a \"frame\" in Emacs terms.
4281 Return an Emacs frame object.
4282 PARAMETERS is an alist of frame parameters.
4283 If the parameters specify that the frame should not have a minibuffer,
4284 and do not specify a specific minibuffer window to use,
4285 then `default-minibuffer-frame' must be a frame whose minibuffer can
4286 be shared by the new frame.
4288 This function is an internal primitive--use `make-frame' instead. */)
4290 Lisp_Object parameters
;
4293 Lisp_Object frame
, tem
;
4295 int minibuffer_only
= 0;
4296 long window_prompting
= 0;
4298 int count
= SPECPDL_INDEX ();
4299 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4300 Lisp_Object display
;
4301 struct w32_display_info
*dpyinfo
= NULL
;
4307 /* Make copy of frame parameters because the original is in pure
4309 parameters
= Fcopy_alist (parameters
);
4311 /* Use this general default value to start with
4312 until we know if this frame has a specified name. */
4313 Vx_resource_name
= Vinvocation_name
;
4315 display
= w32_get_arg (parameters
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
4316 if (EQ (display
, Qunbound
))
4318 dpyinfo
= check_x_display_info (display
);
4320 kb
= dpyinfo
->terminal
->kboard
;
4322 kb
= &the_only_kboard
;
4325 name
= w32_get_arg (parameters
, Qname
, "name", "Name", RES_TYPE_STRING
);
4327 && ! EQ (name
, Qunbound
)
4329 error ("Invalid frame name--not a string or nil");
4332 Vx_resource_name
= name
;
4334 /* See if parent window is specified. */
4335 parent
= w32_get_arg (parameters
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
4336 if (EQ (parent
, Qunbound
))
4338 if (! NILP (parent
))
4339 CHECK_NUMBER (parent
);
4341 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
4342 /* No need to protect DISPLAY because that's not used after passing
4343 it to make_frame_without_minibuffer. */
4345 GCPRO4 (parameters
, parent
, name
, frame
);
4346 tem
= w32_get_arg (parameters
, Qminibuffer
, "minibuffer", "Minibuffer",
4348 if (EQ (tem
, Qnone
) || NILP (tem
))
4349 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
4350 else if (EQ (tem
, Qonly
))
4352 f
= make_minibuffer_frame ();
4353 minibuffer_only
= 1;
4355 else if (WINDOWP (tem
))
4356 f
= make_frame_without_minibuffer (tem
, kb
, display
);
4360 XSETFRAME (frame
, f
);
4362 /* Note that Windows does support scroll bars. */
4363 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
4365 /* By default, make scrollbars the system standard width. */
4366 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
4368 f
->terminal
= dpyinfo
->terminal
;
4369 f
->terminal
->reference_count
++;
4371 f
->output_method
= output_w32
;
4372 f
->output_data
.w32
=
4373 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
4374 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
4375 FRAME_FONTSET (f
) = -1;
4376 record_unwind_protect (unwind_create_frame
, frame
);
4379 = w32_get_arg (parameters
, Qicon_name
, "iconName", "Title", RES_TYPE_STRING
);
4380 if (! STRINGP (f
->icon_name
))
4381 f
->icon_name
= Qnil
;
4383 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
4385 FRAME_KBOARD (f
) = kb
;
4388 /* Specify the parent under which to make this window. */
4392 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
4393 f
->output_data
.w32
->explicit_parent
= 1;
4397 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4398 f
->output_data
.w32
->explicit_parent
= 0;
4401 /* Set the name; the functions to which we pass f expect the name to
4403 if (EQ (name
, Qunbound
) || NILP (name
))
4405 f
->name
= build_string (dpyinfo
->w32_id_name
);
4406 f
->explicit_name
= 0;
4411 f
->explicit_name
= 1;
4412 /* use the frame's title when getting resources for this frame. */
4413 specbind (Qx_resource_name
, name
);
4416 f
->resx
= dpyinfo
->resx
;
4417 f
->resy
= dpyinfo
->resy
;
4419 if (uniscribe_available
)
4420 register_font_driver (&uniscribe_font_driver
, f
);
4421 register_font_driver (&w32font_driver
, f
);
4423 x_default_parameter (f
, parameters
, Qfont_backend
, Qnil
,
4424 "fontBackend", "FontBackend", RES_TYPE_STRING
);
4425 /* Extract the window parameters from the supplied values
4426 that are needed to determine window geometry. */
4427 x_default_font_parameter (f
, parameters
);
4428 x_default_parameter (f
, parameters
, Qborder_width
, make_number (2),
4429 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4430 /* This defaults to 2 in order to match xterm. We recognize either
4431 internalBorderWidth or internalBorder (which is what xterm calls
4433 if (NILP (Fassq (Qinternal_border_width
, parameters
)))
4437 value
= w32_get_arg (parameters
, Qinternal_border_width
,
4438 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
4439 if (! EQ (value
, Qunbound
))
4440 parameters
= Fcons (Fcons (Qinternal_border_width
, value
),
4443 /* Default internalBorderWidth to 0 on Windows to match other programs. */
4444 x_default_parameter (f
, parameters
, Qinternal_border_width
, make_number (0),
4445 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
4446 x_default_parameter (f
, parameters
, Qvertical_scroll_bars
, Qright
,
4447 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
4449 /* Also do the stuff which must be set before the window exists. */
4450 x_default_parameter (f
, parameters
, Qforeground_color
, build_string ("black"),
4451 "foreground", "Foreground", RES_TYPE_STRING
);
4452 x_default_parameter (f
, parameters
, Qbackground_color
, build_string ("white"),
4453 "background", "Background", RES_TYPE_STRING
);
4454 x_default_parameter (f
, parameters
, Qmouse_color
, build_string ("black"),
4455 "pointerColor", "Foreground", RES_TYPE_STRING
);
4456 x_default_parameter (f
, parameters
, Qcursor_color
, build_string ("black"),
4457 "cursorColor", "Foreground", RES_TYPE_STRING
);
4458 x_default_parameter (f
, parameters
, Qborder_color
, build_string ("black"),
4459 "borderColor", "BorderColor", RES_TYPE_STRING
);
4460 x_default_parameter (f
, parameters
, Qscreen_gamma
, Qnil
,
4461 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
4462 x_default_parameter (f
, parameters
, Qline_spacing
, Qnil
,
4463 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
4464 x_default_parameter (f
, parameters
, Qleft_fringe
, Qnil
,
4465 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
4466 x_default_parameter (f
, parameters
, Qright_fringe
, Qnil
,
4467 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
4470 /* Init faces before x_default_parameter is called for scroll-bar
4471 parameters because that function calls x_set_scroll_bar_width,
4472 which calls change_frame_size, which calls Fset_window_buffer,
4473 which runs hooks, which call Fvertical_motion. At the end, we
4474 end up in init_iterator with a null face cache, which should not
4476 init_frame_faces (f
);
4478 x_default_parameter (f
, parameters
, Qmenu_bar_lines
, make_number (1),
4479 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
4480 x_default_parameter (f
, parameters
, Qtool_bar_lines
, make_number (1),
4481 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
4483 x_default_parameter (f
, parameters
, Qbuffer_predicate
, Qnil
,
4484 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
4485 x_default_parameter (f
, parameters
, Qtitle
, Qnil
,
4486 "title", "Title", RES_TYPE_STRING
);
4487 x_default_parameter (f
, parameters
, Qfullscreen
, Qnil
,
4488 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
4490 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
4491 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4493 f
->output_data
.w32
->text_cursor
= w32_load_cursor (IDC_IBEAM
);
4494 f
->output_data
.w32
->nontext_cursor
= w32_load_cursor (IDC_ARROW
);
4495 f
->output_data
.w32
->modeline_cursor
= w32_load_cursor (IDC_ARROW
);
4496 f
->output_data
.w32
->hand_cursor
= w32_load_cursor (IDC_HAND
);
4497 f
->output_data
.w32
->hourglass_cursor
= w32_load_cursor (IDC_WAIT
);
4498 f
->output_data
.w32
->horizontal_drag_cursor
= w32_load_cursor (IDC_SIZEWE
);
4500 f
->output_data
.w32
->current_cursor
= f
->output_data
.w32
->nontext_cursor
;
4502 window_prompting
= x_figure_window_size (f
, parameters
, 1);
4504 tem
= w32_get_arg (parameters
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
4505 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
4507 w32_window (f
, window_prompting
, minibuffer_only
);
4508 x_icon (f
, parameters
);
4512 /* Now consider the frame official. */
4513 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
4514 Vframe_list
= Fcons (frame
, Vframe_list
);
4516 /* We need to do this after creating the window, so that the
4517 icon-creation functions can say whose icon they're describing. */
4518 x_default_parameter (f
, parameters
, Qicon_type
, Qnil
,
4519 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
4521 x_default_parameter (f
, parameters
, Qauto_raise
, Qnil
,
4522 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4523 x_default_parameter (f
, parameters
, Qauto_lower
, Qnil
,
4524 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4525 x_default_parameter (f
, parameters
, Qcursor_type
, Qbox
,
4526 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4527 x_default_parameter (f
, parameters
, Qscroll_bar_width
, Qnil
,
4528 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
4529 x_default_parameter (f
, parameters
, Qalpha
, Qnil
,
4530 "alpha", "Alpha", RES_TYPE_NUMBER
);
4532 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4533 Change will not be effected unless different from the current
4535 width
= FRAME_COLS (f
);
4536 height
= FRAME_LINES (f
);
4538 FRAME_LINES (f
) = 0;
4539 SET_FRAME_COLS (f
, 0);
4540 change_frame_size (f
, height
, width
, 1, 0, 0);
4542 /* Tell the server what size and position, etc, we want, and how
4543 badly we want them. This should be done after we have the menu
4544 bar so that its size can be taken into account. */
4546 x_wm_set_size_hint (f
, window_prompting
, 0);
4549 /* Make the window appear on the frame and enable display, unless
4550 the caller says not to. However, with explicit parent, Emacs
4551 cannot control visibility, so don't try. */
4552 if (! f
->output_data
.w32
->explicit_parent
)
4554 Lisp_Object visibility
;
4556 visibility
= w32_get_arg (parameters
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
4557 if (EQ (visibility
, Qunbound
))
4560 if (EQ (visibility
, Qicon
))
4561 x_iconify_frame (f
);
4562 else if (! NILP (visibility
))
4563 x_make_frame_visible (f
);
4565 /* Must have been Qnil. */
4569 /* Initialize `default-minibuffer-frame' in case this is the first
4570 frame on this terminal. */
4571 if (FRAME_HAS_MINIBUF_P (f
)
4572 && (!FRAMEP (kb
->Vdefault_minibuffer_frame
)
4573 || !FRAME_LIVE_P (XFRAME (kb
->Vdefault_minibuffer_frame
))))
4574 kb
->Vdefault_minibuffer_frame
= frame
;
4576 /* All remaining specified parameters, which have not been "used"
4577 by x_get_arg and friends, now go in the misc. alist of the frame. */
4578 for (tem
= parameters
; CONSP (tem
); tem
= XCDR (tem
))
4579 if (CONSP (XCAR (tem
)) && !NILP (XCAR (XCAR (tem
))))
4580 f
->param_alist
= Fcons (XCAR (tem
), f
->param_alist
);
4584 /* Make sure windows on this frame appear in calls to next-window
4585 and similar functions. */
4586 Vwindow_list
= Qnil
;
4588 return unbind_to (count
, frame
);
4591 /* FRAME is used only to get a handle on the X display. We don't pass the
4592 display info directly because we're called from frame.c, which doesn't
4593 know about that structure. */
4595 x_get_focus_frame (frame
)
4596 struct frame
*frame
;
4598 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
4600 if (! dpyinfo
->w32_focus_frame
)
4603 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
4607 DEFUN ("x-focus-frame", Fx_focus_frame
, Sx_focus_frame
, 1, 1, 0,
4608 doc
: /* Give FRAME input focus, raising to foreground if necessary. */)
4612 x_focus_on_frame (check_x_frame (frame
));
4617 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
4618 doc
: /* Internal function called by `color-defined-p', which see. */)
4620 Lisp_Object color
, frame
;
4623 FRAME_PTR f
= check_x_frame (frame
);
4625 CHECK_STRING (color
);
4627 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
4633 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
4634 doc
: /* Internal function called by `color-values', which see. */)
4636 Lisp_Object color
, frame
;
4639 FRAME_PTR f
= check_x_frame (frame
);
4641 CHECK_STRING (color
);
4643 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
4644 return list3 (make_number ((GetRValue (foo
.pixel
) << 8)
4645 | GetRValue (foo
.pixel
)),
4646 make_number ((GetGValue (foo
.pixel
) << 8)
4647 | GetGValue (foo
.pixel
)),
4648 make_number ((GetBValue (foo
.pixel
) << 8)
4649 | GetBValue (foo
.pixel
)));
4654 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
4655 doc
: /* Internal function called by `display-color-p', which see. */)
4657 Lisp_Object display
;
4659 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4661 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
4667 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
,
4668 Sx_display_grayscale_p
, 0, 1, 0,
4669 doc
: /* Return t if DISPLAY supports shades of gray.
4670 Note that color displays do support shades of gray.
4671 The optional argument DISPLAY specifies which display to ask about.
4672 DISPLAY should be either a frame or a display name (a string).
4673 If omitted or nil, that stands for the selected frame's display. */)
4675 Lisp_Object display
;
4677 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4679 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
4685 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
,
4686 Sx_display_pixel_width
, 0, 1, 0,
4687 doc
: /* Return the width 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
->width
);
4699 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
4700 Sx_display_pixel_height
, 0, 1, 0,
4701 doc
: /* Return the height in pixels 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
->height
);
4713 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
4715 doc
: /* Return the number of bitplanes 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
);
4724 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
4727 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
4729 doc
: /* Return the number of color cells of DISPLAY.
4730 The optional argument DISPLAY specifies which display to ask about.
4731 DISPLAY should be either a frame or a display name (a string).
4732 If omitted or nil, that stands for the selected frame's display. */)
4734 Lisp_Object display
;
4736 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4740 hdc
= GetDC (dpyinfo
->root_window
);
4741 if (dpyinfo
->has_palette
)
4742 cap
= GetDeviceCaps (hdc
, SIZEPALETTE
);
4744 cap
= GetDeviceCaps (hdc
, NUMCOLORS
);
4746 /* We force 24+ bit depths to 24-bit, both to prevent an overflow
4747 and because probably is more meaningful on Windows anyway */
4749 cap
= 1 << min (dpyinfo
->n_planes
* dpyinfo
->n_cbits
, 24);
4751 ReleaseDC (dpyinfo
->root_window
, hdc
);
4753 return make_number (cap
);
4756 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
4757 Sx_server_max_request_size
,
4759 doc
: /* Return the maximum request size of the server of DISPLAY.
4760 The optional argument DISPLAY specifies which display to ask about.
4761 DISPLAY should be either a frame or a display name (a string).
4762 If omitted or nil, that stands for the selected frame's display. */)
4764 Lisp_Object display
;
4766 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4768 return make_number (1);
4771 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
4772 doc
: /* Return the "vendor ID" string of the W32 system (Microsoft).
4773 The optional argument DISPLAY specifies which display to ask about.
4774 DISPLAY should be either a frame or a display name (a string).
4775 If omitted or nil, that stands for the selected frame's display. */)
4777 Lisp_Object display
;
4779 return build_string ("Microsoft Corp.");
4782 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
4783 doc
: /* Return the version numbers of the server of DISPLAY.
4784 The value is a list of three integers: the major and minor
4785 version numbers of the X Protocol in use, and the distributor-specific
4786 release number. See also the function `x-server-vendor'.
4788 The optional argument DISPLAY specifies which display to ask about.
4789 DISPLAY should be either a frame or a display name (a string).
4790 If omitted or nil, that stands for the selected frame's display. */)
4792 Lisp_Object display
;
4794 return Fcons (make_number (w32_major_version
),
4795 Fcons (make_number (w32_minor_version
),
4796 Fcons (make_number (w32_build_number
), Qnil
)));
4799 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
4800 doc
: /* Return the number of screens on the server of DISPLAY.
4801 The optional argument DISPLAY specifies which display to ask about.
4802 DISPLAY should be either a frame or a display name (a string).
4803 If omitted or nil, that stands for the selected frame's display. */)
4805 Lisp_Object display
;
4807 return make_number (1);
4810 DEFUN ("x-display-mm-height", Fx_display_mm_height
,
4811 Sx_display_mm_height
, 0, 1, 0,
4812 doc
: /* Return the height in millimeters of DISPLAY.
4813 The optional argument DISPLAY specifies which display to ask about.
4814 DISPLAY should be either a frame or a display name (a string).
4815 If omitted or nil, that stands for the selected frame's display. */)
4817 Lisp_Object display
;
4819 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4823 hdc
= GetDC (dpyinfo
->root_window
);
4825 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
4827 ReleaseDC (dpyinfo
->root_window
, hdc
);
4829 return make_number (cap
);
4832 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
4833 doc
: /* Return the width in millimeters of DISPLAY.
4834 The optional argument DISPLAY specifies which display to ask about.
4835 DISPLAY should be either a frame or a display name (a string).
4836 If omitted or nil, that stands for the selected frame's display. */)
4838 Lisp_Object display
;
4840 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4845 hdc
= GetDC (dpyinfo
->root_window
);
4847 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
4849 ReleaseDC (dpyinfo
->root_window
, hdc
);
4851 return make_number (cap
);
4854 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
4855 Sx_display_backing_store
, 0, 1, 0,
4856 doc
: /* Return an indication of whether DISPLAY does backing store.
4857 The value may be `always', `when-mapped', or `not-useful'.
4858 The optional argument DISPLAY specifies which display to ask about.
4859 DISPLAY should be either a frame or a display name (a string).
4860 If omitted or nil, that stands for the selected frame's display. */)
4862 Lisp_Object display
;
4864 return intern ("not-useful");
4867 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
4868 Sx_display_visual_class
, 0, 1, 0,
4869 doc
: /* Return the visual class of DISPLAY.
4870 The value is one of the symbols `static-gray', `gray-scale',
4871 `static-color', `pseudo-color', `true-color', or `direct-color'.
4873 The optional argument DISPLAY specifies which display to ask about.
4874 DISPLAY should be either a frame or a display name (a string).
4875 If omitted or nil, that stands for the selected frame's display. */)
4877 Lisp_Object display
;
4879 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4880 Lisp_Object result
= Qnil
;
4882 if (dpyinfo
->has_palette
)
4883 result
= intern ("pseudo-color");
4884 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
4885 result
= intern ("static-grey");
4886 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
4887 result
= intern ("static-color");
4888 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
4889 result
= intern ("true-color");
4894 DEFUN ("x-display-save-under", Fx_display_save_under
,
4895 Sx_display_save_under
, 0, 1, 0,
4896 doc
: /* Return t if DISPLAY supports the save-under feature.
4897 The optional argument DISPLAY specifies which display to ask about.
4898 DISPLAY should be either a frame or a display name (a string).
4899 If omitted or nil, that stands for the selected frame's display. */)
4901 Lisp_Object display
;
4908 register struct frame
*f
;
4910 return FRAME_PIXEL_WIDTH (f
);
4915 register struct frame
*f
;
4917 return FRAME_PIXEL_HEIGHT (f
);
4922 register struct frame
*f
;
4924 return FRAME_COLUMN_WIDTH (f
);
4929 register struct frame
*f
;
4931 return FRAME_LINE_HEIGHT (f
);
4936 register struct frame
*f
;
4938 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
4941 /* Return the display structure for the display named NAME.
4942 Open a new connection if necessary. */
4944 struct w32_display_info
*
4945 x_display_info_for_name (name
)
4949 struct w32_display_info
*dpyinfo
;
4951 CHECK_STRING (name
);
4953 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
4955 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
4958 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
4963 /* Use this general default value to start with. */
4964 Vx_resource_name
= Vinvocation_name
;
4966 validate_x_resource_name ();
4968 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
4969 (char *) SDATA (Vx_resource_name
));
4972 error ("Cannot connect to server %s", SDATA (name
));
4975 XSETFASTINT (Vwindow_system_version
, 3);
4980 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
4981 1, 3, 0, doc
: /* Open a connection to a server.
4982 DISPLAY is the name of the display to connect to.
4983 Optional second arg XRM-STRING is a string of resources in xrdb format.
4984 If the optional third arg MUST-SUCCEED is non-nil,
4985 terminate Emacs if we can't open the connection. */)
4986 (display
, xrm_string
, must_succeed
)
4987 Lisp_Object display
, xrm_string
, must_succeed
;
4989 unsigned char *xrm_option
;
4990 struct w32_display_info
*dpyinfo
;
4992 /* If initialization has already been done, return now to avoid
4993 overwriting critical parts of one_w32_display_info. */
4997 CHECK_STRING (display
);
4998 if (! NILP (xrm_string
))
4999 CHECK_STRING (xrm_string
);
5002 if (! EQ (Vwindow_system
, intern ("w32")))
5003 error ("Not using Microsoft Windows");
5006 /* Allow color mapping to be defined externally; first look in user's
5007 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
5009 Lisp_Object color_file
;
5010 struct gcpro gcpro1
;
5012 color_file
= build_string ("~/rgb.txt");
5014 GCPRO1 (color_file
);
5016 if (NILP (Ffile_readable_p (color_file
)))
5018 Fexpand_file_name (build_string ("rgb.txt"),
5019 Fsymbol_value (intern ("data-directory")));
5021 Vw32_color_map
= Fw32_load_color_file (color_file
);
5025 if (NILP (Vw32_color_map
))
5026 Vw32_color_map
= Fw32_default_color_map ();
5028 /* Merge in system logical colors. */
5029 add_system_logical_colors_to_map (&Vw32_color_map
);
5031 if (! NILP (xrm_string
))
5032 xrm_option
= (unsigned char *) SDATA (xrm_string
);
5034 xrm_option
= (unsigned char *) 0;
5036 /* Use this general default value to start with. */
5037 /* First remove .exe suffix from invocation-name - it looks ugly. */
5039 char basename
[ MAX_PATH
], *str
;
5041 strcpy (basename
, SDATA (Vinvocation_name
));
5042 str
= strrchr (basename
, '.');
5044 Vinvocation_name
= build_string (basename
);
5046 Vx_resource_name
= Vinvocation_name
;
5048 validate_x_resource_name ();
5050 /* This is what opens the connection and sets x_current_display.
5051 This also initializes many symbols, such as those used for input. */
5052 dpyinfo
= w32_term_init (display
, xrm_option
,
5053 (char *) SDATA (Vx_resource_name
));
5057 if (!NILP (must_succeed
))
5058 fatal ("Cannot connect to server %s.\n",
5061 error ("Cannot connect to server %s", SDATA (display
));
5066 XSETFASTINT (Vwindow_system_version
, 3);
5070 DEFUN ("x-close-connection", Fx_close_connection
,
5071 Sx_close_connection
, 1, 1, 0,
5072 doc
: /* Close the connection to DISPLAY's server.
5073 For DISPLAY, specify either a frame or a display name (a string).
5074 If DISPLAY is nil, that stands for the selected frame's display. */)
5076 Lisp_Object display
;
5078 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
5081 if (dpyinfo
->reference_count
> 0)
5082 error ("Display still has frames on it");
5085 x_destroy_all_bitmaps (dpyinfo
);
5087 x_delete_display (dpyinfo
);
5093 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
5094 doc
: /* Return the list of display names that Emacs has connections to. */)
5097 Lisp_Object tail
, result
;
5100 for (tail
= w32_display_name_list
; CONSP (tail
); tail
= XCDR (tail
))
5101 result
= Fcons (XCAR (XCAR (tail
)), result
);
5106 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
5107 doc
: /* This is a noop on W32 systems. */)
5109 Lisp_Object display
, on
;
5116 /***********************************************************************
5118 ***********************************************************************/
5120 DEFUN ("x-change-window-property", Fx_change_window_property
,
5121 Sx_change_window_property
, 2, 6, 0,
5122 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
5123 VALUE may be a string or a list of conses, numbers and/or strings.
5124 If an element in the list is a string, it is converted to
5125 an Atom and the value of the Atom is used. If an element is a cons,
5126 it is converted to a 32 bit number where the car is the 16 top bits and the
5127 cdr is the lower 16 bits.
5128 FRAME nil or omitted means use the selected frame.
5129 If TYPE is given and non-nil, it is the name of the type of VALUE.
5130 If TYPE is not given or nil, the type is STRING.
5131 FORMAT gives the size in bits of each element if VALUE is a list.
5132 It must be one of 8, 16 or 32.
5133 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
5134 If OUTER_P is non-nil, the property is changed for the outer X window of
5135 FRAME. Default is to change on the edit X window.
5138 (prop
, value
, frame
, type
, format
, outer_p
)
5139 Lisp_Object prop
, value
, frame
, type
, format
, outer_p
;
5141 #if 0 /* TODO : port window properties to W32 */
5142 struct frame
*f
= check_x_frame (frame
);
5145 CHECK_STRING (prop
);
5146 CHECK_STRING (value
);
5149 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5150 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5151 prop_atom
, XA_STRING
, 8, PropModeReplace
,
5152 SDATA (value
), SCHARS (value
));
5154 /* Make sure the property is set when we return. */
5155 XFlush (FRAME_W32_DISPLAY (f
));
5164 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
5165 Sx_delete_window_property
, 1, 2, 0,
5166 doc
: /* Remove window property PROP from X window of FRAME.
5167 FRAME nil or omitted means use the selected frame. Value is PROP. */)
5169 Lisp_Object prop
, frame
;
5171 #if 0 /* TODO : port window properties to W32 */
5173 struct frame
*f
= check_x_frame (frame
);
5176 CHECK_STRING (prop
);
5178 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5179 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
5181 /* Make sure the property is removed when we return. */
5182 XFlush (FRAME_W32_DISPLAY (f
));
5190 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
5192 doc
: /* Value is the value of window property PROP on FRAME.
5193 If FRAME is nil or omitted, use the selected frame. Value is nil
5194 if FRAME hasn't a property with name PROP or if PROP has no string
5197 Lisp_Object prop
, frame
;
5199 #if 0 /* TODO : port window properties to W32 */
5201 struct frame
*f
= check_x_frame (frame
);
5204 Lisp_Object prop_value
= Qnil
;
5205 char *tmp_data
= NULL
;
5208 unsigned long actual_size
, bytes_remaining
;
5210 CHECK_STRING (prop
);
5212 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5213 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5214 prop_atom
, 0, 0, False
, XA_STRING
,
5215 &actual_type
, &actual_format
, &actual_size
,
5216 &bytes_remaining
, (unsigned char **) &tmp_data
);
5219 int size
= bytes_remaining
;
5224 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5225 prop_atom
, 0, bytes_remaining
,
5227 &actual_type
, &actual_format
,
5228 &actual_size
, &bytes_remaining
,
5229 (unsigned char **) &tmp_data
);
5231 prop_value
= make_string (tmp_data
, size
);
5246 /***********************************************************************
5248 ***********************************************************************/
5250 /* Non-zero means an hourglass cursor is currently shown. */
5252 static int hourglass_shown_p
;
5254 /* Number of seconds to wait before displaying an hourglass cursor. */
5256 static Lisp_Object Vhourglass_delay
;
5258 /* Default number of seconds to wait before displaying an hourglass
5261 #define DEFAULT_HOURGLASS_DELAY 1
5263 /* Return non-zero if houglass timer has been started or hourglass is shown. */
5266 hourglass_started ()
5268 return hourglass_shown_p
|| hourglass_timer
;
5271 /* Cancel a currently active hourglass timer, and start a new one. */
5277 int secs
, msecs
= 0;
5278 struct frame
* f
= SELECTED_FRAME ();
5280 /* No cursors on non GUI frames. */
5281 if (!FRAME_W32_P (f
))
5284 cancel_hourglass ();
5286 if (INTEGERP (Vhourglass_delay
)
5287 && XINT (Vhourglass_delay
) > 0)
5288 secs
= XFASTINT (Vhourglass_delay
);
5289 else if (FLOATP (Vhourglass_delay
)
5290 && XFLOAT_DATA (Vhourglass_delay
) > 0)
5293 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
5294 secs
= XFASTINT (tem
);
5295 msecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000;
5298 secs
= DEFAULT_HOURGLASS_DELAY
;
5300 delay
= secs
* 1000 + msecs
;
5301 hourglass_hwnd
= FRAME_W32_WINDOW (f
);
5302 hourglass_timer
= SetTimer (hourglass_hwnd
, HOURGLASS_ID
, delay
, NULL
);
5306 /* Cancel the hourglass cursor timer if active, hide an hourglass
5312 if (hourglass_timer
)
5314 KillTimer (hourglass_hwnd
, hourglass_timer
);
5315 hourglass_timer
= 0;
5318 if (hourglass_shown_p
)
5323 /* Timer function of hourglass_timer.
5325 Display an hourglass cursor. Set the hourglass_p flag in display info
5326 to indicate that an hourglass cursor is shown. */
5332 if (!hourglass_shown_p
)
5334 f
->output_data
.w32
->hourglass_p
= 1;
5335 if (!menubar_in_use
&& !current_popup_menu
)
5336 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
5337 hourglass_shown_p
= 1;
5342 /* Hide the hourglass cursor on all frames, if it is currently shown. */
5347 if (hourglass_shown_p
)
5349 struct frame
*f
= x_window_to_frame (&one_w32_display_info
,
5352 f
->output_data
.w32
->hourglass_p
= 0;
5353 SetCursor (f
->output_data
.w32
->current_cursor
);
5354 hourglass_shown_p
= 0;
5360 /***********************************************************************
5362 ***********************************************************************/
5364 static Lisp_Object x_create_tip_frame
P_ ((struct w32_display_info
*,
5365 Lisp_Object
, Lisp_Object
));
5366 static void compute_tip_xy
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
5367 Lisp_Object
, int, int, int *, int *));
5369 /* The frame of a currently visible tooltip. */
5371 Lisp_Object tip_frame
;
5373 /* If non-nil, a timer started that hides the last tooltip when it
5376 Lisp_Object tip_timer
;
5379 /* If non-nil, a vector of 3 elements containing the last args
5380 with which x-show-tip was called. See there. */
5382 Lisp_Object last_show_tip_args
;
5384 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
5386 Lisp_Object Vx_max_tooltip_size
;
5390 unwind_create_tip_frame (frame
)
5393 Lisp_Object deleted
;
5395 deleted
= unwind_create_frame (frame
);
5396 if (EQ (deleted
, Qt
))
5406 /* Create a frame for a tooltip on the display described by DPYINFO.
5407 PARMS is a list of frame parameters. TEXT is the string to
5408 display in the tip frame. Value is the frame.
5410 Note that functions called here, esp. x_default_parameter can
5411 signal errors, for instance when a specified color name is
5412 undefined. We have to make sure that we're in a consistent state
5413 when this happens. */
5416 x_create_tip_frame (dpyinfo
, parms
, text
)
5417 struct w32_display_info
*dpyinfo
;
5418 Lisp_Object parms
, text
;
5421 Lisp_Object frame
, tem
;
5423 long window_prompting
= 0;
5425 int count
= SPECPDL_INDEX ();
5426 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5428 int face_change_count_before
= face_change_count
;
5430 struct buffer
*old_buffer
;
5434 /* Use this general default value to start with until we know if
5435 this frame has a specified name. */
5436 Vx_resource_name
= Vinvocation_name
;
5439 kb
= dpyinfo
->terminal
->kboard
;
5441 kb
= &the_only_kboard
;
5444 /* Get the name of the frame to use for resource lookup. */
5445 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
5447 && !EQ (name
, Qunbound
)
5449 error ("Invalid frame name--not a string or nil");
5450 Vx_resource_name
= name
;
5453 GCPRO3 (parms
, name
, frame
);
5454 /* Make a frame without minibuffer nor mode-line. */
5456 f
->wants_modeline
= 0;
5457 XSETFRAME (frame
, f
);
5459 buffer
= Fget_buffer_create (build_string (" *tip*"));
5460 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, Qnil
);
5461 old_buffer
= current_buffer
;
5462 set_buffer_internal_1 (XBUFFER (buffer
));
5463 current_buffer
->truncate_lines
= Qnil
;
5464 specbind (Qinhibit_read_only
, Qt
);
5465 specbind (Qinhibit_modification_hooks
, Qt
);
5468 set_buffer_internal_1 (old_buffer
);
5470 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
5471 record_unwind_protect (unwind_create_tip_frame
, frame
);
5473 /* By setting the output method, we're essentially saying that
5474 the frame is live, as per FRAME_LIVE_P. If we get a signal
5475 from this point on, x_destroy_window might screw up reference
5477 f
->terminal
= dpyinfo
->terminal
;
5478 f
->terminal
->reference_count
++;
5479 f
->output_method
= output_w32
;
5480 f
->output_data
.w32
=
5481 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
5482 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
5484 FRAME_FONTSET (f
) = -1;
5485 f
->icon_name
= Qnil
;
5487 #if 0 /* GLYPH_DEBUG TODO: image support. */
5488 image_cache_refcount
= FRAME_IMAGE_CACHE (f
)->refcount
;
5489 dpyinfo_refcount
= dpyinfo
->reference_count
;
5490 #endif /* GLYPH_DEBUG */
5492 FRAME_KBOARD (f
) = kb
;
5494 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5495 f
->output_data
.w32
->explicit_parent
= 0;
5497 /* Set the name; the functions to which we pass f expect the name to
5499 if (EQ (name
, Qunbound
) || NILP (name
))
5501 f
->name
= build_string (dpyinfo
->w32_id_name
);
5502 f
->explicit_name
= 0;
5507 f
->explicit_name
= 1;
5508 /* use the frame's title when getting resources for this frame. */
5509 specbind (Qx_resource_name
, name
);
5512 f
->resx
= dpyinfo
->resx
;
5513 f
->resy
= dpyinfo
->resy
;
5515 /* Perhaps, we must allow frame parameter, say `font-backend',
5516 to specify which font backends to use. */
5517 register_font_driver (&w32font_driver
, f
);
5519 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
5520 "fontBackend", "FontBackend", RES_TYPE_STRING
);
5522 /* Extract the window parameters from the supplied values
5523 that are needed to determine window geometry. */
5524 x_default_font_parameter (f
, parms
);
5526 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
5527 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5528 /* This defaults to 2 in order to match xterm. We recognize either
5529 internalBorderWidth or internalBorder (which is what xterm calls
5531 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5535 value
= w32_get_arg (parms
, Qinternal_border_width
,
5536 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
5537 if (! EQ (value
, Qunbound
))
5538 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
5541 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
5542 "internalBorderWidth", "internalBorderWidth",
5545 /* Also do the stuff which must be set before the window exists. */
5546 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
5547 "foreground", "Foreground", RES_TYPE_STRING
);
5548 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
5549 "background", "Background", RES_TYPE_STRING
);
5550 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
5551 "pointerColor", "Foreground", RES_TYPE_STRING
);
5552 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
5553 "cursorColor", "Foreground", RES_TYPE_STRING
);
5554 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
5555 "borderColor", "BorderColor", RES_TYPE_STRING
);
5557 /* Init faces before x_default_parameter is called for scroll-bar
5558 parameters because that function calls x_set_scroll_bar_width,
5559 which calls change_frame_size, which calls Fset_window_buffer,
5560 which runs hooks, which call Fvertical_motion. At the end, we
5561 end up in init_iterator with a null face cache, which should not
5563 init_frame_faces (f
);
5565 f
->output_data
.w32
->dwStyle
= WS_BORDER
| WS_POPUP
| WS_DISABLED
;
5566 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5568 window_prompting
= x_figure_window_size (f
, parms
, 0);
5570 /* No fringes on tip frame. */
5572 f
->left_fringe_width
= 0;
5573 f
->right_fringe_width
= 0;
5576 my_create_tip_window (f
);
5581 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
5582 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5583 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5584 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5585 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5586 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5588 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
5589 Change will not be effected unless different from the current
5591 width
= FRAME_COLS (f
);
5592 height
= FRAME_LINES (f
);
5593 FRAME_LINES (f
) = 0;
5594 SET_FRAME_COLS (f
, 0);
5595 change_frame_size (f
, height
, width
, 1, 0, 0);
5597 /* Add `tooltip' frame parameter's default value. */
5598 if (NILP (Fframe_parameter (frame
, intern ("tooltip"))))
5599 Fmodify_frame_parameters (frame
, Fcons (Fcons (intern ("tooltip"), Qt
),
5602 /* Set up faces after all frame parameters are known. This call
5603 also merges in face attributes specified for new frames.
5605 Frame parameters may be changed if .Xdefaults contains
5606 specifications for the default font. For example, if there is an
5607 `Emacs.default.attributeBackground: pink', the `background-color'
5608 attribute of the frame get's set, which let's the internal border
5609 of the tooltip frame appear in pink. Prevent this. */
5611 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
5613 /* Set tip_frame here, so that */
5615 call2 (Qface_set_after_frame_default
, frame
, Qnil
);
5617 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
5618 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qbackground_color
, bg
),
5626 /* It is now ok to make the frame official even if we get an error
5627 below. And the frame needs to be on Vframe_list or making it
5628 visible won't work. */
5629 Vframe_list
= Fcons (frame
, Vframe_list
);
5631 /* Now that the frame is official, it counts as a reference to
5633 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
5635 /* Setting attributes of faces of the tooltip frame from resources
5636 and similar will increment face_change_count, which leads to the
5637 clearing of all current matrices. Since this isn't necessary
5638 here, avoid it by resetting face_change_count to the value it
5639 had before we created the tip frame. */
5640 face_change_count
= face_change_count_before
;
5642 /* Discard the unwind_protect. */
5643 return unbind_to (count
, frame
);
5647 /* Compute where to display tip frame F. PARMS is the list of frame
5648 parameters for F. DX and DY are specified offsets from the current
5649 location of the mouse. WIDTH and HEIGHT are the width and height
5650 of the tooltip. Return coordinates relative to the root window of
5651 the display in *ROOT_X, and *ROOT_Y. */
5654 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, root_x
, root_y
)
5656 Lisp_Object parms
, dx
, dy
;
5658 int *root_x
, *root_y
;
5660 Lisp_Object left
, top
;
5661 int min_x
, min_y
, max_x
, max_y
;
5663 /* User-specified position? */
5664 left
= Fcdr (Fassq (Qleft
, parms
));
5665 top
= Fcdr (Fassq (Qtop
, parms
));
5667 /* Move the tooltip window where the mouse pointer is. Resize and
5669 if (!INTEGERP (left
) || !INTEGERP (top
))
5673 /* Default min and max values. */
5676 max_x
= FRAME_W32_DISPLAY_INFO (f
)->width
;
5677 max_y
= FRAME_W32_DISPLAY_INFO (f
)->height
;
5685 /* If multiple monitor support is available, constrain the tip onto
5686 the current monitor. This improves the above by allowing negative
5687 co-ordinates if monitor positions are such that they are valid, and
5688 snaps a tooltip onto a single monitor if we are close to the edge
5689 where it would otherwise flow onto the other monitor (or into
5690 nothingness if there is a gap in the overlap). */
5691 if (monitor_from_point_fn
&& get_monitor_info_fn
)
5693 struct MONITOR_INFO info
;
5695 = monitor_from_point_fn (pt
, MONITOR_DEFAULT_TO_NEAREST
);
5696 info
.cbSize
= sizeof (info
);
5698 if (get_monitor_info_fn (monitor
, &info
))
5700 min_x
= info
.rcWork
.left
;
5701 min_y
= info
.rcWork
.top
;
5702 max_x
= info
.rcWork
.right
;
5703 max_y
= info
.rcWork
.bottom
;
5709 *root_y
= XINT (top
);
5710 else if (*root_y
+ XINT (dy
) <= min_y
)
5711 *root_y
= min_y
; /* Can happen for negative dy */
5712 else if (*root_y
+ XINT (dy
) + height
<= max_y
)
5713 /* It fits below the pointer */
5714 *root_y
+= XINT (dy
);
5715 else if (height
+ XINT (dy
) + min_y
<= *root_y
)
5716 /* It fits above the pointer. */
5717 *root_y
-= height
+ XINT (dy
);
5719 /* Put it on the top. */
5722 if (INTEGERP (left
))
5723 *root_x
= XINT (left
);
5724 else if (*root_x
+ XINT (dx
) <= min_x
)
5725 *root_x
= 0; /* Can happen for negative dx */
5726 else if (*root_x
+ XINT (dx
) + width
<= max_x
)
5727 /* It fits to the right of the pointer. */
5728 *root_x
+= XINT (dx
);
5729 else if (width
+ XINT (dx
) + min_x
<= *root_x
)
5730 /* It fits to the left of the pointer. */
5731 *root_x
-= width
+ XINT (dx
);
5733 /* Put it left justified on the screen -- it ought to fit that way. */
5738 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
5739 doc
: /* Show STRING in a \"tooltip\" window on frame FRAME.
5740 A tooltip window is a small window displaying a string.
5742 This is an internal function; Lisp code should call `tooltip-show'.
5744 FRAME nil or omitted means use the selected frame.
5746 PARMS is an optional list of frame parameters which can be
5747 used to change the tooltip's appearance.
5749 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
5750 means use the default timeout of 5 seconds.
5752 If the list of frame parameters PARMS contains a `left' parameter,
5753 the tooltip is displayed at that x-position. Otherwise it is
5754 displayed at the mouse position, with offset DX added (default is 5 if
5755 DX isn't specified). Likewise for the y-position; if a `top' frame
5756 parameter is specified, it determines the y-position of the tooltip
5757 window, otherwise it is displayed at the mouse position, with offset
5758 DY added (default is -10).
5760 A tooltip's maximum size is specified by `x-max-tooltip-size'.
5761 Text larger than the specified size is clipped. */)
5762 (string
, frame
, parms
, timeout
, dx
, dy
)
5763 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
5768 struct buffer
*old_buffer
;
5769 struct text_pos pos
;
5770 int i
, width
, height
;
5771 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5772 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5773 int count
= SPECPDL_INDEX ();
5775 specbind (Qinhibit_redisplay
, Qt
);
5777 GCPRO4 (string
, parms
, frame
, timeout
);
5779 CHECK_STRING (string
);
5780 f
= check_x_frame (frame
);
5782 timeout
= make_number (5);
5784 CHECK_NATNUM (timeout
);
5787 dx
= make_number (5);
5792 dy
= make_number (-10);
5796 if (NILP (last_show_tip_args
))
5797 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
5799 if (!NILP (tip_frame
))
5801 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
5802 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
5803 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
5805 if (EQ (frame
, last_frame
)
5806 && !NILP (Fequal (last_string
, string
))
5807 && !NILP (Fequal (last_parms
, parms
)))
5809 struct frame
*f
= XFRAME (tip_frame
);
5811 /* Only DX and DY have changed. */
5812 if (!NILP (tip_timer
))
5814 Lisp_Object timer
= tip_timer
;
5816 call1 (Qcancel_timer
, timer
);
5820 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
5821 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
5823 /* Put tooltip in topmost group and in position. */
5824 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
5825 root_x
, root_y
, 0, 0,
5826 SWP_NOSIZE
| SWP_NOACTIVATE
);
5828 /* Ensure tooltip is on top of other topmost windows (eg menus). */
5829 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
5831 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
5838 /* Hide a previous tip, if any. */
5841 ASET (last_show_tip_args
, 0, string
);
5842 ASET (last_show_tip_args
, 1, frame
);
5843 ASET (last_show_tip_args
, 2, parms
);
5845 /* Add default values to frame parameters. */
5846 if (NILP (Fassq (Qname
, parms
)))
5847 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
5848 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5849 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
5850 if (NILP (Fassq (Qborder_width
, parms
)))
5851 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
5852 if (NILP (Fassq (Qborder_color
, parms
)))
5853 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
5854 if (NILP (Fassq (Qbackground_color
, parms
)))
5855 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
5858 /* Block input until the tip has been fully drawn, to avoid crashes
5859 when drawing tips in menus. */
5862 /* Create a frame for the tooltip, and record it in the global
5863 variable tip_frame. */
5864 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
, string
);
5867 /* Set up the frame's root window. */
5868 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5869 w
->left_col
= w
->top_line
= make_number (0);
5871 if (CONSP (Vx_max_tooltip_size
)
5872 && INTEGERP (XCAR (Vx_max_tooltip_size
))
5873 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
5874 && INTEGERP (XCDR (Vx_max_tooltip_size
))
5875 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
5877 w
->total_cols
= XCAR (Vx_max_tooltip_size
);
5878 w
->total_lines
= XCDR (Vx_max_tooltip_size
);
5882 w
->total_cols
= make_number (80);
5883 w
->total_lines
= make_number (40);
5886 FRAME_TOTAL_COLS (f
) = XINT (w
->total_cols
);
5888 w
->pseudo_window_p
= 1;
5890 /* Display the tooltip text in a temporary buffer. */
5891 old_buffer
= current_buffer
;
5892 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
5893 current_buffer
->truncate_lines
= Qnil
;
5894 clear_glyph_matrix (w
->desired_matrix
);
5895 clear_glyph_matrix (w
->current_matrix
);
5896 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
5897 try_window (FRAME_ROOT_WINDOW (f
), pos
, 0);
5899 /* Compute width and height of the tooltip. */
5901 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5903 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5907 /* Stop at the first empty row at the end. */
5908 if (!row
->enabled_p
|| !row
->displays_text_p
)
5911 /* Let the row go over the full width of the frame. */
5912 row
->full_width_p
= 1;
5914 #ifdef TODO /* Investigate why some fonts need more width than is
5915 calculated for some tooltips. */
5916 /* There's a glyph at the end of rows that is use to place
5917 the cursor there. Don't include the width of this glyph. */
5918 if (row
->used
[TEXT_AREA
])
5920 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5921 row_width
= row
->pixel_width
- last
->pixel_width
;
5925 row_width
= row
->pixel_width
;
5927 /* TODO: find why tips do not draw along baseline as instructed. */
5928 height
+= row
->height
;
5929 width
= max (width
, row_width
);
5932 /* Add the frame's internal border to the width and height the X
5933 window should have. */
5934 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5935 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5937 /* Move the tooltip window where the mouse pointer is. Resize and
5939 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
5942 /* Adjust Window size to take border into account. */
5944 rect
.left
= rect
.top
= 0;
5946 rect
.bottom
= height
;
5947 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
5948 FRAME_EXTERNAL_MENU_BAR (f
));
5950 /* Position and size tooltip, and put it in the topmost group.
5951 The add-on of 3 to the 5th argument is a kludge: without it,
5952 some fonts cause the last character of the tip to be truncated,
5953 for some obscure reason. */
5954 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
5955 root_x
, root_y
, rect
.right
- rect
.left
+ 3,
5956 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
);
5958 /* Ensure tooltip is on top of other topmost windows (eg menus). */
5959 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
5961 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
5963 /* Let redisplay know that we have made the frame visible already. */
5964 f
->async_visible
= 1;
5966 ShowWindow (FRAME_W32_WINDOW (f
), SW_SHOWNOACTIVATE
);
5969 /* Draw into the window. */
5970 w
->must_be_updated_p
= 1;
5971 update_single_window (w
, 1);
5975 /* Restore original current buffer. */
5976 set_buffer_internal_1 (old_buffer
);
5977 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5980 /* Let the tip disappear after timeout seconds. */
5981 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
5982 intern ("x-hide-tip"));
5985 return unbind_to (count
, Qnil
);
5989 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
5990 doc
: /* Hide the current tooltip window, if there is any.
5991 Value is t if tooltip was open, nil otherwise. */)
5995 Lisp_Object deleted
, frame
, timer
;
5996 struct gcpro gcpro1
, gcpro2
;
5998 /* Return quickly if nothing to do. */
5999 if (NILP (tip_timer
) && NILP (tip_frame
))
6004 GCPRO2 (frame
, timer
);
6005 tip_frame
= tip_timer
= deleted
= Qnil
;
6007 count
= SPECPDL_INDEX ();
6008 specbind (Qinhibit_redisplay
, Qt
);
6009 specbind (Qinhibit_quit
, Qt
);
6012 call1 (Qcancel_timer
, timer
);
6016 Fdelete_frame (frame
, Qnil
);
6021 return unbind_to (count
, deleted
);
6026 /***********************************************************************
6027 File selection dialog
6028 ***********************************************************************/
6029 extern Lisp_Object Qfile_name_history
;
6031 /* Callback for altering the behavior of the Open File dialog.
6032 Makes the Filename text field contain "Current Directory" and be
6033 read-only when "Directories" is selected in the filter. This
6034 allows us to work around the fact that the standard Open File
6035 dialog does not support directories. */
6037 file_dialog_callback (hwnd
, msg
, wParam
, lParam
)
6043 if (msg
== WM_NOTIFY
)
6045 OFNOTIFY
* notify
= (OFNOTIFY
*)lParam
;
6046 /* Detect when the Filter dropdown is changed. */
6047 if (notify
->hdr
.code
== CDN_TYPECHANGE
6048 || notify
->hdr
.code
== CDN_INITDONE
)
6050 HWND dialog
= GetParent (hwnd
);
6051 HWND edit_control
= GetDlgItem (dialog
, FILE_NAME_TEXT_FIELD
);
6053 /* Directories is in index 2. */
6054 if (notify
->lpOFN
->nFilterIndex
== 2)
6056 CommDlg_OpenSave_SetControlText (dialog
, FILE_NAME_TEXT_FIELD
,
6057 "Current Directory");
6058 EnableWindow (edit_control
, FALSE
);
6062 /* Don't override default filename on init done. */
6063 if (notify
->hdr
.code
== CDN_TYPECHANGE
)
6064 CommDlg_OpenSave_SetControlText (dialog
,
6065 FILE_NAME_TEXT_FIELD
, "");
6066 EnableWindow (edit_control
, TRUE
);
6073 /* Since we compile with _WIN32_WINNT set to 0x0400 (for NT4 compatibility)
6074 we end up with the old file dialogs. Define a big enough struct for the
6075 new dialog to trick GetOpenFileName into giving us the new dialogs on
6076 Windows 2000 and XP. */
6079 OPENFILENAME real_details
;
6086 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
6087 doc
: /* Read file name, prompting with PROMPT in directory DIR.
6088 Use a file selection dialog.
6089 Select DEFAULT-FILENAME in the dialog's file selection box, if
6090 specified. Ensure that file exists if MUSTMATCH is non-nil.
6091 If ONLY-DIR-P is non-nil, the user can only select directories. */)
6092 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
)
6093 Lisp_Object prompt
, dir
, default_filename
, mustmatch
, only_dir_p
;
6095 struct frame
*f
= SELECTED_FRAME ();
6096 Lisp_Object file
= Qnil
;
6097 int count
= SPECPDL_INDEX ();
6098 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
6099 char filename
[MAX_PATH
+ 1];
6100 char init_dir
[MAX_PATH
+ 1];
6101 int default_filter_index
= 1; /* 1: All Files, 2: Directories only */
6103 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
6104 CHECK_STRING (prompt
);
6107 /* Create the dialog with PROMPT as title, using DIR as initial
6108 directory and using "*" as pattern. */
6109 dir
= Fexpand_file_name (dir
, Qnil
);
6110 strncpy (init_dir
, SDATA (ENCODE_FILE (dir
)), MAX_PATH
);
6111 init_dir
[MAX_PATH
] = '\0';
6112 unixtodos_filename (init_dir
);
6114 if (STRINGP (default_filename
))
6116 char *file_name_only
;
6117 char *full_path_name
= SDATA (ENCODE_FILE (default_filename
));
6119 unixtodos_filename (full_path_name
);
6121 file_name_only
= strrchr (full_path_name
, '\\');
6122 if (!file_name_only
)
6123 file_name_only
= full_path_name
;
6127 strncpy (filename
, file_name_only
, MAX_PATH
);
6128 filename
[MAX_PATH
] = '\0';
6134 NEWOPENFILENAME new_file_details
;
6135 BOOL file_opened
= FALSE
;
6136 OPENFILENAME
* file_details
= &new_file_details
.real_details
;
6138 /* Prevent redisplay. */
6139 specbind (Qinhibit_redisplay
, Qt
);
6142 bzero (&new_file_details
, sizeof (new_file_details
));
6143 /* Apparently NT4 crashes if you give it an unexpected size.
6144 I'm not sure about Windows 9x, so play it safe. */
6145 if (w32_major_version
> 4 && w32_major_version
< 95)
6146 file_details
->lStructSize
= sizeof (NEWOPENFILENAME
);
6148 file_details
->lStructSize
= sizeof (OPENFILENAME
);
6150 file_details
->hwndOwner
= FRAME_W32_WINDOW (f
);
6151 /* Undocumented Bug in Common File Dialog:
6152 If a filter is not specified, shell links are not resolved. */
6153 file_details
->lpstrFilter
= "All Files (*.*)\0*.*\0Directories\0*|*\0\0";
6154 file_details
->lpstrFile
= filename
;
6155 file_details
->nMaxFile
= sizeof (filename
);
6156 file_details
->lpstrInitialDir
= init_dir
;
6157 file_details
->lpstrTitle
= SDATA (prompt
);
6159 if (! NILP (only_dir_p
))
6160 default_filter_index
= 2;
6162 file_details
->nFilterIndex
= default_filter_index
;
6164 file_details
->Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
6165 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
6166 if (!NILP (mustmatch
))
6168 /* Require that the path to the parent directory exists. */
6169 file_details
->Flags
|= OFN_PATHMUSTEXIST
;
6170 /* If we are looking for a file, require that it exists. */
6171 if (NILP (only_dir_p
))
6172 file_details
->Flags
|= OFN_FILEMUSTEXIST
;
6175 file_details
->lpfnHook
= (LPOFNHOOKPROC
) file_dialog_callback
;
6177 file_opened
= GetOpenFileName (file_details
);
6183 dostounix_filename (filename
);
6185 if (file_details
->nFilterIndex
== 2)
6187 /* "Directories" selected - strip dummy file name. */
6188 char * last
= strrchr (filename
, '/');
6192 file
= DECODE_FILE (build_string (filename
));
6194 /* User cancelled the dialog without making a selection. */
6195 else if (!CommDlgExtendedError ())
6197 /* An error occurred, fallback on reading from the mini-buffer. */
6199 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
6200 dir
, mustmatch
, dir
, Qfile_name_history
,
6201 default_filename
, Qnil
);
6203 file
= unbind_to (count
, file
);
6208 /* Make "Cancel" equivalent to C-g. */
6210 Fsignal (Qquit
, Qnil
);
6212 return unbind_to (count
, file
);
6216 /* Moving files to the system recycle bin.
6217 Used by `move-file-to-trash' instead of the default moving to ~/.Trash */
6218 DEFUN ("system-move-file-to-trash", Fsystem_move_file_to_trash
,
6219 Ssystem_move_file_to_trash
, 1, 1, 0,
6220 doc
: /* Move file or directory named FILENAME to the recycle bin. */)
6222 Lisp_Object filename
;
6224 Lisp_Object handler
;
6225 Lisp_Object encoded_file
;
6226 Lisp_Object operation
;
6228 operation
= Qdelete_file
;
6229 if (!NILP (Ffile_directory_p (filename
))
6230 && NILP (Ffile_symlink_p (filename
)))
6232 operation
= Qdelete_directory
;
6233 filename
= Fdirectory_file_name (filename
);
6235 filename
= Fexpand_file_name (filename
, Qnil
);
6237 handler
= Ffind_file_name_handler (filename
, operation
);
6238 if (!NILP (handler
))
6239 return call2 (handler
, operation
, filename
);
6241 encoded_file
= ENCODE_FILE (filename
);
6245 SHFILEOPSTRUCT file_op
;
6246 char tmp_path
[MAX_PATH
+ 1];
6248 path
= map_w32_filename (SDATA (encoded_file
), NULL
);
6250 /* On Windows, write permission is required to delete/move files. */
6251 _chmod (path
, 0666);
6253 bzero (tmp_path
, sizeof (tmp_path
));
6254 strcpy (tmp_path
, path
);
6256 bzero (&file_op
, sizeof (file_op
));
6257 file_op
.hwnd
= HWND_DESKTOP
;
6258 file_op
.wFunc
= FO_DELETE
;
6259 file_op
.pFrom
= tmp_path
;
6260 file_op
.fFlags
= FOF_SILENT
| FOF_NOCONFIRMATION
| FOF_ALLOWUNDO
6261 | FOF_NOERRORUI
| FOF_NO_CONNECTED_ELEMENTS
;
6262 file_op
.fAnyOperationsAborted
= FALSE
;
6264 if (SHFileOperation (&file_op
) != 0)
6265 report_file_error ("Removing old name", list1 (filename
));
6271 /***********************************************************************
6272 w32 specialized functions
6273 ***********************************************************************/
6275 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
,
6276 Sw32_send_sys_command
, 1, 2, 0,
6277 doc
: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND.
6278 Some useful values for COMMAND are #xf030 to maximize frame (#xf020
6279 to minimize), #xf120 to restore frame to original size, and #xf100
6280 to activate the menubar for keyboard access. #xf140 activates the
6281 screen saver if defined.
6283 If optional parameter FRAME is not specified, use selected frame. */)
6285 Lisp_Object command
, frame
;
6287 FRAME_PTR f
= check_x_frame (frame
);
6289 CHECK_NUMBER (command
);
6291 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
6296 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
6297 doc
: /* Get Windows to perform OPERATION on DOCUMENT.
6298 This is a wrapper around the ShellExecute system function, which
6299 invokes the application registered to handle OPERATION for DOCUMENT.
6301 OPERATION is either nil or a string that names a supported operation.
6302 What operations can be used depends on the particular DOCUMENT and its
6303 handler application, but typically it is one of the following common
6306 \"open\" - open DOCUMENT, which could be a file, a directory, or an
6307 executable program. If it is an application, that
6308 application is launched in the current buffer's default
6309 directory. Otherwise, the application associated with
6310 DOCUMENT is launched in the buffer's default directory.
6311 \"print\" - print DOCUMENT, which must be a file
6312 \"explore\" - start the Windows Explorer on DOCUMENT
6313 \"edit\" - launch an editor and open DOCUMENT for editing; which
6314 editor is launched depends on the association for the
6316 \"find\" - initiate search starting from DOCUMENT which must specify
6318 nil - invoke the default OPERATION, or \"open\" if default is
6319 not defined or unavailable
6321 DOCUMENT is typically the name of a document file or a URL, but can
6322 also be a program executable to run, or a directory to open in the
6325 If DOCUMENT is a program executable, the optional third arg PARAMETERS
6326 can be a string containing command line parameters that will be passed
6327 to the program; otherwise, PARAMETERS should be nil or unspecified.
6329 Optional fourth argument SHOW-FLAG can be used to control how the
6330 application will be displayed when it is invoked. If SHOW-FLAG is nil
6331 or unspecified, the application is displayed normally, otherwise it is
6332 an integer representing a ShowWindow flag:
6337 6 - start minimized */)
6338 (operation
, document
, parameters
, show_flag
)
6339 Lisp_Object operation
, document
, parameters
, show_flag
;
6341 Lisp_Object current_dir
;
6343 CHECK_STRING (document
);
6345 /* Encode filename, current directory and parameters. */
6346 current_dir
= ENCODE_FILE (current_buffer
->directory
);
6347 document
= ENCODE_FILE (document
);
6348 if (STRINGP (parameters
))
6349 parameters
= ENCODE_SYSTEM (parameters
);
6351 if ((int) ShellExecute (NULL
,
6352 (STRINGP (operation
) ?
6353 SDATA (operation
) : NULL
),
6355 (STRINGP (parameters
) ?
6356 SDATA (parameters
) : NULL
),
6357 SDATA (current_dir
),
6358 (INTEGERP (show_flag
) ?
6359 XINT (show_flag
) : SW_SHOWDEFAULT
))
6362 error ("ShellExecute failed: %s", w32_strerror (0));
6365 /* Lookup virtual keycode from string representing the name of a
6366 non-ascii keystroke into the corresponding virtual key, using
6367 lispy_function_keys. */
6369 lookup_vk_code (char *key
)
6373 for (i
= 0; i
< 256; i
++)
6374 if (lispy_function_keys
[i
]
6375 && strcmp (lispy_function_keys
[i
], key
) == 0)
6381 /* Convert a one-element vector style key sequence to a hot key
6384 w32_parse_hot_key (key
)
6387 /* Copied from Fdefine_key and store_in_keymap. */
6388 register Lisp_Object c
;
6392 struct gcpro gcpro1
;
6396 if (XFASTINT (Flength (key
)) != 1)
6401 c
= Faref (key
, make_number (0));
6403 if (CONSP (c
) && lucid_event_type_list_p (c
))
6404 c
= Fevent_convert_list (c
);
6408 if (! INTEGERP (c
) && ! SYMBOLP (c
))
6409 error ("Key definition is invalid");
6411 /* Work out the base key and the modifiers. */
6414 c
= parse_modifiers (c
);
6415 lisp_modifiers
= XINT (Fcar (Fcdr (c
)));
6419 vk_code
= lookup_vk_code (SDATA (SYMBOL_NAME (c
)));
6421 else if (INTEGERP (c
))
6423 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
6424 /* Many ascii characters are their own virtual key code. */
6425 vk_code
= XINT (c
) & CHARACTERBITS
;
6428 if (vk_code
< 0 || vk_code
> 255)
6431 if ((lisp_modifiers
& meta_modifier
) != 0
6432 && !NILP (Vw32_alt_is_meta
))
6433 lisp_modifiers
|= alt_modifier
;
6435 /* Supply defs missing from mingw32. */
6437 #define MOD_ALT 0x0001
6438 #define MOD_CONTROL 0x0002
6439 #define MOD_SHIFT 0x0004
6440 #define MOD_WIN 0x0008
6443 /* Convert lisp modifiers to Windows hot-key form. */
6444 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
6445 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
6446 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
6447 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
6449 return HOTKEY (vk_code
, w32_modifiers
);
6452 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
,
6453 Sw32_register_hot_key
, 1, 1, 0,
6454 doc
: /* Register KEY as a hot-key combination.
6455 Certain key combinations like Alt-Tab are reserved for system use on
6456 Windows, and therefore are normally intercepted by the system. However,
6457 most of these key combinations can be received by registering them as
6458 hot-keys, overriding their special meaning.
6460 KEY must be a one element key definition in vector form that would be
6461 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta
6462 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper
6463 is always interpreted as the Windows modifier keys.
6465 The return value is the hotkey-id if registered, otherwise nil. */)
6469 key
= w32_parse_hot_key (key
);
6471 if (!NILP (key
) && NILP (Fmemq (key
, w32_grabbed_keys
)))
6473 /* Reuse an empty slot if possible. */
6474 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
6476 /* Safe to add new key to list, even if we have focus. */
6478 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
6480 XSETCAR (item
, key
);
6482 /* Notify input thread about new hot-key definition, so that it
6483 takes effect without needing to switch focus. */
6484 #ifdef USE_LISP_UNION_TYPE
6485 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
6488 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
6496 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
,
6497 Sw32_unregister_hot_key
, 1, 1, 0,
6498 doc
: /* Unregister KEY as a hot-key combination. */)
6504 if (!INTEGERP (key
))
6505 key
= w32_parse_hot_key (key
);
6507 item
= Fmemq (key
, w32_grabbed_keys
);
6511 /* Notify input thread about hot-key definition being removed, so
6512 that it takes effect without needing focus switch. */
6513 #ifdef USE_LISP_UNION_TYPE
6514 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
6515 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
.i
))
6517 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
6518 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
))
6522 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
6529 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
,
6530 Sw32_registered_hot_keys
, 0, 0, 0,
6531 doc
: /* Return list of registered hot-key IDs. */)
6534 return Fdelq (Qnil
, Fcopy_sequence (w32_grabbed_keys
));
6537 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
,
6538 Sw32_reconstruct_hot_key
, 1, 1, 0,
6539 doc
: /* Convert hot-key ID to a lisp key combination.
6540 usage: (w32-reconstruct-hot-key ID) */)
6542 Lisp_Object hotkeyid
;
6544 int vk_code
, w32_modifiers
;
6547 CHECK_NUMBER (hotkeyid
);
6549 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
6550 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
6552 if (vk_code
< 256 && lispy_function_keys
[vk_code
])
6553 key
= intern (lispy_function_keys
[vk_code
]);
6555 key
= make_number (vk_code
);
6557 key
= Fcons (key
, Qnil
);
6558 if (w32_modifiers
& MOD_SHIFT
)
6559 key
= Fcons (Qshift
, key
);
6560 if (w32_modifiers
& MOD_CONTROL
)
6561 key
= Fcons (Qctrl
, key
);
6562 if (w32_modifiers
& MOD_ALT
)
6563 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
6564 if (w32_modifiers
& MOD_WIN
)
6565 key
= Fcons (Qhyper
, key
);
6570 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
,
6571 Sw32_toggle_lock_key
, 1, 2, 0,
6572 doc
: /* Toggle the state of the lock key KEY.
6573 KEY can be `capslock', `kp-numlock', or `scroll'.
6574 If the optional parameter NEW-STATE is a number, then the state of KEY
6575 is set to off if the low bit of NEW-STATE is zero, otherwise on. */)
6577 Lisp_Object key
, new_state
;
6581 if (EQ (key
, intern ("capslock")))
6582 vk_code
= VK_CAPITAL
;
6583 else if (EQ (key
, intern ("kp-numlock")))
6584 vk_code
= VK_NUMLOCK
;
6585 else if (EQ (key
, intern ("scroll")))
6586 vk_code
= VK_SCROLL
;
6590 if (!dwWindowsThreadId
)
6591 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
6593 #ifdef USE_LISP_UNION_TYPE
6594 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
6595 (WPARAM
) vk_code
, (LPARAM
) new_state
.i
))
6597 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
6598 (WPARAM
) vk_code
, (LPARAM
) new_state
))
6602 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
6603 return make_number (msg
.wParam
);
6608 DEFUN ("w32-window-exists-p", Fw32_window_exists_p
, Sw32_window_exists_p
,
6610 doc
: /* Return non-nil if a window exists with the specified CLASS and NAME.
6612 This is a direct interface to the Windows API FindWindow function. */)
6614 Lisp_Object
class, name
;
6619 CHECK_STRING (class);
6621 CHECK_STRING (name
);
6623 hnd
= FindWindow (STRINGP (class) ? ((LPCTSTR
) SDATA (class)) : NULL
,
6624 STRINGP (name
) ? ((LPCTSTR
) SDATA (name
)) : NULL
);
6630 DEFUN ("w32-battery-status", Fw32_battery_status
, Sw32_battery_status
, 0, 0, 0,
6631 doc
: /* Get power status information from Windows system.
6633 The following %-sequences are provided:
6634 %L AC line status (verbose)
6635 %B Battery status (verbose)
6636 %b Battery status, empty means high, `-' means low,
6637 `!' means critical, and `+' means charging
6638 %p Battery load percentage
6639 %s Remaining time (to charge or discharge) in seconds
6640 %m Remaining time (to charge or discharge) in minutes
6641 %h Remaining time (to charge or discharge) in hours
6642 %t Remaining time (to charge or discharge) in the form `h:min' */)
6645 Lisp_Object status
= Qnil
;
6647 SYSTEM_POWER_STATUS system_status
;
6648 if (GetSystemPowerStatus (&system_status
))
6650 Lisp_Object line_status
, battery_status
, battery_status_symbol
;
6651 Lisp_Object load_percentage
, seconds
, minutes
, hours
, remain
;
6652 Lisp_Object sequences
[8];
6654 long seconds_left
= (long) system_status
.BatteryLifeTime
;
6656 if (system_status
.ACLineStatus
== 0)
6657 line_status
= build_string ("off-line");
6658 else if (system_status
.ACLineStatus
== 1)
6659 line_status
= build_string ("on-line");
6661 line_status
= build_string ("N/A");
6663 if (system_status
.BatteryFlag
& 128)
6665 battery_status
= build_string ("N/A");
6666 battery_status_symbol
= build_string ("");
6668 else if (system_status
.BatteryFlag
& 8)
6670 battery_status
= build_string ("charging");
6671 battery_status_symbol
= build_string ("+");
6672 if (system_status
.BatteryFullLifeTime
!= -1L)
6673 seconds_left
= system_status
.BatteryFullLifeTime
- seconds_left
;
6675 else if (system_status
.BatteryFlag
& 4)
6677 battery_status
= build_string ("critical");
6678 battery_status_symbol
= build_string ("!");
6680 else if (system_status
.BatteryFlag
& 2)
6682 battery_status
= build_string ("low");
6683 battery_status_symbol
= build_string ("-");
6685 else if (system_status
.BatteryFlag
& 1)
6687 battery_status
= build_string ("high");
6688 battery_status_symbol
= build_string ("");
6692 battery_status
= build_string ("medium");
6693 battery_status_symbol
= build_string ("");
6696 if (system_status
.BatteryLifePercent
> 100)
6697 load_percentage
= build_string ("N/A");
6701 _snprintf (buffer
, 16, "%d", system_status
.BatteryLifePercent
);
6702 load_percentage
= build_string (buffer
);
6705 if (seconds_left
< 0)
6706 seconds
= minutes
= hours
= remain
= build_string ("N/A");
6712 _snprintf (buffer
, 16, "%ld", seconds_left
);
6713 seconds
= build_string (buffer
);
6715 m
= seconds_left
/ 60;
6716 _snprintf (buffer
, 16, "%ld", m
);
6717 minutes
= build_string (buffer
);
6719 h
= seconds_left
/ 3600.0;
6720 _snprintf (buffer
, 16, "%3.1f", h
);
6721 hours
= build_string (buffer
);
6723 _snprintf (buffer
, 16, "%ld:%02ld", m
/ 60, m
% 60);
6724 remain
= build_string (buffer
);
6726 sequences
[0] = Fcons (make_number ('L'), line_status
);
6727 sequences
[1] = Fcons (make_number ('B'), battery_status
);
6728 sequences
[2] = Fcons (make_number ('b'), battery_status_symbol
);
6729 sequences
[3] = Fcons (make_number ('p'), load_percentage
);
6730 sequences
[4] = Fcons (make_number ('s'), seconds
);
6731 sequences
[5] = Fcons (make_number ('m'), minutes
);
6732 sequences
[6] = Fcons (make_number ('h'), hours
);
6733 sequences
[7] = Fcons (make_number ('t'), remain
);
6735 status
= Flist (8, sequences
);
6741 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
6742 doc
: /* Return storage information about the file system FILENAME is on.
6743 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
6744 storage of the file system, FREE is the free storage, and AVAIL is the
6745 storage available to a non-superuser. All 3 numbers are in bytes.
6746 If the underlying system call fails, value is nil. */)
6748 Lisp_Object filename
;
6750 Lisp_Object encoded
, value
;
6752 CHECK_STRING (filename
);
6753 filename
= Fexpand_file_name (filename
, Qnil
);
6754 encoded
= ENCODE_FILE (filename
);
6758 /* Determining the required information on Windows turns out, sadly,
6759 to be more involved than one would hope. The original Win32 api
6760 call for this will return bogus information on some systems, but we
6761 must dynamically probe for the replacement api, since that was
6762 added rather late on. */
6764 HMODULE hKernel
= GetModuleHandle ("kernel32");
6765 BOOL (*pfn_GetDiskFreeSpaceEx
)
6766 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
6767 = (void *) GetProcAddress (hKernel
, "GetDiskFreeSpaceEx");
6769 /* On Windows, we may need to specify the root directory of the
6770 volume holding FILENAME. */
6771 char rootname
[MAX_PATH
];
6772 char *name
= SDATA (encoded
);
6774 /* find the root name of the volume if given */
6775 if (isalpha (name
[0]) && name
[1] == ':')
6777 rootname
[0] = name
[0];
6778 rootname
[1] = name
[1];
6782 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
6784 char *str
= rootname
;
6788 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
6798 if (pfn_GetDiskFreeSpaceEx
)
6800 /* Unsigned large integers cannot be cast to double, so
6801 use signed ones instead. */
6802 LARGE_INTEGER availbytes
;
6803 LARGE_INTEGER freebytes
;
6804 LARGE_INTEGER totalbytes
;
6806 if (pfn_GetDiskFreeSpaceEx (rootname
,
6807 (ULARGE_INTEGER
*)&availbytes
,
6808 (ULARGE_INTEGER
*)&totalbytes
,
6809 (ULARGE_INTEGER
*)&freebytes
))
6810 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
6811 make_float ((double) freebytes
.QuadPart
),
6812 make_float ((double) availbytes
.QuadPart
));
6816 DWORD sectors_per_cluster
;
6817 DWORD bytes_per_sector
;
6818 DWORD free_clusters
;
6819 DWORD total_clusters
;
6821 if (GetDiskFreeSpace (rootname
,
6822 §ors_per_cluster
,
6826 value
= list3 (make_float ((double) total_clusters
6827 * sectors_per_cluster
* bytes_per_sector
),
6828 make_float ((double) free_clusters
6829 * sectors_per_cluster
* bytes_per_sector
),
6830 make_float ((double) free_clusters
6831 * sectors_per_cluster
* bytes_per_sector
));
6838 DEFUN ("default-printer-name", Fdefault_printer_name
, Sdefault_printer_name
,
6839 0, 0, 0, doc
: /* Return the name of Windows default printer device. */)
6842 static char pname_buf
[256];
6845 PRINTER_INFO_2
*ppi2
= NULL
;
6846 DWORD dwNeeded
= 0, dwReturned
= 0;
6848 /* Retrieve the default string from Win.ini (the registry).
6849 * String will be in form "printername,drivername,portname".
6850 * This is the most portable way to get the default printer. */
6851 if (GetProfileString ("windows", "device", ",,", pname_buf
, sizeof (pname_buf
)) <= 0)
6853 /* printername precedes first "," character */
6854 strtok (pname_buf
, ",");
6855 /* We want to know more than the printer name */
6856 if (!OpenPrinter (pname_buf
, &hPrn
, NULL
))
6858 GetPrinter (hPrn
, 2, NULL
, 0, &dwNeeded
);
6861 ClosePrinter (hPrn
);
6864 /* Allocate memory for the PRINTER_INFO_2 struct */
6865 ppi2
= (PRINTER_INFO_2
*) xmalloc (dwNeeded
);
6868 ClosePrinter (hPrn
);
6871 /* Call GetPrinter again with big enouth memory block */
6872 err
= GetPrinter (hPrn
, 2, (LPBYTE
)ppi2
, dwNeeded
, &dwReturned
);
6873 ClosePrinter (hPrn
);
6882 if (ppi2
->Attributes
& PRINTER_ATTRIBUTE_SHARED
&& ppi2
->pServerName
)
6884 /* a remote printer */
6885 if (*ppi2
->pServerName
== '\\')
6886 _snprintf (pname_buf
, sizeof (pname_buf
), "%s\\%s", ppi2
->pServerName
,
6889 _snprintf (pname_buf
, sizeof (pname_buf
), "\\\\%s\\%s", ppi2
->pServerName
,
6891 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
6895 /* a local printer */
6896 strncpy (pname_buf
, ppi2
->pPortName
, sizeof (pname_buf
));
6897 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
6898 /* `pPortName' can include several ports, delimited by ','.
6899 * we only use the first one. */
6900 strtok (pname_buf
, ",");
6905 return build_string (pname_buf
);
6908 /***********************************************************************
6910 ***********************************************************************/
6912 /* Keep this list in the same order as frame_parms in frame.c.
6913 Use 0 for unsupported frame parameters. */
6915 frame_parm_handler w32_frame_parm_handlers
[] =
6919 x_set_background_color
,
6925 x_set_foreground_color
,
6928 x_set_internal_border_width
,
6929 x_set_menu_bar_lines
,
6931 x_explicitly_set_name
,
6932 x_set_scroll_bar_width
,
6935 x_set_vertical_scroll_bars
,
6937 x_set_tool_bar_lines
,
6938 0, /* x_set_scroll_bar_foreground, */
6939 0, /* x_set_scroll_bar_background, */
6944 0, /* x_set_wait_for_wm, */
6953 globals_of_w32fns ();
6954 /* This is zero if not using MS-Windows. */
6956 track_mouse_window
= NULL
;
6958 w32_visible_system_caret_hwnd
= NULL
;
6960 DEFSYM (Qnone
, "none");
6961 DEFSYM (Qsuppress_icon
, "suppress-icon");
6962 DEFSYM (Qundefined_color
, "undefined-color");
6963 DEFSYM (Qcancel_timer
, "cancel-timer");
6964 DEFSYM (Qhyper
, "hyper");
6965 DEFSYM (Qsuper
, "super");
6966 DEFSYM (Qmeta
, "meta");
6967 DEFSYM (Qalt
, "alt");
6968 DEFSYM (Qctrl
, "ctrl");
6969 DEFSYM (Qcontrol
, "control");
6970 DEFSYM (Qshift
, "shift");
6971 DEFSYM (Qfont_param
, "font-parameter");
6972 /* This is the end of symbol initialization. */
6974 /* Text property `display' should be nonsticky by default. */
6975 Vtext_property_default_nonsticky
6976 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
6979 Fput (Qundefined_color
, Qerror_conditions
,
6980 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
6981 Fput (Qundefined_color
, Qerror_message
,
6982 build_string ("Undefined color"));
6984 staticpro (&w32_grabbed_keys
);
6985 w32_grabbed_keys
= Qnil
;
6987 DEFVAR_LISP ("w32-color-map", &Vw32_color_map
,
6988 doc
: /* An array of color name mappings for Windows. */);
6989 Vw32_color_map
= Qnil
;
6991 DEFVAR_LISP ("w32-pass-alt-to-system", &Vw32_pass_alt_to_system
,
6992 doc
: /* Non-nil if Alt key presses are passed on to Windows.
6993 When non-nil, for example, Alt pressed and released and then space will
6994 open the System menu. When nil, Emacs processes the Alt key events, and
6995 then silently swallows them. */);
6996 Vw32_pass_alt_to_system
= Qnil
;
6998 DEFVAR_LISP ("w32-alt-is-meta", &Vw32_alt_is_meta
,
6999 doc
: /* Non-nil if the Alt key is to be considered the same as the META key.
7000 When nil, Emacs will translate the Alt key to the ALT modifier, not to META. */);
7001 Vw32_alt_is_meta
= Qt
;
7003 DEFVAR_INT ("w32-quit-key", &w32_quit_key
,
7004 doc
: /* If non-zero, the virtual key code for an alternative quit key. */);
7007 DEFVAR_LISP ("w32-pass-lwindow-to-system",
7008 &Vw32_pass_lwindow_to_system
,
7009 doc
: /* If non-nil, the left \"Windows\" key is passed on to Windows.
7011 When non-nil, the Start menu is opened by tapping the key.
7012 If you set this to nil, the left \"Windows\" key is processed by Emacs
7013 according to the value of `w32-lwindow-modifier', which see.
7015 Note that some combinations of the left \"Windows\" key with other keys are
7016 caught by Windows at low level, and so binding them in Emacs will have no
7017 effect. For example, <lwindow>-r always pops up the Windows Run dialog,
7018 <lwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
7019 the doc string of `w32-phantom-key-code'. */);
7020 Vw32_pass_lwindow_to_system
= Qt
;
7022 DEFVAR_LISP ("w32-pass-rwindow-to-system",
7023 &Vw32_pass_rwindow_to_system
,
7024 doc
: /* If non-nil, the right \"Windows\" key is passed on to Windows.
7026 When non-nil, the Start menu is opened by tapping the key.
7027 If you set this to nil, the right \"Windows\" key is processed by Emacs
7028 according to the value of `w32-rwindow-modifier', which see.
7030 Note that some combinations of the right \"Windows\" key with other keys are
7031 caught by Windows at low level, and so binding them in Emacs will have no
7032 effect. For example, <rwindow>-r always pops up the Windows Run dialog,
7033 <rwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
7034 the doc string of `w32-phantom-key-code'. */);
7035 Vw32_pass_rwindow_to_system
= Qt
;
7037 DEFVAR_LISP ("w32-phantom-key-code",
7038 &Vw32_phantom_key_code
,
7039 doc
: /* Virtual key code used to generate \"phantom\" key presses.
7040 Value is a number between 0 and 255.
7042 Phantom key presses are generated in order to stop the system from
7043 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or
7044 `w32-pass-rwindow-to-system' is nil. */);
7045 /* Although 255 is technically not a valid key code, it works and
7046 means that this hack won't interfere with any real key code. */
7047 XSETINT (Vw32_phantom_key_code
, 255);
7049 DEFVAR_LISP ("w32-enable-num-lock",
7050 &Vw32_enable_num_lock
,
7051 doc
: /* If non-nil, the Num Lock key acts normally.
7052 Set to nil to handle Num Lock as the `kp-numlock' key. */);
7053 Vw32_enable_num_lock
= Qt
;
7055 DEFVAR_LISP ("w32-enable-caps-lock",
7056 &Vw32_enable_caps_lock
,
7057 doc
: /* If non-nil, the Caps Lock key acts normally.
7058 Set to nil to handle Caps Lock as the `capslock' key. */);
7059 Vw32_enable_caps_lock
= Qt
;
7061 DEFVAR_LISP ("w32-scroll-lock-modifier",
7062 &Vw32_scroll_lock_modifier
,
7063 doc
: /* Modifier to use for the Scroll Lock ON state.
7064 The value can be hyper, super, meta, alt, control or shift for the
7065 respective modifier, or nil to handle Scroll Lock as the `scroll' key.
7066 Any other value will cause the Scroll Lock key to be ignored. */);
7067 Vw32_scroll_lock_modifier
= Qt
;
7069 DEFVAR_LISP ("w32-lwindow-modifier",
7070 &Vw32_lwindow_modifier
,
7071 doc
: /* Modifier to use for the left \"Windows\" key.
7072 The value can be hyper, super, meta, alt, control or shift for the
7073 respective modifier, or nil to appear as the `lwindow' key.
7074 Any other value will cause the key to be ignored. */);
7075 Vw32_lwindow_modifier
= Qnil
;
7077 DEFVAR_LISP ("w32-rwindow-modifier",
7078 &Vw32_rwindow_modifier
,
7079 doc
: /* Modifier to use for the right \"Windows\" key.
7080 The value can be hyper, super, meta, alt, control or shift for the
7081 respective modifier, or nil to appear as the `rwindow' key.
7082 Any other value will cause the key to be ignored. */);
7083 Vw32_rwindow_modifier
= Qnil
;
7085 DEFVAR_LISP ("w32-apps-modifier",
7086 &Vw32_apps_modifier
,
7087 doc
: /* Modifier to use for the \"Apps\" key.
7088 The value can be hyper, super, meta, alt, control or shift for the
7089 respective modifier, or nil to appear as the `apps' key.
7090 Any other value will cause the key to be ignored. */);
7091 Vw32_apps_modifier
= Qnil
;
7093 DEFVAR_BOOL ("w32-enable-synthesized-fonts", &w32_enable_synthesized_fonts
,
7094 doc
: /* Non-nil enables selection of artificially italicized and bold fonts. */);
7095 w32_enable_synthesized_fonts
= 0;
7097 DEFVAR_LISP ("w32-enable-palette", &Vw32_enable_palette
,
7098 doc
: /* Non-nil enables Windows palette management to map colors exactly. */);
7099 Vw32_enable_palette
= Qt
;
7101 DEFVAR_INT ("w32-mouse-button-tolerance",
7102 &w32_mouse_button_tolerance
,
7103 doc
: /* Analogue of double click interval for faking middle mouse events.
7104 The value is the minimum time in milliseconds that must elapse between
7105 left and right button down events before they are considered distinct events.
7106 If both mouse buttons are depressed within this interval, a middle mouse
7107 button down event is generated instead. */);
7108 w32_mouse_button_tolerance
= GetDoubleClickTime () / 2;
7110 DEFVAR_INT ("w32-mouse-move-interval",
7111 &w32_mouse_move_interval
,
7112 doc
: /* Minimum interval between mouse move events.
7113 The value is the minimum time in milliseconds that must elapse between
7114 successive mouse move (or scroll bar drag) events before they are
7115 reported as lisp events. */);
7116 w32_mouse_move_interval
= 0;
7118 DEFVAR_BOOL ("w32-pass-extra-mouse-buttons-to-system",
7119 &w32_pass_extra_mouse_buttons_to_system
,
7120 doc
: /* If non-nil, the fourth and fifth mouse buttons are passed to Windows.
7121 Recent versions of Windows support mice with up to five buttons.
7122 Since most applications don't support these extra buttons, most mouse
7123 drivers will allow you to map them to functions at the system level.
7124 If this variable is non-nil, Emacs will pass them on, allowing the
7125 system to handle them. */);
7126 w32_pass_extra_mouse_buttons_to_system
= 0;
7128 DEFVAR_BOOL ("w32-pass-multimedia-buttons-to-system",
7129 &w32_pass_multimedia_buttons_to_system
,
7130 doc
: /* If non-nil, media buttons are passed to Windows.
7131 Some modern keyboards contain buttons for controlling media players, web
7132 browsers and other applications. Generally these buttons are handled on a
7133 system wide basis, but by setting this to nil they are made available
7134 to Emacs for binding. Depending on your keyboard, additional keys that
7135 may be available are:
7137 browser-back, browser-forward, browser-refresh, browser-stop,
7138 browser-search, browser-favorites, browser-home,
7139 mail, mail-reply, mail-forward, mail-send,
7141 help, find, new, open, close, save, print, undo, redo, copy, cut, paste,
7142 spell-check, correction-list, toggle-dictate-command,
7143 media-next, media-previous, media-stop, media-play-pause, media-select,
7144 media-play, media-pause, media-record, media-fast-forward, media-rewind,
7145 media-channel-up, media-channel-down,
7146 volume-mute, volume-up, volume-down,
7147 mic-volume-mute, mic-volume-down, mic-volume-up, mic-toggle,
7148 bass-down, bass-boost, bass-up, treble-down, treble-up */);
7149 w32_pass_multimedia_buttons_to_system
= 1;
7151 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
7152 doc
: /* The shape of the pointer when over text.
7153 Changing the value does not affect existing frames
7154 unless you set the mouse color. */);
7155 Vx_pointer_shape
= Qnil
;
7157 Vx_nontext_pointer_shape
= Qnil
;
7159 Vx_mode_pointer_shape
= Qnil
;
7161 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
7162 doc
: /* The shape of the pointer when Emacs is busy.
7163 This variable takes effect when you create a new frame
7164 or when you set the mouse color. */);
7165 Vx_hourglass_pointer_shape
= Qnil
;
7167 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
7168 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
7169 display_hourglass_p
= 1;
7171 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
7172 doc
: /* *Seconds to wait before displaying an hourglass pointer.
7173 Value must be an integer or float. */);
7174 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
7176 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
7177 &Vx_sensitive_text_pointer_shape
,
7178 doc
: /* The shape of the pointer when over mouse-sensitive text.
7179 This variable takes effect when you create a new frame
7180 or when you set the mouse color. */);
7181 Vx_sensitive_text_pointer_shape
= Qnil
;
7183 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
7184 &Vx_window_horizontal_drag_shape
,
7185 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
7186 This variable takes effect when you create a new frame
7187 or when you set the mouse color. */);
7188 Vx_window_horizontal_drag_shape
= Qnil
;
7190 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
7191 doc
: /* A string indicating the foreground color of the cursor box. */);
7192 Vx_cursor_fore_pixel
= Qnil
;
7194 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size
,
7195 doc
: /* Maximum size for tooltips.
7196 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
7197 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
7199 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
7200 doc
: /* Non-nil if no window manager is in use.
7201 Emacs doesn't try to figure this out; this is always nil
7202 unless you set it to something else. */);
7203 /* We don't have any way to find this out, so set it to nil
7204 and maybe the user would like to set it to t. */
7205 Vx_no_window_manager
= Qnil
;
7207 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
7208 &Vx_pixel_size_width_font_regexp
,
7209 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
7211 Since Emacs gets width of a font matching with this regexp from
7212 PIXEL_SIZE field of the name, font finding mechanism gets faster for
7213 such a font. This is especially effective for such large fonts as
7214 Chinese, Japanese, and Korean. */);
7215 Vx_pixel_size_width_font_regexp
= Qnil
;
7217 DEFVAR_LISP ("w32-bdf-filename-alist",
7218 &Vw32_bdf_filename_alist
,
7219 doc
: /* List of bdf fonts and their corresponding filenames. */);
7220 Vw32_bdf_filename_alist
= Qnil
;
7222 DEFVAR_BOOL ("w32-strict-fontnames",
7223 &w32_strict_fontnames
,
7224 doc
: /* Non-nil means only use fonts that are exact matches for those requested.
7225 Default is nil, which allows old fontnames that are not XLFD compliant,
7226 and allows third-party CJK display to work by specifying false charset
7227 fields to trick Emacs into translating to Big5, SJIS etc.
7228 Setting this to t will prevent wrong fonts being selected when
7229 fontsets are automatically created. */);
7230 w32_strict_fontnames
= 0;
7232 DEFVAR_BOOL ("w32-strict-painting",
7233 &w32_strict_painting
,
7234 doc
: /* Non-nil means use strict rules for repainting frames.
7235 Set this to nil to get the old behavior for repainting; this should
7236 only be necessary if the default setting causes problems. */);
7237 w32_strict_painting
= 1;
7239 #if 0 /* TODO: Port to W32 */
7240 defsubr (&Sx_change_window_property
);
7241 defsubr (&Sx_delete_window_property
);
7242 defsubr (&Sx_window_property
);
7244 defsubr (&Sxw_display_color_p
);
7245 defsubr (&Sx_display_grayscale_p
);
7246 defsubr (&Sxw_color_defined_p
);
7247 defsubr (&Sxw_color_values
);
7248 defsubr (&Sx_server_max_request_size
);
7249 defsubr (&Sx_server_vendor
);
7250 defsubr (&Sx_server_version
);
7251 defsubr (&Sx_display_pixel_width
);
7252 defsubr (&Sx_display_pixel_height
);
7253 defsubr (&Sx_display_mm_width
);
7254 defsubr (&Sx_display_mm_height
);
7255 defsubr (&Sx_display_screens
);
7256 defsubr (&Sx_display_planes
);
7257 defsubr (&Sx_display_color_cells
);
7258 defsubr (&Sx_display_visual_class
);
7259 defsubr (&Sx_display_backing_store
);
7260 defsubr (&Sx_display_save_under
);
7261 defsubr (&Sx_create_frame
);
7262 defsubr (&Sx_open_connection
);
7263 defsubr (&Sx_close_connection
);
7264 defsubr (&Sx_display_list
);
7265 defsubr (&Sx_synchronize
);
7266 defsubr (&Sx_focus_frame
);
7268 /* W32 specific functions */
7270 defsubr (&Sw32_define_rgb_color
);
7271 defsubr (&Sw32_default_color_map
);
7272 defsubr (&Sw32_load_color_file
);
7273 defsubr (&Sw32_send_sys_command
);
7274 defsubr (&Sw32_shell_execute
);
7275 defsubr (&Sw32_register_hot_key
);
7276 defsubr (&Sw32_unregister_hot_key
);
7277 defsubr (&Sw32_registered_hot_keys
);
7278 defsubr (&Sw32_reconstruct_hot_key
);
7279 defsubr (&Sw32_toggle_lock_key
);
7280 defsubr (&Sw32_window_exists_p
);
7281 defsubr (&Sw32_battery_status
);
7283 defsubr (&Sfile_system_info
);
7284 defsubr (&Sdefault_printer_name
);
7286 check_window_system_func
= check_w32
;
7289 hourglass_timer
= 0;
7290 hourglass_hwnd
= NULL
;
7291 hourglass_shown_p
= 0;
7292 defsubr (&Sx_show_tip
);
7293 defsubr (&Sx_hide_tip
);
7295 staticpro (&tip_timer
);
7297 staticpro (&tip_frame
);
7299 last_show_tip_args
= Qnil
;
7300 staticpro (&last_show_tip_args
);
7302 defsubr (&Sx_file_dialog
);
7303 defsubr (&Ssystem_move_file_to_trash
);
7308 globals_of_w32fns is used to initialize those global variables that
7309 must always be initialized on startup even when the global variable
7310 initialized is non zero (see the function main in emacs.c).
7311 globals_of_w32fns is called from syms_of_w32fns when the global
7312 variable initialized is 0 and directly from main when initialized
7316 globals_of_w32fns ()
7318 HMODULE user32_lib
= GetModuleHandle ("user32.dll");
7320 TrackMouseEvent not available in all versions of Windows, so must load
7321 it dynamically. Do it once, here, instead of every time it is used.
7323 track_mouse_event_fn
= (TrackMouseEvent_Proc
)
7324 GetProcAddress (user32_lib
, "TrackMouseEvent");
7325 /* ditto for GetClipboardSequenceNumber. */
7326 clipboard_sequence_fn
= (ClipboardSequence_Proc
)
7327 GetProcAddress (user32_lib
, "GetClipboardSequenceNumber");
7329 monitor_from_point_fn
= (MonitorFromPoint_Proc
)
7330 GetProcAddress (user32_lib
, "MonitorFromPoint");
7331 get_monitor_info_fn
= (GetMonitorInfo_Proc
)
7332 GetProcAddress (user32_lib
, "GetMonitorInfoA");
7335 HMODULE imm32_lib
= GetModuleHandle ("imm32.dll");
7336 get_composition_string_fn
= (ImmGetCompositionString_Proc
)
7337 GetProcAddress (imm32_lib
, "ImmGetCompositionStringW");
7338 get_ime_context_fn
= (ImmGetContext_Proc
)
7339 GetProcAddress (imm32_lib
, "ImmGetContext");
7341 DEFVAR_INT ("w32-ansi-code-page",
7342 &w32_ansi_code_page
,
7343 doc
: /* The ANSI code page used by the system. */);
7344 w32_ansi_code_page
= GetACP ();
7346 /* MessageBox does not work without this when linked to comctl32.dll 6.0. */
7347 InitCommonControls ();
7349 syms_of_w32uniscribe ();
7358 button
= MessageBox (NULL
,
7359 "A fatal error has occurred!\n\n"
7360 "Would you like to attach a debugger?\n\n"
7361 "Select YES to debug, NO to abort Emacs"
7363 "\n\n(type \"gdb -p <emacs-PID>\" and\n"
7364 "\"continue\" inside GDB before clicking YES.)"
7366 , "Emacs Abort Dialog",
7367 MB_ICONEXCLAMATION
| MB_TASKMODAL
7368 | MB_SETFOREGROUND
| MB_YESNO
);
7373 exit (2); /* tell the compiler we will never return */
7381 /* For convenience when debugging. */
7385 return GetLastError ();
7388 /* arch-tag: 707589ab-b9be-4638-8cdd-74629cc9b446
7389 (do not change this comment) */