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 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 2, 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 */
33 #include "dispextern.h"
40 #include "intervals.h"
41 #include "blockinput.h"
44 #include "termhooks.h"
49 #include "bitmaps/gray.xbm"
57 #define FILE_NAME_TEXT_FIELD edt1
59 void syms_of_w32fns ();
60 void globals_of_w32fns ();
62 extern void free_frame_menubar ();
63 extern double atof ();
64 extern int w32_console_toggle_lock_key
P_ ((int, Lisp_Object
));
65 extern void w32_menu_display_help
P_ ((HWND
, HMENU
, UINT
, UINT
));
66 extern void w32_free_menu_strings
P_ ((HWND
));
67 extern XCharStruct
*w32_per_char_metric
P_ ((XFontStruct
*, wchar_t *, int));
71 extern char *lispy_function_keys
[];
73 /* The gray bitmap `bitmaps/gray'. This is done because w32term.c uses
74 it, and including `bitmaps/gray' more than once is a problem when
75 config.h defines `static' as an empty replacement string. */
77 int gray_bitmap_width
= gray_width
;
78 int gray_bitmap_height
= gray_height
;
79 unsigned char *gray_bitmap_bits
= gray_bits
;
81 /* The colormap for converting color names to RGB values */
82 Lisp_Object Vw32_color_map
;
84 /* Non nil if alt key presses are passed on to Windows. */
85 Lisp_Object Vw32_pass_alt_to_system
;
87 /* Non nil if alt key is translated to meta_modifier, nil if it is translated
89 Lisp_Object Vw32_alt_is_meta
;
91 /* If non-zero, the windows virtual key code for an alternative quit key. */
94 /* Non nil if left window key events are passed on to Windows (this only
95 affects whether "tapping" the key opens the Start menu). */
96 Lisp_Object Vw32_pass_lwindow_to_system
;
98 /* Non nil if right window key events are passed on to Windows (this
99 only affects whether "tapping" the key opens the Start menu). */
100 Lisp_Object Vw32_pass_rwindow_to_system
;
102 /* Virtual key code used to generate "phantom" key presses in order
103 to stop system from acting on Windows key events. */
104 Lisp_Object Vw32_phantom_key_code
;
106 /* Modifier associated with the left "Windows" key, or nil to act as a
108 Lisp_Object Vw32_lwindow_modifier
;
110 /* Modifier associated with the right "Windows" key, or nil to act as a
112 Lisp_Object Vw32_rwindow_modifier
;
114 /* Modifier associated with the "Apps" key, or nil to act as a normal
116 Lisp_Object Vw32_apps_modifier
;
118 /* Value is nil if Num Lock acts as a function key. */
119 Lisp_Object Vw32_enable_num_lock
;
121 /* Value is nil if Caps Lock acts as a function key. */
122 Lisp_Object Vw32_enable_caps_lock
;
124 /* Modifier associated with Scroll Lock, or nil to act as a normal key. */
125 Lisp_Object Vw32_scroll_lock_modifier
;
127 /* Switch to control whether we inhibit requests for synthesized bold
128 and italic versions of fonts. */
129 int w32_enable_synthesized_fonts
;
131 /* Enable palette management. */
132 Lisp_Object Vw32_enable_palette
;
134 /* Control how close left/right button down events must be to
135 be converted to a middle button down event. */
136 int w32_mouse_button_tolerance
;
138 /* Minimum interval between mouse movement (and scroll bar drag)
139 events that are passed on to the event loop. */
140 int w32_mouse_move_interval
;
142 /* Flag to indicate if XBUTTON events should be passed on to Windows. */
143 int w32_pass_extra_mouse_buttons_to_system
;
145 /* Non nil if no window manager is in use. */
146 Lisp_Object Vx_no_window_manager
;
148 /* Non-zero means we're allowed to display a hourglass pointer. */
150 int display_hourglass_p
;
152 /* The background and shape of the mouse pointer, and shape when not
153 over text or in the modeline. */
155 Lisp_Object Vx_pointer_shape
, Vx_nontext_pointer_shape
, Vx_mode_pointer_shape
;
156 Lisp_Object Vx_hourglass_pointer_shape
, Vx_window_horizontal_drag_shape
;
158 /* The shape when over mouse-sensitive text. */
160 Lisp_Object Vx_sensitive_text_pointer_shape
;
163 #define IDC_HAND MAKEINTRESOURCE(32649)
166 /* Color of chars displayed in cursor box. */
168 Lisp_Object Vx_cursor_fore_pixel
;
170 /* Nonzero if using Windows. */
172 static int w32_in_use
;
174 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
176 Lisp_Object Vx_pixel_size_width_font_regexp
;
178 /* Alist of bdf fonts and the files that define them. */
179 Lisp_Object Vw32_bdf_filename_alist
;
181 /* A flag to control whether fonts are matched strictly or not. */
182 int w32_strict_fontnames
;
184 /* A flag to control whether we should only repaint if GetUpdateRect
185 indicates there is an update region. */
186 int w32_strict_painting
;
188 /* Associative list linking character set strings to Windows codepages. */
189 Lisp_Object Vw32_charset_info_alist
;
191 /* VIETNAMESE_CHARSET is not defined in some versions of MSVC. */
192 #ifndef VIETNAMESE_CHARSET
193 #define VIETNAMESE_CHARSET 163
197 Lisp_Object Qsuppress_icon
;
198 Lisp_Object Qundefined_color
;
199 Lisp_Object Qcancel_timer
;
205 Lisp_Object Qcontrol
;
208 Lisp_Object Qw32_charset_ansi
;
209 Lisp_Object Qw32_charset_default
;
210 Lisp_Object Qw32_charset_symbol
;
211 Lisp_Object Qw32_charset_shiftjis
;
212 Lisp_Object Qw32_charset_hangeul
;
213 Lisp_Object Qw32_charset_gb2312
;
214 Lisp_Object Qw32_charset_chinesebig5
;
215 Lisp_Object Qw32_charset_oem
;
217 #ifndef JOHAB_CHARSET
218 #define JOHAB_CHARSET 130
221 Lisp_Object Qw32_charset_easteurope
;
222 Lisp_Object Qw32_charset_turkish
;
223 Lisp_Object Qw32_charset_baltic
;
224 Lisp_Object Qw32_charset_russian
;
225 Lisp_Object Qw32_charset_arabic
;
226 Lisp_Object Qw32_charset_greek
;
227 Lisp_Object Qw32_charset_hebrew
;
228 Lisp_Object Qw32_charset_vietnamese
;
229 Lisp_Object Qw32_charset_thai
;
230 Lisp_Object Qw32_charset_johab
;
231 Lisp_Object Qw32_charset_mac
;
234 #ifdef UNICODE_CHARSET
235 Lisp_Object Qw32_charset_unicode
;
238 /* The ANSI codepage. */
239 int w32_ansi_code_page
;
241 /* Prefix for system colors. */
242 #define SYSTEM_COLOR_PREFIX "System"
243 #define SYSTEM_COLOR_PREFIX_LEN (sizeof (SYSTEM_COLOR_PREFIX) - 1)
245 /* State variables for emulating a three button mouse. */
250 static int button_state
= 0;
251 static W32Msg saved_mouse_button_msg
;
252 static unsigned mouse_button_timer
= 0; /* non-zero when timer is active */
253 static W32Msg saved_mouse_move_msg
;
254 static unsigned mouse_move_timer
= 0;
256 /* Window that is tracking the mouse. */
257 static HWND track_mouse_window
;
259 typedef BOOL (WINAPI
* TrackMouseEvent_Proc
)
260 (IN OUT LPTRACKMOUSEEVENT lpEventTrack
);
262 TrackMouseEvent_Proc track_mouse_event_fn
= NULL
;
263 ClipboardSequence_Proc clipboard_sequence_fn
= NULL
;
264 extern AppendMenuW_Proc unicode_append_menu
;
266 /* W95 mousewheel handler */
267 unsigned int msh_mousewheel
= 0;
270 #define MOUSE_BUTTON_ID 1
271 #define MOUSE_MOVE_ID 2
272 #define MENU_FREE_ID 3
273 /* The delay (milliseconds) before a menu is freed after WM_EXITMENULOOP
275 #define MENU_FREE_DELAY 1000
276 static unsigned menu_free_timer
= 0;
278 /* The below are defined in frame.c. */
280 extern Lisp_Object Vwindow_system_version
;
283 int image_cache_refcount
, dpyinfo_refcount
;
287 /* From w32term.c. */
288 extern int w32_num_mouse_buttons
;
289 extern Lisp_Object Vw32_recognize_altgr
;
291 extern HWND w32_system_caret_hwnd
;
293 extern int w32_system_caret_height
;
294 extern int w32_system_caret_x
;
295 extern int w32_system_caret_y
;
296 extern int w32_use_visible_system_caret
;
298 static HWND w32_visible_system_caret_hwnd
;
301 /* Error if we are not connected to MS-Windows. */
306 error ("MS-Windows not in use or not initialized");
309 /* Nonzero if we can use mouse menus.
310 You should not call this unless HAVE_MENUS is defined. */
318 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
319 and checking validity for W32. */
322 check_x_frame (frame
)
328 frame
= selected_frame
;
329 CHECK_LIVE_FRAME (frame
);
331 if (! FRAME_W32_P (f
))
332 error ("Non-W32 frame used");
336 /* Let the user specify a display with a frame.
337 nil stands for the selected frame--or, if that is not a w32 frame,
338 the first display on the list. */
340 struct w32_display_info
*
341 check_x_display_info (frame
)
346 struct frame
*sf
= XFRAME (selected_frame
);
348 if (FRAME_W32_P (sf
) && FRAME_LIVE_P (sf
))
349 return FRAME_W32_DISPLAY_INFO (sf
);
351 return &one_w32_display_info
;
353 else if (STRINGP (frame
))
354 return x_display_info_for_name (frame
);
359 CHECK_LIVE_FRAME (frame
);
361 if (! FRAME_W32_P (f
))
362 error ("Non-W32 frame used");
363 return FRAME_W32_DISPLAY_INFO (f
);
367 /* Return the Emacs frame-object corresponding to an w32 window.
368 It could be the frame's main window or an icon window. */
370 /* This function can be called during GC, so use GC_xxx type test macros. */
373 x_window_to_frame (dpyinfo
, wdesc
)
374 struct w32_display_info
*dpyinfo
;
377 Lisp_Object tail
, frame
;
380 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
383 if (!GC_FRAMEP (frame
))
386 if (!FRAME_W32_P (f
) || FRAME_W32_DISPLAY_INFO (f
) != dpyinfo
)
388 if (f
->output_data
.w32
->hourglass_window
== wdesc
)
391 if (FRAME_W32_WINDOW (f
) == wdesc
)
398 static Lisp_Object unwind_create_frame
P_ ((Lisp_Object
));
399 static Lisp_Object unwind_create_tip_frame
P_ ((Lisp_Object
));
400 static void my_create_window
P_ ((struct frame
*));
401 static void my_create_tip_window
P_ ((struct frame
*));
403 /* TODO: Native Input Method support; see x_create_im. */
404 void x_set_foreground_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
405 void x_set_background_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
406 void x_set_mouse_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
407 void x_set_cursor_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
408 void x_set_border_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
409 void x_set_cursor_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
410 void x_set_icon_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
411 void x_set_icon_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
412 void x_explicitly_set_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
413 void x_set_menu_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
414 void x_set_title
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
415 void x_set_tool_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
416 static void x_edge_detection
P_ ((struct frame
*, struct image
*, Lisp_Object
,
422 /* Store the screen positions of frame F into XPTR and YPTR.
423 These are the positions of the containing window manager window,
424 not Emacs's own window. */
427 x_real_positions (f
, xptr
, yptr
)
434 GetClientRect(FRAME_W32_WINDOW(f
), &rect
);
435 AdjustWindowRect(&rect
, f
->output_data
.w32
->dwStyle
, FRAME_EXTERNAL_MENU_BAR(f
));
440 ClientToScreen (FRAME_W32_WINDOW(f
), &pt
);
442 /* Remember x_pixels_diff and y_pixels_diff. */
443 f
->x_pixels_diff
= pt
.x
- rect
.left
;
444 f
->y_pixels_diff
= pt
.y
- rect
.top
;
452 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
,
453 Sw32_define_rgb_color
, 4, 4, 0,
454 doc
: /* Convert RGB numbers to a windows color reference and associate with NAME.
455 This adds or updates a named color to w32-color-map, making it
456 available for use. The original entry's RGB ref is returned, or nil
457 if the entry is new. */)
458 (red
, green
, blue
, name
)
459 Lisp_Object red
, green
, blue
, name
;
462 Lisp_Object oldrgb
= Qnil
;
466 CHECK_NUMBER (green
);
470 XSETINT (rgb
, RGB(XUINT (red
), XUINT (green
), XUINT (blue
)));
474 /* replace existing entry in w32-color-map or add new entry. */
475 entry
= Fassoc (name
, Vw32_color_map
);
478 entry
= Fcons (name
, rgb
);
479 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
483 oldrgb
= Fcdr (entry
);
484 Fsetcdr (entry
, rgb
);
492 DEFUN ("w32-load-color-file", Fw32_load_color_file
,
493 Sw32_load_color_file
, 1, 1, 0,
494 doc
: /* Create an alist of color entries from an external file.
495 Assign this value to w32-color-map to replace the existing color map.
497 The file should define one named RGB color per line like so:
499 where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
501 Lisp_Object filename
;
504 Lisp_Object cmap
= Qnil
;
507 CHECK_STRING (filename
);
508 abspath
= Fexpand_file_name (filename
, Qnil
);
510 fp
= fopen (SDATA (filename
), "rt");
514 int red
, green
, blue
;
519 while (fgets (buf
, sizeof (buf
), fp
) != NULL
) {
520 if (sscanf (buf
, "%u %u %u %n", &red
, &green
, &blue
, &num
) == 3)
522 char *name
= buf
+ num
;
523 num
= strlen (name
) - 1;
524 if (name
[num
] == '\n')
526 cmap
= Fcons (Fcons (build_string (name
),
527 make_number (RGB (red
, green
, blue
))),
539 /* The default colors for the w32 color map */
540 typedef struct colormap_t
546 colormap_t w32_color_map
[] =
548 {"snow" , PALETTERGB (255,250,250)},
549 {"ghost white" , PALETTERGB (248,248,255)},
550 {"GhostWhite" , PALETTERGB (248,248,255)},
551 {"white smoke" , PALETTERGB (245,245,245)},
552 {"WhiteSmoke" , PALETTERGB (245,245,245)},
553 {"gainsboro" , PALETTERGB (220,220,220)},
554 {"floral white" , PALETTERGB (255,250,240)},
555 {"FloralWhite" , PALETTERGB (255,250,240)},
556 {"old lace" , PALETTERGB (253,245,230)},
557 {"OldLace" , PALETTERGB (253,245,230)},
558 {"linen" , PALETTERGB (250,240,230)},
559 {"antique white" , PALETTERGB (250,235,215)},
560 {"AntiqueWhite" , PALETTERGB (250,235,215)},
561 {"papaya whip" , PALETTERGB (255,239,213)},
562 {"PapayaWhip" , PALETTERGB (255,239,213)},
563 {"blanched almond" , PALETTERGB (255,235,205)},
564 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
565 {"bisque" , PALETTERGB (255,228,196)},
566 {"peach puff" , PALETTERGB (255,218,185)},
567 {"PeachPuff" , PALETTERGB (255,218,185)},
568 {"navajo white" , PALETTERGB (255,222,173)},
569 {"NavajoWhite" , PALETTERGB (255,222,173)},
570 {"moccasin" , PALETTERGB (255,228,181)},
571 {"cornsilk" , PALETTERGB (255,248,220)},
572 {"ivory" , PALETTERGB (255,255,240)},
573 {"lemon chiffon" , PALETTERGB (255,250,205)},
574 {"LemonChiffon" , PALETTERGB (255,250,205)},
575 {"seashell" , PALETTERGB (255,245,238)},
576 {"honeydew" , PALETTERGB (240,255,240)},
577 {"mint cream" , PALETTERGB (245,255,250)},
578 {"MintCream" , PALETTERGB (245,255,250)},
579 {"azure" , PALETTERGB (240,255,255)},
580 {"alice blue" , PALETTERGB (240,248,255)},
581 {"AliceBlue" , PALETTERGB (240,248,255)},
582 {"lavender" , PALETTERGB (230,230,250)},
583 {"lavender blush" , PALETTERGB (255,240,245)},
584 {"LavenderBlush" , PALETTERGB (255,240,245)},
585 {"misty rose" , PALETTERGB (255,228,225)},
586 {"MistyRose" , PALETTERGB (255,228,225)},
587 {"white" , PALETTERGB (255,255,255)},
588 {"black" , PALETTERGB ( 0, 0, 0)},
589 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
590 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
591 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
592 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
593 {"dim gray" , PALETTERGB (105,105,105)},
594 {"DimGray" , PALETTERGB (105,105,105)},
595 {"dim grey" , PALETTERGB (105,105,105)},
596 {"DimGrey" , PALETTERGB (105,105,105)},
597 {"slate gray" , PALETTERGB (112,128,144)},
598 {"SlateGray" , PALETTERGB (112,128,144)},
599 {"slate grey" , PALETTERGB (112,128,144)},
600 {"SlateGrey" , PALETTERGB (112,128,144)},
601 {"light slate gray" , PALETTERGB (119,136,153)},
602 {"LightSlateGray" , PALETTERGB (119,136,153)},
603 {"light slate grey" , PALETTERGB (119,136,153)},
604 {"LightSlateGrey" , PALETTERGB (119,136,153)},
605 {"gray" , PALETTERGB (190,190,190)},
606 {"grey" , PALETTERGB (190,190,190)},
607 {"light grey" , PALETTERGB (211,211,211)},
608 {"LightGrey" , PALETTERGB (211,211,211)},
609 {"light gray" , PALETTERGB (211,211,211)},
610 {"LightGray" , PALETTERGB (211,211,211)},
611 {"midnight blue" , PALETTERGB ( 25, 25,112)},
612 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
613 {"navy" , PALETTERGB ( 0, 0,128)},
614 {"navy blue" , PALETTERGB ( 0, 0,128)},
615 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
616 {"cornflower blue" , PALETTERGB (100,149,237)},
617 {"CornflowerBlue" , PALETTERGB (100,149,237)},
618 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
619 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
620 {"slate blue" , PALETTERGB (106, 90,205)},
621 {"SlateBlue" , PALETTERGB (106, 90,205)},
622 {"medium slate blue" , PALETTERGB (123,104,238)},
623 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
624 {"light slate blue" , PALETTERGB (132,112,255)},
625 {"LightSlateBlue" , PALETTERGB (132,112,255)},
626 {"medium blue" , PALETTERGB ( 0, 0,205)},
627 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
628 {"royal blue" , PALETTERGB ( 65,105,225)},
629 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
630 {"blue" , PALETTERGB ( 0, 0,255)},
631 {"dodger blue" , PALETTERGB ( 30,144,255)},
632 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
633 {"deep sky blue" , PALETTERGB ( 0,191,255)},
634 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
635 {"sky blue" , PALETTERGB (135,206,235)},
636 {"SkyBlue" , PALETTERGB (135,206,235)},
637 {"light sky blue" , PALETTERGB (135,206,250)},
638 {"LightSkyBlue" , PALETTERGB (135,206,250)},
639 {"steel blue" , PALETTERGB ( 70,130,180)},
640 {"SteelBlue" , PALETTERGB ( 70,130,180)},
641 {"light steel blue" , PALETTERGB (176,196,222)},
642 {"LightSteelBlue" , PALETTERGB (176,196,222)},
643 {"light blue" , PALETTERGB (173,216,230)},
644 {"LightBlue" , PALETTERGB (173,216,230)},
645 {"powder blue" , PALETTERGB (176,224,230)},
646 {"PowderBlue" , PALETTERGB (176,224,230)},
647 {"pale turquoise" , PALETTERGB (175,238,238)},
648 {"PaleTurquoise" , PALETTERGB (175,238,238)},
649 {"dark turquoise" , PALETTERGB ( 0,206,209)},
650 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
651 {"medium turquoise" , PALETTERGB ( 72,209,204)},
652 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
653 {"turquoise" , PALETTERGB ( 64,224,208)},
654 {"cyan" , PALETTERGB ( 0,255,255)},
655 {"light cyan" , PALETTERGB (224,255,255)},
656 {"LightCyan" , PALETTERGB (224,255,255)},
657 {"cadet blue" , PALETTERGB ( 95,158,160)},
658 {"CadetBlue" , PALETTERGB ( 95,158,160)},
659 {"medium aquamarine" , PALETTERGB (102,205,170)},
660 {"MediumAquamarine" , PALETTERGB (102,205,170)},
661 {"aquamarine" , PALETTERGB (127,255,212)},
662 {"dark green" , PALETTERGB ( 0,100, 0)},
663 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
664 {"dark olive green" , PALETTERGB ( 85,107, 47)},
665 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
666 {"dark sea green" , PALETTERGB (143,188,143)},
667 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
668 {"sea green" , PALETTERGB ( 46,139, 87)},
669 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
670 {"medium sea green" , PALETTERGB ( 60,179,113)},
671 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
672 {"light sea green" , PALETTERGB ( 32,178,170)},
673 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
674 {"pale green" , PALETTERGB (152,251,152)},
675 {"PaleGreen" , PALETTERGB (152,251,152)},
676 {"spring green" , PALETTERGB ( 0,255,127)},
677 {"SpringGreen" , PALETTERGB ( 0,255,127)},
678 {"lawn green" , PALETTERGB (124,252, 0)},
679 {"LawnGreen" , PALETTERGB (124,252, 0)},
680 {"green" , PALETTERGB ( 0,255, 0)},
681 {"chartreuse" , PALETTERGB (127,255, 0)},
682 {"medium spring green" , PALETTERGB ( 0,250,154)},
683 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
684 {"green yellow" , PALETTERGB (173,255, 47)},
685 {"GreenYellow" , PALETTERGB (173,255, 47)},
686 {"lime green" , PALETTERGB ( 50,205, 50)},
687 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
688 {"yellow green" , PALETTERGB (154,205, 50)},
689 {"YellowGreen" , PALETTERGB (154,205, 50)},
690 {"forest green" , PALETTERGB ( 34,139, 34)},
691 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
692 {"olive drab" , PALETTERGB (107,142, 35)},
693 {"OliveDrab" , PALETTERGB (107,142, 35)},
694 {"dark khaki" , PALETTERGB (189,183,107)},
695 {"DarkKhaki" , PALETTERGB (189,183,107)},
696 {"khaki" , PALETTERGB (240,230,140)},
697 {"pale goldenrod" , PALETTERGB (238,232,170)},
698 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
699 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
700 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
701 {"light yellow" , PALETTERGB (255,255,224)},
702 {"LightYellow" , PALETTERGB (255,255,224)},
703 {"yellow" , PALETTERGB (255,255, 0)},
704 {"gold" , PALETTERGB (255,215, 0)},
705 {"light goldenrod" , PALETTERGB (238,221,130)},
706 {"LightGoldenrod" , PALETTERGB (238,221,130)},
707 {"goldenrod" , PALETTERGB (218,165, 32)},
708 {"dark goldenrod" , PALETTERGB (184,134, 11)},
709 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
710 {"rosy brown" , PALETTERGB (188,143,143)},
711 {"RosyBrown" , PALETTERGB (188,143,143)},
712 {"indian red" , PALETTERGB (205, 92, 92)},
713 {"IndianRed" , PALETTERGB (205, 92, 92)},
714 {"saddle brown" , PALETTERGB (139, 69, 19)},
715 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
716 {"sienna" , PALETTERGB (160, 82, 45)},
717 {"peru" , PALETTERGB (205,133, 63)},
718 {"burlywood" , PALETTERGB (222,184,135)},
719 {"beige" , PALETTERGB (245,245,220)},
720 {"wheat" , PALETTERGB (245,222,179)},
721 {"sandy brown" , PALETTERGB (244,164, 96)},
722 {"SandyBrown" , PALETTERGB (244,164, 96)},
723 {"tan" , PALETTERGB (210,180,140)},
724 {"chocolate" , PALETTERGB (210,105, 30)},
725 {"firebrick" , PALETTERGB (178,34, 34)},
726 {"brown" , PALETTERGB (165,42, 42)},
727 {"dark salmon" , PALETTERGB (233,150,122)},
728 {"DarkSalmon" , PALETTERGB (233,150,122)},
729 {"salmon" , PALETTERGB (250,128,114)},
730 {"light salmon" , PALETTERGB (255,160,122)},
731 {"LightSalmon" , PALETTERGB (255,160,122)},
732 {"orange" , PALETTERGB (255,165, 0)},
733 {"dark orange" , PALETTERGB (255,140, 0)},
734 {"DarkOrange" , PALETTERGB (255,140, 0)},
735 {"coral" , PALETTERGB (255,127, 80)},
736 {"light coral" , PALETTERGB (240,128,128)},
737 {"LightCoral" , PALETTERGB (240,128,128)},
738 {"tomato" , PALETTERGB (255, 99, 71)},
739 {"orange red" , PALETTERGB (255, 69, 0)},
740 {"OrangeRed" , PALETTERGB (255, 69, 0)},
741 {"red" , PALETTERGB (255, 0, 0)},
742 {"hot pink" , PALETTERGB (255,105,180)},
743 {"HotPink" , PALETTERGB (255,105,180)},
744 {"deep pink" , PALETTERGB (255, 20,147)},
745 {"DeepPink" , PALETTERGB (255, 20,147)},
746 {"pink" , PALETTERGB (255,192,203)},
747 {"light pink" , PALETTERGB (255,182,193)},
748 {"LightPink" , PALETTERGB (255,182,193)},
749 {"pale violet red" , PALETTERGB (219,112,147)},
750 {"PaleVioletRed" , PALETTERGB (219,112,147)},
751 {"maroon" , PALETTERGB (176, 48, 96)},
752 {"medium violet red" , PALETTERGB (199, 21,133)},
753 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
754 {"violet red" , PALETTERGB (208, 32,144)},
755 {"VioletRed" , PALETTERGB (208, 32,144)},
756 {"magenta" , PALETTERGB (255, 0,255)},
757 {"violet" , PALETTERGB (238,130,238)},
758 {"plum" , PALETTERGB (221,160,221)},
759 {"orchid" , PALETTERGB (218,112,214)},
760 {"medium orchid" , PALETTERGB (186, 85,211)},
761 {"MediumOrchid" , PALETTERGB (186, 85,211)},
762 {"dark orchid" , PALETTERGB (153, 50,204)},
763 {"DarkOrchid" , PALETTERGB (153, 50,204)},
764 {"dark violet" , PALETTERGB (148, 0,211)},
765 {"DarkViolet" , PALETTERGB (148, 0,211)},
766 {"blue violet" , PALETTERGB (138, 43,226)},
767 {"BlueViolet" , PALETTERGB (138, 43,226)},
768 {"purple" , PALETTERGB (160, 32,240)},
769 {"medium purple" , PALETTERGB (147,112,219)},
770 {"MediumPurple" , PALETTERGB (147,112,219)},
771 {"thistle" , PALETTERGB (216,191,216)},
772 {"gray0" , PALETTERGB ( 0, 0, 0)},
773 {"grey0" , PALETTERGB ( 0, 0, 0)},
774 {"dark grey" , PALETTERGB (169,169,169)},
775 {"DarkGrey" , PALETTERGB (169,169,169)},
776 {"dark gray" , PALETTERGB (169,169,169)},
777 {"DarkGray" , PALETTERGB (169,169,169)},
778 {"dark blue" , PALETTERGB ( 0, 0,139)},
779 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
780 {"dark cyan" , PALETTERGB ( 0,139,139)},
781 {"DarkCyan" , PALETTERGB ( 0,139,139)},
782 {"dark magenta" , PALETTERGB (139, 0,139)},
783 {"DarkMagenta" , PALETTERGB (139, 0,139)},
784 {"dark red" , PALETTERGB (139, 0, 0)},
785 {"DarkRed" , PALETTERGB (139, 0, 0)},
786 {"light green" , PALETTERGB (144,238,144)},
787 {"LightGreen" , PALETTERGB (144,238,144)},
790 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
791 0, 0, 0, doc
: /* Return the default color map. */)
795 colormap_t
*pc
= w32_color_map
;
802 for (i
= 0; i
< sizeof (w32_color_map
) / sizeof (w32_color_map
[0]);
804 cmap
= Fcons (Fcons (build_string (pc
->name
),
805 make_number (pc
->colorref
)),
823 color
= Frassq (rgb
, Vw32_color_map
);
828 return (Fcar (color
));
834 w32_color_map_lookup (colorname
)
837 Lisp_Object tail
, ret
= Qnil
;
841 for (tail
= Vw32_color_map
; !NILP (tail
); tail
= Fcdr (tail
))
843 register Lisp_Object elt
, tem
;
846 if (!CONSP (elt
)) continue;
850 if (lstrcmpi (SDATA (tem
), colorname
) == 0)
867 add_system_logical_colors_to_map (system_colors
)
868 Lisp_Object
*system_colors
;
872 /* Other registry operations are done with input blocked. */
875 /* Look for "Control Panel/Colors" under User and Machine registry
877 if (RegOpenKeyEx (HKEY_CURRENT_USER
, "Control Panel\\Colors", 0,
878 KEY_READ
, &colors_key
) == ERROR_SUCCESS
879 || RegOpenKeyEx (HKEY_LOCAL_MACHINE
, "Control Panel\\Colors", 0,
880 KEY_READ
, &colors_key
) == ERROR_SUCCESS
)
883 char color_buffer
[64];
884 char full_name_buffer
[MAX_PATH
+ SYSTEM_COLOR_PREFIX_LEN
];
886 DWORD name_size
, color_size
;
887 char *name_buffer
= full_name_buffer
+ SYSTEM_COLOR_PREFIX_LEN
;
889 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
890 color_size
= sizeof (color_buffer
);
892 strcpy (full_name_buffer
, SYSTEM_COLOR_PREFIX
);
894 while (RegEnumValueA (colors_key
, index
, name_buffer
, &name_size
,
895 NULL
, NULL
, color_buffer
, &color_size
)
899 if (sscanf (color_buffer
, " %u %u %u", &r
, &g
, &b
) == 3)
900 *system_colors
= Fcons (Fcons (build_string (full_name_buffer
),
901 make_number (RGB (r
, g
, b
))),
904 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
905 color_size
= sizeof (color_buffer
);
908 RegCloseKey (colors_key
);
916 x_to_w32_color (colorname
)
919 register Lisp_Object ret
= Qnil
;
923 if (colorname
[0] == '#')
925 /* Could be an old-style RGB Device specification. */
928 color
= colorname
+ 1;
930 size
= strlen(color
);
931 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
939 for (i
= 0; i
< 3; i
++)
945 /* The check for 'x' in the following conditional takes into
946 account the fact that strtol allows a "0x" in front of
947 our numbers, and we don't. */
948 if (!isxdigit(color
[0]) || color
[1] == 'x')
952 value
= strtoul(color
, &end
, 16);
954 if (errno
== ERANGE
|| end
- color
!= size
)
959 value
= value
* 0x10;
970 colorval
|= (value
<< pos
);
975 XSETINT (ret
, colorval
);
982 else if (strnicmp(colorname
, "rgb:", 4) == 0)
990 color
= colorname
+ 4;
991 for (i
= 0; i
< 3; i
++)
996 /* The check for 'x' in the following conditional takes into
997 account the fact that strtol allows a "0x" in front of
998 our numbers, and we don't. */
999 if (!isxdigit(color
[0]) || color
[1] == 'x')
1001 value
= strtoul(color
, &end
, 16);
1002 if (errno
== ERANGE
)
1004 switch (end
- color
)
1007 value
= value
* 0x10 + value
;
1020 if (value
== ULONG_MAX
)
1022 colorval
|= (value
<< pos
);
1029 XSETINT (ret
, colorval
);
1037 else if (strnicmp(colorname
, "rgbi:", 5) == 0)
1039 /* This is an RGB Intensity specification. */
1046 color
= colorname
+ 5;
1047 for (i
= 0; i
< 3; i
++)
1053 value
= strtod(color
, &end
);
1054 if (errno
== ERANGE
)
1056 if (value
< 0.0 || value
> 1.0)
1058 val
= (UINT
)(0x100 * value
);
1059 /* We used 0x100 instead of 0xFF to give a continuous
1060 range between 0.0 and 1.0 inclusive. The next statement
1061 fixes the 1.0 case. */
1064 colorval
|= (val
<< pos
);
1071 XSETINT (ret
, colorval
);
1079 /* I am not going to attempt to handle any of the CIE color schemes
1080 or TekHVC, since I don't know the algorithms for conversion to
1083 /* If we fail to lookup the color name in w32_color_map, then check the
1084 colorname to see if it can be crudely approximated: If the X color
1085 ends in a number (e.g., "darkseagreen2"), strip the number and
1086 return the result of looking up the base color name. */
1087 ret
= w32_color_map_lookup (colorname
);
1090 int len
= strlen (colorname
);
1092 if (isdigit (colorname
[len
- 1]))
1094 char *ptr
, *approx
= alloca (len
+ 1);
1096 strcpy (approx
, colorname
);
1097 ptr
= &approx
[len
- 1];
1098 while (ptr
> approx
&& isdigit (*ptr
))
1101 ret
= w32_color_map_lookup (approx
);
1110 w32_regenerate_palette (FRAME_PTR f
)
1112 struct w32_palette_entry
* list
;
1113 LOGPALETTE
* log_palette
;
1114 HPALETTE new_palette
;
1117 /* don't bother trying to create palette if not supported */
1118 if (! FRAME_W32_DISPLAY_INFO (f
)->has_palette
)
1121 log_palette
= (LOGPALETTE
*)
1122 alloca (sizeof (LOGPALETTE
) +
1123 FRAME_W32_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
1124 log_palette
->palVersion
= 0x300;
1125 log_palette
->palNumEntries
= FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1127 list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1129 i
< FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1130 i
++, list
= list
->next
)
1131 log_palette
->palPalEntry
[i
] = list
->entry
;
1133 new_palette
= CreatePalette (log_palette
);
1137 if (FRAME_W32_DISPLAY_INFO (f
)->palette
)
1138 DeleteObject (FRAME_W32_DISPLAY_INFO (f
)->palette
);
1139 FRAME_W32_DISPLAY_INFO (f
)->palette
= new_palette
;
1141 /* Realize display palette and garbage all frames. */
1142 release_frame_dc (f
, get_frame_dc (f
));
1147 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
1148 #define SET_W32_COLOR(pe, color) \
1151 pe.peRed = GetRValue (color); \
1152 pe.peGreen = GetGValue (color); \
1153 pe.peBlue = GetBValue (color); \
1158 /* Keep these around in case we ever want to track color usage. */
1160 w32_map_color (FRAME_PTR f
, COLORREF color
)
1162 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1164 if (NILP (Vw32_enable_palette
))
1167 /* check if color is already mapped */
1170 if (W32_COLOR (list
->entry
) == color
)
1178 /* not already mapped, so add to list and recreate Windows palette */
1179 list
= (struct w32_palette_entry
*)
1180 xmalloc (sizeof (struct w32_palette_entry
));
1181 SET_W32_COLOR (list
->entry
, color
);
1183 list
->next
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1184 FRAME_W32_DISPLAY_INFO (f
)->color_list
= list
;
1185 FRAME_W32_DISPLAY_INFO (f
)->num_colors
++;
1187 /* set flag that palette must be regenerated */
1188 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1192 w32_unmap_color (FRAME_PTR f
, COLORREF color
)
1194 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1195 struct w32_palette_entry
**prev
= &FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1197 if (NILP (Vw32_enable_palette
))
1200 /* check if color is already mapped */
1203 if (W32_COLOR (list
->entry
) == color
)
1205 if (--list
->refcount
== 0)
1209 FRAME_W32_DISPLAY_INFO (f
)->num_colors
--;
1219 /* set flag that palette must be regenerated */
1220 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1225 /* Gamma-correct COLOR on frame F. */
1228 gamma_correct (f
, color
)
1234 *color
= PALETTERGB (
1235 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1236 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1237 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1242 /* Decide if color named COLOR is valid for the display associated with
1243 the selected frame; if so, return the rgb values in COLOR_DEF.
1244 If ALLOC is nonzero, allocate a new colormap cell. */
1247 w32_defined_color (f
, color
, color_def
, alloc
)
1253 register Lisp_Object tem
;
1254 COLORREF w32_color_ref
;
1256 tem
= x_to_w32_color (color
);
1262 /* Apply gamma correction. */
1263 w32_color_ref
= XUINT (tem
);
1264 gamma_correct (f
, &w32_color_ref
);
1265 XSETINT (tem
, w32_color_ref
);
1268 /* Map this color to the palette if it is enabled. */
1269 if (!NILP (Vw32_enable_palette
))
1271 struct w32_palette_entry
* entry
=
1272 one_w32_display_info
.color_list
;
1273 struct w32_palette_entry
** prev
=
1274 &one_w32_display_info
.color_list
;
1276 /* check if color is already mapped */
1279 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1281 prev
= &entry
->next
;
1282 entry
= entry
->next
;
1285 if (entry
== NULL
&& alloc
)
1287 /* not already mapped, so add to list */
1288 entry
= (struct w32_palette_entry
*)
1289 xmalloc (sizeof (struct w32_palette_entry
));
1290 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1293 one_w32_display_info
.num_colors
++;
1295 /* set flag that palette must be regenerated */
1296 one_w32_display_info
.regen_palette
= TRUE
;
1299 /* Ensure COLORREF value is snapped to nearest color in (default)
1300 palette by simulating the PALETTERGB macro. This works whether
1301 or not the display device has a palette. */
1302 w32_color_ref
= XUINT (tem
) | 0x2000000;
1304 color_def
->pixel
= w32_color_ref
;
1305 color_def
->red
= GetRValue (w32_color_ref
) * 256;
1306 color_def
->green
= GetGValue (w32_color_ref
) * 256;
1307 color_def
->blue
= GetBValue (w32_color_ref
) * 256;
1317 /* Given a string ARG naming a color, compute a pixel value from it
1318 suitable for screen F.
1319 If F is not a color screen, return DEF (default) regardless of what
1323 x_decode_color (f
, arg
, def
)
1332 if (strcmp (SDATA (arg
), "black") == 0)
1333 return BLACK_PIX_DEFAULT (f
);
1334 else if (strcmp (SDATA (arg
), "white") == 0)
1335 return WHITE_PIX_DEFAULT (f
);
1337 if ((FRAME_W32_DISPLAY_INFO (f
)->n_planes
* FRAME_W32_DISPLAY_INFO (f
)->n_cbits
) == 1)
1340 /* w32_defined_color is responsible for coping with failures
1341 by looking for a near-miss. */
1342 if (w32_defined_color (f
, SDATA (arg
), &cdef
, 1))
1345 /* defined_color failed; return an ultimate default. */
1351 /* Functions called only from `x_set_frame_param'
1352 to set individual parameters.
1354 If FRAME_W32_WINDOW (f) is 0,
1355 the frame is being created and its window does not exist yet.
1356 In that case, just record the parameter's new value
1357 in the standard place; do not attempt to change the window. */
1360 x_set_foreground_color (f
, arg
, oldval
)
1362 Lisp_Object arg
, oldval
;
1364 struct w32_output
*x
= f
->output_data
.w32
;
1365 PIX_TYPE fg
, old_fg
;
1367 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1368 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
1369 FRAME_FOREGROUND_PIXEL (f
) = fg
;
1371 if (FRAME_W32_WINDOW (f
) != 0)
1373 if (x
->cursor_pixel
== old_fg
)
1374 x
->cursor_pixel
= fg
;
1376 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
1377 if (FRAME_VISIBLE_P (f
))
1383 x_set_background_color (f
, arg
, oldval
)
1385 Lisp_Object arg
, oldval
;
1387 FRAME_BACKGROUND_PIXEL (f
)
1388 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
1390 if (FRAME_W32_WINDOW (f
) != 0)
1392 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
1393 FRAME_BACKGROUND_PIXEL (f
));
1395 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
1397 if (FRAME_VISIBLE_P (f
))
1403 x_set_mouse_color (f
, arg
, oldval
)
1405 Lisp_Object arg
, oldval
;
1407 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
1411 if (!EQ (Qnil
, arg
))
1412 f
->output_data
.w32
->mouse_pixel
1413 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1414 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
1416 /* Don't let pointers be invisible. */
1417 if (mask_color
== f
->output_data
.w32
->mouse_pixel
1418 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
1419 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
1421 #if 0 /* TODO : cursor changes */
1424 /* It's not okay to crash if the user selects a screwy cursor. */
1425 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
1427 if (!EQ (Qnil
, Vx_pointer_shape
))
1429 CHECK_NUMBER (Vx_pointer_shape
);
1430 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
1433 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1434 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
1436 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
1438 CHECK_NUMBER (Vx_nontext_pointer_shape
);
1439 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1440 XINT (Vx_nontext_pointer_shape
));
1443 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
1444 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1446 if (!EQ (Qnil
, Vx_hourglass_pointer_shape
))
1448 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
1449 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1450 XINT (Vx_hourglass_pointer_shape
));
1453 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
1454 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
1456 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1457 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
1459 CHECK_NUMBER (Vx_mode_pointer_shape
);
1460 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1461 XINT (Vx_mode_pointer_shape
));
1464 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1465 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
1467 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
1469 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
1471 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1472 XINT (Vx_sensitive_text_pointer_shape
));
1475 hand_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
1477 if (!NILP (Vx_window_horizontal_drag_shape
))
1479 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
1480 horizontal_drag_cursor
1481 = XCreateFontCursor (FRAME_X_DISPLAY (f
),
1482 XINT (Vx_window_horizontal_drag_shape
));
1485 horizontal_drag_cursor
1486 = XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_sb_h_double_arrow
);
1488 /* Check and report errors with the above calls. */
1489 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
1490 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
1493 XColor fore_color
, back_color
;
1495 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
1496 back_color
.pixel
= mask_color
;
1497 XQueryColor (FRAME_W32_DISPLAY (f
),
1498 DefaultColormap (FRAME_W32_DISPLAY (f
),
1499 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1501 XQueryColor (FRAME_W32_DISPLAY (f
),
1502 DefaultColormap (FRAME_W32_DISPLAY (f
),
1503 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1505 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
1506 &fore_color
, &back_color
);
1507 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
1508 &fore_color
, &back_color
);
1509 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
1510 &fore_color
, &back_color
);
1511 XRecolorCursor (FRAME_W32_DISPLAY (f
), hand_cursor
,
1512 &fore_color
, &back_color
);
1513 XRecolorCursor (FRAME_W32_DISPLAY (f
), hourglass_cursor
,
1514 &fore_color
, &back_color
);
1517 if (FRAME_W32_WINDOW (f
) != 0)
1518 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
1520 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
1521 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
1522 f
->output_data
.w32
->text_cursor
= cursor
;
1524 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
1525 && f
->output_data
.w32
->nontext_cursor
!= 0)
1526 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
1527 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
1529 if (hourglass_cursor
!= f
->output_data
.w32
->hourglass_cursor
1530 && f
->output_data
.w32
->hourglass_cursor
!= 0)
1531 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hourglass_cursor
);
1532 f
->output_data
.w32
->hourglass_cursor
= hourglass_cursor
;
1534 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
1535 && f
->output_data
.w32
->modeline_cursor
!= 0)
1536 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
1537 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
1539 if (hand_cursor
!= f
->output_data
.w32
->hand_cursor
1540 && f
->output_data
.w32
->hand_cursor
!= 0)
1541 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hand_cursor
);
1542 f
->output_data
.w32
->hand_cursor
= hand_cursor
;
1544 XFlush (FRAME_W32_DISPLAY (f
));
1547 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1551 /* Defined in w32term.c. */
1553 x_set_cursor_color (f
, arg
, oldval
)
1555 Lisp_Object arg
, oldval
;
1557 unsigned long fore_pixel
, pixel
;
1559 if (!NILP (Vx_cursor_fore_pixel
))
1560 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1561 WHITE_PIX_DEFAULT (f
));
1563 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1565 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1567 /* Make sure that the cursor color differs from the background color. */
1568 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
1570 pixel
= f
->output_data
.w32
->mouse_pixel
;
1571 if (pixel
== fore_pixel
)
1572 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1575 f
->output_data
.w32
->cursor_foreground_pixel
= fore_pixel
;
1576 f
->output_data
.w32
->cursor_pixel
= pixel
;
1578 if (FRAME_W32_WINDOW (f
) != 0)
1581 /* Update frame's cursor_gc. */
1582 f
->output_data
.w32
->cursor_gc
->foreground
= fore_pixel
;
1583 f
->output_data
.w32
->cursor_gc
->background
= pixel
;
1587 if (FRAME_VISIBLE_P (f
))
1589 x_update_cursor (f
, 0);
1590 x_update_cursor (f
, 1);
1594 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1597 /* Set the border-color of frame F to pixel value PIX.
1598 Note that this does not fully take effect if done before
1602 x_set_border_pixel (f
, pix
)
1607 f
->output_data
.w32
->border_pixel
= pix
;
1609 if (FRAME_W32_WINDOW (f
) != 0 && f
->border_width
> 0)
1611 if (FRAME_VISIBLE_P (f
))
1616 /* Set the border-color of frame F to value described by ARG.
1617 ARG can be a string naming a color.
1618 The border-color is used for the border that is drawn by the server.
1619 Note that this does not fully take effect if done before
1620 F has a window; it must be redone when the window is created. */
1623 x_set_border_color (f
, arg
, oldval
)
1625 Lisp_Object arg
, oldval
;
1630 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1631 x_set_border_pixel (f
, pix
);
1632 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1637 x_set_cursor_type (f
, arg
, oldval
)
1639 Lisp_Object arg
, oldval
;
1641 set_frame_cursor_types (f
, arg
);
1643 /* Make sure the cursor gets redrawn. */
1644 cursor_type_changed
= 1;
1648 x_set_icon_type (f
, arg
, oldval
)
1650 Lisp_Object arg
, oldval
;
1654 if (NILP (arg
) && NILP (oldval
))
1657 if (STRINGP (arg
) && STRINGP (oldval
)
1658 && EQ (Fstring_equal (oldval
, arg
), Qt
))
1661 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
1666 result
= x_bitmap_icon (f
, arg
);
1670 error ("No icon window available");
1677 x_set_icon_name (f
, arg
, oldval
)
1679 Lisp_Object arg
, oldval
;
1683 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1686 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
1692 if (f
->output_data
.w32
->icon_bitmap
!= 0)
1697 result
= x_text_icon (f
,
1698 (char *) SDATA ((!NILP (f
->icon_name
)
1707 error ("No icon window available");
1710 /* If the window was unmapped (and its icon was mapped),
1711 the new icon is not mapped, so map the window in its stead. */
1712 if (FRAME_VISIBLE_P (f
))
1714 #ifdef USE_X_TOOLKIT
1715 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
1717 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
1720 XFlush (FRAME_W32_DISPLAY (f
));
1727 x_set_menu_bar_lines (f
, value
, oldval
)
1729 Lisp_Object value
, oldval
;
1732 int olines
= FRAME_MENU_BAR_LINES (f
);
1734 /* Right now, menu bars don't work properly in minibuf-only frames;
1735 most of the commands try to apply themselves to the minibuffer
1736 frame itself, and get an error because you can't switch buffers
1737 in or split the minibuffer window. */
1738 if (FRAME_MINIBUF_ONLY_P (f
))
1741 if (INTEGERP (value
))
1742 nlines
= XINT (value
);
1746 FRAME_MENU_BAR_LINES (f
) = 0;
1748 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1751 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1752 free_frame_menubar (f
);
1753 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1755 /* Adjust the frame size so that the client (text) dimensions
1756 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
1758 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
1759 do_pending_window_change (0);
1765 /* Set the number of lines used for the tool bar of frame F to VALUE.
1766 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1767 is the old number of tool bar lines. This function changes the
1768 height of all windows on frame F to match the new tool bar height.
1769 The frame's height doesn't change. */
1772 x_set_tool_bar_lines (f
, value
, oldval
)
1774 Lisp_Object value
, oldval
;
1776 int delta
, nlines
, root_height
;
1777 Lisp_Object root_window
;
1779 /* Treat tool bars like menu bars. */
1780 if (FRAME_MINIBUF_ONLY_P (f
))
1783 /* Use VALUE only if an integer >= 0. */
1784 if (INTEGERP (value
) && XINT (value
) >= 0)
1785 nlines
= XFASTINT (value
);
1789 /* Make sure we redisplay all windows in this frame. */
1790 ++windows_or_buffers_changed
;
1792 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
1794 /* Don't resize the tool-bar to more than we have room for. */
1795 root_window
= FRAME_ROOT_WINDOW (f
);
1796 root_height
= WINDOW_TOTAL_LINES (XWINDOW (root_window
));
1797 if (root_height
- delta
< 1)
1799 delta
= root_height
- 1;
1800 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
1803 FRAME_TOOL_BAR_LINES (f
) = nlines
;
1804 change_window_heights (root_window
, delta
);
1807 /* We also have to make sure that the internal border at the top of
1808 the frame, below the menu bar or tool bar, is redrawn when the
1809 tool bar disappears. This is so because the internal border is
1810 below the tool bar if one is displayed, but is below the menu bar
1811 if there isn't a tool bar. The tool bar draws into the area
1812 below the menu bar. */
1813 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
1817 clear_current_matrices (f
);
1818 updating_frame
= NULL
;
1821 /* If the tool bar gets smaller, the internal border below it
1822 has to be cleared. It was formerly part of the display
1823 of the larger tool bar, and updating windows won't clear it. */
1826 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1827 int width
= FRAME_PIXEL_WIDTH (f
);
1828 int y
= nlines
* FRAME_LINE_HEIGHT (f
);
1832 HDC hdc
= get_frame_dc (f
);
1833 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
1834 release_frame_dc (f
, hdc
);
1838 if (WINDOWP (f
->tool_bar_window
))
1839 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1844 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1847 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1848 name; if NAME is a string, set F's name to NAME and set
1849 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1851 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1852 suggesting a new name, which lisp code should override; if
1853 F->explicit_name is set, ignore the new name; otherwise, set it. */
1856 x_set_name (f
, name
, explicit)
1861 /* Make sure that requests from lisp code override requests from
1862 Emacs redisplay code. */
1865 /* If we're switching from explicit to implicit, we had better
1866 update the mode lines and thereby update the title. */
1867 if (f
->explicit_name
&& NILP (name
))
1868 update_mode_lines
= 1;
1870 f
->explicit_name
= ! NILP (name
);
1872 else if (f
->explicit_name
)
1875 /* If NAME is nil, set the name to the w32_id_name. */
1878 /* Check for no change needed in this very common case
1879 before we do any consing. */
1880 if (!strcmp (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
,
1883 name
= build_string (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
);
1886 CHECK_STRING (name
);
1888 /* Don't change the name if it's already NAME. */
1889 if (! NILP (Fstring_equal (name
, f
->name
)))
1894 /* For setting the frame title, the title parameter should override
1895 the name parameter. */
1896 if (! NILP (f
->title
))
1899 if (FRAME_W32_WINDOW (f
))
1901 if (STRING_MULTIBYTE (name
))
1902 name
= ENCODE_SYSTEM (name
);
1905 SetWindowText(FRAME_W32_WINDOW (f
), SDATA (name
));
1910 /* This function should be called when the user's lisp code has
1911 specified a name for the frame; the name will override any set by the
1914 x_explicitly_set_name (f
, arg
, oldval
)
1916 Lisp_Object arg
, oldval
;
1918 x_set_name (f
, arg
, 1);
1921 /* This function should be called by Emacs redisplay code to set the
1922 name; names set this way will never override names set by the user's
1925 x_implicitly_set_name (f
, arg
, oldval
)
1927 Lisp_Object arg
, oldval
;
1929 x_set_name (f
, arg
, 0);
1932 /* Change the title of frame F to NAME.
1933 If NAME is nil, use the frame name as the title.
1935 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1936 name; if NAME is a string, set F's name to NAME and set
1937 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1939 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1940 suggesting a new name, which lisp code should override; if
1941 F->explicit_name is set, ignore the new name; otherwise, set it. */
1944 x_set_title (f
, name
, old_name
)
1946 Lisp_Object name
, old_name
;
1948 /* Don't change the title if it's already NAME. */
1949 if (EQ (name
, f
->title
))
1952 update_mode_lines
= 1;
1959 if (FRAME_W32_WINDOW (f
))
1961 if (STRING_MULTIBYTE (name
))
1962 name
= ENCODE_SYSTEM (name
);
1965 SetWindowText(FRAME_W32_WINDOW (f
), SDATA (name
));
1971 void x_set_scroll_bar_default_width (f
)
1974 int wid
= FRAME_COLUMN_WIDTH (f
);
1976 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
1977 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) +
1982 /* Subroutines of creating a frame. */
1985 /* Return the value of parameter PARAM.
1987 First search ALIST, then Vdefault_frame_alist, then the X defaults
1988 database, using ATTRIBUTE as the attribute name and CLASS as its class.
1990 Convert the resource to the type specified by desired_type.
1992 If no default is specified, return Qunbound. If you call
1993 w32_get_arg, make sure you deal with Qunbound in a reasonable way,
1994 and don't let it get stored in any Lisp-visible variables! */
1997 w32_get_arg (alist
, param
, attribute
, class, type
)
1998 Lisp_Object alist
, param
;
2001 enum resource_types type
;
2003 return x_get_arg (check_x_display_info (Qnil
),
2004 alist
, param
, attribute
, class, type
);
2009 w32_load_cursor (LPCTSTR name
)
2011 /* Try first to load cursor from application resource. */
2012 Cursor cursor
= LoadImage ((HINSTANCE
) GetModuleHandle(NULL
),
2013 name
, IMAGE_CURSOR
, 0, 0,
2014 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
2017 /* Then try to load a shared predefined cursor. */
2018 cursor
= LoadImage (NULL
, name
, IMAGE_CURSOR
, 0, 0,
2019 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
2024 extern LRESULT CALLBACK
w32_wnd_proc ();
2027 w32_init_class (hinst
)
2032 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
2033 wc
.lpfnWndProc
= (WNDPROC
) w32_wnd_proc
;
2035 wc
.cbWndExtra
= WND_EXTRA_BYTES
;
2036 wc
.hInstance
= hinst
;
2037 wc
.hIcon
= LoadIcon (hinst
, EMACS_CLASS
);
2038 wc
.hCursor
= w32_load_cursor (IDC_ARROW
);
2039 wc
.hbrBackground
= NULL
; /* GetStockObject (WHITE_BRUSH); */
2040 wc
.lpszMenuName
= NULL
;
2041 wc
.lpszClassName
= EMACS_CLASS
;
2043 return (RegisterClass (&wc
));
2047 w32_createscrollbar (f
, bar
)
2049 struct scroll_bar
* bar
;
2051 return (CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
2052 /* Position and size of scroll bar. */
2053 XINT(bar
->left
) + VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
2055 XINT(bar
->width
) - VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
2057 FRAME_W32_WINDOW (f
),
2064 w32_createwindow (f
)
2070 rect
.left
= rect
.top
= 0;
2071 rect
.right
= FRAME_PIXEL_WIDTH (f
);
2072 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
2074 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
2075 FRAME_EXTERNAL_MENU_BAR (f
));
2077 /* Do first time app init */
2081 w32_init_class (hinst
);
2084 FRAME_W32_WINDOW (f
) = hwnd
2085 = CreateWindow (EMACS_CLASS
,
2087 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
2090 rect
.right
- rect
.left
,
2091 rect
.bottom
- rect
.top
,
2099 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
2100 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
2101 SetWindowLong (hwnd
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
2102 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->scroll_bar_actual_width
);
2103 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
2105 /* Enable drag-n-drop. */
2106 DragAcceptFiles (hwnd
, TRUE
);
2108 /* Do this to discard the default setting specified by our parent. */
2109 ShowWindow (hwnd
, SW_HIDE
);
2114 my_post_msg (wmsg
, hwnd
, msg
, wParam
, lParam
)
2121 wmsg
->msg
.hwnd
= hwnd
;
2122 wmsg
->msg
.message
= msg
;
2123 wmsg
->msg
.wParam
= wParam
;
2124 wmsg
->msg
.lParam
= lParam
;
2125 wmsg
->msg
.time
= GetMessageTime ();
2130 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
2131 between left and right keys as advertised. We test for this
2132 support dynamically, and set a flag when the support is absent. If
2133 absent, we keep track of the left and right control and alt keys
2134 ourselves. This is particularly necessary on keyboards that rely
2135 upon the AltGr key, which is represented as having the left control
2136 and right alt keys pressed. For these keyboards, we need to know
2137 when the left alt key has been pressed in addition to the AltGr key
2138 so that we can properly support M-AltGr-key sequences (such as M-@
2139 on Swedish keyboards). */
2141 #define EMACS_LCONTROL 0
2142 #define EMACS_RCONTROL 1
2143 #define EMACS_LMENU 2
2144 #define EMACS_RMENU 3
2146 static int modifiers
[4];
2147 static int modifiers_recorded
;
2148 static int modifier_key_support_tested
;
2151 test_modifier_support (unsigned int wparam
)
2155 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
2157 if (wparam
== VK_CONTROL
)
2167 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
2168 modifiers_recorded
= 1;
2170 modifiers_recorded
= 0;
2171 modifier_key_support_tested
= 1;
2175 record_keydown (unsigned int wparam
, unsigned int lparam
)
2179 if (!modifier_key_support_tested
)
2180 test_modifier_support (wparam
);
2182 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2185 if (wparam
== VK_CONTROL
)
2186 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2188 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2194 record_keyup (unsigned int wparam
, unsigned int lparam
)
2198 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2201 if (wparam
== VK_CONTROL
)
2202 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2204 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2209 /* Emacs can lose focus while a modifier key has been pressed. When
2210 it regains focus, be conservative and clear all modifiers since
2211 we cannot reconstruct the left and right modifier state. */
2217 if (GetFocus () == NULL
)
2218 /* Emacs doesn't have keyboard focus. Do nothing. */
2221 ctrl
= GetAsyncKeyState (VK_CONTROL
);
2222 alt
= GetAsyncKeyState (VK_MENU
);
2224 if (!(ctrl
& 0x08000))
2225 /* Clear any recorded control modifier state. */
2226 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2228 if (!(alt
& 0x08000))
2229 /* Clear any recorded alt modifier state. */
2230 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2232 /* Update the state of all modifier keys, because modifiers used in
2233 hot-key combinations can get stuck on if Emacs loses focus as a
2234 result of a hot-key being pressed. */
2238 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
2240 GetKeyboardState (keystate
);
2241 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
2242 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
2243 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
2244 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
2245 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
2246 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
2247 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
2248 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
2249 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
2250 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
2251 SetKeyboardState (keystate
);
2255 /* Synchronize modifier state with what is reported with the current
2256 keystroke. Even if we cannot distinguish between left and right
2257 modifier keys, we know that, if no modifiers are set, then neither
2258 the left or right modifier should be set. */
2262 if (!modifiers_recorded
)
2265 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
2266 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2268 if (!(GetKeyState (VK_MENU
) & 0x8000))
2269 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2273 modifier_set (int vkey
)
2275 if (vkey
== VK_CAPITAL
|| vkey
== VK_SCROLL
)
2276 return (GetKeyState (vkey
) & 0x1);
2277 if (!modifiers_recorded
)
2278 return (GetKeyState (vkey
) & 0x8000);
2283 return modifiers
[EMACS_LCONTROL
];
2285 return modifiers
[EMACS_RCONTROL
];
2287 return modifiers
[EMACS_LMENU
];
2289 return modifiers
[EMACS_RMENU
];
2291 return (GetKeyState (vkey
) & 0x8000);
2294 /* Convert between the modifier bits W32 uses and the modifier bits
2298 w32_key_to_modifier (int key
)
2300 Lisp_Object key_mapping
;
2305 key_mapping
= Vw32_lwindow_modifier
;
2308 key_mapping
= Vw32_rwindow_modifier
;
2311 key_mapping
= Vw32_apps_modifier
;
2314 key_mapping
= Vw32_scroll_lock_modifier
;
2320 /* NB. This code runs in the input thread, asychronously to the lisp
2321 thread, so we must be careful to ensure access to lisp data is
2322 thread-safe. The following code is safe because the modifier
2323 variable values are updated atomically from lisp and symbols are
2324 not relocated by GC. Also, we don't have to worry about seeing GC
2326 if (EQ (key_mapping
, Qhyper
))
2327 return hyper_modifier
;
2328 if (EQ (key_mapping
, Qsuper
))
2329 return super_modifier
;
2330 if (EQ (key_mapping
, Qmeta
))
2331 return meta_modifier
;
2332 if (EQ (key_mapping
, Qalt
))
2333 return alt_modifier
;
2334 if (EQ (key_mapping
, Qctrl
))
2335 return ctrl_modifier
;
2336 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
2337 return ctrl_modifier
;
2338 if (EQ (key_mapping
, Qshift
))
2339 return shift_modifier
;
2341 /* Don't generate any modifier if not explicitly requested. */
2346 w32_get_modifiers ()
2348 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
2349 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
2350 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
2351 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
2352 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
2353 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
2354 (modifier_set (VK_MENU
) ?
2355 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
2358 /* We map the VK_* modifiers into console modifier constants
2359 so that we can use the same routines to handle both console
2360 and window input. */
2363 construct_console_modifiers ()
2368 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
2369 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
2370 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
2371 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
2372 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
2373 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
2374 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
2375 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
2376 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
2377 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
2378 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
2384 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
2388 /* Convert to emacs modifiers. */
2389 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
2395 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
2397 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
2400 if (virt_key
== VK_RETURN
)
2401 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
2403 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
2404 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
2406 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
2407 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
2409 if (virt_key
== VK_CLEAR
)
2410 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
2415 /* List of special key combinations which w32 would normally capture,
2416 but emacs should grab instead. Not directly visible to lisp, to
2417 simplify synchronization. Each item is an integer encoding a virtual
2418 key code and modifier combination to capture. */
2419 Lisp_Object w32_grabbed_keys
;
2421 #define HOTKEY(vk,mods) make_number (((vk) & 255) | ((mods) << 8))
2422 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
2423 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
2424 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
2426 #define RAW_HOTKEY_ID(k) ((k) & 0xbfff)
2427 #define RAW_HOTKEY_VK_CODE(k) ((k) & 255)
2428 #define RAW_HOTKEY_MODIFIERS(k) ((k) >> 8)
2430 /* Register hot-keys for reserved key combinations when Emacs has
2431 keyboard focus, since this is the only way Emacs can receive key
2432 combinations like Alt-Tab which are used by the system. */
2435 register_hot_keys (hwnd
)
2438 Lisp_Object keylist
;
2440 /* Use GC_CONSP, since we are called asynchronously. */
2441 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
2443 Lisp_Object key
= XCAR (keylist
);
2445 /* Deleted entries get set to nil. */
2446 if (!INTEGERP (key
))
2449 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
2450 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
2455 unregister_hot_keys (hwnd
)
2458 Lisp_Object keylist
;
2460 /* Use GC_CONSP, since we are called asynchronously. */
2461 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
2463 Lisp_Object key
= XCAR (keylist
);
2465 if (!INTEGERP (key
))
2468 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
2472 /* Main message dispatch loop. */
2475 w32_msg_pump (deferred_msg
* msg_buf
)
2481 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
2483 while (GetMessage (&msg
, NULL
, 0, 0))
2485 if (msg
.hwnd
== NULL
)
2487 switch (msg
.message
)
2490 /* Produced by complete_deferred_msg; just ignore. */
2492 case WM_EMACS_CREATEWINDOW
:
2493 w32_createwindow ((struct frame
*) msg
.wParam
);
2494 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2497 case WM_EMACS_SETLOCALE
:
2498 SetThreadLocale (msg
.wParam
);
2499 /* Reply is not expected. */
2501 case WM_EMACS_SETKEYBOARDLAYOUT
:
2502 result
= (int) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
2503 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2507 case WM_EMACS_REGISTER_HOT_KEY
:
2508 focus_window
= GetFocus ();
2509 if (focus_window
!= NULL
)
2510 RegisterHotKey (focus_window
,
2511 RAW_HOTKEY_ID (msg
.wParam
),
2512 RAW_HOTKEY_MODIFIERS (msg
.wParam
),
2513 RAW_HOTKEY_VK_CODE (msg
.wParam
));
2514 /* Reply is not expected. */
2516 case WM_EMACS_UNREGISTER_HOT_KEY
:
2517 focus_window
= GetFocus ();
2518 if (focus_window
!= NULL
)
2519 UnregisterHotKey (focus_window
, RAW_HOTKEY_ID (msg
.wParam
));
2520 /* Mark item as erased. NB: this code must be
2521 thread-safe. The next line is okay because the cons
2522 cell is never made into garbage and is not relocated by
2524 XSETCAR ((Lisp_Object
) ((EMACS_INT
) msg
.lParam
), Qnil
);
2525 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2528 case WM_EMACS_TOGGLE_LOCK_KEY
:
2530 int vk_code
= (int) msg
.wParam
;
2531 int cur_state
= (GetKeyState (vk_code
) & 1);
2532 Lisp_Object new_state
= (Lisp_Object
) ((EMACS_INT
) msg
.lParam
);
2534 /* NB: This code must be thread-safe. It is safe to
2535 call NILP because symbols are not relocated by GC,
2536 and pointer here is not touched by GC (so the markbit
2537 can't be set). Numbers are safe because they are
2538 immediate values. */
2539 if (NILP (new_state
)
2540 || (NUMBERP (new_state
)
2541 && ((XUINT (new_state
)) & 1) != cur_state
))
2543 one_w32_display_info
.faked_key
= vk_code
;
2545 keybd_event ((BYTE
) vk_code
,
2546 (BYTE
) MapVirtualKey (vk_code
, 0),
2547 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2548 keybd_event ((BYTE
) vk_code
,
2549 (BYTE
) MapVirtualKey (vk_code
, 0),
2550 KEYEVENTF_EXTENDEDKEY
| 0, 0);
2551 keybd_event ((BYTE
) vk_code
,
2552 (BYTE
) MapVirtualKey (vk_code
, 0),
2553 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2554 cur_state
= !cur_state
;
2556 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2562 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
2567 DispatchMessage (&msg
);
2570 /* Exit nested loop when our deferred message has completed. */
2571 if (msg_buf
->completed
)
2576 deferred_msg
* deferred_msg_head
;
2578 static deferred_msg
*
2579 find_deferred_msg (HWND hwnd
, UINT msg
)
2581 deferred_msg
* item
;
2583 /* Don't actually need synchronization for read access, since
2584 modification of single pointer is always atomic. */
2585 /* enter_crit (); */
2587 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2588 if (item
->w32msg
.msg
.hwnd
== hwnd
2589 && item
->w32msg
.msg
.message
== msg
)
2592 /* leave_crit (); */
2598 send_deferred_msg (deferred_msg
* msg_buf
,
2604 /* Only input thread can send deferred messages. */
2605 if (GetCurrentThreadId () != dwWindowsThreadId
)
2608 /* It is an error to send a message that is already deferred. */
2609 if (find_deferred_msg (hwnd
, msg
) != NULL
)
2612 /* Enforced synchronization is not needed because this is the only
2613 function that alters deferred_msg_head, and the following critical
2614 section is guaranteed to only be serially reentered (since only the
2615 input thread can call us). */
2617 /* enter_crit (); */
2619 msg_buf
->completed
= 0;
2620 msg_buf
->next
= deferred_msg_head
;
2621 deferred_msg_head
= msg_buf
;
2622 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
2624 /* leave_crit (); */
2626 /* Start a new nested message loop to process other messages until
2627 this one is completed. */
2628 w32_msg_pump (msg_buf
);
2630 deferred_msg_head
= msg_buf
->next
;
2632 return msg_buf
->result
;
2636 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
2638 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
2640 if (msg_buf
== NULL
)
2641 /* Message may have been cancelled, so don't abort(). */
2644 msg_buf
->result
= result
;
2645 msg_buf
->completed
= 1;
2647 /* Ensure input thread is woken so it notices the completion. */
2648 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2652 cancel_all_deferred_msgs ()
2654 deferred_msg
* item
;
2656 /* Don't actually need synchronization for read access, since
2657 modification of single pointer is always atomic. */
2658 /* enter_crit (); */
2660 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2663 item
->completed
= 1;
2666 /* leave_crit (); */
2668 /* Ensure input thread is woken so it notices the completion. */
2669 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2677 deferred_msg dummy_buf
;
2679 /* Ensure our message queue is created */
2681 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
2683 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2686 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
2687 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
2688 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
2690 /* This is the inital message loop which should only exit when the
2691 application quits. */
2692 w32_msg_pump (&dummy_buf
);
2698 signal_user_input ()
2700 /* Interrupt any lisp that wants to be interrupted by input. */
2701 if (!NILP (Vthrow_on_input
))
2703 Vquit_flag
= Vthrow_on_input
;
2704 /* If we're inside a function that wants immediate quits,
2706 if (immediate_quit
&& NILP (Vinhibit_quit
))
2716 post_character_message (hwnd
, msg
, wParam
, lParam
, modifiers
)
2726 wmsg
.dwModifiers
= modifiers
;
2728 /* Detect quit_char and set quit-flag directly. Note that we
2729 still need to post a message to ensure the main thread will be
2730 woken up if blocked in sys_select(), but we do NOT want to post
2731 the quit_char message itself (because it will usually be as if
2732 the user had typed quit_char twice). Instead, we post a dummy
2733 message that has no particular effect. */
2736 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
2737 c
= make_ctrl_char (c
) & 0377;
2739 || (wmsg
.dwModifiers
== 0 &&
2740 w32_quit_key
&& wParam
== w32_quit_key
))
2744 /* The choice of message is somewhat arbitrary, as long as
2745 the main thread handler just ignores it. */
2748 /* Interrupt any blocking system calls. */
2751 /* As a safety precaution, forcibly complete any deferred
2752 messages. This is a kludge, but I don't see any particularly
2753 clean way to handle the situation where a deferred message is
2754 "dropped" in the lisp thread, and will thus never be
2755 completed, eg. by the user trying to activate the menubar
2756 when the lisp thread is busy, and then typing C-g when the
2757 menubar doesn't open promptly (with the result that the
2758 menubar never responds at all because the deferred
2759 WM_INITMENU message is never completed). Another problem
2760 situation is when the lisp thread calls SendMessage (to send
2761 a window manager command) when a message has been deferred;
2762 the lisp thread gets blocked indefinitely waiting for the
2763 deferred message to be completed, which itself is waiting for
2764 the lisp thread to respond.
2766 Note that we don't want to block the input thread waiting for
2767 a reponse from the lisp thread (although that would at least
2768 solve the deadlock problem above), because we want to be able
2769 to receive C-g to interrupt the lisp thread. */
2770 cancel_all_deferred_msgs ();
2773 signal_user_input ();
2776 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2779 /* Main window procedure */
2782 w32_wnd_proc (hwnd
, msg
, wParam
, lParam
)
2789 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
2791 int windows_translate
;
2794 /* Note that it is okay to call x_window_to_frame, even though we are
2795 not running in the main lisp thread, because frame deletion
2796 requires the lisp thread to synchronize with this thread. Thus, if
2797 a frame struct is returned, it can be used without concern that the
2798 lisp thread might make it disappear while we are using it.
2800 NB. Walking the frame list in this thread is safe (as long as
2801 writes of Lisp_Object slots are atomic, which they are on Windows).
2802 Although delete-frame can destructively modify the frame list while
2803 we are walking it, a garbage collection cannot occur until after
2804 delete-frame has synchronized with this thread.
2806 It is also safe to use functions that make GDI calls, such as
2807 w32_clear_rect, because these functions must obtain a DC handle
2808 from the frame struct using get_frame_dc which is thread-aware. */
2813 f
= x_window_to_frame (dpyinfo
, hwnd
);
2816 HDC hdc
= get_frame_dc (f
);
2817 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
2818 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
2819 release_frame_dc (f
, hdc
);
2821 #if defined (W32_DEBUG_DISPLAY)
2822 DebPrint (("WM_ERASEBKGND (frame %p): erasing %d,%d-%d,%d\n",
2824 wmsg
.rect
.left
, wmsg
.rect
.top
,
2825 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2826 #endif /* W32_DEBUG_DISPLAY */
2829 case WM_PALETTECHANGED
:
2830 /* ignore our own changes */
2831 if ((HWND
)wParam
!= hwnd
)
2833 f
= x_window_to_frame (dpyinfo
, hwnd
);
2835 /* get_frame_dc will realize our palette and force all
2836 frames to be redrawn if needed. */
2837 release_frame_dc (f
, get_frame_dc (f
));
2842 PAINTSTRUCT paintStruct
;
2844 bzero (&update_rect
, sizeof (update_rect
));
2846 f
= x_window_to_frame (dpyinfo
, hwnd
);
2849 DebPrint (("WM_PAINT received for unknown window %p\n", hwnd
));
2853 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
2854 fails. Apparently this can happen under some
2856 if (GetUpdateRect (hwnd
, &update_rect
, FALSE
) || !w32_strict_painting
)
2859 BeginPaint (hwnd
, &paintStruct
);
2861 /* The rectangles returned by GetUpdateRect and BeginPaint
2862 do not always match. Play it safe by assuming both areas
2864 UnionRect (&(wmsg
.rect
), &update_rect
, &(paintStruct
.rcPaint
));
2866 #if defined (W32_DEBUG_DISPLAY)
2867 DebPrint (("WM_PAINT (frame %p): painting %d,%d-%d,%d\n",
2869 wmsg
.rect
.left
, wmsg
.rect
.top
,
2870 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2871 DebPrint ((" [update region is %d,%d-%d,%d]\n",
2872 update_rect
.left
, update_rect
.top
,
2873 update_rect
.right
, update_rect
.bottom
));
2875 EndPaint (hwnd
, &paintStruct
);
2878 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2883 /* If GetUpdateRect returns 0 (meaning there is no update
2884 region), assume the whole window needs to be repainted. */
2885 GetClientRect(hwnd
, &wmsg
.rect
);
2886 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2890 case WM_INPUTLANGCHANGE
:
2891 /* Inform lisp thread of keyboard layout changes. */
2892 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2894 /* Clear dead keys in the keyboard state; for simplicity only
2895 preserve modifier key states. */
2900 GetKeyboardState (keystate
);
2901 for (i
= 0; i
< 256; i
++)
2918 SetKeyboardState (keystate
);
2923 /* Synchronize hot keys with normal input. */
2924 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
2929 record_keyup (wParam
, lParam
);
2934 /* Ignore keystrokes we fake ourself; see below. */
2935 if (dpyinfo
->faked_key
== wParam
)
2937 dpyinfo
->faked_key
= 0;
2938 /* Make sure TranslateMessage sees them though (as long as
2939 they don't produce WM_CHAR messages). This ensures that
2940 indicator lights are toggled promptly on Windows 9x, for
2942 if (lispy_function_keys
[wParam
] != 0)
2944 windows_translate
= 1;
2950 /* Synchronize modifiers with current keystroke. */
2952 record_keydown (wParam
, lParam
);
2953 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
2955 windows_translate
= 0;
2960 if (NILP (Vw32_pass_lwindow_to_system
))
2962 /* Prevent system from acting on keyup (which opens the
2963 Start menu if no other key was pressed) by simulating a
2964 press of Space which we will ignore. */
2965 if (GetAsyncKeyState (wParam
) & 1)
2967 if (NUMBERP (Vw32_phantom_key_code
))
2968 key
= XUINT (Vw32_phantom_key_code
) & 255;
2971 dpyinfo
->faked_key
= key
;
2972 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
2975 if (!NILP (Vw32_lwindow_modifier
))
2979 if (NILP (Vw32_pass_rwindow_to_system
))
2981 if (GetAsyncKeyState (wParam
) & 1)
2983 if (NUMBERP (Vw32_phantom_key_code
))
2984 key
= XUINT (Vw32_phantom_key_code
) & 255;
2987 dpyinfo
->faked_key
= key
;
2988 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
2991 if (!NILP (Vw32_rwindow_modifier
))
2995 if (!NILP (Vw32_apps_modifier
))
2999 if (NILP (Vw32_pass_alt_to_system
))
3000 /* Prevent DefWindowProc from activating the menu bar if an
3001 Alt key is pressed and released by itself. */
3003 windows_translate
= 1;
3006 /* Decide whether to treat as modifier or function key. */
3007 if (NILP (Vw32_enable_caps_lock
))
3008 goto disable_lock_key
;
3009 windows_translate
= 1;
3012 /* Decide whether to treat as modifier or function key. */
3013 if (NILP (Vw32_enable_num_lock
))
3014 goto disable_lock_key
;
3015 windows_translate
= 1;
3018 /* Decide whether to treat as modifier or function key. */
3019 if (NILP (Vw32_scroll_lock_modifier
))
3020 goto disable_lock_key
;
3021 windows_translate
= 1;
3024 /* Ensure the appropriate lock key state (and indicator light)
3025 remains in the same state. We do this by faking another
3026 press of the relevant key. Apparently, this really is the
3027 only way to toggle the state of the indicator lights. */
3028 dpyinfo
->faked_key
= wParam
;
3029 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3030 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3031 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3032 KEYEVENTF_EXTENDEDKEY
| 0, 0);
3033 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3034 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3035 /* Ensure indicator lights are updated promptly on Windows 9x
3036 (TranslateMessage apparently does this), after forwarding
3038 post_character_message (hwnd
, msg
, wParam
, lParam
,
3039 w32_get_key_modifiers (wParam
, lParam
));
3040 windows_translate
= 1;
3044 case VK_PROCESSKEY
: /* Generated by IME. */
3045 windows_translate
= 1;
3048 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
3049 which is confusing for purposes of key binding; convert
3050 VK_CANCEL events into VK_PAUSE events. */
3054 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
3055 for purposes of key binding; convert these back into
3056 VK_NUMLOCK events, at least when we want to see NumLock key
3057 presses. (Note that there is never any possibility that
3058 VK_PAUSE with Ctrl really is C-Pause as per above.) */
3059 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
3060 wParam
= VK_NUMLOCK
;
3063 /* If not defined as a function key, change it to a WM_CHAR message. */
3064 if (lispy_function_keys
[wParam
] == 0)
3066 DWORD modifiers
= construct_console_modifiers ();
3068 if (!NILP (Vw32_recognize_altgr
)
3069 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
3071 /* Always let TranslateMessage handle AltGr key chords;
3072 for some reason, ToAscii doesn't always process AltGr
3073 chords correctly. */
3074 windows_translate
= 1;
3076 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
3078 /* Handle key chords including any modifiers other
3079 than shift directly, in order to preserve as much
3080 modifier information as possible. */
3081 if ('A' <= wParam
&& wParam
<= 'Z')
3083 /* Don't translate modified alphabetic keystrokes,
3084 so the user doesn't need to constantly switch
3085 layout to type control or meta keystrokes when
3086 the normal layout translates alphabetic
3087 characters to non-ascii characters. */
3088 if (!modifier_set (VK_SHIFT
))
3089 wParam
+= ('a' - 'A');
3094 /* Try to handle other keystrokes by determining the
3095 base character (ie. translating the base key plus
3099 KEY_EVENT_RECORD key
;
3101 key
.bKeyDown
= TRUE
;
3102 key
.wRepeatCount
= 1;
3103 key
.wVirtualKeyCode
= wParam
;
3104 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
3105 key
.uChar
.AsciiChar
= 0;
3106 key
.dwControlKeyState
= modifiers
;
3108 add
= w32_kbd_patch_key (&key
);
3109 /* 0 means an unrecognised keycode, negative means
3110 dead key. Ignore both. */
3113 /* Forward asciified character sequence. */
3114 post_character_message
3115 (hwnd
, WM_CHAR
, key
.uChar
.AsciiChar
, lParam
,
3116 w32_get_key_modifiers (wParam
, lParam
));
3117 w32_kbd_patch_key (&key
);
3124 /* Let TranslateMessage handle everything else. */
3125 windows_translate
= 1;
3131 if (windows_translate
)
3133 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
3135 windows_msg
.time
= GetMessageTime ();
3136 TranslateMessage (&windows_msg
);
3144 post_character_message (hwnd
, msg
, wParam
, lParam
,
3145 w32_get_key_modifiers (wParam
, lParam
));
3148 /* Simulate middle mouse button events when left and right buttons
3149 are used together, but only if user has two button mouse. */
3150 case WM_LBUTTONDOWN
:
3151 case WM_RBUTTONDOWN
:
3152 if (w32_num_mouse_buttons
> 2)
3153 goto handle_plain_button
;
3156 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
3157 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
3159 if (button_state
& this)
3162 if (button_state
== 0)
3165 button_state
|= this;
3167 if (button_state
& other
)
3169 if (mouse_button_timer
)
3171 KillTimer (hwnd
, mouse_button_timer
);
3172 mouse_button_timer
= 0;
3174 /* Generate middle mouse event instead. */
3175 msg
= WM_MBUTTONDOWN
;
3176 button_state
|= MMOUSE
;
3178 else if (button_state
& MMOUSE
)
3180 /* Ignore button event if we've already generated a
3181 middle mouse down event. This happens if the
3182 user releases and press one of the two buttons
3183 after we've faked a middle mouse event. */
3188 /* Flush out saved message. */
3189 post_msg (&saved_mouse_button_msg
);
3191 wmsg
.dwModifiers
= w32_get_modifiers ();
3192 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3194 /* Clear message buffer. */
3195 saved_mouse_button_msg
.msg
.hwnd
= 0;
3199 /* Hold onto message for now. */
3200 mouse_button_timer
=
3201 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
3202 w32_mouse_button_tolerance
, NULL
);
3203 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
3204 saved_mouse_button_msg
.msg
.message
= msg
;
3205 saved_mouse_button_msg
.msg
.wParam
= wParam
;
3206 saved_mouse_button_msg
.msg
.lParam
= lParam
;
3207 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
3208 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
3215 if (w32_num_mouse_buttons
> 2)
3216 goto handle_plain_button
;
3219 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
3220 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
3222 if ((button_state
& this) == 0)
3225 button_state
&= ~this;
3227 if (button_state
& MMOUSE
)
3229 /* Only generate event when second button is released. */
3230 if ((button_state
& other
) == 0)
3233 button_state
&= ~MMOUSE
;
3235 if (button_state
) abort ();
3242 /* Flush out saved message if necessary. */
3243 if (saved_mouse_button_msg
.msg
.hwnd
)
3245 post_msg (&saved_mouse_button_msg
);
3248 wmsg
.dwModifiers
= w32_get_modifiers ();
3249 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3251 /* Always clear message buffer and cancel timer. */
3252 saved_mouse_button_msg
.msg
.hwnd
= 0;
3253 KillTimer (hwnd
, mouse_button_timer
);
3254 mouse_button_timer
= 0;
3256 if (button_state
== 0)
3261 case WM_XBUTTONDOWN
:
3263 if (w32_pass_extra_mouse_buttons_to_system
)
3265 /* else fall through and process them. */
3266 case WM_MBUTTONDOWN
:
3268 handle_plain_button
:
3273 /* Ignore middle and extra buttons as long as the menu is active. */
3274 f
= x_window_to_frame (dpyinfo
, hwnd
);
3275 if (f
&& f
->output_data
.w32
->menubar_active
)
3278 if (parse_button (msg
, HIWORD (wParam
), &button
, &up
))
3280 if (up
) ReleaseCapture ();
3281 else SetCapture (hwnd
);
3282 button
= (button
== 0) ? LMOUSE
:
3283 ((button
== 1) ? MMOUSE
: RMOUSE
);
3285 button_state
&= ~button
;
3287 button_state
|= button
;
3291 wmsg
.dwModifiers
= w32_get_modifiers ();
3292 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3293 signal_user_input ();
3295 /* Need to return true for XBUTTON messages, false for others,
3296 to indicate that we processed the message. */
3297 return (msg
== WM_XBUTTONDOWN
|| msg
== WM_XBUTTONUP
);
3300 /* If the mouse has just moved into the frame, start tracking
3301 it, so we will be notified when it leaves the frame. Mouse
3302 tracking only works under W98 and NT4 and later. On earlier
3303 versions, there is no way of telling when the mouse leaves the
3304 frame, so we just have to put up with help-echo and mouse
3305 highlighting remaining while the frame is not active. */
3306 if (track_mouse_event_fn
&& !track_mouse_window
)
3308 TRACKMOUSEEVENT tme
;
3309 tme
.cbSize
= sizeof (tme
);
3310 tme
.dwFlags
= TME_LEAVE
;
3311 tme
.hwndTrack
= hwnd
;
3313 track_mouse_event_fn (&tme
);
3314 track_mouse_window
= hwnd
;
3317 if (w32_mouse_move_interval
<= 0
3318 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
3320 wmsg
.dwModifiers
= w32_get_modifiers ();
3321 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3325 /* Hang onto mouse move and scroll messages for a bit, to avoid
3326 sending such events to Emacs faster than it can process them.
3327 If we get more events before the timer from the first message
3328 expires, we just replace the first message. */
3330 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
3332 SetTimer (hwnd
, MOUSE_MOVE_ID
,
3333 w32_mouse_move_interval
, NULL
);
3335 /* Hold onto message for now. */
3336 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
3337 saved_mouse_move_msg
.msg
.message
= msg
;
3338 saved_mouse_move_msg
.msg
.wParam
= wParam
;
3339 saved_mouse_move_msg
.msg
.lParam
= lParam
;
3340 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
3341 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
3346 wmsg
.dwModifiers
= w32_get_modifiers ();
3347 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3348 signal_user_input ();
3352 wmsg
.dwModifiers
= w32_get_modifiers ();
3353 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3354 signal_user_input ();
3358 /* Flush out saved messages if necessary. */
3359 if (wParam
== mouse_button_timer
)
3361 if (saved_mouse_button_msg
.msg
.hwnd
)
3363 post_msg (&saved_mouse_button_msg
);
3364 signal_user_input ();
3365 saved_mouse_button_msg
.msg
.hwnd
= 0;
3367 KillTimer (hwnd
, mouse_button_timer
);
3368 mouse_button_timer
= 0;
3370 else if (wParam
== mouse_move_timer
)
3372 if (saved_mouse_move_msg
.msg
.hwnd
)
3374 post_msg (&saved_mouse_move_msg
);
3375 saved_mouse_move_msg
.msg
.hwnd
= 0;
3377 KillTimer (hwnd
, mouse_move_timer
);
3378 mouse_move_timer
= 0;
3380 else if (wParam
== menu_free_timer
)
3382 KillTimer (hwnd
, menu_free_timer
);
3383 menu_free_timer
= 0;
3384 f
= x_window_to_frame (dpyinfo
, hwnd
);
3385 if (!f
->output_data
.w32
->menu_command_in_progress
)
3387 /* Free memory used by owner-drawn and help-echo strings. */
3388 w32_free_menu_strings (hwnd
);
3389 f
->output_data
.w32
->menubar_active
= 0;
3395 /* Windows doesn't send us focus messages when putting up and
3396 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
3397 The only indication we get that something happened is receiving
3398 this message afterwards. So this is a good time to reset our
3399 keyboard modifiers' state. */
3406 /* We must ensure menu bar is fully constructed and up to date
3407 before allowing user interaction with it. To achieve this
3408 we send this message to the lisp thread and wait for a
3409 reply (whose value is not actually needed) to indicate that
3410 the menu bar is now ready for use, so we can now return.
3412 To remain responsive in the meantime, we enter a nested message
3413 loop that can process all other messages.
3415 However, we skip all this if the message results from calling
3416 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
3417 thread a message because it is blocked on us at this point. We
3418 set menubar_active before calling TrackPopupMenu to indicate
3419 this (there is no possibility of confusion with real menubar
3422 f
= x_window_to_frame (dpyinfo
, hwnd
);
3424 && (f
->output_data
.w32
->menubar_active
3425 /* We can receive this message even in the absence of a
3426 menubar (ie. when the system menu is activated) - in this
3427 case we do NOT want to forward the message, otherwise it
3428 will cause the menubar to suddenly appear when the user
3429 had requested it to be turned off! */
3430 || f
->output_data
.w32
->menubar_widget
== NULL
))
3434 deferred_msg msg_buf
;
3436 /* Detect if message has already been deferred; in this case
3437 we cannot return any sensible value to ignore this. */
3438 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3441 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
3444 case WM_EXITMENULOOP
:
3445 f
= x_window_to_frame (dpyinfo
, hwnd
);
3447 /* If a menu command is not already in progress, check again
3448 after a short delay, since Windows often (always?) sends the
3449 WM_EXITMENULOOP before the corresponding WM_COMMAND message. */
3450 if (f
&& !f
->output_data
.w32
->menu_command_in_progress
)
3451 menu_free_timer
= SetTimer (hwnd
, MENU_FREE_ID
, MENU_FREE_DELAY
, NULL
);
3455 /* Direct handling of help_echo in menus. Should be safe now
3456 that we generate the help_echo by placing a help event in the
3459 HMENU menu
= (HMENU
) lParam
;
3460 UINT menu_item
= (UINT
) LOWORD (wParam
);
3461 UINT flags
= (UINT
) HIWORD (wParam
);
3463 w32_menu_display_help (hwnd
, menu
, menu_item
, flags
);
3467 case WM_MEASUREITEM
:
3468 f
= x_window_to_frame (dpyinfo
, hwnd
);
3471 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
3473 if (pMis
->CtlType
== ODT_MENU
)
3475 /* Work out dimensions for popup menu titles. */
3476 char * title
= (char *) pMis
->itemData
;
3477 HDC hdc
= GetDC (hwnd
);
3478 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3479 LOGFONT menu_logfont
;
3483 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3484 menu_logfont
.lfWeight
= FW_BOLD
;
3485 menu_font
= CreateFontIndirect (&menu_logfont
);
3486 old_font
= SelectObject (hdc
, menu_font
);
3488 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
3491 if (unicode_append_menu
)
3492 GetTextExtentPoint32W (hdc
, (WCHAR
*) title
,
3493 wcslen ((WCHAR
*) title
),
3496 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
3498 pMis
->itemWidth
= size
.cx
;
3499 if (pMis
->itemHeight
< size
.cy
)
3500 pMis
->itemHeight
= size
.cy
;
3503 pMis
->itemWidth
= 0;
3505 SelectObject (hdc
, old_font
);
3506 DeleteObject (menu_font
);
3507 ReleaseDC (hwnd
, hdc
);
3514 f
= x_window_to_frame (dpyinfo
, hwnd
);
3517 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
3519 if (pDis
->CtlType
== ODT_MENU
)
3521 /* Draw popup menu title. */
3522 char * title
= (char *) pDis
->itemData
;
3525 HDC hdc
= pDis
->hDC
;
3526 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3527 LOGFONT menu_logfont
;
3530 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3531 menu_logfont
.lfWeight
= FW_BOLD
;
3532 menu_font
= CreateFontIndirect (&menu_logfont
);
3533 old_font
= SelectObject (hdc
, menu_font
);
3535 /* Always draw title as if not selected. */
3536 if (unicode_append_menu
)
3539 + GetSystemMetrics (SM_CXMENUCHECK
),
3541 ETO_OPAQUE
, &pDis
->rcItem
,
3543 wcslen ((WCHAR
*) title
), NULL
);
3547 + GetSystemMetrics (SM_CXMENUCHECK
),
3549 ETO_OPAQUE
, &pDis
->rcItem
,
3550 title
, strlen (title
), NULL
);
3552 SelectObject (hdc
, old_font
);
3553 DeleteObject (menu_font
);
3561 /* Still not right - can't distinguish between clicks in the
3562 client area of the frame from clicks forwarded from the scroll
3563 bars - may have to hook WM_NCHITTEST to remember the mouse
3564 position and then check if it is in the client area ourselves. */
3565 case WM_MOUSEACTIVATE
:
3566 /* Discard the mouse click that activates a frame, allowing the
3567 user to click anywhere without changing point (or worse!).
3568 Don't eat mouse clicks on scrollbars though!! */
3569 if (LOWORD (lParam
) == HTCLIENT
)
3570 return MA_ACTIVATEANDEAT
;
3575 /* No longer tracking mouse. */
3576 track_mouse_window
= NULL
;
3578 case WM_ACTIVATEAPP
:
3580 case WM_WINDOWPOSCHANGED
:
3582 /* Inform lisp thread that a frame might have just been obscured
3583 or exposed, so should recheck visibility of all frames. */
3584 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3588 dpyinfo
->faked_key
= 0;
3590 register_hot_keys (hwnd
);
3593 unregister_hot_keys (hwnd
);
3596 /* Relinquish the system caret. */
3597 if (w32_system_caret_hwnd
)
3599 w32_visible_system_caret_hwnd
= NULL
;
3600 w32_system_caret_hwnd
= NULL
;
3605 f
= x_window_to_frame (dpyinfo
, hwnd
);
3606 if (f
&& HIWORD (wParam
) == 0)
3608 f
->output_data
.w32
->menu_command_in_progress
= 1;
3609 if (menu_free_timer
)
3611 KillTimer (hwnd
, menu_free_timer
);
3612 menu_free_timer
= 0;
3618 wmsg
.dwModifiers
= w32_get_modifiers ();
3619 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3623 wmsg
.dwModifiers
= w32_get_modifiers ();
3624 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3627 case WM_WINDOWPOSCHANGING
:
3628 /* Don't restrict the sizing of tip frames. */
3629 if (hwnd
== tip_window
)
3633 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
3635 wp
.length
= sizeof (WINDOWPLACEMENT
);
3636 GetWindowPlacement (hwnd
, &wp
);
3638 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
3645 DWORD internal_border
;
3646 DWORD scrollbar_extra
;
3649 wp
.length
= sizeof(wp
);
3650 GetWindowRect (hwnd
, &wr
);
3654 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
3655 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
3656 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
3657 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
3661 memset (&rect
, 0, sizeof (rect
));
3662 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
3663 GetMenu (hwnd
) != NULL
);
3665 /* Force width and height of client area to be exact
3666 multiples of the character cell dimensions. */
3667 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
3668 - 2 * internal_border
- scrollbar_extra
)
3670 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
3671 - 2 * internal_border
)
3676 /* For right/bottom sizing we can just fix the sizes.
3677 However for top/left sizing we will need to fix the X
3678 and Y positions as well. */
3683 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
3684 && (lppos
->flags
& SWP_NOMOVE
) == 0)
3686 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
3693 lppos
->flags
|= SWP_NOMOVE
;
3704 case WM_GETMINMAXINFO
:
3705 /* Hack to correct bug that allows Emacs frames to be resized
3706 below the Minimum Tracking Size. */
3707 ((LPMINMAXINFO
) lParam
)->ptMinTrackSize
.y
++;
3708 /* Hack to allow resizing the Emacs frame above the screen size.
3709 Note that Windows 9x limits coordinates to 16-bits. */
3710 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.x
= 32767;
3711 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.y
= 32767;
3715 if (LOWORD (lParam
) == HTCLIENT
)
3720 case WM_EMACS_SETCURSOR
:
3722 Cursor cursor
= (Cursor
) wParam
;
3728 case WM_EMACS_CREATESCROLLBAR
:
3729 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
3730 (struct scroll_bar
*) lParam
);
3732 case WM_EMACS_SHOWWINDOW
:
3733 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
3735 case WM_EMACS_SETFOREGROUND
:
3737 HWND foreground_window
;
3738 DWORD foreground_thread
, retval
;
3740 /* On NT 5.0, and apparently Windows 98, it is necessary to
3741 attach to the thread that currently has focus in order to
3742 pull the focus away from it. */
3743 foreground_window
= GetForegroundWindow ();
3744 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
3745 if (!foreground_window
3746 || foreground_thread
== GetCurrentThreadId ()
3747 || !AttachThreadInput (GetCurrentThreadId (),
3748 foreground_thread
, TRUE
))
3749 foreground_thread
= 0;
3751 retval
= SetForegroundWindow ((HWND
) wParam
);
3753 /* Detach from the previous foreground thread. */
3754 if (foreground_thread
)
3755 AttachThreadInput (GetCurrentThreadId (),
3756 foreground_thread
, FALSE
);
3761 case WM_EMACS_SETWINDOWPOS
:
3763 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
3764 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
3765 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
3768 case WM_EMACS_DESTROYWINDOW
:
3769 DragAcceptFiles ((HWND
) wParam
, FALSE
);
3770 return DestroyWindow ((HWND
) wParam
);
3772 case WM_EMACS_HIDE_CARET
:
3773 return HideCaret (hwnd
);
3775 case WM_EMACS_SHOW_CARET
:
3776 return ShowCaret (hwnd
);
3778 case WM_EMACS_DESTROY_CARET
:
3779 w32_system_caret_hwnd
= NULL
;
3780 w32_visible_system_caret_hwnd
= NULL
;
3781 return DestroyCaret ();
3783 case WM_EMACS_TRACK_CARET
:
3784 /* If there is currently no system caret, create one. */
3785 if (w32_system_caret_hwnd
== NULL
)
3787 /* Use the default caret width, and avoid changing it
3788 unneccesarily, as it confuses screen reader software. */
3789 w32_system_caret_hwnd
= hwnd
;
3790 CreateCaret (hwnd
, NULL
, 0,
3791 w32_system_caret_height
);
3794 if (!SetCaretPos (w32_system_caret_x
, w32_system_caret_y
))
3796 /* Ensure visible caret gets turned on when requested. */
3797 else if (w32_use_visible_system_caret
3798 && w32_visible_system_caret_hwnd
!= hwnd
)
3800 w32_visible_system_caret_hwnd
= hwnd
;
3801 return ShowCaret (hwnd
);
3803 /* Ensure visible caret gets turned off when requested. */
3804 else if (!w32_use_visible_system_caret
3805 && w32_visible_system_caret_hwnd
)
3807 w32_visible_system_caret_hwnd
= NULL
;
3808 return HideCaret (hwnd
);
3813 case WM_EMACS_TRACKPOPUPMENU
:
3818 pos
= (POINT
*)lParam
;
3819 flags
= TPM_CENTERALIGN
;
3820 if (button_state
& LMOUSE
)
3821 flags
|= TPM_LEFTBUTTON
;
3822 else if (button_state
& RMOUSE
)
3823 flags
|= TPM_RIGHTBUTTON
;
3825 /* Remember we did a SetCapture on the initial mouse down event,
3826 so for safety, we make sure the capture is cancelled now. */
3830 /* Use menubar_active to indicate that WM_INITMENU is from
3831 TrackPopupMenu below, and should be ignored. */
3832 f
= x_window_to_frame (dpyinfo
, hwnd
);
3834 f
->output_data
.w32
->menubar_active
= 1;
3836 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
3840 /* Eat any mouse messages during popupmenu */
3841 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
3843 /* Get the menu selection, if any */
3844 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
3846 retval
= LOWORD (amsg
.wParam
);
3862 /* Check for messages registered at runtime. */
3863 if (msg
== msh_mousewheel
)
3865 wmsg
.dwModifiers
= w32_get_modifiers ();
3866 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3867 signal_user_input ();
3872 return DefWindowProc (hwnd
, msg
, wParam
, lParam
);
3876 /* The most common default return code for handled messages is 0. */
3881 my_create_window (f
)
3886 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
3888 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
3892 /* Create a tooltip window. Unlike my_create_window, we do not do this
3893 indirectly via the Window thread, as we do not need to process Window
3894 messages for the tooltip. Creating tooltips indirectly also creates
3895 deadlocks when tooltips are created for menu items. */
3897 my_create_tip_window (f
)
3902 rect
.left
= rect
.top
= 0;
3903 rect
.right
= FRAME_PIXEL_WIDTH (f
);
3904 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
3906 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
3907 FRAME_EXTERNAL_MENU_BAR (f
));
3909 tip_window
= FRAME_W32_WINDOW (f
)
3910 = CreateWindow (EMACS_CLASS
,
3912 f
->output_data
.w32
->dwStyle
,
3915 rect
.right
- rect
.left
,
3916 rect
.bottom
- rect
.top
,
3917 FRAME_W32_WINDOW (SELECTED_FRAME ()), /* owner */
3924 SetWindowLong (tip_window
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
3925 SetWindowLong (tip_window
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
3926 SetWindowLong (tip_window
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
3927 SetWindowLong (tip_window
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
3929 /* Tip frames have no scrollbars. */
3930 SetWindowLong (tip_window
, WND_SCROLLBAR_INDEX
, 0);
3932 /* Do this to discard the default setting specified by our parent. */
3933 ShowWindow (tip_window
, SW_HIDE
);
3938 /* Create and set up the w32 window for frame F. */
3941 w32_window (f
, window_prompting
, minibuffer_only
)
3943 long window_prompting
;
3944 int minibuffer_only
;
3948 /* Use the resource name as the top-level window name
3949 for looking up resources. Make a non-Lisp copy
3950 for the window manager, so GC relocation won't bother it.
3952 Elsewhere we specify the window name for the window manager. */
3955 char *str
= (char *) SDATA (Vx_resource_name
);
3956 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
3957 strcpy (f
->namebuf
, str
);
3960 my_create_window (f
);
3962 validate_x_resource_name ();
3964 /* x_set_name normally ignores requests to set the name if the
3965 requested name is the same as the current name. This is the one
3966 place where that assumption isn't correct; f->name is set, but
3967 the server hasn't been told. */
3970 int explicit = f
->explicit_name
;
3972 f
->explicit_name
= 0;
3975 x_set_name (f
, name
, explicit);
3980 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
3981 initialize_frame_menubar (f
);
3983 if (FRAME_W32_WINDOW (f
) == 0)
3984 error ("Unable to create window");
3987 /* Handle the icon stuff for this window. Perhaps later we might
3988 want an x_set_icon_position which can be called interactively as
3996 Lisp_Object icon_x
, icon_y
;
3998 /* Set the position of the icon. Note that Windows 95 groups all
3999 icons in the tray. */
4000 icon_x
= w32_get_arg (parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
4001 icon_y
= w32_get_arg (parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
4002 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
4004 CHECK_NUMBER (icon_x
);
4005 CHECK_NUMBER (icon_y
);
4007 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
4008 error ("Both left and top icon corners of icon must be specified");
4012 if (! EQ (icon_x
, Qunbound
))
4013 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
4016 /* Start up iconic or window? */
4017 x_wm_set_window_state
4018 (f
, (EQ (w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
4022 x_text_icon (f
, (char *) SDATA ((!NILP (f
->icon_name
)
4035 XGCValues gc_values
;
4039 /* Create the GC's of this frame.
4040 Note that many default values are used. */
4043 gc_values
.font
= FRAME_FONT (f
);
4045 /* Cursor has cursor-color background, background-color foreground. */
4046 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
4047 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
4048 f
->output_data
.w32
->cursor_gc
4049 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
4050 (GCFont
| GCForeground
| GCBackground
),
4054 f
->output_data
.w32
->white_relief
.gc
= 0;
4055 f
->output_data
.w32
->black_relief
.gc
= 0;
4061 /* Handler for signals raised during x_create_frame and
4062 x_create_top_frame. FRAME is the frame which is partially
4066 unwind_create_frame (frame
)
4069 struct frame
*f
= XFRAME (frame
);
4071 /* If frame is ``official'', nothing to do. */
4072 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
4075 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4078 x_free_frame_resources (f
);
4080 /* Check that reference counts are indeed correct. */
4081 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
4082 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
4091 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
4093 doc
: /* Make a new window, which is called a \"frame\" in Emacs terms.
4094 Returns an Emacs frame object.
4095 PARAMETERS is an alist of frame parameters.
4096 If the parameters specify that the frame should not have a minibuffer,
4097 and do not specify a specific minibuffer window to use,
4098 then `default-minibuffer-frame' must be a frame whose minibuffer can
4099 be shared by the new frame.
4101 This function is an internal primitive--use `make-frame' instead. */)
4103 Lisp_Object parameters
;
4106 Lisp_Object frame
, tem
;
4108 int minibuffer_only
= 0;
4109 long window_prompting
= 0;
4111 int count
= SPECPDL_INDEX ();
4112 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4113 Lisp_Object display
;
4114 struct w32_display_info
*dpyinfo
= NULL
;
4120 /* Use this general default value to start with
4121 until we know if this frame has a specified name. */
4122 Vx_resource_name
= Vinvocation_name
;
4124 display
= w32_get_arg (parameters
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
4125 if (EQ (display
, Qunbound
))
4127 dpyinfo
= check_x_display_info (display
);
4129 kb
= dpyinfo
->kboard
;
4131 kb
= &the_only_kboard
;
4134 name
= w32_get_arg (parameters
, Qname
, "name", "Name", RES_TYPE_STRING
);
4136 && ! EQ (name
, Qunbound
)
4138 error ("Invalid frame name--not a string or nil");
4141 Vx_resource_name
= name
;
4143 /* See if parent window is specified. */
4144 parent
= w32_get_arg (parameters
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
4145 if (EQ (parent
, Qunbound
))
4147 if (! NILP (parent
))
4148 CHECK_NUMBER (parent
);
4150 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
4151 /* No need to protect DISPLAY because that's not used after passing
4152 it to make_frame_without_minibuffer. */
4154 GCPRO4 (parameters
, parent
, name
, frame
);
4155 tem
= w32_get_arg (parameters
, Qminibuffer
, "minibuffer", "Minibuffer",
4157 if (EQ (tem
, Qnone
) || NILP (tem
))
4158 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
4159 else if (EQ (tem
, Qonly
))
4161 f
= make_minibuffer_frame ();
4162 minibuffer_only
= 1;
4164 else if (WINDOWP (tem
))
4165 f
= make_frame_without_minibuffer (tem
, kb
, display
);
4169 XSETFRAME (frame
, f
);
4171 /* Note that Windows does support scroll bars. */
4172 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
4174 /* By default, make scrollbars the system standard width. */
4175 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
4177 f
->output_method
= output_w32
;
4178 f
->output_data
.w32
=
4179 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
4180 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
4181 FRAME_FONTSET (f
) = -1;
4182 record_unwind_protect (unwind_create_frame
, frame
);
4185 = w32_get_arg (parameters
, Qicon_name
, "iconName", "Title", RES_TYPE_STRING
);
4186 if (! STRINGP (f
->icon_name
))
4187 f
->icon_name
= Qnil
;
4189 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
4191 FRAME_KBOARD (f
) = kb
;
4194 /* Specify the parent under which to make this window. */
4198 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
4199 f
->output_data
.w32
->explicit_parent
= 1;
4203 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4204 f
->output_data
.w32
->explicit_parent
= 0;
4207 /* Set the name; the functions to which we pass f expect the name to
4209 if (EQ (name
, Qunbound
) || NILP (name
))
4211 f
->name
= build_string (dpyinfo
->w32_id_name
);
4212 f
->explicit_name
= 0;
4217 f
->explicit_name
= 1;
4218 /* use the frame's title when getting resources for this frame. */
4219 specbind (Qx_resource_name
, name
);
4222 /* Extract the window parameters from the supplied values
4223 that are needed to determine window geometry. */
4227 font
= w32_get_arg (parameters
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4230 /* First, try whatever font the caller has specified. */
4233 tem
= Fquery_fontset (font
, Qnil
);
4235 font
= x_new_fontset (f
, SDATA (tem
));
4237 font
= x_new_font (f
, SDATA (font
));
4239 /* Try out a font which we hope has bold and italic variations. */
4240 if (!STRINGP (font
))
4241 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
4242 if (! STRINGP (font
))
4243 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
4244 /* If those didn't work, look for something which will at least work. */
4245 if (! STRINGP (font
))
4246 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
4248 if (! STRINGP (font
))
4249 font
= build_string ("Fixedsys");
4251 x_default_parameter (f
, parameters
, Qfont
, font
,
4252 "font", "Font", RES_TYPE_STRING
);
4255 x_default_parameter (f
, parameters
, Qborder_width
, make_number (2),
4256 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4257 /* This defaults to 2 in order to match xterm. We recognize either
4258 internalBorderWidth or internalBorder (which is what xterm calls
4260 if (NILP (Fassq (Qinternal_border_width
, parameters
)))
4264 value
= w32_get_arg (parameters
, Qinternal_border_width
,
4265 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
4266 if (! EQ (value
, Qunbound
))
4267 parameters
= Fcons (Fcons (Qinternal_border_width
, value
),
4270 /* Default internalBorderWidth to 0 on Windows to match other programs. */
4271 x_default_parameter (f
, parameters
, Qinternal_border_width
, make_number (0),
4272 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
4273 x_default_parameter (f
, parameters
, Qvertical_scroll_bars
, Qright
,
4274 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
4276 /* Also do the stuff which must be set before the window exists. */
4277 x_default_parameter (f
, parameters
, Qforeground_color
, build_string ("black"),
4278 "foreground", "Foreground", RES_TYPE_STRING
);
4279 x_default_parameter (f
, parameters
, Qbackground_color
, build_string ("white"),
4280 "background", "Background", RES_TYPE_STRING
);
4281 x_default_parameter (f
, parameters
, Qmouse_color
, build_string ("black"),
4282 "pointerColor", "Foreground", RES_TYPE_STRING
);
4283 x_default_parameter (f
, parameters
, Qcursor_color
, build_string ("black"),
4284 "cursorColor", "Foreground", RES_TYPE_STRING
);
4285 x_default_parameter (f
, parameters
, Qborder_color
, build_string ("black"),
4286 "borderColor", "BorderColor", RES_TYPE_STRING
);
4287 x_default_parameter (f
, parameters
, Qscreen_gamma
, Qnil
,
4288 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
4289 x_default_parameter (f
, parameters
, Qline_spacing
, Qnil
,
4290 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
4291 x_default_parameter (f
, parameters
, Qleft_fringe
, Qnil
,
4292 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
4293 x_default_parameter (f
, parameters
, Qright_fringe
, Qnil
,
4294 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
4297 /* Init faces before x_default_parameter is called for scroll-bar
4298 parameters because that function calls x_set_scroll_bar_width,
4299 which calls change_frame_size, which calls Fset_window_buffer,
4300 which runs hooks, which call Fvertical_motion. At the end, we
4301 end up in init_iterator with a null face cache, which should not
4303 init_frame_faces (f
);
4305 x_default_parameter (f
, parameters
, Qmenu_bar_lines
, make_number (1),
4306 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
4307 x_default_parameter (f
, parameters
, Qtool_bar_lines
, make_number (1),
4308 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
4310 x_default_parameter (f
, parameters
, Qbuffer_predicate
, Qnil
,
4311 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
4312 x_default_parameter (f
, parameters
, Qtitle
, Qnil
,
4313 "title", "Title", RES_TYPE_STRING
);
4314 x_default_parameter (f
, parameters
, Qfullscreen
, Qnil
,
4315 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
4317 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
4318 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4320 f
->output_data
.w32
->text_cursor
= w32_load_cursor (IDC_IBEAM
);
4321 f
->output_data
.w32
->nontext_cursor
= w32_load_cursor (IDC_ARROW
);
4322 f
->output_data
.w32
->modeline_cursor
= w32_load_cursor (IDC_ARROW
);
4323 f
->output_data
.w32
->hand_cursor
= w32_load_cursor (IDC_HAND
);
4324 f
->output_data
.w32
->hourglass_cursor
= w32_load_cursor (IDC_WAIT
);
4325 f
->output_data
.w32
->horizontal_drag_cursor
= w32_load_cursor (IDC_SIZEWE
);
4327 window_prompting
= x_figure_window_size (f
, parameters
, 1);
4329 tem
= w32_get_arg (parameters
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
4330 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
4332 w32_window (f
, window_prompting
, minibuffer_only
);
4333 x_icon (f
, parameters
);
4337 /* Now consider the frame official. */
4338 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
4339 Vframe_list
= Fcons (frame
, Vframe_list
);
4341 /* We need to do this after creating the window, so that the
4342 icon-creation functions can say whose icon they're describing. */
4343 x_default_parameter (f
, parameters
, Qicon_type
, Qnil
,
4344 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
4346 x_default_parameter (f
, parameters
, Qauto_raise
, Qnil
,
4347 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4348 x_default_parameter (f
, parameters
, Qauto_lower
, Qnil
,
4349 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4350 x_default_parameter (f
, parameters
, Qcursor_type
, Qbox
,
4351 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4352 x_default_parameter (f
, parameters
, Qscroll_bar_width
, Qnil
,
4353 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
4355 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4356 Change will not be effected unless different from the current
4358 width
= FRAME_COLS (f
);
4359 height
= FRAME_LINES (f
);
4361 FRAME_LINES (f
) = 0;
4362 SET_FRAME_COLS (f
, 0);
4363 change_frame_size (f
, height
, width
, 1, 0, 0);
4365 /* Tell the server what size and position, etc, we want, and how
4366 badly we want them. This should be done after we have the menu
4367 bar so that its size can be taken into account. */
4369 x_wm_set_size_hint (f
, window_prompting
, 0);
4372 /* Make the window appear on the frame and enable display, unless
4373 the caller says not to. However, with explicit parent, Emacs
4374 cannot control visibility, so don't try. */
4375 if (! f
->output_data
.w32
->explicit_parent
)
4377 Lisp_Object visibility
;
4379 visibility
= w32_get_arg (parameters
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
4380 if (EQ (visibility
, Qunbound
))
4383 if (EQ (visibility
, Qicon
))
4384 x_iconify_frame (f
);
4385 else if (! NILP (visibility
))
4386 x_make_frame_visible (f
);
4388 /* Must have been Qnil. */
4393 /* Make sure windows on this frame appear in calls to next-window
4394 and similar functions. */
4395 Vwindow_list
= Qnil
;
4397 return unbind_to (count
, frame
);
4400 /* FRAME is used only to get a handle on the X display. We don't pass the
4401 display info directly because we're called from frame.c, which doesn't
4402 know about that structure. */
4404 x_get_focus_frame (frame
)
4405 struct frame
*frame
;
4407 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
4409 if (! dpyinfo
->w32_focus_frame
)
4412 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
4416 DEFUN ("w32-focus-frame", Fw32_focus_frame
, Sw32_focus_frame
, 1, 1, 0,
4417 doc
: /* Give FRAME input focus, raising to foreground if necessary. */)
4421 x_focus_on_frame (check_x_frame (frame
));
4426 /* Return the charset portion of a font name. */
4427 char * xlfd_charset_of_font (char * fontname
)
4429 char *charset
, *encoding
;
4431 encoding
= strrchr(fontname
, '-');
4432 if (!encoding
|| encoding
== fontname
)
4435 for (charset
= encoding
- 1; charset
>= fontname
; charset
--)
4436 if (*charset
== '-')
4439 if (charset
== fontname
|| strcmp(charset
, "-*-*") == 0)
4445 struct font_info
*w32_load_bdf_font (struct frame
*f
, char *fontname
,
4446 int size
, char* filename
);
4447 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
);
4448 static BOOL
w32_to_x_font (LOGFONT
* lplf
, char * lpxstr
, int len
,
4450 static BOOL
x_to_w32_font (char *lpxstr
, LOGFONT
*lplogfont
);
4452 static struct font_info
*
4453 w32_load_system_font (f
,fontname
,size
)
4458 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4459 Lisp_Object font_names
;
4461 /* Get a list of all the fonts that match this name. Once we
4462 have a list of matching fonts, we compare them against the fonts
4463 we already have loaded by comparing names. */
4464 font_names
= w32_list_fonts (f
, build_string (fontname
), size
, 100);
4466 if (!NILP (font_names
))
4471 /* First check if any are already loaded, as that is cheaper
4472 than loading another one. */
4473 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
4474 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
4475 if (dpyinfo
->font_table
[i
].name
4476 && (!strcmp (dpyinfo
->font_table
[i
].name
,
4477 SDATA (XCAR (tail
)))
4478 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
4479 SDATA (XCAR (tail
)))))
4480 return (dpyinfo
->font_table
+ i
);
4482 fontname
= (char *) SDATA (XCAR (font_names
));
4484 else if (w32_strict_fontnames
)
4486 /* If EnumFontFamiliesEx was available, we got a full list of
4487 fonts back so stop now to avoid the possibility of loading a
4488 random font. If we had to fall back to EnumFontFamilies, the
4489 list is incomplete, so continue whether the font we want was
4491 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
4492 FARPROC enum_font_families_ex
4493 = GetProcAddress (gdi32
, "EnumFontFamiliesExA");
4494 if (enum_font_families_ex
)
4498 /* Load the font and add it to the table. */
4500 char *full_name
, *encoding
, *charset
;
4502 struct font_info
*fontp
;
4508 if (!fontname
|| !x_to_w32_font (fontname
, &lf
))
4511 if (!*lf
.lfFaceName
)
4512 /* If no name was specified for the font, we get a random font
4513 from CreateFontIndirect - this is not particularly
4514 desirable, especially since CreateFontIndirect does not
4515 fill out the missing name in lf, so we never know what we
4519 lf
.lfQuality
= DEFAULT_QUALITY
;
4521 font
= (XFontStruct
*) xmalloc (sizeof (XFontStruct
));
4522 bzero (font
, sizeof (*font
));
4524 /* Set bdf to NULL to indicate that this is a Windows font. */
4529 font
->hfont
= CreateFontIndirect (&lf
);
4531 if (font
->hfont
== NULL
)
4540 codepage
= w32_codepage_for_font (fontname
);
4542 hdc
= GetDC (dpyinfo
->root_window
);
4543 oldobj
= SelectObject (hdc
, font
->hfont
);
4545 ok
= GetTextMetrics (hdc
, &font
->tm
);
4546 if (codepage
== CP_UNICODE
)
4547 font
->double_byte_p
= 1;
4550 /* Unfortunately, some fonts (eg. MingLiU, a big5 ttf font)
4551 don't report themselves as double byte fonts, when
4552 patently they are. So instead of trusting
4553 GetFontLanguageInfo, we check the properties of the
4554 codepage directly, since that is ultimately what we are
4555 working from anyway. */
4556 /* font->double_byte_p = GetFontLanguageInfo(hdc) & GCP_DBCS; */
4558 GetCPInfo (codepage
, &cpi
);
4559 font
->double_byte_p
= cpi
.MaxCharSize
> 1;
4562 SelectObject (hdc
, oldobj
);
4563 ReleaseDC (dpyinfo
->root_window
, hdc
);
4564 /* Fill out details in lf according to the font that was
4566 lf
.lfHeight
= font
->tm
.tmInternalLeading
- font
->tm
.tmHeight
;
4567 lf
.lfWidth
= font
->tm
.tmMaxCharWidth
;
4568 lf
.lfWeight
= font
->tm
.tmWeight
;
4569 lf
.lfItalic
= font
->tm
.tmItalic
;
4570 lf
.lfCharSet
= font
->tm
.tmCharSet
;
4571 lf
.lfPitchAndFamily
= ((font
->tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
)
4572 ? VARIABLE_PITCH
: FIXED_PITCH
);
4573 lf
.lfOutPrecision
= ((font
->tm
.tmPitchAndFamily
& TMPF_VECTOR
)
4574 ? OUT_STROKE_PRECIS
: OUT_STRING_PRECIS
);
4576 w32_cache_char_metrics (font
);
4583 w32_unload_font (dpyinfo
, font
);
4587 /* Find a free slot in the font table. */
4588 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
4589 if (dpyinfo
->font_table
[i
].name
== NULL
)
4592 /* If no free slot found, maybe enlarge the font table. */
4593 if (i
== dpyinfo
->n_fonts
4594 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
4597 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
4598 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
4600 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
4603 fontp
= dpyinfo
->font_table
+ i
;
4604 if (i
== dpyinfo
->n_fonts
)
4607 /* Now fill in the slots of *FONTP. */
4609 bzero (fontp
, sizeof (*fontp
));
4611 fontp
->font_idx
= i
;
4612 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
4613 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
4615 if (lf
.lfPitchAndFamily
== FIXED_PITCH
)
4617 /* Fixed width font. */
4618 fontp
->average_width
= fontp
->space_width
= FONT_WIDTH (font
);
4624 pcm
= w32_per_char_metric (font
, &space
, ANSI_FONT
);
4626 fontp
->space_width
= pcm
->width
;
4628 fontp
->space_width
= FONT_WIDTH (font
);
4630 fontp
->average_width
= font
->tm
.tmAveCharWidth
;
4633 charset
= xlfd_charset_of_font (fontname
);
4635 /* Cache the W32 codepage for a font. This makes w32_encode_char
4636 (called for every glyph during redisplay) much faster. */
4637 fontp
->codepage
= codepage
;
4639 /* Work out the font's full name. */
4640 full_name
= (char *)xmalloc (100);
4641 if (full_name
&& w32_to_x_font (&lf
, full_name
, 100, charset
))
4642 fontp
->full_name
= full_name
;
4645 /* If all else fails - just use the name we used to load it. */
4647 fontp
->full_name
= fontp
->name
;
4650 fontp
->size
= FONT_WIDTH (font
);
4651 fontp
->height
= FONT_HEIGHT (font
);
4653 /* The slot `encoding' specifies how to map a character
4654 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
4655 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
4656 (0:0x20..0x7F, 1:0xA0..0xFF,
4657 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
4658 2:0xA020..0xFF7F). For the moment, we don't know which charset
4659 uses this font. So, we set information in fontp->encoding[1]
4660 which is never used by any charset. If mapping can't be
4661 decided, set FONT_ENCODING_NOT_DECIDED. */
4663 /* SJIS fonts need to be set to type 4, all others seem to work as
4664 type FONT_ENCODING_NOT_DECIDED. */
4665 encoding
= strrchr (fontp
->name
, '-');
4666 if (encoding
&& strnicmp (encoding
+1, "sjis", 4) == 0)
4667 fontp
->encoding
[1] = 4;
4669 fontp
->encoding
[1] = FONT_ENCODING_NOT_DECIDED
;
4671 /* The following three values are set to 0 under W32, which is
4672 what they get set to if XGetFontProperty fails under X. */
4673 fontp
->baseline_offset
= 0;
4674 fontp
->relative_compose
= 0;
4675 fontp
->default_ascent
= 0;
4677 /* Set global flag fonts_changed_p to non-zero if the font loaded
4678 has a character with a smaller width than any other character
4679 before, or if the font loaded has a smaller height than any
4680 other font loaded before. If this happens, it will make a
4681 glyph matrix reallocation necessary. */
4682 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
4688 /* Load font named FONTNAME of size SIZE for frame F, and return a
4689 pointer to the structure font_info while allocating it dynamically.
4690 If loading fails, return NULL. */
4692 w32_load_font (f
,fontname
,size
)
4697 Lisp_Object bdf_fonts
;
4698 struct font_info
*retval
= NULL
;
4699 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4701 bdf_fonts
= w32_list_bdf_fonts (build_string (fontname
), 1);
4703 while (!retval
&& CONSP (bdf_fonts
))
4705 char *bdf_name
, *bdf_file
;
4706 Lisp_Object bdf_pair
;
4709 bdf_name
= SDATA (XCAR (bdf_fonts
));
4710 bdf_pair
= Fassoc (XCAR (bdf_fonts
), Vw32_bdf_filename_alist
);
4711 bdf_file
= SDATA (XCDR (bdf_pair
));
4713 // If the font is already loaded, do not load it again.
4714 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
4716 if ((dpyinfo
->font_table
[i
].name
4717 && !strcmp (dpyinfo
->font_table
[i
].name
, bdf_name
))
4718 || (dpyinfo
->font_table
[i
].full_name
4719 && !strcmp (dpyinfo
->font_table
[i
].full_name
, bdf_name
)))
4720 return dpyinfo
->font_table
+ i
;
4723 retval
= w32_load_bdf_font (f
, bdf_name
, size
, bdf_file
);
4725 bdf_fonts
= XCDR (bdf_fonts
);
4731 return w32_load_system_font(f
, fontname
, size
);
4736 w32_unload_font (dpyinfo
, font
)
4737 struct w32_display_info
*dpyinfo
;
4742 if (font
->per_char
) xfree (font
->per_char
);
4743 if (font
->bdf
) w32_free_bdf_font (font
->bdf
);
4745 if (font
->hfont
) DeleteObject(font
->hfont
);
4750 /* The font conversion stuff between x and w32 */
4752 /* X font string is as follows (from faces.el)
4756 * (weight "\\(bold\\|demibold\\|medium\\)") ; 1
4757 * (weight\? "\\([^-]*\\)") ; 1
4758 * (slant "\\([ior]\\)") ; 2
4759 * (slant\? "\\([^-]?\\)") ; 2
4760 * (swidth "\\([^-]*\\)") ; 3
4761 * (adstyle "[^-]*") ; 4
4762 * (pixelsize "[0-9]+")
4763 * (pointsize "[0-9][0-9]+")
4764 * (resx "[0-9][0-9]+")
4765 * (resy "[0-9][0-9]+")
4766 * (spacing "[cmp?*]")
4767 * (avgwidth "[0-9]+")
4768 * (registry "[^-]+")
4769 * (encoding "[^-]+")
4774 x_to_w32_weight (lpw
)
4777 if (!lpw
) return (FW_DONTCARE
);
4779 if (stricmp (lpw
,"heavy") == 0) return FW_HEAVY
;
4780 else if (stricmp (lpw
,"extrabold") == 0) return FW_EXTRABOLD
;
4781 else if (stricmp (lpw
,"bold") == 0) return FW_BOLD
;
4782 else if (stricmp (lpw
,"demibold") == 0) return FW_SEMIBOLD
;
4783 else if (stricmp (lpw
,"semibold") == 0) return FW_SEMIBOLD
;
4784 else if (stricmp (lpw
,"medium") == 0) return FW_MEDIUM
;
4785 else if (stricmp (lpw
,"normal") == 0) return FW_NORMAL
;
4786 else if (stricmp (lpw
,"light") == 0) return FW_LIGHT
;
4787 else if (stricmp (lpw
,"extralight") == 0) return FW_EXTRALIGHT
;
4788 else if (stricmp (lpw
,"thin") == 0) return FW_THIN
;
4795 w32_to_x_weight (fnweight
)
4798 if (fnweight
>= FW_HEAVY
) return "heavy";
4799 if (fnweight
>= FW_EXTRABOLD
) return "extrabold";
4800 if (fnweight
>= FW_BOLD
) return "bold";
4801 if (fnweight
>= FW_SEMIBOLD
) return "demibold";
4802 if (fnweight
>= FW_MEDIUM
) return "medium";
4803 if (fnweight
>= FW_NORMAL
) return "normal";
4804 if (fnweight
>= FW_LIGHT
) return "light";
4805 if (fnweight
>= FW_EXTRALIGHT
) return "extralight";
4806 if (fnweight
>= FW_THIN
) return "thin";
4812 x_to_w32_charset (lpcs
)
4815 Lisp_Object this_entry
, w32_charset
;
4817 int len
= strlen (lpcs
);
4819 /* Support "*-#nnn" format for unknown charsets. */
4820 if (strncmp (lpcs
, "*-#", 3) == 0)
4821 return atoi (lpcs
+ 3);
4823 /* Handle wildcards by ignoring them; eg. treat "big5*-*" as "big5". */
4824 charset
= alloca (len
+ 1);
4825 strcpy (charset
, lpcs
);
4826 lpcs
= strchr (charset
, '*');
4830 /* Look through w32-charset-info-alist for the character set.
4831 Format of each entry is
4832 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
4834 this_entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
4836 if (NILP(this_entry
))
4838 /* At startup, we want iso8859-1 fonts to come up properly. */
4839 if (stricmp(charset
, "iso8859-1") == 0)
4840 return ANSI_CHARSET
;
4842 return DEFAULT_CHARSET
;
4845 w32_charset
= Fcar (Fcdr (this_entry
));
4847 /* Translate Lisp symbol to number. */
4848 if (EQ (w32_charset
, Qw32_charset_ansi
))
4849 return ANSI_CHARSET
;
4850 if (EQ (w32_charset
, Qw32_charset_symbol
))
4851 return SYMBOL_CHARSET
;
4852 if (EQ (w32_charset
, Qw32_charset_shiftjis
))
4853 return SHIFTJIS_CHARSET
;
4854 if (EQ (w32_charset
, Qw32_charset_hangeul
))
4855 return HANGEUL_CHARSET
;
4856 if (EQ (w32_charset
, Qw32_charset_chinesebig5
))
4857 return CHINESEBIG5_CHARSET
;
4858 if (EQ (w32_charset
, Qw32_charset_gb2312
))
4859 return GB2312_CHARSET
;
4860 if (EQ (w32_charset
, Qw32_charset_oem
))
4862 #ifdef JOHAB_CHARSET
4863 if (EQ (w32_charset
, Qw32_charset_johab
))
4864 return JOHAB_CHARSET
;
4865 if (EQ (w32_charset
, Qw32_charset_easteurope
))
4866 return EASTEUROPE_CHARSET
;
4867 if (EQ (w32_charset
, Qw32_charset_turkish
))
4868 return TURKISH_CHARSET
;
4869 if (EQ (w32_charset
, Qw32_charset_baltic
))
4870 return BALTIC_CHARSET
;
4871 if (EQ (w32_charset
, Qw32_charset_russian
))
4872 return RUSSIAN_CHARSET
;
4873 if (EQ (w32_charset
, Qw32_charset_arabic
))
4874 return ARABIC_CHARSET
;
4875 if (EQ (w32_charset
, Qw32_charset_greek
))
4876 return GREEK_CHARSET
;
4877 if (EQ (w32_charset
, Qw32_charset_hebrew
))
4878 return HEBREW_CHARSET
;
4879 if (EQ (w32_charset
, Qw32_charset_vietnamese
))
4880 return VIETNAMESE_CHARSET
;
4881 if (EQ (w32_charset
, Qw32_charset_thai
))
4882 return THAI_CHARSET
;
4883 if (EQ (w32_charset
, Qw32_charset_mac
))
4885 #endif /* JOHAB_CHARSET */
4886 #ifdef UNICODE_CHARSET
4887 if (EQ (w32_charset
, Qw32_charset_unicode
))
4888 return UNICODE_CHARSET
;
4891 return DEFAULT_CHARSET
;
4896 w32_to_x_charset (fncharset
)
4899 static char buf
[32];
4900 Lisp_Object charset_type
;
4905 /* Handle startup case of w32-charset-info-alist not
4906 being set up yet. */
4907 if (NILP(Vw32_charset_info_alist
))
4909 charset_type
= Qw32_charset_ansi
;
4911 case DEFAULT_CHARSET
:
4912 charset_type
= Qw32_charset_default
;
4914 case SYMBOL_CHARSET
:
4915 charset_type
= Qw32_charset_symbol
;
4917 case SHIFTJIS_CHARSET
:
4918 charset_type
= Qw32_charset_shiftjis
;
4920 case HANGEUL_CHARSET
:
4921 charset_type
= Qw32_charset_hangeul
;
4923 case GB2312_CHARSET
:
4924 charset_type
= Qw32_charset_gb2312
;
4926 case CHINESEBIG5_CHARSET
:
4927 charset_type
= Qw32_charset_chinesebig5
;
4930 charset_type
= Qw32_charset_oem
;
4933 /* More recent versions of Windows (95 and NT4.0) define more
4935 #ifdef EASTEUROPE_CHARSET
4936 case EASTEUROPE_CHARSET
:
4937 charset_type
= Qw32_charset_easteurope
;
4939 case TURKISH_CHARSET
:
4940 charset_type
= Qw32_charset_turkish
;
4942 case BALTIC_CHARSET
:
4943 charset_type
= Qw32_charset_baltic
;
4945 case RUSSIAN_CHARSET
:
4946 charset_type
= Qw32_charset_russian
;
4948 case ARABIC_CHARSET
:
4949 charset_type
= Qw32_charset_arabic
;
4952 charset_type
= Qw32_charset_greek
;
4954 case HEBREW_CHARSET
:
4955 charset_type
= Qw32_charset_hebrew
;
4957 case VIETNAMESE_CHARSET
:
4958 charset_type
= Qw32_charset_vietnamese
;
4961 charset_type
= Qw32_charset_thai
;
4964 charset_type
= Qw32_charset_mac
;
4967 charset_type
= Qw32_charset_johab
;
4971 #ifdef UNICODE_CHARSET
4972 case UNICODE_CHARSET
:
4973 charset_type
= Qw32_charset_unicode
;
4977 /* Encode numerical value of unknown charset. */
4978 sprintf (buf
, "*-#%u", fncharset
);
4984 char * best_match
= NULL
;
4986 /* Look through w32-charset-info-alist for the character set.
4987 Prefer ISO codepages, and prefer lower numbers in the ISO
4988 range. Only return charsets for codepages which are installed.
4990 Format of each entry is
4991 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
4993 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
4996 Lisp_Object w32_charset
;
4997 Lisp_Object codepage
;
4999 Lisp_Object this_entry
= XCAR (rest
);
5001 /* Skip invalid entries in alist. */
5002 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
5003 || !CONSP (XCDR (this_entry
))
5004 || !SYMBOLP (XCAR (XCDR (this_entry
))))
5007 x_charset
= SDATA (XCAR (this_entry
));
5008 w32_charset
= XCAR (XCDR (this_entry
));
5009 codepage
= XCDR (XCDR (this_entry
));
5011 /* Look for Same charset and a valid codepage (or non-int
5012 which means ignore). */
5013 if (EQ (w32_charset
, charset_type
)
5014 && (!INTEGERP (codepage
) || XINT (codepage
) == CP_DEFAULT
5015 || IsValidCodePage (XINT (codepage
))))
5017 /* If we don't have a match already, then this is the
5020 best_match
= x_charset
;
5021 /* If this is an ISO codepage, and the best so far isn't,
5022 then this is better. */
5023 else if (strnicmp (best_match
, "iso", 3) != 0
5024 && strnicmp (x_charset
, "iso", 3) == 0)
5025 best_match
= x_charset
;
5026 /* If both are ISO8859 codepages, choose the one with the
5027 lowest number in the encoding field. */
5028 else if (strnicmp (best_match
, "iso8859-", 8) == 0
5029 && strnicmp (x_charset
, "iso8859-", 8) == 0)
5031 int best_enc
= atoi (best_match
+ 8);
5032 int this_enc
= atoi (x_charset
+ 8);
5033 if (this_enc
> 0 && this_enc
< best_enc
)
5034 best_match
= x_charset
;
5039 /* If no match, encode the numeric value. */
5042 sprintf (buf
, "*-#%u", fncharset
);
5046 strncpy(buf
, best_match
, 31);
5053 /* Return all the X charsets that map to a font. */
5055 w32_to_all_x_charsets (fncharset
)
5058 static char buf
[32];
5059 Lisp_Object charset_type
;
5060 Lisp_Object retval
= Qnil
;
5065 /* Handle startup case of w32-charset-info-alist not
5066 being set up yet. */
5067 if (NILP(Vw32_charset_info_alist
))
5068 return Fcons (build_string ("iso8859-1"), Qnil
);
5070 charset_type
= Qw32_charset_ansi
;
5072 case DEFAULT_CHARSET
:
5073 charset_type
= Qw32_charset_default
;
5075 case SYMBOL_CHARSET
:
5076 charset_type
= Qw32_charset_symbol
;
5078 case SHIFTJIS_CHARSET
:
5079 charset_type
= Qw32_charset_shiftjis
;
5081 case HANGEUL_CHARSET
:
5082 charset_type
= Qw32_charset_hangeul
;
5084 case GB2312_CHARSET
:
5085 charset_type
= Qw32_charset_gb2312
;
5087 case CHINESEBIG5_CHARSET
:
5088 charset_type
= Qw32_charset_chinesebig5
;
5091 charset_type
= Qw32_charset_oem
;
5094 /* More recent versions of Windows (95 and NT4.0) define more
5096 #ifdef EASTEUROPE_CHARSET
5097 case EASTEUROPE_CHARSET
:
5098 charset_type
= Qw32_charset_easteurope
;
5100 case TURKISH_CHARSET
:
5101 charset_type
= Qw32_charset_turkish
;
5103 case BALTIC_CHARSET
:
5104 charset_type
= Qw32_charset_baltic
;
5106 case RUSSIAN_CHARSET
:
5107 charset_type
= Qw32_charset_russian
;
5109 case ARABIC_CHARSET
:
5110 charset_type
= Qw32_charset_arabic
;
5113 charset_type
= Qw32_charset_greek
;
5115 case HEBREW_CHARSET
:
5116 charset_type
= Qw32_charset_hebrew
;
5118 case VIETNAMESE_CHARSET
:
5119 charset_type
= Qw32_charset_vietnamese
;
5122 charset_type
= Qw32_charset_thai
;
5125 charset_type
= Qw32_charset_mac
;
5128 charset_type
= Qw32_charset_johab
;
5132 #ifdef UNICODE_CHARSET
5133 case UNICODE_CHARSET
:
5134 charset_type
= Qw32_charset_unicode
;
5138 /* Encode numerical value of unknown charset. */
5139 sprintf (buf
, "*-#%u", fncharset
);
5140 return Fcons (build_string (buf
), Qnil
);
5145 /* Look through w32-charset-info-alist for the character set.
5146 Only return charsets for codepages which are installed.
5148 Format of each entry in Vw32_charset_info_alist is
5149 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5151 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
5153 Lisp_Object x_charset
;
5154 Lisp_Object w32_charset
;
5155 Lisp_Object codepage
;
5157 Lisp_Object this_entry
= XCAR (rest
);
5159 /* Skip invalid entries in alist. */
5160 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
5161 || !CONSP (XCDR (this_entry
))
5162 || !SYMBOLP (XCAR (XCDR (this_entry
))))
5165 x_charset
= XCAR (this_entry
);
5166 w32_charset
= XCAR (XCDR (this_entry
));
5167 codepage
= XCDR (XCDR (this_entry
));
5169 /* Look for Same charset and a valid codepage (or non-int
5170 which means ignore). */
5171 if (EQ (w32_charset
, charset_type
)
5172 && (!INTEGERP (codepage
) || XINT (codepage
) == CP_DEFAULT
5173 || IsValidCodePage (XINT (codepage
))))
5175 retval
= Fcons (x_charset
, retval
);
5179 /* If no match, encode the numeric value. */
5182 sprintf (buf
, "*-#%u", fncharset
);
5183 return Fcons (build_string (buf
), Qnil
);
5190 /* Get the Windows codepage corresponding to the specified font. The
5191 charset info in the font name is used to look up
5192 w32-charset-to-codepage-alist. */
5194 w32_codepage_for_font (char *fontname
)
5196 Lisp_Object codepage
, entry
;
5197 char *charset_str
, *charset
, *end
;
5199 if (NILP (Vw32_charset_info_alist
))
5202 /* Extract charset part of font string. */
5203 charset
= xlfd_charset_of_font (fontname
);
5208 charset_str
= (char *) alloca (strlen (charset
) + 1);
5209 strcpy (charset_str
, charset
);
5212 /* Remove leading "*-". */
5213 if (strncmp ("*-", charset_str
, 2) == 0)
5214 charset
= charset_str
+ 2;
5217 charset
= charset_str
;
5219 /* Stop match at wildcard (including preceding '-'). */
5220 if (end
= strchr (charset
, '*'))
5222 if (end
> charset
&& *(end
-1) == '-')
5227 entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
5231 codepage
= Fcdr (Fcdr (entry
));
5233 if (NILP (codepage
))
5235 else if (XFASTINT (codepage
) == XFASTINT (Qt
))
5237 else if (INTEGERP (codepage
))
5238 return XINT (codepage
);
5245 w32_to_x_font (lplogfont
, lpxstr
, len
, specific_charset
)
5246 LOGFONT
* lplogfont
;
5249 char * specific_charset
;
5253 char height_pixels
[8];
5255 char width_pixels
[8];
5256 char *fontname_dash
;
5257 int display_resy
= (int) one_w32_display_info
.resy
;
5258 int display_resx
= (int) one_w32_display_info
.resx
;
5260 struct coding_system coding
;
5262 if (!lpxstr
) abort ();
5267 if (lplogfont
->lfOutPrecision
== OUT_STRING_PRECIS
)
5268 fonttype
= "raster";
5269 else if (lplogfont
->lfOutPrecision
== OUT_STROKE_PRECIS
)
5270 fonttype
= "outline";
5272 fonttype
= "unknown";
5274 setup_coding_system (Fcheck_coding_system (Vlocale_coding_system
),
5276 coding
.src_multibyte
= 0;
5277 coding
.dst_multibyte
= 1;
5278 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
5279 /* We explicitely disable composition handling because selection
5280 data should not contain any composition sequence. */
5281 coding
.composing
= COMPOSITION_DISABLED
;
5282 bufsz
= decoding_buffer_size (&coding
, LF_FACESIZE
);
5284 fontname
= alloca(sizeof(*fontname
) * bufsz
);
5285 decode_coding (&coding
, lplogfont
->lfFaceName
, fontname
,
5286 strlen(lplogfont
->lfFaceName
), bufsz
- 1);
5287 *(fontname
+ coding
.produced
) = '\0';
5289 /* Replace dashes with underscores so the dashes are not
5291 fontname_dash
= fontname
;
5292 while (fontname_dash
= strchr (fontname_dash
, '-'))
5293 *fontname_dash
= '_';
5295 if (lplogfont
->lfHeight
)
5297 sprintf (height_pixels
, "%u", abs (lplogfont
->lfHeight
));
5298 sprintf (height_dpi
, "%u",
5299 abs (lplogfont
->lfHeight
) * 720 / display_resy
);
5303 strcpy (height_pixels
, "*");
5304 strcpy (height_dpi
, "*");
5307 #if 0 /* Never put the width in the xfld. It fails on fonts with
5308 double-width characters. */
5309 if (lplogfont
->lfWidth
)
5310 sprintf (width_pixels
, "%u", lplogfont
->lfWidth
* 10);
5313 strcpy (width_pixels
, "*");
5315 _snprintf (lpxstr
, len
- 1,
5316 "-%s-%s-%s-%c-normal-normal-%s-%s-%d-%d-%c-%s-%s",
5317 fonttype
, /* foundry */
5318 fontname
, /* family */
5319 w32_to_x_weight (lplogfont
->lfWeight
), /* weight */
5320 lplogfont
->lfItalic
?'i':'r', /* slant */
5322 /* add style name */
5323 height_pixels
, /* pixel size */
5324 height_dpi
, /* point size */
5325 display_resx
, /* resx */
5326 display_resy
, /* resy */
5327 ((lplogfont
->lfPitchAndFamily
& 0x3) == VARIABLE_PITCH
)
5328 ? 'p' : 'c', /* spacing */
5329 width_pixels
, /* avg width */
5330 specific_charset
? specific_charset
5331 : w32_to_x_charset (lplogfont
->lfCharSet
)
5332 /* charset registry and encoding */
5335 lpxstr
[len
- 1] = 0; /* just to be sure */
5340 x_to_w32_font (lpxstr
, lplogfont
)
5342 LOGFONT
* lplogfont
;
5344 struct coding_system coding
;
5346 if (!lplogfont
) return (FALSE
);
5348 memset (lplogfont
, 0, sizeof (*lplogfont
));
5350 /* Set default value for each field. */
5352 lplogfont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
5353 lplogfont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
5354 lplogfont
->lfQuality
= DEFAULT_QUALITY
;
5356 /* go for maximum quality */
5357 lplogfont
->lfOutPrecision
= OUT_STROKE_PRECIS
;
5358 lplogfont
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
5359 lplogfont
->lfQuality
= PROOF_QUALITY
;
5362 lplogfont
->lfCharSet
= DEFAULT_CHARSET
;
5363 lplogfont
->lfWeight
= FW_DONTCARE
;
5364 lplogfont
->lfPitchAndFamily
= DEFAULT_PITCH
| FF_DONTCARE
;
5369 /* Provide a simple escape mechanism for specifying Windows font names
5370 * directly -- if font spec does not beginning with '-', assume this
5372 * "<font name>[:height in pixels[:width in pixels[:weight]]]"
5378 char name
[50], weight
[20], slant
, pitch
, pixels
[10], height
[10],
5379 width
[10], resy
[10], remainder
[50];
5381 int dpi
= (int) one_w32_display_info
.resy
;
5383 fields
= sscanf (lpxstr
,
5384 "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%49s",
5385 name
, weight
, &slant
, pixels
, height
, resy
, &pitch
, width
, remainder
);
5389 /* In the general case when wildcards cover more than one field,
5390 we don't know which field is which, so don't fill any in.
5391 However, we need to cope with this particular form, which is
5392 generated by font_list_1 (invoked by try_font_list):
5393 "-raster-6x10-*-gb2312*-*"
5394 and make sure to correctly parse the charset field. */
5397 fields
= sscanf (lpxstr
,
5398 "-%*[^-]-%49[^-]-*-%49s",
5401 else if (fields
< 9)
5407 if (fields
> 0 && name
[0] != '*')
5413 (Fcheck_coding_system (Vlocale_coding_system
), &coding
);
5414 coding
.src_multibyte
= 1;
5415 coding
.dst_multibyte
= 0;
5416 /* Need to set COMPOSITION_DISABLED, otherwise Emacs crashes in
5417 encode_coding_iso2022 trying to dereference a null pointer. */
5418 coding
.composing
= COMPOSITION_DISABLED
;
5419 if (coding
.type
== coding_type_iso2022
)
5420 coding
.flags
|= CODING_FLAG_ISO_SAFE
;
5421 bufsize
= encoding_buffer_size (&coding
, strlen (name
));
5422 buf
= (unsigned char *) alloca (bufsize
);
5423 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
5424 encode_coding (&coding
, name
, buf
, strlen (name
), bufsize
);
5425 if (coding
.produced
>= LF_FACESIZE
)
5426 coding
.produced
= LF_FACESIZE
- 1;
5427 buf
[coding
.produced
] = 0;
5428 strcpy (lplogfont
->lfFaceName
, buf
);
5432 lplogfont
->lfFaceName
[0] = '\0';
5437 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
5441 lplogfont
->lfItalic
= (fields
> 0 && slant
== 'i');
5445 if (fields
> 0 && pixels
[0] != '*')
5446 lplogfont
->lfHeight
= atoi (pixels
);
5450 if (fields
> 0 && resy
[0] != '*')
5453 if (tem
> 0) dpi
= tem
;
5456 if (fields
> -1 && lplogfont
->lfHeight
== 0 && height
[0] != '*')
5457 lplogfont
->lfHeight
= atoi (height
) * dpi
/ 720;
5460 lplogfont
->lfPitchAndFamily
=
5461 (fields
> 0 && pitch
== 'p') ? VARIABLE_PITCH
: FIXED_PITCH
;
5465 if (fields
> 0 && width
[0] != '*')
5466 lplogfont
->lfWidth
= atoi (width
) / 10;
5470 /* Strip the trailing '-' if present. (it shouldn't be, as it
5471 fails the test against xlfd-tight-regexp in fontset.el). */
5473 int len
= strlen (remainder
);
5474 if (len
> 0 && remainder
[len
-1] == '-')
5475 remainder
[len
-1] = 0;
5477 encoding
= remainder
;
5479 if (strncmp (encoding
, "*-", 2) == 0)
5482 lplogfont
->lfCharSet
= x_to_w32_charset (encoding
);
5487 char name
[100], height
[10], width
[10], weight
[20];
5489 fields
= sscanf (lpxstr
,
5490 "%99[^:]:%9[^:]:%9[^:]:%19s",
5491 name
, height
, width
, weight
);
5493 if (fields
== EOF
) return (FALSE
);
5497 strncpy (lplogfont
->lfFaceName
,name
, LF_FACESIZE
);
5498 lplogfont
->lfFaceName
[LF_FACESIZE
-1] = 0;
5502 lplogfont
->lfFaceName
[0] = 0;
5508 lplogfont
->lfHeight
= atoi (height
);
5513 lplogfont
->lfWidth
= atoi (width
);
5517 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
5520 /* This makes TrueType fonts work better. */
5521 lplogfont
->lfHeight
= - abs (lplogfont
->lfHeight
);
5526 /* Strip the pixel height and point height from the given xlfd, and
5527 return the pixel height. If no pixel height is specified, calculate
5528 one from the point height, or if that isn't defined either, return
5529 0 (which usually signifies a scalable font).
5532 xlfd_strip_height (char *fontname
)
5534 int pixel_height
, field_number
;
5535 char *read_from
, *write_to
;
5539 pixel_height
= field_number
= 0;
5542 /* Look for height fields. */
5543 for (read_from
= fontname
; *read_from
; read_from
++)
5545 if (*read_from
== '-')
5548 if (field_number
== 7) /* Pixel height. */
5551 write_to
= read_from
;
5553 /* Find end of field. */
5554 for (;*read_from
&& *read_from
!= '-'; read_from
++)
5557 /* Split the fontname at end of field. */
5563 pixel_height
= atoi (write_to
);
5564 /* Blank out field. */
5565 if (read_from
> write_to
)
5570 /* If the pixel height field is at the end (partial xlfd),
5573 return pixel_height
;
5575 /* If we got a pixel height, the point height can be
5576 ignored. Just blank it out and break now. */
5579 /* Find end of point size field. */
5580 for (; *read_from
&& *read_from
!= '-'; read_from
++)
5586 /* Blank out the point size field. */
5587 if (read_from
> write_to
)
5593 return pixel_height
;
5597 /* If the point height is already blank, break now. */
5598 if (*read_from
== '-')
5604 else if (field_number
== 8)
5606 /* If we didn't get a pixel height, try to get the point
5607 height and convert that. */
5609 char *point_size_start
= read_from
++;
5611 /* Find end of field. */
5612 for (; *read_from
&& *read_from
!= '-'; read_from
++)
5621 point_size
= atoi (point_size_start
);
5623 /* Convert to pixel height. */
5624 pixel_height
= point_size
5625 * one_w32_display_info
.height_in
/ 720;
5627 /* Blank out this field and break. */
5635 /* Shift the rest of the font spec into place. */
5636 if (write_to
&& read_from
> write_to
)
5638 for (; *read_from
; read_from
++, write_to
++)
5639 *write_to
= *read_from
;
5643 return pixel_height
;
5646 /* Assume parameter 1 is fully qualified, no wildcards. */
5648 w32_font_match (fontname
, pattern
)
5653 char *font_name_copy
;
5654 char *regex
= alloca (strlen (pattern
) * 2 + 3);
5656 font_name_copy
= alloca (strlen (fontname
) + 1);
5657 strcpy (font_name_copy
, fontname
);
5662 /* Turn pattern into a regexp and do a regexp match. */
5663 for (; *pattern
; pattern
++)
5665 if (*pattern
== '?')
5667 else if (*pattern
== '*')
5678 /* Strip out font heights and compare them seperately, since
5679 rounding error can cause mismatches. This also allows a
5680 comparison between a font that declares only a pixel height and a
5681 pattern that declares the point height.
5684 int font_height
, pattern_height
;
5686 font_height
= xlfd_strip_height (font_name_copy
);
5687 pattern_height
= xlfd_strip_height (regex
);
5689 /* Compare now, and don't bother doing expensive regexp matching
5690 if the heights differ. */
5691 if (font_height
&& pattern_height
&& (font_height
!= pattern_height
))
5695 return (fast_string_match_ignore_case (build_string (regex
),
5696 build_string(font_name_copy
)) >= 0);
5699 /* Callback functions, and a structure holding info they need, for
5700 listing system fonts on W32. We need one set of functions to do the
5701 job properly, but these don't work on NT 3.51 and earlier, so we
5702 have a second set which don't handle character sets properly to
5705 In both cases, there are two passes made. The first pass gets one
5706 font from each family, the second pass lists all the fonts from
5709 typedef struct enumfont_t
5714 XFontStruct
*size_ref
;
5715 Lisp_Object pattern
;
5721 enum_font_maybe_add_to_list (enumfont_t
*, LOGFONT
*, char *, Lisp_Object
);
5725 enum_font_cb2 (lplf
, lptm
, FontType
, lpef
)
5727 NEWTEXTMETRIC
* lptm
;
5731 /* Ignore struck out and underlined versions of fonts. */
5732 if (lplf
->elfLogFont
.lfStrikeOut
|| lplf
->elfLogFont
.lfUnderline
)
5735 /* Only return fonts with names starting with @ if they were
5736 explicitly specified, since Microsoft uses an initial @ to
5737 denote fonts for vertical writing, without providing a more
5738 convenient way of identifying them. */
5739 if (lplf
->elfLogFont
.lfFaceName
[0] == '@'
5740 && lpef
->logfont
.lfFaceName
[0] != '@')
5743 /* Check that the character set matches if it was specified */
5744 if (lpef
->logfont
.lfCharSet
!= DEFAULT_CHARSET
&&
5745 lplf
->elfLogFont
.lfCharSet
!= lpef
->logfont
.lfCharSet
)
5748 if (FontType
== RASTER_FONTTYPE
)
5750 /* DBCS raster fonts have problems displaying, so skip them. */
5751 int charset
= lplf
->elfLogFont
.lfCharSet
;
5752 if (charset
== SHIFTJIS_CHARSET
5753 || charset
== HANGEUL_CHARSET
5754 || charset
== CHINESEBIG5_CHARSET
5755 || charset
== GB2312_CHARSET
5756 #ifdef JOHAB_CHARSET
5757 || charset
== JOHAB_CHARSET
5765 Lisp_Object width
= Qnil
;
5766 Lisp_Object charset_list
= Qnil
;
5767 char *charset
= NULL
;
5769 /* Truetype fonts do not report their true metrics until loaded */
5770 if (FontType
!= RASTER_FONTTYPE
)
5772 if (!NILP (lpef
->pattern
))
5774 /* Scalable fonts are as big as you want them to be. */
5775 lplf
->elfLogFont
.lfHeight
= lpef
->logfont
.lfHeight
;
5776 lplf
->elfLogFont
.lfWidth
= lpef
->logfont
.lfWidth
;
5777 width
= make_number (lpef
->logfont
.lfWidth
);
5781 lplf
->elfLogFont
.lfHeight
= 0;
5782 lplf
->elfLogFont
.lfWidth
= 0;
5786 /* Make sure the height used here is the same as everywhere
5787 else (ie character height, not cell height). */
5788 if (lplf
->elfLogFont
.lfHeight
> 0)
5790 /* lptm can be trusted for RASTER fonts, but not scalable ones. */
5791 if (FontType
== RASTER_FONTTYPE
)
5792 lplf
->elfLogFont
.lfHeight
= lptm
->tmInternalLeading
- lptm
->tmHeight
;
5794 lplf
->elfLogFont
.lfHeight
= -lplf
->elfLogFont
.lfHeight
;
5797 if (!NILP (lpef
->pattern
))
5799 charset
= xlfd_charset_of_font (SDATA (lpef
->pattern
));
5801 /* We already checked charsets above, but DEFAULT_CHARSET
5802 slipped through. So only allow exact matches for DEFAULT_CHARSET. */
5804 && strncmp (charset
, "*-*", 3) != 0
5805 && lpef
->logfont
.lfCharSet
== DEFAULT_CHARSET
5806 && strcmp (charset
, w32_to_x_charset (DEFAULT_CHARSET
)) != 0)
5811 charset_list
= Fcons (build_string (charset
), Qnil
);
5813 charset_list
= w32_to_all_x_charsets (lplf
->elfLogFont
.lfCharSet
);
5815 /* Loop through the charsets. */
5816 for ( ; CONSP (charset_list
); charset_list
= Fcdr (charset_list
))
5818 Lisp_Object this_charset
= Fcar (charset_list
);
5819 charset
= SDATA (this_charset
);
5821 /* List bold and italic variations if w32-enable-synthesized-fonts
5822 is non-nil and this is a plain font. */
5823 if (w32_enable_synthesized_fonts
5824 && lplf
->elfLogFont
.lfWeight
== FW_NORMAL
5825 && lplf
->elfLogFont
.lfItalic
== FALSE
)
5827 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5830 lplf
->elfLogFont
.lfWeight
= FW_BOLD
;
5831 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5834 lplf
->elfLogFont
.lfItalic
= TRUE
;
5835 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5838 lplf
->elfLogFont
.lfWeight
= FW_NORMAL
;
5839 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5843 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5852 enum_font_maybe_add_to_list (lpef
, logfont
, match_charset
, width
)
5855 char * match_charset
;
5860 if (!w32_to_x_font (logfont
, buf
, 100, match_charset
))
5863 if (NILP (lpef
->pattern
)
5864 || w32_font_match (buf
, SDATA (lpef
->pattern
)))
5866 /* Check if we already listed this font. This may happen if
5867 w32_enable_synthesized_fonts is non-nil, and there are real
5868 bold and italic versions of the font. */
5869 Lisp_Object font_name
= build_string (buf
);
5870 if (NILP (Fmember (font_name
, lpef
->list
)))
5872 Lisp_Object entry
= Fcons (font_name
, width
);
5873 lpef
->list
= Fcons (entry
, lpef
->list
);
5881 enum_font_cb1 (lplf
, lptm
, FontType
, lpef
)
5883 NEWTEXTMETRIC
* lptm
;
5887 return EnumFontFamilies (lpef
->hdc
,
5888 lplf
->elfLogFont
.lfFaceName
,
5889 (FONTENUMPROC
) enum_font_cb2
,
5895 enum_fontex_cb2 (lplf
, lptm
, font_type
, lpef
)
5896 ENUMLOGFONTEX
* lplf
;
5897 NEWTEXTMETRICEX
* lptm
;
5901 /* We are not interested in the extra info we get back from the 'Ex
5902 version - only the fact that we get character set variations
5903 enumerated seperately. */
5904 return enum_font_cb2 ((ENUMLOGFONT
*) lplf
, (NEWTEXTMETRIC
*) lptm
,
5909 enum_fontex_cb1 (lplf
, lptm
, font_type
, lpef
)
5910 ENUMLOGFONTEX
* lplf
;
5911 NEWTEXTMETRICEX
* lptm
;
5915 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
5916 FARPROC enum_font_families_ex
5917 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
5918 /* We don't really expect EnumFontFamiliesEx to disappear once we
5919 get here, so don't bother handling it gracefully. */
5920 if (enum_font_families_ex
== NULL
)
5921 error ("gdi32.dll has disappeared!");
5922 return enum_font_families_ex (lpef
->hdc
,
5924 (FONTENUMPROC
) enum_fontex_cb2
,
5928 /* Interface to fontset handler. (adapted from mw32font.c in Meadow
5929 and xterm.c in Emacs 20.3) */
5931 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
)
5933 char *fontname
, *ptnstr
;
5934 Lisp_Object list
, tem
, newlist
= Qnil
;
5937 list
= Vw32_bdf_filename_alist
;
5938 ptnstr
= SDATA (pattern
);
5940 for ( ; CONSP (list
); list
= XCDR (list
))
5944 fontname
= SDATA (XCAR (tem
));
5945 else if (STRINGP (tem
))
5946 fontname
= SDATA (tem
);
5950 if (w32_font_match (fontname
, ptnstr
))
5952 newlist
= Fcons (XCAR (tem
), newlist
);
5954 if (max_names
>= 0 && n_fonts
>= max_names
)
5963 /* Return a list of names of available fonts matching PATTERN on frame
5964 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
5965 to be listed. Frame F NULL means we have not yet created any
5966 frame, which means we can't get proper size info, as we don't have
5967 a device context to use for GetTextMetrics.
5968 MAXNAMES sets a limit on how many fonts to match. If MAXNAMES is
5969 negative, then all matching fonts are returned. */
5972 w32_list_fonts (f
, pattern
, size
, maxnames
)
5974 Lisp_Object pattern
;
5978 Lisp_Object patterns
, key
= Qnil
, tem
, tpat
;
5979 Lisp_Object list
= Qnil
, newlist
= Qnil
, second_best
= Qnil
;
5980 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
5983 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
5984 if (NILP (patterns
))
5985 patterns
= Fcons (pattern
, Qnil
);
5987 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
5992 tpat
= XCAR (patterns
);
5994 if (!STRINGP (tpat
))
5997 /* Avoid expensive EnumFontFamilies functions if we are not
5998 going to be able to output one of these anyway. */
5999 codepage
= w32_codepage_for_font (SDATA (tpat
));
6000 if (codepage
!= CP_8BIT
&& codepage
!= CP_UNICODE
6001 && codepage
!= CP_DEFAULT
&& codepage
!= CP_UNKNOWN
6002 && !IsValidCodePage(codepage
))
6005 /* See if we cached the result for this particular query.
6006 The cache is an alist of the form:
6007 ((PATTERN (FONTNAME . WIDTH) ...) ...)
6009 if (tem
= XCDR (dpyinfo
->name_list_element
),
6010 !NILP (list
= Fassoc (tpat
, tem
)))
6012 list
= Fcdr_safe (list
);
6013 /* We have a cached list. Don't have to get the list again. */
6018 /* At first, put PATTERN in the cache. */
6023 /* Use EnumFontFamiliesEx where it is available, as it knows
6024 about character sets. Fall back to EnumFontFamilies for
6025 older versions of NT that don't support the 'Ex function. */
6026 x_to_w32_font (SDATA (tpat
), &ef
.logfont
);
6028 LOGFONT font_match_pattern
;
6029 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6030 FARPROC enum_font_families_ex
6031 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6033 /* We do our own pattern matching so we can handle wildcards. */
6034 font_match_pattern
.lfFaceName
[0] = 0;
6035 font_match_pattern
.lfPitchAndFamily
= 0;
6036 /* We can use the charset, because if it is a wildcard it will
6037 be DEFAULT_CHARSET anyway. */
6038 font_match_pattern
.lfCharSet
= ef
.logfont
.lfCharSet
;
6040 ef
.hdc
= GetDC (dpyinfo
->root_window
);
6042 if (enum_font_families_ex
)
6043 enum_font_families_ex (ef
.hdc
,
6044 &font_match_pattern
,
6045 (FONTENUMPROC
) enum_fontex_cb1
,
6048 EnumFontFamilies (ef
.hdc
, NULL
, (FONTENUMPROC
) enum_font_cb1
,
6051 ReleaseDC (dpyinfo
->root_window
, ef
.hdc
);
6057 /* Make a list of the fonts we got back.
6058 Store that in the font cache for the display. */
6059 XSETCDR (dpyinfo
->name_list_element
,
6060 Fcons (Fcons (tpat
, list
),
6061 XCDR (dpyinfo
->name_list_element
)));
6064 if (NILP (list
)) continue; /* Try the remaining alternatives. */
6066 newlist
= second_best
= Qnil
;
6068 /* Make a list of the fonts that have the right width. */
6069 for (; CONSP (list
); list
= XCDR (list
))
6076 if (NILP (XCAR (tem
)))
6080 newlist
= Fcons (XCAR (tem
), newlist
);
6082 if (maxnames
>= 0 && n_fonts
>= maxnames
)
6087 if (!INTEGERP (XCDR (tem
)))
6089 /* Since we don't yet know the size of the font, we must
6090 load it and try GetTextMetrics. */
6091 W32FontStruct thisinfo
;
6096 if (!x_to_w32_font (SDATA (XCAR (tem
)), &lf
))
6100 thisinfo
.bdf
= NULL
;
6101 thisinfo
.hfont
= CreateFontIndirect (&lf
);
6102 if (thisinfo
.hfont
== NULL
)
6105 hdc
= GetDC (dpyinfo
->root_window
);
6106 oldobj
= SelectObject (hdc
, thisinfo
.hfont
);
6107 if (GetTextMetrics (hdc
, &thisinfo
.tm
))
6108 XSETCDR (tem
, make_number (FONT_WIDTH (&thisinfo
)));
6110 XSETCDR (tem
, make_number (0));
6111 SelectObject (hdc
, oldobj
);
6112 ReleaseDC (dpyinfo
->root_window
, hdc
);
6113 DeleteObject(thisinfo
.hfont
);
6116 found_size
= XINT (XCDR (tem
));
6117 if (found_size
== size
)
6119 newlist
= Fcons (XCAR (tem
), newlist
);
6121 if (maxnames
>= 0 && n_fonts
>= maxnames
)
6124 /* keep track of the closest matching size in case
6125 no exact match is found. */
6126 else if (found_size
> 0)
6128 if (NILP (second_best
))
6131 else if (found_size
< size
)
6133 if (XINT (XCDR (second_best
)) > size
6134 || XINT (XCDR (second_best
)) < found_size
)
6139 if (XINT (XCDR (second_best
)) > size
6140 && XINT (XCDR (second_best
)) >
6147 if (!NILP (newlist
))
6149 else if (!NILP (second_best
))
6151 newlist
= Fcons (XCAR (second_best
), Qnil
);
6156 /* Include any bdf fonts. */
6157 if (n_fonts
< maxnames
|| maxnames
< 0)
6159 Lisp_Object combined
[2];
6160 combined
[0] = w32_list_bdf_fonts (pattern
, maxnames
- n_fonts
);
6161 combined
[1] = newlist
;
6162 newlist
= Fnconc(2, combined
);
6169 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
6171 w32_get_font_info (f
, font_idx
)
6175 return (FRAME_W32_FONT_TABLE (f
) + font_idx
);
6180 w32_query_font (struct frame
*f
, char *fontname
)
6183 struct font_info
*pfi
;
6185 pfi
= FRAME_W32_FONT_TABLE (f
);
6187 for (i
= 0; i
< one_w32_display_info
.n_fonts
;i
++, pfi
++)
6189 if (strcmp(pfi
->name
, fontname
) == 0) return pfi
;
6195 /* Find a CCL program for a font specified by FONTP, and set the member
6196 `encoder' of the structure. */
6199 w32_find_ccl_program (fontp
)
6200 struct font_info
*fontp
;
6202 Lisp_Object list
, elt
;
6204 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
6208 && STRINGP (XCAR (elt
))
6209 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
6215 struct ccl_program
*ccl
6216 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
6218 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
6221 fontp
->font_encoder
= ccl
;
6225 /* directory-files from dired.c. */
6226 Lisp_Object Fdirectory_files
P_((Lisp_Object
, Lisp_Object
, Lisp_Object
, Lisp_Object
));
6229 /* Find BDF files in a specified directory. (use GCPRO when calling,
6230 as this calls lisp to get a directory listing). */
6232 w32_find_bdf_fonts_in_dir (Lisp_Object directory
)
6234 Lisp_Object filelist
, list
= Qnil
;
6237 if (!STRINGP(directory
))
6240 filelist
= Fdirectory_files (directory
, Qt
,
6241 build_string (".*\\.[bB][dD][fF]"), Qt
);
6243 for ( ; CONSP(filelist
); filelist
= XCDR (filelist
))
6245 Lisp_Object filename
= XCAR (filelist
);
6246 if (w32_BDF_to_x_font (SDATA (filename
), fontname
, 100))
6247 store_in_alist (&list
, build_string (fontname
), filename
);
6252 DEFUN ("w32-find-bdf-fonts", Fw32_find_bdf_fonts
, Sw32_find_bdf_fonts
,
6254 doc
: /* Return a list of BDF fonts in DIRECTORY.
6255 The list is suitable for appending to `w32-bdf-filename-alist'.
6256 Fonts which do not contain an xlfd description will not be included
6257 in the list. DIRECTORY may be a list of directories. */)
6259 Lisp_Object directory
;
6261 Lisp_Object list
= Qnil
;
6262 struct gcpro gcpro1
, gcpro2
;
6264 if (!CONSP (directory
))
6265 return w32_find_bdf_fonts_in_dir (directory
);
6267 for ( ; CONSP (directory
); directory
= XCDR (directory
))
6269 Lisp_Object pair
[2];
6272 GCPRO2 (directory
, list
);
6273 pair
[1] = w32_find_bdf_fonts_in_dir( XCAR (directory
) );
6274 list
= Fnconc( 2, pair
);
6281 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
6282 doc
: /* Internal function called by `color-defined-p', which see. */)
6284 Lisp_Object color
, frame
;
6287 FRAME_PTR f
= check_x_frame (frame
);
6289 CHECK_STRING (color
);
6291 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
6297 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
6298 doc
: /* Internal function called by `color-values', which see. */)
6300 Lisp_Object color
, frame
;
6303 FRAME_PTR f
= check_x_frame (frame
);
6305 CHECK_STRING (color
);
6307 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
6311 rgb
[0] = make_number ((GetRValue (foo
.pixel
) << 8)
6312 | GetRValue (foo
.pixel
));
6313 rgb
[1] = make_number ((GetGValue (foo
.pixel
) << 8)
6314 | GetGValue (foo
.pixel
));
6315 rgb
[2] = make_number ((GetBValue (foo
.pixel
) << 8)
6316 | GetBValue (foo
.pixel
));
6317 return Flist (3, rgb
);
6323 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
6324 doc
: /* Internal function called by `display-color-p', which see. */)
6326 Lisp_Object display
;
6328 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6330 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
6336 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
,
6337 Sx_display_grayscale_p
, 0, 1, 0,
6338 doc
: /* Return t if DISPLAY supports shades of gray.
6339 Note that color displays do support shades of gray.
6340 The optional argument DISPLAY specifies which display to ask about.
6341 DISPLAY should be either a frame or a display name (a string).
6342 If omitted or nil, that stands for the selected frame's display. */)
6344 Lisp_Object display
;
6346 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6348 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
6354 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
,
6355 Sx_display_pixel_width
, 0, 1, 0,
6356 doc
: /* Returns the width in pixels of DISPLAY.
6357 The optional argument DISPLAY specifies which display to ask about.
6358 DISPLAY should be either a frame or a display name (a string).
6359 If omitted or nil, that stands for the selected frame's display. */)
6361 Lisp_Object display
;
6363 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6365 return make_number (dpyinfo
->width
);
6368 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
6369 Sx_display_pixel_height
, 0, 1, 0,
6370 doc
: /* Returns the height in pixels of DISPLAY.
6371 The optional argument DISPLAY specifies which display to ask about.
6372 DISPLAY should be either a frame or a display name (a string).
6373 If omitted or nil, that stands for the selected frame's display. */)
6375 Lisp_Object display
;
6377 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6379 return make_number (dpyinfo
->height
);
6382 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
6384 doc
: /* Returns the number of bitplanes of DISPLAY.
6385 The optional argument DISPLAY specifies which display to ask about.
6386 DISPLAY should be either a frame or a display name (a string).
6387 If omitted or nil, that stands for the selected frame's display. */)
6389 Lisp_Object display
;
6391 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6393 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
6396 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
6398 doc
: /* Returns the number of color cells of DISPLAY.
6399 The optional argument DISPLAY specifies which display to ask about.
6400 DISPLAY should be either a frame or a display name (a string).
6401 If omitted or nil, that stands for the selected frame's display. */)
6403 Lisp_Object display
;
6405 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6409 hdc
= GetDC (dpyinfo
->root_window
);
6410 if (dpyinfo
->has_palette
)
6411 cap
= GetDeviceCaps (hdc
, SIZEPALETTE
);
6413 cap
= GetDeviceCaps (hdc
, NUMCOLORS
);
6415 /* We force 24+ bit depths to 24-bit, both to prevent an overflow
6416 and because probably is more meaningful on Windows anyway */
6418 cap
= 1 << min(dpyinfo
->n_planes
* dpyinfo
->n_cbits
, 24);
6420 ReleaseDC (dpyinfo
->root_window
, hdc
);
6422 return make_number (cap
);
6425 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
6426 Sx_server_max_request_size
,
6428 doc
: /* Returns the maximum request size of the server of DISPLAY.
6429 The optional argument DISPLAY specifies which display to ask about.
6430 DISPLAY should be either a frame or a display name (a string).
6431 If omitted or nil, that stands for the selected frame's display. */)
6433 Lisp_Object display
;
6435 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6437 return make_number (1);
6440 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
6441 doc
: /* Returns the "vendor ID" string of the W32 system (Microsoft).
6442 The optional argument DISPLAY specifies which display to ask about.
6443 DISPLAY should be either a frame or a display name (a string).
6444 If omitted or nil, that stands for the selected frame's display. */)
6446 Lisp_Object display
;
6448 return build_string ("Microsoft Corp.");
6451 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
6452 doc
: /* Returns the version numbers of the server of DISPLAY.
6453 The value is a list of three integers: the major and minor
6454 version numbers of the X Protocol in use, and the distributor-specific release
6455 number. See also the function `x-server-vendor'.
6457 The optional argument DISPLAY specifies which display to ask about.
6458 DISPLAY should be either a frame or a display name (a string).
6459 If omitted or nil, that stands for the selected frame's display. */)
6461 Lisp_Object display
;
6463 return Fcons (make_number (w32_major_version
),
6464 Fcons (make_number (w32_minor_version
),
6465 Fcons (make_number (w32_build_number
), Qnil
)));
6468 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
6469 doc
: /* Returns the number of screens on the server of DISPLAY.
6470 The optional argument DISPLAY specifies which display to ask about.
6471 DISPLAY should be either a frame or a display name (a string).
6472 If omitted or nil, that stands for the selected frame's display. */)
6474 Lisp_Object display
;
6476 return make_number (1);
6479 DEFUN ("x-display-mm-height", Fx_display_mm_height
,
6480 Sx_display_mm_height
, 0, 1, 0,
6481 doc
: /* Returns the height in millimeters of DISPLAY.
6482 The optional argument DISPLAY specifies which display to ask about.
6483 DISPLAY should be either a frame or a display name (a string).
6484 If omitted or nil, that stands for the selected frame's display. */)
6486 Lisp_Object display
;
6488 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6492 hdc
= GetDC (dpyinfo
->root_window
);
6494 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
6496 ReleaseDC (dpyinfo
->root_window
, hdc
);
6498 return make_number (cap
);
6501 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
6502 doc
: /* Returns the width in millimeters of DISPLAY.
6503 The optional argument DISPLAY specifies which display to ask about.
6504 DISPLAY should be either a frame or a display name (a string).
6505 If omitted or nil, that stands for the selected frame's display. */)
6507 Lisp_Object display
;
6509 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6514 hdc
= GetDC (dpyinfo
->root_window
);
6516 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
6518 ReleaseDC (dpyinfo
->root_window
, hdc
);
6520 return make_number (cap
);
6523 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
6524 Sx_display_backing_store
, 0, 1, 0,
6525 doc
: /* Returns an indication of whether DISPLAY does backing store.
6526 The value may be `always', `when-mapped', or `not-useful'.
6527 The optional argument DISPLAY specifies which display to ask about.
6528 DISPLAY should be either a frame or a display name (a string).
6529 If omitted or nil, that stands for the selected frame's display. */)
6531 Lisp_Object display
;
6533 return intern ("not-useful");
6536 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
6537 Sx_display_visual_class
, 0, 1, 0,
6538 doc
: /* Returns the visual class of DISPLAY.
6539 The value is one of the symbols `static-gray', `gray-scale',
6540 `static-color', `pseudo-color', `true-color', or `direct-color'.
6542 The optional argument DISPLAY specifies which display to ask about.
6543 DISPLAY should be either a frame or a display name (a string).
6544 If omitted or nil, that stands for the selected frame's display. */)
6546 Lisp_Object display
;
6548 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6549 Lisp_Object result
= Qnil
;
6551 if (dpyinfo
->has_palette
)
6552 result
= intern ("pseudo-color");
6553 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
6554 result
= intern ("static-grey");
6555 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
6556 result
= intern ("static-color");
6557 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
6558 result
= intern ("true-color");
6563 DEFUN ("x-display-save-under", Fx_display_save_under
,
6564 Sx_display_save_under
, 0, 1, 0,
6565 doc
: /* Returns t if DISPLAY supports the save-under feature.
6566 The optional argument DISPLAY specifies which display to ask about.
6567 DISPLAY should be either a frame or a display name (a string).
6568 If omitted or nil, that stands for the selected frame's display. */)
6570 Lisp_Object display
;
6577 register struct frame
*f
;
6579 return FRAME_PIXEL_WIDTH (f
);
6584 register struct frame
*f
;
6586 return FRAME_PIXEL_HEIGHT (f
);
6591 register struct frame
*f
;
6593 return FRAME_COLUMN_WIDTH (f
);
6598 register struct frame
*f
;
6600 return FRAME_LINE_HEIGHT (f
);
6605 register struct frame
*f
;
6607 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
6610 /* Return the display structure for the display named NAME.
6611 Open a new connection if necessary. */
6613 struct w32_display_info
*
6614 x_display_info_for_name (name
)
6618 struct w32_display_info
*dpyinfo
;
6620 CHECK_STRING (name
);
6622 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
6624 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
6627 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
6632 /* Use this general default value to start with. */
6633 Vx_resource_name
= Vinvocation_name
;
6635 validate_x_resource_name ();
6637 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
6638 (char *) SDATA (Vx_resource_name
));
6641 error ("Cannot connect to server %s", SDATA (name
));
6644 XSETFASTINT (Vwindow_system_version
, 3);
6649 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
6650 1, 3, 0, doc
: /* Open a connection to a server.
6651 DISPLAY is the name of the display to connect to.
6652 Optional second arg XRM-STRING is a string of resources in xrdb format.
6653 If the optional third arg MUST-SUCCEED is non-nil,
6654 terminate Emacs if we can't open the connection. */)
6655 (display
, xrm_string
, must_succeed
)
6656 Lisp_Object display
, xrm_string
, must_succeed
;
6658 unsigned char *xrm_option
;
6659 struct w32_display_info
*dpyinfo
;
6661 /* If initialization has already been done, return now to avoid
6662 overwriting critical parts of one_w32_display_info. */
6666 CHECK_STRING (display
);
6667 if (! NILP (xrm_string
))
6668 CHECK_STRING (xrm_string
);
6670 if (! EQ (Vwindow_system
, intern ("w32")))
6671 error ("Not using Microsoft Windows");
6673 /* Allow color mapping to be defined externally; first look in user's
6674 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
6676 Lisp_Object color_file
;
6677 struct gcpro gcpro1
;
6679 color_file
= build_string("~/rgb.txt");
6681 GCPRO1 (color_file
);
6683 if (NILP (Ffile_readable_p (color_file
)))
6685 Fexpand_file_name (build_string ("rgb.txt"),
6686 Fsymbol_value (intern ("data-directory")));
6688 Vw32_color_map
= Fw32_load_color_file (color_file
);
6692 if (NILP (Vw32_color_map
))
6693 Vw32_color_map
= Fw32_default_color_map ();
6695 /* Merge in system logical colors. */
6696 add_system_logical_colors_to_map (&Vw32_color_map
);
6698 if (! NILP (xrm_string
))
6699 xrm_option
= (unsigned char *) SDATA (xrm_string
);
6701 xrm_option
= (unsigned char *) 0;
6703 /* Use this general default value to start with. */
6704 /* First remove .exe suffix from invocation-name - it looks ugly. */
6706 char basename
[ MAX_PATH
], *str
;
6708 strcpy (basename
, SDATA (Vinvocation_name
));
6709 str
= strrchr (basename
, '.');
6711 Vinvocation_name
= build_string (basename
);
6713 Vx_resource_name
= Vinvocation_name
;
6715 validate_x_resource_name ();
6717 /* This is what opens the connection and sets x_current_display.
6718 This also initializes many symbols, such as those used for input. */
6719 dpyinfo
= w32_term_init (display
, xrm_option
,
6720 (char *) SDATA (Vx_resource_name
));
6724 if (!NILP (must_succeed
))
6725 fatal ("Cannot connect to server %s.\n",
6728 error ("Cannot connect to server %s", SDATA (display
));
6733 XSETFASTINT (Vwindow_system_version
, 3);
6737 DEFUN ("x-close-connection", Fx_close_connection
,
6738 Sx_close_connection
, 1, 1, 0,
6739 doc
: /* Close the connection to DISPLAY's server.
6740 For DISPLAY, specify either a frame or a display name (a string).
6741 If DISPLAY is nil, that stands for the selected frame's display. */)
6743 Lisp_Object display
;
6745 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6748 if (dpyinfo
->reference_count
> 0)
6749 error ("Display still has frames on it");
6752 /* Free the fonts in the font table. */
6753 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
6754 if (dpyinfo
->font_table
[i
].name
)
6756 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
6757 xfree (dpyinfo
->font_table
[i
].full_name
);
6758 xfree (dpyinfo
->font_table
[i
].name
);
6759 w32_unload_font (dpyinfo
, dpyinfo
->font_table
[i
].font
);
6761 x_destroy_all_bitmaps (dpyinfo
);
6763 x_delete_display (dpyinfo
);
6769 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
6770 doc
: /* Return the list of display names that Emacs has connections to. */)
6773 Lisp_Object tail
, result
;
6776 for (tail
= w32_display_name_list
; ! NILP (tail
); tail
= XCDR (tail
))
6777 result
= Fcons (XCAR (XCAR (tail
)), result
);
6782 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
6783 doc
: /* This is a noop on W32 systems. */)
6785 Lisp_Object display
, on
;
6792 /***********************************************************************
6794 ***********************************************************************/
6796 DEFUN ("x-change-window-property", Fx_change_window_property
,
6797 Sx_change_window_property
, 2, 6, 0,
6798 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
6799 VALUE may be a string or a list of conses, numbers and/or strings.
6800 If an element in the list is a string, it is converted to
6801 an Atom and the value of the Atom is used. If an element is a cons,
6802 it is converted to a 32 bit number where the car is the 16 top bits and the
6803 cdr is the lower 16 bits.
6804 FRAME nil or omitted means use the selected frame.
6805 If TYPE is given and non-nil, it is the name of the type of VALUE.
6806 If TYPE is not given or nil, the type is STRING.
6807 FORMAT gives the size in bits of each element if VALUE is a list.
6808 It must be one of 8, 16 or 32.
6809 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
6810 If OUTER_P is non-nil, the property is changed for the outer X window of
6811 FRAME. Default is to change on the edit X window.
6814 (prop
, value
, frame
, type
, format
, outer_p
)
6815 Lisp_Object prop
, value
, frame
, type
, format
, outer_p
;
6817 #if 0 /* TODO : port window properties to W32 */
6818 struct frame
*f
= check_x_frame (frame
);
6821 CHECK_STRING (prop
);
6822 CHECK_STRING (value
);
6825 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
6826 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
6827 prop_atom
, XA_STRING
, 8, PropModeReplace
,
6828 SDATA (value
), SCHARS (value
));
6830 /* Make sure the property is set when we return. */
6831 XFlush (FRAME_W32_DISPLAY (f
));
6840 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
6841 Sx_delete_window_property
, 1, 2, 0,
6842 doc
: /* Remove window property PROP from X window of FRAME.
6843 FRAME nil or omitted means use the selected frame. Value is PROP. */)
6845 Lisp_Object prop
, frame
;
6847 #if 0 /* TODO : port window properties to W32 */
6849 struct frame
*f
= check_x_frame (frame
);
6852 CHECK_STRING (prop
);
6854 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
6855 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
6857 /* Make sure the property is removed when we return. */
6858 XFlush (FRAME_W32_DISPLAY (f
));
6866 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
6868 doc
: /* Value is the value of window property PROP on FRAME.
6869 If FRAME is nil or omitted, use the selected frame. Value is nil
6870 if FRAME hasn't a property with name PROP or if PROP has no string
6873 Lisp_Object prop
, frame
;
6875 #if 0 /* TODO : port window properties to W32 */
6877 struct frame
*f
= check_x_frame (frame
);
6880 Lisp_Object prop_value
= Qnil
;
6881 char *tmp_data
= NULL
;
6884 unsigned long actual_size
, bytes_remaining
;
6886 CHECK_STRING (prop
);
6888 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
6889 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
6890 prop_atom
, 0, 0, False
, XA_STRING
,
6891 &actual_type
, &actual_format
, &actual_size
,
6892 &bytes_remaining
, (unsigned char **) &tmp_data
);
6895 int size
= bytes_remaining
;
6900 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
6901 prop_atom
, 0, bytes_remaining
,
6903 &actual_type
, &actual_format
,
6904 &actual_size
, &bytes_remaining
,
6905 (unsigned char **) &tmp_data
);
6907 prop_value
= make_string (tmp_data
, size
);
6922 /***********************************************************************
6924 ***********************************************************************/
6926 /* If non-null, an asynchronous timer that, when it expires, displays
6927 an hourglass cursor on all frames. */
6929 static struct atimer
*hourglass_atimer
;
6931 /* Non-zero means an hourglass cursor is currently shown. */
6933 static int hourglass_shown_p
;
6935 /* Number of seconds to wait before displaying an hourglass cursor. */
6937 static Lisp_Object Vhourglass_delay
;
6939 /* Default number of seconds to wait before displaying an hourglass
6942 #define DEFAULT_HOURGLASS_DELAY 1
6944 /* Function prototypes. */
6946 static void show_hourglass
P_ ((struct atimer
*));
6947 static void hide_hourglass
P_ ((void));
6950 /* Cancel a currently active hourglass timer, and start a new one. */
6955 #if 0 /* TODO: cursor shape changes. */
6957 int secs
, usecs
= 0;
6959 cancel_hourglass ();
6961 if (INTEGERP (Vhourglass_delay
)
6962 && XINT (Vhourglass_delay
) > 0)
6963 secs
= XFASTINT (Vhourglass_delay
);
6964 else if (FLOATP (Vhourglass_delay
)
6965 && XFLOAT_DATA (Vhourglass_delay
) > 0)
6968 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
6969 secs
= XFASTINT (tem
);
6970 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
6973 secs
= DEFAULT_HOURGLASS_DELAY
;
6975 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
6976 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
6977 show_hourglass
, NULL
);
6982 /* Cancel the hourglass cursor timer if active, hide an hourglass
6988 if (hourglass_atimer
)
6990 cancel_atimer (hourglass_atimer
);
6991 hourglass_atimer
= NULL
;
6994 if (hourglass_shown_p
)
6999 /* Timer function of hourglass_atimer. TIMER is equal to
7002 Display an hourglass cursor on all frames by mapping the frames'
7003 hourglass_window. Set the hourglass_p flag in the frames'
7004 output_data.x structure to indicate that an hourglass cursor is
7005 shown on the frames. */
7008 show_hourglass (timer
)
7009 struct atimer
*timer
;
7011 #if 0 /* TODO: cursor shape changes. */
7012 /* The timer implementation will cancel this timer automatically
7013 after this function has run. Set hourglass_atimer to null
7014 so that we know the timer doesn't have to be canceled. */
7015 hourglass_atimer
= NULL
;
7017 if (!hourglass_shown_p
)
7019 Lisp_Object rest
, frame
;
7023 FOR_EACH_FRAME (rest
, frame
)
7024 if (FRAME_W32_P (XFRAME (frame
)))
7026 struct frame
*f
= XFRAME (frame
);
7028 f
->output_data
.w32
->hourglass_p
= 1;
7030 if (!f
->output_data
.w32
->hourglass_window
)
7032 unsigned long mask
= CWCursor
;
7033 XSetWindowAttributes attrs
;
7035 attrs
.cursor
= f
->output_data
.w32
->hourglass_cursor
;
7037 f
->output_data
.w32
->hourglass_window
7038 = XCreateWindow (FRAME_X_DISPLAY (f
),
7039 FRAME_OUTER_WINDOW (f
),
7040 0, 0, 32000, 32000, 0, 0,
7046 XMapRaised (FRAME_X_DISPLAY (f
),
7047 f
->output_data
.w32
->hourglass_window
);
7048 XFlush (FRAME_X_DISPLAY (f
));
7051 hourglass_shown_p
= 1;
7058 /* Hide the hourglass cursor on all frames, if it is currently shown. */
7063 #if 0 /* TODO: cursor shape changes. */
7064 if (hourglass_shown_p
)
7066 Lisp_Object rest
, frame
;
7069 FOR_EACH_FRAME (rest
, frame
)
7071 struct frame
*f
= XFRAME (frame
);
7074 /* Watch out for newly created frames. */
7075 && f
->output_data
.x
->hourglass_window
)
7077 XUnmapWindow (FRAME_X_DISPLAY (f
),
7078 f
->output_data
.x
->hourglass_window
);
7079 /* Sync here because XTread_socket looks at the
7080 hourglass_p flag that is reset to zero below. */
7081 XSync (FRAME_X_DISPLAY (f
), False
);
7082 f
->output_data
.x
->hourglass_p
= 0;
7086 hourglass_shown_p
= 0;
7094 /***********************************************************************
7096 ***********************************************************************/
7098 static Lisp_Object x_create_tip_frame
P_ ((struct w32_display_info
*,
7099 Lisp_Object
, Lisp_Object
));
7100 static void compute_tip_xy
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
7101 Lisp_Object
, int, int, int *, int *));
7103 /* The frame of a currently visible tooltip. */
7105 Lisp_Object tip_frame
;
7107 /* If non-nil, a timer started that hides the last tooltip when it
7110 Lisp_Object tip_timer
;
7113 /* If non-nil, a vector of 3 elements containing the last args
7114 with which x-show-tip was called. See there. */
7116 Lisp_Object last_show_tip_args
;
7118 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
7120 Lisp_Object Vx_max_tooltip_size
;
7124 unwind_create_tip_frame (frame
)
7127 Lisp_Object deleted
;
7129 deleted
= unwind_create_frame (frame
);
7130 if (EQ (deleted
, Qt
))
7140 /* Create a frame for a tooltip on the display described by DPYINFO.
7141 PARMS is a list of frame parameters. TEXT is the string to
7142 display in the tip frame. Value is the frame.
7144 Note that functions called here, esp. x_default_parameter can
7145 signal errors, for instance when a specified color name is
7146 undefined. We have to make sure that we're in a consistent state
7147 when this happens. */
7150 x_create_tip_frame (dpyinfo
, parms
, text
)
7151 struct w32_display_info
*dpyinfo
;
7152 Lisp_Object parms
, text
;
7155 Lisp_Object frame
, tem
;
7157 long window_prompting
= 0;
7159 int count
= SPECPDL_INDEX ();
7160 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7162 int face_change_count_before
= face_change_count
;
7164 struct buffer
*old_buffer
;
7168 /* Use this general default value to start with until we know if
7169 this frame has a specified name. */
7170 Vx_resource_name
= Vinvocation_name
;
7173 kb
= dpyinfo
->kboard
;
7175 kb
= &the_only_kboard
;
7178 /* Get the name of the frame to use for resource lookup. */
7179 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
7181 && !EQ (name
, Qunbound
)
7183 error ("Invalid frame name--not a string or nil");
7184 Vx_resource_name
= name
;
7187 GCPRO3 (parms
, name
, frame
);
7188 /* Make a frame without minibuffer nor mode-line. */
7190 f
->wants_modeline
= 0;
7191 XSETFRAME (frame
, f
);
7193 buffer
= Fget_buffer_create (build_string (" *tip*"));
7194 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, Qnil
);
7195 old_buffer
= current_buffer
;
7196 set_buffer_internal_1 (XBUFFER (buffer
));
7197 current_buffer
->truncate_lines
= Qnil
;
7198 specbind (Qinhibit_read_only
, Qt
);
7199 specbind (Qinhibit_modification_hooks
, Qt
);
7202 set_buffer_internal_1 (old_buffer
);
7204 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
7205 record_unwind_protect (unwind_create_tip_frame
, frame
);
7207 /* By setting the output method, we're essentially saying that
7208 the frame is live, as per FRAME_LIVE_P. If we get a signal
7209 from this point on, x_destroy_window might screw up reference
7211 f
->output_method
= output_w32
;
7212 f
->output_data
.w32
=
7213 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
7214 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
7216 FRAME_FONTSET (f
) = -1;
7217 f
->icon_name
= Qnil
;
7219 #if 0 /* GLYPH_DEBUG TODO: image support. */
7220 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
7221 dpyinfo_refcount
= dpyinfo
->reference_count
;
7222 #endif /* GLYPH_DEBUG */
7224 FRAME_KBOARD (f
) = kb
;
7226 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
7227 f
->output_data
.w32
->explicit_parent
= 0;
7229 /* Set the name; the functions to which we pass f expect the name to
7231 if (EQ (name
, Qunbound
) || NILP (name
))
7233 f
->name
= build_string (dpyinfo
->w32_id_name
);
7234 f
->explicit_name
= 0;
7239 f
->explicit_name
= 1;
7240 /* use the frame's title when getting resources for this frame. */
7241 specbind (Qx_resource_name
, name
);
7244 /* Extract the window parameters from the supplied values
7245 that are needed to determine window geometry. */
7249 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
7252 /* First, try whatever font the caller has specified. */
7255 tem
= Fquery_fontset (font
, Qnil
);
7257 font
= x_new_fontset (f
, SDATA (tem
));
7259 font
= x_new_font (f
, SDATA (font
));
7262 /* Try out a font which we hope has bold and italic variations. */
7263 if (!STRINGP (font
))
7264 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
7265 if (! STRINGP (font
))
7266 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
7267 /* If those didn't work, look for something which will at least work. */
7268 if (! STRINGP (font
))
7269 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
7271 if (! STRINGP (font
))
7272 font
= build_string ("Fixedsys");
7274 x_default_parameter (f
, parms
, Qfont
, font
,
7275 "font", "Font", RES_TYPE_STRING
);
7278 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
7279 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
7280 /* This defaults to 2 in order to match xterm. We recognize either
7281 internalBorderWidth or internalBorder (which is what xterm calls
7283 if (NILP (Fassq (Qinternal_border_width
, parms
)))
7287 value
= w32_get_arg (parms
, Qinternal_border_width
,
7288 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
7289 if (! EQ (value
, Qunbound
))
7290 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
7293 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
7294 "internalBorderWidth", "internalBorderWidth",
7297 /* Also do the stuff which must be set before the window exists. */
7298 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
7299 "foreground", "Foreground", RES_TYPE_STRING
);
7300 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
7301 "background", "Background", RES_TYPE_STRING
);
7302 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
7303 "pointerColor", "Foreground", RES_TYPE_STRING
);
7304 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
7305 "cursorColor", "Foreground", RES_TYPE_STRING
);
7306 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
7307 "borderColor", "BorderColor", RES_TYPE_STRING
);
7309 /* Init faces before x_default_parameter is called for scroll-bar
7310 parameters because that function calls x_set_scroll_bar_width,
7311 which calls change_frame_size, which calls Fset_window_buffer,
7312 which runs hooks, which call Fvertical_motion. At the end, we
7313 end up in init_iterator with a null face cache, which should not
7315 init_frame_faces (f
);
7317 f
->output_data
.w32
->dwStyle
= WS_BORDER
| WS_POPUP
| WS_DISABLED
;
7318 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
7320 window_prompting
= x_figure_window_size (f
, parms
, 0);
7322 /* No fringes on tip frame. */
7324 f
->left_fringe_width
= 0;
7325 f
->right_fringe_width
= 0;
7328 my_create_tip_window (f
);
7333 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
7334 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
7335 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
7336 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
7337 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
7338 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
7340 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
7341 Change will not be effected unless different from the current
7343 width
= FRAME_COLS (f
);
7344 height
= FRAME_LINES (f
);
7345 FRAME_LINES (f
) = 0;
7346 SET_FRAME_COLS (f
, 0);
7347 change_frame_size (f
, height
, width
, 1, 0, 0);
7349 /* Add `tooltip' frame parameter's default value. */
7350 if (NILP (Fframe_parameter (frame
, intern ("tooltip"))))
7351 Fmodify_frame_parameters (frame
, Fcons (Fcons (intern ("tooltip"), Qt
),
7354 /* Set up faces after all frame parameters are known. This call
7355 also merges in face attributes specified for new frames.
7357 Frame parameters may be changed if .Xdefaults contains
7358 specifications for the default font. For example, if there is an
7359 `Emacs.default.attributeBackground: pink', the `background-color'
7360 attribute of the frame get's set, which let's the internal border
7361 of the tooltip frame appear in pink. Prevent this. */
7363 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
7365 /* Set tip_frame here, so that */
7367 call1 (Qface_set_after_frame_default
, frame
);
7369 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
7370 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qbackground_color
, bg
),
7378 /* It is now ok to make the frame official even if we get an error
7379 below. And the frame needs to be on Vframe_list or making it
7380 visible won't work. */
7381 Vframe_list
= Fcons (frame
, Vframe_list
);
7383 /* Now that the frame is official, it counts as a reference to
7385 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
7387 /* Setting attributes of faces of the tooltip frame from resources
7388 and similar will increment face_change_count, which leads to the
7389 clearing of all current matrices. Since this isn't necessary
7390 here, avoid it by resetting face_change_count to the value it
7391 had before we created the tip frame. */
7392 face_change_count
= face_change_count_before
;
7394 /* Discard the unwind_protect. */
7395 return unbind_to (count
, frame
);
7399 /* Compute where to display tip frame F. PARMS is the list of frame
7400 parameters for F. DX and DY are specified offsets from the current
7401 location of the mouse. WIDTH and HEIGHT are the width and height
7402 of the tooltip. Return coordinates relative to the root window of
7403 the display in *ROOT_X, and *ROOT_Y. */
7406 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, root_x
, root_y
)
7408 Lisp_Object parms
, dx
, dy
;
7410 int *root_x
, *root_y
;
7412 Lisp_Object left
, top
;
7414 /* User-specified position? */
7415 left
= Fcdr (Fassq (Qleft
, parms
));
7416 top
= Fcdr (Fassq (Qtop
, parms
));
7418 /* Move the tooltip window where the mouse pointer is. Resize and
7420 if (!INTEGERP (left
) || !INTEGERP (top
))
7432 *root_y
= XINT (top
);
7433 else if (*root_y
+ XINT (dy
) <= 0)
7434 *root_y
= 0; /* Can happen for negative dy */
7435 else if (*root_y
+ XINT (dy
) + height
<= FRAME_W32_DISPLAY_INFO (f
)->height
)
7436 /* It fits below the pointer */
7437 *root_y
+= XINT (dy
);
7438 else if (height
+ XINT (dy
) <= *root_y
)
7439 /* It fits above the pointer. */
7440 *root_y
-= height
+ XINT (dy
);
7442 /* Put it on the top. */
7445 if (INTEGERP (left
))
7446 *root_x
= XINT (left
);
7447 else if (*root_x
+ XINT (dx
) <= 0)
7448 *root_x
= 0; /* Can happen for negative dx */
7449 else if (*root_x
+ XINT (dx
) + width
<= FRAME_W32_DISPLAY_INFO (f
)->width
)
7450 /* It fits to the right of the pointer. */
7451 *root_x
+= XINT (dx
);
7452 else if (width
+ XINT (dx
) <= *root_x
)
7453 /* It fits to the left of the pointer. */
7454 *root_x
-= width
+ XINT (dx
);
7456 /* Put it left justified on the screen -- it ought to fit that way. */
7461 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
7462 doc
: /* Show STRING in a \"tooltip\" window on frame FRAME.
7463 A tooltip window is a small window displaying a string.
7465 FRAME nil or omitted means use the selected frame.
7467 PARMS is an optional list of frame parameters which can be
7468 used to change the tooltip's appearance.
7470 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
7471 means use the default timeout of 5 seconds.
7473 If the list of frame parameters PARMS contains a `left' parameter,
7474 the tooltip is displayed at that x-position. Otherwise it is
7475 displayed at the mouse position, with offset DX added (default is 5 if
7476 DX isn't specified). Likewise for the y-position; if a `top' frame
7477 parameter is specified, it determines the y-position of the tooltip
7478 window, otherwise it is displayed at the mouse position, with offset
7479 DY added (default is -10).
7481 A tooltip's maximum size is specified by `x-max-tooltip-size'.
7482 Text larger than the specified size is clipped. */)
7483 (string
, frame
, parms
, timeout
, dx
, dy
)
7484 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
7489 struct buffer
*old_buffer
;
7490 struct text_pos pos
;
7491 int i
, width
, height
;
7492 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7493 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7494 int count
= SPECPDL_INDEX ();
7496 specbind (Qinhibit_redisplay
, Qt
);
7498 GCPRO4 (string
, parms
, frame
, timeout
);
7500 CHECK_STRING (string
);
7501 f
= check_x_frame (frame
);
7503 timeout
= make_number (5);
7505 CHECK_NATNUM (timeout
);
7508 dx
= make_number (5);
7513 dy
= make_number (-10);
7517 if (NILP (last_show_tip_args
))
7518 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
7520 if (!NILP (tip_frame
))
7522 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
7523 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
7524 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
7526 if (EQ (frame
, last_frame
)
7527 && !NILP (Fequal (last_string
, string
))
7528 && !NILP (Fequal (last_parms
, parms
)))
7530 struct frame
*f
= XFRAME (tip_frame
);
7532 /* Only DX and DY have changed. */
7533 if (!NILP (tip_timer
))
7535 Lisp_Object timer
= tip_timer
;
7537 call1 (Qcancel_timer
, timer
);
7541 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
7542 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
7544 /* Put tooltip in topmost group and in position. */
7545 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
7546 root_x
, root_y
, 0, 0,
7547 SWP_NOSIZE
| SWP_NOACTIVATE
);
7549 /* Ensure tooltip is on top of other topmost windows (eg menus). */
7550 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
7552 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
7559 /* Hide a previous tip, if any. */
7562 ASET (last_show_tip_args
, 0, string
);
7563 ASET (last_show_tip_args
, 1, frame
);
7564 ASET (last_show_tip_args
, 2, parms
);
7566 /* Add default values to frame parameters. */
7567 if (NILP (Fassq (Qname
, parms
)))
7568 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
7569 if (NILP (Fassq (Qinternal_border_width
, parms
)))
7570 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
7571 if (NILP (Fassq (Qborder_width
, parms
)))
7572 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
7573 if (NILP (Fassq (Qborder_color
, parms
)))
7574 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
7575 if (NILP (Fassq (Qbackground_color
, parms
)))
7576 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
7579 /* Block input until the tip has been fully drawn, to avoid crashes
7580 when drawing tips in menus. */
7583 /* Create a frame for the tooltip, and record it in the global
7584 variable tip_frame. */
7585 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
, string
);
7588 /* Set up the frame's root window. */
7589 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7590 w
->left_col
= w
->top_line
= make_number (0);
7592 if (CONSP (Vx_max_tooltip_size
)
7593 && INTEGERP (XCAR (Vx_max_tooltip_size
))
7594 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
7595 && INTEGERP (XCDR (Vx_max_tooltip_size
))
7596 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
7598 w
->total_cols
= XCAR (Vx_max_tooltip_size
);
7599 w
->total_lines
= XCDR (Vx_max_tooltip_size
);
7603 w
->total_cols
= make_number (80);
7604 w
->total_lines
= make_number (40);
7607 FRAME_TOTAL_COLS (f
) = XINT (w
->total_cols
);
7609 w
->pseudo_window_p
= 1;
7611 /* Display the tooltip text in a temporary buffer. */
7612 old_buffer
= current_buffer
;
7613 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
7614 current_buffer
->truncate_lines
= Qnil
;
7615 clear_glyph_matrix (w
->desired_matrix
);
7616 clear_glyph_matrix (w
->current_matrix
);
7617 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
7618 try_window (FRAME_ROOT_WINDOW (f
), pos
, 0);
7620 /* Compute width and height of the tooltip. */
7622 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
7624 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
7628 /* Stop at the first empty row at the end. */
7629 if (!row
->enabled_p
|| !row
->displays_text_p
)
7632 /* Let the row go over the full width of the frame. */
7633 row
->full_width_p
= 1;
7635 #ifdef TODO /* Investigate why some fonts need more width than is
7636 calculated for some tooltips. */
7637 /* There's a glyph at the end of rows that is use to place
7638 the cursor there. Don't include the width of this glyph. */
7639 if (row
->used
[TEXT_AREA
])
7641 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
7642 row_width
= row
->pixel_width
- last
->pixel_width
;
7646 row_width
= row
->pixel_width
;
7648 /* TODO: find why tips do not draw along baseline as instructed. */
7649 height
+= row
->height
;
7650 width
= max (width
, row_width
);
7653 /* Add the frame's internal border to the width and height the X
7654 window should have. */
7655 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
7656 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
7658 /* Move the tooltip window where the mouse pointer is. Resize and
7660 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
7663 /* Adjust Window size to take border into account. */
7665 rect
.left
= rect
.top
= 0;
7667 rect
.bottom
= height
;
7668 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
7669 FRAME_EXTERNAL_MENU_BAR (f
));
7671 /* Position and size tooltip, and put it in the topmost group. */
7672 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
7673 root_x
, root_y
, rect
.right
- rect
.left
,
7674 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
);
7676 /* Ensure tooltip is on top of other topmost windows (eg menus). */
7677 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
7679 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
7681 /* Let redisplay know that we have made the frame visible already. */
7682 f
->async_visible
= 1;
7684 ShowWindow (FRAME_W32_WINDOW (f
), SW_SHOWNOACTIVATE
);
7687 /* Draw into the window. */
7688 w
->must_be_updated_p
= 1;
7689 update_single_window (w
, 1);
7693 /* Restore original current buffer. */
7694 set_buffer_internal_1 (old_buffer
);
7695 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7698 /* Let the tip disappear after timeout seconds. */
7699 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
7700 intern ("x-hide-tip"));
7703 return unbind_to (count
, Qnil
);
7707 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
7708 doc
: /* Hide the current tooltip window, if there is any.
7709 Value is t if tooltip was open, nil otherwise. */)
7713 Lisp_Object deleted
, frame
, timer
;
7714 struct gcpro gcpro1
, gcpro2
;
7716 /* Return quickly if nothing to do. */
7717 if (NILP (tip_timer
) && NILP (tip_frame
))
7722 GCPRO2 (frame
, timer
);
7723 tip_frame
= tip_timer
= deleted
= Qnil
;
7725 count
= SPECPDL_INDEX ();
7726 specbind (Qinhibit_redisplay
, Qt
);
7727 specbind (Qinhibit_quit
, Qt
);
7730 call1 (Qcancel_timer
, timer
);
7734 Fdelete_frame (frame
, Qnil
);
7739 return unbind_to (count
, deleted
);
7744 /***********************************************************************
7745 File selection dialog
7746 ***********************************************************************/
7747 extern Lisp_Object Qfile_name_history
;
7749 /* Callback for altering the behaviour of the Open File dialog.
7750 Makes the Filename text field contain "Current Directory" and be
7751 read-only when "Directories" is selected in the filter. This
7752 allows us to work around the fact that the standard Open File
7753 dialog does not support directories. */
7755 file_dialog_callback (hwnd
, msg
, wParam
, lParam
)
7761 if (msg
== WM_NOTIFY
)
7763 OFNOTIFY
* notify
= (OFNOTIFY
*)lParam
;
7764 /* Detect when the Filter dropdown is changed. */
7765 if (notify
->hdr
.code
== CDN_TYPECHANGE
7766 || notify
->hdr
.code
== CDN_INITDONE
)
7768 HWND dialog
= GetParent (hwnd
);
7769 HWND edit_control
= GetDlgItem (dialog
, FILE_NAME_TEXT_FIELD
);
7771 /* Directories is in index 2. */
7772 if (notify
->lpOFN
->nFilterIndex
== 2)
7774 CommDlg_OpenSave_SetControlText (dialog
, FILE_NAME_TEXT_FIELD
,
7775 "Current Directory");
7776 EnableWindow (edit_control
, FALSE
);
7780 /* Don't override default filename on init done. */
7781 if (notify
->hdr
.code
== CDN_TYPECHANGE
)
7782 CommDlg_OpenSave_SetControlText (dialog
,
7783 FILE_NAME_TEXT_FIELD
, "");
7784 EnableWindow (edit_control
, TRUE
);
7791 /* Since we compile with _WIN32_WINNT set to 0x0400 (for NT4 compatibility)
7792 we end up with the old file dialogs. Define a big enough struct for the
7793 new dialog to trick GetOpenFileName into giving us the new dialogs on
7794 Windows 2000 and XP. */
7797 OPENFILENAME real_details
;
7804 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
7805 doc
: /* Read file name, prompting with PROMPT in directory DIR.
7806 Use a file selection dialog.
7807 Select DEFAULT-FILENAME in the dialog's file selection box, if
7808 specified. Ensure that file exists if MUSTMATCH is non-nil.
7809 If ONLY-DIR-P is non-nil, the user can only select directories. */)
7810 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
)
7811 Lisp_Object prompt
, dir
, default_filename
, mustmatch
, only_dir_p
;
7813 struct frame
*f
= SELECTED_FRAME ();
7814 Lisp_Object file
= Qnil
;
7815 int count
= SPECPDL_INDEX ();
7816 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
7817 char filename
[MAX_PATH
+ 1];
7818 char init_dir
[MAX_PATH
+ 1];
7819 int default_filter_index
= 1; /* 1: All Files, 2: Directories only */
7821 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
7822 CHECK_STRING (prompt
);
7825 /* Create the dialog with PROMPT as title, using DIR as initial
7826 directory and using "*" as pattern. */
7827 dir
= Fexpand_file_name (dir
, Qnil
);
7828 strncpy (init_dir
, SDATA (ENCODE_FILE (dir
)), MAX_PATH
);
7829 init_dir
[MAX_PATH
] = '\0';
7830 unixtodos_filename (init_dir
);
7832 if (STRINGP (default_filename
))
7834 char *file_name_only
;
7835 char *full_path_name
= SDATA (ENCODE_FILE (default_filename
));
7837 unixtodos_filename (full_path_name
);
7839 file_name_only
= strrchr (full_path_name
, '\\');
7840 if (!file_name_only
)
7841 file_name_only
= full_path_name
;
7845 strncpy (filename
, file_name_only
, MAX_PATH
);
7846 filename
[MAX_PATH
] = '\0';
7852 NEWOPENFILENAME new_file_details
;
7853 BOOL file_opened
= FALSE
;
7854 OPENFILENAME
* file_details
= &new_file_details
.real_details
;
7856 /* Prevent redisplay. */
7857 specbind (Qinhibit_redisplay
, Qt
);
7860 bzero (&new_file_details
, sizeof (new_file_details
));
7861 /* Apparently NT4 crashes if you give it an unexpected size.
7862 I'm not sure about Windows 9x, so play it safe. */
7863 if (w32_major_version
> 4 && w32_major_version
< 95)
7864 file_details
->lStructSize
= sizeof (new_file_details
);
7866 file_details
->lStructSize
= sizeof (file_details
);
7868 file_details
->hwndOwner
= FRAME_W32_WINDOW (f
);
7869 /* Undocumented Bug in Common File Dialog:
7870 If a filter is not specified, shell links are not resolved. */
7871 file_details
->lpstrFilter
= "All Files (*.*)\0*.*\0Directories\0*|*\0\0";
7872 file_details
->lpstrFile
= filename
;
7873 file_details
->nMaxFile
= sizeof (filename
);
7874 file_details
->lpstrInitialDir
= init_dir
;
7875 file_details
->lpstrTitle
= SDATA (prompt
);
7877 if (! NILP (only_dir_p
))
7878 default_filter_index
= 2;
7880 file_details
->nFilterIndex
= default_filter_index
;
7882 file_details
->Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
7883 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
7884 if (!NILP (mustmatch
))
7886 /* Require that the path to the parent directory exists. */
7887 file_details
->Flags
|= OFN_PATHMUSTEXIST
;
7888 /* If we are looking for a file, require that it exists. */
7889 if (NILP (only_dir_p
))
7890 file_details
->Flags
|= OFN_FILEMUSTEXIST
;
7893 file_details
->lpfnHook
= (LPOFNHOOKPROC
) file_dialog_callback
;
7895 file_opened
= GetOpenFileName (file_details
);
7901 dostounix_filename (filename
);
7903 if (file_details
->nFilterIndex
== 2)
7905 /* "Directories" selected - strip dummy file name. */
7906 char * last
= strrchr (filename
, '/');
7910 file
= DECODE_FILE(build_string (filename
));
7912 /* User cancelled the dialog without making a selection. */
7913 else if (!CommDlgExtendedError ())
7915 /* An error occurred, fallback on reading from the mini-buffer. */
7917 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
7918 dir
, mustmatch
, dir
, Qfile_name_history
,
7919 default_filename
, Qnil
);
7921 file
= unbind_to (count
, file
);
7926 /* Make "Cancel" equivalent to C-g. */
7928 Fsignal (Qquit
, Qnil
);
7930 return unbind_to (count
, file
);
7935 /***********************************************************************
7936 w32 specialized functions
7937 ***********************************************************************/
7939 DEFUN ("w32-select-font", Fw32_select_font
, Sw32_select_font
, 0, 2, 0,
7940 doc
: /* Select a font for the named FRAME using the W32 font dialog.
7941 Returns an X-style font string corresponding to the selection.
7943 If FRAME is omitted or nil, it defaults to the selected frame.
7944 If INCLUDE-PROPORTIONAL is non-nil, include proportional fonts
7945 in the font selection dialog. */)
7946 (frame
, include_proportional
)
7947 Lisp_Object frame
, include_proportional
;
7949 FRAME_PTR f
= check_x_frame (frame
);
7957 bzero (&cf
, sizeof (cf
));
7958 bzero (&lf
, sizeof (lf
));
7960 cf
.lStructSize
= sizeof (cf
);
7961 cf
.hwndOwner
= FRAME_W32_WINDOW (f
);
7962 cf
.Flags
= CF_FORCEFONTEXIST
| CF_SCREENFONTS
| CF_NOVERTFONTS
;
7964 /* Unless include_proportional is non-nil, limit the selection to
7965 monospaced fonts. */
7966 if (NILP (include_proportional
))
7967 cf
.Flags
|= CF_FIXEDPITCHONLY
;
7971 /* Initialize as much of the font details as we can from the current
7973 hdc
= GetDC (FRAME_W32_WINDOW (f
));
7974 oldobj
= SelectObject (hdc
, FRAME_FONT (f
)->hfont
);
7975 GetTextFace (hdc
, LF_FACESIZE
, lf
.lfFaceName
);
7976 if (GetTextMetrics (hdc
, &tm
))
7978 lf
.lfHeight
= tm
.tmInternalLeading
- tm
.tmHeight
;
7979 lf
.lfWeight
= tm
.tmWeight
;
7980 lf
.lfItalic
= tm
.tmItalic
;
7981 lf
.lfUnderline
= tm
.tmUnderlined
;
7982 lf
.lfStrikeOut
= tm
.tmStruckOut
;
7983 lf
.lfCharSet
= tm
.tmCharSet
;
7984 cf
.Flags
|= CF_INITTOLOGFONTSTRUCT
;
7986 SelectObject (hdc
, oldobj
);
7987 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
7989 if (!ChooseFont (&cf
) || !w32_to_x_font (&lf
, buf
, 100, NULL
))
7992 return build_string (buf
);
7995 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
,
7996 Sw32_send_sys_command
, 1, 2, 0,
7997 doc
: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND.
7998 Some useful values for COMMAND are #xf030 to maximize frame (#xf020
7999 to minimize), #xf120 to restore frame to original size, and #xf100
8000 to activate the menubar for keyboard access. #xf140 activates the
8001 screen saver if defined.
8003 If optional parameter FRAME is not specified, use selected frame. */)
8005 Lisp_Object command
, frame
;
8007 FRAME_PTR f
= check_x_frame (frame
);
8009 CHECK_NUMBER (command
);
8011 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
8016 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
8017 doc
: /* Get Windows to perform OPERATION on DOCUMENT.
8018 This is a wrapper around the ShellExecute system function, which
8019 invokes the application registered to handle OPERATION for DOCUMENT.
8020 OPERATION is typically \"open\", \"print\" or \"explore\" (but can be
8021 nil for the default action), and DOCUMENT is typically the name of a
8022 document file or URL, but can also be a program executable to run or
8023 a directory to open in the Windows Explorer.
8025 If DOCUMENT is a program executable, PARAMETERS can be a string
8026 containing command line parameters, but otherwise should be nil.
8028 SHOW-FLAG can be used to control whether the invoked application is hidden
8029 or minimized. If SHOW-FLAG is nil, the application is displayed normally,
8030 otherwise it is an integer representing a ShowWindow flag:
8035 6 - start minimized */)
8036 (operation
, document
, parameters
, show_flag
)
8037 Lisp_Object operation
, document
, parameters
, show_flag
;
8039 Lisp_Object current_dir
;
8041 CHECK_STRING (document
);
8043 /* Encode filename and current directory. */
8044 current_dir
= ENCODE_FILE (current_buffer
->directory
);
8045 document
= ENCODE_FILE (document
);
8046 if ((int) ShellExecute (NULL
,
8047 (STRINGP (operation
) ?
8048 SDATA (operation
) : NULL
),
8050 (STRINGP (parameters
) ?
8051 SDATA (parameters
) : NULL
),
8052 SDATA (current_dir
),
8053 (INTEGERP (show_flag
) ?
8054 XINT (show_flag
) : SW_SHOWDEFAULT
))
8057 error ("ShellExecute failed: %s", w32_strerror (0));
8060 /* Lookup virtual keycode from string representing the name of a
8061 non-ascii keystroke into the corresponding virtual key, using
8062 lispy_function_keys. */
8064 lookup_vk_code (char *key
)
8068 for (i
= 0; i
< 256; i
++)
8069 if (lispy_function_keys
[i
] != 0
8070 && strcmp (lispy_function_keys
[i
], key
) == 0)
8076 /* Convert a one-element vector style key sequence to a hot key
8079 w32_parse_hot_key (key
)
8082 /* Copied from Fdefine_key and store_in_keymap. */
8083 register Lisp_Object c
;
8087 struct gcpro gcpro1
;
8091 if (XFASTINT (Flength (key
)) != 1)
8096 c
= Faref (key
, make_number (0));
8098 if (CONSP (c
) && lucid_event_type_list_p (c
))
8099 c
= Fevent_convert_list (c
);
8103 if (! INTEGERP (c
) && ! SYMBOLP (c
))
8104 error ("Key definition is invalid");
8106 /* Work out the base key and the modifiers. */
8109 c
= parse_modifiers (c
);
8110 lisp_modifiers
= XINT (Fcar (Fcdr (c
)));
8114 vk_code
= lookup_vk_code (SDATA (SYMBOL_NAME (c
)));
8116 else if (INTEGERP (c
))
8118 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
8119 /* Many ascii characters are their own virtual key code. */
8120 vk_code
= XINT (c
) & CHARACTERBITS
;
8123 if (vk_code
< 0 || vk_code
> 255)
8126 if ((lisp_modifiers
& meta_modifier
) != 0
8127 && !NILP (Vw32_alt_is_meta
))
8128 lisp_modifiers
|= alt_modifier
;
8130 /* Supply defs missing from mingw32. */
8132 #define MOD_ALT 0x0001
8133 #define MOD_CONTROL 0x0002
8134 #define MOD_SHIFT 0x0004
8135 #define MOD_WIN 0x0008
8138 /* Convert lisp modifiers to Windows hot-key form. */
8139 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
8140 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
8141 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
8142 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
8144 return HOTKEY (vk_code
, w32_modifiers
);
8147 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
,
8148 Sw32_register_hot_key
, 1, 1, 0,
8149 doc
: /* Register KEY as a hot-key combination.
8150 Certain key combinations like Alt-Tab are reserved for system use on
8151 Windows, and therefore are normally intercepted by the system. However,
8152 most of these key combinations can be received by registering them as
8153 hot-keys, overriding their special meaning.
8155 KEY must be a one element key definition in vector form that would be
8156 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta
8157 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper
8158 is always interpreted as the Windows modifier keys.
8160 The return value is the hotkey-id if registered, otherwise nil. */)
8164 key
= w32_parse_hot_key (key
);
8166 if (NILP (Fmemq (key
, w32_grabbed_keys
)))
8168 /* Reuse an empty slot if possible. */
8169 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
8171 /* Safe to add new key to list, even if we have focus. */
8173 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
8175 XSETCAR (item
, key
);
8177 /* Notify input thread about new hot-key definition, so that it
8178 takes effect without needing to switch focus. */
8179 #ifdef USE_LISP_UNION_TYPE
8180 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
8183 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
8191 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
,
8192 Sw32_unregister_hot_key
, 1, 1, 0,
8193 doc
: /* Unregister KEY as a hot-key combination. */)
8199 if (!INTEGERP (key
))
8200 key
= w32_parse_hot_key (key
);
8202 item
= Fmemq (key
, w32_grabbed_keys
);
8206 /* Notify input thread about hot-key definition being removed, so
8207 that it takes effect without needing focus switch. */
8208 #ifdef USE_LISP_UNION_TYPE
8209 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
8210 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
.i
))
8212 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
8213 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
))
8218 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
8225 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
,
8226 Sw32_registered_hot_keys
, 0, 0, 0,
8227 doc
: /* Return list of registered hot-key IDs. */)
8230 return Fcopy_sequence (w32_grabbed_keys
);
8233 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
,
8234 Sw32_reconstruct_hot_key
, 1, 1, 0,
8235 doc
: /* Convert hot-key ID to a lisp key combination.
8236 usage: (w32-reconstruct-hot-key ID) */)
8238 Lisp_Object hotkeyid
;
8240 int vk_code
, w32_modifiers
;
8243 CHECK_NUMBER (hotkeyid
);
8245 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
8246 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
8248 if (lispy_function_keys
[vk_code
])
8249 key
= intern (lispy_function_keys
[vk_code
]);
8251 key
= make_number (vk_code
);
8253 key
= Fcons (key
, Qnil
);
8254 if (w32_modifiers
& MOD_SHIFT
)
8255 key
= Fcons (Qshift
, key
);
8256 if (w32_modifiers
& MOD_CONTROL
)
8257 key
= Fcons (Qctrl
, key
);
8258 if (w32_modifiers
& MOD_ALT
)
8259 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
8260 if (w32_modifiers
& MOD_WIN
)
8261 key
= Fcons (Qhyper
, key
);
8266 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
,
8267 Sw32_toggle_lock_key
, 1, 2, 0,
8268 doc
: /* Toggle the state of the lock key KEY.
8269 KEY can be `capslock', `kp-numlock', or `scroll'.
8270 If the optional parameter NEW-STATE is a number, then the state of KEY
8271 is set to off if the low bit of NEW-STATE is zero, otherwise on. */)
8273 Lisp_Object key
, new_state
;
8277 if (EQ (key
, intern ("capslock")))
8278 vk_code
= VK_CAPITAL
;
8279 else if (EQ (key
, intern ("kp-numlock")))
8280 vk_code
= VK_NUMLOCK
;
8281 else if (EQ (key
, intern ("scroll")))
8282 vk_code
= VK_SCROLL
;
8286 if (!dwWindowsThreadId
)
8287 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
8289 #ifdef USE_LISP_UNION_TYPE
8290 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
8291 (WPARAM
) vk_code
, (LPARAM
) new_state
.i
))
8293 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
8294 (WPARAM
) vk_code
, (LPARAM
) new_state
))
8298 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
8299 return make_number (msg
.wParam
);
8304 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
8305 doc
: /* Return storage information about the file system FILENAME is on.
8306 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
8307 storage of the file system, FREE is the free storage, and AVAIL is the
8308 storage available to a non-superuser. All 3 numbers are in bytes.
8309 If the underlying system call fails, value is nil. */)
8311 Lisp_Object filename
;
8313 Lisp_Object encoded
, value
;
8315 CHECK_STRING (filename
);
8316 filename
= Fexpand_file_name (filename
, Qnil
);
8317 encoded
= ENCODE_FILE (filename
);
8321 /* Determining the required information on Windows turns out, sadly,
8322 to be more involved than one would hope. The original Win32 api
8323 call for this will return bogus information on some systems, but we
8324 must dynamically probe for the replacement api, since that was
8325 added rather late on. */
8327 HMODULE hKernel
= GetModuleHandle ("kernel32");
8328 BOOL (*pfn_GetDiskFreeSpaceEx
)
8329 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
8330 = (void *) GetProcAddress (hKernel
, "GetDiskFreeSpaceEx");
8332 /* On Windows, we may need to specify the root directory of the
8333 volume holding FILENAME. */
8334 char rootname
[MAX_PATH
];
8335 char *name
= SDATA (encoded
);
8337 /* find the root name of the volume if given */
8338 if (isalpha (name
[0]) && name
[1] == ':')
8340 rootname
[0] = name
[0];
8341 rootname
[1] = name
[1];
8345 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
8347 char *str
= rootname
;
8351 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
8361 if (pfn_GetDiskFreeSpaceEx
)
8363 /* Unsigned large integers cannot be cast to double, so
8364 use signed ones instead. */
8365 LARGE_INTEGER availbytes
;
8366 LARGE_INTEGER freebytes
;
8367 LARGE_INTEGER totalbytes
;
8369 if (pfn_GetDiskFreeSpaceEx(rootname
,
8370 (ULARGE_INTEGER
*)&availbytes
,
8371 (ULARGE_INTEGER
*)&totalbytes
,
8372 (ULARGE_INTEGER
*)&freebytes
))
8373 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
8374 make_float ((double) freebytes
.QuadPart
),
8375 make_float ((double) availbytes
.QuadPart
));
8379 DWORD sectors_per_cluster
;
8380 DWORD bytes_per_sector
;
8381 DWORD free_clusters
;
8382 DWORD total_clusters
;
8384 if (GetDiskFreeSpace(rootname
,
8385 §ors_per_cluster
,
8389 value
= list3 (make_float ((double) total_clusters
8390 * sectors_per_cluster
* bytes_per_sector
),
8391 make_float ((double) free_clusters
8392 * sectors_per_cluster
* bytes_per_sector
),
8393 make_float ((double) free_clusters
8394 * sectors_per_cluster
* bytes_per_sector
));
8401 DEFUN ("default-printer-name", Fdefault_printer_name
, Sdefault_printer_name
,
8402 0, 0, 0, doc
: /* Return the name of Windows default printer device. */)
8405 static char pname_buf
[256];
8408 PRINTER_INFO_2
*ppi2
= NULL
;
8409 DWORD dwNeeded
= 0, dwReturned
= 0;
8411 /* Retrieve the default string from Win.ini (the registry).
8412 * String will be in form "printername,drivername,portname".
8413 * This is the most portable way to get the default printer. */
8414 if (GetProfileString ("windows", "device", ",,", pname_buf
, sizeof (pname_buf
)) <= 0)
8416 /* printername precedes first "," character */
8417 strtok (pname_buf
, ",");
8418 /* We want to know more than the printer name */
8419 if (!OpenPrinter (pname_buf
, &hPrn
, NULL
))
8421 GetPrinter (hPrn
, 2, NULL
, 0, &dwNeeded
);
8424 ClosePrinter (hPrn
);
8427 /* Allocate memory for the PRINTER_INFO_2 struct */
8428 ppi2
= (PRINTER_INFO_2
*) xmalloc (dwNeeded
);
8431 ClosePrinter (hPrn
);
8434 /* Call GetPrinter() again with big enouth memory block */
8435 err
= GetPrinter (hPrn
, 2, (LPBYTE
)ppi2
, dwNeeded
, &dwReturned
);
8436 ClosePrinter (hPrn
);
8445 if (ppi2
->Attributes
& PRINTER_ATTRIBUTE_SHARED
&& ppi2
->pServerName
)
8447 /* a remote printer */
8448 if (*ppi2
->pServerName
== '\\')
8449 _snprintf(pname_buf
, sizeof (pname_buf
), "%s\\%s", ppi2
->pServerName
,
8452 _snprintf(pname_buf
, sizeof (pname_buf
), "\\\\%s\\%s", ppi2
->pServerName
,
8454 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
8458 /* a local printer */
8459 strncpy(pname_buf
, ppi2
->pPortName
, sizeof (pname_buf
));
8460 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
8461 /* `pPortName' can include several ports, delimited by ','.
8462 * we only use the first one. */
8463 strtok(pname_buf
, ",");
8468 return build_string (pname_buf
);
8471 /***********************************************************************
8473 ***********************************************************************/
8475 /* Keep this list in the same order as frame_parms in frame.c.
8476 Use 0 for unsupported frame parameters. */
8478 frame_parm_handler w32_frame_parm_handlers
[] =
8482 x_set_background_color
,
8488 x_set_foreground_color
,
8491 x_set_internal_border_width
,
8492 x_set_menu_bar_lines
,
8494 x_explicitly_set_name
,
8495 x_set_scroll_bar_width
,
8498 x_set_vertical_scroll_bars
,
8500 x_set_tool_bar_lines
,
8501 0, /* x_set_scroll_bar_foreground, */
8502 0, /* x_set_scroll_bar_background, */
8507 0, /* x_set_wait_for_wm, */
8514 globals_of_w32fns ();
8515 /* This is zero if not using MS-Windows. */
8517 track_mouse_window
= NULL
;
8519 w32_visible_system_caret_hwnd
= NULL
;
8521 Qnone
= intern ("none");
8523 Qsuppress_icon
= intern ("suppress-icon");
8524 staticpro (&Qsuppress_icon
);
8525 Qundefined_color
= intern ("undefined-color");
8526 staticpro (&Qundefined_color
);
8527 Qcancel_timer
= intern ("cancel-timer");
8528 staticpro (&Qcancel_timer
);
8530 Qhyper
= intern ("hyper");
8531 staticpro (&Qhyper
);
8532 Qsuper
= intern ("super");
8533 staticpro (&Qsuper
);
8534 Qmeta
= intern ("meta");
8536 Qalt
= intern ("alt");
8538 Qctrl
= intern ("ctrl");
8540 Qcontrol
= intern ("control");
8541 staticpro (&Qcontrol
);
8542 Qshift
= intern ("shift");
8543 staticpro (&Qshift
);
8544 /* This is the end of symbol initialization. */
8546 /* Text property `display' should be nonsticky by default. */
8547 Vtext_property_default_nonsticky
8548 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
8551 Fput (Qundefined_color
, Qerror_conditions
,
8552 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
8553 Fput (Qundefined_color
, Qerror_message
,
8554 build_string ("Undefined color"));
8556 staticpro (&w32_grabbed_keys
);
8557 w32_grabbed_keys
= Qnil
;
8559 DEFVAR_LISP ("w32-color-map", &Vw32_color_map
,
8560 doc
: /* An array of color name mappings for Windows. */);
8561 Vw32_color_map
= Qnil
;
8563 DEFVAR_LISP ("w32-pass-alt-to-system", &Vw32_pass_alt_to_system
,
8564 doc
: /* Non-nil if alt key presses are passed on to Windows.
8565 When non-nil, for example, alt pressed and released and then space will
8566 open the System menu. When nil, Emacs silently swallows alt key events. */);
8567 Vw32_pass_alt_to_system
= Qnil
;
8569 DEFVAR_LISP ("w32-alt-is-meta", &Vw32_alt_is_meta
,
8570 doc
: /* Non-nil if the alt key is to be considered the same as the meta key.
8571 When nil, Emacs will translate the alt key to the Alt modifier, and not Meta. */);
8572 Vw32_alt_is_meta
= Qt
;
8574 DEFVAR_INT ("w32-quit-key", &w32_quit_key
,
8575 doc
: /* If non-zero, the virtual key code for an alternative quit key. */);
8578 DEFVAR_LISP ("w32-pass-lwindow-to-system",
8579 &Vw32_pass_lwindow_to_system
,
8580 doc
: /* Non-nil if the left \"Windows\" key is passed on to Windows.
8581 When non-nil, the Start menu is opened by tapping the key. */);
8582 Vw32_pass_lwindow_to_system
= Qt
;
8584 DEFVAR_LISP ("w32-pass-rwindow-to-system",
8585 &Vw32_pass_rwindow_to_system
,
8586 doc
: /* Non-nil if the right \"Windows\" key is passed on to Windows.
8587 When non-nil, the Start menu is opened by tapping the key. */);
8588 Vw32_pass_rwindow_to_system
= Qt
;
8590 DEFVAR_LISP ("w32-phantom-key-code",
8591 &Vw32_phantom_key_code
,
8592 doc
: /* Virtual key code used to generate \"phantom\" key presses.
8593 Value is a number between 0 and 255.
8595 Phantom key presses are generated in order to stop the system from
8596 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or
8597 `w32-pass-rwindow-to-system' is nil. */);
8598 /* Although 255 is technically not a valid key code, it works and
8599 means that this hack won't interfere with any real key code. */
8600 XSETINT (Vw32_phantom_key_code
, 255);
8602 DEFVAR_LISP ("w32-enable-num-lock",
8603 &Vw32_enable_num_lock
,
8604 doc
: /* Non-nil if Num Lock should act normally.
8605 Set to nil to see Num Lock as the key `kp-numlock'. */);
8606 Vw32_enable_num_lock
= Qt
;
8608 DEFVAR_LISP ("w32-enable-caps-lock",
8609 &Vw32_enable_caps_lock
,
8610 doc
: /* Non-nil if Caps Lock should act normally.
8611 Set to nil to see Caps Lock as the key `capslock'. */);
8612 Vw32_enable_caps_lock
= Qt
;
8614 DEFVAR_LISP ("w32-scroll-lock-modifier",
8615 &Vw32_scroll_lock_modifier
,
8616 doc
: /* Modifier to use for the Scroll Lock on state.
8617 The value can be hyper, super, meta, alt, control or shift for the
8618 respective modifier, or nil to see Scroll Lock as the key `scroll'.
8619 Any other value will cause the key to be ignored. */);
8620 Vw32_scroll_lock_modifier
= Qt
;
8622 DEFVAR_LISP ("w32-lwindow-modifier",
8623 &Vw32_lwindow_modifier
,
8624 doc
: /* Modifier to use for the left \"Windows\" key.
8625 The value can be hyper, super, meta, alt, control or shift for the
8626 respective modifier, or nil to appear as the key `lwindow'.
8627 Any other value will cause the key to be ignored. */);
8628 Vw32_lwindow_modifier
= Qnil
;
8630 DEFVAR_LISP ("w32-rwindow-modifier",
8631 &Vw32_rwindow_modifier
,
8632 doc
: /* Modifier to use for the right \"Windows\" key.
8633 The value can be hyper, super, meta, alt, control or shift for the
8634 respective modifier, or nil to appear as the key `rwindow'.
8635 Any other value will cause the key to be ignored. */);
8636 Vw32_rwindow_modifier
= Qnil
;
8638 DEFVAR_LISP ("w32-apps-modifier",
8639 &Vw32_apps_modifier
,
8640 doc
: /* Modifier to use for the \"Apps\" key.
8641 The value can be hyper, super, meta, alt, control or shift for the
8642 respective modifier, or nil to appear as the key `apps'.
8643 Any other value will cause the key to be ignored. */);
8644 Vw32_apps_modifier
= Qnil
;
8646 DEFVAR_BOOL ("w32-enable-synthesized-fonts", &w32_enable_synthesized_fonts
,
8647 doc
: /* Non-nil enables selection of artificially italicized and bold fonts. */);
8648 w32_enable_synthesized_fonts
= 0;
8650 DEFVAR_LISP ("w32-enable-palette", &Vw32_enable_palette
,
8651 doc
: /* Non-nil enables Windows palette management to map colors exactly. */);
8652 Vw32_enable_palette
= Qt
;
8654 DEFVAR_INT ("w32-mouse-button-tolerance",
8655 &w32_mouse_button_tolerance
,
8656 doc
: /* Analogue of double click interval for faking middle mouse events.
8657 The value is the minimum time in milliseconds that must elapse between
8658 left/right button down events before they are considered distinct events.
8659 If both mouse buttons are depressed within this interval, a middle mouse
8660 button down event is generated instead. */);
8661 w32_mouse_button_tolerance
= GetDoubleClickTime () / 2;
8663 DEFVAR_INT ("w32-mouse-move-interval",
8664 &w32_mouse_move_interval
,
8665 doc
: /* Minimum interval between mouse move events.
8666 The value is the minimum time in milliseconds that must elapse between
8667 successive mouse move (or scroll bar drag) events before they are
8668 reported as lisp events. */);
8669 w32_mouse_move_interval
= 0;
8671 DEFVAR_BOOL ("w32-pass-extra-mouse-buttons-to-system",
8672 &w32_pass_extra_mouse_buttons_to_system
,
8673 doc
: /* Non-nil if the fourth and fifth mouse buttons are passed to Windows.
8674 Recent versions of Windows support mice with up to five buttons.
8675 Since most applications don't support these extra buttons, most mouse
8676 drivers will allow you to map them to functions at the system level.
8677 If this variable is non-nil, Emacs will pass them on, allowing the
8678 system to handle them. */);
8679 w32_pass_extra_mouse_buttons_to_system
= 0;
8681 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
8682 doc
: /* The shape of the pointer when over text.
8683 Changing the value does not affect existing frames
8684 unless you set the mouse color. */);
8685 Vx_pointer_shape
= Qnil
;
8687 Vx_nontext_pointer_shape
= Qnil
;
8689 Vx_mode_pointer_shape
= Qnil
;
8691 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
8692 doc
: /* The shape of the pointer when Emacs is busy.
8693 This variable takes effect when you create a new frame
8694 or when you set the mouse color. */);
8695 Vx_hourglass_pointer_shape
= Qnil
;
8697 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
8698 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
8699 display_hourglass_p
= 1;
8701 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
8702 doc
: /* *Seconds to wait before displaying an hourglass pointer.
8703 Value must be an integer or float. */);
8704 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
8706 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
8707 &Vx_sensitive_text_pointer_shape
,
8708 doc
: /* The shape of the pointer when over mouse-sensitive text.
8709 This variable takes effect when you create a new frame
8710 or when you set the mouse color. */);
8711 Vx_sensitive_text_pointer_shape
= Qnil
;
8713 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
8714 &Vx_window_horizontal_drag_shape
,
8715 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
8716 This variable takes effect when you create a new frame
8717 or when you set the mouse color. */);
8718 Vx_window_horizontal_drag_shape
= Qnil
;
8720 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
8721 doc
: /* A string indicating the foreground color of the cursor box. */);
8722 Vx_cursor_fore_pixel
= Qnil
;
8724 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size
,
8725 doc
: /* Maximum size for tooltips.
8726 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
8727 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
8729 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
8730 doc
: /* Non-nil if no window manager is in use.
8731 Emacs doesn't try to figure this out; this is always nil
8732 unless you set it to something else. */);
8733 /* We don't have any way to find this out, so set it to nil
8734 and maybe the user would like to set it to t. */
8735 Vx_no_window_manager
= Qnil
;
8737 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
8738 &Vx_pixel_size_width_font_regexp
,
8739 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
8741 Since Emacs gets width of a font matching with this regexp from
8742 PIXEL_SIZE field of the name, font finding mechanism gets faster for
8743 such a font. This is especially effective for such large fonts as
8744 Chinese, Japanese, and Korean. */);
8745 Vx_pixel_size_width_font_regexp
= Qnil
;
8747 DEFVAR_LISP ("w32-bdf-filename-alist",
8748 &Vw32_bdf_filename_alist
,
8749 doc
: /* List of bdf fonts and their corresponding filenames. */);
8750 Vw32_bdf_filename_alist
= Qnil
;
8752 DEFVAR_BOOL ("w32-strict-fontnames",
8753 &w32_strict_fontnames
,
8754 doc
: /* Non-nil means only use fonts that are exact matches for those requested.
8755 Default is nil, which allows old fontnames that are not XLFD compliant,
8756 and allows third-party CJK display to work by specifying false charset
8757 fields to trick Emacs into translating to Big5, SJIS etc.
8758 Setting this to t will prevent wrong fonts being selected when
8759 fontsets are automatically created. */);
8760 w32_strict_fontnames
= 0;
8762 DEFVAR_BOOL ("w32-strict-painting",
8763 &w32_strict_painting
,
8764 doc
: /* Non-nil means use strict rules for repainting frames.
8765 Set this to nil to get the old behavior for repainting; this should
8766 only be necessary if the default setting causes problems. */);
8767 w32_strict_painting
= 1;
8769 DEFVAR_LISP ("w32-charset-info-alist",
8770 &Vw32_charset_info_alist
,
8771 doc
: /* Alist linking Emacs character sets to Windows fonts and codepages.
8772 Each entry should be of the form:
8774 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE))
8776 where CHARSET_NAME is a string used in font names to identify the charset,
8777 WINDOWS_CHARSET is a symbol that can be one of:
8778 w32-charset-ansi, w32-charset-default, w32-charset-symbol,
8779 w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312,
8780 w32-charset-chinesebig5,
8781 w32-charset-johab, w32-charset-hebrew,
8782 w32-charset-arabic, w32-charset-greek, w32-charset-turkish,
8783 w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope,
8784 w32-charset-russian, w32-charset-mac, w32-charset-baltic,
8785 w32-charset-unicode,
8787 CODEPAGE should be an integer specifying the codepage that should be used
8788 to display the character set, t to do no translation and output as Unicode,
8789 or nil to do no translation and output as 8 bit (or multibyte on far-east
8790 versions of Windows) characters. */);
8791 Vw32_charset_info_alist
= Qnil
;
8793 staticpro (&Qw32_charset_ansi
);
8794 Qw32_charset_ansi
= intern ("w32-charset-ansi");
8795 staticpro (&Qw32_charset_symbol
);
8796 Qw32_charset_default
= intern ("w32-charset-default");
8797 staticpro (&Qw32_charset_default
);
8798 Qw32_charset_symbol
= intern ("w32-charset-symbol");
8799 staticpro (&Qw32_charset_shiftjis
);
8800 Qw32_charset_shiftjis
= intern ("w32-charset-shiftjis");
8801 staticpro (&Qw32_charset_hangeul
);
8802 Qw32_charset_hangeul
= intern ("w32-charset-hangeul");
8803 staticpro (&Qw32_charset_chinesebig5
);
8804 Qw32_charset_chinesebig5
= intern ("w32-charset-chinesebig5");
8805 staticpro (&Qw32_charset_gb2312
);
8806 Qw32_charset_gb2312
= intern ("w32-charset-gb2312");
8807 staticpro (&Qw32_charset_oem
);
8808 Qw32_charset_oem
= intern ("w32-charset-oem");
8810 #ifdef JOHAB_CHARSET
8812 static int w32_extra_charsets_defined
= 1;
8813 DEFVAR_BOOL ("w32-extra-charsets-defined", &w32_extra_charsets_defined
,
8814 doc
: /* Internal variable. */);
8816 staticpro (&Qw32_charset_johab
);
8817 Qw32_charset_johab
= intern ("w32-charset-johab");
8818 staticpro (&Qw32_charset_easteurope
);
8819 Qw32_charset_easteurope
= intern ("w32-charset-easteurope");
8820 staticpro (&Qw32_charset_turkish
);
8821 Qw32_charset_turkish
= intern ("w32-charset-turkish");
8822 staticpro (&Qw32_charset_baltic
);
8823 Qw32_charset_baltic
= intern ("w32-charset-baltic");
8824 staticpro (&Qw32_charset_russian
);
8825 Qw32_charset_russian
= intern ("w32-charset-russian");
8826 staticpro (&Qw32_charset_arabic
);
8827 Qw32_charset_arabic
= intern ("w32-charset-arabic");
8828 staticpro (&Qw32_charset_greek
);
8829 Qw32_charset_greek
= intern ("w32-charset-greek");
8830 staticpro (&Qw32_charset_hebrew
);
8831 Qw32_charset_hebrew
= intern ("w32-charset-hebrew");
8832 staticpro (&Qw32_charset_vietnamese
);
8833 Qw32_charset_vietnamese
= intern ("w32-charset-vietnamese");
8834 staticpro (&Qw32_charset_thai
);
8835 Qw32_charset_thai
= intern ("w32-charset-thai");
8836 staticpro (&Qw32_charset_mac
);
8837 Qw32_charset_mac
= intern ("w32-charset-mac");
8841 #ifdef UNICODE_CHARSET
8843 static int w32_unicode_charset_defined
= 1;
8844 DEFVAR_BOOL ("w32-unicode-charset-defined",
8845 &w32_unicode_charset_defined
,
8846 doc
: /* Internal variable. */);
8848 staticpro (&Qw32_charset_unicode
);
8849 Qw32_charset_unicode
= intern ("w32-charset-unicode");
8852 #if 0 /* TODO: Port to W32 */
8853 defsubr (&Sx_change_window_property
);
8854 defsubr (&Sx_delete_window_property
);
8855 defsubr (&Sx_window_property
);
8857 defsubr (&Sxw_display_color_p
);
8858 defsubr (&Sx_display_grayscale_p
);
8859 defsubr (&Sxw_color_defined_p
);
8860 defsubr (&Sxw_color_values
);
8861 defsubr (&Sx_server_max_request_size
);
8862 defsubr (&Sx_server_vendor
);
8863 defsubr (&Sx_server_version
);
8864 defsubr (&Sx_display_pixel_width
);
8865 defsubr (&Sx_display_pixel_height
);
8866 defsubr (&Sx_display_mm_width
);
8867 defsubr (&Sx_display_mm_height
);
8868 defsubr (&Sx_display_screens
);
8869 defsubr (&Sx_display_planes
);
8870 defsubr (&Sx_display_color_cells
);
8871 defsubr (&Sx_display_visual_class
);
8872 defsubr (&Sx_display_backing_store
);
8873 defsubr (&Sx_display_save_under
);
8874 defsubr (&Sx_create_frame
);
8875 defsubr (&Sx_open_connection
);
8876 defsubr (&Sx_close_connection
);
8877 defsubr (&Sx_display_list
);
8878 defsubr (&Sx_synchronize
);
8880 /* W32 specific functions */
8882 defsubr (&Sw32_focus_frame
);
8883 defsubr (&Sw32_select_font
);
8884 defsubr (&Sw32_define_rgb_color
);
8885 defsubr (&Sw32_default_color_map
);
8886 defsubr (&Sw32_load_color_file
);
8887 defsubr (&Sw32_send_sys_command
);
8888 defsubr (&Sw32_shell_execute
);
8889 defsubr (&Sw32_register_hot_key
);
8890 defsubr (&Sw32_unregister_hot_key
);
8891 defsubr (&Sw32_registered_hot_keys
);
8892 defsubr (&Sw32_reconstruct_hot_key
);
8893 defsubr (&Sw32_toggle_lock_key
);
8894 defsubr (&Sw32_find_bdf_fonts
);
8896 defsubr (&Sfile_system_info
);
8897 defsubr (&Sdefault_printer_name
);
8899 /* Setting callback functions for fontset handler. */
8900 get_font_info_func
= w32_get_font_info
;
8902 #if 0 /* This function pointer doesn't seem to be used anywhere.
8903 And the pointer assigned has the wrong type, anyway. */
8904 list_fonts_func
= w32_list_fonts
;
8907 load_font_func
= w32_load_font
;
8908 find_ccl_program_func
= w32_find_ccl_program
;
8909 query_font_func
= w32_query_font
;
8910 set_frame_fontset_func
= x_set_font
;
8911 check_window_system_func
= check_w32
;
8914 hourglass_atimer
= NULL
;
8915 hourglass_shown_p
= 0;
8916 defsubr (&Sx_show_tip
);
8917 defsubr (&Sx_hide_tip
);
8919 staticpro (&tip_timer
);
8921 staticpro (&tip_frame
);
8923 last_show_tip_args
= Qnil
;
8924 staticpro (&last_show_tip_args
);
8926 defsubr (&Sx_file_dialog
);
8931 globals_of_w32fns is used to initialize those global variables that
8932 must always be initialized on startup even when the global variable
8933 initialized is non zero (see the function main in emacs.c).
8934 globals_of_w32fns is called from syms_of_w32fns when the global
8935 variable initialized is 0 and directly from main when initialized
8938 void globals_of_w32fns ()
8940 HMODULE user32_lib
= GetModuleHandle ("user32.dll");
8942 TrackMouseEvent not available in all versions of Windows, so must load
8943 it dynamically. Do it once, here, instead of every time it is used.
8945 track_mouse_event_fn
= (TrackMouseEvent_Proc
)
8946 GetProcAddress (user32_lib
, "TrackMouseEvent");
8947 /* ditto for GetClipboardSequenceNumber. */
8948 clipboard_sequence_fn
= (ClipboardSequence_Proc
)
8949 GetProcAddress (user32_lib
, "GetClipboardSequenceNumber");
8951 DEFVAR_INT ("w32-ansi-code-page",
8952 &w32_ansi_code_page
,
8953 doc
: /* The ANSI code page used by the system. */);
8954 w32_ansi_code_page
= GetACP ();
8959 void w32_abort (void) NO_RETURN
;
8965 button
= MessageBox (NULL
,
8966 "A fatal error has occurred!\n\n"
8967 "Would you like to attach a debugger?\n\n"
8968 "Select YES to debug, NO to abort Emacs"
8970 "\n\n(type \"gdb -p <emacs-PID>\" and\n"
8971 "\"continue\" inside GDB before clicking YES.)"
8973 , "Emacs Abort Dialog",
8974 MB_ICONEXCLAMATION
| MB_TASKMODAL
8975 | MB_SETFOREGROUND
| MB_YESNO
);
8980 exit (2); /* tell the compiler we will never return */
8988 /* For convenience when debugging. */
8992 return GetLastError ();
8995 /* arch-tag: 707589ab-b9be-4638-8cdd-74629cc9b446
8996 (do not change this comment) */