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 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 */
36 #include "intervals.h"
37 #include "dispextern.h"
39 #include "blockinput.h"
41 #include "character.h"
47 #include "termhooks.h"
50 #include "bitmaps/gray.xbm"
58 #define FILE_NAME_TEXT_FIELD edt1
60 void syms_of_w32fns ();
61 void globals_of_w32fns ();
63 extern void free_frame_menubar ();
64 extern double atof ();
65 extern int w32_console_toggle_lock_key
P_ ((int, Lisp_Object
));
66 extern void w32_menu_display_help
P_ ((HWND
, HMENU
, UINT
, UINT
));
67 extern void w32_free_menu_strings
P_ ((HWND
));
68 extern XCharStruct
*w32_per_char_metric
P_ ((XFontStruct
*, wchar_t *, int));
72 extern char *lispy_function_keys
[];
74 /* The gray bitmap `bitmaps/gray'. This is done because w32term.c uses
75 it, and including `bitmaps/gray' more than once is a problem when
76 config.h defines `static' as an empty replacement string. */
78 int gray_bitmap_width
= gray_width
;
79 int gray_bitmap_height
= gray_height
;
80 unsigned char *gray_bitmap_bits
= gray_bits
;
82 /* The colormap for converting color names to RGB values */
83 Lisp_Object Vw32_color_map
;
85 /* Non nil if alt key presses are passed on to Windows. */
86 Lisp_Object Vw32_pass_alt_to_system
;
88 /* Non nil if alt key is translated to meta_modifier, nil if it is translated
90 Lisp_Object Vw32_alt_is_meta
;
92 /* If non-zero, the windows virtual key code for an alternative quit key. */
95 /* Non nil if left window key events are passed on to Windows (this only
96 affects whether "tapping" the key opens the Start menu). */
97 Lisp_Object Vw32_pass_lwindow_to_system
;
99 /* Non nil if right window key events are passed on to Windows (this
100 only affects whether "tapping" the key opens the Start menu). */
101 Lisp_Object Vw32_pass_rwindow_to_system
;
103 /* Virtual key code used to generate "phantom" key presses in order
104 to stop system from acting on Windows key events. */
105 Lisp_Object Vw32_phantom_key_code
;
107 /* Modifier associated with the left "Windows" key, or nil to act as a
109 Lisp_Object Vw32_lwindow_modifier
;
111 /* Modifier associated with the right "Windows" key, or nil to act as a
113 Lisp_Object Vw32_rwindow_modifier
;
115 /* Modifier associated with the "Apps" key, or nil to act as a normal
117 Lisp_Object Vw32_apps_modifier
;
119 /* Value is nil if Num Lock acts as a function key. */
120 Lisp_Object Vw32_enable_num_lock
;
122 /* Value is nil if Caps Lock acts as a function key. */
123 Lisp_Object Vw32_enable_caps_lock
;
125 /* Modifier associated with Scroll Lock, or nil to act as a normal key. */
126 Lisp_Object Vw32_scroll_lock_modifier
;
128 /* Switch to control whether we inhibit requests for synthesized bold
129 and italic versions of fonts. */
130 int w32_enable_synthesized_fonts
;
132 /* Enable palette management. */
133 Lisp_Object Vw32_enable_palette
;
135 /* Control how close left/right button down events must be to
136 be converted to a middle button down event. */
137 int w32_mouse_button_tolerance
;
139 /* Minimum interval between mouse movement (and scroll bar drag)
140 events that are passed on to the event loop. */
141 int w32_mouse_move_interval
;
143 /* Flag to indicate if XBUTTON events should be passed on to Windows. */
144 int w32_pass_extra_mouse_buttons_to_system
;
146 /* Non nil if no window manager is in use. */
147 Lisp_Object Vx_no_window_manager
;
149 /* Non-zero means we're allowed to display a hourglass pointer. */
151 int display_hourglass_p
;
153 /* The background and shape of the mouse pointer, and shape when not
154 over text or in the modeline. */
156 Lisp_Object Vx_pointer_shape
, Vx_nontext_pointer_shape
, Vx_mode_pointer_shape
;
157 Lisp_Object Vx_hourglass_pointer_shape
, Vx_window_horizontal_drag_shape
;
159 /* The shape when over mouse-sensitive text. */
161 Lisp_Object Vx_sensitive_text_pointer_shape
;
164 #define IDC_HAND MAKEINTRESOURCE(32649)
167 /* Color of chars displayed in cursor box. */
169 Lisp_Object Vx_cursor_fore_pixel
;
171 /* Nonzero if using Windows. */
173 static int w32_in_use
;
175 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
177 Lisp_Object Vx_pixel_size_width_font_regexp
;
179 /* Alist of bdf fonts and the files that define them. */
180 Lisp_Object Vw32_bdf_filename_alist
;
182 /* A flag to control whether fonts are matched strictly or not. */
183 int w32_strict_fontnames
;
185 /* A flag to control whether we should only repaint if GetUpdateRect
186 indicates there is an update region. */
187 int w32_strict_painting
;
189 /* Associative list linking character set strings to Windows codepages. */
190 Lisp_Object Vw32_charset_info_alist
;
192 /* VIETNAMESE_CHARSET is not defined in some versions of MSVC. */
193 #ifndef VIETNAMESE_CHARSET
194 #define VIETNAMESE_CHARSET 163
198 Lisp_Object Qsuppress_icon
;
199 Lisp_Object Qundefined_color
;
200 Lisp_Object Qcancel_timer
;
206 Lisp_Object Qcontrol
;
209 Lisp_Object Qw32_charset_ansi
;
210 Lisp_Object Qw32_charset_default
;
211 Lisp_Object Qw32_charset_symbol
;
212 Lisp_Object Qw32_charset_shiftjis
;
213 Lisp_Object Qw32_charset_hangeul
;
214 Lisp_Object Qw32_charset_gb2312
;
215 Lisp_Object Qw32_charset_chinesebig5
;
216 Lisp_Object Qw32_charset_oem
;
218 #ifndef JOHAB_CHARSET
219 #define JOHAB_CHARSET 130
222 Lisp_Object Qw32_charset_easteurope
;
223 Lisp_Object Qw32_charset_turkish
;
224 Lisp_Object Qw32_charset_baltic
;
225 Lisp_Object Qw32_charset_russian
;
226 Lisp_Object Qw32_charset_arabic
;
227 Lisp_Object Qw32_charset_greek
;
228 Lisp_Object Qw32_charset_hebrew
;
229 Lisp_Object Qw32_charset_vietnamese
;
230 Lisp_Object Qw32_charset_thai
;
231 Lisp_Object Qw32_charset_johab
;
232 Lisp_Object Qw32_charset_mac
;
235 #ifdef UNICODE_CHARSET
236 Lisp_Object Qw32_charset_unicode
;
239 /* The ANSI codepage. */
240 int w32_ansi_code_page
;
242 /* Prefix for system colors. */
243 #define SYSTEM_COLOR_PREFIX "System"
244 #define SYSTEM_COLOR_PREFIX_LEN (sizeof (SYSTEM_COLOR_PREFIX) - 1)
246 /* State variables for emulating a three button mouse. */
251 static int button_state
= 0;
252 static W32Msg saved_mouse_button_msg
;
253 static unsigned mouse_button_timer
= 0; /* non-zero when timer is active */
254 static W32Msg saved_mouse_move_msg
;
255 static unsigned mouse_move_timer
= 0;
257 /* Window that is tracking the mouse. */
258 static HWND track_mouse_window
;
260 typedef BOOL (WINAPI
* TrackMouseEvent_Proc
)
261 (IN OUT LPTRACKMOUSEEVENT lpEventTrack
);
263 TrackMouseEvent_Proc track_mouse_event_fn
= NULL
;
264 ClipboardSequence_Proc clipboard_sequence_fn
= NULL
;
265 extern AppendMenuW_Proc unicode_append_menu
;
267 /* W95 mousewheel handler */
268 unsigned int msh_mousewheel
= 0;
271 #define MOUSE_BUTTON_ID 1
272 #define MOUSE_MOVE_ID 2
273 #define MENU_FREE_ID 3
274 /* The delay (milliseconds) before a menu is freed after WM_EXITMENULOOP
276 #define MENU_FREE_DELAY 1000
277 static unsigned menu_free_timer
= 0;
279 /* The below are defined in frame.c. */
281 extern Lisp_Object Vwindow_system_version
;
284 int image_cache_refcount
, dpyinfo_refcount
;
288 /* From w32term.c. */
289 extern int w32_num_mouse_buttons
;
290 extern Lisp_Object Vw32_recognize_altgr
;
292 extern HWND w32_system_caret_hwnd
;
294 extern int w32_system_caret_height
;
295 extern int w32_system_caret_x
;
296 extern int w32_system_caret_y
;
297 extern int w32_use_visible_system_caret
;
299 static HWND w32_visible_system_caret_hwnd
;
302 /* Error if we are not connected to MS-Windows. */
307 error ("MS-Windows not in use or not initialized");
310 /* Nonzero if we can use mouse menus.
311 You should not call this unless HAVE_MENUS is defined. */
319 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
320 and checking validity for W32. */
323 check_x_frame (frame
)
329 frame
= selected_frame
;
330 CHECK_LIVE_FRAME (frame
);
332 if (! FRAME_W32_P (f
))
333 error ("Non-W32 frame used");
337 /* Let the user specify a display with a frame.
338 nil stands for the selected frame--or, if that is not a w32 frame,
339 the first display on the list. */
341 struct w32_display_info
*
342 check_x_display_info (frame
)
347 struct frame
*sf
= XFRAME (selected_frame
);
349 if (FRAME_W32_P (sf
) && FRAME_LIVE_P (sf
))
350 return FRAME_W32_DISPLAY_INFO (sf
);
352 return &one_w32_display_info
;
354 else if (STRINGP (frame
))
355 return x_display_info_for_name (frame
);
360 CHECK_LIVE_FRAME (frame
);
362 if (! FRAME_W32_P (f
))
363 error ("Non-W32 frame used");
364 return FRAME_W32_DISPLAY_INFO (f
);
368 /* Return the Emacs frame-object corresponding to an w32 window.
369 It could be the frame's main window or an icon window. */
371 /* This function can be called during GC, so use GC_xxx type test macros. */
374 x_window_to_frame (dpyinfo
, wdesc
)
375 struct w32_display_info
*dpyinfo
;
378 Lisp_Object tail
, frame
;
381 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
384 if (!GC_FRAMEP (frame
))
387 if (!FRAME_W32_P (f
) || FRAME_W32_DISPLAY_INFO (f
) != dpyinfo
)
389 if (f
->output_data
.w32
->hourglass_window
== wdesc
)
392 if (FRAME_W32_WINDOW (f
) == wdesc
)
399 static Lisp_Object unwind_create_frame
P_ ((Lisp_Object
));
400 static Lisp_Object unwind_create_tip_frame
P_ ((Lisp_Object
));
401 static void my_create_window
P_ ((struct frame
*));
402 static void my_create_tip_window
P_ ((struct frame
*));
404 /* TODO: Native Input Method support; see x_create_im. */
405 void x_set_foreground_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
406 void x_set_background_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
407 void x_set_mouse_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
408 void x_set_cursor_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
409 void x_set_border_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
410 void x_set_cursor_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
411 void x_set_icon_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
412 void x_set_icon_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
413 void x_explicitly_set_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
414 void x_set_menu_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
415 void x_set_title
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
416 void x_set_tool_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
417 static void x_edge_detection
P_ ((struct frame
*, struct image
*, Lisp_Object
,
423 /* Store the screen positions of frame F into XPTR and YPTR.
424 These are the positions of the containing window manager window,
425 not Emacs's own window. */
428 x_real_positions (f
, xptr
, yptr
)
435 GetClientRect(FRAME_W32_WINDOW(f
), &rect
);
436 AdjustWindowRect(&rect
, f
->output_data
.w32
->dwStyle
, FRAME_EXTERNAL_MENU_BAR(f
));
441 ClientToScreen (FRAME_W32_WINDOW(f
), &pt
);
443 /* Remember x_pixels_diff and y_pixels_diff. */
444 f
->x_pixels_diff
= pt
.x
- rect
.left
;
445 f
->y_pixels_diff
= pt
.y
- rect
.top
;
453 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
,
454 Sw32_define_rgb_color
, 4, 4, 0,
455 doc
: /* Convert RGB numbers to a windows color reference and associate with NAME.
456 This adds or updates a named color to w32-color-map, making it
457 available for use. The original entry's RGB ref is returned, or nil
458 if the entry is new. */)
459 (red
, green
, blue
, name
)
460 Lisp_Object red
, green
, blue
, name
;
463 Lisp_Object oldrgb
= Qnil
;
467 CHECK_NUMBER (green
);
471 XSETINT (rgb
, RGB(XUINT (red
), XUINT (green
), XUINT (blue
)));
475 /* replace existing entry in w32-color-map or add new entry. */
476 entry
= Fassoc (name
, Vw32_color_map
);
479 entry
= Fcons (name
, rgb
);
480 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
484 oldrgb
= Fcdr (entry
);
485 Fsetcdr (entry
, rgb
);
493 DEFUN ("w32-load-color-file", Fw32_load_color_file
,
494 Sw32_load_color_file
, 1, 1, 0,
495 doc
: /* Create an alist of color entries from an external file.
496 Assign this value to w32-color-map to replace the existing color map.
498 The file should define one named RGB color per line like so:
500 where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
502 Lisp_Object filename
;
505 Lisp_Object cmap
= Qnil
;
508 CHECK_STRING (filename
);
509 abspath
= Fexpand_file_name (filename
, Qnil
);
511 fp
= fopen (SDATA (filename
), "rt");
515 int red
, green
, blue
;
520 while (fgets (buf
, sizeof (buf
), fp
) != NULL
) {
521 if (sscanf (buf
, "%u %u %u %n", &red
, &green
, &blue
, &num
) == 3)
523 char *name
= buf
+ num
;
524 num
= strlen (name
) - 1;
525 if (name
[num
] == '\n')
527 cmap
= Fcons (Fcons (build_string (name
),
528 make_number (RGB (red
, green
, blue
))),
540 /* The default colors for the w32 color map */
541 typedef struct colormap_t
547 colormap_t w32_color_map
[] =
549 {"snow" , PALETTERGB (255,250,250)},
550 {"ghost white" , PALETTERGB (248,248,255)},
551 {"GhostWhite" , PALETTERGB (248,248,255)},
552 {"white smoke" , PALETTERGB (245,245,245)},
553 {"WhiteSmoke" , PALETTERGB (245,245,245)},
554 {"gainsboro" , PALETTERGB (220,220,220)},
555 {"floral white" , PALETTERGB (255,250,240)},
556 {"FloralWhite" , PALETTERGB (255,250,240)},
557 {"old lace" , PALETTERGB (253,245,230)},
558 {"OldLace" , PALETTERGB (253,245,230)},
559 {"linen" , PALETTERGB (250,240,230)},
560 {"antique white" , PALETTERGB (250,235,215)},
561 {"AntiqueWhite" , PALETTERGB (250,235,215)},
562 {"papaya whip" , PALETTERGB (255,239,213)},
563 {"PapayaWhip" , PALETTERGB (255,239,213)},
564 {"blanched almond" , PALETTERGB (255,235,205)},
565 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
566 {"bisque" , PALETTERGB (255,228,196)},
567 {"peach puff" , PALETTERGB (255,218,185)},
568 {"PeachPuff" , PALETTERGB (255,218,185)},
569 {"navajo white" , PALETTERGB (255,222,173)},
570 {"NavajoWhite" , PALETTERGB (255,222,173)},
571 {"moccasin" , PALETTERGB (255,228,181)},
572 {"cornsilk" , PALETTERGB (255,248,220)},
573 {"ivory" , PALETTERGB (255,255,240)},
574 {"lemon chiffon" , PALETTERGB (255,250,205)},
575 {"LemonChiffon" , PALETTERGB (255,250,205)},
576 {"seashell" , PALETTERGB (255,245,238)},
577 {"honeydew" , PALETTERGB (240,255,240)},
578 {"mint cream" , PALETTERGB (245,255,250)},
579 {"MintCream" , PALETTERGB (245,255,250)},
580 {"azure" , PALETTERGB (240,255,255)},
581 {"alice blue" , PALETTERGB (240,248,255)},
582 {"AliceBlue" , PALETTERGB (240,248,255)},
583 {"lavender" , PALETTERGB (230,230,250)},
584 {"lavender blush" , PALETTERGB (255,240,245)},
585 {"LavenderBlush" , PALETTERGB (255,240,245)},
586 {"misty rose" , PALETTERGB (255,228,225)},
587 {"MistyRose" , PALETTERGB (255,228,225)},
588 {"white" , PALETTERGB (255,255,255)},
589 {"black" , PALETTERGB ( 0, 0, 0)},
590 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
591 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
592 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
593 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
594 {"dim gray" , PALETTERGB (105,105,105)},
595 {"DimGray" , PALETTERGB (105,105,105)},
596 {"dim grey" , PALETTERGB (105,105,105)},
597 {"DimGrey" , PALETTERGB (105,105,105)},
598 {"slate gray" , PALETTERGB (112,128,144)},
599 {"SlateGray" , PALETTERGB (112,128,144)},
600 {"slate grey" , PALETTERGB (112,128,144)},
601 {"SlateGrey" , PALETTERGB (112,128,144)},
602 {"light slate gray" , PALETTERGB (119,136,153)},
603 {"LightSlateGray" , PALETTERGB (119,136,153)},
604 {"light slate grey" , PALETTERGB (119,136,153)},
605 {"LightSlateGrey" , PALETTERGB (119,136,153)},
606 {"gray" , PALETTERGB (190,190,190)},
607 {"grey" , PALETTERGB (190,190,190)},
608 {"light grey" , PALETTERGB (211,211,211)},
609 {"LightGrey" , PALETTERGB (211,211,211)},
610 {"light gray" , PALETTERGB (211,211,211)},
611 {"LightGray" , PALETTERGB (211,211,211)},
612 {"midnight blue" , PALETTERGB ( 25, 25,112)},
613 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
614 {"navy" , PALETTERGB ( 0, 0,128)},
615 {"navy blue" , PALETTERGB ( 0, 0,128)},
616 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
617 {"cornflower blue" , PALETTERGB (100,149,237)},
618 {"CornflowerBlue" , PALETTERGB (100,149,237)},
619 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
620 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
621 {"slate blue" , PALETTERGB (106, 90,205)},
622 {"SlateBlue" , PALETTERGB (106, 90,205)},
623 {"medium slate blue" , PALETTERGB (123,104,238)},
624 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
625 {"light slate blue" , PALETTERGB (132,112,255)},
626 {"LightSlateBlue" , PALETTERGB (132,112,255)},
627 {"medium blue" , PALETTERGB ( 0, 0,205)},
628 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
629 {"royal blue" , PALETTERGB ( 65,105,225)},
630 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
631 {"blue" , PALETTERGB ( 0, 0,255)},
632 {"dodger blue" , PALETTERGB ( 30,144,255)},
633 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
634 {"deep sky blue" , PALETTERGB ( 0,191,255)},
635 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
636 {"sky blue" , PALETTERGB (135,206,235)},
637 {"SkyBlue" , PALETTERGB (135,206,235)},
638 {"light sky blue" , PALETTERGB (135,206,250)},
639 {"LightSkyBlue" , PALETTERGB (135,206,250)},
640 {"steel blue" , PALETTERGB ( 70,130,180)},
641 {"SteelBlue" , PALETTERGB ( 70,130,180)},
642 {"light steel blue" , PALETTERGB (176,196,222)},
643 {"LightSteelBlue" , PALETTERGB (176,196,222)},
644 {"light blue" , PALETTERGB (173,216,230)},
645 {"LightBlue" , PALETTERGB (173,216,230)},
646 {"powder blue" , PALETTERGB (176,224,230)},
647 {"PowderBlue" , PALETTERGB (176,224,230)},
648 {"pale turquoise" , PALETTERGB (175,238,238)},
649 {"PaleTurquoise" , PALETTERGB (175,238,238)},
650 {"dark turquoise" , PALETTERGB ( 0,206,209)},
651 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
652 {"medium turquoise" , PALETTERGB ( 72,209,204)},
653 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
654 {"turquoise" , PALETTERGB ( 64,224,208)},
655 {"cyan" , PALETTERGB ( 0,255,255)},
656 {"light cyan" , PALETTERGB (224,255,255)},
657 {"LightCyan" , PALETTERGB (224,255,255)},
658 {"cadet blue" , PALETTERGB ( 95,158,160)},
659 {"CadetBlue" , PALETTERGB ( 95,158,160)},
660 {"medium aquamarine" , PALETTERGB (102,205,170)},
661 {"MediumAquamarine" , PALETTERGB (102,205,170)},
662 {"aquamarine" , PALETTERGB (127,255,212)},
663 {"dark green" , PALETTERGB ( 0,100, 0)},
664 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
665 {"dark olive green" , PALETTERGB ( 85,107, 47)},
666 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
667 {"dark sea green" , PALETTERGB (143,188,143)},
668 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
669 {"sea green" , PALETTERGB ( 46,139, 87)},
670 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
671 {"medium sea green" , PALETTERGB ( 60,179,113)},
672 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
673 {"light sea green" , PALETTERGB ( 32,178,170)},
674 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
675 {"pale green" , PALETTERGB (152,251,152)},
676 {"PaleGreen" , PALETTERGB (152,251,152)},
677 {"spring green" , PALETTERGB ( 0,255,127)},
678 {"SpringGreen" , PALETTERGB ( 0,255,127)},
679 {"lawn green" , PALETTERGB (124,252, 0)},
680 {"LawnGreen" , PALETTERGB (124,252, 0)},
681 {"green" , PALETTERGB ( 0,255, 0)},
682 {"chartreuse" , PALETTERGB (127,255, 0)},
683 {"medium spring green" , PALETTERGB ( 0,250,154)},
684 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
685 {"green yellow" , PALETTERGB (173,255, 47)},
686 {"GreenYellow" , PALETTERGB (173,255, 47)},
687 {"lime green" , PALETTERGB ( 50,205, 50)},
688 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
689 {"yellow green" , PALETTERGB (154,205, 50)},
690 {"YellowGreen" , PALETTERGB (154,205, 50)},
691 {"forest green" , PALETTERGB ( 34,139, 34)},
692 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
693 {"olive drab" , PALETTERGB (107,142, 35)},
694 {"OliveDrab" , PALETTERGB (107,142, 35)},
695 {"dark khaki" , PALETTERGB (189,183,107)},
696 {"DarkKhaki" , PALETTERGB (189,183,107)},
697 {"khaki" , PALETTERGB (240,230,140)},
698 {"pale goldenrod" , PALETTERGB (238,232,170)},
699 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
700 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
701 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
702 {"light yellow" , PALETTERGB (255,255,224)},
703 {"LightYellow" , PALETTERGB (255,255,224)},
704 {"yellow" , PALETTERGB (255,255, 0)},
705 {"gold" , PALETTERGB (255,215, 0)},
706 {"light goldenrod" , PALETTERGB (238,221,130)},
707 {"LightGoldenrod" , PALETTERGB (238,221,130)},
708 {"goldenrod" , PALETTERGB (218,165, 32)},
709 {"dark goldenrod" , PALETTERGB (184,134, 11)},
710 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
711 {"rosy brown" , PALETTERGB (188,143,143)},
712 {"RosyBrown" , PALETTERGB (188,143,143)},
713 {"indian red" , PALETTERGB (205, 92, 92)},
714 {"IndianRed" , PALETTERGB (205, 92, 92)},
715 {"saddle brown" , PALETTERGB (139, 69, 19)},
716 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
717 {"sienna" , PALETTERGB (160, 82, 45)},
718 {"peru" , PALETTERGB (205,133, 63)},
719 {"burlywood" , PALETTERGB (222,184,135)},
720 {"beige" , PALETTERGB (245,245,220)},
721 {"wheat" , PALETTERGB (245,222,179)},
722 {"sandy brown" , PALETTERGB (244,164, 96)},
723 {"SandyBrown" , PALETTERGB (244,164, 96)},
724 {"tan" , PALETTERGB (210,180,140)},
725 {"chocolate" , PALETTERGB (210,105, 30)},
726 {"firebrick" , PALETTERGB (178,34, 34)},
727 {"brown" , PALETTERGB (165,42, 42)},
728 {"dark salmon" , PALETTERGB (233,150,122)},
729 {"DarkSalmon" , PALETTERGB (233,150,122)},
730 {"salmon" , PALETTERGB (250,128,114)},
731 {"light salmon" , PALETTERGB (255,160,122)},
732 {"LightSalmon" , PALETTERGB (255,160,122)},
733 {"orange" , PALETTERGB (255,165, 0)},
734 {"dark orange" , PALETTERGB (255,140, 0)},
735 {"DarkOrange" , PALETTERGB (255,140, 0)},
736 {"coral" , PALETTERGB (255,127, 80)},
737 {"light coral" , PALETTERGB (240,128,128)},
738 {"LightCoral" , PALETTERGB (240,128,128)},
739 {"tomato" , PALETTERGB (255, 99, 71)},
740 {"orange red" , PALETTERGB (255, 69, 0)},
741 {"OrangeRed" , PALETTERGB (255, 69, 0)},
742 {"red" , PALETTERGB (255, 0, 0)},
743 {"hot pink" , PALETTERGB (255,105,180)},
744 {"HotPink" , PALETTERGB (255,105,180)},
745 {"deep pink" , PALETTERGB (255, 20,147)},
746 {"DeepPink" , PALETTERGB (255, 20,147)},
747 {"pink" , PALETTERGB (255,192,203)},
748 {"light pink" , PALETTERGB (255,182,193)},
749 {"LightPink" , PALETTERGB (255,182,193)},
750 {"pale violet red" , PALETTERGB (219,112,147)},
751 {"PaleVioletRed" , PALETTERGB (219,112,147)},
752 {"maroon" , PALETTERGB (176, 48, 96)},
753 {"medium violet red" , PALETTERGB (199, 21,133)},
754 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
755 {"violet red" , PALETTERGB (208, 32,144)},
756 {"VioletRed" , PALETTERGB (208, 32,144)},
757 {"magenta" , PALETTERGB (255, 0,255)},
758 {"violet" , PALETTERGB (238,130,238)},
759 {"plum" , PALETTERGB (221,160,221)},
760 {"orchid" , PALETTERGB (218,112,214)},
761 {"medium orchid" , PALETTERGB (186, 85,211)},
762 {"MediumOrchid" , PALETTERGB (186, 85,211)},
763 {"dark orchid" , PALETTERGB (153, 50,204)},
764 {"DarkOrchid" , PALETTERGB (153, 50,204)},
765 {"dark violet" , PALETTERGB (148, 0,211)},
766 {"DarkViolet" , PALETTERGB (148, 0,211)},
767 {"blue violet" , PALETTERGB (138, 43,226)},
768 {"BlueViolet" , PALETTERGB (138, 43,226)},
769 {"purple" , PALETTERGB (160, 32,240)},
770 {"medium purple" , PALETTERGB (147,112,219)},
771 {"MediumPurple" , PALETTERGB (147,112,219)},
772 {"thistle" , PALETTERGB (216,191,216)},
773 {"gray0" , PALETTERGB ( 0, 0, 0)},
774 {"grey0" , PALETTERGB ( 0, 0, 0)},
775 {"dark grey" , PALETTERGB (169,169,169)},
776 {"DarkGrey" , PALETTERGB (169,169,169)},
777 {"dark gray" , PALETTERGB (169,169,169)},
778 {"DarkGray" , PALETTERGB (169,169,169)},
779 {"dark blue" , PALETTERGB ( 0, 0,139)},
780 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
781 {"dark cyan" , PALETTERGB ( 0,139,139)},
782 {"DarkCyan" , PALETTERGB ( 0,139,139)},
783 {"dark magenta" , PALETTERGB (139, 0,139)},
784 {"DarkMagenta" , PALETTERGB (139, 0,139)},
785 {"dark red" , PALETTERGB (139, 0, 0)},
786 {"DarkRed" , PALETTERGB (139, 0, 0)},
787 {"light green" , PALETTERGB (144,238,144)},
788 {"LightGreen" , PALETTERGB (144,238,144)},
791 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
792 0, 0, 0, doc
: /* Return the default color map. */)
796 colormap_t
*pc
= w32_color_map
;
803 for (i
= 0; i
< sizeof (w32_color_map
) / sizeof (w32_color_map
[0]);
805 cmap
= Fcons (Fcons (build_string (pc
->name
),
806 make_number (pc
->colorref
)),
824 color
= Frassq (rgb
, Vw32_color_map
);
829 return (Fcar (color
));
835 w32_color_map_lookup (colorname
)
838 Lisp_Object tail
, ret
= Qnil
;
842 for (tail
= Vw32_color_map
; !NILP (tail
); tail
= Fcdr (tail
))
844 register Lisp_Object elt
, tem
;
847 if (!CONSP (elt
)) continue;
851 if (lstrcmpi (SDATA (tem
), colorname
) == 0)
868 add_system_logical_colors_to_map (system_colors
)
869 Lisp_Object
*system_colors
;
873 /* Other registry operations are done with input blocked. */
876 /* Look for "Control Panel/Colors" under User and Machine registry
878 if (RegOpenKeyEx (HKEY_CURRENT_USER
, "Control Panel\\Colors", 0,
879 KEY_READ
, &colors_key
) == ERROR_SUCCESS
880 || RegOpenKeyEx (HKEY_LOCAL_MACHINE
, "Control Panel\\Colors", 0,
881 KEY_READ
, &colors_key
) == ERROR_SUCCESS
)
884 char color_buffer
[64];
885 char full_name_buffer
[MAX_PATH
+ SYSTEM_COLOR_PREFIX_LEN
];
887 DWORD name_size
, color_size
;
888 char *name_buffer
= full_name_buffer
+ SYSTEM_COLOR_PREFIX_LEN
;
890 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
891 color_size
= sizeof (color_buffer
);
893 strcpy (full_name_buffer
, SYSTEM_COLOR_PREFIX
);
895 while (RegEnumValueA (colors_key
, index
, name_buffer
, &name_size
,
896 NULL
, NULL
, color_buffer
, &color_size
)
900 if (sscanf (color_buffer
, " %u %u %u", &r
, &g
, &b
) == 3)
901 *system_colors
= Fcons (Fcons (build_string (full_name_buffer
),
902 make_number (RGB (r
, g
, b
))),
905 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
906 color_size
= sizeof (color_buffer
);
909 RegCloseKey (colors_key
);
917 x_to_w32_color (colorname
)
920 register Lisp_Object ret
= Qnil
;
924 if (colorname
[0] == '#')
926 /* Could be an old-style RGB Device specification. */
929 color
= colorname
+ 1;
931 size
= strlen(color
);
932 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
940 for (i
= 0; i
< 3; i
++)
946 /* The check for 'x' in the following conditional takes into
947 account the fact that strtol allows a "0x" in front of
948 our numbers, and we don't. */
949 if (!isxdigit(color
[0]) || color
[1] == 'x')
953 value
= strtoul(color
, &end
, 16);
955 if (errno
== ERANGE
|| end
- color
!= size
)
960 value
= value
* 0x10;
971 colorval
|= (value
<< pos
);
976 XSETINT (ret
, colorval
);
983 else if (strnicmp(colorname
, "rgb:", 4) == 0)
991 color
= colorname
+ 4;
992 for (i
= 0; i
< 3; i
++)
997 /* The check for 'x' in the following conditional takes into
998 account the fact that strtol allows a "0x" in front of
999 our numbers, and we don't. */
1000 if (!isxdigit(color
[0]) || color
[1] == 'x')
1002 value
= strtoul(color
, &end
, 16);
1003 if (errno
== ERANGE
)
1005 switch (end
- color
)
1008 value
= value
* 0x10 + value
;
1021 if (value
== ULONG_MAX
)
1023 colorval
|= (value
<< pos
);
1030 XSETINT (ret
, colorval
);
1038 else if (strnicmp(colorname
, "rgbi:", 5) == 0)
1040 /* This is an RGB Intensity specification. */
1047 color
= colorname
+ 5;
1048 for (i
= 0; i
< 3; i
++)
1054 value
= strtod(color
, &end
);
1055 if (errno
== ERANGE
)
1057 if (value
< 0.0 || value
> 1.0)
1059 val
= (UINT
)(0x100 * value
);
1060 /* We used 0x100 instead of 0xFF to give a continuous
1061 range between 0.0 and 1.0 inclusive. The next statement
1062 fixes the 1.0 case. */
1065 colorval
|= (val
<< pos
);
1072 XSETINT (ret
, colorval
);
1080 /* I am not going to attempt to handle any of the CIE color schemes
1081 or TekHVC, since I don't know the algorithms for conversion to
1084 /* If we fail to lookup the color name in w32_color_map, then check the
1085 colorname to see if it can be crudely approximated: If the X color
1086 ends in a number (e.g., "darkseagreen2"), strip the number and
1087 return the result of looking up the base color name. */
1088 ret
= w32_color_map_lookup (colorname
);
1091 int len
= strlen (colorname
);
1093 if (isdigit (colorname
[len
- 1]))
1095 char *ptr
, *approx
= alloca (len
+ 1);
1097 strcpy (approx
, colorname
);
1098 ptr
= &approx
[len
- 1];
1099 while (ptr
> approx
&& isdigit (*ptr
))
1102 ret
= w32_color_map_lookup (approx
);
1111 w32_regenerate_palette (FRAME_PTR f
)
1113 struct w32_palette_entry
* list
;
1114 LOGPALETTE
* log_palette
;
1115 HPALETTE new_palette
;
1118 /* don't bother trying to create palette if not supported */
1119 if (! FRAME_W32_DISPLAY_INFO (f
)->has_palette
)
1122 log_palette
= (LOGPALETTE
*)
1123 alloca (sizeof (LOGPALETTE
) +
1124 FRAME_W32_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
1125 log_palette
->palVersion
= 0x300;
1126 log_palette
->palNumEntries
= FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1128 list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1130 i
< FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1131 i
++, list
= list
->next
)
1132 log_palette
->palPalEntry
[i
] = list
->entry
;
1134 new_palette
= CreatePalette (log_palette
);
1138 if (FRAME_W32_DISPLAY_INFO (f
)->palette
)
1139 DeleteObject (FRAME_W32_DISPLAY_INFO (f
)->palette
);
1140 FRAME_W32_DISPLAY_INFO (f
)->palette
= new_palette
;
1142 /* Realize display palette and garbage all frames. */
1143 release_frame_dc (f
, get_frame_dc (f
));
1148 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
1149 #define SET_W32_COLOR(pe, color) \
1152 pe.peRed = GetRValue (color); \
1153 pe.peGreen = GetGValue (color); \
1154 pe.peBlue = GetBValue (color); \
1159 /* Keep these around in case we ever want to track color usage. */
1161 w32_map_color (FRAME_PTR f
, COLORREF color
)
1163 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1165 if (NILP (Vw32_enable_palette
))
1168 /* check if color is already mapped */
1171 if (W32_COLOR (list
->entry
) == color
)
1179 /* not already mapped, so add to list and recreate Windows palette */
1180 list
= (struct w32_palette_entry
*)
1181 xmalloc (sizeof (struct w32_palette_entry
));
1182 SET_W32_COLOR (list
->entry
, color
);
1184 list
->next
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1185 FRAME_W32_DISPLAY_INFO (f
)->color_list
= list
;
1186 FRAME_W32_DISPLAY_INFO (f
)->num_colors
++;
1188 /* set flag that palette must be regenerated */
1189 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1193 w32_unmap_color (FRAME_PTR f
, COLORREF color
)
1195 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1196 struct w32_palette_entry
**prev
= &FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1198 if (NILP (Vw32_enable_palette
))
1201 /* check if color is already mapped */
1204 if (W32_COLOR (list
->entry
) == color
)
1206 if (--list
->refcount
== 0)
1210 FRAME_W32_DISPLAY_INFO (f
)->num_colors
--;
1220 /* set flag that palette must be regenerated */
1221 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1226 /* Gamma-correct COLOR on frame F. */
1229 gamma_correct (f
, color
)
1235 *color
= PALETTERGB (
1236 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1237 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1238 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1243 /* Decide if color named COLOR is valid for the display associated with
1244 the selected frame; if so, return the rgb values in COLOR_DEF.
1245 If ALLOC is nonzero, allocate a new colormap cell. */
1248 w32_defined_color (f
, color
, color_def
, alloc
)
1254 register Lisp_Object tem
;
1255 COLORREF w32_color_ref
;
1257 tem
= x_to_w32_color (color
);
1263 /* Apply gamma correction. */
1264 w32_color_ref
= XUINT (tem
);
1265 gamma_correct (f
, &w32_color_ref
);
1266 XSETINT (tem
, w32_color_ref
);
1269 /* Map this color to the palette if it is enabled. */
1270 if (!NILP (Vw32_enable_palette
))
1272 struct w32_palette_entry
* entry
=
1273 one_w32_display_info
.color_list
;
1274 struct w32_palette_entry
** prev
=
1275 &one_w32_display_info
.color_list
;
1277 /* check if color is already mapped */
1280 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1282 prev
= &entry
->next
;
1283 entry
= entry
->next
;
1286 if (entry
== NULL
&& alloc
)
1288 /* not already mapped, so add to list */
1289 entry
= (struct w32_palette_entry
*)
1290 xmalloc (sizeof (struct w32_palette_entry
));
1291 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1294 one_w32_display_info
.num_colors
++;
1296 /* set flag that palette must be regenerated */
1297 one_w32_display_info
.regen_palette
= TRUE
;
1300 /* Ensure COLORREF value is snapped to nearest color in (default)
1301 palette by simulating the PALETTERGB macro. This works whether
1302 or not the display device has a palette. */
1303 w32_color_ref
= XUINT (tem
) | 0x2000000;
1305 color_def
->pixel
= w32_color_ref
;
1306 color_def
->red
= GetRValue (w32_color_ref
) * 256;
1307 color_def
->green
= GetGValue (w32_color_ref
) * 256;
1308 color_def
->blue
= GetBValue (w32_color_ref
) * 256;
1318 /* Given a string ARG naming a color, compute a pixel value from it
1319 suitable for screen F.
1320 If F is not a color screen, return DEF (default) regardless of what
1324 x_decode_color (f
, arg
, def
)
1333 if (strcmp (SDATA (arg
), "black") == 0)
1334 return BLACK_PIX_DEFAULT (f
);
1335 else if (strcmp (SDATA (arg
), "white") == 0)
1336 return WHITE_PIX_DEFAULT (f
);
1338 if ((FRAME_W32_DISPLAY_INFO (f
)->n_planes
* FRAME_W32_DISPLAY_INFO (f
)->n_cbits
) == 1)
1341 /* w32_defined_color is responsible for coping with failures
1342 by looking for a near-miss. */
1343 if (w32_defined_color (f
, SDATA (arg
), &cdef
, 1))
1346 /* defined_color failed; return an ultimate default. */
1352 /* Functions called only from `x_set_frame_param'
1353 to set individual parameters.
1355 If FRAME_W32_WINDOW (f) is 0,
1356 the frame is being created and its window does not exist yet.
1357 In that case, just record the parameter's new value
1358 in the standard place; do not attempt to change the window. */
1361 x_set_foreground_color (f
, arg
, oldval
)
1363 Lisp_Object arg
, oldval
;
1365 struct w32_output
*x
= f
->output_data
.w32
;
1366 PIX_TYPE fg
, old_fg
;
1368 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1369 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
1370 FRAME_FOREGROUND_PIXEL (f
) = fg
;
1372 if (FRAME_W32_WINDOW (f
) != 0)
1374 if (x
->cursor_pixel
== old_fg
)
1375 x
->cursor_pixel
= fg
;
1377 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
1378 if (FRAME_VISIBLE_P (f
))
1384 x_set_background_color (f
, arg
, oldval
)
1386 Lisp_Object arg
, oldval
;
1388 FRAME_BACKGROUND_PIXEL (f
)
1389 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
1391 if (FRAME_W32_WINDOW (f
) != 0)
1393 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
1394 FRAME_BACKGROUND_PIXEL (f
));
1396 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
1398 if (FRAME_VISIBLE_P (f
))
1404 x_set_mouse_color (f
, arg
, oldval
)
1406 Lisp_Object arg
, oldval
;
1408 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
1412 if (!EQ (Qnil
, arg
))
1413 f
->output_data
.w32
->mouse_pixel
1414 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1415 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
1417 /* Don't let pointers be invisible. */
1418 if (mask_color
== f
->output_data
.w32
->mouse_pixel
1419 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
1420 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
1422 #if 0 /* TODO : cursor changes */
1425 /* It's not okay to crash if the user selects a screwy cursor. */
1426 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
1428 if (!EQ (Qnil
, Vx_pointer_shape
))
1430 CHECK_NUMBER (Vx_pointer_shape
);
1431 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
1434 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1435 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
1437 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
1439 CHECK_NUMBER (Vx_nontext_pointer_shape
);
1440 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1441 XINT (Vx_nontext_pointer_shape
));
1444 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
1445 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1447 if (!EQ (Qnil
, Vx_hourglass_pointer_shape
))
1449 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
1450 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1451 XINT (Vx_hourglass_pointer_shape
));
1454 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
1455 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
1457 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1458 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
1460 CHECK_NUMBER (Vx_mode_pointer_shape
);
1461 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1462 XINT (Vx_mode_pointer_shape
));
1465 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1466 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
1468 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
1470 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
1472 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1473 XINT (Vx_sensitive_text_pointer_shape
));
1476 hand_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
1478 if (!NILP (Vx_window_horizontal_drag_shape
))
1480 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
1481 horizontal_drag_cursor
1482 = XCreateFontCursor (FRAME_X_DISPLAY (f
),
1483 XINT (Vx_window_horizontal_drag_shape
));
1486 horizontal_drag_cursor
1487 = XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_sb_h_double_arrow
);
1489 /* Check and report errors with the above calls. */
1490 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
1491 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
1494 XColor fore_color
, back_color
;
1496 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
1497 back_color
.pixel
= mask_color
;
1498 XQueryColor (FRAME_W32_DISPLAY (f
),
1499 DefaultColormap (FRAME_W32_DISPLAY (f
),
1500 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1502 XQueryColor (FRAME_W32_DISPLAY (f
),
1503 DefaultColormap (FRAME_W32_DISPLAY (f
),
1504 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1506 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
1507 &fore_color
, &back_color
);
1508 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
1509 &fore_color
, &back_color
);
1510 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
1511 &fore_color
, &back_color
);
1512 XRecolorCursor (FRAME_W32_DISPLAY (f
), hand_cursor
,
1513 &fore_color
, &back_color
);
1514 XRecolorCursor (FRAME_W32_DISPLAY (f
), hourglass_cursor
,
1515 &fore_color
, &back_color
);
1518 if (FRAME_W32_WINDOW (f
) != 0)
1519 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
1521 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
1522 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
1523 f
->output_data
.w32
->text_cursor
= cursor
;
1525 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
1526 && f
->output_data
.w32
->nontext_cursor
!= 0)
1527 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
1528 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
1530 if (hourglass_cursor
!= f
->output_data
.w32
->hourglass_cursor
1531 && f
->output_data
.w32
->hourglass_cursor
!= 0)
1532 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hourglass_cursor
);
1533 f
->output_data
.w32
->hourglass_cursor
= hourglass_cursor
;
1535 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
1536 && f
->output_data
.w32
->modeline_cursor
!= 0)
1537 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
1538 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
1540 if (hand_cursor
!= f
->output_data
.w32
->hand_cursor
1541 && f
->output_data
.w32
->hand_cursor
!= 0)
1542 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hand_cursor
);
1543 f
->output_data
.w32
->hand_cursor
= hand_cursor
;
1545 XFlush (FRAME_W32_DISPLAY (f
));
1548 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1552 /* Defined in w32term.c. */
1554 x_set_cursor_color (f
, arg
, oldval
)
1556 Lisp_Object arg
, oldval
;
1558 unsigned long fore_pixel
, pixel
;
1560 if (!NILP (Vx_cursor_fore_pixel
))
1561 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1562 WHITE_PIX_DEFAULT (f
));
1564 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1566 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1568 /* Make sure that the cursor color differs from the background color. */
1569 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
1571 pixel
= f
->output_data
.w32
->mouse_pixel
;
1572 if (pixel
== fore_pixel
)
1573 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1576 f
->output_data
.w32
->cursor_foreground_pixel
= fore_pixel
;
1577 f
->output_data
.w32
->cursor_pixel
= pixel
;
1579 if (FRAME_W32_WINDOW (f
) != 0)
1582 /* Update frame's cursor_gc. */
1583 f
->output_data
.w32
->cursor_gc
->foreground
= fore_pixel
;
1584 f
->output_data
.w32
->cursor_gc
->background
= pixel
;
1588 if (FRAME_VISIBLE_P (f
))
1590 x_update_cursor (f
, 0);
1591 x_update_cursor (f
, 1);
1595 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1598 /* Set the border-color of frame F to pixel value PIX.
1599 Note that this does not fully take effect if done before
1603 x_set_border_pixel (f
, pix
)
1608 f
->output_data
.w32
->border_pixel
= pix
;
1610 if (FRAME_W32_WINDOW (f
) != 0 && f
->border_width
> 0)
1612 if (FRAME_VISIBLE_P (f
))
1617 /* Set the border-color of frame F to value described by ARG.
1618 ARG can be a string naming a color.
1619 The border-color is used for the border that is drawn by the server.
1620 Note that this does not fully take effect if done before
1621 F has a window; it must be redone when the window is created. */
1624 x_set_border_color (f
, arg
, oldval
)
1626 Lisp_Object arg
, oldval
;
1631 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1632 x_set_border_pixel (f
, pix
);
1633 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1638 x_set_cursor_type (f
, arg
, oldval
)
1640 Lisp_Object arg
, oldval
;
1642 set_frame_cursor_types (f
, arg
);
1644 /* Make sure the cursor gets redrawn. */
1645 cursor_type_changed
= 1;
1649 x_set_icon_type (f
, arg
, oldval
)
1651 Lisp_Object arg
, oldval
;
1655 if (NILP (arg
) && NILP (oldval
))
1658 if (STRINGP (arg
) && STRINGP (oldval
)
1659 && EQ (Fstring_equal (oldval
, arg
), Qt
))
1662 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
1667 result
= x_bitmap_icon (f
, arg
);
1671 error ("No icon window available");
1678 x_set_icon_name (f
, arg
, oldval
)
1680 Lisp_Object arg
, oldval
;
1684 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1687 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
1693 if (f
->output_data
.w32
->icon_bitmap
!= 0)
1698 result
= x_text_icon (f
,
1699 (char *) SDATA ((!NILP (f
->icon_name
)
1708 error ("No icon window available");
1711 /* If the window was unmapped (and its icon was mapped),
1712 the new icon is not mapped, so map the window in its stead. */
1713 if (FRAME_VISIBLE_P (f
))
1715 #ifdef USE_X_TOOLKIT
1716 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
1718 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
1721 XFlush (FRAME_W32_DISPLAY (f
));
1728 x_set_menu_bar_lines (f
, value
, oldval
)
1730 Lisp_Object value
, oldval
;
1733 int olines
= FRAME_MENU_BAR_LINES (f
);
1735 /* Right now, menu bars don't work properly in minibuf-only frames;
1736 most of the commands try to apply themselves to the minibuffer
1737 frame itself, and get an error because you can't switch buffers
1738 in or split the minibuffer window. */
1739 if (FRAME_MINIBUF_ONLY_P (f
))
1742 if (INTEGERP (value
))
1743 nlines
= XINT (value
);
1747 FRAME_MENU_BAR_LINES (f
) = 0;
1749 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1752 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1753 free_frame_menubar (f
);
1754 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1756 /* Adjust the frame size so that the client (text) dimensions
1757 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
1759 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
1760 do_pending_window_change (0);
1766 /* Set the number of lines used for the tool bar of frame F to VALUE.
1767 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1768 is the old number of tool bar lines. This function changes the
1769 height of all windows on frame F to match the new tool bar height.
1770 The frame's height doesn't change. */
1773 x_set_tool_bar_lines (f
, value
, oldval
)
1775 Lisp_Object value
, oldval
;
1777 int delta
, nlines
, root_height
;
1778 Lisp_Object root_window
;
1780 /* Treat tool bars like menu bars. */
1781 if (FRAME_MINIBUF_ONLY_P (f
))
1784 /* Use VALUE only if an integer >= 0. */
1785 if (INTEGERP (value
) && XINT (value
) >= 0)
1786 nlines
= XFASTINT (value
);
1790 /* Make sure we redisplay all windows in this frame. */
1791 ++windows_or_buffers_changed
;
1793 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
1795 /* Don't resize the tool-bar to more than we have room for. */
1796 root_window
= FRAME_ROOT_WINDOW (f
);
1797 root_height
= WINDOW_TOTAL_LINES (XWINDOW (root_window
));
1798 if (root_height
- delta
< 1)
1800 delta
= root_height
- 1;
1801 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
1804 FRAME_TOOL_BAR_LINES (f
) = nlines
;
1805 change_window_heights (root_window
, delta
);
1808 /* We also have to make sure that the internal border at the top of
1809 the frame, below the menu bar or tool bar, is redrawn when the
1810 tool bar disappears. This is so because the internal border is
1811 below the tool bar if one is displayed, but is below the menu bar
1812 if there isn't a tool bar. The tool bar draws into the area
1813 below the menu bar. */
1814 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
1818 clear_current_matrices (f
);
1819 updating_frame
= NULL
;
1822 /* If the tool bar gets smaller, the internal border below it
1823 has to be cleared. It was formerly part of the display
1824 of the larger tool bar, and updating windows won't clear it. */
1827 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1828 int width
= FRAME_PIXEL_WIDTH (f
);
1829 int y
= nlines
* FRAME_LINE_HEIGHT (f
);
1833 HDC hdc
= get_frame_dc (f
);
1834 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
1835 release_frame_dc (f
, hdc
);
1839 if (WINDOWP (f
->tool_bar_window
))
1840 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1845 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1848 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1849 name; if NAME is a string, set F's name to NAME and set
1850 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1852 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1853 suggesting a new name, which lisp code should override; if
1854 F->explicit_name is set, ignore the new name; otherwise, set it. */
1857 x_set_name (f
, name
, explicit)
1862 /* Make sure that requests from lisp code override requests from
1863 Emacs redisplay code. */
1866 /* If we're switching from explicit to implicit, we had better
1867 update the mode lines and thereby update the title. */
1868 if (f
->explicit_name
&& NILP (name
))
1869 update_mode_lines
= 1;
1871 f
->explicit_name
= ! NILP (name
);
1873 else if (f
->explicit_name
)
1876 /* If NAME is nil, set the name to the w32_id_name. */
1879 /* Check for no change needed in this very common case
1880 before we do any consing. */
1881 if (!strcmp (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
,
1884 name
= build_string (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
);
1887 CHECK_STRING (name
);
1889 /* Don't change the name if it's already NAME. */
1890 if (! NILP (Fstring_equal (name
, f
->name
)))
1895 /* For setting the frame title, the title parameter should override
1896 the name parameter. */
1897 if (! NILP (f
->title
))
1900 if (FRAME_W32_WINDOW (f
))
1902 if (STRING_MULTIBYTE (name
))
1903 name
= ENCODE_SYSTEM (name
);
1906 SetWindowText(FRAME_W32_WINDOW (f
), SDATA (name
));
1911 /* This function should be called when the user's lisp code has
1912 specified a name for the frame; the name will override any set by the
1915 x_explicitly_set_name (f
, arg
, oldval
)
1917 Lisp_Object arg
, oldval
;
1919 x_set_name (f
, arg
, 1);
1922 /* This function should be called by Emacs redisplay code to set the
1923 name; names set this way will never override names set by the user's
1926 x_implicitly_set_name (f
, arg
, oldval
)
1928 Lisp_Object arg
, oldval
;
1930 x_set_name (f
, arg
, 0);
1933 /* Change the title of frame F to NAME.
1934 If NAME is nil, use the frame name as the title.
1936 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1937 name; if NAME is a string, set F's name to NAME and set
1938 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1940 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1941 suggesting a new name, which lisp code should override; if
1942 F->explicit_name is set, ignore the new name; otherwise, set it. */
1945 x_set_title (f
, name
, old_name
)
1947 Lisp_Object name
, old_name
;
1949 /* Don't change the title if it's already NAME. */
1950 if (EQ (name
, f
->title
))
1953 update_mode_lines
= 1;
1960 if (FRAME_W32_WINDOW (f
))
1962 if (STRING_MULTIBYTE (name
))
1963 name
= ENCODE_SYSTEM (name
);
1966 SetWindowText(FRAME_W32_WINDOW (f
), SDATA (name
));
1972 void x_set_scroll_bar_default_width (f
)
1975 int wid
= FRAME_COLUMN_WIDTH (f
);
1977 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
1978 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) +
1983 /* Subroutines of creating a frame. */
1986 /* Return the value of parameter PARAM.
1988 First search ALIST, then Vdefault_frame_alist, then the X defaults
1989 database, using ATTRIBUTE as the attribute name and CLASS as its class.
1991 Convert the resource to the type specified by desired_type.
1993 If no default is specified, return Qunbound. If you call
1994 w32_get_arg, make sure you deal with Qunbound in a reasonable way,
1995 and don't let it get stored in any Lisp-visible variables! */
1998 w32_get_arg (alist
, param
, attribute
, class, type
)
1999 Lisp_Object alist
, param
;
2002 enum resource_types type
;
2004 return x_get_arg (check_x_display_info (Qnil
),
2005 alist
, param
, attribute
, class, type
);
2010 w32_load_cursor (LPCTSTR name
)
2012 /* Try first to load cursor from application resource. */
2013 Cursor cursor
= LoadImage ((HINSTANCE
) GetModuleHandle(NULL
),
2014 name
, IMAGE_CURSOR
, 0, 0,
2015 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
2018 /* Then try to load a shared predefined cursor. */
2019 cursor
= LoadImage (NULL
, name
, IMAGE_CURSOR
, 0, 0,
2020 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
2025 extern LRESULT CALLBACK
w32_wnd_proc ();
2028 w32_init_class (hinst
)
2033 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
2034 wc
.lpfnWndProc
= (WNDPROC
) w32_wnd_proc
;
2036 wc
.cbWndExtra
= WND_EXTRA_BYTES
;
2037 wc
.hInstance
= hinst
;
2038 wc
.hIcon
= LoadIcon (hinst
, EMACS_CLASS
);
2039 wc
.hCursor
= w32_load_cursor (IDC_ARROW
);
2040 wc
.hbrBackground
= NULL
; /* GetStockObject (WHITE_BRUSH); */
2041 wc
.lpszMenuName
= NULL
;
2042 wc
.lpszClassName
= EMACS_CLASS
;
2044 return (RegisterClass (&wc
));
2048 w32_createscrollbar (f
, bar
)
2050 struct scroll_bar
* bar
;
2052 return (CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
2053 /* Position and size of scroll bar. */
2054 XINT(bar
->left
) + VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
2056 XINT(bar
->width
) - VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
2058 FRAME_W32_WINDOW (f
),
2065 w32_createwindow (f
)
2071 rect
.left
= rect
.top
= 0;
2072 rect
.right
= FRAME_PIXEL_WIDTH (f
);
2073 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
2075 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
2076 FRAME_EXTERNAL_MENU_BAR (f
));
2078 /* Do first time app init */
2082 w32_init_class (hinst
);
2085 FRAME_W32_WINDOW (f
) = hwnd
2086 = CreateWindow (EMACS_CLASS
,
2088 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
2091 rect
.right
- rect
.left
,
2092 rect
.bottom
- rect
.top
,
2100 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
2101 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
2102 SetWindowLong (hwnd
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
2103 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->scroll_bar_actual_width
);
2104 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
2106 /* Enable drag-n-drop. */
2107 DragAcceptFiles (hwnd
, TRUE
);
2109 /* Do this to discard the default setting specified by our parent. */
2110 ShowWindow (hwnd
, SW_HIDE
);
2115 my_post_msg (wmsg
, hwnd
, msg
, wParam
, lParam
)
2122 wmsg
->msg
.hwnd
= hwnd
;
2123 wmsg
->msg
.message
= msg
;
2124 wmsg
->msg
.wParam
= wParam
;
2125 wmsg
->msg
.lParam
= lParam
;
2126 wmsg
->msg
.time
= GetMessageTime ();
2131 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
2132 between left and right keys as advertised. We test for this
2133 support dynamically, and set a flag when the support is absent. If
2134 absent, we keep track of the left and right control and alt keys
2135 ourselves. This is particularly necessary on keyboards that rely
2136 upon the AltGr key, which is represented as having the left control
2137 and right alt keys pressed. For these keyboards, we need to know
2138 when the left alt key has been pressed in addition to the AltGr key
2139 so that we can properly support M-AltGr-key sequences (such as M-@
2140 on Swedish keyboards). */
2142 #define EMACS_LCONTROL 0
2143 #define EMACS_RCONTROL 1
2144 #define EMACS_LMENU 2
2145 #define EMACS_RMENU 3
2147 static int modifiers
[4];
2148 static int modifiers_recorded
;
2149 static int modifier_key_support_tested
;
2152 test_modifier_support (unsigned int wparam
)
2156 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
2158 if (wparam
== VK_CONTROL
)
2168 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
2169 modifiers_recorded
= 1;
2171 modifiers_recorded
= 0;
2172 modifier_key_support_tested
= 1;
2176 record_keydown (unsigned int wparam
, unsigned int lparam
)
2180 if (!modifier_key_support_tested
)
2181 test_modifier_support (wparam
);
2183 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2186 if (wparam
== VK_CONTROL
)
2187 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2189 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2195 record_keyup (unsigned int wparam
, unsigned int lparam
)
2199 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2202 if (wparam
== VK_CONTROL
)
2203 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2205 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2210 /* Emacs can lose focus while a modifier key has been pressed. When
2211 it regains focus, be conservative and clear all modifiers since
2212 we cannot reconstruct the left and right modifier state. */
2218 if (GetFocus () == NULL
)
2219 /* Emacs doesn't have keyboard focus. Do nothing. */
2222 ctrl
= GetAsyncKeyState (VK_CONTROL
);
2223 alt
= GetAsyncKeyState (VK_MENU
);
2225 if (!(ctrl
& 0x08000))
2226 /* Clear any recorded control modifier state. */
2227 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2229 if (!(alt
& 0x08000))
2230 /* Clear any recorded alt modifier state. */
2231 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2233 /* Update the state of all modifier keys, because modifiers used in
2234 hot-key combinations can get stuck on if Emacs loses focus as a
2235 result of a hot-key being pressed. */
2239 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
2241 GetKeyboardState (keystate
);
2242 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
2243 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
2244 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
2245 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
2246 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
2247 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
2248 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
2249 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
2250 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
2251 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
2252 SetKeyboardState (keystate
);
2256 /* Synchronize modifier state with what is reported with the current
2257 keystroke. Even if we cannot distinguish between left and right
2258 modifier keys, we know that, if no modifiers are set, then neither
2259 the left or right modifier should be set. */
2263 if (!modifiers_recorded
)
2266 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
2267 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2269 if (!(GetKeyState (VK_MENU
) & 0x8000))
2270 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2274 modifier_set (int vkey
)
2276 if (vkey
== VK_CAPITAL
|| vkey
== VK_SCROLL
)
2277 return (GetKeyState (vkey
) & 0x1);
2278 if (!modifiers_recorded
)
2279 return (GetKeyState (vkey
) & 0x8000);
2284 return modifiers
[EMACS_LCONTROL
];
2286 return modifiers
[EMACS_RCONTROL
];
2288 return modifiers
[EMACS_LMENU
];
2290 return modifiers
[EMACS_RMENU
];
2292 return (GetKeyState (vkey
) & 0x8000);
2295 /* Convert between the modifier bits W32 uses and the modifier bits
2299 w32_key_to_modifier (int key
)
2301 Lisp_Object key_mapping
;
2306 key_mapping
= Vw32_lwindow_modifier
;
2309 key_mapping
= Vw32_rwindow_modifier
;
2312 key_mapping
= Vw32_apps_modifier
;
2315 key_mapping
= Vw32_scroll_lock_modifier
;
2321 /* NB. This code runs in the input thread, asychronously to the lisp
2322 thread, so we must be careful to ensure access to lisp data is
2323 thread-safe. The following code is safe because the modifier
2324 variable values are updated atomically from lisp and symbols are
2325 not relocated by GC. Also, we don't have to worry about seeing GC
2327 if (EQ (key_mapping
, Qhyper
))
2328 return hyper_modifier
;
2329 if (EQ (key_mapping
, Qsuper
))
2330 return super_modifier
;
2331 if (EQ (key_mapping
, Qmeta
))
2332 return meta_modifier
;
2333 if (EQ (key_mapping
, Qalt
))
2334 return alt_modifier
;
2335 if (EQ (key_mapping
, Qctrl
))
2336 return ctrl_modifier
;
2337 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
2338 return ctrl_modifier
;
2339 if (EQ (key_mapping
, Qshift
))
2340 return shift_modifier
;
2342 /* Don't generate any modifier if not explicitly requested. */
2347 w32_get_modifiers ()
2349 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
2350 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
2351 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
2352 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
2353 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
2354 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
2355 (modifier_set (VK_MENU
) ?
2356 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
2359 /* We map the VK_* modifiers into console modifier constants
2360 so that we can use the same routines to handle both console
2361 and window input. */
2364 construct_console_modifiers ()
2369 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
2370 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
2371 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
2372 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
2373 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
2374 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
2375 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
2376 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
2377 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
2378 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
2379 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
2385 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
2389 /* Convert to emacs modifiers. */
2390 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
2396 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
2398 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
2401 if (virt_key
== VK_RETURN
)
2402 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
2404 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
2405 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
2407 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
2408 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
2410 if (virt_key
== VK_CLEAR
)
2411 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
2416 /* List of special key combinations which w32 would normally capture,
2417 but emacs should grab instead. Not directly visible to lisp, to
2418 simplify synchronization. Each item is an integer encoding a virtual
2419 key code and modifier combination to capture. */
2420 Lisp_Object w32_grabbed_keys
;
2422 #define HOTKEY(vk,mods) make_number (((vk) & 255) | ((mods) << 8))
2423 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
2424 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
2425 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
2427 #define RAW_HOTKEY_ID(k) ((k) & 0xbfff)
2428 #define RAW_HOTKEY_VK_CODE(k) ((k) & 255)
2429 #define RAW_HOTKEY_MODIFIERS(k) ((k) >> 8)
2431 /* Register hot-keys for reserved key combinations when Emacs has
2432 keyboard focus, since this is the only way Emacs can receive key
2433 combinations like Alt-Tab which are used by the system. */
2436 register_hot_keys (hwnd
)
2439 Lisp_Object keylist
;
2441 /* Use GC_CONSP, since we are called asynchronously. */
2442 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
2444 Lisp_Object key
= XCAR (keylist
);
2446 /* Deleted entries get set to nil. */
2447 if (!INTEGERP (key
))
2450 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
2451 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
2456 unregister_hot_keys (hwnd
)
2459 Lisp_Object keylist
;
2461 /* Use GC_CONSP, since we are called asynchronously. */
2462 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
2464 Lisp_Object key
= XCAR (keylist
);
2466 if (!INTEGERP (key
))
2469 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
2473 /* Main message dispatch loop. */
2476 w32_msg_pump (deferred_msg
* msg_buf
)
2482 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
2484 while (GetMessage (&msg
, NULL
, 0, 0))
2486 if (msg
.hwnd
== NULL
)
2488 switch (msg
.message
)
2491 /* Produced by complete_deferred_msg; just ignore. */
2493 case WM_EMACS_CREATEWINDOW
:
2494 w32_createwindow ((struct frame
*) msg
.wParam
);
2495 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2498 case WM_EMACS_SETLOCALE
:
2499 SetThreadLocale (msg
.wParam
);
2500 /* Reply is not expected. */
2502 case WM_EMACS_SETKEYBOARDLAYOUT
:
2503 result
= (int) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
2504 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2508 case WM_EMACS_REGISTER_HOT_KEY
:
2509 focus_window
= GetFocus ();
2510 if (focus_window
!= NULL
)
2511 RegisterHotKey (focus_window
,
2512 RAW_HOTKEY_ID (msg
.wParam
),
2513 RAW_HOTKEY_MODIFIERS (msg
.wParam
),
2514 RAW_HOTKEY_VK_CODE (msg
.wParam
));
2515 /* Reply is not expected. */
2517 case WM_EMACS_UNREGISTER_HOT_KEY
:
2518 focus_window
= GetFocus ();
2519 if (focus_window
!= NULL
)
2520 UnregisterHotKey (focus_window
, RAW_HOTKEY_ID (msg
.wParam
));
2521 /* Mark item as erased. NB: this code must be
2522 thread-safe. The next line is okay because the cons
2523 cell is never made into garbage and is not relocated by
2525 XSETCAR ((Lisp_Object
) ((EMACS_INT
) msg
.lParam
), Qnil
);
2526 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2529 case WM_EMACS_TOGGLE_LOCK_KEY
:
2531 int vk_code
= (int) msg
.wParam
;
2532 int cur_state
= (GetKeyState (vk_code
) & 1);
2533 Lisp_Object new_state
= (Lisp_Object
) ((EMACS_INT
) msg
.lParam
);
2535 /* NB: This code must be thread-safe. It is safe to
2536 call NILP because symbols are not relocated by GC,
2537 and pointer here is not touched by GC (so the markbit
2538 can't be set). Numbers are safe because they are
2539 immediate values. */
2540 if (NILP (new_state
)
2541 || (NUMBERP (new_state
)
2542 && ((XUINT (new_state
)) & 1) != cur_state
))
2544 one_w32_display_info
.faked_key
= vk_code
;
2546 keybd_event ((BYTE
) vk_code
,
2547 (BYTE
) MapVirtualKey (vk_code
, 0),
2548 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2549 keybd_event ((BYTE
) vk_code
,
2550 (BYTE
) MapVirtualKey (vk_code
, 0),
2551 KEYEVENTF_EXTENDEDKEY
| 0, 0);
2552 keybd_event ((BYTE
) vk_code
,
2553 (BYTE
) MapVirtualKey (vk_code
, 0),
2554 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2555 cur_state
= !cur_state
;
2557 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2563 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
2568 DispatchMessage (&msg
);
2571 /* Exit nested loop when our deferred message has completed. */
2572 if (msg_buf
->completed
)
2577 deferred_msg
* deferred_msg_head
;
2579 static deferred_msg
*
2580 find_deferred_msg (HWND hwnd
, UINT msg
)
2582 deferred_msg
* item
;
2584 /* Don't actually need synchronization for read access, since
2585 modification of single pointer is always atomic. */
2586 /* enter_crit (); */
2588 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2589 if (item
->w32msg
.msg
.hwnd
== hwnd
2590 && item
->w32msg
.msg
.message
== msg
)
2593 /* leave_crit (); */
2599 send_deferred_msg (deferred_msg
* msg_buf
,
2605 /* Only input thread can send deferred messages. */
2606 if (GetCurrentThreadId () != dwWindowsThreadId
)
2609 /* It is an error to send a message that is already deferred. */
2610 if (find_deferred_msg (hwnd
, msg
) != NULL
)
2613 /* Enforced synchronization is not needed because this is the only
2614 function that alters deferred_msg_head, and the following critical
2615 section is guaranteed to only be serially reentered (since only the
2616 input thread can call us). */
2618 /* enter_crit (); */
2620 msg_buf
->completed
= 0;
2621 msg_buf
->next
= deferred_msg_head
;
2622 deferred_msg_head
= msg_buf
;
2623 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
2625 /* leave_crit (); */
2627 /* Start a new nested message loop to process other messages until
2628 this one is completed. */
2629 w32_msg_pump (msg_buf
);
2631 deferred_msg_head
= msg_buf
->next
;
2633 return msg_buf
->result
;
2637 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
2639 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
2641 if (msg_buf
== NULL
)
2642 /* Message may have been cancelled, so don't abort(). */
2645 msg_buf
->result
= result
;
2646 msg_buf
->completed
= 1;
2648 /* Ensure input thread is woken so it notices the completion. */
2649 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2653 cancel_all_deferred_msgs ()
2655 deferred_msg
* item
;
2657 /* Don't actually need synchronization for read access, since
2658 modification of single pointer is always atomic. */
2659 /* enter_crit (); */
2661 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2664 item
->completed
= 1;
2667 /* leave_crit (); */
2669 /* Ensure input thread is woken so it notices the completion. */
2670 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2678 deferred_msg dummy_buf
;
2680 /* Ensure our message queue is created */
2682 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
2684 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2687 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
2688 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
2689 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
2691 /* This is the inital message loop which should only exit when the
2692 application quits. */
2693 w32_msg_pump (&dummy_buf
);
2699 post_character_message (hwnd
, msg
, wParam
, lParam
, modifiers
)
2709 wmsg
.dwModifiers
= modifiers
;
2711 /* Detect quit_char and set quit-flag directly. Note that we
2712 still need to post a message to ensure the main thread will be
2713 woken up if blocked in sys_select(), but we do NOT want to post
2714 the quit_char message itself (because it will usually be as if
2715 the user had typed quit_char twice). Instead, we post a dummy
2716 message that has no particular effect. */
2719 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
2720 c
= make_ctrl_char (c
) & 0377;
2722 || (wmsg
.dwModifiers
== 0 &&
2723 w32_quit_key
&& wParam
== w32_quit_key
))
2727 /* The choice of message is somewhat arbitrary, as long as
2728 the main thread handler just ignores it. */
2731 /* Interrupt any blocking system calls. */
2734 /* As a safety precaution, forcibly complete any deferred
2735 messages. This is a kludge, but I don't see any particularly
2736 clean way to handle the situation where a deferred message is
2737 "dropped" in the lisp thread, and will thus never be
2738 completed, eg. by the user trying to activate the menubar
2739 when the lisp thread is busy, and then typing C-g when the
2740 menubar doesn't open promptly (with the result that the
2741 menubar never responds at all because the deferred
2742 WM_INITMENU message is never completed). Another problem
2743 situation is when the lisp thread calls SendMessage (to send
2744 a window manager command) when a message has been deferred;
2745 the lisp thread gets blocked indefinitely waiting for the
2746 deferred message to be completed, which itself is waiting for
2747 the lisp thread to respond.
2749 Note that we don't want to block the input thread waiting for
2750 a reponse from the lisp thread (although that would at least
2751 solve the deadlock problem above), because we want to be able
2752 to receive C-g to interrupt the lisp thread. */
2753 cancel_all_deferred_msgs ();
2757 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2760 /* Main window procedure */
2763 w32_wnd_proc (hwnd
, msg
, wParam
, lParam
)
2770 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
2772 int windows_translate
;
2775 /* Note that it is okay to call x_window_to_frame, even though we are
2776 not running in the main lisp thread, because frame deletion
2777 requires the lisp thread to synchronize with this thread. Thus, if
2778 a frame struct is returned, it can be used without concern that the
2779 lisp thread might make it disappear while we are using it.
2781 NB. Walking the frame list in this thread is safe (as long as
2782 writes of Lisp_Object slots are atomic, which they are on Windows).
2783 Although delete-frame can destructively modify the frame list while
2784 we are walking it, a garbage collection cannot occur until after
2785 delete-frame has synchronized with this thread.
2787 It is also safe to use functions that make GDI calls, such as
2788 w32_clear_rect, because these functions must obtain a DC handle
2789 from the frame struct using get_frame_dc which is thread-aware. */
2794 f
= x_window_to_frame (dpyinfo
, hwnd
);
2797 HDC hdc
= get_frame_dc (f
);
2798 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
2799 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
2800 release_frame_dc (f
, hdc
);
2802 #if defined (W32_DEBUG_DISPLAY)
2803 DebPrint (("WM_ERASEBKGND (frame %p): erasing %d,%d-%d,%d\n",
2805 wmsg
.rect
.left
, wmsg
.rect
.top
,
2806 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2807 #endif /* W32_DEBUG_DISPLAY */
2810 case WM_PALETTECHANGED
:
2811 /* ignore our own changes */
2812 if ((HWND
)wParam
!= hwnd
)
2814 f
= x_window_to_frame (dpyinfo
, hwnd
);
2816 /* get_frame_dc will realize our palette and force all
2817 frames to be redrawn if needed. */
2818 release_frame_dc (f
, get_frame_dc (f
));
2823 PAINTSTRUCT paintStruct
;
2825 bzero (&update_rect
, sizeof (update_rect
));
2827 f
= x_window_to_frame (dpyinfo
, hwnd
);
2830 DebPrint (("WM_PAINT received for unknown window %p\n", hwnd
));
2834 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
2835 fails. Apparently this can happen under some
2837 if (GetUpdateRect (hwnd
, &update_rect
, FALSE
) || !w32_strict_painting
)
2840 BeginPaint (hwnd
, &paintStruct
);
2842 /* The rectangles returned by GetUpdateRect and BeginPaint
2843 do not always match. Play it safe by assuming both areas
2845 UnionRect (&(wmsg
.rect
), &update_rect
, &(paintStruct
.rcPaint
));
2847 #if defined (W32_DEBUG_DISPLAY)
2848 DebPrint (("WM_PAINT (frame %p): painting %d,%d-%d,%d\n",
2850 wmsg
.rect
.left
, wmsg
.rect
.top
,
2851 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2852 DebPrint ((" [update region is %d,%d-%d,%d]\n",
2853 update_rect
.left
, update_rect
.top
,
2854 update_rect
.right
, update_rect
.bottom
));
2856 EndPaint (hwnd
, &paintStruct
);
2859 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2864 /* If GetUpdateRect returns 0 (meaning there is no update
2865 region), assume the whole window needs to be repainted. */
2866 GetClientRect(hwnd
, &wmsg
.rect
);
2867 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2871 case WM_INPUTLANGCHANGE
:
2872 /* Inform lisp thread of keyboard layout changes. */
2873 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2875 /* Clear dead keys in the keyboard state; for simplicity only
2876 preserve modifier key states. */
2881 GetKeyboardState (keystate
);
2882 for (i
= 0; i
< 256; i
++)
2899 SetKeyboardState (keystate
);
2904 /* Synchronize hot keys with normal input. */
2905 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
2910 record_keyup (wParam
, lParam
);
2915 /* Ignore keystrokes we fake ourself; see below. */
2916 if (dpyinfo
->faked_key
== wParam
)
2918 dpyinfo
->faked_key
= 0;
2919 /* Make sure TranslateMessage sees them though (as long as
2920 they don't produce WM_CHAR messages). This ensures that
2921 indicator lights are toggled promptly on Windows 9x, for
2923 if (lispy_function_keys
[wParam
] != 0)
2925 windows_translate
= 1;
2931 /* Synchronize modifiers with current keystroke. */
2933 record_keydown (wParam
, lParam
);
2934 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
2936 windows_translate
= 0;
2941 if (NILP (Vw32_pass_lwindow_to_system
))
2943 /* Prevent system from acting on keyup (which opens the
2944 Start menu if no other key was pressed) by simulating a
2945 press of Space which we will ignore. */
2946 if (GetAsyncKeyState (wParam
) & 1)
2948 if (NUMBERP (Vw32_phantom_key_code
))
2949 key
= XUINT (Vw32_phantom_key_code
) & 255;
2952 dpyinfo
->faked_key
= key
;
2953 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
2956 if (!NILP (Vw32_lwindow_modifier
))
2960 if (NILP (Vw32_pass_rwindow_to_system
))
2962 if (GetAsyncKeyState (wParam
) & 1)
2964 if (NUMBERP (Vw32_phantom_key_code
))
2965 key
= XUINT (Vw32_phantom_key_code
) & 255;
2968 dpyinfo
->faked_key
= key
;
2969 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
2972 if (!NILP (Vw32_rwindow_modifier
))
2976 if (!NILP (Vw32_apps_modifier
))
2980 if (NILP (Vw32_pass_alt_to_system
))
2981 /* Prevent DefWindowProc from activating the menu bar if an
2982 Alt key is pressed and released by itself. */
2984 windows_translate
= 1;
2987 /* Decide whether to treat as modifier or function key. */
2988 if (NILP (Vw32_enable_caps_lock
))
2989 goto disable_lock_key
;
2990 windows_translate
= 1;
2993 /* Decide whether to treat as modifier or function key. */
2994 if (NILP (Vw32_enable_num_lock
))
2995 goto disable_lock_key
;
2996 windows_translate
= 1;
2999 /* Decide whether to treat as modifier or function key. */
3000 if (NILP (Vw32_scroll_lock_modifier
))
3001 goto disable_lock_key
;
3002 windows_translate
= 1;
3005 /* Ensure the appropriate lock key state (and indicator light)
3006 remains in the same state. We do this by faking another
3007 press of the relevant key. Apparently, this really is the
3008 only way to toggle the state of the indicator lights. */
3009 dpyinfo
->faked_key
= wParam
;
3010 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3011 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3012 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3013 KEYEVENTF_EXTENDEDKEY
| 0, 0);
3014 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3015 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3016 /* Ensure indicator lights are updated promptly on Windows 9x
3017 (TranslateMessage apparently does this), after forwarding
3019 post_character_message (hwnd
, msg
, wParam
, lParam
,
3020 w32_get_key_modifiers (wParam
, lParam
));
3021 windows_translate
= 1;
3025 case VK_PROCESSKEY
: /* Generated by IME. */
3026 windows_translate
= 1;
3029 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
3030 which is confusing for purposes of key binding; convert
3031 VK_CANCEL events into VK_PAUSE events. */
3035 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
3036 for purposes of key binding; convert these back into
3037 VK_NUMLOCK events, at least when we want to see NumLock key
3038 presses. (Note that there is never any possibility that
3039 VK_PAUSE with Ctrl really is C-Pause as per above.) */
3040 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
3041 wParam
= VK_NUMLOCK
;
3044 /* If not defined as a function key, change it to a WM_CHAR message. */
3045 if (lispy_function_keys
[wParam
] == 0)
3047 DWORD modifiers
= construct_console_modifiers ();
3049 if (!NILP (Vw32_recognize_altgr
)
3050 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
3052 /* Always let TranslateMessage handle AltGr key chords;
3053 for some reason, ToAscii doesn't always process AltGr
3054 chords correctly. */
3055 windows_translate
= 1;
3057 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
3059 /* Handle key chords including any modifiers other
3060 than shift directly, in order to preserve as much
3061 modifier information as possible. */
3062 if ('A' <= wParam
&& wParam
<= 'Z')
3064 /* Don't translate modified alphabetic keystrokes,
3065 so the user doesn't need to constantly switch
3066 layout to type control or meta keystrokes when
3067 the normal layout translates alphabetic
3068 characters to non-ascii characters. */
3069 if (!modifier_set (VK_SHIFT
))
3070 wParam
+= ('a' - 'A');
3075 /* Try to handle other keystrokes by determining the
3076 base character (ie. translating the base key plus
3080 KEY_EVENT_RECORD key
;
3082 key
.bKeyDown
= TRUE
;
3083 key
.wRepeatCount
= 1;
3084 key
.wVirtualKeyCode
= wParam
;
3085 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
3086 key
.uChar
.AsciiChar
= 0;
3087 key
.dwControlKeyState
= modifiers
;
3089 add
= w32_kbd_patch_key (&key
);
3090 /* 0 means an unrecognised keycode, negative means
3091 dead key. Ignore both. */
3094 /* Forward asciified character sequence. */
3095 post_character_message
3096 (hwnd
, WM_CHAR
, key
.uChar
.AsciiChar
, lParam
,
3097 w32_get_key_modifiers (wParam
, lParam
));
3098 w32_kbd_patch_key (&key
);
3105 /* Let TranslateMessage handle everything else. */
3106 windows_translate
= 1;
3112 if (windows_translate
)
3114 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
3116 windows_msg
.time
= GetMessageTime ();
3117 TranslateMessage (&windows_msg
);
3125 post_character_message (hwnd
, msg
, wParam
, lParam
,
3126 w32_get_key_modifiers (wParam
, lParam
));
3129 /* Simulate middle mouse button events when left and right buttons
3130 are used together, but only if user has two button mouse. */
3131 case WM_LBUTTONDOWN
:
3132 case WM_RBUTTONDOWN
:
3133 if (w32_num_mouse_buttons
> 2)
3134 goto handle_plain_button
;
3137 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
3138 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
3140 if (button_state
& this)
3143 if (button_state
== 0)
3146 button_state
|= this;
3148 if (button_state
& other
)
3150 if (mouse_button_timer
)
3152 KillTimer (hwnd
, mouse_button_timer
);
3153 mouse_button_timer
= 0;
3155 /* Generate middle mouse event instead. */
3156 msg
= WM_MBUTTONDOWN
;
3157 button_state
|= MMOUSE
;
3159 else if (button_state
& MMOUSE
)
3161 /* Ignore button event if we've already generated a
3162 middle mouse down event. This happens if the
3163 user releases and press one of the two buttons
3164 after we've faked a middle mouse event. */
3169 /* Flush out saved message. */
3170 post_msg (&saved_mouse_button_msg
);
3172 wmsg
.dwModifiers
= w32_get_modifiers ();
3173 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3175 /* Clear message buffer. */
3176 saved_mouse_button_msg
.msg
.hwnd
= 0;
3180 /* Hold onto message for now. */
3181 mouse_button_timer
=
3182 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
3183 w32_mouse_button_tolerance
, NULL
);
3184 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
3185 saved_mouse_button_msg
.msg
.message
= msg
;
3186 saved_mouse_button_msg
.msg
.wParam
= wParam
;
3187 saved_mouse_button_msg
.msg
.lParam
= lParam
;
3188 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
3189 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
3196 if (w32_num_mouse_buttons
> 2)
3197 goto handle_plain_button
;
3200 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
3201 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
3203 if ((button_state
& this) == 0)
3206 button_state
&= ~this;
3208 if (button_state
& MMOUSE
)
3210 /* Only generate event when second button is released. */
3211 if ((button_state
& other
) == 0)
3214 button_state
&= ~MMOUSE
;
3216 if (button_state
) abort ();
3223 /* Flush out saved message if necessary. */
3224 if (saved_mouse_button_msg
.msg
.hwnd
)
3226 post_msg (&saved_mouse_button_msg
);
3229 wmsg
.dwModifiers
= w32_get_modifiers ();
3230 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3232 /* Always clear message buffer and cancel timer. */
3233 saved_mouse_button_msg
.msg
.hwnd
= 0;
3234 KillTimer (hwnd
, mouse_button_timer
);
3235 mouse_button_timer
= 0;
3237 if (button_state
== 0)
3242 case WM_XBUTTONDOWN
:
3244 if (w32_pass_extra_mouse_buttons_to_system
)
3246 /* else fall through and process them. */
3247 case WM_MBUTTONDOWN
:
3249 handle_plain_button
:
3254 if (parse_button (msg
, HIWORD (wParam
), &button
, &up
))
3256 if (up
) ReleaseCapture ();
3257 else SetCapture (hwnd
);
3258 button
= (button
== 0) ? LMOUSE
:
3259 ((button
== 1) ? MMOUSE
: RMOUSE
);
3261 button_state
&= ~button
;
3263 button_state
|= button
;
3267 wmsg
.dwModifiers
= w32_get_modifiers ();
3268 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3270 /* Need to return true for XBUTTON messages, false for others,
3271 to indicate that we processed the message. */
3272 return (msg
== WM_XBUTTONDOWN
|| msg
== WM_XBUTTONUP
);
3275 /* If the mouse has just moved into the frame, start tracking
3276 it, so we will be notified when it leaves the frame. Mouse
3277 tracking only works under W98 and NT4 and later. On earlier
3278 versions, there is no way of telling when the mouse leaves the
3279 frame, so we just have to put up with help-echo and mouse
3280 highlighting remaining while the frame is not active. */
3281 if (track_mouse_event_fn
&& !track_mouse_window
)
3283 TRACKMOUSEEVENT tme
;
3284 tme
.cbSize
= sizeof (tme
);
3285 tme
.dwFlags
= TME_LEAVE
;
3286 tme
.hwndTrack
= hwnd
;
3288 track_mouse_event_fn (&tme
);
3289 track_mouse_window
= hwnd
;
3292 if (w32_mouse_move_interval
<= 0
3293 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
3295 wmsg
.dwModifiers
= w32_get_modifiers ();
3296 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3300 /* Hang onto mouse move and scroll messages for a bit, to avoid
3301 sending such events to Emacs faster than it can process them.
3302 If we get more events before the timer from the first message
3303 expires, we just replace the first message. */
3305 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
3307 SetTimer (hwnd
, MOUSE_MOVE_ID
,
3308 w32_mouse_move_interval
, NULL
);
3310 /* Hold onto message for now. */
3311 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
3312 saved_mouse_move_msg
.msg
.message
= msg
;
3313 saved_mouse_move_msg
.msg
.wParam
= wParam
;
3314 saved_mouse_move_msg
.msg
.lParam
= lParam
;
3315 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
3316 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
3321 wmsg
.dwModifiers
= w32_get_modifiers ();
3322 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3326 wmsg
.dwModifiers
= w32_get_modifiers ();
3327 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3331 /* Flush out saved messages if necessary. */
3332 if (wParam
== mouse_button_timer
)
3334 if (saved_mouse_button_msg
.msg
.hwnd
)
3336 post_msg (&saved_mouse_button_msg
);
3337 saved_mouse_button_msg
.msg
.hwnd
= 0;
3339 KillTimer (hwnd
, mouse_button_timer
);
3340 mouse_button_timer
= 0;
3342 else if (wParam
== mouse_move_timer
)
3344 if (saved_mouse_move_msg
.msg
.hwnd
)
3346 post_msg (&saved_mouse_move_msg
);
3347 saved_mouse_move_msg
.msg
.hwnd
= 0;
3349 KillTimer (hwnd
, mouse_move_timer
);
3350 mouse_move_timer
= 0;
3352 else if (wParam
== menu_free_timer
)
3354 KillTimer (hwnd
, menu_free_timer
);
3355 menu_free_timer
= 0;
3356 f
= x_window_to_frame (dpyinfo
, hwnd
);
3357 if (!f
->output_data
.w32
->menu_command_in_progress
)
3359 /* Free memory used by owner-drawn and help-echo strings. */
3360 w32_free_menu_strings (hwnd
);
3361 f
->output_data
.w32
->menubar_active
= 0;
3367 /* Windows doesn't send us focus messages when putting up and
3368 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
3369 The only indication we get that something happened is receiving
3370 this message afterwards. So this is a good time to reset our
3371 keyboard modifiers' state. */
3378 /* We must ensure menu bar is fully constructed and up to date
3379 before allowing user interaction with it. To achieve this
3380 we send this message to the lisp thread and wait for a
3381 reply (whose value is not actually needed) to indicate that
3382 the menu bar is now ready for use, so we can now return.
3384 To remain responsive in the meantime, we enter a nested message
3385 loop that can process all other messages.
3387 However, we skip all this if the message results from calling
3388 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
3389 thread a message because it is blocked on us at this point. We
3390 set menubar_active before calling TrackPopupMenu to indicate
3391 this (there is no possibility of confusion with real menubar
3394 f
= x_window_to_frame (dpyinfo
, hwnd
);
3396 && (f
->output_data
.w32
->menubar_active
3397 /* We can receive this message even in the absence of a
3398 menubar (ie. when the system menu is activated) - in this
3399 case we do NOT want to forward the message, otherwise it
3400 will cause the menubar to suddenly appear when the user
3401 had requested it to be turned off! */
3402 || f
->output_data
.w32
->menubar_widget
== NULL
))
3406 deferred_msg msg_buf
;
3408 /* Detect if message has already been deferred; in this case
3409 we cannot return any sensible value to ignore this. */
3410 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3413 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
3416 case WM_EXITMENULOOP
:
3417 f
= x_window_to_frame (dpyinfo
, hwnd
);
3419 /* If a menu command is not already in progress, check again
3420 after a short delay, since Windows often (always?) sends the
3421 WM_EXITMENULOOP before the corresponding WM_COMMAND message. */
3422 if (f
&& !f
->output_data
.w32
->menu_command_in_progress
)
3423 menu_free_timer
= SetTimer (hwnd
, MENU_FREE_ID
, MENU_FREE_DELAY
, NULL
);
3427 /* Direct handling of help_echo in menus. Should be safe now
3428 that we generate the help_echo by placing a help event in the
3431 HMENU menu
= (HMENU
) lParam
;
3432 UINT menu_item
= (UINT
) LOWORD (wParam
);
3433 UINT flags
= (UINT
) HIWORD (wParam
);
3435 w32_menu_display_help (hwnd
, menu
, menu_item
, flags
);
3439 case WM_MEASUREITEM
:
3440 f
= x_window_to_frame (dpyinfo
, hwnd
);
3443 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
3445 if (pMis
->CtlType
== ODT_MENU
)
3447 /* Work out dimensions for popup menu titles. */
3448 char * title
= (char *) pMis
->itemData
;
3449 HDC hdc
= GetDC (hwnd
);
3450 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3451 LOGFONT menu_logfont
;
3455 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3456 menu_logfont
.lfWeight
= FW_BOLD
;
3457 menu_font
= CreateFontIndirect (&menu_logfont
);
3458 old_font
= SelectObject (hdc
, menu_font
);
3460 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
3463 if (unicode_append_menu
)
3464 GetTextExtentPoint32W (hdc
, (WCHAR
*) title
,
3465 wcslen ((WCHAR
*) title
),
3468 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
3470 pMis
->itemWidth
= size
.cx
;
3471 if (pMis
->itemHeight
< size
.cy
)
3472 pMis
->itemHeight
= size
.cy
;
3475 pMis
->itemWidth
= 0;
3477 SelectObject (hdc
, old_font
);
3478 DeleteObject (menu_font
);
3479 ReleaseDC (hwnd
, hdc
);
3486 f
= x_window_to_frame (dpyinfo
, hwnd
);
3489 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
3491 if (pDis
->CtlType
== ODT_MENU
)
3493 /* Draw popup menu title. */
3494 char * title
= (char *) pDis
->itemData
;
3497 HDC hdc
= pDis
->hDC
;
3498 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3499 LOGFONT menu_logfont
;
3502 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3503 menu_logfont
.lfWeight
= FW_BOLD
;
3504 menu_font
= CreateFontIndirect (&menu_logfont
);
3505 old_font
= SelectObject (hdc
, menu_font
);
3507 /* Always draw title as if not selected. */
3508 if (unicode_append_menu
)
3511 + GetSystemMetrics (SM_CXMENUCHECK
),
3513 ETO_OPAQUE
, &pDis
->rcItem
,
3515 wcslen ((WCHAR
*) title
), NULL
);
3519 + GetSystemMetrics (SM_CXMENUCHECK
),
3521 ETO_OPAQUE
, &pDis
->rcItem
,
3522 title
, strlen (title
), NULL
);
3524 SelectObject (hdc
, old_font
);
3525 DeleteObject (menu_font
);
3533 /* Still not right - can't distinguish between clicks in the
3534 client area of the frame from clicks forwarded from the scroll
3535 bars - may have to hook WM_NCHITTEST to remember the mouse
3536 position and then check if it is in the client area ourselves. */
3537 case WM_MOUSEACTIVATE
:
3538 /* Discard the mouse click that activates a frame, allowing the
3539 user to click anywhere without changing point (or worse!).
3540 Don't eat mouse clicks on scrollbars though!! */
3541 if (LOWORD (lParam
) == HTCLIENT
)
3542 return MA_ACTIVATEANDEAT
;
3547 /* No longer tracking mouse. */
3548 track_mouse_window
= NULL
;
3550 case WM_ACTIVATEAPP
:
3552 case WM_WINDOWPOSCHANGED
:
3554 /* Inform lisp thread that a frame might have just been obscured
3555 or exposed, so should recheck visibility of all frames. */
3556 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3560 dpyinfo
->faked_key
= 0;
3562 register_hot_keys (hwnd
);
3565 unregister_hot_keys (hwnd
);
3568 /* Relinquish the system caret. */
3569 if (w32_system_caret_hwnd
)
3571 w32_visible_system_caret_hwnd
= NULL
;
3572 w32_system_caret_hwnd
= NULL
;
3577 f
= x_window_to_frame (dpyinfo
, hwnd
);
3578 if (f
&& HIWORD (wParam
) == 0)
3580 f
->output_data
.w32
->menu_command_in_progress
= 1;
3581 if (menu_free_timer
)
3583 KillTimer (hwnd
, menu_free_timer
);
3584 menu_free_timer
= 0;
3590 wmsg
.dwModifiers
= w32_get_modifiers ();
3591 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3595 wmsg
.dwModifiers
= w32_get_modifiers ();
3596 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3599 case WM_WINDOWPOSCHANGING
:
3600 /* Don't restrict the sizing of tip frames. */
3601 if (hwnd
== tip_window
)
3605 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
3607 wp
.length
= sizeof (WINDOWPLACEMENT
);
3608 GetWindowPlacement (hwnd
, &wp
);
3610 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
3617 DWORD internal_border
;
3618 DWORD scrollbar_extra
;
3621 wp
.length
= sizeof(wp
);
3622 GetWindowRect (hwnd
, &wr
);
3626 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
3627 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
3628 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
3629 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
3633 memset (&rect
, 0, sizeof (rect
));
3634 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
3635 GetMenu (hwnd
) != NULL
);
3637 /* Force width and height of client area to be exact
3638 multiples of the character cell dimensions. */
3639 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
3640 - 2 * internal_border
- scrollbar_extra
)
3642 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
3643 - 2 * internal_border
)
3648 /* For right/bottom sizing we can just fix the sizes.
3649 However for top/left sizing we will need to fix the X
3650 and Y positions as well. */
3655 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
3656 && (lppos
->flags
& SWP_NOMOVE
) == 0)
3658 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
3665 lppos
->flags
|= SWP_NOMOVE
;
3676 case WM_GETMINMAXINFO
:
3677 /* Hack to correct bug that allows Emacs frames to be resized
3678 below the Minimum Tracking Size. */
3679 ((LPMINMAXINFO
) lParam
)->ptMinTrackSize
.y
++;
3680 /* Hack to allow resizing the Emacs frame above the screen size.
3681 Note that Windows 9x limits coordinates to 16-bits. */
3682 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.x
= 32767;
3683 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.y
= 32767;
3687 if (LOWORD (lParam
) == HTCLIENT
)
3692 case WM_EMACS_SETCURSOR
:
3694 Cursor cursor
= (Cursor
) wParam
;
3700 case WM_EMACS_CREATESCROLLBAR
:
3701 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
3702 (struct scroll_bar
*) lParam
);
3704 case WM_EMACS_SHOWWINDOW
:
3705 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
3707 case WM_EMACS_SETFOREGROUND
:
3709 HWND foreground_window
;
3710 DWORD foreground_thread
, retval
;
3712 /* On NT 5.0, and apparently Windows 98, it is necessary to
3713 attach to the thread that currently has focus in order to
3714 pull the focus away from it. */
3715 foreground_window
= GetForegroundWindow ();
3716 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
3717 if (!foreground_window
3718 || foreground_thread
== GetCurrentThreadId ()
3719 || !AttachThreadInput (GetCurrentThreadId (),
3720 foreground_thread
, TRUE
))
3721 foreground_thread
= 0;
3723 retval
= SetForegroundWindow ((HWND
) wParam
);
3725 /* Detach from the previous foreground thread. */
3726 if (foreground_thread
)
3727 AttachThreadInput (GetCurrentThreadId (),
3728 foreground_thread
, FALSE
);
3733 case WM_EMACS_SETWINDOWPOS
:
3735 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
3736 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
3737 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
3740 case WM_EMACS_DESTROYWINDOW
:
3741 DragAcceptFiles ((HWND
) wParam
, FALSE
);
3742 return DestroyWindow ((HWND
) wParam
);
3744 case WM_EMACS_HIDE_CARET
:
3745 return HideCaret (hwnd
);
3747 case WM_EMACS_SHOW_CARET
:
3748 return ShowCaret (hwnd
);
3750 case WM_EMACS_DESTROY_CARET
:
3751 w32_system_caret_hwnd
= NULL
;
3752 w32_visible_system_caret_hwnd
= NULL
;
3753 return DestroyCaret ();
3755 case WM_EMACS_TRACK_CARET
:
3756 /* If there is currently no system caret, create one. */
3757 if (w32_system_caret_hwnd
== NULL
)
3759 /* Use the default caret width, and avoid changing it
3760 unneccesarily, as it confuses screen reader software. */
3761 w32_system_caret_hwnd
= hwnd
;
3762 CreateCaret (hwnd
, NULL
, 0,
3763 w32_system_caret_height
);
3766 if (!SetCaretPos (w32_system_caret_x
, w32_system_caret_y
))
3768 /* Ensure visible caret gets turned on when requested. */
3769 else if (w32_use_visible_system_caret
3770 && w32_visible_system_caret_hwnd
!= hwnd
)
3772 w32_visible_system_caret_hwnd
= hwnd
;
3773 return ShowCaret (hwnd
);
3775 /* Ensure visible caret gets turned off when requested. */
3776 else if (!w32_use_visible_system_caret
3777 && w32_visible_system_caret_hwnd
)
3779 w32_visible_system_caret_hwnd
= NULL
;
3780 return HideCaret (hwnd
);
3785 case WM_EMACS_TRACKPOPUPMENU
:
3790 pos
= (POINT
*)lParam
;
3791 flags
= TPM_CENTERALIGN
;
3792 if (button_state
& LMOUSE
)
3793 flags
|= TPM_LEFTBUTTON
;
3794 else if (button_state
& RMOUSE
)
3795 flags
|= TPM_RIGHTBUTTON
;
3797 /* Remember we did a SetCapture on the initial mouse down event,
3798 so for safety, we make sure the capture is cancelled now. */
3802 /* Use menubar_active to indicate that WM_INITMENU is from
3803 TrackPopupMenu below, and should be ignored. */
3804 f
= x_window_to_frame (dpyinfo
, hwnd
);
3806 f
->output_data
.w32
->menubar_active
= 1;
3808 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
3812 /* Eat any mouse messages during popupmenu */
3813 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
3815 /* Get the menu selection, if any */
3816 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
3818 retval
= LOWORD (amsg
.wParam
);
3834 /* Check for messages registered at runtime. */
3835 if (msg
== msh_mousewheel
)
3837 wmsg
.dwModifiers
= w32_get_modifiers ();
3838 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3843 return DefWindowProc (hwnd
, msg
, wParam
, lParam
);
3847 /* The most common default return code for handled messages is 0. */
3852 my_create_window (f
)
3857 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
3859 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
3863 /* Create a tooltip window. Unlike my_create_window, we do not do this
3864 indirectly via the Window thread, as we do not need to process Window
3865 messages for the tooltip. Creating tooltips indirectly also creates
3866 deadlocks when tooltips are created for menu items. */
3868 my_create_tip_window (f
)
3873 rect
.left
= rect
.top
= 0;
3874 rect
.right
= FRAME_PIXEL_WIDTH (f
);
3875 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
3877 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
3878 FRAME_EXTERNAL_MENU_BAR (f
));
3880 tip_window
= FRAME_W32_WINDOW (f
)
3881 = CreateWindow (EMACS_CLASS
,
3883 f
->output_data
.w32
->dwStyle
,
3886 rect
.right
- rect
.left
,
3887 rect
.bottom
- rect
.top
,
3888 FRAME_W32_WINDOW (SELECTED_FRAME ()), /* owner */
3895 SetWindowLong (tip_window
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
3896 SetWindowLong (tip_window
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
3897 SetWindowLong (tip_window
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
3898 SetWindowLong (tip_window
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
3900 /* Tip frames have no scrollbars. */
3901 SetWindowLong (tip_window
, WND_SCROLLBAR_INDEX
, 0);
3903 /* Do this to discard the default setting specified by our parent. */
3904 ShowWindow (tip_window
, SW_HIDE
);
3909 /* Create and set up the w32 window for frame F. */
3912 w32_window (f
, window_prompting
, minibuffer_only
)
3914 long window_prompting
;
3915 int minibuffer_only
;
3919 /* Use the resource name as the top-level window name
3920 for looking up resources. Make a non-Lisp copy
3921 for the window manager, so GC relocation won't bother it.
3923 Elsewhere we specify the window name for the window manager. */
3926 char *str
= (char *) SDATA (Vx_resource_name
);
3927 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
3928 strcpy (f
->namebuf
, str
);
3931 my_create_window (f
);
3933 validate_x_resource_name ();
3935 /* x_set_name normally ignores requests to set the name if the
3936 requested name is the same as the current name. This is the one
3937 place where that assumption isn't correct; f->name is set, but
3938 the server hasn't been told. */
3941 int explicit = f
->explicit_name
;
3943 f
->explicit_name
= 0;
3946 x_set_name (f
, name
, explicit);
3951 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
3952 initialize_frame_menubar (f
);
3954 if (FRAME_W32_WINDOW (f
) == 0)
3955 error ("Unable to create window");
3958 /* Handle the icon stuff for this window. Perhaps later we might
3959 want an x_set_icon_position which can be called interactively as
3967 Lisp_Object icon_x
, icon_y
;
3969 /* Set the position of the icon. Note that Windows 95 groups all
3970 icons in the tray. */
3971 icon_x
= w32_get_arg (parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
3972 icon_y
= w32_get_arg (parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
3973 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
3975 CHECK_NUMBER (icon_x
);
3976 CHECK_NUMBER (icon_y
);
3978 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
3979 error ("Both left and top icon corners of icon must be specified");
3983 if (! EQ (icon_x
, Qunbound
))
3984 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
3987 /* Start up iconic or window? */
3988 x_wm_set_window_state
3989 (f
, (EQ (w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
3993 x_text_icon (f
, (char *) SDATA ((!NILP (f
->icon_name
)
4006 XGCValues gc_values
;
4010 /* Create the GC's of this frame.
4011 Note that many default values are used. */
4014 gc_values
.font
= FRAME_FONT (f
);
4016 /* Cursor has cursor-color background, background-color foreground. */
4017 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
4018 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
4019 f
->output_data
.w32
->cursor_gc
4020 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
4021 (GCFont
| GCForeground
| GCBackground
),
4025 f
->output_data
.w32
->white_relief
.gc
= 0;
4026 f
->output_data
.w32
->black_relief
.gc
= 0;
4032 /* Handler for signals raised during x_create_frame and
4033 x_create_top_frame. FRAME is the frame which is partially
4037 unwind_create_frame (frame
)
4040 struct frame
*f
= XFRAME (frame
);
4042 /* If frame is ``official'', nothing to do. */
4043 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
4046 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4049 x_free_frame_resources (f
);
4051 /* Check that reference counts are indeed correct. */
4052 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
4053 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
4062 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
4064 doc
: /* Make a new window, which is called a \"frame\" in Emacs terms.
4065 Returns an Emacs frame object.
4066 PARAMETERS is an alist of frame parameters.
4067 If the parameters specify that the frame should not have a minibuffer,
4068 and do not specify a specific minibuffer window to use,
4069 then `default-minibuffer-frame' must be a frame whose minibuffer can
4070 be shared by the new frame.
4072 This function is an internal primitive--use `make-frame' instead. */)
4074 Lisp_Object parameters
;
4077 Lisp_Object frame
, tem
;
4079 int minibuffer_only
= 0;
4080 long window_prompting
= 0;
4082 int count
= SPECPDL_INDEX ();
4083 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4084 Lisp_Object display
;
4085 struct w32_display_info
*dpyinfo
= NULL
;
4091 /* Use this general default value to start with
4092 until we know if this frame has a specified name. */
4093 Vx_resource_name
= Vinvocation_name
;
4095 display
= w32_get_arg (parameters
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
4096 if (EQ (display
, Qunbound
))
4098 dpyinfo
= check_x_display_info (display
);
4100 kb
= dpyinfo
->kboard
;
4102 kb
= &the_only_kboard
;
4105 name
= w32_get_arg (parameters
, Qname
, "name", "Name", RES_TYPE_STRING
);
4107 && ! EQ (name
, Qunbound
)
4109 error ("Invalid frame name--not a string or nil");
4112 Vx_resource_name
= name
;
4114 /* See if parent window is specified. */
4115 parent
= w32_get_arg (parameters
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
4116 if (EQ (parent
, Qunbound
))
4118 if (! NILP (parent
))
4119 CHECK_NUMBER (parent
);
4121 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
4122 /* No need to protect DISPLAY because that's not used after passing
4123 it to make_frame_without_minibuffer. */
4125 GCPRO4 (parameters
, parent
, name
, frame
);
4126 tem
= w32_get_arg (parameters
, Qminibuffer
, "minibuffer", "Minibuffer",
4128 if (EQ (tem
, Qnone
) || NILP (tem
))
4129 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
4130 else if (EQ (tem
, Qonly
))
4132 f
= make_minibuffer_frame ();
4133 minibuffer_only
= 1;
4135 else if (WINDOWP (tem
))
4136 f
= make_frame_without_minibuffer (tem
, kb
, display
);
4140 XSETFRAME (frame
, f
);
4142 /* Note that Windows does support scroll bars. */
4143 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
4145 /* By default, make scrollbars the system standard width. */
4146 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
4148 f
->output_method
= output_w32
;
4149 f
->output_data
.w32
=
4150 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
4151 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
4152 FRAME_FONTSET (f
) = -1;
4153 record_unwind_protect (unwind_create_frame
, frame
);
4156 = w32_get_arg (parameters
, Qicon_name
, "iconName", "Title", RES_TYPE_STRING
);
4157 if (! STRINGP (f
->icon_name
))
4158 f
->icon_name
= Qnil
;
4160 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
4162 FRAME_KBOARD (f
) = kb
;
4165 /* Specify the parent under which to make this window. */
4169 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
4170 f
->output_data
.w32
->explicit_parent
= 1;
4174 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4175 f
->output_data
.w32
->explicit_parent
= 0;
4178 /* Set the name; the functions to which we pass f expect the name to
4180 if (EQ (name
, Qunbound
) || NILP (name
))
4182 f
->name
= build_string (dpyinfo
->w32_id_name
);
4183 f
->explicit_name
= 0;
4188 f
->explicit_name
= 1;
4189 /* use the frame's title when getting resources for this frame. */
4190 specbind (Qx_resource_name
, name
);
4193 /* Extract the window parameters from the supplied values
4194 that are needed to determine window geometry. */
4198 font
= w32_get_arg (parameters
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4201 /* First, try whatever font the caller has specified. */
4204 tem
= Fquery_fontset (font
, Qnil
);
4206 font
= x_new_fontset (f
, tem
);
4208 font
= x_new_font (f
, SDATA (font
));
4210 /* Try out a font which we hope has bold and italic variations. */
4211 if (!STRINGP (font
))
4212 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
4213 if (! STRINGP (font
))
4214 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
4215 /* If those didn't work, look for something which will at least work. */
4216 if (! STRINGP (font
))
4217 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
4219 if (! STRINGP (font
))
4220 font
= build_string ("Fixedsys");
4222 x_default_parameter (f
, parameters
, Qfont
, font
,
4223 "font", "Font", RES_TYPE_STRING
);
4226 x_default_parameter (f
, parameters
, Qborder_width
, make_number (2),
4227 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4228 /* This defaults to 2 in order to match xterm. We recognize either
4229 internalBorderWidth or internalBorder (which is what xterm calls
4231 if (NILP (Fassq (Qinternal_border_width
, parameters
)))
4235 value
= w32_get_arg (parameters
, Qinternal_border_width
,
4236 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
4237 if (! EQ (value
, Qunbound
))
4238 parameters
= Fcons (Fcons (Qinternal_border_width
, value
),
4241 /* Default internalBorderWidth to 0 on Windows to match other programs. */
4242 x_default_parameter (f
, parameters
, Qinternal_border_width
, make_number (0),
4243 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
4244 x_default_parameter (f
, parameters
, Qvertical_scroll_bars
, Qright
,
4245 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
4247 /* Also do the stuff which must be set before the window exists. */
4248 x_default_parameter (f
, parameters
, Qforeground_color
, build_string ("black"),
4249 "foreground", "Foreground", RES_TYPE_STRING
);
4250 x_default_parameter (f
, parameters
, Qbackground_color
, build_string ("white"),
4251 "background", "Background", RES_TYPE_STRING
);
4252 x_default_parameter (f
, parameters
, Qmouse_color
, build_string ("black"),
4253 "pointerColor", "Foreground", RES_TYPE_STRING
);
4254 x_default_parameter (f
, parameters
, Qcursor_color
, build_string ("black"),
4255 "cursorColor", "Foreground", RES_TYPE_STRING
);
4256 x_default_parameter (f
, parameters
, Qborder_color
, build_string ("black"),
4257 "borderColor", "BorderColor", RES_TYPE_STRING
);
4258 x_default_parameter (f
, parameters
, Qscreen_gamma
, Qnil
,
4259 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
4260 x_default_parameter (f
, parameters
, Qline_spacing
, Qnil
,
4261 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
4262 x_default_parameter (f
, parameters
, Qleft_fringe
, Qnil
,
4263 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
4264 x_default_parameter (f
, parameters
, Qright_fringe
, Qnil
,
4265 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
4268 /* Init faces before x_default_parameter is called for scroll-bar
4269 parameters because that function calls x_set_scroll_bar_width,
4270 which calls change_frame_size, which calls Fset_window_buffer,
4271 which runs hooks, which call Fvertical_motion. At the end, we
4272 end up in init_iterator with a null face cache, which should not
4274 init_frame_faces (f
);
4276 x_default_parameter (f
, parameters
, Qmenu_bar_lines
, make_number (1),
4277 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
4278 x_default_parameter (f
, parameters
, Qtool_bar_lines
, make_number (1),
4279 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
4281 x_default_parameter (f
, parameters
, Qbuffer_predicate
, Qnil
,
4282 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
4283 x_default_parameter (f
, parameters
, Qtitle
, Qnil
,
4284 "title", "Title", RES_TYPE_STRING
);
4285 x_default_parameter (f
, parameters
, Qfullscreen
, Qnil
,
4286 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
4288 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
4289 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4291 f
->output_data
.w32
->text_cursor
= w32_load_cursor (IDC_IBEAM
);
4292 f
->output_data
.w32
->nontext_cursor
= w32_load_cursor (IDC_ARROW
);
4293 f
->output_data
.w32
->modeline_cursor
= w32_load_cursor (IDC_ARROW
);
4294 f
->output_data
.w32
->hand_cursor
= w32_load_cursor (IDC_HAND
);
4295 f
->output_data
.w32
->hourglass_cursor
= w32_load_cursor (IDC_WAIT
);
4296 f
->output_data
.w32
->horizontal_drag_cursor
= w32_load_cursor (IDC_SIZEWE
);
4298 window_prompting
= x_figure_window_size (f
, parameters
, 1);
4300 tem
= w32_get_arg (parameters
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
4301 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
4303 w32_window (f
, window_prompting
, minibuffer_only
);
4304 x_icon (f
, parameters
);
4308 /* Now consider the frame official. */
4309 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
4310 Vframe_list
= Fcons (frame
, Vframe_list
);
4312 /* We need to do this after creating the window, so that the
4313 icon-creation functions can say whose icon they're describing. */
4314 x_default_parameter (f
, parameters
, Qicon_type
, Qnil
,
4315 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
4317 x_default_parameter (f
, parameters
, Qauto_raise
, Qnil
,
4318 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4319 x_default_parameter (f
, parameters
, Qauto_lower
, Qnil
,
4320 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4321 x_default_parameter (f
, parameters
, Qcursor_type
, Qbox
,
4322 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4323 x_default_parameter (f
, parameters
, Qscroll_bar_width
, Qnil
,
4324 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
4326 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4327 Change will not be effected unless different from the current
4329 width
= FRAME_COLS (f
);
4330 height
= FRAME_LINES (f
);
4332 FRAME_LINES (f
) = 0;
4333 SET_FRAME_COLS (f
, 0);
4334 change_frame_size (f
, height
, width
, 1, 0, 0);
4336 /* Tell the server what size and position, etc, we want, and how
4337 badly we want them. This should be done after we have the menu
4338 bar so that its size can be taken into account. */
4340 x_wm_set_size_hint (f
, window_prompting
, 0);
4343 /* Avoid a bug that causes the new frame to never become visible if
4344 an echo area message is displayed during the following call1. */
4345 specbind(Qredisplay_dont_pause
, Qt
);
4347 /* Set up faces after all frame parameters are known. This call
4348 also merges in face attributes specified for new frames. If we
4349 don't do this, the `menu' face for instance won't have the right
4350 colors, and the menu bar won't appear in the specified colors for
4352 call1 (Qface_set_after_frame_default
, frame
);
4354 /* Make the window appear on the frame and enable display, unless
4355 the caller says not to. However, with explicit parent, Emacs
4356 cannot control visibility, so don't try. */
4357 if (! f
->output_data
.w32
->explicit_parent
)
4359 Lisp_Object visibility
;
4361 visibility
= w32_get_arg (parameters
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
4362 if (EQ (visibility
, Qunbound
))
4365 if (EQ (visibility
, Qicon
))
4366 x_iconify_frame (f
);
4367 else if (! NILP (visibility
))
4368 x_make_frame_visible (f
);
4370 /* Must have been Qnil. */
4375 /* Make sure windows on this frame appear in calls to next-window
4376 and similar functions. */
4377 Vwindow_list
= Qnil
;
4379 return unbind_to (count
, frame
);
4382 /* FRAME is used only to get a handle on the X display. We don't pass the
4383 display info directly because we're called from frame.c, which doesn't
4384 know about that structure. */
4386 x_get_focus_frame (frame
)
4387 struct frame
*frame
;
4389 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
4391 if (! dpyinfo
->w32_focus_frame
)
4394 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
4398 DEFUN ("w32-focus-frame", Fw32_focus_frame
, Sw32_focus_frame
, 1, 1, 0,
4399 doc
: /* Give FRAME input focus, raising to foreground if necessary. */)
4403 x_focus_on_frame (check_x_frame (frame
));
4408 /* Return the charset portion of a font name. */
4409 char * xlfd_charset_of_font (char * fontname
)
4411 char *charset
, *encoding
;
4413 encoding
= strrchr(fontname
, '-');
4414 if (!encoding
|| encoding
== fontname
)
4417 for (charset
= encoding
- 1; charset
>= fontname
; charset
--)
4418 if (*charset
== '-')
4421 if (charset
== fontname
|| strcmp(charset
, "-*-*") == 0)
4427 struct font_info
*w32_load_bdf_font (struct frame
*f
, char *fontname
,
4428 int size
, char* filename
);
4429 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
);
4430 static BOOL
w32_to_x_font (LOGFONT
* lplf
, char * lpxstr
, int len
,
4432 static BOOL
x_to_w32_font (char *lpxstr
, LOGFONT
*lplogfont
);
4434 static struct font_info
*
4435 w32_load_system_font (f
,fontname
,size
)
4440 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4441 Lisp_Object font_names
;
4443 /* Get a list of all the fonts that match this name. Once we
4444 have a list of matching fonts, we compare them against the fonts
4445 we already have loaded by comparing names. */
4446 font_names
= w32_list_fonts (f
, build_string (fontname
), size
, 100);
4448 if (!NILP (font_names
))
4453 /* First check if any are already loaded, as that is cheaper
4454 than loading another one. */
4455 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
4456 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
4457 if (dpyinfo
->font_table
[i
].name
4458 && (!strcmp (dpyinfo
->font_table
[i
].name
,
4459 SDATA (XCAR (tail
)))
4460 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
4461 SDATA (XCAR (tail
)))))
4462 return (dpyinfo
->font_table
+ i
);
4464 fontname
= (char *) SDATA (XCAR (font_names
));
4466 else if (w32_strict_fontnames
)
4468 /* If EnumFontFamiliesEx was available, we got a full list of
4469 fonts back so stop now to avoid the possibility of loading a
4470 random font. If we had to fall back to EnumFontFamilies, the
4471 list is incomplete, so continue whether the font we want was
4473 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
4474 FARPROC enum_font_families_ex
4475 = GetProcAddress (gdi32
, "EnumFontFamiliesExA");
4476 if (enum_font_families_ex
)
4480 /* Load the font and add it to the table. */
4482 char *full_name
, *encoding
, *charset
;
4484 struct font_info
*fontp
;
4490 if (!fontname
|| !x_to_w32_font (fontname
, &lf
))
4493 if (!*lf
.lfFaceName
)
4494 /* If no name was specified for the font, we get a random font
4495 from CreateFontIndirect - this is not particularly
4496 desirable, especially since CreateFontIndirect does not
4497 fill out the missing name in lf, so we never know what we
4501 lf
.lfQuality
= DEFAULT_QUALITY
;
4503 font
= (XFontStruct
*) xmalloc (sizeof (XFontStruct
));
4504 bzero (font
, sizeof (*font
));
4506 /* Set bdf to NULL to indicate that this is a Windows font. */
4511 font
->hfont
= CreateFontIndirect (&lf
);
4513 if (font
->hfont
== NULL
)
4522 codepage
= w32_codepage_for_font (fontname
);
4524 hdc
= GetDC (dpyinfo
->root_window
);
4525 oldobj
= SelectObject (hdc
, font
->hfont
);
4527 ok
= GetTextMetrics (hdc
, &font
->tm
);
4528 if (codepage
== CP_UNICODE
)
4529 font
->double_byte_p
= 1;
4532 /* Unfortunately, some fonts (eg. MingLiU, a big5 ttf font)
4533 don't report themselves as double byte fonts, when
4534 patently they are. So instead of trusting
4535 GetFontLanguageInfo, we check the properties of the
4536 codepage directly, since that is ultimately what we are
4537 working from anyway. */
4538 /* font->double_byte_p = GetFontLanguageInfo(hdc) & GCP_DBCS; */
4540 GetCPInfo (codepage
, &cpi
);
4541 font
->double_byte_p
= cpi
.MaxCharSize
> 1;
4544 SelectObject (hdc
, oldobj
);
4545 ReleaseDC (dpyinfo
->root_window
, hdc
);
4546 /* Fill out details in lf according to the font that was
4548 lf
.lfHeight
= font
->tm
.tmInternalLeading
- font
->tm
.tmHeight
;
4549 lf
.lfWidth
= font
->tm
.tmMaxCharWidth
;
4550 lf
.lfWeight
= font
->tm
.tmWeight
;
4551 lf
.lfItalic
= font
->tm
.tmItalic
;
4552 lf
.lfCharSet
= font
->tm
.tmCharSet
;
4553 lf
.lfPitchAndFamily
= ((font
->tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
)
4554 ? VARIABLE_PITCH
: FIXED_PITCH
);
4555 lf
.lfOutPrecision
= ((font
->tm
.tmPitchAndFamily
& TMPF_VECTOR
)
4556 ? OUT_STROKE_PRECIS
: OUT_STRING_PRECIS
);
4558 w32_cache_char_metrics (font
);
4565 w32_unload_font (dpyinfo
, font
);
4569 /* Find a free slot in the font table. */
4570 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
4571 if (dpyinfo
->font_table
[i
].name
== NULL
)
4574 /* If no free slot found, maybe enlarge the font table. */
4575 if (i
== dpyinfo
->n_fonts
4576 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
4579 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
4580 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
4582 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
4585 fontp
= dpyinfo
->font_table
+ i
;
4586 if (i
== dpyinfo
->n_fonts
)
4589 /* Now fill in the slots of *FONTP. */
4591 bzero (fontp
, sizeof (*fontp
));
4593 fontp
->font_idx
= i
;
4594 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
4595 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
4597 if (lf
.lfPitchAndFamily
== FIXED_PITCH
)
4599 /* Fixed width font. */
4600 fontp
->average_width
= fontp
->space_width
= FONT_WIDTH (font
);
4606 pcm
= w32_per_char_metric (font
, &space
, ANSI_FONT
);
4608 fontp
->space_width
= pcm
->width
;
4610 fontp
->space_width
= FONT_WIDTH (font
);
4612 fontp
->average_width
= font
->tm
.tmAveCharWidth
;
4616 fontp
->charset
= -1;
4617 charset
= xlfd_charset_of_font (fontname
);
4619 /* Cache the W32 codepage for a font. This makes w32_encode_char
4620 (called for every glyph during redisplay) much faster. */
4621 fontp
->codepage
= codepage
;
4623 /* Work out the font's full name. */
4624 full_name
= (char *)xmalloc (100);
4625 if (full_name
&& w32_to_x_font (&lf
, full_name
, 100, charset
))
4626 fontp
->full_name
= full_name
;
4629 /* If all else fails - just use the name we used to load it. */
4631 fontp
->full_name
= fontp
->name
;
4634 fontp
->size
= FONT_WIDTH (font
);
4635 fontp
->height
= FONT_HEIGHT (font
);
4637 /* The slot `encoding' specifies how to map a character
4638 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
4639 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
4640 (0:0x20..0x7F, 1:0xA0..0xFF,
4641 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
4642 2:0xA020..0xFF7F). For the moment, we don't know which charset
4643 uses this font. So, we set information in fontp->encoding_type
4644 which is never used by any charset. If mapping can't be
4645 decided, set FONT_ENCODING_NOT_DECIDED. */
4647 /* SJIS fonts need to be set to type 4, all others seem to work as
4648 type FONT_ENCODING_NOT_DECIDED. */
4649 encoding
= strrchr (fontp
->name
, '-');
4650 if (encoding
&& strnicmp (encoding
+1, "sjis", 4) == 0)
4651 fontp
->encoding_type
= 4;
4653 fontp
->encoding_type
= FONT_ENCODING_NOT_DECIDED
;
4655 /* The following three values are set to 0 under W32, which is
4656 what they get set to if XGetFontProperty fails under X. */
4657 fontp
->baseline_offset
= 0;
4658 fontp
->relative_compose
= 0;
4659 fontp
->default_ascent
= 0;
4661 /* Set global flag fonts_changed_p to non-zero if the font loaded
4662 has a character with a smaller width than any other character
4663 before, or if the font loaded has a smaller height than any
4664 other font loaded before. If this happens, it will make a
4665 glyph matrix reallocation necessary. */
4666 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
4672 /* Load font named FONTNAME of size SIZE for frame F, and return a
4673 pointer to the structure font_info while allocating it dynamically.
4674 If loading fails, return NULL. */
4676 w32_load_font (f
,fontname
,size
)
4681 Lisp_Object bdf_fonts
;
4682 struct font_info
*retval
= NULL
;
4683 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4685 bdf_fonts
= w32_list_bdf_fonts (build_string (fontname
), 1);
4687 while (!retval
&& CONSP (bdf_fonts
))
4689 char *bdf_name
, *bdf_file
;
4690 Lisp_Object bdf_pair
;
4693 bdf_name
= SDATA (XCAR (bdf_fonts
));
4694 bdf_pair
= Fassoc (XCAR (bdf_fonts
), Vw32_bdf_filename_alist
);
4695 bdf_file
= SDATA (XCDR (bdf_pair
));
4697 // If the font is already loaded, do not load it again.
4698 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
4700 if ((dpyinfo
->font_table
[i
].name
4701 && !strcmp (dpyinfo
->font_table
[i
].name
, bdf_name
))
4702 || (dpyinfo
->font_table
[i
].full_name
4703 && !strcmp (dpyinfo
->font_table
[i
].full_name
, bdf_name
)))
4704 return dpyinfo
->font_table
+ i
;
4707 retval
= w32_load_bdf_font (f
, bdf_name
, size
, bdf_file
);
4709 bdf_fonts
= XCDR (bdf_fonts
);
4715 return w32_load_system_font(f
, fontname
, size
);
4720 w32_unload_font (dpyinfo
, font
)
4721 struct w32_display_info
*dpyinfo
;
4726 if (font
->per_char
) xfree (font
->per_char
);
4727 if (font
->bdf
) w32_free_bdf_font (font
->bdf
);
4729 if (font
->hfont
) DeleteObject(font
->hfont
);
4734 /* The font conversion stuff between x and w32 */
4736 /* X font string is as follows (from faces.el)
4740 * (weight "\\(bold\\|demibold\\|medium\\)") ; 1
4741 * (weight\? "\\([^-]*\\)") ; 1
4742 * (slant "\\([ior]\\)") ; 2
4743 * (slant\? "\\([^-]?\\)") ; 2
4744 * (swidth "\\([^-]*\\)") ; 3
4745 * (adstyle "[^-]*") ; 4
4746 * (pixelsize "[0-9]+")
4747 * (pointsize "[0-9][0-9]+")
4748 * (resx "[0-9][0-9]+")
4749 * (resy "[0-9][0-9]+")
4750 * (spacing "[cmp?*]")
4751 * (avgwidth "[0-9]+")
4752 * (registry "[^-]+")
4753 * (encoding "[^-]+")
4758 x_to_w32_weight (lpw
)
4761 if (!lpw
) return (FW_DONTCARE
);
4763 if (stricmp (lpw
,"heavy") == 0) return FW_HEAVY
;
4764 else if (stricmp (lpw
,"extrabold") == 0) return FW_EXTRABOLD
;
4765 else if (stricmp (lpw
,"bold") == 0) return FW_BOLD
;
4766 else if (stricmp (lpw
,"demibold") == 0) return FW_SEMIBOLD
;
4767 else if (stricmp (lpw
,"semibold") == 0) return FW_SEMIBOLD
;
4768 else if (stricmp (lpw
,"medium") == 0) return FW_MEDIUM
;
4769 else if (stricmp (lpw
,"normal") == 0) return FW_NORMAL
;
4770 else if (stricmp (lpw
,"light") == 0) return FW_LIGHT
;
4771 else if (stricmp (lpw
,"extralight") == 0) return FW_EXTRALIGHT
;
4772 else if (stricmp (lpw
,"thin") == 0) return FW_THIN
;
4779 w32_to_x_weight (fnweight
)
4782 if (fnweight
>= FW_HEAVY
) return "heavy";
4783 if (fnweight
>= FW_EXTRABOLD
) return "extrabold";
4784 if (fnweight
>= FW_BOLD
) return "bold";
4785 if (fnweight
>= FW_SEMIBOLD
) return "demibold";
4786 if (fnweight
>= FW_MEDIUM
) return "medium";
4787 if (fnweight
>= FW_NORMAL
) return "normal";
4788 if (fnweight
>= FW_LIGHT
) return "light";
4789 if (fnweight
>= FW_EXTRALIGHT
) return "extralight";
4790 if (fnweight
>= FW_THIN
) return "thin";
4796 x_to_w32_charset (lpcs
)
4799 Lisp_Object this_entry
, w32_charset
;
4801 int len
= strlen (lpcs
);
4803 /* Support "*-#nnn" format for unknown charsets. */
4804 if (strncmp (lpcs
, "*-#", 3) == 0)
4805 return atoi (lpcs
+ 3);
4807 /* All Windows fonts qualify as unicode. */
4808 if (!strncmp (lpcs
, "iso10646", 8))
4809 return DEFAULT_CHARSET
;
4811 /* Handle wildcards by ignoring them; eg. treat "big5*-*" as "big5". */
4812 charset
= alloca (len
+ 1);
4813 strcpy (charset
, lpcs
);
4814 lpcs
= strchr (charset
, '*');
4818 /* Look through w32-charset-info-alist for the character set.
4819 Format of each entry is
4820 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
4822 this_entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
4824 if (NILP(this_entry
))
4826 /* At startup, we want iso8859-1 fonts to come up properly. */
4827 if (stricmp(charset
, "iso8859-1") == 0)
4828 return ANSI_CHARSET
;
4830 return DEFAULT_CHARSET
;
4833 w32_charset
= Fcar (Fcdr (this_entry
));
4835 /* Translate Lisp symbol to number. */
4836 if (EQ (w32_charset
, Qw32_charset_ansi
))
4837 return ANSI_CHARSET
;
4838 if (EQ (w32_charset
, Qw32_charset_symbol
))
4839 return SYMBOL_CHARSET
;
4840 if (EQ (w32_charset
, Qw32_charset_shiftjis
))
4841 return SHIFTJIS_CHARSET
;
4842 if (EQ (w32_charset
, Qw32_charset_hangeul
))
4843 return HANGEUL_CHARSET
;
4844 if (EQ (w32_charset
, Qw32_charset_chinesebig5
))
4845 return CHINESEBIG5_CHARSET
;
4846 if (EQ (w32_charset
, Qw32_charset_gb2312
))
4847 return GB2312_CHARSET
;
4848 if (EQ (w32_charset
, Qw32_charset_oem
))
4850 #ifdef JOHAB_CHARSET
4851 if (EQ (w32_charset
, Qw32_charset_johab
))
4852 return JOHAB_CHARSET
;
4853 if (EQ (w32_charset
, Qw32_charset_easteurope
))
4854 return EASTEUROPE_CHARSET
;
4855 if (EQ (w32_charset
, Qw32_charset_turkish
))
4856 return TURKISH_CHARSET
;
4857 if (EQ (w32_charset
, Qw32_charset_baltic
))
4858 return BALTIC_CHARSET
;
4859 if (EQ (w32_charset
, Qw32_charset_russian
))
4860 return RUSSIAN_CHARSET
;
4861 if (EQ (w32_charset
, Qw32_charset_arabic
))
4862 return ARABIC_CHARSET
;
4863 if (EQ (w32_charset
, Qw32_charset_greek
))
4864 return GREEK_CHARSET
;
4865 if (EQ (w32_charset
, Qw32_charset_hebrew
))
4866 return HEBREW_CHARSET
;
4867 if (EQ (w32_charset
, Qw32_charset_vietnamese
))
4868 return VIETNAMESE_CHARSET
;
4869 if (EQ (w32_charset
, Qw32_charset_thai
))
4870 return THAI_CHARSET
;
4871 if (EQ (w32_charset
, Qw32_charset_mac
))
4873 #endif /* JOHAB_CHARSET */
4874 #ifdef UNICODE_CHARSET
4875 if (EQ (w32_charset
, Qw32_charset_unicode
))
4876 return UNICODE_CHARSET
;
4879 return DEFAULT_CHARSET
;
4884 w32_to_x_charset (fncharset
, matching
)
4888 static char buf
[32];
4889 Lisp_Object charset_type
;
4894 /* If fully specified, accept it as it is. Otherwise use a
4896 char *wildcard
= strchr (matching
, '*');
4899 else if (strchr (matching
, '-'))
4902 match_len
= strlen (matching
);
4908 /* Handle startup case of w32-charset-info-alist not
4909 being set up yet. */
4910 if (NILP(Vw32_charset_info_alist
))
4912 charset_type
= Qw32_charset_ansi
;
4914 case DEFAULT_CHARSET
:
4915 charset_type
= Qw32_charset_default
;
4917 case SYMBOL_CHARSET
:
4918 charset_type
= Qw32_charset_symbol
;
4920 case SHIFTJIS_CHARSET
:
4921 charset_type
= Qw32_charset_shiftjis
;
4923 case HANGEUL_CHARSET
:
4924 charset_type
= Qw32_charset_hangeul
;
4926 case GB2312_CHARSET
:
4927 charset_type
= Qw32_charset_gb2312
;
4929 case CHINESEBIG5_CHARSET
:
4930 charset_type
= Qw32_charset_chinesebig5
;
4933 charset_type
= Qw32_charset_oem
;
4936 /* More recent versions of Windows (95 and NT4.0) define more
4938 #ifdef EASTEUROPE_CHARSET
4939 case EASTEUROPE_CHARSET
:
4940 charset_type
= Qw32_charset_easteurope
;
4942 case TURKISH_CHARSET
:
4943 charset_type
= Qw32_charset_turkish
;
4945 case BALTIC_CHARSET
:
4946 charset_type
= Qw32_charset_baltic
;
4948 case RUSSIAN_CHARSET
:
4949 charset_type
= Qw32_charset_russian
;
4951 case ARABIC_CHARSET
:
4952 charset_type
= Qw32_charset_arabic
;
4955 charset_type
= Qw32_charset_greek
;
4957 case HEBREW_CHARSET
:
4958 charset_type
= Qw32_charset_hebrew
;
4960 case VIETNAMESE_CHARSET
:
4961 charset_type
= Qw32_charset_vietnamese
;
4964 charset_type
= Qw32_charset_thai
;
4967 charset_type
= Qw32_charset_mac
;
4970 charset_type
= Qw32_charset_johab
;
4974 #ifdef UNICODE_CHARSET
4975 case UNICODE_CHARSET
:
4976 charset_type
= Qw32_charset_unicode
;
4980 /* Encode numerical value of unknown charset. */
4981 sprintf (buf
, "*-#%u", fncharset
);
4987 char * best_match
= NULL
;
4988 int matching_found
= 0;
4990 /* Look through w32-charset-info-alist for the character set.
4991 Prefer ISO codepages, and prefer lower numbers in the ISO
4992 range. Only return charsets for codepages which are installed.
4994 Format of each entry is
4995 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
4997 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
5000 Lisp_Object w32_charset
;
5001 Lisp_Object codepage
;
5003 Lisp_Object this_entry
= XCAR (rest
);
5005 /* Skip invalid entries in alist. */
5006 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
5007 || !CONSP (XCDR (this_entry
))
5008 || !SYMBOLP (XCAR (XCDR (this_entry
))))
5011 x_charset
= SDATA (XCAR (this_entry
));
5012 w32_charset
= XCAR (XCDR (this_entry
));
5013 codepage
= XCDR (XCDR (this_entry
));
5015 /* Look for Same charset and a valid codepage (or non-int
5016 which means ignore). */
5017 if (EQ (w32_charset
, charset_type
)
5018 && (!INTEGERP (codepage
) || XINT (codepage
) == CP_DEFAULT
5019 || IsValidCodePage (XINT (codepage
))))
5021 /* If we don't have a match already, then this is the
5025 best_match
= x_charset
;
5026 if (matching
&& !strnicmp (x_charset
, matching
, match_len
))
5029 /* If we already found a match for MATCHING, then
5030 only consider other matches. */
5031 else if (matching_found
5032 && strnicmp (x_charset
, matching
, match_len
))
5034 /* If this matches what we want, and the best so far doesn't,
5035 then this is better. */
5036 else if (!matching_found
&& matching
5037 && !strnicmp (x_charset
, matching
, match_len
))
5039 best_match
= x_charset
;
5042 /* If this is fully specified, and the best so far isn't,
5043 then this is better. */
5044 else if ((!strchr (best_match
, '-') && strchr (x_charset
, '-'))
5045 /* If this is an ISO codepage, and the best so far isn't,
5046 then this is better, but only if it fully specifies the
5048 || (strnicmp (best_match
, "iso", 3) != 0
5049 && strnicmp (x_charset
, "iso", 3) == 0
5050 && strchr (x_charset
, '-')))
5051 best_match
= x_charset
;
5052 /* If both are ISO8859 codepages, choose the one with the
5053 lowest number in the encoding field. */
5054 else if (strnicmp (best_match
, "iso8859-", 8) == 0
5055 && strnicmp (x_charset
, "iso8859-", 8) == 0)
5057 int best_enc
= atoi (best_match
+ 8);
5058 int this_enc
= atoi (x_charset
+ 8);
5059 if (this_enc
> 0 && this_enc
< best_enc
)
5060 best_match
= x_charset
;
5065 /* If no match, encode the numeric value. */
5068 sprintf (buf
, "*-#%u", fncharset
);
5072 strncpy (buf
, best_match
, 31);
5073 /* If the charset is not fully specified, put -0 on the end. */
5074 if (!strchr (best_match
, '-'))
5076 int pos
= strlen (best_match
);
5077 /* Charset specifiers shouldn't be very long. If it is a made
5078 up one, truncating it should not do any harm since it isn't
5079 recognized anyway. */
5082 strcpy (buf
+ pos
, "-0");
5090 /* Return all the X charsets that map to a font. */
5092 w32_to_all_x_charsets (fncharset
)
5095 static char buf
[32];
5096 Lisp_Object charset_type
;
5097 Lisp_Object retval
= Qnil
;
5102 /* Handle startup case of w32-charset-info-alist not
5103 being set up yet. */
5104 if (NILP(Vw32_charset_info_alist
))
5105 return Fcons (build_string ("iso8859-1"), Qnil
);
5107 charset_type
= Qw32_charset_ansi
;
5109 case DEFAULT_CHARSET
:
5110 charset_type
= Qw32_charset_default
;
5112 case SYMBOL_CHARSET
:
5113 charset_type
= Qw32_charset_symbol
;
5115 case SHIFTJIS_CHARSET
:
5116 charset_type
= Qw32_charset_shiftjis
;
5118 case HANGEUL_CHARSET
:
5119 charset_type
= Qw32_charset_hangeul
;
5121 case GB2312_CHARSET
:
5122 charset_type
= Qw32_charset_gb2312
;
5124 case CHINESEBIG5_CHARSET
:
5125 charset_type
= Qw32_charset_chinesebig5
;
5128 charset_type
= Qw32_charset_oem
;
5131 /* More recent versions of Windows (95 and NT4.0) define more
5133 #ifdef EASTEUROPE_CHARSET
5134 case EASTEUROPE_CHARSET
:
5135 charset_type
= Qw32_charset_easteurope
;
5137 case TURKISH_CHARSET
:
5138 charset_type
= Qw32_charset_turkish
;
5140 case BALTIC_CHARSET
:
5141 charset_type
= Qw32_charset_baltic
;
5143 case RUSSIAN_CHARSET
:
5144 charset_type
= Qw32_charset_russian
;
5146 case ARABIC_CHARSET
:
5147 charset_type
= Qw32_charset_arabic
;
5150 charset_type
= Qw32_charset_greek
;
5152 case HEBREW_CHARSET
:
5153 charset_type
= Qw32_charset_hebrew
;
5155 case VIETNAMESE_CHARSET
:
5156 charset_type
= Qw32_charset_vietnamese
;
5159 charset_type
= Qw32_charset_thai
;
5162 charset_type
= Qw32_charset_mac
;
5165 charset_type
= Qw32_charset_johab
;
5169 #ifdef UNICODE_CHARSET
5170 case UNICODE_CHARSET
:
5171 charset_type
= Qw32_charset_unicode
;
5175 /* Encode numerical value of unknown charset. */
5176 sprintf (buf
, "*-#%u", fncharset
);
5177 return Fcons (build_string (buf
), Qnil
);
5182 /* Look through w32-charset-info-alist for the character set.
5183 Only return fully specified charsets for codepages which are
5186 Format of each entry in Vw32_charset_info_alist is
5187 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5189 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
5191 Lisp_Object x_charset
;
5192 Lisp_Object w32_charset
;
5193 Lisp_Object codepage
;
5195 Lisp_Object this_entry
= XCAR (rest
);
5197 /* Skip invalid entries in alist. */
5198 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
5199 || !CONSP (XCDR (this_entry
))
5200 || !SYMBOLP (XCAR (XCDR (this_entry
))))
5203 x_charset
= XCAR (this_entry
);
5204 w32_charset
= XCAR (XCDR (this_entry
));
5205 codepage
= XCDR (XCDR (this_entry
));
5207 if (!strchr (SDATA (x_charset
), '-'))
5210 /* Look for Same charset and a valid codepage (or non-int
5211 which means ignore). */
5212 if (EQ (w32_charset
, charset_type
)
5213 && (!INTEGERP (codepage
) || XINT (codepage
) == CP_DEFAULT
5214 || IsValidCodePage (XINT (codepage
))))
5216 retval
= Fcons (x_charset
, retval
);
5220 /* If no match, encode the numeric value. */
5223 sprintf (buf
, "*-#%u", fncharset
);
5224 return Fcons (build_string (buf
), Qnil
);
5231 /* Get the Windows codepage corresponding to the specified font. The
5232 charset info in the font name is used to look up
5233 w32-charset-to-codepage-alist. */
5235 w32_codepage_for_font (char *fontname
)
5237 Lisp_Object codepage
, entry
;
5238 char *charset_str
, *charset
, *end
;
5240 /* Extract charset part of font string. */
5241 charset
= xlfd_charset_of_font (fontname
);
5246 charset_str
= (char *) alloca (strlen (charset
) + 1);
5247 strcpy (charset_str
, charset
);
5250 /* Remove leading "*-". */
5251 if (strncmp ("*-", charset_str
, 2) == 0)
5252 charset
= charset_str
+ 2;
5255 charset
= charset_str
;
5257 /* Stop match at wildcard (including preceding '-'). */
5258 if (end
= strchr (charset
, '*'))
5260 if (end
> charset
&& *(end
-1) == '-')
5265 if (!strcmp (charset
, "iso10646"))
5268 if (NILP (Vw32_charset_info_alist
))
5271 entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
5275 codepage
= Fcdr (Fcdr (entry
));
5277 if (NILP (codepage
))
5279 else if (XFASTINT (codepage
) == XFASTINT (Qt
))
5281 else if (INTEGERP (codepage
))
5282 return XINT (codepage
);
5289 w32_to_x_font (lplogfont
, lpxstr
, len
, specific_charset
)
5290 LOGFONT
* lplogfont
;
5293 char * specific_charset
;
5297 char height_pixels
[8];
5299 char width_pixels
[8];
5300 char *fontname_dash
;
5301 int display_resy
= (int) one_w32_display_info
.resy
;
5302 int display_resx
= (int) one_w32_display_info
.resx
;
5303 struct coding_system coding
;
5305 if (!lpxstr
) abort ();
5310 if (lplogfont
->lfOutPrecision
== OUT_STRING_PRECIS
)
5311 fonttype
= "raster";
5312 else if (lplogfont
->lfOutPrecision
== OUT_STROKE_PRECIS
)
5313 fonttype
= "outline";
5315 fonttype
= "unknown";
5317 setup_coding_system (Fcheck_coding_system (Vlocale_coding_system
),
5319 coding
.src_multibyte
= 0;
5320 coding
.dst_multibyte
= 1;
5321 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
5322 /* We explicitely disable composition handling because selection
5323 data should not contain any composition sequence. */
5324 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
5326 coding
.dst_bytes
= LF_FACESIZE
* 2;
5327 coding
.destination
= (unsigned char *) xmalloc (coding
.dst_bytes
+ 1);
5328 decode_coding_c_string (&coding
, lplogfont
->lfFaceName
,
5329 strlen(lplogfont
->lfFaceName
), Qnil
);
5330 fontname
= coding
.destination
;
5332 *(fontname
+ coding
.produced
) = '\0';
5334 /* Replace dashes with underscores so the dashes are not
5336 fontname_dash
= fontname
;
5337 while (fontname_dash
= strchr (fontname_dash
, '-'))
5338 *fontname_dash
= '_';
5340 if (lplogfont
->lfHeight
)
5342 sprintf (height_pixels
, "%u", abs (lplogfont
->lfHeight
));
5343 sprintf (height_dpi
, "%u",
5344 abs (lplogfont
->lfHeight
) * 720 / display_resy
);
5348 strcpy (height_pixels
, "*");
5349 strcpy (height_dpi
, "*");
5352 #if 0 /* Never put the width in the xfld. It fails on fonts with
5353 double-width characters. */
5354 if (lplogfont
->lfWidth
)
5355 sprintf (width_pixels
, "%u", lplogfont
->lfWidth
* 10);
5358 strcpy (width_pixels
, "*");
5360 _snprintf (lpxstr
, len
- 1,
5361 "-%s-%s-%s-%c-normal-normal-%s-%s-%d-%d-%c-%s-%s",
5362 fonttype
, /* foundry */
5363 fontname
, /* family */
5364 w32_to_x_weight (lplogfont
->lfWeight
), /* weight */
5365 lplogfont
->lfItalic
?'i':'r', /* slant */
5367 /* add style name */
5368 height_pixels
, /* pixel size */
5369 height_dpi
, /* point size */
5370 display_resx
, /* resx */
5371 display_resy
, /* resy */
5372 ((lplogfont
->lfPitchAndFamily
& 0x3) == VARIABLE_PITCH
)
5373 ? 'p' : 'c', /* spacing */
5374 width_pixels
, /* avg width */
5375 w32_to_x_charset (lplogfont
->lfCharSet
, specific_charset
)
5376 /* charset registry and encoding */
5379 lpxstr
[len
- 1] = 0; /* just to be sure */
5384 x_to_w32_font (lpxstr
, lplogfont
)
5386 LOGFONT
* lplogfont
;
5388 struct coding_system coding
;
5390 if (!lplogfont
) return (FALSE
);
5392 memset (lplogfont
, 0, sizeof (*lplogfont
));
5394 /* Set default value for each field. */
5396 lplogfont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
5397 lplogfont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
5398 lplogfont
->lfQuality
= DEFAULT_QUALITY
;
5400 /* go for maximum quality */
5401 lplogfont
->lfOutPrecision
= OUT_STROKE_PRECIS
;
5402 lplogfont
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
5403 lplogfont
->lfQuality
= PROOF_QUALITY
;
5406 lplogfont
->lfCharSet
= DEFAULT_CHARSET
;
5407 lplogfont
->lfWeight
= FW_DONTCARE
;
5408 lplogfont
->lfPitchAndFamily
= DEFAULT_PITCH
| FF_DONTCARE
;
5413 /* Provide a simple escape mechanism for specifying Windows font names
5414 * directly -- if font spec does not beginning with '-', assume this
5416 * "<font name>[:height in pixels[:width in pixels[:weight]]]"
5422 char name
[50], weight
[20], slant
, pitch
, pixels
[10], height
[10],
5423 width
[10], resy
[10], remainder
[50];
5425 int dpi
= (int) one_w32_display_info
.resy
;
5427 fields
= sscanf (lpxstr
,
5428 "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%49s",
5429 name
, weight
, &slant
, pixels
, height
, resy
, &pitch
, width
, remainder
);
5433 /* In the general case when wildcards cover more than one field,
5434 we don't know which field is which, so don't fill any in.
5435 However, we need to cope with this particular form, which is
5436 generated by font_list_1 (invoked by try_font_list):
5437 "-raster-6x10-*-gb2312*-*"
5438 and make sure to correctly parse the charset field. */
5441 fields
= sscanf (lpxstr
,
5442 "-%*[^-]-%49[^-]-*-%49s",
5445 else if (fields
< 9)
5451 if (fields
> 0 && name
[0] != '*')
5453 Lisp_Object string
= build_string (name
);
5455 (Fcheck_coding_system (Vlocale_coding_system
), &coding
);
5456 coding
.mode
|= (CODING_MODE_SAFE_ENCODING
| CODING_MODE_LAST_BLOCK
);
5457 /* Disable composition/charset annotation. */
5458 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
5459 coding
.dst_bytes
= SCHARS (string
) * 2;
5461 coding
.destination
= (unsigned char *) xmalloc (coding
.dst_bytes
);
5462 encode_coding_object (&coding
, string
, 0, 0,
5463 SCHARS (string
), SBYTES (string
), Qnil
);
5464 if (coding
.produced
>= LF_FACESIZE
)
5465 coding
.produced
= LF_FACESIZE
- 1;
5467 coding
.destination
[coding
.produced
] = '\0';
5469 strcpy (lplogfont
->lfFaceName
, coding
.destination
);
5470 xfree (coding
.destination
);
5474 lplogfont
->lfFaceName
[0] = '\0';
5479 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
5483 lplogfont
->lfItalic
= (fields
> 0 && slant
== 'i');
5487 if (fields
> 0 && pixels
[0] != '*')
5488 lplogfont
->lfHeight
= atoi (pixels
);
5492 if (fields
> 0 && resy
[0] != '*')
5495 if (tem
> 0) dpi
= tem
;
5498 if (fields
> -1 && lplogfont
->lfHeight
== 0 && height
[0] != '*')
5499 lplogfont
->lfHeight
= atoi (height
) * dpi
/ 720;
5502 lplogfont
->lfPitchAndFamily
=
5503 (fields
> 0 && pitch
== 'p') ? VARIABLE_PITCH
: FIXED_PITCH
;
5507 if (fields
> 0 && width
[0] != '*')
5508 lplogfont
->lfWidth
= atoi (width
) / 10;
5512 /* Strip the trailing '-' if present. (it shouldn't be, as it
5513 fails the test against xlfd-tight-regexp in fontset.el). */
5515 int len
= strlen (remainder
);
5516 if (len
> 0 && remainder
[len
-1] == '-')
5517 remainder
[len
-1] = 0;
5519 encoding
= remainder
;
5521 if (strncmp (encoding
, "*-", 2) == 0)
5524 lplogfont
->lfCharSet
= x_to_w32_charset (encoding
);
5529 char name
[100], height
[10], width
[10], weight
[20];
5531 fields
= sscanf (lpxstr
,
5532 "%99[^:]:%9[^:]:%9[^:]:%19s",
5533 name
, height
, width
, weight
);
5535 if (fields
== EOF
) return (FALSE
);
5539 strncpy (lplogfont
->lfFaceName
,name
, LF_FACESIZE
);
5540 lplogfont
->lfFaceName
[LF_FACESIZE
-1] = 0;
5544 lplogfont
->lfFaceName
[0] = 0;
5550 lplogfont
->lfHeight
= atoi (height
);
5555 lplogfont
->lfWidth
= atoi (width
);
5559 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
5562 /* This makes TrueType fonts work better. */
5563 lplogfont
->lfHeight
= - abs (lplogfont
->lfHeight
);
5568 /* Strip the pixel height and point height from the given xlfd, and
5569 return the pixel height. If no pixel height is specified, calculate
5570 one from the point height, or if that isn't defined either, return
5571 0 (which usually signifies a scalable font).
5574 xlfd_strip_height (char *fontname
)
5576 int pixel_height
, field_number
;
5577 char *read_from
, *write_to
;
5581 pixel_height
= field_number
= 0;
5584 /* Look for height fields. */
5585 for (read_from
= fontname
; *read_from
; read_from
++)
5587 if (*read_from
== '-')
5590 if (field_number
== 7) /* Pixel height. */
5593 write_to
= read_from
;
5595 /* Find end of field. */
5596 for (;*read_from
&& *read_from
!= '-'; read_from
++)
5599 /* Split the fontname at end of field. */
5605 pixel_height
= atoi (write_to
);
5606 /* Blank out field. */
5607 if (read_from
> write_to
)
5612 /* If the pixel height field is at the end (partial xlfd),
5615 return pixel_height
;
5617 /* If we got a pixel height, the point height can be
5618 ignored. Just blank it out and break now. */
5621 /* Find end of point size field. */
5622 for (; *read_from
&& *read_from
!= '-'; read_from
++)
5628 /* Blank out the point size field. */
5629 if (read_from
> write_to
)
5635 return pixel_height
;
5639 /* If the point height is already blank, break now. */
5640 if (*read_from
== '-')
5646 else if (field_number
== 8)
5648 /* If we didn't get a pixel height, try to get the point
5649 height and convert that. */
5651 char *point_size_start
= read_from
++;
5653 /* Find end of field. */
5654 for (; *read_from
&& *read_from
!= '-'; read_from
++)
5663 point_size
= atoi (point_size_start
);
5665 /* Convert to pixel height. */
5666 pixel_height
= point_size
5667 * one_w32_display_info
.height_in
/ 720;
5669 /* Blank out this field and break. */
5677 /* Shift the rest of the font spec into place. */
5678 if (write_to
&& read_from
> write_to
)
5680 for (; *read_from
; read_from
++, write_to
++)
5681 *write_to
= *read_from
;
5685 return pixel_height
;
5688 /* Assume parameter 1 is fully qualified, no wildcards. */
5690 w32_font_match (fontname
, pattern
)
5695 char *font_name_copy
;
5696 char *regex
= alloca (strlen (pattern
) * 2 + 3);
5698 font_name_copy
= alloca (strlen (fontname
) + 1);
5699 strcpy (font_name_copy
, fontname
);
5704 /* Turn pattern into a regexp and do a regexp match. */
5705 for (; *pattern
; pattern
++)
5707 if (*pattern
== '?')
5709 else if (*pattern
== '*')
5720 /* Strip out font heights and compare them seperately, since
5721 rounding error can cause mismatches. This also allows a
5722 comparison between a font that declares only a pixel height and a
5723 pattern that declares the point height.
5726 int font_height
, pattern_height
;
5728 font_height
= xlfd_strip_height (font_name_copy
);
5729 pattern_height
= xlfd_strip_height (regex
);
5731 /* Compare now, and don't bother doing expensive regexp matching
5732 if the heights differ. */
5733 if (font_height
&& pattern_height
&& (font_height
!= pattern_height
))
5737 return (fast_string_match_ignore_case (build_string (regex
),
5738 build_string(font_name_copy
)) >= 0);
5741 /* Callback functions, and a structure holding info they need, for
5742 listing system fonts on W32. We need one set of functions to do the
5743 job properly, but these don't work on NT 3.51 and earlier, so we
5744 have a second set which don't handle character sets properly to
5747 In both cases, there are two passes made. The first pass gets one
5748 font from each family, the second pass lists all the fonts from
5751 typedef struct enumfont_t
5756 XFontStruct
*size_ref
;
5757 Lisp_Object pattern
;
5763 enum_font_maybe_add_to_list (enumfont_t
*, LOGFONT
*, char *, Lisp_Object
);
5767 enum_font_cb2 (lplf
, lptm
, FontType
, lpef
)
5769 NEWTEXTMETRIC
* lptm
;
5773 /* Ignore struck out and underlined versions of fonts. */
5774 if (lplf
->elfLogFont
.lfStrikeOut
|| lplf
->elfLogFont
.lfUnderline
)
5777 /* Only return fonts with names starting with @ if they were
5778 explicitly specified, since Microsoft uses an initial @ to
5779 denote fonts for vertical writing, without providing a more
5780 convenient way of identifying them. */
5781 if (lplf
->elfLogFont
.lfFaceName
[0] == '@'
5782 && lpef
->logfont
.lfFaceName
[0] != '@')
5785 /* Check that the character set matches if it was specified */
5786 if (lpef
->logfont
.lfCharSet
!= DEFAULT_CHARSET
&&
5787 lplf
->elfLogFont
.lfCharSet
!= lpef
->logfont
.lfCharSet
)
5790 if (FontType
== RASTER_FONTTYPE
)
5792 /* DBCS raster fonts have problems displaying, so skip them. */
5793 int charset
= lplf
->elfLogFont
.lfCharSet
;
5794 if (charset
== SHIFTJIS_CHARSET
5795 || charset
== HANGEUL_CHARSET
5796 || charset
== CHINESEBIG5_CHARSET
5797 || charset
== GB2312_CHARSET
5798 #ifdef JOHAB_CHARSET
5799 || charset
== JOHAB_CHARSET
5807 Lisp_Object width
= Qnil
;
5808 Lisp_Object charset_list
= Qnil
;
5809 char *charset
= NULL
;
5811 /* Truetype fonts do not report their true metrics until loaded */
5812 if (FontType
!= RASTER_FONTTYPE
)
5814 if (!NILP (lpef
->pattern
))
5816 /* Scalable fonts are as big as you want them to be. */
5817 lplf
->elfLogFont
.lfHeight
= lpef
->logfont
.lfHeight
;
5818 lplf
->elfLogFont
.lfWidth
= lpef
->logfont
.lfWidth
;
5819 width
= make_number (lpef
->logfont
.lfWidth
);
5823 lplf
->elfLogFont
.lfHeight
= 0;
5824 lplf
->elfLogFont
.lfWidth
= 0;
5828 /* Make sure the height used here is the same as everywhere
5829 else (ie character height, not cell height). */
5830 if (lplf
->elfLogFont
.lfHeight
> 0)
5832 /* lptm can be trusted for RASTER fonts, but not scalable ones. */
5833 if (FontType
== RASTER_FONTTYPE
)
5834 lplf
->elfLogFont
.lfHeight
= lptm
->tmInternalLeading
- lptm
->tmHeight
;
5836 lplf
->elfLogFont
.lfHeight
= -lplf
->elfLogFont
.lfHeight
;
5839 if (!NILP (lpef
->pattern
))
5841 charset
= xlfd_charset_of_font (SDATA (lpef
->pattern
));
5843 /* We already checked charsets above, but DEFAULT_CHARSET
5844 slipped through. So only allow exact matches for DEFAULT_CHARSET. */
5846 && strncmp (charset
, "*-*", 3) != 0
5847 && lpef
->logfont
.lfCharSet
== DEFAULT_CHARSET
5848 && strcmp (charset
, w32_to_x_charset (DEFAULT_CHARSET
, NULL
)) != 0)
5853 charset_list
= Fcons (build_string (charset
), Qnil
);
5855 /* Always prefer unicode. */
5857 = Fcons (build_string ("iso10646-1"),
5858 w32_to_all_x_charsets (lplf
->elfLogFont
.lfCharSet
));
5860 /* Loop through the charsets. */
5861 for ( ; CONSP (charset_list
); charset_list
= Fcdr (charset_list
))
5863 Lisp_Object this_charset
= Fcar (charset_list
);
5864 charset
= SDATA (this_charset
);
5866 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5869 /* List bold and italic variations if w32-enable-synthesized-fonts
5870 is non-nil and this is a plain font. */
5871 if (w32_enable_synthesized_fonts
5872 && lplf
->elfLogFont
.lfWeight
== FW_NORMAL
5873 && lplf
->elfLogFont
.lfItalic
== FALSE
)
5876 lplf
->elfLogFont
.lfWeight
= FW_BOLD
;
5877 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5880 lplf
->elfLogFont
.lfItalic
= TRUE
;
5881 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5884 lplf
->elfLogFont
.lfWeight
= FW_NORMAL
;
5885 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5895 enum_font_maybe_add_to_list (lpef
, logfont
, match_charset
, width
)
5898 char * match_charset
;
5903 if (!w32_to_x_font (logfont
, buf
, 100, match_charset
))
5906 if (NILP (lpef
->pattern
)
5907 || w32_font_match (buf
, SDATA (lpef
->pattern
)))
5909 /* Check if we already listed this font. This may happen if
5910 w32_enable_synthesized_fonts is non-nil, and there are real
5911 bold and italic versions of the font. */
5912 Lisp_Object font_name
= build_string (buf
);
5913 if (NILP (Fmember (font_name
, lpef
->list
)))
5915 Lisp_Object entry
= Fcons (font_name
, width
);
5916 lpef
->list
= Fcons (entry
, lpef
->list
);
5924 enum_font_cb1 (lplf
, lptm
, FontType
, lpef
)
5926 NEWTEXTMETRIC
* lptm
;
5930 return EnumFontFamilies (lpef
->hdc
,
5931 lplf
->elfLogFont
.lfFaceName
,
5932 (FONTENUMPROC
) enum_font_cb2
,
5938 enum_fontex_cb2 (lplf
, lptm
, font_type
, lpef
)
5939 ENUMLOGFONTEX
* lplf
;
5940 NEWTEXTMETRICEX
* lptm
;
5944 /* We are not interested in the extra info we get back from the 'Ex
5945 version - only the fact that we get character set variations
5946 enumerated seperately. */
5947 return enum_font_cb2 ((ENUMLOGFONT
*) lplf
, (NEWTEXTMETRIC
*) lptm
,
5952 enum_fontex_cb1 (lplf
, lptm
, font_type
, lpef
)
5953 ENUMLOGFONTEX
* lplf
;
5954 NEWTEXTMETRICEX
* lptm
;
5958 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
5959 FARPROC enum_font_families_ex
5960 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
5961 /* We don't really expect EnumFontFamiliesEx to disappear once we
5962 get here, so don't bother handling it gracefully. */
5963 if (enum_font_families_ex
== NULL
)
5964 error ("gdi32.dll has disappeared!");
5965 return enum_font_families_ex (lpef
->hdc
,
5967 (FONTENUMPROC
) enum_fontex_cb2
,
5971 /* Interface to fontset handler. (adapted from mw32font.c in Meadow
5972 and xterm.c in Emacs 20.3) */
5974 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
)
5976 char *fontname
, *ptnstr
;
5977 Lisp_Object list
, tem
, newlist
= Qnil
;
5980 list
= Vw32_bdf_filename_alist
;
5981 ptnstr
= SDATA (pattern
);
5983 for ( ; CONSP (list
); list
= XCDR (list
))
5987 fontname
= SDATA (XCAR (tem
));
5988 else if (STRINGP (tem
))
5989 fontname
= SDATA (tem
);
5993 if (w32_font_match (fontname
, ptnstr
))
5995 newlist
= Fcons (XCAR (tem
), newlist
);
5997 if (max_names
>= 0 && n_fonts
>= max_names
)
6006 /* Return a list of names of available fonts matching PATTERN on frame
6007 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
6008 to be listed. Frame F NULL means we have not yet created any
6009 frame, which means we can't get proper size info, as we don't have
6010 a device context to use for GetTextMetrics.
6011 MAXNAMES sets a limit on how many fonts to match. If MAXNAMES is
6012 negative, then all matching fonts are returned. */
6015 w32_list_fonts (f
, pattern
, size
, maxnames
)
6017 Lisp_Object pattern
;
6021 Lisp_Object patterns
, key
= Qnil
, tem
, tpat
;
6022 Lisp_Object list
= Qnil
, newlist
= Qnil
, second_best
= Qnil
;
6023 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
6026 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
6027 if (NILP (patterns
))
6028 patterns
= Fcons (pattern
, Qnil
);
6030 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
6035 tpat
= XCAR (patterns
);
6037 if (!STRINGP (tpat
))
6040 /* Avoid expensive EnumFontFamilies functions if we are not
6041 going to be able to output one of these anyway. */
6042 codepage
= w32_codepage_for_font (SDATA (tpat
));
6043 if (codepage
!= CP_8BIT
&& codepage
!= CP_UNICODE
6044 && codepage
!= CP_DEFAULT
&& codepage
!= CP_UNKNOWN
6045 && !IsValidCodePage(codepage
))
6048 /* See if we cached the result for this particular query.
6049 The cache is an alist of the form:
6050 ((PATTERN (FONTNAME . WIDTH) ...) ...)
6052 if (tem
= XCDR (dpyinfo
->name_list_element
),
6053 !NILP (list
= Fassoc (tpat
, tem
)))
6055 list
= Fcdr_safe (list
);
6056 /* We have a cached list. Don't have to get the list again. */
6061 /* At first, put PATTERN in the cache. */
6066 /* Use EnumFontFamiliesEx where it is available, as it knows
6067 about character sets. Fall back to EnumFontFamilies for
6068 older versions of NT that don't support the 'Ex function. */
6069 x_to_w32_font (SDATA (tpat
), &ef
.logfont
);
6071 LOGFONT font_match_pattern
;
6072 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6073 FARPROC enum_font_families_ex
6074 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6076 /* We do our own pattern matching so we can handle wildcards. */
6077 font_match_pattern
.lfFaceName
[0] = 0;
6078 font_match_pattern
.lfPitchAndFamily
= 0;
6079 /* We can use the charset, because if it is a wildcard it will
6080 be DEFAULT_CHARSET anyway. */
6081 font_match_pattern
.lfCharSet
= ef
.logfont
.lfCharSet
;
6083 ef
.hdc
= GetDC (dpyinfo
->root_window
);
6085 if (enum_font_families_ex
)
6086 enum_font_families_ex (ef
.hdc
,
6087 &font_match_pattern
,
6088 (FONTENUMPROC
) enum_fontex_cb1
,
6091 EnumFontFamilies (ef
.hdc
, NULL
, (FONTENUMPROC
) enum_font_cb1
,
6094 ReleaseDC (dpyinfo
->root_window
, ef
.hdc
);
6100 /* Make a list of the fonts we got back.
6101 Store that in the font cache for the display. */
6102 XSETCDR (dpyinfo
->name_list_element
,
6103 Fcons (Fcons (tpat
, list
),
6104 XCDR (dpyinfo
->name_list_element
)));
6107 if (NILP (list
)) continue; /* Try the remaining alternatives. */
6109 newlist
= second_best
= Qnil
;
6111 /* Make a list of the fonts that have the right width. */
6112 for (; CONSP (list
); list
= XCDR (list
))
6119 if (NILP (XCAR (tem
)))
6123 newlist
= Fcons (XCAR (tem
), newlist
);
6125 if (maxnames
>= 0 && n_fonts
>= maxnames
)
6130 if (!INTEGERP (XCDR (tem
)))
6132 /* Since we don't yet know the size of the font, we must
6133 load it and try GetTextMetrics. */
6134 W32FontStruct thisinfo
;
6139 if (!x_to_w32_font (SDATA (XCAR (tem
)), &lf
))
6143 thisinfo
.bdf
= NULL
;
6144 thisinfo
.hfont
= CreateFontIndirect (&lf
);
6145 if (thisinfo
.hfont
== NULL
)
6148 hdc
= GetDC (dpyinfo
->root_window
);
6149 oldobj
= SelectObject (hdc
, thisinfo
.hfont
);
6150 if (GetTextMetrics (hdc
, &thisinfo
.tm
))
6151 XSETCDR (tem
, make_number (FONT_WIDTH (&thisinfo
)));
6153 XSETCDR (tem
, make_number (0));
6154 SelectObject (hdc
, oldobj
);
6155 ReleaseDC (dpyinfo
->root_window
, hdc
);
6156 DeleteObject(thisinfo
.hfont
);
6159 found_size
= XINT (XCDR (tem
));
6160 if (found_size
== size
)
6162 newlist
= Fcons (XCAR (tem
), newlist
);
6164 if (maxnames
>= 0 && n_fonts
>= maxnames
)
6167 /* keep track of the closest matching size in case
6168 no exact match is found. */
6169 else if (found_size
> 0)
6171 if (NILP (second_best
))
6174 else if (found_size
< size
)
6176 if (XINT (XCDR (second_best
)) > size
6177 || XINT (XCDR (second_best
)) < found_size
)
6182 if (XINT (XCDR (second_best
)) > size
6183 && XINT (XCDR (second_best
)) >
6190 if (!NILP (newlist
))
6192 else if (!NILP (second_best
))
6194 newlist
= Fcons (XCAR (second_best
), Qnil
);
6199 /* Include any bdf fonts. */
6200 if (n_fonts
< maxnames
|| maxnames
< 0)
6202 Lisp_Object combined
[2];
6203 combined
[0] = w32_list_bdf_fonts (pattern
, maxnames
- n_fonts
);
6204 combined
[1] = newlist
;
6205 newlist
= Fnconc(2, combined
);
6212 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
6214 w32_get_font_info (f
, font_idx
)
6218 return (FRAME_W32_FONT_TABLE (f
) + font_idx
);
6223 w32_query_font (struct frame
*f
, char *fontname
)
6226 struct font_info
*pfi
;
6228 pfi
= FRAME_W32_FONT_TABLE (f
);
6230 for (i
= 0; i
< one_w32_display_info
.n_fonts
;i
++, pfi
++)
6232 if (strcmp(pfi
->name
, fontname
) == 0) return pfi
;
6238 /* Find a CCL program for a font specified by FONTP, and set the member
6239 `encoder' of the structure. */
6242 w32_find_ccl_program (fontp
)
6243 struct font_info
*fontp
;
6245 Lisp_Object list
, elt
;
6247 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
6251 && STRINGP (XCAR (elt
))
6252 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
6258 struct ccl_program
*ccl
6259 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
6261 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
6264 fontp
->font_encoder
= ccl
;
6268 /* directory-files from dired.c. */
6269 Lisp_Object Fdirectory_files
P_((Lisp_Object
, Lisp_Object
, Lisp_Object
, Lisp_Object
));
6272 /* Find BDF files in a specified directory. (use GCPRO when calling,
6273 as this calls lisp to get a directory listing). */
6275 w32_find_bdf_fonts_in_dir (Lisp_Object directory
)
6277 Lisp_Object filelist
, list
= Qnil
;
6280 if (!STRINGP(directory
))
6283 filelist
= Fdirectory_files (directory
, Qt
,
6284 build_string (".*\\.[bB][dD][fF]"), Qt
);
6286 for ( ; CONSP(filelist
); filelist
= XCDR (filelist
))
6288 Lisp_Object filename
= XCAR (filelist
);
6289 if (w32_BDF_to_x_font (SDATA (filename
), fontname
, 100))
6290 store_in_alist (&list
, build_string (fontname
), filename
);
6295 DEFUN ("w32-find-bdf-fonts", Fw32_find_bdf_fonts
, Sw32_find_bdf_fonts
,
6297 doc
: /* Return a list of BDF fonts in DIRECTORY.
6298 The list is suitable for appending to `w32-bdf-filename-alist'.
6299 Fonts which do not contain an xlfd description will not be included
6300 in the list. DIRECTORY may be a list of directories. */)
6302 Lisp_Object directory
;
6304 Lisp_Object list
= Qnil
;
6305 struct gcpro gcpro1
, gcpro2
;
6307 if (!CONSP (directory
))
6308 return w32_find_bdf_fonts_in_dir (directory
);
6310 for ( ; CONSP (directory
); directory
= XCDR (directory
))
6312 Lisp_Object pair
[2];
6315 GCPRO2 (directory
, list
);
6316 pair
[1] = w32_find_bdf_fonts_in_dir( XCAR (directory
) );
6317 list
= Fnconc( 2, pair
);
6324 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
6325 doc
: /* Internal function called by `color-defined-p', which see. */)
6327 Lisp_Object color
, frame
;
6330 FRAME_PTR f
= check_x_frame (frame
);
6332 CHECK_STRING (color
);
6334 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
6340 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
6341 doc
: /* Internal function called by `color-values', which see. */)
6343 Lisp_Object color
, frame
;
6346 FRAME_PTR f
= check_x_frame (frame
);
6348 CHECK_STRING (color
);
6350 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
6354 rgb
[0] = make_number ((GetRValue (foo
.pixel
) << 8)
6355 | GetRValue (foo
.pixel
));
6356 rgb
[1] = make_number ((GetGValue (foo
.pixel
) << 8)
6357 | GetGValue (foo
.pixel
));
6358 rgb
[2] = make_number ((GetBValue (foo
.pixel
) << 8)
6359 | GetBValue (foo
.pixel
));
6360 return Flist (3, rgb
);
6366 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
6367 doc
: /* Internal function called by `display-color-p', which see. */)
6369 Lisp_Object display
;
6371 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6373 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
6379 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
,
6380 Sx_display_grayscale_p
, 0, 1, 0,
6381 doc
: /* Return t if DISPLAY supports shades of gray.
6382 Note that color displays do support shades of gray.
6383 The optional argument DISPLAY specifies which display to ask about.
6384 DISPLAY should be either a frame or a display name (a string).
6385 If omitted or nil, that stands for the selected frame's display. */)
6387 Lisp_Object display
;
6389 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6391 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
6397 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
,
6398 Sx_display_pixel_width
, 0, 1, 0,
6399 doc
: /* Returns the width in pixels of DISPLAY.
6400 The optional argument DISPLAY specifies which display to ask about.
6401 DISPLAY should be either a frame or a display name (a string).
6402 If omitted or nil, that stands for the selected frame's display. */)
6404 Lisp_Object display
;
6406 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6408 return make_number (dpyinfo
->width
);
6411 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
6412 Sx_display_pixel_height
, 0, 1, 0,
6413 doc
: /* Returns the height in pixels of DISPLAY.
6414 The optional argument DISPLAY specifies which display to ask about.
6415 DISPLAY should be either a frame or a display name (a string).
6416 If omitted or nil, that stands for the selected frame's display. */)
6418 Lisp_Object display
;
6420 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6422 return make_number (dpyinfo
->height
);
6425 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
6427 doc
: /* Returns the number of bitplanes of DISPLAY.
6428 The optional argument DISPLAY specifies which display to ask about.
6429 DISPLAY should be either a frame or a display name (a string).
6430 If omitted or nil, that stands for the selected frame's display. */)
6432 Lisp_Object display
;
6434 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6436 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
6439 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
6441 doc
: /* Returns the number of color cells of DISPLAY.
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 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6452 hdc
= GetDC (dpyinfo
->root_window
);
6453 if (dpyinfo
->has_palette
)
6454 cap
= GetDeviceCaps (hdc
, SIZEPALETTE
);
6456 cap
= GetDeviceCaps (hdc
, NUMCOLORS
);
6458 /* We force 24+ bit depths to 24-bit, both to prevent an overflow
6459 and because probably is more meaningful on Windows anyway */
6461 cap
= 1 << min(dpyinfo
->n_planes
* dpyinfo
->n_cbits
, 24);
6463 ReleaseDC (dpyinfo
->root_window
, hdc
);
6465 return make_number (cap
);
6468 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
6469 Sx_server_max_request_size
,
6471 doc
: /* Returns the maximum request size of the server of DISPLAY.
6472 The optional argument DISPLAY specifies which display to ask about.
6473 DISPLAY should be either a frame or a display name (a string).
6474 If omitted or nil, that stands for the selected frame's display. */)
6476 Lisp_Object display
;
6478 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6480 return make_number (1);
6483 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
6484 doc
: /* Returns the "vendor ID" string of the W32 system (Microsoft).
6485 The optional argument DISPLAY specifies which display to ask about.
6486 DISPLAY should be either a frame or a display name (a string).
6487 If omitted or nil, that stands for the selected frame's display. */)
6489 Lisp_Object display
;
6491 return build_string ("Microsoft Corp.");
6494 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
6495 doc
: /* Returns the version numbers of the server of DISPLAY.
6496 The value is a list of three integers: the major and minor
6497 version numbers of the X Protocol in use, and the distributor-specific release
6498 number. See also the function `x-server-vendor'.
6500 The optional argument DISPLAY specifies which display to ask about.
6501 DISPLAY should be either a frame or a display name (a string).
6502 If omitted or nil, that stands for the selected frame's display. */)
6504 Lisp_Object display
;
6506 return Fcons (make_number (w32_major_version
),
6507 Fcons (make_number (w32_minor_version
),
6508 Fcons (make_number (w32_build_number
), Qnil
)));
6511 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
6512 doc
: /* Returns the number of screens on the server of DISPLAY.
6513 The optional argument DISPLAY specifies which display to ask about.
6514 DISPLAY should be either a frame or a display name (a string).
6515 If omitted or nil, that stands for the selected frame's display. */)
6517 Lisp_Object display
;
6519 return make_number (1);
6522 DEFUN ("x-display-mm-height", Fx_display_mm_height
,
6523 Sx_display_mm_height
, 0, 1, 0,
6524 doc
: /* Returns the height in millimeters of DISPLAY.
6525 The optional argument DISPLAY specifies which display to ask about.
6526 DISPLAY should be either a frame or a display name (a string).
6527 If omitted or nil, that stands for the selected frame's display. */)
6529 Lisp_Object display
;
6531 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6535 hdc
= GetDC (dpyinfo
->root_window
);
6537 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
6539 ReleaseDC (dpyinfo
->root_window
, hdc
);
6541 return make_number (cap
);
6544 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
6545 doc
: /* Returns the width in millimeters of DISPLAY.
6546 The optional argument DISPLAY specifies which display to ask about.
6547 DISPLAY should be either a frame or a display name (a string).
6548 If omitted or nil, that stands for the selected frame's display. */)
6550 Lisp_Object display
;
6552 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6557 hdc
= GetDC (dpyinfo
->root_window
);
6559 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
6561 ReleaseDC (dpyinfo
->root_window
, hdc
);
6563 return make_number (cap
);
6566 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
6567 Sx_display_backing_store
, 0, 1, 0,
6568 doc
: /* Returns an indication of whether DISPLAY does backing store.
6569 The value may be `always', `when-mapped', or `not-useful'.
6570 The optional argument DISPLAY specifies which display to ask about.
6571 DISPLAY should be either a frame or a display name (a string).
6572 If omitted or nil, that stands for the selected frame's display. */)
6574 Lisp_Object display
;
6576 return intern ("not-useful");
6579 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
6580 Sx_display_visual_class
, 0, 1, 0,
6581 doc
: /* Returns the visual class of DISPLAY.
6582 The value is one of the symbols `static-gray', `gray-scale',
6583 `static-color', `pseudo-color', `true-color', or `direct-color'.
6585 The optional argument DISPLAY specifies which display to ask about.
6586 DISPLAY should be either a frame or a display name (a string).
6587 If omitted or nil, that stands for the selected frame's display. */)
6589 Lisp_Object display
;
6591 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6592 Lisp_Object result
= Qnil
;
6594 if (dpyinfo
->has_palette
)
6595 result
= intern ("pseudo-color");
6596 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
6597 result
= intern ("static-grey");
6598 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
6599 result
= intern ("static-color");
6600 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
6601 result
= intern ("true-color");
6606 DEFUN ("x-display-save-under", Fx_display_save_under
,
6607 Sx_display_save_under
, 0, 1, 0,
6608 doc
: /* Returns t if DISPLAY supports the save-under feature.
6609 The optional argument DISPLAY specifies which display to ask about.
6610 DISPLAY should be either a frame or a display name (a string).
6611 If omitted or nil, that stands for the selected frame's display. */)
6613 Lisp_Object display
;
6620 register struct frame
*f
;
6622 return FRAME_PIXEL_WIDTH (f
);
6627 register struct frame
*f
;
6629 return FRAME_PIXEL_HEIGHT (f
);
6634 register struct frame
*f
;
6636 return FRAME_COLUMN_WIDTH (f
);
6641 register struct frame
*f
;
6643 return FRAME_LINE_HEIGHT (f
);
6648 register struct frame
*f
;
6650 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
6653 /* Return the display structure for the display named NAME.
6654 Open a new connection if necessary. */
6656 struct w32_display_info
*
6657 x_display_info_for_name (name
)
6661 struct w32_display_info
*dpyinfo
;
6663 CHECK_STRING (name
);
6665 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
6667 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
6670 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
6675 /* Use this general default value to start with. */
6676 Vx_resource_name
= Vinvocation_name
;
6678 validate_x_resource_name ();
6680 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
6681 (char *) SDATA (Vx_resource_name
));
6684 error ("Cannot connect to server %s", SDATA (name
));
6687 XSETFASTINT (Vwindow_system_version
, 3);
6692 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
6693 1, 3, 0, doc
: /* Open a connection to a server.
6694 DISPLAY is the name of the display to connect to.
6695 Optional second arg XRM-STRING is a string of resources in xrdb format.
6696 If the optional third arg MUST-SUCCEED is non-nil,
6697 terminate Emacs if we can't open the connection. */)
6698 (display
, xrm_string
, must_succeed
)
6699 Lisp_Object display
, xrm_string
, must_succeed
;
6701 unsigned char *xrm_option
;
6702 struct w32_display_info
*dpyinfo
;
6704 /* If initialization has already been done, return now to avoid
6705 overwriting critical parts of one_w32_display_info. */
6709 CHECK_STRING (display
);
6710 if (! NILP (xrm_string
))
6711 CHECK_STRING (xrm_string
);
6713 if (! EQ (Vwindow_system
, intern ("w32")))
6714 error ("Not using Microsoft Windows");
6716 /* Allow color mapping to be defined externally; first look in user's
6717 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
6719 Lisp_Object color_file
;
6720 struct gcpro gcpro1
;
6722 color_file
= build_string("~/rgb.txt");
6724 GCPRO1 (color_file
);
6726 if (NILP (Ffile_readable_p (color_file
)))
6728 Fexpand_file_name (build_string ("rgb.txt"),
6729 Fsymbol_value (intern ("data-directory")));
6731 Vw32_color_map
= Fw32_load_color_file (color_file
);
6735 if (NILP (Vw32_color_map
))
6736 Vw32_color_map
= Fw32_default_color_map ();
6738 /* Merge in system logical colors. */
6739 add_system_logical_colors_to_map (&Vw32_color_map
);
6741 if (! NILP (xrm_string
))
6742 xrm_option
= (unsigned char *) SDATA (xrm_string
);
6744 xrm_option
= (unsigned char *) 0;
6746 /* Use this general default value to start with. */
6747 /* First remove .exe suffix from invocation-name - it looks ugly. */
6749 char basename
[ MAX_PATH
], *str
;
6751 strcpy (basename
, SDATA (Vinvocation_name
));
6752 str
= strrchr (basename
, '.');
6754 Vinvocation_name
= build_string (basename
);
6756 Vx_resource_name
= Vinvocation_name
;
6758 validate_x_resource_name ();
6760 /* This is what opens the connection and sets x_current_display.
6761 This also initializes many symbols, such as those used for input. */
6762 dpyinfo
= w32_term_init (display
, xrm_option
,
6763 (char *) SDATA (Vx_resource_name
));
6767 if (!NILP (must_succeed
))
6768 fatal ("Cannot connect to server %s.\n",
6771 error ("Cannot connect to server %s", SDATA (display
));
6776 XSETFASTINT (Vwindow_system_version
, 3);
6780 DEFUN ("x-close-connection", Fx_close_connection
,
6781 Sx_close_connection
, 1, 1, 0,
6782 doc
: /* Close the connection to DISPLAY's server.
6783 For DISPLAY, specify either a frame or a display name (a string).
6784 If DISPLAY is nil, that stands for the selected frame's display. */)
6786 Lisp_Object display
;
6788 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6791 if (dpyinfo
->reference_count
> 0)
6792 error ("Display still has frames on it");
6795 /* Free the fonts in the font table. */
6796 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
6797 if (dpyinfo
->font_table
[i
].name
)
6799 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
6800 xfree (dpyinfo
->font_table
[i
].full_name
);
6801 xfree (dpyinfo
->font_table
[i
].name
);
6802 w32_unload_font (dpyinfo
, dpyinfo
->font_table
[i
].font
);
6804 x_destroy_all_bitmaps (dpyinfo
);
6806 x_delete_display (dpyinfo
);
6812 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
6813 doc
: /* Return the list of display names that Emacs has connections to. */)
6816 Lisp_Object tail
, result
;
6819 for (tail
= w32_display_name_list
; ! NILP (tail
); tail
= XCDR (tail
))
6820 result
= Fcons (XCAR (XCAR (tail
)), result
);
6825 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
6826 doc
: /* This is a noop on W32 systems. */)
6828 Lisp_Object display
, on
;
6835 /***********************************************************************
6837 ***********************************************************************/
6839 DEFUN ("x-change-window-property", Fx_change_window_property
,
6840 Sx_change_window_property
, 2, 6, 0,
6841 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
6842 VALUE may be a string or a list of conses, numbers and/or strings.
6843 If an element in the list is a string, it is converted to
6844 an Atom and the value of the Atom is used. If an element is a cons,
6845 it is converted to a 32 bit number where the car is the 16 top bits and the
6846 cdr is the lower 16 bits.
6847 FRAME nil or omitted means use the selected frame.
6848 If TYPE is given and non-nil, it is the name of the type of VALUE.
6849 If TYPE is not given or nil, the type is STRING.
6850 FORMAT gives the size in bits of each element if VALUE is a list.
6851 It must be one of 8, 16 or 32.
6852 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
6853 If OUTER_P is non-nil, the property is changed for the outer X window of
6854 FRAME. Default is to change on the edit X window.
6857 (prop
, value
, frame
, type
, format
, outer_p
)
6858 Lisp_Object prop
, value
, frame
, type
, format
, outer_p
;
6860 #if 0 /* TODO : port window properties to W32 */
6861 struct frame
*f
= check_x_frame (frame
);
6864 CHECK_STRING (prop
);
6865 CHECK_STRING (value
);
6868 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
6869 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
6870 prop_atom
, XA_STRING
, 8, PropModeReplace
,
6871 SDATA (value
), SCHARS (value
));
6873 /* Make sure the property is set when we return. */
6874 XFlush (FRAME_W32_DISPLAY (f
));
6883 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
6884 Sx_delete_window_property
, 1, 2, 0,
6885 doc
: /* Remove window property PROP from X window of FRAME.
6886 FRAME nil or omitted means use the selected frame. Value is PROP. */)
6888 Lisp_Object prop
, frame
;
6890 #if 0 /* TODO : port window properties to W32 */
6892 struct frame
*f
= check_x_frame (frame
);
6895 CHECK_STRING (prop
);
6897 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
6898 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
6900 /* Make sure the property is removed when we return. */
6901 XFlush (FRAME_W32_DISPLAY (f
));
6909 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
6911 doc
: /* Value is the value of window property PROP on FRAME.
6912 If FRAME is nil or omitted, use the selected frame. Value is nil
6913 if FRAME hasn't a property with name PROP or if PROP has no string
6916 Lisp_Object prop
, frame
;
6918 #if 0 /* TODO : port window properties to W32 */
6920 struct frame
*f
= check_x_frame (frame
);
6923 Lisp_Object prop_value
= Qnil
;
6924 char *tmp_data
= NULL
;
6927 unsigned long actual_size
, bytes_remaining
;
6929 CHECK_STRING (prop
);
6931 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
6932 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
6933 prop_atom
, 0, 0, False
, XA_STRING
,
6934 &actual_type
, &actual_format
, &actual_size
,
6935 &bytes_remaining
, (unsigned char **) &tmp_data
);
6938 int size
= bytes_remaining
;
6943 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
6944 prop_atom
, 0, bytes_remaining
,
6946 &actual_type
, &actual_format
,
6947 &actual_size
, &bytes_remaining
,
6948 (unsigned char **) &tmp_data
);
6950 prop_value
= make_string (tmp_data
, size
);
6965 /***********************************************************************
6967 ***********************************************************************/
6969 /* If non-null, an asynchronous timer that, when it expires, displays
6970 an hourglass cursor on all frames. */
6972 static struct atimer
*hourglass_atimer
;
6974 /* Non-zero means an hourglass cursor is currently shown. */
6976 static int hourglass_shown_p
;
6978 /* Number of seconds to wait before displaying an hourglass cursor. */
6980 static Lisp_Object Vhourglass_delay
;
6982 /* Default number of seconds to wait before displaying an hourglass
6985 #define DEFAULT_HOURGLASS_DELAY 1
6987 /* Function prototypes. */
6989 static void show_hourglass
P_ ((struct atimer
*));
6990 static void hide_hourglass
P_ ((void));
6993 /* Cancel a currently active hourglass timer, and start a new one. */
6998 #if 0 /* TODO: cursor shape changes. */
7000 int secs
, usecs
= 0;
7002 cancel_hourglass ();
7004 if (INTEGERP (Vhourglass_delay
)
7005 && XINT (Vhourglass_delay
) > 0)
7006 secs
= XFASTINT (Vhourglass_delay
);
7007 else if (FLOATP (Vhourglass_delay
)
7008 && XFLOAT_DATA (Vhourglass_delay
) > 0)
7011 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
7012 secs
= XFASTINT (tem
);
7013 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
7016 secs
= DEFAULT_HOURGLASS_DELAY
;
7018 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
7019 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
7020 show_hourglass
, NULL
);
7025 /* Cancel the hourglass cursor timer if active, hide an hourglass
7031 if (hourglass_atimer
)
7033 cancel_atimer (hourglass_atimer
);
7034 hourglass_atimer
= NULL
;
7037 if (hourglass_shown_p
)
7042 /* Timer function of hourglass_atimer. TIMER is equal to
7045 Display an hourglass cursor on all frames by mapping the frames'
7046 hourglass_window. Set the hourglass_p flag in the frames'
7047 output_data.x structure to indicate that an hourglass cursor is
7048 shown on the frames. */
7051 show_hourglass (timer
)
7052 struct atimer
*timer
;
7054 #if 0 /* TODO: cursor shape changes. */
7055 /* The timer implementation will cancel this timer automatically
7056 after this function has run. Set hourglass_atimer to null
7057 so that we know the timer doesn't have to be canceled. */
7058 hourglass_atimer
= NULL
;
7060 if (!hourglass_shown_p
)
7062 Lisp_Object rest
, frame
;
7066 FOR_EACH_FRAME (rest
, frame
)
7067 if (FRAME_W32_P (XFRAME (frame
)))
7069 struct frame
*f
= XFRAME (frame
);
7071 f
->output_data
.w32
->hourglass_p
= 1;
7073 if (!f
->output_data
.w32
->hourglass_window
)
7075 unsigned long mask
= CWCursor
;
7076 XSetWindowAttributes attrs
;
7078 attrs
.cursor
= f
->output_data
.w32
->hourglass_cursor
;
7080 f
->output_data
.w32
->hourglass_window
7081 = XCreateWindow (FRAME_X_DISPLAY (f
),
7082 FRAME_OUTER_WINDOW (f
),
7083 0, 0, 32000, 32000, 0, 0,
7089 XMapRaised (FRAME_X_DISPLAY (f
),
7090 f
->output_data
.w32
->hourglass_window
);
7091 XFlush (FRAME_X_DISPLAY (f
));
7094 hourglass_shown_p
= 1;
7101 /* Hide the hourglass cursor on all frames, if it is currently shown. */
7106 #if 0 /* TODO: cursor shape changes. */
7107 if (hourglass_shown_p
)
7109 Lisp_Object rest
, frame
;
7112 FOR_EACH_FRAME (rest
, frame
)
7114 struct frame
*f
= XFRAME (frame
);
7117 /* Watch out for newly created frames. */
7118 && f
->output_data
.x
->hourglass_window
)
7120 XUnmapWindow (FRAME_X_DISPLAY (f
),
7121 f
->output_data
.x
->hourglass_window
);
7122 /* Sync here because XTread_socket looks at the
7123 hourglass_p flag that is reset to zero below. */
7124 XSync (FRAME_X_DISPLAY (f
), False
);
7125 f
->output_data
.x
->hourglass_p
= 0;
7129 hourglass_shown_p
= 0;
7137 /***********************************************************************
7139 ***********************************************************************/
7141 static Lisp_Object x_create_tip_frame
P_ ((struct w32_display_info
*,
7142 Lisp_Object
, Lisp_Object
));
7143 static void compute_tip_xy
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
7144 Lisp_Object
, int, int, int *, int *));
7146 /* The frame of a currently visible tooltip. */
7148 Lisp_Object tip_frame
;
7150 /* If non-nil, a timer started that hides the last tooltip when it
7153 Lisp_Object tip_timer
;
7156 /* If non-nil, a vector of 3 elements containing the last args
7157 with which x-show-tip was called. See there. */
7159 Lisp_Object last_show_tip_args
;
7161 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
7163 Lisp_Object Vx_max_tooltip_size
;
7167 unwind_create_tip_frame (frame
)
7170 Lisp_Object deleted
;
7172 deleted
= unwind_create_frame (frame
);
7173 if (EQ (deleted
, Qt
))
7183 /* Create a frame for a tooltip on the display described by DPYINFO.
7184 PARMS is a list of frame parameters. TEXT is the string to
7185 display in the tip frame. Value is the frame.
7187 Note that functions called here, esp. x_default_parameter can
7188 signal errors, for instance when a specified color name is
7189 undefined. We have to make sure that we're in a consistent state
7190 when this happens. */
7193 x_create_tip_frame (dpyinfo
, parms
, text
)
7194 struct w32_display_info
*dpyinfo
;
7195 Lisp_Object parms
, text
;
7198 Lisp_Object frame
, tem
;
7200 long window_prompting
= 0;
7202 int count
= SPECPDL_INDEX ();
7203 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7205 int face_change_count_before
= face_change_count
;
7207 struct buffer
*old_buffer
;
7211 /* Use this general default value to start with until we know if
7212 this frame has a specified name. */
7213 Vx_resource_name
= Vinvocation_name
;
7216 kb
= dpyinfo
->kboard
;
7218 kb
= &the_only_kboard
;
7221 /* Get the name of the frame to use for resource lookup. */
7222 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
7224 && !EQ (name
, Qunbound
)
7226 error ("Invalid frame name--not a string or nil");
7227 Vx_resource_name
= name
;
7230 GCPRO3 (parms
, name
, frame
);
7231 /* Make a frame without minibuffer nor mode-line. */
7233 f
->wants_modeline
= 0;
7234 XSETFRAME (frame
, f
);
7236 buffer
= Fget_buffer_create (build_string (" *tip*"));
7237 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, Qnil
);
7238 old_buffer
= current_buffer
;
7239 set_buffer_internal_1 (XBUFFER (buffer
));
7240 current_buffer
->truncate_lines
= Qnil
;
7241 specbind (Qinhibit_read_only
, Qt
);
7242 specbind (Qinhibit_modification_hooks
, Qt
);
7245 set_buffer_internal_1 (old_buffer
);
7247 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
7248 record_unwind_protect (unwind_create_tip_frame
, frame
);
7250 /* By setting the output method, we're essentially saying that
7251 the frame is live, as per FRAME_LIVE_P. If we get a signal
7252 from this point on, x_destroy_window might screw up reference
7254 f
->output_method
= output_w32
;
7255 f
->output_data
.w32
=
7256 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
7257 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
7259 FRAME_FONTSET (f
) = -1;
7260 f
->icon_name
= Qnil
;
7262 #if 0 /* GLYPH_DEBUG TODO: image support. */
7263 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
7264 dpyinfo_refcount
= dpyinfo
->reference_count
;
7265 #endif /* GLYPH_DEBUG */
7267 FRAME_KBOARD (f
) = kb
;
7269 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
7270 f
->output_data
.w32
->explicit_parent
= 0;
7272 /* Set the name; the functions to which we pass f expect the name to
7274 if (EQ (name
, Qunbound
) || NILP (name
))
7276 f
->name
= build_string (dpyinfo
->w32_id_name
);
7277 f
->explicit_name
= 0;
7282 f
->explicit_name
= 1;
7283 /* use the frame's title when getting resources for this frame. */
7284 specbind (Qx_resource_name
, name
);
7287 /* Extract the window parameters from the supplied values
7288 that are needed to determine window geometry. */
7292 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
7295 /* First, try whatever font the caller has specified. */
7298 tem
= Fquery_fontset (font
, Qnil
);
7300 font
= x_new_fontset (f
, tem
);
7302 font
= x_new_font (f
, SDATA (font
));
7305 /* Try out a font which we hope has bold and italic variations. */
7306 if (!STRINGP (font
))
7307 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
7308 if (! STRINGP (font
))
7309 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
7310 /* If those didn't work, look for something which will at least work. */
7311 if (! STRINGP (font
))
7312 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
7314 if (! STRINGP (font
))
7315 font
= build_string ("Fixedsys");
7317 x_default_parameter (f
, parms
, Qfont
, font
,
7318 "font", "Font", RES_TYPE_STRING
);
7321 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
7322 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
7323 /* This defaults to 2 in order to match xterm. We recognize either
7324 internalBorderWidth or internalBorder (which is what xterm calls
7326 if (NILP (Fassq (Qinternal_border_width
, parms
)))
7330 value
= w32_get_arg (parms
, Qinternal_border_width
,
7331 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
7332 if (! EQ (value
, Qunbound
))
7333 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
7336 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
7337 "internalBorderWidth", "internalBorderWidth",
7340 /* Also do the stuff which must be set before the window exists. */
7341 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
7342 "foreground", "Foreground", RES_TYPE_STRING
);
7343 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
7344 "background", "Background", RES_TYPE_STRING
);
7345 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
7346 "pointerColor", "Foreground", RES_TYPE_STRING
);
7347 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
7348 "cursorColor", "Foreground", RES_TYPE_STRING
);
7349 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
7350 "borderColor", "BorderColor", RES_TYPE_STRING
);
7352 /* Init faces before x_default_parameter is called for scroll-bar
7353 parameters because that function calls x_set_scroll_bar_width,
7354 which calls change_frame_size, which calls Fset_window_buffer,
7355 which runs hooks, which call Fvertical_motion. At the end, we
7356 end up in init_iterator with a null face cache, which should not
7358 init_frame_faces (f
);
7360 f
->output_data
.w32
->dwStyle
= WS_BORDER
| WS_POPUP
| WS_DISABLED
;
7361 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
7363 window_prompting
= x_figure_window_size (f
, parms
, 0);
7365 /* No fringes on tip frame. */
7367 f
->left_fringe_width
= 0;
7368 f
->right_fringe_width
= 0;
7371 my_create_tip_window (f
);
7376 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
7377 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
7378 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
7379 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
7380 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
7381 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
7383 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
7384 Change will not be effected unless different from the current
7386 width
= FRAME_COLS (f
);
7387 height
= FRAME_LINES (f
);
7388 FRAME_LINES (f
) = 0;
7389 SET_FRAME_COLS (f
, 0);
7390 change_frame_size (f
, height
, width
, 1, 0, 0);
7392 /* Add `tooltip' frame parameter's default value. */
7393 if (NILP (Fframe_parameter (frame
, intern ("tooltip"))))
7394 Fmodify_frame_parameters (frame
, Fcons (Fcons (intern ("tooltip"), Qt
),
7397 /* Set up faces after all frame parameters are known. This call
7398 also merges in face attributes specified for new frames.
7400 Frame parameters may be changed if .Xdefaults contains
7401 specifications for the default font. For example, if there is an
7402 `Emacs.default.attributeBackground: pink', the `background-color'
7403 attribute of the frame get's set, which let's the internal border
7404 of the tooltip frame appear in pink. Prevent this. */
7406 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
7408 /* Set tip_frame here, so that */
7410 call1 (Qface_set_after_frame_default
, frame
);
7412 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
7413 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qbackground_color
, bg
),
7421 /* It is now ok to make the frame official even if we get an error
7422 below. And the frame needs to be on Vframe_list or making it
7423 visible won't work. */
7424 Vframe_list
= Fcons (frame
, Vframe_list
);
7426 /* Now that the frame is official, it counts as a reference to
7428 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
7430 /* Setting attributes of faces of the tooltip frame from resources
7431 and similar will increment face_change_count, which leads to the
7432 clearing of all current matrices. Since this isn't necessary
7433 here, avoid it by resetting face_change_count to the value it
7434 had before we created the tip frame. */
7435 face_change_count
= face_change_count_before
;
7437 /* Discard the unwind_protect. */
7438 return unbind_to (count
, frame
);
7442 /* Compute where to display tip frame F. PARMS is the list of frame
7443 parameters for F. DX and DY are specified offsets from the current
7444 location of the mouse. WIDTH and HEIGHT are the width and height
7445 of the tooltip. Return coordinates relative to the root window of
7446 the display in *ROOT_X, and *ROOT_Y. */
7449 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, root_x
, root_y
)
7451 Lisp_Object parms
, dx
, dy
;
7453 int *root_x
, *root_y
;
7455 Lisp_Object left
, top
;
7457 /* User-specified position? */
7458 left
= Fcdr (Fassq (Qleft
, parms
));
7459 top
= Fcdr (Fassq (Qtop
, parms
));
7461 /* Move the tooltip window where the mouse pointer is. Resize and
7463 if (!INTEGERP (left
) || !INTEGERP (top
))
7475 *root_y
= XINT (top
);
7476 else if (*root_y
+ XINT (dy
) <= 0)
7477 *root_y
= 0; /* Can happen for negative dy */
7478 else if (*root_y
+ XINT (dy
) + height
<= FRAME_W32_DISPLAY_INFO (f
)->height
)
7479 /* It fits below the pointer */
7480 *root_y
+= XINT (dy
);
7481 else if (height
+ XINT (dy
) <= *root_y
)
7482 /* It fits above the pointer. */
7483 *root_y
-= height
+ XINT (dy
);
7485 /* Put it on the top. */
7488 if (INTEGERP (left
))
7489 *root_x
= XINT (left
);
7490 else if (*root_x
+ XINT (dx
) <= 0)
7491 *root_x
= 0; /* Can happen for negative dx */
7492 else if (*root_x
+ XINT (dx
) + width
<= FRAME_W32_DISPLAY_INFO (f
)->width
)
7493 /* It fits to the right of the pointer. */
7494 *root_x
+= XINT (dx
);
7495 else if (width
+ XINT (dx
) <= *root_x
)
7496 /* It fits to the left of the pointer. */
7497 *root_x
-= width
+ XINT (dx
);
7499 /* Put it left justified on the screen -- it ought to fit that way. */
7504 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
7505 doc
: /* Show STRING in a \"tooltip\" window on frame FRAME.
7506 A tooltip window is a small window displaying a string.
7508 FRAME nil or omitted means use the selected frame.
7510 PARMS is an optional list of frame parameters which can be
7511 used to change the tooltip's appearance.
7513 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
7514 means use the default timeout of 5 seconds.
7516 If the list of frame parameters PARMS contains a `left' parameter,
7517 the tooltip is displayed at that x-position. Otherwise it is
7518 displayed at the mouse position, with offset DX added (default is 5 if
7519 DX isn't specified). Likewise for the y-position; if a `top' frame
7520 parameter is specified, it determines the y-position of the tooltip
7521 window, otherwise it is displayed at the mouse position, with offset
7522 DY added (default is -10).
7524 A tooltip's maximum size is specified by `x-max-tooltip-size'.
7525 Text larger than the specified size is clipped. */)
7526 (string
, frame
, parms
, timeout
, dx
, dy
)
7527 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
7532 struct buffer
*old_buffer
;
7533 struct text_pos pos
;
7534 int i
, width
, height
;
7535 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7536 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7537 int count
= SPECPDL_INDEX ();
7539 specbind (Qinhibit_redisplay
, Qt
);
7541 GCPRO4 (string
, parms
, frame
, timeout
);
7543 CHECK_STRING (string
);
7544 f
= check_x_frame (frame
);
7546 timeout
= make_number (5);
7548 CHECK_NATNUM (timeout
);
7551 dx
= make_number (5);
7556 dy
= make_number (-10);
7560 if (NILP (last_show_tip_args
))
7561 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
7563 if (!NILP (tip_frame
))
7565 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
7566 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
7567 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
7569 if (EQ (frame
, last_frame
)
7570 && !NILP (Fequal (last_string
, string
))
7571 && !NILP (Fequal (last_parms
, parms
)))
7573 struct frame
*f
= XFRAME (tip_frame
);
7575 /* Only DX and DY have changed. */
7576 if (!NILP (tip_timer
))
7578 Lisp_Object timer
= tip_timer
;
7580 call1 (Qcancel_timer
, timer
);
7584 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
7585 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
7587 /* Put tooltip in topmost group and in position. */
7588 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
7589 root_x
, root_y
, 0, 0,
7590 SWP_NOSIZE
| SWP_NOACTIVATE
);
7592 /* Ensure tooltip is on top of other topmost windows (eg menus). */
7593 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
7595 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
7602 /* Hide a previous tip, if any. */
7605 ASET (last_show_tip_args
, 0, string
);
7606 ASET (last_show_tip_args
, 1, frame
);
7607 ASET (last_show_tip_args
, 2, parms
);
7609 /* Add default values to frame parameters. */
7610 if (NILP (Fassq (Qname
, parms
)))
7611 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
7612 if (NILP (Fassq (Qinternal_border_width
, parms
)))
7613 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
7614 if (NILP (Fassq (Qborder_width
, parms
)))
7615 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
7616 if (NILP (Fassq (Qborder_color
, parms
)))
7617 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
7618 if (NILP (Fassq (Qbackground_color
, parms
)))
7619 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
7622 /* Block input until the tip has been fully drawn, to avoid crashes
7623 when drawing tips in menus. */
7626 /* Create a frame for the tooltip, and record it in the global
7627 variable tip_frame. */
7628 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
, string
);
7631 /* Set up the frame's root window. */
7632 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7633 w
->left_col
= w
->top_line
= make_number (0);
7635 if (CONSP (Vx_max_tooltip_size
)
7636 && INTEGERP (XCAR (Vx_max_tooltip_size
))
7637 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
7638 && INTEGERP (XCDR (Vx_max_tooltip_size
))
7639 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
7641 w
->total_cols
= XCAR (Vx_max_tooltip_size
);
7642 w
->total_lines
= XCDR (Vx_max_tooltip_size
);
7646 w
->total_cols
= make_number (80);
7647 w
->total_lines
= make_number (40);
7650 FRAME_TOTAL_COLS (f
) = XINT (w
->total_cols
);
7652 w
->pseudo_window_p
= 1;
7654 /* Display the tooltip text in a temporary buffer. */
7655 old_buffer
= current_buffer
;
7656 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
7657 current_buffer
->truncate_lines
= Qnil
;
7658 clear_glyph_matrix (w
->desired_matrix
);
7659 clear_glyph_matrix (w
->current_matrix
);
7660 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
7661 try_window (FRAME_ROOT_WINDOW (f
), pos
, 0);
7663 /* Compute width and height of the tooltip. */
7665 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
7667 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
7671 /* Stop at the first empty row at the end. */
7672 if (!row
->enabled_p
|| !row
->displays_text_p
)
7675 /* Let the row go over the full width of the frame. */
7676 row
->full_width_p
= 1;
7678 #ifdef TODO /* Investigate why some fonts need more width than is
7679 calculated for some tooltips. */
7680 /* There's a glyph at the end of rows that is use to place
7681 the cursor there. Don't include the width of this glyph. */
7682 if (row
->used
[TEXT_AREA
])
7684 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
7685 row_width
= row
->pixel_width
- last
->pixel_width
;
7689 row_width
= row
->pixel_width
;
7691 /* TODO: find why tips do not draw along baseline as instructed. */
7692 height
+= row
->height
;
7693 width
= max (width
, row_width
);
7696 /* Add the frame's internal border to the width and height the X
7697 window should have. */
7698 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
7699 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
7701 /* Move the tooltip window where the mouse pointer is. Resize and
7703 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
7706 /* Adjust Window size to take border into account. */
7708 rect
.left
= rect
.top
= 0;
7710 rect
.bottom
= height
;
7711 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
7712 FRAME_EXTERNAL_MENU_BAR (f
));
7714 /* Position and size tooltip, and put it in the topmost group. */
7715 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
7716 root_x
, root_y
, rect
.right
- rect
.left
,
7717 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
);
7719 /* Ensure tooltip is on top of other topmost windows (eg menus). */
7720 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
7722 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
7724 /* Let redisplay know that we have made the frame visible already. */
7725 f
->async_visible
= 1;
7727 ShowWindow (FRAME_W32_WINDOW (f
), SW_SHOWNOACTIVATE
);
7730 /* Draw into the window. */
7731 w
->must_be_updated_p
= 1;
7732 update_single_window (w
, 1);
7736 /* Restore original current buffer. */
7737 set_buffer_internal_1 (old_buffer
);
7738 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7741 /* Let the tip disappear after timeout seconds. */
7742 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
7743 intern ("x-hide-tip"));
7746 return unbind_to (count
, Qnil
);
7750 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
7751 doc
: /* Hide the current tooltip window, if there is any.
7752 Value is t if tooltip was open, nil otherwise. */)
7756 Lisp_Object deleted
, frame
, timer
;
7757 struct gcpro gcpro1
, gcpro2
;
7759 /* Return quickly if nothing to do. */
7760 if (NILP (tip_timer
) && NILP (tip_frame
))
7765 GCPRO2 (frame
, timer
);
7766 tip_frame
= tip_timer
= deleted
= Qnil
;
7768 count
= SPECPDL_INDEX ();
7769 specbind (Qinhibit_redisplay
, Qt
);
7770 specbind (Qinhibit_quit
, Qt
);
7773 call1 (Qcancel_timer
, timer
);
7777 Fdelete_frame (frame
, Qnil
);
7782 return unbind_to (count
, deleted
);
7787 /***********************************************************************
7788 File selection dialog
7789 ***********************************************************************/
7790 extern Lisp_Object Qfile_name_history
;
7792 /* Callback for altering the behaviour of the Open File dialog.
7793 Makes the Filename text field contain "Current Directory" and be
7794 read-only when "Directories" is selected in the filter. This
7795 allows us to work around the fact that the standard Open File
7796 dialog does not support directories. */
7798 file_dialog_callback (hwnd
, msg
, wParam
, lParam
)
7804 if (msg
== WM_NOTIFY
)
7806 OFNOTIFY
* notify
= (OFNOTIFY
*)lParam
;
7807 /* Detect when the Filter dropdown is changed. */
7808 if (notify
->hdr
.code
== CDN_TYPECHANGE
7809 || notify
->hdr
.code
== CDN_INITDONE
)
7811 HWND dialog
= GetParent (hwnd
);
7812 HWND edit_control
= GetDlgItem (dialog
, FILE_NAME_TEXT_FIELD
);
7814 /* Directories is in index 2. */
7815 if (notify
->lpOFN
->nFilterIndex
== 2)
7817 CommDlg_OpenSave_SetControlText (dialog
, FILE_NAME_TEXT_FIELD
,
7818 "Current Directory");
7819 EnableWindow (edit_control
, FALSE
);
7823 /* Don't override default filename on init done. */
7824 if (notify
->hdr
.code
== CDN_TYPECHANGE
)
7825 CommDlg_OpenSave_SetControlText (dialog
,
7826 FILE_NAME_TEXT_FIELD
, "");
7827 EnableWindow (edit_control
, TRUE
);
7834 /* Since we compile with _WIN32_WINNT set to 0x0400 (for NT4 compatibility)
7835 we end up with the old file dialogs. Define a big enough struct for the
7836 new dialog to trick GetOpenFileName into giving us the new dialogs on
7837 Windows 2000 and XP. */
7840 OPENFILENAME real_details
;
7847 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
7848 doc
: /* Read file name, prompting with PROMPT in directory DIR.
7849 Use a file selection dialog.
7850 Select DEFAULT-FILENAME in the dialog's file selection box, if
7851 specified. Ensure that file exists if MUSTMATCH is non-nil.
7852 If ONLY-DIR-P is non-nil, the user can only select directories. */)
7853 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
)
7854 Lisp_Object prompt
, dir
, default_filename
, mustmatch
, only_dir_p
;
7856 struct frame
*f
= SELECTED_FRAME ();
7857 Lisp_Object file
= Qnil
;
7858 int count
= SPECPDL_INDEX ();
7859 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
7860 char filename
[MAX_PATH
+ 1];
7861 char init_dir
[MAX_PATH
+ 1];
7862 int default_filter_index
= 1; /* 1: All Files, 2: Directories only */
7864 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
7865 CHECK_STRING (prompt
);
7868 /* Create the dialog with PROMPT as title, using DIR as initial
7869 directory and using "*" as pattern. */
7870 dir
= Fexpand_file_name (dir
, Qnil
);
7871 strncpy (init_dir
, SDATA (ENCODE_FILE (dir
)), MAX_PATH
);
7872 init_dir
[MAX_PATH
] = '\0';
7873 unixtodos_filename (init_dir
);
7875 if (STRINGP (default_filename
))
7877 char *file_name_only
;
7878 char *full_path_name
= SDATA (ENCODE_FILE (default_filename
));
7880 unixtodos_filename (full_path_name
);
7882 file_name_only
= strrchr (full_path_name
, '\\');
7883 if (!file_name_only
)
7884 file_name_only
= full_path_name
;
7888 strncpy (filename
, file_name_only
, MAX_PATH
);
7889 filename
[MAX_PATH
] = '\0';
7895 NEWOPENFILENAME new_file_details
;
7896 BOOL file_opened
= FALSE
;
7897 OPENFILENAME
* file_details
= &new_file_details
.real_details
;
7899 /* Prevent redisplay. */
7900 specbind (Qinhibit_redisplay
, Qt
);
7903 bzero (&new_file_details
, sizeof (new_file_details
));
7904 /* Apparently NT4 crashes if you give it an unexpected size.
7905 I'm not sure about Windows 9x, so play it safe. */
7906 if (w32_major_version
> 4 && w32_major_version
< 95)
7907 file_details
->lStructSize
= sizeof (new_file_details
);
7909 file_details
->lStructSize
= sizeof (file_details
);
7911 file_details
->hwndOwner
= FRAME_W32_WINDOW (f
);
7912 /* Undocumented Bug in Common File Dialog:
7913 If a filter is not specified, shell links are not resolved. */
7914 file_details
->lpstrFilter
= "All Files (*.*)\0*.*\0Directories\0*|*\0\0";
7915 file_details
->lpstrFile
= filename
;
7916 file_details
->nMaxFile
= sizeof (filename
);
7917 file_details
->lpstrInitialDir
= init_dir
;
7918 file_details
->lpstrTitle
= SDATA (prompt
);
7920 if (! NILP (only_dir_p
))
7921 default_filter_index
= 2;
7923 file_details
->nFilterIndex
= default_filter_index
;
7925 file_details
->Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
7926 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
7927 if (!NILP (mustmatch
))
7929 /* Require that the path to the parent directory exists. */
7930 file_details
->Flags
|= OFN_PATHMUSTEXIST
;
7931 /* If we are looking for a file, require that it exists. */
7932 if (NILP (only_dir_p
))
7933 file_details
->Flags
|= OFN_FILEMUSTEXIST
;
7936 file_details
->lpfnHook
= (LPOFNHOOKPROC
) file_dialog_callback
;
7938 file_opened
= GetOpenFileName (file_details
);
7944 dostounix_filename (filename
);
7946 if (file_details
->nFilterIndex
== 2)
7948 /* "Directories" selected - strip dummy file name. */
7949 char * last
= strrchr (filename
, '/');
7953 file
= DECODE_FILE(build_string (filename
));
7955 /* User cancelled the dialog without making a selection. */
7956 else if (!CommDlgExtendedError ())
7958 /* An error occurred, fallback on reading from the mini-buffer. */
7960 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
7961 dir
, mustmatch
, dir
, Qfile_name_history
,
7962 default_filename
, Qnil
);
7964 file
= unbind_to (count
, file
);
7969 /* Make "Cancel" equivalent to C-g. */
7971 Fsignal (Qquit
, Qnil
);
7973 return unbind_to (count
, file
);
7978 /***********************************************************************
7979 w32 specialized functions
7980 ***********************************************************************/
7982 DEFUN ("w32-select-font", Fw32_select_font
, Sw32_select_font
, 0, 2, 0,
7983 doc
: /* Select a font using the W32 font dialog.
7984 Returns an X font string corresponding to the selection. */)
7985 (frame
, include_proportional
)
7986 Lisp_Object frame
, include_proportional
;
7988 FRAME_PTR f
= check_x_frame (frame
);
7996 bzero (&cf
, sizeof (cf
));
7997 bzero (&lf
, sizeof (lf
));
7999 cf
.lStructSize
= sizeof (cf
);
8000 cf
.hwndOwner
= FRAME_W32_WINDOW (f
);
8001 cf
.Flags
= CF_FORCEFONTEXIST
| CF_SCREENFONTS
| CF_NOVERTFONTS
;
8003 /* Unless include_proportional is non-nil, limit the selection to
8004 monospaced fonts. */
8005 if (NILP (include_proportional
))
8006 cf
.Flags
|= CF_FIXEDPITCHONLY
;
8010 /* Initialize as much of the font details as we can from the current
8012 hdc
= GetDC (FRAME_W32_WINDOW (f
));
8013 oldobj
= SelectObject (hdc
, FRAME_FONT (f
)->hfont
);
8014 GetTextFace (hdc
, LF_FACESIZE
, lf
.lfFaceName
);
8015 if (GetTextMetrics (hdc
, &tm
))
8017 lf
.lfHeight
= tm
.tmInternalLeading
- tm
.tmHeight
;
8018 lf
.lfWeight
= tm
.tmWeight
;
8019 lf
.lfItalic
= tm
.tmItalic
;
8020 lf
.lfUnderline
= tm
.tmUnderlined
;
8021 lf
.lfStrikeOut
= tm
.tmStruckOut
;
8022 lf
.lfCharSet
= tm
.tmCharSet
;
8023 cf
.Flags
|= CF_INITTOLOGFONTSTRUCT
;
8025 SelectObject (hdc
, oldobj
);
8026 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
8028 if (!ChooseFont (&cf
) || !w32_to_x_font (&lf
, buf
, 100, NULL
))
8031 return build_string (buf
);
8034 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
,
8035 Sw32_send_sys_command
, 1, 2, 0,
8036 doc
: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND.
8037 Some useful values for COMMAND are #xf030 to maximize frame (#xf020
8038 to minimize), #xf120 to restore frame to original size, and #xf100
8039 to activate the menubar for keyboard access. #xf140 activates the
8040 screen saver if defined.
8042 If optional parameter FRAME is not specified, use selected frame. */)
8044 Lisp_Object command
, frame
;
8046 FRAME_PTR f
= check_x_frame (frame
);
8048 CHECK_NUMBER (command
);
8050 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
8055 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
8056 doc
: /* Get Windows to perform OPERATION on DOCUMENT.
8057 This is a wrapper around the ShellExecute system function, which
8058 invokes the application registered to handle OPERATION for DOCUMENT.
8059 OPERATION is typically \"open\", \"print\" or \"explore\" (but can be
8060 nil for the default action), and DOCUMENT is typically the name of a
8061 document file or URL, but can also be a program executable to run or
8062 a directory to open in the Windows Explorer.
8064 If DOCUMENT is a program executable, PARAMETERS can be a string
8065 containing command line parameters, but otherwise should be nil.
8067 SHOW-FLAG can be used to control whether the invoked application is hidden
8068 or minimized. If SHOW-FLAG is nil, the application is displayed normally,
8069 otherwise it is an integer representing a ShowWindow flag:
8074 6 - start minimized */)
8075 (operation
, document
, parameters
, show_flag
)
8076 Lisp_Object operation
, document
, parameters
, show_flag
;
8078 Lisp_Object current_dir
;
8080 CHECK_STRING (document
);
8082 /* Encode filename and current directory. */
8083 current_dir
= ENCODE_FILE (current_buffer
->directory
);
8084 document
= ENCODE_FILE (document
);
8085 if ((int) ShellExecute (NULL
,
8086 (STRINGP (operation
) ?
8087 SDATA (operation
) : NULL
),
8089 (STRINGP (parameters
) ?
8090 SDATA (parameters
) : NULL
),
8091 SDATA (current_dir
),
8092 (INTEGERP (show_flag
) ?
8093 XINT (show_flag
) : SW_SHOWDEFAULT
))
8096 error ("ShellExecute failed: %s", w32_strerror (0));
8099 /* Lookup virtual keycode from string representing the name of a
8100 non-ascii keystroke into the corresponding virtual key, using
8101 lispy_function_keys. */
8103 lookup_vk_code (char *key
)
8107 for (i
= 0; i
< 256; i
++)
8108 if (lispy_function_keys
[i
] != 0
8109 && strcmp (lispy_function_keys
[i
], key
) == 0)
8115 /* Convert a one-element vector style key sequence to a hot key
8118 w32_parse_hot_key (key
)
8121 /* Copied from Fdefine_key and store_in_keymap. */
8122 register Lisp_Object c
;
8126 struct gcpro gcpro1
;
8130 if (XFASTINT (Flength (key
)) != 1)
8135 c
= Faref (key
, make_number (0));
8137 if (CONSP (c
) && lucid_event_type_list_p (c
))
8138 c
= Fevent_convert_list (c
);
8142 if (! INTEGERP (c
) && ! SYMBOLP (c
))
8143 error ("Key definition is invalid");
8145 /* Work out the base key and the modifiers. */
8148 c
= parse_modifiers (c
);
8149 lisp_modifiers
= XINT (Fcar (Fcdr (c
)));
8153 vk_code
= lookup_vk_code (SDATA (SYMBOL_NAME (c
)));
8155 else if (INTEGERP (c
))
8157 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
8158 /* Many ascii characters are their own virtual key code. */
8159 vk_code
= XINT (c
) & CHARACTERBITS
;
8162 if (vk_code
< 0 || vk_code
> 255)
8165 if ((lisp_modifiers
& meta_modifier
) != 0
8166 && !NILP (Vw32_alt_is_meta
))
8167 lisp_modifiers
|= alt_modifier
;
8169 /* Supply defs missing from mingw32. */
8171 #define MOD_ALT 0x0001
8172 #define MOD_CONTROL 0x0002
8173 #define MOD_SHIFT 0x0004
8174 #define MOD_WIN 0x0008
8177 /* Convert lisp modifiers to Windows hot-key form. */
8178 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
8179 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
8180 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
8181 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
8183 return HOTKEY (vk_code
, w32_modifiers
);
8186 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
,
8187 Sw32_register_hot_key
, 1, 1, 0,
8188 doc
: /* Register KEY as a hot-key combination.
8189 Certain key combinations like Alt-Tab are reserved for system use on
8190 Windows, and therefore are normally intercepted by the system. However,
8191 most of these key combinations can be received by registering them as
8192 hot-keys, overriding their special meaning.
8194 KEY must be a one element key definition in vector form that would be
8195 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta
8196 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper
8197 is always interpreted as the Windows modifier keys.
8199 The return value is the hotkey-id if registered, otherwise nil. */)
8203 key
= w32_parse_hot_key (key
);
8205 if (NILP (Fmemq (key
, w32_grabbed_keys
)))
8207 /* Reuse an empty slot if possible. */
8208 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
8210 /* Safe to add new key to list, even if we have focus. */
8212 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
8214 XSETCAR (item
, key
);
8216 /* Notify input thread about new hot-key definition, so that it
8217 takes effect without needing to switch focus. */
8218 #ifdef USE_LISP_UNION_TYPE
8219 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
8222 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
8230 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
,
8231 Sw32_unregister_hot_key
, 1, 1, 0,
8232 doc
: /* Unregister KEY as a hot-key combination. */)
8238 if (!INTEGERP (key
))
8239 key
= w32_parse_hot_key (key
);
8241 item
= Fmemq (key
, w32_grabbed_keys
);
8245 /* Notify input thread about hot-key definition being removed, so
8246 that it takes effect without needing focus switch. */
8247 #ifdef USE_LISP_UNION_TYPE
8248 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
8249 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
.i
))
8251 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
8252 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
))
8257 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
8264 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
,
8265 Sw32_registered_hot_keys
, 0, 0, 0,
8266 doc
: /* Return list of registered hot-key IDs. */)
8269 return Fcopy_sequence (w32_grabbed_keys
);
8272 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
,
8273 Sw32_reconstruct_hot_key
, 1, 1, 0,
8274 doc
: /* Convert hot-key ID to a lisp key combination.
8275 usage: (w32-reconstruct-hot-key ID) */)
8277 Lisp_Object hotkeyid
;
8279 int vk_code
, w32_modifiers
;
8282 CHECK_NUMBER (hotkeyid
);
8284 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
8285 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
8287 if (lispy_function_keys
[vk_code
])
8288 key
= intern (lispy_function_keys
[vk_code
]);
8290 key
= make_number (vk_code
);
8292 key
= Fcons (key
, Qnil
);
8293 if (w32_modifiers
& MOD_SHIFT
)
8294 key
= Fcons (Qshift
, key
);
8295 if (w32_modifiers
& MOD_CONTROL
)
8296 key
= Fcons (Qctrl
, key
);
8297 if (w32_modifiers
& MOD_ALT
)
8298 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
8299 if (w32_modifiers
& MOD_WIN
)
8300 key
= Fcons (Qhyper
, key
);
8305 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
,
8306 Sw32_toggle_lock_key
, 1, 2, 0,
8307 doc
: /* Toggle the state of the lock key KEY.
8308 KEY can be `capslock', `kp-numlock', or `scroll'.
8309 If the optional parameter NEW-STATE is a number, then the state of KEY
8310 is set to off if the low bit of NEW-STATE is zero, otherwise on. */)
8312 Lisp_Object key
, new_state
;
8316 if (EQ (key
, intern ("capslock")))
8317 vk_code
= VK_CAPITAL
;
8318 else if (EQ (key
, intern ("kp-numlock")))
8319 vk_code
= VK_NUMLOCK
;
8320 else if (EQ (key
, intern ("scroll")))
8321 vk_code
= VK_SCROLL
;
8325 if (!dwWindowsThreadId
)
8326 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
8328 #ifdef USE_LISP_UNION_TYPE
8329 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
8330 (WPARAM
) vk_code
, (LPARAM
) new_state
.i
))
8332 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
8333 (WPARAM
) vk_code
, (LPARAM
) new_state
))
8337 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
8338 return make_number (msg
.wParam
);
8343 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
8344 doc
: /* Return storage information about the file system FILENAME is on.
8345 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
8346 storage of the file system, FREE is the free storage, and AVAIL is the
8347 storage available to a non-superuser. All 3 numbers are in bytes.
8348 If the underlying system call fails, value is nil. */)
8350 Lisp_Object filename
;
8352 Lisp_Object encoded
, value
;
8354 CHECK_STRING (filename
);
8355 filename
= Fexpand_file_name (filename
, Qnil
);
8356 encoded
= ENCODE_FILE (filename
);
8360 /* Determining the required information on Windows turns out, sadly,
8361 to be more involved than one would hope. The original Win32 api
8362 call for this will return bogus information on some systems, but we
8363 must dynamically probe for the replacement api, since that was
8364 added rather late on. */
8366 HMODULE hKernel
= GetModuleHandle ("kernel32");
8367 BOOL (*pfn_GetDiskFreeSpaceEx
)
8368 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
8369 = (void *) GetProcAddress (hKernel
, "GetDiskFreeSpaceEx");
8371 /* On Windows, we may need to specify the root directory of the
8372 volume holding FILENAME. */
8373 char rootname
[MAX_PATH
];
8374 char *name
= SDATA (encoded
);
8376 /* find the root name of the volume if given */
8377 if (isalpha (name
[0]) && name
[1] == ':')
8379 rootname
[0] = name
[0];
8380 rootname
[1] = name
[1];
8384 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
8386 char *str
= rootname
;
8390 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
8400 if (pfn_GetDiskFreeSpaceEx
)
8402 /* Unsigned large integers cannot be cast to double, so
8403 use signed ones instead. */
8404 LARGE_INTEGER availbytes
;
8405 LARGE_INTEGER freebytes
;
8406 LARGE_INTEGER totalbytes
;
8408 if (pfn_GetDiskFreeSpaceEx(rootname
,
8409 (ULARGE_INTEGER
*)&availbytes
,
8410 (ULARGE_INTEGER
*)&totalbytes
,
8411 (ULARGE_INTEGER
*)&freebytes
))
8412 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
8413 make_float ((double) freebytes
.QuadPart
),
8414 make_float ((double) availbytes
.QuadPart
));
8418 DWORD sectors_per_cluster
;
8419 DWORD bytes_per_sector
;
8420 DWORD free_clusters
;
8421 DWORD total_clusters
;
8423 if (GetDiskFreeSpace(rootname
,
8424 §ors_per_cluster
,
8428 value
= list3 (make_float ((double) total_clusters
8429 * sectors_per_cluster
* bytes_per_sector
),
8430 make_float ((double) free_clusters
8431 * sectors_per_cluster
* bytes_per_sector
),
8432 make_float ((double) free_clusters
8433 * sectors_per_cluster
* bytes_per_sector
));
8440 DEFUN ("default-printer-name", Fdefault_printer_name
, Sdefault_printer_name
,
8441 0, 0, 0, doc
: /* Return the name of Windows default printer device. */)
8444 static char pname_buf
[256];
8447 PRINTER_INFO_2
*ppi2
= NULL
;
8448 DWORD dwNeeded
= 0, dwReturned
= 0;
8450 /* Retrieve the default string from Win.ini (the registry).
8451 * String will be in form "printername,drivername,portname".
8452 * This is the most portable way to get the default printer. */
8453 if (GetProfileString ("windows", "device", ",,", pname_buf
, sizeof (pname_buf
)) <= 0)
8455 /* printername precedes first "," character */
8456 strtok (pname_buf
, ",");
8457 /* We want to know more than the printer name */
8458 if (!OpenPrinter (pname_buf
, &hPrn
, NULL
))
8460 GetPrinter (hPrn
, 2, NULL
, 0, &dwNeeded
);
8463 ClosePrinter (hPrn
);
8466 /* Allocate memory for the PRINTER_INFO_2 struct */
8467 ppi2
= (PRINTER_INFO_2
*) xmalloc (dwNeeded
);
8470 ClosePrinter (hPrn
);
8473 /* Call GetPrinter() again with big enouth memory block */
8474 err
= GetPrinter (hPrn
, 2, (LPBYTE
)ppi2
, dwNeeded
, &dwReturned
);
8475 ClosePrinter (hPrn
);
8484 if (ppi2
->Attributes
& PRINTER_ATTRIBUTE_SHARED
&& ppi2
->pServerName
)
8486 /* a remote printer */
8487 if (*ppi2
->pServerName
== '\\')
8488 _snprintf(pname_buf
, sizeof (pname_buf
), "%s\\%s", ppi2
->pServerName
,
8491 _snprintf(pname_buf
, sizeof (pname_buf
), "\\\\%s\\%s", ppi2
->pServerName
,
8493 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
8497 /* a local printer */
8498 strncpy(pname_buf
, ppi2
->pPortName
, sizeof (pname_buf
));
8499 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
8500 /* `pPortName' can include several ports, delimited by ','.
8501 * we only use the first one. */
8502 strtok(pname_buf
, ",");
8507 return build_string (pname_buf
);
8510 /***********************************************************************
8512 ***********************************************************************/
8514 /* Keep this list in the same order as frame_parms in frame.c.
8515 Use 0 for unsupported frame parameters. */
8517 frame_parm_handler w32_frame_parm_handlers
[] =
8521 x_set_background_color
,
8527 x_set_foreground_color
,
8530 x_set_internal_border_width
,
8531 x_set_menu_bar_lines
,
8533 x_explicitly_set_name
,
8534 x_set_scroll_bar_width
,
8537 x_set_vertical_scroll_bars
,
8539 x_set_tool_bar_lines
,
8540 0, /* x_set_scroll_bar_foreground, */
8541 0, /* x_set_scroll_bar_background, */
8546 0, /* x_set_wait_for_wm, */
8553 globals_of_w32fns ();
8554 /* This is zero if not using MS-Windows. */
8556 track_mouse_window
= NULL
;
8558 w32_visible_system_caret_hwnd
= NULL
;
8560 Qnone
= intern ("none");
8562 Qsuppress_icon
= intern ("suppress-icon");
8563 staticpro (&Qsuppress_icon
);
8564 Qundefined_color
= intern ("undefined-color");
8565 staticpro (&Qundefined_color
);
8566 Qcancel_timer
= intern ("cancel-timer");
8567 staticpro (&Qcancel_timer
);
8569 Qhyper
= intern ("hyper");
8570 staticpro (&Qhyper
);
8571 Qsuper
= intern ("super");
8572 staticpro (&Qsuper
);
8573 Qmeta
= intern ("meta");
8575 Qalt
= intern ("alt");
8577 Qctrl
= intern ("ctrl");
8579 Qcontrol
= intern ("control");
8580 staticpro (&Qcontrol
);
8581 Qshift
= intern ("shift");
8582 staticpro (&Qshift
);
8583 /* This is the end of symbol initialization. */
8585 /* Text property `display' should be nonsticky by default. */
8586 Vtext_property_default_nonsticky
8587 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
8590 Fput (Qundefined_color
, Qerror_conditions
,
8591 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
8592 Fput (Qundefined_color
, Qerror_message
,
8593 build_string ("Undefined color"));
8595 staticpro (&w32_grabbed_keys
);
8596 w32_grabbed_keys
= Qnil
;
8598 DEFVAR_LISP ("w32-color-map", &Vw32_color_map
,
8599 doc
: /* An array of color name mappings for Windows. */);
8600 Vw32_color_map
= Qnil
;
8602 DEFVAR_LISP ("w32-pass-alt-to-system", &Vw32_pass_alt_to_system
,
8603 doc
: /* Non-nil if alt key presses are passed on to Windows.
8604 When non-nil, for example, alt pressed and released and then space will
8605 open the System menu. When nil, Emacs silently swallows alt key events. */);
8606 Vw32_pass_alt_to_system
= Qnil
;
8608 DEFVAR_LISP ("w32-alt-is-meta", &Vw32_alt_is_meta
,
8609 doc
: /* Non-nil if the alt key is to be considered the same as the meta key.
8610 When nil, Emacs will translate the alt key to the Alt modifier, and not Meta. */);
8611 Vw32_alt_is_meta
= Qt
;
8613 DEFVAR_INT ("w32-quit-key", &w32_quit_key
,
8614 doc
: /* If non-zero, the virtual key code for an alternative quit key. */);
8617 DEFVAR_LISP ("w32-pass-lwindow-to-system",
8618 &Vw32_pass_lwindow_to_system
,
8619 doc
: /* Non-nil if the left \"Windows\" key is passed on to Windows.
8620 When non-nil, the Start menu is opened by tapping the key. */);
8621 Vw32_pass_lwindow_to_system
= Qt
;
8623 DEFVAR_LISP ("w32-pass-rwindow-to-system",
8624 &Vw32_pass_rwindow_to_system
,
8625 doc
: /* Non-nil if the right \"Windows\" key is passed on to Windows.
8626 When non-nil, the Start menu is opened by tapping the key. */);
8627 Vw32_pass_rwindow_to_system
= Qt
;
8629 DEFVAR_LISP ("w32-phantom-key-code",
8630 &Vw32_phantom_key_code
,
8631 doc
: /* Virtual key code used to generate \"phantom\" key presses.
8632 Value is a number between 0 and 255.
8634 Phantom key presses are generated in order to stop the system from
8635 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or
8636 `w32-pass-rwindow-to-system' is nil. */);
8637 /* Although 255 is technically not a valid key code, it works and
8638 means that this hack won't interfere with any real key code. */
8639 XSETINT (Vw32_phantom_key_code
, 255);
8641 DEFVAR_LISP ("w32-enable-num-lock",
8642 &Vw32_enable_num_lock
,
8643 doc
: /* Non-nil if Num Lock should act normally.
8644 Set to nil to see Num Lock as the key `kp-numlock'. */);
8645 Vw32_enable_num_lock
= Qt
;
8647 DEFVAR_LISP ("w32-enable-caps-lock",
8648 &Vw32_enable_caps_lock
,
8649 doc
: /* Non-nil if Caps Lock should act normally.
8650 Set to nil to see Caps Lock as the key `capslock'. */);
8651 Vw32_enable_caps_lock
= Qt
;
8653 DEFVAR_LISP ("w32-scroll-lock-modifier",
8654 &Vw32_scroll_lock_modifier
,
8655 doc
: /* Modifier to use for the Scroll Lock on state.
8656 The value can be hyper, super, meta, alt, control or shift for the
8657 respective modifier, or nil to see Scroll Lock as the key `scroll'.
8658 Any other value will cause the key to be ignored. */);
8659 Vw32_scroll_lock_modifier
= Qt
;
8661 DEFVAR_LISP ("w32-lwindow-modifier",
8662 &Vw32_lwindow_modifier
,
8663 doc
: /* Modifier to use for the left \"Windows\" key.
8664 The value can be hyper, super, meta, alt, control or shift for the
8665 respective modifier, or nil to appear as the key `lwindow'.
8666 Any other value will cause the key to be ignored. */);
8667 Vw32_lwindow_modifier
= Qnil
;
8669 DEFVAR_LISP ("w32-rwindow-modifier",
8670 &Vw32_rwindow_modifier
,
8671 doc
: /* Modifier to use for the right \"Windows\" key.
8672 The value can be hyper, super, meta, alt, control or shift for the
8673 respective modifier, or nil to appear as the key `rwindow'.
8674 Any other value will cause the key to be ignored. */);
8675 Vw32_rwindow_modifier
= Qnil
;
8677 DEFVAR_LISP ("w32-apps-modifier",
8678 &Vw32_apps_modifier
,
8679 doc
: /* Modifier to use for the \"Apps\" key.
8680 The value can be hyper, super, meta, alt, control or shift for the
8681 respective modifier, or nil to appear as the key `apps'.
8682 Any other value will cause the key to be ignored. */);
8683 Vw32_apps_modifier
= Qnil
;
8685 DEFVAR_BOOL ("w32-enable-synthesized-fonts", &w32_enable_synthesized_fonts
,
8686 doc
: /* Non-nil enables selection of artificially italicized and bold fonts. */);
8687 w32_enable_synthesized_fonts
= 0;
8689 DEFVAR_LISP ("w32-enable-palette", &Vw32_enable_palette
,
8690 doc
: /* Non-nil enables Windows palette management to map colors exactly. */);
8691 Vw32_enable_palette
= Qt
;
8693 DEFVAR_INT ("w32-mouse-button-tolerance",
8694 &w32_mouse_button_tolerance
,
8695 doc
: /* Analogue of double click interval for faking middle mouse events.
8696 The value is the minimum time in milliseconds that must elapse between
8697 left/right button down events before they are considered distinct events.
8698 If both mouse buttons are depressed within this interval, a middle mouse
8699 button down event is generated instead. */);
8700 w32_mouse_button_tolerance
= GetDoubleClickTime () / 2;
8702 DEFVAR_INT ("w32-mouse-move-interval",
8703 &w32_mouse_move_interval
,
8704 doc
: /* Minimum interval between mouse move events.
8705 The value is the minimum time in milliseconds that must elapse between
8706 successive mouse move (or scroll bar drag) events before they are
8707 reported as lisp events. */);
8708 w32_mouse_move_interval
= 0;
8710 DEFVAR_BOOL ("w32-pass-extra-mouse-buttons-to-system",
8711 &w32_pass_extra_mouse_buttons_to_system
,
8712 doc
: /* Non-nil if the fourth and fifth mouse buttons are passed to Windows.
8713 Recent versions of Windows support mice with up to five buttons.
8714 Since most applications don't support these extra buttons, most mouse
8715 drivers will allow you to map them to functions at the system level.
8716 If this variable is non-nil, Emacs will pass them on, allowing the
8717 system to handle them. */);
8718 w32_pass_extra_mouse_buttons_to_system
= 0;
8720 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
8721 doc
: /* The shape of the pointer when over text.
8722 Changing the value does not affect existing frames
8723 unless you set the mouse color. */);
8724 Vx_pointer_shape
= Qnil
;
8726 Vx_nontext_pointer_shape
= Qnil
;
8728 Vx_mode_pointer_shape
= Qnil
;
8730 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
8731 doc
: /* The shape of the pointer when Emacs is busy.
8732 This variable takes effect when you create a new frame
8733 or when you set the mouse color. */);
8734 Vx_hourglass_pointer_shape
= Qnil
;
8736 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
8737 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
8738 display_hourglass_p
= 1;
8740 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
8741 doc
: /* *Seconds to wait before displaying an hourglass pointer.
8742 Value must be an integer or float. */);
8743 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
8745 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
8746 &Vx_sensitive_text_pointer_shape
,
8747 doc
: /* The shape of the pointer when over mouse-sensitive text.
8748 This variable takes effect when you create a new frame
8749 or when you set the mouse color. */);
8750 Vx_sensitive_text_pointer_shape
= Qnil
;
8752 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
8753 &Vx_window_horizontal_drag_shape
,
8754 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
8755 This variable takes effect when you create a new frame
8756 or when you set the mouse color. */);
8757 Vx_window_horizontal_drag_shape
= Qnil
;
8759 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
8760 doc
: /* A string indicating the foreground color of the cursor box. */);
8761 Vx_cursor_fore_pixel
= Qnil
;
8763 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size
,
8764 doc
: /* Maximum size for tooltips.
8765 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
8766 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
8768 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
8769 doc
: /* Non-nil if no window manager is in use.
8770 Emacs doesn't try to figure this out; this is always nil
8771 unless you set it to something else. */);
8772 /* We don't have any way to find this out, so set it to nil
8773 and maybe the user would like to set it to t. */
8774 Vx_no_window_manager
= Qnil
;
8776 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
8777 &Vx_pixel_size_width_font_regexp
,
8778 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
8780 Since Emacs gets width of a font matching with this regexp from
8781 PIXEL_SIZE field of the name, font finding mechanism gets faster for
8782 such a font. This is especially effective for such large fonts as
8783 Chinese, Japanese, and Korean. */);
8784 Vx_pixel_size_width_font_regexp
= Qnil
;
8786 DEFVAR_LISP ("w32-bdf-filename-alist",
8787 &Vw32_bdf_filename_alist
,
8788 doc
: /* List of bdf fonts and their corresponding filenames. */);
8789 Vw32_bdf_filename_alist
= Qnil
;
8791 DEFVAR_BOOL ("w32-strict-fontnames",
8792 &w32_strict_fontnames
,
8793 doc
: /* Non-nil means only use fonts that are exact matches for those requested.
8794 Default is nil, which allows old fontnames that are not XLFD compliant,
8795 and allows third-party CJK display to work by specifying false charset
8796 fields to trick Emacs into translating to Big5, SJIS etc.
8797 Setting this to t will prevent wrong fonts being selected when
8798 fontsets are automatically created. */);
8799 w32_strict_fontnames
= 0;
8801 DEFVAR_BOOL ("w32-strict-painting",
8802 &w32_strict_painting
,
8803 doc
: /* Non-nil means use strict rules for repainting frames.
8804 Set this to nil to get the old behavior for repainting; this should
8805 only be necessary if the default setting causes problems. */);
8806 w32_strict_painting
= 1;
8808 DEFVAR_LISP ("w32-charset-info-alist",
8809 &Vw32_charset_info_alist
,
8810 doc
: /* Alist linking Emacs character sets to Windows fonts and codepages.
8811 Each entry should be of the form:
8813 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE))
8815 where CHARSET_NAME is a string used in font names to identify the charset,
8816 WINDOWS_CHARSET is a symbol that can be one of:
8817 w32-charset-ansi, w32-charset-default, w32-charset-symbol,
8818 w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312,
8819 w32-charset-chinesebig5,
8820 w32-charset-johab, w32-charset-hebrew,
8821 w32-charset-arabic, w32-charset-greek, w32-charset-turkish,
8822 w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope,
8823 w32-charset-russian, w32-charset-mac, w32-charset-baltic,
8824 w32-charset-unicode,
8826 CODEPAGE should be an integer specifying the codepage that should be used
8827 to display the character set, t to do no translation and output as Unicode,
8828 or nil to do no translation and output as 8 bit (or multibyte on far-east
8829 versions of Windows) characters. */);
8830 Vw32_charset_info_alist
= Qnil
;
8832 staticpro (&Qw32_charset_ansi
);
8833 Qw32_charset_ansi
= intern ("w32-charset-ansi");
8834 staticpro (&Qw32_charset_symbol
);
8835 Qw32_charset_default
= intern ("w32-charset-default");
8836 staticpro (&Qw32_charset_default
);
8837 Qw32_charset_symbol
= intern ("w32-charset-symbol");
8838 staticpro (&Qw32_charset_shiftjis
);
8839 Qw32_charset_shiftjis
= intern ("w32-charset-shiftjis");
8840 staticpro (&Qw32_charset_hangeul
);
8841 Qw32_charset_hangeul
= intern ("w32-charset-hangeul");
8842 staticpro (&Qw32_charset_chinesebig5
);
8843 Qw32_charset_chinesebig5
= intern ("w32-charset-chinesebig5");
8844 staticpro (&Qw32_charset_gb2312
);
8845 Qw32_charset_gb2312
= intern ("w32-charset-gb2312");
8846 staticpro (&Qw32_charset_oem
);
8847 Qw32_charset_oem
= intern ("w32-charset-oem");
8849 #ifdef JOHAB_CHARSET
8851 static int w32_extra_charsets_defined
= 1;
8852 DEFVAR_BOOL ("w32-extra-charsets-defined", &w32_extra_charsets_defined
,
8853 doc
: /* Internal variable. */);
8855 staticpro (&Qw32_charset_johab
);
8856 Qw32_charset_johab
= intern ("w32-charset-johab");
8857 staticpro (&Qw32_charset_easteurope
);
8858 Qw32_charset_easteurope
= intern ("w32-charset-easteurope");
8859 staticpro (&Qw32_charset_turkish
);
8860 Qw32_charset_turkish
= intern ("w32-charset-turkish");
8861 staticpro (&Qw32_charset_baltic
);
8862 Qw32_charset_baltic
= intern ("w32-charset-baltic");
8863 staticpro (&Qw32_charset_russian
);
8864 Qw32_charset_russian
= intern ("w32-charset-russian");
8865 staticpro (&Qw32_charset_arabic
);
8866 Qw32_charset_arabic
= intern ("w32-charset-arabic");
8867 staticpro (&Qw32_charset_greek
);
8868 Qw32_charset_greek
= intern ("w32-charset-greek");
8869 staticpro (&Qw32_charset_hebrew
);
8870 Qw32_charset_hebrew
= intern ("w32-charset-hebrew");
8871 staticpro (&Qw32_charset_vietnamese
);
8872 Qw32_charset_vietnamese
= intern ("w32-charset-vietnamese");
8873 staticpro (&Qw32_charset_thai
);
8874 Qw32_charset_thai
= intern ("w32-charset-thai");
8875 staticpro (&Qw32_charset_mac
);
8876 Qw32_charset_mac
= intern ("w32-charset-mac");
8880 #ifdef UNICODE_CHARSET
8882 static int w32_unicode_charset_defined
= 1;
8883 DEFVAR_BOOL ("w32-unicode-charset-defined",
8884 &w32_unicode_charset_defined
,
8885 doc
: /* Internal variable. */);
8887 staticpro (&Qw32_charset_unicode
);
8888 Qw32_charset_unicode
= intern ("w32-charset-unicode");
8891 #if 0 /* TODO: Port to W32 */
8892 defsubr (&Sx_change_window_property
);
8893 defsubr (&Sx_delete_window_property
);
8894 defsubr (&Sx_window_property
);
8896 defsubr (&Sxw_display_color_p
);
8897 defsubr (&Sx_display_grayscale_p
);
8898 defsubr (&Sxw_color_defined_p
);
8899 defsubr (&Sxw_color_values
);
8900 defsubr (&Sx_server_max_request_size
);
8901 defsubr (&Sx_server_vendor
);
8902 defsubr (&Sx_server_version
);
8903 defsubr (&Sx_display_pixel_width
);
8904 defsubr (&Sx_display_pixel_height
);
8905 defsubr (&Sx_display_mm_width
);
8906 defsubr (&Sx_display_mm_height
);
8907 defsubr (&Sx_display_screens
);
8908 defsubr (&Sx_display_planes
);
8909 defsubr (&Sx_display_color_cells
);
8910 defsubr (&Sx_display_visual_class
);
8911 defsubr (&Sx_display_backing_store
);
8912 defsubr (&Sx_display_save_under
);
8913 defsubr (&Sx_create_frame
);
8914 defsubr (&Sx_open_connection
);
8915 defsubr (&Sx_close_connection
);
8916 defsubr (&Sx_display_list
);
8917 defsubr (&Sx_synchronize
);
8919 /* W32 specific functions */
8921 defsubr (&Sw32_focus_frame
);
8922 defsubr (&Sw32_select_font
);
8923 defsubr (&Sw32_define_rgb_color
);
8924 defsubr (&Sw32_default_color_map
);
8925 defsubr (&Sw32_load_color_file
);
8926 defsubr (&Sw32_send_sys_command
);
8927 defsubr (&Sw32_shell_execute
);
8928 defsubr (&Sw32_register_hot_key
);
8929 defsubr (&Sw32_unregister_hot_key
);
8930 defsubr (&Sw32_registered_hot_keys
);
8931 defsubr (&Sw32_reconstruct_hot_key
);
8932 defsubr (&Sw32_toggle_lock_key
);
8933 defsubr (&Sw32_find_bdf_fonts
);
8935 defsubr (&Sfile_system_info
);
8936 defsubr (&Sdefault_printer_name
);
8938 /* Setting callback functions for fontset handler. */
8939 get_font_info_func
= w32_get_font_info
;
8941 #if 0 /* This function pointer doesn't seem to be used anywhere.
8942 And the pointer assigned has the wrong type, anyway. */
8943 list_fonts_func
= w32_list_fonts
;
8946 load_font_func
= w32_load_font
;
8947 find_ccl_program_func
= w32_find_ccl_program
;
8948 query_font_func
= w32_query_font
;
8949 set_frame_fontset_func
= x_set_font
;
8950 get_font_repertory_func
= x_get_font_repertory
;
8951 check_window_system_func
= check_w32
;
8954 hourglass_atimer
= NULL
;
8955 hourglass_shown_p
= 0;
8956 defsubr (&Sx_show_tip
);
8957 defsubr (&Sx_hide_tip
);
8959 staticpro (&tip_timer
);
8961 staticpro (&tip_frame
);
8963 last_show_tip_args
= Qnil
;
8964 staticpro (&last_show_tip_args
);
8966 defsubr (&Sx_file_dialog
);
8971 globals_of_w32fns is used to initialize those global variables that
8972 must always be initialized on startup even when the global variable
8973 initialized is non zero (see the function main in emacs.c).
8974 globals_of_w32fns is called from syms_of_w32fns when the global
8975 variable initialized is 0 and directly from main when initialized
8978 void globals_of_w32fns ()
8980 HMODULE user32_lib
= GetModuleHandle ("user32.dll");
8982 TrackMouseEvent not available in all versions of Windows, so must load
8983 it dynamically. Do it once, here, instead of every time it is used.
8985 track_mouse_event_fn
= (TrackMouseEvent_Proc
)
8986 GetProcAddress (user32_lib
, "TrackMouseEvent");
8987 /* ditto for GetClipboardSequenceNumber. */
8988 clipboard_sequence_fn
= (ClipboardSequence_Proc
)
8989 GetProcAddress (user32_lib
, "GetClipboardSequenceNumber");
8991 DEFVAR_INT ("w32-ansi-code-page",
8992 &w32_ansi_code_page
,
8993 doc
: /* The ANSI code page used by the system. */);
8994 w32_ansi_code_page
= GetACP ();
8999 void w32_abort (void) NO_RETURN
;
9005 button
= MessageBox (NULL
,
9006 "A fatal error has occurred!\n\n"
9007 "Would you like to attach a debugger?\n\n"
9008 "Select YES to debug, NO to abort Emacs"
9010 "\n\n(type \"gdb -p <emacs-PID>\" and\n"
9011 "\"continue\" inside GDB before clicking YES.)"
9013 , "Emacs Abort Dialog",
9014 MB_ICONEXCLAMATION
| MB_TASKMODAL
9015 | MB_SETFOREGROUND
| MB_YESNO
);
9020 exit (2); /* tell the compiler we will never return */
9028 /* For convenience when debugging. */
9032 return GetLastError ();
9035 /* arch-tag: 707589ab-b9be-4638-8cdd-74629cc9b446
9036 (do not change this comment) */