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 /* Make copy of frame parameters because the original is in pure
4274 parameters
= Fcopy_alist (parameters
);
4276 /* Use this general default value to start with
4277 until we know if this frame has a specified name. */
4278 Vx_resource_name
= Vinvocation_name
;
4280 display
= w32_get_arg (parameters
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
4281 if (EQ (display
, Qunbound
))
4283 dpyinfo
= check_x_display_info (display
);
4285 kb
= dpyinfo
->terminal
->kboard
;
4287 kb
= &the_only_kboard
;
4290 name
= w32_get_arg (parameters
, Qname
, "name", "Name", RES_TYPE_STRING
);
4292 && ! EQ (name
, Qunbound
)
4294 error ("Invalid frame name--not a string or nil");
4297 Vx_resource_name
= name
;
4299 /* See if parent window is specified. */
4300 parent
= w32_get_arg (parameters
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
4301 if (EQ (parent
, Qunbound
))
4303 if (! NILP (parent
))
4304 CHECK_NUMBER (parent
);
4306 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
4307 /* No need to protect DISPLAY because that's not used after passing
4308 it to make_frame_without_minibuffer. */
4310 GCPRO4 (parameters
, parent
, name
, frame
);
4311 tem
= w32_get_arg (parameters
, Qminibuffer
, "minibuffer", "Minibuffer",
4313 if (EQ (tem
, Qnone
) || NILP (tem
))
4314 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
4315 else if (EQ (tem
, Qonly
))
4317 f
= make_minibuffer_frame ();
4318 minibuffer_only
= 1;
4320 else if (WINDOWP (tem
))
4321 f
= make_frame_without_minibuffer (tem
, kb
, display
);
4325 XSETFRAME (frame
, f
);
4327 /* Note that Windows does support scroll bars. */
4328 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
4330 /* By default, make scrollbars the system standard width. */
4331 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
4333 f
->terminal
= dpyinfo
->terminal
;
4334 f
->terminal
->reference_count
++;
4336 f
->output_method
= output_w32
;
4337 f
->output_data
.w32
=
4338 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
4339 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
4340 FRAME_FONTSET (f
) = -1;
4341 record_unwind_protect (unwind_create_frame
, frame
);
4344 = w32_get_arg (parameters
, Qicon_name
, "iconName", "Title", RES_TYPE_STRING
);
4345 if (! STRINGP (f
->icon_name
))
4346 f
->icon_name
= Qnil
;
4348 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
4350 FRAME_KBOARD (f
) = kb
;
4353 /* Specify the parent under which to make this window. */
4357 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
4358 f
->output_data
.w32
->explicit_parent
= 1;
4362 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4363 f
->output_data
.w32
->explicit_parent
= 0;
4366 /* Set the name; the functions to which we pass f expect the name to
4368 if (EQ (name
, Qunbound
) || NILP (name
))
4370 f
->name
= build_string (dpyinfo
->w32_id_name
);
4371 f
->explicit_name
= 0;
4376 f
->explicit_name
= 1;
4377 /* use the frame's title when getting resources for this frame. */
4378 specbind (Qx_resource_name
, name
);
4381 f
->resx
= dpyinfo
->resx
;
4382 f
->resy
= dpyinfo
->resy
;
4384 #ifdef USE_FONT_BACKEND
4385 if (enable_font_backend
)
4387 /* Perhaps, we must allow frame parameter, say `font-backend',
4388 to specify which font backends to use. */
4389 register_font_driver (&w32font_driver
, f
);
4391 x_default_parameter (f
, parameters
, Qfont_backend
, Qnil
,
4392 "fontBackend", "FontBackend", RES_TYPE_STRING
);
4394 #endif /* USE_FONT_BACKEND */
4396 /* Extract the window parameters from the supplied values
4397 that are needed to determine window geometry. */
4398 #ifdef USE_FONT_BACKEND
4399 if (enable_font_backend
)
4400 x_default_font_parameter (f
, parameters
);
4406 font
= w32_get_arg (parameters
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4409 /* First, try whatever font the caller has specified. */
4412 tem
= Fquery_fontset (font
, Qnil
);
4414 font
= x_new_fontset (f
, tem
);
4416 font
= x_new_font (f
, SDATA (font
));
4418 /* Try out a font which we hope has bold and italic variations. */
4419 if (!STRINGP (font
))
4420 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
4421 if (! STRINGP (font
))
4422 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
4423 /* If those didn't work, look for something which will at least work. */
4424 if (! STRINGP (font
))
4425 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
4427 if (! STRINGP (font
))
4428 font
= build_string ("Fixedsys");
4430 x_default_parameter (f
, parameters
, Qfont
, font
,
4431 "font", "Font", RES_TYPE_STRING
);
4434 x_default_parameter (f
, parameters
, Qborder_width
, make_number (2),
4435 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4436 /* This defaults to 2 in order to match xterm. We recognize either
4437 internalBorderWidth or internalBorder (which is what xterm calls
4439 if (NILP (Fassq (Qinternal_border_width
, parameters
)))
4443 value
= w32_get_arg (parameters
, Qinternal_border_width
,
4444 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
4445 if (! EQ (value
, Qunbound
))
4446 parameters
= Fcons (Fcons (Qinternal_border_width
, value
),
4449 /* Default internalBorderWidth to 0 on Windows to match other programs. */
4450 x_default_parameter (f
, parameters
, Qinternal_border_width
, make_number (0),
4451 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
4452 x_default_parameter (f
, parameters
, Qvertical_scroll_bars
, Qright
,
4453 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
4455 /* Also do the stuff which must be set before the window exists. */
4456 x_default_parameter (f
, parameters
, Qforeground_color
, build_string ("black"),
4457 "foreground", "Foreground", RES_TYPE_STRING
);
4458 x_default_parameter (f
, parameters
, Qbackground_color
, build_string ("white"),
4459 "background", "Background", RES_TYPE_STRING
);
4460 x_default_parameter (f
, parameters
, Qmouse_color
, build_string ("black"),
4461 "pointerColor", "Foreground", RES_TYPE_STRING
);
4462 x_default_parameter (f
, parameters
, Qcursor_color
, build_string ("black"),
4463 "cursorColor", "Foreground", RES_TYPE_STRING
);
4464 x_default_parameter (f
, parameters
, Qborder_color
, build_string ("black"),
4465 "borderColor", "BorderColor", RES_TYPE_STRING
);
4466 x_default_parameter (f
, parameters
, Qscreen_gamma
, Qnil
,
4467 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
4468 x_default_parameter (f
, parameters
, Qline_spacing
, Qnil
,
4469 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
4470 x_default_parameter (f
, parameters
, Qleft_fringe
, Qnil
,
4471 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
4472 x_default_parameter (f
, parameters
, Qright_fringe
, Qnil
,
4473 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
4476 /* Init faces before x_default_parameter is called for scroll-bar
4477 parameters because that function calls x_set_scroll_bar_width,
4478 which calls change_frame_size, which calls Fset_window_buffer,
4479 which runs hooks, which call Fvertical_motion. At the end, we
4480 end up in init_iterator with a null face cache, which should not
4482 init_frame_faces (f
);
4484 x_default_parameter (f
, parameters
, Qmenu_bar_lines
, make_number (1),
4485 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
4486 x_default_parameter (f
, parameters
, Qtool_bar_lines
, make_number (1),
4487 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
4489 x_default_parameter (f
, parameters
, Qbuffer_predicate
, Qnil
,
4490 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
4491 x_default_parameter (f
, parameters
, Qtitle
, Qnil
,
4492 "title", "Title", RES_TYPE_STRING
);
4493 x_default_parameter (f
, parameters
, Qfullscreen
, Qnil
,
4494 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
4496 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
4497 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4499 f
->output_data
.w32
->text_cursor
= w32_load_cursor (IDC_IBEAM
);
4500 f
->output_data
.w32
->nontext_cursor
= w32_load_cursor (IDC_ARROW
);
4501 f
->output_data
.w32
->modeline_cursor
= w32_load_cursor (IDC_ARROW
);
4502 f
->output_data
.w32
->hand_cursor
= w32_load_cursor (IDC_HAND
);
4503 f
->output_data
.w32
->hourglass_cursor
= w32_load_cursor (IDC_WAIT
);
4504 f
->output_data
.w32
->horizontal_drag_cursor
= w32_load_cursor (IDC_SIZEWE
);
4506 window_prompting
= x_figure_window_size (f
, parameters
, 1);
4508 tem
= w32_get_arg (parameters
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
4509 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
4511 w32_window (f
, window_prompting
, minibuffer_only
);
4512 x_icon (f
, parameters
);
4516 /* Now consider the frame official. */
4517 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
4518 Vframe_list
= Fcons (frame
, Vframe_list
);
4520 /* We need to do this after creating the window, so that the
4521 icon-creation functions can say whose icon they're describing. */
4522 x_default_parameter (f
, parameters
, Qicon_type
, Qnil
,
4523 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
4525 x_default_parameter (f
, parameters
, Qauto_raise
, Qnil
,
4526 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4527 x_default_parameter (f
, parameters
, Qauto_lower
, Qnil
,
4528 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4529 x_default_parameter (f
, parameters
, Qcursor_type
, Qbox
,
4530 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4531 x_default_parameter (f
, parameters
, Qscroll_bar_width
, Qnil
,
4532 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
4534 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4535 Change will not be effected unless different from the current
4537 width
= FRAME_COLS (f
);
4538 height
= FRAME_LINES (f
);
4540 FRAME_LINES (f
) = 0;
4541 SET_FRAME_COLS (f
, 0);
4542 change_frame_size (f
, height
, width
, 1, 0, 0);
4544 /* Tell the server what size and position, etc, we want, and how
4545 badly we want them. This should be done after we have the menu
4546 bar so that its size can be taken into account. */
4548 x_wm_set_size_hint (f
, window_prompting
, 0);
4551 /* Make the window appear on the frame and enable display, unless
4552 the caller says not to. However, with explicit parent, Emacs
4553 cannot control visibility, so don't try. */
4554 if (! f
->output_data
.w32
->explicit_parent
)
4556 Lisp_Object visibility
;
4558 visibility
= w32_get_arg (parameters
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
4559 if (EQ (visibility
, Qunbound
))
4562 if (EQ (visibility
, Qicon
))
4563 x_iconify_frame (f
);
4564 else if (! NILP (visibility
))
4565 x_make_frame_visible (f
);
4567 /* Must have been Qnil. */
4571 /* Initialize `default-minibuffer-frame' in case this is the first
4572 frame on this terminal. */
4573 if (FRAME_HAS_MINIBUF_P (f
)
4574 && (!FRAMEP (kb
->Vdefault_minibuffer_frame
)
4575 || !FRAME_LIVE_P (XFRAME (kb
->Vdefault_minibuffer_frame
))))
4576 kb
->Vdefault_minibuffer_frame
= frame
;
4578 /* All remaining specified parameters, which have not been "used"
4579 by x_get_arg and friends, now go in the misc. alist of the frame. */
4580 for (tem
= parameters
; CONSP (tem
); tem
= XCDR (tem
))
4581 if (CONSP (XCAR (tem
)) && !NILP (XCAR (XCAR (tem
))))
4582 f
->param_alist
= Fcons (XCAR (tem
), f
->param_alist
);
4586 /* Make sure windows on this frame appear in calls to next-window
4587 and similar functions. */
4588 Vwindow_list
= Qnil
;
4590 return unbind_to (count
, frame
);
4593 /* FRAME is used only to get a handle on the X display. We don't pass the
4594 display info directly because we're called from frame.c, which doesn't
4595 know about that structure. */
4597 x_get_focus_frame (frame
)
4598 struct frame
*frame
;
4600 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
4602 if (! dpyinfo
->w32_focus_frame
)
4605 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
4609 DEFUN ("x-focus-frame", Fx_focus_frame
, Sx_focus_frame
, 1, 1, 0,
4610 doc
: /* Give FRAME input focus, raising to foreground if necessary. */)
4614 x_focus_on_frame (check_x_frame (frame
));
4619 /* Return the charset portion of a font name. */
4621 xlfd_charset_of_font (char * fontname
)
4623 char *charset
, *encoding
;
4625 encoding
= strrchr (fontname
, '-');
4626 if (!encoding
|| encoding
== fontname
)
4629 for (charset
= encoding
- 1; charset
>= fontname
; charset
--)
4630 if (*charset
== '-')
4633 if (charset
== fontname
|| strcmp (charset
, "-*-*") == 0)
4639 struct font_info
*w32_load_bdf_font (struct frame
*f
, char *fontname
,
4640 int size
, char* filename
);
4641 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
);
4642 static BOOL
w32_to_x_font (LOGFONT
* lplf
, char * lpxstr
, int len
,
4644 static BOOL
x_to_w32_font (char *lpxstr
, LOGFONT
*lplogfont
);
4646 static struct font_info
*
4647 w32_load_system_font (f
, fontname
, size
)
4652 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4653 Lisp_Object font_names
;
4655 /* Get a list of all the fonts that match this name. Once we
4656 have a list of matching fonts, we compare them against the fonts
4657 we already have loaded by comparing names. */
4658 font_names
= w32_list_fonts (f
, build_string (fontname
), size
, 100);
4660 if (!NILP (font_names
))
4665 /* First check if any are already loaded, as that is cheaper
4666 than loading another one. */
4667 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
4668 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
4669 if (dpyinfo
->font_table
[i
].name
4670 && (!strcmp (dpyinfo
->font_table
[i
].name
,
4671 SDATA (XCAR (tail
)))
4672 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
4673 SDATA (XCAR (tail
)))))
4674 return (dpyinfo
->font_table
+ i
);
4676 fontname
= (char *) SDATA (XCAR (font_names
));
4678 else if (w32_strict_fontnames
)
4680 /* If EnumFontFamiliesEx was available, we got a full list of
4681 fonts back so stop now to avoid the possibility of loading a
4682 random font. If we had to fall back to EnumFontFamilies, the
4683 list is incomplete, so continue whether the font we want was
4685 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
4686 FARPROC enum_font_families_ex
4687 = GetProcAddress (gdi32
, "EnumFontFamiliesExA");
4688 if (enum_font_families_ex
)
4692 /* Load the font and add it to the table. */
4694 char *full_name
, *encoding
, *charset
;
4696 struct font_info
*fontp
;
4702 if (!fontname
|| !x_to_w32_font (fontname
, &lf
))
4705 if (!*lf
.lfFaceName
)
4706 /* If no name was specified for the font, we get a random font
4707 from CreateFontIndirect - this is not particularly
4708 desirable, especially since CreateFontIndirect does not
4709 fill out the missing name in lf, so we never know what we
4713 lf
.lfQuality
= DEFAULT_QUALITY
;
4715 font
= (XFontStruct
*) xmalloc (sizeof (XFontStruct
));
4716 bzero (font
, sizeof (*font
));
4718 /* Set bdf to NULL to indicate that this is a Windows font. */
4723 font
->hfont
= CreateFontIndirect (&lf
);
4725 if (font
->hfont
== NULL
)
4734 codepage
= w32_codepage_for_font (fontname
);
4736 hdc
= GetDC (dpyinfo
->root_window
);
4737 oldobj
= SelectObject (hdc
, font
->hfont
);
4739 ok
= GetTextMetrics (hdc
, &font
->tm
);
4740 if (codepage
== CP_UNICODE
)
4741 font
->double_byte_p
= 1;
4744 /* Unfortunately, some fonts (eg. MingLiU, a big5 ttf font)
4745 don't report themselves as double byte fonts, when
4746 patently they are. So instead of trusting
4747 GetFontLanguageInfo, we check the properties of the
4748 codepage directly, since that is ultimately what we are
4749 working from anyway. */
4750 /* font->double_byte_p = GetFontLanguageInfo (hdc) & GCP_DBCS; */
4752 GetCPInfo (codepage
, &cpi
);
4753 font
->double_byte_p
= cpi
.MaxCharSize
> 1;
4756 SelectObject (hdc
, oldobj
);
4757 ReleaseDC (dpyinfo
->root_window
, hdc
);
4758 /* Fill out details in lf according to the font that was
4760 lf
.lfHeight
= font
->tm
.tmInternalLeading
- font
->tm
.tmHeight
;
4761 lf
.lfWidth
= font
->tm
.tmMaxCharWidth
;
4762 lf
.lfWeight
= font
->tm
.tmWeight
;
4763 lf
.lfItalic
= font
->tm
.tmItalic
;
4764 lf
.lfCharSet
= font
->tm
.tmCharSet
;
4765 lf
.lfPitchAndFamily
= ((font
->tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
)
4766 ? VARIABLE_PITCH
: FIXED_PITCH
);
4767 lf
.lfOutPrecision
= ((font
->tm
.tmPitchAndFamily
& TMPF_VECTOR
)
4768 ? OUT_STROKE_PRECIS
: OUT_STRING_PRECIS
);
4770 w32_cache_char_metrics (font
);
4777 w32_unload_font (dpyinfo
, font
);
4781 /* Find a free slot in the font table. */
4782 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
4783 if (dpyinfo
->font_table
[i
].name
== NULL
)
4786 /* If no free slot found, maybe enlarge the font table. */
4787 if (i
== dpyinfo
->n_fonts
4788 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
4791 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
4792 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
4794 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
4797 fontp
= dpyinfo
->font_table
+ i
;
4798 if (i
== dpyinfo
->n_fonts
)
4801 /* Now fill in the slots of *FONTP. */
4803 bzero (fontp
, sizeof (*fontp
));
4805 fontp
->font_idx
= i
;
4806 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
4807 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
4809 if ((lf
.lfPitchAndFamily
& 0x03) == FIXED_PITCH
)
4811 /* Fixed width font. */
4812 fontp
->average_width
= fontp
->space_width
= FONT_AVG_WIDTH (font
);
4818 pcm
= w32_per_char_metric (font
, &space
, ANSI_FONT
);
4820 fontp
->space_width
= pcm
->width
;
4822 fontp
->space_width
= FONT_AVG_WIDTH (font
);
4824 fontp
->average_width
= font
->tm
.tmAveCharWidth
;
4827 fontp
->charset
= -1;
4828 charset
= xlfd_charset_of_font (fontname
);
4830 /* Cache the W32 codepage for a font. This makes w32_encode_char
4831 (called for every glyph during redisplay) much faster. */
4832 fontp
->codepage
= codepage
;
4834 /* Work out the font's full name. */
4835 full_name
= (char *)xmalloc (100);
4836 if (full_name
&& w32_to_x_font (&lf
, full_name
, 100, charset
))
4837 fontp
->full_name
= full_name
;
4840 /* If all else fails - just use the name we used to load it. */
4842 fontp
->full_name
= fontp
->name
;
4845 fontp
->size
= FONT_WIDTH (font
);
4846 fontp
->height
= FONT_HEIGHT (font
);
4848 /* The slot `encoding' specifies how to map a character
4849 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
4850 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
4851 (0:0x20..0x7F, 1:0xA0..0xFF,
4852 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
4853 2:0xA020..0xFF7F). For the moment, we don't know which charset
4854 uses this font. So, we set information in fontp->encoding_type
4855 which is never used by any charset. If mapping can't be
4856 decided, set FONT_ENCODING_NOT_DECIDED. */
4858 /* SJIS fonts need to be set to type 4, all others seem to work as
4859 type FONT_ENCODING_NOT_DECIDED. */
4860 encoding
= strrchr (fontp
->name
, '-');
4861 if (encoding
&& strnicmp (encoding
+1, "sjis", 4) == 0)
4862 fontp
->encoding_type
= 4;
4864 fontp
->encoding_type
= FONT_ENCODING_NOT_DECIDED
;
4866 /* The following three values are set to 0 under W32, which is
4867 what they get set to if XGetFontProperty fails under X. */
4868 fontp
->baseline_offset
= 0;
4869 fontp
->relative_compose
= 0;
4870 fontp
->default_ascent
= 0;
4872 /* Set global flag fonts_changed_p to non-zero if the font loaded
4873 has a character with a smaller width than any other character
4874 before, or if the font loaded has a smaller height than any
4875 other font loaded before. If this happens, it will make a
4876 glyph matrix reallocation necessary. */
4877 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
4883 /* Load font named FONTNAME of size SIZE for frame F, and return a
4884 pointer to the structure font_info while allocating it dynamically.
4885 If loading fails, return NULL. */
4887 w32_load_font (f
, fontname
, size
)
4892 Lisp_Object bdf_fonts
;
4893 struct font_info
*retval
= NULL
;
4894 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4896 bdf_fonts
= w32_list_bdf_fonts (build_string (fontname
), 1);
4898 while (!retval
&& CONSP (bdf_fonts
))
4900 char *bdf_name
, *bdf_file
;
4901 Lisp_Object bdf_pair
;
4904 bdf_name
= SDATA (XCAR (bdf_fonts
));
4905 bdf_pair
= Fassoc (XCAR (bdf_fonts
), Vw32_bdf_filename_alist
);
4906 bdf_file
= SDATA (XCDR (bdf_pair
));
4908 // If the font is already loaded, do not load it again.
4909 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
4911 if ((dpyinfo
->font_table
[i
].name
4912 && !strcmp (dpyinfo
->font_table
[i
].name
, bdf_name
))
4913 || (dpyinfo
->font_table
[i
].full_name
4914 && !strcmp (dpyinfo
->font_table
[i
].full_name
, bdf_name
)))
4915 return dpyinfo
->font_table
+ i
;
4918 retval
= w32_load_bdf_font (f
, bdf_name
, size
, bdf_file
);
4920 bdf_fonts
= XCDR (bdf_fonts
);
4926 return w32_load_system_font (f
, fontname
, size
);
4931 w32_unload_font (dpyinfo
, font
)
4932 struct w32_display_info
*dpyinfo
;
4937 if (font
->per_char
) xfree (font
->per_char
);
4938 if (font
->bdf
) w32_free_bdf_font (font
->bdf
);
4940 if (font
->hfont
) DeleteObject (font
->hfont
);
4945 /* The font conversion stuff between x and w32 */
4947 /* X font string is as follows (from faces.el)
4951 * (weight "\\(bold\\|demibold\\|medium\\)") ; 1
4952 * (weight\? "\\([^-]*\\)") ; 1
4953 * (slant "\\([ior]\\)") ; 2
4954 * (slant\? "\\([^-]?\\)") ; 2
4955 * (swidth "\\([^-]*\\)") ; 3
4956 * (adstyle "[^-]*") ; 4
4957 * (pixelsize "[0-9]+")
4958 * (pointsize "[0-9][0-9]+")
4959 * (resx "[0-9][0-9]+")
4960 * (resy "[0-9][0-9]+")
4961 * (spacing "[cmp?*]")
4962 * (avgwidth "[0-9]+")
4963 * (registry "[^-]+")
4964 * (encoding "[^-]+")
4969 x_to_w32_weight (lpw
)
4972 if (!lpw
) return (FW_DONTCARE
);
4974 if (stricmp (lpw
, "heavy") == 0) return FW_HEAVY
;
4975 else if (stricmp (lpw
, "extrabold") == 0) return FW_EXTRABOLD
;
4976 else if (stricmp (lpw
, "bold") == 0) return FW_BOLD
;
4977 else if (stricmp (lpw
, "demibold") == 0) return FW_SEMIBOLD
;
4978 else if (stricmp (lpw
, "semibold") == 0) return FW_SEMIBOLD
;
4979 else if (stricmp (lpw
, "medium") == 0) return FW_MEDIUM
;
4980 else if (stricmp (lpw
, "normal") == 0) return FW_NORMAL
;
4981 else if (stricmp (lpw
, "light") == 0) return FW_LIGHT
;
4982 else if (stricmp (lpw
, "extralight") == 0) return FW_EXTRALIGHT
;
4983 else if (stricmp (lpw
, "thin") == 0) return FW_THIN
;
4990 w32_to_x_weight (fnweight
)
4993 if (fnweight
>= FW_HEAVY
) return "heavy";
4994 if (fnweight
>= FW_EXTRABOLD
) return "extrabold";
4995 if (fnweight
>= FW_BOLD
) return "bold";
4996 if (fnweight
>= FW_SEMIBOLD
) return "demibold";
4997 if (fnweight
>= FW_MEDIUM
) return "medium";
4998 if (fnweight
>= FW_NORMAL
) return "normal";
4999 if (fnweight
>= FW_LIGHT
) return "light";
5000 if (fnweight
>= FW_EXTRALIGHT
) return "extralight";
5001 if (fnweight
>= FW_THIN
) return "thin";
5007 x_to_w32_charset (lpcs
)
5010 Lisp_Object this_entry
, w32_charset
;
5012 int len
= strlen (lpcs
);
5014 /* Support "*-#nnn" format for unknown charsets. */
5015 if (strncmp (lpcs
, "*-#", 3) == 0)
5016 return atoi (lpcs
+ 3);
5018 /* All Windows fonts qualify as unicode. */
5019 if (!strncmp (lpcs
, "iso10646", 8))
5020 return DEFAULT_CHARSET
;
5022 /* Handle wildcards by ignoring them; eg. treat "big5*-*" as "big5". */
5023 charset
= alloca (len
+ 1);
5024 strcpy (charset
, lpcs
);
5025 lpcs
= strchr (charset
, '*');
5029 /* Look through w32-charset-info-alist for the character set.
5030 Format of each entry is
5031 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5033 this_entry
= Fassoc (build_string (charset
), Vw32_charset_info_alist
);
5035 if (NILP (this_entry
))
5037 /* At startup, we want iso8859-1 fonts to come up properly. */
5038 if (stricmp (charset
, "iso8859-1") == 0)
5039 return ANSI_CHARSET
;
5041 return DEFAULT_CHARSET
;
5044 w32_charset
= Fcar (Fcdr (this_entry
));
5046 /* Translate Lisp symbol to number. */
5047 if (EQ (w32_charset
, Qw32_charset_ansi
))
5048 return ANSI_CHARSET
;
5049 if (EQ (w32_charset
, Qw32_charset_symbol
))
5050 return SYMBOL_CHARSET
;
5051 if (EQ (w32_charset
, Qw32_charset_shiftjis
))
5052 return SHIFTJIS_CHARSET
;
5053 if (EQ (w32_charset
, Qw32_charset_hangeul
))
5054 return HANGEUL_CHARSET
;
5055 if (EQ (w32_charset
, Qw32_charset_chinesebig5
))
5056 return CHINESEBIG5_CHARSET
;
5057 if (EQ (w32_charset
, Qw32_charset_gb2312
))
5058 return GB2312_CHARSET
;
5059 if (EQ (w32_charset
, Qw32_charset_oem
))
5061 #ifdef JOHAB_CHARSET
5062 if (EQ (w32_charset
, Qw32_charset_johab
))
5063 return JOHAB_CHARSET
;
5064 if (EQ (w32_charset
, Qw32_charset_easteurope
))
5065 return EASTEUROPE_CHARSET
;
5066 if (EQ (w32_charset
, Qw32_charset_turkish
))
5067 return TURKISH_CHARSET
;
5068 if (EQ (w32_charset
, Qw32_charset_baltic
))
5069 return BALTIC_CHARSET
;
5070 if (EQ (w32_charset
, Qw32_charset_russian
))
5071 return RUSSIAN_CHARSET
;
5072 if (EQ (w32_charset
, Qw32_charset_arabic
))
5073 return ARABIC_CHARSET
;
5074 if (EQ (w32_charset
, Qw32_charset_greek
))
5075 return GREEK_CHARSET
;
5076 if (EQ (w32_charset
, Qw32_charset_hebrew
))
5077 return HEBREW_CHARSET
;
5078 if (EQ (w32_charset
, Qw32_charset_vietnamese
))
5079 return VIETNAMESE_CHARSET
;
5080 if (EQ (w32_charset
, Qw32_charset_thai
))
5081 return THAI_CHARSET
;
5082 if (EQ (w32_charset
, Qw32_charset_mac
))
5084 #endif /* JOHAB_CHARSET */
5085 #ifdef UNICODE_CHARSET
5086 if (EQ (w32_charset
, Qw32_charset_unicode
))
5087 return UNICODE_CHARSET
;
5090 return DEFAULT_CHARSET
;
5095 w32_to_x_charset (fncharset
, matching
)
5099 static char buf
[32];
5100 Lisp_Object charset_type
;
5105 /* If fully specified, accept it as it is. Otherwise use a
5107 char *wildcard
= strchr (matching
, '*');
5110 else if (strchr (matching
, '-'))
5113 match_len
= strlen (matching
);
5119 /* Handle startup case of w32-charset-info-alist not
5120 being set up yet. */
5121 if (NILP (Vw32_charset_info_alist
))
5123 charset_type
= Qw32_charset_ansi
;
5125 case DEFAULT_CHARSET
:
5126 charset_type
= Qw32_charset_default
;
5128 case SYMBOL_CHARSET
:
5129 charset_type
= Qw32_charset_symbol
;
5131 case SHIFTJIS_CHARSET
:
5132 charset_type
= Qw32_charset_shiftjis
;
5134 case HANGEUL_CHARSET
:
5135 charset_type
= Qw32_charset_hangeul
;
5137 case GB2312_CHARSET
:
5138 charset_type
= Qw32_charset_gb2312
;
5140 case CHINESEBIG5_CHARSET
:
5141 charset_type
= Qw32_charset_chinesebig5
;
5144 charset_type
= Qw32_charset_oem
;
5147 /* More recent versions of Windows (95 and NT4.0) define more
5149 #ifdef EASTEUROPE_CHARSET
5150 case EASTEUROPE_CHARSET
:
5151 charset_type
= Qw32_charset_easteurope
;
5153 case TURKISH_CHARSET
:
5154 charset_type
= Qw32_charset_turkish
;
5156 case BALTIC_CHARSET
:
5157 charset_type
= Qw32_charset_baltic
;
5159 case RUSSIAN_CHARSET
:
5160 charset_type
= Qw32_charset_russian
;
5162 case ARABIC_CHARSET
:
5163 charset_type
= Qw32_charset_arabic
;
5166 charset_type
= Qw32_charset_greek
;
5168 case HEBREW_CHARSET
:
5169 charset_type
= Qw32_charset_hebrew
;
5171 case VIETNAMESE_CHARSET
:
5172 charset_type
= Qw32_charset_vietnamese
;
5175 charset_type
= Qw32_charset_thai
;
5178 charset_type
= Qw32_charset_mac
;
5181 charset_type
= Qw32_charset_johab
;
5185 #ifdef UNICODE_CHARSET
5186 case UNICODE_CHARSET
:
5187 charset_type
= Qw32_charset_unicode
;
5191 /* Encode numerical value of unknown charset. */
5192 sprintf (buf
, "*-#%u", fncharset
);
5198 char * best_match
= NULL
;
5199 int matching_found
= 0;
5201 /* Look through w32-charset-info-alist for the character set.
5202 Prefer ISO codepages, and prefer lower numbers in the ISO
5203 range. Only return charsets for codepages which are installed.
5205 Format of each entry is
5206 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5208 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
5211 Lisp_Object w32_charset
;
5212 Lisp_Object codepage
;
5214 Lisp_Object this_entry
= XCAR (rest
);
5216 /* Skip invalid entries in alist. */
5217 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
5218 || !CONSP (XCDR (this_entry
))
5219 || !SYMBOLP (XCAR (XCDR (this_entry
))))
5222 x_charset
= SDATA (XCAR (this_entry
));
5223 w32_charset
= XCAR (XCDR (this_entry
));
5224 codepage
= XCDR (XCDR (this_entry
));
5226 /* Look for Same charset and a valid codepage (or non-int
5227 which means ignore). */
5228 if (EQ (w32_charset
, charset_type
)
5229 && (!INTEGERP (codepage
) || XINT (codepage
) == CP_DEFAULT
5230 || IsValidCodePage (XINT (codepage
))))
5232 /* If we don't have a match already, then this is the
5236 best_match
= x_charset
;
5237 if (matching
&& !strnicmp (x_charset
, matching
, match_len
))
5240 /* If we already found a match for MATCHING, then
5241 only consider other matches. */
5242 else if (matching_found
5243 && strnicmp (x_charset
, matching
, match_len
))
5245 /* If this matches what we want, and the best so far doesn't,
5246 then this is better. */
5247 else if (!matching_found
&& matching
5248 && !strnicmp (x_charset
, matching
, match_len
))
5250 best_match
= x_charset
;
5253 /* If this is fully specified, and the best so far isn't,
5254 then this is better. */
5255 else if ((!strchr (best_match
, '-') && strchr (x_charset
, '-'))
5256 /* If this is an ISO codepage, and the best so far isn't,
5257 then this is better, but only if it fully specifies the
5259 || (strnicmp (best_match
, "iso", 3) != 0
5260 && strnicmp (x_charset
, "iso", 3) == 0
5261 && strchr (x_charset
, '-')))
5262 best_match
= x_charset
;
5263 /* If both are ISO8859 codepages, choose the one with the
5264 lowest number in the encoding field. */
5265 else if (strnicmp (best_match
, "iso8859-", 8) == 0
5266 && strnicmp (x_charset
, "iso8859-", 8) == 0)
5268 int best_enc
= atoi (best_match
+ 8);
5269 int this_enc
= atoi (x_charset
+ 8);
5270 if (this_enc
> 0 && this_enc
< best_enc
)
5271 best_match
= x_charset
;
5276 /* If no match, encode the numeric value. */
5279 sprintf (buf
, "*-#%u", fncharset
);
5283 strncpy (buf
, best_match
, 31);
5284 /* If the charset is not fully specified, put -0 on the end. */
5285 if (!strchr (best_match
, '-'))
5287 int pos
= strlen (best_match
);
5288 /* Charset specifiers shouldn't be very long. If it is a made
5289 up one, truncating it should not do any harm since it isn't
5290 recognized anyway. */
5293 strcpy (buf
+ pos
, "-0");
5301 /* Return all the X charsets that map to a font. */
5303 w32_to_all_x_charsets (fncharset
)
5306 static char buf
[32];
5307 Lisp_Object charset_type
;
5308 Lisp_Object retval
= Qnil
;
5313 /* Handle startup case of w32-charset-info-alist not
5314 being set up yet. */
5315 if (NILP (Vw32_charset_info_alist
))
5316 return Fcons (build_string ("iso8859-1"), Qnil
);
5318 charset_type
= Qw32_charset_ansi
;
5320 case DEFAULT_CHARSET
:
5321 charset_type
= Qw32_charset_default
;
5323 case SYMBOL_CHARSET
:
5324 charset_type
= Qw32_charset_symbol
;
5326 case SHIFTJIS_CHARSET
:
5327 charset_type
= Qw32_charset_shiftjis
;
5329 case HANGEUL_CHARSET
:
5330 charset_type
= Qw32_charset_hangeul
;
5332 case GB2312_CHARSET
:
5333 charset_type
= Qw32_charset_gb2312
;
5335 case CHINESEBIG5_CHARSET
:
5336 charset_type
= Qw32_charset_chinesebig5
;
5339 charset_type
= Qw32_charset_oem
;
5342 /* More recent versions of Windows (95 and NT4.0) define more
5344 #ifdef EASTEUROPE_CHARSET
5345 case EASTEUROPE_CHARSET
:
5346 charset_type
= Qw32_charset_easteurope
;
5348 case TURKISH_CHARSET
:
5349 charset_type
= Qw32_charset_turkish
;
5351 case BALTIC_CHARSET
:
5352 charset_type
= Qw32_charset_baltic
;
5354 case RUSSIAN_CHARSET
:
5355 charset_type
= Qw32_charset_russian
;
5357 case ARABIC_CHARSET
:
5358 charset_type
= Qw32_charset_arabic
;
5361 charset_type
= Qw32_charset_greek
;
5363 case HEBREW_CHARSET
:
5364 charset_type
= Qw32_charset_hebrew
;
5366 case VIETNAMESE_CHARSET
:
5367 charset_type
= Qw32_charset_vietnamese
;
5370 charset_type
= Qw32_charset_thai
;
5373 charset_type
= Qw32_charset_mac
;
5376 charset_type
= Qw32_charset_johab
;
5380 #ifdef UNICODE_CHARSET
5381 case UNICODE_CHARSET
:
5382 charset_type
= Qw32_charset_unicode
;
5386 /* Encode numerical value of unknown charset. */
5387 sprintf (buf
, "*-#%u", fncharset
);
5388 return Fcons (build_string (buf
), Qnil
);
5393 /* Look through w32-charset-info-alist for the character set.
5394 Only return fully specified charsets for codepages which are
5397 Format of each entry in Vw32_charset_info_alist is
5398 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5400 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
5402 Lisp_Object x_charset
;
5403 Lisp_Object w32_charset
;
5404 Lisp_Object codepage
;
5406 Lisp_Object this_entry
= XCAR (rest
);
5408 /* Skip invalid entries in alist. */
5409 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
5410 || !CONSP (XCDR (this_entry
))
5411 || !SYMBOLP (XCAR (XCDR (this_entry
))))
5414 x_charset
= XCAR (this_entry
);
5415 w32_charset
= XCAR (XCDR (this_entry
));
5416 codepage
= XCDR (XCDR (this_entry
));
5418 if (!strchr (SDATA (x_charset
), '-'))
5421 /* Look for Same charset and a valid codepage (or non-int
5422 which means ignore). */
5423 if (EQ (w32_charset
, charset_type
)
5424 && (!INTEGERP (codepage
) || XINT (codepage
) == CP_DEFAULT
5425 || IsValidCodePage (XINT (codepage
))))
5427 retval
= Fcons (x_charset
, retval
);
5431 /* If no match, encode the numeric value. */
5434 sprintf (buf
, "*-#%u", fncharset
);
5435 return Fcons (build_string (buf
), Qnil
);
5442 /* Get the Windows codepage corresponding to the specified font. The
5443 charset info in the font name is used to look up
5444 w32-charset-to-codepage-alist. */
5446 w32_codepage_for_font (char *fontname
)
5448 Lisp_Object codepage
, entry
;
5449 char *charset_str
, *charset
, *end
;
5451 /* Extract charset part of font string. */
5452 charset
= xlfd_charset_of_font (fontname
);
5457 charset_str
= (char *) alloca (strlen (charset
) + 1);
5458 strcpy (charset_str
, charset
);
5461 /* Remove leading "*-". */
5462 if (strncmp ("*-", charset_str
, 2) == 0)
5463 charset
= charset_str
+ 2;
5466 charset
= charset_str
;
5468 /* Stop match at wildcard (including preceding '-'). */
5469 if (end
= strchr (charset
, '*'))
5471 if (end
> charset
&& *(end
-1) == '-')
5476 if (!strcmp (charset
, "iso10646"))
5479 if (NILP (Vw32_charset_info_alist
))
5482 entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
5486 codepage
= Fcdr (Fcdr (entry
));
5488 if (NILP (codepage
))
5490 else if (XFASTINT (codepage
) == XFASTINT (Qt
))
5492 else if (INTEGERP (codepage
))
5493 return XINT (codepage
);
5500 w32_to_x_font (lplogfont
, lpxstr
, len
, specific_charset
)
5501 LOGFONT
* lplogfont
;
5504 char * specific_charset
;
5508 char height_pixels
[8];
5510 char width_pixels
[8];
5511 char *fontname_dash
;
5512 int display_resy
= (int) one_w32_display_info
.resy
;
5513 int display_resx
= (int) one_w32_display_info
.resx
;
5514 struct coding_system coding
;
5516 if (!lpxstr
) abort ();
5521 if (lplogfont
->lfOutPrecision
== OUT_STRING_PRECIS
)
5522 fonttype
= "raster";
5523 else if (lplogfont
->lfOutPrecision
== OUT_STROKE_PRECIS
)
5524 fonttype
= "outline";
5526 fonttype
= "unknown";
5528 setup_coding_system (Fcheck_coding_system (Vlocale_coding_system
),
5530 coding
.src_multibyte
= 0;
5531 coding
.dst_multibyte
= 1;
5532 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
5533 /* We explicitely disable composition handling because selection
5534 data should not contain any composition sequence. */
5535 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
5537 coding
.dst_bytes
= LF_FACESIZE
* 2;
5538 coding
.destination
= (unsigned char *) xmalloc (coding
.dst_bytes
+ 1);
5539 decode_coding_c_string (&coding
, lplogfont
->lfFaceName
,
5540 strlen(lplogfont
->lfFaceName
), Qnil
);
5541 fontname
= coding
.destination
;
5543 *(fontname
+ coding
.produced
) = '\0';
5545 /* Replace dashes with underscores so the dashes are not
5547 fontname_dash
= fontname
;
5548 while (fontname_dash
= strchr (fontname_dash
, '-'))
5549 *fontname_dash
= '_';
5551 if (lplogfont
->lfHeight
)
5553 sprintf (height_pixels
, "%u", eabs (lplogfont
->lfHeight
));
5554 sprintf (height_dpi
, "%u",
5555 eabs (lplogfont
->lfHeight
) * 720 / display_resy
);
5559 strcpy (height_pixels
, "*");
5560 strcpy (height_dpi
, "*");
5563 #if 0 /* Never put the width in the xfld. It fails on fonts with
5564 double-width characters. */
5565 if (lplogfont
->lfWidth
)
5566 sprintf (width_pixels
, "%u", lplogfont
->lfWidth
* 10);
5569 strcpy (width_pixels
, "*");
5571 _snprintf (lpxstr
, len
- 1,
5572 "-%s-%s-%s-%c-normal-normal-%s-%s-%d-%d-%c-%s-%s",
5573 fonttype
, /* foundry */
5574 fontname
, /* family */
5575 w32_to_x_weight (lplogfont
->lfWeight
), /* weight */
5576 lplogfont
->lfItalic
?'i':'r', /* slant */
5578 /* add style name */
5579 height_pixels
, /* pixel size */
5580 height_dpi
, /* point size */
5581 display_resx
, /* resx */
5582 display_resy
, /* resy */
5583 ((lplogfont
->lfPitchAndFamily
& 0x3) == VARIABLE_PITCH
)
5584 ? 'p' : 'c', /* spacing */
5585 width_pixels
, /* avg width */
5586 w32_to_x_charset (lplogfont
->lfCharSet
, specific_charset
)
5587 /* charset registry and encoding */
5590 lpxstr
[len
- 1] = 0; /* just to be sure */
5595 x_to_w32_font (lpxstr
, lplogfont
)
5597 LOGFONT
* lplogfont
;
5599 struct coding_system coding
;
5601 if (!lplogfont
) return (FALSE
);
5603 memset (lplogfont
, 0, sizeof (*lplogfont
));
5605 /* Set default value for each field. */
5607 lplogfont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
5608 lplogfont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
5609 lplogfont
->lfQuality
= DEFAULT_QUALITY
;
5611 /* go for maximum quality */
5612 lplogfont
->lfOutPrecision
= OUT_STROKE_PRECIS
;
5613 lplogfont
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
5614 lplogfont
->lfQuality
= PROOF_QUALITY
;
5617 lplogfont
->lfCharSet
= DEFAULT_CHARSET
;
5618 lplogfont
->lfWeight
= FW_DONTCARE
;
5619 lplogfont
->lfPitchAndFamily
= DEFAULT_PITCH
| FF_DONTCARE
;
5624 /* Provide a simple escape mechanism for specifying Windows font names
5625 * directly -- if font spec does not beginning with '-', assume this
5627 * "<font name>[:height in pixels[:width in pixels[:weight]]]"
5633 char name
[50], weight
[20], slant
, pitch
, pixels
[10], height
[10],
5634 width
[10], resy
[10], remainder
[50];
5636 int dpi
= (int) one_w32_display_info
.resy
;
5638 fields
= sscanf (lpxstr
,
5639 "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%49s",
5640 name
, weight
, &slant
, pixels
, height
, resy
, &pitch
, width
, remainder
);
5644 /* In the general case when wildcards cover more than one field,
5645 we don't know which field is which, so don't fill any in.
5646 However, we need to cope with this particular form, which is
5647 generated by font_list_1 (invoked by try_font_list):
5648 "-raster-6x10-*-gb2312*-*"
5649 and make sure to correctly parse the charset field. */
5652 fields
= sscanf (lpxstr
,
5653 "-%*[^-]-%49[^-]-*-%49s",
5656 else if (fields
< 9)
5662 if (fields
> 0 && name
[0] != '*')
5664 Lisp_Object string
= build_string (name
);
5666 (Fcheck_coding_system (Vlocale_coding_system
), &coding
);
5667 coding
.mode
|= (CODING_MODE_SAFE_ENCODING
| CODING_MODE_LAST_BLOCK
);
5668 /* Disable composition/charset annotation. */
5669 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
5670 coding
.dst_bytes
= SCHARS (string
) * 2;
5672 coding
.destination
= (unsigned char *) xmalloc (coding
.dst_bytes
);
5673 encode_coding_object (&coding
, string
, 0, 0,
5674 SCHARS (string
), SBYTES (string
), Qnil
);
5675 if (coding
.produced
>= LF_FACESIZE
)
5676 coding
.produced
= LF_FACESIZE
- 1;
5678 coding
.destination
[coding
.produced
] = '\0';
5680 strcpy (lplogfont
->lfFaceName
, coding
.destination
);
5681 xfree (coding
.destination
);
5685 lplogfont
->lfFaceName
[0] = '\0';
5690 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
5694 lplogfont
->lfItalic
= (fields
> 0 && slant
== 'i');
5698 if (fields
> 0 && pixels
[0] != '*')
5699 lplogfont
->lfHeight
= atoi (pixels
);
5703 if (fields
> 0 && resy
[0] != '*')
5706 if (tem
> 0) dpi
= tem
;
5709 if (fields
> -1 && lplogfont
->lfHeight
== 0 && height
[0] != '*')
5710 lplogfont
->lfHeight
= atoi (height
) * dpi
/ 720;
5715 lplogfont
->lfPitchAndFamily
= VARIABLE_PITCH
| FF_DONTCARE
;
5716 else if (pitch
== 'c')
5717 lplogfont
->lfPitchAndFamily
= FIXED_PITCH
| FF_DONTCARE
;
5722 if (fields
> 0 && width
[0] != '*')
5723 lplogfont
->lfWidth
= atoi (width
) / 10;
5727 /* Strip the trailing '-' if present. (it shouldn't be, as it
5728 fails the test against xlfd-tight-regexp in fontset.el). */
5730 int len
= strlen (remainder
);
5731 if (len
> 0 && remainder
[len
-1] == '-')
5732 remainder
[len
-1] = 0;
5734 encoding
= remainder
;
5736 if (strncmp (encoding
, "*-", 2) == 0)
5739 lplogfont
->lfCharSet
= x_to_w32_charset (encoding
);
5744 char name
[100], height
[10], width
[10], weight
[20];
5746 fields
= sscanf (lpxstr
,
5747 "%99[^:]:%9[^:]:%9[^:]:%19s",
5748 name
, height
, width
, weight
);
5750 if (fields
== EOF
) return (FALSE
);
5754 strncpy (lplogfont
->lfFaceName
, name
, LF_FACESIZE
);
5755 lplogfont
->lfFaceName
[LF_FACESIZE
-1] = 0;
5759 lplogfont
->lfFaceName
[0] = 0;
5765 lplogfont
->lfHeight
= atoi (height
);
5770 lplogfont
->lfWidth
= atoi (width
);
5774 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
5777 /* This makes TrueType fonts work better. */
5778 lplogfont
->lfHeight
= - eabs (lplogfont
->lfHeight
);
5783 /* Strip the pixel height and point height from the given xlfd, and
5784 return the pixel height. If no pixel height is specified, calculate
5785 one from the point height, or if that isn't defined either, return
5786 0 (which usually signifies a scalable font).
5789 xlfd_strip_height (char *fontname
)
5791 int pixel_height
, field_number
;
5792 char *read_from
, *write_to
;
5796 pixel_height
= field_number
= 0;
5799 /* Look for height fields. */
5800 for (read_from
= fontname
; *read_from
; read_from
++)
5802 if (*read_from
== '-')
5805 if (field_number
== 7) /* Pixel height. */
5808 write_to
= read_from
;
5810 /* Find end of field. */
5811 for (;*read_from
&& *read_from
!= '-'; read_from
++)
5814 /* Split the fontname at end of field. */
5820 pixel_height
= atoi (write_to
);
5821 /* Blank out field. */
5822 if (read_from
> write_to
)
5827 /* If the pixel height field is at the end (partial xlfd),
5830 return pixel_height
;
5832 /* If we got a pixel height, the point height can be
5833 ignored. Just blank it out and break now. */
5836 /* Find end of point size field. */
5837 for (; *read_from
&& *read_from
!= '-'; read_from
++)
5843 /* Blank out the point size field. */
5844 if (read_from
> write_to
)
5850 return pixel_height
;
5854 /* If the point height is already blank, break now. */
5855 if (*read_from
== '-')
5861 else if (field_number
== 8)
5863 /* If we didn't get a pixel height, try to get the point
5864 height and convert that. */
5866 char *point_size_start
= read_from
++;
5868 /* Find end of field. */
5869 for (; *read_from
&& *read_from
!= '-'; read_from
++)
5878 point_size
= atoi (point_size_start
);
5880 /* Convert to pixel height. */
5881 pixel_height
= point_size
5882 * one_w32_display_info
.height_in
/ 720;
5884 /* Blank out this field and break. */
5892 /* Shift the rest of the font spec into place. */
5893 if (write_to
&& read_from
> write_to
)
5895 for (; *read_from
; read_from
++, write_to
++)
5896 *write_to
= *read_from
;
5900 return pixel_height
;
5903 /* Assume parameter 1 is fully qualified, no wildcards. */
5905 w32_font_match (fontname
, pattern
)
5910 char *font_name_copy
;
5911 char *regex
= alloca (strlen (pattern
) * 2 + 3);
5913 font_name_copy
= alloca (strlen (fontname
) + 1);
5914 strcpy (font_name_copy
, fontname
);
5919 /* Turn pattern into a regexp and do a regexp match. */
5920 for (; *pattern
; pattern
++)
5922 if (*pattern
== '?')
5924 else if (*pattern
== '*')
5935 /* Strip out font heights and compare them seperately, since
5936 rounding error can cause mismatches. This also allows a
5937 comparison between a font that declares only a pixel height and a
5938 pattern that declares the point height.
5941 int font_height
, pattern_height
;
5943 font_height
= xlfd_strip_height (font_name_copy
);
5944 pattern_height
= xlfd_strip_height (regex
);
5946 /* Compare now, and don't bother doing expensive regexp matching
5947 if the heights differ. */
5948 if (font_height
&& pattern_height
&& (font_height
!= pattern_height
))
5952 return (fast_string_match_ignore_case (build_string (regex
),
5953 build_string (font_name_copy
)) >= 0);
5956 /* Callback functions, and a structure holding info they need, for
5957 listing system fonts on W32. We need one set of functions to do the
5958 job properly, but these don't work on NT 3.51 and earlier, so we
5959 have a second set which don't handle character sets properly to
5962 In both cases, there are two passes made. The first pass gets one
5963 font from each family, the second pass lists all the fonts from
5966 typedef struct enumfont_t
5971 XFontStruct
*size_ref
;
5972 Lisp_Object pattern
;
5978 enum_font_maybe_add_to_list (enumfont_t
*, LOGFONT
*, char *, Lisp_Object
);
5982 enum_font_cb2 (lplf
, lptm
, FontType
, lpef
)
5984 NEWTEXTMETRIC
* lptm
;
5988 /* Ignore struck out and underlined versions of fonts. */
5989 if (lplf
->elfLogFont
.lfStrikeOut
|| lplf
->elfLogFont
.lfUnderline
)
5992 /* Only return fonts with names starting with @ if they were
5993 explicitly specified, since Microsoft uses an initial @ to
5994 denote fonts for vertical writing, without providing a more
5995 convenient way of identifying them. */
5996 if (lplf
->elfLogFont
.lfFaceName
[0] == '@'
5997 && lpef
->logfont
.lfFaceName
[0] != '@')
6000 /* Check that the character set matches if it was specified */
6001 if (lpef
->logfont
.lfCharSet
!= DEFAULT_CHARSET
&&
6002 lplf
->elfLogFont
.lfCharSet
!= lpef
->logfont
.lfCharSet
)
6005 if (FontType
== RASTER_FONTTYPE
)
6007 /* DBCS raster fonts have problems displaying, so skip them. */
6008 int charset
= lplf
->elfLogFont
.lfCharSet
;
6009 if (charset
== SHIFTJIS_CHARSET
6010 || charset
== HANGEUL_CHARSET
6011 || charset
== CHINESEBIG5_CHARSET
6012 || charset
== GB2312_CHARSET
6013 #ifdef JOHAB_CHARSET
6014 || charset
== JOHAB_CHARSET
6022 Lisp_Object width
= Qnil
;
6023 Lisp_Object charset_list
= Qnil
;
6024 char *charset
= NULL
;
6026 /* Truetype fonts do not report their true metrics until loaded */
6027 if (FontType
!= RASTER_FONTTYPE
)
6029 if (!NILP (lpef
->pattern
))
6031 /* Scalable fonts are as big as you want them to be. */
6032 lplf
->elfLogFont
.lfHeight
= lpef
->logfont
.lfHeight
;
6033 lplf
->elfLogFont
.lfWidth
= lpef
->logfont
.lfWidth
;
6034 width
= make_number (lpef
->logfont
.lfWidth
);
6038 lplf
->elfLogFont
.lfHeight
= 0;
6039 lplf
->elfLogFont
.lfWidth
= 0;
6043 /* Make sure the height used here is the same as everywhere
6044 else (ie character height, not cell height). */
6045 if (lplf
->elfLogFont
.lfHeight
> 0)
6047 /* lptm can be trusted for RASTER fonts, but not scalable ones. */
6048 if (FontType
== RASTER_FONTTYPE
)
6049 lplf
->elfLogFont
.lfHeight
= lptm
->tmInternalLeading
- lptm
->tmHeight
;
6051 lplf
->elfLogFont
.lfHeight
= -lplf
->elfLogFont
.lfHeight
;
6054 if (!NILP (lpef
->pattern
))
6056 charset
= xlfd_charset_of_font (SDATA (lpef
->pattern
));
6058 /* We already checked charsets above, but DEFAULT_CHARSET
6059 slipped through. So only allow exact matches for DEFAULT_CHARSET. */
6061 && strncmp (charset
, "*-*", 3) != 0
6062 && lpef
->logfont
.lfCharSet
== DEFAULT_CHARSET
6063 && strcmp (charset
, w32_to_x_charset (DEFAULT_CHARSET
, NULL
)) != 0)
6068 charset_list
= Fcons (build_string (charset
), Qnil
);
6070 /* Always prefer unicode. */
6072 = Fcons (build_string ("iso10646-1"),
6073 w32_to_all_x_charsets (lplf
->elfLogFont
.lfCharSet
));
6075 /* Loop through the charsets. */
6076 for ( ; CONSP (charset_list
); charset_list
= Fcdr (charset_list
))
6078 Lisp_Object this_charset
= Fcar (charset_list
);
6079 charset
= SDATA (this_charset
);
6081 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
6084 /* List bold and italic variations if w32-enable-synthesized-fonts
6085 is non-nil and this is a plain font. */
6086 if (w32_enable_synthesized_fonts
6087 && lplf
->elfLogFont
.lfWeight
== FW_NORMAL
6088 && lplf
->elfLogFont
.lfItalic
== FALSE
)
6091 lplf
->elfLogFont
.lfWeight
= FW_BOLD
;
6092 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
6095 lplf
->elfLogFont
.lfItalic
= TRUE
;
6096 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
6099 lplf
->elfLogFont
.lfWeight
= FW_NORMAL
;
6100 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
6110 enum_font_maybe_add_to_list (lpef
, logfont
, match_charset
, width
)
6113 char * match_charset
;
6118 if (!w32_to_x_font (logfont
, buf
, 100, match_charset
))
6121 if (NILP (lpef
->pattern
)
6122 || w32_font_match (buf
, SDATA (lpef
->pattern
)))
6124 /* Check if we already listed this font. This may happen if
6125 w32_enable_synthesized_fonts is non-nil, and there are real
6126 bold and italic versions of the font. */
6127 Lisp_Object font_name
= build_string (buf
);
6128 if (NILP (Fmember (font_name
, lpef
->list
)))
6130 Lisp_Object entry
= Fcons (font_name
, width
);
6131 lpef
->list
= Fcons (entry
, lpef
->list
);
6139 enum_font_cb1 (lplf
, lptm
, FontType
, lpef
)
6141 NEWTEXTMETRIC
* lptm
;
6145 return EnumFontFamilies (lpef
->hdc
,
6146 lplf
->elfLogFont
.lfFaceName
,
6147 (FONTENUMPROC
) enum_font_cb2
,
6153 enum_fontex_cb2 (lplf
, lptm
, font_type
, lpef
)
6154 ENUMLOGFONTEX
* lplf
;
6155 NEWTEXTMETRICEX
* lptm
;
6159 /* We are not interested in the extra info we get back from the 'Ex
6160 version - only the fact that we get character set variations
6161 enumerated seperately. */
6162 return enum_font_cb2 ((ENUMLOGFONT
*) lplf
, (NEWTEXTMETRIC
*) lptm
,
6167 enum_fontex_cb1 (lplf
, lptm
, font_type
, lpef
)
6168 ENUMLOGFONTEX
* lplf
;
6169 NEWTEXTMETRICEX
* lptm
;
6173 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6174 FARPROC enum_font_families_ex
6175 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6176 /* We don't really expect EnumFontFamiliesEx to disappear once we
6177 get here, so don't bother handling it gracefully. */
6178 if (enum_font_families_ex
== NULL
)
6179 error ("gdi32.dll has disappeared!");
6180 return enum_font_families_ex (lpef
->hdc
,
6182 (FONTENUMPROC
) enum_fontex_cb2
,
6186 /* Interface to fontset handler. (adapted from mw32font.c in Meadow
6187 and xterm.c in Emacs 20.3) */
6190 w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
)
6192 char *fontname
, *ptnstr
;
6193 Lisp_Object list
, tem
, newlist
= Qnil
;
6196 list
= Vw32_bdf_filename_alist
;
6197 ptnstr
= SDATA (pattern
);
6199 for ( ; CONSP (list
); list
= XCDR (list
))
6203 fontname
= SDATA (XCAR (tem
));
6204 else if (STRINGP (tem
))
6205 fontname
= SDATA (tem
);
6209 if (w32_font_match (fontname
, ptnstr
))
6211 newlist
= Fcons (XCAR (tem
), newlist
);
6213 if (max_names
>= 0 && n_fonts
>= max_names
)
6222 /* Return a list of names of available fonts matching PATTERN on frame
6223 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
6224 to be listed. Frame F NULL means we have not yet created any
6225 frame, which means we can't get proper size info, as we don't have
6226 a device context to use for GetTextMetrics.
6227 MAXNAMES sets a limit on how many fonts to match. If MAXNAMES is
6228 negative, then all matching fonts are returned. */
6231 w32_list_fonts (f
, pattern
, size
, maxnames
)
6233 Lisp_Object pattern
;
6237 Lisp_Object patterns
, key
= Qnil
, tem
, tpat
;
6238 Lisp_Object list
= Qnil
, newlist
= Qnil
, second_best
= Qnil
;
6239 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
6242 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
6243 if (NILP (patterns
))
6244 patterns
= Fcons (pattern
, Qnil
);
6246 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
6251 tpat
= XCAR (patterns
);
6253 if (!STRINGP (tpat
))
6256 /* Avoid expensive EnumFontFamilies functions if we are not
6257 going to be able to output one of these anyway. */
6258 codepage
= w32_codepage_for_font (SDATA (tpat
));
6259 if (codepage
!= CP_8BIT
&& codepage
!= CP_UNICODE
6260 && codepage
!= CP_DEFAULT
&& codepage
!= CP_UNKNOWN
6261 && !IsValidCodePage (codepage
))
6264 /* See if we cached the result for this particular query.
6265 The cache is an alist of the form:
6266 ((PATTERN (FONTNAME . WIDTH) ...) ...)
6268 if (tem
= XCDR (dpyinfo
->name_list_element
),
6269 !NILP (list
= Fassoc (tpat
, tem
)))
6271 list
= Fcdr_safe (list
);
6272 /* We have a cached list. Don't have to get the list again. */
6277 /* At first, put PATTERN in the cache. */
6282 /* Use EnumFontFamiliesEx where it is available, as it knows
6283 about character sets. Fall back to EnumFontFamilies for
6284 older versions of NT that don't support the 'Ex function. */
6285 x_to_w32_font (SDATA (tpat
), &ef
.logfont
);
6287 LOGFONT font_match_pattern
;
6288 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6289 FARPROC enum_font_families_ex
6290 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6292 /* We do our own pattern matching so we can handle wildcards. */
6293 font_match_pattern
.lfFaceName
[0] = 0;
6294 font_match_pattern
.lfPitchAndFamily
= 0;
6295 /* We can use the charset, because if it is a wildcard it will
6296 be DEFAULT_CHARSET anyway. */
6297 font_match_pattern
.lfCharSet
= ef
.logfont
.lfCharSet
;
6299 ef
.hdc
= GetDC (dpyinfo
->root_window
);
6301 if (enum_font_families_ex
)
6302 enum_font_families_ex (ef
.hdc
,
6303 &font_match_pattern
,
6304 (FONTENUMPROC
) enum_fontex_cb1
,
6307 EnumFontFamilies (ef
.hdc
, NULL
, (FONTENUMPROC
) enum_font_cb1
,
6310 ReleaseDC (dpyinfo
->root_window
, ef
.hdc
);
6316 /* Make a list of the fonts we got back.
6317 Store that in the font cache for the display. */
6318 XSETCDR (dpyinfo
->name_list_element
,
6319 Fcons (Fcons (tpat
, list
),
6320 XCDR (dpyinfo
->name_list_element
)));
6323 if (NILP (list
)) continue; /* Try the remaining alternatives. */
6325 newlist
= second_best
= Qnil
;
6327 /* Make a list of the fonts that have the right width. */
6328 for (; CONSP (list
); list
= XCDR (list
))
6335 if (NILP (XCAR (tem
)))
6339 newlist
= Fcons (XCAR (tem
), newlist
);
6341 if (maxnames
>= 0 && n_fonts
>= maxnames
)
6346 if (!INTEGERP (XCDR (tem
)))
6348 /* Since we don't yet know the size of the font, we must
6349 load it and try GetTextMetrics. */
6350 W32FontStruct thisinfo
;
6355 if (!x_to_w32_font (SDATA (XCAR (tem
)), &lf
))
6359 thisinfo
.bdf
= NULL
;
6360 thisinfo
.hfont
= CreateFontIndirect (&lf
);
6361 if (thisinfo
.hfont
== NULL
)
6364 hdc
= GetDC (dpyinfo
->root_window
);
6365 oldobj
= SelectObject (hdc
, thisinfo
.hfont
);
6366 if (GetTextMetrics (hdc
, &thisinfo
.tm
))
6367 XSETCDR (tem
, make_number (FONT_AVG_WIDTH (&thisinfo
)));
6369 XSETCDR (tem
, make_number (0));
6370 SelectObject (hdc
, oldobj
);
6371 ReleaseDC (dpyinfo
->root_window
, hdc
);
6372 DeleteObject (thisinfo
.hfont
);
6375 found_size
= XINT (XCDR (tem
));
6376 if (found_size
== size
)
6378 newlist
= Fcons (XCAR (tem
), newlist
);
6380 if (maxnames
>= 0 && n_fonts
>= maxnames
)
6383 /* keep track of the closest matching size in case
6384 no exact match is found. */
6385 else if (found_size
> 0)
6387 if (NILP (second_best
))
6390 else if (found_size
< size
)
6392 if (XINT (XCDR (second_best
)) > size
6393 || XINT (XCDR (second_best
)) < found_size
)
6398 if (XINT (XCDR (second_best
)) > size
6399 && XINT (XCDR (second_best
)) >
6406 if (!NILP (newlist
))
6408 else if (!NILP (second_best
))
6410 newlist
= Fcons (XCAR (second_best
), Qnil
);
6415 /* Include any bdf fonts. */
6416 if (n_fonts
< maxnames
|| maxnames
< 0)
6418 Lisp_Object combined
[2];
6419 combined
[0] = w32_list_bdf_fonts (pattern
, maxnames
- n_fonts
);
6420 combined
[1] = newlist
;
6421 newlist
= Fnconc (2, combined
);
6428 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
6430 w32_get_font_info (f
, font_idx
)
6434 return (FRAME_W32_FONT_TABLE (f
) + font_idx
);
6439 w32_query_font (struct frame
*f
, char *fontname
)
6442 struct font_info
*pfi
;
6444 pfi
= FRAME_W32_FONT_TABLE (f
);
6446 for (i
= 0; i
< one_w32_display_info
.n_fonts
;i
++, pfi
++)
6448 if (stricmp (pfi
->name
, fontname
) == 0) return pfi
;
6454 /* Find a CCL program for a font specified by FONTP, and set the member
6455 `encoder' of the structure. */
6458 w32_find_ccl_program (fontp
)
6459 struct font_info
*fontp
;
6461 Lisp_Object list
, elt
;
6463 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
6467 && STRINGP (XCAR (elt
))
6468 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
6474 struct ccl_program
*ccl
6475 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
6477 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
6480 fontp
->font_encoder
= ccl
;
6484 /* directory-files from dired.c. */
6485 Lisp_Object Fdirectory_files
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
, Lisp_Object
));
6488 /* Find BDF files in a specified directory. (use GCPRO when calling,
6489 as this calls lisp to get a directory listing). */
6491 w32_find_bdf_fonts_in_dir (Lisp_Object directory
)
6493 Lisp_Object filelist
, list
= Qnil
;
6496 if (!STRINGP (directory
))
6499 filelist
= Fdirectory_files (directory
, Qt
,
6500 build_string (".*\\.[bB][dD][fF]"), Qt
);
6502 for ( ; CONSP (filelist
); filelist
= XCDR (filelist
))
6504 Lisp_Object filename
= XCAR (filelist
);
6505 if (w32_BDF_to_x_font (SDATA (filename
), fontname
, 100))
6506 store_in_alist (&list
, build_string (fontname
), filename
);
6511 DEFUN ("w32-find-bdf-fonts", Fw32_find_bdf_fonts
, Sw32_find_bdf_fonts
,
6513 doc
: /* Return a list of BDF fonts in DIRECTORY.
6514 The list is suitable for appending to `w32-bdf-filename-alist'.
6515 Fonts which do not contain an xlfd description will not be included
6516 in the list. DIRECTORY may be a list of directories. */)
6518 Lisp_Object directory
;
6520 Lisp_Object list
= Qnil
;
6521 struct gcpro gcpro1
, gcpro2
;
6523 if (!CONSP (directory
))
6524 return w32_find_bdf_fonts_in_dir (directory
);
6526 for ( ; CONSP (directory
); directory
= XCDR (directory
))
6528 Lisp_Object pair
[2];
6531 GCPRO2 (directory
, list
);
6532 pair
[1] = w32_find_bdf_fonts_in_dir ( XCAR (directory
) );
6533 list
= Fnconc ( 2, pair
);
6540 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
6541 doc
: /* Internal function called by `color-defined-p', which see. */)
6543 Lisp_Object color
, frame
;
6546 FRAME_PTR f
= check_x_frame (frame
);
6548 CHECK_STRING (color
);
6550 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
6556 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
6557 doc
: /* Internal function called by `color-values', which see. */)
6559 Lisp_Object color
, frame
;
6562 FRAME_PTR f
= check_x_frame (frame
);
6564 CHECK_STRING (color
);
6566 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
6567 return list3 (make_number ((GetRValue (foo
.pixel
) << 8)
6568 | GetRValue (foo
.pixel
)),
6569 make_number ((GetGValue (foo
.pixel
) << 8)
6570 | GetGValue (foo
.pixel
)),
6571 make_number ((GetBValue (foo
.pixel
) << 8)
6572 | GetBValue (foo
.pixel
)));
6577 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
6578 doc
: /* Internal function called by `display-color-p', which see. */)
6580 Lisp_Object display
;
6582 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6584 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
6590 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
,
6591 Sx_display_grayscale_p
, 0, 1, 0,
6592 doc
: /* Return t if DISPLAY supports shades of gray.
6593 Note that color displays do support shades of gray.
6594 The optional argument DISPLAY specifies which display to ask about.
6595 DISPLAY should be either a frame or a display name (a string).
6596 If omitted or nil, that stands for the selected frame's display. */)
6598 Lisp_Object display
;
6600 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6602 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
6608 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
,
6609 Sx_display_pixel_width
, 0, 1, 0,
6610 doc
: /* Return the width in pixels of DISPLAY.
6611 The optional argument DISPLAY specifies which display to ask about.
6612 DISPLAY should be either a frame or a display name (a string).
6613 If omitted or nil, that stands for the selected frame's display. */)
6615 Lisp_Object display
;
6617 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6619 return make_number (dpyinfo
->width
);
6622 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
6623 Sx_display_pixel_height
, 0, 1, 0,
6624 doc
: /* Return the height in pixels of DISPLAY.
6625 The optional argument DISPLAY specifies which display to ask about.
6626 DISPLAY should be either a frame or a display name (a string).
6627 If omitted or nil, that stands for the selected frame's display. */)
6629 Lisp_Object display
;
6631 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6633 return make_number (dpyinfo
->height
);
6636 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
6638 doc
: /* Return the number of bitplanes of DISPLAY.
6639 The optional argument DISPLAY specifies which display to ask about.
6640 DISPLAY should be either a frame or a display name (a string).
6641 If omitted or nil, that stands for the selected frame's display. */)
6643 Lisp_Object display
;
6645 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6647 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
6650 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
6652 doc
: /* Return the number of color cells of DISPLAY.
6653 The optional argument DISPLAY specifies which display to ask about.
6654 DISPLAY should be either a frame or a display name (a string).
6655 If omitted or nil, that stands for the selected frame's display. */)
6657 Lisp_Object display
;
6659 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6663 hdc
= GetDC (dpyinfo
->root_window
);
6664 if (dpyinfo
->has_palette
)
6665 cap
= GetDeviceCaps (hdc
, SIZEPALETTE
);
6667 cap
= GetDeviceCaps (hdc
, NUMCOLORS
);
6669 /* We force 24+ bit depths to 24-bit, both to prevent an overflow
6670 and because probably is more meaningful on Windows anyway */
6672 cap
= 1 << min (dpyinfo
->n_planes
* dpyinfo
->n_cbits
, 24);
6674 ReleaseDC (dpyinfo
->root_window
, hdc
);
6676 return make_number (cap
);
6679 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
6680 Sx_server_max_request_size
,
6682 doc
: /* Return the maximum request size of the server of DISPLAY.
6683 The optional argument DISPLAY specifies which display to ask about.
6684 DISPLAY should be either a frame or a display name (a string).
6685 If omitted or nil, that stands for the selected frame's display. */)
6687 Lisp_Object display
;
6689 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6691 return make_number (1);
6694 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
6695 doc
: /* Return the "vendor ID" string of the W32 system (Microsoft).
6696 The optional argument DISPLAY specifies which display to ask about.
6697 DISPLAY should be either a frame or a display name (a string).
6698 If omitted or nil, that stands for the selected frame's display. */)
6700 Lisp_Object display
;
6702 return build_string ("Microsoft Corp.");
6705 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
6706 doc
: /* Return the version numbers of the server of DISPLAY.
6707 The value is a list of three integers: the major and minor
6708 version numbers of the X Protocol in use, and the distributor-specific
6709 release number. See also the function `x-server-vendor'.
6711 The optional argument DISPLAY specifies which display to ask about.
6712 DISPLAY should be either a frame or a display name (a string).
6713 If omitted or nil, that stands for the selected frame's display. */)
6715 Lisp_Object display
;
6717 return Fcons (make_number (w32_major_version
),
6718 Fcons (make_number (w32_minor_version
),
6719 Fcons (make_number (w32_build_number
), Qnil
)));
6722 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
6723 doc
: /* Return the number of screens on the server of DISPLAY.
6724 The optional argument DISPLAY specifies which display to ask about.
6725 DISPLAY should be either a frame or a display name (a string).
6726 If omitted or nil, that stands for the selected frame's display. */)
6728 Lisp_Object display
;
6730 return make_number (1);
6733 DEFUN ("x-display-mm-height", Fx_display_mm_height
,
6734 Sx_display_mm_height
, 0, 1, 0,
6735 doc
: /* Return the height in millimeters of DISPLAY.
6736 The optional argument DISPLAY specifies which display to ask about.
6737 DISPLAY should be either a frame or a display name (a string).
6738 If omitted or nil, that stands for the selected frame's display. */)
6740 Lisp_Object display
;
6742 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6746 hdc
= GetDC (dpyinfo
->root_window
);
6748 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
6750 ReleaseDC (dpyinfo
->root_window
, hdc
);
6752 return make_number (cap
);
6755 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
6756 doc
: /* Return the width in millimeters of DISPLAY.
6757 The optional argument DISPLAY specifies which display to ask about.
6758 DISPLAY should be either a frame or a display name (a string).
6759 If omitted or nil, that stands for the selected frame's display. */)
6761 Lisp_Object display
;
6763 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6768 hdc
= GetDC (dpyinfo
->root_window
);
6770 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
6772 ReleaseDC (dpyinfo
->root_window
, hdc
);
6774 return make_number (cap
);
6777 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
6778 Sx_display_backing_store
, 0, 1, 0,
6779 doc
: /* Return an indication of whether DISPLAY does backing store.
6780 The value may be `always', `when-mapped', or `not-useful'.
6781 The optional argument DISPLAY specifies which display to ask about.
6782 DISPLAY should be either a frame or a display name (a string).
6783 If omitted or nil, that stands for the selected frame's display. */)
6785 Lisp_Object display
;
6787 return intern ("not-useful");
6790 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
6791 Sx_display_visual_class
, 0, 1, 0,
6792 doc
: /* Return the visual class of DISPLAY.
6793 The value is one of the symbols `static-gray', `gray-scale',
6794 `static-color', `pseudo-color', `true-color', or `direct-color'.
6796 The optional argument DISPLAY specifies which display to ask about.
6797 DISPLAY should be either a frame or a display name (a string).
6798 If omitted or nil, that stands for the selected frame's display. */)
6800 Lisp_Object display
;
6802 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6803 Lisp_Object result
= Qnil
;
6805 if (dpyinfo
->has_palette
)
6806 result
= intern ("pseudo-color");
6807 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
6808 result
= intern ("static-grey");
6809 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
6810 result
= intern ("static-color");
6811 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
6812 result
= intern ("true-color");
6817 DEFUN ("x-display-save-under", Fx_display_save_under
,
6818 Sx_display_save_under
, 0, 1, 0,
6819 doc
: /* Return t if DISPLAY supports the save-under feature.
6820 The optional argument DISPLAY specifies which display to ask about.
6821 DISPLAY should be either a frame or a display name (a string).
6822 If omitted or nil, that stands for the selected frame's display. */)
6824 Lisp_Object display
;
6831 register struct frame
*f
;
6833 return FRAME_PIXEL_WIDTH (f
);
6838 register struct frame
*f
;
6840 return FRAME_PIXEL_HEIGHT (f
);
6845 register struct frame
*f
;
6847 return FRAME_COLUMN_WIDTH (f
);
6852 register struct frame
*f
;
6854 return FRAME_LINE_HEIGHT (f
);
6859 register struct frame
*f
;
6861 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
6864 /* Return the display structure for the display named NAME.
6865 Open a new connection if necessary. */
6867 struct w32_display_info
*
6868 x_display_info_for_name (name
)
6872 struct w32_display_info
*dpyinfo
;
6874 CHECK_STRING (name
);
6876 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
6878 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
6881 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
6886 /* Use this general default value to start with. */
6887 Vx_resource_name
= Vinvocation_name
;
6889 validate_x_resource_name ();
6891 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
6892 (char *) SDATA (Vx_resource_name
));
6895 error ("Cannot connect to server %s", SDATA (name
));
6898 XSETFASTINT (Vwindow_system_version
, 3);
6903 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
6904 1, 3, 0, doc
: /* Open a connection to a server.
6905 DISPLAY is the name of the display to connect to.
6906 Optional second arg XRM-STRING is a string of resources in xrdb format.
6907 If the optional third arg MUST-SUCCEED is non-nil,
6908 terminate Emacs if we can't open the connection. */)
6909 (display
, xrm_string
, must_succeed
)
6910 Lisp_Object display
, xrm_string
, must_succeed
;
6912 unsigned char *xrm_option
;
6913 struct w32_display_info
*dpyinfo
;
6915 /* If initialization has already been done, return now to avoid
6916 overwriting critical parts of one_w32_display_info. */
6920 CHECK_STRING (display
);
6921 if (! NILP (xrm_string
))
6922 CHECK_STRING (xrm_string
);
6925 if (! EQ (Vwindow_system
, intern ("w32")))
6926 error ("Not using Microsoft Windows");
6929 /* Allow color mapping to be defined externally; first look in user's
6930 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
6932 Lisp_Object color_file
;
6933 struct gcpro gcpro1
;
6935 color_file
= build_string ("~/rgb.txt");
6937 GCPRO1 (color_file
);
6939 if (NILP (Ffile_readable_p (color_file
)))
6941 Fexpand_file_name (build_string ("rgb.txt"),
6942 Fsymbol_value (intern ("data-directory")));
6944 Vw32_color_map
= Fw32_load_color_file (color_file
);
6948 if (NILP (Vw32_color_map
))
6949 Vw32_color_map
= Fw32_default_color_map ();
6951 /* Merge in system logical colors. */
6952 add_system_logical_colors_to_map (&Vw32_color_map
);
6954 if (! NILP (xrm_string
))
6955 xrm_option
= (unsigned char *) SDATA (xrm_string
);
6957 xrm_option
= (unsigned char *) 0;
6959 /* Use this general default value to start with. */
6960 /* First remove .exe suffix from invocation-name - it looks ugly. */
6962 char basename
[ MAX_PATH
], *str
;
6964 strcpy (basename
, SDATA (Vinvocation_name
));
6965 str
= strrchr (basename
, '.');
6967 Vinvocation_name
= build_string (basename
);
6969 Vx_resource_name
= Vinvocation_name
;
6971 validate_x_resource_name ();
6973 /* This is what opens the connection and sets x_current_display.
6974 This also initializes many symbols, such as those used for input. */
6975 dpyinfo
= w32_term_init (display
, xrm_option
,
6976 (char *) SDATA (Vx_resource_name
));
6980 if (!NILP (must_succeed
))
6981 fatal ("Cannot connect to server %s.\n",
6984 error ("Cannot connect to server %s", SDATA (display
));
6989 XSETFASTINT (Vwindow_system_version
, 3);
6993 DEFUN ("x-close-connection", Fx_close_connection
,
6994 Sx_close_connection
, 1, 1, 0,
6995 doc
: /* Close the connection to DISPLAY's server.
6996 For DISPLAY, specify either a frame or a display name (a string).
6997 If DISPLAY is nil, that stands for the selected frame's display. */)
6999 Lisp_Object display
;
7001 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7004 if (dpyinfo
->reference_count
> 0)
7005 error ("Display still has frames on it");
7008 /* Free the fonts in the font table. */
7009 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
7010 if (dpyinfo
->font_table
[i
].name
)
7012 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
7013 xfree (dpyinfo
->font_table
[i
].full_name
);
7014 xfree (dpyinfo
->font_table
[i
].name
);
7015 w32_unload_font (dpyinfo
, dpyinfo
->font_table
[i
].font
);
7017 x_destroy_all_bitmaps (dpyinfo
);
7019 x_delete_display (dpyinfo
);
7025 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
7026 doc
: /* Return the list of display names that Emacs has connections to. */)
7029 Lisp_Object tail
, result
;
7032 for (tail
= w32_display_name_list
; CONSP (tail
); tail
= XCDR (tail
))
7033 result
= Fcons (XCAR (XCAR (tail
)), result
);
7038 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
7039 doc
: /* This is a noop on W32 systems. */)
7041 Lisp_Object display
, on
;
7048 /***********************************************************************
7050 ***********************************************************************/
7052 DEFUN ("x-change-window-property", Fx_change_window_property
,
7053 Sx_change_window_property
, 2, 6, 0,
7054 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
7055 VALUE may be a string or a list of conses, numbers and/or strings.
7056 If an element in the list is a string, it is converted to
7057 an Atom and the value of the Atom is used. If an element is a cons,
7058 it is converted to a 32 bit number where the car is the 16 top bits and the
7059 cdr is the lower 16 bits.
7060 FRAME nil or omitted means use the selected frame.
7061 If TYPE is given and non-nil, it is the name of the type of VALUE.
7062 If TYPE is not given or nil, the type is STRING.
7063 FORMAT gives the size in bits of each element if VALUE is a list.
7064 It must be one of 8, 16 or 32.
7065 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
7066 If OUTER_P is non-nil, the property is changed for the outer X window of
7067 FRAME. Default is to change on the edit X window.
7070 (prop
, value
, frame
, type
, format
, outer_p
)
7071 Lisp_Object prop
, value
, frame
, type
, format
, outer_p
;
7073 #if 0 /* TODO : port window properties to W32 */
7074 struct frame
*f
= check_x_frame (frame
);
7077 CHECK_STRING (prop
);
7078 CHECK_STRING (value
);
7081 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
7082 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
7083 prop_atom
, XA_STRING
, 8, PropModeReplace
,
7084 SDATA (value
), SCHARS (value
));
7086 /* Make sure the property is set when we return. */
7087 XFlush (FRAME_W32_DISPLAY (f
));
7096 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
7097 Sx_delete_window_property
, 1, 2, 0,
7098 doc
: /* Remove window property PROP from X window of FRAME.
7099 FRAME nil or omitted means use the selected frame. Value is PROP. */)
7101 Lisp_Object prop
, frame
;
7103 #if 0 /* TODO : port window properties to W32 */
7105 struct frame
*f
= check_x_frame (frame
);
7108 CHECK_STRING (prop
);
7110 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
7111 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
7113 /* Make sure the property is removed when we return. */
7114 XFlush (FRAME_W32_DISPLAY (f
));
7122 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
7124 doc
: /* Value is the value of window property PROP on FRAME.
7125 If FRAME is nil or omitted, use the selected frame. Value is nil
7126 if FRAME hasn't a property with name PROP or if PROP has no string
7129 Lisp_Object prop
, frame
;
7131 #if 0 /* TODO : port window properties to W32 */
7133 struct frame
*f
= check_x_frame (frame
);
7136 Lisp_Object prop_value
= Qnil
;
7137 char *tmp_data
= NULL
;
7140 unsigned long actual_size
, bytes_remaining
;
7142 CHECK_STRING (prop
);
7144 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
7145 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
7146 prop_atom
, 0, 0, False
, XA_STRING
,
7147 &actual_type
, &actual_format
, &actual_size
,
7148 &bytes_remaining
, (unsigned char **) &tmp_data
);
7151 int size
= bytes_remaining
;
7156 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
7157 prop_atom
, 0, bytes_remaining
,
7159 &actual_type
, &actual_format
,
7160 &actual_size
, &bytes_remaining
,
7161 (unsigned char **) &tmp_data
);
7163 prop_value
= make_string (tmp_data
, size
);
7178 /***********************************************************************
7180 ***********************************************************************/
7182 /* If non-null, an asynchronous timer that, when it expires, displays
7183 an hourglass cursor on all frames. */
7185 static struct atimer
*hourglass_atimer
;
7187 /* Non-zero means an hourglass cursor is currently shown. */
7189 static int hourglass_shown_p
;
7191 /* Number of seconds to wait before displaying an hourglass cursor. */
7193 static Lisp_Object Vhourglass_delay
;
7195 /* Default number of seconds to wait before displaying an hourglass
7198 #define DEFAULT_HOURGLASS_DELAY 1
7200 /* Function prototypes. */
7202 static void show_hourglass
P_ ((struct atimer
*));
7203 static void hide_hourglass
P_ ((void));
7206 /* Cancel a currently active hourglass timer, and start a new one. */
7211 #if 0 /* TODO: cursor shape changes. */
7213 int secs
, usecs
= 0;
7215 cancel_hourglass ();
7217 if (INTEGERP (Vhourglass_delay
)
7218 && XINT (Vhourglass_delay
) > 0)
7219 secs
= XFASTINT (Vhourglass_delay
);
7220 else if (FLOATP (Vhourglass_delay
)
7221 && XFLOAT_DATA (Vhourglass_delay
) > 0)
7224 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
7225 secs
= XFASTINT (tem
);
7226 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
7229 secs
= DEFAULT_HOURGLASS_DELAY
;
7231 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
7232 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
7233 show_hourglass
, NULL
);
7238 /* Cancel the hourglass cursor timer if active, hide an hourglass
7244 if (hourglass_atimer
)
7246 cancel_atimer (hourglass_atimer
);
7247 hourglass_atimer
= NULL
;
7250 if (hourglass_shown_p
)
7255 /* Timer function of hourglass_atimer. TIMER is equal to
7258 Display an hourglass cursor on all frames by mapping the frames'
7259 hourglass_window. Set the hourglass_p flag in the frames'
7260 output_data.x structure to indicate that an hourglass cursor is
7261 shown on the frames. */
7264 show_hourglass (timer
)
7265 struct atimer
*timer
;
7267 #if 0 /* TODO: cursor shape changes. */
7268 /* The timer implementation will cancel this timer automatically
7269 after this function has run. Set hourglass_atimer to null
7270 so that we know the timer doesn't have to be canceled. */
7271 hourglass_atimer
= NULL
;
7273 if (!hourglass_shown_p
)
7275 Lisp_Object rest
, frame
;
7279 FOR_EACH_FRAME (rest
, frame
)
7280 if (FRAME_W32_P (XFRAME (frame
)))
7282 struct frame
*f
= XFRAME (frame
);
7284 f
->output_data
.w32
->hourglass_p
= 1;
7286 if (!f
->output_data
.w32
->hourglass_window
)
7288 unsigned long mask
= CWCursor
;
7289 XSetWindowAttributes attrs
;
7291 attrs
.cursor
= f
->output_data
.w32
->hourglass_cursor
;
7293 f
->output_data
.w32
->hourglass_window
7294 = XCreateWindow (FRAME_X_DISPLAY (f
),
7295 FRAME_OUTER_WINDOW (f
),
7296 0, 0, 32000, 32000, 0, 0,
7302 XMapRaised (FRAME_X_DISPLAY (f
),
7303 f
->output_data
.w32
->hourglass_window
);
7304 XFlush (FRAME_X_DISPLAY (f
));
7307 hourglass_shown_p
= 1;
7314 /* Hide the hourglass cursor on all frames, if it is currently shown. */
7319 #if 0 /* TODO: cursor shape changes. */
7320 if (hourglass_shown_p
)
7322 Lisp_Object rest
, frame
;
7325 FOR_EACH_FRAME (rest
, frame
)
7327 struct frame
*f
= XFRAME (frame
);
7330 /* Watch out for newly created frames. */
7331 && f
->output_data
.x
->hourglass_window
)
7333 XUnmapWindow (FRAME_X_DISPLAY (f
),
7334 f
->output_data
.x
->hourglass_window
);
7335 /* Sync here because XTread_socket looks at the
7336 hourglass_p flag that is reset to zero below. */
7337 XSync (FRAME_X_DISPLAY (f
), False
);
7338 f
->output_data
.x
->hourglass_p
= 0;
7342 hourglass_shown_p
= 0;
7350 /***********************************************************************
7352 ***********************************************************************/
7354 static Lisp_Object x_create_tip_frame
P_ ((struct w32_display_info
*,
7355 Lisp_Object
, Lisp_Object
));
7356 static void compute_tip_xy
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
7357 Lisp_Object
, int, int, int *, int *));
7359 /* The frame of a currently visible tooltip. */
7361 Lisp_Object tip_frame
;
7363 /* If non-nil, a timer started that hides the last tooltip when it
7366 Lisp_Object tip_timer
;
7369 /* If non-nil, a vector of 3 elements containing the last args
7370 with which x-show-tip was called. See there. */
7372 Lisp_Object last_show_tip_args
;
7374 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
7376 Lisp_Object Vx_max_tooltip_size
;
7380 unwind_create_tip_frame (frame
)
7383 Lisp_Object deleted
;
7385 deleted
= unwind_create_frame (frame
);
7386 if (EQ (deleted
, Qt
))
7396 /* Create a frame for a tooltip on the display described by DPYINFO.
7397 PARMS is a list of frame parameters. TEXT is the string to
7398 display in the tip frame. Value is the frame.
7400 Note that functions called here, esp. x_default_parameter can
7401 signal errors, for instance when a specified color name is
7402 undefined. We have to make sure that we're in a consistent state
7403 when this happens. */
7406 x_create_tip_frame (dpyinfo
, parms
, text
)
7407 struct w32_display_info
*dpyinfo
;
7408 Lisp_Object parms
, text
;
7411 Lisp_Object frame
, tem
;
7413 long window_prompting
= 0;
7415 int count
= SPECPDL_INDEX ();
7416 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7418 int face_change_count_before
= face_change_count
;
7420 struct buffer
*old_buffer
;
7424 /* Use this general default value to start with until we know if
7425 this frame has a specified name. */
7426 Vx_resource_name
= Vinvocation_name
;
7429 kb
= dpyinfo
->terminal
->kboard
;
7431 kb
= &the_only_kboard
;
7434 /* Get the name of the frame to use for resource lookup. */
7435 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
7437 && !EQ (name
, Qunbound
)
7439 error ("Invalid frame name--not a string or nil");
7440 Vx_resource_name
= name
;
7443 GCPRO3 (parms
, name
, frame
);
7444 /* Make a frame without minibuffer nor mode-line. */
7446 f
->wants_modeline
= 0;
7447 XSETFRAME (frame
, f
);
7449 buffer
= Fget_buffer_create (build_string (" *tip*"));
7450 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, Qnil
);
7451 old_buffer
= current_buffer
;
7452 set_buffer_internal_1 (XBUFFER (buffer
));
7453 current_buffer
->truncate_lines
= Qnil
;
7454 specbind (Qinhibit_read_only
, Qt
);
7455 specbind (Qinhibit_modification_hooks
, Qt
);
7458 set_buffer_internal_1 (old_buffer
);
7460 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
7461 record_unwind_protect (unwind_create_tip_frame
, frame
);
7463 /* By setting the output method, we're essentially saying that
7464 the frame is live, as per FRAME_LIVE_P. If we get a signal
7465 from this point on, x_destroy_window might screw up reference
7467 f
->terminal
= dpyinfo
->terminal
;
7468 f
->terminal
->reference_count
++;
7469 f
->output_method
= output_w32
;
7470 f
->output_data
.w32
=
7471 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
7472 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
7474 FRAME_FONTSET (f
) = -1;
7475 f
->icon_name
= Qnil
;
7477 #if 0 /* GLYPH_DEBUG TODO: image support. */
7478 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
7479 dpyinfo_refcount
= dpyinfo
->reference_count
;
7480 #endif /* GLYPH_DEBUG */
7482 FRAME_KBOARD (f
) = kb
;
7484 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
7485 f
->output_data
.w32
->explicit_parent
= 0;
7487 /* Set the name; the functions to which we pass f expect the name to
7489 if (EQ (name
, Qunbound
) || NILP (name
))
7491 f
->name
= build_string (dpyinfo
->w32_id_name
);
7492 f
->explicit_name
= 0;
7497 f
->explicit_name
= 1;
7498 /* use the frame's title when getting resources for this frame. */
7499 specbind (Qx_resource_name
, name
);
7502 f
->resx
= dpyinfo
->resx
;
7503 f
->resy
= dpyinfo
->resy
;
7505 #ifdef USE_FONT_BACKEND
7506 if (enable_font_backend
)
7508 /* Perhaps, we must allow frame parameter, say `font-backend',
7509 to specify which font backends to use. */
7510 register_font_driver (&w32font_driver
, f
);
7512 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
7513 "fontBackend", "FontBackend", RES_TYPE_STRING
);
7515 #endif /* USE_FONT_BACKEND */
7517 /* Extract the window parameters from the supplied values
7518 that are needed to determine window geometry. */
7519 #ifdef USE_FONT_BACKEND
7520 if (enable_font_backend
)
7521 x_default_font_parameter (f
, parms
);
7523 #endif /* USE_FONT_BACKEND */
7527 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
7530 /* First, try whatever font the caller has specified. */
7533 tem
= Fquery_fontset (font
, Qnil
);
7535 font
= x_new_fontset (f
, tem
);
7537 font
= x_new_font (f
, SDATA (font
));
7540 /* Try out a font which we hope has bold and italic variations. */
7541 if (!STRINGP (font
))
7542 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
7543 if (! STRINGP (font
))
7544 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
7545 /* If those didn't work, look for something which will at least work. */
7546 if (! STRINGP (font
))
7547 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
7549 if (! STRINGP (font
))
7550 font
= build_string ("Fixedsys");
7552 x_default_parameter (f
, parms
, Qfont
, font
,
7553 "font", "Font", RES_TYPE_STRING
);
7556 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
7557 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
7558 /* This defaults to 2 in order to match xterm. We recognize either
7559 internalBorderWidth or internalBorder (which is what xterm calls
7561 if (NILP (Fassq (Qinternal_border_width
, parms
)))
7565 value
= w32_get_arg (parms
, Qinternal_border_width
,
7566 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
7567 if (! EQ (value
, Qunbound
))
7568 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
7571 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
7572 "internalBorderWidth", "internalBorderWidth",
7575 /* Also do the stuff which must be set before the window exists. */
7576 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
7577 "foreground", "Foreground", RES_TYPE_STRING
);
7578 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
7579 "background", "Background", RES_TYPE_STRING
);
7580 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
7581 "pointerColor", "Foreground", RES_TYPE_STRING
);
7582 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
7583 "cursorColor", "Foreground", RES_TYPE_STRING
);
7584 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
7585 "borderColor", "BorderColor", RES_TYPE_STRING
);
7587 /* Init faces before x_default_parameter is called for scroll-bar
7588 parameters because that function calls x_set_scroll_bar_width,
7589 which calls change_frame_size, which calls Fset_window_buffer,
7590 which runs hooks, which call Fvertical_motion. At the end, we
7591 end up in init_iterator with a null face cache, which should not
7593 init_frame_faces (f
);
7595 f
->output_data
.w32
->dwStyle
= WS_BORDER
| WS_POPUP
| WS_DISABLED
;
7596 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
7598 window_prompting
= x_figure_window_size (f
, parms
, 0);
7600 /* No fringes on tip frame. */
7602 f
->left_fringe_width
= 0;
7603 f
->right_fringe_width
= 0;
7606 my_create_tip_window (f
);
7611 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
7612 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
7613 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
7614 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
7615 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
7616 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
7618 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
7619 Change will not be effected unless different from the current
7621 width
= FRAME_COLS (f
);
7622 height
= FRAME_LINES (f
);
7623 FRAME_LINES (f
) = 0;
7624 SET_FRAME_COLS (f
, 0);
7625 change_frame_size (f
, height
, width
, 1, 0, 0);
7627 /* Add `tooltip' frame parameter's default value. */
7628 if (NILP (Fframe_parameter (frame
, intern ("tooltip"))))
7629 Fmodify_frame_parameters (frame
, Fcons (Fcons (intern ("tooltip"), Qt
),
7632 /* Set up faces after all frame parameters are known. This call
7633 also merges in face attributes specified for new frames.
7635 Frame parameters may be changed if .Xdefaults contains
7636 specifications for the default font. For example, if there is an
7637 `Emacs.default.attributeBackground: pink', the `background-color'
7638 attribute of the frame get's set, which let's the internal border
7639 of the tooltip frame appear in pink. Prevent this. */
7641 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
7643 /* Set tip_frame here, so that */
7645 call1 (Qface_set_after_frame_default
, frame
);
7647 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
7648 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qbackground_color
, bg
),
7656 /* It is now ok to make the frame official even if we get an error
7657 below. And the frame needs to be on Vframe_list or making it
7658 visible won't work. */
7659 Vframe_list
= Fcons (frame
, Vframe_list
);
7661 /* Now that the frame is official, it counts as a reference to
7663 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
7665 /* Setting attributes of faces of the tooltip frame from resources
7666 and similar will increment face_change_count, which leads to the
7667 clearing of all current matrices. Since this isn't necessary
7668 here, avoid it by resetting face_change_count to the value it
7669 had before we created the tip frame. */
7670 face_change_count
= face_change_count_before
;
7672 /* Discard the unwind_protect. */
7673 return unbind_to (count
, frame
);
7677 /* Compute where to display tip frame F. PARMS is the list of frame
7678 parameters for F. DX and DY are specified offsets from the current
7679 location of the mouse. WIDTH and HEIGHT are the width and height
7680 of the tooltip. Return coordinates relative to the root window of
7681 the display in *ROOT_X, and *ROOT_Y. */
7684 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, root_x
, root_y
)
7686 Lisp_Object parms
, dx
, dy
;
7688 int *root_x
, *root_y
;
7690 Lisp_Object left
, top
;
7692 /* User-specified position? */
7693 left
= Fcdr (Fassq (Qleft
, parms
));
7694 top
= Fcdr (Fassq (Qtop
, parms
));
7696 /* Move the tooltip window where the mouse pointer is. Resize and
7698 if (!INTEGERP (left
) || !INTEGERP (top
))
7710 *root_y
= XINT (top
);
7711 else if (*root_y
+ XINT (dy
) <= 0)
7712 *root_y
= 0; /* Can happen for negative dy */
7713 else if (*root_y
+ XINT (dy
) + height
<= FRAME_W32_DISPLAY_INFO (f
)->height
)
7714 /* It fits below the pointer */
7715 *root_y
+= XINT (dy
);
7716 else if (height
+ XINT (dy
) <= *root_y
)
7717 /* It fits above the pointer. */
7718 *root_y
-= height
+ XINT (dy
);
7720 /* Put it on the top. */
7723 if (INTEGERP (left
))
7724 *root_x
= XINT (left
);
7725 else if (*root_x
+ XINT (dx
) <= 0)
7726 *root_x
= 0; /* Can happen for negative dx */
7727 else if (*root_x
+ XINT (dx
) + width
<= FRAME_W32_DISPLAY_INFO (f
)->width
)
7728 /* It fits to the right of the pointer. */
7729 *root_x
+= XINT (dx
);
7730 else if (width
+ XINT (dx
) <= *root_x
)
7731 /* It fits to the left of the pointer. */
7732 *root_x
-= width
+ XINT (dx
);
7734 /* Put it left justified on the screen -- it ought to fit that way. */
7739 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
7740 doc
: /* Show STRING in a \"tooltip\" window on frame FRAME.
7741 A tooltip window is a small window displaying a string.
7743 This is an internal function; Lisp code should call `tooltip-show'.
7745 FRAME nil or omitted means use the selected frame.
7747 PARMS is an optional list of frame parameters which can be
7748 used to change the tooltip's appearance.
7750 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
7751 means use the default timeout of 5 seconds.
7753 If the list of frame parameters PARMS contains a `left' parameter,
7754 the tooltip is displayed at that x-position. Otherwise it is
7755 displayed at the mouse position, with offset DX added (default is 5 if
7756 DX isn't specified). Likewise for the y-position; if a `top' frame
7757 parameter is specified, it determines the y-position of the tooltip
7758 window, otherwise it is displayed at the mouse position, with offset
7759 DY added (default is -10).
7761 A tooltip's maximum size is specified by `x-max-tooltip-size'.
7762 Text larger than the specified size is clipped. */)
7763 (string
, frame
, parms
, timeout
, dx
, dy
)
7764 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
7769 struct buffer
*old_buffer
;
7770 struct text_pos pos
;
7771 int i
, width
, height
;
7772 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7773 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7774 int count
= SPECPDL_INDEX ();
7776 specbind (Qinhibit_redisplay
, Qt
);
7778 GCPRO4 (string
, parms
, frame
, timeout
);
7780 CHECK_STRING (string
);
7781 f
= check_x_frame (frame
);
7783 timeout
= make_number (5);
7785 CHECK_NATNUM (timeout
);
7788 dx
= make_number (5);
7793 dy
= make_number (-10);
7797 if (NILP (last_show_tip_args
))
7798 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
7800 if (!NILP (tip_frame
))
7802 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
7803 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
7804 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
7806 if (EQ (frame
, last_frame
)
7807 && !NILP (Fequal (last_string
, string
))
7808 && !NILP (Fequal (last_parms
, parms
)))
7810 struct frame
*f
= XFRAME (tip_frame
);
7812 /* Only DX and DY have changed. */
7813 if (!NILP (tip_timer
))
7815 Lisp_Object timer
= tip_timer
;
7817 call1 (Qcancel_timer
, timer
);
7821 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
7822 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
7824 /* Put tooltip in topmost group and in position. */
7825 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
7826 root_x
, root_y
, 0, 0,
7827 SWP_NOSIZE
| SWP_NOACTIVATE
);
7829 /* Ensure tooltip is on top of other topmost windows (eg menus). */
7830 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
7832 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
7839 /* Hide a previous tip, if any. */
7842 ASET (last_show_tip_args
, 0, string
);
7843 ASET (last_show_tip_args
, 1, frame
);
7844 ASET (last_show_tip_args
, 2, parms
);
7846 /* Add default values to frame parameters. */
7847 if (NILP (Fassq (Qname
, parms
)))
7848 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
7849 if (NILP (Fassq (Qinternal_border_width
, parms
)))
7850 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
7851 if (NILP (Fassq (Qborder_width
, parms
)))
7852 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
7853 if (NILP (Fassq (Qborder_color
, parms
)))
7854 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
7855 if (NILP (Fassq (Qbackground_color
, parms
)))
7856 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
7859 /* Block input until the tip has been fully drawn, to avoid crashes
7860 when drawing tips in menus. */
7863 /* Create a frame for the tooltip, and record it in the global
7864 variable tip_frame. */
7865 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
, string
);
7868 /* Set up the frame's root window. */
7869 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7870 w
->left_col
= w
->top_line
= make_number (0);
7872 if (CONSP (Vx_max_tooltip_size
)
7873 && INTEGERP (XCAR (Vx_max_tooltip_size
))
7874 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
7875 && INTEGERP (XCDR (Vx_max_tooltip_size
))
7876 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
7878 w
->total_cols
= XCAR (Vx_max_tooltip_size
);
7879 w
->total_lines
= XCDR (Vx_max_tooltip_size
);
7883 w
->total_cols
= make_number (80);
7884 w
->total_lines
= make_number (40);
7887 FRAME_TOTAL_COLS (f
) = XINT (w
->total_cols
);
7889 w
->pseudo_window_p
= 1;
7891 /* Display the tooltip text in a temporary buffer. */
7892 old_buffer
= current_buffer
;
7893 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
7894 current_buffer
->truncate_lines
= Qnil
;
7895 clear_glyph_matrix (w
->desired_matrix
);
7896 clear_glyph_matrix (w
->current_matrix
);
7897 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
7898 try_window (FRAME_ROOT_WINDOW (f
), pos
, 0);
7900 /* Compute width and height of the tooltip. */
7902 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
7904 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
7908 /* Stop at the first empty row at the end. */
7909 if (!row
->enabled_p
|| !row
->displays_text_p
)
7912 /* Let the row go over the full width of the frame. */
7913 row
->full_width_p
= 1;
7915 #ifdef TODO /* Investigate why some fonts need more width than is
7916 calculated for some tooltips. */
7917 /* There's a glyph at the end of rows that is use to place
7918 the cursor there. Don't include the width of this glyph. */
7919 if (row
->used
[TEXT_AREA
])
7921 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
7922 row_width
= row
->pixel_width
- last
->pixel_width
;
7926 row_width
= row
->pixel_width
;
7928 /* TODO: find why tips do not draw along baseline as instructed. */
7929 height
+= row
->height
;
7930 width
= max (width
, row_width
);
7933 /* Add the frame's internal border to the width and height the X
7934 window should have. */
7935 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
7936 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
7938 /* Move the tooltip window where the mouse pointer is. Resize and
7940 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
7943 /* Adjust Window size to take border into account. */
7945 rect
.left
= rect
.top
= 0;
7947 rect
.bottom
= height
;
7948 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
7949 FRAME_EXTERNAL_MENU_BAR (f
));
7951 /* Position and size tooltip, and put it in the topmost group.
7952 The add-on of 3 to the 5th argument is a kludge: without it,
7953 some fonts cause the last character of the tip to be truncated,
7954 for some obscure reason. */
7955 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
7956 root_x
, root_y
, rect
.right
- rect
.left
+ 3,
7957 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
);
7959 /* Ensure tooltip is on top of other topmost windows (eg menus). */
7960 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
7962 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
7964 /* Let redisplay know that we have made the frame visible already. */
7965 f
->async_visible
= 1;
7967 ShowWindow (FRAME_W32_WINDOW (f
), SW_SHOWNOACTIVATE
);
7970 /* Draw into the window. */
7971 w
->must_be_updated_p
= 1;
7972 update_single_window (w
, 1);
7976 /* Restore original current buffer. */
7977 set_buffer_internal_1 (old_buffer
);
7978 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7981 /* Let the tip disappear after timeout seconds. */
7982 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
7983 intern ("x-hide-tip"));
7986 return unbind_to (count
, Qnil
);
7990 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
7991 doc
: /* Hide the current tooltip window, if there is any.
7992 Value is t if tooltip was open, nil otherwise. */)
7996 Lisp_Object deleted
, frame
, timer
;
7997 struct gcpro gcpro1
, gcpro2
;
7999 /* Return quickly if nothing to do. */
8000 if (NILP (tip_timer
) && NILP (tip_frame
))
8005 GCPRO2 (frame
, timer
);
8006 tip_frame
= tip_timer
= deleted
= Qnil
;
8008 count
= SPECPDL_INDEX ();
8009 specbind (Qinhibit_redisplay
, Qt
);
8010 specbind (Qinhibit_quit
, Qt
);
8013 call1 (Qcancel_timer
, timer
);
8017 Fdelete_frame (frame
, Qnil
);
8022 return unbind_to (count
, deleted
);
8027 /***********************************************************************
8028 File selection dialog
8029 ***********************************************************************/
8030 extern Lisp_Object Qfile_name_history
;
8032 /* Callback for altering the behaviour of the Open File dialog.
8033 Makes the Filename text field contain "Current Directory" and be
8034 read-only when "Directories" is selected in the filter. This
8035 allows us to work around the fact that the standard Open File
8036 dialog does not support directories. */
8038 file_dialog_callback (hwnd
, msg
, wParam
, lParam
)
8044 if (msg
== WM_NOTIFY
)
8046 OFNOTIFY
* notify
= (OFNOTIFY
*)lParam
;
8047 /* Detect when the Filter dropdown is changed. */
8048 if (notify
->hdr
.code
== CDN_TYPECHANGE
8049 || notify
->hdr
.code
== CDN_INITDONE
)
8051 HWND dialog
= GetParent (hwnd
);
8052 HWND edit_control
= GetDlgItem (dialog
, FILE_NAME_TEXT_FIELD
);
8054 /* Directories is in index 2. */
8055 if (notify
->lpOFN
->nFilterIndex
== 2)
8057 CommDlg_OpenSave_SetControlText (dialog
, FILE_NAME_TEXT_FIELD
,
8058 "Current Directory");
8059 EnableWindow (edit_control
, FALSE
);
8063 /* Don't override default filename on init done. */
8064 if (notify
->hdr
.code
== CDN_TYPECHANGE
)
8065 CommDlg_OpenSave_SetControlText (dialog
,
8066 FILE_NAME_TEXT_FIELD
, "");
8067 EnableWindow (edit_control
, TRUE
);
8074 /* Since we compile with _WIN32_WINNT set to 0x0400 (for NT4 compatibility)
8075 we end up with the old file dialogs. Define a big enough struct for the
8076 new dialog to trick GetOpenFileName into giving us the new dialogs on
8077 Windows 2000 and XP. */
8080 OPENFILENAME real_details
;
8087 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
8088 doc
: /* Read file name, prompting with PROMPT in directory DIR.
8089 Use a file selection dialog.
8090 Select DEFAULT-FILENAME in the dialog's file selection box, if
8091 specified. Ensure that file exists if MUSTMATCH is non-nil.
8092 If ONLY-DIR-P is non-nil, the user can only select directories. */)
8093 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
)
8094 Lisp_Object prompt
, dir
, default_filename
, mustmatch
, only_dir_p
;
8096 struct frame
*f
= SELECTED_FRAME ();
8097 Lisp_Object file
= Qnil
;
8098 int count
= SPECPDL_INDEX ();
8099 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
8100 char filename
[MAX_PATH
+ 1];
8101 char init_dir
[MAX_PATH
+ 1];
8102 int default_filter_index
= 1; /* 1: All Files, 2: Directories only */
8104 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
8105 CHECK_STRING (prompt
);
8108 /* Create the dialog with PROMPT as title, using DIR as initial
8109 directory and using "*" as pattern. */
8110 dir
= Fexpand_file_name (dir
, Qnil
);
8111 strncpy (init_dir
, SDATA (ENCODE_FILE (dir
)), MAX_PATH
);
8112 init_dir
[MAX_PATH
] = '\0';
8113 unixtodos_filename (init_dir
);
8115 if (STRINGP (default_filename
))
8117 char *file_name_only
;
8118 char *full_path_name
= SDATA (ENCODE_FILE (default_filename
));
8120 unixtodos_filename (full_path_name
);
8122 file_name_only
= strrchr (full_path_name
, '\\');
8123 if (!file_name_only
)
8124 file_name_only
= full_path_name
;
8128 strncpy (filename
, file_name_only
, MAX_PATH
);
8129 filename
[MAX_PATH
] = '\0';
8135 NEWOPENFILENAME new_file_details
;
8136 BOOL file_opened
= FALSE
;
8137 OPENFILENAME
* file_details
= &new_file_details
.real_details
;
8139 /* Prevent redisplay. */
8140 specbind (Qinhibit_redisplay
, Qt
);
8143 bzero (&new_file_details
, sizeof (new_file_details
));
8144 /* Apparently NT4 crashes if you give it an unexpected size.
8145 I'm not sure about Windows 9x, so play it safe. */
8146 if (w32_major_version
> 4 && w32_major_version
< 95)
8147 file_details
->lStructSize
= sizeof (NEWOPENFILENAME
);
8149 file_details
->lStructSize
= sizeof (OPENFILENAME
);
8151 file_details
->hwndOwner
= FRAME_W32_WINDOW (f
);
8152 /* Undocumented Bug in Common File Dialog:
8153 If a filter is not specified, shell links are not resolved. */
8154 file_details
->lpstrFilter
= "All Files (*.*)\0*.*\0Directories\0*|*\0\0";
8155 file_details
->lpstrFile
= filename
;
8156 file_details
->nMaxFile
= sizeof (filename
);
8157 file_details
->lpstrInitialDir
= init_dir
;
8158 file_details
->lpstrTitle
= SDATA (prompt
);
8160 if (! NILP (only_dir_p
))
8161 default_filter_index
= 2;
8163 file_details
->nFilterIndex
= default_filter_index
;
8165 file_details
->Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
8166 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
8167 if (!NILP (mustmatch
))
8169 /* Require that the path to the parent directory exists. */
8170 file_details
->Flags
|= OFN_PATHMUSTEXIST
;
8171 /* If we are looking for a file, require that it exists. */
8172 if (NILP (only_dir_p
))
8173 file_details
->Flags
|= OFN_FILEMUSTEXIST
;
8176 file_details
->lpfnHook
= (LPOFNHOOKPROC
) file_dialog_callback
;
8178 file_opened
= GetOpenFileName (file_details
);
8184 dostounix_filename (filename
);
8186 if (file_details
->nFilterIndex
== 2)
8188 /* "Directories" selected - strip dummy file name. */
8189 char * last
= strrchr (filename
, '/');
8193 file
= DECODE_FILE (build_string (filename
));
8195 /* User cancelled the dialog without making a selection. */
8196 else if (!CommDlgExtendedError ())
8198 /* An error occurred, fallback on reading from the mini-buffer. */
8200 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
8201 dir
, mustmatch
, dir
, Qfile_name_history
,
8202 default_filename
, Qnil
);
8204 file
= unbind_to (count
, file
);
8209 /* Make "Cancel" equivalent to C-g. */
8211 Fsignal (Qquit
, Qnil
);
8213 return unbind_to (count
, file
);
8218 /***********************************************************************
8219 w32 specialized functions
8220 ***********************************************************************/
8222 DEFUN ("w32-select-font", Fw32_select_font
, Sw32_select_font
, 0, 2, 0,
8223 doc
: /* Select a font for the named FRAME using the W32 font dialog.
8224 Return an X-style font string corresponding to the selection.
8226 If FRAME is omitted or nil, it defaults to the selected frame.
8227 If INCLUDE-PROPORTIONAL is non-nil, include proportional fonts
8228 in the font selection dialog. */)
8229 (frame
, include_proportional
)
8230 Lisp_Object frame
, include_proportional
;
8232 FRAME_PTR f
= check_x_frame (frame
);
8240 bzero (&cf
, sizeof (cf
));
8241 bzero (&lf
, sizeof (lf
));
8243 cf
.lStructSize
= sizeof (cf
);
8244 cf
.hwndOwner
= FRAME_W32_WINDOW (f
);
8245 cf
.Flags
= CF_FORCEFONTEXIST
| CF_SCREENFONTS
| CF_NOVERTFONTS
;
8247 /* Unless include_proportional is non-nil, limit the selection to
8248 monospaced fonts. */
8249 if (NILP (include_proportional
))
8250 cf
.Flags
|= CF_FIXEDPITCHONLY
;
8254 /* Initialize as much of the font details as we can from the current
8256 hdc
= GetDC (FRAME_W32_WINDOW (f
));
8257 oldobj
= SelectObject (hdc
, FRAME_FONT (f
)->hfont
);
8258 GetTextFace (hdc
, LF_FACESIZE
, lf
.lfFaceName
);
8259 if (GetTextMetrics (hdc
, &tm
))
8261 lf
.lfHeight
= tm
.tmInternalLeading
- tm
.tmHeight
;
8262 lf
.lfWeight
= tm
.tmWeight
;
8263 lf
.lfItalic
= tm
.tmItalic
;
8264 lf
.lfUnderline
= tm
.tmUnderlined
;
8265 lf
.lfStrikeOut
= tm
.tmStruckOut
;
8266 lf
.lfCharSet
= tm
.tmCharSet
;
8267 cf
.Flags
|= CF_INITTOLOGFONTSTRUCT
;
8269 SelectObject (hdc
, oldobj
);
8270 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
8272 if (!ChooseFont (&cf
) || !w32_to_x_font (&lf
, buf
, 100, NULL
))
8275 return build_string (buf
);
8278 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
,
8279 Sw32_send_sys_command
, 1, 2, 0,
8280 doc
: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND.
8281 Some useful values for COMMAND are #xf030 to maximize frame (#xf020
8282 to minimize), #xf120 to restore frame to original size, and #xf100
8283 to activate the menubar for keyboard access. #xf140 activates the
8284 screen saver if defined.
8286 If optional parameter FRAME is not specified, use selected frame. */)
8288 Lisp_Object command
, frame
;
8290 FRAME_PTR f
= check_x_frame (frame
);
8292 CHECK_NUMBER (command
);
8294 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
8299 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
8300 doc
: /* Get Windows to perform OPERATION on DOCUMENT.
8301 This is a wrapper around the ShellExecute system function, which
8302 invokes the application registered to handle OPERATION for DOCUMENT.
8304 OPERATION is either nil or a string that names a supported operation.
8305 What operations can be used depends on the particular DOCUMENT and its
8306 handler application, but typically it is one of the following common
8309 \"open\" - open DOCUMENT, which could be a file, a directory, or an
8310 executable program. If it is an application, that
8311 application is launched in the current buffer's default
8312 directory. Otherwise, the application associated with
8313 DOCUMENT is launched in the buffer's default directory.
8314 \"print\" - print DOCUMENT, which must be a file
8315 \"explore\" - start the Windows Explorer on DOCUMENT
8316 \"edit\" - launch an editor and open DOCUMENT for editing; which
8317 editor is launched depends on the association for the
8319 \"find\" - initiate search starting from DOCUMENT which must specify
8321 nil - invoke the default OPERATION, or \"open\" if default is
8322 not defined or unavailable
8324 DOCUMENT is typically the name of a document file or a URL, but can
8325 also be a program executable to run, or a directory to open in the
8328 If DOCUMENT is a program executable, the optional third arg PARAMETERS
8329 can be a string containing command line parameters that will be passed
8330 to the program; otherwise, PARAMETERS should be nil or unspecified.
8332 Optional fourth argument SHOW-FLAG can be used to control how the
8333 application will be displayed when it is invoked. If SHOW-FLAG is nil
8334 or unspecified, the application is displayed normally, otherwise it is
8335 an integer representing a ShowWindow flag:
8340 6 - start minimized */)
8341 (operation
, document
, parameters
, show_flag
)
8342 Lisp_Object operation
, document
, parameters
, show_flag
;
8344 Lisp_Object current_dir
;
8346 CHECK_STRING (document
);
8348 /* Encode filename and current directory. */
8349 current_dir
= ENCODE_FILE (current_buffer
->directory
);
8350 document
= ENCODE_FILE (document
);
8351 if ((int) ShellExecute (NULL
,
8352 (STRINGP (operation
) ?
8353 SDATA (operation
) : NULL
),
8355 (STRINGP (parameters
) ?
8356 SDATA (parameters
) : NULL
),
8357 SDATA (current_dir
),
8358 (INTEGERP (show_flag
) ?
8359 XINT (show_flag
) : SW_SHOWDEFAULT
))
8362 error ("ShellExecute failed: %s", w32_strerror (0));
8365 /* Lookup virtual keycode from string representing the name of a
8366 non-ascii keystroke into the corresponding virtual key, using
8367 lispy_function_keys. */
8369 lookup_vk_code (char *key
)
8373 for (i
= 0; i
< 256; i
++)
8374 if (lispy_function_keys
[i
]
8375 && strcmp (lispy_function_keys
[i
], key
) == 0)
8381 /* Convert a one-element vector style key sequence to a hot key
8384 w32_parse_hot_key (key
)
8387 /* Copied from Fdefine_key and store_in_keymap. */
8388 register Lisp_Object c
;
8392 struct gcpro gcpro1
;
8396 if (XFASTINT (Flength (key
)) != 1)
8401 c
= Faref (key
, make_number (0));
8403 if (CONSP (c
) && lucid_event_type_list_p (c
))
8404 c
= Fevent_convert_list (c
);
8408 if (! INTEGERP (c
) && ! SYMBOLP (c
))
8409 error ("Key definition is invalid");
8411 /* Work out the base key and the modifiers. */
8414 c
= parse_modifiers (c
);
8415 lisp_modifiers
= XINT (Fcar (Fcdr (c
)));
8419 vk_code
= lookup_vk_code (SDATA (SYMBOL_NAME (c
)));
8421 else if (INTEGERP (c
))
8423 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
8424 /* Many ascii characters are their own virtual key code. */
8425 vk_code
= XINT (c
) & CHARACTERBITS
;
8428 if (vk_code
< 0 || vk_code
> 255)
8431 if ((lisp_modifiers
& meta_modifier
) != 0
8432 && !NILP (Vw32_alt_is_meta
))
8433 lisp_modifiers
|= alt_modifier
;
8435 /* Supply defs missing from mingw32. */
8437 #define MOD_ALT 0x0001
8438 #define MOD_CONTROL 0x0002
8439 #define MOD_SHIFT 0x0004
8440 #define MOD_WIN 0x0008
8443 /* Convert lisp modifiers to Windows hot-key form. */
8444 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
8445 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
8446 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
8447 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
8449 return HOTKEY (vk_code
, w32_modifiers
);
8452 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
,
8453 Sw32_register_hot_key
, 1, 1, 0,
8454 doc
: /* Register KEY as a hot-key combination.
8455 Certain key combinations like Alt-Tab are reserved for system use on
8456 Windows, and therefore are normally intercepted by the system. However,
8457 most of these key combinations can be received by registering them as
8458 hot-keys, overriding their special meaning.
8460 KEY must be a one element key definition in vector form that would be
8461 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta
8462 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper
8463 is always interpreted as the Windows modifier keys.
8465 The return value is the hotkey-id if registered, otherwise nil. */)
8469 key
= w32_parse_hot_key (key
);
8471 if (!NILP (key
) && NILP (Fmemq (key
, w32_grabbed_keys
)))
8473 /* Reuse an empty slot if possible. */
8474 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
8476 /* Safe to add new key to list, even if we have focus. */
8478 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
8480 XSETCAR (item
, key
);
8482 /* Notify input thread about new hot-key definition, so that it
8483 takes effect without needing to switch focus. */
8484 #ifdef USE_LISP_UNION_TYPE
8485 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
8488 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
8496 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
,
8497 Sw32_unregister_hot_key
, 1, 1, 0,
8498 doc
: /* Unregister KEY as a hot-key combination. */)
8504 if (!INTEGERP (key
))
8505 key
= w32_parse_hot_key (key
);
8507 item
= Fmemq (key
, w32_grabbed_keys
);
8511 /* Notify input thread about hot-key definition being removed, so
8512 that it takes effect without needing focus switch. */
8513 #ifdef USE_LISP_UNION_TYPE
8514 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
8515 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
.i
))
8517 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
8518 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
))
8522 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
8529 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
,
8530 Sw32_registered_hot_keys
, 0, 0, 0,
8531 doc
: /* Return list of registered hot-key IDs. */)
8534 return Fdelq (Qnil
, Fcopy_sequence (w32_grabbed_keys
));
8537 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
,
8538 Sw32_reconstruct_hot_key
, 1, 1, 0,
8539 doc
: /* Convert hot-key ID to a lisp key combination.
8540 usage: (w32-reconstruct-hot-key ID) */)
8542 Lisp_Object hotkeyid
;
8544 int vk_code
, w32_modifiers
;
8547 CHECK_NUMBER (hotkeyid
);
8549 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
8550 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
8552 if (vk_code
< 256 && lispy_function_keys
[vk_code
])
8553 key
= intern (lispy_function_keys
[vk_code
]);
8555 key
= make_number (vk_code
);
8557 key
= Fcons (key
, Qnil
);
8558 if (w32_modifiers
& MOD_SHIFT
)
8559 key
= Fcons (Qshift
, key
);
8560 if (w32_modifiers
& MOD_CONTROL
)
8561 key
= Fcons (Qctrl
, key
);
8562 if (w32_modifiers
& MOD_ALT
)
8563 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
8564 if (w32_modifiers
& MOD_WIN
)
8565 key
= Fcons (Qhyper
, key
);
8570 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
,
8571 Sw32_toggle_lock_key
, 1, 2, 0,
8572 doc
: /* Toggle the state of the lock key KEY.
8573 KEY can be `capslock', `kp-numlock', or `scroll'.
8574 If the optional parameter NEW-STATE is a number, then the state of KEY
8575 is set to off if the low bit of NEW-STATE is zero, otherwise on. */)
8577 Lisp_Object key
, new_state
;
8581 if (EQ (key
, intern ("capslock")))
8582 vk_code
= VK_CAPITAL
;
8583 else if (EQ (key
, intern ("kp-numlock")))
8584 vk_code
= VK_NUMLOCK
;
8585 else if (EQ (key
, intern ("scroll")))
8586 vk_code
= VK_SCROLL
;
8590 if (!dwWindowsThreadId
)
8591 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
8593 #ifdef USE_LISP_UNION_TYPE
8594 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
8595 (WPARAM
) vk_code
, (LPARAM
) new_state
.i
))
8597 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
8598 (WPARAM
) vk_code
, (LPARAM
) new_state
))
8602 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
8603 return make_number (msg
.wParam
);
8608 DEFUN ("w32-window-exists-p", Fw32_window_exists_p
, Sw32_window_exists_p
,
8610 doc
: /* Return non-nil if a window exists with the specified CLASS and NAME.
8612 This is a direct interface to the Windows API FindWindow function. */)
8614 Lisp_Object
class, name
;
8619 CHECK_STRING (class);
8621 CHECK_STRING (name
);
8623 hnd
= FindWindow (STRINGP (class) ? ((LPCTSTR
) SDATA (class)) : NULL
,
8624 STRINGP (name
) ? ((LPCTSTR
) SDATA (name
)) : NULL
);
8632 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
8633 doc
: /* Return storage information about the file system FILENAME is on.
8634 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
8635 storage of the file system, FREE is the free storage, and AVAIL is the
8636 storage available to a non-superuser. All 3 numbers are in bytes.
8637 If the underlying system call fails, value is nil. */)
8639 Lisp_Object filename
;
8641 Lisp_Object encoded
, value
;
8643 CHECK_STRING (filename
);
8644 filename
= Fexpand_file_name (filename
, Qnil
);
8645 encoded
= ENCODE_FILE (filename
);
8649 /* Determining the required information on Windows turns out, sadly,
8650 to be more involved than one would hope. The original Win32 api
8651 call for this will return bogus information on some systems, but we
8652 must dynamically probe for the replacement api, since that was
8653 added rather late on. */
8655 HMODULE hKernel
= GetModuleHandle ("kernel32");
8656 BOOL (*pfn_GetDiskFreeSpaceEx
)
8657 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
8658 = (void *) GetProcAddress (hKernel
, "GetDiskFreeSpaceEx");
8660 /* On Windows, we may need to specify the root directory of the
8661 volume holding FILENAME. */
8662 char rootname
[MAX_PATH
];
8663 char *name
= SDATA (encoded
);
8665 /* find the root name of the volume if given */
8666 if (isalpha (name
[0]) && name
[1] == ':')
8668 rootname
[0] = name
[0];
8669 rootname
[1] = name
[1];
8673 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
8675 char *str
= rootname
;
8679 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
8689 if (pfn_GetDiskFreeSpaceEx
)
8691 /* Unsigned large integers cannot be cast to double, so
8692 use signed ones instead. */
8693 LARGE_INTEGER availbytes
;
8694 LARGE_INTEGER freebytes
;
8695 LARGE_INTEGER totalbytes
;
8697 if (pfn_GetDiskFreeSpaceEx (rootname
,
8698 (ULARGE_INTEGER
*)&availbytes
,
8699 (ULARGE_INTEGER
*)&totalbytes
,
8700 (ULARGE_INTEGER
*)&freebytes
))
8701 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
8702 make_float ((double) freebytes
.QuadPart
),
8703 make_float ((double) availbytes
.QuadPart
));
8707 DWORD sectors_per_cluster
;
8708 DWORD bytes_per_sector
;
8709 DWORD free_clusters
;
8710 DWORD total_clusters
;
8712 if (GetDiskFreeSpace (rootname
,
8713 §ors_per_cluster
,
8717 value
= list3 (make_float ((double) total_clusters
8718 * sectors_per_cluster
* bytes_per_sector
),
8719 make_float ((double) free_clusters
8720 * sectors_per_cluster
* bytes_per_sector
),
8721 make_float ((double) free_clusters
8722 * sectors_per_cluster
* bytes_per_sector
));
8729 DEFUN ("default-printer-name", Fdefault_printer_name
, Sdefault_printer_name
,
8730 0, 0, 0, doc
: /* Return the name of Windows default printer device. */)
8733 static char pname_buf
[256];
8736 PRINTER_INFO_2
*ppi2
= NULL
;
8737 DWORD dwNeeded
= 0, dwReturned
= 0;
8739 /* Retrieve the default string from Win.ini (the registry).
8740 * String will be in form "printername,drivername,portname".
8741 * This is the most portable way to get the default printer. */
8742 if (GetProfileString ("windows", "device", ",,", pname_buf
, sizeof (pname_buf
)) <= 0)
8744 /* printername precedes first "," character */
8745 strtok (pname_buf
, ",");
8746 /* We want to know more than the printer name */
8747 if (!OpenPrinter (pname_buf
, &hPrn
, NULL
))
8749 GetPrinter (hPrn
, 2, NULL
, 0, &dwNeeded
);
8752 ClosePrinter (hPrn
);
8755 /* Allocate memory for the PRINTER_INFO_2 struct */
8756 ppi2
= (PRINTER_INFO_2
*) xmalloc (dwNeeded
);
8759 ClosePrinter (hPrn
);
8762 /* Call GetPrinter again with big enouth memory block */
8763 err
= GetPrinter (hPrn
, 2, (LPBYTE
)ppi2
, dwNeeded
, &dwReturned
);
8764 ClosePrinter (hPrn
);
8773 if (ppi2
->Attributes
& PRINTER_ATTRIBUTE_SHARED
&& ppi2
->pServerName
)
8775 /* a remote printer */
8776 if (*ppi2
->pServerName
== '\\')
8777 _snprintf (pname_buf
, sizeof (pname_buf
), "%s\\%s", ppi2
->pServerName
,
8780 _snprintf (pname_buf
, sizeof (pname_buf
), "\\\\%s\\%s", ppi2
->pServerName
,
8782 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
8786 /* a local printer */
8787 strncpy (pname_buf
, ppi2
->pPortName
, sizeof (pname_buf
));
8788 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
8789 /* `pPortName' can include several ports, delimited by ','.
8790 * we only use the first one. */
8791 strtok (pname_buf
, ",");
8796 return build_string (pname_buf
);
8799 /***********************************************************************
8801 ***********************************************************************/
8803 /* Keep this list in the same order as frame_parms in frame.c.
8804 Use 0 for unsupported frame parameters. */
8806 frame_parm_handler w32_frame_parm_handlers
[] =
8810 x_set_background_color
,
8816 x_set_foreground_color
,
8819 x_set_internal_border_width
,
8820 x_set_menu_bar_lines
,
8822 x_explicitly_set_name
,
8823 x_set_scroll_bar_width
,
8826 x_set_vertical_scroll_bars
,
8828 x_set_tool_bar_lines
,
8829 0, /* x_set_scroll_bar_foreground, */
8830 0, /* x_set_scroll_bar_background, */
8835 0, /* x_set_wait_for_wm, */
8837 #ifdef USE_FONT_BACKEND
8845 globals_of_w32fns ();
8846 /* This is zero if not using MS-Windows. */
8848 track_mouse_window
= NULL
;
8850 w32_visible_system_caret_hwnd
= NULL
;
8852 DEFSYM (Qnone
, "none");
8853 DEFSYM (Qsuppress_icon
, "suppress-icon");
8854 DEFSYM (Qundefined_color
, "undefined-color");
8855 DEFSYM (Qcancel_timer
, "cancel-timer");
8856 DEFSYM (Qhyper
, "hyper");
8857 DEFSYM (Qsuper
, "super");
8858 DEFSYM (Qmeta
, "meta");
8859 DEFSYM (Qalt
, "alt");
8860 DEFSYM (Qctrl
, "ctrl");
8861 DEFSYM (Qcontrol
, "control");
8862 DEFSYM (Qshift
, "shift");
8863 /* This is the end of symbol initialization. */
8865 /* Text property `display' should be nonsticky by default. */
8866 Vtext_property_default_nonsticky
8867 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
8870 Fput (Qundefined_color
, Qerror_conditions
,
8871 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
8872 Fput (Qundefined_color
, Qerror_message
,
8873 build_string ("Undefined color"));
8875 staticpro (&w32_grabbed_keys
);
8876 w32_grabbed_keys
= Qnil
;
8878 DEFVAR_LISP ("w32-color-map", &Vw32_color_map
,
8879 doc
: /* An array of color name mappings for Windows. */);
8880 Vw32_color_map
= Qnil
;
8882 DEFVAR_LISP ("w32-pass-alt-to-system", &Vw32_pass_alt_to_system
,
8883 doc
: /* Non-nil if Alt key presses are passed on to Windows.
8884 When non-nil, for example, Alt pressed and released and then space will
8885 open the System menu. When nil, Emacs processes the Alt key events, and
8886 then silently swallows them. */);
8887 Vw32_pass_alt_to_system
= Qnil
;
8889 DEFVAR_LISP ("w32-alt-is-meta", &Vw32_alt_is_meta
,
8890 doc
: /* Non-nil if the Alt key is to be considered the same as the META key.
8891 When nil, Emacs will translate the Alt key to the ALT modifier, not to META. */);
8892 Vw32_alt_is_meta
= Qt
;
8894 DEFVAR_INT ("w32-quit-key", &w32_quit_key
,
8895 doc
: /* If non-zero, the virtual key code for an alternative quit key. */);
8898 DEFVAR_LISP ("w32-pass-lwindow-to-system",
8899 &Vw32_pass_lwindow_to_system
,
8900 doc
: /* If non-nil, the left \"Windows\" key is passed on to Windows.
8902 When non-nil, the Start menu is opened by tapping the key.
8903 If you set this to nil, the left \"Windows\" key is processed by Emacs
8904 according to the value of `w32-lwindow-modifier', which see.
8906 Note that some combinations of the left \"Windows\" key with other keys are
8907 caught by Windows at low level, and so binding them in Emacs will have no
8908 effect. For example, <lwindow>-r always pops up the Windows Run dialog,
8909 <lwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
8910 the doc string of `w32-phantom-key-code'. */);
8911 Vw32_pass_lwindow_to_system
= Qt
;
8913 DEFVAR_LISP ("w32-pass-rwindow-to-system",
8914 &Vw32_pass_rwindow_to_system
,
8915 doc
: /* If non-nil, the right \"Windows\" key is passed on to Windows.
8917 When non-nil, the Start menu is opened by tapping the key.
8918 If you set this to nil, the right \"Windows\" key is processed by Emacs
8919 according to the value of `w32-rwindow-modifier', which see.
8921 Note that some combinations of the right \"Windows\" key with other keys are
8922 caught by Windows at low level, and so binding them in Emacs will have no
8923 effect. For example, <rwindow>-r always pops up the Windows Run dialog,
8924 <rwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
8925 the doc string of `w32-phantom-key-code'. */);
8926 Vw32_pass_rwindow_to_system
= Qt
;
8928 DEFVAR_LISP ("w32-phantom-key-code",
8929 &Vw32_phantom_key_code
,
8930 doc
: /* Virtual key code used to generate \"phantom\" key presses.
8931 Value is a number between 0 and 255.
8933 Phantom key presses are generated in order to stop the system from
8934 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or
8935 `w32-pass-rwindow-to-system' is nil. */);
8936 /* Although 255 is technically not a valid key code, it works and
8937 means that this hack won't interfere with any real key code. */
8938 XSETINT (Vw32_phantom_key_code
, 255);
8940 DEFVAR_LISP ("w32-enable-num-lock",
8941 &Vw32_enable_num_lock
,
8942 doc
: /* If non-nil, the Num Lock key acts normally.
8943 Set to nil to handle Num Lock as the `kp-numlock' key. */);
8944 Vw32_enable_num_lock
= Qt
;
8946 DEFVAR_LISP ("w32-enable-caps-lock",
8947 &Vw32_enable_caps_lock
,
8948 doc
: /* If non-nil, the Caps Lock key acts normally.
8949 Set to nil to handle Caps Lock as the `capslock' key. */);
8950 Vw32_enable_caps_lock
= Qt
;
8952 DEFVAR_LISP ("w32-scroll-lock-modifier",
8953 &Vw32_scroll_lock_modifier
,
8954 doc
: /* Modifier to use for the Scroll Lock ON state.
8955 The value can be hyper, super, meta, alt, control or shift for the
8956 respective modifier, or nil to handle Scroll Lock as the `scroll' key.
8957 Any other value will cause the Scroll Lock key to be ignored. */);
8958 Vw32_scroll_lock_modifier
= Qt
;
8960 DEFVAR_LISP ("w32-lwindow-modifier",
8961 &Vw32_lwindow_modifier
,
8962 doc
: /* Modifier to use for the left \"Windows\" key.
8963 The value can be hyper, super, meta, alt, control or shift for the
8964 respective modifier, or nil to appear as the `lwindow' key.
8965 Any other value will cause the key to be ignored. */);
8966 Vw32_lwindow_modifier
= Qnil
;
8968 DEFVAR_LISP ("w32-rwindow-modifier",
8969 &Vw32_rwindow_modifier
,
8970 doc
: /* Modifier to use for the right \"Windows\" key.
8971 The value can be hyper, super, meta, alt, control or shift for the
8972 respective modifier, or nil to appear as the `rwindow' key.
8973 Any other value will cause the key to be ignored. */);
8974 Vw32_rwindow_modifier
= Qnil
;
8976 DEFVAR_LISP ("w32-apps-modifier",
8977 &Vw32_apps_modifier
,
8978 doc
: /* Modifier to use for the \"Apps\" key.
8979 The value can be hyper, super, meta, alt, control or shift for the
8980 respective modifier, or nil to appear as the `apps' key.
8981 Any other value will cause the key to be ignored. */);
8982 Vw32_apps_modifier
= Qnil
;
8984 DEFVAR_BOOL ("w32-enable-synthesized-fonts", &w32_enable_synthesized_fonts
,
8985 doc
: /* Non-nil enables selection of artificially italicized and bold fonts. */);
8986 w32_enable_synthesized_fonts
= 0;
8988 DEFVAR_LISP ("w32-enable-palette", &Vw32_enable_palette
,
8989 doc
: /* Non-nil enables Windows palette management to map colors exactly. */);
8990 Vw32_enable_palette
= Qt
;
8992 DEFVAR_INT ("w32-mouse-button-tolerance",
8993 &w32_mouse_button_tolerance
,
8994 doc
: /* Analogue of double click interval for faking middle mouse events.
8995 The value is the minimum time in milliseconds that must elapse between
8996 left and right button down events before they are considered distinct events.
8997 If both mouse buttons are depressed within this interval, a middle mouse
8998 button down event is generated instead. */);
8999 w32_mouse_button_tolerance
= GetDoubleClickTime () / 2;
9001 DEFVAR_INT ("w32-mouse-move-interval",
9002 &w32_mouse_move_interval
,
9003 doc
: /* Minimum interval between mouse move events.
9004 The value is the minimum time in milliseconds that must elapse between
9005 successive mouse move (or scroll bar drag) events before they are
9006 reported as lisp events. */);
9007 w32_mouse_move_interval
= 0;
9009 DEFVAR_BOOL ("w32-pass-extra-mouse-buttons-to-system",
9010 &w32_pass_extra_mouse_buttons_to_system
,
9011 doc
: /* If non-nil, the fourth and fifth mouse buttons are passed to Windows.
9012 Recent versions of Windows support mice with up to five buttons.
9013 Since most applications don't support these extra buttons, most mouse
9014 drivers will allow you to map them to functions at the system level.
9015 If this variable is non-nil, Emacs will pass them on, allowing the
9016 system to handle them. */);
9017 w32_pass_extra_mouse_buttons_to_system
= 0;
9019 DEFVAR_BOOL ("w32-pass-multimedia-buttons-to-system",
9020 &w32_pass_multimedia_buttons_to_system
,
9021 doc
: /* If non-nil, media buttons are passed to Windows.
9022 Some modern keyboards contain buttons for controlling media players, web
9023 browsers and other applications. Generally these buttons are handled on a
9024 system wide basis, but by setting this to nil they are made available
9025 to Emacs for binding. Depending on your keyboard, additional keys that
9026 may be available are:
9028 browser-back, browser-forward, browser-refresh, browser-stop,
9029 browser-search, browser-favorites, browser-home,
9030 mail, mail-reply, mail-forward, mail-send,
9032 help, find, new, open, close, save, print, undo, redo, copy, cut, paste,
9033 spell-check, correction-list, toggle-dictate-command,
9034 media-next, media-previous, media-stop, media-play-pause, media-select,
9035 media-play, media-pause, media-record, media-fast-forward, media-rewind,
9036 media-channel-up, media-channel-down,
9037 volume-mute, volume-up, volume-down,
9038 mic-volume-mute, mic-volume-down, mic-volume-up, mic-toggle,
9039 bass-down, bass-boost, bass-up, treble-down, treble-up */);
9040 w32_pass_multimedia_buttons_to_system
= 1;
9042 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
9043 doc
: /* The shape of the pointer when over text.
9044 Changing the value does not affect existing frames
9045 unless you set the mouse color. */);
9046 Vx_pointer_shape
= Qnil
;
9048 Vx_nontext_pointer_shape
= Qnil
;
9050 Vx_mode_pointer_shape
= Qnil
;
9052 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
9053 doc
: /* The shape of the pointer when Emacs is busy.
9054 This variable takes effect when you create a new frame
9055 or when you set the mouse color. */);
9056 Vx_hourglass_pointer_shape
= Qnil
;
9058 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
9059 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
9060 display_hourglass_p
= 1;
9062 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
9063 doc
: /* *Seconds to wait before displaying an hourglass pointer.
9064 Value must be an integer or float. */);
9065 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
9067 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
9068 &Vx_sensitive_text_pointer_shape
,
9069 doc
: /* The shape of the pointer when over mouse-sensitive text.
9070 This variable takes effect when you create a new frame
9071 or when you set the mouse color. */);
9072 Vx_sensitive_text_pointer_shape
= Qnil
;
9074 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
9075 &Vx_window_horizontal_drag_shape
,
9076 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
9077 This variable takes effect when you create a new frame
9078 or when you set the mouse color. */);
9079 Vx_window_horizontal_drag_shape
= Qnil
;
9081 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
9082 doc
: /* A string indicating the foreground color of the cursor box. */);
9083 Vx_cursor_fore_pixel
= Qnil
;
9085 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size
,
9086 doc
: /* Maximum size for tooltips.
9087 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
9088 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
9090 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
9091 doc
: /* Non-nil if no window manager is in use.
9092 Emacs doesn't try to figure this out; this is always nil
9093 unless you set it to something else. */);
9094 /* We don't have any way to find this out, so set it to nil
9095 and maybe the user would like to set it to t. */
9096 Vx_no_window_manager
= Qnil
;
9098 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
9099 &Vx_pixel_size_width_font_regexp
,
9100 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
9102 Since Emacs gets width of a font matching with this regexp from
9103 PIXEL_SIZE field of the name, font finding mechanism gets faster for
9104 such a font. This is especially effective for such large fonts as
9105 Chinese, Japanese, and Korean. */);
9106 Vx_pixel_size_width_font_regexp
= Qnil
;
9108 DEFVAR_LISP ("w32-bdf-filename-alist",
9109 &Vw32_bdf_filename_alist
,
9110 doc
: /* List of bdf fonts and their corresponding filenames. */);
9111 Vw32_bdf_filename_alist
= Qnil
;
9113 DEFVAR_BOOL ("w32-strict-fontnames",
9114 &w32_strict_fontnames
,
9115 doc
: /* Non-nil means only use fonts that are exact matches for those requested.
9116 Default is nil, which allows old fontnames that are not XLFD compliant,
9117 and allows third-party CJK display to work by specifying false charset
9118 fields to trick Emacs into translating to Big5, SJIS etc.
9119 Setting this to t will prevent wrong fonts being selected when
9120 fontsets are automatically created. */);
9121 w32_strict_fontnames
= 0;
9123 DEFVAR_BOOL ("w32-strict-painting",
9124 &w32_strict_painting
,
9125 doc
: /* Non-nil means use strict rules for repainting frames.
9126 Set this to nil to get the old behavior for repainting; this should
9127 only be necessary if the default setting causes problems. */);
9128 w32_strict_painting
= 1;
9130 DEFVAR_LISP ("w32-charset-info-alist",
9131 &Vw32_charset_info_alist
,
9132 doc
: /* Alist linking Emacs character sets to Windows fonts and codepages.
9133 Each entry should be of the form:
9135 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE))
9137 where CHARSET_NAME is a string used in font names to identify the charset,
9138 WINDOWS_CHARSET is a symbol that can be one of:
9139 w32-charset-ansi, w32-charset-default, w32-charset-symbol,
9140 w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312,
9141 w32-charset-chinesebig5,
9142 w32-charset-johab, w32-charset-hebrew,
9143 w32-charset-arabic, w32-charset-greek, w32-charset-turkish,
9144 w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope,
9145 w32-charset-russian, w32-charset-mac, w32-charset-baltic,
9146 w32-charset-unicode,
9148 CODEPAGE should be an integer specifying the codepage that should be used
9149 to display the character set, t to do no translation and output as Unicode,
9150 or nil to do no translation and output as 8 bit (or multibyte on far-east
9151 versions of Windows) characters. */);
9152 Vw32_charset_info_alist
= Qnil
;
9154 DEFSYM (Qw32_charset_ansi
, "w32-charset-ansi");
9155 DEFSYM (Qw32_charset_symbol
, "w32-charset-symbol");
9156 DEFSYM (Qw32_charset_default
, "w32-charset-default");
9157 DEFSYM (Qw32_charset_shiftjis
, "w32-charset-shiftjis");
9158 DEFSYM (Qw32_charset_hangeul
, "w32-charset-hangeul");
9159 DEFSYM (Qw32_charset_chinesebig5
, "w32-charset-chinesebig5");
9160 DEFSYM (Qw32_charset_gb2312
, "w32-charset-gb2312");
9161 DEFSYM (Qw32_charset_oem
, "w32-charset-oem");
9163 #ifdef JOHAB_CHARSET
9165 static int w32_extra_charsets_defined
= 1;
9166 DEFVAR_BOOL ("w32-extra-charsets-defined", &w32_extra_charsets_defined
,
9167 doc
: /* Internal variable. */);
9169 DEFSYM (Qw32_charset_johab
, "w32-charset-johab");
9170 DEFSYM (Qw32_charset_easteurope
, "w32-charset-easteurope");
9171 DEFSYM (Qw32_charset_turkish
, "w32-charset-turkish");
9172 DEFSYM (Qw32_charset_baltic
, "w32-charset-baltic");
9173 DEFSYM (Qw32_charset_russian
, "w32-charset-russian");
9174 DEFSYM (Qw32_charset_arabic
, "w32-charset-arabic");
9175 DEFSYM (Qw32_charset_greek
, "w32-charset-greek");
9176 DEFSYM (Qw32_charset_hebrew
, "w32-charset-hebrew");
9177 DEFSYM (Qw32_charset_vietnamese
, "w32-charset-vietnamese");
9178 DEFSYM (Qw32_charset_thai
, "w32-charset-thai");
9179 DEFSYM (Qw32_charset_mac
, "w32-charset-mac");
9183 #ifdef UNICODE_CHARSET
9185 static int w32_unicode_charset_defined
= 1;
9186 DEFVAR_BOOL ("w32-unicode-charset-defined",
9187 &w32_unicode_charset_defined
,
9188 doc
: /* Internal variable. */);
9189 DEFSYM (Qw32_charset_unicode
, "w32-charset-unicode");
9193 #if 0 /* TODO: Port to W32 */
9194 defsubr (&Sx_change_window_property
);
9195 defsubr (&Sx_delete_window_property
);
9196 defsubr (&Sx_window_property
);
9198 defsubr (&Sxw_display_color_p
);
9199 defsubr (&Sx_display_grayscale_p
);
9200 defsubr (&Sxw_color_defined_p
);
9201 defsubr (&Sxw_color_values
);
9202 defsubr (&Sx_server_max_request_size
);
9203 defsubr (&Sx_server_vendor
);
9204 defsubr (&Sx_server_version
);
9205 defsubr (&Sx_display_pixel_width
);
9206 defsubr (&Sx_display_pixel_height
);
9207 defsubr (&Sx_display_mm_width
);
9208 defsubr (&Sx_display_mm_height
);
9209 defsubr (&Sx_display_screens
);
9210 defsubr (&Sx_display_planes
);
9211 defsubr (&Sx_display_color_cells
);
9212 defsubr (&Sx_display_visual_class
);
9213 defsubr (&Sx_display_backing_store
);
9214 defsubr (&Sx_display_save_under
);
9215 defsubr (&Sx_create_frame
);
9216 defsubr (&Sx_open_connection
);
9217 defsubr (&Sx_close_connection
);
9218 defsubr (&Sx_display_list
);
9219 defsubr (&Sx_synchronize
);
9220 defsubr (&Sx_focus_frame
);
9222 /* W32 specific functions */
9224 defsubr (&Sw32_select_font
);
9225 defsubr (&Sw32_define_rgb_color
);
9226 defsubr (&Sw32_default_color_map
);
9227 defsubr (&Sw32_load_color_file
);
9228 defsubr (&Sw32_send_sys_command
);
9229 defsubr (&Sw32_shell_execute
);
9230 defsubr (&Sw32_register_hot_key
);
9231 defsubr (&Sw32_unregister_hot_key
);
9232 defsubr (&Sw32_registered_hot_keys
);
9233 defsubr (&Sw32_reconstruct_hot_key
);
9234 defsubr (&Sw32_toggle_lock_key
);
9235 defsubr (&Sw32_window_exists_p
);
9236 defsubr (&Sw32_find_bdf_fonts
);
9238 defsubr (&Sfile_system_info
);
9239 defsubr (&Sdefault_printer_name
);
9241 /* Setting callback functions for fontset handler. */
9242 get_font_info_func
= w32_get_font_info
;
9244 #if 0 /* This function pointer doesn't seem to be used anywhere.
9245 And the pointer assigned has the wrong type, anyway. */
9246 list_fonts_func
= w32_list_fonts
;
9249 load_font_func
= w32_load_font
;
9250 find_ccl_program_func
= w32_find_ccl_program
;
9251 query_font_func
= w32_query_font
;
9252 set_frame_fontset_func
= x_set_font
;
9253 get_font_repertory_func
= x_get_font_repertory
;
9254 check_window_system_func
= check_w32
;
9257 hourglass_atimer
= NULL
;
9258 hourglass_shown_p
= 0;
9259 defsubr (&Sx_show_tip
);
9260 defsubr (&Sx_hide_tip
);
9262 staticpro (&tip_timer
);
9264 staticpro (&tip_frame
);
9266 last_show_tip_args
= Qnil
;
9267 staticpro (&last_show_tip_args
);
9269 defsubr (&Sx_file_dialog
);
9274 globals_of_w32fns is used to initialize those global variables that
9275 must always be initialized on startup even when the global variable
9276 initialized is non zero (see the function main in emacs.c).
9277 globals_of_w32fns is called from syms_of_w32fns when the global
9278 variable initialized is 0 and directly from main when initialized
9282 globals_of_w32fns ()
9284 HMODULE user32_lib
= GetModuleHandle ("user32.dll");
9286 TrackMouseEvent not available in all versions of Windows, so must load
9287 it dynamically. Do it once, here, instead of every time it is used.
9289 track_mouse_event_fn
= (TrackMouseEvent_Proc
)
9290 GetProcAddress (user32_lib
, "TrackMouseEvent");
9291 /* ditto for GetClipboardSequenceNumber. */
9292 clipboard_sequence_fn
= (ClipboardSequence_Proc
)
9293 GetProcAddress (user32_lib
, "GetClipboardSequenceNumber");
9295 HMODULE imm32_lib
= GetModuleHandle ("imm32.dll");
9296 get_composition_string_fn
= (ImmGetCompositionString_Proc
)
9297 GetProcAddress (imm32_lib
, "ImmGetCompositionStringW");
9298 get_ime_context_fn
= (ImmGetContext_Proc
)
9299 GetProcAddress (imm32_lib
, "ImmGetContext");
9301 DEFVAR_INT ("w32-ansi-code-page",
9302 &w32_ansi_code_page
,
9303 doc
: /* The ANSI code page used by the system. */);
9304 w32_ansi_code_page
= GetACP ();
9306 /* MessageBox does not work without this when linked to comctl32.dll 6.0. */
9307 InitCommonControls ();
9316 button
= MessageBox (NULL
,
9317 "A fatal error has occurred!\n\n"
9318 "Would you like to attach a debugger?\n\n"
9319 "Select YES to debug, NO to abort Emacs"
9321 "\n\n(type \"gdb -p <emacs-PID>\" and\n"
9322 "\"continue\" inside GDB before clicking YES.)"
9324 , "Emacs Abort Dialog",
9325 MB_ICONEXCLAMATION
| MB_TASKMODAL
9326 | MB_SETFOREGROUND
| MB_YESNO
);
9331 exit (2); /* tell the compiler we will never return */
9339 /* For convenience when debugging. */
9343 return GetLastError ();
9346 /* arch-tag: 707589ab-b9be-4638-8cdd-74629cc9b446
9347 (do not change this comment) */