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 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 /* Added by Kevin Gallo */
37 #include "intervals.h"
38 #include "dispextern.h"
40 #include "blockinput.h"
42 #include "character.h"
48 #include "termhooks.h"
51 #include "bitmaps/gray.xbm"
62 #define FILE_NAME_TEXT_FIELD edt1
64 #ifdef USE_FONT_BACKEND
68 void syms_of_w32fns ();
69 void globals_of_w32fns ();
71 extern void free_frame_menubar ();
72 extern double atof ();
73 extern int w32_console_toggle_lock_key
P_ ((int, Lisp_Object
));
74 extern void w32_menu_display_help
P_ ((HWND
, HMENU
, UINT
, UINT
));
75 extern void w32_free_menu_strings
P_ ((HWND
));
76 extern XCharStruct
*w32_per_char_metric
P_ ((XFontStruct
*, wchar_t *, int));
80 extern char *lispy_function_keys
[];
82 /* The colormap for converting color names to RGB values */
83 Lisp_Object Vw32_color_map
;
85 /* Non nil if alt key presses are passed on to Windows. */
86 Lisp_Object Vw32_pass_alt_to_system
;
88 /* Non nil if alt key is translated to meta_modifier, nil if it is translated
90 Lisp_Object Vw32_alt_is_meta
;
92 /* If non-zero, the windows virtual key code for an alternative quit key. */
95 /* Non nil if left window key events are passed on to Windows (this only
96 affects whether "tapping" the key opens the Start menu). */
97 Lisp_Object Vw32_pass_lwindow_to_system
;
99 /* Non nil if right window key events are passed on to Windows (this
100 only affects whether "tapping" the key opens the Start menu). */
101 Lisp_Object Vw32_pass_rwindow_to_system
;
103 /* Virtual key code used to generate "phantom" key presses in order
104 to stop system from acting on Windows key events. */
105 Lisp_Object Vw32_phantom_key_code
;
107 /* Modifier associated with the left "Windows" key, or nil to act as a
109 Lisp_Object Vw32_lwindow_modifier
;
111 /* Modifier associated with the right "Windows" key, or nil to act as a
113 Lisp_Object Vw32_rwindow_modifier
;
115 /* Modifier associated with the "Apps" key, or nil to act as a normal
117 Lisp_Object Vw32_apps_modifier
;
119 /* Value is nil if Num Lock acts as a function key. */
120 Lisp_Object Vw32_enable_num_lock
;
122 /* Value is nil if Caps Lock acts as a function key. */
123 Lisp_Object Vw32_enable_caps_lock
;
125 /* Modifier associated with Scroll Lock, or nil to act as a normal key. */
126 Lisp_Object Vw32_scroll_lock_modifier
;
128 /* Switch to control whether we inhibit requests for synthesized bold
129 and italic versions of fonts. */
130 int w32_enable_synthesized_fonts
;
132 /* Enable palette management. */
133 Lisp_Object Vw32_enable_palette
;
135 /* Control how close left/right button down events must be to
136 be converted to a middle button down event. */
137 int w32_mouse_button_tolerance
;
139 /* Minimum interval between mouse movement (and scroll bar drag)
140 events that are passed on to the event loop. */
141 int w32_mouse_move_interval
;
143 /* Flag to indicate if XBUTTON events should be passed on to Windows. */
144 static int w32_pass_extra_mouse_buttons_to_system
;
146 /* Flag to indicate if media keys should be passed on to Windows. */
147 static int w32_pass_multimedia_buttons_to_system
;
149 /* Non nil if no window manager is in use. */
150 Lisp_Object Vx_no_window_manager
;
152 /* Non-zero means we're allowed to display a hourglass pointer. */
154 int display_hourglass_p
;
156 /* The background and shape of the mouse pointer, and shape when not
157 over text or in the modeline. */
159 Lisp_Object Vx_pointer_shape
, Vx_nontext_pointer_shape
, Vx_mode_pointer_shape
;
160 Lisp_Object Vx_hourglass_pointer_shape
, Vx_window_horizontal_drag_shape
;
162 /* The shape when over mouse-sensitive text. */
164 Lisp_Object Vx_sensitive_text_pointer_shape
;
167 #define IDC_HAND MAKEINTRESOURCE(32649)
170 /* Color of chars displayed in cursor box. */
172 Lisp_Object Vx_cursor_fore_pixel
;
174 /* Nonzero if using Windows. */
176 static int w32_in_use
;
178 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
180 Lisp_Object Vx_pixel_size_width_font_regexp
;
182 /* Alist of bdf fonts and the files that define them. */
183 Lisp_Object Vw32_bdf_filename_alist
;
185 /* A flag to control whether fonts are matched strictly or not. */
186 static int w32_strict_fontnames
;
188 /* A flag to control whether we should only repaint if GetUpdateRect
189 indicates there is an update region. */
190 static int w32_strict_painting
;
192 /* Associative list linking character set strings to Windows codepages. */
193 static Lisp_Object Vw32_charset_info_alist
;
195 /* VIETNAMESE_CHARSET is not defined in some versions of MSVC. */
196 #ifndef VIETNAMESE_CHARSET
197 #define VIETNAMESE_CHARSET 163
201 Lisp_Object Qsuppress_icon
;
202 Lisp_Object Qundefined_color
;
203 Lisp_Object Qcancel_timer
;
209 Lisp_Object Qcontrol
;
212 Lisp_Object Qw32_charset_ansi
;
213 Lisp_Object Qw32_charset_default
;
214 Lisp_Object Qw32_charset_symbol
;
215 Lisp_Object Qw32_charset_shiftjis
;
216 Lisp_Object Qw32_charset_hangeul
;
217 Lisp_Object Qw32_charset_gb2312
;
218 Lisp_Object Qw32_charset_chinesebig5
;
219 Lisp_Object Qw32_charset_oem
;
221 #ifndef JOHAB_CHARSET
222 #define JOHAB_CHARSET 130
225 Lisp_Object Qw32_charset_easteurope
;
226 Lisp_Object Qw32_charset_turkish
;
227 Lisp_Object Qw32_charset_baltic
;
228 Lisp_Object Qw32_charset_russian
;
229 Lisp_Object Qw32_charset_arabic
;
230 Lisp_Object Qw32_charset_greek
;
231 Lisp_Object Qw32_charset_hebrew
;
232 Lisp_Object Qw32_charset_vietnamese
;
233 Lisp_Object Qw32_charset_thai
;
234 Lisp_Object Qw32_charset_johab
;
235 Lisp_Object Qw32_charset_mac
;
238 #ifdef UNICODE_CHARSET
239 Lisp_Object Qw32_charset_unicode
;
242 /* The ANSI codepage. */
243 int w32_ansi_code_page
;
245 /* Prefix for system colors. */
246 #define SYSTEM_COLOR_PREFIX "System"
247 #define SYSTEM_COLOR_PREFIX_LEN (sizeof (SYSTEM_COLOR_PREFIX) - 1)
249 /* State variables for emulating a three button mouse. */
254 static int button_state
= 0;
255 static W32Msg saved_mouse_button_msg
;
256 static unsigned mouse_button_timer
= 0; /* non-zero when timer is active */
257 static W32Msg saved_mouse_move_msg
;
258 static unsigned mouse_move_timer
= 0;
260 /* Window that is tracking the mouse. */
261 static HWND track_mouse_window
;
263 typedef BOOL (WINAPI
* TrackMouseEvent_Proc
)
264 (IN OUT LPTRACKMOUSEEVENT lpEventTrack
);
265 typedef LONG (WINAPI
* ImmGetCompositionString_Proc
)
266 (IN HIMC context
, IN DWORD index
, OUT LPVOID buffer
, IN DWORD bufLen
);
267 typedef HIMC (WINAPI
* ImmGetContext_Proc
) (IN HWND window
);
269 TrackMouseEvent_Proc track_mouse_event_fn
= NULL
;
270 ClipboardSequence_Proc clipboard_sequence_fn
= NULL
;
271 ImmGetCompositionString_Proc get_composition_string_fn
= NULL
;
272 ImmGetContext_Proc get_ime_context_fn
= NULL
;
274 extern AppendMenuW_Proc unicode_append_menu
;
276 /* Flag to selectively ignore WM_IME_CHAR messages. */
277 static int ignore_ime_char
= 0;
279 /* W95 mousewheel handler */
280 unsigned int msh_mousewheel
= 0;
283 #define MOUSE_BUTTON_ID 1
284 #define MOUSE_MOVE_ID 2
285 #define MENU_FREE_ID 3
286 /* The delay (milliseconds) before a menu is freed after WM_EXITMENULOOP
288 #define MENU_FREE_DELAY 1000
289 static unsigned menu_free_timer
= 0;
291 /* The below are defined in frame.c. */
293 extern Lisp_Object Vwindow_system_version
;
296 int image_cache_refcount
, dpyinfo_refcount
;
300 /* From w32term.c. */
301 extern int w32_num_mouse_buttons
;
302 extern Lisp_Object Vw32_recognize_altgr
;
304 extern HWND w32_system_caret_hwnd
;
306 extern int w32_system_caret_height
;
307 extern int w32_system_caret_x
;
308 extern int w32_system_caret_y
;
309 extern int w32_use_visible_system_caret
;
311 static HWND w32_visible_system_caret_hwnd
;
314 extern HMENU current_popup_menu
;
315 static int menubar_in_use
= 0;
318 /* Error if we are not connected to MS-Windows. */
323 error ("MS-Windows not in use or not initialized");
326 /* Nonzero if we can use mouse menus.
327 You should not call this unless HAVE_MENUS is defined. */
335 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
336 and checking validity for W32. */
339 check_x_frame (frame
)
345 frame
= selected_frame
;
346 CHECK_LIVE_FRAME (frame
);
348 if (! FRAME_W32_P (f
))
349 error ("Non-W32 frame used");
353 /* Let the user specify a display with a frame.
354 nil stands for the selected frame--or, if that is not a w32 frame,
355 the first display on the list. */
357 struct w32_display_info
*
358 check_x_display_info (frame
)
363 struct frame
*sf
= XFRAME (selected_frame
);
365 if (FRAME_W32_P (sf
) && FRAME_LIVE_P (sf
))
366 return FRAME_W32_DISPLAY_INFO (sf
);
368 return &one_w32_display_info
;
370 else if (STRINGP (frame
))
371 return x_display_info_for_name (frame
);
376 CHECK_LIVE_FRAME (frame
);
378 if (! FRAME_W32_P (f
))
379 error ("Non-W32 frame used");
380 return FRAME_W32_DISPLAY_INFO (f
);
384 /* Return the Emacs frame-object corresponding to an w32 window.
385 It could be the frame's main window or an icon window. */
387 /* This function can be called during GC, so use GC_xxx type test macros. */
390 x_window_to_frame (dpyinfo
, wdesc
)
391 struct w32_display_info
*dpyinfo
;
394 Lisp_Object tail
, frame
;
397 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
403 if (!FRAME_W32_P (f
) || FRAME_W32_DISPLAY_INFO (f
) != dpyinfo
)
405 if (f
->output_data
.w32
->hourglass_window
== wdesc
)
408 if (FRAME_W32_WINDOW (f
) == wdesc
)
415 static Lisp_Object unwind_create_frame
P_ ((Lisp_Object
));
416 static Lisp_Object unwind_create_tip_frame
P_ ((Lisp_Object
));
417 static void my_create_window
P_ ((struct frame
*));
418 static void my_create_tip_window
P_ ((struct frame
*));
420 /* TODO: Native Input Method support; see x_create_im. */
421 void x_set_foreground_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
422 void x_set_background_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
423 void x_set_mouse_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
424 void x_set_cursor_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
425 void x_set_border_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
426 void x_set_cursor_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
427 void x_set_icon_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
428 void x_set_icon_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
429 void x_explicitly_set_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
430 void x_set_menu_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
431 void x_set_title
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
432 void x_set_tool_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
433 static void x_edge_detection
P_ ((struct frame
*, struct image
*, Lisp_Object
,
439 /* Store the screen positions of frame F into XPTR and YPTR.
440 These are the positions of the containing window manager window,
441 not Emacs's own window. */
444 x_real_positions (f
, xptr
, yptr
)
451 /* Get the bounds of the WM window. */
452 GetWindowRect (FRAME_W32_WINDOW (f
), &rect
);
457 /* Convert (0, 0) in the client area to screen co-ordinates. */
458 ClientToScreen (FRAME_W32_WINDOW (f
), &pt
);
460 /* Remember x_pixels_diff and y_pixels_diff. */
461 f
->x_pixels_diff
= pt
.x
- rect
.left
;
462 f
->y_pixels_diff
= pt
.y
- rect
.top
;
470 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
,
471 Sw32_define_rgb_color
, 4, 4, 0,
472 doc
: /* Convert RGB numbers to a windows color reference and associate with NAME.
473 This adds or updates a named color to `w32-color-map', making it
474 available for use. The original entry's RGB ref is returned, or nil
475 if the entry is new. */)
476 (red
, green
, blue
, name
)
477 Lisp_Object red
, green
, blue
, name
;
480 Lisp_Object oldrgb
= Qnil
;
484 CHECK_NUMBER (green
);
488 XSETINT (rgb
, RGB (XUINT (red
), XUINT (green
), XUINT (blue
)));
492 /* replace existing entry in w32-color-map or add new entry. */
493 entry
= Fassoc (name
, Vw32_color_map
);
496 entry
= Fcons (name
, rgb
);
497 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
501 oldrgb
= Fcdr (entry
);
502 Fsetcdr (entry
, rgb
);
510 DEFUN ("w32-load-color-file", Fw32_load_color_file
,
511 Sw32_load_color_file
, 1, 1, 0,
512 doc
: /* Create an alist of color entries from an external file.
513 Assign this value to `w32-color-map' to replace the existing color map.
515 The file should define one named RGB color per line like so:
517 where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
519 Lisp_Object filename
;
522 Lisp_Object cmap
= Qnil
;
525 CHECK_STRING (filename
);
526 abspath
= Fexpand_file_name (filename
, Qnil
);
528 fp
= fopen (SDATA (filename
), "rt");
532 int red
, green
, blue
;
537 while (fgets (buf
, sizeof (buf
), fp
) != NULL
) {
538 if (sscanf (buf
, "%u %u %u %n", &red
, &green
, &blue
, &num
) == 3)
540 char *name
= buf
+ num
;
541 num
= strlen (name
) - 1;
542 if (name
[num
] == '\n')
544 cmap
= Fcons (Fcons (build_string (name
),
545 make_number (RGB (red
, green
, blue
))),
557 /* The default colors for the w32 color map */
558 typedef struct colormap_t
564 colormap_t w32_color_map
[] =
566 {"snow" , PALETTERGB (255,250,250)},
567 {"ghost white" , PALETTERGB (248,248,255)},
568 {"GhostWhite" , PALETTERGB (248,248,255)},
569 {"white smoke" , PALETTERGB (245,245,245)},
570 {"WhiteSmoke" , PALETTERGB (245,245,245)},
571 {"gainsboro" , PALETTERGB (220,220,220)},
572 {"floral white" , PALETTERGB (255,250,240)},
573 {"FloralWhite" , PALETTERGB (255,250,240)},
574 {"old lace" , PALETTERGB (253,245,230)},
575 {"OldLace" , PALETTERGB (253,245,230)},
576 {"linen" , PALETTERGB (250,240,230)},
577 {"antique white" , PALETTERGB (250,235,215)},
578 {"AntiqueWhite" , PALETTERGB (250,235,215)},
579 {"papaya whip" , PALETTERGB (255,239,213)},
580 {"PapayaWhip" , PALETTERGB (255,239,213)},
581 {"blanched almond" , PALETTERGB (255,235,205)},
582 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
583 {"bisque" , PALETTERGB (255,228,196)},
584 {"peach puff" , PALETTERGB (255,218,185)},
585 {"PeachPuff" , PALETTERGB (255,218,185)},
586 {"navajo white" , PALETTERGB (255,222,173)},
587 {"NavajoWhite" , PALETTERGB (255,222,173)},
588 {"moccasin" , PALETTERGB (255,228,181)},
589 {"cornsilk" , PALETTERGB (255,248,220)},
590 {"ivory" , PALETTERGB (255,255,240)},
591 {"lemon chiffon" , PALETTERGB (255,250,205)},
592 {"LemonChiffon" , PALETTERGB (255,250,205)},
593 {"seashell" , PALETTERGB (255,245,238)},
594 {"honeydew" , PALETTERGB (240,255,240)},
595 {"mint cream" , PALETTERGB (245,255,250)},
596 {"MintCream" , PALETTERGB (245,255,250)},
597 {"azure" , PALETTERGB (240,255,255)},
598 {"alice blue" , PALETTERGB (240,248,255)},
599 {"AliceBlue" , PALETTERGB (240,248,255)},
600 {"lavender" , PALETTERGB (230,230,250)},
601 {"lavender blush" , PALETTERGB (255,240,245)},
602 {"LavenderBlush" , PALETTERGB (255,240,245)},
603 {"misty rose" , PALETTERGB (255,228,225)},
604 {"MistyRose" , PALETTERGB (255,228,225)},
605 {"white" , PALETTERGB (255,255,255)},
606 {"black" , PALETTERGB ( 0, 0, 0)},
607 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
608 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
609 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
610 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
611 {"dim gray" , PALETTERGB (105,105,105)},
612 {"DimGray" , PALETTERGB (105,105,105)},
613 {"dim grey" , PALETTERGB (105,105,105)},
614 {"DimGrey" , PALETTERGB (105,105,105)},
615 {"slate gray" , PALETTERGB (112,128,144)},
616 {"SlateGray" , PALETTERGB (112,128,144)},
617 {"slate grey" , PALETTERGB (112,128,144)},
618 {"SlateGrey" , PALETTERGB (112,128,144)},
619 {"light slate gray" , PALETTERGB (119,136,153)},
620 {"LightSlateGray" , PALETTERGB (119,136,153)},
621 {"light slate grey" , PALETTERGB (119,136,153)},
622 {"LightSlateGrey" , PALETTERGB (119,136,153)},
623 {"gray" , PALETTERGB (190,190,190)},
624 {"grey" , PALETTERGB (190,190,190)},
625 {"light grey" , PALETTERGB (211,211,211)},
626 {"LightGrey" , PALETTERGB (211,211,211)},
627 {"light gray" , PALETTERGB (211,211,211)},
628 {"LightGray" , PALETTERGB (211,211,211)},
629 {"midnight blue" , PALETTERGB ( 25, 25,112)},
630 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
631 {"navy" , PALETTERGB ( 0, 0,128)},
632 {"navy blue" , PALETTERGB ( 0, 0,128)},
633 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
634 {"cornflower blue" , PALETTERGB (100,149,237)},
635 {"CornflowerBlue" , PALETTERGB (100,149,237)},
636 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
637 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
638 {"slate blue" , PALETTERGB (106, 90,205)},
639 {"SlateBlue" , PALETTERGB (106, 90,205)},
640 {"medium slate blue" , PALETTERGB (123,104,238)},
641 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
642 {"light slate blue" , PALETTERGB (132,112,255)},
643 {"LightSlateBlue" , PALETTERGB (132,112,255)},
644 {"medium blue" , PALETTERGB ( 0, 0,205)},
645 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
646 {"royal blue" , PALETTERGB ( 65,105,225)},
647 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
648 {"blue" , PALETTERGB ( 0, 0,255)},
649 {"dodger blue" , PALETTERGB ( 30,144,255)},
650 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
651 {"deep sky blue" , PALETTERGB ( 0,191,255)},
652 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
653 {"sky blue" , PALETTERGB (135,206,235)},
654 {"SkyBlue" , PALETTERGB (135,206,235)},
655 {"light sky blue" , PALETTERGB (135,206,250)},
656 {"LightSkyBlue" , PALETTERGB (135,206,250)},
657 {"steel blue" , PALETTERGB ( 70,130,180)},
658 {"SteelBlue" , PALETTERGB ( 70,130,180)},
659 {"light steel blue" , PALETTERGB (176,196,222)},
660 {"LightSteelBlue" , PALETTERGB (176,196,222)},
661 {"light blue" , PALETTERGB (173,216,230)},
662 {"LightBlue" , PALETTERGB (173,216,230)},
663 {"powder blue" , PALETTERGB (176,224,230)},
664 {"PowderBlue" , PALETTERGB (176,224,230)},
665 {"pale turquoise" , PALETTERGB (175,238,238)},
666 {"PaleTurquoise" , PALETTERGB (175,238,238)},
667 {"dark turquoise" , PALETTERGB ( 0,206,209)},
668 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
669 {"medium turquoise" , PALETTERGB ( 72,209,204)},
670 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
671 {"turquoise" , PALETTERGB ( 64,224,208)},
672 {"cyan" , PALETTERGB ( 0,255,255)},
673 {"light cyan" , PALETTERGB (224,255,255)},
674 {"LightCyan" , PALETTERGB (224,255,255)},
675 {"cadet blue" , PALETTERGB ( 95,158,160)},
676 {"CadetBlue" , PALETTERGB ( 95,158,160)},
677 {"medium aquamarine" , PALETTERGB (102,205,170)},
678 {"MediumAquamarine" , PALETTERGB (102,205,170)},
679 {"aquamarine" , PALETTERGB (127,255,212)},
680 {"dark green" , PALETTERGB ( 0,100, 0)},
681 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
682 {"dark olive green" , PALETTERGB ( 85,107, 47)},
683 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
684 {"dark sea green" , PALETTERGB (143,188,143)},
685 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
686 {"sea green" , PALETTERGB ( 46,139, 87)},
687 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
688 {"medium sea green" , PALETTERGB ( 60,179,113)},
689 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
690 {"light sea green" , PALETTERGB ( 32,178,170)},
691 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
692 {"pale green" , PALETTERGB (152,251,152)},
693 {"PaleGreen" , PALETTERGB (152,251,152)},
694 {"spring green" , PALETTERGB ( 0,255,127)},
695 {"SpringGreen" , PALETTERGB ( 0,255,127)},
696 {"lawn green" , PALETTERGB (124,252, 0)},
697 {"LawnGreen" , PALETTERGB (124,252, 0)},
698 {"green" , PALETTERGB ( 0,255, 0)},
699 {"chartreuse" , PALETTERGB (127,255, 0)},
700 {"medium spring green" , PALETTERGB ( 0,250,154)},
701 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
702 {"green yellow" , PALETTERGB (173,255, 47)},
703 {"GreenYellow" , PALETTERGB (173,255, 47)},
704 {"lime green" , PALETTERGB ( 50,205, 50)},
705 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
706 {"yellow green" , PALETTERGB (154,205, 50)},
707 {"YellowGreen" , PALETTERGB (154,205, 50)},
708 {"forest green" , PALETTERGB ( 34,139, 34)},
709 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
710 {"olive drab" , PALETTERGB (107,142, 35)},
711 {"OliveDrab" , PALETTERGB (107,142, 35)},
712 {"dark khaki" , PALETTERGB (189,183,107)},
713 {"DarkKhaki" , PALETTERGB (189,183,107)},
714 {"khaki" , PALETTERGB (240,230,140)},
715 {"pale goldenrod" , PALETTERGB (238,232,170)},
716 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
717 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
718 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
719 {"light yellow" , PALETTERGB (255,255,224)},
720 {"LightYellow" , PALETTERGB (255,255,224)},
721 {"yellow" , PALETTERGB (255,255, 0)},
722 {"gold" , PALETTERGB (255,215, 0)},
723 {"light goldenrod" , PALETTERGB (238,221,130)},
724 {"LightGoldenrod" , PALETTERGB (238,221,130)},
725 {"goldenrod" , PALETTERGB (218,165, 32)},
726 {"dark goldenrod" , PALETTERGB (184,134, 11)},
727 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
728 {"rosy brown" , PALETTERGB (188,143,143)},
729 {"RosyBrown" , PALETTERGB (188,143,143)},
730 {"indian red" , PALETTERGB (205, 92, 92)},
731 {"IndianRed" , PALETTERGB (205, 92, 92)},
732 {"saddle brown" , PALETTERGB (139, 69, 19)},
733 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
734 {"sienna" , PALETTERGB (160, 82, 45)},
735 {"peru" , PALETTERGB (205,133, 63)},
736 {"burlywood" , PALETTERGB (222,184,135)},
737 {"beige" , PALETTERGB (245,245,220)},
738 {"wheat" , PALETTERGB (245,222,179)},
739 {"sandy brown" , PALETTERGB (244,164, 96)},
740 {"SandyBrown" , PALETTERGB (244,164, 96)},
741 {"tan" , PALETTERGB (210,180,140)},
742 {"chocolate" , PALETTERGB (210,105, 30)},
743 {"firebrick" , PALETTERGB (178,34, 34)},
744 {"brown" , PALETTERGB (165,42, 42)},
745 {"dark salmon" , PALETTERGB (233,150,122)},
746 {"DarkSalmon" , PALETTERGB (233,150,122)},
747 {"salmon" , PALETTERGB (250,128,114)},
748 {"light salmon" , PALETTERGB (255,160,122)},
749 {"LightSalmon" , PALETTERGB (255,160,122)},
750 {"orange" , PALETTERGB (255,165, 0)},
751 {"dark orange" , PALETTERGB (255,140, 0)},
752 {"DarkOrange" , PALETTERGB (255,140, 0)},
753 {"coral" , PALETTERGB (255,127, 80)},
754 {"light coral" , PALETTERGB (240,128,128)},
755 {"LightCoral" , PALETTERGB (240,128,128)},
756 {"tomato" , PALETTERGB (255, 99, 71)},
757 {"orange red" , PALETTERGB (255, 69, 0)},
758 {"OrangeRed" , PALETTERGB (255, 69, 0)},
759 {"red" , PALETTERGB (255, 0, 0)},
760 {"hot pink" , PALETTERGB (255,105,180)},
761 {"HotPink" , PALETTERGB (255,105,180)},
762 {"deep pink" , PALETTERGB (255, 20,147)},
763 {"DeepPink" , PALETTERGB (255, 20,147)},
764 {"pink" , PALETTERGB (255,192,203)},
765 {"light pink" , PALETTERGB (255,182,193)},
766 {"LightPink" , PALETTERGB (255,182,193)},
767 {"pale violet red" , PALETTERGB (219,112,147)},
768 {"PaleVioletRed" , PALETTERGB (219,112,147)},
769 {"maroon" , PALETTERGB (176, 48, 96)},
770 {"medium violet red" , PALETTERGB (199, 21,133)},
771 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
772 {"violet red" , PALETTERGB (208, 32,144)},
773 {"VioletRed" , PALETTERGB (208, 32,144)},
774 {"magenta" , PALETTERGB (255, 0,255)},
775 {"violet" , PALETTERGB (238,130,238)},
776 {"plum" , PALETTERGB (221,160,221)},
777 {"orchid" , PALETTERGB (218,112,214)},
778 {"medium orchid" , PALETTERGB (186, 85,211)},
779 {"MediumOrchid" , PALETTERGB (186, 85,211)},
780 {"dark orchid" , PALETTERGB (153, 50,204)},
781 {"DarkOrchid" , PALETTERGB (153, 50,204)},
782 {"dark violet" , PALETTERGB (148, 0,211)},
783 {"DarkViolet" , PALETTERGB (148, 0,211)},
784 {"blue violet" , PALETTERGB (138, 43,226)},
785 {"BlueViolet" , PALETTERGB (138, 43,226)},
786 {"purple" , PALETTERGB (160, 32,240)},
787 {"medium purple" , PALETTERGB (147,112,219)},
788 {"MediumPurple" , PALETTERGB (147,112,219)},
789 {"thistle" , PALETTERGB (216,191,216)},
790 {"gray0" , PALETTERGB ( 0, 0, 0)},
791 {"grey0" , PALETTERGB ( 0, 0, 0)},
792 {"dark grey" , PALETTERGB (169,169,169)},
793 {"DarkGrey" , PALETTERGB (169,169,169)},
794 {"dark gray" , PALETTERGB (169,169,169)},
795 {"DarkGray" , PALETTERGB (169,169,169)},
796 {"dark blue" , PALETTERGB ( 0, 0,139)},
797 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
798 {"dark cyan" , PALETTERGB ( 0,139,139)},
799 {"DarkCyan" , PALETTERGB ( 0,139,139)},
800 {"dark magenta" , PALETTERGB (139, 0,139)},
801 {"DarkMagenta" , PALETTERGB (139, 0,139)},
802 {"dark red" , PALETTERGB (139, 0, 0)},
803 {"DarkRed" , PALETTERGB (139, 0, 0)},
804 {"light green" , PALETTERGB (144,238,144)},
805 {"LightGreen" , PALETTERGB (144,238,144)},
808 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
809 0, 0, 0, doc
: /* Return the default color map. */)
813 colormap_t
*pc
= w32_color_map
;
820 for (i
= 0; i
< sizeof (w32_color_map
) / sizeof (w32_color_map
[0]);
822 cmap
= Fcons (Fcons (build_string (pc
->name
),
823 make_number (pc
->colorref
)),
841 color
= Frassq (rgb
, Vw32_color_map
);
846 return (Fcar (color
));
852 w32_color_map_lookup (colorname
)
855 Lisp_Object tail
, ret
= Qnil
;
859 for (tail
= Vw32_color_map
; CONSP (tail
); tail
= XCDR (tail
))
861 register Lisp_Object elt
, tem
;
864 if (!CONSP (elt
)) continue;
868 if (lstrcmpi (SDATA (tem
), colorname
) == 0)
885 add_system_logical_colors_to_map (system_colors
)
886 Lisp_Object
*system_colors
;
890 /* Other registry operations are done with input blocked. */
893 /* Look for "Control Panel/Colors" under User and Machine registry
895 if (RegOpenKeyEx (HKEY_CURRENT_USER
, "Control Panel\\Colors", 0,
896 KEY_READ
, &colors_key
) == ERROR_SUCCESS
897 || RegOpenKeyEx (HKEY_LOCAL_MACHINE
, "Control Panel\\Colors", 0,
898 KEY_READ
, &colors_key
) == ERROR_SUCCESS
)
901 char color_buffer
[64];
902 char full_name_buffer
[MAX_PATH
+ SYSTEM_COLOR_PREFIX_LEN
];
904 DWORD name_size
, color_size
;
905 char *name_buffer
= full_name_buffer
+ SYSTEM_COLOR_PREFIX_LEN
;
907 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
908 color_size
= sizeof (color_buffer
);
910 strcpy (full_name_buffer
, SYSTEM_COLOR_PREFIX
);
912 while (RegEnumValueA (colors_key
, index
, name_buffer
, &name_size
,
913 NULL
, NULL
, color_buffer
, &color_size
)
917 if (sscanf (color_buffer
, " %u %u %u", &r
, &g
, &b
) == 3)
918 *system_colors
= Fcons (Fcons (build_string (full_name_buffer
),
919 make_number (RGB (r
, g
, b
))),
922 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
923 color_size
= sizeof (color_buffer
);
926 RegCloseKey (colors_key
);
934 x_to_w32_color (colorname
)
937 register Lisp_Object ret
= Qnil
;
941 if (colorname
[0] == '#')
943 /* Could be an old-style RGB Device specification. */
946 color
= colorname
+ 1;
948 size
= strlen (color
);
949 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
957 for (i
= 0; i
< 3; i
++)
963 /* The check for 'x' in the following conditional takes into
964 account the fact that strtol allows a "0x" in front of
965 our numbers, and we don't. */
966 if (!isxdigit (color
[0]) || color
[1] == 'x')
970 value
= strtoul (color
, &end
, 16);
972 if (errno
== ERANGE
|| end
- color
!= size
)
977 value
= value
* 0x10;
988 colorval
|= (value
<< pos
);
993 XSETINT (ret
, colorval
);
1000 else if (strnicmp (colorname
, "rgb:", 4) == 0)
1008 color
= colorname
+ 4;
1009 for (i
= 0; i
< 3; i
++)
1012 unsigned long value
;
1014 /* The check for 'x' in the following conditional takes into
1015 account the fact that strtol allows a "0x" in front of
1016 our numbers, and we don't. */
1017 if (!isxdigit (color
[0]) || color
[1] == 'x')
1019 value
= strtoul (color
, &end
, 16);
1020 if (errno
== ERANGE
)
1022 switch (end
- color
)
1025 value
= value
* 0x10 + value
;
1038 if (value
== ULONG_MAX
)
1040 colorval
|= (value
<< pos
);
1047 XSETINT (ret
, colorval
);
1055 else if (strnicmp (colorname
, "rgbi:", 5) == 0)
1057 /* This is an RGB Intensity specification. */
1064 color
= colorname
+ 5;
1065 for (i
= 0; i
< 3; i
++)
1071 value
= strtod (color
, &end
);
1072 if (errno
== ERANGE
)
1074 if (value
< 0.0 || value
> 1.0)
1076 val
= (UINT
)(0x100 * value
);
1077 /* We used 0x100 instead of 0xFF to give a continuous
1078 range between 0.0 and 1.0 inclusive. The next statement
1079 fixes the 1.0 case. */
1082 colorval
|= (val
<< pos
);
1089 XSETINT (ret
, colorval
);
1097 /* I am not going to attempt to handle any of the CIE color schemes
1098 or TekHVC, since I don't know the algorithms for conversion to
1101 /* If we fail to lookup the color name in w32_color_map, then check the
1102 colorname to see if it can be crudely approximated: If the X color
1103 ends in a number (e.g., "darkseagreen2"), strip the number and
1104 return the result of looking up the base color name. */
1105 ret
= w32_color_map_lookup (colorname
);
1108 int len
= strlen (colorname
);
1110 if (isdigit (colorname
[len
- 1]))
1112 char *ptr
, *approx
= alloca (len
+ 1);
1114 strcpy (approx
, colorname
);
1115 ptr
= &approx
[len
- 1];
1116 while (ptr
> approx
&& isdigit (*ptr
))
1119 ret
= w32_color_map_lookup (approx
);
1128 w32_regenerate_palette (FRAME_PTR f
)
1130 struct w32_palette_entry
* list
;
1131 LOGPALETTE
* log_palette
;
1132 HPALETTE new_palette
;
1135 /* don't bother trying to create palette if not supported */
1136 if (! FRAME_W32_DISPLAY_INFO (f
)->has_palette
)
1139 log_palette
= (LOGPALETTE
*)
1140 alloca (sizeof (LOGPALETTE
) +
1141 FRAME_W32_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
1142 log_palette
->palVersion
= 0x300;
1143 log_palette
->palNumEntries
= FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1145 list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1147 i
< FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1148 i
++, list
= list
->next
)
1149 log_palette
->palPalEntry
[i
] = list
->entry
;
1151 new_palette
= CreatePalette (log_palette
);
1155 if (FRAME_W32_DISPLAY_INFO (f
)->palette
)
1156 DeleteObject (FRAME_W32_DISPLAY_INFO (f
)->palette
);
1157 FRAME_W32_DISPLAY_INFO (f
)->palette
= new_palette
;
1159 /* Realize display palette and garbage all frames. */
1160 release_frame_dc (f
, get_frame_dc (f
));
1165 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
1166 #define SET_W32_COLOR(pe, color) \
1169 pe.peRed = GetRValue (color); \
1170 pe.peGreen = GetGValue (color); \
1171 pe.peBlue = GetBValue (color); \
1176 /* Keep these around in case we ever want to track color usage. */
1178 w32_map_color (FRAME_PTR f
, COLORREF color
)
1180 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1182 if (NILP (Vw32_enable_palette
))
1185 /* check if color is already mapped */
1188 if (W32_COLOR (list
->entry
) == color
)
1196 /* not already mapped, so add to list and recreate Windows palette */
1197 list
= (struct w32_palette_entry
*)
1198 xmalloc (sizeof (struct w32_palette_entry
));
1199 SET_W32_COLOR (list
->entry
, color
);
1201 list
->next
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1202 FRAME_W32_DISPLAY_INFO (f
)->color_list
= list
;
1203 FRAME_W32_DISPLAY_INFO (f
)->num_colors
++;
1205 /* set flag that palette must be regenerated */
1206 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1210 w32_unmap_color (FRAME_PTR f
, COLORREF color
)
1212 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1213 struct w32_palette_entry
**prev
= &FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1215 if (NILP (Vw32_enable_palette
))
1218 /* check if color is already mapped */
1221 if (W32_COLOR (list
->entry
) == color
)
1223 if (--list
->refcount
== 0)
1227 FRAME_W32_DISPLAY_INFO (f
)->num_colors
--;
1237 /* set flag that palette must be regenerated */
1238 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1243 /* Gamma-correct COLOR on frame F. */
1246 gamma_correct (f
, color
)
1252 *color
= PALETTERGB (
1253 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1254 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1255 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1260 /* Decide if color named COLOR is valid for the display associated with
1261 the selected frame; if so, return the rgb values in COLOR_DEF.
1262 If ALLOC is nonzero, allocate a new colormap cell. */
1265 w32_defined_color (f
, color
, color_def
, alloc
)
1271 register Lisp_Object tem
;
1272 COLORREF w32_color_ref
;
1274 tem
= x_to_w32_color (color
);
1280 /* Apply gamma correction. */
1281 w32_color_ref
= XUINT (tem
);
1282 gamma_correct (f
, &w32_color_ref
);
1283 XSETINT (tem
, w32_color_ref
);
1286 /* Map this color to the palette if it is enabled. */
1287 if (!NILP (Vw32_enable_palette
))
1289 struct w32_palette_entry
* entry
=
1290 one_w32_display_info
.color_list
;
1291 struct w32_palette_entry
** prev
=
1292 &one_w32_display_info
.color_list
;
1294 /* check if color is already mapped */
1297 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1299 prev
= &entry
->next
;
1300 entry
= entry
->next
;
1303 if (entry
== NULL
&& alloc
)
1305 /* not already mapped, so add to list */
1306 entry
= (struct w32_palette_entry
*)
1307 xmalloc (sizeof (struct w32_palette_entry
));
1308 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1311 one_w32_display_info
.num_colors
++;
1313 /* set flag that palette must be regenerated */
1314 one_w32_display_info
.regen_palette
= TRUE
;
1317 /* Ensure COLORREF value is snapped to nearest color in (default)
1318 palette by simulating the PALETTERGB macro. This works whether
1319 or not the display device has a palette. */
1320 w32_color_ref
= XUINT (tem
) | 0x2000000;
1322 color_def
->pixel
= w32_color_ref
;
1323 color_def
->red
= GetRValue (w32_color_ref
) * 256;
1324 color_def
->green
= GetGValue (w32_color_ref
) * 256;
1325 color_def
->blue
= GetBValue (w32_color_ref
) * 256;
1335 /* Given a string ARG naming a color, compute a pixel value from it
1336 suitable for screen F.
1337 If F is not a color screen, return DEF (default) regardless of what
1341 x_decode_color (f
, arg
, def
)
1350 if (strcmp (SDATA (arg
), "black") == 0)
1351 return BLACK_PIX_DEFAULT (f
);
1352 else if (strcmp (SDATA (arg
), "white") == 0)
1353 return WHITE_PIX_DEFAULT (f
);
1355 if ((FRAME_W32_DISPLAY_INFO (f
)->n_planes
* FRAME_W32_DISPLAY_INFO (f
)->n_cbits
) == 1)
1358 /* w32_defined_color is responsible for coping with failures
1359 by looking for a near-miss. */
1360 if (w32_defined_color (f
, SDATA (arg
), &cdef
, 1))
1363 /* defined_color failed; return an ultimate default. */
1369 /* Functions called only from `x_set_frame_param'
1370 to set individual parameters.
1372 If FRAME_W32_WINDOW (f) is 0,
1373 the frame is being created and its window does not exist yet.
1374 In that case, just record the parameter's new value
1375 in the standard place; do not attempt to change the window. */
1378 x_set_foreground_color (f
, arg
, oldval
)
1380 Lisp_Object arg
, oldval
;
1382 struct w32_output
*x
= f
->output_data
.w32
;
1383 PIX_TYPE fg
, old_fg
;
1385 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1386 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
1387 FRAME_FOREGROUND_PIXEL (f
) = fg
;
1389 if (FRAME_W32_WINDOW (f
) != 0)
1391 if (x
->cursor_pixel
== old_fg
)
1392 x
->cursor_pixel
= fg
;
1394 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
1395 if (FRAME_VISIBLE_P (f
))
1401 x_set_background_color (f
, arg
, oldval
)
1403 Lisp_Object arg
, oldval
;
1405 FRAME_BACKGROUND_PIXEL (f
)
1406 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
1408 if (FRAME_W32_WINDOW (f
) != 0)
1410 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
1411 FRAME_BACKGROUND_PIXEL (f
));
1413 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
1415 if (FRAME_VISIBLE_P (f
))
1421 x_set_mouse_color (f
, arg
, oldval
)
1423 Lisp_Object arg
, oldval
;
1425 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
1429 if (!EQ (Qnil
, arg
))
1430 f
->output_data
.w32
->mouse_pixel
1431 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1432 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
1434 /* Don't let pointers be invisible. */
1435 if (mask_color
== f
->output_data
.w32
->mouse_pixel
1436 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
1437 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
1439 #if 0 /* TODO : cursor changes */
1442 /* It's not okay to crash if the user selects a screwy cursor. */
1443 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
1445 if (!EQ (Qnil
, Vx_pointer_shape
))
1447 CHECK_NUMBER (Vx_pointer_shape
);
1448 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
1451 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1452 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
1454 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
1456 CHECK_NUMBER (Vx_nontext_pointer_shape
);
1457 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1458 XINT (Vx_nontext_pointer_shape
));
1461 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
1462 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1464 if (!EQ (Qnil
, Vx_hourglass_pointer_shape
))
1466 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
1467 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1468 XINT (Vx_hourglass_pointer_shape
));
1471 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
1472 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
1474 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1475 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
1477 CHECK_NUMBER (Vx_mode_pointer_shape
);
1478 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1479 XINT (Vx_mode_pointer_shape
));
1482 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1483 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
1485 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
1487 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
1489 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1490 XINT (Vx_sensitive_text_pointer_shape
));
1493 hand_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
1495 if (!NILP (Vx_window_horizontal_drag_shape
))
1497 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
1498 horizontal_drag_cursor
1499 = XCreateFontCursor (FRAME_X_DISPLAY (f
),
1500 XINT (Vx_window_horizontal_drag_shape
));
1503 horizontal_drag_cursor
1504 = XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_sb_h_double_arrow
);
1506 /* Check and report errors with the above calls. */
1507 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
1508 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
1511 XColor fore_color
, back_color
;
1513 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
1514 back_color
.pixel
= mask_color
;
1515 XQueryColor (FRAME_W32_DISPLAY (f
),
1516 DefaultColormap (FRAME_W32_DISPLAY (f
),
1517 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1519 XQueryColor (FRAME_W32_DISPLAY (f
),
1520 DefaultColormap (FRAME_W32_DISPLAY (f
),
1521 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1523 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
1524 &fore_color
, &back_color
);
1525 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
1526 &fore_color
, &back_color
);
1527 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
1528 &fore_color
, &back_color
);
1529 XRecolorCursor (FRAME_W32_DISPLAY (f
), hand_cursor
,
1530 &fore_color
, &back_color
);
1531 XRecolorCursor (FRAME_W32_DISPLAY (f
), hourglass_cursor
,
1532 &fore_color
, &back_color
);
1535 if (FRAME_W32_WINDOW (f
) != 0)
1536 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
1538 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
1539 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
1540 f
->output_data
.w32
->text_cursor
= cursor
;
1542 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
1543 && f
->output_data
.w32
->nontext_cursor
!= 0)
1544 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
1545 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
1547 if (hourglass_cursor
!= f
->output_data
.w32
->hourglass_cursor
1548 && f
->output_data
.w32
->hourglass_cursor
!= 0)
1549 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hourglass_cursor
);
1550 f
->output_data
.w32
->hourglass_cursor
= hourglass_cursor
;
1552 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
1553 && f
->output_data
.w32
->modeline_cursor
!= 0)
1554 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
1555 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
1557 if (hand_cursor
!= f
->output_data
.w32
->hand_cursor
1558 && f
->output_data
.w32
->hand_cursor
!= 0)
1559 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hand_cursor
);
1560 f
->output_data
.w32
->hand_cursor
= hand_cursor
;
1562 XFlush (FRAME_W32_DISPLAY (f
));
1565 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1570 x_set_cursor_color (f
, arg
, oldval
)
1572 Lisp_Object arg
, oldval
;
1574 unsigned long fore_pixel
, pixel
;
1576 if (!NILP (Vx_cursor_fore_pixel
))
1577 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1578 WHITE_PIX_DEFAULT (f
));
1580 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1582 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1584 /* Make sure that the cursor color differs from the background color. */
1585 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
1587 pixel
= f
->output_data
.w32
->mouse_pixel
;
1588 if (pixel
== fore_pixel
)
1589 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1592 f
->output_data
.w32
->cursor_foreground_pixel
= fore_pixel
;
1593 f
->output_data
.w32
->cursor_pixel
= pixel
;
1595 if (FRAME_W32_WINDOW (f
) != 0)
1598 /* Update frame's cursor_gc. */
1599 f
->output_data
.w32
->cursor_gc
->foreground
= fore_pixel
;
1600 f
->output_data
.w32
->cursor_gc
->background
= pixel
;
1604 if (FRAME_VISIBLE_P (f
))
1606 x_update_cursor (f
, 0);
1607 x_update_cursor (f
, 1);
1611 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1614 /* Set the border-color of frame F to pixel value PIX.
1615 Note that this does not fully take effect if done before
1619 x_set_border_pixel (f
, pix
)
1624 f
->output_data
.w32
->border_pixel
= pix
;
1626 if (FRAME_W32_WINDOW (f
) != 0 && f
->border_width
> 0)
1628 if (FRAME_VISIBLE_P (f
))
1633 /* Set the border-color of frame F to value described by ARG.
1634 ARG can be a string naming a color.
1635 The border-color is used for the border that is drawn by the server.
1636 Note that this does not fully take effect if done before
1637 F has a window; it must be redone when the window is created. */
1640 x_set_border_color (f
, arg
, oldval
)
1642 Lisp_Object arg
, oldval
;
1647 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1648 x_set_border_pixel (f
, pix
);
1649 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1654 x_set_cursor_type (f
, arg
, oldval
)
1656 Lisp_Object arg
, oldval
;
1658 set_frame_cursor_types (f
, arg
);
1660 /* Make sure the cursor gets redrawn. */
1661 cursor_type_changed
= 1;
1665 x_set_icon_type (f
, arg
, oldval
)
1667 Lisp_Object arg
, oldval
;
1671 if (NILP (arg
) && NILP (oldval
))
1674 if (STRINGP (arg
) && STRINGP (oldval
)
1675 && EQ (Fstring_equal (oldval
, arg
), Qt
))
1678 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
1683 result
= x_bitmap_icon (f
, arg
);
1687 error ("No icon window available");
1694 x_set_icon_name (f
, arg
, oldval
)
1696 Lisp_Object arg
, oldval
;
1700 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1703 else if (!NILP (arg
) || NILP (oldval
))
1709 if (f
->output_data
.w32
->icon_bitmap
!= 0)
1714 result
= x_text_icon (f
,
1715 (char *) SDATA ((!NILP (f
->icon_name
)
1724 error ("No icon window available");
1727 /* If the window was unmapped (and its icon was mapped),
1728 the new icon is not mapped, so map the window in its stead. */
1729 if (FRAME_VISIBLE_P (f
))
1731 #ifdef USE_X_TOOLKIT
1732 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
1734 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
1737 XFlush (FRAME_W32_DISPLAY (f
));
1744 x_set_menu_bar_lines (f
, value
, oldval
)
1746 Lisp_Object value
, oldval
;
1749 int olines
= FRAME_MENU_BAR_LINES (f
);
1751 /* Right now, menu bars don't work properly in minibuf-only frames;
1752 most of the commands try to apply themselves to the minibuffer
1753 frame itself, and get an error because you can't switch buffers
1754 in or split the minibuffer window. */
1755 if (FRAME_MINIBUF_ONLY_P (f
))
1758 if (INTEGERP (value
))
1759 nlines
= XINT (value
);
1763 FRAME_MENU_BAR_LINES (f
) = 0;
1765 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1768 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1769 free_frame_menubar (f
);
1770 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1772 /* Adjust the frame size so that the client (text) dimensions
1773 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
1775 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
1776 do_pending_window_change (0);
1782 /* Set the number of lines used for the tool bar of frame F to VALUE.
1783 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1784 is the old number of tool bar lines. This function changes the
1785 height of all windows on frame F to match the new tool bar height.
1786 The frame's height doesn't change. */
1789 x_set_tool_bar_lines (f
, value
, oldval
)
1791 Lisp_Object value
, oldval
;
1793 int delta
, nlines
, root_height
;
1794 Lisp_Object root_window
;
1796 /* Treat tool bars like menu bars. */
1797 if (FRAME_MINIBUF_ONLY_P (f
))
1800 /* Use VALUE only if an integer >= 0. */
1801 if (INTEGERP (value
) && XINT (value
) >= 0)
1802 nlines
= XFASTINT (value
);
1806 /* Make sure we redisplay all windows in this frame. */
1807 ++windows_or_buffers_changed
;
1809 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
1811 /* Don't resize the tool-bar to more than we have room for. */
1812 root_window
= FRAME_ROOT_WINDOW (f
);
1813 root_height
= WINDOW_TOTAL_LINES (XWINDOW (root_window
));
1814 if (root_height
- delta
< 1)
1816 delta
= root_height
- 1;
1817 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
1820 FRAME_TOOL_BAR_LINES (f
) = nlines
;
1821 change_window_heights (root_window
, delta
);
1824 /* We also have to make sure that the internal border at the top of
1825 the frame, below the menu bar or tool bar, is redrawn when the
1826 tool bar disappears. This is so because the internal border is
1827 below the tool bar if one is displayed, but is below the menu bar
1828 if there isn't a tool bar. The tool bar draws into the area
1829 below the menu bar. */
1830 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
1833 clear_current_matrices (f
);
1836 /* If the tool bar gets smaller, the internal border below it
1837 has to be cleared. It was formerly part of the display
1838 of the larger tool bar, and updating windows won't clear it. */
1841 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1842 int width
= FRAME_PIXEL_WIDTH (f
);
1843 int y
= nlines
* FRAME_LINE_HEIGHT (f
);
1847 HDC hdc
= get_frame_dc (f
);
1848 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
1849 release_frame_dc (f
, hdc
);
1853 if (WINDOWP (f
->tool_bar_window
))
1854 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1859 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1862 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1863 name; if NAME is a string, set F's name to NAME and set
1864 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1866 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1867 suggesting a new name, which lisp code should override; if
1868 F->explicit_name is set, ignore the new name; otherwise, set it. */
1871 x_set_name (f
, name
, explicit)
1876 /* Make sure that requests from lisp code override requests from
1877 Emacs redisplay code. */
1880 /* If we're switching from explicit to implicit, we had better
1881 update the mode lines and thereby update the title. */
1882 if (f
->explicit_name
&& NILP (name
))
1883 update_mode_lines
= 1;
1885 f
->explicit_name
= ! NILP (name
);
1887 else if (f
->explicit_name
)
1890 /* If NAME is nil, set the name to the w32_id_name. */
1893 /* Check for no change needed in this very common case
1894 before we do any consing. */
1895 if (!strcmp (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
,
1898 name
= build_string (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
);
1901 CHECK_STRING (name
);
1903 /* Don't change the name if it's already NAME. */
1904 if (! NILP (Fstring_equal (name
, f
->name
)))
1909 /* For setting the frame title, the title parameter should override
1910 the name parameter. */
1911 if (! NILP (f
->title
))
1914 if (FRAME_W32_WINDOW (f
))
1916 if (STRING_MULTIBYTE (name
))
1917 name
= ENCODE_SYSTEM (name
);
1920 SetWindowText (FRAME_W32_WINDOW (f
), SDATA (name
));
1925 /* This function should be called when the user's lisp code has
1926 specified a name for the frame; the name will override any set by the
1929 x_explicitly_set_name (f
, arg
, oldval
)
1931 Lisp_Object arg
, oldval
;
1933 x_set_name (f
, arg
, 1);
1936 /* This function should be called by Emacs redisplay code to set the
1937 name; names set this way will never override names set by the user's
1940 x_implicitly_set_name (f
, arg
, oldval
)
1942 Lisp_Object arg
, oldval
;
1944 x_set_name (f
, arg
, 0);
1947 /* Change the title of frame F to NAME.
1948 If NAME is nil, use the frame name as the title. */
1951 x_set_title (f
, name
, old_name
)
1953 Lisp_Object name
, old_name
;
1955 /* Don't change the title if it's already NAME. */
1956 if (EQ (name
, f
->title
))
1959 update_mode_lines
= 1;
1966 if (FRAME_W32_WINDOW (f
))
1968 if (STRING_MULTIBYTE (name
))
1969 name
= ENCODE_SYSTEM (name
);
1972 SetWindowText (FRAME_W32_WINDOW (f
), SDATA (name
));
1978 void x_set_scroll_bar_default_width (f
)
1981 int wid
= FRAME_COLUMN_WIDTH (f
);
1983 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
1984 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) +
1989 /* Subroutines of creating a frame. */
1992 /* Return the value of parameter PARAM.
1994 First search ALIST, then Vdefault_frame_alist, then the X defaults
1995 database, using ATTRIBUTE as the attribute name and CLASS as its class.
1997 Convert the resource to the type specified by desired_type.
1999 If no default is specified, return Qunbound. If you call
2000 w32_get_arg, make sure you deal with Qunbound in a reasonable way,
2001 and don't let it get stored in any Lisp-visible variables! */
2004 w32_get_arg (alist
, param
, attribute
, class, type
)
2005 Lisp_Object alist
, param
;
2008 enum resource_types type
;
2010 return x_get_arg (check_x_display_info (Qnil
),
2011 alist
, param
, attribute
, class, type
);
2016 w32_load_cursor (LPCTSTR name
)
2018 /* Try first to load cursor from application resource. */
2019 Cursor cursor
= LoadImage ((HINSTANCE
) GetModuleHandle (NULL
),
2020 name
, IMAGE_CURSOR
, 0, 0,
2021 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
2024 /* Then try to load a shared predefined cursor. */
2025 cursor
= LoadImage (NULL
, name
, IMAGE_CURSOR
, 0, 0,
2026 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
2031 extern LRESULT CALLBACK
w32_wnd_proc ();
2034 w32_init_class (hinst
)
2039 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
2040 wc
.lpfnWndProc
= (WNDPROC
) w32_wnd_proc
;
2042 wc
.cbWndExtra
= WND_EXTRA_BYTES
;
2043 wc
.hInstance
= hinst
;
2044 wc
.hIcon
= LoadIcon (hinst
, EMACS_CLASS
);
2045 wc
.hCursor
= w32_load_cursor (IDC_ARROW
);
2046 wc
.hbrBackground
= NULL
; /* GetStockObject (WHITE_BRUSH); */
2047 wc
.lpszMenuName
= NULL
;
2048 wc
.lpszClassName
= EMACS_CLASS
;
2050 return (RegisterClass (&wc
));
2054 w32_createscrollbar (f
, bar
)
2056 struct scroll_bar
* bar
;
2058 return (CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
2059 /* Position and size of scroll bar. */
2060 XINT (bar
->left
) + VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
2062 XINT (bar
->width
) - VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
2064 FRAME_W32_WINDOW (f
),
2071 w32_createwindow (f
)
2076 Lisp_Object top
= Qunbound
;
2077 Lisp_Object left
= Qunbound
;
2079 rect
.left
= rect
.top
= 0;
2080 rect
.right
= FRAME_PIXEL_WIDTH (f
);
2081 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
2083 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
2084 FRAME_EXTERNAL_MENU_BAR (f
));
2086 /* Do first time app init */
2090 w32_init_class (hinst
);
2093 if (f
->size_hint_flags
& USPosition
|| f
->size_hint_flags
& PPosition
)
2095 XSETINT (left
, f
->left_pos
);
2096 XSETINT (top
, f
->top_pos
);
2098 else if (EQ (left
, Qunbound
) && EQ (top
, Qunbound
))
2100 /* When called with RES_TYPE_NUMBER, w32_get_arg will return zero
2101 for anything that is not a number and is not Qunbound. */
2102 left
= w32_get_arg (Qnil
, Qleft
, "left", "Left", RES_TYPE_NUMBER
);
2103 top
= w32_get_arg (Qnil
, Qtop
, "top", "Top", RES_TYPE_NUMBER
);
2106 FRAME_W32_WINDOW (f
) = hwnd
2107 = CreateWindow (EMACS_CLASS
,
2109 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
2110 EQ (left
, Qunbound
) ? CW_USEDEFAULT
: XINT (left
),
2111 EQ (top
, Qunbound
) ? CW_USEDEFAULT
: XINT (top
),
2112 rect
.right
- rect
.left
,
2113 rect
.bottom
- rect
.top
,
2121 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
2122 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
2123 SetWindowLong (hwnd
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
2124 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->scroll_bar_actual_width
);
2125 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
2127 /* Enable drag-n-drop. */
2128 DragAcceptFiles (hwnd
, TRUE
);
2130 /* Do this to discard the default setting specified by our parent. */
2131 ShowWindow (hwnd
, SW_HIDE
);
2133 /* Update frame positions. */
2134 GetWindowRect (hwnd
, &rect
);
2135 f
->left_pos
= rect
.left
;
2136 f
->top_pos
= rect
.top
;
2141 my_post_msg (wmsg
, hwnd
, msg
, wParam
, lParam
)
2148 wmsg
->msg
.hwnd
= hwnd
;
2149 wmsg
->msg
.message
= msg
;
2150 wmsg
->msg
.wParam
= wParam
;
2151 wmsg
->msg
.lParam
= lParam
;
2152 wmsg
->msg
.time
= GetMessageTime ();
2157 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
2158 between left and right keys as advertised. We test for this
2159 support dynamically, and set a flag when the support is absent. If
2160 absent, we keep track of the left and right control and alt keys
2161 ourselves. This is particularly necessary on keyboards that rely
2162 upon the AltGr key, which is represented as having the left control
2163 and right alt keys pressed. For these keyboards, we need to know
2164 when the left alt key has been pressed in addition to the AltGr key
2165 so that we can properly support M-AltGr-key sequences (such as M-@
2166 on Swedish keyboards). */
2168 #define EMACS_LCONTROL 0
2169 #define EMACS_RCONTROL 1
2170 #define EMACS_LMENU 2
2171 #define EMACS_RMENU 3
2173 static int modifiers
[4];
2174 static int modifiers_recorded
;
2175 static int modifier_key_support_tested
;
2178 test_modifier_support (unsigned int wparam
)
2182 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
2184 if (wparam
== VK_CONTROL
)
2194 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
2195 modifiers_recorded
= 1;
2197 modifiers_recorded
= 0;
2198 modifier_key_support_tested
= 1;
2202 record_keydown (unsigned int wparam
, unsigned int lparam
)
2206 if (!modifier_key_support_tested
)
2207 test_modifier_support (wparam
);
2209 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2212 if (wparam
== VK_CONTROL
)
2213 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2215 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2221 record_keyup (unsigned int wparam
, unsigned int lparam
)
2225 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2228 if (wparam
== VK_CONTROL
)
2229 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2231 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2236 /* Emacs can lose focus while a modifier key has been pressed. When
2237 it regains focus, be conservative and clear all modifiers since
2238 we cannot reconstruct the left and right modifier state. */
2244 if (GetFocus () == NULL
)
2245 /* Emacs doesn't have keyboard focus. Do nothing. */
2248 ctrl
= GetAsyncKeyState (VK_CONTROL
);
2249 alt
= GetAsyncKeyState (VK_MENU
);
2251 if (!(ctrl
& 0x08000))
2252 /* Clear any recorded control modifier state. */
2253 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2255 if (!(alt
& 0x08000))
2256 /* Clear any recorded alt modifier state. */
2257 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2259 /* Update the state of all modifier keys, because modifiers used in
2260 hot-key combinations can get stuck on if Emacs loses focus as a
2261 result of a hot-key being pressed. */
2265 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
2267 GetKeyboardState (keystate
);
2268 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
2269 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
2270 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
2271 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
2272 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
2273 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
2274 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
2275 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
2276 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
2277 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
2278 SetKeyboardState (keystate
);
2282 /* Synchronize modifier state with what is reported with the current
2283 keystroke. Even if we cannot distinguish between left and right
2284 modifier keys, we know that, if no modifiers are set, then neither
2285 the left or right modifier should be set. */
2289 if (!modifiers_recorded
)
2292 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
2293 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2295 if (!(GetKeyState (VK_MENU
) & 0x8000))
2296 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2300 modifier_set (int vkey
)
2302 if (vkey
== VK_CAPITAL
|| vkey
== VK_SCROLL
)
2303 return (GetKeyState (vkey
) & 0x1);
2304 if (!modifiers_recorded
)
2305 return (GetKeyState (vkey
) & 0x8000);
2310 return modifiers
[EMACS_LCONTROL
];
2312 return modifiers
[EMACS_RCONTROL
];
2314 return modifiers
[EMACS_LMENU
];
2316 return modifiers
[EMACS_RMENU
];
2318 return (GetKeyState (vkey
) & 0x8000);
2321 /* Convert between the modifier bits W32 uses and the modifier bits
2325 w32_key_to_modifier (int key
)
2327 Lisp_Object key_mapping
;
2332 key_mapping
= Vw32_lwindow_modifier
;
2335 key_mapping
= Vw32_rwindow_modifier
;
2338 key_mapping
= Vw32_apps_modifier
;
2341 key_mapping
= Vw32_scroll_lock_modifier
;
2347 /* NB. This code runs in the input thread, asychronously to the lisp
2348 thread, so we must be careful to ensure access to lisp data is
2349 thread-safe. The following code is safe because the modifier
2350 variable values are updated atomically from lisp and symbols are
2351 not relocated by GC. Also, we don't have to worry about seeing GC
2353 if (EQ (key_mapping
, Qhyper
))
2354 return hyper_modifier
;
2355 if (EQ (key_mapping
, Qsuper
))
2356 return super_modifier
;
2357 if (EQ (key_mapping
, Qmeta
))
2358 return meta_modifier
;
2359 if (EQ (key_mapping
, Qalt
))
2360 return alt_modifier
;
2361 if (EQ (key_mapping
, Qctrl
))
2362 return ctrl_modifier
;
2363 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
2364 return ctrl_modifier
;
2365 if (EQ (key_mapping
, Qshift
))
2366 return shift_modifier
;
2368 /* Don't generate any modifier if not explicitly requested. */
2373 w32_get_modifiers ()
2375 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
2376 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
2377 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
2378 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
2379 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
2380 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
2381 (modifier_set (VK_MENU
) ?
2382 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
2385 /* We map the VK_* modifiers into console modifier constants
2386 so that we can use the same routines to handle both console
2387 and window input. */
2390 construct_console_modifiers ()
2395 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
2396 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
2397 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
2398 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
2399 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
2400 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
2401 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
2402 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
2403 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
2404 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
2405 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
2411 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
2415 /* Convert to emacs modifiers. */
2416 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
2422 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
2424 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
2427 if (virt_key
== VK_RETURN
)
2428 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
2430 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
2431 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
2433 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
2434 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
2436 if (virt_key
== VK_CLEAR
)
2437 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
2442 /* List of special key combinations which w32 would normally capture,
2443 but Emacs should grab instead. Not directly visible to lisp, to
2444 simplify synchronization. Each item is an integer encoding a virtual
2445 key code and modifier combination to capture. */
2446 static Lisp_Object w32_grabbed_keys
;
2448 #define HOTKEY(vk, mods) make_number (((vk) & 255) | ((mods) << 8))
2449 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
2450 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
2451 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
2453 #define RAW_HOTKEY_ID(k) ((k) & 0xbfff)
2454 #define RAW_HOTKEY_VK_CODE(k) ((k) & 255)
2455 #define RAW_HOTKEY_MODIFIERS(k) ((k) >> 8)
2457 /* Register hot-keys for reserved key combinations when Emacs has
2458 keyboard focus, since this is the only way Emacs can receive key
2459 combinations like Alt-Tab which are used by the system. */
2462 register_hot_keys (hwnd
)
2465 Lisp_Object keylist
;
2467 /* Use CONSP, since we are called asynchronously. */
2468 for (keylist
= w32_grabbed_keys
; CONSP (keylist
); keylist
= XCDR (keylist
))
2470 Lisp_Object key
= XCAR (keylist
);
2472 /* Deleted entries get set to nil. */
2473 if (!INTEGERP (key
))
2476 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
2477 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
2482 unregister_hot_keys (hwnd
)
2485 Lisp_Object keylist
;
2487 for (keylist
= w32_grabbed_keys
; CONSP (keylist
); keylist
= XCDR (keylist
))
2489 Lisp_Object key
= XCAR (keylist
);
2491 if (!INTEGERP (key
))
2494 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
2498 /* Main message dispatch loop. */
2501 w32_msg_pump (deferred_msg
* msg_buf
)
2507 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
2509 while (GetMessage (&msg
, NULL
, 0, 0))
2511 if (msg
.hwnd
== NULL
)
2513 switch (msg
.message
)
2516 /* Produced by complete_deferred_msg; just ignore. */
2518 case WM_EMACS_CREATEWINDOW
:
2519 /* Initialize COM for this window. Even though we don't use it,
2520 some third party shell extensions can cause it to be used in
2521 system dialogs, which causes a crash if it is not initialized.
2522 This is a known bug in Windows, which was fixed long ago, but
2523 the patch for XP is not publically available until XP SP3,
2524 and older versions will never be patched. */
2525 CoInitialize (NULL
);
2526 w32_createwindow ((struct frame
*) msg
.wParam
);
2527 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2530 case WM_EMACS_SETLOCALE
:
2531 SetThreadLocale (msg
.wParam
);
2532 /* Reply is not expected. */
2534 case WM_EMACS_SETKEYBOARDLAYOUT
:
2535 result
= (int) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
2536 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2540 case WM_EMACS_REGISTER_HOT_KEY
:
2541 focus_window
= GetFocus ();
2542 if (focus_window
!= NULL
)
2543 RegisterHotKey (focus_window
,
2544 RAW_HOTKEY_ID (msg
.wParam
),
2545 RAW_HOTKEY_MODIFIERS (msg
.wParam
),
2546 RAW_HOTKEY_VK_CODE (msg
.wParam
));
2547 /* Reply is not expected. */
2549 case WM_EMACS_UNREGISTER_HOT_KEY
:
2550 focus_window
= GetFocus ();
2551 if (focus_window
!= NULL
)
2552 UnregisterHotKey (focus_window
, RAW_HOTKEY_ID (msg
.wParam
));
2553 /* Mark item as erased. NB: this code must be
2554 thread-safe. The next line is okay because the cons
2555 cell is never made into garbage and is not relocated by
2557 XSETCAR ((Lisp_Object
) ((EMACS_INT
) msg
.lParam
), Qnil
);
2558 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2561 case WM_EMACS_TOGGLE_LOCK_KEY
:
2563 int vk_code
= (int) msg
.wParam
;
2564 int cur_state
= (GetKeyState (vk_code
) & 1);
2565 Lisp_Object new_state
= (Lisp_Object
) ((EMACS_INT
) msg
.lParam
);
2567 /* NB: This code must be thread-safe. It is safe to
2568 call NILP because symbols are not relocated by GC,
2569 and pointer here is not touched by GC (so the markbit
2570 can't be set). Numbers are safe because they are
2571 immediate values. */
2572 if (NILP (new_state
)
2573 || (NUMBERP (new_state
)
2574 && ((XUINT (new_state
)) & 1) != cur_state
))
2576 one_w32_display_info
.faked_key
= vk_code
;
2578 keybd_event ((BYTE
) vk_code
,
2579 (BYTE
) MapVirtualKey (vk_code
, 0),
2580 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2581 keybd_event ((BYTE
) vk_code
,
2582 (BYTE
) MapVirtualKey (vk_code
, 0),
2583 KEYEVENTF_EXTENDEDKEY
| 0, 0);
2584 keybd_event ((BYTE
) vk_code
,
2585 (BYTE
) MapVirtualKey (vk_code
, 0),
2586 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2587 cur_state
= !cur_state
;
2589 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2595 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
2600 DispatchMessage (&msg
);
2603 /* Exit nested loop when our deferred message has completed. */
2604 if (msg_buf
->completed
)
2609 deferred_msg
* deferred_msg_head
;
2611 static deferred_msg
*
2612 find_deferred_msg (HWND hwnd
, UINT msg
)
2614 deferred_msg
* item
;
2616 /* Don't actually need synchronization for read access, since
2617 modification of single pointer is always atomic. */
2618 /* enter_crit (); */
2620 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2621 if (item
->w32msg
.msg
.hwnd
== hwnd
2622 && item
->w32msg
.msg
.message
== msg
)
2625 /* leave_crit (); */
2631 send_deferred_msg (deferred_msg
* msg_buf
,
2637 /* Only input thread can send deferred messages. */
2638 if (GetCurrentThreadId () != dwWindowsThreadId
)
2641 /* It is an error to send a message that is already deferred. */
2642 if (find_deferred_msg (hwnd
, msg
) != NULL
)
2645 /* Enforced synchronization is not needed because this is the only
2646 function that alters deferred_msg_head, and the following critical
2647 section is guaranteed to only be serially reentered (since only the
2648 input thread can call us). */
2650 /* enter_crit (); */
2652 msg_buf
->completed
= 0;
2653 msg_buf
->next
= deferred_msg_head
;
2654 deferred_msg_head
= msg_buf
;
2655 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
2657 /* leave_crit (); */
2659 /* Start a new nested message loop to process other messages until
2660 this one is completed. */
2661 w32_msg_pump (msg_buf
);
2663 deferred_msg_head
= msg_buf
->next
;
2665 return msg_buf
->result
;
2669 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
2671 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
2673 if (msg_buf
== NULL
)
2674 /* Message may have been cancelled, so don't abort. */
2677 msg_buf
->result
= result
;
2678 msg_buf
->completed
= 1;
2680 /* Ensure input thread is woken so it notices the completion. */
2681 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2685 cancel_all_deferred_msgs ()
2687 deferred_msg
* item
;
2689 /* Don't actually need synchronization for read access, since
2690 modification of single pointer is always atomic. */
2691 /* enter_crit (); */
2693 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2696 item
->completed
= 1;
2699 /* leave_crit (); */
2701 /* Ensure input thread is woken so it notices the completion. */
2702 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2706 w32_msg_worker (void *arg
)
2709 deferred_msg dummy_buf
;
2711 /* Ensure our message queue is created */
2713 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
2715 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2718 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
2719 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
2720 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
2722 /* This is the inital message loop which should only exit when the
2723 application quits. */
2724 w32_msg_pump (&dummy_buf
);
2730 signal_user_input ()
2732 /* Interrupt any lisp that wants to be interrupted by input. */
2733 if (!NILP (Vthrow_on_input
))
2735 Vquit_flag
= Vthrow_on_input
;
2736 /* If we're inside a function that wants immediate quits,
2738 if (immediate_quit
&& NILP (Vinhibit_quit
))
2748 post_character_message (hwnd
, msg
, wParam
, lParam
, modifiers
)
2758 wmsg
.dwModifiers
= modifiers
;
2760 /* Detect quit_char and set quit-flag directly. Note that we
2761 still need to post a message to ensure the main thread will be
2762 woken up if blocked in sys_select, but we do NOT want to post
2763 the quit_char message itself (because it will usually be as if
2764 the user had typed quit_char twice). Instead, we post a dummy
2765 message that has no particular effect. */
2768 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
2769 c
= make_ctrl_char (c
) & 0377;
2771 || (wmsg
.dwModifiers
== 0 &&
2772 w32_quit_key
&& wParam
== w32_quit_key
))
2776 /* The choice of message is somewhat arbitrary, as long as
2777 the main thread handler just ignores it. */
2780 /* Interrupt any blocking system calls. */
2783 /* As a safety precaution, forcibly complete any deferred
2784 messages. This is a kludge, but I don't see any particularly
2785 clean way to handle the situation where a deferred message is
2786 "dropped" in the lisp thread, and will thus never be
2787 completed, eg. by the user trying to activate the menubar
2788 when the lisp thread is busy, and then typing C-g when the
2789 menubar doesn't open promptly (with the result that the
2790 menubar never responds at all because the deferred
2791 WM_INITMENU message is never completed). Another problem
2792 situation is when the lisp thread calls SendMessage (to send
2793 a window manager command) when a message has been deferred;
2794 the lisp thread gets blocked indefinitely waiting for the
2795 deferred message to be completed, which itself is waiting for
2796 the lisp thread to respond.
2798 Note that we don't want to block the input thread waiting for
2799 a reponse from the lisp thread (although that would at least
2800 solve the deadlock problem above), because we want to be able
2801 to receive C-g to interrupt the lisp thread. */
2802 cancel_all_deferred_msgs ();
2805 signal_user_input ();
2808 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2811 /* Main window procedure */
2814 w32_wnd_proc (hwnd
, msg
, wParam
, lParam
)
2821 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
2823 int windows_translate
;
2826 /* Note that it is okay to call x_window_to_frame, even though we are
2827 not running in the main lisp thread, because frame deletion
2828 requires the lisp thread to synchronize with this thread. Thus, if
2829 a frame struct is returned, it can be used without concern that the
2830 lisp thread might make it disappear while we are using it.
2832 NB. Walking the frame list in this thread is safe (as long as
2833 writes of Lisp_Object slots are atomic, which they are on Windows).
2834 Although delete-frame can destructively modify the frame list while
2835 we are walking it, a garbage collection cannot occur until after
2836 delete-frame has synchronized with this thread.
2838 It is also safe to use functions that make GDI calls, such as
2839 w32_clear_rect, because these functions must obtain a DC handle
2840 from the frame struct using get_frame_dc which is thread-aware. */
2845 f
= x_window_to_frame (dpyinfo
, hwnd
);
2848 HDC hdc
= get_frame_dc (f
);
2849 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
2850 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
2851 release_frame_dc (f
, hdc
);
2853 #if defined (W32_DEBUG_DISPLAY)
2854 DebPrint (("WM_ERASEBKGND (frame %p): erasing %d,%d-%d,%d\n",
2856 wmsg
.rect
.left
, wmsg
.rect
.top
,
2857 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2858 #endif /* W32_DEBUG_DISPLAY */
2861 case WM_PALETTECHANGED
:
2862 /* ignore our own changes */
2863 if ((HWND
)wParam
!= hwnd
)
2865 f
= x_window_to_frame (dpyinfo
, hwnd
);
2867 /* get_frame_dc will realize our palette and force all
2868 frames to be redrawn if needed. */
2869 release_frame_dc (f
, get_frame_dc (f
));
2874 PAINTSTRUCT paintStruct
;
2876 bzero (&update_rect
, sizeof (update_rect
));
2878 f
= x_window_to_frame (dpyinfo
, hwnd
);
2881 DebPrint (("WM_PAINT received for unknown window %p\n", hwnd
));
2885 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
2886 fails. Apparently this can happen under some
2888 if (GetUpdateRect (hwnd
, &update_rect
, FALSE
) || !w32_strict_painting
)
2891 BeginPaint (hwnd
, &paintStruct
);
2893 /* The rectangles returned by GetUpdateRect and BeginPaint
2894 do not always match. Play it safe by assuming both areas
2896 UnionRect (&(wmsg
.rect
), &update_rect
, &(paintStruct
.rcPaint
));
2898 #if defined (W32_DEBUG_DISPLAY)
2899 DebPrint (("WM_PAINT (frame %p): painting %d,%d-%d,%d\n",
2901 wmsg
.rect
.left
, wmsg
.rect
.top
,
2902 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2903 DebPrint ((" [update region is %d,%d-%d,%d]\n",
2904 update_rect
.left
, update_rect
.top
,
2905 update_rect
.right
, update_rect
.bottom
));
2907 EndPaint (hwnd
, &paintStruct
);
2910 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2915 /* If GetUpdateRect returns 0 (meaning there is no update
2916 region), assume the whole window needs to be repainted. */
2917 GetClientRect (hwnd
, &wmsg
.rect
);
2918 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2922 case WM_INPUTLANGCHANGE
:
2923 /* Inform lisp thread of keyboard layout changes. */
2924 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2926 /* Clear dead keys in the keyboard state; for simplicity only
2927 preserve modifier key states. */
2932 GetKeyboardState (keystate
);
2933 for (i
= 0; i
< 256; i
++)
2950 SetKeyboardState (keystate
);
2955 /* Synchronize hot keys with normal input. */
2956 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
2961 record_keyup (wParam
, lParam
);
2966 /* Ignore keystrokes we fake ourself; see below. */
2967 if (dpyinfo
->faked_key
== wParam
)
2969 dpyinfo
->faked_key
= 0;
2970 /* Make sure TranslateMessage sees them though (as long as
2971 they don't produce WM_CHAR messages). This ensures that
2972 indicator lights are toggled promptly on Windows 9x, for
2974 if (wParam
< 256 && lispy_function_keys
[wParam
])
2976 windows_translate
= 1;
2982 /* Synchronize modifiers with current keystroke. */
2984 record_keydown (wParam
, lParam
);
2985 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
2987 windows_translate
= 0;
2992 if (NILP (Vw32_pass_lwindow_to_system
))
2994 /* Prevent system from acting on keyup (which opens the
2995 Start menu if no other key was pressed) by simulating a
2996 press of Space which we will ignore. */
2997 if (GetAsyncKeyState (wParam
) & 1)
2999 if (NUMBERP (Vw32_phantom_key_code
))
3000 key
= XUINT (Vw32_phantom_key_code
) & 255;
3003 dpyinfo
->faked_key
= key
;
3004 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
3007 if (!NILP (Vw32_lwindow_modifier
))
3011 if (NILP (Vw32_pass_rwindow_to_system
))
3013 if (GetAsyncKeyState (wParam
) & 1)
3015 if (NUMBERP (Vw32_phantom_key_code
))
3016 key
= XUINT (Vw32_phantom_key_code
) & 255;
3019 dpyinfo
->faked_key
= key
;
3020 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
3023 if (!NILP (Vw32_rwindow_modifier
))
3027 if (!NILP (Vw32_apps_modifier
))
3031 if (NILP (Vw32_pass_alt_to_system
))
3032 /* Prevent DefWindowProc from activating the menu bar if an
3033 Alt key is pressed and released by itself. */
3035 windows_translate
= 1;
3038 /* Decide whether to treat as modifier or function key. */
3039 if (NILP (Vw32_enable_caps_lock
))
3040 goto disable_lock_key
;
3041 windows_translate
= 1;
3044 /* Decide whether to treat as modifier or function key. */
3045 if (NILP (Vw32_enable_num_lock
))
3046 goto disable_lock_key
;
3047 windows_translate
= 1;
3050 /* Decide whether to treat as modifier or function key. */
3051 if (NILP (Vw32_scroll_lock_modifier
))
3052 goto disable_lock_key
;
3053 windows_translate
= 1;
3056 /* Ensure the appropriate lock key state (and indicator light)
3057 remains in the same state. We do this by faking another
3058 press of the relevant key. Apparently, this really is the
3059 only way to toggle the state of the indicator lights. */
3060 dpyinfo
->faked_key
= wParam
;
3061 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3062 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3063 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3064 KEYEVENTF_EXTENDEDKEY
| 0, 0);
3065 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3066 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3067 /* Ensure indicator lights are updated promptly on Windows 9x
3068 (TranslateMessage apparently does this), after forwarding
3070 post_character_message (hwnd
, msg
, wParam
, lParam
,
3071 w32_get_key_modifiers (wParam
, lParam
));
3072 windows_translate
= 1;
3076 case VK_PROCESSKEY
: /* Generated by IME. */
3077 windows_translate
= 1;
3080 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
3081 which is confusing for purposes of key binding; convert
3082 VK_CANCEL events into VK_PAUSE events. */
3086 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
3087 for purposes of key binding; convert these back into
3088 VK_NUMLOCK events, at least when we want to see NumLock key
3089 presses. (Note that there is never any possibility that
3090 VK_PAUSE with Ctrl really is C-Pause as per above.) */
3091 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
3092 wParam
= VK_NUMLOCK
;
3095 /* If not defined as a function key, change it to a WM_CHAR message. */
3096 if (wParam
> 255 || !lispy_function_keys
[wParam
])
3098 DWORD modifiers
= construct_console_modifiers ();
3100 if (!NILP (Vw32_recognize_altgr
)
3101 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
3103 /* Always let TranslateMessage handle AltGr key chords;
3104 for some reason, ToAscii doesn't always process AltGr
3105 chords correctly. */
3106 windows_translate
= 1;
3108 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
3110 /* Handle key chords including any modifiers other
3111 than shift directly, in order to preserve as much
3112 modifier information as possible. */
3113 if ('A' <= wParam
&& wParam
<= 'Z')
3115 /* Don't translate modified alphabetic keystrokes,
3116 so the user doesn't need to constantly switch
3117 layout to type control or meta keystrokes when
3118 the normal layout translates alphabetic
3119 characters to non-ascii characters. */
3120 if (!modifier_set (VK_SHIFT
))
3121 wParam
+= ('a' - 'A');
3126 /* Try to handle other keystrokes by determining the
3127 base character (ie. translating the base key plus
3131 KEY_EVENT_RECORD key
;
3133 key
.bKeyDown
= TRUE
;
3134 key
.wRepeatCount
= 1;
3135 key
.wVirtualKeyCode
= wParam
;
3136 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
3137 key
.uChar
.AsciiChar
= 0;
3138 key
.dwControlKeyState
= modifiers
;
3140 add
= w32_kbd_patch_key (&key
);
3141 /* 0 means an unrecognised keycode, negative means
3142 dead key. Ignore both. */
3145 /* Forward asciified character sequence. */
3146 post_character_message
3148 (unsigned char) key
.uChar
.AsciiChar
, lParam
,
3149 w32_get_key_modifiers (wParam
, lParam
));
3150 w32_kbd_patch_key (&key
);
3157 /* Let TranslateMessage handle everything else. */
3158 windows_translate
= 1;
3164 if (windows_translate
)
3166 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
3167 windows_msg
.time
= GetMessageTime ();
3168 TranslateMessage (&windows_msg
);
3176 post_character_message (hwnd
, msg
, wParam
, lParam
,
3177 w32_get_key_modifiers (wParam
, lParam
));
3181 /* WM_UNICHAR looks promising from the docs, but the exact
3182 circumstances in which TranslateMessage sends it is one of those
3183 Microsoft secret API things that EU and US courts are supposed
3184 to have put a stop to already. Spy++ shows it being sent to Notepad
3185 and other MS apps, but never to Emacs.
3187 Some third party IMEs send it in accordance with the official
3188 documentation though, so handle it here.
3190 UNICODE_NOCHAR is used to test for support for this message.
3191 TRUE indicates that the message is supported. */
3192 if (wParam
== UNICODE_NOCHAR
)
3197 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3198 signal_user_input ();
3199 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3204 /* If we can't get the IME result as unicode, use default processing,
3205 which will at least allow characters decodable in the system locale
3207 if (!get_composition_string_fn
)
3210 else if (!ignore_ime_char
)
3215 HIMC context
= get_ime_context_fn (hwnd
);
3216 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3217 /* Get buffer size. */
3218 size
= get_composition_string_fn (context
, GCS_RESULTSTR
, buffer
, 0);
3219 buffer
= alloca(size
);
3220 size
= get_composition_string_fn (context
, GCS_RESULTSTR
,
3222 signal_user_input ();
3223 for (i
= 0; i
< size
/ sizeof (wchar_t); i
++)
3225 my_post_msg (&wmsg
, hwnd
, WM_UNICHAR
, (WPARAM
) buffer
[i
],
3228 /* We output the whole string above, so ignore following ones
3229 until we are notified of the end of composition. */
3230 ignore_ime_char
= 1;
3234 case WM_IME_ENDCOMPOSITION
:
3235 ignore_ime_char
= 0;
3238 /* Simulate middle mouse button events when left and right buttons
3239 are used together, but only if user has two button mouse. */
3240 case WM_LBUTTONDOWN
:
3241 case WM_RBUTTONDOWN
:
3242 if (w32_num_mouse_buttons
> 2)
3243 goto handle_plain_button
;
3246 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
3247 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
3249 if (button_state
& this)
3252 if (button_state
== 0)
3255 button_state
|= this;
3257 if (button_state
& other
)
3259 if (mouse_button_timer
)
3261 KillTimer (hwnd
, mouse_button_timer
);
3262 mouse_button_timer
= 0;
3264 /* Generate middle mouse event instead. */
3265 msg
= WM_MBUTTONDOWN
;
3266 button_state
|= MMOUSE
;
3268 else if (button_state
& MMOUSE
)
3270 /* Ignore button event if we've already generated a
3271 middle mouse down event. This happens if the
3272 user releases and press one of the two buttons
3273 after we've faked a middle mouse event. */
3278 /* Flush out saved message. */
3279 post_msg (&saved_mouse_button_msg
);
3281 wmsg
.dwModifiers
= w32_get_modifiers ();
3282 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3283 signal_user_input ();
3285 /* Clear message buffer. */
3286 saved_mouse_button_msg
.msg
.hwnd
= 0;
3290 /* Hold onto message for now. */
3291 mouse_button_timer
=
3292 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
3293 w32_mouse_button_tolerance
, NULL
);
3294 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
3295 saved_mouse_button_msg
.msg
.message
= msg
;
3296 saved_mouse_button_msg
.msg
.wParam
= wParam
;
3297 saved_mouse_button_msg
.msg
.lParam
= lParam
;
3298 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
3299 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
3306 if (w32_num_mouse_buttons
> 2)
3307 goto handle_plain_button
;
3310 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
3311 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
3313 if ((button_state
& this) == 0)
3316 button_state
&= ~this;
3318 if (button_state
& MMOUSE
)
3320 /* Only generate event when second button is released. */
3321 if ((button_state
& other
) == 0)
3324 button_state
&= ~MMOUSE
;
3326 if (button_state
) abort ();
3333 /* Flush out saved message if necessary. */
3334 if (saved_mouse_button_msg
.msg
.hwnd
)
3336 post_msg (&saved_mouse_button_msg
);
3339 wmsg
.dwModifiers
= w32_get_modifiers ();
3340 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3341 signal_user_input ();
3343 /* Always clear message buffer and cancel timer. */
3344 saved_mouse_button_msg
.msg
.hwnd
= 0;
3345 KillTimer (hwnd
, mouse_button_timer
);
3346 mouse_button_timer
= 0;
3348 if (button_state
== 0)
3353 case WM_XBUTTONDOWN
:
3355 if (w32_pass_extra_mouse_buttons_to_system
)
3357 /* else fall through and process them. */
3358 case WM_MBUTTONDOWN
:
3360 handle_plain_button
:
3365 /* Ignore middle and extra buttons as long as the menu is active. */
3366 f
= x_window_to_frame (dpyinfo
, hwnd
);
3367 if (f
&& f
->output_data
.w32
->menubar_active
)
3370 if (parse_button (msg
, HIWORD (wParam
), &button
, &up
))
3372 if (up
) ReleaseCapture ();
3373 else SetCapture (hwnd
);
3374 button
= (button
== 0) ? LMOUSE
:
3375 ((button
== 1) ? MMOUSE
: RMOUSE
);
3377 button_state
&= ~button
;
3379 button_state
|= button
;
3383 wmsg
.dwModifiers
= w32_get_modifiers ();
3384 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3385 signal_user_input ();
3387 /* Need to return true for XBUTTON messages, false for others,
3388 to indicate that we processed the message. */
3389 return (msg
== WM_XBUTTONDOWN
|| msg
== WM_XBUTTONUP
);
3392 /* Ignore mouse movements as long as the menu is active. These
3393 movements are processed by the window manager anyway, and
3394 it's wrong to handle them as if they happened on the
3395 underlying frame. */
3396 f
= x_window_to_frame (dpyinfo
, hwnd
);
3397 if (f
&& f
->output_data
.w32
->menubar_active
)
3400 /* If the mouse has just moved into the frame, start tracking
3401 it, so we will be notified when it leaves the frame. Mouse
3402 tracking only works under W98 and NT4 and later. On earlier
3403 versions, there is no way of telling when the mouse leaves the
3404 frame, so we just have to put up with help-echo and mouse
3405 highlighting remaining while the frame is not active. */
3406 if (track_mouse_event_fn
&& !track_mouse_window
)
3408 TRACKMOUSEEVENT tme
;
3409 tme
.cbSize
= sizeof (tme
);
3410 tme
.dwFlags
= TME_LEAVE
;
3411 tme
.hwndTrack
= hwnd
;
3413 track_mouse_event_fn (&tme
);
3414 track_mouse_window
= hwnd
;
3417 if (w32_mouse_move_interval
<= 0
3418 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
3420 wmsg
.dwModifiers
= w32_get_modifiers ();
3421 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3425 /* Hang onto mouse move and scroll messages for a bit, to avoid
3426 sending such events to Emacs faster than it can process them.
3427 If we get more events before the timer from the first message
3428 expires, we just replace the first message. */
3430 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
3432 SetTimer (hwnd
, MOUSE_MOVE_ID
,
3433 w32_mouse_move_interval
, NULL
);
3435 /* Hold onto message for now. */
3436 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
3437 saved_mouse_move_msg
.msg
.message
= msg
;
3438 saved_mouse_move_msg
.msg
.wParam
= wParam
;
3439 saved_mouse_move_msg
.msg
.lParam
= lParam
;
3440 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
3441 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
3447 wmsg
.dwModifiers
= w32_get_modifiers ();
3448 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3449 signal_user_input ();
3453 if (w32_pass_multimedia_buttons_to_system
)
3455 /* Otherwise, pass to lisp, the same way we do with mousehwheel. */
3456 case WM_MOUSEHWHEEL
:
3457 wmsg
.dwModifiers
= w32_get_modifiers ();
3458 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3459 signal_user_input ();
3460 /* Non-zero must be returned when WM_MOUSEHWHEEL messages are
3461 handled, to prevent the system trying to handle it by faking
3462 scroll bar events. */
3466 /* Flush out saved messages if necessary. */
3467 if (wParam
== mouse_button_timer
)
3469 if (saved_mouse_button_msg
.msg
.hwnd
)
3471 post_msg (&saved_mouse_button_msg
);
3472 signal_user_input ();
3473 saved_mouse_button_msg
.msg
.hwnd
= 0;
3475 KillTimer (hwnd
, mouse_button_timer
);
3476 mouse_button_timer
= 0;
3478 else if (wParam
== mouse_move_timer
)
3480 if (saved_mouse_move_msg
.msg
.hwnd
)
3482 post_msg (&saved_mouse_move_msg
);
3483 saved_mouse_move_msg
.msg
.hwnd
= 0;
3485 KillTimer (hwnd
, mouse_move_timer
);
3486 mouse_move_timer
= 0;
3488 else if (wParam
== menu_free_timer
)
3490 KillTimer (hwnd
, menu_free_timer
);
3491 menu_free_timer
= 0;
3492 f
= x_window_to_frame (dpyinfo
, hwnd
);
3493 /* If a popup menu is active, don't wipe its strings. */
3495 && current_popup_menu
== NULL
)
3497 /* Free memory used by owner-drawn and help-echo strings. */
3498 w32_free_menu_strings (hwnd
);
3499 f
->output_data
.w32
->menubar_active
= 0;
3506 /* Windows doesn't send us focus messages when putting up and
3507 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
3508 The only indication we get that something happened is receiving
3509 this message afterwards. So this is a good time to reset our
3510 keyboard modifiers' state. */
3517 /* We must ensure menu bar is fully constructed and up to date
3518 before allowing user interaction with it. To achieve this
3519 we send this message to the lisp thread and wait for a
3520 reply (whose value is not actually needed) to indicate that
3521 the menu bar is now ready for use, so we can now return.
3523 To remain responsive in the meantime, we enter a nested message
3524 loop that can process all other messages.
3526 However, we skip all this if the message results from calling
3527 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
3528 thread a message because it is blocked on us at this point. We
3529 set menubar_active before calling TrackPopupMenu to indicate
3530 this (there is no possibility of confusion with real menubar
3533 f
= x_window_to_frame (dpyinfo
, hwnd
);
3535 && (f
->output_data
.w32
->menubar_active
3536 /* We can receive this message even in the absence of a
3537 menubar (ie. when the system menu is activated) - in this
3538 case we do NOT want to forward the message, otherwise it
3539 will cause the menubar to suddenly appear when the user
3540 had requested it to be turned off! */
3541 || f
->output_data
.w32
->menubar_widget
== NULL
))
3545 deferred_msg msg_buf
;
3547 /* Detect if message has already been deferred; in this case
3548 we cannot return any sensible value to ignore this. */
3549 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3554 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
3557 case WM_EXITMENULOOP
:
3558 f
= x_window_to_frame (dpyinfo
, hwnd
);
3560 /* If a menu is still active, check again after a short delay,
3561 since Windows often (always?) sends the WM_EXITMENULOOP
3562 before the corresponding WM_COMMAND message.
3563 Don't do this if a popup menu is active, since it is only
3564 menubar menus that require cleaning up in this way.
3566 if (f
&& menubar_in_use
&& current_popup_menu
== NULL
)
3567 menu_free_timer
= SetTimer (hwnd
, MENU_FREE_ID
, MENU_FREE_DELAY
, NULL
);
3571 /* Direct handling of help_echo in menus. Should be safe now
3572 that we generate the help_echo by placing a help event in the
3575 HMENU menu
= (HMENU
) lParam
;
3576 UINT menu_item
= (UINT
) LOWORD (wParam
);
3577 UINT flags
= (UINT
) HIWORD (wParam
);
3579 w32_menu_display_help (hwnd
, menu
, menu_item
, flags
);
3583 case WM_MEASUREITEM
:
3584 f
= x_window_to_frame (dpyinfo
, hwnd
);
3587 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
3589 if (pMis
->CtlType
== ODT_MENU
)
3591 /* Work out dimensions for popup menu titles. */
3592 char * title
= (char *) pMis
->itemData
;
3593 HDC hdc
= GetDC (hwnd
);
3594 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3595 LOGFONT menu_logfont
;
3599 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3600 menu_logfont
.lfWeight
= FW_BOLD
;
3601 menu_font
= CreateFontIndirect (&menu_logfont
);
3602 old_font
= SelectObject (hdc
, menu_font
);
3604 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
3607 if (unicode_append_menu
)
3608 GetTextExtentPoint32W (hdc
, (WCHAR
*) title
,
3609 wcslen ((WCHAR
*) title
),
3612 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
3614 pMis
->itemWidth
= size
.cx
;
3615 if (pMis
->itemHeight
< size
.cy
)
3616 pMis
->itemHeight
= size
.cy
;
3619 pMis
->itemWidth
= 0;
3621 SelectObject (hdc
, old_font
);
3622 DeleteObject (menu_font
);
3623 ReleaseDC (hwnd
, hdc
);
3630 f
= x_window_to_frame (dpyinfo
, hwnd
);
3633 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
3635 if (pDis
->CtlType
== ODT_MENU
)
3637 /* Draw popup menu title. */
3638 char * title
= (char *) pDis
->itemData
;
3641 HDC hdc
= pDis
->hDC
;
3642 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3643 LOGFONT menu_logfont
;
3646 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3647 menu_logfont
.lfWeight
= FW_BOLD
;
3648 menu_font
= CreateFontIndirect (&menu_logfont
);
3649 old_font
= SelectObject (hdc
, menu_font
);
3651 /* Always draw title as if not selected. */
3652 if (unicode_append_menu
)
3655 + GetSystemMetrics (SM_CXMENUCHECK
),
3657 ETO_OPAQUE
, &pDis
->rcItem
,
3659 wcslen ((WCHAR
*) title
), NULL
);
3663 + GetSystemMetrics (SM_CXMENUCHECK
),
3665 ETO_OPAQUE
, &pDis
->rcItem
,
3666 title
, strlen (title
), NULL
);
3668 SelectObject (hdc
, old_font
);
3669 DeleteObject (menu_font
);
3677 /* Still not right - can't distinguish between clicks in the
3678 client area of the frame from clicks forwarded from the scroll
3679 bars - may have to hook WM_NCHITTEST to remember the mouse
3680 position and then check if it is in the client area ourselves. */
3681 case WM_MOUSEACTIVATE
:
3682 /* Discard the mouse click that activates a frame, allowing the
3683 user to click anywhere without changing point (or worse!).
3684 Don't eat mouse clicks on scrollbars though!! */
3685 if (LOWORD (lParam
) == HTCLIENT
)
3686 return MA_ACTIVATEANDEAT
;
3691 /* No longer tracking mouse. */
3692 track_mouse_window
= NULL
;
3694 case WM_ACTIVATEAPP
:
3696 case WM_WINDOWPOSCHANGED
:
3698 /* Inform lisp thread that a frame might have just been obscured
3699 or exposed, so should recheck visibility of all frames. */
3700 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3704 dpyinfo
->faked_key
= 0;
3706 register_hot_keys (hwnd
);
3709 unregister_hot_keys (hwnd
);
3712 /* Relinquish the system caret. */
3713 if (w32_system_caret_hwnd
)
3715 w32_visible_system_caret_hwnd
= NULL
;
3716 w32_system_caret_hwnd
= NULL
;
3722 f
= x_window_to_frame (dpyinfo
, hwnd
);
3723 if (f
&& HIWORD (wParam
) == 0)
3725 if (menu_free_timer
)
3727 KillTimer (hwnd
, menu_free_timer
);
3728 menu_free_timer
= 0;
3734 wmsg
.dwModifiers
= w32_get_modifiers ();
3735 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3743 wmsg
.dwModifiers
= w32_get_modifiers ();
3744 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3747 case WM_WINDOWPOSCHANGING
:
3748 /* Don't restrict the sizing of tip frames. */
3749 if (hwnd
== tip_window
)
3753 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
3755 wp
.length
= sizeof (WINDOWPLACEMENT
);
3756 GetWindowPlacement (hwnd
, &wp
);
3758 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
3765 DWORD internal_border
;
3766 DWORD scrollbar_extra
;
3769 wp
.length
= sizeof (wp
);
3770 GetWindowRect (hwnd
, &wr
);
3774 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
3775 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
3776 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
3777 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
3781 memset (&rect
, 0, sizeof (rect
));
3782 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
3783 GetMenu (hwnd
) != NULL
);
3785 /* Force width and height of client area to be exact
3786 multiples of the character cell dimensions. */
3787 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
3788 - 2 * internal_border
- scrollbar_extra
)
3790 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
3791 - 2 * internal_border
)
3796 /* For right/bottom sizing we can just fix the sizes.
3797 However for top/left sizing we will need to fix the X
3798 and Y positions as well. */
3800 int cx_mintrack
= GetSystemMetrics (SM_CXMINTRACK
);
3801 int cy_mintrack
= GetSystemMetrics (SM_CYMINTRACK
);
3803 lppos
->cx
= max (lppos
->cx
- wdiff
, cx_mintrack
);
3804 lppos
->cy
= max (lppos
->cy
- hdiff
, cy_mintrack
);
3806 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
3807 && (lppos
->flags
& SWP_NOMOVE
) == 0)
3809 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
3816 lppos
->flags
|= SWP_NOMOVE
;
3827 case WM_GETMINMAXINFO
:
3828 /* Hack to allow resizing the Emacs frame above the screen size.
3829 Note that Windows 9x limits coordinates to 16-bits. */
3830 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.x
= 32767;
3831 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.y
= 32767;
3835 if (LOWORD (lParam
) == HTCLIENT
)
3840 case WM_EMACS_SETCURSOR
:
3842 Cursor cursor
= (Cursor
) wParam
;
3848 case WM_EMACS_CREATESCROLLBAR
:
3849 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
3850 (struct scroll_bar
*) lParam
);
3852 case WM_EMACS_SHOWWINDOW
:
3853 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
3855 case WM_EMACS_SETFOREGROUND
:
3857 HWND foreground_window
;
3858 DWORD foreground_thread
, retval
;
3860 /* On NT 5.0, and apparently Windows 98, it is necessary to
3861 attach to the thread that currently has focus in order to
3862 pull the focus away from it. */
3863 foreground_window
= GetForegroundWindow ();
3864 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
3865 if (!foreground_window
3866 || foreground_thread
== GetCurrentThreadId ()
3867 || !AttachThreadInput (GetCurrentThreadId (),
3868 foreground_thread
, TRUE
))
3869 foreground_thread
= 0;
3871 retval
= SetForegroundWindow ((HWND
) wParam
);
3873 /* Detach from the previous foreground thread. */
3874 if (foreground_thread
)
3875 AttachThreadInput (GetCurrentThreadId (),
3876 foreground_thread
, FALSE
);
3881 case WM_EMACS_SETWINDOWPOS
:
3883 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
3884 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
3885 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
3888 case WM_EMACS_DESTROYWINDOW
:
3889 DragAcceptFiles ((HWND
) wParam
, FALSE
);
3890 return DestroyWindow ((HWND
) wParam
);
3892 case WM_EMACS_HIDE_CARET
:
3893 return HideCaret (hwnd
);
3895 case WM_EMACS_SHOW_CARET
:
3896 return ShowCaret (hwnd
);
3898 case WM_EMACS_DESTROY_CARET
:
3899 w32_system_caret_hwnd
= NULL
;
3900 w32_visible_system_caret_hwnd
= NULL
;
3901 return DestroyCaret ();
3903 case WM_EMACS_TRACK_CARET
:
3904 /* If there is currently no system caret, create one. */
3905 if (w32_system_caret_hwnd
== NULL
)
3907 /* Use the default caret width, and avoid changing it
3908 unneccesarily, as it confuses screen reader software. */
3909 w32_system_caret_hwnd
= hwnd
;
3910 CreateCaret (hwnd
, NULL
, 0,
3911 w32_system_caret_height
);
3914 if (!SetCaretPos (w32_system_caret_x
, w32_system_caret_y
))
3916 /* Ensure visible caret gets turned on when requested. */
3917 else if (w32_use_visible_system_caret
3918 && w32_visible_system_caret_hwnd
!= hwnd
)
3920 w32_visible_system_caret_hwnd
= hwnd
;
3921 return ShowCaret (hwnd
);
3923 /* Ensure visible caret gets turned off when requested. */
3924 else if (!w32_use_visible_system_caret
3925 && w32_visible_system_caret_hwnd
)
3927 w32_visible_system_caret_hwnd
= NULL
;
3928 return HideCaret (hwnd
);
3933 case WM_EMACS_TRACKPOPUPMENU
:
3938 pos
= (POINT
*)lParam
;
3939 flags
= TPM_CENTERALIGN
;
3940 if (button_state
& LMOUSE
)
3941 flags
|= TPM_LEFTBUTTON
;
3942 else if (button_state
& RMOUSE
)
3943 flags
|= TPM_RIGHTBUTTON
;
3945 /* Remember we did a SetCapture on the initial mouse down event,
3946 so for safety, we make sure the capture is cancelled now. */
3950 /* Use menubar_active to indicate that WM_INITMENU is from
3951 TrackPopupMenu below, and should be ignored. */
3952 f
= x_window_to_frame (dpyinfo
, hwnd
);
3954 f
->output_data
.w32
->menubar_active
= 1;
3956 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
3960 /* Eat any mouse messages during popupmenu */
3961 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
3963 /* Get the menu selection, if any */
3964 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
3966 retval
= LOWORD (amsg
.wParam
);
3982 /* Check for messages registered at runtime. */
3983 if (msg
== msh_mousewheel
)
3985 wmsg
.dwModifiers
= w32_get_modifiers ();
3986 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3987 signal_user_input ();
3992 return DefWindowProc (hwnd
, msg
, wParam
, lParam
);
3996 /* The most common default return code for handled messages is 0. */
4001 my_create_window (f
)
4006 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
4008 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
4012 /* Create a tooltip window. Unlike my_create_window, we do not do this
4013 indirectly via the Window thread, as we do not need to process Window
4014 messages for the tooltip. Creating tooltips indirectly also creates
4015 deadlocks when tooltips are created for menu items. */
4017 my_create_tip_window (f
)
4022 rect
.left
= rect
.top
= 0;
4023 rect
.right
= FRAME_PIXEL_WIDTH (f
);
4024 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
4026 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
4027 FRAME_EXTERNAL_MENU_BAR (f
));
4029 tip_window
= FRAME_W32_WINDOW (f
)
4030 = CreateWindow (EMACS_CLASS
,
4032 f
->output_data
.w32
->dwStyle
,
4035 rect
.right
- rect
.left
,
4036 rect
.bottom
- rect
.top
,
4037 FRAME_W32_WINDOW (SELECTED_FRAME ()), /* owner */
4044 SetWindowLong (tip_window
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
4045 SetWindowLong (tip_window
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
4046 SetWindowLong (tip_window
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
4047 SetWindowLong (tip_window
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
4049 /* Tip frames have no scrollbars. */
4050 SetWindowLong (tip_window
, WND_SCROLLBAR_INDEX
, 0);
4052 /* Do this to discard the default setting specified by our parent. */
4053 ShowWindow (tip_window
, SW_HIDE
);
4058 /* Create and set up the w32 window for frame F. */
4061 w32_window (f
, window_prompting
, minibuffer_only
)
4063 long window_prompting
;
4064 int minibuffer_only
;
4068 /* Use the resource name as the top-level window name
4069 for looking up resources. Make a non-Lisp copy
4070 for the window manager, so GC relocation won't bother it.
4072 Elsewhere we specify the window name for the window manager. */
4075 char *str
= (char *) SDATA (Vx_resource_name
);
4076 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
4077 strcpy (f
->namebuf
, str
);
4080 my_create_window (f
);
4082 validate_x_resource_name ();
4084 /* x_set_name normally ignores requests to set the name if the
4085 requested name is the same as the current name. This is the one
4086 place where that assumption isn't correct; f->name is set, but
4087 the server hasn't been told. */
4090 int explicit = f
->explicit_name
;
4092 f
->explicit_name
= 0;
4095 x_set_name (f
, name
, explicit);
4100 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
4101 initialize_frame_menubar (f
);
4103 if (FRAME_W32_WINDOW (f
) == 0)
4104 error ("Unable to create window");
4107 /* Handle the icon stuff for this window. Perhaps later we might
4108 want an x_set_icon_position which can be called interactively as
4116 Lisp_Object icon_x
, icon_y
;
4118 /* Set the position of the icon. Note that Windows 95 groups all
4119 icons in the tray. */
4120 icon_x
= w32_get_arg (parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
4121 icon_y
= w32_get_arg (parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
4122 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
4124 CHECK_NUMBER (icon_x
);
4125 CHECK_NUMBER (icon_y
);
4127 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
4128 error ("Both left and top icon corners of icon must be specified");
4132 if (! EQ (icon_x
, Qunbound
))
4133 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
4136 /* Start up iconic or window? */
4137 x_wm_set_window_state
4138 (f
, (EQ (w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
4142 x_text_icon (f
, (char *) SDATA ((!NILP (f
->icon_name
)
4155 XGCValues gc_values
;
4159 /* Create the GC's of this frame.
4160 Note that many default values are used. */
4163 gc_values
.font
= FRAME_FONT (f
);
4165 /* Cursor has cursor-color background, background-color foreground. */
4166 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
4167 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
4168 f
->output_data
.w32
->cursor_gc
4169 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
4170 (GCFont
| GCForeground
| GCBackground
),
4174 f
->output_data
.w32
->white_relief
.gc
= 0;
4175 f
->output_data
.w32
->black_relief
.gc
= 0;
4181 /* Handler for signals raised during x_create_frame and
4182 x_create_top_frame. FRAME is the frame which is partially
4186 unwind_create_frame (frame
)
4189 struct frame
*f
= XFRAME (frame
);
4191 /* If frame is ``official'', nothing to do. */
4192 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
4195 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4198 x_free_frame_resources (f
);
4200 /* Check that reference counts are indeed correct. */
4201 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
4202 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
4210 #ifdef USE_FONT_BACKEND
4212 x_default_font_parameter (f
, parms
)
4216 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4217 Lisp_Object font
= x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font",
4220 if (!STRINGP (font
))
4223 static char *names
[]
4224 = { "Courier New-10",
4225 "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1",
4226 "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1",
4230 for (i
= 0; names
[i
]; i
++)
4232 font
= font_open_by_name (f
, names
[i
]);
4237 error ("No suitable font was found");
4239 x_default_parameter (f
, parms
, Qfont
, font
, "font", "Font", RES_TYPE_STRING
);
4243 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
4245 doc
: /* Make a new window, which is called a \"frame\" in Emacs terms.
4246 Return an Emacs frame object.
4247 PARAMETERS is an alist of frame parameters.
4248 If the parameters specify that the frame should not have a minibuffer,
4249 and do not specify a specific minibuffer window to use,
4250 then `default-minibuffer-frame' must be a frame whose minibuffer can
4251 be shared by the new frame.
4253 This function is an internal primitive--use `make-frame' instead. */)
4255 Lisp_Object parameters
;
4258 Lisp_Object frame
, tem
;
4260 int minibuffer_only
= 0;
4261 long window_prompting
= 0;
4263 int count
= SPECPDL_INDEX ();
4264 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4265 Lisp_Object display
;
4266 struct w32_display_info
*dpyinfo
= NULL
;
4272 /* Use this general default value to start with
4273 until we know if this frame has a specified name. */
4274 Vx_resource_name
= Vinvocation_name
;
4276 display
= w32_get_arg (parameters
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
4277 if (EQ (display
, Qunbound
))
4279 dpyinfo
= check_x_display_info (display
);
4281 kb
= dpyinfo
->terminal
->kboard
;
4283 kb
= &the_only_kboard
;
4286 name
= w32_get_arg (parameters
, Qname
, "name", "Name", RES_TYPE_STRING
);
4288 && ! EQ (name
, Qunbound
)
4290 error ("Invalid frame name--not a string or nil");
4293 Vx_resource_name
= name
;
4295 /* See if parent window is specified. */
4296 parent
= w32_get_arg (parameters
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
4297 if (EQ (parent
, Qunbound
))
4299 if (! NILP (parent
))
4300 CHECK_NUMBER (parent
);
4302 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
4303 /* No need to protect DISPLAY because that's not used after passing
4304 it to make_frame_without_minibuffer. */
4306 GCPRO4 (parameters
, parent
, name
, frame
);
4307 tem
= w32_get_arg (parameters
, Qminibuffer
, "minibuffer", "Minibuffer",
4309 if (EQ (tem
, Qnone
) || NILP (tem
))
4310 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
4311 else if (EQ (tem
, Qonly
))
4313 f
= make_minibuffer_frame ();
4314 minibuffer_only
= 1;
4316 else if (WINDOWP (tem
))
4317 f
= make_frame_without_minibuffer (tem
, kb
, display
);
4321 XSETFRAME (frame
, f
);
4323 /* Note that Windows does support scroll bars. */
4324 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
4326 /* By default, make scrollbars the system standard width. */
4327 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
4329 f
->terminal
= dpyinfo
->terminal
;
4330 f
->terminal
->reference_count
++;
4332 f
->output_method
= output_w32
;
4333 f
->output_data
.w32
=
4334 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
4335 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
4336 FRAME_FONTSET (f
) = -1;
4337 record_unwind_protect (unwind_create_frame
, frame
);
4340 = w32_get_arg (parameters
, Qicon_name
, "iconName", "Title", RES_TYPE_STRING
);
4341 if (! STRINGP (f
->icon_name
))
4342 f
->icon_name
= Qnil
;
4344 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
4346 FRAME_KBOARD (f
) = kb
;
4349 /* Specify the parent under which to make this window. */
4353 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
4354 f
->output_data
.w32
->explicit_parent
= 1;
4358 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4359 f
->output_data
.w32
->explicit_parent
= 0;
4362 /* Set the name; the functions to which we pass f expect the name to
4364 if (EQ (name
, Qunbound
) || NILP (name
))
4366 f
->name
= build_string (dpyinfo
->w32_id_name
);
4367 f
->explicit_name
= 0;
4372 f
->explicit_name
= 1;
4373 /* use the frame's title when getting resources for this frame. */
4374 specbind (Qx_resource_name
, name
);
4377 f
->resx
= dpyinfo
->resx
;
4378 f
->resy
= dpyinfo
->resy
;
4380 #ifdef USE_FONT_BACKEND
4381 if (enable_font_backend
)
4383 /* Perhaps, we must allow frame parameter, say `font-backend',
4384 to specify which font backends to use. */
4385 register_font_driver (&w32font_driver
, f
);
4387 x_default_parameter (f
, parameters
, Qfont_backend
, Qnil
,
4388 "fontBackend", "FontBackend", RES_TYPE_STRING
);
4390 #endif /* USE_FONT_BACKEND */
4392 /* Extract the window parameters from the supplied values
4393 that are needed to determine window geometry. */
4394 #ifdef USE_FONT_BACKEND
4395 if (enable_font_backend
)
4396 x_default_font_parameter (f
, parameters
);
4402 font
= w32_get_arg (parameters
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4405 /* First, try whatever font the caller has specified. */
4408 tem
= Fquery_fontset (font
, Qnil
);
4410 font
= x_new_fontset (f
, tem
);
4412 font
= x_new_font (f
, SDATA (font
));
4414 /* Try out a font which we hope has bold and italic variations. */
4415 if (!STRINGP (font
))
4416 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
4417 if (! STRINGP (font
))
4418 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
4419 /* If those didn't work, look for something which will at least work. */
4420 if (! STRINGP (font
))
4421 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
4423 if (! STRINGP (font
))
4424 font
= build_string ("Fixedsys");
4426 x_default_parameter (f
, parameters
, Qfont
, font
,
4427 "font", "Font", RES_TYPE_STRING
);
4430 x_default_parameter (f
, parameters
, Qborder_width
, make_number (2),
4431 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4432 /* This defaults to 2 in order to match xterm. We recognize either
4433 internalBorderWidth or internalBorder (which is what xterm calls
4435 if (NILP (Fassq (Qinternal_border_width
, parameters
)))
4439 value
= w32_get_arg (parameters
, Qinternal_border_width
,
4440 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
4441 if (! EQ (value
, Qunbound
))
4442 parameters
= Fcons (Fcons (Qinternal_border_width
, value
),
4445 /* Default internalBorderWidth to 0 on Windows to match other programs. */
4446 x_default_parameter (f
, parameters
, Qinternal_border_width
, make_number (0),
4447 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
4448 x_default_parameter (f
, parameters
, Qvertical_scroll_bars
, Qright
,
4449 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
4451 /* Also do the stuff which must be set before the window exists. */
4452 x_default_parameter (f
, parameters
, Qforeground_color
, build_string ("black"),
4453 "foreground", "Foreground", RES_TYPE_STRING
);
4454 x_default_parameter (f
, parameters
, Qbackground_color
, build_string ("white"),
4455 "background", "Background", RES_TYPE_STRING
);
4456 x_default_parameter (f
, parameters
, Qmouse_color
, build_string ("black"),
4457 "pointerColor", "Foreground", RES_TYPE_STRING
);
4458 x_default_parameter (f
, parameters
, Qcursor_color
, build_string ("black"),
4459 "cursorColor", "Foreground", RES_TYPE_STRING
);
4460 x_default_parameter (f
, parameters
, Qborder_color
, build_string ("black"),
4461 "borderColor", "BorderColor", RES_TYPE_STRING
);
4462 x_default_parameter (f
, parameters
, Qscreen_gamma
, Qnil
,
4463 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
4464 x_default_parameter (f
, parameters
, Qline_spacing
, Qnil
,
4465 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
4466 x_default_parameter (f
, parameters
, Qleft_fringe
, Qnil
,
4467 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
4468 x_default_parameter (f
, parameters
, Qright_fringe
, Qnil
,
4469 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
4472 /* Init faces before x_default_parameter is called for scroll-bar
4473 parameters because that function calls x_set_scroll_bar_width,
4474 which calls change_frame_size, which calls Fset_window_buffer,
4475 which runs hooks, which call Fvertical_motion. At the end, we
4476 end up in init_iterator with a null face cache, which should not
4478 init_frame_faces (f
);
4480 x_default_parameter (f
, parameters
, Qmenu_bar_lines
, make_number (1),
4481 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
4482 x_default_parameter (f
, parameters
, Qtool_bar_lines
, make_number (1),
4483 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
4485 x_default_parameter (f
, parameters
, Qbuffer_predicate
, Qnil
,
4486 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
4487 x_default_parameter (f
, parameters
, Qtitle
, Qnil
,
4488 "title", "Title", RES_TYPE_STRING
);
4489 x_default_parameter (f
, parameters
, Qfullscreen
, Qnil
,
4490 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
4492 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
4493 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4495 f
->output_data
.w32
->text_cursor
= w32_load_cursor (IDC_IBEAM
);
4496 f
->output_data
.w32
->nontext_cursor
= w32_load_cursor (IDC_ARROW
);
4497 f
->output_data
.w32
->modeline_cursor
= w32_load_cursor (IDC_ARROW
);
4498 f
->output_data
.w32
->hand_cursor
= w32_load_cursor (IDC_HAND
);
4499 f
->output_data
.w32
->hourglass_cursor
= w32_load_cursor (IDC_WAIT
);
4500 f
->output_data
.w32
->horizontal_drag_cursor
= w32_load_cursor (IDC_SIZEWE
);
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
);
4530 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4531 Change will not be effected unless different from the current
4533 width
= FRAME_COLS (f
);
4534 height
= FRAME_LINES (f
);
4536 FRAME_LINES (f
) = 0;
4537 SET_FRAME_COLS (f
, 0);
4538 change_frame_size (f
, height
, width
, 1, 0, 0);
4540 /* Tell the server what size and position, etc, we want, and how
4541 badly we want them. This should be done after we have the menu
4542 bar so that its size can be taken into account. */
4544 x_wm_set_size_hint (f
, window_prompting
, 0);
4547 /* Make the window appear on the frame and enable display, unless
4548 the caller says not to. However, with explicit parent, Emacs
4549 cannot control visibility, so don't try. */
4550 if (! f
->output_data
.w32
->explicit_parent
)
4552 Lisp_Object visibility
;
4554 visibility
= w32_get_arg (parameters
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
4555 if (EQ (visibility
, Qunbound
))
4558 if (EQ (visibility
, Qicon
))
4559 x_iconify_frame (f
);
4560 else if (! NILP (visibility
))
4561 x_make_frame_visible (f
);
4563 /* Must have been Qnil. */
4567 /* Initialize `default-minibuffer-frame' in case this is the first
4568 frame on this terminal. */
4569 if (FRAME_HAS_MINIBUF_P (f
)
4570 && (!FRAMEP (kb
->Vdefault_minibuffer_frame
)
4571 || !FRAME_LIVE_P (XFRAME (kb
->Vdefault_minibuffer_frame
))))
4572 kb
->Vdefault_minibuffer_frame
= frame
;
4574 /* All remaining specified parameters, which have not been "used"
4575 by x_get_arg and friends, now go in the misc. alist of the frame. */
4576 for (tem
= parameters
; CONSP (tem
); tem
= XCDR (tem
))
4577 if (CONSP (XCAR (tem
)) && !NILP (XCAR (XCAR (tem
))))
4578 f
->param_alist
= Fcons (XCAR (tem
), f
->param_alist
);
4582 /* Make sure windows on this frame appear in calls to next-window
4583 and similar functions. */
4584 Vwindow_list
= Qnil
;
4586 return unbind_to (count
, frame
);
4589 /* FRAME is used only to get a handle on the X display. We don't pass the
4590 display info directly because we're called from frame.c, which doesn't
4591 know about that structure. */
4593 x_get_focus_frame (frame
)
4594 struct frame
*frame
;
4596 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
4598 if (! dpyinfo
->w32_focus_frame
)
4601 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
4605 DEFUN ("x-focus-frame", Fx_focus_frame
, Sx_focus_frame
, 1, 1, 0,
4606 doc
: /* Give FRAME input focus, raising to foreground if necessary. */)
4610 x_focus_on_frame (check_x_frame (frame
));
4615 /* Return the charset portion of a font name. */
4617 xlfd_charset_of_font (char * fontname
)
4619 char *charset
, *encoding
;
4621 encoding
= strrchr (fontname
, '-');
4622 if (!encoding
|| encoding
== fontname
)
4625 for (charset
= encoding
- 1; charset
>= fontname
; charset
--)
4626 if (*charset
== '-')
4629 if (charset
== fontname
|| strcmp (charset
, "-*-*") == 0)
4635 struct font_info
*w32_load_bdf_font (struct frame
*f
, char *fontname
,
4636 int size
, char* filename
);
4637 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
);
4638 static BOOL
w32_to_x_font (LOGFONT
* lplf
, char * lpxstr
, int len
,
4640 static BOOL
x_to_w32_font (char *lpxstr
, LOGFONT
*lplogfont
);
4642 static struct font_info
*
4643 w32_load_system_font (f
, fontname
, size
)
4648 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4649 Lisp_Object font_names
;
4651 /* Get a list of all the fonts that match this name. Once we
4652 have a list of matching fonts, we compare them against the fonts
4653 we already have loaded by comparing names. */
4654 font_names
= w32_list_fonts (f
, build_string (fontname
), size
, 100);
4656 if (!NILP (font_names
))
4661 /* First check if any are already loaded, as that is cheaper
4662 than loading another one. */
4663 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
4664 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
4665 if (dpyinfo
->font_table
[i
].name
4666 && (!strcmp (dpyinfo
->font_table
[i
].name
,
4667 SDATA (XCAR (tail
)))
4668 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
4669 SDATA (XCAR (tail
)))))
4670 return (dpyinfo
->font_table
+ i
);
4672 fontname
= (char *) SDATA (XCAR (font_names
));
4674 else if (w32_strict_fontnames
)
4676 /* If EnumFontFamiliesEx was available, we got a full list of
4677 fonts back so stop now to avoid the possibility of loading a
4678 random font. If we had to fall back to EnumFontFamilies, the
4679 list is incomplete, so continue whether the font we want was
4681 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
4682 FARPROC enum_font_families_ex
4683 = GetProcAddress (gdi32
, "EnumFontFamiliesExA");
4684 if (enum_font_families_ex
)
4688 /* Load the font and add it to the table. */
4690 char *full_name
, *encoding
, *charset
;
4692 struct font_info
*fontp
;
4698 if (!fontname
|| !x_to_w32_font (fontname
, &lf
))
4701 if (!*lf
.lfFaceName
)
4702 /* If no name was specified for the font, we get a random font
4703 from CreateFontIndirect - this is not particularly
4704 desirable, especially since CreateFontIndirect does not
4705 fill out the missing name in lf, so we never know what we
4709 lf
.lfQuality
= DEFAULT_QUALITY
;
4711 font
= (XFontStruct
*) xmalloc (sizeof (XFontStruct
));
4712 bzero (font
, sizeof (*font
));
4714 /* Set bdf to NULL to indicate that this is a Windows font. */
4719 font
->hfont
= CreateFontIndirect (&lf
);
4721 if (font
->hfont
== NULL
)
4730 codepage
= w32_codepage_for_font (fontname
);
4732 hdc
= GetDC (dpyinfo
->root_window
);
4733 oldobj
= SelectObject (hdc
, font
->hfont
);
4735 ok
= GetTextMetrics (hdc
, &font
->tm
);
4736 if (codepage
== CP_UNICODE
)
4737 font
->double_byte_p
= 1;
4740 /* Unfortunately, some fonts (eg. MingLiU, a big5 ttf font)
4741 don't report themselves as double byte fonts, when
4742 patently they are. So instead of trusting
4743 GetFontLanguageInfo, we check the properties of the
4744 codepage directly, since that is ultimately what we are
4745 working from anyway. */
4746 /* font->double_byte_p = GetFontLanguageInfo (hdc) & GCP_DBCS; */
4748 GetCPInfo (codepage
, &cpi
);
4749 font
->double_byte_p
= cpi
.MaxCharSize
> 1;
4752 SelectObject (hdc
, oldobj
);
4753 ReleaseDC (dpyinfo
->root_window
, hdc
);
4754 /* Fill out details in lf according to the font that was
4756 lf
.lfHeight
= font
->tm
.tmInternalLeading
- font
->tm
.tmHeight
;
4757 lf
.lfWidth
= font
->tm
.tmMaxCharWidth
;
4758 lf
.lfWeight
= font
->tm
.tmWeight
;
4759 lf
.lfItalic
= font
->tm
.tmItalic
;
4760 lf
.lfCharSet
= font
->tm
.tmCharSet
;
4761 lf
.lfPitchAndFamily
= ((font
->tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
)
4762 ? VARIABLE_PITCH
: FIXED_PITCH
);
4763 lf
.lfOutPrecision
= ((font
->tm
.tmPitchAndFamily
& TMPF_VECTOR
)
4764 ? OUT_STROKE_PRECIS
: OUT_STRING_PRECIS
);
4766 w32_cache_char_metrics (font
);
4773 w32_unload_font (dpyinfo
, font
);
4777 /* Find a free slot in the font table. */
4778 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
4779 if (dpyinfo
->font_table
[i
].name
== NULL
)
4782 /* If no free slot found, maybe enlarge the font table. */
4783 if (i
== dpyinfo
->n_fonts
4784 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
4787 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
4788 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
4790 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
4793 fontp
= dpyinfo
->font_table
+ i
;
4794 if (i
== dpyinfo
->n_fonts
)
4797 /* Now fill in the slots of *FONTP. */
4799 bzero (fontp
, sizeof (*fontp
));
4801 fontp
->font_idx
= i
;
4802 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
4803 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
4805 if ((lf
.lfPitchAndFamily
& 0x03) == FIXED_PITCH
)
4807 /* Fixed width font. */
4808 fontp
->average_width
= fontp
->space_width
= FONT_AVG_WIDTH (font
);
4814 pcm
= w32_per_char_metric (font
, &space
, ANSI_FONT
);
4816 fontp
->space_width
= pcm
->width
;
4818 fontp
->space_width
= FONT_AVG_WIDTH (font
);
4820 fontp
->average_width
= font
->tm
.tmAveCharWidth
;
4823 fontp
->charset
= -1;
4824 charset
= xlfd_charset_of_font (fontname
);
4826 /* Cache the W32 codepage for a font. This makes w32_encode_char
4827 (called for every glyph during redisplay) much faster. */
4828 fontp
->codepage
= codepage
;
4830 /* Work out the font's full name. */
4831 full_name
= (char *)xmalloc (100);
4832 if (full_name
&& w32_to_x_font (&lf
, full_name
, 100, charset
))
4833 fontp
->full_name
= full_name
;
4836 /* If all else fails - just use the name we used to load it. */
4838 fontp
->full_name
= fontp
->name
;
4841 fontp
->size
= FONT_WIDTH (font
);
4842 fontp
->height
= FONT_HEIGHT (font
);
4844 /* The slot `encoding' specifies how to map a character
4845 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
4846 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
4847 (0:0x20..0x7F, 1:0xA0..0xFF,
4848 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
4849 2:0xA020..0xFF7F). For the moment, we don't know which charset
4850 uses this font. So, we set information in fontp->encoding_type
4851 which is never used by any charset. If mapping can't be
4852 decided, set FONT_ENCODING_NOT_DECIDED. */
4854 /* SJIS fonts need to be set to type 4, all others seem to work as
4855 type FONT_ENCODING_NOT_DECIDED. */
4856 encoding
= strrchr (fontp
->name
, '-');
4857 if (encoding
&& strnicmp (encoding
+1, "sjis", 4) == 0)
4858 fontp
->encoding_type
= 4;
4860 fontp
->encoding_type
= FONT_ENCODING_NOT_DECIDED
;
4862 /* The following three values are set to 0 under W32, which is
4863 what they get set to if XGetFontProperty fails under X. */
4864 fontp
->baseline_offset
= 0;
4865 fontp
->relative_compose
= 0;
4866 fontp
->default_ascent
= 0;
4868 /* Set global flag fonts_changed_p to non-zero if the font loaded
4869 has a character with a smaller width than any other character
4870 before, or if the font loaded has a smaller height than any
4871 other font loaded before. If this happens, it will make a
4872 glyph matrix reallocation necessary. */
4873 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
4879 /* Load font named FONTNAME of size SIZE for frame F, and return a
4880 pointer to the structure font_info while allocating it dynamically.
4881 If loading fails, return NULL. */
4883 w32_load_font (f
, fontname
, size
)
4888 Lisp_Object bdf_fonts
;
4889 struct font_info
*retval
= NULL
;
4890 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4892 bdf_fonts
= w32_list_bdf_fonts (build_string (fontname
), 1);
4894 while (!retval
&& CONSP (bdf_fonts
))
4896 char *bdf_name
, *bdf_file
;
4897 Lisp_Object bdf_pair
;
4900 bdf_name
= SDATA (XCAR (bdf_fonts
));
4901 bdf_pair
= Fassoc (XCAR (bdf_fonts
), Vw32_bdf_filename_alist
);
4902 bdf_file
= SDATA (XCDR (bdf_pair
));
4904 // If the font is already loaded, do not load it again.
4905 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
4907 if ((dpyinfo
->font_table
[i
].name
4908 && !strcmp (dpyinfo
->font_table
[i
].name
, bdf_name
))
4909 || (dpyinfo
->font_table
[i
].full_name
4910 && !strcmp (dpyinfo
->font_table
[i
].full_name
, bdf_name
)))
4911 return dpyinfo
->font_table
+ i
;
4914 retval
= w32_load_bdf_font (f
, bdf_name
, size
, bdf_file
);
4916 bdf_fonts
= XCDR (bdf_fonts
);
4922 return w32_load_system_font (f
, fontname
, size
);
4927 w32_unload_font (dpyinfo
, font
)
4928 struct w32_display_info
*dpyinfo
;
4933 if (font
->per_char
) xfree (font
->per_char
);
4934 if (font
->bdf
) w32_free_bdf_font (font
->bdf
);
4936 if (font
->hfont
) DeleteObject (font
->hfont
);
4941 /* The font conversion stuff between x and w32 */
4943 /* X font string is as follows (from faces.el)
4947 * (weight "\\(bold\\|demibold\\|medium\\)") ; 1
4948 * (weight\? "\\([^-]*\\)") ; 1
4949 * (slant "\\([ior]\\)") ; 2
4950 * (slant\? "\\([^-]?\\)") ; 2
4951 * (swidth "\\([^-]*\\)") ; 3
4952 * (adstyle "[^-]*") ; 4
4953 * (pixelsize "[0-9]+")
4954 * (pointsize "[0-9][0-9]+")
4955 * (resx "[0-9][0-9]+")
4956 * (resy "[0-9][0-9]+")
4957 * (spacing "[cmp?*]")
4958 * (avgwidth "[0-9]+")
4959 * (registry "[^-]+")
4960 * (encoding "[^-]+")
4965 x_to_w32_weight (lpw
)
4968 if (!lpw
) return (FW_DONTCARE
);
4970 if (stricmp (lpw
, "heavy") == 0) return FW_HEAVY
;
4971 else if (stricmp (lpw
, "extrabold") == 0) return FW_EXTRABOLD
;
4972 else if (stricmp (lpw
, "bold") == 0) return FW_BOLD
;
4973 else if (stricmp (lpw
, "demibold") == 0) return FW_SEMIBOLD
;
4974 else if (stricmp (lpw
, "semibold") == 0) return FW_SEMIBOLD
;
4975 else if (stricmp (lpw
, "medium") == 0) return FW_MEDIUM
;
4976 else if (stricmp (lpw
, "normal") == 0) return FW_NORMAL
;
4977 else if (stricmp (lpw
, "light") == 0) return FW_LIGHT
;
4978 else if (stricmp (lpw
, "extralight") == 0) return FW_EXTRALIGHT
;
4979 else if (stricmp (lpw
, "thin") == 0) return FW_THIN
;
4986 w32_to_x_weight (fnweight
)
4989 if (fnweight
>= FW_HEAVY
) return "heavy";
4990 if (fnweight
>= FW_EXTRABOLD
) return "extrabold";
4991 if (fnweight
>= FW_BOLD
) return "bold";
4992 if (fnweight
>= FW_SEMIBOLD
) return "demibold";
4993 if (fnweight
>= FW_MEDIUM
) return "medium";
4994 if (fnweight
>= FW_NORMAL
) return "normal";
4995 if (fnweight
>= FW_LIGHT
) return "light";
4996 if (fnweight
>= FW_EXTRALIGHT
) return "extralight";
4997 if (fnweight
>= FW_THIN
) return "thin";
5003 x_to_w32_charset (lpcs
)
5006 Lisp_Object this_entry
, w32_charset
;
5008 int len
= strlen (lpcs
);
5010 /* Support "*-#nnn" format for unknown charsets. */
5011 if (strncmp (lpcs
, "*-#", 3) == 0)
5012 return atoi (lpcs
+ 3);
5014 /* All Windows fonts qualify as unicode. */
5015 if (!strncmp (lpcs
, "iso10646", 8))
5016 return DEFAULT_CHARSET
;
5018 /* Handle wildcards by ignoring them; eg. treat "big5*-*" as "big5". */
5019 charset
= alloca (len
+ 1);
5020 strcpy (charset
, lpcs
);
5021 lpcs
= strchr (charset
, '*');
5025 /* Look through w32-charset-info-alist for the character set.
5026 Format of each entry is
5027 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5029 this_entry
= Fassoc (build_string (charset
), Vw32_charset_info_alist
);
5031 if (NILP (this_entry
))
5033 /* At startup, we want iso8859-1 fonts to come up properly. */
5034 if (stricmp (charset
, "iso8859-1") == 0)
5035 return ANSI_CHARSET
;
5037 return DEFAULT_CHARSET
;
5040 w32_charset
= Fcar (Fcdr (this_entry
));
5042 /* Translate Lisp symbol to number. */
5043 if (EQ (w32_charset
, Qw32_charset_ansi
))
5044 return ANSI_CHARSET
;
5045 if (EQ (w32_charset
, Qw32_charset_symbol
))
5046 return SYMBOL_CHARSET
;
5047 if (EQ (w32_charset
, Qw32_charset_shiftjis
))
5048 return SHIFTJIS_CHARSET
;
5049 if (EQ (w32_charset
, Qw32_charset_hangeul
))
5050 return HANGEUL_CHARSET
;
5051 if (EQ (w32_charset
, Qw32_charset_chinesebig5
))
5052 return CHINESEBIG5_CHARSET
;
5053 if (EQ (w32_charset
, Qw32_charset_gb2312
))
5054 return GB2312_CHARSET
;
5055 if (EQ (w32_charset
, Qw32_charset_oem
))
5057 #ifdef JOHAB_CHARSET
5058 if (EQ (w32_charset
, Qw32_charset_johab
))
5059 return JOHAB_CHARSET
;
5060 if (EQ (w32_charset
, Qw32_charset_easteurope
))
5061 return EASTEUROPE_CHARSET
;
5062 if (EQ (w32_charset
, Qw32_charset_turkish
))
5063 return TURKISH_CHARSET
;
5064 if (EQ (w32_charset
, Qw32_charset_baltic
))
5065 return BALTIC_CHARSET
;
5066 if (EQ (w32_charset
, Qw32_charset_russian
))
5067 return RUSSIAN_CHARSET
;
5068 if (EQ (w32_charset
, Qw32_charset_arabic
))
5069 return ARABIC_CHARSET
;
5070 if (EQ (w32_charset
, Qw32_charset_greek
))
5071 return GREEK_CHARSET
;
5072 if (EQ (w32_charset
, Qw32_charset_hebrew
))
5073 return HEBREW_CHARSET
;
5074 if (EQ (w32_charset
, Qw32_charset_vietnamese
))
5075 return VIETNAMESE_CHARSET
;
5076 if (EQ (w32_charset
, Qw32_charset_thai
))
5077 return THAI_CHARSET
;
5078 if (EQ (w32_charset
, Qw32_charset_mac
))
5080 #endif /* JOHAB_CHARSET */
5081 #ifdef UNICODE_CHARSET
5082 if (EQ (w32_charset
, Qw32_charset_unicode
))
5083 return UNICODE_CHARSET
;
5086 return DEFAULT_CHARSET
;
5091 w32_to_x_charset (fncharset
, matching
)
5095 static char buf
[32];
5096 Lisp_Object charset_type
;
5101 /* If fully specified, accept it as it is. Otherwise use a
5103 char *wildcard
= strchr (matching
, '*');
5106 else if (strchr (matching
, '-'))
5109 match_len
= strlen (matching
);
5115 /* Handle startup case of w32-charset-info-alist not
5116 being set up yet. */
5117 if (NILP (Vw32_charset_info_alist
))
5119 charset_type
= Qw32_charset_ansi
;
5121 case DEFAULT_CHARSET
:
5122 charset_type
= Qw32_charset_default
;
5124 case SYMBOL_CHARSET
:
5125 charset_type
= Qw32_charset_symbol
;
5127 case SHIFTJIS_CHARSET
:
5128 charset_type
= Qw32_charset_shiftjis
;
5130 case HANGEUL_CHARSET
:
5131 charset_type
= Qw32_charset_hangeul
;
5133 case GB2312_CHARSET
:
5134 charset_type
= Qw32_charset_gb2312
;
5136 case CHINESEBIG5_CHARSET
:
5137 charset_type
= Qw32_charset_chinesebig5
;
5140 charset_type
= Qw32_charset_oem
;
5143 /* More recent versions of Windows (95 and NT4.0) define more
5145 #ifdef EASTEUROPE_CHARSET
5146 case EASTEUROPE_CHARSET
:
5147 charset_type
= Qw32_charset_easteurope
;
5149 case TURKISH_CHARSET
:
5150 charset_type
= Qw32_charset_turkish
;
5152 case BALTIC_CHARSET
:
5153 charset_type
= Qw32_charset_baltic
;
5155 case RUSSIAN_CHARSET
:
5156 charset_type
= Qw32_charset_russian
;
5158 case ARABIC_CHARSET
:
5159 charset_type
= Qw32_charset_arabic
;
5162 charset_type
= Qw32_charset_greek
;
5164 case HEBREW_CHARSET
:
5165 charset_type
= Qw32_charset_hebrew
;
5167 case VIETNAMESE_CHARSET
:
5168 charset_type
= Qw32_charset_vietnamese
;
5171 charset_type
= Qw32_charset_thai
;
5174 charset_type
= Qw32_charset_mac
;
5177 charset_type
= Qw32_charset_johab
;
5181 #ifdef UNICODE_CHARSET
5182 case UNICODE_CHARSET
:
5183 charset_type
= Qw32_charset_unicode
;
5187 /* Encode numerical value of unknown charset. */
5188 sprintf (buf
, "*-#%u", fncharset
);
5194 char * best_match
= NULL
;
5195 int matching_found
= 0;
5197 /* Look through w32-charset-info-alist for the character set.
5198 Prefer ISO codepages, and prefer lower numbers in the ISO
5199 range. Only return charsets for codepages which are installed.
5201 Format of each entry is
5202 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5204 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
5207 Lisp_Object w32_charset
;
5208 Lisp_Object codepage
;
5210 Lisp_Object this_entry
= XCAR (rest
);
5212 /* Skip invalid entries in alist. */
5213 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
5214 || !CONSP (XCDR (this_entry
))
5215 || !SYMBOLP (XCAR (XCDR (this_entry
))))
5218 x_charset
= SDATA (XCAR (this_entry
));
5219 w32_charset
= XCAR (XCDR (this_entry
));
5220 codepage
= XCDR (XCDR (this_entry
));
5222 /* Look for Same charset and a valid codepage (or non-int
5223 which means ignore). */
5224 if (EQ (w32_charset
, charset_type
)
5225 && (!INTEGERP (codepage
) || XINT (codepage
) == CP_DEFAULT
5226 || IsValidCodePage (XINT (codepage
))))
5228 /* If we don't have a match already, then this is the
5232 best_match
= x_charset
;
5233 if (matching
&& !strnicmp (x_charset
, matching
, match_len
))
5236 /* If we already found a match for MATCHING, then
5237 only consider other matches. */
5238 else if (matching_found
5239 && strnicmp (x_charset
, matching
, match_len
))
5241 /* If this matches what we want, and the best so far doesn't,
5242 then this is better. */
5243 else if (!matching_found
&& matching
5244 && !strnicmp (x_charset
, matching
, match_len
))
5246 best_match
= x_charset
;
5249 /* If this is fully specified, and the best so far isn't,
5250 then this is better. */
5251 else if ((!strchr (best_match
, '-') && strchr (x_charset
, '-'))
5252 /* If this is an ISO codepage, and the best so far isn't,
5253 then this is better, but only if it fully specifies the
5255 || (strnicmp (best_match
, "iso", 3) != 0
5256 && strnicmp (x_charset
, "iso", 3) == 0
5257 && strchr (x_charset
, '-')))
5258 best_match
= x_charset
;
5259 /* If both are ISO8859 codepages, choose the one with the
5260 lowest number in the encoding field. */
5261 else if (strnicmp (best_match
, "iso8859-", 8) == 0
5262 && strnicmp (x_charset
, "iso8859-", 8) == 0)
5264 int best_enc
= atoi (best_match
+ 8);
5265 int this_enc
= atoi (x_charset
+ 8);
5266 if (this_enc
> 0 && this_enc
< best_enc
)
5267 best_match
= x_charset
;
5272 /* If no match, encode the numeric value. */
5275 sprintf (buf
, "*-#%u", fncharset
);
5279 strncpy (buf
, best_match
, 31);
5280 /* If the charset is not fully specified, put -0 on the end. */
5281 if (!strchr (best_match
, '-'))
5283 int pos
= strlen (best_match
);
5284 /* Charset specifiers shouldn't be very long. If it is a made
5285 up one, truncating it should not do any harm since it isn't
5286 recognized anyway. */
5289 strcpy (buf
+ pos
, "-0");
5297 /* Return all the X charsets that map to a font. */
5299 w32_to_all_x_charsets (fncharset
)
5302 static char buf
[32];
5303 Lisp_Object charset_type
;
5304 Lisp_Object retval
= Qnil
;
5309 /* Handle startup case of w32-charset-info-alist not
5310 being set up yet. */
5311 if (NILP (Vw32_charset_info_alist
))
5312 return Fcons (build_string ("iso8859-1"), Qnil
);
5314 charset_type
= Qw32_charset_ansi
;
5316 case DEFAULT_CHARSET
:
5317 charset_type
= Qw32_charset_default
;
5319 case SYMBOL_CHARSET
:
5320 charset_type
= Qw32_charset_symbol
;
5322 case SHIFTJIS_CHARSET
:
5323 charset_type
= Qw32_charset_shiftjis
;
5325 case HANGEUL_CHARSET
:
5326 charset_type
= Qw32_charset_hangeul
;
5328 case GB2312_CHARSET
:
5329 charset_type
= Qw32_charset_gb2312
;
5331 case CHINESEBIG5_CHARSET
:
5332 charset_type
= Qw32_charset_chinesebig5
;
5335 charset_type
= Qw32_charset_oem
;
5338 /* More recent versions of Windows (95 and NT4.0) define more
5340 #ifdef EASTEUROPE_CHARSET
5341 case EASTEUROPE_CHARSET
:
5342 charset_type
= Qw32_charset_easteurope
;
5344 case TURKISH_CHARSET
:
5345 charset_type
= Qw32_charset_turkish
;
5347 case BALTIC_CHARSET
:
5348 charset_type
= Qw32_charset_baltic
;
5350 case RUSSIAN_CHARSET
:
5351 charset_type
= Qw32_charset_russian
;
5353 case ARABIC_CHARSET
:
5354 charset_type
= Qw32_charset_arabic
;
5357 charset_type
= Qw32_charset_greek
;
5359 case HEBREW_CHARSET
:
5360 charset_type
= Qw32_charset_hebrew
;
5362 case VIETNAMESE_CHARSET
:
5363 charset_type
= Qw32_charset_vietnamese
;
5366 charset_type
= Qw32_charset_thai
;
5369 charset_type
= Qw32_charset_mac
;
5372 charset_type
= Qw32_charset_johab
;
5376 #ifdef UNICODE_CHARSET
5377 case UNICODE_CHARSET
:
5378 charset_type
= Qw32_charset_unicode
;
5382 /* Encode numerical value of unknown charset. */
5383 sprintf (buf
, "*-#%u", fncharset
);
5384 return Fcons (build_string (buf
), Qnil
);
5389 /* Look through w32-charset-info-alist for the character set.
5390 Only return fully specified charsets for codepages which are
5393 Format of each entry in Vw32_charset_info_alist is
5394 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5396 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
5398 Lisp_Object x_charset
;
5399 Lisp_Object w32_charset
;
5400 Lisp_Object codepage
;
5402 Lisp_Object this_entry
= XCAR (rest
);
5404 /* Skip invalid entries in alist. */
5405 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
5406 || !CONSP (XCDR (this_entry
))
5407 || !SYMBOLP (XCAR (XCDR (this_entry
))))
5410 x_charset
= XCAR (this_entry
);
5411 w32_charset
= XCAR (XCDR (this_entry
));
5412 codepage
= XCDR (XCDR (this_entry
));
5414 if (!strchr (SDATA (x_charset
), '-'))
5417 /* Look for Same charset and a valid codepage (or non-int
5418 which means ignore). */
5419 if (EQ (w32_charset
, charset_type
)
5420 && (!INTEGERP (codepage
) || XINT (codepage
) == CP_DEFAULT
5421 || IsValidCodePage (XINT (codepage
))))
5423 retval
= Fcons (x_charset
, retval
);
5427 /* If no match, encode the numeric value. */
5430 sprintf (buf
, "*-#%u", fncharset
);
5431 return Fcons (build_string (buf
), Qnil
);
5438 /* Get the Windows codepage corresponding to the specified font. The
5439 charset info in the font name is used to look up
5440 w32-charset-to-codepage-alist. */
5442 w32_codepage_for_font (char *fontname
)
5444 Lisp_Object codepage
, entry
;
5445 char *charset_str
, *charset
, *end
;
5447 /* Extract charset part of font string. */
5448 charset
= xlfd_charset_of_font (fontname
);
5453 charset_str
= (char *) alloca (strlen (charset
) + 1);
5454 strcpy (charset_str
, charset
);
5457 /* Remove leading "*-". */
5458 if (strncmp ("*-", charset_str
, 2) == 0)
5459 charset
= charset_str
+ 2;
5462 charset
= charset_str
;
5464 /* Stop match at wildcard (including preceding '-'). */
5465 if (end
= strchr (charset
, '*'))
5467 if (end
> charset
&& *(end
-1) == '-')
5472 if (!strcmp (charset
, "iso10646"))
5475 if (NILP (Vw32_charset_info_alist
))
5478 entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
5482 codepage
= Fcdr (Fcdr (entry
));
5484 if (NILP (codepage
))
5486 else if (XFASTINT (codepage
) == XFASTINT (Qt
))
5488 else if (INTEGERP (codepage
))
5489 return XINT (codepage
);
5496 w32_to_x_font (lplogfont
, lpxstr
, len
, specific_charset
)
5497 LOGFONT
* lplogfont
;
5500 char * specific_charset
;
5504 char height_pixels
[8];
5506 char width_pixels
[8];
5507 char *fontname_dash
;
5508 int display_resy
= (int) one_w32_display_info
.resy
;
5509 int display_resx
= (int) one_w32_display_info
.resx
;
5510 struct coding_system coding
;
5512 if (!lpxstr
) abort ();
5517 if (lplogfont
->lfOutPrecision
== OUT_STRING_PRECIS
)
5518 fonttype
= "raster";
5519 else if (lplogfont
->lfOutPrecision
== OUT_STROKE_PRECIS
)
5520 fonttype
= "outline";
5522 fonttype
= "unknown";
5524 setup_coding_system (Fcheck_coding_system (Vlocale_coding_system
),
5526 coding
.src_multibyte
= 0;
5527 coding
.dst_multibyte
= 1;
5528 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
5529 /* We explicitely disable composition handling because selection
5530 data should not contain any composition sequence. */
5531 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
5533 coding
.dst_bytes
= LF_FACESIZE
* 2;
5534 coding
.destination
= (unsigned char *) xmalloc (coding
.dst_bytes
+ 1);
5535 decode_coding_c_string (&coding
, lplogfont
->lfFaceName
,
5536 strlen(lplogfont
->lfFaceName
), Qnil
);
5537 fontname
= coding
.destination
;
5539 *(fontname
+ coding
.produced
) = '\0';
5541 /* Replace dashes with underscores so the dashes are not
5543 fontname_dash
= fontname
;
5544 while (fontname_dash
= strchr (fontname_dash
, '-'))
5545 *fontname_dash
= '_';
5547 if (lplogfont
->lfHeight
)
5549 sprintf (height_pixels
, "%u", eabs (lplogfont
->lfHeight
));
5550 sprintf (height_dpi
, "%u",
5551 eabs (lplogfont
->lfHeight
) * 720 / display_resy
);
5555 strcpy (height_pixels
, "*");
5556 strcpy (height_dpi
, "*");
5559 #if 0 /* Never put the width in the xfld. It fails on fonts with
5560 double-width characters. */
5561 if (lplogfont
->lfWidth
)
5562 sprintf (width_pixels
, "%u", lplogfont
->lfWidth
* 10);
5565 strcpy (width_pixels
, "*");
5567 _snprintf (lpxstr
, len
- 1,
5568 "-%s-%s-%s-%c-normal-normal-%s-%s-%d-%d-%c-%s-%s",
5569 fonttype
, /* foundry */
5570 fontname
, /* family */
5571 w32_to_x_weight (lplogfont
->lfWeight
), /* weight */
5572 lplogfont
->lfItalic
?'i':'r', /* slant */
5574 /* add style name */
5575 height_pixels
, /* pixel size */
5576 height_dpi
, /* point size */
5577 display_resx
, /* resx */
5578 display_resy
, /* resy */
5579 ((lplogfont
->lfPitchAndFamily
& 0x3) == VARIABLE_PITCH
)
5580 ? 'p' : 'c', /* spacing */
5581 width_pixels
, /* avg width */
5582 w32_to_x_charset (lplogfont
->lfCharSet
, specific_charset
)
5583 /* charset registry and encoding */
5586 lpxstr
[len
- 1] = 0; /* just to be sure */
5591 x_to_w32_font (lpxstr
, lplogfont
)
5593 LOGFONT
* lplogfont
;
5595 struct coding_system coding
;
5597 if (!lplogfont
) return (FALSE
);
5599 memset (lplogfont
, 0, sizeof (*lplogfont
));
5601 /* Set default value for each field. */
5603 lplogfont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
5604 lplogfont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
5605 lplogfont
->lfQuality
= DEFAULT_QUALITY
;
5607 /* go for maximum quality */
5608 lplogfont
->lfOutPrecision
= OUT_STROKE_PRECIS
;
5609 lplogfont
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
5610 lplogfont
->lfQuality
= PROOF_QUALITY
;
5613 lplogfont
->lfCharSet
= DEFAULT_CHARSET
;
5614 lplogfont
->lfWeight
= FW_DONTCARE
;
5615 lplogfont
->lfPitchAndFamily
= DEFAULT_PITCH
| FF_DONTCARE
;
5620 /* Provide a simple escape mechanism for specifying Windows font names
5621 * directly -- if font spec does not beginning with '-', assume this
5623 * "<font name>[:height in pixels[:width in pixels[:weight]]]"
5629 char name
[50], weight
[20], slant
, pitch
, pixels
[10], height
[10],
5630 width
[10], resy
[10], remainder
[50];
5632 int dpi
= (int) one_w32_display_info
.resy
;
5634 fields
= sscanf (lpxstr
,
5635 "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%49s",
5636 name
, weight
, &slant
, pixels
, height
, resy
, &pitch
, width
, remainder
);
5640 /* In the general case when wildcards cover more than one field,
5641 we don't know which field is which, so don't fill any in.
5642 However, we need to cope with this particular form, which is
5643 generated by font_list_1 (invoked by try_font_list):
5644 "-raster-6x10-*-gb2312*-*"
5645 and make sure to correctly parse the charset field. */
5648 fields
= sscanf (lpxstr
,
5649 "-%*[^-]-%49[^-]-*-%49s",
5652 else if (fields
< 9)
5658 if (fields
> 0 && name
[0] != '*')
5660 Lisp_Object string
= build_string (name
);
5662 (Fcheck_coding_system (Vlocale_coding_system
), &coding
);
5663 coding
.mode
|= (CODING_MODE_SAFE_ENCODING
| CODING_MODE_LAST_BLOCK
);
5664 /* Disable composition/charset annotation. */
5665 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
5666 coding
.dst_bytes
= SCHARS (string
) * 2;
5668 coding
.destination
= (unsigned char *) xmalloc (coding
.dst_bytes
);
5669 encode_coding_object (&coding
, string
, 0, 0,
5670 SCHARS (string
), SBYTES (string
), Qnil
);
5671 if (coding
.produced
>= LF_FACESIZE
)
5672 coding
.produced
= LF_FACESIZE
- 1;
5674 coding
.destination
[coding
.produced
] = '\0';
5676 strcpy (lplogfont
->lfFaceName
, coding
.destination
);
5677 xfree (coding
.destination
);
5681 lplogfont
->lfFaceName
[0] = '\0';
5686 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
5690 lplogfont
->lfItalic
= (fields
> 0 && slant
== 'i');
5694 if (fields
> 0 && pixels
[0] != '*')
5695 lplogfont
->lfHeight
= atoi (pixels
);
5699 if (fields
> 0 && resy
[0] != '*')
5702 if (tem
> 0) dpi
= tem
;
5705 if (fields
> -1 && lplogfont
->lfHeight
== 0 && height
[0] != '*')
5706 lplogfont
->lfHeight
= atoi (height
) * dpi
/ 720;
5711 lplogfont
->lfPitchAndFamily
= VARIABLE_PITCH
| FF_DONTCARE
;
5712 else if (pitch
== 'c')
5713 lplogfont
->lfPitchAndFamily
= FIXED_PITCH
| FF_DONTCARE
;
5718 if (fields
> 0 && width
[0] != '*')
5719 lplogfont
->lfWidth
= atoi (width
) / 10;
5723 /* Strip the trailing '-' if present. (it shouldn't be, as it
5724 fails the test against xlfd-tight-regexp in fontset.el). */
5726 int len
= strlen (remainder
);
5727 if (len
> 0 && remainder
[len
-1] == '-')
5728 remainder
[len
-1] = 0;
5730 encoding
= remainder
;
5732 if (strncmp (encoding
, "*-", 2) == 0)
5735 lplogfont
->lfCharSet
= x_to_w32_charset (encoding
);
5740 char name
[100], height
[10], width
[10], weight
[20];
5742 fields
= sscanf (lpxstr
,
5743 "%99[^:]:%9[^:]:%9[^:]:%19s",
5744 name
, height
, width
, weight
);
5746 if (fields
== EOF
) return (FALSE
);
5750 strncpy (lplogfont
->lfFaceName
, name
, LF_FACESIZE
);
5751 lplogfont
->lfFaceName
[LF_FACESIZE
-1] = 0;
5755 lplogfont
->lfFaceName
[0] = 0;
5761 lplogfont
->lfHeight
= atoi (height
);
5766 lplogfont
->lfWidth
= atoi (width
);
5770 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
5773 /* This makes TrueType fonts work better. */
5774 lplogfont
->lfHeight
= - eabs (lplogfont
->lfHeight
);
5779 /* Strip the pixel height and point height from the given xlfd, and
5780 return the pixel height. If no pixel height is specified, calculate
5781 one from the point height, or if that isn't defined either, return
5782 0 (which usually signifies a scalable font).
5785 xlfd_strip_height (char *fontname
)
5787 int pixel_height
, field_number
;
5788 char *read_from
, *write_to
;
5792 pixel_height
= field_number
= 0;
5795 /* Look for height fields. */
5796 for (read_from
= fontname
; *read_from
; read_from
++)
5798 if (*read_from
== '-')
5801 if (field_number
== 7) /* Pixel height. */
5804 write_to
= read_from
;
5806 /* Find end of field. */
5807 for (;*read_from
&& *read_from
!= '-'; read_from
++)
5810 /* Split the fontname at end of field. */
5816 pixel_height
= atoi (write_to
);
5817 /* Blank out field. */
5818 if (read_from
> write_to
)
5823 /* If the pixel height field is at the end (partial xlfd),
5826 return pixel_height
;
5828 /* If we got a pixel height, the point height can be
5829 ignored. Just blank it out and break now. */
5832 /* Find end of point size field. */
5833 for (; *read_from
&& *read_from
!= '-'; read_from
++)
5839 /* Blank out the point size field. */
5840 if (read_from
> write_to
)
5846 return pixel_height
;
5850 /* If the point height is already blank, break now. */
5851 if (*read_from
== '-')
5857 else if (field_number
== 8)
5859 /* If we didn't get a pixel height, try to get the point
5860 height and convert that. */
5862 char *point_size_start
= read_from
++;
5864 /* Find end of field. */
5865 for (; *read_from
&& *read_from
!= '-'; read_from
++)
5874 point_size
= atoi (point_size_start
);
5876 /* Convert to pixel height. */
5877 pixel_height
= point_size
5878 * one_w32_display_info
.height_in
/ 720;
5880 /* Blank out this field and break. */
5888 /* Shift the rest of the font spec into place. */
5889 if (write_to
&& read_from
> write_to
)
5891 for (; *read_from
; read_from
++, write_to
++)
5892 *write_to
= *read_from
;
5896 return pixel_height
;
5899 /* Assume parameter 1 is fully qualified, no wildcards. */
5901 w32_font_match (fontname
, pattern
)
5906 char *font_name_copy
;
5907 char *regex
= alloca (strlen (pattern
) * 2 + 3);
5909 font_name_copy
= alloca (strlen (fontname
) + 1);
5910 strcpy (font_name_copy
, fontname
);
5915 /* Turn pattern into a regexp and do a regexp match. */
5916 for (; *pattern
; pattern
++)
5918 if (*pattern
== '?')
5920 else if (*pattern
== '*')
5931 /* Strip out font heights and compare them seperately, since
5932 rounding error can cause mismatches. This also allows a
5933 comparison between a font that declares only a pixel height and a
5934 pattern that declares the point height.
5937 int font_height
, pattern_height
;
5939 font_height
= xlfd_strip_height (font_name_copy
);
5940 pattern_height
= xlfd_strip_height (regex
);
5942 /* Compare now, and don't bother doing expensive regexp matching
5943 if the heights differ. */
5944 if (font_height
&& pattern_height
&& (font_height
!= pattern_height
))
5948 return (fast_string_match_ignore_case (build_string (regex
),
5949 build_string (font_name_copy
)) >= 0);
5952 /* Callback functions, and a structure holding info they need, for
5953 listing system fonts on W32. We need one set of functions to do the
5954 job properly, but these don't work on NT 3.51 and earlier, so we
5955 have a second set which don't handle character sets properly to
5958 In both cases, there are two passes made. The first pass gets one
5959 font from each family, the second pass lists all the fonts from
5962 typedef struct enumfont_t
5967 XFontStruct
*size_ref
;
5968 Lisp_Object pattern
;
5974 enum_font_maybe_add_to_list (enumfont_t
*, LOGFONT
*, char *, Lisp_Object
);
5978 enum_font_cb2 (lplf
, lptm
, FontType
, lpef
)
5980 NEWTEXTMETRIC
* lptm
;
5984 /* Ignore struck out and underlined versions of fonts. */
5985 if (lplf
->elfLogFont
.lfStrikeOut
|| lplf
->elfLogFont
.lfUnderline
)
5988 /* Only return fonts with names starting with @ if they were
5989 explicitly specified, since Microsoft uses an initial @ to
5990 denote fonts for vertical writing, without providing a more
5991 convenient way of identifying them. */
5992 if (lplf
->elfLogFont
.lfFaceName
[0] == '@'
5993 && lpef
->logfont
.lfFaceName
[0] != '@')
5996 /* Check that the character set matches if it was specified */
5997 if (lpef
->logfont
.lfCharSet
!= DEFAULT_CHARSET
&&
5998 lplf
->elfLogFont
.lfCharSet
!= lpef
->logfont
.lfCharSet
)
6001 if (FontType
== RASTER_FONTTYPE
)
6003 /* DBCS raster fonts have problems displaying, so skip them. */
6004 int charset
= lplf
->elfLogFont
.lfCharSet
;
6005 if (charset
== SHIFTJIS_CHARSET
6006 || charset
== HANGEUL_CHARSET
6007 || charset
== CHINESEBIG5_CHARSET
6008 || charset
== GB2312_CHARSET
6009 #ifdef JOHAB_CHARSET
6010 || charset
== JOHAB_CHARSET
6018 Lisp_Object width
= Qnil
;
6019 Lisp_Object charset_list
= Qnil
;
6020 char *charset
= NULL
;
6022 /* Truetype fonts do not report their true metrics until loaded */
6023 if (FontType
!= RASTER_FONTTYPE
)
6025 if (!NILP (lpef
->pattern
))
6027 /* Scalable fonts are as big as you want them to be. */
6028 lplf
->elfLogFont
.lfHeight
= lpef
->logfont
.lfHeight
;
6029 lplf
->elfLogFont
.lfWidth
= lpef
->logfont
.lfWidth
;
6030 width
= make_number (lpef
->logfont
.lfWidth
);
6034 lplf
->elfLogFont
.lfHeight
= 0;
6035 lplf
->elfLogFont
.lfWidth
= 0;
6039 /* Make sure the height used here is the same as everywhere
6040 else (ie character height, not cell height). */
6041 if (lplf
->elfLogFont
.lfHeight
> 0)
6043 /* lptm can be trusted for RASTER fonts, but not scalable ones. */
6044 if (FontType
== RASTER_FONTTYPE
)
6045 lplf
->elfLogFont
.lfHeight
= lptm
->tmInternalLeading
- lptm
->tmHeight
;
6047 lplf
->elfLogFont
.lfHeight
= -lplf
->elfLogFont
.lfHeight
;
6050 if (!NILP (lpef
->pattern
))
6052 charset
= xlfd_charset_of_font (SDATA (lpef
->pattern
));
6054 /* We already checked charsets above, but DEFAULT_CHARSET
6055 slipped through. So only allow exact matches for DEFAULT_CHARSET. */
6057 && strncmp (charset
, "*-*", 3) != 0
6058 && lpef
->logfont
.lfCharSet
== DEFAULT_CHARSET
6059 && strcmp (charset
, w32_to_x_charset (DEFAULT_CHARSET
, NULL
)) != 0)
6064 charset_list
= Fcons (build_string (charset
), Qnil
);
6066 /* Always prefer unicode. */
6068 = Fcons (build_string ("iso10646-1"),
6069 w32_to_all_x_charsets (lplf
->elfLogFont
.lfCharSet
));
6071 /* Loop through the charsets. */
6072 for ( ; CONSP (charset_list
); charset_list
= Fcdr (charset_list
))
6074 Lisp_Object this_charset
= Fcar (charset_list
);
6075 charset
= SDATA (this_charset
);
6077 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
6080 /* List bold and italic variations if w32-enable-synthesized-fonts
6081 is non-nil and this is a plain font. */
6082 if (w32_enable_synthesized_fonts
6083 && lplf
->elfLogFont
.lfWeight
== FW_NORMAL
6084 && lplf
->elfLogFont
.lfItalic
== FALSE
)
6087 lplf
->elfLogFont
.lfWeight
= FW_BOLD
;
6088 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
6091 lplf
->elfLogFont
.lfItalic
= TRUE
;
6092 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
6095 lplf
->elfLogFont
.lfWeight
= FW_NORMAL
;
6096 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
6106 enum_font_maybe_add_to_list (lpef
, logfont
, match_charset
, width
)
6109 char * match_charset
;
6114 if (!w32_to_x_font (logfont
, buf
, 100, match_charset
))
6117 if (NILP (lpef
->pattern
)
6118 || w32_font_match (buf
, SDATA (lpef
->pattern
)))
6120 /* Check if we already listed this font. This may happen if
6121 w32_enable_synthesized_fonts is non-nil, and there are real
6122 bold and italic versions of the font. */
6123 Lisp_Object font_name
= build_string (buf
);
6124 if (NILP (Fmember (font_name
, lpef
->list
)))
6126 Lisp_Object entry
= Fcons (font_name
, width
);
6127 lpef
->list
= Fcons (entry
, lpef
->list
);
6135 enum_font_cb1 (lplf
, lptm
, FontType
, lpef
)
6137 NEWTEXTMETRIC
* lptm
;
6141 return EnumFontFamilies (lpef
->hdc
,
6142 lplf
->elfLogFont
.lfFaceName
,
6143 (FONTENUMPROC
) enum_font_cb2
,
6149 enum_fontex_cb2 (lplf
, lptm
, font_type
, lpef
)
6150 ENUMLOGFONTEX
* lplf
;
6151 NEWTEXTMETRICEX
* lptm
;
6155 /* We are not interested in the extra info we get back from the 'Ex
6156 version - only the fact that we get character set variations
6157 enumerated seperately. */
6158 return enum_font_cb2 ((ENUMLOGFONT
*) lplf
, (NEWTEXTMETRIC
*) lptm
,
6163 enum_fontex_cb1 (lplf
, lptm
, font_type
, lpef
)
6164 ENUMLOGFONTEX
* lplf
;
6165 NEWTEXTMETRICEX
* lptm
;
6169 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6170 FARPROC enum_font_families_ex
6171 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6172 /* We don't really expect EnumFontFamiliesEx to disappear once we
6173 get here, so don't bother handling it gracefully. */
6174 if (enum_font_families_ex
== NULL
)
6175 error ("gdi32.dll has disappeared!");
6176 return enum_font_families_ex (lpef
->hdc
,
6178 (FONTENUMPROC
) enum_fontex_cb2
,
6182 /* Interface to fontset handler. (adapted from mw32font.c in Meadow
6183 and xterm.c in Emacs 20.3) */
6186 w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
)
6188 char *fontname
, *ptnstr
;
6189 Lisp_Object list
, tem
, newlist
= Qnil
;
6192 list
= Vw32_bdf_filename_alist
;
6193 ptnstr
= SDATA (pattern
);
6195 for ( ; CONSP (list
); list
= XCDR (list
))
6199 fontname
= SDATA (XCAR (tem
));
6200 else if (STRINGP (tem
))
6201 fontname
= SDATA (tem
);
6205 if (w32_font_match (fontname
, ptnstr
))
6207 newlist
= Fcons (XCAR (tem
), newlist
);
6209 if (max_names
>= 0 && n_fonts
>= max_names
)
6218 /* Return a list of names of available fonts matching PATTERN on frame
6219 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
6220 to be listed. Frame F NULL means we have not yet created any
6221 frame, which means we can't get proper size info, as we don't have
6222 a device context to use for GetTextMetrics.
6223 MAXNAMES sets a limit on how many fonts to match. If MAXNAMES is
6224 negative, then all matching fonts are returned. */
6227 w32_list_fonts (f
, pattern
, size
, maxnames
)
6229 Lisp_Object pattern
;
6233 Lisp_Object patterns
, key
= Qnil
, tem
, tpat
;
6234 Lisp_Object list
= Qnil
, newlist
= Qnil
, second_best
= Qnil
;
6235 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
6238 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
6239 if (NILP (patterns
))
6240 patterns
= Fcons (pattern
, Qnil
);
6242 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
6247 tpat
= XCAR (patterns
);
6249 if (!STRINGP (tpat
))
6252 /* Avoid expensive EnumFontFamilies functions if we are not
6253 going to be able to output one of these anyway. */
6254 codepage
= w32_codepage_for_font (SDATA (tpat
));
6255 if (codepage
!= CP_8BIT
&& codepage
!= CP_UNICODE
6256 && codepage
!= CP_DEFAULT
&& codepage
!= CP_UNKNOWN
6257 && !IsValidCodePage (codepage
))
6260 /* See if we cached the result for this particular query.
6261 The cache is an alist of the form:
6262 ((PATTERN (FONTNAME . WIDTH) ...) ...)
6264 if (tem
= XCDR (dpyinfo
->name_list_element
),
6265 !NILP (list
= Fassoc (tpat
, tem
)))
6267 list
= Fcdr_safe (list
);
6268 /* We have a cached list. Don't have to get the list again. */
6273 /* At first, put PATTERN in the cache. */
6278 /* Use EnumFontFamiliesEx where it is available, as it knows
6279 about character sets. Fall back to EnumFontFamilies for
6280 older versions of NT that don't support the 'Ex function. */
6281 x_to_w32_font (SDATA (tpat
), &ef
.logfont
);
6283 LOGFONT font_match_pattern
;
6284 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6285 FARPROC enum_font_families_ex
6286 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6288 /* We do our own pattern matching so we can handle wildcards. */
6289 font_match_pattern
.lfFaceName
[0] = 0;
6290 font_match_pattern
.lfPitchAndFamily
= 0;
6291 /* We can use the charset, because if it is a wildcard it will
6292 be DEFAULT_CHARSET anyway. */
6293 font_match_pattern
.lfCharSet
= ef
.logfont
.lfCharSet
;
6295 ef
.hdc
= GetDC (dpyinfo
->root_window
);
6297 if (enum_font_families_ex
)
6298 enum_font_families_ex (ef
.hdc
,
6299 &font_match_pattern
,
6300 (FONTENUMPROC
) enum_fontex_cb1
,
6303 EnumFontFamilies (ef
.hdc
, NULL
, (FONTENUMPROC
) enum_font_cb1
,
6306 ReleaseDC (dpyinfo
->root_window
, ef
.hdc
);
6312 /* Make a list of the fonts we got back.
6313 Store that in the font cache for the display. */
6314 XSETCDR (dpyinfo
->name_list_element
,
6315 Fcons (Fcons (tpat
, list
),
6316 XCDR (dpyinfo
->name_list_element
)));
6319 if (NILP (list
)) continue; /* Try the remaining alternatives. */
6321 newlist
= second_best
= Qnil
;
6323 /* Make a list of the fonts that have the right width. */
6324 for (; CONSP (list
); list
= XCDR (list
))
6331 if (NILP (XCAR (tem
)))
6335 newlist
= Fcons (XCAR (tem
), newlist
);
6337 if (maxnames
>= 0 && n_fonts
>= maxnames
)
6342 if (!INTEGERP (XCDR (tem
)))
6344 /* Since we don't yet know the size of the font, we must
6345 load it and try GetTextMetrics. */
6346 W32FontStruct thisinfo
;
6351 if (!x_to_w32_font (SDATA (XCAR (tem
)), &lf
))
6355 thisinfo
.bdf
= NULL
;
6356 thisinfo
.hfont
= CreateFontIndirect (&lf
);
6357 if (thisinfo
.hfont
== NULL
)
6360 hdc
= GetDC (dpyinfo
->root_window
);
6361 oldobj
= SelectObject (hdc
, thisinfo
.hfont
);
6362 if (GetTextMetrics (hdc
, &thisinfo
.tm
))
6363 XSETCDR (tem
, make_number (FONT_AVG_WIDTH (&thisinfo
)));
6365 XSETCDR (tem
, make_number (0));
6366 SelectObject (hdc
, oldobj
);
6367 ReleaseDC (dpyinfo
->root_window
, hdc
);
6368 DeleteObject (thisinfo
.hfont
);
6371 found_size
= XINT (XCDR (tem
));
6372 if (found_size
== size
)
6374 newlist
= Fcons (XCAR (tem
), newlist
);
6376 if (maxnames
>= 0 && n_fonts
>= maxnames
)
6379 /* keep track of the closest matching size in case
6380 no exact match is found. */
6381 else if (found_size
> 0)
6383 if (NILP (second_best
))
6386 else if (found_size
< size
)
6388 if (XINT (XCDR (second_best
)) > size
6389 || XINT (XCDR (second_best
)) < found_size
)
6394 if (XINT (XCDR (second_best
)) > size
6395 && XINT (XCDR (second_best
)) >
6402 if (!NILP (newlist
))
6404 else if (!NILP (second_best
))
6406 newlist
= Fcons (XCAR (second_best
), Qnil
);
6411 /* Include any bdf fonts. */
6412 if (n_fonts
< maxnames
|| maxnames
< 0)
6414 Lisp_Object combined
[2];
6415 combined
[0] = w32_list_bdf_fonts (pattern
, maxnames
- n_fonts
);
6416 combined
[1] = newlist
;
6417 newlist
= Fnconc (2, combined
);
6424 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
6426 w32_get_font_info (f
, font_idx
)
6430 return (FRAME_W32_FONT_TABLE (f
) + font_idx
);
6435 w32_query_font (struct frame
*f
, char *fontname
)
6438 struct font_info
*pfi
;
6440 pfi
= FRAME_W32_FONT_TABLE (f
);
6442 for (i
= 0; i
< one_w32_display_info
.n_fonts
;i
++, pfi
++)
6444 if (stricmp (pfi
->name
, fontname
) == 0) return pfi
;
6450 /* Find a CCL program for a font specified by FONTP, and set the member
6451 `encoder' of the structure. */
6454 w32_find_ccl_program (fontp
)
6455 struct font_info
*fontp
;
6457 Lisp_Object list
, elt
;
6459 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
6463 && STRINGP (XCAR (elt
))
6464 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
6470 struct ccl_program
*ccl
6471 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
6473 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
6476 fontp
->font_encoder
= ccl
;
6480 /* directory-files from dired.c. */
6481 Lisp_Object Fdirectory_files
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
, Lisp_Object
));
6484 /* Find BDF files in a specified directory. (use GCPRO when calling,
6485 as this calls lisp to get a directory listing). */
6487 w32_find_bdf_fonts_in_dir (Lisp_Object directory
)
6489 Lisp_Object filelist
, list
= Qnil
;
6492 if (!STRINGP (directory
))
6495 filelist
= Fdirectory_files (directory
, Qt
,
6496 build_string (".*\\.[bB][dD][fF]"), Qt
);
6498 for ( ; CONSP (filelist
); filelist
= XCDR (filelist
))
6500 Lisp_Object filename
= XCAR (filelist
);
6501 if (w32_BDF_to_x_font (SDATA (filename
), fontname
, 100))
6502 store_in_alist (&list
, build_string (fontname
), filename
);
6507 DEFUN ("w32-find-bdf-fonts", Fw32_find_bdf_fonts
, Sw32_find_bdf_fonts
,
6509 doc
: /* Return a list of BDF fonts in DIRECTORY.
6510 The list is suitable for appending to `w32-bdf-filename-alist'.
6511 Fonts which do not contain an xlfd description will not be included
6512 in the list. DIRECTORY may be a list of directories. */)
6514 Lisp_Object directory
;
6516 Lisp_Object list
= Qnil
;
6517 struct gcpro gcpro1
, gcpro2
;
6519 if (!CONSP (directory
))
6520 return w32_find_bdf_fonts_in_dir (directory
);
6522 for ( ; CONSP (directory
); directory
= XCDR (directory
))
6524 Lisp_Object pair
[2];
6527 GCPRO2 (directory
, list
);
6528 pair
[1] = w32_find_bdf_fonts_in_dir ( XCAR (directory
) );
6529 list
= Fnconc ( 2, pair
);
6536 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
6537 doc
: /* Internal function called by `color-defined-p', which see. */)
6539 Lisp_Object color
, frame
;
6542 FRAME_PTR f
= check_x_frame (frame
);
6544 CHECK_STRING (color
);
6546 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
6552 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
6553 doc
: /* Internal function called by `color-values', which see. */)
6555 Lisp_Object color
, frame
;
6558 FRAME_PTR f
= check_x_frame (frame
);
6560 CHECK_STRING (color
);
6562 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
6563 return list3 (make_number ((GetRValue (foo
.pixel
) << 8)
6564 | GetRValue (foo
.pixel
)),
6565 make_number ((GetGValue (foo
.pixel
) << 8)
6566 | GetGValue (foo
.pixel
)),
6567 make_number ((GetBValue (foo
.pixel
) << 8)
6568 | GetBValue (foo
.pixel
)));
6573 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
6574 doc
: /* Internal function called by `display-color-p', which see. */)
6576 Lisp_Object display
;
6578 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6580 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
6586 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
,
6587 Sx_display_grayscale_p
, 0, 1, 0,
6588 doc
: /* Return t if DISPLAY supports shades of gray.
6589 Note that color displays do support shades of gray.
6590 The optional argument DISPLAY specifies which display to ask about.
6591 DISPLAY should be either a frame or a display name (a string).
6592 If omitted or nil, that stands for the selected frame's display. */)
6594 Lisp_Object display
;
6596 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6598 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
6604 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
,
6605 Sx_display_pixel_width
, 0, 1, 0,
6606 doc
: /* Return the width in pixels of DISPLAY.
6607 The optional argument DISPLAY specifies which display to ask about.
6608 DISPLAY should be either a frame or a display name (a string).
6609 If omitted or nil, that stands for the selected frame's display. */)
6611 Lisp_Object display
;
6613 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6615 return make_number (dpyinfo
->width
);
6618 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
6619 Sx_display_pixel_height
, 0, 1, 0,
6620 doc
: /* Return the height in pixels of DISPLAY.
6621 The optional argument DISPLAY specifies which display to ask about.
6622 DISPLAY should be either a frame or a display name (a string).
6623 If omitted or nil, that stands for the selected frame's display. */)
6625 Lisp_Object display
;
6627 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6629 return make_number (dpyinfo
->height
);
6632 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
6634 doc
: /* Return the number of bitplanes of DISPLAY.
6635 The optional argument DISPLAY specifies which display to ask about.
6636 DISPLAY should be either a frame or a display name (a string).
6637 If omitted or nil, that stands for the selected frame's display. */)
6639 Lisp_Object display
;
6641 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6643 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
6646 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
6648 doc
: /* Return the number of color cells of DISPLAY.
6649 The optional argument DISPLAY specifies which display to ask about.
6650 DISPLAY should be either a frame or a display name (a string).
6651 If omitted or nil, that stands for the selected frame's display. */)
6653 Lisp_Object display
;
6655 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6659 hdc
= GetDC (dpyinfo
->root_window
);
6660 if (dpyinfo
->has_palette
)
6661 cap
= GetDeviceCaps (hdc
, SIZEPALETTE
);
6663 cap
= GetDeviceCaps (hdc
, NUMCOLORS
);
6665 /* We force 24+ bit depths to 24-bit, both to prevent an overflow
6666 and because probably is more meaningful on Windows anyway */
6668 cap
= 1 << min (dpyinfo
->n_planes
* dpyinfo
->n_cbits
, 24);
6670 ReleaseDC (dpyinfo
->root_window
, hdc
);
6672 return make_number (cap
);
6675 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
6676 Sx_server_max_request_size
,
6678 doc
: /* Return the maximum request size of the server of DISPLAY.
6679 The optional argument DISPLAY specifies which display to ask about.
6680 DISPLAY should be either a frame or a display name (a string).
6681 If omitted or nil, that stands for the selected frame's display. */)
6683 Lisp_Object display
;
6685 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6687 return make_number (1);
6690 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
6691 doc
: /* Return the "vendor ID" string of the W32 system (Microsoft).
6692 The optional argument DISPLAY specifies which display to ask about.
6693 DISPLAY should be either a frame or a display name (a string).
6694 If omitted or nil, that stands for the selected frame's display. */)
6696 Lisp_Object display
;
6698 return build_string ("Microsoft Corp.");
6701 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
6702 doc
: /* Return the version numbers of the server of DISPLAY.
6703 The value is a list of three integers: the major and minor
6704 version numbers of the X Protocol in use, and the distributor-specific
6705 release number. See also the function `x-server-vendor'.
6707 The optional argument DISPLAY specifies which display to ask about.
6708 DISPLAY should be either a frame or a display name (a string).
6709 If omitted or nil, that stands for the selected frame's display. */)
6711 Lisp_Object display
;
6713 return Fcons (make_number (w32_major_version
),
6714 Fcons (make_number (w32_minor_version
),
6715 Fcons (make_number (w32_build_number
), Qnil
)));
6718 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
6719 doc
: /* Return the number of screens on the server of DISPLAY.
6720 The optional argument DISPLAY specifies which display to ask about.
6721 DISPLAY should be either a frame or a display name (a string).
6722 If omitted or nil, that stands for the selected frame's display. */)
6724 Lisp_Object display
;
6726 return make_number (1);
6729 DEFUN ("x-display-mm-height", Fx_display_mm_height
,
6730 Sx_display_mm_height
, 0, 1, 0,
6731 doc
: /* Return the height in millimeters of DISPLAY.
6732 The optional argument DISPLAY specifies which display to ask about.
6733 DISPLAY should be either a frame or a display name (a string).
6734 If omitted or nil, that stands for the selected frame's display. */)
6736 Lisp_Object display
;
6738 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6742 hdc
= GetDC (dpyinfo
->root_window
);
6744 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
6746 ReleaseDC (dpyinfo
->root_window
, hdc
);
6748 return make_number (cap
);
6751 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
6752 doc
: /* Return the width in millimeters of DISPLAY.
6753 The optional argument DISPLAY specifies which display to ask about.
6754 DISPLAY should be either a frame or a display name (a string).
6755 If omitted or nil, that stands for the selected frame's display. */)
6757 Lisp_Object display
;
6759 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6764 hdc
= GetDC (dpyinfo
->root_window
);
6766 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
6768 ReleaseDC (dpyinfo
->root_window
, hdc
);
6770 return make_number (cap
);
6773 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
6774 Sx_display_backing_store
, 0, 1, 0,
6775 doc
: /* Return an indication of whether DISPLAY does backing store.
6776 The value may be `always', `when-mapped', or `not-useful'.
6777 The optional argument DISPLAY specifies which display to ask about.
6778 DISPLAY should be either a frame or a display name (a string).
6779 If omitted or nil, that stands for the selected frame's display. */)
6781 Lisp_Object display
;
6783 return intern ("not-useful");
6786 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
6787 Sx_display_visual_class
, 0, 1, 0,
6788 doc
: /* Return the visual class of DISPLAY.
6789 The value is one of the symbols `static-gray', `gray-scale',
6790 `static-color', `pseudo-color', `true-color', or `direct-color'.
6792 The optional argument DISPLAY specifies which display to ask about.
6793 DISPLAY should be either a frame or a display name (a string).
6794 If omitted or nil, that stands for the selected frame's display. */)
6796 Lisp_Object display
;
6798 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6799 Lisp_Object result
= Qnil
;
6801 if (dpyinfo
->has_palette
)
6802 result
= intern ("pseudo-color");
6803 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
6804 result
= intern ("static-grey");
6805 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
6806 result
= intern ("static-color");
6807 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
6808 result
= intern ("true-color");
6813 DEFUN ("x-display-save-under", Fx_display_save_under
,
6814 Sx_display_save_under
, 0, 1, 0,
6815 doc
: /* Return t if DISPLAY supports the save-under feature.
6816 The optional argument DISPLAY specifies which display to ask about.
6817 DISPLAY should be either a frame or a display name (a string).
6818 If omitted or nil, that stands for the selected frame's display. */)
6820 Lisp_Object display
;
6827 register struct frame
*f
;
6829 return FRAME_PIXEL_WIDTH (f
);
6834 register struct frame
*f
;
6836 return FRAME_PIXEL_HEIGHT (f
);
6841 register struct frame
*f
;
6843 return FRAME_COLUMN_WIDTH (f
);
6848 register struct frame
*f
;
6850 return FRAME_LINE_HEIGHT (f
);
6855 register struct frame
*f
;
6857 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
6860 /* Return the display structure for the display named NAME.
6861 Open a new connection if necessary. */
6863 struct w32_display_info
*
6864 x_display_info_for_name (name
)
6868 struct w32_display_info
*dpyinfo
;
6870 CHECK_STRING (name
);
6872 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
6874 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
6877 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
6882 /* Use this general default value to start with. */
6883 Vx_resource_name
= Vinvocation_name
;
6885 validate_x_resource_name ();
6887 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
6888 (char *) SDATA (Vx_resource_name
));
6891 error ("Cannot connect to server %s", SDATA (name
));
6894 XSETFASTINT (Vwindow_system_version
, 3);
6899 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
6900 1, 3, 0, doc
: /* Open a connection to a server.
6901 DISPLAY is the name of the display to connect to.
6902 Optional second arg XRM-STRING is a string of resources in xrdb format.
6903 If the optional third arg MUST-SUCCEED is non-nil,
6904 terminate Emacs if we can't open the connection. */)
6905 (display
, xrm_string
, must_succeed
)
6906 Lisp_Object display
, xrm_string
, must_succeed
;
6908 unsigned char *xrm_option
;
6909 struct w32_display_info
*dpyinfo
;
6911 /* If initialization has already been done, return now to avoid
6912 overwriting critical parts of one_w32_display_info. */
6916 CHECK_STRING (display
);
6917 if (! NILP (xrm_string
))
6918 CHECK_STRING (xrm_string
);
6921 if (! EQ (Vwindow_system
, intern ("w32")))
6922 error ("Not using Microsoft Windows");
6925 /* Allow color mapping to be defined externally; first look in user's
6926 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
6928 Lisp_Object color_file
;
6929 struct gcpro gcpro1
;
6931 color_file
= build_string ("~/rgb.txt");
6933 GCPRO1 (color_file
);
6935 if (NILP (Ffile_readable_p (color_file
)))
6937 Fexpand_file_name (build_string ("rgb.txt"),
6938 Fsymbol_value (intern ("data-directory")));
6940 Vw32_color_map
= Fw32_load_color_file (color_file
);
6944 if (NILP (Vw32_color_map
))
6945 Vw32_color_map
= Fw32_default_color_map ();
6947 /* Merge in system logical colors. */
6948 add_system_logical_colors_to_map (&Vw32_color_map
);
6950 if (! NILP (xrm_string
))
6951 xrm_option
= (unsigned char *) SDATA (xrm_string
);
6953 xrm_option
= (unsigned char *) 0;
6955 /* Use this general default value to start with. */
6956 /* First remove .exe suffix from invocation-name - it looks ugly. */
6958 char basename
[ MAX_PATH
], *str
;
6960 strcpy (basename
, SDATA (Vinvocation_name
));
6961 str
= strrchr (basename
, '.');
6963 Vinvocation_name
= build_string (basename
);
6965 Vx_resource_name
= Vinvocation_name
;
6967 validate_x_resource_name ();
6969 /* This is what opens the connection and sets x_current_display.
6970 This also initializes many symbols, such as those used for input. */
6971 dpyinfo
= w32_term_init (display
, xrm_option
,
6972 (char *) SDATA (Vx_resource_name
));
6976 if (!NILP (must_succeed
))
6977 fatal ("Cannot connect to server %s.\n",
6980 error ("Cannot connect to server %s", SDATA (display
));
6985 XSETFASTINT (Vwindow_system_version
, 3);
6989 DEFUN ("x-close-connection", Fx_close_connection
,
6990 Sx_close_connection
, 1, 1, 0,
6991 doc
: /* Close the connection to DISPLAY's server.
6992 For DISPLAY, specify either a frame or a display name (a string).
6993 If DISPLAY is nil, that stands for the selected frame's display. */)
6995 Lisp_Object display
;
6997 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7000 if (dpyinfo
->reference_count
> 0)
7001 error ("Display still has frames on it");
7004 /* Free the fonts in the font table. */
7005 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
7006 if (dpyinfo
->font_table
[i
].name
)
7008 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
7009 xfree (dpyinfo
->font_table
[i
].full_name
);
7010 xfree (dpyinfo
->font_table
[i
].name
);
7011 w32_unload_font (dpyinfo
, dpyinfo
->font_table
[i
].font
);
7013 x_destroy_all_bitmaps (dpyinfo
);
7015 x_delete_display (dpyinfo
);
7021 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
7022 doc
: /* Return the list of display names that Emacs has connections to. */)
7025 Lisp_Object tail
, result
;
7028 for (tail
= w32_display_name_list
; CONSP (tail
); tail
= XCDR (tail
))
7029 result
= Fcons (XCAR (XCAR (tail
)), result
);
7034 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
7035 doc
: /* This is a noop on W32 systems. */)
7037 Lisp_Object display
, on
;
7044 /***********************************************************************
7046 ***********************************************************************/
7048 DEFUN ("x-change-window-property", Fx_change_window_property
,
7049 Sx_change_window_property
, 2, 6, 0,
7050 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
7051 VALUE may be a string or a list of conses, numbers and/or strings.
7052 If an element in the list is a string, it is converted to
7053 an Atom and the value of the Atom is used. If an element is a cons,
7054 it is converted to a 32 bit number where the car is the 16 top bits and the
7055 cdr is the lower 16 bits.
7056 FRAME nil or omitted means use the selected frame.
7057 If TYPE is given and non-nil, it is the name of the type of VALUE.
7058 If TYPE is not given or nil, the type is STRING.
7059 FORMAT gives the size in bits of each element if VALUE is a list.
7060 It must be one of 8, 16 or 32.
7061 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
7062 If OUTER_P is non-nil, the property is changed for the outer X window of
7063 FRAME. Default is to change on the edit X window.
7066 (prop
, value
, frame
, type
, format
, outer_p
)
7067 Lisp_Object prop
, value
, frame
, type
, format
, outer_p
;
7069 #if 0 /* TODO : port window properties to W32 */
7070 struct frame
*f
= check_x_frame (frame
);
7073 CHECK_STRING (prop
);
7074 CHECK_STRING (value
);
7077 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
7078 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
7079 prop_atom
, XA_STRING
, 8, PropModeReplace
,
7080 SDATA (value
), SCHARS (value
));
7082 /* Make sure the property is set when we return. */
7083 XFlush (FRAME_W32_DISPLAY (f
));
7092 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
7093 Sx_delete_window_property
, 1, 2, 0,
7094 doc
: /* Remove window property PROP from X window of FRAME.
7095 FRAME nil or omitted means use the selected frame. Value is PROP. */)
7097 Lisp_Object prop
, frame
;
7099 #if 0 /* TODO : port window properties to W32 */
7101 struct frame
*f
= check_x_frame (frame
);
7104 CHECK_STRING (prop
);
7106 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
7107 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
7109 /* Make sure the property is removed when we return. */
7110 XFlush (FRAME_W32_DISPLAY (f
));
7118 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
7120 doc
: /* Value is the value of window property PROP on FRAME.
7121 If FRAME is nil or omitted, use the selected frame. Value is nil
7122 if FRAME hasn't a property with name PROP or if PROP has no string
7125 Lisp_Object prop
, frame
;
7127 #if 0 /* TODO : port window properties to W32 */
7129 struct frame
*f
= check_x_frame (frame
);
7132 Lisp_Object prop_value
= Qnil
;
7133 char *tmp_data
= NULL
;
7136 unsigned long actual_size
, bytes_remaining
;
7138 CHECK_STRING (prop
);
7140 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
7141 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
7142 prop_atom
, 0, 0, False
, XA_STRING
,
7143 &actual_type
, &actual_format
, &actual_size
,
7144 &bytes_remaining
, (unsigned char **) &tmp_data
);
7147 int size
= bytes_remaining
;
7152 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
7153 prop_atom
, 0, bytes_remaining
,
7155 &actual_type
, &actual_format
,
7156 &actual_size
, &bytes_remaining
,
7157 (unsigned char **) &tmp_data
);
7159 prop_value
= make_string (tmp_data
, size
);
7174 /***********************************************************************
7176 ***********************************************************************/
7178 /* If non-null, an asynchronous timer that, when it expires, displays
7179 an hourglass cursor on all frames. */
7181 static struct atimer
*hourglass_atimer
;
7183 /* Non-zero means an hourglass cursor is currently shown. */
7185 static int hourglass_shown_p
;
7187 /* Number of seconds to wait before displaying an hourglass cursor. */
7189 static Lisp_Object Vhourglass_delay
;
7191 /* Default number of seconds to wait before displaying an hourglass
7194 #define DEFAULT_HOURGLASS_DELAY 1
7196 /* Function prototypes. */
7198 static void show_hourglass
P_ ((struct atimer
*));
7199 static void hide_hourglass
P_ ((void));
7202 /* Cancel a currently active hourglass timer, and start a new one. */
7207 #if 0 /* TODO: cursor shape changes. */
7209 int secs
, usecs
= 0;
7211 cancel_hourglass ();
7213 if (INTEGERP (Vhourglass_delay
)
7214 && XINT (Vhourglass_delay
) > 0)
7215 secs
= XFASTINT (Vhourglass_delay
);
7216 else if (FLOATP (Vhourglass_delay
)
7217 && XFLOAT_DATA (Vhourglass_delay
) > 0)
7220 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
7221 secs
= XFASTINT (tem
);
7222 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
7225 secs
= DEFAULT_HOURGLASS_DELAY
;
7227 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
7228 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
7229 show_hourglass
, NULL
);
7234 /* Cancel the hourglass cursor timer if active, hide an hourglass
7240 if (hourglass_atimer
)
7242 cancel_atimer (hourglass_atimer
);
7243 hourglass_atimer
= NULL
;
7246 if (hourglass_shown_p
)
7251 /* Timer function of hourglass_atimer. TIMER is equal to
7254 Display an hourglass cursor on all frames by mapping the frames'
7255 hourglass_window. Set the hourglass_p flag in the frames'
7256 output_data.x structure to indicate that an hourglass cursor is
7257 shown on the frames. */
7260 show_hourglass (timer
)
7261 struct atimer
*timer
;
7263 #if 0 /* TODO: cursor shape changes. */
7264 /* The timer implementation will cancel this timer automatically
7265 after this function has run. Set hourglass_atimer to null
7266 so that we know the timer doesn't have to be canceled. */
7267 hourglass_atimer
= NULL
;
7269 if (!hourglass_shown_p
)
7271 Lisp_Object rest
, frame
;
7275 FOR_EACH_FRAME (rest
, frame
)
7276 if (FRAME_W32_P (XFRAME (frame
)))
7278 struct frame
*f
= XFRAME (frame
);
7280 f
->output_data
.w32
->hourglass_p
= 1;
7282 if (!f
->output_data
.w32
->hourglass_window
)
7284 unsigned long mask
= CWCursor
;
7285 XSetWindowAttributes attrs
;
7287 attrs
.cursor
= f
->output_data
.w32
->hourglass_cursor
;
7289 f
->output_data
.w32
->hourglass_window
7290 = XCreateWindow (FRAME_X_DISPLAY (f
),
7291 FRAME_OUTER_WINDOW (f
),
7292 0, 0, 32000, 32000, 0, 0,
7298 XMapRaised (FRAME_X_DISPLAY (f
),
7299 f
->output_data
.w32
->hourglass_window
);
7300 XFlush (FRAME_X_DISPLAY (f
));
7303 hourglass_shown_p
= 1;
7310 /* Hide the hourglass cursor on all frames, if it is currently shown. */
7315 #if 0 /* TODO: cursor shape changes. */
7316 if (hourglass_shown_p
)
7318 Lisp_Object rest
, frame
;
7321 FOR_EACH_FRAME (rest
, frame
)
7323 struct frame
*f
= XFRAME (frame
);
7326 /* Watch out for newly created frames. */
7327 && f
->output_data
.x
->hourglass_window
)
7329 XUnmapWindow (FRAME_X_DISPLAY (f
),
7330 f
->output_data
.x
->hourglass_window
);
7331 /* Sync here because XTread_socket looks at the
7332 hourglass_p flag that is reset to zero below. */
7333 XSync (FRAME_X_DISPLAY (f
), False
);
7334 f
->output_data
.x
->hourglass_p
= 0;
7338 hourglass_shown_p
= 0;
7346 /***********************************************************************
7348 ***********************************************************************/
7350 static Lisp_Object x_create_tip_frame
P_ ((struct w32_display_info
*,
7351 Lisp_Object
, Lisp_Object
));
7352 static void compute_tip_xy
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
7353 Lisp_Object
, int, int, int *, int *));
7355 /* The frame of a currently visible tooltip. */
7357 Lisp_Object tip_frame
;
7359 /* If non-nil, a timer started that hides the last tooltip when it
7362 Lisp_Object tip_timer
;
7365 /* If non-nil, a vector of 3 elements containing the last args
7366 with which x-show-tip was called. See there. */
7368 Lisp_Object last_show_tip_args
;
7370 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
7372 Lisp_Object Vx_max_tooltip_size
;
7376 unwind_create_tip_frame (frame
)
7379 Lisp_Object deleted
;
7381 deleted
= unwind_create_frame (frame
);
7382 if (EQ (deleted
, Qt
))
7392 /* Create a frame for a tooltip on the display described by DPYINFO.
7393 PARMS is a list of frame parameters. TEXT is the string to
7394 display in the tip frame. Value is the frame.
7396 Note that functions called here, esp. x_default_parameter can
7397 signal errors, for instance when a specified color name is
7398 undefined. We have to make sure that we're in a consistent state
7399 when this happens. */
7402 x_create_tip_frame (dpyinfo
, parms
, text
)
7403 struct w32_display_info
*dpyinfo
;
7404 Lisp_Object parms
, text
;
7407 Lisp_Object frame
, tem
;
7409 long window_prompting
= 0;
7411 int count
= SPECPDL_INDEX ();
7412 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7414 int face_change_count_before
= face_change_count
;
7416 struct buffer
*old_buffer
;
7420 /* Use this general default value to start with until we know if
7421 this frame has a specified name. */
7422 Vx_resource_name
= Vinvocation_name
;
7425 kb
= dpyinfo
->terminal
->kboard
;
7427 kb
= &the_only_kboard
;
7430 /* Get the name of the frame to use for resource lookup. */
7431 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
7433 && !EQ (name
, Qunbound
)
7435 error ("Invalid frame name--not a string or nil");
7436 Vx_resource_name
= name
;
7439 GCPRO3 (parms
, name
, frame
);
7440 /* Make a frame without minibuffer nor mode-line. */
7442 f
->wants_modeline
= 0;
7443 XSETFRAME (frame
, f
);
7445 buffer
= Fget_buffer_create (build_string (" *tip*"));
7446 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, Qnil
);
7447 old_buffer
= current_buffer
;
7448 set_buffer_internal_1 (XBUFFER (buffer
));
7449 current_buffer
->truncate_lines
= Qnil
;
7450 specbind (Qinhibit_read_only
, Qt
);
7451 specbind (Qinhibit_modification_hooks
, Qt
);
7454 set_buffer_internal_1 (old_buffer
);
7456 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
7457 record_unwind_protect (unwind_create_tip_frame
, frame
);
7459 /* By setting the output method, we're essentially saying that
7460 the frame is live, as per FRAME_LIVE_P. If we get a signal
7461 from this point on, x_destroy_window might screw up reference
7463 f
->terminal
= dpyinfo
->terminal
;
7464 f
->terminal
->reference_count
++;
7465 f
->output_method
= output_w32
;
7466 f
->output_data
.w32
=
7467 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
7468 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
7470 FRAME_FONTSET (f
) = -1;
7471 f
->icon_name
= Qnil
;
7473 #if 0 /* GLYPH_DEBUG TODO: image support. */
7474 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
7475 dpyinfo_refcount
= dpyinfo
->reference_count
;
7476 #endif /* GLYPH_DEBUG */
7478 FRAME_KBOARD (f
) = kb
;
7480 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
7481 f
->output_data
.w32
->explicit_parent
= 0;
7483 /* Set the name; the functions to which we pass f expect the name to
7485 if (EQ (name
, Qunbound
) || NILP (name
))
7487 f
->name
= build_string (dpyinfo
->w32_id_name
);
7488 f
->explicit_name
= 0;
7493 f
->explicit_name
= 1;
7494 /* use the frame's title when getting resources for this frame. */
7495 specbind (Qx_resource_name
, name
);
7498 f
->resx
= dpyinfo
->resx
;
7499 f
->resy
= dpyinfo
->resy
;
7501 #ifdef USE_FONT_BACKEND
7502 if (enable_font_backend
)
7504 /* Perhaps, we must allow frame parameter, say `font-backend',
7505 to specify which font backends to use. */
7506 register_font_driver (&w32font_driver
, f
);
7508 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
7509 "fontBackend", "FontBackend", RES_TYPE_STRING
);
7511 #endif /* USE_FONT_BACKEND */
7513 /* Extract the window parameters from the supplied values
7514 that are needed to determine window geometry. */
7515 #ifdef USE_FONT_BACKEND
7516 if (enable_font_backend
)
7517 x_default_font_parameter (f
, parms
);
7519 #endif /* USE_FONT_BACKEND */
7523 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
7526 /* First, try whatever font the caller has specified. */
7529 tem
= Fquery_fontset (font
, Qnil
);
7531 font
= x_new_fontset (f
, tem
);
7533 font
= x_new_font (f
, SDATA (font
));
7536 /* Try out a font which we hope has bold and italic variations. */
7537 if (!STRINGP (font
))
7538 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
7539 if (! STRINGP (font
))
7540 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
7541 /* If those didn't work, look for something which will at least work. */
7542 if (! STRINGP (font
))
7543 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
7545 if (! STRINGP (font
))
7546 font
= build_string ("Fixedsys");
7548 x_default_parameter (f
, parms
, Qfont
, font
,
7549 "font", "Font", RES_TYPE_STRING
);
7552 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
7553 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
7554 /* This defaults to 2 in order to match xterm. We recognize either
7555 internalBorderWidth or internalBorder (which is what xterm calls
7557 if (NILP (Fassq (Qinternal_border_width
, parms
)))
7561 value
= w32_get_arg (parms
, Qinternal_border_width
,
7562 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
7563 if (! EQ (value
, Qunbound
))
7564 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
7567 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
7568 "internalBorderWidth", "internalBorderWidth",
7571 /* Also do the stuff which must be set before the window exists. */
7572 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
7573 "foreground", "Foreground", RES_TYPE_STRING
);
7574 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
7575 "background", "Background", RES_TYPE_STRING
);
7576 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
7577 "pointerColor", "Foreground", RES_TYPE_STRING
);
7578 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
7579 "cursorColor", "Foreground", RES_TYPE_STRING
);
7580 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
7581 "borderColor", "BorderColor", RES_TYPE_STRING
);
7583 /* Init faces before x_default_parameter is called for scroll-bar
7584 parameters because that function calls x_set_scroll_bar_width,
7585 which calls change_frame_size, which calls Fset_window_buffer,
7586 which runs hooks, which call Fvertical_motion. At the end, we
7587 end up in init_iterator with a null face cache, which should not
7589 init_frame_faces (f
);
7591 f
->output_data
.w32
->dwStyle
= WS_BORDER
| WS_POPUP
| WS_DISABLED
;
7592 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
7594 window_prompting
= x_figure_window_size (f
, parms
, 0);
7596 /* No fringes on tip frame. */
7598 f
->left_fringe_width
= 0;
7599 f
->right_fringe_width
= 0;
7602 my_create_tip_window (f
);
7607 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
7608 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
7609 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
7610 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
7611 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
7612 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
7614 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
7615 Change will not be effected unless different from the current
7617 width
= FRAME_COLS (f
);
7618 height
= FRAME_LINES (f
);
7619 FRAME_LINES (f
) = 0;
7620 SET_FRAME_COLS (f
, 0);
7621 change_frame_size (f
, height
, width
, 1, 0, 0);
7623 /* Add `tooltip' frame parameter's default value. */
7624 if (NILP (Fframe_parameter (frame
, intern ("tooltip"))))
7625 Fmodify_frame_parameters (frame
, Fcons (Fcons (intern ("tooltip"), Qt
),
7628 /* Set up faces after all frame parameters are known. This call
7629 also merges in face attributes specified for new frames.
7631 Frame parameters may be changed if .Xdefaults contains
7632 specifications for the default font. For example, if there is an
7633 `Emacs.default.attributeBackground: pink', the `background-color'
7634 attribute of the frame get's set, which let's the internal border
7635 of the tooltip frame appear in pink. Prevent this. */
7637 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
7639 /* Set tip_frame here, so that */
7641 call1 (Qface_set_after_frame_default
, frame
);
7643 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
7644 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qbackground_color
, bg
),
7652 /* It is now ok to make the frame official even if we get an error
7653 below. And the frame needs to be on Vframe_list or making it
7654 visible won't work. */
7655 Vframe_list
= Fcons (frame
, Vframe_list
);
7657 /* Now that the frame is official, it counts as a reference to
7659 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
7661 /* Setting attributes of faces of the tooltip frame from resources
7662 and similar will increment face_change_count, which leads to the
7663 clearing of all current matrices. Since this isn't necessary
7664 here, avoid it by resetting face_change_count to the value it
7665 had before we created the tip frame. */
7666 face_change_count
= face_change_count_before
;
7668 /* Discard the unwind_protect. */
7669 return unbind_to (count
, frame
);
7673 /* Compute where to display tip frame F. PARMS is the list of frame
7674 parameters for F. DX and DY are specified offsets from the current
7675 location of the mouse. WIDTH and HEIGHT are the width and height
7676 of the tooltip. Return coordinates relative to the root window of
7677 the display in *ROOT_X, and *ROOT_Y. */
7680 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, root_x
, root_y
)
7682 Lisp_Object parms
, dx
, dy
;
7684 int *root_x
, *root_y
;
7686 Lisp_Object left
, top
;
7688 /* User-specified position? */
7689 left
= Fcdr (Fassq (Qleft
, parms
));
7690 top
= Fcdr (Fassq (Qtop
, parms
));
7692 /* Move the tooltip window where the mouse pointer is. Resize and
7694 if (!INTEGERP (left
) || !INTEGERP (top
))
7706 *root_y
= XINT (top
);
7707 else if (*root_y
+ XINT (dy
) <= 0)
7708 *root_y
= 0; /* Can happen for negative dy */
7709 else if (*root_y
+ XINT (dy
) + height
<= FRAME_W32_DISPLAY_INFO (f
)->height
)
7710 /* It fits below the pointer */
7711 *root_y
+= XINT (dy
);
7712 else if (height
+ XINT (dy
) <= *root_y
)
7713 /* It fits above the pointer. */
7714 *root_y
-= height
+ XINT (dy
);
7716 /* Put it on the top. */
7719 if (INTEGERP (left
))
7720 *root_x
= XINT (left
);
7721 else if (*root_x
+ XINT (dx
) <= 0)
7722 *root_x
= 0; /* Can happen for negative dx */
7723 else if (*root_x
+ XINT (dx
) + width
<= FRAME_W32_DISPLAY_INFO (f
)->width
)
7724 /* It fits to the right of the pointer. */
7725 *root_x
+= XINT (dx
);
7726 else if (width
+ XINT (dx
) <= *root_x
)
7727 /* It fits to the left of the pointer. */
7728 *root_x
-= width
+ XINT (dx
);
7730 /* Put it left justified on the screen -- it ought to fit that way. */
7735 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
7736 doc
: /* Show STRING in a \"tooltip\" window on frame FRAME.
7737 A tooltip window is a small window displaying a string.
7739 This is an internal function; Lisp code should call `tooltip-show'.
7741 FRAME nil or omitted means use the selected frame.
7743 PARMS is an optional list of frame parameters which can be
7744 used to change the tooltip's appearance.
7746 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
7747 means use the default timeout of 5 seconds.
7749 If the list of frame parameters PARMS contains a `left' parameter,
7750 the tooltip is displayed at that x-position. Otherwise it is
7751 displayed at the mouse position, with offset DX added (default is 5 if
7752 DX isn't specified). Likewise for the y-position; if a `top' frame
7753 parameter is specified, it determines the y-position of the tooltip
7754 window, otherwise it is displayed at the mouse position, with offset
7755 DY added (default is -10).
7757 A tooltip's maximum size is specified by `x-max-tooltip-size'.
7758 Text larger than the specified size is clipped. */)
7759 (string
, frame
, parms
, timeout
, dx
, dy
)
7760 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
7765 struct buffer
*old_buffer
;
7766 struct text_pos pos
;
7767 int i
, width
, height
;
7768 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7769 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7770 int count
= SPECPDL_INDEX ();
7772 specbind (Qinhibit_redisplay
, Qt
);
7774 GCPRO4 (string
, parms
, frame
, timeout
);
7776 CHECK_STRING (string
);
7777 f
= check_x_frame (frame
);
7779 timeout
= make_number (5);
7781 CHECK_NATNUM (timeout
);
7784 dx
= make_number (5);
7789 dy
= make_number (-10);
7793 if (NILP (last_show_tip_args
))
7794 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
7796 if (!NILP (tip_frame
))
7798 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
7799 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
7800 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
7802 if (EQ (frame
, last_frame
)
7803 && !NILP (Fequal (last_string
, string
))
7804 && !NILP (Fequal (last_parms
, parms
)))
7806 struct frame
*f
= XFRAME (tip_frame
);
7808 /* Only DX and DY have changed. */
7809 if (!NILP (tip_timer
))
7811 Lisp_Object timer
= tip_timer
;
7813 call1 (Qcancel_timer
, timer
);
7817 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
7818 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
7820 /* Put tooltip in topmost group and in position. */
7821 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
7822 root_x
, root_y
, 0, 0,
7823 SWP_NOSIZE
| SWP_NOACTIVATE
);
7825 /* Ensure tooltip is on top of other topmost windows (eg menus). */
7826 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
7828 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
7835 /* Hide a previous tip, if any. */
7838 ASET (last_show_tip_args
, 0, string
);
7839 ASET (last_show_tip_args
, 1, frame
);
7840 ASET (last_show_tip_args
, 2, parms
);
7842 /* Add default values to frame parameters. */
7843 if (NILP (Fassq (Qname
, parms
)))
7844 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
7845 if (NILP (Fassq (Qinternal_border_width
, parms
)))
7846 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
7847 if (NILP (Fassq (Qborder_width
, parms
)))
7848 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
7849 if (NILP (Fassq (Qborder_color
, parms
)))
7850 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
7851 if (NILP (Fassq (Qbackground_color
, parms
)))
7852 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
7855 /* Block input until the tip has been fully drawn, to avoid crashes
7856 when drawing tips in menus. */
7859 /* Create a frame for the tooltip, and record it in the global
7860 variable tip_frame. */
7861 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
, string
);
7864 /* Set up the frame's root window. */
7865 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7866 w
->left_col
= w
->top_line
= make_number (0);
7868 if (CONSP (Vx_max_tooltip_size
)
7869 && INTEGERP (XCAR (Vx_max_tooltip_size
))
7870 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
7871 && INTEGERP (XCDR (Vx_max_tooltip_size
))
7872 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
7874 w
->total_cols
= XCAR (Vx_max_tooltip_size
);
7875 w
->total_lines
= XCDR (Vx_max_tooltip_size
);
7879 w
->total_cols
= make_number (80);
7880 w
->total_lines
= make_number (40);
7883 FRAME_TOTAL_COLS (f
) = XINT (w
->total_cols
);
7885 w
->pseudo_window_p
= 1;
7887 /* Display the tooltip text in a temporary buffer. */
7888 old_buffer
= current_buffer
;
7889 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
7890 current_buffer
->truncate_lines
= Qnil
;
7891 clear_glyph_matrix (w
->desired_matrix
);
7892 clear_glyph_matrix (w
->current_matrix
);
7893 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
7894 try_window (FRAME_ROOT_WINDOW (f
), pos
, 0);
7896 /* Compute width and height of the tooltip. */
7898 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
7900 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
7904 /* Stop at the first empty row at the end. */
7905 if (!row
->enabled_p
|| !row
->displays_text_p
)
7908 /* Let the row go over the full width of the frame. */
7909 row
->full_width_p
= 1;
7911 #ifdef TODO /* Investigate why some fonts need more width than is
7912 calculated for some tooltips. */
7913 /* There's a glyph at the end of rows that is use to place
7914 the cursor there. Don't include the width of this glyph. */
7915 if (row
->used
[TEXT_AREA
])
7917 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
7918 row_width
= row
->pixel_width
- last
->pixel_width
;
7922 row_width
= row
->pixel_width
;
7924 /* TODO: find why tips do not draw along baseline as instructed. */
7925 height
+= row
->height
;
7926 width
= max (width
, row_width
);
7929 /* Add the frame's internal border to the width and height the X
7930 window should have. */
7931 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
7932 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
7934 /* Move the tooltip window where the mouse pointer is. Resize and
7936 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
7939 /* Adjust Window size to take border into account. */
7941 rect
.left
= rect
.top
= 0;
7943 rect
.bottom
= height
;
7944 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
7945 FRAME_EXTERNAL_MENU_BAR (f
));
7947 /* Position and size tooltip, and put it in the topmost group.
7948 The add-on of 3 to the 5th argument is a kludge: without it,
7949 some fonts cause the last character of the tip to be truncated,
7950 for some obscure reason. */
7951 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
7952 root_x
, root_y
, rect
.right
- rect
.left
+ 3,
7953 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
);
7955 /* Ensure tooltip is on top of other topmost windows (eg menus). */
7956 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
7958 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
7960 /* Let redisplay know that we have made the frame visible already. */
7961 f
->async_visible
= 1;
7963 ShowWindow (FRAME_W32_WINDOW (f
), SW_SHOWNOACTIVATE
);
7966 /* Draw into the window. */
7967 w
->must_be_updated_p
= 1;
7968 update_single_window (w
, 1);
7972 /* Restore original current buffer. */
7973 set_buffer_internal_1 (old_buffer
);
7974 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7977 /* Let the tip disappear after timeout seconds. */
7978 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
7979 intern ("x-hide-tip"));
7982 return unbind_to (count
, Qnil
);
7986 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
7987 doc
: /* Hide the current tooltip window, if there is any.
7988 Value is t if tooltip was open, nil otherwise. */)
7992 Lisp_Object deleted
, frame
, timer
;
7993 struct gcpro gcpro1
, gcpro2
;
7995 /* Return quickly if nothing to do. */
7996 if (NILP (tip_timer
) && NILP (tip_frame
))
8001 GCPRO2 (frame
, timer
);
8002 tip_frame
= tip_timer
= deleted
= Qnil
;
8004 count
= SPECPDL_INDEX ();
8005 specbind (Qinhibit_redisplay
, Qt
);
8006 specbind (Qinhibit_quit
, Qt
);
8009 call1 (Qcancel_timer
, timer
);
8013 Fdelete_frame (frame
, Qnil
);
8018 return unbind_to (count
, deleted
);
8023 /***********************************************************************
8024 File selection dialog
8025 ***********************************************************************/
8026 extern Lisp_Object Qfile_name_history
;
8028 /* Callback for altering the behaviour of the Open File dialog.
8029 Makes the Filename text field contain "Current Directory" and be
8030 read-only when "Directories" is selected in the filter. This
8031 allows us to work around the fact that the standard Open File
8032 dialog does not support directories. */
8034 file_dialog_callback (hwnd
, msg
, wParam
, lParam
)
8040 if (msg
== WM_NOTIFY
)
8042 OFNOTIFY
* notify
= (OFNOTIFY
*)lParam
;
8043 /* Detect when the Filter dropdown is changed. */
8044 if (notify
->hdr
.code
== CDN_TYPECHANGE
8045 || notify
->hdr
.code
== CDN_INITDONE
)
8047 HWND dialog
= GetParent (hwnd
);
8048 HWND edit_control
= GetDlgItem (dialog
, FILE_NAME_TEXT_FIELD
);
8050 /* Directories is in index 2. */
8051 if (notify
->lpOFN
->nFilterIndex
== 2)
8053 CommDlg_OpenSave_SetControlText (dialog
, FILE_NAME_TEXT_FIELD
,
8054 "Current Directory");
8055 EnableWindow (edit_control
, FALSE
);
8059 /* Don't override default filename on init done. */
8060 if (notify
->hdr
.code
== CDN_TYPECHANGE
)
8061 CommDlg_OpenSave_SetControlText (dialog
,
8062 FILE_NAME_TEXT_FIELD
, "");
8063 EnableWindow (edit_control
, TRUE
);
8070 /* Since we compile with _WIN32_WINNT set to 0x0400 (for NT4 compatibility)
8071 we end up with the old file dialogs. Define a big enough struct for the
8072 new dialog to trick GetOpenFileName into giving us the new dialogs on
8073 Windows 2000 and XP. */
8076 OPENFILENAME real_details
;
8083 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
8084 doc
: /* Read file name, prompting with PROMPT in directory DIR.
8085 Use a file selection dialog.
8086 Select DEFAULT-FILENAME in the dialog's file selection box, if
8087 specified. Ensure that file exists if MUSTMATCH is non-nil.
8088 If ONLY-DIR-P is non-nil, the user can only select directories. */)
8089 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
)
8090 Lisp_Object prompt
, dir
, default_filename
, mustmatch
, only_dir_p
;
8092 struct frame
*f
= SELECTED_FRAME ();
8093 Lisp_Object file
= Qnil
;
8094 int count
= SPECPDL_INDEX ();
8095 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
8096 char filename
[MAX_PATH
+ 1];
8097 char init_dir
[MAX_PATH
+ 1];
8098 int default_filter_index
= 1; /* 1: All Files, 2: Directories only */
8100 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
8101 CHECK_STRING (prompt
);
8104 /* Create the dialog with PROMPT as title, using DIR as initial
8105 directory and using "*" as pattern. */
8106 dir
= Fexpand_file_name (dir
, Qnil
);
8107 strncpy (init_dir
, SDATA (ENCODE_FILE (dir
)), MAX_PATH
);
8108 init_dir
[MAX_PATH
] = '\0';
8109 unixtodos_filename (init_dir
);
8111 if (STRINGP (default_filename
))
8113 char *file_name_only
;
8114 char *full_path_name
= SDATA (ENCODE_FILE (default_filename
));
8116 unixtodos_filename (full_path_name
);
8118 file_name_only
= strrchr (full_path_name
, '\\');
8119 if (!file_name_only
)
8120 file_name_only
= full_path_name
;
8124 strncpy (filename
, file_name_only
, MAX_PATH
);
8125 filename
[MAX_PATH
] = '\0';
8131 NEWOPENFILENAME new_file_details
;
8132 BOOL file_opened
= FALSE
;
8133 OPENFILENAME
* file_details
= &new_file_details
.real_details
;
8135 /* Prevent redisplay. */
8136 specbind (Qinhibit_redisplay
, Qt
);
8139 bzero (&new_file_details
, sizeof (new_file_details
));
8140 /* Apparently NT4 crashes if you give it an unexpected size.
8141 I'm not sure about Windows 9x, so play it safe. */
8142 if (w32_major_version
> 4 && w32_major_version
< 95)
8143 file_details
->lStructSize
= sizeof (NEWOPENFILENAME
);
8145 file_details
->lStructSize
= sizeof (OPENFILENAME
);
8147 file_details
->hwndOwner
= FRAME_W32_WINDOW (f
);
8148 /* Undocumented Bug in Common File Dialog:
8149 If a filter is not specified, shell links are not resolved. */
8150 file_details
->lpstrFilter
= "All Files (*.*)\0*.*\0Directories\0*|*\0\0";
8151 file_details
->lpstrFile
= filename
;
8152 file_details
->nMaxFile
= sizeof (filename
);
8153 file_details
->lpstrInitialDir
= init_dir
;
8154 file_details
->lpstrTitle
= SDATA (prompt
);
8156 if (! NILP (only_dir_p
))
8157 default_filter_index
= 2;
8159 file_details
->nFilterIndex
= default_filter_index
;
8161 file_details
->Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
8162 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
8163 if (!NILP (mustmatch
))
8165 /* Require that the path to the parent directory exists. */
8166 file_details
->Flags
|= OFN_PATHMUSTEXIST
;
8167 /* If we are looking for a file, require that it exists. */
8168 if (NILP (only_dir_p
))
8169 file_details
->Flags
|= OFN_FILEMUSTEXIST
;
8172 file_details
->lpfnHook
= (LPOFNHOOKPROC
) file_dialog_callback
;
8174 file_opened
= GetOpenFileName (file_details
);
8180 dostounix_filename (filename
);
8182 if (file_details
->nFilterIndex
== 2)
8184 /* "Directories" selected - strip dummy file name. */
8185 char * last
= strrchr (filename
, '/');
8189 file
= DECODE_FILE (build_string (filename
));
8191 /* User cancelled the dialog without making a selection. */
8192 else if (!CommDlgExtendedError ())
8194 /* An error occurred, fallback on reading from the mini-buffer. */
8196 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
8197 dir
, mustmatch
, dir
, Qfile_name_history
,
8198 default_filename
, Qnil
);
8200 file
= unbind_to (count
, file
);
8205 /* Make "Cancel" equivalent to C-g. */
8207 Fsignal (Qquit
, Qnil
);
8209 return unbind_to (count
, file
);
8214 /***********************************************************************
8215 w32 specialized functions
8216 ***********************************************************************/
8218 DEFUN ("w32-select-font", Fw32_select_font
, Sw32_select_font
, 0, 2, 0,
8219 doc
: /* Select a font for the named FRAME using the W32 font dialog.
8220 Return an X-style font string corresponding to the selection.
8222 If FRAME is omitted or nil, it defaults to the selected frame.
8223 If INCLUDE-PROPORTIONAL is non-nil, include proportional fonts
8224 in the font selection dialog. */)
8225 (frame
, include_proportional
)
8226 Lisp_Object frame
, include_proportional
;
8228 FRAME_PTR f
= check_x_frame (frame
);
8236 bzero (&cf
, sizeof (cf
));
8237 bzero (&lf
, sizeof (lf
));
8239 cf
.lStructSize
= sizeof (cf
);
8240 cf
.hwndOwner
= FRAME_W32_WINDOW (f
);
8241 cf
.Flags
= CF_FORCEFONTEXIST
| CF_SCREENFONTS
| CF_NOVERTFONTS
;
8243 /* Unless include_proportional is non-nil, limit the selection to
8244 monospaced fonts. */
8245 if (NILP (include_proportional
))
8246 cf
.Flags
|= CF_FIXEDPITCHONLY
;
8250 /* Initialize as much of the font details as we can from the current
8252 hdc
= GetDC (FRAME_W32_WINDOW (f
));
8253 oldobj
= SelectObject (hdc
, FRAME_FONT (f
)->hfont
);
8254 GetTextFace (hdc
, LF_FACESIZE
, lf
.lfFaceName
);
8255 if (GetTextMetrics (hdc
, &tm
))
8257 lf
.lfHeight
= tm
.tmInternalLeading
- tm
.tmHeight
;
8258 lf
.lfWeight
= tm
.tmWeight
;
8259 lf
.lfItalic
= tm
.tmItalic
;
8260 lf
.lfUnderline
= tm
.tmUnderlined
;
8261 lf
.lfStrikeOut
= tm
.tmStruckOut
;
8262 lf
.lfCharSet
= tm
.tmCharSet
;
8263 cf
.Flags
|= CF_INITTOLOGFONTSTRUCT
;
8265 SelectObject (hdc
, oldobj
);
8266 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
8268 if (!ChooseFont (&cf
) || !w32_to_x_font (&lf
, buf
, 100, NULL
))
8271 return build_string (buf
);
8274 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
,
8275 Sw32_send_sys_command
, 1, 2, 0,
8276 doc
: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND.
8277 Some useful values for COMMAND are #xf030 to maximize frame (#xf020
8278 to minimize), #xf120 to restore frame to original size, and #xf100
8279 to activate the menubar for keyboard access. #xf140 activates the
8280 screen saver if defined.
8282 If optional parameter FRAME is not specified, use selected frame. */)
8284 Lisp_Object command
, frame
;
8286 FRAME_PTR f
= check_x_frame (frame
);
8288 CHECK_NUMBER (command
);
8290 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
8295 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
8296 doc
: /* Get Windows to perform OPERATION on DOCUMENT.
8297 This is a wrapper around the ShellExecute system function, which
8298 invokes the application registered to handle OPERATION for DOCUMENT.
8300 OPERATION is either nil or a string that names a supported operation.
8301 What operations can be used depends on the particular DOCUMENT and its
8302 handler application, but typically it is one of the following common
8305 \"open\" - open DOCUMENT, which could be a file, a directory, or an
8306 executable program. If it is an application, that
8307 application is launched in the current buffer's default
8308 directory. Otherwise, the application associated with
8309 DOCUMENT is launched in the buffer's default directory.
8310 \"print\" - print DOCUMENT, which must be a file
8311 \"explore\" - start the Windows Explorer on DOCUMENT
8312 \"edit\" - launch an editor and open DOCUMENT for editing; which
8313 editor is launched depends on the association for the
8315 \"find\" - initiate search starting from DOCUMENT which must specify
8317 nil - invoke the default OPERATION, or \"open\" if default is
8318 not defined or unavailable
8320 DOCUMENT is typically the name of a document file or a URL, but can
8321 also be a program executable to run, or a directory to open in the
8324 If DOCUMENT is a program executable, the optional third arg PARAMETERS
8325 can be a string containing command line parameters that will be passed
8326 to the program; otherwise, PARAMETERS should be nil or unspecified.
8328 Optional fourth argument SHOW-FLAG can be used to control how the
8329 application will be displayed when it is invoked. If SHOW-FLAG is nil
8330 or unspecified, the application is displayed normally, otherwise it is
8331 an integer representing a ShowWindow flag:
8336 6 - start minimized */)
8337 (operation
, document
, parameters
, show_flag
)
8338 Lisp_Object operation
, document
, parameters
, show_flag
;
8340 Lisp_Object current_dir
;
8342 CHECK_STRING (document
);
8344 /* Encode filename and current directory. */
8345 current_dir
= ENCODE_FILE (current_buffer
->directory
);
8346 document
= ENCODE_FILE (document
);
8347 if ((int) ShellExecute (NULL
,
8348 (STRINGP (operation
) ?
8349 SDATA (operation
) : NULL
),
8351 (STRINGP (parameters
) ?
8352 SDATA (parameters
) : NULL
),
8353 SDATA (current_dir
),
8354 (INTEGERP (show_flag
) ?
8355 XINT (show_flag
) : SW_SHOWDEFAULT
))
8358 error ("ShellExecute failed: %s", w32_strerror (0));
8361 /* Lookup virtual keycode from string representing the name of a
8362 non-ascii keystroke into the corresponding virtual key, using
8363 lispy_function_keys. */
8365 lookup_vk_code (char *key
)
8369 for (i
= 0; i
< 256; i
++)
8370 if (lispy_function_keys
[i
]
8371 && strcmp (lispy_function_keys
[i
], key
) == 0)
8377 /* Convert a one-element vector style key sequence to a hot key
8380 w32_parse_hot_key (key
)
8383 /* Copied from Fdefine_key and store_in_keymap. */
8384 register Lisp_Object c
;
8388 struct gcpro gcpro1
;
8392 if (XFASTINT (Flength (key
)) != 1)
8397 c
= Faref (key
, make_number (0));
8399 if (CONSP (c
) && lucid_event_type_list_p (c
))
8400 c
= Fevent_convert_list (c
);
8404 if (! INTEGERP (c
) && ! SYMBOLP (c
))
8405 error ("Key definition is invalid");
8407 /* Work out the base key and the modifiers. */
8410 c
= parse_modifiers (c
);
8411 lisp_modifiers
= XINT (Fcar (Fcdr (c
)));
8415 vk_code
= lookup_vk_code (SDATA (SYMBOL_NAME (c
)));
8417 else if (INTEGERP (c
))
8419 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
8420 /* Many ascii characters are their own virtual key code. */
8421 vk_code
= XINT (c
) & CHARACTERBITS
;
8424 if (vk_code
< 0 || vk_code
> 255)
8427 if ((lisp_modifiers
& meta_modifier
) != 0
8428 && !NILP (Vw32_alt_is_meta
))
8429 lisp_modifiers
|= alt_modifier
;
8431 /* Supply defs missing from mingw32. */
8433 #define MOD_ALT 0x0001
8434 #define MOD_CONTROL 0x0002
8435 #define MOD_SHIFT 0x0004
8436 #define MOD_WIN 0x0008
8439 /* Convert lisp modifiers to Windows hot-key form. */
8440 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
8441 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
8442 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
8443 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
8445 return HOTKEY (vk_code
, w32_modifiers
);
8448 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
,
8449 Sw32_register_hot_key
, 1, 1, 0,
8450 doc
: /* Register KEY as a hot-key combination.
8451 Certain key combinations like Alt-Tab are reserved for system use on
8452 Windows, and therefore are normally intercepted by the system. However,
8453 most of these key combinations can be received by registering them as
8454 hot-keys, overriding their special meaning.
8456 KEY must be a one element key definition in vector form that would be
8457 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta
8458 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper
8459 is always interpreted as the Windows modifier keys.
8461 The return value is the hotkey-id if registered, otherwise nil. */)
8465 key
= w32_parse_hot_key (key
);
8467 if (!NILP (key
) && NILP (Fmemq (key
, w32_grabbed_keys
)))
8469 /* Reuse an empty slot if possible. */
8470 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
8472 /* Safe to add new key to list, even if we have focus. */
8474 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
8476 XSETCAR (item
, key
);
8478 /* Notify input thread about new hot-key definition, so that it
8479 takes effect without needing to switch focus. */
8480 #ifdef USE_LISP_UNION_TYPE
8481 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
8484 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
8492 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
,
8493 Sw32_unregister_hot_key
, 1, 1, 0,
8494 doc
: /* Unregister KEY as a hot-key combination. */)
8500 if (!INTEGERP (key
))
8501 key
= w32_parse_hot_key (key
);
8503 item
= Fmemq (key
, w32_grabbed_keys
);
8507 /* Notify input thread about hot-key definition being removed, so
8508 that it takes effect without needing focus switch. */
8509 #ifdef USE_LISP_UNION_TYPE
8510 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
8511 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
.i
))
8513 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
8514 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
))
8518 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
8525 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
,
8526 Sw32_registered_hot_keys
, 0, 0, 0,
8527 doc
: /* Return list of registered hot-key IDs. */)
8530 return Fdelq (Qnil
, Fcopy_sequence (w32_grabbed_keys
));
8533 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
,
8534 Sw32_reconstruct_hot_key
, 1, 1, 0,
8535 doc
: /* Convert hot-key ID to a lisp key combination.
8536 usage: (w32-reconstruct-hot-key ID) */)
8538 Lisp_Object hotkeyid
;
8540 int vk_code
, w32_modifiers
;
8543 CHECK_NUMBER (hotkeyid
);
8545 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
8546 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
8548 if (vk_code
< 256 && lispy_function_keys
[vk_code
])
8549 key
= intern (lispy_function_keys
[vk_code
]);
8551 key
= make_number (vk_code
);
8553 key
= Fcons (key
, Qnil
);
8554 if (w32_modifiers
& MOD_SHIFT
)
8555 key
= Fcons (Qshift
, key
);
8556 if (w32_modifiers
& MOD_CONTROL
)
8557 key
= Fcons (Qctrl
, key
);
8558 if (w32_modifiers
& MOD_ALT
)
8559 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
8560 if (w32_modifiers
& MOD_WIN
)
8561 key
= Fcons (Qhyper
, key
);
8566 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
,
8567 Sw32_toggle_lock_key
, 1, 2, 0,
8568 doc
: /* Toggle the state of the lock key KEY.
8569 KEY can be `capslock', `kp-numlock', or `scroll'.
8570 If the optional parameter NEW-STATE is a number, then the state of KEY
8571 is set to off if the low bit of NEW-STATE is zero, otherwise on. */)
8573 Lisp_Object key
, new_state
;
8577 if (EQ (key
, intern ("capslock")))
8578 vk_code
= VK_CAPITAL
;
8579 else if (EQ (key
, intern ("kp-numlock")))
8580 vk_code
= VK_NUMLOCK
;
8581 else if (EQ (key
, intern ("scroll")))
8582 vk_code
= VK_SCROLL
;
8586 if (!dwWindowsThreadId
)
8587 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
8589 #ifdef USE_LISP_UNION_TYPE
8590 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
8591 (WPARAM
) vk_code
, (LPARAM
) new_state
.i
))
8593 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
8594 (WPARAM
) vk_code
, (LPARAM
) new_state
))
8598 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
8599 return make_number (msg
.wParam
);
8604 DEFUN ("w32-window-exists-p", Fw32_window_exists_p
, Sw32_window_exists_p
,
8606 doc
: /* Return non-nil if a window exists with the specified CLASS and NAME.
8608 This is a direct interface to the Windows API FindWindow function. */)
8610 Lisp_Object
class, name
;
8615 CHECK_STRING (class);
8617 CHECK_STRING (name
);
8619 hnd
= FindWindow (STRINGP (class) ? ((LPCTSTR
) SDATA (class)) : NULL
,
8620 STRINGP (name
) ? ((LPCTSTR
) SDATA (name
)) : NULL
);
8628 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
8629 doc
: /* Return storage information about the file system FILENAME is on.
8630 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
8631 storage of the file system, FREE is the free storage, and AVAIL is the
8632 storage available to a non-superuser. All 3 numbers are in bytes.
8633 If the underlying system call fails, value is nil. */)
8635 Lisp_Object filename
;
8637 Lisp_Object encoded
, value
;
8639 CHECK_STRING (filename
);
8640 filename
= Fexpand_file_name (filename
, Qnil
);
8641 encoded
= ENCODE_FILE (filename
);
8645 /* Determining the required information on Windows turns out, sadly,
8646 to be more involved than one would hope. The original Win32 api
8647 call for this will return bogus information on some systems, but we
8648 must dynamically probe for the replacement api, since that was
8649 added rather late on. */
8651 HMODULE hKernel
= GetModuleHandle ("kernel32");
8652 BOOL (*pfn_GetDiskFreeSpaceEx
)
8653 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
8654 = (void *) GetProcAddress (hKernel
, "GetDiskFreeSpaceEx");
8656 /* On Windows, we may need to specify the root directory of the
8657 volume holding FILENAME. */
8658 char rootname
[MAX_PATH
];
8659 char *name
= SDATA (encoded
);
8661 /* find the root name of the volume if given */
8662 if (isalpha (name
[0]) && name
[1] == ':')
8664 rootname
[0] = name
[0];
8665 rootname
[1] = name
[1];
8669 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
8671 char *str
= rootname
;
8675 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
8685 if (pfn_GetDiskFreeSpaceEx
)
8687 /* Unsigned large integers cannot be cast to double, so
8688 use signed ones instead. */
8689 LARGE_INTEGER availbytes
;
8690 LARGE_INTEGER freebytes
;
8691 LARGE_INTEGER totalbytes
;
8693 if (pfn_GetDiskFreeSpaceEx (rootname
,
8694 (ULARGE_INTEGER
*)&availbytes
,
8695 (ULARGE_INTEGER
*)&totalbytes
,
8696 (ULARGE_INTEGER
*)&freebytes
))
8697 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
8698 make_float ((double) freebytes
.QuadPart
),
8699 make_float ((double) availbytes
.QuadPart
));
8703 DWORD sectors_per_cluster
;
8704 DWORD bytes_per_sector
;
8705 DWORD free_clusters
;
8706 DWORD total_clusters
;
8708 if (GetDiskFreeSpace (rootname
,
8709 §ors_per_cluster
,
8713 value
= list3 (make_float ((double) total_clusters
8714 * sectors_per_cluster
* bytes_per_sector
),
8715 make_float ((double) free_clusters
8716 * sectors_per_cluster
* bytes_per_sector
),
8717 make_float ((double) free_clusters
8718 * sectors_per_cluster
* bytes_per_sector
));
8725 DEFUN ("default-printer-name", Fdefault_printer_name
, Sdefault_printer_name
,
8726 0, 0, 0, doc
: /* Return the name of Windows default printer device. */)
8729 static char pname_buf
[256];
8732 PRINTER_INFO_2
*ppi2
= NULL
;
8733 DWORD dwNeeded
= 0, dwReturned
= 0;
8735 /* Retrieve the default string from Win.ini (the registry).
8736 * String will be in form "printername,drivername,portname".
8737 * This is the most portable way to get the default printer. */
8738 if (GetProfileString ("windows", "device", ",,", pname_buf
, sizeof (pname_buf
)) <= 0)
8740 /* printername precedes first "," character */
8741 strtok (pname_buf
, ",");
8742 /* We want to know more than the printer name */
8743 if (!OpenPrinter (pname_buf
, &hPrn
, NULL
))
8745 GetPrinter (hPrn
, 2, NULL
, 0, &dwNeeded
);
8748 ClosePrinter (hPrn
);
8751 /* Allocate memory for the PRINTER_INFO_2 struct */
8752 ppi2
= (PRINTER_INFO_2
*) xmalloc (dwNeeded
);
8755 ClosePrinter (hPrn
);
8758 /* Call GetPrinter again with big enouth memory block */
8759 err
= GetPrinter (hPrn
, 2, (LPBYTE
)ppi2
, dwNeeded
, &dwReturned
);
8760 ClosePrinter (hPrn
);
8769 if (ppi2
->Attributes
& PRINTER_ATTRIBUTE_SHARED
&& ppi2
->pServerName
)
8771 /* a remote printer */
8772 if (*ppi2
->pServerName
== '\\')
8773 _snprintf (pname_buf
, sizeof (pname_buf
), "%s\\%s", ppi2
->pServerName
,
8776 _snprintf (pname_buf
, sizeof (pname_buf
), "\\\\%s\\%s", ppi2
->pServerName
,
8778 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
8782 /* a local printer */
8783 strncpy (pname_buf
, ppi2
->pPortName
, sizeof (pname_buf
));
8784 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
8785 /* `pPortName' can include several ports, delimited by ','.
8786 * we only use the first one. */
8787 strtok (pname_buf
, ",");
8792 return build_string (pname_buf
);
8795 /***********************************************************************
8797 ***********************************************************************/
8799 /* Keep this list in the same order as frame_parms in frame.c.
8800 Use 0 for unsupported frame parameters. */
8802 frame_parm_handler w32_frame_parm_handlers
[] =
8806 x_set_background_color
,
8812 x_set_foreground_color
,
8815 x_set_internal_border_width
,
8816 x_set_menu_bar_lines
,
8818 x_explicitly_set_name
,
8819 x_set_scroll_bar_width
,
8822 x_set_vertical_scroll_bars
,
8824 x_set_tool_bar_lines
,
8825 0, /* x_set_scroll_bar_foreground, */
8826 0, /* x_set_scroll_bar_background, */
8831 0, /* x_set_wait_for_wm, */
8833 #ifdef USE_FONT_BACKEND
8841 globals_of_w32fns ();
8842 /* This is zero if not using MS-Windows. */
8844 track_mouse_window
= NULL
;
8846 w32_visible_system_caret_hwnd
= NULL
;
8848 DEFSYM (Qnone
, "none");
8849 DEFSYM (Qsuppress_icon
, "suppress-icon");
8850 DEFSYM (Qundefined_color
, "undefined-color");
8851 DEFSYM (Qcancel_timer
, "cancel-timer");
8852 DEFSYM (Qhyper
, "hyper");
8853 DEFSYM (Qsuper
, "super");
8854 DEFSYM (Qmeta
, "meta");
8855 DEFSYM (Qalt
, "alt");
8856 DEFSYM (Qctrl
, "ctrl");
8857 DEFSYM (Qcontrol
, "control");
8858 DEFSYM (Qshift
, "shift");
8859 /* This is the end of symbol initialization. */
8861 /* Text property `display' should be nonsticky by default. */
8862 Vtext_property_default_nonsticky
8863 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
8866 Fput (Qundefined_color
, Qerror_conditions
,
8867 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
8868 Fput (Qundefined_color
, Qerror_message
,
8869 build_string ("Undefined color"));
8871 staticpro (&w32_grabbed_keys
);
8872 w32_grabbed_keys
= Qnil
;
8874 DEFVAR_LISP ("w32-color-map", &Vw32_color_map
,
8875 doc
: /* An array of color name mappings for Windows. */);
8876 Vw32_color_map
= Qnil
;
8878 DEFVAR_LISP ("w32-pass-alt-to-system", &Vw32_pass_alt_to_system
,
8879 doc
: /* Non-nil if Alt key presses are passed on to Windows.
8880 When non-nil, for example, Alt pressed and released and then space will
8881 open the System menu. When nil, Emacs processes the Alt key events, and
8882 then silently swallows them. */);
8883 Vw32_pass_alt_to_system
= Qnil
;
8885 DEFVAR_LISP ("w32-alt-is-meta", &Vw32_alt_is_meta
,
8886 doc
: /* Non-nil if the Alt key is to be considered the same as the META key.
8887 When nil, Emacs will translate the Alt key to the ALT modifier, not to META. */);
8888 Vw32_alt_is_meta
= Qt
;
8890 DEFVAR_INT ("w32-quit-key", &w32_quit_key
,
8891 doc
: /* If non-zero, the virtual key code for an alternative quit key. */);
8894 DEFVAR_LISP ("w32-pass-lwindow-to-system",
8895 &Vw32_pass_lwindow_to_system
,
8896 doc
: /* If non-nil, the left \"Windows\" key is passed on to Windows.
8898 When non-nil, the Start menu is opened by tapping the key.
8899 If you set this to nil, the left \"Windows\" key is processed by Emacs
8900 according to the value of `w32-lwindow-modifier', which see.
8902 Note that some combinations of the left \"Windows\" key with other keys are
8903 caught by Windows at low level, and so binding them in Emacs will have no
8904 effect. For example, <lwindow>-r always pops up the Windows Run dialog,
8905 <lwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
8906 the doc string of `w32-phantom-key-code'. */);
8907 Vw32_pass_lwindow_to_system
= Qt
;
8909 DEFVAR_LISP ("w32-pass-rwindow-to-system",
8910 &Vw32_pass_rwindow_to_system
,
8911 doc
: /* If non-nil, the right \"Windows\" key is passed on to Windows.
8913 When non-nil, the Start menu is opened by tapping the key.
8914 If you set this to nil, the right \"Windows\" key is processed by Emacs
8915 according to the value of `w32-rwindow-modifier', which see.
8917 Note that some combinations of the right \"Windows\" key with other keys are
8918 caught by Windows at low level, and so binding them in Emacs will have no
8919 effect. For example, <rwindow>-r always pops up the Windows Run dialog,
8920 <rwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
8921 the doc string of `w32-phantom-key-code'. */);
8922 Vw32_pass_rwindow_to_system
= Qt
;
8924 DEFVAR_LISP ("w32-phantom-key-code",
8925 &Vw32_phantom_key_code
,
8926 doc
: /* Virtual key code used to generate \"phantom\" key presses.
8927 Value is a number between 0 and 255.
8929 Phantom key presses are generated in order to stop the system from
8930 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or
8931 `w32-pass-rwindow-to-system' is nil. */);
8932 /* Although 255 is technically not a valid key code, it works and
8933 means that this hack won't interfere with any real key code. */
8934 XSETINT (Vw32_phantom_key_code
, 255);
8936 DEFVAR_LISP ("w32-enable-num-lock",
8937 &Vw32_enable_num_lock
,
8938 doc
: /* If non-nil, the Num Lock key acts normally.
8939 Set to nil to handle Num Lock as the `kp-numlock' key. */);
8940 Vw32_enable_num_lock
= Qt
;
8942 DEFVAR_LISP ("w32-enable-caps-lock",
8943 &Vw32_enable_caps_lock
,
8944 doc
: /* If non-nil, the Caps Lock key acts normally.
8945 Set to nil to handle Caps Lock as the `capslock' key. */);
8946 Vw32_enable_caps_lock
= Qt
;
8948 DEFVAR_LISP ("w32-scroll-lock-modifier",
8949 &Vw32_scroll_lock_modifier
,
8950 doc
: /* Modifier to use for the Scroll Lock ON state.
8951 The value can be hyper, super, meta, alt, control or shift for the
8952 respective modifier, or nil to handle Scroll Lock as the `scroll' key.
8953 Any other value will cause the Scroll Lock key to be ignored. */);
8954 Vw32_scroll_lock_modifier
= Qt
;
8956 DEFVAR_LISP ("w32-lwindow-modifier",
8957 &Vw32_lwindow_modifier
,
8958 doc
: /* Modifier to use for the left \"Windows\" key.
8959 The value can be hyper, super, meta, alt, control or shift for the
8960 respective modifier, or nil to appear as the `lwindow' key.
8961 Any other value will cause the key to be ignored. */);
8962 Vw32_lwindow_modifier
= Qnil
;
8964 DEFVAR_LISP ("w32-rwindow-modifier",
8965 &Vw32_rwindow_modifier
,
8966 doc
: /* Modifier to use for the right \"Windows\" key.
8967 The value can be hyper, super, meta, alt, control or shift for the
8968 respective modifier, or nil to appear as the `rwindow' key.
8969 Any other value will cause the key to be ignored. */);
8970 Vw32_rwindow_modifier
= Qnil
;
8972 DEFVAR_LISP ("w32-apps-modifier",
8973 &Vw32_apps_modifier
,
8974 doc
: /* Modifier to use for the \"Apps\" key.
8975 The value can be hyper, super, meta, alt, control or shift for the
8976 respective modifier, or nil to appear as the `apps' key.
8977 Any other value will cause the key to be ignored. */);
8978 Vw32_apps_modifier
= Qnil
;
8980 DEFVAR_BOOL ("w32-enable-synthesized-fonts", &w32_enable_synthesized_fonts
,
8981 doc
: /* Non-nil enables selection of artificially italicized and bold fonts. */);
8982 w32_enable_synthesized_fonts
= 0;
8984 DEFVAR_LISP ("w32-enable-palette", &Vw32_enable_palette
,
8985 doc
: /* Non-nil enables Windows palette management to map colors exactly. */);
8986 Vw32_enable_palette
= Qt
;
8988 DEFVAR_INT ("w32-mouse-button-tolerance",
8989 &w32_mouse_button_tolerance
,
8990 doc
: /* Analogue of double click interval for faking middle mouse events.
8991 The value is the minimum time in milliseconds that must elapse between
8992 left and right button down events before they are considered distinct events.
8993 If both mouse buttons are depressed within this interval, a middle mouse
8994 button down event is generated instead. */);
8995 w32_mouse_button_tolerance
= GetDoubleClickTime () / 2;
8997 DEFVAR_INT ("w32-mouse-move-interval",
8998 &w32_mouse_move_interval
,
8999 doc
: /* Minimum interval between mouse move events.
9000 The value is the minimum time in milliseconds that must elapse between
9001 successive mouse move (or scroll bar drag) events before they are
9002 reported as lisp events. */);
9003 w32_mouse_move_interval
= 0;
9005 DEFVAR_BOOL ("w32-pass-extra-mouse-buttons-to-system",
9006 &w32_pass_extra_mouse_buttons_to_system
,
9007 doc
: /* If non-nil, the fourth and fifth mouse buttons are passed to Windows.
9008 Recent versions of Windows support mice with up to five buttons.
9009 Since most applications don't support these extra buttons, most mouse
9010 drivers will allow you to map them to functions at the system level.
9011 If this variable is non-nil, Emacs will pass them on, allowing the
9012 system to handle them. */);
9013 w32_pass_extra_mouse_buttons_to_system
= 0;
9015 DEFVAR_BOOL ("w32-pass-multimedia-buttons-to-system",
9016 &w32_pass_multimedia_buttons_to_system
,
9017 doc
: /* If non-nil, media buttons are passed to Windows.
9018 Some modern keyboards contain buttons for controlling media players, web
9019 browsers and other applications. Generally these buttons are handled on a
9020 system wide basis, but by setting this to nil they are made available
9021 to Emacs for binding. Depending on your keyboard, additional keys that
9022 may be available are:
9024 browser-back, browser-forward, browser-refresh, browser-stop,
9025 browser-search, browser-favorites, browser-home,
9026 mail, mail-reply, mail-forward, mail-send,
9028 help, find, new, open, close, save, print, undo, redo, copy, cut, paste,
9029 spell-check, correction-list, toggle-dictate-command,
9030 media-next, media-previous, media-stop, media-play-pause, media-select,
9031 media-play, media-pause, media-record, media-fast-forward, media-rewind,
9032 media-channel-up, media-channel-down,
9033 volume-mute, volume-up, volume-down,
9034 mic-volume-mute, mic-volume-down, mic-volume-up, mic-toggle,
9035 bass-down, bass-boost, bass-up, treble-down, treble-up */);
9036 w32_pass_multimedia_buttons_to_system
= 1;
9038 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
9039 doc
: /* The shape of the pointer when over text.
9040 Changing the value does not affect existing frames
9041 unless you set the mouse color. */);
9042 Vx_pointer_shape
= Qnil
;
9044 Vx_nontext_pointer_shape
= Qnil
;
9046 Vx_mode_pointer_shape
= Qnil
;
9048 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
9049 doc
: /* The shape of the pointer when Emacs is busy.
9050 This variable takes effect when you create a new frame
9051 or when you set the mouse color. */);
9052 Vx_hourglass_pointer_shape
= Qnil
;
9054 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
9055 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
9056 display_hourglass_p
= 1;
9058 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
9059 doc
: /* *Seconds to wait before displaying an hourglass pointer.
9060 Value must be an integer or float. */);
9061 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
9063 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
9064 &Vx_sensitive_text_pointer_shape
,
9065 doc
: /* The shape of the pointer when over mouse-sensitive text.
9066 This variable takes effect when you create a new frame
9067 or when you set the mouse color. */);
9068 Vx_sensitive_text_pointer_shape
= Qnil
;
9070 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
9071 &Vx_window_horizontal_drag_shape
,
9072 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
9073 This variable takes effect when you create a new frame
9074 or when you set the mouse color. */);
9075 Vx_window_horizontal_drag_shape
= Qnil
;
9077 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
9078 doc
: /* A string indicating the foreground color of the cursor box. */);
9079 Vx_cursor_fore_pixel
= Qnil
;
9081 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size
,
9082 doc
: /* Maximum size for tooltips.
9083 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
9084 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
9086 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
9087 doc
: /* Non-nil if no window manager is in use.
9088 Emacs doesn't try to figure this out; this is always nil
9089 unless you set it to something else. */);
9090 /* We don't have any way to find this out, so set it to nil
9091 and maybe the user would like to set it to t. */
9092 Vx_no_window_manager
= Qnil
;
9094 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
9095 &Vx_pixel_size_width_font_regexp
,
9096 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
9098 Since Emacs gets width of a font matching with this regexp from
9099 PIXEL_SIZE field of the name, font finding mechanism gets faster for
9100 such a font. This is especially effective for such large fonts as
9101 Chinese, Japanese, and Korean. */);
9102 Vx_pixel_size_width_font_regexp
= Qnil
;
9104 DEFVAR_LISP ("w32-bdf-filename-alist",
9105 &Vw32_bdf_filename_alist
,
9106 doc
: /* List of bdf fonts and their corresponding filenames. */);
9107 Vw32_bdf_filename_alist
= Qnil
;
9109 DEFVAR_BOOL ("w32-strict-fontnames",
9110 &w32_strict_fontnames
,
9111 doc
: /* Non-nil means only use fonts that are exact matches for those requested.
9112 Default is nil, which allows old fontnames that are not XLFD compliant,
9113 and allows third-party CJK display to work by specifying false charset
9114 fields to trick Emacs into translating to Big5, SJIS etc.
9115 Setting this to t will prevent wrong fonts being selected when
9116 fontsets are automatically created. */);
9117 w32_strict_fontnames
= 0;
9119 DEFVAR_BOOL ("w32-strict-painting",
9120 &w32_strict_painting
,
9121 doc
: /* Non-nil means use strict rules for repainting frames.
9122 Set this to nil to get the old behavior for repainting; this should
9123 only be necessary if the default setting causes problems. */);
9124 w32_strict_painting
= 1;
9126 DEFVAR_LISP ("w32-charset-info-alist",
9127 &Vw32_charset_info_alist
,
9128 doc
: /* Alist linking Emacs character sets to Windows fonts and codepages.
9129 Each entry should be of the form:
9131 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE))
9133 where CHARSET_NAME is a string used in font names to identify the charset,
9134 WINDOWS_CHARSET is a symbol that can be one of:
9135 w32-charset-ansi, w32-charset-default, w32-charset-symbol,
9136 w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312,
9137 w32-charset-chinesebig5,
9138 w32-charset-johab, w32-charset-hebrew,
9139 w32-charset-arabic, w32-charset-greek, w32-charset-turkish,
9140 w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope,
9141 w32-charset-russian, w32-charset-mac, w32-charset-baltic,
9142 w32-charset-unicode,
9144 CODEPAGE should be an integer specifying the codepage that should be used
9145 to display the character set, t to do no translation and output as Unicode,
9146 or nil to do no translation and output as 8 bit (or multibyte on far-east
9147 versions of Windows) characters. */);
9148 Vw32_charset_info_alist
= Qnil
;
9150 DEFSYM (Qw32_charset_ansi
, "w32-charset-ansi");
9151 DEFSYM (Qw32_charset_symbol
, "w32-charset-symbol");
9152 DEFSYM (Qw32_charset_default
, "w32-charset-default");
9153 DEFSYM (Qw32_charset_shiftjis
, "w32-charset-shiftjis");
9154 DEFSYM (Qw32_charset_hangeul
, "w32-charset-hangeul");
9155 DEFSYM (Qw32_charset_chinesebig5
, "w32-charset-chinesebig5");
9156 DEFSYM (Qw32_charset_gb2312
, "w32-charset-gb2312");
9157 DEFSYM (Qw32_charset_oem
, "w32-charset-oem");
9159 #ifdef JOHAB_CHARSET
9161 static int w32_extra_charsets_defined
= 1;
9162 DEFVAR_BOOL ("w32-extra-charsets-defined", &w32_extra_charsets_defined
,
9163 doc
: /* Internal variable. */);
9165 DEFSYM (Qw32_charset_johab
, "w32-charset-johab");
9166 DEFSYM (Qw32_charset_easteurope
, "w32-charset-easteurope");
9167 DEFSYM (Qw32_charset_turkish
, "w32-charset-turkish");
9168 DEFSYM (Qw32_charset_baltic
, "w32-charset-baltic");
9169 DEFSYM (Qw32_charset_russian
, "w32-charset-russian");
9170 DEFSYM (Qw32_charset_arabic
, "w32-charset-arabic");
9171 DEFSYM (Qw32_charset_greek
, "w32-charset-greek");
9172 DEFSYM (Qw32_charset_hebrew
, "w32-charset-hebrew");
9173 DEFSYM (Qw32_charset_vietnamese
, "w32-charset-vietnamese");
9174 DEFSYM (Qw32_charset_thai
, "w32-charset-thai");
9175 DEFSYM (Qw32_charset_mac
, "w32-charset-mac");
9179 #ifdef UNICODE_CHARSET
9181 static int w32_unicode_charset_defined
= 1;
9182 DEFVAR_BOOL ("w32-unicode-charset-defined",
9183 &w32_unicode_charset_defined
,
9184 doc
: /* Internal variable. */);
9185 DEFSYM (Qw32_charset_unicode
, "w32-charset-unicode");
9189 #if 0 /* TODO: Port to W32 */
9190 defsubr (&Sx_change_window_property
);
9191 defsubr (&Sx_delete_window_property
);
9192 defsubr (&Sx_window_property
);
9194 defsubr (&Sxw_display_color_p
);
9195 defsubr (&Sx_display_grayscale_p
);
9196 defsubr (&Sxw_color_defined_p
);
9197 defsubr (&Sxw_color_values
);
9198 defsubr (&Sx_server_max_request_size
);
9199 defsubr (&Sx_server_vendor
);
9200 defsubr (&Sx_server_version
);
9201 defsubr (&Sx_display_pixel_width
);
9202 defsubr (&Sx_display_pixel_height
);
9203 defsubr (&Sx_display_mm_width
);
9204 defsubr (&Sx_display_mm_height
);
9205 defsubr (&Sx_display_screens
);
9206 defsubr (&Sx_display_planes
);
9207 defsubr (&Sx_display_color_cells
);
9208 defsubr (&Sx_display_visual_class
);
9209 defsubr (&Sx_display_backing_store
);
9210 defsubr (&Sx_display_save_under
);
9211 defsubr (&Sx_create_frame
);
9212 defsubr (&Sx_open_connection
);
9213 defsubr (&Sx_close_connection
);
9214 defsubr (&Sx_display_list
);
9215 defsubr (&Sx_synchronize
);
9216 defsubr (&Sx_focus_frame
);
9218 /* W32 specific functions */
9220 defsubr (&Sw32_select_font
);
9221 defsubr (&Sw32_define_rgb_color
);
9222 defsubr (&Sw32_default_color_map
);
9223 defsubr (&Sw32_load_color_file
);
9224 defsubr (&Sw32_send_sys_command
);
9225 defsubr (&Sw32_shell_execute
);
9226 defsubr (&Sw32_register_hot_key
);
9227 defsubr (&Sw32_unregister_hot_key
);
9228 defsubr (&Sw32_registered_hot_keys
);
9229 defsubr (&Sw32_reconstruct_hot_key
);
9230 defsubr (&Sw32_toggle_lock_key
);
9231 defsubr (&Sw32_window_exists_p
);
9232 defsubr (&Sw32_find_bdf_fonts
);
9234 defsubr (&Sfile_system_info
);
9235 defsubr (&Sdefault_printer_name
);
9237 /* Setting callback functions for fontset handler. */
9238 get_font_info_func
= w32_get_font_info
;
9240 #if 0 /* This function pointer doesn't seem to be used anywhere.
9241 And the pointer assigned has the wrong type, anyway. */
9242 list_fonts_func
= w32_list_fonts
;
9245 load_font_func
= w32_load_font
;
9246 find_ccl_program_func
= w32_find_ccl_program
;
9247 query_font_func
= w32_query_font
;
9248 set_frame_fontset_func
= x_set_font
;
9249 get_font_repertory_func
= x_get_font_repertory
;
9250 check_window_system_func
= check_w32
;
9253 hourglass_atimer
= NULL
;
9254 hourglass_shown_p
= 0;
9255 defsubr (&Sx_show_tip
);
9256 defsubr (&Sx_hide_tip
);
9258 staticpro (&tip_timer
);
9260 staticpro (&tip_frame
);
9262 last_show_tip_args
= Qnil
;
9263 staticpro (&last_show_tip_args
);
9265 defsubr (&Sx_file_dialog
);
9270 globals_of_w32fns is used to initialize those global variables that
9271 must always be initialized on startup even when the global variable
9272 initialized is non zero (see the function main in emacs.c).
9273 globals_of_w32fns is called from syms_of_w32fns when the global
9274 variable initialized is 0 and directly from main when initialized
9278 globals_of_w32fns ()
9280 HMODULE user32_lib
= GetModuleHandle ("user32.dll");
9282 TrackMouseEvent not available in all versions of Windows, so must load
9283 it dynamically. Do it once, here, instead of every time it is used.
9285 track_mouse_event_fn
= (TrackMouseEvent_Proc
)
9286 GetProcAddress (user32_lib
, "TrackMouseEvent");
9287 /* ditto for GetClipboardSequenceNumber. */
9288 clipboard_sequence_fn
= (ClipboardSequence_Proc
)
9289 GetProcAddress (user32_lib
, "GetClipboardSequenceNumber");
9291 HMODULE imm32_lib
= GetModuleHandle ("imm32.dll");
9292 get_composition_string_fn
= (ImmGetCompositionString_Proc
)
9293 GetProcAddress (imm32_lib
, "ImmGetCompositionStringW");
9294 get_ime_context_fn
= (ImmGetContext_Proc
)
9295 GetProcAddress (imm32_lib
, "ImmGetContext");
9297 DEFVAR_INT ("w32-ansi-code-page",
9298 &w32_ansi_code_page
,
9299 doc
: /* The ANSI code page used by the system. */);
9300 w32_ansi_code_page
= GetACP ();
9302 /* MessageBox does not work without this when linked to comctl32.dll 6.0. */
9303 InitCommonControls ();
9312 button
= MessageBox (NULL
,
9313 "A fatal error has occurred!\n\n"
9314 "Would you like to attach a debugger?\n\n"
9315 "Select YES to debug, NO to abort Emacs"
9317 "\n\n(type \"gdb -p <emacs-PID>\" and\n"
9318 "\"continue\" inside GDB before clicking YES.)"
9320 , "Emacs Abort Dialog",
9321 MB_ICONEXCLAMATION
| MB_TASKMODAL
9322 | MB_SETFOREGROUND
| MB_YESNO
);
9327 exit (2); /* tell the compiler we will never return */
9335 /* For convenience when debugging. */
9339 return GetLastError ();
9342 /* arch-tag: 707589ab-b9be-4638-8cdd-74629cc9b446
9343 (do not change this comment) */