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"
61 #define FILE_NAME_TEXT_FIELD edt1
63 #ifdef USE_FONT_BACKEND
67 void syms_of_w32fns ();
68 void globals_of_w32fns ();
70 extern void free_frame_menubar ();
71 extern double atof ();
72 extern int w32_console_toggle_lock_key
P_ ((int, Lisp_Object
));
73 extern void w32_menu_display_help
P_ ((HWND
, HMENU
, UINT
, UINT
));
74 extern void w32_free_menu_strings
P_ ((HWND
));
75 extern XCharStruct
*w32_per_char_metric
P_ ((XFontStruct
*, wchar_t *, int));
79 extern char *lispy_function_keys
[];
81 /* The gray bitmap `bitmaps/gray'. This is done because w32term.c uses
82 it, and including `bitmaps/gray' more than once is a problem when
83 config.h defines `static' as an empty replacement string. */
85 int gray_bitmap_width
= gray_width
;
86 int gray_bitmap_height
= gray_height
;
87 unsigned char *gray_bitmap_bits
= gray_bits
;
89 /* The colormap for converting color names to RGB values */
90 Lisp_Object Vw32_color_map
;
92 /* Non nil if alt key presses are passed on to Windows. */
93 Lisp_Object Vw32_pass_alt_to_system
;
95 /* Non nil if alt key is translated to meta_modifier, nil if it is translated
97 Lisp_Object Vw32_alt_is_meta
;
99 /* If non-zero, the windows virtual key code for an alternative quit key. */
102 /* Non nil if left window key events are passed on to Windows (this only
103 affects whether "tapping" the key opens the Start menu). */
104 Lisp_Object Vw32_pass_lwindow_to_system
;
106 /* Non nil if right window key events are passed on to Windows (this
107 only affects whether "tapping" the key opens the Start menu). */
108 Lisp_Object Vw32_pass_rwindow_to_system
;
110 /* Virtual key code used to generate "phantom" key presses in order
111 to stop system from acting on Windows key events. */
112 Lisp_Object Vw32_phantom_key_code
;
114 /* Modifier associated with the left "Windows" key, or nil to act as a
116 Lisp_Object Vw32_lwindow_modifier
;
118 /* Modifier associated with the right "Windows" key, or nil to act as a
120 Lisp_Object Vw32_rwindow_modifier
;
122 /* Modifier associated with the "Apps" key, or nil to act as a normal
124 Lisp_Object Vw32_apps_modifier
;
126 /* Value is nil if Num Lock acts as a function key. */
127 Lisp_Object Vw32_enable_num_lock
;
129 /* Value is nil if Caps Lock acts as a function key. */
130 Lisp_Object Vw32_enable_caps_lock
;
132 /* Modifier associated with Scroll Lock, or nil to act as a normal key. */
133 Lisp_Object Vw32_scroll_lock_modifier
;
135 /* Switch to control whether we inhibit requests for synthesized bold
136 and italic versions of fonts. */
137 int w32_enable_synthesized_fonts
;
139 /* Enable palette management. */
140 Lisp_Object Vw32_enable_palette
;
142 /* Control how close left/right button down events must be to
143 be converted to a middle button down event. */
144 int w32_mouse_button_tolerance
;
146 /* Minimum interval between mouse movement (and scroll bar drag)
147 events that are passed on to the event loop. */
148 int w32_mouse_move_interval
;
150 /* Flag to indicate if XBUTTON events should be passed on to Windows. */
151 int w32_pass_extra_mouse_buttons_to_system
;
153 /* Flag to indicate if media keys should be passed on to Windows. */
154 int w32_pass_multimedia_buttons_to_system
;
156 /* Non nil if no window manager is in use. */
157 Lisp_Object Vx_no_window_manager
;
159 /* Non-zero means we're allowed to display a hourglass pointer. */
161 int display_hourglass_p
;
163 /* The background and shape of the mouse pointer, and shape when not
164 over text or in the modeline. */
166 Lisp_Object Vx_pointer_shape
, Vx_nontext_pointer_shape
, Vx_mode_pointer_shape
;
167 Lisp_Object Vx_hourglass_pointer_shape
, Vx_window_horizontal_drag_shape
;
169 /* The shape when over mouse-sensitive text. */
171 Lisp_Object Vx_sensitive_text_pointer_shape
;
174 #define IDC_HAND MAKEINTRESOURCE(32649)
177 /* Color of chars displayed in cursor box. */
179 Lisp_Object Vx_cursor_fore_pixel
;
181 /* Nonzero if using Windows. */
183 static int w32_in_use
;
185 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
187 Lisp_Object Vx_pixel_size_width_font_regexp
;
189 /* Alist of bdf fonts and the files that define them. */
190 Lisp_Object Vw32_bdf_filename_alist
;
192 /* A flag to control whether fonts are matched strictly or not. */
193 int w32_strict_fontnames
;
195 /* A flag to control whether we should only repaint if GetUpdateRect
196 indicates there is an update region. */
197 int w32_strict_painting
;
199 /* Associative list linking character set strings to Windows codepages. */
200 Lisp_Object Vw32_charset_info_alist
;
202 /* VIETNAMESE_CHARSET is not defined in some versions of MSVC. */
203 #ifndef VIETNAMESE_CHARSET
204 #define VIETNAMESE_CHARSET 163
208 Lisp_Object Qsuppress_icon
;
209 Lisp_Object Qundefined_color
;
210 Lisp_Object Qcancel_timer
;
216 Lisp_Object Qcontrol
;
219 Lisp_Object Qw32_charset_ansi
;
220 Lisp_Object Qw32_charset_default
;
221 Lisp_Object Qw32_charset_symbol
;
222 Lisp_Object Qw32_charset_shiftjis
;
223 Lisp_Object Qw32_charset_hangeul
;
224 Lisp_Object Qw32_charset_gb2312
;
225 Lisp_Object Qw32_charset_chinesebig5
;
226 Lisp_Object Qw32_charset_oem
;
228 #ifndef JOHAB_CHARSET
229 #define JOHAB_CHARSET 130
232 Lisp_Object Qw32_charset_easteurope
;
233 Lisp_Object Qw32_charset_turkish
;
234 Lisp_Object Qw32_charset_baltic
;
235 Lisp_Object Qw32_charset_russian
;
236 Lisp_Object Qw32_charset_arabic
;
237 Lisp_Object Qw32_charset_greek
;
238 Lisp_Object Qw32_charset_hebrew
;
239 Lisp_Object Qw32_charset_vietnamese
;
240 Lisp_Object Qw32_charset_thai
;
241 Lisp_Object Qw32_charset_johab
;
242 Lisp_Object Qw32_charset_mac
;
245 #ifdef UNICODE_CHARSET
246 Lisp_Object Qw32_charset_unicode
;
249 /* The ANSI codepage. */
250 int w32_ansi_code_page
;
252 /* Prefix for system colors. */
253 #define SYSTEM_COLOR_PREFIX "System"
254 #define SYSTEM_COLOR_PREFIX_LEN (sizeof (SYSTEM_COLOR_PREFIX) - 1)
256 /* State variables for emulating a three button mouse. */
261 static int button_state
= 0;
262 static W32Msg saved_mouse_button_msg
;
263 static unsigned mouse_button_timer
= 0; /* non-zero when timer is active */
264 static W32Msg saved_mouse_move_msg
;
265 static unsigned mouse_move_timer
= 0;
267 /* Window that is tracking the mouse. */
268 static HWND track_mouse_window
;
270 typedef BOOL (WINAPI
* TrackMouseEvent_Proc
)
271 (IN OUT LPTRACKMOUSEEVENT lpEventTrack
);
273 TrackMouseEvent_Proc track_mouse_event_fn
= NULL
;
274 ClipboardSequence_Proc clipboard_sequence_fn
= NULL
;
275 extern AppendMenuW_Proc unicode_append_menu
;
277 /* W95 mousewheel handler */
278 unsigned int msh_mousewheel
= 0;
281 #define MOUSE_BUTTON_ID 1
282 #define MOUSE_MOVE_ID 2
283 #define MENU_FREE_ID 3
284 /* The delay (milliseconds) before a menu is freed after WM_EXITMENULOOP
286 #define MENU_FREE_DELAY 1000
287 static unsigned menu_free_timer
= 0;
289 /* The below are defined in frame.c. */
291 extern Lisp_Object Vwindow_system_version
;
294 int image_cache_refcount
, dpyinfo_refcount
;
298 /* From w32term.c. */
299 extern int w32_num_mouse_buttons
;
300 extern Lisp_Object Vw32_recognize_altgr
;
302 extern HWND w32_system_caret_hwnd
;
304 extern int w32_system_caret_height
;
305 extern int w32_system_caret_x
;
306 extern int w32_system_caret_y
;
307 extern int w32_use_visible_system_caret
;
309 static HWND w32_visible_system_caret_hwnd
;
312 extern HMENU current_popup_menu
;
313 static int menubar_in_use
= 0;
316 /* Error if we are not connected to MS-Windows. */
321 error ("MS-Windows not in use or not initialized");
324 /* Nonzero if we can use mouse menus.
325 You should not call this unless HAVE_MENUS is defined. */
333 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
334 and checking validity for W32. */
337 check_x_frame (frame
)
343 frame
= selected_frame
;
344 CHECK_LIVE_FRAME (frame
);
346 if (! FRAME_W32_P (f
))
347 error ("Non-W32 frame used");
351 /* Let the user specify a display with a frame.
352 nil stands for the selected frame--or, if that is not a w32 frame,
353 the first display on the list. */
355 struct w32_display_info
*
356 check_x_display_info (frame
)
361 struct frame
*sf
= XFRAME (selected_frame
);
363 if (FRAME_W32_P (sf
) && FRAME_LIVE_P (sf
))
364 return FRAME_W32_DISPLAY_INFO (sf
);
366 return &one_w32_display_info
;
368 else if (STRINGP (frame
))
369 return x_display_info_for_name (frame
);
374 CHECK_LIVE_FRAME (frame
);
376 if (! FRAME_W32_P (f
))
377 error ("Non-W32 frame used");
378 return FRAME_W32_DISPLAY_INFO (f
);
382 /* Return the Emacs frame-object corresponding to an w32 window.
383 It could be the frame's main window or an icon window. */
385 /* This function can be called during GC, so use GC_xxx type test macros. */
388 x_window_to_frame (dpyinfo
, wdesc
)
389 struct w32_display_info
*dpyinfo
;
392 Lisp_Object tail
, frame
;
395 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
401 if (!FRAME_W32_P (f
) || FRAME_W32_DISPLAY_INFO (f
) != dpyinfo
)
403 if (f
->output_data
.w32
->hourglass_window
== wdesc
)
406 if (FRAME_W32_WINDOW (f
) == wdesc
)
413 static Lisp_Object unwind_create_frame
P_ ((Lisp_Object
));
414 static Lisp_Object unwind_create_tip_frame
P_ ((Lisp_Object
));
415 static void my_create_window
P_ ((struct frame
*));
416 static void my_create_tip_window
P_ ((struct frame
*));
418 /* TODO: Native Input Method support; see x_create_im. */
419 void x_set_foreground_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
420 void x_set_background_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
421 void x_set_mouse_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
422 void x_set_cursor_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
423 void x_set_border_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
424 void x_set_cursor_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
425 void x_set_icon_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
426 void x_set_icon_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
427 void x_explicitly_set_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
428 void x_set_menu_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
429 void x_set_title
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
430 void x_set_tool_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
431 static void x_edge_detection
P_ ((struct frame
*, struct image
*, Lisp_Object
,
437 /* Store the screen positions of frame F into XPTR and YPTR.
438 These are the positions of the containing window manager window,
439 not Emacs's own window. */
442 x_real_positions (f
, xptr
, yptr
)
449 /* Get the bounds of the WM window. */
450 GetWindowRect (FRAME_W32_WINDOW (f
), &rect
);
455 /* Convert (0, 0) in the client area to screen co-ordinates. */
456 ClientToScreen (FRAME_W32_WINDOW (f
), &pt
);
458 /* Remember x_pixels_diff and y_pixels_diff. */
459 f
->x_pixels_diff
= pt
.x
- rect
.left
;
460 f
->y_pixels_diff
= pt
.y
- rect
.top
;
468 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
,
469 Sw32_define_rgb_color
, 4, 4, 0,
470 doc
: /* Convert RGB numbers to a windows color reference and associate with NAME.
471 This adds or updates a named color to w32-color-map, making it
472 available for use. The original entry's RGB ref is returned, or nil
473 if the entry is new. */)
474 (red
, green
, blue
, name
)
475 Lisp_Object red
, green
, blue
, name
;
478 Lisp_Object oldrgb
= Qnil
;
482 CHECK_NUMBER (green
);
486 XSETINT (rgb
, RGB(XUINT (red
), XUINT (green
), XUINT (blue
)));
490 /* replace existing entry in w32-color-map or add new entry. */
491 entry
= Fassoc (name
, Vw32_color_map
);
494 entry
= Fcons (name
, rgb
);
495 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
499 oldrgb
= Fcdr (entry
);
500 Fsetcdr (entry
, rgb
);
508 DEFUN ("w32-load-color-file", Fw32_load_color_file
,
509 Sw32_load_color_file
, 1, 1, 0,
510 doc
: /* Create an alist of color entries from an external file.
511 Assign this value to w32-color-map to replace the existing color map.
513 The file should define one named RGB color per line like so:
515 where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
517 Lisp_Object filename
;
520 Lisp_Object cmap
= Qnil
;
523 CHECK_STRING (filename
);
524 abspath
= Fexpand_file_name (filename
, Qnil
);
526 fp
= fopen (SDATA (filename
), "rt");
530 int red
, green
, blue
;
535 while (fgets (buf
, sizeof (buf
), fp
) != NULL
) {
536 if (sscanf (buf
, "%u %u %u %n", &red
, &green
, &blue
, &num
) == 3)
538 char *name
= buf
+ num
;
539 num
= strlen (name
) - 1;
540 if (name
[num
] == '\n')
542 cmap
= Fcons (Fcons (build_string (name
),
543 make_number (RGB (red
, green
, blue
))),
555 /* The default colors for the w32 color map */
556 typedef struct colormap_t
562 colormap_t w32_color_map
[] =
564 {"snow" , PALETTERGB (255,250,250)},
565 {"ghost white" , PALETTERGB (248,248,255)},
566 {"GhostWhite" , PALETTERGB (248,248,255)},
567 {"white smoke" , PALETTERGB (245,245,245)},
568 {"WhiteSmoke" , PALETTERGB (245,245,245)},
569 {"gainsboro" , PALETTERGB (220,220,220)},
570 {"floral white" , PALETTERGB (255,250,240)},
571 {"FloralWhite" , PALETTERGB (255,250,240)},
572 {"old lace" , PALETTERGB (253,245,230)},
573 {"OldLace" , PALETTERGB (253,245,230)},
574 {"linen" , PALETTERGB (250,240,230)},
575 {"antique white" , PALETTERGB (250,235,215)},
576 {"AntiqueWhite" , PALETTERGB (250,235,215)},
577 {"papaya whip" , PALETTERGB (255,239,213)},
578 {"PapayaWhip" , PALETTERGB (255,239,213)},
579 {"blanched almond" , PALETTERGB (255,235,205)},
580 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
581 {"bisque" , PALETTERGB (255,228,196)},
582 {"peach puff" , PALETTERGB (255,218,185)},
583 {"PeachPuff" , PALETTERGB (255,218,185)},
584 {"navajo white" , PALETTERGB (255,222,173)},
585 {"NavajoWhite" , PALETTERGB (255,222,173)},
586 {"moccasin" , PALETTERGB (255,228,181)},
587 {"cornsilk" , PALETTERGB (255,248,220)},
588 {"ivory" , PALETTERGB (255,255,240)},
589 {"lemon chiffon" , PALETTERGB (255,250,205)},
590 {"LemonChiffon" , PALETTERGB (255,250,205)},
591 {"seashell" , PALETTERGB (255,245,238)},
592 {"honeydew" , PALETTERGB (240,255,240)},
593 {"mint cream" , PALETTERGB (245,255,250)},
594 {"MintCream" , PALETTERGB (245,255,250)},
595 {"azure" , PALETTERGB (240,255,255)},
596 {"alice blue" , PALETTERGB (240,248,255)},
597 {"AliceBlue" , PALETTERGB (240,248,255)},
598 {"lavender" , PALETTERGB (230,230,250)},
599 {"lavender blush" , PALETTERGB (255,240,245)},
600 {"LavenderBlush" , PALETTERGB (255,240,245)},
601 {"misty rose" , PALETTERGB (255,228,225)},
602 {"MistyRose" , PALETTERGB (255,228,225)},
603 {"white" , PALETTERGB (255,255,255)},
604 {"black" , PALETTERGB ( 0, 0, 0)},
605 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
606 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
607 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
608 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
609 {"dim gray" , PALETTERGB (105,105,105)},
610 {"DimGray" , PALETTERGB (105,105,105)},
611 {"dim grey" , PALETTERGB (105,105,105)},
612 {"DimGrey" , PALETTERGB (105,105,105)},
613 {"slate gray" , PALETTERGB (112,128,144)},
614 {"SlateGray" , PALETTERGB (112,128,144)},
615 {"slate grey" , PALETTERGB (112,128,144)},
616 {"SlateGrey" , PALETTERGB (112,128,144)},
617 {"light slate gray" , PALETTERGB (119,136,153)},
618 {"LightSlateGray" , PALETTERGB (119,136,153)},
619 {"light slate grey" , PALETTERGB (119,136,153)},
620 {"LightSlateGrey" , PALETTERGB (119,136,153)},
621 {"gray" , PALETTERGB (190,190,190)},
622 {"grey" , PALETTERGB (190,190,190)},
623 {"light grey" , PALETTERGB (211,211,211)},
624 {"LightGrey" , PALETTERGB (211,211,211)},
625 {"light gray" , PALETTERGB (211,211,211)},
626 {"LightGray" , PALETTERGB (211,211,211)},
627 {"midnight blue" , PALETTERGB ( 25, 25,112)},
628 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
629 {"navy" , PALETTERGB ( 0, 0,128)},
630 {"navy blue" , PALETTERGB ( 0, 0,128)},
631 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
632 {"cornflower blue" , PALETTERGB (100,149,237)},
633 {"CornflowerBlue" , PALETTERGB (100,149,237)},
634 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
635 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
636 {"slate blue" , PALETTERGB (106, 90,205)},
637 {"SlateBlue" , PALETTERGB (106, 90,205)},
638 {"medium slate blue" , PALETTERGB (123,104,238)},
639 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
640 {"light slate blue" , PALETTERGB (132,112,255)},
641 {"LightSlateBlue" , PALETTERGB (132,112,255)},
642 {"medium blue" , PALETTERGB ( 0, 0,205)},
643 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
644 {"royal blue" , PALETTERGB ( 65,105,225)},
645 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
646 {"blue" , PALETTERGB ( 0, 0,255)},
647 {"dodger blue" , PALETTERGB ( 30,144,255)},
648 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
649 {"deep sky blue" , PALETTERGB ( 0,191,255)},
650 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
651 {"sky blue" , PALETTERGB (135,206,235)},
652 {"SkyBlue" , PALETTERGB (135,206,235)},
653 {"light sky blue" , PALETTERGB (135,206,250)},
654 {"LightSkyBlue" , PALETTERGB (135,206,250)},
655 {"steel blue" , PALETTERGB ( 70,130,180)},
656 {"SteelBlue" , PALETTERGB ( 70,130,180)},
657 {"light steel blue" , PALETTERGB (176,196,222)},
658 {"LightSteelBlue" , PALETTERGB (176,196,222)},
659 {"light blue" , PALETTERGB (173,216,230)},
660 {"LightBlue" , PALETTERGB (173,216,230)},
661 {"powder blue" , PALETTERGB (176,224,230)},
662 {"PowderBlue" , PALETTERGB (176,224,230)},
663 {"pale turquoise" , PALETTERGB (175,238,238)},
664 {"PaleTurquoise" , PALETTERGB (175,238,238)},
665 {"dark turquoise" , PALETTERGB ( 0,206,209)},
666 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
667 {"medium turquoise" , PALETTERGB ( 72,209,204)},
668 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
669 {"turquoise" , PALETTERGB ( 64,224,208)},
670 {"cyan" , PALETTERGB ( 0,255,255)},
671 {"light cyan" , PALETTERGB (224,255,255)},
672 {"LightCyan" , PALETTERGB (224,255,255)},
673 {"cadet blue" , PALETTERGB ( 95,158,160)},
674 {"CadetBlue" , PALETTERGB ( 95,158,160)},
675 {"medium aquamarine" , PALETTERGB (102,205,170)},
676 {"MediumAquamarine" , PALETTERGB (102,205,170)},
677 {"aquamarine" , PALETTERGB (127,255,212)},
678 {"dark green" , PALETTERGB ( 0,100, 0)},
679 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
680 {"dark olive green" , PALETTERGB ( 85,107, 47)},
681 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
682 {"dark sea green" , PALETTERGB (143,188,143)},
683 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
684 {"sea green" , PALETTERGB ( 46,139, 87)},
685 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
686 {"medium sea green" , PALETTERGB ( 60,179,113)},
687 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
688 {"light sea green" , PALETTERGB ( 32,178,170)},
689 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
690 {"pale green" , PALETTERGB (152,251,152)},
691 {"PaleGreen" , PALETTERGB (152,251,152)},
692 {"spring green" , PALETTERGB ( 0,255,127)},
693 {"SpringGreen" , PALETTERGB ( 0,255,127)},
694 {"lawn green" , PALETTERGB (124,252, 0)},
695 {"LawnGreen" , PALETTERGB (124,252, 0)},
696 {"green" , PALETTERGB ( 0,255, 0)},
697 {"chartreuse" , PALETTERGB (127,255, 0)},
698 {"medium spring green" , PALETTERGB ( 0,250,154)},
699 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
700 {"green yellow" , PALETTERGB (173,255, 47)},
701 {"GreenYellow" , PALETTERGB (173,255, 47)},
702 {"lime green" , PALETTERGB ( 50,205, 50)},
703 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
704 {"yellow green" , PALETTERGB (154,205, 50)},
705 {"YellowGreen" , PALETTERGB (154,205, 50)},
706 {"forest green" , PALETTERGB ( 34,139, 34)},
707 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
708 {"olive drab" , PALETTERGB (107,142, 35)},
709 {"OliveDrab" , PALETTERGB (107,142, 35)},
710 {"dark khaki" , PALETTERGB (189,183,107)},
711 {"DarkKhaki" , PALETTERGB (189,183,107)},
712 {"khaki" , PALETTERGB (240,230,140)},
713 {"pale goldenrod" , PALETTERGB (238,232,170)},
714 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
715 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
716 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
717 {"light yellow" , PALETTERGB (255,255,224)},
718 {"LightYellow" , PALETTERGB (255,255,224)},
719 {"yellow" , PALETTERGB (255,255, 0)},
720 {"gold" , PALETTERGB (255,215, 0)},
721 {"light goldenrod" , PALETTERGB (238,221,130)},
722 {"LightGoldenrod" , PALETTERGB (238,221,130)},
723 {"goldenrod" , PALETTERGB (218,165, 32)},
724 {"dark goldenrod" , PALETTERGB (184,134, 11)},
725 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
726 {"rosy brown" , PALETTERGB (188,143,143)},
727 {"RosyBrown" , PALETTERGB (188,143,143)},
728 {"indian red" , PALETTERGB (205, 92, 92)},
729 {"IndianRed" , PALETTERGB (205, 92, 92)},
730 {"saddle brown" , PALETTERGB (139, 69, 19)},
731 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
732 {"sienna" , PALETTERGB (160, 82, 45)},
733 {"peru" , PALETTERGB (205,133, 63)},
734 {"burlywood" , PALETTERGB (222,184,135)},
735 {"beige" , PALETTERGB (245,245,220)},
736 {"wheat" , PALETTERGB (245,222,179)},
737 {"sandy brown" , PALETTERGB (244,164, 96)},
738 {"SandyBrown" , PALETTERGB (244,164, 96)},
739 {"tan" , PALETTERGB (210,180,140)},
740 {"chocolate" , PALETTERGB (210,105, 30)},
741 {"firebrick" , PALETTERGB (178,34, 34)},
742 {"brown" , PALETTERGB (165,42, 42)},
743 {"dark salmon" , PALETTERGB (233,150,122)},
744 {"DarkSalmon" , PALETTERGB (233,150,122)},
745 {"salmon" , PALETTERGB (250,128,114)},
746 {"light salmon" , PALETTERGB (255,160,122)},
747 {"LightSalmon" , PALETTERGB (255,160,122)},
748 {"orange" , PALETTERGB (255,165, 0)},
749 {"dark orange" , PALETTERGB (255,140, 0)},
750 {"DarkOrange" , PALETTERGB (255,140, 0)},
751 {"coral" , PALETTERGB (255,127, 80)},
752 {"light coral" , PALETTERGB (240,128,128)},
753 {"LightCoral" , PALETTERGB (240,128,128)},
754 {"tomato" , PALETTERGB (255, 99, 71)},
755 {"orange red" , PALETTERGB (255, 69, 0)},
756 {"OrangeRed" , PALETTERGB (255, 69, 0)},
757 {"red" , PALETTERGB (255, 0, 0)},
758 {"hot pink" , PALETTERGB (255,105,180)},
759 {"HotPink" , PALETTERGB (255,105,180)},
760 {"deep pink" , PALETTERGB (255, 20,147)},
761 {"DeepPink" , PALETTERGB (255, 20,147)},
762 {"pink" , PALETTERGB (255,192,203)},
763 {"light pink" , PALETTERGB (255,182,193)},
764 {"LightPink" , PALETTERGB (255,182,193)},
765 {"pale violet red" , PALETTERGB (219,112,147)},
766 {"PaleVioletRed" , PALETTERGB (219,112,147)},
767 {"maroon" , PALETTERGB (176, 48, 96)},
768 {"medium violet red" , PALETTERGB (199, 21,133)},
769 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
770 {"violet red" , PALETTERGB (208, 32,144)},
771 {"VioletRed" , PALETTERGB (208, 32,144)},
772 {"magenta" , PALETTERGB (255, 0,255)},
773 {"violet" , PALETTERGB (238,130,238)},
774 {"plum" , PALETTERGB (221,160,221)},
775 {"orchid" , PALETTERGB (218,112,214)},
776 {"medium orchid" , PALETTERGB (186, 85,211)},
777 {"MediumOrchid" , PALETTERGB (186, 85,211)},
778 {"dark orchid" , PALETTERGB (153, 50,204)},
779 {"DarkOrchid" , PALETTERGB (153, 50,204)},
780 {"dark violet" , PALETTERGB (148, 0,211)},
781 {"DarkViolet" , PALETTERGB (148, 0,211)},
782 {"blue violet" , PALETTERGB (138, 43,226)},
783 {"BlueViolet" , PALETTERGB (138, 43,226)},
784 {"purple" , PALETTERGB (160, 32,240)},
785 {"medium purple" , PALETTERGB (147,112,219)},
786 {"MediumPurple" , PALETTERGB (147,112,219)},
787 {"thistle" , PALETTERGB (216,191,216)},
788 {"gray0" , PALETTERGB ( 0, 0, 0)},
789 {"grey0" , PALETTERGB ( 0, 0, 0)},
790 {"dark grey" , PALETTERGB (169,169,169)},
791 {"DarkGrey" , PALETTERGB (169,169,169)},
792 {"dark gray" , PALETTERGB (169,169,169)},
793 {"DarkGray" , PALETTERGB (169,169,169)},
794 {"dark blue" , PALETTERGB ( 0, 0,139)},
795 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
796 {"dark cyan" , PALETTERGB ( 0,139,139)},
797 {"DarkCyan" , PALETTERGB ( 0,139,139)},
798 {"dark magenta" , PALETTERGB (139, 0,139)},
799 {"DarkMagenta" , PALETTERGB (139, 0,139)},
800 {"dark red" , PALETTERGB (139, 0, 0)},
801 {"DarkRed" , PALETTERGB (139, 0, 0)},
802 {"light green" , PALETTERGB (144,238,144)},
803 {"LightGreen" , PALETTERGB (144,238,144)},
806 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
807 0, 0, 0, doc
: /* Return the default color map. */)
811 colormap_t
*pc
= w32_color_map
;
818 for (i
= 0; i
< sizeof (w32_color_map
) / sizeof (w32_color_map
[0]);
820 cmap
= Fcons (Fcons (build_string (pc
->name
),
821 make_number (pc
->colorref
)),
839 color
= Frassq (rgb
, Vw32_color_map
);
844 return (Fcar (color
));
850 w32_color_map_lookup (colorname
)
853 Lisp_Object tail
, ret
= Qnil
;
857 for (tail
= Vw32_color_map
; CONSP (tail
); tail
= XCDR (tail
))
859 register Lisp_Object elt
, tem
;
862 if (!CONSP (elt
)) continue;
866 if (lstrcmpi (SDATA (tem
), colorname
) == 0)
883 add_system_logical_colors_to_map (system_colors
)
884 Lisp_Object
*system_colors
;
888 /* Other registry operations are done with input blocked. */
891 /* Look for "Control Panel/Colors" under User and Machine registry
893 if (RegOpenKeyEx (HKEY_CURRENT_USER
, "Control Panel\\Colors", 0,
894 KEY_READ
, &colors_key
) == ERROR_SUCCESS
895 || RegOpenKeyEx (HKEY_LOCAL_MACHINE
, "Control Panel\\Colors", 0,
896 KEY_READ
, &colors_key
) == ERROR_SUCCESS
)
899 char color_buffer
[64];
900 char full_name_buffer
[MAX_PATH
+ SYSTEM_COLOR_PREFIX_LEN
];
902 DWORD name_size
, color_size
;
903 char *name_buffer
= full_name_buffer
+ SYSTEM_COLOR_PREFIX_LEN
;
905 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
906 color_size
= sizeof (color_buffer
);
908 strcpy (full_name_buffer
, SYSTEM_COLOR_PREFIX
);
910 while (RegEnumValueA (colors_key
, index
, name_buffer
, &name_size
,
911 NULL
, NULL
, color_buffer
, &color_size
)
915 if (sscanf (color_buffer
, " %u %u %u", &r
, &g
, &b
) == 3)
916 *system_colors
= Fcons (Fcons (build_string (full_name_buffer
),
917 make_number (RGB (r
, g
, b
))),
920 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
921 color_size
= sizeof (color_buffer
);
924 RegCloseKey (colors_key
);
932 x_to_w32_color (colorname
)
935 register Lisp_Object ret
= Qnil
;
939 if (colorname
[0] == '#')
941 /* Could be an old-style RGB Device specification. */
944 color
= colorname
+ 1;
946 size
= strlen(color
);
947 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
955 for (i
= 0; i
< 3; i
++)
961 /* The check for 'x' in the following conditional takes into
962 account the fact that strtol allows a "0x" in front of
963 our numbers, and we don't. */
964 if (!isxdigit(color
[0]) || color
[1] == 'x')
968 value
= strtoul(color
, &end
, 16);
970 if (errno
== ERANGE
|| end
- color
!= size
)
975 value
= value
* 0x10;
986 colorval
|= (value
<< pos
);
991 XSETINT (ret
, colorval
);
998 else if (strnicmp(colorname
, "rgb:", 4) == 0)
1006 color
= colorname
+ 4;
1007 for (i
= 0; i
< 3; i
++)
1010 unsigned long value
;
1012 /* The check for 'x' in the following conditional takes into
1013 account the fact that strtol allows a "0x" in front of
1014 our numbers, and we don't. */
1015 if (!isxdigit(color
[0]) || color
[1] == 'x')
1017 value
= strtoul(color
, &end
, 16);
1018 if (errno
== ERANGE
)
1020 switch (end
- color
)
1023 value
= value
* 0x10 + value
;
1036 if (value
== ULONG_MAX
)
1038 colorval
|= (value
<< pos
);
1045 XSETINT (ret
, colorval
);
1053 else if (strnicmp(colorname
, "rgbi:", 5) == 0)
1055 /* This is an RGB Intensity specification. */
1062 color
= colorname
+ 5;
1063 for (i
= 0; i
< 3; i
++)
1069 value
= strtod(color
, &end
);
1070 if (errno
== ERANGE
)
1072 if (value
< 0.0 || value
> 1.0)
1074 val
= (UINT
)(0x100 * value
);
1075 /* We used 0x100 instead of 0xFF to give a continuous
1076 range between 0.0 and 1.0 inclusive. The next statement
1077 fixes the 1.0 case. */
1080 colorval
|= (val
<< pos
);
1087 XSETINT (ret
, colorval
);
1095 /* I am not going to attempt to handle any of the CIE color schemes
1096 or TekHVC, since I don't know the algorithms for conversion to
1099 /* If we fail to lookup the color name in w32_color_map, then check the
1100 colorname to see if it can be crudely approximated: If the X color
1101 ends in a number (e.g., "darkseagreen2"), strip the number and
1102 return the result of looking up the base color name. */
1103 ret
= w32_color_map_lookup (colorname
);
1106 int len
= strlen (colorname
);
1108 if (isdigit (colorname
[len
- 1]))
1110 char *ptr
, *approx
= alloca (len
+ 1);
1112 strcpy (approx
, colorname
);
1113 ptr
= &approx
[len
- 1];
1114 while (ptr
> approx
&& isdigit (*ptr
))
1117 ret
= w32_color_map_lookup (approx
);
1126 w32_regenerate_palette (FRAME_PTR f
)
1128 struct w32_palette_entry
* list
;
1129 LOGPALETTE
* log_palette
;
1130 HPALETTE new_palette
;
1133 /* don't bother trying to create palette if not supported */
1134 if (! FRAME_W32_DISPLAY_INFO (f
)->has_palette
)
1137 log_palette
= (LOGPALETTE
*)
1138 alloca (sizeof (LOGPALETTE
) +
1139 FRAME_W32_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
1140 log_palette
->palVersion
= 0x300;
1141 log_palette
->palNumEntries
= FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1143 list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1145 i
< FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1146 i
++, list
= list
->next
)
1147 log_palette
->palPalEntry
[i
] = list
->entry
;
1149 new_palette
= CreatePalette (log_palette
);
1153 if (FRAME_W32_DISPLAY_INFO (f
)->palette
)
1154 DeleteObject (FRAME_W32_DISPLAY_INFO (f
)->palette
);
1155 FRAME_W32_DISPLAY_INFO (f
)->palette
= new_palette
;
1157 /* Realize display palette and garbage all frames. */
1158 release_frame_dc (f
, get_frame_dc (f
));
1163 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
1164 #define SET_W32_COLOR(pe, color) \
1167 pe.peRed = GetRValue (color); \
1168 pe.peGreen = GetGValue (color); \
1169 pe.peBlue = GetBValue (color); \
1174 /* Keep these around in case we ever want to track color usage. */
1176 w32_map_color (FRAME_PTR f
, COLORREF color
)
1178 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1180 if (NILP (Vw32_enable_palette
))
1183 /* check if color is already mapped */
1186 if (W32_COLOR (list
->entry
) == color
)
1194 /* not already mapped, so add to list and recreate Windows palette */
1195 list
= (struct w32_palette_entry
*)
1196 xmalloc (sizeof (struct w32_palette_entry
));
1197 SET_W32_COLOR (list
->entry
, color
);
1199 list
->next
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1200 FRAME_W32_DISPLAY_INFO (f
)->color_list
= list
;
1201 FRAME_W32_DISPLAY_INFO (f
)->num_colors
++;
1203 /* set flag that palette must be regenerated */
1204 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1208 w32_unmap_color (FRAME_PTR f
, COLORREF color
)
1210 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1211 struct w32_palette_entry
**prev
= &FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1213 if (NILP (Vw32_enable_palette
))
1216 /* check if color is already mapped */
1219 if (W32_COLOR (list
->entry
) == color
)
1221 if (--list
->refcount
== 0)
1225 FRAME_W32_DISPLAY_INFO (f
)->num_colors
--;
1235 /* set flag that palette must be regenerated */
1236 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1241 /* Gamma-correct COLOR on frame F. */
1244 gamma_correct (f
, color
)
1250 *color
= PALETTERGB (
1251 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1252 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1253 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1258 /* Decide if color named COLOR is valid for the display associated with
1259 the selected frame; if so, return the rgb values in COLOR_DEF.
1260 If ALLOC is nonzero, allocate a new colormap cell. */
1263 w32_defined_color (f
, color
, color_def
, alloc
)
1269 register Lisp_Object tem
;
1270 COLORREF w32_color_ref
;
1272 tem
= x_to_w32_color (color
);
1278 /* Apply gamma correction. */
1279 w32_color_ref
= XUINT (tem
);
1280 gamma_correct (f
, &w32_color_ref
);
1281 XSETINT (tem
, w32_color_ref
);
1284 /* Map this color to the palette if it is enabled. */
1285 if (!NILP (Vw32_enable_palette
))
1287 struct w32_palette_entry
* entry
=
1288 one_w32_display_info
.color_list
;
1289 struct w32_palette_entry
** prev
=
1290 &one_w32_display_info
.color_list
;
1292 /* check if color is already mapped */
1295 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1297 prev
= &entry
->next
;
1298 entry
= entry
->next
;
1301 if (entry
== NULL
&& alloc
)
1303 /* not already mapped, so add to list */
1304 entry
= (struct w32_palette_entry
*)
1305 xmalloc (sizeof (struct w32_palette_entry
));
1306 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1309 one_w32_display_info
.num_colors
++;
1311 /* set flag that palette must be regenerated */
1312 one_w32_display_info
.regen_palette
= TRUE
;
1315 /* Ensure COLORREF value is snapped to nearest color in (default)
1316 palette by simulating the PALETTERGB macro. This works whether
1317 or not the display device has a palette. */
1318 w32_color_ref
= XUINT (tem
) | 0x2000000;
1320 color_def
->pixel
= w32_color_ref
;
1321 color_def
->red
= GetRValue (w32_color_ref
) * 256;
1322 color_def
->green
= GetGValue (w32_color_ref
) * 256;
1323 color_def
->blue
= GetBValue (w32_color_ref
) * 256;
1333 /* Given a string ARG naming a color, compute a pixel value from it
1334 suitable for screen F.
1335 If F is not a color screen, return DEF (default) regardless of what
1339 x_decode_color (f
, arg
, def
)
1348 if (strcmp (SDATA (arg
), "black") == 0)
1349 return BLACK_PIX_DEFAULT (f
);
1350 else if (strcmp (SDATA (arg
), "white") == 0)
1351 return WHITE_PIX_DEFAULT (f
);
1353 if ((FRAME_W32_DISPLAY_INFO (f
)->n_planes
* FRAME_W32_DISPLAY_INFO (f
)->n_cbits
) == 1)
1356 /* w32_defined_color is responsible for coping with failures
1357 by looking for a near-miss. */
1358 if (w32_defined_color (f
, SDATA (arg
), &cdef
, 1))
1361 /* defined_color failed; return an ultimate default. */
1367 /* Functions called only from `x_set_frame_param'
1368 to set individual parameters.
1370 If FRAME_W32_WINDOW (f) is 0,
1371 the frame is being created and its window does not exist yet.
1372 In that case, just record the parameter's new value
1373 in the standard place; do not attempt to change the window. */
1376 x_set_foreground_color (f
, arg
, oldval
)
1378 Lisp_Object arg
, oldval
;
1380 struct w32_output
*x
= f
->output_data
.w32
;
1381 PIX_TYPE fg
, old_fg
;
1383 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1384 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
1385 FRAME_FOREGROUND_PIXEL (f
) = fg
;
1387 if (FRAME_W32_WINDOW (f
) != 0)
1389 if (x
->cursor_pixel
== old_fg
)
1390 x
->cursor_pixel
= fg
;
1392 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
1393 if (FRAME_VISIBLE_P (f
))
1399 x_set_background_color (f
, arg
, oldval
)
1401 Lisp_Object arg
, oldval
;
1403 FRAME_BACKGROUND_PIXEL (f
)
1404 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
1406 if (FRAME_W32_WINDOW (f
) != 0)
1408 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
1409 FRAME_BACKGROUND_PIXEL (f
));
1411 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
1413 if (FRAME_VISIBLE_P (f
))
1419 x_set_mouse_color (f
, arg
, oldval
)
1421 Lisp_Object arg
, oldval
;
1423 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
1427 if (!EQ (Qnil
, arg
))
1428 f
->output_data
.w32
->mouse_pixel
1429 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1430 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
1432 /* Don't let pointers be invisible. */
1433 if (mask_color
== f
->output_data
.w32
->mouse_pixel
1434 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
1435 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
1437 #if 0 /* TODO : cursor changes */
1440 /* It's not okay to crash if the user selects a screwy cursor. */
1441 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
1443 if (!EQ (Qnil
, Vx_pointer_shape
))
1445 CHECK_NUMBER (Vx_pointer_shape
);
1446 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
1449 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1450 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
1452 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
1454 CHECK_NUMBER (Vx_nontext_pointer_shape
);
1455 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1456 XINT (Vx_nontext_pointer_shape
));
1459 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
1460 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1462 if (!EQ (Qnil
, Vx_hourglass_pointer_shape
))
1464 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
1465 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1466 XINT (Vx_hourglass_pointer_shape
));
1469 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
1470 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
1472 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1473 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
1475 CHECK_NUMBER (Vx_mode_pointer_shape
);
1476 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1477 XINT (Vx_mode_pointer_shape
));
1480 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1481 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
1483 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
1485 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
1487 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1488 XINT (Vx_sensitive_text_pointer_shape
));
1491 hand_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
1493 if (!NILP (Vx_window_horizontal_drag_shape
))
1495 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
1496 horizontal_drag_cursor
1497 = XCreateFontCursor (FRAME_X_DISPLAY (f
),
1498 XINT (Vx_window_horizontal_drag_shape
));
1501 horizontal_drag_cursor
1502 = XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_sb_h_double_arrow
);
1504 /* Check and report errors with the above calls. */
1505 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
1506 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
1509 XColor fore_color
, back_color
;
1511 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
1512 back_color
.pixel
= mask_color
;
1513 XQueryColor (FRAME_W32_DISPLAY (f
),
1514 DefaultColormap (FRAME_W32_DISPLAY (f
),
1515 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1517 XQueryColor (FRAME_W32_DISPLAY (f
),
1518 DefaultColormap (FRAME_W32_DISPLAY (f
),
1519 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1521 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
1522 &fore_color
, &back_color
);
1523 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
1524 &fore_color
, &back_color
);
1525 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
1526 &fore_color
, &back_color
);
1527 XRecolorCursor (FRAME_W32_DISPLAY (f
), hand_cursor
,
1528 &fore_color
, &back_color
);
1529 XRecolorCursor (FRAME_W32_DISPLAY (f
), hourglass_cursor
,
1530 &fore_color
, &back_color
);
1533 if (FRAME_W32_WINDOW (f
) != 0)
1534 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
1536 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
1537 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
1538 f
->output_data
.w32
->text_cursor
= cursor
;
1540 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
1541 && f
->output_data
.w32
->nontext_cursor
!= 0)
1542 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
1543 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
1545 if (hourglass_cursor
!= f
->output_data
.w32
->hourglass_cursor
1546 && f
->output_data
.w32
->hourglass_cursor
!= 0)
1547 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hourglass_cursor
);
1548 f
->output_data
.w32
->hourglass_cursor
= hourglass_cursor
;
1550 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
1551 && f
->output_data
.w32
->modeline_cursor
!= 0)
1552 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
1553 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
1555 if (hand_cursor
!= f
->output_data
.w32
->hand_cursor
1556 && f
->output_data
.w32
->hand_cursor
!= 0)
1557 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hand_cursor
);
1558 f
->output_data
.w32
->hand_cursor
= hand_cursor
;
1560 XFlush (FRAME_W32_DISPLAY (f
));
1563 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1567 /* Defined in w32term.c. */
1569 x_set_cursor_color (f
, arg
, oldval
)
1571 Lisp_Object arg
, oldval
;
1573 unsigned long fore_pixel
, pixel
;
1575 if (!NILP (Vx_cursor_fore_pixel
))
1576 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1577 WHITE_PIX_DEFAULT (f
));
1579 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1581 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1583 /* Make sure that the cursor color differs from the background color. */
1584 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
1586 pixel
= f
->output_data
.w32
->mouse_pixel
;
1587 if (pixel
== fore_pixel
)
1588 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1591 f
->output_data
.w32
->cursor_foreground_pixel
= fore_pixel
;
1592 f
->output_data
.w32
->cursor_pixel
= pixel
;
1594 if (FRAME_W32_WINDOW (f
) != 0)
1597 /* Update frame's cursor_gc. */
1598 f
->output_data
.w32
->cursor_gc
->foreground
= fore_pixel
;
1599 f
->output_data
.w32
->cursor_gc
->background
= pixel
;
1603 if (FRAME_VISIBLE_P (f
))
1605 x_update_cursor (f
, 0);
1606 x_update_cursor (f
, 1);
1610 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1613 /* Set the border-color of frame F to pixel value PIX.
1614 Note that this does not fully take effect if done before
1618 x_set_border_pixel (f
, pix
)
1623 f
->output_data
.w32
->border_pixel
= pix
;
1625 if (FRAME_W32_WINDOW (f
) != 0 && f
->border_width
> 0)
1627 if (FRAME_VISIBLE_P (f
))
1632 /* Set the border-color of frame F to value described by ARG.
1633 ARG can be a string naming a color.
1634 The border-color is used for the border that is drawn by the server.
1635 Note that this does not fully take effect if done before
1636 F has a window; it must be redone when the window is created. */
1639 x_set_border_color (f
, arg
, oldval
)
1641 Lisp_Object arg
, oldval
;
1646 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1647 x_set_border_pixel (f
, pix
);
1648 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1653 x_set_cursor_type (f
, arg
, oldval
)
1655 Lisp_Object arg
, oldval
;
1657 set_frame_cursor_types (f
, arg
);
1659 /* Make sure the cursor gets redrawn. */
1660 cursor_type_changed
= 1;
1664 x_set_icon_type (f
, arg
, oldval
)
1666 Lisp_Object arg
, oldval
;
1670 if (NILP (arg
) && NILP (oldval
))
1673 if (STRINGP (arg
) && STRINGP (oldval
)
1674 && EQ (Fstring_equal (oldval
, arg
), Qt
))
1677 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
1682 result
= x_bitmap_icon (f
, arg
);
1686 error ("No icon window available");
1693 x_set_icon_name (f
, arg
, oldval
)
1695 Lisp_Object arg
, oldval
;
1699 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1702 else if (!NILP (arg
) || NILP (oldval
))
1708 if (f
->output_data
.w32
->icon_bitmap
!= 0)
1713 result
= x_text_icon (f
,
1714 (char *) SDATA ((!NILP (f
->icon_name
)
1723 error ("No icon window available");
1726 /* If the window was unmapped (and its icon was mapped),
1727 the new icon is not mapped, so map the window in its stead. */
1728 if (FRAME_VISIBLE_P (f
))
1730 #ifdef USE_X_TOOLKIT
1731 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
1733 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
1736 XFlush (FRAME_W32_DISPLAY (f
));
1743 x_set_menu_bar_lines (f
, value
, oldval
)
1745 Lisp_Object value
, oldval
;
1748 int olines
= FRAME_MENU_BAR_LINES (f
);
1750 /* Right now, menu bars don't work properly in minibuf-only frames;
1751 most of the commands try to apply themselves to the minibuffer
1752 frame itself, and get an error because you can't switch buffers
1753 in or split the minibuffer window. */
1754 if (FRAME_MINIBUF_ONLY_P (f
))
1757 if (INTEGERP (value
))
1758 nlines
= XINT (value
);
1762 FRAME_MENU_BAR_LINES (f
) = 0;
1764 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1767 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1768 free_frame_menubar (f
);
1769 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1771 /* Adjust the frame size so that the client (text) dimensions
1772 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
1774 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
1775 do_pending_window_change (0);
1781 /* Set the number of lines used for the tool bar of frame F to VALUE.
1782 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1783 is the old number of tool bar lines. This function changes the
1784 height of all windows on frame F to match the new tool bar height.
1785 The frame's height doesn't change. */
1788 x_set_tool_bar_lines (f
, value
, oldval
)
1790 Lisp_Object value
, oldval
;
1792 int delta
, nlines
, root_height
;
1793 Lisp_Object root_window
;
1795 /* Treat tool bars like menu bars. */
1796 if (FRAME_MINIBUF_ONLY_P (f
))
1799 /* Use VALUE only if an integer >= 0. */
1800 if (INTEGERP (value
) && XINT (value
) >= 0)
1801 nlines
= XFASTINT (value
);
1805 /* Make sure we redisplay all windows in this frame. */
1806 ++windows_or_buffers_changed
;
1808 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
1810 /* Don't resize the tool-bar to more than we have room for. */
1811 root_window
= FRAME_ROOT_WINDOW (f
);
1812 root_height
= WINDOW_TOTAL_LINES (XWINDOW (root_window
));
1813 if (root_height
- delta
< 1)
1815 delta
= root_height
- 1;
1816 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
1819 FRAME_TOOL_BAR_LINES (f
) = nlines
;
1820 change_window_heights (root_window
, delta
);
1823 /* We also have to make sure that the internal border at the top of
1824 the frame, below the menu bar or tool bar, is redrawn when the
1825 tool bar disappears. This is so because the internal border is
1826 below the tool bar if one is displayed, but is below the menu bar
1827 if there isn't a tool bar. The tool bar draws into the area
1828 below the menu bar. */
1829 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
1832 clear_current_matrices (f
);
1835 /* If the tool bar gets smaller, the internal border below it
1836 has to be cleared. It was formerly part of the display
1837 of the larger tool bar, and updating windows won't clear it. */
1840 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1841 int width
= FRAME_PIXEL_WIDTH (f
);
1842 int y
= nlines
* FRAME_LINE_HEIGHT (f
);
1846 HDC hdc
= get_frame_dc (f
);
1847 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
1848 release_frame_dc (f
, hdc
);
1852 if (WINDOWP (f
->tool_bar_window
))
1853 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1858 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1861 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1862 name; if NAME is a string, set F's name to NAME and set
1863 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1865 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1866 suggesting a new name, which lisp code should override; if
1867 F->explicit_name is set, ignore the new name; otherwise, set it. */
1870 x_set_name (f
, name
, explicit)
1875 /* Make sure that requests from lisp code override requests from
1876 Emacs redisplay code. */
1879 /* If we're switching from explicit to implicit, we had better
1880 update the mode lines and thereby update the title. */
1881 if (f
->explicit_name
&& NILP (name
))
1882 update_mode_lines
= 1;
1884 f
->explicit_name
= ! NILP (name
);
1886 else if (f
->explicit_name
)
1889 /* If NAME is nil, set the name to the w32_id_name. */
1892 /* Check for no change needed in this very common case
1893 before we do any consing. */
1894 if (!strcmp (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
,
1897 name
= build_string (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
);
1900 CHECK_STRING (name
);
1902 /* Don't change the name if it's already NAME. */
1903 if (! NILP (Fstring_equal (name
, f
->name
)))
1908 /* For setting the frame title, the title parameter should override
1909 the name parameter. */
1910 if (! NILP (f
->title
))
1913 if (FRAME_W32_WINDOW (f
))
1915 if (STRING_MULTIBYTE (name
))
1916 name
= ENCODE_SYSTEM (name
);
1919 SetWindowText(FRAME_W32_WINDOW (f
), SDATA (name
));
1924 /* This function should be called when the user's lisp code has
1925 specified a name for the frame; the name will override any set by the
1928 x_explicitly_set_name (f
, arg
, oldval
)
1930 Lisp_Object arg
, oldval
;
1932 x_set_name (f
, arg
, 1);
1935 /* This function should be called by Emacs redisplay code to set the
1936 name; names set this way will never override names set by the user's
1939 x_implicitly_set_name (f
, arg
, oldval
)
1941 Lisp_Object arg
, oldval
;
1943 x_set_name (f
, arg
, 0);
1946 /* Change the title of frame F to NAME.
1947 If NAME is nil, use the frame name as the title. */
1950 x_set_title (f
, name
, old_name
)
1952 Lisp_Object name
, old_name
;
1954 /* Don't change the title if it's already NAME. */
1955 if (EQ (name
, f
->title
))
1958 update_mode_lines
= 1;
1965 if (FRAME_W32_WINDOW (f
))
1967 if (STRING_MULTIBYTE (name
))
1968 name
= ENCODE_SYSTEM (name
);
1971 SetWindowText(FRAME_W32_WINDOW (f
), SDATA (name
));
1977 void x_set_scroll_bar_default_width (f
)
1980 int wid
= FRAME_COLUMN_WIDTH (f
);
1982 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
1983 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) +
1988 /* Subroutines of creating a frame. */
1991 /* Return the value of parameter PARAM.
1993 First search ALIST, then Vdefault_frame_alist, then the X defaults
1994 database, using ATTRIBUTE as the attribute name and CLASS as its class.
1996 Convert the resource to the type specified by desired_type.
1998 If no default is specified, return Qunbound. If you call
1999 w32_get_arg, make sure you deal with Qunbound in a reasonable way,
2000 and don't let it get stored in any Lisp-visible variables! */
2003 w32_get_arg (alist
, param
, attribute
, class, type
)
2004 Lisp_Object alist
, param
;
2007 enum resource_types type
;
2009 return x_get_arg (check_x_display_info (Qnil
),
2010 alist
, param
, attribute
, class, type
);
2015 w32_load_cursor (LPCTSTR name
)
2017 /* Try first to load cursor from application resource. */
2018 Cursor cursor
= LoadImage ((HINSTANCE
) GetModuleHandle(NULL
),
2019 name
, IMAGE_CURSOR
, 0, 0,
2020 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
2023 /* Then try to load a shared predefined cursor. */
2024 cursor
= LoadImage (NULL
, name
, IMAGE_CURSOR
, 0, 0,
2025 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
2030 extern LRESULT CALLBACK
w32_wnd_proc ();
2033 w32_init_class (hinst
)
2038 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
2039 wc
.lpfnWndProc
= (WNDPROC
) w32_wnd_proc
;
2041 wc
.cbWndExtra
= WND_EXTRA_BYTES
;
2042 wc
.hInstance
= hinst
;
2043 wc
.hIcon
= LoadIcon (hinst
, EMACS_CLASS
);
2044 wc
.hCursor
= w32_load_cursor (IDC_ARROW
);
2045 wc
.hbrBackground
= NULL
; /* GetStockObject (WHITE_BRUSH); */
2046 wc
.lpszMenuName
= NULL
;
2047 wc
.lpszClassName
= EMACS_CLASS
;
2049 return (RegisterClass (&wc
));
2053 w32_createscrollbar (f
, bar
)
2055 struct scroll_bar
* bar
;
2057 return (CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
2058 /* Position and size of scroll bar. */
2059 XINT(bar
->left
) + VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
2061 XINT(bar
->width
) - VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
2063 FRAME_W32_WINDOW (f
),
2070 w32_createwindow (f
)
2075 Lisp_Object top
= Qunbound
;
2076 Lisp_Object left
= Qunbound
;
2078 rect
.left
= rect
.top
= 0;
2079 rect
.right
= FRAME_PIXEL_WIDTH (f
);
2080 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
2082 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
2083 FRAME_EXTERNAL_MENU_BAR (f
));
2085 /* Do first time app init */
2089 w32_init_class (hinst
);
2092 if (f
->size_hint_flags
& USPosition
|| f
->size_hint_flags
& PPosition
)
2094 XSETINT (left
, f
->left_pos
);
2095 XSETINT (top
, f
->top_pos
);
2097 else if (EQ (left
, Qunbound
) && EQ (top
, Qunbound
))
2099 /* When called with RES_TYPE_NUMBER, w32_get_arg will return zero
2100 for anything that is not a number and is not Qunbound. */
2101 left
= w32_get_arg (Qnil
, Qleft
, "left", "Left", RES_TYPE_NUMBER
);
2102 top
= w32_get_arg (Qnil
, Qtop
, "top", "Top", RES_TYPE_NUMBER
);
2105 FRAME_W32_WINDOW (f
) = hwnd
2106 = CreateWindow (EMACS_CLASS
,
2108 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
2109 EQ (left
, Qunbound
) ? CW_USEDEFAULT
: XINT (left
),
2110 EQ (top
, Qunbound
) ? CW_USEDEFAULT
: XINT (top
),
2111 rect
.right
- rect
.left
,
2112 rect
.bottom
- rect
.top
,
2120 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
2121 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
2122 SetWindowLong (hwnd
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
2123 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->scroll_bar_actual_width
);
2124 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
2126 /* Enable drag-n-drop. */
2127 DragAcceptFiles (hwnd
, TRUE
);
2129 /* Do this to discard the default setting specified by our parent. */
2130 ShowWindow (hwnd
, SW_HIDE
);
2132 /* Update frame positions. */
2133 GetWindowRect (hwnd
, &rect
);
2134 f
->left_pos
= rect
.left
;
2135 f
->top_pos
= rect
.top
;
2140 my_post_msg (wmsg
, hwnd
, msg
, wParam
, lParam
)
2147 wmsg
->msg
.hwnd
= hwnd
;
2148 wmsg
->msg
.message
= msg
;
2149 wmsg
->msg
.wParam
= wParam
;
2150 wmsg
->msg
.lParam
= lParam
;
2151 wmsg
->msg
.time
= GetMessageTime ();
2156 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
2157 between left and right keys as advertised. We test for this
2158 support dynamically, and set a flag when the support is absent. If
2159 absent, we keep track of the left and right control and alt keys
2160 ourselves. This is particularly necessary on keyboards that rely
2161 upon the AltGr key, which is represented as having the left control
2162 and right alt keys pressed. For these keyboards, we need to know
2163 when the left alt key has been pressed in addition to the AltGr key
2164 so that we can properly support M-AltGr-key sequences (such as M-@
2165 on Swedish keyboards). */
2167 #define EMACS_LCONTROL 0
2168 #define EMACS_RCONTROL 1
2169 #define EMACS_LMENU 2
2170 #define EMACS_RMENU 3
2172 static int modifiers
[4];
2173 static int modifiers_recorded
;
2174 static int modifier_key_support_tested
;
2177 test_modifier_support (unsigned int wparam
)
2181 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
2183 if (wparam
== VK_CONTROL
)
2193 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
2194 modifiers_recorded
= 1;
2196 modifiers_recorded
= 0;
2197 modifier_key_support_tested
= 1;
2201 record_keydown (unsigned int wparam
, unsigned int lparam
)
2205 if (!modifier_key_support_tested
)
2206 test_modifier_support (wparam
);
2208 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2211 if (wparam
== VK_CONTROL
)
2212 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2214 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2220 record_keyup (unsigned int wparam
, unsigned int lparam
)
2224 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2227 if (wparam
== VK_CONTROL
)
2228 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2230 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2235 /* Emacs can lose focus while a modifier key has been pressed. When
2236 it regains focus, be conservative and clear all modifiers since
2237 we cannot reconstruct the left and right modifier state. */
2243 if (GetFocus () == NULL
)
2244 /* Emacs doesn't have keyboard focus. Do nothing. */
2247 ctrl
= GetAsyncKeyState (VK_CONTROL
);
2248 alt
= GetAsyncKeyState (VK_MENU
);
2250 if (!(ctrl
& 0x08000))
2251 /* Clear any recorded control modifier state. */
2252 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2254 if (!(alt
& 0x08000))
2255 /* Clear any recorded alt modifier state. */
2256 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2258 /* Update the state of all modifier keys, because modifiers used in
2259 hot-key combinations can get stuck on if Emacs loses focus as a
2260 result of a hot-key being pressed. */
2264 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
2266 GetKeyboardState (keystate
);
2267 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
2268 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
2269 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
2270 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
2271 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
2272 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
2273 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
2274 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
2275 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
2276 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
2277 SetKeyboardState (keystate
);
2281 /* Synchronize modifier state with what is reported with the current
2282 keystroke. Even if we cannot distinguish between left and right
2283 modifier keys, we know that, if no modifiers are set, then neither
2284 the left or right modifier should be set. */
2288 if (!modifiers_recorded
)
2291 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
2292 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2294 if (!(GetKeyState (VK_MENU
) & 0x8000))
2295 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2299 modifier_set (int vkey
)
2301 if (vkey
== VK_CAPITAL
|| vkey
== VK_SCROLL
)
2302 return (GetKeyState (vkey
) & 0x1);
2303 if (!modifiers_recorded
)
2304 return (GetKeyState (vkey
) & 0x8000);
2309 return modifiers
[EMACS_LCONTROL
];
2311 return modifiers
[EMACS_RCONTROL
];
2313 return modifiers
[EMACS_LMENU
];
2315 return modifiers
[EMACS_RMENU
];
2317 return (GetKeyState (vkey
) & 0x8000);
2320 /* Convert between the modifier bits W32 uses and the modifier bits
2324 w32_key_to_modifier (int key
)
2326 Lisp_Object key_mapping
;
2331 key_mapping
= Vw32_lwindow_modifier
;
2334 key_mapping
= Vw32_rwindow_modifier
;
2337 key_mapping
= Vw32_apps_modifier
;
2340 key_mapping
= Vw32_scroll_lock_modifier
;
2346 /* NB. This code runs in the input thread, asychronously to the lisp
2347 thread, so we must be careful to ensure access to lisp data is
2348 thread-safe. The following code is safe because the modifier
2349 variable values are updated atomically from lisp and symbols are
2350 not relocated by GC. Also, we don't have to worry about seeing GC
2352 if (EQ (key_mapping
, Qhyper
))
2353 return hyper_modifier
;
2354 if (EQ (key_mapping
, Qsuper
))
2355 return super_modifier
;
2356 if (EQ (key_mapping
, Qmeta
))
2357 return meta_modifier
;
2358 if (EQ (key_mapping
, Qalt
))
2359 return alt_modifier
;
2360 if (EQ (key_mapping
, Qctrl
))
2361 return ctrl_modifier
;
2362 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
2363 return ctrl_modifier
;
2364 if (EQ (key_mapping
, Qshift
))
2365 return shift_modifier
;
2367 /* Don't generate any modifier if not explicitly requested. */
2372 w32_get_modifiers ()
2374 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
2375 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
2376 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
2377 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
2378 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
2379 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
2380 (modifier_set (VK_MENU
) ?
2381 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
2384 /* We map the VK_* modifiers into console modifier constants
2385 so that we can use the same routines to handle both console
2386 and window input. */
2389 construct_console_modifiers ()
2394 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
2395 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
2396 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
2397 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
2398 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
2399 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
2400 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
2401 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
2402 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
2403 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
2404 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
2410 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
2414 /* Convert to emacs modifiers. */
2415 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
2421 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
2423 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
2426 if (virt_key
== VK_RETURN
)
2427 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
2429 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
2430 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
2432 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
2433 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
2435 if (virt_key
== VK_CLEAR
)
2436 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
2441 /* List of special key combinations which w32 would normally capture,
2442 but emacs should grab instead. Not directly visible to lisp, to
2443 simplify synchronization. Each item is an integer encoding a virtual
2444 key code and modifier combination to capture. */
2445 Lisp_Object w32_grabbed_keys
;
2447 #define HOTKEY(vk,mods) make_number (((vk) & 255) | ((mods) << 8))
2448 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
2449 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
2450 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
2452 #define RAW_HOTKEY_ID(k) ((k) & 0xbfff)
2453 #define RAW_HOTKEY_VK_CODE(k) ((k) & 255)
2454 #define RAW_HOTKEY_MODIFIERS(k) ((k) >> 8)
2456 /* Register hot-keys for reserved key combinations when Emacs has
2457 keyboard focus, since this is the only way Emacs can receive key
2458 combinations like Alt-Tab which are used by the system. */
2461 register_hot_keys (hwnd
)
2464 Lisp_Object keylist
;
2466 /* Use CONSP, since we are called asynchronously. */
2467 for (keylist
= w32_grabbed_keys
; CONSP (keylist
); keylist
= XCDR (keylist
))
2469 Lisp_Object key
= XCAR (keylist
);
2471 /* Deleted entries get set to nil. */
2472 if (!INTEGERP (key
))
2475 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
2476 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
2481 unregister_hot_keys (hwnd
)
2484 Lisp_Object keylist
;
2486 for (keylist
= w32_grabbed_keys
; CONSP (keylist
); keylist
= XCDR (keylist
))
2488 Lisp_Object key
= XCAR (keylist
);
2490 if (!INTEGERP (key
))
2493 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
2497 /* Main message dispatch loop. */
2500 w32_msg_pump (deferred_msg
* msg_buf
)
2506 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
2508 while (GetMessage (&msg
, NULL
, 0, 0))
2510 if (msg
.hwnd
== NULL
)
2512 switch (msg
.message
)
2515 /* Produced by complete_deferred_msg; just ignore. */
2517 case WM_EMACS_CREATEWINDOW
:
2518 /* Initialize COM for this window. Even though we don't use it,
2519 some third party shell extensions can cause it to be used in
2520 system dialogs, which causes a crash if it is not initialized.
2521 This is a known bug in Windows, which was fixed long ago, but
2522 the patch for XP is not publically available until XP SP3,
2523 and older versions will never be patched. */
2524 CoInitialize (NULL
);
2525 w32_createwindow ((struct frame
*) msg
.wParam
);
2526 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2529 case WM_EMACS_SETLOCALE
:
2530 SetThreadLocale (msg
.wParam
);
2531 /* Reply is not expected. */
2533 case WM_EMACS_SETKEYBOARDLAYOUT
:
2534 result
= (int) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
2535 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2539 case WM_EMACS_REGISTER_HOT_KEY
:
2540 focus_window
= GetFocus ();
2541 if (focus_window
!= NULL
)
2542 RegisterHotKey (focus_window
,
2543 RAW_HOTKEY_ID (msg
.wParam
),
2544 RAW_HOTKEY_MODIFIERS (msg
.wParam
),
2545 RAW_HOTKEY_VK_CODE (msg
.wParam
));
2546 /* Reply is not expected. */
2548 case WM_EMACS_UNREGISTER_HOT_KEY
:
2549 focus_window
= GetFocus ();
2550 if (focus_window
!= NULL
)
2551 UnregisterHotKey (focus_window
, RAW_HOTKEY_ID (msg
.wParam
));
2552 /* Mark item as erased. NB: this code must be
2553 thread-safe. The next line is okay because the cons
2554 cell is never made into garbage and is not relocated by
2556 XSETCAR ((Lisp_Object
) ((EMACS_INT
) msg
.lParam
), Qnil
);
2557 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2560 case WM_EMACS_TOGGLE_LOCK_KEY
:
2562 int vk_code
= (int) msg
.wParam
;
2563 int cur_state
= (GetKeyState (vk_code
) & 1);
2564 Lisp_Object new_state
= (Lisp_Object
) ((EMACS_INT
) msg
.lParam
);
2566 /* NB: This code must be thread-safe. It is safe to
2567 call NILP because symbols are not relocated by GC,
2568 and pointer here is not touched by GC (so the markbit
2569 can't be set). Numbers are safe because they are
2570 immediate values. */
2571 if (NILP (new_state
)
2572 || (NUMBERP (new_state
)
2573 && ((XUINT (new_state
)) & 1) != cur_state
))
2575 one_w32_display_info
.faked_key
= vk_code
;
2577 keybd_event ((BYTE
) vk_code
,
2578 (BYTE
) MapVirtualKey (vk_code
, 0),
2579 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2580 keybd_event ((BYTE
) vk_code
,
2581 (BYTE
) MapVirtualKey (vk_code
, 0),
2582 KEYEVENTF_EXTENDEDKEY
| 0, 0);
2583 keybd_event ((BYTE
) vk_code
,
2584 (BYTE
) MapVirtualKey (vk_code
, 0),
2585 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2586 cur_state
= !cur_state
;
2588 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2594 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
2599 DispatchMessage (&msg
);
2602 /* Exit nested loop when our deferred message has completed. */
2603 if (msg_buf
->completed
)
2608 deferred_msg
* deferred_msg_head
;
2610 static deferred_msg
*
2611 find_deferred_msg (HWND hwnd
, UINT msg
)
2613 deferred_msg
* item
;
2615 /* Don't actually need synchronization for read access, since
2616 modification of single pointer is always atomic. */
2617 /* enter_crit (); */
2619 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2620 if (item
->w32msg
.msg
.hwnd
== hwnd
2621 && item
->w32msg
.msg
.message
== msg
)
2624 /* leave_crit (); */
2630 send_deferred_msg (deferred_msg
* msg_buf
,
2636 /* Only input thread can send deferred messages. */
2637 if (GetCurrentThreadId () != dwWindowsThreadId
)
2640 /* It is an error to send a message that is already deferred. */
2641 if (find_deferred_msg (hwnd
, msg
) != NULL
)
2644 /* Enforced synchronization is not needed because this is the only
2645 function that alters deferred_msg_head, and the following critical
2646 section is guaranteed to only be serially reentered (since only the
2647 input thread can call us). */
2649 /* enter_crit (); */
2651 msg_buf
->completed
= 0;
2652 msg_buf
->next
= deferred_msg_head
;
2653 deferred_msg_head
= msg_buf
;
2654 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
2656 /* leave_crit (); */
2658 /* Start a new nested message loop to process other messages until
2659 this one is completed. */
2660 w32_msg_pump (msg_buf
);
2662 deferred_msg_head
= msg_buf
->next
;
2664 return msg_buf
->result
;
2668 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
2670 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
2672 if (msg_buf
== NULL
)
2673 /* Message may have been cancelled, so don't abort(). */
2676 msg_buf
->result
= result
;
2677 msg_buf
->completed
= 1;
2679 /* Ensure input thread is woken so it notices the completion. */
2680 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2684 cancel_all_deferred_msgs ()
2686 deferred_msg
* item
;
2688 /* Don't actually need synchronization for read access, since
2689 modification of single pointer is always atomic. */
2690 /* enter_crit (); */
2692 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2695 item
->completed
= 1;
2698 /* leave_crit (); */
2700 /* Ensure input thread is woken so it notices the completion. */
2701 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2705 w32_msg_worker (void *arg
)
2708 deferred_msg dummy_buf
;
2710 /* Ensure our message queue is created */
2712 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
2714 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2717 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
2718 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
2719 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
2721 /* This is the inital message loop which should only exit when the
2722 application quits. */
2723 w32_msg_pump (&dummy_buf
);
2729 signal_user_input ()
2731 /* Interrupt any lisp that wants to be interrupted by input. */
2732 if (!NILP (Vthrow_on_input
))
2734 Vquit_flag
= Vthrow_on_input
;
2735 /* If we're inside a function that wants immediate quits,
2737 if (immediate_quit
&& NILP (Vinhibit_quit
))
2747 post_character_message (hwnd
, msg
, wParam
, lParam
, modifiers
)
2757 wmsg
.dwModifiers
= modifiers
;
2759 /* Detect quit_char and set quit-flag directly. Note that we
2760 still need to post a message to ensure the main thread will be
2761 woken up if blocked in sys_select(), but we do NOT want to post
2762 the quit_char message itself (because it will usually be as if
2763 the user had typed quit_char twice). Instead, we post a dummy
2764 message that has no particular effect. */
2767 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
2768 c
= make_ctrl_char (c
) & 0377;
2770 || (wmsg
.dwModifiers
== 0 &&
2771 w32_quit_key
&& wParam
== w32_quit_key
))
2775 /* The choice of message is somewhat arbitrary, as long as
2776 the main thread handler just ignores it. */
2779 /* Interrupt any blocking system calls. */
2782 /* As a safety precaution, forcibly complete any deferred
2783 messages. This is a kludge, but I don't see any particularly
2784 clean way to handle the situation where a deferred message is
2785 "dropped" in the lisp thread, and will thus never be
2786 completed, eg. by the user trying to activate the menubar
2787 when the lisp thread is busy, and then typing C-g when the
2788 menubar doesn't open promptly (with the result that the
2789 menubar never responds at all because the deferred
2790 WM_INITMENU message is never completed). Another problem
2791 situation is when the lisp thread calls SendMessage (to send
2792 a window manager command) when a message has been deferred;
2793 the lisp thread gets blocked indefinitely waiting for the
2794 deferred message to be completed, which itself is waiting for
2795 the lisp thread to respond.
2797 Note that we don't want to block the input thread waiting for
2798 a reponse from the lisp thread (although that would at least
2799 solve the deadlock problem above), because we want to be able
2800 to receive C-g to interrupt the lisp thread. */
2801 cancel_all_deferred_msgs ();
2804 signal_user_input ();
2807 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2810 /* Main window procedure */
2813 w32_wnd_proc (hwnd
, msg
, wParam
, lParam
)
2820 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
2822 int windows_translate
;
2825 /* Note that it is okay to call x_window_to_frame, even though we are
2826 not running in the main lisp thread, because frame deletion
2827 requires the lisp thread to synchronize with this thread. Thus, if
2828 a frame struct is returned, it can be used without concern that the
2829 lisp thread might make it disappear while we are using it.
2831 NB. Walking the frame list in this thread is safe (as long as
2832 writes of Lisp_Object slots are atomic, which they are on Windows).
2833 Although delete-frame can destructively modify the frame list while
2834 we are walking it, a garbage collection cannot occur until after
2835 delete-frame has synchronized with this thread.
2837 It is also safe to use functions that make GDI calls, such as
2838 w32_clear_rect, because these functions must obtain a DC handle
2839 from the frame struct using get_frame_dc which is thread-aware. */
2844 f
= x_window_to_frame (dpyinfo
, hwnd
);
2847 HDC hdc
= get_frame_dc (f
);
2848 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
2849 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
2850 release_frame_dc (f
, hdc
);
2852 #if defined (W32_DEBUG_DISPLAY)
2853 DebPrint (("WM_ERASEBKGND (frame %p): erasing %d,%d-%d,%d\n",
2855 wmsg
.rect
.left
, wmsg
.rect
.top
,
2856 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2857 #endif /* W32_DEBUG_DISPLAY */
2860 case WM_PALETTECHANGED
:
2861 /* ignore our own changes */
2862 if ((HWND
)wParam
!= hwnd
)
2864 f
= x_window_to_frame (dpyinfo
, hwnd
);
2866 /* get_frame_dc will realize our palette and force all
2867 frames to be redrawn if needed. */
2868 release_frame_dc (f
, get_frame_dc (f
));
2873 PAINTSTRUCT paintStruct
;
2875 bzero (&update_rect
, sizeof (update_rect
));
2877 f
= x_window_to_frame (dpyinfo
, hwnd
);
2880 DebPrint (("WM_PAINT received for unknown window %p\n", hwnd
));
2884 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
2885 fails. Apparently this can happen under some
2887 if (GetUpdateRect (hwnd
, &update_rect
, FALSE
) || !w32_strict_painting
)
2890 BeginPaint (hwnd
, &paintStruct
);
2892 /* The rectangles returned by GetUpdateRect and BeginPaint
2893 do not always match. Play it safe by assuming both areas
2895 UnionRect (&(wmsg
.rect
), &update_rect
, &(paintStruct
.rcPaint
));
2897 #if defined (W32_DEBUG_DISPLAY)
2898 DebPrint (("WM_PAINT (frame %p): painting %d,%d-%d,%d\n",
2900 wmsg
.rect
.left
, wmsg
.rect
.top
,
2901 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2902 DebPrint ((" [update region is %d,%d-%d,%d]\n",
2903 update_rect
.left
, update_rect
.top
,
2904 update_rect
.right
, update_rect
.bottom
));
2906 EndPaint (hwnd
, &paintStruct
);
2909 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2914 /* If GetUpdateRect returns 0 (meaning there is no update
2915 region), assume the whole window needs to be repainted. */
2916 GetClientRect(hwnd
, &wmsg
.rect
);
2917 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2921 case WM_INPUTLANGCHANGE
:
2922 /* Inform lisp thread of keyboard layout changes. */
2923 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2925 /* Clear dead keys in the keyboard state; for simplicity only
2926 preserve modifier key states. */
2931 GetKeyboardState (keystate
);
2932 for (i
= 0; i
< 256; i
++)
2949 SetKeyboardState (keystate
);
2954 /* Synchronize hot keys with normal input. */
2955 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
2960 record_keyup (wParam
, lParam
);
2965 /* Ignore keystrokes we fake ourself; see below. */
2966 if (dpyinfo
->faked_key
== wParam
)
2968 dpyinfo
->faked_key
= 0;
2969 /* Make sure TranslateMessage sees them though (as long as
2970 they don't produce WM_CHAR messages). This ensures that
2971 indicator lights are toggled promptly on Windows 9x, for
2973 if (lispy_function_keys
[wParam
] != 0)
2975 windows_translate
= 1;
2981 /* Synchronize modifiers with current keystroke. */
2983 record_keydown (wParam
, lParam
);
2984 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
2986 windows_translate
= 0;
2991 if (NILP (Vw32_pass_lwindow_to_system
))
2993 /* Prevent system from acting on keyup (which opens the
2994 Start menu if no other key was pressed) by simulating a
2995 press of Space which we will ignore. */
2996 if (GetAsyncKeyState (wParam
) & 1)
2998 if (NUMBERP (Vw32_phantom_key_code
))
2999 key
= XUINT (Vw32_phantom_key_code
) & 255;
3002 dpyinfo
->faked_key
= key
;
3003 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
3006 if (!NILP (Vw32_lwindow_modifier
))
3010 if (NILP (Vw32_pass_rwindow_to_system
))
3012 if (GetAsyncKeyState (wParam
) & 1)
3014 if (NUMBERP (Vw32_phantom_key_code
))
3015 key
= XUINT (Vw32_phantom_key_code
) & 255;
3018 dpyinfo
->faked_key
= key
;
3019 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
3022 if (!NILP (Vw32_rwindow_modifier
))
3026 if (!NILP (Vw32_apps_modifier
))
3030 if (NILP (Vw32_pass_alt_to_system
))
3031 /* Prevent DefWindowProc from activating the menu bar if an
3032 Alt key is pressed and released by itself. */
3034 windows_translate
= 1;
3037 /* Decide whether to treat as modifier or function key. */
3038 if (NILP (Vw32_enable_caps_lock
))
3039 goto disable_lock_key
;
3040 windows_translate
= 1;
3043 /* Decide whether to treat as modifier or function key. */
3044 if (NILP (Vw32_enable_num_lock
))
3045 goto disable_lock_key
;
3046 windows_translate
= 1;
3049 /* Decide whether to treat as modifier or function key. */
3050 if (NILP (Vw32_scroll_lock_modifier
))
3051 goto disable_lock_key
;
3052 windows_translate
= 1;
3055 /* Ensure the appropriate lock key state (and indicator light)
3056 remains in the same state. We do this by faking another
3057 press of the relevant key. Apparently, this really is the
3058 only way to toggle the state of the indicator lights. */
3059 dpyinfo
->faked_key
= wParam
;
3060 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3061 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3062 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3063 KEYEVENTF_EXTENDEDKEY
| 0, 0);
3064 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3065 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3066 /* Ensure indicator lights are updated promptly on Windows 9x
3067 (TranslateMessage apparently does this), after forwarding
3069 post_character_message (hwnd
, msg
, wParam
, lParam
,
3070 w32_get_key_modifiers (wParam
, lParam
));
3071 windows_translate
= 1;
3075 case VK_PROCESSKEY
: /* Generated by IME. */
3076 windows_translate
= 1;
3079 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
3080 which is confusing for purposes of key binding; convert
3081 VK_CANCEL events into VK_PAUSE events. */
3085 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
3086 for purposes of key binding; convert these back into
3087 VK_NUMLOCK events, at least when we want to see NumLock key
3088 presses. (Note that there is never any possibility that
3089 VK_PAUSE with Ctrl really is C-Pause as per above.) */
3090 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
3091 wParam
= VK_NUMLOCK
;
3094 /* If not defined as a function key, change it to a WM_CHAR message. */
3095 if (lispy_function_keys
[wParam
] == 0)
3097 DWORD modifiers
= construct_console_modifiers ();
3099 if (!NILP (Vw32_recognize_altgr
)
3100 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
3102 /* Always let TranslateMessage handle AltGr key chords;
3103 for some reason, ToAscii doesn't always process AltGr
3104 chords correctly. */
3105 windows_translate
= 1;
3107 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
3109 /* Handle key chords including any modifiers other
3110 than shift directly, in order to preserve as much
3111 modifier information as possible. */
3112 if ('A' <= wParam
&& wParam
<= 'Z')
3114 /* Don't translate modified alphabetic keystrokes,
3115 so the user doesn't need to constantly switch
3116 layout to type control or meta keystrokes when
3117 the normal layout translates alphabetic
3118 characters to non-ascii characters. */
3119 if (!modifier_set (VK_SHIFT
))
3120 wParam
+= ('a' - 'A');
3125 /* Try to handle other keystrokes by determining the
3126 base character (ie. translating the base key plus
3130 KEY_EVENT_RECORD key
;
3132 key
.bKeyDown
= TRUE
;
3133 key
.wRepeatCount
= 1;
3134 key
.wVirtualKeyCode
= wParam
;
3135 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
3136 key
.uChar
.AsciiChar
= 0;
3137 key
.dwControlKeyState
= modifiers
;
3139 add
= w32_kbd_patch_key (&key
);
3140 /* 0 means an unrecognised keycode, negative means
3141 dead key. Ignore both. */
3144 /* Forward asciified character sequence. */
3145 post_character_message
3146 (hwnd
, WM_CHAR
, key
.uChar
.AsciiChar
, lParam
,
3147 w32_get_key_modifiers (wParam
, lParam
));
3148 w32_kbd_patch_key (&key
);
3155 /* Let TranslateMessage handle everything else. */
3156 windows_translate
= 1;
3162 if (windows_translate
)
3164 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
3166 windows_msg
.time
= GetMessageTime ();
3167 TranslateMessage (&windows_msg
);
3175 post_character_message (hwnd
, msg
, wParam
, lParam
,
3176 w32_get_key_modifiers (wParam
, lParam
));
3179 /* Simulate middle mouse button events when left and right buttons
3180 are used together, but only if user has two button mouse. */
3181 case WM_LBUTTONDOWN
:
3182 case WM_RBUTTONDOWN
:
3183 if (w32_num_mouse_buttons
> 2)
3184 goto handle_plain_button
;
3187 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
3188 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
3190 if (button_state
& this)
3193 if (button_state
== 0)
3196 button_state
|= this;
3198 if (button_state
& other
)
3200 if (mouse_button_timer
)
3202 KillTimer (hwnd
, mouse_button_timer
);
3203 mouse_button_timer
= 0;
3205 /* Generate middle mouse event instead. */
3206 msg
= WM_MBUTTONDOWN
;
3207 button_state
|= MMOUSE
;
3209 else if (button_state
& MMOUSE
)
3211 /* Ignore button event if we've already generated a
3212 middle mouse down event. This happens if the
3213 user releases and press one of the two buttons
3214 after we've faked a middle mouse event. */
3219 /* Flush out saved message. */
3220 post_msg (&saved_mouse_button_msg
);
3222 wmsg
.dwModifiers
= w32_get_modifiers ();
3223 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3224 signal_user_input ();
3226 /* Clear message buffer. */
3227 saved_mouse_button_msg
.msg
.hwnd
= 0;
3231 /* Hold onto message for now. */
3232 mouse_button_timer
=
3233 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
3234 w32_mouse_button_tolerance
, NULL
);
3235 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
3236 saved_mouse_button_msg
.msg
.message
= msg
;
3237 saved_mouse_button_msg
.msg
.wParam
= wParam
;
3238 saved_mouse_button_msg
.msg
.lParam
= lParam
;
3239 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
3240 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
3247 if (w32_num_mouse_buttons
> 2)
3248 goto handle_plain_button
;
3251 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
3252 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
3254 if ((button_state
& this) == 0)
3257 button_state
&= ~this;
3259 if (button_state
& MMOUSE
)
3261 /* Only generate event when second button is released. */
3262 if ((button_state
& other
) == 0)
3265 button_state
&= ~MMOUSE
;
3267 if (button_state
) abort ();
3274 /* Flush out saved message if necessary. */
3275 if (saved_mouse_button_msg
.msg
.hwnd
)
3277 post_msg (&saved_mouse_button_msg
);
3280 wmsg
.dwModifiers
= w32_get_modifiers ();
3281 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3282 signal_user_input ();
3284 /* Always clear message buffer and cancel timer. */
3285 saved_mouse_button_msg
.msg
.hwnd
= 0;
3286 KillTimer (hwnd
, mouse_button_timer
);
3287 mouse_button_timer
= 0;
3289 if (button_state
== 0)
3294 case WM_XBUTTONDOWN
:
3296 if (w32_pass_extra_mouse_buttons_to_system
)
3298 /* else fall through and process them. */
3299 case WM_MBUTTONDOWN
:
3301 handle_plain_button
:
3306 /* Ignore middle and extra buttons as long as the menu is active. */
3307 f
= x_window_to_frame (dpyinfo
, hwnd
);
3308 if (f
&& f
->output_data
.w32
->menubar_active
)
3311 if (parse_button (msg
, HIWORD (wParam
), &button
, &up
))
3313 if (up
) ReleaseCapture ();
3314 else SetCapture (hwnd
);
3315 button
= (button
== 0) ? LMOUSE
:
3316 ((button
== 1) ? MMOUSE
: RMOUSE
);
3318 button_state
&= ~button
;
3320 button_state
|= button
;
3324 wmsg
.dwModifiers
= w32_get_modifiers ();
3325 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3326 signal_user_input ();
3328 /* Need to return true for XBUTTON messages, false for others,
3329 to indicate that we processed the message. */
3330 return (msg
== WM_XBUTTONDOWN
|| msg
== WM_XBUTTONUP
);
3333 /* Ignore mouse movements as long as the menu is active. These
3334 movements are processed by the window manager anyway, and
3335 it's wrong to handle them as if they happened on the
3336 underlying frame. */
3337 f
= x_window_to_frame (dpyinfo
, hwnd
);
3338 if (f
&& f
->output_data
.w32
->menubar_active
)
3341 /* If the mouse has just moved into the frame, start tracking
3342 it, so we will be notified when it leaves the frame. Mouse
3343 tracking only works under W98 and NT4 and later. On earlier
3344 versions, there is no way of telling when the mouse leaves the
3345 frame, so we just have to put up with help-echo and mouse
3346 highlighting remaining while the frame is not active. */
3347 if (track_mouse_event_fn
&& !track_mouse_window
)
3349 TRACKMOUSEEVENT tme
;
3350 tme
.cbSize
= sizeof (tme
);
3351 tme
.dwFlags
= TME_LEAVE
;
3352 tme
.hwndTrack
= hwnd
;
3354 track_mouse_event_fn (&tme
);
3355 track_mouse_window
= hwnd
;
3358 if (w32_mouse_move_interval
<= 0
3359 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
3361 wmsg
.dwModifiers
= w32_get_modifiers ();
3362 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3366 /* Hang onto mouse move and scroll messages for a bit, to avoid
3367 sending such events to Emacs faster than it can process them.
3368 If we get more events before the timer from the first message
3369 expires, we just replace the first message. */
3371 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
3373 SetTimer (hwnd
, MOUSE_MOVE_ID
,
3374 w32_mouse_move_interval
, NULL
);
3376 /* Hold onto message for now. */
3377 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
3378 saved_mouse_move_msg
.msg
.message
= msg
;
3379 saved_mouse_move_msg
.msg
.wParam
= wParam
;
3380 saved_mouse_move_msg
.msg
.lParam
= lParam
;
3381 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
3382 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
3388 wmsg
.dwModifiers
= w32_get_modifiers ();
3389 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3390 signal_user_input ();
3394 if (w32_pass_multimedia_buttons_to_system
)
3396 /* Otherwise, pass to lisp, the same way we do with mousehwheel. */
3397 case WM_MOUSEHWHEEL
:
3398 wmsg
.dwModifiers
= w32_get_modifiers ();
3399 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3400 signal_user_input ();
3401 /* Non-zero must be returned when WM_MOUSEHWHEEL messages are
3402 handled, to prevent the system trying to handle it by faking
3403 scroll bar events. */
3407 /* Flush out saved messages if necessary. */
3408 if (wParam
== mouse_button_timer
)
3410 if (saved_mouse_button_msg
.msg
.hwnd
)
3412 post_msg (&saved_mouse_button_msg
);
3413 signal_user_input ();
3414 saved_mouse_button_msg
.msg
.hwnd
= 0;
3416 KillTimer (hwnd
, mouse_button_timer
);
3417 mouse_button_timer
= 0;
3419 else if (wParam
== mouse_move_timer
)
3421 if (saved_mouse_move_msg
.msg
.hwnd
)
3423 post_msg (&saved_mouse_move_msg
);
3424 saved_mouse_move_msg
.msg
.hwnd
= 0;
3426 KillTimer (hwnd
, mouse_move_timer
);
3427 mouse_move_timer
= 0;
3429 else if (wParam
== menu_free_timer
)
3431 KillTimer (hwnd
, menu_free_timer
);
3432 menu_free_timer
= 0;
3433 f
= x_window_to_frame (dpyinfo
, hwnd
);
3434 /* If a popup menu is active, don't wipe its strings. */
3436 && current_popup_menu
== NULL
)
3438 /* Free memory used by owner-drawn and help-echo strings. */
3439 w32_free_menu_strings (hwnd
);
3440 f
->output_data
.w32
->menubar_active
= 0;
3447 /* Windows doesn't send us focus messages when putting up and
3448 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
3449 The only indication we get that something happened is receiving
3450 this message afterwards. So this is a good time to reset our
3451 keyboard modifiers' state. */
3458 /* We must ensure menu bar is fully constructed and up to date
3459 before allowing user interaction with it. To achieve this
3460 we send this message to the lisp thread and wait for a
3461 reply (whose value is not actually needed) to indicate that
3462 the menu bar is now ready for use, so we can now return.
3464 To remain responsive in the meantime, we enter a nested message
3465 loop that can process all other messages.
3467 However, we skip all this if the message results from calling
3468 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
3469 thread a message because it is blocked on us at this point. We
3470 set menubar_active before calling TrackPopupMenu to indicate
3471 this (there is no possibility of confusion with real menubar
3474 f
= x_window_to_frame (dpyinfo
, hwnd
);
3476 && (f
->output_data
.w32
->menubar_active
3477 /* We can receive this message even in the absence of a
3478 menubar (ie. when the system menu is activated) - in this
3479 case we do NOT want to forward the message, otherwise it
3480 will cause the menubar to suddenly appear when the user
3481 had requested it to be turned off! */
3482 || f
->output_data
.w32
->menubar_widget
== NULL
))
3486 deferred_msg msg_buf
;
3488 /* Detect if message has already been deferred; in this case
3489 we cannot return any sensible value to ignore this. */
3490 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3495 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
3498 case WM_EXITMENULOOP
:
3499 f
= x_window_to_frame (dpyinfo
, hwnd
);
3501 /* If a menu is still active, check again after a short delay,
3502 since Windows often (always?) sends the WM_EXITMENULOOP
3503 before the corresponding WM_COMMAND message.
3504 Don't do this if a popup menu is active, since it is only
3505 menubar menus that require cleaning up in this way.
3507 if (f
&& menubar_in_use
&& current_popup_menu
== NULL
)
3508 menu_free_timer
= SetTimer (hwnd
, MENU_FREE_ID
, MENU_FREE_DELAY
, NULL
);
3512 /* Direct handling of help_echo in menus. Should be safe now
3513 that we generate the help_echo by placing a help event in the
3516 HMENU menu
= (HMENU
) lParam
;
3517 UINT menu_item
= (UINT
) LOWORD (wParam
);
3518 UINT flags
= (UINT
) HIWORD (wParam
);
3520 w32_menu_display_help (hwnd
, menu
, menu_item
, flags
);
3524 case WM_MEASUREITEM
:
3525 f
= x_window_to_frame (dpyinfo
, hwnd
);
3528 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
3530 if (pMis
->CtlType
== ODT_MENU
)
3532 /* Work out dimensions for popup menu titles. */
3533 char * title
= (char *) pMis
->itemData
;
3534 HDC hdc
= GetDC (hwnd
);
3535 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3536 LOGFONT menu_logfont
;
3540 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3541 menu_logfont
.lfWeight
= FW_BOLD
;
3542 menu_font
= CreateFontIndirect (&menu_logfont
);
3543 old_font
= SelectObject (hdc
, menu_font
);
3545 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
3548 if (unicode_append_menu
)
3549 GetTextExtentPoint32W (hdc
, (WCHAR
*) title
,
3550 wcslen ((WCHAR
*) title
),
3553 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
3555 pMis
->itemWidth
= size
.cx
;
3556 if (pMis
->itemHeight
< size
.cy
)
3557 pMis
->itemHeight
= size
.cy
;
3560 pMis
->itemWidth
= 0;
3562 SelectObject (hdc
, old_font
);
3563 DeleteObject (menu_font
);
3564 ReleaseDC (hwnd
, hdc
);
3571 f
= x_window_to_frame (dpyinfo
, hwnd
);
3574 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
3576 if (pDis
->CtlType
== ODT_MENU
)
3578 /* Draw popup menu title. */
3579 char * title
= (char *) pDis
->itemData
;
3582 HDC hdc
= pDis
->hDC
;
3583 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3584 LOGFONT menu_logfont
;
3587 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3588 menu_logfont
.lfWeight
= FW_BOLD
;
3589 menu_font
= CreateFontIndirect (&menu_logfont
);
3590 old_font
= SelectObject (hdc
, menu_font
);
3592 /* Always draw title as if not selected. */
3593 if (unicode_append_menu
)
3596 + GetSystemMetrics (SM_CXMENUCHECK
),
3598 ETO_OPAQUE
, &pDis
->rcItem
,
3600 wcslen ((WCHAR
*) title
), NULL
);
3604 + GetSystemMetrics (SM_CXMENUCHECK
),
3606 ETO_OPAQUE
, &pDis
->rcItem
,
3607 title
, strlen (title
), NULL
);
3609 SelectObject (hdc
, old_font
);
3610 DeleteObject (menu_font
);
3618 /* Still not right - can't distinguish between clicks in the
3619 client area of the frame from clicks forwarded from the scroll
3620 bars - may have to hook WM_NCHITTEST to remember the mouse
3621 position and then check if it is in the client area ourselves. */
3622 case WM_MOUSEACTIVATE
:
3623 /* Discard the mouse click that activates a frame, allowing the
3624 user to click anywhere without changing point (or worse!).
3625 Don't eat mouse clicks on scrollbars though!! */
3626 if (LOWORD (lParam
) == HTCLIENT
)
3627 return MA_ACTIVATEANDEAT
;
3632 /* No longer tracking mouse. */
3633 track_mouse_window
= NULL
;
3635 case WM_ACTIVATEAPP
:
3637 case WM_WINDOWPOSCHANGED
:
3639 /* Inform lisp thread that a frame might have just been obscured
3640 or exposed, so should recheck visibility of all frames. */
3641 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3645 dpyinfo
->faked_key
= 0;
3647 register_hot_keys (hwnd
);
3650 unregister_hot_keys (hwnd
);
3653 /* Relinquish the system caret. */
3654 if (w32_system_caret_hwnd
)
3656 w32_visible_system_caret_hwnd
= NULL
;
3657 w32_system_caret_hwnd
= NULL
;
3663 f
= x_window_to_frame (dpyinfo
, hwnd
);
3664 if (f
&& HIWORD (wParam
) == 0)
3666 if (menu_free_timer
)
3668 KillTimer (hwnd
, menu_free_timer
);
3669 menu_free_timer
= 0;
3675 wmsg
.dwModifiers
= w32_get_modifiers ();
3676 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3684 wmsg
.dwModifiers
= w32_get_modifiers ();
3685 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3688 case WM_WINDOWPOSCHANGING
:
3689 /* Don't restrict the sizing of tip frames. */
3690 if (hwnd
== tip_window
)
3694 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
3696 wp
.length
= sizeof (WINDOWPLACEMENT
);
3697 GetWindowPlacement (hwnd
, &wp
);
3699 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
3706 DWORD internal_border
;
3707 DWORD scrollbar_extra
;
3710 wp
.length
= sizeof(wp
);
3711 GetWindowRect (hwnd
, &wr
);
3715 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
3716 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
3717 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
3718 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
3722 memset (&rect
, 0, sizeof (rect
));
3723 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
3724 GetMenu (hwnd
) != NULL
);
3726 /* Force width and height of client area to be exact
3727 multiples of the character cell dimensions. */
3728 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
3729 - 2 * internal_border
- scrollbar_extra
)
3731 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
3732 - 2 * internal_border
)
3737 /* For right/bottom sizing we can just fix the sizes.
3738 However for top/left sizing we will need to fix the X
3739 and Y positions as well. */
3741 int cx_mintrack
= GetSystemMetrics (SM_CXMINTRACK
);
3742 int cy_mintrack
= GetSystemMetrics (SM_CYMINTRACK
);
3744 lppos
->cx
= max (lppos
->cx
- wdiff
, cx_mintrack
);
3745 lppos
->cy
= max (lppos
->cy
- hdiff
, cy_mintrack
);
3747 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
3748 && (lppos
->flags
& SWP_NOMOVE
) == 0)
3750 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
3757 lppos
->flags
|= SWP_NOMOVE
;
3768 case WM_GETMINMAXINFO
:
3769 /* Hack to allow resizing the Emacs frame above the screen size.
3770 Note that Windows 9x limits coordinates to 16-bits. */
3771 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.x
= 32767;
3772 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.y
= 32767;
3776 if (LOWORD (lParam
) == HTCLIENT
)
3781 case WM_EMACS_SETCURSOR
:
3783 Cursor cursor
= (Cursor
) wParam
;
3789 case WM_EMACS_CREATESCROLLBAR
:
3790 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
3791 (struct scroll_bar
*) lParam
);
3793 case WM_EMACS_SHOWWINDOW
:
3794 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
3796 case WM_EMACS_SETFOREGROUND
:
3798 HWND foreground_window
;
3799 DWORD foreground_thread
, retval
;
3801 /* On NT 5.0, and apparently Windows 98, it is necessary to
3802 attach to the thread that currently has focus in order to
3803 pull the focus away from it. */
3804 foreground_window
= GetForegroundWindow ();
3805 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
3806 if (!foreground_window
3807 || foreground_thread
== GetCurrentThreadId ()
3808 || !AttachThreadInput (GetCurrentThreadId (),
3809 foreground_thread
, TRUE
))
3810 foreground_thread
= 0;
3812 retval
= SetForegroundWindow ((HWND
) wParam
);
3814 /* Detach from the previous foreground thread. */
3815 if (foreground_thread
)
3816 AttachThreadInput (GetCurrentThreadId (),
3817 foreground_thread
, FALSE
);
3822 case WM_EMACS_SETWINDOWPOS
:
3824 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
3825 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
3826 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
3829 case WM_EMACS_DESTROYWINDOW
:
3830 DragAcceptFiles ((HWND
) wParam
, FALSE
);
3831 return DestroyWindow ((HWND
) wParam
);
3833 case WM_EMACS_HIDE_CARET
:
3834 return HideCaret (hwnd
);
3836 case WM_EMACS_SHOW_CARET
:
3837 return ShowCaret (hwnd
);
3839 case WM_EMACS_DESTROY_CARET
:
3840 w32_system_caret_hwnd
= NULL
;
3841 w32_visible_system_caret_hwnd
= NULL
;
3842 return DestroyCaret ();
3844 case WM_EMACS_TRACK_CARET
:
3845 /* If there is currently no system caret, create one. */
3846 if (w32_system_caret_hwnd
== NULL
)
3848 /* Use the default caret width, and avoid changing it
3849 unneccesarily, as it confuses screen reader software. */
3850 w32_system_caret_hwnd
= hwnd
;
3851 CreateCaret (hwnd
, NULL
, 0,
3852 w32_system_caret_height
);
3855 if (!SetCaretPos (w32_system_caret_x
, w32_system_caret_y
))
3857 /* Ensure visible caret gets turned on when requested. */
3858 else if (w32_use_visible_system_caret
3859 && w32_visible_system_caret_hwnd
!= hwnd
)
3861 w32_visible_system_caret_hwnd
= hwnd
;
3862 return ShowCaret (hwnd
);
3864 /* Ensure visible caret gets turned off when requested. */
3865 else if (!w32_use_visible_system_caret
3866 && w32_visible_system_caret_hwnd
)
3868 w32_visible_system_caret_hwnd
= NULL
;
3869 return HideCaret (hwnd
);
3874 case WM_EMACS_TRACKPOPUPMENU
:
3879 pos
= (POINT
*)lParam
;
3880 flags
= TPM_CENTERALIGN
;
3881 if (button_state
& LMOUSE
)
3882 flags
|= TPM_LEFTBUTTON
;
3883 else if (button_state
& RMOUSE
)
3884 flags
|= TPM_RIGHTBUTTON
;
3886 /* Remember we did a SetCapture on the initial mouse down event,
3887 so for safety, we make sure the capture is cancelled now. */
3891 /* Use menubar_active to indicate that WM_INITMENU is from
3892 TrackPopupMenu below, and should be ignored. */
3893 f
= x_window_to_frame (dpyinfo
, hwnd
);
3895 f
->output_data
.w32
->menubar_active
= 1;
3897 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
3901 /* Eat any mouse messages during popupmenu */
3902 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
3904 /* Get the menu selection, if any */
3905 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
3907 retval
= LOWORD (amsg
.wParam
);
3923 /* Check for messages registered at runtime. */
3924 if (msg
== msh_mousewheel
)
3926 wmsg
.dwModifiers
= w32_get_modifiers ();
3927 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3928 signal_user_input ();
3933 return DefWindowProc (hwnd
, msg
, wParam
, lParam
);
3937 /* The most common default return code for handled messages is 0. */
3942 my_create_window (f
)
3947 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
3949 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
3953 /* Create a tooltip window. Unlike my_create_window, we do not do this
3954 indirectly via the Window thread, as we do not need to process Window
3955 messages for the tooltip. Creating tooltips indirectly also creates
3956 deadlocks when tooltips are created for menu items. */
3958 my_create_tip_window (f
)
3963 rect
.left
= rect
.top
= 0;
3964 rect
.right
= FRAME_PIXEL_WIDTH (f
);
3965 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
3967 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
3968 FRAME_EXTERNAL_MENU_BAR (f
));
3970 tip_window
= FRAME_W32_WINDOW (f
)
3971 = CreateWindow (EMACS_CLASS
,
3973 f
->output_data
.w32
->dwStyle
,
3976 rect
.right
- rect
.left
,
3977 rect
.bottom
- rect
.top
,
3978 FRAME_W32_WINDOW (SELECTED_FRAME ()), /* owner */
3985 SetWindowLong (tip_window
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
3986 SetWindowLong (tip_window
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
3987 SetWindowLong (tip_window
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
3988 SetWindowLong (tip_window
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
3990 /* Tip frames have no scrollbars. */
3991 SetWindowLong (tip_window
, WND_SCROLLBAR_INDEX
, 0);
3993 /* Do this to discard the default setting specified by our parent. */
3994 ShowWindow (tip_window
, SW_HIDE
);
3999 /* Create and set up the w32 window for frame F. */
4002 w32_window (f
, window_prompting
, minibuffer_only
)
4004 long window_prompting
;
4005 int minibuffer_only
;
4009 /* Use the resource name as the top-level window name
4010 for looking up resources. Make a non-Lisp copy
4011 for the window manager, so GC relocation won't bother it.
4013 Elsewhere we specify the window name for the window manager. */
4016 char *str
= (char *) SDATA (Vx_resource_name
);
4017 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
4018 strcpy (f
->namebuf
, str
);
4021 my_create_window (f
);
4023 validate_x_resource_name ();
4025 /* x_set_name normally ignores requests to set the name if the
4026 requested name is the same as the current name. This is the one
4027 place where that assumption isn't correct; f->name is set, but
4028 the server hasn't been told. */
4031 int explicit = f
->explicit_name
;
4033 f
->explicit_name
= 0;
4036 x_set_name (f
, name
, explicit);
4041 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
4042 initialize_frame_menubar (f
);
4044 if (FRAME_W32_WINDOW (f
) == 0)
4045 error ("Unable to create window");
4048 /* Handle the icon stuff for this window. Perhaps later we might
4049 want an x_set_icon_position which can be called interactively as
4057 Lisp_Object icon_x
, icon_y
;
4059 /* Set the position of the icon. Note that Windows 95 groups all
4060 icons in the tray. */
4061 icon_x
= w32_get_arg (parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
4062 icon_y
= w32_get_arg (parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
4063 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
4065 CHECK_NUMBER (icon_x
);
4066 CHECK_NUMBER (icon_y
);
4068 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
4069 error ("Both left and top icon corners of icon must be specified");
4073 if (! EQ (icon_x
, Qunbound
))
4074 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
4077 /* Start up iconic or window? */
4078 x_wm_set_window_state
4079 (f
, (EQ (w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
4083 x_text_icon (f
, (char *) SDATA ((!NILP (f
->icon_name
)
4096 XGCValues gc_values
;
4100 /* Create the GC's of this frame.
4101 Note that many default values are used. */
4104 gc_values
.font
= FRAME_FONT (f
);
4106 /* Cursor has cursor-color background, background-color foreground. */
4107 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
4108 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
4109 f
->output_data
.w32
->cursor_gc
4110 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
4111 (GCFont
| GCForeground
| GCBackground
),
4115 f
->output_data
.w32
->white_relief
.gc
= 0;
4116 f
->output_data
.w32
->black_relief
.gc
= 0;
4122 /* Handler for signals raised during x_create_frame and
4123 x_create_top_frame. FRAME is the frame which is partially
4127 unwind_create_frame (frame
)
4130 struct frame
*f
= XFRAME (frame
);
4132 /* If frame is ``official'', nothing to do. */
4133 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
4136 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4139 x_free_frame_resources (f
);
4141 /* Check that reference counts are indeed correct. */
4142 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
4143 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
4151 #ifdef USE_FONT_BACKEND
4153 x_default_font_parameter (f
, parms
)
4157 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4158 Lisp_Object font
= x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font",
4161 if (!STRINGP (font
))
4164 static char *names
[]
4165 = { "Courier New-10",
4166 "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1",
4167 "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1",
4171 for (i
= 0; names
[i
]; i
++)
4173 font
= font_open_by_name (f
, names
[i
]);
4178 error ("No suitable font was found");
4180 x_default_parameter (f
, parms
, Qfont
, font
, "font", "Font", RES_TYPE_STRING
);
4184 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
4186 doc
: /* Make a new window, which is called a \"frame\" in Emacs terms.
4187 Returns an Emacs frame object.
4188 PARAMETERS is an alist of frame parameters.
4189 If the parameters specify that the frame should not have a minibuffer,
4190 and do not specify a specific minibuffer window to use,
4191 then `default-minibuffer-frame' must be a frame whose minibuffer can
4192 be shared by the new frame.
4194 This function is an internal primitive--use `make-frame' instead. */)
4196 Lisp_Object parameters
;
4199 Lisp_Object frame
, tem
;
4201 int minibuffer_only
= 0;
4202 long window_prompting
= 0;
4204 int count
= SPECPDL_INDEX ();
4205 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4206 Lisp_Object display
;
4207 struct w32_display_info
*dpyinfo
= NULL
;
4213 /* Use this general default value to start with
4214 until we know if this frame has a specified name. */
4215 Vx_resource_name
= Vinvocation_name
;
4217 display
= w32_get_arg (parameters
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
4218 if (EQ (display
, Qunbound
))
4220 dpyinfo
= check_x_display_info (display
);
4222 kb
= dpyinfo
->terminal
->kboard
;
4224 kb
= &the_only_kboard
;
4227 name
= w32_get_arg (parameters
, Qname
, "name", "Name", RES_TYPE_STRING
);
4229 && ! EQ (name
, Qunbound
)
4231 error ("Invalid frame name--not a string or nil");
4234 Vx_resource_name
= name
;
4236 /* See if parent window is specified. */
4237 parent
= w32_get_arg (parameters
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
4238 if (EQ (parent
, Qunbound
))
4240 if (! NILP (parent
))
4241 CHECK_NUMBER (parent
);
4243 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
4244 /* No need to protect DISPLAY because that's not used after passing
4245 it to make_frame_without_minibuffer. */
4247 GCPRO4 (parameters
, parent
, name
, frame
);
4248 tem
= w32_get_arg (parameters
, Qminibuffer
, "minibuffer", "Minibuffer",
4250 if (EQ (tem
, Qnone
) || NILP (tem
))
4251 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
4252 else if (EQ (tem
, Qonly
))
4254 f
= make_minibuffer_frame ();
4255 minibuffer_only
= 1;
4257 else if (WINDOWP (tem
))
4258 f
= make_frame_without_minibuffer (tem
, kb
, display
);
4262 XSETFRAME (frame
, f
);
4264 /* Note that Windows does support scroll bars. */
4265 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
4267 /* By default, make scrollbars the system standard width. */
4268 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
4270 f
->terminal
= dpyinfo
->terminal
;
4271 f
->terminal
->reference_count
++;
4273 f
->output_method
= output_w32
;
4274 f
->output_data
.w32
=
4275 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
4276 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
4277 FRAME_FONTSET (f
) = -1;
4278 record_unwind_protect (unwind_create_frame
, frame
);
4281 = w32_get_arg (parameters
, Qicon_name
, "iconName", "Title", RES_TYPE_STRING
);
4282 if (! STRINGP (f
->icon_name
))
4283 f
->icon_name
= Qnil
;
4285 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
4287 FRAME_KBOARD (f
) = kb
;
4290 /* Specify the parent under which to make this window. */
4294 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
4295 f
->output_data
.w32
->explicit_parent
= 1;
4299 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4300 f
->output_data
.w32
->explicit_parent
= 0;
4303 /* Set the name; the functions to which we pass f expect the name to
4305 if (EQ (name
, Qunbound
) || NILP (name
))
4307 f
->name
= build_string (dpyinfo
->w32_id_name
);
4308 f
->explicit_name
= 0;
4313 f
->explicit_name
= 1;
4314 /* use the frame's title when getting resources for this frame. */
4315 specbind (Qx_resource_name
, name
);
4318 f
->resx
= dpyinfo
->resx
;
4319 f
->resy
= dpyinfo
->resy
;
4321 #ifdef USE_FONT_BACKEND
4322 if (enable_font_backend
)
4324 /* Perhaps, we must allow frame parameter, say `font-backend',
4325 to specify which font backends to use. */
4326 register_font_driver (&w32font_driver
, f
);
4328 x_default_parameter (f
, parameters
, Qfont_backend
, Qnil
,
4329 "fontBackend", "FontBackend", RES_TYPE_STRING
);
4331 #endif /* USE_FONT_BACKEND */
4333 /* Extract the window parameters from the supplied values
4334 that are needed to determine window geometry. */
4335 #ifdef USE_FONT_BACKEND
4336 if (enable_font_backend
)
4337 x_default_font_parameter (f
, parameters
);
4343 font
= w32_get_arg (parameters
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4346 /* First, try whatever font the caller has specified. */
4349 tem
= Fquery_fontset (font
, Qnil
);
4351 font
= x_new_fontset (f
, tem
);
4353 font
= x_new_font (f
, SDATA (font
));
4355 /* Try out a font which we hope has bold and italic variations. */
4356 if (!STRINGP (font
))
4357 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
4358 if (! STRINGP (font
))
4359 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
4360 /* If those didn't work, look for something which will at least work. */
4361 if (! STRINGP (font
))
4362 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
4364 if (! STRINGP (font
))
4365 font
= build_string ("Fixedsys");
4367 x_default_parameter (f
, parameters
, Qfont
, font
,
4368 "font", "Font", RES_TYPE_STRING
);
4371 x_default_parameter (f
, parameters
, Qborder_width
, make_number (2),
4372 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4373 /* This defaults to 2 in order to match xterm. We recognize either
4374 internalBorderWidth or internalBorder (which is what xterm calls
4376 if (NILP (Fassq (Qinternal_border_width
, parameters
)))
4380 value
= w32_get_arg (parameters
, Qinternal_border_width
,
4381 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
4382 if (! EQ (value
, Qunbound
))
4383 parameters
= Fcons (Fcons (Qinternal_border_width
, value
),
4386 /* Default internalBorderWidth to 0 on Windows to match other programs. */
4387 x_default_parameter (f
, parameters
, Qinternal_border_width
, make_number (0),
4388 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
4389 x_default_parameter (f
, parameters
, Qvertical_scroll_bars
, Qright
,
4390 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
4392 /* Also do the stuff which must be set before the window exists. */
4393 x_default_parameter (f
, parameters
, Qforeground_color
, build_string ("black"),
4394 "foreground", "Foreground", RES_TYPE_STRING
);
4395 x_default_parameter (f
, parameters
, Qbackground_color
, build_string ("white"),
4396 "background", "Background", RES_TYPE_STRING
);
4397 x_default_parameter (f
, parameters
, Qmouse_color
, build_string ("black"),
4398 "pointerColor", "Foreground", RES_TYPE_STRING
);
4399 x_default_parameter (f
, parameters
, Qcursor_color
, build_string ("black"),
4400 "cursorColor", "Foreground", RES_TYPE_STRING
);
4401 x_default_parameter (f
, parameters
, Qborder_color
, build_string ("black"),
4402 "borderColor", "BorderColor", RES_TYPE_STRING
);
4403 x_default_parameter (f
, parameters
, Qscreen_gamma
, Qnil
,
4404 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
4405 x_default_parameter (f
, parameters
, Qline_spacing
, Qnil
,
4406 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
4407 x_default_parameter (f
, parameters
, Qleft_fringe
, Qnil
,
4408 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
4409 x_default_parameter (f
, parameters
, Qright_fringe
, Qnil
,
4410 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
4413 /* Init faces before x_default_parameter is called for scroll-bar
4414 parameters because that function calls x_set_scroll_bar_width,
4415 which calls change_frame_size, which calls Fset_window_buffer,
4416 which runs hooks, which call Fvertical_motion. At the end, we
4417 end up in init_iterator with a null face cache, which should not
4419 init_frame_faces (f
);
4421 x_default_parameter (f
, parameters
, Qmenu_bar_lines
, make_number (1),
4422 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
4423 x_default_parameter (f
, parameters
, Qtool_bar_lines
, make_number (1),
4424 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
4426 x_default_parameter (f
, parameters
, Qbuffer_predicate
, Qnil
,
4427 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
4428 x_default_parameter (f
, parameters
, Qtitle
, Qnil
,
4429 "title", "Title", RES_TYPE_STRING
);
4430 x_default_parameter (f
, parameters
, Qfullscreen
, Qnil
,
4431 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
4433 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
4434 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4436 f
->output_data
.w32
->text_cursor
= w32_load_cursor (IDC_IBEAM
);
4437 f
->output_data
.w32
->nontext_cursor
= w32_load_cursor (IDC_ARROW
);
4438 f
->output_data
.w32
->modeline_cursor
= w32_load_cursor (IDC_ARROW
);
4439 f
->output_data
.w32
->hand_cursor
= w32_load_cursor (IDC_HAND
);
4440 f
->output_data
.w32
->hourglass_cursor
= w32_load_cursor (IDC_WAIT
);
4441 f
->output_data
.w32
->horizontal_drag_cursor
= w32_load_cursor (IDC_SIZEWE
);
4443 window_prompting
= x_figure_window_size (f
, parameters
, 1);
4445 tem
= w32_get_arg (parameters
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
4446 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
4448 w32_window (f
, window_prompting
, minibuffer_only
);
4449 x_icon (f
, parameters
);
4453 /* Now consider the frame official. */
4454 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
4455 Vframe_list
= Fcons (frame
, Vframe_list
);
4457 /* We need to do this after creating the window, so that the
4458 icon-creation functions can say whose icon they're describing. */
4459 x_default_parameter (f
, parameters
, Qicon_type
, Qnil
,
4460 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
4462 x_default_parameter (f
, parameters
, Qauto_raise
, Qnil
,
4463 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4464 x_default_parameter (f
, parameters
, Qauto_lower
, Qnil
,
4465 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4466 x_default_parameter (f
, parameters
, Qcursor_type
, Qbox
,
4467 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4468 x_default_parameter (f
, parameters
, Qscroll_bar_width
, Qnil
,
4469 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
4471 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4472 Change will not be effected unless different from the current
4474 width
= FRAME_COLS (f
);
4475 height
= FRAME_LINES (f
);
4477 FRAME_LINES (f
) = 0;
4478 SET_FRAME_COLS (f
, 0);
4479 change_frame_size (f
, height
, width
, 1, 0, 0);
4481 /* Tell the server what size and position, etc, we want, and how
4482 badly we want them. This should be done after we have the menu
4483 bar so that its size can be taken into account. */
4485 x_wm_set_size_hint (f
, window_prompting
, 0);
4488 /* Make the window appear on the frame and enable display, unless
4489 the caller says not to. However, with explicit parent, Emacs
4490 cannot control visibility, so don't try. */
4491 if (! f
->output_data
.w32
->explicit_parent
)
4493 Lisp_Object visibility
;
4495 visibility
= w32_get_arg (parameters
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
4496 if (EQ (visibility
, Qunbound
))
4499 if (EQ (visibility
, Qicon
))
4500 x_iconify_frame (f
);
4501 else if (! NILP (visibility
))
4502 x_make_frame_visible (f
);
4504 /* Must have been Qnil. */
4508 /* Initialize `default-minibuffer-frame' in case this is the first
4509 frame on this terminal. */
4510 if (FRAME_HAS_MINIBUF_P (f
)
4511 && (!FRAMEP (kb
->Vdefault_minibuffer_frame
)
4512 || !FRAME_LIVE_P (XFRAME (kb
->Vdefault_minibuffer_frame
))))
4513 kb
->Vdefault_minibuffer_frame
= frame
;
4515 /* All remaining specified parameters, which have not been "used"
4516 by x_get_arg and friends, now go in the misc. alist of the frame. */
4517 for (tem
= parameters
; CONSP (tem
); tem
= XCDR (tem
))
4518 if (CONSP (XCAR (tem
)) && !NILP (XCAR (XCAR (tem
))))
4519 f
->param_alist
= Fcons (XCAR (tem
), f
->param_alist
);
4523 /* Make sure windows on this frame appear in calls to next-window
4524 and similar functions. */
4525 Vwindow_list
= Qnil
;
4527 return unbind_to (count
, frame
);
4530 /* FRAME is used only to get a handle on the X display. We don't pass the
4531 display info directly because we're called from frame.c, which doesn't
4532 know about that structure. */
4534 x_get_focus_frame (frame
)
4535 struct frame
*frame
;
4537 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
4539 if (! dpyinfo
->w32_focus_frame
)
4542 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
4546 DEFUN ("x-focus-frame", Fx_focus_frame
, Sx_focus_frame
, 1, 1, 0,
4547 doc
: /* Give FRAME input focus, raising to foreground if necessary. */)
4551 x_focus_on_frame (check_x_frame (frame
));
4556 /* Return the charset portion of a font name. */
4557 char * xlfd_charset_of_font (char * fontname
)
4559 char *charset
, *encoding
;
4561 encoding
= strrchr(fontname
, '-');
4562 if (!encoding
|| encoding
== fontname
)
4565 for (charset
= encoding
- 1; charset
>= fontname
; charset
--)
4566 if (*charset
== '-')
4569 if (charset
== fontname
|| strcmp(charset
, "-*-*") == 0)
4575 struct font_info
*w32_load_bdf_font (struct frame
*f
, char *fontname
,
4576 int size
, char* filename
);
4577 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
);
4578 static BOOL
w32_to_x_font (LOGFONT
* lplf
, char * lpxstr
, int len
,
4580 static BOOL
x_to_w32_font (char *lpxstr
, LOGFONT
*lplogfont
);
4582 static struct font_info
*
4583 w32_load_system_font (f
,fontname
,size
)
4588 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4589 Lisp_Object font_names
;
4591 /* Get a list of all the fonts that match this name. Once we
4592 have a list of matching fonts, we compare them against the fonts
4593 we already have loaded by comparing names. */
4594 font_names
= w32_list_fonts (f
, build_string (fontname
), size
, 100);
4596 if (!NILP (font_names
))
4601 /* First check if any are already loaded, as that is cheaper
4602 than loading another one. */
4603 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
4604 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
4605 if (dpyinfo
->font_table
[i
].name
4606 && (!strcmp (dpyinfo
->font_table
[i
].name
,
4607 SDATA (XCAR (tail
)))
4608 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
4609 SDATA (XCAR (tail
)))))
4610 return (dpyinfo
->font_table
+ i
);
4612 fontname
= (char *) SDATA (XCAR (font_names
));
4614 else if (w32_strict_fontnames
)
4616 /* If EnumFontFamiliesEx was available, we got a full list of
4617 fonts back so stop now to avoid the possibility of loading a
4618 random font. If we had to fall back to EnumFontFamilies, the
4619 list is incomplete, so continue whether the font we want was
4621 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
4622 FARPROC enum_font_families_ex
4623 = GetProcAddress (gdi32
, "EnumFontFamiliesExA");
4624 if (enum_font_families_ex
)
4628 /* Load the font and add it to the table. */
4630 char *full_name
, *encoding
, *charset
;
4632 struct font_info
*fontp
;
4638 if (!fontname
|| !x_to_w32_font (fontname
, &lf
))
4641 if (!*lf
.lfFaceName
)
4642 /* If no name was specified for the font, we get a random font
4643 from CreateFontIndirect - this is not particularly
4644 desirable, especially since CreateFontIndirect does not
4645 fill out the missing name in lf, so we never know what we
4649 lf
.lfQuality
= DEFAULT_QUALITY
;
4651 font
= (XFontStruct
*) xmalloc (sizeof (XFontStruct
));
4652 bzero (font
, sizeof (*font
));
4654 /* Set bdf to NULL to indicate that this is a Windows font. */
4659 font
->hfont
= CreateFontIndirect (&lf
);
4661 if (font
->hfont
== NULL
)
4670 codepage
= w32_codepage_for_font (fontname
);
4672 hdc
= GetDC (dpyinfo
->root_window
);
4673 oldobj
= SelectObject (hdc
, font
->hfont
);
4675 ok
= GetTextMetrics (hdc
, &font
->tm
);
4676 if (codepage
== CP_UNICODE
)
4677 font
->double_byte_p
= 1;
4680 /* Unfortunately, some fonts (eg. MingLiU, a big5 ttf font)
4681 don't report themselves as double byte fonts, when
4682 patently they are. So instead of trusting
4683 GetFontLanguageInfo, we check the properties of the
4684 codepage directly, since that is ultimately what we are
4685 working from anyway. */
4686 /* font->double_byte_p = GetFontLanguageInfo(hdc) & GCP_DBCS; */
4688 GetCPInfo (codepage
, &cpi
);
4689 font
->double_byte_p
= cpi
.MaxCharSize
> 1;
4692 SelectObject (hdc
, oldobj
);
4693 ReleaseDC (dpyinfo
->root_window
, hdc
);
4694 /* Fill out details in lf according to the font that was
4696 lf
.lfHeight
= font
->tm
.tmInternalLeading
- font
->tm
.tmHeight
;
4697 lf
.lfWidth
= font
->tm
.tmMaxCharWidth
;
4698 lf
.lfWeight
= font
->tm
.tmWeight
;
4699 lf
.lfItalic
= font
->tm
.tmItalic
;
4700 lf
.lfCharSet
= font
->tm
.tmCharSet
;
4701 lf
.lfPitchAndFamily
= ((font
->tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
)
4702 ? VARIABLE_PITCH
: FIXED_PITCH
);
4703 lf
.lfOutPrecision
= ((font
->tm
.tmPitchAndFamily
& TMPF_VECTOR
)
4704 ? OUT_STROKE_PRECIS
: OUT_STRING_PRECIS
);
4706 w32_cache_char_metrics (font
);
4713 w32_unload_font (dpyinfo
, font
);
4717 /* Find a free slot in the font table. */
4718 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
4719 if (dpyinfo
->font_table
[i
].name
== NULL
)
4722 /* If no free slot found, maybe enlarge the font table. */
4723 if (i
== dpyinfo
->n_fonts
4724 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
4727 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
4728 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
4730 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
4733 fontp
= dpyinfo
->font_table
+ i
;
4734 if (i
== dpyinfo
->n_fonts
)
4737 /* Now fill in the slots of *FONTP. */
4739 bzero (fontp
, sizeof (*fontp
));
4741 fontp
->font_idx
= i
;
4742 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
4743 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
4745 if ((lf
.lfPitchAndFamily
& 0x03) == FIXED_PITCH
)
4747 /* Fixed width font. */
4748 fontp
->average_width
= fontp
->space_width
= FONT_AVG_WIDTH (font
);
4754 pcm
= w32_per_char_metric (font
, &space
, ANSI_FONT
);
4756 fontp
->space_width
= pcm
->width
;
4758 fontp
->space_width
= FONT_AVG_WIDTH (font
);
4760 fontp
->average_width
= font
->tm
.tmAveCharWidth
;
4763 fontp
->charset
= -1;
4764 charset
= xlfd_charset_of_font (fontname
);
4766 /* Cache the W32 codepage for a font. This makes w32_encode_char
4767 (called for every glyph during redisplay) much faster. */
4768 fontp
->codepage
= codepage
;
4770 /* Work out the font's full name. */
4771 full_name
= (char *)xmalloc (100);
4772 if (full_name
&& w32_to_x_font (&lf
, full_name
, 100, charset
))
4773 fontp
->full_name
= full_name
;
4776 /* If all else fails - just use the name we used to load it. */
4778 fontp
->full_name
= fontp
->name
;
4781 fontp
->size
= FONT_WIDTH (font
);
4782 fontp
->height
= FONT_HEIGHT (font
);
4784 /* The slot `encoding' specifies how to map a character
4785 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
4786 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
4787 (0:0x20..0x7F, 1:0xA0..0xFF,
4788 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
4789 2:0xA020..0xFF7F). For the moment, we don't know which charset
4790 uses this font. So, we set information in fontp->encoding_type
4791 which is never used by any charset. If mapping can't be
4792 decided, set FONT_ENCODING_NOT_DECIDED. */
4794 /* SJIS fonts need to be set to type 4, all others seem to work as
4795 type FONT_ENCODING_NOT_DECIDED. */
4796 encoding
= strrchr (fontp
->name
, '-');
4797 if (encoding
&& strnicmp (encoding
+1, "sjis", 4) == 0)
4798 fontp
->encoding_type
= 4;
4800 fontp
->encoding_type
= FONT_ENCODING_NOT_DECIDED
;
4802 /* The following three values are set to 0 under W32, which is
4803 what they get set to if XGetFontProperty fails under X. */
4804 fontp
->baseline_offset
= 0;
4805 fontp
->relative_compose
= 0;
4806 fontp
->default_ascent
= 0;
4808 /* Set global flag fonts_changed_p to non-zero if the font loaded
4809 has a character with a smaller width than any other character
4810 before, or if the font loaded has a smaller height than any
4811 other font loaded before. If this happens, it will make a
4812 glyph matrix reallocation necessary. */
4813 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
4819 /* Load font named FONTNAME of size SIZE for frame F, and return a
4820 pointer to the structure font_info while allocating it dynamically.
4821 If loading fails, return NULL. */
4823 w32_load_font (f
,fontname
,size
)
4828 Lisp_Object bdf_fonts
;
4829 struct font_info
*retval
= NULL
;
4830 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4832 bdf_fonts
= w32_list_bdf_fonts (build_string (fontname
), 1);
4834 while (!retval
&& CONSP (bdf_fonts
))
4836 char *bdf_name
, *bdf_file
;
4837 Lisp_Object bdf_pair
;
4840 bdf_name
= SDATA (XCAR (bdf_fonts
));
4841 bdf_pair
= Fassoc (XCAR (bdf_fonts
), Vw32_bdf_filename_alist
);
4842 bdf_file
= SDATA (XCDR (bdf_pair
));
4844 // If the font is already loaded, do not load it again.
4845 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
4847 if ((dpyinfo
->font_table
[i
].name
4848 && !strcmp (dpyinfo
->font_table
[i
].name
, bdf_name
))
4849 || (dpyinfo
->font_table
[i
].full_name
4850 && !strcmp (dpyinfo
->font_table
[i
].full_name
, bdf_name
)))
4851 return dpyinfo
->font_table
+ i
;
4854 retval
= w32_load_bdf_font (f
, bdf_name
, size
, bdf_file
);
4856 bdf_fonts
= XCDR (bdf_fonts
);
4862 return w32_load_system_font(f
, fontname
, size
);
4867 w32_unload_font (dpyinfo
, font
)
4868 struct w32_display_info
*dpyinfo
;
4873 if (font
->per_char
) xfree (font
->per_char
);
4874 if (font
->bdf
) w32_free_bdf_font (font
->bdf
);
4876 if (font
->hfont
) DeleteObject(font
->hfont
);
4881 /* The font conversion stuff between x and w32 */
4883 /* X font string is as follows (from faces.el)
4887 * (weight "\\(bold\\|demibold\\|medium\\)") ; 1
4888 * (weight\? "\\([^-]*\\)") ; 1
4889 * (slant "\\([ior]\\)") ; 2
4890 * (slant\? "\\([^-]?\\)") ; 2
4891 * (swidth "\\([^-]*\\)") ; 3
4892 * (adstyle "[^-]*") ; 4
4893 * (pixelsize "[0-9]+")
4894 * (pointsize "[0-9][0-9]+")
4895 * (resx "[0-9][0-9]+")
4896 * (resy "[0-9][0-9]+")
4897 * (spacing "[cmp?*]")
4898 * (avgwidth "[0-9]+")
4899 * (registry "[^-]+")
4900 * (encoding "[^-]+")
4905 x_to_w32_weight (lpw
)
4908 if (!lpw
) return (FW_DONTCARE
);
4910 if (stricmp (lpw
,"heavy") == 0) return FW_HEAVY
;
4911 else if (stricmp (lpw
,"extrabold") == 0) return FW_EXTRABOLD
;
4912 else if (stricmp (lpw
,"bold") == 0) return FW_BOLD
;
4913 else if (stricmp (lpw
,"demibold") == 0) return FW_SEMIBOLD
;
4914 else if (stricmp (lpw
,"semibold") == 0) return FW_SEMIBOLD
;
4915 else if (stricmp (lpw
,"medium") == 0) return FW_MEDIUM
;
4916 else if (stricmp (lpw
,"normal") == 0) return FW_NORMAL
;
4917 else if (stricmp (lpw
,"light") == 0) return FW_LIGHT
;
4918 else if (stricmp (lpw
,"extralight") == 0) return FW_EXTRALIGHT
;
4919 else if (stricmp (lpw
,"thin") == 0) return FW_THIN
;
4926 w32_to_x_weight (fnweight
)
4929 if (fnweight
>= FW_HEAVY
) return "heavy";
4930 if (fnweight
>= FW_EXTRABOLD
) return "extrabold";
4931 if (fnweight
>= FW_BOLD
) return "bold";
4932 if (fnweight
>= FW_SEMIBOLD
) return "demibold";
4933 if (fnweight
>= FW_MEDIUM
) return "medium";
4934 if (fnweight
>= FW_NORMAL
) return "normal";
4935 if (fnweight
>= FW_LIGHT
) return "light";
4936 if (fnweight
>= FW_EXTRALIGHT
) return "extralight";
4937 if (fnweight
>= FW_THIN
) return "thin";
4943 x_to_w32_charset (lpcs
)
4946 Lisp_Object this_entry
, w32_charset
;
4948 int len
= strlen (lpcs
);
4950 /* Support "*-#nnn" format for unknown charsets. */
4951 if (strncmp (lpcs
, "*-#", 3) == 0)
4952 return atoi (lpcs
+ 3);
4954 /* All Windows fonts qualify as unicode. */
4955 if (!strncmp (lpcs
, "iso10646", 8))
4956 return DEFAULT_CHARSET
;
4958 /* Handle wildcards by ignoring them; eg. treat "big5*-*" as "big5". */
4959 charset
= alloca (len
+ 1);
4960 strcpy (charset
, lpcs
);
4961 lpcs
= strchr (charset
, '*');
4965 /* Look through w32-charset-info-alist for the character set.
4966 Format of each entry is
4967 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
4969 this_entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
4971 if (NILP(this_entry
))
4973 /* At startup, we want iso8859-1 fonts to come up properly. */
4974 if (stricmp(charset
, "iso8859-1") == 0)
4975 return ANSI_CHARSET
;
4977 return DEFAULT_CHARSET
;
4980 w32_charset
= Fcar (Fcdr (this_entry
));
4982 /* Translate Lisp symbol to number. */
4983 if (EQ (w32_charset
, Qw32_charset_ansi
))
4984 return ANSI_CHARSET
;
4985 if (EQ (w32_charset
, Qw32_charset_symbol
))
4986 return SYMBOL_CHARSET
;
4987 if (EQ (w32_charset
, Qw32_charset_shiftjis
))
4988 return SHIFTJIS_CHARSET
;
4989 if (EQ (w32_charset
, Qw32_charset_hangeul
))
4990 return HANGEUL_CHARSET
;
4991 if (EQ (w32_charset
, Qw32_charset_chinesebig5
))
4992 return CHINESEBIG5_CHARSET
;
4993 if (EQ (w32_charset
, Qw32_charset_gb2312
))
4994 return GB2312_CHARSET
;
4995 if (EQ (w32_charset
, Qw32_charset_oem
))
4997 #ifdef JOHAB_CHARSET
4998 if (EQ (w32_charset
, Qw32_charset_johab
))
4999 return JOHAB_CHARSET
;
5000 if (EQ (w32_charset
, Qw32_charset_easteurope
))
5001 return EASTEUROPE_CHARSET
;
5002 if (EQ (w32_charset
, Qw32_charset_turkish
))
5003 return TURKISH_CHARSET
;
5004 if (EQ (w32_charset
, Qw32_charset_baltic
))
5005 return BALTIC_CHARSET
;
5006 if (EQ (w32_charset
, Qw32_charset_russian
))
5007 return RUSSIAN_CHARSET
;
5008 if (EQ (w32_charset
, Qw32_charset_arabic
))
5009 return ARABIC_CHARSET
;
5010 if (EQ (w32_charset
, Qw32_charset_greek
))
5011 return GREEK_CHARSET
;
5012 if (EQ (w32_charset
, Qw32_charset_hebrew
))
5013 return HEBREW_CHARSET
;
5014 if (EQ (w32_charset
, Qw32_charset_vietnamese
))
5015 return VIETNAMESE_CHARSET
;
5016 if (EQ (w32_charset
, Qw32_charset_thai
))
5017 return THAI_CHARSET
;
5018 if (EQ (w32_charset
, Qw32_charset_mac
))
5020 #endif /* JOHAB_CHARSET */
5021 #ifdef UNICODE_CHARSET
5022 if (EQ (w32_charset
, Qw32_charset_unicode
))
5023 return UNICODE_CHARSET
;
5026 return DEFAULT_CHARSET
;
5031 w32_to_x_charset (fncharset
, matching
)
5035 static char buf
[32];
5036 Lisp_Object charset_type
;
5041 /* If fully specified, accept it as it is. Otherwise use a
5043 char *wildcard
= strchr (matching
, '*');
5046 else if (strchr (matching
, '-'))
5049 match_len
= strlen (matching
);
5055 /* Handle startup case of w32-charset-info-alist not
5056 being set up yet. */
5057 if (NILP(Vw32_charset_info_alist
))
5059 charset_type
= Qw32_charset_ansi
;
5061 case DEFAULT_CHARSET
:
5062 charset_type
= Qw32_charset_default
;
5064 case SYMBOL_CHARSET
:
5065 charset_type
= Qw32_charset_symbol
;
5067 case SHIFTJIS_CHARSET
:
5068 charset_type
= Qw32_charset_shiftjis
;
5070 case HANGEUL_CHARSET
:
5071 charset_type
= Qw32_charset_hangeul
;
5073 case GB2312_CHARSET
:
5074 charset_type
= Qw32_charset_gb2312
;
5076 case CHINESEBIG5_CHARSET
:
5077 charset_type
= Qw32_charset_chinesebig5
;
5080 charset_type
= Qw32_charset_oem
;
5083 /* More recent versions of Windows (95 and NT4.0) define more
5085 #ifdef EASTEUROPE_CHARSET
5086 case EASTEUROPE_CHARSET
:
5087 charset_type
= Qw32_charset_easteurope
;
5089 case TURKISH_CHARSET
:
5090 charset_type
= Qw32_charset_turkish
;
5092 case BALTIC_CHARSET
:
5093 charset_type
= Qw32_charset_baltic
;
5095 case RUSSIAN_CHARSET
:
5096 charset_type
= Qw32_charset_russian
;
5098 case ARABIC_CHARSET
:
5099 charset_type
= Qw32_charset_arabic
;
5102 charset_type
= Qw32_charset_greek
;
5104 case HEBREW_CHARSET
:
5105 charset_type
= Qw32_charset_hebrew
;
5107 case VIETNAMESE_CHARSET
:
5108 charset_type
= Qw32_charset_vietnamese
;
5111 charset_type
= Qw32_charset_thai
;
5114 charset_type
= Qw32_charset_mac
;
5117 charset_type
= Qw32_charset_johab
;
5121 #ifdef UNICODE_CHARSET
5122 case UNICODE_CHARSET
:
5123 charset_type
= Qw32_charset_unicode
;
5127 /* Encode numerical value of unknown charset. */
5128 sprintf (buf
, "*-#%u", fncharset
);
5134 char * best_match
= NULL
;
5135 int matching_found
= 0;
5137 /* Look through w32-charset-info-alist for the character set.
5138 Prefer ISO codepages, and prefer lower numbers in the ISO
5139 range. Only return charsets for codepages which are installed.
5141 Format of each entry is
5142 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5144 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
5147 Lisp_Object w32_charset
;
5148 Lisp_Object codepage
;
5150 Lisp_Object this_entry
= XCAR (rest
);
5152 /* Skip invalid entries in alist. */
5153 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
5154 || !CONSP (XCDR (this_entry
))
5155 || !SYMBOLP (XCAR (XCDR (this_entry
))))
5158 x_charset
= SDATA (XCAR (this_entry
));
5159 w32_charset
= XCAR (XCDR (this_entry
));
5160 codepage
= XCDR (XCDR (this_entry
));
5162 /* Look for Same charset and a valid codepage (or non-int
5163 which means ignore). */
5164 if (EQ (w32_charset
, charset_type
)
5165 && (!INTEGERP (codepage
) || XINT (codepage
) == CP_DEFAULT
5166 || IsValidCodePage (XINT (codepage
))))
5168 /* If we don't have a match already, then this is the
5172 best_match
= x_charset
;
5173 if (matching
&& !strnicmp (x_charset
, matching
, match_len
))
5176 /* If we already found a match for MATCHING, then
5177 only consider other matches. */
5178 else if (matching_found
5179 && strnicmp (x_charset
, matching
, match_len
))
5181 /* If this matches what we want, and the best so far doesn't,
5182 then this is better. */
5183 else if (!matching_found
&& matching
5184 && !strnicmp (x_charset
, matching
, match_len
))
5186 best_match
= x_charset
;
5189 /* If this is fully specified, and the best so far isn't,
5190 then this is better. */
5191 else if ((!strchr (best_match
, '-') && strchr (x_charset
, '-'))
5192 /* If this is an ISO codepage, and the best so far isn't,
5193 then this is better, but only if it fully specifies the
5195 || (strnicmp (best_match
, "iso", 3) != 0
5196 && strnicmp (x_charset
, "iso", 3) == 0
5197 && strchr (x_charset
, '-')))
5198 best_match
= x_charset
;
5199 /* If both are ISO8859 codepages, choose the one with the
5200 lowest number in the encoding field. */
5201 else if (strnicmp (best_match
, "iso8859-", 8) == 0
5202 && strnicmp (x_charset
, "iso8859-", 8) == 0)
5204 int best_enc
= atoi (best_match
+ 8);
5205 int this_enc
= atoi (x_charset
+ 8);
5206 if (this_enc
> 0 && this_enc
< best_enc
)
5207 best_match
= x_charset
;
5212 /* If no match, encode the numeric value. */
5215 sprintf (buf
, "*-#%u", fncharset
);
5219 strncpy (buf
, best_match
, 31);
5220 /* If the charset is not fully specified, put -0 on the end. */
5221 if (!strchr (best_match
, '-'))
5223 int pos
= strlen (best_match
);
5224 /* Charset specifiers shouldn't be very long. If it is a made
5225 up one, truncating it should not do any harm since it isn't
5226 recognized anyway. */
5229 strcpy (buf
+ pos
, "-0");
5237 /* Return all the X charsets that map to a font. */
5239 w32_to_all_x_charsets (fncharset
)
5242 static char buf
[32];
5243 Lisp_Object charset_type
;
5244 Lisp_Object retval
= Qnil
;
5249 /* Handle startup case of w32-charset-info-alist not
5250 being set up yet. */
5251 if (NILP(Vw32_charset_info_alist
))
5252 return Fcons (build_string ("iso8859-1"), Qnil
);
5254 charset_type
= Qw32_charset_ansi
;
5256 case DEFAULT_CHARSET
:
5257 charset_type
= Qw32_charset_default
;
5259 case SYMBOL_CHARSET
:
5260 charset_type
= Qw32_charset_symbol
;
5262 case SHIFTJIS_CHARSET
:
5263 charset_type
= Qw32_charset_shiftjis
;
5265 case HANGEUL_CHARSET
:
5266 charset_type
= Qw32_charset_hangeul
;
5268 case GB2312_CHARSET
:
5269 charset_type
= Qw32_charset_gb2312
;
5271 case CHINESEBIG5_CHARSET
:
5272 charset_type
= Qw32_charset_chinesebig5
;
5275 charset_type
= Qw32_charset_oem
;
5278 /* More recent versions of Windows (95 and NT4.0) define more
5280 #ifdef EASTEUROPE_CHARSET
5281 case EASTEUROPE_CHARSET
:
5282 charset_type
= Qw32_charset_easteurope
;
5284 case TURKISH_CHARSET
:
5285 charset_type
= Qw32_charset_turkish
;
5287 case BALTIC_CHARSET
:
5288 charset_type
= Qw32_charset_baltic
;
5290 case RUSSIAN_CHARSET
:
5291 charset_type
= Qw32_charset_russian
;
5293 case ARABIC_CHARSET
:
5294 charset_type
= Qw32_charset_arabic
;
5297 charset_type
= Qw32_charset_greek
;
5299 case HEBREW_CHARSET
:
5300 charset_type
= Qw32_charset_hebrew
;
5302 case VIETNAMESE_CHARSET
:
5303 charset_type
= Qw32_charset_vietnamese
;
5306 charset_type
= Qw32_charset_thai
;
5309 charset_type
= Qw32_charset_mac
;
5312 charset_type
= Qw32_charset_johab
;
5316 #ifdef UNICODE_CHARSET
5317 case UNICODE_CHARSET
:
5318 charset_type
= Qw32_charset_unicode
;
5322 /* Encode numerical value of unknown charset. */
5323 sprintf (buf
, "*-#%u", fncharset
);
5324 return Fcons (build_string (buf
), Qnil
);
5329 /* Look through w32-charset-info-alist for the character set.
5330 Only return fully specified charsets for codepages which are
5333 Format of each entry in Vw32_charset_info_alist is
5334 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5336 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
5338 Lisp_Object x_charset
;
5339 Lisp_Object w32_charset
;
5340 Lisp_Object codepage
;
5342 Lisp_Object this_entry
= XCAR (rest
);
5344 /* Skip invalid entries in alist. */
5345 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
5346 || !CONSP (XCDR (this_entry
))
5347 || !SYMBOLP (XCAR (XCDR (this_entry
))))
5350 x_charset
= XCAR (this_entry
);
5351 w32_charset
= XCAR (XCDR (this_entry
));
5352 codepage
= XCDR (XCDR (this_entry
));
5354 if (!strchr (SDATA (x_charset
), '-'))
5357 /* Look for Same charset and a valid codepage (or non-int
5358 which means ignore). */
5359 if (EQ (w32_charset
, charset_type
)
5360 && (!INTEGERP (codepage
) || XINT (codepage
) == CP_DEFAULT
5361 || IsValidCodePage (XINT (codepage
))))
5363 retval
= Fcons (x_charset
, retval
);
5367 /* If no match, encode the numeric value. */
5370 sprintf (buf
, "*-#%u", fncharset
);
5371 return Fcons (build_string (buf
), Qnil
);
5378 /* Get the Windows codepage corresponding to the specified font. The
5379 charset info in the font name is used to look up
5380 w32-charset-to-codepage-alist. */
5382 w32_codepage_for_font (char *fontname
)
5384 Lisp_Object codepage
, entry
;
5385 char *charset_str
, *charset
, *end
;
5387 /* Extract charset part of font string. */
5388 charset
= xlfd_charset_of_font (fontname
);
5393 charset_str
= (char *) alloca (strlen (charset
) + 1);
5394 strcpy (charset_str
, charset
);
5397 /* Remove leading "*-". */
5398 if (strncmp ("*-", charset_str
, 2) == 0)
5399 charset
= charset_str
+ 2;
5402 charset
= charset_str
;
5404 /* Stop match at wildcard (including preceding '-'). */
5405 if (end
= strchr (charset
, '*'))
5407 if (end
> charset
&& *(end
-1) == '-')
5412 if (!strcmp (charset
, "iso10646"))
5415 if (NILP (Vw32_charset_info_alist
))
5418 entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
5422 codepage
= Fcdr (Fcdr (entry
));
5424 if (NILP (codepage
))
5426 else if (XFASTINT (codepage
) == XFASTINT (Qt
))
5428 else if (INTEGERP (codepage
))
5429 return XINT (codepage
);
5436 w32_to_x_font (lplogfont
, lpxstr
, len
, specific_charset
)
5437 LOGFONT
* lplogfont
;
5440 char * specific_charset
;
5444 char height_pixels
[8];
5446 char width_pixels
[8];
5447 char *fontname_dash
;
5448 int display_resy
= (int) one_w32_display_info
.resy
;
5449 int display_resx
= (int) one_w32_display_info
.resx
;
5450 struct coding_system coding
;
5452 if (!lpxstr
) abort ();
5457 if (lplogfont
->lfOutPrecision
== OUT_STRING_PRECIS
)
5458 fonttype
= "raster";
5459 else if (lplogfont
->lfOutPrecision
== OUT_STROKE_PRECIS
)
5460 fonttype
= "outline";
5462 fonttype
= "unknown";
5464 setup_coding_system (Fcheck_coding_system (Vlocale_coding_system
),
5466 coding
.src_multibyte
= 0;
5467 coding
.dst_multibyte
= 1;
5468 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
5469 /* We explicitely disable composition handling because selection
5470 data should not contain any composition sequence. */
5471 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
5473 coding
.dst_bytes
= LF_FACESIZE
* 2;
5474 coding
.destination
= (unsigned char *) xmalloc (coding
.dst_bytes
+ 1);
5475 decode_coding_c_string (&coding
, lplogfont
->lfFaceName
,
5476 strlen(lplogfont
->lfFaceName
), Qnil
);
5477 fontname
= coding
.destination
;
5479 *(fontname
+ coding
.produced
) = '\0';
5481 /* Replace dashes with underscores so the dashes are not
5483 fontname_dash
= fontname
;
5484 while (fontname_dash
= strchr (fontname_dash
, '-'))
5485 *fontname_dash
= '_';
5487 if (lplogfont
->lfHeight
)
5489 sprintf (height_pixels
, "%u", eabs (lplogfont
->lfHeight
));
5490 sprintf (height_dpi
, "%u",
5491 eabs (lplogfont
->lfHeight
) * 720 / display_resy
);
5495 strcpy (height_pixels
, "*");
5496 strcpy (height_dpi
, "*");
5499 #if 0 /* Never put the width in the xfld. It fails on fonts with
5500 double-width characters. */
5501 if (lplogfont
->lfWidth
)
5502 sprintf (width_pixels
, "%u", lplogfont
->lfWidth
* 10);
5505 strcpy (width_pixels
, "*");
5507 _snprintf (lpxstr
, len
- 1,
5508 "-%s-%s-%s-%c-normal-normal-%s-%s-%d-%d-%c-%s-%s",
5509 fonttype
, /* foundry */
5510 fontname
, /* family */
5511 w32_to_x_weight (lplogfont
->lfWeight
), /* weight */
5512 lplogfont
->lfItalic
?'i':'r', /* slant */
5514 /* add style name */
5515 height_pixels
, /* pixel size */
5516 height_dpi
, /* point size */
5517 display_resx
, /* resx */
5518 display_resy
, /* resy */
5519 ((lplogfont
->lfPitchAndFamily
& 0x3) == VARIABLE_PITCH
)
5520 ? 'p' : 'c', /* spacing */
5521 width_pixels
, /* avg width */
5522 w32_to_x_charset (lplogfont
->lfCharSet
, specific_charset
)
5523 /* charset registry and encoding */
5526 lpxstr
[len
- 1] = 0; /* just to be sure */
5531 x_to_w32_font (lpxstr
, lplogfont
)
5533 LOGFONT
* lplogfont
;
5535 struct coding_system coding
;
5537 if (!lplogfont
) return (FALSE
);
5539 memset (lplogfont
, 0, sizeof (*lplogfont
));
5541 /* Set default value for each field. */
5543 lplogfont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
5544 lplogfont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
5545 lplogfont
->lfQuality
= DEFAULT_QUALITY
;
5547 /* go for maximum quality */
5548 lplogfont
->lfOutPrecision
= OUT_STROKE_PRECIS
;
5549 lplogfont
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
5550 lplogfont
->lfQuality
= PROOF_QUALITY
;
5553 lplogfont
->lfCharSet
= DEFAULT_CHARSET
;
5554 lplogfont
->lfWeight
= FW_DONTCARE
;
5555 lplogfont
->lfPitchAndFamily
= DEFAULT_PITCH
| FF_DONTCARE
;
5560 /* Provide a simple escape mechanism for specifying Windows font names
5561 * directly -- if font spec does not beginning with '-', assume this
5563 * "<font name>[:height in pixels[:width in pixels[:weight]]]"
5569 char name
[50], weight
[20], slant
, pitch
, pixels
[10], height
[10],
5570 width
[10], resy
[10], remainder
[50];
5572 int dpi
= (int) one_w32_display_info
.resy
;
5574 fields
= sscanf (lpxstr
,
5575 "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%49s",
5576 name
, weight
, &slant
, pixels
, height
, resy
, &pitch
, width
, remainder
);
5580 /* In the general case when wildcards cover more than one field,
5581 we don't know which field is which, so don't fill any in.
5582 However, we need to cope with this particular form, which is
5583 generated by font_list_1 (invoked by try_font_list):
5584 "-raster-6x10-*-gb2312*-*"
5585 and make sure to correctly parse the charset field. */
5588 fields
= sscanf (lpxstr
,
5589 "-%*[^-]-%49[^-]-*-%49s",
5592 else if (fields
< 9)
5598 if (fields
> 0 && name
[0] != '*')
5600 Lisp_Object string
= build_string (name
);
5602 (Fcheck_coding_system (Vlocale_coding_system
), &coding
);
5603 coding
.mode
|= (CODING_MODE_SAFE_ENCODING
| CODING_MODE_LAST_BLOCK
);
5604 /* Disable composition/charset annotation. */
5605 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
5606 coding
.dst_bytes
= SCHARS (string
) * 2;
5608 coding
.destination
= (unsigned char *) xmalloc (coding
.dst_bytes
);
5609 encode_coding_object (&coding
, string
, 0, 0,
5610 SCHARS (string
), SBYTES (string
), Qnil
);
5611 if (coding
.produced
>= LF_FACESIZE
)
5612 coding
.produced
= LF_FACESIZE
- 1;
5614 coding
.destination
[coding
.produced
] = '\0';
5616 strcpy (lplogfont
->lfFaceName
, coding
.destination
);
5617 xfree (coding
.destination
);
5621 lplogfont
->lfFaceName
[0] = '\0';
5626 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
5630 lplogfont
->lfItalic
= (fields
> 0 && slant
== 'i');
5634 if (fields
> 0 && pixels
[0] != '*')
5635 lplogfont
->lfHeight
= atoi (pixels
);
5639 if (fields
> 0 && resy
[0] != '*')
5642 if (tem
> 0) dpi
= tem
;
5645 if (fields
> -1 && lplogfont
->lfHeight
== 0 && height
[0] != '*')
5646 lplogfont
->lfHeight
= atoi (height
) * dpi
/ 720;
5651 lplogfont
->lfPitchAndFamily
= VARIABLE_PITCH
| FF_DONTCARE
;
5652 else if (pitch
== 'c')
5653 lplogfont
->lfPitchAndFamily
= FIXED_PITCH
| FF_DONTCARE
;
5658 if (fields
> 0 && width
[0] != '*')
5659 lplogfont
->lfWidth
= atoi (width
) / 10;
5663 /* Strip the trailing '-' if present. (it shouldn't be, as it
5664 fails the test against xlfd-tight-regexp in fontset.el). */
5666 int len
= strlen (remainder
);
5667 if (len
> 0 && remainder
[len
-1] == '-')
5668 remainder
[len
-1] = 0;
5670 encoding
= remainder
;
5672 if (strncmp (encoding
, "*-", 2) == 0)
5675 lplogfont
->lfCharSet
= x_to_w32_charset (encoding
);
5680 char name
[100], height
[10], width
[10], weight
[20];
5682 fields
= sscanf (lpxstr
,
5683 "%99[^:]:%9[^:]:%9[^:]:%19s",
5684 name
, height
, width
, weight
);
5686 if (fields
== EOF
) return (FALSE
);
5690 strncpy (lplogfont
->lfFaceName
,name
, LF_FACESIZE
);
5691 lplogfont
->lfFaceName
[LF_FACESIZE
-1] = 0;
5695 lplogfont
->lfFaceName
[0] = 0;
5701 lplogfont
->lfHeight
= atoi (height
);
5706 lplogfont
->lfWidth
= atoi (width
);
5710 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
5713 /* This makes TrueType fonts work better. */
5714 lplogfont
->lfHeight
= - eabs (lplogfont
->lfHeight
);
5719 /* Strip the pixel height and point height from the given xlfd, and
5720 return the pixel height. If no pixel height is specified, calculate
5721 one from the point height, or if that isn't defined either, return
5722 0 (which usually signifies a scalable font).
5725 xlfd_strip_height (char *fontname
)
5727 int pixel_height
, field_number
;
5728 char *read_from
, *write_to
;
5732 pixel_height
= field_number
= 0;
5735 /* Look for height fields. */
5736 for (read_from
= fontname
; *read_from
; read_from
++)
5738 if (*read_from
== '-')
5741 if (field_number
== 7) /* Pixel height. */
5744 write_to
= read_from
;
5746 /* Find end of field. */
5747 for (;*read_from
&& *read_from
!= '-'; read_from
++)
5750 /* Split the fontname at end of field. */
5756 pixel_height
= atoi (write_to
);
5757 /* Blank out field. */
5758 if (read_from
> write_to
)
5763 /* If the pixel height field is at the end (partial xlfd),
5766 return pixel_height
;
5768 /* If we got a pixel height, the point height can be
5769 ignored. Just blank it out and break now. */
5772 /* Find end of point size field. */
5773 for (; *read_from
&& *read_from
!= '-'; read_from
++)
5779 /* Blank out the point size field. */
5780 if (read_from
> write_to
)
5786 return pixel_height
;
5790 /* If the point height is already blank, break now. */
5791 if (*read_from
== '-')
5797 else if (field_number
== 8)
5799 /* If we didn't get a pixel height, try to get the point
5800 height and convert that. */
5802 char *point_size_start
= read_from
++;
5804 /* Find end of field. */
5805 for (; *read_from
&& *read_from
!= '-'; read_from
++)
5814 point_size
= atoi (point_size_start
);
5816 /* Convert to pixel height. */
5817 pixel_height
= point_size
5818 * one_w32_display_info
.height_in
/ 720;
5820 /* Blank out this field and break. */
5828 /* Shift the rest of the font spec into place. */
5829 if (write_to
&& read_from
> write_to
)
5831 for (; *read_from
; read_from
++, write_to
++)
5832 *write_to
= *read_from
;
5836 return pixel_height
;
5839 /* Assume parameter 1 is fully qualified, no wildcards. */
5841 w32_font_match (fontname
, pattern
)
5846 char *font_name_copy
;
5847 char *regex
= alloca (strlen (pattern
) * 2 + 3);
5849 font_name_copy
= alloca (strlen (fontname
) + 1);
5850 strcpy (font_name_copy
, fontname
);
5855 /* Turn pattern into a regexp and do a regexp match. */
5856 for (; *pattern
; pattern
++)
5858 if (*pattern
== '?')
5860 else if (*pattern
== '*')
5871 /* Strip out font heights and compare them seperately, since
5872 rounding error can cause mismatches. This also allows a
5873 comparison between a font that declares only a pixel height and a
5874 pattern that declares the point height.
5877 int font_height
, pattern_height
;
5879 font_height
= xlfd_strip_height (font_name_copy
);
5880 pattern_height
= xlfd_strip_height (regex
);
5882 /* Compare now, and don't bother doing expensive regexp matching
5883 if the heights differ. */
5884 if (font_height
&& pattern_height
&& (font_height
!= pattern_height
))
5888 return (fast_string_match_ignore_case (build_string (regex
),
5889 build_string(font_name_copy
)) >= 0);
5892 /* Callback functions, and a structure holding info they need, for
5893 listing system fonts on W32. We need one set of functions to do the
5894 job properly, but these don't work on NT 3.51 and earlier, so we
5895 have a second set which don't handle character sets properly to
5898 In both cases, there are two passes made. The first pass gets one
5899 font from each family, the second pass lists all the fonts from
5902 typedef struct enumfont_t
5907 XFontStruct
*size_ref
;
5908 Lisp_Object pattern
;
5914 enum_font_maybe_add_to_list (enumfont_t
*, LOGFONT
*, char *, Lisp_Object
);
5918 enum_font_cb2 (lplf
, lptm
, FontType
, lpef
)
5920 NEWTEXTMETRIC
* lptm
;
5924 /* Ignore struck out and underlined versions of fonts. */
5925 if (lplf
->elfLogFont
.lfStrikeOut
|| lplf
->elfLogFont
.lfUnderline
)
5928 /* Only return fonts with names starting with @ if they were
5929 explicitly specified, since Microsoft uses an initial @ to
5930 denote fonts for vertical writing, without providing a more
5931 convenient way of identifying them. */
5932 if (lplf
->elfLogFont
.lfFaceName
[0] == '@'
5933 && lpef
->logfont
.lfFaceName
[0] != '@')
5936 /* Check that the character set matches if it was specified */
5937 if (lpef
->logfont
.lfCharSet
!= DEFAULT_CHARSET
&&
5938 lplf
->elfLogFont
.lfCharSet
!= lpef
->logfont
.lfCharSet
)
5941 if (FontType
== RASTER_FONTTYPE
)
5943 /* DBCS raster fonts have problems displaying, so skip them. */
5944 int charset
= lplf
->elfLogFont
.lfCharSet
;
5945 if (charset
== SHIFTJIS_CHARSET
5946 || charset
== HANGEUL_CHARSET
5947 || charset
== CHINESEBIG5_CHARSET
5948 || charset
== GB2312_CHARSET
5949 #ifdef JOHAB_CHARSET
5950 || charset
== JOHAB_CHARSET
5958 Lisp_Object width
= Qnil
;
5959 Lisp_Object charset_list
= Qnil
;
5960 char *charset
= NULL
;
5962 /* Truetype fonts do not report their true metrics until loaded */
5963 if (FontType
!= RASTER_FONTTYPE
)
5965 if (!NILP (lpef
->pattern
))
5967 /* Scalable fonts are as big as you want them to be. */
5968 lplf
->elfLogFont
.lfHeight
= lpef
->logfont
.lfHeight
;
5969 lplf
->elfLogFont
.lfWidth
= lpef
->logfont
.lfWidth
;
5970 width
= make_number (lpef
->logfont
.lfWidth
);
5974 lplf
->elfLogFont
.lfHeight
= 0;
5975 lplf
->elfLogFont
.lfWidth
= 0;
5979 /* Make sure the height used here is the same as everywhere
5980 else (ie character height, not cell height). */
5981 if (lplf
->elfLogFont
.lfHeight
> 0)
5983 /* lptm can be trusted for RASTER fonts, but not scalable ones. */
5984 if (FontType
== RASTER_FONTTYPE
)
5985 lplf
->elfLogFont
.lfHeight
= lptm
->tmInternalLeading
- lptm
->tmHeight
;
5987 lplf
->elfLogFont
.lfHeight
= -lplf
->elfLogFont
.lfHeight
;
5990 if (!NILP (lpef
->pattern
))
5992 charset
= xlfd_charset_of_font (SDATA (lpef
->pattern
));
5994 /* We already checked charsets above, but DEFAULT_CHARSET
5995 slipped through. So only allow exact matches for DEFAULT_CHARSET. */
5997 && strncmp (charset
, "*-*", 3) != 0
5998 && lpef
->logfont
.lfCharSet
== DEFAULT_CHARSET
5999 && strcmp (charset
, w32_to_x_charset (DEFAULT_CHARSET
, NULL
)) != 0)
6004 charset_list
= Fcons (build_string (charset
), Qnil
);
6006 /* Always prefer unicode. */
6008 = Fcons (build_string ("iso10646-1"),
6009 w32_to_all_x_charsets (lplf
->elfLogFont
.lfCharSet
));
6011 /* Loop through the charsets. */
6012 for ( ; CONSP (charset_list
); charset_list
= Fcdr (charset_list
))
6014 Lisp_Object this_charset
= Fcar (charset_list
);
6015 charset
= SDATA (this_charset
);
6017 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
6020 /* List bold and italic variations if w32-enable-synthesized-fonts
6021 is non-nil and this is a plain font. */
6022 if (w32_enable_synthesized_fonts
6023 && lplf
->elfLogFont
.lfWeight
== FW_NORMAL
6024 && lplf
->elfLogFont
.lfItalic
== FALSE
)
6027 lplf
->elfLogFont
.lfWeight
= FW_BOLD
;
6028 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
6031 lplf
->elfLogFont
.lfItalic
= TRUE
;
6032 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
6035 lplf
->elfLogFont
.lfWeight
= FW_NORMAL
;
6036 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
6046 enum_font_maybe_add_to_list (lpef
, logfont
, match_charset
, width
)
6049 char * match_charset
;
6054 if (!w32_to_x_font (logfont
, buf
, 100, match_charset
))
6057 if (NILP (lpef
->pattern
)
6058 || w32_font_match (buf
, SDATA (lpef
->pattern
)))
6060 /* Check if we already listed this font. This may happen if
6061 w32_enable_synthesized_fonts is non-nil, and there are real
6062 bold and italic versions of the font. */
6063 Lisp_Object font_name
= build_string (buf
);
6064 if (NILP (Fmember (font_name
, lpef
->list
)))
6066 Lisp_Object entry
= Fcons (font_name
, width
);
6067 lpef
->list
= Fcons (entry
, lpef
->list
);
6075 enum_font_cb1 (lplf
, lptm
, FontType
, lpef
)
6077 NEWTEXTMETRIC
* lptm
;
6081 return EnumFontFamilies (lpef
->hdc
,
6082 lplf
->elfLogFont
.lfFaceName
,
6083 (FONTENUMPROC
) enum_font_cb2
,
6089 enum_fontex_cb2 (lplf
, lptm
, font_type
, lpef
)
6090 ENUMLOGFONTEX
* lplf
;
6091 NEWTEXTMETRICEX
* lptm
;
6095 /* We are not interested in the extra info we get back from the 'Ex
6096 version - only the fact that we get character set variations
6097 enumerated seperately. */
6098 return enum_font_cb2 ((ENUMLOGFONT
*) lplf
, (NEWTEXTMETRIC
*) lptm
,
6103 enum_fontex_cb1 (lplf
, lptm
, font_type
, lpef
)
6104 ENUMLOGFONTEX
* lplf
;
6105 NEWTEXTMETRICEX
* lptm
;
6109 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6110 FARPROC enum_font_families_ex
6111 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6112 /* We don't really expect EnumFontFamiliesEx to disappear once we
6113 get here, so don't bother handling it gracefully. */
6114 if (enum_font_families_ex
== NULL
)
6115 error ("gdi32.dll has disappeared!");
6116 return enum_font_families_ex (lpef
->hdc
,
6118 (FONTENUMPROC
) enum_fontex_cb2
,
6122 /* Interface to fontset handler. (adapted from mw32font.c in Meadow
6123 and xterm.c in Emacs 20.3) */
6125 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
)
6127 char *fontname
, *ptnstr
;
6128 Lisp_Object list
, tem
, newlist
= Qnil
;
6131 list
= Vw32_bdf_filename_alist
;
6132 ptnstr
= SDATA (pattern
);
6134 for ( ; CONSP (list
); list
= XCDR (list
))
6138 fontname
= SDATA (XCAR (tem
));
6139 else if (STRINGP (tem
))
6140 fontname
= SDATA (tem
);
6144 if (w32_font_match (fontname
, ptnstr
))
6146 newlist
= Fcons (XCAR (tem
), newlist
);
6148 if (max_names
>= 0 && n_fonts
>= max_names
)
6157 /* Return a list of names of available fonts matching PATTERN on frame
6158 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
6159 to be listed. Frame F NULL means we have not yet created any
6160 frame, which means we can't get proper size info, as we don't have
6161 a device context to use for GetTextMetrics.
6162 MAXNAMES sets a limit on how many fonts to match. If MAXNAMES is
6163 negative, then all matching fonts are returned. */
6166 w32_list_fonts (f
, pattern
, size
, maxnames
)
6168 Lisp_Object pattern
;
6172 Lisp_Object patterns
, key
= Qnil
, tem
, tpat
;
6173 Lisp_Object list
= Qnil
, newlist
= Qnil
, second_best
= Qnil
;
6174 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
6177 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
6178 if (NILP (patterns
))
6179 patterns
= Fcons (pattern
, Qnil
);
6181 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
6186 tpat
= XCAR (patterns
);
6188 if (!STRINGP (tpat
))
6191 /* Avoid expensive EnumFontFamilies functions if we are not
6192 going to be able to output one of these anyway. */
6193 codepage
= w32_codepage_for_font (SDATA (tpat
));
6194 if (codepage
!= CP_8BIT
&& codepage
!= CP_UNICODE
6195 && codepage
!= CP_DEFAULT
&& codepage
!= CP_UNKNOWN
6196 && !IsValidCodePage(codepage
))
6199 /* See if we cached the result for this particular query.
6200 The cache is an alist of the form:
6201 ((PATTERN (FONTNAME . WIDTH) ...) ...)
6203 if (tem
= XCDR (dpyinfo
->name_list_element
),
6204 !NILP (list
= Fassoc (tpat
, tem
)))
6206 list
= Fcdr_safe (list
);
6207 /* We have a cached list. Don't have to get the list again. */
6212 /* At first, put PATTERN in the cache. */
6217 /* Use EnumFontFamiliesEx where it is available, as it knows
6218 about character sets. Fall back to EnumFontFamilies for
6219 older versions of NT that don't support the 'Ex function. */
6220 x_to_w32_font (SDATA (tpat
), &ef
.logfont
);
6222 LOGFONT font_match_pattern
;
6223 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6224 FARPROC enum_font_families_ex
6225 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6227 /* We do our own pattern matching so we can handle wildcards. */
6228 font_match_pattern
.lfFaceName
[0] = 0;
6229 font_match_pattern
.lfPitchAndFamily
= 0;
6230 /* We can use the charset, because if it is a wildcard it will
6231 be DEFAULT_CHARSET anyway. */
6232 font_match_pattern
.lfCharSet
= ef
.logfont
.lfCharSet
;
6234 ef
.hdc
= GetDC (dpyinfo
->root_window
);
6236 if (enum_font_families_ex
)
6237 enum_font_families_ex (ef
.hdc
,
6238 &font_match_pattern
,
6239 (FONTENUMPROC
) enum_fontex_cb1
,
6242 EnumFontFamilies (ef
.hdc
, NULL
, (FONTENUMPROC
) enum_font_cb1
,
6245 ReleaseDC (dpyinfo
->root_window
, ef
.hdc
);
6251 /* Make a list of the fonts we got back.
6252 Store that in the font cache for the display. */
6253 XSETCDR (dpyinfo
->name_list_element
,
6254 Fcons (Fcons (tpat
, list
),
6255 XCDR (dpyinfo
->name_list_element
)));
6258 if (NILP (list
)) continue; /* Try the remaining alternatives. */
6260 newlist
= second_best
= Qnil
;
6262 /* Make a list of the fonts that have the right width. */
6263 for (; CONSP (list
); list
= XCDR (list
))
6270 if (NILP (XCAR (tem
)))
6274 newlist
= Fcons (XCAR (tem
), newlist
);
6276 if (maxnames
>= 0 && n_fonts
>= maxnames
)
6281 if (!INTEGERP (XCDR (tem
)))
6283 /* Since we don't yet know the size of the font, we must
6284 load it and try GetTextMetrics. */
6285 W32FontStruct thisinfo
;
6290 if (!x_to_w32_font (SDATA (XCAR (tem
)), &lf
))
6294 thisinfo
.bdf
= NULL
;
6295 thisinfo
.hfont
= CreateFontIndirect (&lf
);
6296 if (thisinfo
.hfont
== NULL
)
6299 hdc
= GetDC (dpyinfo
->root_window
);
6300 oldobj
= SelectObject (hdc
, thisinfo
.hfont
);
6301 if (GetTextMetrics (hdc
, &thisinfo
.tm
))
6302 XSETCDR (tem
, make_number (FONT_AVG_WIDTH (&thisinfo
)));
6304 XSETCDR (tem
, make_number (0));
6305 SelectObject (hdc
, oldobj
);
6306 ReleaseDC (dpyinfo
->root_window
, hdc
);
6307 DeleteObject(thisinfo
.hfont
);
6310 found_size
= XINT (XCDR (tem
));
6311 if (found_size
== size
)
6313 newlist
= Fcons (XCAR (tem
), newlist
);
6315 if (maxnames
>= 0 && n_fonts
>= maxnames
)
6318 /* keep track of the closest matching size in case
6319 no exact match is found. */
6320 else if (found_size
> 0)
6322 if (NILP (second_best
))
6325 else if (found_size
< size
)
6327 if (XINT (XCDR (second_best
)) > size
6328 || XINT (XCDR (second_best
)) < found_size
)
6333 if (XINT (XCDR (second_best
)) > size
6334 && XINT (XCDR (second_best
)) >
6341 if (!NILP (newlist
))
6343 else if (!NILP (second_best
))
6345 newlist
= Fcons (XCAR (second_best
), Qnil
);
6350 /* Include any bdf fonts. */
6351 if (n_fonts
< maxnames
|| maxnames
< 0)
6353 Lisp_Object combined
[2];
6354 combined
[0] = w32_list_bdf_fonts (pattern
, maxnames
- n_fonts
);
6355 combined
[1] = newlist
;
6356 newlist
= Fnconc(2, combined
);
6363 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
6365 w32_get_font_info (f
, font_idx
)
6369 return (FRAME_W32_FONT_TABLE (f
) + font_idx
);
6374 w32_query_font (struct frame
*f
, char *fontname
)
6377 struct font_info
*pfi
;
6379 pfi
= FRAME_W32_FONT_TABLE (f
);
6381 for (i
= 0; i
< one_w32_display_info
.n_fonts
;i
++, pfi
++)
6383 if (stricmp(pfi
->name
, fontname
) == 0) return pfi
;
6389 /* Find a CCL program for a font specified by FONTP, and set the member
6390 `encoder' of the structure. */
6393 w32_find_ccl_program (fontp
)
6394 struct font_info
*fontp
;
6396 Lisp_Object list
, elt
;
6398 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
6402 && STRINGP (XCAR (elt
))
6403 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
6409 struct ccl_program
*ccl
6410 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
6412 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
6415 fontp
->font_encoder
= ccl
;
6419 /* directory-files from dired.c. */
6420 Lisp_Object Fdirectory_files
P_((Lisp_Object
, Lisp_Object
, Lisp_Object
, Lisp_Object
));
6423 /* Find BDF files in a specified directory. (use GCPRO when calling,
6424 as this calls lisp to get a directory listing). */
6426 w32_find_bdf_fonts_in_dir (Lisp_Object directory
)
6428 Lisp_Object filelist
, list
= Qnil
;
6431 if (!STRINGP(directory
))
6434 filelist
= Fdirectory_files (directory
, Qt
,
6435 build_string (".*\\.[bB][dD][fF]"), Qt
);
6437 for ( ; CONSP(filelist
); filelist
= XCDR (filelist
))
6439 Lisp_Object filename
= XCAR (filelist
);
6440 if (w32_BDF_to_x_font (SDATA (filename
), fontname
, 100))
6441 store_in_alist (&list
, build_string (fontname
), filename
);
6446 DEFUN ("w32-find-bdf-fonts", Fw32_find_bdf_fonts
, Sw32_find_bdf_fonts
,
6448 doc
: /* Return a list of BDF fonts in DIRECTORY.
6449 The list is suitable for appending to `w32-bdf-filename-alist'.
6450 Fonts which do not contain an xlfd description will not be included
6451 in the list. DIRECTORY may be a list of directories. */)
6453 Lisp_Object directory
;
6455 Lisp_Object list
= Qnil
;
6456 struct gcpro gcpro1
, gcpro2
;
6458 if (!CONSP (directory
))
6459 return w32_find_bdf_fonts_in_dir (directory
);
6461 for ( ; CONSP (directory
); directory
= XCDR (directory
))
6463 Lisp_Object pair
[2];
6466 GCPRO2 (directory
, list
);
6467 pair
[1] = w32_find_bdf_fonts_in_dir( XCAR (directory
) );
6468 list
= Fnconc( 2, pair
);
6475 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
6476 doc
: /* Internal function called by `color-defined-p', which see. */)
6478 Lisp_Object color
, frame
;
6481 FRAME_PTR f
= check_x_frame (frame
);
6483 CHECK_STRING (color
);
6485 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
6491 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
6492 doc
: /* Internal function called by `color-values', which see. */)
6494 Lisp_Object color
, frame
;
6497 FRAME_PTR f
= check_x_frame (frame
);
6499 CHECK_STRING (color
);
6501 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
6502 return list3 (make_number ((GetRValue (foo
.pixel
) << 8)
6503 | GetRValue (foo
.pixel
)),
6504 make_number ((GetGValue (foo
.pixel
) << 8)
6505 | GetGValue (foo
.pixel
)),
6506 make_number ((GetBValue (foo
.pixel
) << 8)
6507 | GetBValue (foo
.pixel
)));
6512 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
6513 doc
: /* Internal function called by `display-color-p', which see. */)
6515 Lisp_Object display
;
6517 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6519 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
6525 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
,
6526 Sx_display_grayscale_p
, 0, 1, 0,
6527 doc
: /* Return t if DISPLAY supports shades of gray.
6528 Note that color displays do support shades of gray.
6529 The optional argument DISPLAY specifies which display to ask about.
6530 DISPLAY should be either a frame or a display name (a string).
6531 If omitted or nil, that stands for the selected frame's display. */)
6533 Lisp_Object display
;
6535 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6537 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
6543 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
,
6544 Sx_display_pixel_width
, 0, 1, 0,
6545 doc
: /* Returns the width in pixels of DISPLAY.
6546 The optional argument DISPLAY specifies which display to ask about.
6547 DISPLAY should be either a frame or a display name (a string).
6548 If omitted or nil, that stands for the selected frame's display. */)
6550 Lisp_Object display
;
6552 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6554 return make_number (dpyinfo
->width
);
6557 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
6558 Sx_display_pixel_height
, 0, 1, 0,
6559 doc
: /* Returns the height in pixels of DISPLAY.
6560 The optional argument DISPLAY specifies which display to ask about.
6561 DISPLAY should be either a frame or a display name (a string).
6562 If omitted or nil, that stands for the selected frame's display. */)
6564 Lisp_Object display
;
6566 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6568 return make_number (dpyinfo
->height
);
6571 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
6573 doc
: /* Returns the number of bitplanes of DISPLAY.
6574 The optional argument DISPLAY specifies which display to ask about.
6575 DISPLAY should be either a frame or a display name (a string).
6576 If omitted or nil, that stands for the selected frame's display. */)
6578 Lisp_Object display
;
6580 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6582 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
6585 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
6587 doc
: /* Returns the number of color cells of DISPLAY.
6588 The optional argument DISPLAY specifies which display to ask about.
6589 DISPLAY should be either a frame or a display name (a string).
6590 If omitted or nil, that stands for the selected frame's display. */)
6592 Lisp_Object display
;
6594 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6598 hdc
= GetDC (dpyinfo
->root_window
);
6599 if (dpyinfo
->has_palette
)
6600 cap
= GetDeviceCaps (hdc
, SIZEPALETTE
);
6602 cap
= GetDeviceCaps (hdc
, NUMCOLORS
);
6604 /* We force 24+ bit depths to 24-bit, both to prevent an overflow
6605 and because probably is more meaningful on Windows anyway */
6607 cap
= 1 << min(dpyinfo
->n_planes
* dpyinfo
->n_cbits
, 24);
6609 ReleaseDC (dpyinfo
->root_window
, hdc
);
6611 return make_number (cap
);
6614 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
6615 Sx_server_max_request_size
,
6617 doc
: /* Returns the maximum request size of the server of DISPLAY.
6618 The optional argument DISPLAY specifies which display to ask about.
6619 DISPLAY should be either a frame or a display name (a string).
6620 If omitted or nil, that stands for the selected frame's display. */)
6622 Lisp_Object display
;
6624 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6626 return make_number (1);
6629 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
6630 doc
: /* Returns the "vendor ID" string of the W32 system (Microsoft).
6631 The optional argument DISPLAY specifies which display to ask about.
6632 DISPLAY should be either a frame or a display name (a string).
6633 If omitted or nil, that stands for the selected frame's display. */)
6635 Lisp_Object display
;
6637 return build_string ("Microsoft Corp.");
6640 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
6641 doc
: /* Returns the version numbers of the server of DISPLAY.
6642 The value is a list of three integers: the major and minor
6643 version numbers of the X Protocol in use, and the distributor-specific release
6644 number. See also the function `x-server-vendor'.
6646 The optional argument DISPLAY specifies which display to ask about.
6647 DISPLAY should be either a frame or a display name (a string).
6648 If omitted or nil, that stands for the selected frame's display. */)
6650 Lisp_Object display
;
6652 return Fcons (make_number (w32_major_version
),
6653 Fcons (make_number (w32_minor_version
),
6654 Fcons (make_number (w32_build_number
), Qnil
)));
6657 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
6658 doc
: /* Returns the number of screens on the server of DISPLAY.
6659 The optional argument DISPLAY specifies which display to ask about.
6660 DISPLAY should be either a frame or a display name (a string).
6661 If omitted or nil, that stands for the selected frame's display. */)
6663 Lisp_Object display
;
6665 return make_number (1);
6668 DEFUN ("x-display-mm-height", Fx_display_mm_height
,
6669 Sx_display_mm_height
, 0, 1, 0,
6670 doc
: /* Returns the height in millimeters of DISPLAY.
6671 The optional argument DISPLAY specifies which display to ask about.
6672 DISPLAY should be either a frame or a display name (a string).
6673 If omitted or nil, that stands for the selected frame's display. */)
6675 Lisp_Object display
;
6677 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6681 hdc
= GetDC (dpyinfo
->root_window
);
6683 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
6685 ReleaseDC (dpyinfo
->root_window
, hdc
);
6687 return make_number (cap
);
6690 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
6691 doc
: /* Returns the width in millimeters of DISPLAY.
6692 The optional argument DISPLAY specifies which display to ask about.
6693 DISPLAY should be either a frame or a display name (a string).
6694 If omitted or nil, that stands for the selected frame's display. */)
6696 Lisp_Object display
;
6698 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6703 hdc
= GetDC (dpyinfo
->root_window
);
6705 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
6707 ReleaseDC (dpyinfo
->root_window
, hdc
);
6709 return make_number (cap
);
6712 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
6713 Sx_display_backing_store
, 0, 1, 0,
6714 doc
: /* Returns an indication of whether DISPLAY does backing store.
6715 The value may be `always', `when-mapped', or `not-useful'.
6716 The optional argument DISPLAY specifies which display to ask about.
6717 DISPLAY should be either a frame or a display name (a string).
6718 If omitted or nil, that stands for the selected frame's display. */)
6720 Lisp_Object display
;
6722 return intern ("not-useful");
6725 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
6726 Sx_display_visual_class
, 0, 1, 0,
6727 doc
: /* Returns the visual class of DISPLAY.
6728 The value is one of the symbols `static-gray', `gray-scale',
6729 `static-color', `pseudo-color', `true-color', or `direct-color'.
6731 The optional argument DISPLAY specifies which display to ask about.
6732 DISPLAY should be either a frame or a display name (a string).
6733 If omitted or nil, that stands for the selected frame's display. */)
6735 Lisp_Object display
;
6737 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6738 Lisp_Object result
= Qnil
;
6740 if (dpyinfo
->has_palette
)
6741 result
= intern ("pseudo-color");
6742 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
6743 result
= intern ("static-grey");
6744 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
6745 result
= intern ("static-color");
6746 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
6747 result
= intern ("true-color");
6752 DEFUN ("x-display-save-under", Fx_display_save_under
,
6753 Sx_display_save_under
, 0, 1, 0,
6754 doc
: /* Returns t if DISPLAY supports the save-under feature.
6755 The optional argument DISPLAY specifies which display to ask about.
6756 DISPLAY should be either a frame or a display name (a string).
6757 If omitted or nil, that stands for the selected frame's display. */)
6759 Lisp_Object display
;
6766 register struct frame
*f
;
6768 return FRAME_PIXEL_WIDTH (f
);
6773 register struct frame
*f
;
6775 return FRAME_PIXEL_HEIGHT (f
);
6780 register struct frame
*f
;
6782 return FRAME_COLUMN_WIDTH (f
);
6787 register struct frame
*f
;
6789 return FRAME_LINE_HEIGHT (f
);
6794 register struct frame
*f
;
6796 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
6799 /* Return the display structure for the display named NAME.
6800 Open a new connection if necessary. */
6802 struct w32_display_info
*
6803 x_display_info_for_name (name
)
6807 struct w32_display_info
*dpyinfo
;
6809 CHECK_STRING (name
);
6811 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
6813 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
6816 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
6821 /* Use this general default value to start with. */
6822 Vx_resource_name
= Vinvocation_name
;
6824 validate_x_resource_name ();
6826 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
6827 (char *) SDATA (Vx_resource_name
));
6830 error ("Cannot connect to server %s", SDATA (name
));
6833 XSETFASTINT (Vwindow_system_version
, 3);
6838 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
6839 1, 3, 0, doc
: /* Open a connection to a server.
6840 DISPLAY is the name of the display to connect to.
6841 Optional second arg XRM-STRING is a string of resources in xrdb format.
6842 If the optional third arg MUST-SUCCEED is non-nil,
6843 terminate Emacs if we can't open the connection. */)
6844 (display
, xrm_string
, must_succeed
)
6845 Lisp_Object display
, xrm_string
, must_succeed
;
6847 unsigned char *xrm_option
;
6848 struct w32_display_info
*dpyinfo
;
6850 /* If initialization has already been done, return now to avoid
6851 overwriting critical parts of one_w32_display_info. */
6855 CHECK_STRING (display
);
6856 if (! NILP (xrm_string
))
6857 CHECK_STRING (xrm_string
);
6860 if (! EQ (Vwindow_system
, intern ("w32")))
6861 error ("Not using Microsoft Windows");
6864 /* Allow color mapping to be defined externally; first look in user's
6865 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
6867 Lisp_Object color_file
;
6868 struct gcpro gcpro1
;
6870 color_file
= build_string("~/rgb.txt");
6872 GCPRO1 (color_file
);
6874 if (NILP (Ffile_readable_p (color_file
)))
6876 Fexpand_file_name (build_string ("rgb.txt"),
6877 Fsymbol_value (intern ("data-directory")));
6879 Vw32_color_map
= Fw32_load_color_file (color_file
);
6883 if (NILP (Vw32_color_map
))
6884 Vw32_color_map
= Fw32_default_color_map ();
6886 /* Merge in system logical colors. */
6887 add_system_logical_colors_to_map (&Vw32_color_map
);
6889 if (! NILP (xrm_string
))
6890 xrm_option
= (unsigned char *) SDATA (xrm_string
);
6892 xrm_option
= (unsigned char *) 0;
6894 /* Use this general default value to start with. */
6895 /* First remove .exe suffix from invocation-name - it looks ugly. */
6897 char basename
[ MAX_PATH
], *str
;
6899 strcpy (basename
, SDATA (Vinvocation_name
));
6900 str
= strrchr (basename
, '.');
6902 Vinvocation_name
= build_string (basename
);
6904 Vx_resource_name
= Vinvocation_name
;
6906 validate_x_resource_name ();
6908 /* This is what opens the connection and sets x_current_display.
6909 This also initializes many symbols, such as those used for input. */
6910 dpyinfo
= w32_term_init (display
, xrm_option
,
6911 (char *) SDATA (Vx_resource_name
));
6915 if (!NILP (must_succeed
))
6916 fatal ("Cannot connect to server %s.\n",
6919 error ("Cannot connect to server %s", SDATA (display
));
6924 XSETFASTINT (Vwindow_system_version
, 3);
6928 DEFUN ("x-close-connection", Fx_close_connection
,
6929 Sx_close_connection
, 1, 1, 0,
6930 doc
: /* Close the connection to DISPLAY's server.
6931 For DISPLAY, specify either a frame or a display name (a string).
6932 If DISPLAY is nil, that stands for the selected frame's display. */)
6934 Lisp_Object display
;
6936 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6939 if (dpyinfo
->reference_count
> 0)
6940 error ("Display still has frames on it");
6943 /* Free the fonts in the font table. */
6944 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
6945 if (dpyinfo
->font_table
[i
].name
)
6947 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
6948 xfree (dpyinfo
->font_table
[i
].full_name
);
6949 xfree (dpyinfo
->font_table
[i
].name
);
6950 w32_unload_font (dpyinfo
, dpyinfo
->font_table
[i
].font
);
6952 x_destroy_all_bitmaps (dpyinfo
);
6954 x_delete_display (dpyinfo
);
6960 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
6961 doc
: /* Return the list of display names that Emacs has connections to. */)
6964 Lisp_Object tail
, result
;
6967 for (tail
= w32_display_name_list
; CONSP (tail
); tail
= XCDR (tail
))
6968 result
= Fcons (XCAR (XCAR (tail
)), result
);
6973 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
6974 doc
: /* This is a noop on W32 systems. */)
6976 Lisp_Object display
, on
;
6983 /***********************************************************************
6985 ***********************************************************************/
6987 DEFUN ("x-change-window-property", Fx_change_window_property
,
6988 Sx_change_window_property
, 2, 6, 0,
6989 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
6990 VALUE may be a string or a list of conses, numbers and/or strings.
6991 If an element in the list is a string, it is converted to
6992 an Atom and the value of the Atom is used. If an element is a cons,
6993 it is converted to a 32 bit number where the car is the 16 top bits and the
6994 cdr is the lower 16 bits.
6995 FRAME nil or omitted means use the selected frame.
6996 If TYPE is given and non-nil, it is the name of the type of VALUE.
6997 If TYPE is not given or nil, the type is STRING.
6998 FORMAT gives the size in bits of each element if VALUE is a list.
6999 It must be one of 8, 16 or 32.
7000 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
7001 If OUTER_P is non-nil, the property is changed for the outer X window of
7002 FRAME. Default is to change on the edit X window.
7005 (prop
, value
, frame
, type
, format
, outer_p
)
7006 Lisp_Object prop
, value
, frame
, type
, format
, outer_p
;
7008 #if 0 /* TODO : port window properties to W32 */
7009 struct frame
*f
= check_x_frame (frame
);
7012 CHECK_STRING (prop
);
7013 CHECK_STRING (value
);
7016 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
7017 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
7018 prop_atom
, XA_STRING
, 8, PropModeReplace
,
7019 SDATA (value
), SCHARS (value
));
7021 /* Make sure the property is set when we return. */
7022 XFlush (FRAME_W32_DISPLAY (f
));
7031 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
7032 Sx_delete_window_property
, 1, 2, 0,
7033 doc
: /* Remove window property PROP from X window of FRAME.
7034 FRAME nil or omitted means use the selected frame. Value is PROP. */)
7036 Lisp_Object prop
, frame
;
7038 #if 0 /* TODO : port window properties to W32 */
7040 struct frame
*f
= check_x_frame (frame
);
7043 CHECK_STRING (prop
);
7045 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
7046 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
7048 /* Make sure the property is removed when we return. */
7049 XFlush (FRAME_W32_DISPLAY (f
));
7057 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
7059 doc
: /* Value is the value of window property PROP on FRAME.
7060 If FRAME is nil or omitted, use the selected frame. Value is nil
7061 if FRAME hasn't a property with name PROP or if PROP has no string
7064 Lisp_Object prop
, frame
;
7066 #if 0 /* TODO : port window properties to W32 */
7068 struct frame
*f
= check_x_frame (frame
);
7071 Lisp_Object prop_value
= Qnil
;
7072 char *tmp_data
= NULL
;
7075 unsigned long actual_size
, bytes_remaining
;
7077 CHECK_STRING (prop
);
7079 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
7080 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
7081 prop_atom
, 0, 0, False
, XA_STRING
,
7082 &actual_type
, &actual_format
, &actual_size
,
7083 &bytes_remaining
, (unsigned char **) &tmp_data
);
7086 int size
= bytes_remaining
;
7091 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
7092 prop_atom
, 0, bytes_remaining
,
7094 &actual_type
, &actual_format
,
7095 &actual_size
, &bytes_remaining
,
7096 (unsigned char **) &tmp_data
);
7098 prop_value
= make_string (tmp_data
, size
);
7113 /***********************************************************************
7115 ***********************************************************************/
7117 /* If non-null, an asynchronous timer that, when it expires, displays
7118 an hourglass cursor on all frames. */
7120 static struct atimer
*hourglass_atimer
;
7122 /* Non-zero means an hourglass cursor is currently shown. */
7124 static int hourglass_shown_p
;
7126 /* Number of seconds to wait before displaying an hourglass cursor. */
7128 static Lisp_Object Vhourglass_delay
;
7130 /* Default number of seconds to wait before displaying an hourglass
7133 #define DEFAULT_HOURGLASS_DELAY 1
7135 /* Function prototypes. */
7137 static void show_hourglass
P_ ((struct atimer
*));
7138 static void hide_hourglass
P_ ((void));
7141 /* Cancel a currently active hourglass timer, and start a new one. */
7146 #if 0 /* TODO: cursor shape changes. */
7148 int secs
, usecs
= 0;
7150 cancel_hourglass ();
7152 if (INTEGERP (Vhourglass_delay
)
7153 && XINT (Vhourglass_delay
) > 0)
7154 secs
= XFASTINT (Vhourglass_delay
);
7155 else if (FLOATP (Vhourglass_delay
)
7156 && XFLOAT_DATA (Vhourglass_delay
) > 0)
7159 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
7160 secs
= XFASTINT (tem
);
7161 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
7164 secs
= DEFAULT_HOURGLASS_DELAY
;
7166 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
7167 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
7168 show_hourglass
, NULL
);
7173 /* Cancel the hourglass cursor timer if active, hide an hourglass
7179 if (hourglass_atimer
)
7181 cancel_atimer (hourglass_atimer
);
7182 hourglass_atimer
= NULL
;
7185 if (hourglass_shown_p
)
7190 /* Timer function of hourglass_atimer. TIMER is equal to
7193 Display an hourglass cursor on all frames by mapping the frames'
7194 hourglass_window. Set the hourglass_p flag in the frames'
7195 output_data.x structure to indicate that an hourglass cursor is
7196 shown on the frames. */
7199 show_hourglass (timer
)
7200 struct atimer
*timer
;
7202 #if 0 /* TODO: cursor shape changes. */
7203 /* The timer implementation will cancel this timer automatically
7204 after this function has run. Set hourglass_atimer to null
7205 so that we know the timer doesn't have to be canceled. */
7206 hourglass_atimer
= NULL
;
7208 if (!hourglass_shown_p
)
7210 Lisp_Object rest
, frame
;
7214 FOR_EACH_FRAME (rest
, frame
)
7215 if (FRAME_W32_P (XFRAME (frame
)))
7217 struct frame
*f
= XFRAME (frame
);
7219 f
->output_data
.w32
->hourglass_p
= 1;
7221 if (!f
->output_data
.w32
->hourglass_window
)
7223 unsigned long mask
= CWCursor
;
7224 XSetWindowAttributes attrs
;
7226 attrs
.cursor
= f
->output_data
.w32
->hourglass_cursor
;
7228 f
->output_data
.w32
->hourglass_window
7229 = XCreateWindow (FRAME_X_DISPLAY (f
),
7230 FRAME_OUTER_WINDOW (f
),
7231 0, 0, 32000, 32000, 0, 0,
7237 XMapRaised (FRAME_X_DISPLAY (f
),
7238 f
->output_data
.w32
->hourglass_window
);
7239 XFlush (FRAME_X_DISPLAY (f
));
7242 hourglass_shown_p
= 1;
7249 /* Hide the hourglass cursor on all frames, if it is currently shown. */
7254 #if 0 /* TODO: cursor shape changes. */
7255 if (hourglass_shown_p
)
7257 Lisp_Object rest
, frame
;
7260 FOR_EACH_FRAME (rest
, frame
)
7262 struct frame
*f
= XFRAME (frame
);
7265 /* Watch out for newly created frames. */
7266 && f
->output_data
.x
->hourglass_window
)
7268 XUnmapWindow (FRAME_X_DISPLAY (f
),
7269 f
->output_data
.x
->hourglass_window
);
7270 /* Sync here because XTread_socket looks at the
7271 hourglass_p flag that is reset to zero below. */
7272 XSync (FRAME_X_DISPLAY (f
), False
);
7273 f
->output_data
.x
->hourglass_p
= 0;
7277 hourglass_shown_p
= 0;
7285 /***********************************************************************
7287 ***********************************************************************/
7289 static Lisp_Object x_create_tip_frame
P_ ((struct w32_display_info
*,
7290 Lisp_Object
, Lisp_Object
));
7291 static void compute_tip_xy
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
7292 Lisp_Object
, int, int, int *, int *));
7294 /* The frame of a currently visible tooltip. */
7296 Lisp_Object tip_frame
;
7298 /* If non-nil, a timer started that hides the last tooltip when it
7301 Lisp_Object tip_timer
;
7304 /* If non-nil, a vector of 3 elements containing the last args
7305 with which x-show-tip was called. See there. */
7307 Lisp_Object last_show_tip_args
;
7309 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
7311 Lisp_Object Vx_max_tooltip_size
;
7315 unwind_create_tip_frame (frame
)
7318 Lisp_Object deleted
;
7320 deleted
= unwind_create_frame (frame
);
7321 if (EQ (deleted
, Qt
))
7331 /* Create a frame for a tooltip on the display described by DPYINFO.
7332 PARMS is a list of frame parameters. TEXT is the string to
7333 display in the tip frame. Value is the frame.
7335 Note that functions called here, esp. x_default_parameter can
7336 signal errors, for instance when a specified color name is
7337 undefined. We have to make sure that we're in a consistent state
7338 when this happens. */
7341 x_create_tip_frame (dpyinfo
, parms
, text
)
7342 struct w32_display_info
*dpyinfo
;
7343 Lisp_Object parms
, text
;
7346 Lisp_Object frame
, tem
;
7348 long window_prompting
= 0;
7350 int count
= SPECPDL_INDEX ();
7351 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7353 int face_change_count_before
= face_change_count
;
7355 struct buffer
*old_buffer
;
7359 /* Use this general default value to start with until we know if
7360 this frame has a specified name. */
7361 Vx_resource_name
= Vinvocation_name
;
7364 kb
= dpyinfo
->terminal
->kboard
;
7366 kb
= &the_only_kboard
;
7369 /* Get the name of the frame to use for resource lookup. */
7370 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
7372 && !EQ (name
, Qunbound
)
7374 error ("Invalid frame name--not a string or nil");
7375 Vx_resource_name
= name
;
7378 GCPRO3 (parms
, name
, frame
);
7379 /* Make a frame without minibuffer nor mode-line. */
7381 f
->wants_modeline
= 0;
7382 XSETFRAME (frame
, f
);
7384 buffer
= Fget_buffer_create (build_string (" *tip*"));
7385 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, Qnil
);
7386 old_buffer
= current_buffer
;
7387 set_buffer_internal_1 (XBUFFER (buffer
));
7388 current_buffer
->truncate_lines
= Qnil
;
7389 specbind (Qinhibit_read_only
, Qt
);
7390 specbind (Qinhibit_modification_hooks
, Qt
);
7393 set_buffer_internal_1 (old_buffer
);
7395 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
7396 record_unwind_protect (unwind_create_tip_frame
, frame
);
7398 /* By setting the output method, we're essentially saying that
7399 the frame is live, as per FRAME_LIVE_P. If we get a signal
7400 from this point on, x_destroy_window might screw up reference
7402 f
->terminal
= dpyinfo
->terminal
;
7403 f
->terminal
->reference_count
++;
7404 f
->output_method
= output_w32
;
7405 f
->output_data
.w32
=
7406 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
7407 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
7409 FRAME_FONTSET (f
) = -1;
7410 f
->icon_name
= Qnil
;
7412 #if 0 /* GLYPH_DEBUG TODO: image support. */
7413 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
7414 dpyinfo_refcount
= dpyinfo
->reference_count
;
7415 #endif /* GLYPH_DEBUG */
7417 FRAME_KBOARD (f
) = kb
;
7419 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
7420 f
->output_data
.w32
->explicit_parent
= 0;
7422 /* Set the name; the functions to which we pass f expect the name to
7424 if (EQ (name
, Qunbound
) || NILP (name
))
7426 f
->name
= build_string (dpyinfo
->w32_id_name
);
7427 f
->explicit_name
= 0;
7432 f
->explicit_name
= 1;
7433 /* use the frame's title when getting resources for this frame. */
7434 specbind (Qx_resource_name
, name
);
7437 f
->resx
= dpyinfo
->resx
;
7438 f
->resy
= dpyinfo
->resy
;
7440 #ifdef USE_FONT_BACKEND
7441 if (enable_font_backend
)
7443 /* Perhaps, we must allow frame parameter, say `font-backend',
7444 to specify which font backends to use. */
7445 register_font_driver (&w32font_driver
, f
);
7447 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
7448 "fontBackend", "FontBackend", RES_TYPE_STRING
);
7450 #endif /* USE_FONT_BACKEND */
7452 /* Extract the window parameters from the supplied values
7453 that are needed to determine window geometry. */
7454 #ifdef USE_FONT_BACKEND
7455 if (enable_font_backend
)
7456 x_default_font_parameter (f
, parms
);
7458 #endif /* USE_FONT_BACKEND */
7462 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
7465 /* First, try whatever font the caller has specified. */
7468 tem
= Fquery_fontset (font
, Qnil
);
7470 font
= x_new_fontset (f
, tem
);
7472 font
= x_new_font (f
, SDATA (font
));
7475 /* Try out a font which we hope has bold and italic variations. */
7476 if (!STRINGP (font
))
7477 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
7478 if (! STRINGP (font
))
7479 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
7480 /* If those didn't work, look for something which will at least work. */
7481 if (! STRINGP (font
))
7482 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
7484 if (! STRINGP (font
))
7485 font
= build_string ("Fixedsys");
7487 x_default_parameter (f
, parms
, Qfont
, font
,
7488 "font", "Font", RES_TYPE_STRING
);
7491 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
7492 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
7493 /* This defaults to 2 in order to match xterm. We recognize either
7494 internalBorderWidth or internalBorder (which is what xterm calls
7496 if (NILP (Fassq (Qinternal_border_width
, parms
)))
7500 value
= w32_get_arg (parms
, Qinternal_border_width
,
7501 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
7502 if (! EQ (value
, Qunbound
))
7503 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
7506 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
7507 "internalBorderWidth", "internalBorderWidth",
7510 /* Also do the stuff which must be set before the window exists. */
7511 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
7512 "foreground", "Foreground", RES_TYPE_STRING
);
7513 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
7514 "background", "Background", RES_TYPE_STRING
);
7515 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
7516 "pointerColor", "Foreground", RES_TYPE_STRING
);
7517 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
7518 "cursorColor", "Foreground", RES_TYPE_STRING
);
7519 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
7520 "borderColor", "BorderColor", RES_TYPE_STRING
);
7522 /* Init faces before x_default_parameter is called for scroll-bar
7523 parameters because that function calls x_set_scroll_bar_width,
7524 which calls change_frame_size, which calls Fset_window_buffer,
7525 which runs hooks, which call Fvertical_motion. At the end, we
7526 end up in init_iterator with a null face cache, which should not
7528 init_frame_faces (f
);
7530 f
->output_data
.w32
->dwStyle
= WS_BORDER
| WS_POPUP
| WS_DISABLED
;
7531 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
7533 window_prompting
= x_figure_window_size (f
, parms
, 0);
7535 /* No fringes on tip frame. */
7537 f
->left_fringe_width
= 0;
7538 f
->right_fringe_width
= 0;
7541 my_create_tip_window (f
);
7546 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
7547 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
7548 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
7549 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
7550 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
7551 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
7553 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
7554 Change will not be effected unless different from the current
7556 width
= FRAME_COLS (f
);
7557 height
= FRAME_LINES (f
);
7558 FRAME_LINES (f
) = 0;
7559 SET_FRAME_COLS (f
, 0);
7560 change_frame_size (f
, height
, width
, 1, 0, 0);
7562 /* Add `tooltip' frame parameter's default value. */
7563 if (NILP (Fframe_parameter (frame
, intern ("tooltip"))))
7564 Fmodify_frame_parameters (frame
, Fcons (Fcons (intern ("tooltip"), Qt
),
7567 /* Set up faces after all frame parameters are known. This call
7568 also merges in face attributes specified for new frames.
7570 Frame parameters may be changed if .Xdefaults contains
7571 specifications for the default font. For example, if there is an
7572 `Emacs.default.attributeBackground: pink', the `background-color'
7573 attribute of the frame get's set, which let's the internal border
7574 of the tooltip frame appear in pink. Prevent this. */
7576 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
7578 /* Set tip_frame here, so that */
7580 call1 (Qface_set_after_frame_default
, frame
);
7582 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
7583 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qbackground_color
, bg
),
7591 /* It is now ok to make the frame official even if we get an error
7592 below. And the frame needs to be on Vframe_list or making it
7593 visible won't work. */
7594 Vframe_list
= Fcons (frame
, Vframe_list
);
7596 /* Now that the frame is official, it counts as a reference to
7598 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
7600 /* Setting attributes of faces of the tooltip frame from resources
7601 and similar will increment face_change_count, which leads to the
7602 clearing of all current matrices. Since this isn't necessary
7603 here, avoid it by resetting face_change_count to the value it
7604 had before we created the tip frame. */
7605 face_change_count
= face_change_count_before
;
7607 /* Discard the unwind_protect. */
7608 return unbind_to (count
, frame
);
7612 /* Compute where to display tip frame F. PARMS is the list of frame
7613 parameters for F. DX and DY are specified offsets from the current
7614 location of the mouse. WIDTH and HEIGHT are the width and height
7615 of the tooltip. Return coordinates relative to the root window of
7616 the display in *ROOT_X, and *ROOT_Y. */
7619 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, root_x
, root_y
)
7621 Lisp_Object parms
, dx
, dy
;
7623 int *root_x
, *root_y
;
7625 Lisp_Object left
, top
;
7627 /* User-specified position? */
7628 left
= Fcdr (Fassq (Qleft
, parms
));
7629 top
= Fcdr (Fassq (Qtop
, parms
));
7631 /* Move the tooltip window where the mouse pointer is. Resize and
7633 if (!INTEGERP (left
) || !INTEGERP (top
))
7645 *root_y
= XINT (top
);
7646 else if (*root_y
+ XINT (dy
) <= 0)
7647 *root_y
= 0; /* Can happen for negative dy */
7648 else if (*root_y
+ XINT (dy
) + height
<= FRAME_W32_DISPLAY_INFO (f
)->height
)
7649 /* It fits below the pointer */
7650 *root_y
+= XINT (dy
);
7651 else if (height
+ XINT (dy
) <= *root_y
)
7652 /* It fits above the pointer. */
7653 *root_y
-= height
+ XINT (dy
);
7655 /* Put it on the top. */
7658 if (INTEGERP (left
))
7659 *root_x
= XINT (left
);
7660 else if (*root_x
+ XINT (dx
) <= 0)
7661 *root_x
= 0; /* Can happen for negative dx */
7662 else if (*root_x
+ XINT (dx
) + width
<= FRAME_W32_DISPLAY_INFO (f
)->width
)
7663 /* It fits to the right of the pointer. */
7664 *root_x
+= XINT (dx
);
7665 else if (width
+ XINT (dx
) <= *root_x
)
7666 /* It fits to the left of the pointer. */
7667 *root_x
-= width
+ XINT (dx
);
7669 /* Put it left justified on the screen -- it ought to fit that way. */
7674 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
7675 doc
: /* Show STRING in a \"tooltip\" window on frame FRAME.
7676 A tooltip window is a small window displaying a string.
7678 This is an internal function; Lisp code should call `tooltip-show'.
7680 FRAME nil or omitted means use the selected frame.
7682 PARMS is an optional list of frame parameters which can be
7683 used to change the tooltip's appearance.
7685 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
7686 means use the default timeout of 5 seconds.
7688 If the list of frame parameters PARMS contains a `left' parameter,
7689 the tooltip is displayed at that x-position. Otherwise it is
7690 displayed at the mouse position, with offset DX added (default is 5 if
7691 DX isn't specified). Likewise for the y-position; if a `top' frame
7692 parameter is specified, it determines the y-position of the tooltip
7693 window, otherwise it is displayed at the mouse position, with offset
7694 DY added (default is -10).
7696 A tooltip's maximum size is specified by `x-max-tooltip-size'.
7697 Text larger than the specified size is clipped. */)
7698 (string
, frame
, parms
, timeout
, dx
, dy
)
7699 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
7704 struct buffer
*old_buffer
;
7705 struct text_pos pos
;
7706 int i
, width
, height
;
7707 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7708 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7709 int count
= SPECPDL_INDEX ();
7711 specbind (Qinhibit_redisplay
, Qt
);
7713 GCPRO4 (string
, parms
, frame
, timeout
);
7715 CHECK_STRING (string
);
7716 f
= check_x_frame (frame
);
7718 timeout
= make_number (5);
7720 CHECK_NATNUM (timeout
);
7723 dx
= make_number (5);
7728 dy
= make_number (-10);
7732 if (NILP (last_show_tip_args
))
7733 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
7735 if (!NILP (tip_frame
))
7737 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
7738 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
7739 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
7741 if (EQ (frame
, last_frame
)
7742 && !NILP (Fequal (last_string
, string
))
7743 && !NILP (Fequal (last_parms
, parms
)))
7745 struct frame
*f
= XFRAME (tip_frame
);
7747 /* Only DX and DY have changed. */
7748 if (!NILP (tip_timer
))
7750 Lisp_Object timer
= tip_timer
;
7752 call1 (Qcancel_timer
, timer
);
7756 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
7757 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
7759 /* Put tooltip in topmost group and in position. */
7760 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
7761 root_x
, root_y
, 0, 0,
7762 SWP_NOSIZE
| SWP_NOACTIVATE
);
7764 /* Ensure tooltip is on top of other topmost windows (eg menus). */
7765 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
7767 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
7774 /* Hide a previous tip, if any. */
7777 ASET (last_show_tip_args
, 0, string
);
7778 ASET (last_show_tip_args
, 1, frame
);
7779 ASET (last_show_tip_args
, 2, parms
);
7781 /* Add default values to frame parameters. */
7782 if (NILP (Fassq (Qname
, parms
)))
7783 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
7784 if (NILP (Fassq (Qinternal_border_width
, parms
)))
7785 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
7786 if (NILP (Fassq (Qborder_width
, parms
)))
7787 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
7788 if (NILP (Fassq (Qborder_color
, parms
)))
7789 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
7790 if (NILP (Fassq (Qbackground_color
, parms
)))
7791 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
7794 /* Block input until the tip has been fully drawn, to avoid crashes
7795 when drawing tips in menus. */
7798 /* Create a frame for the tooltip, and record it in the global
7799 variable tip_frame. */
7800 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
, string
);
7803 /* Set up the frame's root window. */
7804 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7805 w
->left_col
= w
->top_line
= make_number (0);
7807 if (CONSP (Vx_max_tooltip_size
)
7808 && INTEGERP (XCAR (Vx_max_tooltip_size
))
7809 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
7810 && INTEGERP (XCDR (Vx_max_tooltip_size
))
7811 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
7813 w
->total_cols
= XCAR (Vx_max_tooltip_size
);
7814 w
->total_lines
= XCDR (Vx_max_tooltip_size
);
7818 w
->total_cols
= make_number (80);
7819 w
->total_lines
= make_number (40);
7822 FRAME_TOTAL_COLS (f
) = XINT (w
->total_cols
);
7824 w
->pseudo_window_p
= 1;
7826 /* Display the tooltip text in a temporary buffer. */
7827 old_buffer
= current_buffer
;
7828 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
7829 current_buffer
->truncate_lines
= Qnil
;
7830 clear_glyph_matrix (w
->desired_matrix
);
7831 clear_glyph_matrix (w
->current_matrix
);
7832 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
7833 try_window (FRAME_ROOT_WINDOW (f
), pos
, 0);
7835 /* Compute width and height of the tooltip. */
7837 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
7839 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
7843 /* Stop at the first empty row at the end. */
7844 if (!row
->enabled_p
|| !row
->displays_text_p
)
7847 /* Let the row go over the full width of the frame. */
7848 row
->full_width_p
= 1;
7850 #ifdef TODO /* Investigate why some fonts need more width than is
7851 calculated for some tooltips. */
7852 /* There's a glyph at the end of rows that is use to place
7853 the cursor there. Don't include the width of this glyph. */
7854 if (row
->used
[TEXT_AREA
])
7856 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
7857 row_width
= row
->pixel_width
- last
->pixel_width
;
7861 row_width
= row
->pixel_width
;
7863 /* TODO: find why tips do not draw along baseline as instructed. */
7864 height
+= row
->height
;
7865 width
= max (width
, row_width
);
7868 /* Add the frame's internal border to the width and height the X
7869 window should have. */
7870 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
7871 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
7873 /* Move the tooltip window where the mouse pointer is. Resize and
7875 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
7878 /* Adjust Window size to take border into account. */
7880 rect
.left
= rect
.top
= 0;
7882 rect
.bottom
= height
;
7883 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
7884 FRAME_EXTERNAL_MENU_BAR (f
));
7886 /* Position and size tooltip, and put it in the topmost group.
7887 The add-on of 3 to the 5th argument is a kludge: without it,
7888 some fonts cause the last character of the tip to be truncated,
7889 for some obscure reason. */
7890 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
7891 root_x
, root_y
, rect
.right
- rect
.left
+ 3,
7892 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
);
7894 /* Ensure tooltip is on top of other topmost windows (eg menus). */
7895 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
7897 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
7899 /* Let redisplay know that we have made the frame visible already. */
7900 f
->async_visible
= 1;
7902 ShowWindow (FRAME_W32_WINDOW (f
), SW_SHOWNOACTIVATE
);
7905 /* Draw into the window. */
7906 w
->must_be_updated_p
= 1;
7907 update_single_window (w
, 1);
7911 /* Restore original current buffer. */
7912 set_buffer_internal_1 (old_buffer
);
7913 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7916 /* Let the tip disappear after timeout seconds. */
7917 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
7918 intern ("x-hide-tip"));
7921 return unbind_to (count
, Qnil
);
7925 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
7926 doc
: /* Hide the current tooltip window, if there is any.
7927 Value is t if tooltip was open, nil otherwise. */)
7931 Lisp_Object deleted
, frame
, timer
;
7932 struct gcpro gcpro1
, gcpro2
;
7934 /* Return quickly if nothing to do. */
7935 if (NILP (tip_timer
) && NILP (tip_frame
))
7940 GCPRO2 (frame
, timer
);
7941 tip_frame
= tip_timer
= deleted
= Qnil
;
7943 count
= SPECPDL_INDEX ();
7944 specbind (Qinhibit_redisplay
, Qt
);
7945 specbind (Qinhibit_quit
, Qt
);
7948 call1 (Qcancel_timer
, timer
);
7952 Fdelete_frame (frame
, Qnil
);
7957 return unbind_to (count
, deleted
);
7962 /***********************************************************************
7963 File selection dialog
7964 ***********************************************************************/
7965 extern Lisp_Object Qfile_name_history
;
7967 /* Callback for altering the behaviour of the Open File dialog.
7968 Makes the Filename text field contain "Current Directory" and be
7969 read-only when "Directories" is selected in the filter. This
7970 allows us to work around the fact that the standard Open File
7971 dialog does not support directories. */
7973 file_dialog_callback (hwnd
, msg
, wParam
, lParam
)
7979 if (msg
== WM_NOTIFY
)
7981 OFNOTIFY
* notify
= (OFNOTIFY
*)lParam
;
7982 /* Detect when the Filter dropdown is changed. */
7983 if (notify
->hdr
.code
== CDN_TYPECHANGE
7984 || notify
->hdr
.code
== CDN_INITDONE
)
7986 HWND dialog
= GetParent (hwnd
);
7987 HWND edit_control
= GetDlgItem (dialog
, FILE_NAME_TEXT_FIELD
);
7989 /* Directories is in index 2. */
7990 if (notify
->lpOFN
->nFilterIndex
== 2)
7992 CommDlg_OpenSave_SetControlText (dialog
, FILE_NAME_TEXT_FIELD
,
7993 "Current Directory");
7994 EnableWindow (edit_control
, FALSE
);
7998 /* Don't override default filename on init done. */
7999 if (notify
->hdr
.code
== CDN_TYPECHANGE
)
8000 CommDlg_OpenSave_SetControlText (dialog
,
8001 FILE_NAME_TEXT_FIELD
, "");
8002 EnableWindow (edit_control
, TRUE
);
8009 /* Since we compile with _WIN32_WINNT set to 0x0400 (for NT4 compatibility)
8010 we end up with the old file dialogs. Define a big enough struct for the
8011 new dialog to trick GetOpenFileName into giving us the new dialogs on
8012 Windows 2000 and XP. */
8015 OPENFILENAME real_details
;
8022 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
8023 doc
: /* Read file name, prompting with PROMPT in directory DIR.
8024 Use a file selection dialog.
8025 Select DEFAULT-FILENAME in the dialog's file selection box, if
8026 specified. Ensure that file exists if MUSTMATCH is non-nil.
8027 If ONLY-DIR-P is non-nil, the user can only select directories. */)
8028 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
)
8029 Lisp_Object prompt
, dir
, default_filename
, mustmatch
, only_dir_p
;
8031 struct frame
*f
= SELECTED_FRAME ();
8032 Lisp_Object file
= Qnil
;
8033 int count
= SPECPDL_INDEX ();
8034 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
8035 char filename
[MAX_PATH
+ 1];
8036 char init_dir
[MAX_PATH
+ 1];
8037 int default_filter_index
= 1; /* 1: All Files, 2: Directories only */
8039 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
8040 CHECK_STRING (prompt
);
8043 /* Create the dialog with PROMPT as title, using DIR as initial
8044 directory and using "*" as pattern. */
8045 dir
= Fexpand_file_name (dir
, Qnil
);
8046 strncpy (init_dir
, SDATA (ENCODE_FILE (dir
)), MAX_PATH
);
8047 init_dir
[MAX_PATH
] = '\0';
8048 unixtodos_filename (init_dir
);
8050 if (STRINGP (default_filename
))
8052 char *file_name_only
;
8053 char *full_path_name
= SDATA (ENCODE_FILE (default_filename
));
8055 unixtodos_filename (full_path_name
);
8057 file_name_only
= strrchr (full_path_name
, '\\');
8058 if (!file_name_only
)
8059 file_name_only
= full_path_name
;
8063 strncpy (filename
, file_name_only
, MAX_PATH
);
8064 filename
[MAX_PATH
] = '\0';
8070 NEWOPENFILENAME new_file_details
;
8071 BOOL file_opened
= FALSE
;
8072 OPENFILENAME
* file_details
= &new_file_details
.real_details
;
8074 /* Prevent redisplay. */
8075 specbind (Qinhibit_redisplay
, Qt
);
8078 bzero (&new_file_details
, sizeof (new_file_details
));
8079 /* Apparently NT4 crashes if you give it an unexpected size.
8080 I'm not sure about Windows 9x, so play it safe. */
8081 if (w32_major_version
> 4 && w32_major_version
< 95)
8082 file_details
->lStructSize
= sizeof (NEWOPENFILENAME
);
8084 file_details
->lStructSize
= sizeof (OPENFILENAME
);
8086 file_details
->hwndOwner
= FRAME_W32_WINDOW (f
);
8087 /* Undocumented Bug in Common File Dialog:
8088 If a filter is not specified, shell links are not resolved. */
8089 file_details
->lpstrFilter
= "All Files (*.*)\0*.*\0Directories\0*|*\0\0";
8090 file_details
->lpstrFile
= filename
;
8091 file_details
->nMaxFile
= sizeof (filename
);
8092 file_details
->lpstrInitialDir
= init_dir
;
8093 file_details
->lpstrTitle
= SDATA (prompt
);
8095 if (! NILP (only_dir_p
))
8096 default_filter_index
= 2;
8098 file_details
->nFilterIndex
= default_filter_index
;
8100 file_details
->Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
8101 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
8102 if (!NILP (mustmatch
))
8104 /* Require that the path to the parent directory exists. */
8105 file_details
->Flags
|= OFN_PATHMUSTEXIST
;
8106 /* If we are looking for a file, require that it exists. */
8107 if (NILP (only_dir_p
))
8108 file_details
->Flags
|= OFN_FILEMUSTEXIST
;
8111 file_details
->lpfnHook
= (LPOFNHOOKPROC
) file_dialog_callback
;
8113 file_opened
= GetOpenFileName (file_details
);
8119 dostounix_filename (filename
);
8121 if (file_details
->nFilterIndex
== 2)
8123 /* "Directories" selected - strip dummy file name. */
8124 char * last
= strrchr (filename
, '/');
8128 file
= DECODE_FILE(build_string (filename
));
8130 /* User cancelled the dialog without making a selection. */
8131 else if (!CommDlgExtendedError ())
8133 /* An error occurred, fallback on reading from the mini-buffer. */
8135 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
8136 dir
, mustmatch
, dir
, Qfile_name_history
,
8137 default_filename
, Qnil
);
8139 file
= unbind_to (count
, file
);
8144 /* Make "Cancel" equivalent to C-g. */
8146 Fsignal (Qquit
, Qnil
);
8148 return unbind_to (count
, file
);
8153 /***********************************************************************
8154 w32 specialized functions
8155 ***********************************************************************/
8157 DEFUN ("w32-select-font", Fw32_select_font
, Sw32_select_font
, 0, 2, 0,
8158 doc
: /* Select a font for the named FRAME using the W32 font dialog.
8159 Returns an X-style font string corresponding to the selection.
8161 If FRAME is omitted or nil, it defaults to the selected frame.
8162 If INCLUDE-PROPORTIONAL is non-nil, include proportional fonts
8163 in the font selection dialog. */)
8164 (frame
, include_proportional
)
8165 Lisp_Object frame
, include_proportional
;
8167 FRAME_PTR f
= check_x_frame (frame
);
8175 bzero (&cf
, sizeof (cf
));
8176 bzero (&lf
, sizeof (lf
));
8178 cf
.lStructSize
= sizeof (cf
);
8179 cf
.hwndOwner
= FRAME_W32_WINDOW (f
);
8180 cf
.Flags
= CF_FORCEFONTEXIST
| CF_SCREENFONTS
| CF_NOVERTFONTS
;
8182 /* Unless include_proportional is non-nil, limit the selection to
8183 monospaced fonts. */
8184 if (NILP (include_proportional
))
8185 cf
.Flags
|= CF_FIXEDPITCHONLY
;
8189 /* Initialize as much of the font details as we can from the current
8191 hdc
= GetDC (FRAME_W32_WINDOW (f
));
8192 oldobj
= SelectObject (hdc
, FRAME_FONT (f
)->hfont
);
8193 GetTextFace (hdc
, LF_FACESIZE
, lf
.lfFaceName
);
8194 if (GetTextMetrics (hdc
, &tm
))
8196 lf
.lfHeight
= tm
.tmInternalLeading
- tm
.tmHeight
;
8197 lf
.lfWeight
= tm
.tmWeight
;
8198 lf
.lfItalic
= tm
.tmItalic
;
8199 lf
.lfUnderline
= tm
.tmUnderlined
;
8200 lf
.lfStrikeOut
= tm
.tmStruckOut
;
8201 lf
.lfCharSet
= tm
.tmCharSet
;
8202 cf
.Flags
|= CF_INITTOLOGFONTSTRUCT
;
8204 SelectObject (hdc
, oldobj
);
8205 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
8207 if (!ChooseFont (&cf
) || !w32_to_x_font (&lf
, buf
, 100, NULL
))
8210 return build_string (buf
);
8213 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
,
8214 Sw32_send_sys_command
, 1, 2, 0,
8215 doc
: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND.
8216 Some useful values for COMMAND are #xf030 to maximize frame (#xf020
8217 to minimize), #xf120 to restore frame to original size, and #xf100
8218 to activate the menubar for keyboard access. #xf140 activates the
8219 screen saver if defined.
8221 If optional parameter FRAME is not specified, use selected frame. */)
8223 Lisp_Object command
, frame
;
8225 FRAME_PTR f
= check_x_frame (frame
);
8227 CHECK_NUMBER (command
);
8229 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
8234 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
8235 doc
: /* Get Windows to perform OPERATION on DOCUMENT.
8236 This is a wrapper around the ShellExecute system function, which
8237 invokes the application registered to handle OPERATION for DOCUMENT.
8239 OPERATION is either nil or a string that names a supported operation.
8240 What operations can be used depends on the particular DOCUMENT and its
8241 handler application, but typically it is one of the following common
8244 \"open\" - open DOCUMENT, which could be a file, a directory, or an
8245 executable program. If it is an application, that
8246 application is launched in the current buffer's default
8247 directory. Otherwise, the application associated with
8248 DOCUMENT is launched in the buffer's default directory.
8249 \"print\" - print DOCUMENT, which must be a file
8250 \"explore\" - start the Windows Explorer on DOCUMENT
8251 \"edit\" - launch an editor and open DOCUMENT for editing; which
8252 editor is launched depends on the association for the
8254 \"find\" - initiate search starting from DOCUMENT which must specify
8256 nil - invoke the default OPERATION, or \"open\" if default is
8257 not defined or unavailable
8259 DOCUMENT is typically the name of a document file or a URL, but can
8260 also be a program executable to run, or a directory to open in the
8263 If DOCUMENT is a program executable, the optional arg PARAMETERS can
8264 be a string containing command line parameters that will be passed to
8265 the program; otherwise, PARAMETERS should be nil or unspecified.
8267 Second optional argument SHOW-FLAG can be used to control how the
8268 application will be displayed when it is invoked. If SHOW-FLAG is nil
8269 or unspceified, the application is displayed normally, otherwise it is
8270 an integer representing a ShowWindow flag:
8275 6 - start minimized */)
8276 (operation
, document
, parameters
, show_flag
)
8277 Lisp_Object operation
, document
, parameters
, show_flag
;
8279 Lisp_Object current_dir
;
8281 CHECK_STRING (document
);
8283 /* Encode filename and current directory. */
8284 current_dir
= ENCODE_FILE (current_buffer
->directory
);
8285 document
= ENCODE_FILE (document
);
8286 if ((int) ShellExecute (NULL
,
8287 (STRINGP (operation
) ?
8288 SDATA (operation
) : NULL
),
8290 (STRINGP (parameters
) ?
8291 SDATA (parameters
) : NULL
),
8292 SDATA (current_dir
),
8293 (INTEGERP (show_flag
) ?
8294 XINT (show_flag
) : SW_SHOWDEFAULT
))
8297 error ("ShellExecute failed: %s", w32_strerror (0));
8300 /* Lookup virtual keycode from string representing the name of a
8301 non-ascii keystroke into the corresponding virtual key, using
8302 lispy_function_keys. */
8304 lookup_vk_code (char *key
)
8308 for (i
= 0; i
< 256; i
++)
8309 if (lispy_function_keys
[i
] != 0
8310 && strcmp (lispy_function_keys
[i
], key
) == 0)
8316 /* Convert a one-element vector style key sequence to a hot key
8319 w32_parse_hot_key (key
)
8322 /* Copied from Fdefine_key and store_in_keymap. */
8323 register Lisp_Object c
;
8327 struct gcpro gcpro1
;
8331 if (XFASTINT (Flength (key
)) != 1)
8336 c
= Faref (key
, make_number (0));
8338 if (CONSP (c
) && lucid_event_type_list_p (c
))
8339 c
= Fevent_convert_list (c
);
8343 if (! INTEGERP (c
) && ! SYMBOLP (c
))
8344 error ("Key definition is invalid");
8346 /* Work out the base key and the modifiers. */
8349 c
= parse_modifiers (c
);
8350 lisp_modifiers
= XINT (Fcar (Fcdr (c
)));
8354 vk_code
= lookup_vk_code (SDATA (SYMBOL_NAME (c
)));
8356 else if (INTEGERP (c
))
8358 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
8359 /* Many ascii characters are their own virtual key code. */
8360 vk_code
= XINT (c
) & CHARACTERBITS
;
8363 if (vk_code
< 0 || vk_code
> 255)
8366 if ((lisp_modifiers
& meta_modifier
) != 0
8367 && !NILP (Vw32_alt_is_meta
))
8368 lisp_modifiers
|= alt_modifier
;
8370 /* Supply defs missing from mingw32. */
8372 #define MOD_ALT 0x0001
8373 #define MOD_CONTROL 0x0002
8374 #define MOD_SHIFT 0x0004
8375 #define MOD_WIN 0x0008
8378 /* Convert lisp modifiers to Windows hot-key form. */
8379 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
8380 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
8381 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
8382 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
8384 return HOTKEY (vk_code
, w32_modifiers
);
8387 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
,
8388 Sw32_register_hot_key
, 1, 1, 0,
8389 doc
: /* Register KEY as a hot-key combination.
8390 Certain key combinations like Alt-Tab are reserved for system use on
8391 Windows, and therefore are normally intercepted by the system. However,
8392 most of these key combinations can be received by registering them as
8393 hot-keys, overriding their special meaning.
8395 KEY must be a one element key definition in vector form that would be
8396 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta
8397 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper
8398 is always interpreted as the Windows modifier keys.
8400 The return value is the hotkey-id if registered, otherwise nil. */)
8404 key
= w32_parse_hot_key (key
);
8406 if (NILP (Fmemq (key
, w32_grabbed_keys
)))
8408 /* Reuse an empty slot if possible. */
8409 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
8411 /* Safe to add new key to list, even if we have focus. */
8413 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
8415 XSETCAR (item
, key
);
8417 /* Notify input thread about new hot-key definition, so that it
8418 takes effect without needing to switch focus. */
8419 #ifdef USE_LISP_UNION_TYPE
8420 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
8423 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
8431 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
,
8432 Sw32_unregister_hot_key
, 1, 1, 0,
8433 doc
: /* Unregister KEY as a hot-key combination. */)
8439 if (!INTEGERP (key
))
8440 key
= w32_parse_hot_key (key
);
8442 item
= Fmemq (key
, w32_grabbed_keys
);
8446 /* Notify input thread about hot-key definition being removed, so
8447 that it takes effect without needing focus switch. */
8448 #ifdef USE_LISP_UNION_TYPE
8449 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
8450 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
.i
))
8452 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
8453 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
))
8458 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
8465 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
,
8466 Sw32_registered_hot_keys
, 0, 0, 0,
8467 doc
: /* Return list of registered hot-key IDs. */)
8470 return Fcopy_sequence (w32_grabbed_keys
);
8473 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
,
8474 Sw32_reconstruct_hot_key
, 1, 1, 0,
8475 doc
: /* Convert hot-key ID to a lisp key combination.
8476 usage: (w32-reconstruct-hot-key ID) */)
8478 Lisp_Object hotkeyid
;
8480 int vk_code
, w32_modifiers
;
8483 CHECK_NUMBER (hotkeyid
);
8485 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
8486 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
8488 if (lispy_function_keys
[vk_code
])
8489 key
= intern (lispy_function_keys
[vk_code
]);
8491 key
= make_number (vk_code
);
8493 key
= Fcons (key
, Qnil
);
8494 if (w32_modifiers
& MOD_SHIFT
)
8495 key
= Fcons (Qshift
, key
);
8496 if (w32_modifiers
& MOD_CONTROL
)
8497 key
= Fcons (Qctrl
, key
);
8498 if (w32_modifiers
& MOD_ALT
)
8499 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
8500 if (w32_modifiers
& MOD_WIN
)
8501 key
= Fcons (Qhyper
, key
);
8506 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
,
8507 Sw32_toggle_lock_key
, 1, 2, 0,
8508 doc
: /* Toggle the state of the lock key KEY.
8509 KEY can be `capslock', `kp-numlock', or `scroll'.
8510 If the optional parameter NEW-STATE is a number, then the state of KEY
8511 is set to off if the low bit of NEW-STATE is zero, otherwise on. */)
8513 Lisp_Object key
, new_state
;
8517 if (EQ (key
, intern ("capslock")))
8518 vk_code
= VK_CAPITAL
;
8519 else if (EQ (key
, intern ("kp-numlock")))
8520 vk_code
= VK_NUMLOCK
;
8521 else if (EQ (key
, intern ("scroll")))
8522 vk_code
= VK_SCROLL
;
8526 if (!dwWindowsThreadId
)
8527 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
8529 #ifdef USE_LISP_UNION_TYPE
8530 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
8531 (WPARAM
) vk_code
, (LPARAM
) new_state
.i
))
8533 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
8534 (WPARAM
) vk_code
, (LPARAM
) new_state
))
8538 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
8539 return make_number (msg
.wParam
);
8544 DEFUN ("w32-window-exists-p", Fw32_window_exists_p
, Sw32_window_exists_p
,
8546 doc
: /* Return non-nil if a window exists with the specified CLASS and NAME.
8548 This is a direct interface to the Windows API FindWindow function. */)
8550 Lisp_Object
class, name
;
8555 CHECK_STRING (class);
8557 CHECK_STRING (name
);
8559 hnd
= FindWindow (STRINGP (class) ? ((LPCTSTR
) SDATA (class)) : NULL
,
8560 STRINGP (name
) ? ((LPCTSTR
) SDATA (name
)) : NULL
);
8568 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
8569 doc
: /* Return storage information about the file system FILENAME is on.
8570 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
8571 storage of the file system, FREE is the free storage, and AVAIL is the
8572 storage available to a non-superuser. All 3 numbers are in bytes.
8573 If the underlying system call fails, value is nil. */)
8575 Lisp_Object filename
;
8577 Lisp_Object encoded
, value
;
8579 CHECK_STRING (filename
);
8580 filename
= Fexpand_file_name (filename
, Qnil
);
8581 encoded
= ENCODE_FILE (filename
);
8585 /* Determining the required information on Windows turns out, sadly,
8586 to be more involved than one would hope. The original Win32 api
8587 call for this will return bogus information on some systems, but we
8588 must dynamically probe for the replacement api, since that was
8589 added rather late on. */
8591 HMODULE hKernel
= GetModuleHandle ("kernel32");
8592 BOOL (*pfn_GetDiskFreeSpaceEx
)
8593 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
8594 = (void *) GetProcAddress (hKernel
, "GetDiskFreeSpaceEx");
8596 /* On Windows, we may need to specify the root directory of the
8597 volume holding FILENAME. */
8598 char rootname
[MAX_PATH
];
8599 char *name
= SDATA (encoded
);
8601 /* find the root name of the volume if given */
8602 if (isalpha (name
[0]) && name
[1] == ':')
8604 rootname
[0] = name
[0];
8605 rootname
[1] = name
[1];
8609 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
8611 char *str
= rootname
;
8615 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
8625 if (pfn_GetDiskFreeSpaceEx
)
8627 /* Unsigned large integers cannot be cast to double, so
8628 use signed ones instead. */
8629 LARGE_INTEGER availbytes
;
8630 LARGE_INTEGER freebytes
;
8631 LARGE_INTEGER totalbytes
;
8633 if (pfn_GetDiskFreeSpaceEx(rootname
,
8634 (ULARGE_INTEGER
*)&availbytes
,
8635 (ULARGE_INTEGER
*)&totalbytes
,
8636 (ULARGE_INTEGER
*)&freebytes
))
8637 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
8638 make_float ((double) freebytes
.QuadPart
),
8639 make_float ((double) availbytes
.QuadPart
));
8643 DWORD sectors_per_cluster
;
8644 DWORD bytes_per_sector
;
8645 DWORD free_clusters
;
8646 DWORD total_clusters
;
8648 if (GetDiskFreeSpace(rootname
,
8649 §ors_per_cluster
,
8653 value
= list3 (make_float ((double) total_clusters
8654 * sectors_per_cluster
* bytes_per_sector
),
8655 make_float ((double) free_clusters
8656 * sectors_per_cluster
* bytes_per_sector
),
8657 make_float ((double) free_clusters
8658 * sectors_per_cluster
* bytes_per_sector
));
8665 DEFUN ("default-printer-name", Fdefault_printer_name
, Sdefault_printer_name
,
8666 0, 0, 0, doc
: /* Return the name of Windows default printer device. */)
8669 static char pname_buf
[256];
8672 PRINTER_INFO_2
*ppi2
= NULL
;
8673 DWORD dwNeeded
= 0, dwReturned
= 0;
8675 /* Retrieve the default string from Win.ini (the registry).
8676 * String will be in form "printername,drivername,portname".
8677 * This is the most portable way to get the default printer. */
8678 if (GetProfileString ("windows", "device", ",,", pname_buf
, sizeof (pname_buf
)) <= 0)
8680 /* printername precedes first "," character */
8681 strtok (pname_buf
, ",");
8682 /* We want to know more than the printer name */
8683 if (!OpenPrinter (pname_buf
, &hPrn
, NULL
))
8685 GetPrinter (hPrn
, 2, NULL
, 0, &dwNeeded
);
8688 ClosePrinter (hPrn
);
8691 /* Allocate memory for the PRINTER_INFO_2 struct */
8692 ppi2
= (PRINTER_INFO_2
*) xmalloc (dwNeeded
);
8695 ClosePrinter (hPrn
);
8698 /* Call GetPrinter() again with big enouth memory block */
8699 err
= GetPrinter (hPrn
, 2, (LPBYTE
)ppi2
, dwNeeded
, &dwReturned
);
8700 ClosePrinter (hPrn
);
8709 if (ppi2
->Attributes
& PRINTER_ATTRIBUTE_SHARED
&& ppi2
->pServerName
)
8711 /* a remote printer */
8712 if (*ppi2
->pServerName
== '\\')
8713 _snprintf(pname_buf
, sizeof (pname_buf
), "%s\\%s", ppi2
->pServerName
,
8716 _snprintf(pname_buf
, sizeof (pname_buf
), "\\\\%s\\%s", ppi2
->pServerName
,
8718 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
8722 /* a local printer */
8723 strncpy(pname_buf
, ppi2
->pPortName
, sizeof (pname_buf
));
8724 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
8725 /* `pPortName' can include several ports, delimited by ','.
8726 * we only use the first one. */
8727 strtok(pname_buf
, ",");
8732 return build_string (pname_buf
);
8735 /***********************************************************************
8737 ***********************************************************************/
8739 /* Keep this list in the same order as frame_parms in frame.c.
8740 Use 0 for unsupported frame parameters. */
8742 frame_parm_handler w32_frame_parm_handlers
[] =
8746 x_set_background_color
,
8752 x_set_foreground_color
,
8755 x_set_internal_border_width
,
8756 x_set_menu_bar_lines
,
8758 x_explicitly_set_name
,
8759 x_set_scroll_bar_width
,
8762 x_set_vertical_scroll_bars
,
8764 x_set_tool_bar_lines
,
8765 0, /* x_set_scroll_bar_foreground, */
8766 0, /* x_set_scroll_bar_background, */
8771 0, /* x_set_wait_for_wm, */
8773 #ifdef USE_FONT_BACKEND
8781 globals_of_w32fns ();
8782 /* This is zero if not using MS-Windows. */
8784 track_mouse_window
= NULL
;
8786 w32_visible_system_caret_hwnd
= NULL
;
8788 DEFSYM (Qnone
, "none");
8789 DEFSYM (Qsuppress_icon
, "suppress-icon");
8790 DEFSYM (Qundefined_color
, "undefined-color");
8791 DEFSYM (Qcancel_timer
, "cancel-timer");
8792 DEFSYM (Qhyper
, "hyper");
8793 DEFSYM (Qsuper
, "super");
8794 DEFSYM (Qmeta
, "meta");
8795 DEFSYM (Qalt
, "alt");
8796 DEFSYM (Qctrl
, "ctrl");
8797 DEFSYM (Qcontrol
, "control");
8798 DEFSYM (Qshift
, "shift");
8799 /* This is the end of symbol initialization. */
8801 /* Text property `display' should be nonsticky by default. */
8802 Vtext_property_default_nonsticky
8803 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
8806 Fput (Qundefined_color
, Qerror_conditions
,
8807 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
8808 Fput (Qundefined_color
, Qerror_message
,
8809 build_string ("Undefined color"));
8811 staticpro (&w32_grabbed_keys
);
8812 w32_grabbed_keys
= Qnil
;
8814 DEFVAR_LISP ("w32-color-map", &Vw32_color_map
,
8815 doc
: /* An array of color name mappings for Windows. */);
8816 Vw32_color_map
= Qnil
;
8818 DEFVAR_LISP ("w32-pass-alt-to-system", &Vw32_pass_alt_to_system
,
8819 doc
: /* Non-nil if Alt key presses are passed on to Windows.
8820 When non-nil, for example, Alt pressed and released and then space will
8821 open the System menu. When nil, Emacs processes the Alt key events, and
8822 then silently swallows them. */);
8823 Vw32_pass_alt_to_system
= Qnil
;
8825 DEFVAR_LISP ("w32-alt-is-meta", &Vw32_alt_is_meta
,
8826 doc
: /* Non-nil if the Alt key is to be considered the same as the META key.
8827 When nil, Emacs will translate the Alt key to the ALT modifier, not to META. */);
8828 Vw32_alt_is_meta
= Qt
;
8830 DEFVAR_INT ("w32-quit-key", &w32_quit_key
,
8831 doc
: /* If non-zero, the virtual key code for an alternative quit key. */);
8834 DEFVAR_LISP ("w32-pass-lwindow-to-system",
8835 &Vw32_pass_lwindow_to_system
,
8836 doc
: /* If non-nil, the left \"Windows\" key is passed on to Windows.
8838 When non-nil, the Start menu is opened by tapping the key.
8839 If you set this to nil, the left \"Windows\" key is processed by Emacs
8840 according to the value of `w32-lwindow-modifier', which see.
8842 Note that some combinations of the left \"Windows\" key with other keys are
8843 caught by Windows at low level, and so binding them in Emacs will have no
8844 effect. For example, <lwindow>-r always pops up the Windows Run dialog,
8845 <lwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
8846 the doc string of `w32-phantom-key-code'. */);
8847 Vw32_pass_lwindow_to_system
= Qt
;
8849 DEFVAR_LISP ("w32-pass-rwindow-to-system",
8850 &Vw32_pass_rwindow_to_system
,
8851 doc
: /* If non-nil, the right \"Windows\" key is passed on to Windows.
8853 When non-nil, the Start menu is opened by tapping the key.
8854 If you set this to nil, the right \"Windows\" key is processed by Emacs
8855 according to the value of `w32-rwindow-modifier', which see.
8857 Note that some combinations of the right \"Windows\" key with other keys are
8858 caught by Windows at low level, and so binding them in Emacs will have no
8859 effect. For example, <rwindow>-r always pops up the Windows Run dialog,
8860 <rwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
8861 the doc string of `w32-phantom-key-code'. */);
8862 Vw32_pass_rwindow_to_system
= Qt
;
8864 DEFVAR_LISP ("w32-phantom-key-code",
8865 &Vw32_phantom_key_code
,
8866 doc
: /* Virtual key code used to generate \"phantom\" key presses.
8867 Value is a number between 0 and 255.
8869 Phantom key presses are generated in order to stop the system from
8870 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or
8871 `w32-pass-rwindow-to-system' is nil. */);
8872 /* Although 255 is technically not a valid key code, it works and
8873 means that this hack won't interfere with any real key code. */
8874 XSETINT (Vw32_phantom_key_code
, 255);
8876 DEFVAR_LISP ("w32-enable-num-lock",
8877 &Vw32_enable_num_lock
,
8878 doc
: /* If non-nil, the Num Lock key acts normally.
8879 Set to nil to handle Num Lock as the `kp-numlock' key. */);
8880 Vw32_enable_num_lock
= Qt
;
8882 DEFVAR_LISP ("w32-enable-caps-lock",
8883 &Vw32_enable_caps_lock
,
8884 doc
: /* If non-nil, the Caps Lock key acts normally.
8885 Set to nil to handle Caps Lock as the `capslock' key. */);
8886 Vw32_enable_caps_lock
= Qt
;
8888 DEFVAR_LISP ("w32-scroll-lock-modifier",
8889 &Vw32_scroll_lock_modifier
,
8890 doc
: /* Modifier to use for the Scroll Lock ON state.
8891 The value can be hyper, super, meta, alt, control or shift for the
8892 respective modifier, or nil to handle Scroll Lock as the `scroll' key.
8893 Any other value will cause the Scroll Lock key to be ignored. */);
8894 Vw32_scroll_lock_modifier
= Qt
;
8896 DEFVAR_LISP ("w32-lwindow-modifier",
8897 &Vw32_lwindow_modifier
,
8898 doc
: /* Modifier to use for the left \"Windows\" key.
8899 The value can be hyper, super, meta, alt, control or shift for the
8900 respective modifier, or nil to appear as the `lwindow' key.
8901 Any other value will cause the key to be ignored. */);
8902 Vw32_lwindow_modifier
= Qnil
;
8904 DEFVAR_LISP ("w32-rwindow-modifier",
8905 &Vw32_rwindow_modifier
,
8906 doc
: /* Modifier to use for the right \"Windows\" key.
8907 The value can be hyper, super, meta, alt, control or shift for the
8908 respective modifier, or nil to appear as the `rwindow' key.
8909 Any other value will cause the key to be ignored. */);
8910 Vw32_rwindow_modifier
= Qnil
;
8912 DEFVAR_LISP ("w32-apps-modifier",
8913 &Vw32_apps_modifier
,
8914 doc
: /* Modifier to use for the \"Apps\" key.
8915 The value can be hyper, super, meta, alt, control or shift for the
8916 respective modifier, or nil to appear as the `apps' key.
8917 Any other value will cause the key to be ignored. */);
8918 Vw32_apps_modifier
= Qnil
;
8920 DEFVAR_BOOL ("w32-enable-synthesized-fonts", &w32_enable_synthesized_fonts
,
8921 doc
: /* Non-nil enables selection of artificially italicized and bold fonts. */);
8922 w32_enable_synthesized_fonts
= 0;
8924 DEFVAR_LISP ("w32-enable-palette", &Vw32_enable_palette
,
8925 doc
: /* Non-nil enables Windows palette management to map colors exactly. */);
8926 Vw32_enable_palette
= Qt
;
8928 DEFVAR_INT ("w32-mouse-button-tolerance",
8929 &w32_mouse_button_tolerance
,
8930 doc
: /* Analogue of double click interval for faking middle mouse events.
8931 The value is the minimum time in milliseconds that must elapse between
8932 left and right button down events before they are considered distinct events.
8933 If both mouse buttons are depressed within this interval, a middle mouse
8934 button down event is generated instead. */);
8935 w32_mouse_button_tolerance
= GetDoubleClickTime () / 2;
8937 DEFVAR_INT ("w32-mouse-move-interval",
8938 &w32_mouse_move_interval
,
8939 doc
: /* Minimum interval between mouse move events.
8940 The value is the minimum time in milliseconds that must elapse between
8941 successive mouse move (or scroll bar drag) events before they are
8942 reported as lisp events. */);
8943 w32_mouse_move_interval
= 0;
8945 DEFVAR_BOOL ("w32-pass-extra-mouse-buttons-to-system",
8946 &w32_pass_extra_mouse_buttons_to_system
,
8947 doc
: /* If non-nil, the fourth and fifth mouse buttons are passed to Windows.
8948 Recent versions of Windows support mice with up to five buttons.
8949 Since most applications don't support these extra buttons, most mouse
8950 drivers will allow you to map them to functions at the system level.
8951 If this variable is non-nil, Emacs will pass them on, allowing the
8952 system to handle them. */);
8953 w32_pass_extra_mouse_buttons_to_system
= 0;
8955 DEFVAR_BOOL ("w32-pass-multimedia-buttons-to-system",
8956 &w32_pass_multimedia_buttons_to_system
,
8957 doc
: /* If non-nil, media buttons are passed to Windows.
8958 Some modern keyboards contain buttons for controlling media players, web
8959 browsers and other applications. Generally these buttons are handled on a
8960 system wide basis, but by setting this to nil they are made available
8961 to Emacs for binding. Depending on your keyboard, additional keys that
8962 may be available are:
8964 browser-back, browser-forward, browser-refresh, browser-stop,
8965 browser-search, browser-favorites, browser-home,
8966 mail, mail-reply, mail-forward, mail-send,
8968 help, find, new, open, close, save, print, undo, redo, copy, cut, paste,
8969 spell-check, correction-list, toggle-dictate-command,
8970 media-next, media-previous, media-stop, media-play-pause, media-select,
8971 media-play, media-pause, media-record, media-fast-forward, media-rewind,
8972 media-channel-up, media-channel-down,
8973 volume-mute, volume-up, volume-down,
8974 mic-volume-mute, mic-volume-down, mic-volume-up, mic-toggle,
8975 bass-down, bass-boost, bass-up, treble-down, treble-up
8977 w32_pass_multimedia_buttons_to_system
= 1;
8979 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
8980 doc
: /* The shape of the pointer when over text.
8981 Changing the value does not affect existing frames
8982 unless you set the mouse color. */);
8983 Vx_pointer_shape
= Qnil
;
8985 Vx_nontext_pointer_shape
= Qnil
;
8987 Vx_mode_pointer_shape
= Qnil
;
8989 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
8990 doc
: /* The shape of the pointer when Emacs is busy.
8991 This variable takes effect when you create a new frame
8992 or when you set the mouse color. */);
8993 Vx_hourglass_pointer_shape
= Qnil
;
8995 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
8996 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
8997 display_hourglass_p
= 1;
8999 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
9000 doc
: /* *Seconds to wait before displaying an hourglass pointer.
9001 Value must be an integer or float. */);
9002 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
9004 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
9005 &Vx_sensitive_text_pointer_shape
,
9006 doc
: /* The shape of the pointer when over mouse-sensitive text.
9007 This variable takes effect when you create a new frame
9008 or when you set the mouse color. */);
9009 Vx_sensitive_text_pointer_shape
= Qnil
;
9011 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
9012 &Vx_window_horizontal_drag_shape
,
9013 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
9014 This variable takes effect when you create a new frame
9015 or when you set the mouse color. */);
9016 Vx_window_horizontal_drag_shape
= Qnil
;
9018 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
9019 doc
: /* A string indicating the foreground color of the cursor box. */);
9020 Vx_cursor_fore_pixel
= Qnil
;
9022 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size
,
9023 doc
: /* Maximum size for tooltips.
9024 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
9025 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
9027 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
9028 doc
: /* Non-nil if no window manager is in use.
9029 Emacs doesn't try to figure this out; this is always nil
9030 unless you set it to something else. */);
9031 /* We don't have any way to find this out, so set it to nil
9032 and maybe the user would like to set it to t. */
9033 Vx_no_window_manager
= Qnil
;
9035 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
9036 &Vx_pixel_size_width_font_regexp
,
9037 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
9039 Since Emacs gets width of a font matching with this regexp from
9040 PIXEL_SIZE field of the name, font finding mechanism gets faster for
9041 such a font. This is especially effective for such large fonts as
9042 Chinese, Japanese, and Korean. */);
9043 Vx_pixel_size_width_font_regexp
= Qnil
;
9045 DEFVAR_LISP ("w32-bdf-filename-alist",
9046 &Vw32_bdf_filename_alist
,
9047 doc
: /* List of bdf fonts and their corresponding filenames. */);
9048 Vw32_bdf_filename_alist
= Qnil
;
9050 DEFVAR_BOOL ("w32-strict-fontnames",
9051 &w32_strict_fontnames
,
9052 doc
: /* Non-nil means only use fonts that are exact matches for those requested.
9053 Default is nil, which allows old fontnames that are not XLFD compliant,
9054 and allows third-party CJK display to work by specifying false charset
9055 fields to trick Emacs into translating to Big5, SJIS etc.
9056 Setting this to t will prevent wrong fonts being selected when
9057 fontsets are automatically created. */);
9058 w32_strict_fontnames
= 0;
9060 DEFVAR_BOOL ("w32-strict-painting",
9061 &w32_strict_painting
,
9062 doc
: /* Non-nil means use strict rules for repainting frames.
9063 Set this to nil to get the old behavior for repainting; this should
9064 only be necessary if the default setting causes problems. */);
9065 w32_strict_painting
= 1;
9067 DEFVAR_LISP ("w32-charset-info-alist",
9068 &Vw32_charset_info_alist
,
9069 doc
: /* Alist linking Emacs character sets to Windows fonts and codepages.
9070 Each entry should be of the form:
9072 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE))
9074 where CHARSET_NAME is a string used in font names to identify the charset,
9075 WINDOWS_CHARSET is a symbol that can be one of:
9076 w32-charset-ansi, w32-charset-default, w32-charset-symbol,
9077 w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312,
9078 w32-charset-chinesebig5,
9079 w32-charset-johab, w32-charset-hebrew,
9080 w32-charset-arabic, w32-charset-greek, w32-charset-turkish,
9081 w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope,
9082 w32-charset-russian, w32-charset-mac, w32-charset-baltic,
9083 w32-charset-unicode,
9085 CODEPAGE should be an integer specifying the codepage that should be used
9086 to display the character set, t to do no translation and output as Unicode,
9087 or nil to do no translation and output as 8 bit (or multibyte on far-east
9088 versions of Windows) characters. */);
9089 Vw32_charset_info_alist
= Qnil
;
9091 DEFSYM (Qw32_charset_ansi
, "w32-charset-ansi");
9092 DEFSYM (Qw32_charset_symbol
, "w32-charset-symbol");
9093 DEFSYM (Qw32_charset_default
, "w32-charset-default");
9094 DEFSYM (Qw32_charset_shiftjis
, "w32-charset-shiftjis");
9095 DEFSYM (Qw32_charset_hangeul
, "w32-charset-hangeul");
9096 DEFSYM (Qw32_charset_chinesebig5
, "w32-charset-chinesebig5");
9097 DEFSYM (Qw32_charset_gb2312
, "w32-charset-gb2312");
9098 DEFSYM (Qw32_charset_oem
, "w32-charset-oem");
9100 #ifdef JOHAB_CHARSET
9102 static int w32_extra_charsets_defined
= 1;
9103 DEFVAR_BOOL ("w32-extra-charsets-defined", &w32_extra_charsets_defined
,
9104 doc
: /* Internal variable. */);
9106 DEFSYM (Qw32_charset_johab
, "w32-charset-johab");
9107 DEFSYM (Qw32_charset_easteurope
, "w32-charset-easteurope");
9108 DEFSYM (Qw32_charset_turkish
, "w32-charset-turkish");
9109 DEFSYM (Qw32_charset_baltic
, "w32-charset-baltic");
9110 DEFSYM (Qw32_charset_russian
, "w32-charset-russian");
9111 DEFSYM (Qw32_charset_arabic
, "w32-charset-arabic");
9112 DEFSYM (Qw32_charset_greek
, "w32-charset-greek");
9113 DEFSYM (Qw32_charset_hebrew
, "w32-charset-hebrew");
9114 DEFSYM (Qw32_charset_vietnamese
, "w32-charset-vietnamese");
9115 DEFSYM (Qw32_charset_thai
, "w32-charset-thai");
9116 DEFSYM (Qw32_charset_mac
, "w32-charset-mac");
9120 #ifdef UNICODE_CHARSET
9122 static int w32_unicode_charset_defined
= 1;
9123 DEFVAR_BOOL ("w32-unicode-charset-defined",
9124 &w32_unicode_charset_defined
,
9125 doc
: /* Internal variable. */);
9126 DEFSYM (Qw32_charset_unicode
, "w32-charset-unicode");
9130 #if 0 /* TODO: Port to W32 */
9131 defsubr (&Sx_change_window_property
);
9132 defsubr (&Sx_delete_window_property
);
9133 defsubr (&Sx_window_property
);
9135 defsubr (&Sxw_display_color_p
);
9136 defsubr (&Sx_display_grayscale_p
);
9137 defsubr (&Sxw_color_defined_p
);
9138 defsubr (&Sxw_color_values
);
9139 defsubr (&Sx_server_max_request_size
);
9140 defsubr (&Sx_server_vendor
);
9141 defsubr (&Sx_server_version
);
9142 defsubr (&Sx_display_pixel_width
);
9143 defsubr (&Sx_display_pixel_height
);
9144 defsubr (&Sx_display_mm_width
);
9145 defsubr (&Sx_display_mm_height
);
9146 defsubr (&Sx_display_screens
);
9147 defsubr (&Sx_display_planes
);
9148 defsubr (&Sx_display_color_cells
);
9149 defsubr (&Sx_display_visual_class
);
9150 defsubr (&Sx_display_backing_store
);
9151 defsubr (&Sx_display_save_under
);
9152 defsubr (&Sx_create_frame
);
9153 defsubr (&Sx_open_connection
);
9154 defsubr (&Sx_close_connection
);
9155 defsubr (&Sx_display_list
);
9156 defsubr (&Sx_synchronize
);
9157 defsubr (&Sx_focus_frame
);
9159 /* W32 specific functions */
9161 defsubr (&Sw32_select_font
);
9162 defsubr (&Sw32_define_rgb_color
);
9163 defsubr (&Sw32_default_color_map
);
9164 defsubr (&Sw32_load_color_file
);
9165 defsubr (&Sw32_send_sys_command
);
9166 defsubr (&Sw32_shell_execute
);
9167 defsubr (&Sw32_register_hot_key
);
9168 defsubr (&Sw32_unregister_hot_key
);
9169 defsubr (&Sw32_registered_hot_keys
);
9170 defsubr (&Sw32_reconstruct_hot_key
);
9171 defsubr (&Sw32_toggle_lock_key
);
9172 defsubr (&Sw32_window_exists_p
);
9173 defsubr (&Sw32_find_bdf_fonts
);
9175 defsubr (&Sfile_system_info
);
9176 defsubr (&Sdefault_printer_name
);
9178 /* Setting callback functions for fontset handler. */
9179 get_font_info_func
= w32_get_font_info
;
9181 #if 0 /* This function pointer doesn't seem to be used anywhere.
9182 And the pointer assigned has the wrong type, anyway. */
9183 list_fonts_func
= w32_list_fonts
;
9186 load_font_func
= w32_load_font
;
9187 find_ccl_program_func
= w32_find_ccl_program
;
9188 query_font_func
= w32_query_font
;
9189 set_frame_fontset_func
= x_set_font
;
9190 get_font_repertory_func
= x_get_font_repertory
;
9191 check_window_system_func
= check_w32
;
9194 hourglass_atimer
= NULL
;
9195 hourglass_shown_p
= 0;
9196 defsubr (&Sx_show_tip
);
9197 defsubr (&Sx_hide_tip
);
9199 staticpro (&tip_timer
);
9201 staticpro (&tip_frame
);
9203 last_show_tip_args
= Qnil
;
9204 staticpro (&last_show_tip_args
);
9206 defsubr (&Sx_file_dialog
);
9211 globals_of_w32fns is used to initialize those global variables that
9212 must always be initialized on startup even when the global variable
9213 initialized is non zero (see the function main in emacs.c).
9214 globals_of_w32fns is called from syms_of_w32fns when the global
9215 variable initialized is 0 and directly from main when initialized
9218 void globals_of_w32fns ()
9220 HMODULE user32_lib
= GetModuleHandle ("user32.dll");
9222 TrackMouseEvent not available in all versions of Windows, so must load
9223 it dynamically. Do it once, here, instead of every time it is used.
9225 track_mouse_event_fn
= (TrackMouseEvent_Proc
)
9226 GetProcAddress (user32_lib
, "TrackMouseEvent");
9227 /* ditto for GetClipboardSequenceNumber. */
9228 clipboard_sequence_fn
= (ClipboardSequence_Proc
)
9229 GetProcAddress (user32_lib
, "GetClipboardSequenceNumber");
9231 DEFVAR_INT ("w32-ansi-code-page",
9232 &w32_ansi_code_page
,
9233 doc
: /* The ANSI code page used by the system. */);
9234 w32_ansi_code_page
= GetACP ();
9236 /* MessageBox does not work without this when linked to comctl32.dll 6.0. */
9237 InitCommonControls ();
9246 button
= MessageBox (NULL
,
9247 "A fatal error has occurred!\n\n"
9248 "Would you like to attach a debugger?\n\n"
9249 "Select YES to debug, NO to abort Emacs"
9251 "\n\n(type \"gdb -p <emacs-PID>\" and\n"
9252 "\"continue\" inside GDB before clicking YES.)"
9254 , "Emacs Abort Dialog",
9255 MB_ICONEXCLAMATION
| MB_TASKMODAL
9256 | MB_SETFOREGROUND
| MB_YESNO
);
9261 exit (2); /* tell the compiler we will never return */
9269 /* For convenience when debugging. */
9273 return GetLastError ();
9276 /* arch-tag: 707589ab-b9be-4638-8cdd-74629cc9b446
9277 (do not change this comment) */