1 /* Graphical user interface functions for the Microsoft W32 API.
2 Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 /* Added by Kevin Gallo */
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 (!NILP (arg
) || NILP (oldval
))
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
)
2070 Lisp_Object top
= Qunbound
;
2071 Lisp_Object left
= Qunbound
;
2073 rect
.left
= rect
.top
= 0;
2074 rect
.right
= FRAME_PIXEL_WIDTH (f
);
2075 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
2077 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
2078 FRAME_EXTERNAL_MENU_BAR (f
));
2080 /* Do first time app init */
2086 w32_init_class (hinst
);
2088 /* Handle the -geometry command line option and the geometry
2089 settings in the registry. They are decoded and put into
2090 initial-frame-alist by w32-win.el:x-handle-geometry. */
2091 ifa
= Fsymbol_value (intern ("initial-frame-alist"));
2094 Lisp_Object lt
= Fassq (Qleft
, ifa
);
2095 Lisp_Object tp
= Fassq (Qtop
, ifa
);
2112 if (EQ (left
, Qunbound
) && EQ (top
, Qunbound
))
2114 /* When called with RES_TYPE_NUMBER, w32_get_arg will return zero
2115 for anything that is not a number and is not Qunbound. */
2116 left
= w32_get_arg (Qnil
, Qleft
, "left", "Left", RES_TYPE_NUMBER
);
2117 top
= w32_get_arg (Qnil
, Qtop
, "top", "Top", RES_TYPE_NUMBER
);
2120 FRAME_W32_WINDOW (f
) = hwnd
2121 = CreateWindow (EMACS_CLASS
,
2123 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
2124 EQ (left
, Qunbound
) ? CW_USEDEFAULT
: XINT (left
),
2125 EQ (top
, Qunbound
) ? CW_USEDEFAULT
: XINT (top
),
2126 rect
.right
- rect
.left
,
2127 rect
.bottom
- rect
.top
,
2135 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
2136 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
2137 SetWindowLong (hwnd
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
2138 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->scroll_bar_actual_width
);
2139 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
2141 /* Enable drag-n-drop. */
2142 DragAcceptFiles (hwnd
, TRUE
);
2144 /* Do this to discard the default setting specified by our parent. */
2145 ShowWindow (hwnd
, SW_HIDE
);
2147 /* Update frame positions. */
2148 GetWindowRect (hwnd
, &rect
);
2149 f
->left_pos
= rect
.left
;
2150 f
->top_pos
= rect
.top
;
2155 my_post_msg (wmsg
, hwnd
, msg
, wParam
, lParam
)
2162 wmsg
->msg
.hwnd
= hwnd
;
2163 wmsg
->msg
.message
= msg
;
2164 wmsg
->msg
.wParam
= wParam
;
2165 wmsg
->msg
.lParam
= lParam
;
2166 wmsg
->msg
.time
= GetMessageTime ();
2171 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
2172 between left and right keys as advertised. We test for this
2173 support dynamically, and set a flag when the support is absent. If
2174 absent, we keep track of the left and right control and alt keys
2175 ourselves. This is particularly necessary on keyboards that rely
2176 upon the AltGr key, which is represented as having the left control
2177 and right alt keys pressed. For these keyboards, we need to know
2178 when the left alt key has been pressed in addition to the AltGr key
2179 so that we can properly support M-AltGr-key sequences (such as M-@
2180 on Swedish keyboards). */
2182 #define EMACS_LCONTROL 0
2183 #define EMACS_RCONTROL 1
2184 #define EMACS_LMENU 2
2185 #define EMACS_RMENU 3
2187 static int modifiers
[4];
2188 static int modifiers_recorded
;
2189 static int modifier_key_support_tested
;
2192 test_modifier_support (unsigned int wparam
)
2196 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
2198 if (wparam
== VK_CONTROL
)
2208 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
2209 modifiers_recorded
= 1;
2211 modifiers_recorded
= 0;
2212 modifier_key_support_tested
= 1;
2216 record_keydown (unsigned int wparam
, unsigned int lparam
)
2220 if (!modifier_key_support_tested
)
2221 test_modifier_support (wparam
);
2223 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2226 if (wparam
== VK_CONTROL
)
2227 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2229 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2235 record_keyup (unsigned int wparam
, unsigned int lparam
)
2239 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2242 if (wparam
== VK_CONTROL
)
2243 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2245 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2250 /* Emacs can lose focus while a modifier key has been pressed. When
2251 it regains focus, be conservative and clear all modifiers since
2252 we cannot reconstruct the left and right modifier state. */
2258 if (GetFocus () == NULL
)
2259 /* Emacs doesn't have keyboard focus. Do nothing. */
2262 ctrl
= GetAsyncKeyState (VK_CONTROL
);
2263 alt
= GetAsyncKeyState (VK_MENU
);
2265 if (!(ctrl
& 0x08000))
2266 /* Clear any recorded control modifier state. */
2267 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2269 if (!(alt
& 0x08000))
2270 /* Clear any recorded alt modifier state. */
2271 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2273 /* Update the state of all modifier keys, because modifiers used in
2274 hot-key combinations can get stuck on if Emacs loses focus as a
2275 result of a hot-key being pressed. */
2279 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
2281 GetKeyboardState (keystate
);
2282 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
2283 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
2284 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
2285 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
2286 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
2287 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
2288 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
2289 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
2290 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
2291 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
2292 SetKeyboardState (keystate
);
2296 /* Synchronize modifier state with what is reported with the current
2297 keystroke. Even if we cannot distinguish between left and right
2298 modifier keys, we know that, if no modifiers are set, then neither
2299 the left or right modifier should be set. */
2303 if (!modifiers_recorded
)
2306 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
2307 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2309 if (!(GetKeyState (VK_MENU
) & 0x8000))
2310 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2314 modifier_set (int vkey
)
2316 if (vkey
== VK_CAPITAL
|| vkey
== VK_SCROLL
)
2317 return (GetKeyState (vkey
) & 0x1);
2318 if (!modifiers_recorded
)
2319 return (GetKeyState (vkey
) & 0x8000);
2324 return modifiers
[EMACS_LCONTROL
];
2326 return modifiers
[EMACS_RCONTROL
];
2328 return modifiers
[EMACS_LMENU
];
2330 return modifiers
[EMACS_RMENU
];
2332 return (GetKeyState (vkey
) & 0x8000);
2335 /* Convert between the modifier bits W32 uses and the modifier bits
2339 w32_key_to_modifier (int key
)
2341 Lisp_Object key_mapping
;
2346 key_mapping
= Vw32_lwindow_modifier
;
2349 key_mapping
= Vw32_rwindow_modifier
;
2352 key_mapping
= Vw32_apps_modifier
;
2355 key_mapping
= Vw32_scroll_lock_modifier
;
2361 /* NB. This code runs in the input thread, asychronously to the lisp
2362 thread, so we must be careful to ensure access to lisp data is
2363 thread-safe. The following code is safe because the modifier
2364 variable values are updated atomically from lisp and symbols are
2365 not relocated by GC. Also, we don't have to worry about seeing GC
2367 if (EQ (key_mapping
, Qhyper
))
2368 return hyper_modifier
;
2369 if (EQ (key_mapping
, Qsuper
))
2370 return super_modifier
;
2371 if (EQ (key_mapping
, Qmeta
))
2372 return meta_modifier
;
2373 if (EQ (key_mapping
, Qalt
))
2374 return alt_modifier
;
2375 if (EQ (key_mapping
, Qctrl
))
2376 return ctrl_modifier
;
2377 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
2378 return ctrl_modifier
;
2379 if (EQ (key_mapping
, Qshift
))
2380 return shift_modifier
;
2382 /* Don't generate any modifier if not explicitly requested. */
2387 w32_get_modifiers ()
2389 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
2390 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
2391 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
2392 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
2393 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
2394 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
2395 (modifier_set (VK_MENU
) ?
2396 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
2399 /* We map the VK_* modifiers into console modifier constants
2400 so that we can use the same routines to handle both console
2401 and window input. */
2404 construct_console_modifiers ()
2409 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
2410 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
2411 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
2412 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
2413 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
2414 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
2415 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
2416 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
2417 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
2418 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
2419 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
2425 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
2429 /* Convert to emacs modifiers. */
2430 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
2436 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
2438 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
2441 if (virt_key
== VK_RETURN
)
2442 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
2444 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
2445 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
2447 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
2448 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
2450 if (virt_key
== VK_CLEAR
)
2451 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
2456 /* List of special key combinations which w32 would normally capture,
2457 but emacs should grab instead. Not directly visible to lisp, to
2458 simplify synchronization. Each item is an integer encoding a virtual
2459 key code and modifier combination to capture. */
2460 Lisp_Object w32_grabbed_keys
;
2462 #define HOTKEY(vk,mods) make_number (((vk) & 255) | ((mods) << 8))
2463 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
2464 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
2465 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
2467 #define RAW_HOTKEY_ID(k) ((k) & 0xbfff)
2468 #define RAW_HOTKEY_VK_CODE(k) ((k) & 255)
2469 #define RAW_HOTKEY_MODIFIERS(k) ((k) >> 8)
2471 /* Register hot-keys for reserved key combinations when Emacs has
2472 keyboard focus, since this is the only way Emacs can receive key
2473 combinations like Alt-Tab which are used by the system. */
2476 register_hot_keys (hwnd
)
2479 Lisp_Object keylist
;
2481 /* Use GC_CONSP, since we are called asynchronously. */
2482 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
2484 Lisp_Object key
= XCAR (keylist
);
2486 /* Deleted entries get set to nil. */
2487 if (!INTEGERP (key
))
2490 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
2491 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
2496 unregister_hot_keys (hwnd
)
2499 Lisp_Object keylist
;
2501 /* Use GC_CONSP, since we are called asynchronously. */
2502 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
2504 Lisp_Object key
= XCAR (keylist
);
2506 if (!INTEGERP (key
))
2509 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
2513 /* Main message dispatch loop. */
2516 w32_msg_pump (deferred_msg
* msg_buf
)
2522 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
2524 while (GetMessage (&msg
, NULL
, 0, 0))
2526 if (msg
.hwnd
== NULL
)
2528 switch (msg
.message
)
2531 /* Produced by complete_deferred_msg; just ignore. */
2533 case WM_EMACS_CREATEWINDOW
:
2534 w32_createwindow ((struct frame
*) msg
.wParam
);
2535 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2538 case WM_EMACS_SETLOCALE
:
2539 SetThreadLocale (msg
.wParam
);
2540 /* Reply is not expected. */
2542 case WM_EMACS_SETKEYBOARDLAYOUT
:
2543 result
= (int) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
2544 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2548 case WM_EMACS_REGISTER_HOT_KEY
:
2549 focus_window
= GetFocus ();
2550 if (focus_window
!= NULL
)
2551 RegisterHotKey (focus_window
,
2552 RAW_HOTKEY_ID (msg
.wParam
),
2553 RAW_HOTKEY_MODIFIERS (msg
.wParam
),
2554 RAW_HOTKEY_VK_CODE (msg
.wParam
));
2555 /* Reply is not expected. */
2557 case WM_EMACS_UNREGISTER_HOT_KEY
:
2558 focus_window
= GetFocus ();
2559 if (focus_window
!= NULL
)
2560 UnregisterHotKey (focus_window
, RAW_HOTKEY_ID (msg
.wParam
));
2561 /* Mark item as erased. NB: this code must be
2562 thread-safe. The next line is okay because the cons
2563 cell is never made into garbage and is not relocated by
2565 XSETCAR ((Lisp_Object
) ((EMACS_INT
) msg
.lParam
), Qnil
);
2566 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2569 case WM_EMACS_TOGGLE_LOCK_KEY
:
2571 int vk_code
= (int) msg
.wParam
;
2572 int cur_state
= (GetKeyState (vk_code
) & 1);
2573 Lisp_Object new_state
= (Lisp_Object
) ((EMACS_INT
) msg
.lParam
);
2575 /* NB: This code must be thread-safe. It is safe to
2576 call NILP because symbols are not relocated by GC,
2577 and pointer here is not touched by GC (so the markbit
2578 can't be set). Numbers are safe because they are
2579 immediate values. */
2580 if (NILP (new_state
)
2581 || (NUMBERP (new_state
)
2582 && ((XUINT (new_state
)) & 1) != cur_state
))
2584 one_w32_display_info
.faked_key
= vk_code
;
2586 keybd_event ((BYTE
) vk_code
,
2587 (BYTE
) MapVirtualKey (vk_code
, 0),
2588 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2589 keybd_event ((BYTE
) vk_code
,
2590 (BYTE
) MapVirtualKey (vk_code
, 0),
2591 KEYEVENTF_EXTENDEDKEY
| 0, 0);
2592 keybd_event ((BYTE
) vk_code
,
2593 (BYTE
) MapVirtualKey (vk_code
, 0),
2594 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2595 cur_state
= !cur_state
;
2597 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2603 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
2608 DispatchMessage (&msg
);
2611 /* Exit nested loop when our deferred message has completed. */
2612 if (msg_buf
->completed
)
2617 deferred_msg
* deferred_msg_head
;
2619 static deferred_msg
*
2620 find_deferred_msg (HWND hwnd
, UINT msg
)
2622 deferred_msg
* item
;
2624 /* Don't actually need synchronization for read access, since
2625 modification of single pointer is always atomic. */
2626 /* enter_crit (); */
2628 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2629 if (item
->w32msg
.msg
.hwnd
== hwnd
2630 && item
->w32msg
.msg
.message
== msg
)
2633 /* leave_crit (); */
2639 send_deferred_msg (deferred_msg
* msg_buf
,
2645 /* Only input thread can send deferred messages. */
2646 if (GetCurrentThreadId () != dwWindowsThreadId
)
2649 /* It is an error to send a message that is already deferred. */
2650 if (find_deferred_msg (hwnd
, msg
) != NULL
)
2653 /* Enforced synchronization is not needed because this is the only
2654 function that alters deferred_msg_head, and the following critical
2655 section is guaranteed to only be serially reentered (since only the
2656 input thread can call us). */
2658 /* enter_crit (); */
2660 msg_buf
->completed
= 0;
2661 msg_buf
->next
= deferred_msg_head
;
2662 deferred_msg_head
= msg_buf
;
2663 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
2665 /* leave_crit (); */
2667 /* Start a new nested message loop to process other messages until
2668 this one is completed. */
2669 w32_msg_pump (msg_buf
);
2671 deferred_msg_head
= msg_buf
->next
;
2673 return msg_buf
->result
;
2677 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
2679 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
2681 if (msg_buf
== NULL
)
2682 /* Message may have been cancelled, so don't abort(). */
2685 msg_buf
->result
= result
;
2686 msg_buf
->completed
= 1;
2688 /* Ensure input thread is woken so it notices the completion. */
2689 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2693 cancel_all_deferred_msgs ()
2695 deferred_msg
* item
;
2697 /* Don't actually need synchronization for read access, since
2698 modification of single pointer is always atomic. */
2699 /* enter_crit (); */
2701 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2704 item
->completed
= 1;
2707 /* leave_crit (); */
2709 /* Ensure input thread is woken so it notices the completion. */
2710 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2718 deferred_msg dummy_buf
;
2720 /* Ensure our message queue is created */
2722 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
2724 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2727 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
2728 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
2729 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
2731 /* This is the inital message loop which should only exit when the
2732 application quits. */
2733 w32_msg_pump (&dummy_buf
);
2739 signal_user_input ()
2741 /* Interrupt any lisp that wants to be interrupted by input. */
2742 if (!NILP (Vthrow_on_input
))
2744 Vquit_flag
= Vthrow_on_input
;
2745 /* If we're inside a function that wants immediate quits,
2747 if (immediate_quit
&& NILP (Vinhibit_quit
))
2757 post_character_message (hwnd
, msg
, wParam
, lParam
, modifiers
)
2767 wmsg
.dwModifiers
= modifiers
;
2769 /* Detect quit_char and set quit-flag directly. Note that we
2770 still need to post a message to ensure the main thread will be
2771 woken up if blocked in sys_select(), but we do NOT want to post
2772 the quit_char message itself (because it will usually be as if
2773 the user had typed quit_char twice). Instead, we post a dummy
2774 message that has no particular effect. */
2777 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
2778 c
= make_ctrl_char (c
) & 0377;
2780 || (wmsg
.dwModifiers
== 0 &&
2781 w32_quit_key
&& wParam
== w32_quit_key
))
2785 /* The choice of message is somewhat arbitrary, as long as
2786 the main thread handler just ignores it. */
2789 /* Interrupt any blocking system calls. */
2792 /* As a safety precaution, forcibly complete any deferred
2793 messages. This is a kludge, but I don't see any particularly
2794 clean way to handle the situation where a deferred message is
2795 "dropped" in the lisp thread, and will thus never be
2796 completed, eg. by the user trying to activate the menubar
2797 when the lisp thread is busy, and then typing C-g when the
2798 menubar doesn't open promptly (with the result that the
2799 menubar never responds at all because the deferred
2800 WM_INITMENU message is never completed). Another problem
2801 situation is when the lisp thread calls SendMessage (to send
2802 a window manager command) when a message has been deferred;
2803 the lisp thread gets blocked indefinitely waiting for the
2804 deferred message to be completed, which itself is waiting for
2805 the lisp thread to respond.
2807 Note that we don't want to block the input thread waiting for
2808 a reponse from the lisp thread (although that would at least
2809 solve the deadlock problem above), because we want to be able
2810 to receive C-g to interrupt the lisp thread. */
2811 cancel_all_deferred_msgs ();
2814 signal_user_input ();
2817 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2820 /* Main window procedure */
2823 w32_wnd_proc (hwnd
, msg
, wParam
, lParam
)
2830 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
2832 int windows_translate
;
2835 /* Note that it is okay to call x_window_to_frame, even though we are
2836 not running in the main lisp thread, because frame deletion
2837 requires the lisp thread to synchronize with this thread. Thus, if
2838 a frame struct is returned, it can be used without concern that the
2839 lisp thread might make it disappear while we are using it.
2841 NB. Walking the frame list in this thread is safe (as long as
2842 writes of Lisp_Object slots are atomic, which they are on Windows).
2843 Although delete-frame can destructively modify the frame list while
2844 we are walking it, a garbage collection cannot occur until after
2845 delete-frame has synchronized with this thread.
2847 It is also safe to use functions that make GDI calls, such as
2848 w32_clear_rect, because these functions must obtain a DC handle
2849 from the frame struct using get_frame_dc which is thread-aware. */
2854 f
= x_window_to_frame (dpyinfo
, hwnd
);
2857 HDC hdc
= get_frame_dc (f
);
2858 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
2859 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
2860 release_frame_dc (f
, hdc
);
2862 #if defined (W32_DEBUG_DISPLAY)
2863 DebPrint (("WM_ERASEBKGND (frame %p): erasing %d,%d-%d,%d\n",
2865 wmsg
.rect
.left
, wmsg
.rect
.top
,
2866 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2867 #endif /* W32_DEBUG_DISPLAY */
2870 case WM_PALETTECHANGED
:
2871 /* ignore our own changes */
2872 if ((HWND
)wParam
!= hwnd
)
2874 f
= x_window_to_frame (dpyinfo
, hwnd
);
2876 /* get_frame_dc will realize our palette and force all
2877 frames to be redrawn if needed. */
2878 release_frame_dc (f
, get_frame_dc (f
));
2883 PAINTSTRUCT paintStruct
;
2885 bzero (&update_rect
, sizeof (update_rect
));
2887 f
= x_window_to_frame (dpyinfo
, hwnd
);
2890 DebPrint (("WM_PAINT received for unknown window %p\n", hwnd
));
2894 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
2895 fails. Apparently this can happen under some
2897 if (GetUpdateRect (hwnd
, &update_rect
, FALSE
) || !w32_strict_painting
)
2900 BeginPaint (hwnd
, &paintStruct
);
2902 /* The rectangles returned by GetUpdateRect and BeginPaint
2903 do not always match. Play it safe by assuming both areas
2905 UnionRect (&(wmsg
.rect
), &update_rect
, &(paintStruct
.rcPaint
));
2907 #if defined (W32_DEBUG_DISPLAY)
2908 DebPrint (("WM_PAINT (frame %p): painting %d,%d-%d,%d\n",
2910 wmsg
.rect
.left
, wmsg
.rect
.top
,
2911 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2912 DebPrint ((" [update region is %d,%d-%d,%d]\n",
2913 update_rect
.left
, update_rect
.top
,
2914 update_rect
.right
, update_rect
.bottom
));
2916 EndPaint (hwnd
, &paintStruct
);
2919 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2924 /* If GetUpdateRect returns 0 (meaning there is no update
2925 region), assume the whole window needs to be repainted. */
2926 GetClientRect(hwnd
, &wmsg
.rect
);
2927 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2931 case WM_INPUTLANGCHANGE
:
2932 /* Inform lisp thread of keyboard layout changes. */
2933 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2935 /* Clear dead keys in the keyboard state; for simplicity only
2936 preserve modifier key states. */
2941 GetKeyboardState (keystate
);
2942 for (i
= 0; i
< 256; i
++)
2959 SetKeyboardState (keystate
);
2964 /* Synchronize hot keys with normal input. */
2965 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
2970 record_keyup (wParam
, lParam
);
2975 /* Ignore keystrokes we fake ourself; see below. */
2976 if (dpyinfo
->faked_key
== wParam
)
2978 dpyinfo
->faked_key
= 0;
2979 /* Make sure TranslateMessage sees them though (as long as
2980 they don't produce WM_CHAR messages). This ensures that
2981 indicator lights are toggled promptly on Windows 9x, for
2983 if (lispy_function_keys
[wParam
] != 0)
2985 windows_translate
= 1;
2991 /* Synchronize modifiers with current keystroke. */
2993 record_keydown (wParam
, lParam
);
2994 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
2996 windows_translate
= 0;
3001 if (NILP (Vw32_pass_lwindow_to_system
))
3003 /* Prevent system from acting on keyup (which opens the
3004 Start menu if no other key was pressed) by simulating a
3005 press of Space which we will ignore. */
3006 if (GetAsyncKeyState (wParam
) & 1)
3008 if (NUMBERP (Vw32_phantom_key_code
))
3009 key
= XUINT (Vw32_phantom_key_code
) & 255;
3012 dpyinfo
->faked_key
= key
;
3013 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
3016 if (!NILP (Vw32_lwindow_modifier
))
3020 if (NILP (Vw32_pass_rwindow_to_system
))
3022 if (GetAsyncKeyState (wParam
) & 1)
3024 if (NUMBERP (Vw32_phantom_key_code
))
3025 key
= XUINT (Vw32_phantom_key_code
) & 255;
3028 dpyinfo
->faked_key
= key
;
3029 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
3032 if (!NILP (Vw32_rwindow_modifier
))
3036 if (!NILP (Vw32_apps_modifier
))
3040 if (NILP (Vw32_pass_alt_to_system
))
3041 /* Prevent DefWindowProc from activating the menu bar if an
3042 Alt key is pressed and released by itself. */
3044 windows_translate
= 1;
3047 /* Decide whether to treat as modifier or function key. */
3048 if (NILP (Vw32_enable_caps_lock
))
3049 goto disable_lock_key
;
3050 windows_translate
= 1;
3053 /* Decide whether to treat as modifier or function key. */
3054 if (NILP (Vw32_enable_num_lock
))
3055 goto disable_lock_key
;
3056 windows_translate
= 1;
3059 /* Decide whether to treat as modifier or function key. */
3060 if (NILP (Vw32_scroll_lock_modifier
))
3061 goto disable_lock_key
;
3062 windows_translate
= 1;
3065 /* Ensure the appropriate lock key state (and indicator light)
3066 remains in the same state. We do this by faking another
3067 press of the relevant key. Apparently, this really is the
3068 only way to toggle the state of the indicator lights. */
3069 dpyinfo
->faked_key
= wParam
;
3070 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3071 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3072 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3073 KEYEVENTF_EXTENDEDKEY
| 0, 0);
3074 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3075 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3076 /* Ensure indicator lights are updated promptly on Windows 9x
3077 (TranslateMessage apparently does this), after forwarding
3079 post_character_message (hwnd
, msg
, wParam
, lParam
,
3080 w32_get_key_modifiers (wParam
, lParam
));
3081 windows_translate
= 1;
3085 case VK_PROCESSKEY
: /* Generated by IME. */
3086 windows_translate
= 1;
3089 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
3090 which is confusing for purposes of key binding; convert
3091 VK_CANCEL events into VK_PAUSE events. */
3095 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
3096 for purposes of key binding; convert these back into
3097 VK_NUMLOCK events, at least when we want to see NumLock key
3098 presses. (Note that there is never any possibility that
3099 VK_PAUSE with Ctrl really is C-Pause as per above.) */
3100 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
3101 wParam
= VK_NUMLOCK
;
3104 /* If not defined as a function key, change it to a WM_CHAR message. */
3105 if (lispy_function_keys
[wParam
] == 0)
3107 DWORD modifiers
= construct_console_modifiers ();
3109 if (!NILP (Vw32_recognize_altgr
)
3110 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
3112 /* Always let TranslateMessage handle AltGr key chords;
3113 for some reason, ToAscii doesn't always process AltGr
3114 chords correctly. */
3115 windows_translate
= 1;
3117 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
3119 /* Handle key chords including any modifiers other
3120 than shift directly, in order to preserve as much
3121 modifier information as possible. */
3122 if ('A' <= wParam
&& wParam
<= 'Z')
3124 /* Don't translate modified alphabetic keystrokes,
3125 so the user doesn't need to constantly switch
3126 layout to type control or meta keystrokes when
3127 the normal layout translates alphabetic
3128 characters to non-ascii characters. */
3129 if (!modifier_set (VK_SHIFT
))
3130 wParam
+= ('a' - 'A');
3135 /* Try to handle other keystrokes by determining the
3136 base character (ie. translating the base key plus
3140 KEY_EVENT_RECORD key
;
3142 key
.bKeyDown
= TRUE
;
3143 key
.wRepeatCount
= 1;
3144 key
.wVirtualKeyCode
= wParam
;
3145 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
3146 key
.uChar
.AsciiChar
= 0;
3147 key
.dwControlKeyState
= modifiers
;
3149 add
= w32_kbd_patch_key (&key
);
3150 /* 0 means an unrecognised keycode, negative means
3151 dead key. Ignore both. */
3154 /* Forward asciified character sequence. */
3155 post_character_message
3156 (hwnd
, WM_CHAR
, key
.uChar
.AsciiChar
, lParam
,
3157 w32_get_key_modifiers (wParam
, lParam
));
3158 w32_kbd_patch_key (&key
);
3165 /* Let TranslateMessage handle everything else. */
3166 windows_translate
= 1;
3172 if (windows_translate
)
3174 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
3176 windows_msg
.time
= GetMessageTime ();
3177 TranslateMessage (&windows_msg
);
3185 post_character_message (hwnd
, msg
, wParam
, lParam
,
3186 w32_get_key_modifiers (wParam
, lParam
));
3189 /* Simulate middle mouse button events when left and right buttons
3190 are used together, but only if user has two button mouse. */
3191 case WM_LBUTTONDOWN
:
3192 case WM_RBUTTONDOWN
:
3193 if (w32_num_mouse_buttons
> 2)
3194 goto handle_plain_button
;
3197 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
3198 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
3200 if (button_state
& this)
3203 if (button_state
== 0)
3206 button_state
|= this;
3208 if (button_state
& other
)
3210 if (mouse_button_timer
)
3212 KillTimer (hwnd
, mouse_button_timer
);
3213 mouse_button_timer
= 0;
3215 /* Generate middle mouse event instead. */
3216 msg
= WM_MBUTTONDOWN
;
3217 button_state
|= MMOUSE
;
3219 else if (button_state
& MMOUSE
)
3221 /* Ignore button event if we've already generated a
3222 middle mouse down event. This happens if the
3223 user releases and press one of the two buttons
3224 after we've faked a middle mouse event. */
3229 /* Flush out saved message. */
3230 post_msg (&saved_mouse_button_msg
);
3232 wmsg
.dwModifiers
= w32_get_modifiers ();
3233 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3234 signal_user_input ();
3236 /* Clear message buffer. */
3237 saved_mouse_button_msg
.msg
.hwnd
= 0;
3241 /* Hold onto message for now. */
3242 mouse_button_timer
=
3243 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
3244 w32_mouse_button_tolerance
, NULL
);
3245 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
3246 saved_mouse_button_msg
.msg
.message
= msg
;
3247 saved_mouse_button_msg
.msg
.wParam
= wParam
;
3248 saved_mouse_button_msg
.msg
.lParam
= lParam
;
3249 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
3250 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
3257 if (w32_num_mouse_buttons
> 2)
3258 goto handle_plain_button
;
3261 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
3262 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
3264 if ((button_state
& this) == 0)
3267 button_state
&= ~this;
3269 if (button_state
& MMOUSE
)
3271 /* Only generate event when second button is released. */
3272 if ((button_state
& other
) == 0)
3275 button_state
&= ~MMOUSE
;
3277 if (button_state
) abort ();
3284 /* Flush out saved message if necessary. */
3285 if (saved_mouse_button_msg
.msg
.hwnd
)
3287 post_msg (&saved_mouse_button_msg
);
3290 wmsg
.dwModifiers
= w32_get_modifiers ();
3291 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3292 signal_user_input ();
3294 /* Always clear message buffer and cancel timer. */
3295 saved_mouse_button_msg
.msg
.hwnd
= 0;
3296 KillTimer (hwnd
, mouse_button_timer
);
3297 mouse_button_timer
= 0;
3299 if (button_state
== 0)
3304 case WM_XBUTTONDOWN
:
3306 if (w32_pass_extra_mouse_buttons_to_system
)
3308 /* else fall through and process them. */
3309 case WM_MBUTTONDOWN
:
3311 handle_plain_button
:
3316 /* Ignore middle and extra buttons as long as the menu is active. */
3317 f
= x_window_to_frame (dpyinfo
, hwnd
);
3318 if (f
&& f
->output_data
.w32
->menubar_active
)
3321 if (parse_button (msg
, HIWORD (wParam
), &button
, &up
))
3323 if (up
) ReleaseCapture ();
3324 else SetCapture (hwnd
);
3325 button
= (button
== 0) ? LMOUSE
:
3326 ((button
== 1) ? MMOUSE
: RMOUSE
);
3328 button_state
&= ~button
;
3330 button_state
|= button
;
3334 wmsg
.dwModifiers
= w32_get_modifiers ();
3335 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3336 signal_user_input ();
3338 /* Need to return true for XBUTTON messages, false for others,
3339 to indicate that we processed the message. */
3340 return (msg
== WM_XBUTTONDOWN
|| msg
== WM_XBUTTONUP
);
3343 /* Ignore mouse movements as long as the menu is active. These
3344 movements are processed by the window manager anyway, and
3345 it's wrong to handle them as if they happened on the
3346 underlying frame. */
3347 f
= x_window_to_frame (dpyinfo
, hwnd
);
3348 if (f
&& f
->output_data
.w32
->menubar_active
)
3351 /* If the mouse has just moved into the frame, start tracking
3352 it, so we will be notified when it leaves the frame. Mouse
3353 tracking only works under W98 and NT4 and later. On earlier
3354 versions, there is no way of telling when the mouse leaves the
3355 frame, so we just have to put up with help-echo and mouse
3356 highlighting remaining while the frame is not active. */
3357 if (track_mouse_event_fn
&& !track_mouse_window
)
3359 TRACKMOUSEEVENT tme
;
3360 tme
.cbSize
= sizeof (tme
);
3361 tme
.dwFlags
= TME_LEAVE
;
3362 tme
.hwndTrack
= hwnd
;
3364 track_mouse_event_fn (&tme
);
3365 track_mouse_window
= hwnd
;
3368 if (w32_mouse_move_interval
<= 0
3369 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
3371 wmsg
.dwModifiers
= w32_get_modifiers ();
3372 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3376 /* Hang onto mouse move and scroll messages for a bit, to avoid
3377 sending such events to Emacs faster than it can process them.
3378 If we get more events before the timer from the first message
3379 expires, we just replace the first message. */
3381 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
3383 SetTimer (hwnd
, MOUSE_MOVE_ID
,
3384 w32_mouse_move_interval
, NULL
);
3386 /* Hold onto message for now. */
3387 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
3388 saved_mouse_move_msg
.msg
.message
= msg
;
3389 saved_mouse_move_msg
.msg
.wParam
= wParam
;
3390 saved_mouse_move_msg
.msg
.lParam
= lParam
;
3391 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
3392 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
3397 wmsg
.dwModifiers
= w32_get_modifiers ();
3398 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3399 signal_user_input ();
3403 wmsg
.dwModifiers
= w32_get_modifiers ();
3404 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3405 signal_user_input ();
3409 /* Flush out saved messages if necessary. */
3410 if (wParam
== mouse_button_timer
)
3412 if (saved_mouse_button_msg
.msg
.hwnd
)
3414 post_msg (&saved_mouse_button_msg
);
3415 signal_user_input ();
3416 saved_mouse_button_msg
.msg
.hwnd
= 0;
3418 KillTimer (hwnd
, mouse_button_timer
);
3419 mouse_button_timer
= 0;
3421 else if (wParam
== mouse_move_timer
)
3423 if (saved_mouse_move_msg
.msg
.hwnd
)
3425 post_msg (&saved_mouse_move_msg
);
3426 saved_mouse_move_msg
.msg
.hwnd
= 0;
3428 KillTimer (hwnd
, mouse_move_timer
);
3429 mouse_move_timer
= 0;
3431 else if (wParam
== menu_free_timer
)
3433 KillTimer (hwnd
, menu_free_timer
);
3434 menu_free_timer
= 0;
3435 f
= x_window_to_frame (dpyinfo
, hwnd
);
3436 if (!f
->output_data
.w32
->menu_command_in_progress
)
3438 /* Free memory used by owner-drawn and help-echo strings. */
3439 w32_free_menu_strings (hwnd
);
3440 f
->output_data
.w32
->menubar_active
= 0;
3446 /* Windows doesn't send us focus messages when putting up and
3447 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
3448 The only indication we get that something happened is receiving
3449 this message afterwards. So this is a good time to reset our
3450 keyboard modifiers' state. */
3457 /* We must ensure menu bar is fully constructed and up to date
3458 before allowing user interaction with it. To achieve this
3459 we send this message to the lisp thread and wait for a
3460 reply (whose value is not actually needed) to indicate that
3461 the menu bar is now ready for use, so we can now return.
3463 To remain responsive in the meantime, we enter a nested message
3464 loop that can process all other messages.
3466 However, we skip all this if the message results from calling
3467 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
3468 thread a message because it is blocked on us at this point. We
3469 set menubar_active before calling TrackPopupMenu to indicate
3470 this (there is no possibility of confusion with real menubar
3473 f
= x_window_to_frame (dpyinfo
, hwnd
);
3475 && (f
->output_data
.w32
->menubar_active
3476 /* We can receive this message even in the absence of a
3477 menubar (ie. when the system menu is activated) - in this
3478 case we do NOT want to forward the message, otherwise it
3479 will cause the menubar to suddenly appear when the user
3480 had requested it to be turned off! */
3481 || f
->output_data
.w32
->menubar_widget
== NULL
))
3485 deferred_msg msg_buf
;
3487 /* Detect if message has already been deferred; in this case
3488 we cannot return any sensible value to ignore this. */
3489 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3492 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
3495 case WM_EXITMENULOOP
:
3496 f
= x_window_to_frame (dpyinfo
, hwnd
);
3498 /* If a menu command is not already in progress, check again
3499 after a short delay, since Windows often (always?) sends the
3500 WM_EXITMENULOOP before the corresponding WM_COMMAND message. */
3501 if (f
&& !f
->output_data
.w32
->menu_command_in_progress
)
3502 menu_free_timer
= SetTimer (hwnd
, MENU_FREE_ID
, MENU_FREE_DELAY
, NULL
);
3506 /* Direct handling of help_echo in menus. Should be safe now
3507 that we generate the help_echo by placing a help event in the
3510 HMENU menu
= (HMENU
) lParam
;
3511 UINT menu_item
= (UINT
) LOWORD (wParam
);
3512 UINT flags
= (UINT
) HIWORD (wParam
);
3514 w32_menu_display_help (hwnd
, menu
, menu_item
, flags
);
3518 case WM_MEASUREITEM
:
3519 f
= x_window_to_frame (dpyinfo
, hwnd
);
3522 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
3524 if (pMis
->CtlType
== ODT_MENU
)
3526 /* Work out dimensions for popup menu titles. */
3527 char * title
= (char *) pMis
->itemData
;
3528 HDC hdc
= GetDC (hwnd
);
3529 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3530 LOGFONT menu_logfont
;
3534 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3535 menu_logfont
.lfWeight
= FW_BOLD
;
3536 menu_font
= CreateFontIndirect (&menu_logfont
);
3537 old_font
= SelectObject (hdc
, menu_font
);
3539 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
3542 if (unicode_append_menu
)
3543 GetTextExtentPoint32W (hdc
, (WCHAR
*) title
,
3544 wcslen ((WCHAR
*) title
),
3547 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
3549 pMis
->itemWidth
= size
.cx
;
3550 if (pMis
->itemHeight
< size
.cy
)
3551 pMis
->itemHeight
= size
.cy
;
3554 pMis
->itemWidth
= 0;
3556 SelectObject (hdc
, old_font
);
3557 DeleteObject (menu_font
);
3558 ReleaseDC (hwnd
, hdc
);
3565 f
= x_window_to_frame (dpyinfo
, hwnd
);
3568 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
3570 if (pDis
->CtlType
== ODT_MENU
)
3572 /* Draw popup menu title. */
3573 char * title
= (char *) pDis
->itemData
;
3576 HDC hdc
= pDis
->hDC
;
3577 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3578 LOGFONT menu_logfont
;
3581 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3582 menu_logfont
.lfWeight
= FW_BOLD
;
3583 menu_font
= CreateFontIndirect (&menu_logfont
);
3584 old_font
= SelectObject (hdc
, menu_font
);
3586 /* Always draw title as if not selected. */
3587 if (unicode_append_menu
)
3590 + GetSystemMetrics (SM_CXMENUCHECK
),
3592 ETO_OPAQUE
, &pDis
->rcItem
,
3594 wcslen ((WCHAR
*) title
), NULL
);
3598 + GetSystemMetrics (SM_CXMENUCHECK
),
3600 ETO_OPAQUE
, &pDis
->rcItem
,
3601 title
, strlen (title
), NULL
);
3603 SelectObject (hdc
, old_font
);
3604 DeleteObject (menu_font
);
3612 /* Still not right - can't distinguish between clicks in the
3613 client area of the frame from clicks forwarded from the scroll
3614 bars - may have to hook WM_NCHITTEST to remember the mouse
3615 position and then check if it is in the client area ourselves. */
3616 case WM_MOUSEACTIVATE
:
3617 /* Discard the mouse click that activates a frame, allowing the
3618 user to click anywhere without changing point (or worse!).
3619 Don't eat mouse clicks on scrollbars though!! */
3620 if (LOWORD (lParam
) == HTCLIENT
)
3621 return MA_ACTIVATEANDEAT
;
3626 /* No longer tracking mouse. */
3627 track_mouse_window
= NULL
;
3629 case WM_ACTIVATEAPP
:
3631 case WM_WINDOWPOSCHANGED
:
3633 /* Inform lisp thread that a frame might have just been obscured
3634 or exposed, so should recheck visibility of all frames. */
3635 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3639 dpyinfo
->faked_key
= 0;
3641 register_hot_keys (hwnd
);
3644 unregister_hot_keys (hwnd
);
3647 /* Relinquish the system caret. */
3648 if (w32_system_caret_hwnd
)
3650 w32_visible_system_caret_hwnd
= NULL
;
3651 w32_system_caret_hwnd
= NULL
;
3656 f
= x_window_to_frame (dpyinfo
, hwnd
);
3657 if (f
&& HIWORD (wParam
) == 0)
3659 f
->output_data
.w32
->menu_command_in_progress
= 1;
3660 if (menu_free_timer
)
3662 KillTimer (hwnd
, menu_free_timer
);
3663 menu_free_timer
= 0;
3669 wmsg
.dwModifiers
= w32_get_modifiers ();
3670 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3674 wmsg
.dwModifiers
= w32_get_modifiers ();
3675 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3678 case WM_WINDOWPOSCHANGING
:
3679 /* Don't restrict the sizing of tip frames. */
3680 if (hwnd
== tip_window
)
3684 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
3686 wp
.length
= sizeof (WINDOWPLACEMENT
);
3687 GetWindowPlacement (hwnd
, &wp
);
3689 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
3696 DWORD internal_border
;
3697 DWORD scrollbar_extra
;
3700 wp
.length
= sizeof(wp
);
3701 GetWindowRect (hwnd
, &wr
);
3705 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
3706 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
3707 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
3708 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
3712 memset (&rect
, 0, sizeof (rect
));
3713 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
3714 GetMenu (hwnd
) != NULL
);
3716 /* Force width and height of client area to be exact
3717 multiples of the character cell dimensions. */
3718 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
3719 - 2 * internal_border
- scrollbar_extra
)
3721 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
3722 - 2 * internal_border
)
3727 /* For right/bottom sizing we can just fix the sizes.
3728 However for top/left sizing we will need to fix the X
3729 and Y positions as well. */
3734 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
3735 && (lppos
->flags
& SWP_NOMOVE
) == 0)
3737 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
3744 lppos
->flags
|= SWP_NOMOVE
;
3755 case WM_GETMINMAXINFO
:
3756 /* Hack to correct bug that allows Emacs frames to be resized
3757 below the Minimum Tracking Size. */
3758 ((LPMINMAXINFO
) lParam
)->ptMinTrackSize
.y
++;
3759 /* Hack to allow resizing the Emacs frame above the screen size.
3760 Note that Windows 9x limits coordinates to 16-bits. */
3761 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.x
= 32767;
3762 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.y
= 32767;
3766 if (LOWORD (lParam
) == HTCLIENT
)
3771 case WM_EMACS_SETCURSOR
:
3773 Cursor cursor
= (Cursor
) wParam
;
3779 case WM_EMACS_CREATESCROLLBAR
:
3780 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
3781 (struct scroll_bar
*) lParam
);
3783 case WM_EMACS_SHOWWINDOW
:
3784 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
3786 case WM_EMACS_SETFOREGROUND
:
3788 HWND foreground_window
;
3789 DWORD foreground_thread
, retval
;
3791 /* On NT 5.0, and apparently Windows 98, it is necessary to
3792 attach to the thread that currently has focus in order to
3793 pull the focus away from it. */
3794 foreground_window
= GetForegroundWindow ();
3795 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
3796 if (!foreground_window
3797 || foreground_thread
== GetCurrentThreadId ()
3798 || !AttachThreadInput (GetCurrentThreadId (),
3799 foreground_thread
, TRUE
))
3800 foreground_thread
= 0;
3802 retval
= SetForegroundWindow ((HWND
) wParam
);
3804 /* Detach from the previous foreground thread. */
3805 if (foreground_thread
)
3806 AttachThreadInput (GetCurrentThreadId (),
3807 foreground_thread
, FALSE
);
3812 case WM_EMACS_SETWINDOWPOS
:
3814 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
3815 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
3816 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
3819 case WM_EMACS_DESTROYWINDOW
:
3820 DragAcceptFiles ((HWND
) wParam
, FALSE
);
3821 return DestroyWindow ((HWND
) wParam
);
3823 case WM_EMACS_HIDE_CARET
:
3824 return HideCaret (hwnd
);
3826 case WM_EMACS_SHOW_CARET
:
3827 return ShowCaret (hwnd
);
3829 case WM_EMACS_DESTROY_CARET
:
3830 w32_system_caret_hwnd
= NULL
;
3831 w32_visible_system_caret_hwnd
= NULL
;
3832 return DestroyCaret ();
3834 case WM_EMACS_TRACK_CARET
:
3835 /* If there is currently no system caret, create one. */
3836 if (w32_system_caret_hwnd
== NULL
)
3838 /* Use the default caret width, and avoid changing it
3839 unneccesarily, as it confuses screen reader software. */
3840 w32_system_caret_hwnd
= hwnd
;
3841 CreateCaret (hwnd
, NULL
, 0,
3842 w32_system_caret_height
);
3845 if (!SetCaretPos (w32_system_caret_x
, w32_system_caret_y
))
3847 /* Ensure visible caret gets turned on when requested. */
3848 else if (w32_use_visible_system_caret
3849 && w32_visible_system_caret_hwnd
!= hwnd
)
3851 w32_visible_system_caret_hwnd
= hwnd
;
3852 return ShowCaret (hwnd
);
3854 /* Ensure visible caret gets turned off when requested. */
3855 else if (!w32_use_visible_system_caret
3856 && w32_visible_system_caret_hwnd
)
3858 w32_visible_system_caret_hwnd
= NULL
;
3859 return HideCaret (hwnd
);
3864 case WM_EMACS_TRACKPOPUPMENU
:
3869 pos
= (POINT
*)lParam
;
3870 flags
= TPM_CENTERALIGN
;
3871 if (button_state
& LMOUSE
)
3872 flags
|= TPM_LEFTBUTTON
;
3873 else if (button_state
& RMOUSE
)
3874 flags
|= TPM_RIGHTBUTTON
;
3876 /* Remember we did a SetCapture on the initial mouse down event,
3877 so for safety, we make sure the capture is cancelled now. */
3881 /* Use menubar_active to indicate that WM_INITMENU is from
3882 TrackPopupMenu below, and should be ignored. */
3883 f
= x_window_to_frame (dpyinfo
, hwnd
);
3885 f
->output_data
.w32
->menubar_active
= 1;
3887 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
3891 /* Eat any mouse messages during popupmenu */
3892 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
3894 /* Get the menu selection, if any */
3895 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
3897 retval
= LOWORD (amsg
.wParam
);
3913 /* Check for messages registered at runtime. */
3914 if (msg
== msh_mousewheel
)
3916 wmsg
.dwModifiers
= w32_get_modifiers ();
3917 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3918 signal_user_input ();
3923 return DefWindowProc (hwnd
, msg
, wParam
, lParam
);
3927 /* The most common default return code for handled messages is 0. */
3932 my_create_window (f
)
3937 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
3939 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
3943 /* Create a tooltip window. Unlike my_create_window, we do not do this
3944 indirectly via the Window thread, as we do not need to process Window
3945 messages for the tooltip. Creating tooltips indirectly also creates
3946 deadlocks when tooltips are created for menu items. */
3948 my_create_tip_window (f
)
3953 rect
.left
= rect
.top
= 0;
3954 rect
.right
= FRAME_PIXEL_WIDTH (f
);
3955 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
3957 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
3958 FRAME_EXTERNAL_MENU_BAR (f
));
3960 tip_window
= FRAME_W32_WINDOW (f
)
3961 = CreateWindow (EMACS_CLASS
,
3963 f
->output_data
.w32
->dwStyle
,
3966 rect
.right
- rect
.left
,
3967 rect
.bottom
- rect
.top
,
3968 FRAME_W32_WINDOW (SELECTED_FRAME ()), /* owner */
3975 SetWindowLong (tip_window
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
3976 SetWindowLong (tip_window
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
3977 SetWindowLong (tip_window
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
3978 SetWindowLong (tip_window
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
3980 /* Tip frames have no scrollbars. */
3981 SetWindowLong (tip_window
, WND_SCROLLBAR_INDEX
, 0);
3983 /* Do this to discard the default setting specified by our parent. */
3984 ShowWindow (tip_window
, SW_HIDE
);
3989 /* Create and set up the w32 window for frame F. */
3992 w32_window (f
, window_prompting
, minibuffer_only
)
3994 long window_prompting
;
3995 int minibuffer_only
;
3999 /* Use the resource name as the top-level window name
4000 for looking up resources. Make a non-Lisp copy
4001 for the window manager, so GC relocation won't bother it.
4003 Elsewhere we specify the window name for the window manager. */
4006 char *str
= (char *) SDATA (Vx_resource_name
);
4007 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
4008 strcpy (f
->namebuf
, str
);
4011 my_create_window (f
);
4013 validate_x_resource_name ();
4015 /* x_set_name normally ignores requests to set the name if the
4016 requested name is the same as the current name. This is the one
4017 place where that assumption isn't correct; f->name is set, but
4018 the server hasn't been told. */
4021 int explicit = f
->explicit_name
;
4023 f
->explicit_name
= 0;
4026 x_set_name (f
, name
, explicit);
4031 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
4032 initialize_frame_menubar (f
);
4034 if (FRAME_W32_WINDOW (f
) == 0)
4035 error ("Unable to create window");
4038 /* Handle the icon stuff for this window. Perhaps later we might
4039 want an x_set_icon_position which can be called interactively as
4047 Lisp_Object icon_x
, icon_y
;
4049 /* Set the position of the icon. Note that Windows 95 groups all
4050 icons in the tray. */
4051 icon_x
= w32_get_arg (parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
4052 icon_y
= w32_get_arg (parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
4053 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
4055 CHECK_NUMBER (icon_x
);
4056 CHECK_NUMBER (icon_y
);
4058 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
4059 error ("Both left and top icon corners of icon must be specified");
4063 if (! EQ (icon_x
, Qunbound
))
4064 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
4067 /* Start up iconic or window? */
4068 x_wm_set_window_state
4069 (f
, (EQ (w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
4073 x_text_icon (f
, (char *) SDATA ((!NILP (f
->icon_name
)
4086 XGCValues gc_values
;
4090 /* Create the GC's of this frame.
4091 Note that many default values are used. */
4094 gc_values
.font
= FRAME_FONT (f
);
4096 /* Cursor has cursor-color background, background-color foreground. */
4097 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
4098 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
4099 f
->output_data
.w32
->cursor_gc
4100 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
4101 (GCFont
| GCForeground
| GCBackground
),
4105 f
->output_data
.w32
->white_relief
.gc
= 0;
4106 f
->output_data
.w32
->black_relief
.gc
= 0;
4112 /* Handler for signals raised during x_create_frame and
4113 x_create_top_frame. FRAME is the frame which is partially
4117 unwind_create_frame (frame
)
4120 struct frame
*f
= XFRAME (frame
);
4122 /* If frame is ``official'', nothing to do. */
4123 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
4126 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4129 x_free_frame_resources (f
);
4131 /* Check that reference counts are indeed correct. */
4132 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
4133 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
4142 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
4144 doc
: /* Make a new window, which is called a \"frame\" in Emacs terms.
4145 Returns an Emacs frame object.
4146 PARAMETERS is an alist of frame parameters.
4147 If the parameters specify that the frame should not have a minibuffer,
4148 and do not specify a specific minibuffer window to use,
4149 then `default-minibuffer-frame' must be a frame whose minibuffer can
4150 be shared by the new frame.
4152 This function is an internal primitive--use `make-frame' instead. */)
4154 Lisp_Object parameters
;
4157 Lisp_Object frame
, tem
;
4159 int minibuffer_only
= 0;
4160 long window_prompting
= 0;
4162 int count
= SPECPDL_INDEX ();
4163 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4164 Lisp_Object display
;
4165 struct w32_display_info
*dpyinfo
= NULL
;
4171 /* Use this general default value to start with
4172 until we know if this frame has a specified name. */
4173 Vx_resource_name
= Vinvocation_name
;
4175 display
= w32_get_arg (parameters
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
4176 if (EQ (display
, Qunbound
))
4178 dpyinfo
= check_x_display_info (display
);
4180 kb
= dpyinfo
->kboard
;
4182 kb
= &the_only_kboard
;
4185 name
= w32_get_arg (parameters
, Qname
, "name", "Name", RES_TYPE_STRING
);
4187 && ! EQ (name
, Qunbound
)
4189 error ("Invalid frame name--not a string or nil");
4192 Vx_resource_name
= name
;
4194 /* See if parent window is specified. */
4195 parent
= w32_get_arg (parameters
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
4196 if (EQ (parent
, Qunbound
))
4198 if (! NILP (parent
))
4199 CHECK_NUMBER (parent
);
4201 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
4202 /* No need to protect DISPLAY because that's not used after passing
4203 it to make_frame_without_minibuffer. */
4205 GCPRO4 (parameters
, parent
, name
, frame
);
4206 tem
= w32_get_arg (parameters
, Qminibuffer
, "minibuffer", "Minibuffer",
4208 if (EQ (tem
, Qnone
) || NILP (tem
))
4209 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
4210 else if (EQ (tem
, Qonly
))
4212 f
= make_minibuffer_frame ();
4213 minibuffer_only
= 1;
4215 else if (WINDOWP (tem
))
4216 f
= make_frame_without_minibuffer (tem
, kb
, display
);
4220 XSETFRAME (frame
, f
);
4222 /* Note that Windows does support scroll bars. */
4223 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
4225 /* By default, make scrollbars the system standard width. */
4226 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
4228 f
->output_method
= output_w32
;
4229 f
->output_data
.w32
=
4230 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
4231 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
4232 FRAME_FONTSET (f
) = -1;
4233 record_unwind_protect (unwind_create_frame
, frame
);
4236 = w32_get_arg (parameters
, Qicon_name
, "iconName", "Title", RES_TYPE_STRING
);
4237 if (! STRINGP (f
->icon_name
))
4238 f
->icon_name
= Qnil
;
4240 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
4242 FRAME_KBOARD (f
) = kb
;
4245 /* Specify the parent under which to make this window. */
4249 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
4250 f
->output_data
.w32
->explicit_parent
= 1;
4254 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4255 f
->output_data
.w32
->explicit_parent
= 0;
4258 /* Set the name; the functions to which we pass f expect the name to
4260 if (EQ (name
, Qunbound
) || NILP (name
))
4262 f
->name
= build_string (dpyinfo
->w32_id_name
);
4263 f
->explicit_name
= 0;
4268 f
->explicit_name
= 1;
4269 /* use the frame's title when getting resources for this frame. */
4270 specbind (Qx_resource_name
, name
);
4273 /* Extract the window parameters from the supplied values
4274 that are needed to determine window geometry. */
4278 font
= w32_get_arg (parameters
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4281 /* First, try whatever font the caller has specified. */
4284 tem
= Fquery_fontset (font
, Qnil
);
4286 font
= x_new_fontset (f
, tem
);
4288 font
= x_new_font (f
, SDATA (font
));
4290 /* Try out a font which we hope has bold and italic variations. */
4291 if (!STRINGP (font
))
4292 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
4293 if (! STRINGP (font
))
4294 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
4295 /* If those didn't work, look for something which will at least work. */
4296 if (! STRINGP (font
))
4297 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
4299 if (! STRINGP (font
))
4300 font
= build_string ("Fixedsys");
4302 x_default_parameter (f
, parameters
, Qfont
, font
,
4303 "font", "Font", RES_TYPE_STRING
);
4306 x_default_parameter (f
, parameters
, Qborder_width
, make_number (2),
4307 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4308 /* This defaults to 2 in order to match xterm. We recognize either
4309 internalBorderWidth or internalBorder (which is what xterm calls
4311 if (NILP (Fassq (Qinternal_border_width
, parameters
)))
4315 value
= w32_get_arg (parameters
, Qinternal_border_width
,
4316 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
4317 if (! EQ (value
, Qunbound
))
4318 parameters
= Fcons (Fcons (Qinternal_border_width
, value
),
4321 /* Default internalBorderWidth to 0 on Windows to match other programs. */
4322 x_default_parameter (f
, parameters
, Qinternal_border_width
, make_number (0),
4323 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
4324 x_default_parameter (f
, parameters
, Qvertical_scroll_bars
, Qright
,
4325 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
4327 /* Also do the stuff which must be set before the window exists. */
4328 x_default_parameter (f
, parameters
, Qforeground_color
, build_string ("black"),
4329 "foreground", "Foreground", RES_TYPE_STRING
);
4330 x_default_parameter (f
, parameters
, Qbackground_color
, build_string ("white"),
4331 "background", "Background", RES_TYPE_STRING
);
4332 x_default_parameter (f
, parameters
, Qmouse_color
, build_string ("black"),
4333 "pointerColor", "Foreground", RES_TYPE_STRING
);
4334 x_default_parameter (f
, parameters
, Qcursor_color
, build_string ("black"),
4335 "cursorColor", "Foreground", RES_TYPE_STRING
);
4336 x_default_parameter (f
, parameters
, Qborder_color
, build_string ("black"),
4337 "borderColor", "BorderColor", RES_TYPE_STRING
);
4338 x_default_parameter (f
, parameters
, Qscreen_gamma
, Qnil
,
4339 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
4340 x_default_parameter (f
, parameters
, Qline_spacing
, Qnil
,
4341 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
4342 x_default_parameter (f
, parameters
, Qleft_fringe
, Qnil
,
4343 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
4344 x_default_parameter (f
, parameters
, Qright_fringe
, Qnil
,
4345 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
4348 /* Init faces before x_default_parameter is called for scroll-bar
4349 parameters because that function calls x_set_scroll_bar_width,
4350 which calls change_frame_size, which calls Fset_window_buffer,
4351 which runs hooks, which call Fvertical_motion. At the end, we
4352 end up in init_iterator with a null face cache, which should not
4354 init_frame_faces (f
);
4356 x_default_parameter (f
, parameters
, Qmenu_bar_lines
, make_number (1),
4357 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
4358 x_default_parameter (f
, parameters
, Qtool_bar_lines
, make_number (1),
4359 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
4361 x_default_parameter (f
, parameters
, Qbuffer_predicate
, Qnil
,
4362 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
4363 x_default_parameter (f
, parameters
, Qtitle
, Qnil
,
4364 "title", "Title", RES_TYPE_STRING
);
4365 x_default_parameter (f
, parameters
, Qfullscreen
, Qnil
,
4366 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
4368 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
4369 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4371 f
->output_data
.w32
->text_cursor
= w32_load_cursor (IDC_IBEAM
);
4372 f
->output_data
.w32
->nontext_cursor
= w32_load_cursor (IDC_ARROW
);
4373 f
->output_data
.w32
->modeline_cursor
= w32_load_cursor (IDC_ARROW
);
4374 f
->output_data
.w32
->hand_cursor
= w32_load_cursor (IDC_HAND
);
4375 f
->output_data
.w32
->hourglass_cursor
= w32_load_cursor (IDC_WAIT
);
4376 f
->output_data
.w32
->horizontal_drag_cursor
= w32_load_cursor (IDC_SIZEWE
);
4378 window_prompting
= x_figure_window_size (f
, parameters
, 1);
4380 tem
= w32_get_arg (parameters
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
4381 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
4383 w32_window (f
, window_prompting
, minibuffer_only
);
4384 x_icon (f
, parameters
);
4388 /* Now consider the frame official. */
4389 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
4390 Vframe_list
= Fcons (frame
, Vframe_list
);
4392 /* We need to do this after creating the window, so that the
4393 icon-creation functions can say whose icon they're describing. */
4394 x_default_parameter (f
, parameters
, Qicon_type
, Qnil
,
4395 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
4397 x_default_parameter (f
, parameters
, Qauto_raise
, Qnil
,
4398 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4399 x_default_parameter (f
, parameters
, Qauto_lower
, Qnil
,
4400 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4401 x_default_parameter (f
, parameters
, Qcursor_type
, Qbox
,
4402 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4403 x_default_parameter (f
, parameters
, Qscroll_bar_width
, Qnil
,
4404 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
4406 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4407 Change will not be effected unless different from the current
4409 width
= FRAME_COLS (f
);
4410 height
= FRAME_LINES (f
);
4412 FRAME_LINES (f
) = 0;
4413 SET_FRAME_COLS (f
, 0);
4414 change_frame_size (f
, height
, width
, 1, 0, 0);
4416 /* Tell the server what size and position, etc, we want, and how
4417 badly we want them. This should be done after we have the menu
4418 bar so that its size can be taken into account. */
4420 x_wm_set_size_hint (f
, window_prompting
, 0);
4423 /* Make the window appear on the frame and enable display, unless
4424 the caller says not to. However, with explicit parent, Emacs
4425 cannot control visibility, so don't try. */
4426 if (! f
->output_data
.w32
->explicit_parent
)
4428 Lisp_Object visibility
;
4430 visibility
= w32_get_arg (parameters
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
4431 if (EQ (visibility
, Qunbound
))
4434 if (EQ (visibility
, Qicon
))
4435 x_iconify_frame (f
);
4436 else if (! NILP (visibility
))
4437 x_make_frame_visible (f
);
4439 /* Must have been Qnil. */
4444 /* Make sure windows on this frame appear in calls to next-window
4445 and similar functions. */
4446 Vwindow_list
= Qnil
;
4448 return unbind_to (count
, frame
);
4451 /* FRAME is used only to get a handle on the X display. We don't pass the
4452 display info directly because we're called from frame.c, which doesn't
4453 know about that structure. */
4455 x_get_focus_frame (frame
)
4456 struct frame
*frame
;
4458 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
4460 if (! dpyinfo
->w32_focus_frame
)
4463 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
4467 DEFUN ("w32-focus-frame", Fw32_focus_frame
, Sw32_focus_frame
, 1, 1, 0,
4468 doc
: /* Give FRAME input focus, raising to foreground if necessary. */)
4472 x_focus_on_frame (check_x_frame (frame
));
4477 /* Return the charset portion of a font name. */
4478 char * xlfd_charset_of_font (char * fontname
)
4480 char *charset
, *encoding
;
4482 encoding
= strrchr(fontname
, '-');
4483 if (!encoding
|| encoding
== fontname
)
4486 for (charset
= encoding
- 1; charset
>= fontname
; charset
--)
4487 if (*charset
== '-')
4490 if (charset
== fontname
|| strcmp(charset
, "-*-*") == 0)
4496 struct font_info
*w32_load_bdf_font (struct frame
*f
, char *fontname
,
4497 int size
, char* filename
);
4498 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
);
4499 static BOOL
w32_to_x_font (LOGFONT
* lplf
, char * lpxstr
, int len
,
4501 static BOOL
x_to_w32_font (char *lpxstr
, LOGFONT
*lplogfont
);
4503 static struct font_info
*
4504 w32_load_system_font (f
,fontname
,size
)
4509 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4510 Lisp_Object font_names
;
4512 /* Get a list of all the fonts that match this name. Once we
4513 have a list of matching fonts, we compare them against the fonts
4514 we already have loaded by comparing names. */
4515 font_names
= w32_list_fonts (f
, build_string (fontname
), size
, 100);
4517 if (!NILP (font_names
))
4522 /* First check if any are already loaded, as that is cheaper
4523 than loading another one. */
4524 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
4525 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
4526 if (dpyinfo
->font_table
[i
].name
4527 && (!strcmp (dpyinfo
->font_table
[i
].name
,
4528 SDATA (XCAR (tail
)))
4529 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
4530 SDATA (XCAR (tail
)))))
4531 return (dpyinfo
->font_table
+ i
);
4533 fontname
= (char *) SDATA (XCAR (font_names
));
4535 else if (w32_strict_fontnames
)
4537 /* If EnumFontFamiliesEx was available, we got a full list of
4538 fonts back so stop now to avoid the possibility of loading a
4539 random font. If we had to fall back to EnumFontFamilies, the
4540 list is incomplete, so continue whether the font we want was
4542 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
4543 FARPROC enum_font_families_ex
4544 = GetProcAddress (gdi32
, "EnumFontFamiliesExA");
4545 if (enum_font_families_ex
)
4549 /* Load the font and add it to the table. */
4551 char *full_name
, *encoding
, *charset
;
4553 struct font_info
*fontp
;
4559 if (!fontname
|| !x_to_w32_font (fontname
, &lf
))
4562 if (!*lf
.lfFaceName
)
4563 /* If no name was specified for the font, we get a random font
4564 from CreateFontIndirect - this is not particularly
4565 desirable, especially since CreateFontIndirect does not
4566 fill out the missing name in lf, so we never know what we
4570 lf
.lfQuality
= DEFAULT_QUALITY
;
4572 font
= (XFontStruct
*) xmalloc (sizeof (XFontStruct
));
4573 bzero (font
, sizeof (*font
));
4575 /* Set bdf to NULL to indicate that this is a Windows font. */
4580 font
->hfont
= CreateFontIndirect (&lf
);
4582 if (font
->hfont
== NULL
)
4591 codepage
= w32_codepage_for_font (fontname
);
4593 hdc
= GetDC (dpyinfo
->root_window
);
4594 oldobj
= SelectObject (hdc
, font
->hfont
);
4596 ok
= GetTextMetrics (hdc
, &font
->tm
);
4597 if (codepage
== CP_UNICODE
)
4598 font
->double_byte_p
= 1;
4601 /* Unfortunately, some fonts (eg. MingLiU, a big5 ttf font)
4602 don't report themselves as double byte fonts, when
4603 patently they are. So instead of trusting
4604 GetFontLanguageInfo, we check the properties of the
4605 codepage directly, since that is ultimately what we are
4606 working from anyway. */
4607 /* font->double_byte_p = GetFontLanguageInfo(hdc) & GCP_DBCS; */
4609 GetCPInfo (codepage
, &cpi
);
4610 font
->double_byte_p
= cpi
.MaxCharSize
> 1;
4613 SelectObject (hdc
, oldobj
);
4614 ReleaseDC (dpyinfo
->root_window
, hdc
);
4615 /* Fill out details in lf according to the font that was
4617 lf
.lfHeight
= font
->tm
.tmInternalLeading
- font
->tm
.tmHeight
;
4618 lf
.lfWidth
= font
->tm
.tmMaxCharWidth
;
4619 lf
.lfWeight
= font
->tm
.tmWeight
;
4620 lf
.lfItalic
= font
->tm
.tmItalic
;
4621 lf
.lfCharSet
= font
->tm
.tmCharSet
;
4622 lf
.lfPitchAndFamily
= ((font
->tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
)
4623 ? VARIABLE_PITCH
: FIXED_PITCH
);
4624 lf
.lfOutPrecision
= ((font
->tm
.tmPitchAndFamily
& TMPF_VECTOR
)
4625 ? OUT_STROKE_PRECIS
: OUT_STRING_PRECIS
);
4627 w32_cache_char_metrics (font
);
4634 w32_unload_font (dpyinfo
, font
);
4638 /* Find a free slot in the font table. */
4639 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
4640 if (dpyinfo
->font_table
[i
].name
== NULL
)
4643 /* If no free slot found, maybe enlarge the font table. */
4644 if (i
== dpyinfo
->n_fonts
4645 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
4648 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
4649 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
4651 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
4654 fontp
= dpyinfo
->font_table
+ i
;
4655 if (i
== dpyinfo
->n_fonts
)
4658 /* Now fill in the slots of *FONTP. */
4660 bzero (fontp
, sizeof (*fontp
));
4662 fontp
->font_idx
= i
;
4663 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
4664 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
4666 if (lf
.lfPitchAndFamily
== FIXED_PITCH
)
4668 /* Fixed width font. */
4669 fontp
->average_width
= fontp
->space_width
= FONT_WIDTH (font
);
4675 pcm
= w32_per_char_metric (font
, &space
, ANSI_FONT
);
4677 fontp
->space_width
= pcm
->width
;
4679 fontp
->space_width
= FONT_WIDTH (font
);
4681 fontp
->average_width
= font
->tm
.tmAveCharWidth
;
4685 fontp
->charset
= -1;
4686 charset
= xlfd_charset_of_font (fontname
);
4688 /* Cache the W32 codepage for a font. This makes w32_encode_char
4689 (called for every glyph during redisplay) much faster. */
4690 fontp
->codepage
= codepage
;
4692 /* Work out the font's full name. */
4693 full_name
= (char *)xmalloc (100);
4694 if (full_name
&& w32_to_x_font (&lf
, full_name
, 100, charset
))
4695 fontp
->full_name
= full_name
;
4698 /* If all else fails - just use the name we used to load it. */
4700 fontp
->full_name
= fontp
->name
;
4703 fontp
->size
= FONT_WIDTH (font
);
4704 fontp
->height
= FONT_HEIGHT (font
);
4706 /* The slot `encoding' specifies how to map a character
4707 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
4708 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
4709 (0:0x20..0x7F, 1:0xA0..0xFF,
4710 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
4711 2:0xA020..0xFF7F). For the moment, we don't know which charset
4712 uses this font. So, we set information in fontp->encoding_type
4713 which is never used by any charset. If mapping can't be
4714 decided, set FONT_ENCODING_NOT_DECIDED. */
4716 /* SJIS fonts need to be set to type 4, all others seem to work as
4717 type FONT_ENCODING_NOT_DECIDED. */
4718 encoding
= strrchr (fontp
->name
, '-');
4719 if (encoding
&& strnicmp (encoding
+1, "sjis", 4) == 0)
4720 fontp
->encoding_type
= 4;
4722 fontp
->encoding_type
= FONT_ENCODING_NOT_DECIDED
;
4724 /* The following three values are set to 0 under W32, which is
4725 what they get set to if XGetFontProperty fails under X. */
4726 fontp
->baseline_offset
= 0;
4727 fontp
->relative_compose
= 0;
4728 fontp
->default_ascent
= 0;
4730 /* Set global flag fonts_changed_p to non-zero if the font loaded
4731 has a character with a smaller width than any other character
4732 before, or if the font loaded has a smaller height than any
4733 other font loaded before. If this happens, it will make a
4734 glyph matrix reallocation necessary. */
4735 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
4741 /* Load font named FONTNAME of size SIZE for frame F, and return a
4742 pointer to the structure font_info while allocating it dynamically.
4743 If loading fails, return NULL. */
4745 w32_load_font (f
,fontname
,size
)
4750 Lisp_Object bdf_fonts
;
4751 struct font_info
*retval
= NULL
;
4752 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4754 bdf_fonts
= w32_list_bdf_fonts (build_string (fontname
), 1);
4756 while (!retval
&& CONSP (bdf_fonts
))
4758 char *bdf_name
, *bdf_file
;
4759 Lisp_Object bdf_pair
;
4762 bdf_name
= SDATA (XCAR (bdf_fonts
));
4763 bdf_pair
= Fassoc (XCAR (bdf_fonts
), Vw32_bdf_filename_alist
);
4764 bdf_file
= SDATA (XCDR (bdf_pair
));
4766 // If the font is already loaded, do not load it again.
4767 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
4769 if ((dpyinfo
->font_table
[i
].name
4770 && !strcmp (dpyinfo
->font_table
[i
].name
, bdf_name
))
4771 || (dpyinfo
->font_table
[i
].full_name
4772 && !strcmp (dpyinfo
->font_table
[i
].full_name
, bdf_name
)))
4773 return dpyinfo
->font_table
+ i
;
4776 retval
= w32_load_bdf_font (f
, bdf_name
, size
, bdf_file
);
4778 bdf_fonts
= XCDR (bdf_fonts
);
4784 return w32_load_system_font(f
, fontname
, size
);
4789 w32_unload_font (dpyinfo
, font
)
4790 struct w32_display_info
*dpyinfo
;
4795 if (font
->per_char
) xfree (font
->per_char
);
4796 if (font
->bdf
) w32_free_bdf_font (font
->bdf
);
4798 if (font
->hfont
) DeleteObject(font
->hfont
);
4803 /* The font conversion stuff between x and w32 */
4805 /* X font string is as follows (from faces.el)
4809 * (weight "\\(bold\\|demibold\\|medium\\)") ; 1
4810 * (weight\? "\\([^-]*\\)") ; 1
4811 * (slant "\\([ior]\\)") ; 2
4812 * (slant\? "\\([^-]?\\)") ; 2
4813 * (swidth "\\([^-]*\\)") ; 3
4814 * (adstyle "[^-]*") ; 4
4815 * (pixelsize "[0-9]+")
4816 * (pointsize "[0-9][0-9]+")
4817 * (resx "[0-9][0-9]+")
4818 * (resy "[0-9][0-9]+")
4819 * (spacing "[cmp?*]")
4820 * (avgwidth "[0-9]+")
4821 * (registry "[^-]+")
4822 * (encoding "[^-]+")
4827 x_to_w32_weight (lpw
)
4830 if (!lpw
) return (FW_DONTCARE
);
4832 if (stricmp (lpw
,"heavy") == 0) return FW_HEAVY
;
4833 else if (stricmp (lpw
,"extrabold") == 0) return FW_EXTRABOLD
;
4834 else if (stricmp (lpw
,"bold") == 0) return FW_BOLD
;
4835 else if (stricmp (lpw
,"demibold") == 0) return FW_SEMIBOLD
;
4836 else if (stricmp (lpw
,"semibold") == 0) return FW_SEMIBOLD
;
4837 else if (stricmp (lpw
,"medium") == 0) return FW_MEDIUM
;
4838 else if (stricmp (lpw
,"normal") == 0) return FW_NORMAL
;
4839 else if (stricmp (lpw
,"light") == 0) return FW_LIGHT
;
4840 else if (stricmp (lpw
,"extralight") == 0) return FW_EXTRALIGHT
;
4841 else if (stricmp (lpw
,"thin") == 0) return FW_THIN
;
4848 w32_to_x_weight (fnweight
)
4851 if (fnweight
>= FW_HEAVY
) return "heavy";
4852 if (fnweight
>= FW_EXTRABOLD
) return "extrabold";
4853 if (fnweight
>= FW_BOLD
) return "bold";
4854 if (fnweight
>= FW_SEMIBOLD
) return "demibold";
4855 if (fnweight
>= FW_MEDIUM
) return "medium";
4856 if (fnweight
>= FW_NORMAL
) return "normal";
4857 if (fnweight
>= FW_LIGHT
) return "light";
4858 if (fnweight
>= FW_EXTRALIGHT
) return "extralight";
4859 if (fnweight
>= FW_THIN
) return "thin";
4865 x_to_w32_charset (lpcs
)
4868 Lisp_Object this_entry
, w32_charset
;
4870 int len
= strlen (lpcs
);
4872 /* Support "*-#nnn" format for unknown charsets. */
4873 if (strncmp (lpcs
, "*-#", 3) == 0)
4874 return atoi (lpcs
+ 3);
4876 /* All Windows fonts qualify as unicode. */
4877 if (!strncmp (lpcs
, "iso10646", 8))
4878 return DEFAULT_CHARSET
;
4880 /* Handle wildcards by ignoring them; eg. treat "big5*-*" as "big5". */
4881 charset
= alloca (len
+ 1);
4882 strcpy (charset
, lpcs
);
4883 lpcs
= strchr (charset
, '*');
4887 /* Look through w32-charset-info-alist for the character set.
4888 Format of each entry is
4889 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
4891 this_entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
4893 if (NILP(this_entry
))
4895 /* At startup, we want iso8859-1 fonts to come up properly. */
4896 if (stricmp(charset
, "iso8859-1") == 0)
4897 return ANSI_CHARSET
;
4899 return DEFAULT_CHARSET
;
4902 w32_charset
= Fcar (Fcdr (this_entry
));
4904 /* Translate Lisp symbol to number. */
4905 if (EQ (w32_charset
, Qw32_charset_ansi
))
4906 return ANSI_CHARSET
;
4907 if (EQ (w32_charset
, Qw32_charset_symbol
))
4908 return SYMBOL_CHARSET
;
4909 if (EQ (w32_charset
, Qw32_charset_shiftjis
))
4910 return SHIFTJIS_CHARSET
;
4911 if (EQ (w32_charset
, Qw32_charset_hangeul
))
4912 return HANGEUL_CHARSET
;
4913 if (EQ (w32_charset
, Qw32_charset_chinesebig5
))
4914 return CHINESEBIG5_CHARSET
;
4915 if (EQ (w32_charset
, Qw32_charset_gb2312
))
4916 return GB2312_CHARSET
;
4917 if (EQ (w32_charset
, Qw32_charset_oem
))
4919 #ifdef JOHAB_CHARSET
4920 if (EQ (w32_charset
, Qw32_charset_johab
))
4921 return JOHAB_CHARSET
;
4922 if (EQ (w32_charset
, Qw32_charset_easteurope
))
4923 return EASTEUROPE_CHARSET
;
4924 if (EQ (w32_charset
, Qw32_charset_turkish
))
4925 return TURKISH_CHARSET
;
4926 if (EQ (w32_charset
, Qw32_charset_baltic
))
4927 return BALTIC_CHARSET
;
4928 if (EQ (w32_charset
, Qw32_charset_russian
))
4929 return RUSSIAN_CHARSET
;
4930 if (EQ (w32_charset
, Qw32_charset_arabic
))
4931 return ARABIC_CHARSET
;
4932 if (EQ (w32_charset
, Qw32_charset_greek
))
4933 return GREEK_CHARSET
;
4934 if (EQ (w32_charset
, Qw32_charset_hebrew
))
4935 return HEBREW_CHARSET
;
4936 if (EQ (w32_charset
, Qw32_charset_vietnamese
))
4937 return VIETNAMESE_CHARSET
;
4938 if (EQ (w32_charset
, Qw32_charset_thai
))
4939 return THAI_CHARSET
;
4940 if (EQ (w32_charset
, Qw32_charset_mac
))
4942 #endif /* JOHAB_CHARSET */
4943 #ifdef UNICODE_CHARSET
4944 if (EQ (w32_charset
, Qw32_charset_unicode
))
4945 return UNICODE_CHARSET
;
4948 return DEFAULT_CHARSET
;
4953 w32_to_x_charset (fncharset
, matching
)
4957 static char buf
[32];
4958 Lisp_Object charset_type
;
4963 /* If fully specified, accept it as it is. Otherwise use a
4965 char *wildcard
= strchr (matching
, '*');
4968 else if (strchr (matching
, '-'))
4971 match_len
= strlen (matching
);
4977 /* Handle startup case of w32-charset-info-alist not
4978 being set up yet. */
4979 if (NILP(Vw32_charset_info_alist
))
4981 charset_type
= Qw32_charset_ansi
;
4983 case DEFAULT_CHARSET
:
4984 charset_type
= Qw32_charset_default
;
4986 case SYMBOL_CHARSET
:
4987 charset_type
= Qw32_charset_symbol
;
4989 case SHIFTJIS_CHARSET
:
4990 charset_type
= Qw32_charset_shiftjis
;
4992 case HANGEUL_CHARSET
:
4993 charset_type
= Qw32_charset_hangeul
;
4995 case GB2312_CHARSET
:
4996 charset_type
= Qw32_charset_gb2312
;
4998 case CHINESEBIG5_CHARSET
:
4999 charset_type
= Qw32_charset_chinesebig5
;
5002 charset_type
= Qw32_charset_oem
;
5005 /* More recent versions of Windows (95 and NT4.0) define more
5007 #ifdef EASTEUROPE_CHARSET
5008 case EASTEUROPE_CHARSET
:
5009 charset_type
= Qw32_charset_easteurope
;
5011 case TURKISH_CHARSET
:
5012 charset_type
= Qw32_charset_turkish
;
5014 case BALTIC_CHARSET
:
5015 charset_type
= Qw32_charset_baltic
;
5017 case RUSSIAN_CHARSET
:
5018 charset_type
= Qw32_charset_russian
;
5020 case ARABIC_CHARSET
:
5021 charset_type
= Qw32_charset_arabic
;
5024 charset_type
= Qw32_charset_greek
;
5026 case HEBREW_CHARSET
:
5027 charset_type
= Qw32_charset_hebrew
;
5029 case VIETNAMESE_CHARSET
:
5030 charset_type
= Qw32_charset_vietnamese
;
5033 charset_type
= Qw32_charset_thai
;
5036 charset_type
= Qw32_charset_mac
;
5039 charset_type
= Qw32_charset_johab
;
5043 #ifdef UNICODE_CHARSET
5044 case UNICODE_CHARSET
:
5045 charset_type
= Qw32_charset_unicode
;
5049 /* Encode numerical value of unknown charset. */
5050 sprintf (buf
, "*-#%u", fncharset
);
5056 char * best_match
= NULL
;
5057 int matching_found
= 0;
5059 /* Look through w32-charset-info-alist for the character set.
5060 Prefer ISO codepages, and prefer lower numbers in the ISO
5061 range. Only return charsets for codepages which are installed.
5063 Format of each entry is
5064 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5066 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
5069 Lisp_Object w32_charset
;
5070 Lisp_Object codepage
;
5072 Lisp_Object this_entry
= XCAR (rest
);
5074 /* Skip invalid entries in alist. */
5075 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
5076 || !CONSP (XCDR (this_entry
))
5077 || !SYMBOLP (XCAR (XCDR (this_entry
))))
5080 x_charset
= SDATA (XCAR (this_entry
));
5081 w32_charset
= XCAR (XCDR (this_entry
));
5082 codepage
= XCDR (XCDR (this_entry
));
5084 /* Look for Same charset and a valid codepage (or non-int
5085 which means ignore). */
5086 if (EQ (w32_charset
, charset_type
)
5087 && (!INTEGERP (codepage
) || XINT (codepage
) == CP_DEFAULT
5088 || IsValidCodePage (XINT (codepage
))))
5090 /* If we don't have a match already, then this is the
5094 best_match
= x_charset
;
5095 if (matching
&& !strnicmp (x_charset
, matching
, match_len
))
5098 /* If we already found a match for MATCHING, then
5099 only consider other matches. */
5100 else if (matching_found
5101 && strnicmp (x_charset
, matching
, match_len
))
5103 /* If this matches what we want, and the best so far doesn't,
5104 then this is better. */
5105 else if (!matching_found
&& matching
5106 && !strnicmp (x_charset
, matching
, match_len
))
5108 best_match
= x_charset
;
5111 /* If this is fully specified, and the best so far isn't,
5112 then this is better. */
5113 else if ((!strchr (best_match
, '-') && strchr (x_charset
, '-'))
5114 /* If this is an ISO codepage, and the best so far isn't,
5115 then this is better, but only if it fully specifies the
5117 || (strnicmp (best_match
, "iso", 3) != 0
5118 && strnicmp (x_charset
, "iso", 3) == 0
5119 && strchr (x_charset
, '-')))
5120 best_match
= x_charset
;
5121 /* If both are ISO8859 codepages, choose the one with the
5122 lowest number in the encoding field. */
5123 else if (strnicmp (best_match
, "iso8859-", 8) == 0
5124 && strnicmp (x_charset
, "iso8859-", 8) == 0)
5126 int best_enc
= atoi (best_match
+ 8);
5127 int this_enc
= atoi (x_charset
+ 8);
5128 if (this_enc
> 0 && this_enc
< best_enc
)
5129 best_match
= x_charset
;
5134 /* If no match, encode the numeric value. */
5137 sprintf (buf
, "*-#%u", fncharset
);
5141 strncpy (buf
, best_match
, 31);
5142 /* If the charset is not fully specified, put -0 on the end. */
5143 if (!strchr (best_match
, '-'))
5145 int pos
= strlen (best_match
);
5146 /* Charset specifiers shouldn't be very long. If it is a made
5147 up one, truncating it should not do any harm since it isn't
5148 recognized anyway. */
5151 strcpy (buf
+ pos
, "-0");
5159 /* Return all the X charsets that map to a font. */
5161 w32_to_all_x_charsets (fncharset
)
5164 static char buf
[32];
5165 Lisp_Object charset_type
;
5166 Lisp_Object retval
= Qnil
;
5171 /* Handle startup case of w32-charset-info-alist not
5172 being set up yet. */
5173 if (NILP(Vw32_charset_info_alist
))
5174 return Fcons (build_string ("iso8859-1"), Qnil
);
5176 charset_type
= Qw32_charset_ansi
;
5178 case DEFAULT_CHARSET
:
5179 charset_type
= Qw32_charset_default
;
5181 case SYMBOL_CHARSET
:
5182 charset_type
= Qw32_charset_symbol
;
5184 case SHIFTJIS_CHARSET
:
5185 charset_type
= Qw32_charset_shiftjis
;
5187 case HANGEUL_CHARSET
:
5188 charset_type
= Qw32_charset_hangeul
;
5190 case GB2312_CHARSET
:
5191 charset_type
= Qw32_charset_gb2312
;
5193 case CHINESEBIG5_CHARSET
:
5194 charset_type
= Qw32_charset_chinesebig5
;
5197 charset_type
= Qw32_charset_oem
;
5200 /* More recent versions of Windows (95 and NT4.0) define more
5202 #ifdef EASTEUROPE_CHARSET
5203 case EASTEUROPE_CHARSET
:
5204 charset_type
= Qw32_charset_easteurope
;
5206 case TURKISH_CHARSET
:
5207 charset_type
= Qw32_charset_turkish
;
5209 case BALTIC_CHARSET
:
5210 charset_type
= Qw32_charset_baltic
;
5212 case RUSSIAN_CHARSET
:
5213 charset_type
= Qw32_charset_russian
;
5215 case ARABIC_CHARSET
:
5216 charset_type
= Qw32_charset_arabic
;
5219 charset_type
= Qw32_charset_greek
;
5221 case HEBREW_CHARSET
:
5222 charset_type
= Qw32_charset_hebrew
;
5224 case VIETNAMESE_CHARSET
:
5225 charset_type
= Qw32_charset_vietnamese
;
5228 charset_type
= Qw32_charset_thai
;
5231 charset_type
= Qw32_charset_mac
;
5234 charset_type
= Qw32_charset_johab
;
5238 #ifdef UNICODE_CHARSET
5239 case UNICODE_CHARSET
:
5240 charset_type
= Qw32_charset_unicode
;
5244 /* Encode numerical value of unknown charset. */
5245 sprintf (buf
, "*-#%u", fncharset
);
5246 return Fcons (build_string (buf
), Qnil
);
5251 /* Look through w32-charset-info-alist for the character set.
5252 Only return fully specified charsets for codepages which are
5255 Format of each entry in Vw32_charset_info_alist is
5256 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5258 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
5260 Lisp_Object x_charset
;
5261 Lisp_Object w32_charset
;
5262 Lisp_Object codepage
;
5264 Lisp_Object this_entry
= XCAR (rest
);
5266 /* Skip invalid entries in alist. */
5267 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
5268 || !CONSP (XCDR (this_entry
))
5269 || !SYMBOLP (XCAR (XCDR (this_entry
))))
5272 x_charset
= XCAR (this_entry
);
5273 w32_charset
= XCAR (XCDR (this_entry
));
5274 codepage
= XCDR (XCDR (this_entry
));
5276 if (!strchr (SDATA (x_charset
), '-'))
5279 /* Look for Same charset and a valid codepage (or non-int
5280 which means ignore). */
5281 if (EQ (w32_charset
, charset_type
)
5282 && (!INTEGERP (codepage
) || XINT (codepage
) == CP_DEFAULT
5283 || IsValidCodePage (XINT (codepage
))))
5285 retval
= Fcons (x_charset
, retval
);
5289 /* If no match, encode the numeric value. */
5292 sprintf (buf
, "*-#%u", fncharset
);
5293 return Fcons (build_string (buf
), Qnil
);
5300 /* Get the Windows codepage corresponding to the specified font. The
5301 charset info in the font name is used to look up
5302 w32-charset-to-codepage-alist. */
5304 w32_codepage_for_font (char *fontname
)
5306 Lisp_Object codepage
, entry
;
5307 char *charset_str
, *charset
, *end
;
5309 /* Extract charset part of font string. */
5310 charset
= xlfd_charset_of_font (fontname
);
5315 charset_str
= (char *) alloca (strlen (charset
) + 1);
5316 strcpy (charset_str
, charset
);
5319 /* Remove leading "*-". */
5320 if (strncmp ("*-", charset_str
, 2) == 0)
5321 charset
= charset_str
+ 2;
5324 charset
= charset_str
;
5326 /* Stop match at wildcard (including preceding '-'). */
5327 if (end
= strchr (charset
, '*'))
5329 if (end
> charset
&& *(end
-1) == '-')
5334 if (!strcmp (charset
, "iso10646"))
5337 if (NILP (Vw32_charset_info_alist
))
5340 entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
5344 codepage
= Fcdr (Fcdr (entry
));
5346 if (NILP (codepage
))
5348 else if (XFASTINT (codepage
) == XFASTINT (Qt
))
5350 else if (INTEGERP (codepage
))
5351 return XINT (codepage
);
5358 w32_to_x_font (lplogfont
, lpxstr
, len
, specific_charset
)
5359 LOGFONT
* lplogfont
;
5362 char * specific_charset
;
5366 char height_pixels
[8];
5368 char width_pixels
[8];
5369 char *fontname_dash
;
5370 int display_resy
= (int) one_w32_display_info
.resy
;
5371 int display_resx
= (int) one_w32_display_info
.resx
;
5372 struct coding_system coding
;
5374 if (!lpxstr
) abort ();
5379 if (lplogfont
->lfOutPrecision
== OUT_STRING_PRECIS
)
5380 fonttype
= "raster";
5381 else if (lplogfont
->lfOutPrecision
== OUT_STROKE_PRECIS
)
5382 fonttype
= "outline";
5384 fonttype
= "unknown";
5386 setup_coding_system (Fcheck_coding_system (Vlocale_coding_system
),
5388 coding
.src_multibyte
= 0;
5389 coding
.dst_multibyte
= 1;
5390 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
5391 /* We explicitely disable composition handling because selection
5392 data should not contain any composition sequence. */
5393 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
5395 coding
.dst_bytes
= LF_FACESIZE
* 2;
5396 coding
.destination
= (unsigned char *) xmalloc (coding
.dst_bytes
+ 1);
5397 decode_coding_c_string (&coding
, lplogfont
->lfFaceName
,
5398 strlen(lplogfont
->lfFaceName
), Qnil
);
5399 fontname
= coding
.destination
;
5401 *(fontname
+ coding
.produced
) = '\0';
5403 /* Replace dashes with underscores so the dashes are not
5405 fontname_dash
= fontname
;
5406 while (fontname_dash
= strchr (fontname_dash
, '-'))
5407 *fontname_dash
= '_';
5409 if (lplogfont
->lfHeight
)
5411 sprintf (height_pixels
, "%u", abs (lplogfont
->lfHeight
));
5412 sprintf (height_dpi
, "%u",
5413 abs (lplogfont
->lfHeight
) * 720 / display_resy
);
5417 strcpy (height_pixels
, "*");
5418 strcpy (height_dpi
, "*");
5421 #if 0 /* Never put the width in the xfld. It fails on fonts with
5422 double-width characters. */
5423 if (lplogfont
->lfWidth
)
5424 sprintf (width_pixels
, "%u", lplogfont
->lfWidth
* 10);
5427 strcpy (width_pixels
, "*");
5429 _snprintf (lpxstr
, len
- 1,
5430 "-%s-%s-%s-%c-normal-normal-%s-%s-%d-%d-%c-%s-%s",
5431 fonttype
, /* foundry */
5432 fontname
, /* family */
5433 w32_to_x_weight (lplogfont
->lfWeight
), /* weight */
5434 lplogfont
->lfItalic
?'i':'r', /* slant */
5436 /* add style name */
5437 height_pixels
, /* pixel size */
5438 height_dpi
, /* point size */
5439 display_resx
, /* resx */
5440 display_resy
, /* resy */
5441 ((lplogfont
->lfPitchAndFamily
& 0x3) == VARIABLE_PITCH
)
5442 ? 'p' : 'c', /* spacing */
5443 width_pixels
, /* avg width */
5444 w32_to_x_charset (lplogfont
->lfCharSet
, specific_charset
)
5445 /* charset registry and encoding */
5448 lpxstr
[len
- 1] = 0; /* just to be sure */
5453 x_to_w32_font (lpxstr
, lplogfont
)
5455 LOGFONT
* lplogfont
;
5457 struct coding_system coding
;
5459 if (!lplogfont
) return (FALSE
);
5461 memset (lplogfont
, 0, sizeof (*lplogfont
));
5463 /* Set default value for each field. */
5465 lplogfont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
5466 lplogfont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
5467 lplogfont
->lfQuality
= DEFAULT_QUALITY
;
5469 /* go for maximum quality */
5470 lplogfont
->lfOutPrecision
= OUT_STROKE_PRECIS
;
5471 lplogfont
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
5472 lplogfont
->lfQuality
= PROOF_QUALITY
;
5475 lplogfont
->lfCharSet
= DEFAULT_CHARSET
;
5476 lplogfont
->lfWeight
= FW_DONTCARE
;
5477 lplogfont
->lfPitchAndFamily
= DEFAULT_PITCH
| FF_DONTCARE
;
5482 /* Provide a simple escape mechanism for specifying Windows font names
5483 * directly -- if font spec does not beginning with '-', assume this
5485 * "<font name>[:height in pixels[:width in pixels[:weight]]]"
5491 char name
[50], weight
[20], slant
, pitch
, pixels
[10], height
[10],
5492 width
[10], resy
[10], remainder
[50];
5494 int dpi
= (int) one_w32_display_info
.resy
;
5496 fields
= sscanf (lpxstr
,
5497 "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%49s",
5498 name
, weight
, &slant
, pixels
, height
, resy
, &pitch
, width
, remainder
);
5502 /* In the general case when wildcards cover more than one field,
5503 we don't know which field is which, so don't fill any in.
5504 However, we need to cope with this particular form, which is
5505 generated by font_list_1 (invoked by try_font_list):
5506 "-raster-6x10-*-gb2312*-*"
5507 and make sure to correctly parse the charset field. */
5510 fields
= sscanf (lpxstr
,
5511 "-%*[^-]-%49[^-]-*-%49s",
5514 else if (fields
< 9)
5520 if (fields
> 0 && name
[0] != '*')
5522 Lisp_Object string
= build_string (name
);
5524 (Fcheck_coding_system (Vlocale_coding_system
), &coding
);
5525 coding
.mode
|= (CODING_MODE_SAFE_ENCODING
| CODING_MODE_LAST_BLOCK
);
5526 /* Disable composition/charset annotation. */
5527 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
5528 coding
.dst_bytes
= SCHARS (string
) * 2;
5530 coding
.destination
= (unsigned char *) xmalloc (coding
.dst_bytes
);
5531 encode_coding_object (&coding
, string
, 0, 0,
5532 SCHARS (string
), SBYTES (string
), Qnil
);
5533 if (coding
.produced
>= LF_FACESIZE
)
5534 coding
.produced
= LF_FACESIZE
- 1;
5536 coding
.destination
[coding
.produced
] = '\0';
5538 strcpy (lplogfont
->lfFaceName
, coding
.destination
);
5539 xfree (coding
.destination
);
5543 lplogfont
->lfFaceName
[0] = '\0';
5548 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
5552 lplogfont
->lfItalic
= (fields
> 0 && slant
== 'i');
5556 if (fields
> 0 && pixels
[0] != '*')
5557 lplogfont
->lfHeight
= atoi (pixels
);
5561 if (fields
> 0 && resy
[0] != '*')
5564 if (tem
> 0) dpi
= tem
;
5567 if (fields
> -1 && lplogfont
->lfHeight
== 0 && height
[0] != '*')
5568 lplogfont
->lfHeight
= atoi (height
) * dpi
/ 720;
5571 lplogfont
->lfPitchAndFamily
=
5572 (fields
> 0 && pitch
== 'p') ? VARIABLE_PITCH
: FIXED_PITCH
;
5576 if (fields
> 0 && width
[0] != '*')
5577 lplogfont
->lfWidth
= atoi (width
) / 10;
5581 /* Strip the trailing '-' if present. (it shouldn't be, as it
5582 fails the test against xlfd-tight-regexp in fontset.el). */
5584 int len
= strlen (remainder
);
5585 if (len
> 0 && remainder
[len
-1] == '-')
5586 remainder
[len
-1] = 0;
5588 encoding
= remainder
;
5590 if (strncmp (encoding
, "*-", 2) == 0)
5593 lplogfont
->lfCharSet
= x_to_w32_charset (encoding
);
5598 char name
[100], height
[10], width
[10], weight
[20];
5600 fields
= sscanf (lpxstr
,
5601 "%99[^:]:%9[^:]:%9[^:]:%19s",
5602 name
, height
, width
, weight
);
5604 if (fields
== EOF
) return (FALSE
);
5608 strncpy (lplogfont
->lfFaceName
,name
, LF_FACESIZE
);
5609 lplogfont
->lfFaceName
[LF_FACESIZE
-1] = 0;
5613 lplogfont
->lfFaceName
[0] = 0;
5619 lplogfont
->lfHeight
= atoi (height
);
5624 lplogfont
->lfWidth
= atoi (width
);
5628 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
5631 /* This makes TrueType fonts work better. */
5632 lplogfont
->lfHeight
= - abs (lplogfont
->lfHeight
);
5637 /* Strip the pixel height and point height from the given xlfd, and
5638 return the pixel height. If no pixel height is specified, calculate
5639 one from the point height, or if that isn't defined either, return
5640 0 (which usually signifies a scalable font).
5643 xlfd_strip_height (char *fontname
)
5645 int pixel_height
, field_number
;
5646 char *read_from
, *write_to
;
5650 pixel_height
= field_number
= 0;
5653 /* Look for height fields. */
5654 for (read_from
= fontname
; *read_from
; read_from
++)
5656 if (*read_from
== '-')
5659 if (field_number
== 7) /* Pixel height. */
5662 write_to
= read_from
;
5664 /* Find end of field. */
5665 for (;*read_from
&& *read_from
!= '-'; read_from
++)
5668 /* Split the fontname at end of field. */
5674 pixel_height
= atoi (write_to
);
5675 /* Blank out field. */
5676 if (read_from
> write_to
)
5681 /* If the pixel height field is at the end (partial xlfd),
5684 return pixel_height
;
5686 /* If we got a pixel height, the point height can be
5687 ignored. Just blank it out and break now. */
5690 /* Find end of point size field. */
5691 for (; *read_from
&& *read_from
!= '-'; read_from
++)
5697 /* Blank out the point size field. */
5698 if (read_from
> write_to
)
5704 return pixel_height
;
5708 /* If the point height is already blank, break now. */
5709 if (*read_from
== '-')
5715 else if (field_number
== 8)
5717 /* If we didn't get a pixel height, try to get the point
5718 height and convert that. */
5720 char *point_size_start
= read_from
++;
5722 /* Find end of field. */
5723 for (; *read_from
&& *read_from
!= '-'; read_from
++)
5732 point_size
= atoi (point_size_start
);
5734 /* Convert to pixel height. */
5735 pixel_height
= point_size
5736 * one_w32_display_info
.height_in
/ 720;
5738 /* Blank out this field and break. */
5746 /* Shift the rest of the font spec into place. */
5747 if (write_to
&& read_from
> write_to
)
5749 for (; *read_from
; read_from
++, write_to
++)
5750 *write_to
= *read_from
;
5754 return pixel_height
;
5757 /* Assume parameter 1 is fully qualified, no wildcards. */
5759 w32_font_match (fontname
, pattern
)
5764 char *font_name_copy
;
5765 char *regex
= alloca (strlen (pattern
) * 2 + 3);
5767 font_name_copy
= alloca (strlen (fontname
) + 1);
5768 strcpy (font_name_copy
, fontname
);
5773 /* Turn pattern into a regexp and do a regexp match. */
5774 for (; *pattern
; pattern
++)
5776 if (*pattern
== '?')
5778 else if (*pattern
== '*')
5789 /* Strip out font heights and compare them seperately, since
5790 rounding error can cause mismatches. This also allows a
5791 comparison between a font that declares only a pixel height and a
5792 pattern that declares the point height.
5795 int font_height
, pattern_height
;
5797 font_height
= xlfd_strip_height (font_name_copy
);
5798 pattern_height
= xlfd_strip_height (regex
);
5800 /* Compare now, and don't bother doing expensive regexp matching
5801 if the heights differ. */
5802 if (font_height
&& pattern_height
&& (font_height
!= pattern_height
))
5806 return (fast_string_match_ignore_case (build_string (regex
),
5807 build_string(font_name_copy
)) >= 0);
5810 /* Callback functions, and a structure holding info they need, for
5811 listing system fonts on W32. We need one set of functions to do the
5812 job properly, but these don't work on NT 3.51 and earlier, so we
5813 have a second set which don't handle character sets properly to
5816 In both cases, there are two passes made. The first pass gets one
5817 font from each family, the second pass lists all the fonts from
5820 typedef struct enumfont_t
5825 XFontStruct
*size_ref
;
5826 Lisp_Object pattern
;
5832 enum_font_maybe_add_to_list (enumfont_t
*, LOGFONT
*, char *, Lisp_Object
);
5836 enum_font_cb2 (lplf
, lptm
, FontType
, lpef
)
5838 NEWTEXTMETRIC
* lptm
;
5842 /* Ignore struck out and underlined versions of fonts. */
5843 if (lplf
->elfLogFont
.lfStrikeOut
|| lplf
->elfLogFont
.lfUnderline
)
5846 /* Only return fonts with names starting with @ if they were
5847 explicitly specified, since Microsoft uses an initial @ to
5848 denote fonts for vertical writing, without providing a more
5849 convenient way of identifying them. */
5850 if (lplf
->elfLogFont
.lfFaceName
[0] == '@'
5851 && lpef
->logfont
.lfFaceName
[0] != '@')
5854 /* Check that the character set matches if it was specified */
5855 if (lpef
->logfont
.lfCharSet
!= DEFAULT_CHARSET
&&
5856 lplf
->elfLogFont
.lfCharSet
!= lpef
->logfont
.lfCharSet
)
5859 if (FontType
== RASTER_FONTTYPE
)
5861 /* DBCS raster fonts have problems displaying, so skip them. */
5862 int charset
= lplf
->elfLogFont
.lfCharSet
;
5863 if (charset
== SHIFTJIS_CHARSET
5864 || charset
== HANGEUL_CHARSET
5865 || charset
== CHINESEBIG5_CHARSET
5866 || charset
== GB2312_CHARSET
5867 #ifdef JOHAB_CHARSET
5868 || charset
== JOHAB_CHARSET
5876 Lisp_Object width
= Qnil
;
5877 Lisp_Object charset_list
= Qnil
;
5878 char *charset
= NULL
;
5880 /* Truetype fonts do not report their true metrics until loaded */
5881 if (FontType
!= RASTER_FONTTYPE
)
5883 if (!NILP (lpef
->pattern
))
5885 /* Scalable fonts are as big as you want them to be. */
5886 lplf
->elfLogFont
.lfHeight
= lpef
->logfont
.lfHeight
;
5887 lplf
->elfLogFont
.lfWidth
= lpef
->logfont
.lfWidth
;
5888 width
= make_number (lpef
->logfont
.lfWidth
);
5892 lplf
->elfLogFont
.lfHeight
= 0;
5893 lplf
->elfLogFont
.lfWidth
= 0;
5897 /* Make sure the height used here is the same as everywhere
5898 else (ie character height, not cell height). */
5899 if (lplf
->elfLogFont
.lfHeight
> 0)
5901 /* lptm can be trusted for RASTER fonts, but not scalable ones. */
5902 if (FontType
== RASTER_FONTTYPE
)
5903 lplf
->elfLogFont
.lfHeight
= lptm
->tmInternalLeading
- lptm
->tmHeight
;
5905 lplf
->elfLogFont
.lfHeight
= -lplf
->elfLogFont
.lfHeight
;
5908 if (!NILP (lpef
->pattern
))
5910 charset
= xlfd_charset_of_font (SDATA (lpef
->pattern
));
5912 /* We already checked charsets above, but DEFAULT_CHARSET
5913 slipped through. So only allow exact matches for DEFAULT_CHARSET. */
5915 && strncmp (charset
, "*-*", 3) != 0
5916 && lpef
->logfont
.lfCharSet
== DEFAULT_CHARSET
5917 && strcmp (charset
, w32_to_x_charset (DEFAULT_CHARSET
, NULL
)) != 0)
5922 charset_list
= Fcons (build_string (charset
), Qnil
);
5924 /* Always prefer unicode. */
5926 = Fcons (build_string ("iso10646-1"),
5927 w32_to_all_x_charsets (lplf
->elfLogFont
.lfCharSet
));
5929 /* Loop through the charsets. */
5930 for ( ; CONSP (charset_list
); charset_list
= Fcdr (charset_list
))
5932 Lisp_Object this_charset
= Fcar (charset_list
);
5933 charset
= SDATA (this_charset
);
5935 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5938 /* List bold and italic variations if w32-enable-synthesized-fonts
5939 is non-nil and this is a plain font. */
5940 if (w32_enable_synthesized_fonts
5941 && lplf
->elfLogFont
.lfWeight
== FW_NORMAL
5942 && lplf
->elfLogFont
.lfItalic
== FALSE
)
5945 lplf
->elfLogFont
.lfWeight
= FW_BOLD
;
5946 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5949 lplf
->elfLogFont
.lfItalic
= TRUE
;
5950 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5953 lplf
->elfLogFont
.lfWeight
= FW_NORMAL
;
5954 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5964 enum_font_maybe_add_to_list (lpef
, logfont
, match_charset
, width
)
5967 char * match_charset
;
5972 if (!w32_to_x_font (logfont
, buf
, 100, match_charset
))
5975 if (NILP (lpef
->pattern
)
5976 || w32_font_match (buf
, SDATA (lpef
->pattern
)))
5978 /* Check if we already listed this font. This may happen if
5979 w32_enable_synthesized_fonts is non-nil, and there are real
5980 bold and italic versions of the font. */
5981 Lisp_Object font_name
= build_string (buf
);
5982 if (NILP (Fmember (font_name
, lpef
->list
)))
5984 Lisp_Object entry
= Fcons (font_name
, width
);
5985 lpef
->list
= Fcons (entry
, lpef
->list
);
5993 enum_font_cb1 (lplf
, lptm
, FontType
, lpef
)
5995 NEWTEXTMETRIC
* lptm
;
5999 return EnumFontFamilies (lpef
->hdc
,
6000 lplf
->elfLogFont
.lfFaceName
,
6001 (FONTENUMPROC
) enum_font_cb2
,
6007 enum_fontex_cb2 (lplf
, lptm
, font_type
, lpef
)
6008 ENUMLOGFONTEX
* lplf
;
6009 NEWTEXTMETRICEX
* lptm
;
6013 /* We are not interested in the extra info we get back from the 'Ex
6014 version - only the fact that we get character set variations
6015 enumerated seperately. */
6016 return enum_font_cb2 ((ENUMLOGFONT
*) lplf
, (NEWTEXTMETRIC
*) lptm
,
6021 enum_fontex_cb1 (lplf
, lptm
, font_type
, lpef
)
6022 ENUMLOGFONTEX
* lplf
;
6023 NEWTEXTMETRICEX
* lptm
;
6027 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6028 FARPROC enum_font_families_ex
6029 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6030 /* We don't really expect EnumFontFamiliesEx to disappear once we
6031 get here, so don't bother handling it gracefully. */
6032 if (enum_font_families_ex
== NULL
)
6033 error ("gdi32.dll has disappeared!");
6034 return enum_font_families_ex (lpef
->hdc
,
6036 (FONTENUMPROC
) enum_fontex_cb2
,
6040 /* Interface to fontset handler. (adapted from mw32font.c in Meadow
6041 and xterm.c in Emacs 20.3) */
6043 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
)
6045 char *fontname
, *ptnstr
;
6046 Lisp_Object list
, tem
, newlist
= Qnil
;
6049 list
= Vw32_bdf_filename_alist
;
6050 ptnstr
= SDATA (pattern
);
6052 for ( ; CONSP (list
); list
= XCDR (list
))
6056 fontname
= SDATA (XCAR (tem
));
6057 else if (STRINGP (tem
))
6058 fontname
= SDATA (tem
);
6062 if (w32_font_match (fontname
, ptnstr
))
6064 newlist
= Fcons (XCAR (tem
), newlist
);
6066 if (max_names
>= 0 && n_fonts
>= max_names
)
6075 /* Return a list of names of available fonts matching PATTERN on frame
6076 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
6077 to be listed. Frame F NULL means we have not yet created any
6078 frame, which means we can't get proper size info, as we don't have
6079 a device context to use for GetTextMetrics.
6080 MAXNAMES sets a limit on how many fonts to match. If MAXNAMES is
6081 negative, then all matching fonts are returned. */
6084 w32_list_fonts (f
, pattern
, size
, maxnames
)
6086 Lisp_Object pattern
;
6090 Lisp_Object patterns
, key
= Qnil
, tem
, tpat
;
6091 Lisp_Object list
= Qnil
, newlist
= Qnil
, second_best
= Qnil
;
6092 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
6095 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
6096 if (NILP (patterns
))
6097 patterns
= Fcons (pattern
, Qnil
);
6099 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
6104 tpat
= XCAR (patterns
);
6106 if (!STRINGP (tpat
))
6109 /* Avoid expensive EnumFontFamilies functions if we are not
6110 going to be able to output one of these anyway. */
6111 codepage
= w32_codepage_for_font (SDATA (tpat
));
6112 if (codepage
!= CP_8BIT
&& codepage
!= CP_UNICODE
6113 && codepage
!= CP_DEFAULT
&& codepage
!= CP_UNKNOWN
6114 && !IsValidCodePage(codepage
))
6117 /* See if we cached the result for this particular query.
6118 The cache is an alist of the form:
6119 ((PATTERN (FONTNAME . WIDTH) ...) ...)
6121 if (tem
= XCDR (dpyinfo
->name_list_element
),
6122 !NILP (list
= Fassoc (tpat
, tem
)))
6124 list
= Fcdr_safe (list
);
6125 /* We have a cached list. Don't have to get the list again. */
6130 /* At first, put PATTERN in the cache. */
6135 /* Use EnumFontFamiliesEx where it is available, as it knows
6136 about character sets. Fall back to EnumFontFamilies for
6137 older versions of NT that don't support the 'Ex function. */
6138 x_to_w32_font (SDATA (tpat
), &ef
.logfont
);
6140 LOGFONT font_match_pattern
;
6141 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6142 FARPROC enum_font_families_ex
6143 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6145 /* We do our own pattern matching so we can handle wildcards. */
6146 font_match_pattern
.lfFaceName
[0] = 0;
6147 font_match_pattern
.lfPitchAndFamily
= 0;
6148 /* We can use the charset, because if it is a wildcard it will
6149 be DEFAULT_CHARSET anyway. */
6150 font_match_pattern
.lfCharSet
= ef
.logfont
.lfCharSet
;
6152 ef
.hdc
= GetDC (dpyinfo
->root_window
);
6154 if (enum_font_families_ex
)
6155 enum_font_families_ex (ef
.hdc
,
6156 &font_match_pattern
,
6157 (FONTENUMPROC
) enum_fontex_cb1
,
6160 EnumFontFamilies (ef
.hdc
, NULL
, (FONTENUMPROC
) enum_font_cb1
,
6163 ReleaseDC (dpyinfo
->root_window
, ef
.hdc
);
6169 /* Make a list of the fonts we got back.
6170 Store that in the font cache for the display. */
6171 XSETCDR (dpyinfo
->name_list_element
,
6172 Fcons (Fcons (tpat
, list
),
6173 XCDR (dpyinfo
->name_list_element
)));
6176 if (NILP (list
)) continue; /* Try the remaining alternatives. */
6178 newlist
= second_best
= Qnil
;
6180 /* Make a list of the fonts that have the right width. */
6181 for (; CONSP (list
); list
= XCDR (list
))
6188 if (NILP (XCAR (tem
)))
6192 newlist
= Fcons (XCAR (tem
), newlist
);
6194 if (maxnames
>= 0 && n_fonts
>= maxnames
)
6199 if (!INTEGERP (XCDR (tem
)))
6201 /* Since we don't yet know the size of the font, we must
6202 load it and try GetTextMetrics. */
6203 W32FontStruct thisinfo
;
6208 if (!x_to_w32_font (SDATA (XCAR (tem
)), &lf
))
6212 thisinfo
.bdf
= NULL
;
6213 thisinfo
.hfont
= CreateFontIndirect (&lf
);
6214 if (thisinfo
.hfont
== NULL
)
6217 hdc
= GetDC (dpyinfo
->root_window
);
6218 oldobj
= SelectObject (hdc
, thisinfo
.hfont
);
6219 if (GetTextMetrics (hdc
, &thisinfo
.tm
))
6220 XSETCDR (tem
, make_number (FONT_WIDTH (&thisinfo
)));
6222 XSETCDR (tem
, make_number (0));
6223 SelectObject (hdc
, oldobj
);
6224 ReleaseDC (dpyinfo
->root_window
, hdc
);
6225 DeleteObject(thisinfo
.hfont
);
6228 found_size
= XINT (XCDR (tem
));
6229 if (found_size
== size
)
6231 newlist
= Fcons (XCAR (tem
), newlist
);
6233 if (maxnames
>= 0 && n_fonts
>= maxnames
)
6236 /* keep track of the closest matching size in case
6237 no exact match is found. */
6238 else if (found_size
> 0)
6240 if (NILP (second_best
))
6243 else if (found_size
< size
)
6245 if (XINT (XCDR (second_best
)) > size
6246 || XINT (XCDR (second_best
)) < found_size
)
6251 if (XINT (XCDR (second_best
)) > size
6252 && XINT (XCDR (second_best
)) >
6259 if (!NILP (newlist
))
6261 else if (!NILP (second_best
))
6263 newlist
= Fcons (XCAR (second_best
), Qnil
);
6268 /* Include any bdf fonts. */
6269 if (n_fonts
< maxnames
|| maxnames
< 0)
6271 Lisp_Object combined
[2];
6272 combined
[0] = w32_list_bdf_fonts (pattern
, maxnames
- n_fonts
);
6273 combined
[1] = newlist
;
6274 newlist
= Fnconc(2, combined
);
6281 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
6283 w32_get_font_info (f
, font_idx
)
6287 return (FRAME_W32_FONT_TABLE (f
) + font_idx
);
6292 w32_query_font (struct frame
*f
, char *fontname
)
6295 struct font_info
*pfi
;
6297 pfi
= FRAME_W32_FONT_TABLE (f
);
6299 for (i
= 0; i
< one_w32_display_info
.n_fonts
;i
++, pfi
++)
6301 if (stricmp(pfi
->name
, fontname
) == 0) return pfi
;
6307 /* Find a CCL program for a font specified by FONTP, and set the member
6308 `encoder' of the structure. */
6311 w32_find_ccl_program (fontp
)
6312 struct font_info
*fontp
;
6314 Lisp_Object list
, elt
;
6316 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
6320 && STRINGP (XCAR (elt
))
6321 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
6327 struct ccl_program
*ccl
6328 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
6330 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
6333 fontp
->font_encoder
= ccl
;
6337 /* directory-files from dired.c. */
6338 Lisp_Object Fdirectory_files
P_((Lisp_Object
, Lisp_Object
, Lisp_Object
, Lisp_Object
));
6341 /* Find BDF files in a specified directory. (use GCPRO when calling,
6342 as this calls lisp to get a directory listing). */
6344 w32_find_bdf_fonts_in_dir (Lisp_Object directory
)
6346 Lisp_Object filelist
, list
= Qnil
;
6349 if (!STRINGP(directory
))
6352 filelist
= Fdirectory_files (directory
, Qt
,
6353 build_string (".*\\.[bB][dD][fF]"), Qt
);
6355 for ( ; CONSP(filelist
); filelist
= XCDR (filelist
))
6357 Lisp_Object filename
= XCAR (filelist
);
6358 if (w32_BDF_to_x_font (SDATA (filename
), fontname
, 100))
6359 store_in_alist (&list
, build_string (fontname
), filename
);
6364 DEFUN ("w32-find-bdf-fonts", Fw32_find_bdf_fonts
, Sw32_find_bdf_fonts
,
6366 doc
: /* Return a list of BDF fonts in DIRECTORY.
6367 The list is suitable for appending to `w32-bdf-filename-alist'.
6368 Fonts which do not contain an xlfd description will not be included
6369 in the list. DIRECTORY may be a list of directories. */)
6371 Lisp_Object directory
;
6373 Lisp_Object list
= Qnil
;
6374 struct gcpro gcpro1
, gcpro2
;
6376 if (!CONSP (directory
))
6377 return w32_find_bdf_fonts_in_dir (directory
);
6379 for ( ; CONSP (directory
); directory
= XCDR (directory
))
6381 Lisp_Object pair
[2];
6384 GCPRO2 (directory
, list
);
6385 pair
[1] = w32_find_bdf_fonts_in_dir( XCAR (directory
) );
6386 list
= Fnconc( 2, pair
);
6393 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
6394 doc
: /* Internal function called by `color-defined-p', which see. */)
6396 Lisp_Object color
, frame
;
6399 FRAME_PTR f
= check_x_frame (frame
);
6401 CHECK_STRING (color
);
6403 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
6409 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
6410 doc
: /* Internal function called by `color-values', which see. */)
6412 Lisp_Object color
, frame
;
6415 FRAME_PTR f
= check_x_frame (frame
);
6417 CHECK_STRING (color
);
6419 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
6420 return list3 (make_number ((GetRValue (foo
.pixel
) << 8)
6421 | GetRValue (foo
.pixel
)),
6422 make_number ((GetGValue (foo
.pixel
) << 8)
6423 | GetGValue (foo
.pixel
)),
6424 make_number ((GetBValue (foo
.pixel
) << 8)
6425 | GetBValue (foo
.pixel
)));
6430 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
6431 doc
: /* Internal function called by `display-color-p', which see. */)
6433 Lisp_Object display
;
6435 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6437 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
6443 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
,
6444 Sx_display_grayscale_p
, 0, 1, 0,
6445 doc
: /* Return t if DISPLAY supports shades of gray.
6446 Note that color displays do support shades of gray.
6447 The optional argument DISPLAY specifies which display to ask about.
6448 DISPLAY should be either a frame or a display name (a string).
6449 If omitted or nil, that stands for the selected frame's display. */)
6451 Lisp_Object display
;
6453 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6455 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
6461 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
,
6462 Sx_display_pixel_width
, 0, 1, 0,
6463 doc
: /* Returns the width in pixels of DISPLAY.
6464 The optional argument DISPLAY specifies which display to ask about.
6465 DISPLAY should be either a frame or a display name (a string).
6466 If omitted or nil, that stands for the selected frame's display. */)
6468 Lisp_Object display
;
6470 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6472 return make_number (dpyinfo
->width
);
6475 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
6476 Sx_display_pixel_height
, 0, 1, 0,
6477 doc
: /* Returns the height in pixels of DISPLAY.
6478 The optional argument DISPLAY specifies which display to ask about.
6479 DISPLAY should be either a frame or a display name (a string).
6480 If omitted or nil, that stands for the selected frame's display. */)
6482 Lisp_Object display
;
6484 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6486 return make_number (dpyinfo
->height
);
6489 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
6491 doc
: /* Returns the number of bitplanes of DISPLAY.
6492 The optional argument DISPLAY specifies which display to ask about.
6493 DISPLAY should be either a frame or a display name (a string).
6494 If omitted or nil, that stands for the selected frame's display. */)
6496 Lisp_Object display
;
6498 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6500 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
6503 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
6505 doc
: /* Returns the number of color cells of DISPLAY.
6506 The optional argument DISPLAY specifies which display to ask about.
6507 DISPLAY should be either a frame or a display name (a string).
6508 If omitted or nil, that stands for the selected frame's display. */)
6510 Lisp_Object display
;
6512 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6516 hdc
= GetDC (dpyinfo
->root_window
);
6517 if (dpyinfo
->has_palette
)
6518 cap
= GetDeviceCaps (hdc
, SIZEPALETTE
);
6520 cap
= GetDeviceCaps (hdc
, NUMCOLORS
);
6522 /* We force 24+ bit depths to 24-bit, both to prevent an overflow
6523 and because probably is more meaningful on Windows anyway */
6525 cap
= 1 << min(dpyinfo
->n_planes
* dpyinfo
->n_cbits
, 24);
6527 ReleaseDC (dpyinfo
->root_window
, hdc
);
6529 return make_number (cap
);
6532 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
6533 Sx_server_max_request_size
,
6535 doc
: /* Returns the maximum request size of the server of DISPLAY.
6536 The optional argument DISPLAY specifies which display to ask about.
6537 DISPLAY should be either a frame or a display name (a string).
6538 If omitted or nil, that stands for the selected frame's display. */)
6540 Lisp_Object display
;
6542 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6544 return make_number (1);
6547 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
6548 doc
: /* Returns the "vendor ID" string of the W32 system (Microsoft).
6549 The optional argument DISPLAY specifies which display to ask about.
6550 DISPLAY should be either a frame or a display name (a string).
6551 If omitted or nil, that stands for the selected frame's display. */)
6553 Lisp_Object display
;
6555 return build_string ("Microsoft Corp.");
6558 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
6559 doc
: /* Returns the version numbers of the server of DISPLAY.
6560 The value is a list of three integers: the major and minor
6561 version numbers of the X Protocol in use, and the distributor-specific release
6562 number. See also the function `x-server-vendor'.
6564 The optional argument DISPLAY specifies which display to ask about.
6565 DISPLAY should be either a frame or a display name (a string).
6566 If omitted or nil, that stands for the selected frame's display. */)
6568 Lisp_Object display
;
6570 return Fcons (make_number (w32_major_version
),
6571 Fcons (make_number (w32_minor_version
),
6572 Fcons (make_number (w32_build_number
), Qnil
)));
6575 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
6576 doc
: /* Returns the number of screens on the server of DISPLAY.
6577 The optional argument DISPLAY specifies which display to ask about.
6578 DISPLAY should be either a frame or a display name (a string).
6579 If omitted or nil, that stands for the selected frame's display. */)
6581 Lisp_Object display
;
6583 return make_number (1);
6586 DEFUN ("x-display-mm-height", Fx_display_mm_height
,
6587 Sx_display_mm_height
, 0, 1, 0,
6588 doc
: /* Returns the height in millimeters of DISPLAY.
6589 The optional argument DISPLAY specifies which display to ask about.
6590 DISPLAY should be either a frame or a display name (a string).
6591 If omitted or nil, that stands for the selected frame's display. */)
6593 Lisp_Object display
;
6595 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6599 hdc
= GetDC (dpyinfo
->root_window
);
6601 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
6603 ReleaseDC (dpyinfo
->root_window
, hdc
);
6605 return make_number (cap
);
6608 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
6609 doc
: /* Returns the width in millimeters of DISPLAY.
6610 The optional argument DISPLAY specifies which display to ask about.
6611 DISPLAY should be either a frame or a display name (a string).
6612 If omitted or nil, that stands for the selected frame's display. */)
6614 Lisp_Object display
;
6616 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6621 hdc
= GetDC (dpyinfo
->root_window
);
6623 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
6625 ReleaseDC (dpyinfo
->root_window
, hdc
);
6627 return make_number (cap
);
6630 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
6631 Sx_display_backing_store
, 0, 1, 0,
6632 doc
: /* Returns an indication of whether DISPLAY does backing store.
6633 The value may be `always', `when-mapped', or `not-useful'.
6634 The optional argument DISPLAY specifies which display to ask about.
6635 DISPLAY should be either a frame or a display name (a string).
6636 If omitted or nil, that stands for the selected frame's display. */)
6638 Lisp_Object display
;
6640 return intern ("not-useful");
6643 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
6644 Sx_display_visual_class
, 0, 1, 0,
6645 doc
: /* Returns the visual class of DISPLAY.
6646 The value is one of the symbols `static-gray', `gray-scale',
6647 `static-color', `pseudo-color', `true-color', or `direct-color'.
6649 The optional argument DISPLAY specifies which display to ask about.
6650 DISPLAY should be either a frame or a display name (a string).
6651 If omitted or nil, that stands for the selected frame's display. */)
6653 Lisp_Object display
;
6655 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6656 Lisp_Object result
= Qnil
;
6658 if (dpyinfo
->has_palette
)
6659 result
= intern ("pseudo-color");
6660 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
6661 result
= intern ("static-grey");
6662 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
6663 result
= intern ("static-color");
6664 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
6665 result
= intern ("true-color");
6670 DEFUN ("x-display-save-under", Fx_display_save_under
,
6671 Sx_display_save_under
, 0, 1, 0,
6672 doc
: /* Returns t if DISPLAY supports the save-under feature.
6673 The optional argument DISPLAY specifies which display to ask about.
6674 DISPLAY should be either a frame or a display name (a string).
6675 If omitted or nil, that stands for the selected frame's display. */)
6677 Lisp_Object display
;
6684 register struct frame
*f
;
6686 return FRAME_PIXEL_WIDTH (f
);
6691 register struct frame
*f
;
6693 return FRAME_PIXEL_HEIGHT (f
);
6698 register struct frame
*f
;
6700 return FRAME_COLUMN_WIDTH (f
);
6705 register struct frame
*f
;
6707 return FRAME_LINE_HEIGHT (f
);
6712 register struct frame
*f
;
6714 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
6717 /* Return the display structure for the display named NAME.
6718 Open a new connection if necessary. */
6720 struct w32_display_info
*
6721 x_display_info_for_name (name
)
6725 struct w32_display_info
*dpyinfo
;
6727 CHECK_STRING (name
);
6729 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
6731 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
6734 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
6739 /* Use this general default value to start with. */
6740 Vx_resource_name
= Vinvocation_name
;
6742 validate_x_resource_name ();
6744 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
6745 (char *) SDATA (Vx_resource_name
));
6748 error ("Cannot connect to server %s", SDATA (name
));
6751 XSETFASTINT (Vwindow_system_version
, 3);
6756 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
6757 1, 3, 0, doc
: /* Open a connection to a server.
6758 DISPLAY is the name of the display to connect to.
6759 Optional second arg XRM-STRING is a string of resources in xrdb format.
6760 If the optional third arg MUST-SUCCEED is non-nil,
6761 terminate Emacs if we can't open the connection. */)
6762 (display
, xrm_string
, must_succeed
)
6763 Lisp_Object display
, xrm_string
, must_succeed
;
6765 unsigned char *xrm_option
;
6766 struct w32_display_info
*dpyinfo
;
6768 /* If initialization has already been done, return now to avoid
6769 overwriting critical parts of one_w32_display_info. */
6773 CHECK_STRING (display
);
6774 if (! NILP (xrm_string
))
6775 CHECK_STRING (xrm_string
);
6777 if (! EQ (Vwindow_system
, intern ("w32")))
6778 error ("Not using Microsoft Windows");
6780 /* Allow color mapping to be defined externally; first look in user's
6781 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
6783 Lisp_Object color_file
;
6784 struct gcpro gcpro1
;
6786 color_file
= build_string("~/rgb.txt");
6788 GCPRO1 (color_file
);
6790 if (NILP (Ffile_readable_p (color_file
)))
6792 Fexpand_file_name (build_string ("rgb.txt"),
6793 Fsymbol_value (intern ("data-directory")));
6795 Vw32_color_map
= Fw32_load_color_file (color_file
);
6799 if (NILP (Vw32_color_map
))
6800 Vw32_color_map
= Fw32_default_color_map ();
6802 /* Merge in system logical colors. */
6803 add_system_logical_colors_to_map (&Vw32_color_map
);
6805 if (! NILP (xrm_string
))
6806 xrm_option
= (unsigned char *) SDATA (xrm_string
);
6808 xrm_option
= (unsigned char *) 0;
6810 /* Use this general default value to start with. */
6811 /* First remove .exe suffix from invocation-name - it looks ugly. */
6813 char basename
[ MAX_PATH
], *str
;
6815 strcpy (basename
, SDATA (Vinvocation_name
));
6816 str
= strrchr (basename
, '.');
6818 Vinvocation_name
= build_string (basename
);
6820 Vx_resource_name
= Vinvocation_name
;
6822 validate_x_resource_name ();
6824 /* This is what opens the connection and sets x_current_display.
6825 This also initializes many symbols, such as those used for input. */
6826 dpyinfo
= w32_term_init (display
, xrm_option
,
6827 (char *) SDATA (Vx_resource_name
));
6831 if (!NILP (must_succeed
))
6832 fatal ("Cannot connect to server %s.\n",
6835 error ("Cannot connect to server %s", SDATA (display
));
6840 XSETFASTINT (Vwindow_system_version
, 3);
6844 DEFUN ("x-close-connection", Fx_close_connection
,
6845 Sx_close_connection
, 1, 1, 0,
6846 doc
: /* Close the connection to DISPLAY's server.
6847 For DISPLAY, specify either a frame or a display name (a string).
6848 If DISPLAY is nil, that stands for the selected frame's display. */)
6850 Lisp_Object display
;
6852 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6855 if (dpyinfo
->reference_count
> 0)
6856 error ("Display still has frames on it");
6859 /* Free the fonts in the font table. */
6860 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
6861 if (dpyinfo
->font_table
[i
].name
)
6863 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
6864 xfree (dpyinfo
->font_table
[i
].full_name
);
6865 xfree (dpyinfo
->font_table
[i
].name
);
6866 w32_unload_font (dpyinfo
, dpyinfo
->font_table
[i
].font
);
6868 x_destroy_all_bitmaps (dpyinfo
);
6870 x_delete_display (dpyinfo
);
6876 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
6877 doc
: /* Return the list of display names that Emacs has connections to. */)
6880 Lisp_Object tail
, result
;
6883 for (tail
= w32_display_name_list
; ! NILP (tail
); tail
= XCDR (tail
))
6884 result
= Fcons (XCAR (XCAR (tail
)), result
);
6889 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
6890 doc
: /* This is a noop on W32 systems. */)
6892 Lisp_Object display
, on
;
6899 /***********************************************************************
6901 ***********************************************************************/
6903 DEFUN ("x-change-window-property", Fx_change_window_property
,
6904 Sx_change_window_property
, 2, 6, 0,
6905 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
6906 VALUE may be a string or a list of conses, numbers and/or strings.
6907 If an element in the list is a string, it is converted to
6908 an Atom and the value of the Atom is used. If an element is a cons,
6909 it is converted to a 32 bit number where the car is the 16 top bits and the
6910 cdr is the lower 16 bits.
6911 FRAME nil or omitted means use the selected frame.
6912 If TYPE is given and non-nil, it is the name of the type of VALUE.
6913 If TYPE is not given or nil, the type is STRING.
6914 FORMAT gives the size in bits of each element if VALUE is a list.
6915 It must be one of 8, 16 or 32.
6916 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
6917 If OUTER_P is non-nil, the property is changed for the outer X window of
6918 FRAME. Default is to change on the edit X window.
6921 (prop
, value
, frame
, type
, format
, outer_p
)
6922 Lisp_Object prop
, value
, frame
, type
, format
, outer_p
;
6924 #if 0 /* TODO : port window properties to W32 */
6925 struct frame
*f
= check_x_frame (frame
);
6928 CHECK_STRING (prop
);
6929 CHECK_STRING (value
);
6932 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
6933 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
6934 prop_atom
, XA_STRING
, 8, PropModeReplace
,
6935 SDATA (value
), SCHARS (value
));
6937 /* Make sure the property is set when we return. */
6938 XFlush (FRAME_W32_DISPLAY (f
));
6947 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
6948 Sx_delete_window_property
, 1, 2, 0,
6949 doc
: /* Remove window property PROP from X window of FRAME.
6950 FRAME nil or omitted means use the selected frame. Value is PROP. */)
6952 Lisp_Object prop
, frame
;
6954 #if 0 /* TODO : port window properties to W32 */
6956 struct frame
*f
= check_x_frame (frame
);
6959 CHECK_STRING (prop
);
6961 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
6962 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
6964 /* Make sure the property is removed when we return. */
6965 XFlush (FRAME_W32_DISPLAY (f
));
6973 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
6975 doc
: /* Value is the value of window property PROP on FRAME.
6976 If FRAME is nil or omitted, use the selected frame. Value is nil
6977 if FRAME hasn't a property with name PROP or if PROP has no string
6980 Lisp_Object prop
, frame
;
6982 #if 0 /* TODO : port window properties to W32 */
6984 struct frame
*f
= check_x_frame (frame
);
6987 Lisp_Object prop_value
= Qnil
;
6988 char *tmp_data
= NULL
;
6991 unsigned long actual_size
, bytes_remaining
;
6993 CHECK_STRING (prop
);
6995 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
6996 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
6997 prop_atom
, 0, 0, False
, XA_STRING
,
6998 &actual_type
, &actual_format
, &actual_size
,
6999 &bytes_remaining
, (unsigned char **) &tmp_data
);
7002 int size
= bytes_remaining
;
7007 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
7008 prop_atom
, 0, bytes_remaining
,
7010 &actual_type
, &actual_format
,
7011 &actual_size
, &bytes_remaining
,
7012 (unsigned char **) &tmp_data
);
7014 prop_value
= make_string (tmp_data
, size
);
7029 /***********************************************************************
7031 ***********************************************************************/
7033 /* If non-null, an asynchronous timer that, when it expires, displays
7034 an hourglass cursor on all frames. */
7036 static struct atimer
*hourglass_atimer
;
7038 /* Non-zero means an hourglass cursor is currently shown. */
7040 static int hourglass_shown_p
;
7042 /* Number of seconds to wait before displaying an hourglass cursor. */
7044 static Lisp_Object Vhourglass_delay
;
7046 /* Default number of seconds to wait before displaying an hourglass
7049 #define DEFAULT_HOURGLASS_DELAY 1
7051 /* Function prototypes. */
7053 static void show_hourglass
P_ ((struct atimer
*));
7054 static void hide_hourglass
P_ ((void));
7057 /* Cancel a currently active hourglass timer, and start a new one. */
7062 #if 0 /* TODO: cursor shape changes. */
7064 int secs
, usecs
= 0;
7066 cancel_hourglass ();
7068 if (INTEGERP (Vhourglass_delay
)
7069 && XINT (Vhourglass_delay
) > 0)
7070 secs
= XFASTINT (Vhourglass_delay
);
7071 else if (FLOATP (Vhourglass_delay
)
7072 && XFLOAT_DATA (Vhourglass_delay
) > 0)
7075 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
7076 secs
= XFASTINT (tem
);
7077 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
7080 secs
= DEFAULT_HOURGLASS_DELAY
;
7082 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
7083 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
7084 show_hourglass
, NULL
);
7089 /* Cancel the hourglass cursor timer if active, hide an hourglass
7095 if (hourglass_atimer
)
7097 cancel_atimer (hourglass_atimer
);
7098 hourglass_atimer
= NULL
;
7101 if (hourglass_shown_p
)
7106 /* Timer function of hourglass_atimer. TIMER is equal to
7109 Display an hourglass cursor on all frames by mapping the frames'
7110 hourglass_window. Set the hourglass_p flag in the frames'
7111 output_data.x structure to indicate that an hourglass cursor is
7112 shown on the frames. */
7115 show_hourglass (timer
)
7116 struct atimer
*timer
;
7118 #if 0 /* TODO: cursor shape changes. */
7119 /* The timer implementation will cancel this timer automatically
7120 after this function has run. Set hourglass_atimer to null
7121 so that we know the timer doesn't have to be canceled. */
7122 hourglass_atimer
= NULL
;
7124 if (!hourglass_shown_p
)
7126 Lisp_Object rest
, frame
;
7130 FOR_EACH_FRAME (rest
, frame
)
7131 if (FRAME_W32_P (XFRAME (frame
)))
7133 struct frame
*f
= XFRAME (frame
);
7135 f
->output_data
.w32
->hourglass_p
= 1;
7137 if (!f
->output_data
.w32
->hourglass_window
)
7139 unsigned long mask
= CWCursor
;
7140 XSetWindowAttributes attrs
;
7142 attrs
.cursor
= f
->output_data
.w32
->hourglass_cursor
;
7144 f
->output_data
.w32
->hourglass_window
7145 = XCreateWindow (FRAME_X_DISPLAY (f
),
7146 FRAME_OUTER_WINDOW (f
),
7147 0, 0, 32000, 32000, 0, 0,
7153 XMapRaised (FRAME_X_DISPLAY (f
),
7154 f
->output_data
.w32
->hourglass_window
);
7155 XFlush (FRAME_X_DISPLAY (f
));
7158 hourglass_shown_p
= 1;
7165 /* Hide the hourglass cursor on all frames, if it is currently shown. */
7170 #if 0 /* TODO: cursor shape changes. */
7171 if (hourglass_shown_p
)
7173 Lisp_Object rest
, frame
;
7176 FOR_EACH_FRAME (rest
, frame
)
7178 struct frame
*f
= XFRAME (frame
);
7181 /* Watch out for newly created frames. */
7182 && f
->output_data
.x
->hourglass_window
)
7184 XUnmapWindow (FRAME_X_DISPLAY (f
),
7185 f
->output_data
.x
->hourglass_window
);
7186 /* Sync here because XTread_socket looks at the
7187 hourglass_p flag that is reset to zero below. */
7188 XSync (FRAME_X_DISPLAY (f
), False
);
7189 f
->output_data
.x
->hourglass_p
= 0;
7193 hourglass_shown_p
= 0;
7201 /***********************************************************************
7203 ***********************************************************************/
7205 static Lisp_Object x_create_tip_frame
P_ ((struct w32_display_info
*,
7206 Lisp_Object
, Lisp_Object
));
7207 static void compute_tip_xy
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
7208 Lisp_Object
, int, int, int *, int *));
7210 /* The frame of a currently visible tooltip. */
7212 Lisp_Object tip_frame
;
7214 /* If non-nil, a timer started that hides the last tooltip when it
7217 Lisp_Object tip_timer
;
7220 /* If non-nil, a vector of 3 elements containing the last args
7221 with which x-show-tip was called. See there. */
7223 Lisp_Object last_show_tip_args
;
7225 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
7227 Lisp_Object Vx_max_tooltip_size
;
7231 unwind_create_tip_frame (frame
)
7234 Lisp_Object deleted
;
7236 deleted
= unwind_create_frame (frame
);
7237 if (EQ (deleted
, Qt
))
7247 /* Create a frame for a tooltip on the display described by DPYINFO.
7248 PARMS is a list of frame parameters. TEXT is the string to
7249 display in the tip frame. Value is the frame.
7251 Note that functions called here, esp. x_default_parameter can
7252 signal errors, for instance when a specified color name is
7253 undefined. We have to make sure that we're in a consistent state
7254 when this happens. */
7257 x_create_tip_frame (dpyinfo
, parms
, text
)
7258 struct w32_display_info
*dpyinfo
;
7259 Lisp_Object parms
, text
;
7262 Lisp_Object frame
, tem
;
7264 long window_prompting
= 0;
7266 int count
= SPECPDL_INDEX ();
7267 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7269 int face_change_count_before
= face_change_count
;
7271 struct buffer
*old_buffer
;
7275 /* Use this general default value to start with until we know if
7276 this frame has a specified name. */
7277 Vx_resource_name
= Vinvocation_name
;
7280 kb
= dpyinfo
->kboard
;
7282 kb
= &the_only_kboard
;
7285 /* Get the name of the frame to use for resource lookup. */
7286 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
7288 && !EQ (name
, Qunbound
)
7290 error ("Invalid frame name--not a string or nil");
7291 Vx_resource_name
= name
;
7294 GCPRO3 (parms
, name
, frame
);
7295 /* Make a frame without minibuffer nor mode-line. */
7297 f
->wants_modeline
= 0;
7298 XSETFRAME (frame
, f
);
7300 buffer
= Fget_buffer_create (build_string (" *tip*"));
7301 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, Qnil
);
7302 old_buffer
= current_buffer
;
7303 set_buffer_internal_1 (XBUFFER (buffer
));
7304 current_buffer
->truncate_lines
= Qnil
;
7305 specbind (Qinhibit_read_only
, Qt
);
7306 specbind (Qinhibit_modification_hooks
, Qt
);
7309 set_buffer_internal_1 (old_buffer
);
7311 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
7312 record_unwind_protect (unwind_create_tip_frame
, frame
);
7314 /* By setting the output method, we're essentially saying that
7315 the frame is live, as per FRAME_LIVE_P. If we get a signal
7316 from this point on, x_destroy_window might screw up reference
7318 f
->output_method
= output_w32
;
7319 f
->output_data
.w32
=
7320 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
7321 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
7323 FRAME_FONTSET (f
) = -1;
7324 f
->icon_name
= Qnil
;
7326 #if 0 /* GLYPH_DEBUG TODO: image support. */
7327 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
7328 dpyinfo_refcount
= dpyinfo
->reference_count
;
7329 #endif /* GLYPH_DEBUG */
7331 FRAME_KBOARD (f
) = kb
;
7333 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
7334 f
->output_data
.w32
->explicit_parent
= 0;
7336 /* Set the name; the functions to which we pass f expect the name to
7338 if (EQ (name
, Qunbound
) || NILP (name
))
7340 f
->name
= build_string (dpyinfo
->w32_id_name
);
7341 f
->explicit_name
= 0;
7346 f
->explicit_name
= 1;
7347 /* use the frame's title when getting resources for this frame. */
7348 specbind (Qx_resource_name
, name
);
7351 /* Extract the window parameters from the supplied values
7352 that are needed to determine window geometry. */
7356 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
7359 /* First, try whatever font the caller has specified. */
7362 tem
= Fquery_fontset (font
, Qnil
);
7364 font
= x_new_fontset (f
, tem
);
7366 font
= x_new_font (f
, SDATA (font
));
7369 /* Try out a font which we hope has bold and italic variations. */
7370 if (!STRINGP (font
))
7371 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
7372 if (! STRINGP (font
))
7373 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
7374 /* If those didn't work, look for something which will at least work. */
7375 if (! STRINGP (font
))
7376 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
7378 if (! STRINGP (font
))
7379 font
= build_string ("Fixedsys");
7381 x_default_parameter (f
, parms
, Qfont
, font
,
7382 "font", "Font", RES_TYPE_STRING
);
7385 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
7386 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
7387 /* This defaults to 2 in order to match xterm. We recognize either
7388 internalBorderWidth or internalBorder (which is what xterm calls
7390 if (NILP (Fassq (Qinternal_border_width
, parms
)))
7394 value
= w32_get_arg (parms
, Qinternal_border_width
,
7395 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
7396 if (! EQ (value
, Qunbound
))
7397 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
7400 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
7401 "internalBorderWidth", "internalBorderWidth",
7404 /* Also do the stuff which must be set before the window exists. */
7405 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
7406 "foreground", "Foreground", RES_TYPE_STRING
);
7407 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
7408 "background", "Background", RES_TYPE_STRING
);
7409 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
7410 "pointerColor", "Foreground", RES_TYPE_STRING
);
7411 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
7412 "cursorColor", "Foreground", RES_TYPE_STRING
);
7413 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
7414 "borderColor", "BorderColor", RES_TYPE_STRING
);
7416 /* Init faces before x_default_parameter is called for scroll-bar
7417 parameters because that function calls x_set_scroll_bar_width,
7418 which calls change_frame_size, which calls Fset_window_buffer,
7419 which runs hooks, which call Fvertical_motion. At the end, we
7420 end up in init_iterator with a null face cache, which should not
7422 init_frame_faces (f
);
7424 f
->output_data
.w32
->dwStyle
= WS_BORDER
| WS_POPUP
| WS_DISABLED
;
7425 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
7427 window_prompting
= x_figure_window_size (f
, parms
, 0);
7429 /* No fringes on tip frame. */
7431 f
->left_fringe_width
= 0;
7432 f
->right_fringe_width
= 0;
7435 my_create_tip_window (f
);
7440 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
7441 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
7442 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
7443 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
7444 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
7445 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
7447 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
7448 Change will not be effected unless different from the current
7450 width
= FRAME_COLS (f
);
7451 height
= FRAME_LINES (f
);
7452 FRAME_LINES (f
) = 0;
7453 SET_FRAME_COLS (f
, 0);
7454 change_frame_size (f
, height
, width
, 1, 0, 0);
7456 /* Add `tooltip' frame parameter's default value. */
7457 if (NILP (Fframe_parameter (frame
, intern ("tooltip"))))
7458 Fmodify_frame_parameters (frame
, Fcons (Fcons (intern ("tooltip"), Qt
),
7461 /* Set up faces after all frame parameters are known. This call
7462 also merges in face attributes specified for new frames.
7464 Frame parameters may be changed if .Xdefaults contains
7465 specifications for the default font. For example, if there is an
7466 `Emacs.default.attributeBackground: pink', the `background-color'
7467 attribute of the frame get's set, which let's the internal border
7468 of the tooltip frame appear in pink. Prevent this. */
7470 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
7472 /* Set tip_frame here, so that */
7474 call1 (Qface_set_after_frame_default
, frame
);
7476 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
7477 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qbackground_color
, bg
),
7485 /* It is now ok to make the frame official even if we get an error
7486 below. And the frame needs to be on Vframe_list or making it
7487 visible won't work. */
7488 Vframe_list
= Fcons (frame
, Vframe_list
);
7490 /* Now that the frame is official, it counts as a reference to
7492 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
7494 /* Setting attributes of faces of the tooltip frame from resources
7495 and similar will increment face_change_count, which leads to the
7496 clearing of all current matrices. Since this isn't necessary
7497 here, avoid it by resetting face_change_count to the value it
7498 had before we created the tip frame. */
7499 face_change_count
= face_change_count_before
;
7501 /* Discard the unwind_protect. */
7502 return unbind_to (count
, frame
);
7506 /* Compute where to display tip frame F. PARMS is the list of frame
7507 parameters for F. DX and DY are specified offsets from the current
7508 location of the mouse. WIDTH and HEIGHT are the width and height
7509 of the tooltip. Return coordinates relative to the root window of
7510 the display in *ROOT_X, and *ROOT_Y. */
7513 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, root_x
, root_y
)
7515 Lisp_Object parms
, dx
, dy
;
7517 int *root_x
, *root_y
;
7519 Lisp_Object left
, top
;
7521 /* User-specified position? */
7522 left
= Fcdr (Fassq (Qleft
, parms
));
7523 top
= Fcdr (Fassq (Qtop
, parms
));
7525 /* Move the tooltip window where the mouse pointer is. Resize and
7527 if (!INTEGERP (left
) || !INTEGERP (top
))
7539 *root_y
= XINT (top
);
7540 else if (*root_y
+ XINT (dy
) <= 0)
7541 *root_y
= 0; /* Can happen for negative dy */
7542 else if (*root_y
+ XINT (dy
) + height
<= FRAME_W32_DISPLAY_INFO (f
)->height
)
7543 /* It fits below the pointer */
7544 *root_y
+= XINT (dy
);
7545 else if (height
+ XINT (dy
) <= *root_y
)
7546 /* It fits above the pointer. */
7547 *root_y
-= height
+ XINT (dy
);
7549 /* Put it on the top. */
7552 if (INTEGERP (left
))
7553 *root_x
= XINT (left
);
7554 else if (*root_x
+ XINT (dx
) <= 0)
7555 *root_x
= 0; /* Can happen for negative dx */
7556 else if (*root_x
+ XINT (dx
) + width
<= FRAME_W32_DISPLAY_INFO (f
)->width
)
7557 /* It fits to the right of the pointer. */
7558 *root_x
+= XINT (dx
);
7559 else if (width
+ XINT (dx
) <= *root_x
)
7560 /* It fits to the left of the pointer. */
7561 *root_x
-= width
+ XINT (dx
);
7563 /* Put it left justified on the screen -- it ought to fit that way. */
7568 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
7569 doc
: /* Show STRING in a \"tooltip\" window on frame FRAME.
7570 A tooltip window is a small window displaying a string.
7572 FRAME nil or omitted means use the selected frame.
7574 PARMS is an optional list of frame parameters which can be
7575 used to change the tooltip's appearance.
7577 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
7578 means use the default timeout of 5 seconds.
7580 If the list of frame parameters PARMS contains a `left' parameter,
7581 the tooltip is displayed at that x-position. Otherwise it is
7582 displayed at the mouse position, with offset DX added (default is 5 if
7583 DX isn't specified). Likewise for the y-position; if a `top' frame
7584 parameter is specified, it determines the y-position of the tooltip
7585 window, otherwise it is displayed at the mouse position, with offset
7586 DY added (default is -10).
7588 A tooltip's maximum size is specified by `x-max-tooltip-size'.
7589 Text larger than the specified size is clipped. */)
7590 (string
, frame
, parms
, timeout
, dx
, dy
)
7591 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
7596 struct buffer
*old_buffer
;
7597 struct text_pos pos
;
7598 int i
, width
, height
;
7599 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7600 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7601 int count
= SPECPDL_INDEX ();
7603 specbind (Qinhibit_redisplay
, Qt
);
7605 GCPRO4 (string
, parms
, frame
, timeout
);
7607 CHECK_STRING (string
);
7608 f
= check_x_frame (frame
);
7610 timeout
= make_number (5);
7612 CHECK_NATNUM (timeout
);
7615 dx
= make_number (5);
7620 dy
= make_number (-10);
7624 if (NILP (last_show_tip_args
))
7625 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
7627 if (!NILP (tip_frame
))
7629 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
7630 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
7631 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
7633 if (EQ (frame
, last_frame
)
7634 && !NILP (Fequal (last_string
, string
))
7635 && !NILP (Fequal (last_parms
, parms
)))
7637 struct frame
*f
= XFRAME (tip_frame
);
7639 /* Only DX and DY have changed. */
7640 if (!NILP (tip_timer
))
7642 Lisp_Object timer
= tip_timer
;
7644 call1 (Qcancel_timer
, timer
);
7648 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
7649 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
7651 /* Put tooltip in topmost group and in position. */
7652 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
7653 root_x
, root_y
, 0, 0,
7654 SWP_NOSIZE
| SWP_NOACTIVATE
);
7656 /* Ensure tooltip is on top of other topmost windows (eg menus). */
7657 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
7659 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
7666 /* Hide a previous tip, if any. */
7669 ASET (last_show_tip_args
, 0, string
);
7670 ASET (last_show_tip_args
, 1, frame
);
7671 ASET (last_show_tip_args
, 2, parms
);
7673 /* Add default values to frame parameters. */
7674 if (NILP (Fassq (Qname
, parms
)))
7675 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
7676 if (NILP (Fassq (Qinternal_border_width
, parms
)))
7677 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
7678 if (NILP (Fassq (Qborder_width
, parms
)))
7679 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
7680 if (NILP (Fassq (Qborder_color
, parms
)))
7681 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
7682 if (NILP (Fassq (Qbackground_color
, parms
)))
7683 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
7686 /* Block input until the tip has been fully drawn, to avoid crashes
7687 when drawing tips in menus. */
7690 /* Create a frame for the tooltip, and record it in the global
7691 variable tip_frame. */
7692 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
, string
);
7695 /* Set up the frame's root window. */
7696 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7697 w
->left_col
= w
->top_line
= make_number (0);
7699 if (CONSP (Vx_max_tooltip_size
)
7700 && INTEGERP (XCAR (Vx_max_tooltip_size
))
7701 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
7702 && INTEGERP (XCDR (Vx_max_tooltip_size
))
7703 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
7705 w
->total_cols
= XCAR (Vx_max_tooltip_size
);
7706 w
->total_lines
= XCDR (Vx_max_tooltip_size
);
7710 w
->total_cols
= make_number (80);
7711 w
->total_lines
= make_number (40);
7714 FRAME_TOTAL_COLS (f
) = XINT (w
->total_cols
);
7716 w
->pseudo_window_p
= 1;
7718 /* Display the tooltip text in a temporary buffer. */
7719 old_buffer
= current_buffer
;
7720 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
7721 current_buffer
->truncate_lines
= Qnil
;
7722 clear_glyph_matrix (w
->desired_matrix
);
7723 clear_glyph_matrix (w
->current_matrix
);
7724 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
7725 try_window (FRAME_ROOT_WINDOW (f
), pos
, 0);
7727 /* Compute width and height of the tooltip. */
7729 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
7731 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
7735 /* Stop at the first empty row at the end. */
7736 if (!row
->enabled_p
|| !row
->displays_text_p
)
7739 /* Let the row go over the full width of the frame. */
7740 row
->full_width_p
= 1;
7742 #ifdef TODO /* Investigate why some fonts need more width than is
7743 calculated for some tooltips. */
7744 /* There's a glyph at the end of rows that is use to place
7745 the cursor there. Don't include the width of this glyph. */
7746 if (row
->used
[TEXT_AREA
])
7748 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
7749 row_width
= row
->pixel_width
- last
->pixel_width
;
7753 row_width
= row
->pixel_width
;
7755 /* TODO: find why tips do not draw along baseline as instructed. */
7756 height
+= row
->height
;
7757 width
= max (width
, row_width
);
7760 /* Add the frame's internal border to the width and height the X
7761 window should have. */
7762 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
7763 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
7765 /* Move the tooltip window where the mouse pointer is. Resize and
7767 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
7770 /* Adjust Window size to take border into account. */
7772 rect
.left
= rect
.top
= 0;
7774 rect
.bottom
= height
;
7775 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
7776 FRAME_EXTERNAL_MENU_BAR (f
));
7778 /* Position and size tooltip, and put it in the topmost group.
7779 The add-on of 3 to the 5th argument is a kludge: without it,
7780 some fonts cause the last character of the tip to be truncated,
7781 for some obscure reason. */
7782 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
7783 root_x
, root_y
, rect
.right
- rect
.left
+ 3,
7784 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
);
7786 /* Ensure tooltip is on top of other topmost windows (eg menus). */
7787 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
7789 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
7791 /* Let redisplay know that we have made the frame visible already. */
7792 f
->async_visible
= 1;
7794 ShowWindow (FRAME_W32_WINDOW (f
), SW_SHOWNOACTIVATE
);
7797 /* Draw into the window. */
7798 w
->must_be_updated_p
= 1;
7799 update_single_window (w
, 1);
7803 /* Restore original current buffer. */
7804 set_buffer_internal_1 (old_buffer
);
7805 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7808 /* Let the tip disappear after timeout seconds. */
7809 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
7810 intern ("x-hide-tip"));
7813 return unbind_to (count
, Qnil
);
7817 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
7818 doc
: /* Hide the current tooltip window, if there is any.
7819 Value is t if tooltip was open, nil otherwise. */)
7823 Lisp_Object deleted
, frame
, timer
;
7824 struct gcpro gcpro1
, gcpro2
;
7826 /* Return quickly if nothing to do. */
7827 if (NILP (tip_timer
) && NILP (tip_frame
))
7832 GCPRO2 (frame
, timer
);
7833 tip_frame
= tip_timer
= deleted
= Qnil
;
7835 count
= SPECPDL_INDEX ();
7836 specbind (Qinhibit_redisplay
, Qt
);
7837 specbind (Qinhibit_quit
, Qt
);
7840 call1 (Qcancel_timer
, timer
);
7844 Fdelete_frame (frame
, Qnil
);
7849 return unbind_to (count
, deleted
);
7854 /***********************************************************************
7855 File selection dialog
7856 ***********************************************************************/
7857 extern Lisp_Object Qfile_name_history
;
7859 /* Callback for altering the behaviour of the Open File dialog.
7860 Makes the Filename text field contain "Current Directory" and be
7861 read-only when "Directories" is selected in the filter. This
7862 allows us to work around the fact that the standard Open File
7863 dialog does not support directories. */
7865 file_dialog_callback (hwnd
, msg
, wParam
, lParam
)
7871 if (msg
== WM_NOTIFY
)
7873 OFNOTIFY
* notify
= (OFNOTIFY
*)lParam
;
7874 /* Detect when the Filter dropdown is changed. */
7875 if (notify
->hdr
.code
== CDN_TYPECHANGE
7876 || notify
->hdr
.code
== CDN_INITDONE
)
7878 HWND dialog
= GetParent (hwnd
);
7879 HWND edit_control
= GetDlgItem (dialog
, FILE_NAME_TEXT_FIELD
);
7881 /* Directories is in index 2. */
7882 if (notify
->lpOFN
->nFilterIndex
== 2)
7884 CommDlg_OpenSave_SetControlText (dialog
, FILE_NAME_TEXT_FIELD
,
7885 "Current Directory");
7886 EnableWindow (edit_control
, FALSE
);
7890 /* Don't override default filename on init done. */
7891 if (notify
->hdr
.code
== CDN_TYPECHANGE
)
7892 CommDlg_OpenSave_SetControlText (dialog
,
7893 FILE_NAME_TEXT_FIELD
, "");
7894 EnableWindow (edit_control
, TRUE
);
7901 /* Since we compile with _WIN32_WINNT set to 0x0400 (for NT4 compatibility)
7902 we end up with the old file dialogs. Define a big enough struct for the
7903 new dialog to trick GetOpenFileName into giving us the new dialogs on
7904 Windows 2000 and XP. */
7907 OPENFILENAME real_details
;
7914 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
7915 doc
: /* Read file name, prompting with PROMPT in directory DIR.
7916 Use a file selection dialog.
7917 Select DEFAULT-FILENAME in the dialog's file selection box, if
7918 specified. Ensure that file exists if MUSTMATCH is non-nil.
7919 If ONLY-DIR-P is non-nil, the user can only select directories. */)
7920 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
)
7921 Lisp_Object prompt
, dir
, default_filename
, mustmatch
, only_dir_p
;
7923 struct frame
*f
= SELECTED_FRAME ();
7924 Lisp_Object file
= Qnil
;
7925 int count
= SPECPDL_INDEX ();
7926 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
7927 char filename
[MAX_PATH
+ 1];
7928 char init_dir
[MAX_PATH
+ 1];
7929 int default_filter_index
= 1; /* 1: All Files, 2: Directories only */
7931 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
7932 CHECK_STRING (prompt
);
7935 /* Create the dialog with PROMPT as title, using DIR as initial
7936 directory and using "*" as pattern. */
7937 dir
= Fexpand_file_name (dir
, Qnil
);
7938 strncpy (init_dir
, SDATA (ENCODE_FILE (dir
)), MAX_PATH
);
7939 init_dir
[MAX_PATH
] = '\0';
7940 unixtodos_filename (init_dir
);
7942 if (STRINGP (default_filename
))
7944 char *file_name_only
;
7945 char *full_path_name
= SDATA (ENCODE_FILE (default_filename
));
7947 unixtodos_filename (full_path_name
);
7949 file_name_only
= strrchr (full_path_name
, '\\');
7950 if (!file_name_only
)
7951 file_name_only
= full_path_name
;
7955 strncpy (filename
, file_name_only
, MAX_PATH
);
7956 filename
[MAX_PATH
] = '\0';
7962 NEWOPENFILENAME new_file_details
;
7963 BOOL file_opened
= FALSE
;
7964 OPENFILENAME
* file_details
= &new_file_details
.real_details
;
7966 /* Prevent redisplay. */
7967 specbind (Qinhibit_redisplay
, Qt
);
7970 bzero (&new_file_details
, sizeof (new_file_details
));
7971 /* Apparently NT4 crashes if you give it an unexpected size.
7972 I'm not sure about Windows 9x, so play it safe. */
7973 if (w32_major_version
> 4 && w32_major_version
< 95)
7974 file_details
->lStructSize
= sizeof (new_file_details
);
7976 file_details
->lStructSize
= sizeof (file_details
);
7978 file_details
->hwndOwner
= FRAME_W32_WINDOW (f
);
7979 /* Undocumented Bug in Common File Dialog:
7980 If a filter is not specified, shell links are not resolved. */
7981 file_details
->lpstrFilter
= "All Files (*.*)\0*.*\0Directories\0*|*\0\0";
7982 file_details
->lpstrFile
= filename
;
7983 file_details
->nMaxFile
= sizeof (filename
);
7984 file_details
->lpstrInitialDir
= init_dir
;
7985 file_details
->lpstrTitle
= SDATA (prompt
);
7987 if (! NILP (only_dir_p
))
7988 default_filter_index
= 2;
7990 file_details
->nFilterIndex
= default_filter_index
;
7992 file_details
->Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
7993 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
7994 if (!NILP (mustmatch
))
7996 /* Require that the path to the parent directory exists. */
7997 file_details
->Flags
|= OFN_PATHMUSTEXIST
;
7998 /* If we are looking for a file, require that it exists. */
7999 if (NILP (only_dir_p
))
8000 file_details
->Flags
|= OFN_FILEMUSTEXIST
;
8003 file_details
->lpfnHook
= (LPOFNHOOKPROC
) file_dialog_callback
;
8005 file_opened
= GetOpenFileName (file_details
);
8011 dostounix_filename (filename
);
8013 if (file_details
->nFilterIndex
== 2)
8015 /* "Directories" selected - strip dummy file name. */
8016 char * last
= strrchr (filename
, '/');
8020 file
= DECODE_FILE(build_string (filename
));
8022 /* User cancelled the dialog without making a selection. */
8023 else if (!CommDlgExtendedError ())
8025 /* An error occurred, fallback on reading from the mini-buffer. */
8027 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
8028 dir
, mustmatch
, dir
, Qfile_name_history
,
8029 default_filename
, Qnil
);
8031 file
= unbind_to (count
, file
);
8036 /* Make "Cancel" equivalent to C-g. */
8038 Fsignal (Qquit
, Qnil
);
8040 return unbind_to (count
, file
);
8045 /***********************************************************************
8046 w32 specialized functions
8047 ***********************************************************************/
8049 DEFUN ("w32-select-font", Fw32_select_font
, Sw32_select_font
, 0, 2, 0,
8050 doc
: /* Select a font for the named FRAME using the W32 font dialog.
8051 Returns an X-style font string corresponding to the selection.
8053 If FRAME is omitted or nil, it defaults to the selected frame.
8054 If INCLUDE-PROPORTIONAL is non-nil, include proportional fonts
8055 in the font selection dialog. */)
8056 (frame
, include_proportional
)
8057 Lisp_Object frame
, include_proportional
;
8059 FRAME_PTR f
= check_x_frame (frame
);
8067 bzero (&cf
, sizeof (cf
));
8068 bzero (&lf
, sizeof (lf
));
8070 cf
.lStructSize
= sizeof (cf
);
8071 cf
.hwndOwner
= FRAME_W32_WINDOW (f
);
8072 cf
.Flags
= CF_FORCEFONTEXIST
| CF_SCREENFONTS
| CF_NOVERTFONTS
;
8074 /* Unless include_proportional is non-nil, limit the selection to
8075 monospaced fonts. */
8076 if (NILP (include_proportional
))
8077 cf
.Flags
|= CF_FIXEDPITCHONLY
;
8081 /* Initialize as much of the font details as we can from the current
8083 hdc
= GetDC (FRAME_W32_WINDOW (f
));
8084 oldobj
= SelectObject (hdc
, FRAME_FONT (f
)->hfont
);
8085 GetTextFace (hdc
, LF_FACESIZE
, lf
.lfFaceName
);
8086 if (GetTextMetrics (hdc
, &tm
))
8088 lf
.lfHeight
= tm
.tmInternalLeading
- tm
.tmHeight
;
8089 lf
.lfWeight
= tm
.tmWeight
;
8090 lf
.lfItalic
= tm
.tmItalic
;
8091 lf
.lfUnderline
= tm
.tmUnderlined
;
8092 lf
.lfStrikeOut
= tm
.tmStruckOut
;
8093 lf
.lfCharSet
= tm
.tmCharSet
;
8094 cf
.Flags
|= CF_INITTOLOGFONTSTRUCT
;
8096 SelectObject (hdc
, oldobj
);
8097 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
8099 if (!ChooseFont (&cf
) || !w32_to_x_font (&lf
, buf
, 100, NULL
))
8102 return build_string (buf
);
8105 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
,
8106 Sw32_send_sys_command
, 1, 2, 0,
8107 doc
: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND.
8108 Some useful values for COMMAND are #xf030 to maximize frame (#xf020
8109 to minimize), #xf120 to restore frame to original size, and #xf100
8110 to activate the menubar for keyboard access. #xf140 activates the
8111 screen saver if defined.
8113 If optional parameter FRAME is not specified, use selected frame. */)
8115 Lisp_Object command
, frame
;
8117 FRAME_PTR f
= check_x_frame (frame
);
8119 CHECK_NUMBER (command
);
8121 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
8126 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
8127 doc
: /* Get Windows to perform OPERATION on DOCUMENT.
8128 This is a wrapper around the ShellExecute system function, which
8129 invokes the application registered to handle OPERATION for DOCUMENT.
8130 OPERATION is typically \"open\", \"print\" or \"explore\" (but can be
8131 nil for the default action), and DOCUMENT is typically the name of a
8132 document file or URL, but can also be a program executable to run or
8133 a directory to open in the Windows Explorer.
8135 If DOCUMENT is a program executable, PARAMETERS can be a string
8136 containing command line parameters, but otherwise should be nil.
8138 SHOW-FLAG can be used to control whether the invoked application is hidden
8139 or minimized. If SHOW-FLAG is nil, the application is displayed normally,
8140 otherwise it is an integer representing a ShowWindow flag:
8145 6 - start minimized */)
8146 (operation
, document
, parameters
, show_flag
)
8147 Lisp_Object operation
, document
, parameters
, show_flag
;
8149 Lisp_Object current_dir
;
8151 CHECK_STRING (document
);
8153 /* Encode filename and current directory. */
8154 current_dir
= ENCODE_FILE (current_buffer
->directory
);
8155 document
= ENCODE_FILE (document
);
8156 if ((int) ShellExecute (NULL
,
8157 (STRINGP (operation
) ?
8158 SDATA (operation
) : NULL
),
8160 (STRINGP (parameters
) ?
8161 SDATA (parameters
) : NULL
),
8162 SDATA (current_dir
),
8163 (INTEGERP (show_flag
) ?
8164 XINT (show_flag
) : SW_SHOWDEFAULT
))
8167 error ("ShellExecute failed: %s", w32_strerror (0));
8170 /* Lookup virtual keycode from string representing the name of a
8171 non-ascii keystroke into the corresponding virtual key, using
8172 lispy_function_keys. */
8174 lookup_vk_code (char *key
)
8178 for (i
= 0; i
< 256; i
++)
8179 if (lispy_function_keys
[i
] != 0
8180 && strcmp (lispy_function_keys
[i
], key
) == 0)
8186 /* Convert a one-element vector style key sequence to a hot key
8189 w32_parse_hot_key (key
)
8192 /* Copied from Fdefine_key and store_in_keymap. */
8193 register Lisp_Object c
;
8197 struct gcpro gcpro1
;
8201 if (XFASTINT (Flength (key
)) != 1)
8206 c
= Faref (key
, make_number (0));
8208 if (CONSP (c
) && lucid_event_type_list_p (c
))
8209 c
= Fevent_convert_list (c
);
8213 if (! INTEGERP (c
) && ! SYMBOLP (c
))
8214 error ("Key definition is invalid");
8216 /* Work out the base key and the modifiers. */
8219 c
= parse_modifiers (c
);
8220 lisp_modifiers
= XINT (Fcar (Fcdr (c
)));
8224 vk_code
= lookup_vk_code (SDATA (SYMBOL_NAME (c
)));
8226 else if (INTEGERP (c
))
8228 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
8229 /* Many ascii characters are their own virtual key code. */
8230 vk_code
= XINT (c
) & CHARACTERBITS
;
8233 if (vk_code
< 0 || vk_code
> 255)
8236 if ((lisp_modifiers
& meta_modifier
) != 0
8237 && !NILP (Vw32_alt_is_meta
))
8238 lisp_modifiers
|= alt_modifier
;
8240 /* Supply defs missing from mingw32. */
8242 #define MOD_ALT 0x0001
8243 #define MOD_CONTROL 0x0002
8244 #define MOD_SHIFT 0x0004
8245 #define MOD_WIN 0x0008
8248 /* Convert lisp modifiers to Windows hot-key form. */
8249 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
8250 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
8251 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
8252 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
8254 return HOTKEY (vk_code
, w32_modifiers
);
8257 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
,
8258 Sw32_register_hot_key
, 1, 1, 0,
8259 doc
: /* Register KEY as a hot-key combination.
8260 Certain key combinations like Alt-Tab are reserved for system use on
8261 Windows, and therefore are normally intercepted by the system. However,
8262 most of these key combinations can be received by registering them as
8263 hot-keys, overriding their special meaning.
8265 KEY must be a one element key definition in vector form that would be
8266 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta
8267 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper
8268 is always interpreted as the Windows modifier keys.
8270 The return value is the hotkey-id if registered, otherwise nil. */)
8274 key
= w32_parse_hot_key (key
);
8276 if (NILP (Fmemq (key
, w32_grabbed_keys
)))
8278 /* Reuse an empty slot if possible. */
8279 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
8281 /* Safe to add new key to list, even if we have focus. */
8283 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
8285 XSETCAR (item
, key
);
8287 /* Notify input thread about new hot-key definition, so that it
8288 takes effect without needing to switch focus. */
8289 #ifdef USE_LISP_UNION_TYPE
8290 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
8293 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
8301 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
,
8302 Sw32_unregister_hot_key
, 1, 1, 0,
8303 doc
: /* Unregister KEY as a hot-key combination. */)
8309 if (!INTEGERP (key
))
8310 key
= w32_parse_hot_key (key
);
8312 item
= Fmemq (key
, w32_grabbed_keys
);
8316 /* Notify input thread about hot-key definition being removed, so
8317 that it takes effect without needing focus switch. */
8318 #ifdef USE_LISP_UNION_TYPE
8319 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
8320 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
.i
))
8322 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
8323 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
))
8328 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
8335 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
,
8336 Sw32_registered_hot_keys
, 0, 0, 0,
8337 doc
: /* Return list of registered hot-key IDs. */)
8340 return Fcopy_sequence (w32_grabbed_keys
);
8343 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
,
8344 Sw32_reconstruct_hot_key
, 1, 1, 0,
8345 doc
: /* Convert hot-key ID to a lisp key combination.
8346 usage: (w32-reconstruct-hot-key ID) */)
8348 Lisp_Object hotkeyid
;
8350 int vk_code
, w32_modifiers
;
8353 CHECK_NUMBER (hotkeyid
);
8355 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
8356 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
8358 if (lispy_function_keys
[vk_code
])
8359 key
= intern (lispy_function_keys
[vk_code
]);
8361 key
= make_number (vk_code
);
8363 key
= Fcons (key
, Qnil
);
8364 if (w32_modifiers
& MOD_SHIFT
)
8365 key
= Fcons (Qshift
, key
);
8366 if (w32_modifiers
& MOD_CONTROL
)
8367 key
= Fcons (Qctrl
, key
);
8368 if (w32_modifiers
& MOD_ALT
)
8369 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
8370 if (w32_modifiers
& MOD_WIN
)
8371 key
= Fcons (Qhyper
, key
);
8376 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
,
8377 Sw32_toggle_lock_key
, 1, 2, 0,
8378 doc
: /* Toggle the state of the lock key KEY.
8379 KEY can be `capslock', `kp-numlock', or `scroll'.
8380 If the optional parameter NEW-STATE is a number, then the state of KEY
8381 is set to off if the low bit of NEW-STATE is zero, otherwise on. */)
8383 Lisp_Object key
, new_state
;
8387 if (EQ (key
, intern ("capslock")))
8388 vk_code
= VK_CAPITAL
;
8389 else if (EQ (key
, intern ("kp-numlock")))
8390 vk_code
= VK_NUMLOCK
;
8391 else if (EQ (key
, intern ("scroll")))
8392 vk_code
= VK_SCROLL
;
8396 if (!dwWindowsThreadId
)
8397 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
8399 #ifdef USE_LISP_UNION_TYPE
8400 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
8401 (WPARAM
) vk_code
, (LPARAM
) new_state
.i
))
8403 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
8404 (WPARAM
) vk_code
, (LPARAM
) new_state
))
8408 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
8409 return make_number (msg
.wParam
);
8414 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
8415 doc
: /* Return storage information about the file system FILENAME is on.
8416 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
8417 storage of the file system, FREE is the free storage, and AVAIL is the
8418 storage available to a non-superuser. All 3 numbers are in bytes.
8419 If the underlying system call fails, value is nil. */)
8421 Lisp_Object filename
;
8423 Lisp_Object encoded
, value
;
8425 CHECK_STRING (filename
);
8426 filename
= Fexpand_file_name (filename
, Qnil
);
8427 encoded
= ENCODE_FILE (filename
);
8431 /* Determining the required information on Windows turns out, sadly,
8432 to be more involved than one would hope. The original Win32 api
8433 call for this will return bogus information on some systems, but we
8434 must dynamically probe for the replacement api, since that was
8435 added rather late on. */
8437 HMODULE hKernel
= GetModuleHandle ("kernel32");
8438 BOOL (*pfn_GetDiskFreeSpaceEx
)
8439 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
8440 = (void *) GetProcAddress (hKernel
, "GetDiskFreeSpaceEx");
8442 /* On Windows, we may need to specify the root directory of the
8443 volume holding FILENAME. */
8444 char rootname
[MAX_PATH
];
8445 char *name
= SDATA (encoded
);
8447 /* find the root name of the volume if given */
8448 if (isalpha (name
[0]) && name
[1] == ':')
8450 rootname
[0] = name
[0];
8451 rootname
[1] = name
[1];
8455 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
8457 char *str
= rootname
;
8461 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
8471 if (pfn_GetDiskFreeSpaceEx
)
8473 /* Unsigned large integers cannot be cast to double, so
8474 use signed ones instead. */
8475 LARGE_INTEGER availbytes
;
8476 LARGE_INTEGER freebytes
;
8477 LARGE_INTEGER totalbytes
;
8479 if (pfn_GetDiskFreeSpaceEx(rootname
,
8480 (ULARGE_INTEGER
*)&availbytes
,
8481 (ULARGE_INTEGER
*)&totalbytes
,
8482 (ULARGE_INTEGER
*)&freebytes
))
8483 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
8484 make_float ((double) freebytes
.QuadPart
),
8485 make_float ((double) availbytes
.QuadPart
));
8489 DWORD sectors_per_cluster
;
8490 DWORD bytes_per_sector
;
8491 DWORD free_clusters
;
8492 DWORD total_clusters
;
8494 if (GetDiskFreeSpace(rootname
,
8495 §ors_per_cluster
,
8499 value
= list3 (make_float ((double) total_clusters
8500 * sectors_per_cluster
* bytes_per_sector
),
8501 make_float ((double) free_clusters
8502 * sectors_per_cluster
* bytes_per_sector
),
8503 make_float ((double) free_clusters
8504 * sectors_per_cluster
* bytes_per_sector
));
8511 DEFUN ("default-printer-name", Fdefault_printer_name
, Sdefault_printer_name
,
8512 0, 0, 0, doc
: /* Return the name of Windows default printer device. */)
8515 static char pname_buf
[256];
8518 PRINTER_INFO_2
*ppi2
= NULL
;
8519 DWORD dwNeeded
= 0, dwReturned
= 0;
8521 /* Retrieve the default string from Win.ini (the registry).
8522 * String will be in form "printername,drivername,portname".
8523 * This is the most portable way to get the default printer. */
8524 if (GetProfileString ("windows", "device", ",,", pname_buf
, sizeof (pname_buf
)) <= 0)
8526 /* printername precedes first "," character */
8527 strtok (pname_buf
, ",");
8528 /* We want to know more than the printer name */
8529 if (!OpenPrinter (pname_buf
, &hPrn
, NULL
))
8531 GetPrinter (hPrn
, 2, NULL
, 0, &dwNeeded
);
8534 ClosePrinter (hPrn
);
8537 /* Allocate memory for the PRINTER_INFO_2 struct */
8538 ppi2
= (PRINTER_INFO_2
*) xmalloc (dwNeeded
);
8541 ClosePrinter (hPrn
);
8544 /* Call GetPrinter() again with big enouth memory block */
8545 err
= GetPrinter (hPrn
, 2, (LPBYTE
)ppi2
, dwNeeded
, &dwReturned
);
8546 ClosePrinter (hPrn
);
8555 if (ppi2
->Attributes
& PRINTER_ATTRIBUTE_SHARED
&& ppi2
->pServerName
)
8557 /* a remote printer */
8558 if (*ppi2
->pServerName
== '\\')
8559 _snprintf(pname_buf
, sizeof (pname_buf
), "%s\\%s", ppi2
->pServerName
,
8562 _snprintf(pname_buf
, sizeof (pname_buf
), "\\\\%s\\%s", ppi2
->pServerName
,
8564 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
8568 /* a local printer */
8569 strncpy(pname_buf
, ppi2
->pPortName
, sizeof (pname_buf
));
8570 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
8571 /* `pPortName' can include several ports, delimited by ','.
8572 * we only use the first one. */
8573 strtok(pname_buf
, ",");
8578 return build_string (pname_buf
);
8581 /***********************************************************************
8583 ***********************************************************************/
8585 /* Keep this list in the same order as frame_parms in frame.c.
8586 Use 0 for unsupported frame parameters. */
8588 frame_parm_handler w32_frame_parm_handlers
[] =
8592 x_set_background_color
,
8598 x_set_foreground_color
,
8601 x_set_internal_border_width
,
8602 x_set_menu_bar_lines
,
8604 x_explicitly_set_name
,
8605 x_set_scroll_bar_width
,
8608 x_set_vertical_scroll_bars
,
8610 x_set_tool_bar_lines
,
8611 0, /* x_set_scroll_bar_foreground, */
8612 0, /* x_set_scroll_bar_background, */
8617 0, /* x_set_wait_for_wm, */
8624 globals_of_w32fns ();
8625 /* This is zero if not using MS-Windows. */
8627 track_mouse_window
= NULL
;
8629 w32_visible_system_caret_hwnd
= NULL
;
8631 Qnone
= intern ("none");
8633 Qsuppress_icon
= intern ("suppress-icon");
8634 staticpro (&Qsuppress_icon
);
8635 Qundefined_color
= intern ("undefined-color");
8636 staticpro (&Qundefined_color
);
8637 Qcancel_timer
= intern ("cancel-timer");
8638 staticpro (&Qcancel_timer
);
8640 Qhyper
= intern ("hyper");
8641 staticpro (&Qhyper
);
8642 Qsuper
= intern ("super");
8643 staticpro (&Qsuper
);
8644 Qmeta
= intern ("meta");
8646 Qalt
= intern ("alt");
8648 Qctrl
= intern ("ctrl");
8650 Qcontrol
= intern ("control");
8651 staticpro (&Qcontrol
);
8652 Qshift
= intern ("shift");
8653 staticpro (&Qshift
);
8654 /* This is the end of symbol initialization. */
8656 /* Text property `display' should be nonsticky by default. */
8657 Vtext_property_default_nonsticky
8658 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
8661 Fput (Qundefined_color
, Qerror_conditions
,
8662 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
8663 Fput (Qundefined_color
, Qerror_message
,
8664 build_string ("Undefined color"));
8666 staticpro (&w32_grabbed_keys
);
8667 w32_grabbed_keys
= Qnil
;
8669 DEFVAR_LISP ("w32-color-map", &Vw32_color_map
,
8670 doc
: /* An array of color name mappings for Windows. */);
8671 Vw32_color_map
= Qnil
;
8673 DEFVAR_LISP ("w32-pass-alt-to-system", &Vw32_pass_alt_to_system
,
8674 doc
: /* Non-nil if alt key presses are passed on to Windows.
8675 When non-nil, for example, alt pressed and released and then space will
8676 open the System menu. When nil, Emacs silently swallows alt key events. */);
8677 Vw32_pass_alt_to_system
= Qnil
;
8679 DEFVAR_LISP ("w32-alt-is-meta", &Vw32_alt_is_meta
,
8680 doc
: /* Non-nil if the alt key is to be considered the same as the meta key.
8681 When nil, Emacs will translate the alt key to the Alt modifier, and not Meta. */);
8682 Vw32_alt_is_meta
= Qt
;
8684 DEFVAR_INT ("w32-quit-key", &w32_quit_key
,
8685 doc
: /* If non-zero, the virtual key code for an alternative quit key. */);
8688 DEFVAR_LISP ("w32-pass-lwindow-to-system",
8689 &Vw32_pass_lwindow_to_system
,
8690 doc
: /* Non-nil if the left \"Windows\" key is passed on to Windows.
8691 When non-nil, the Start menu is opened by tapping the key. */);
8692 Vw32_pass_lwindow_to_system
= Qt
;
8694 DEFVAR_LISP ("w32-pass-rwindow-to-system",
8695 &Vw32_pass_rwindow_to_system
,
8696 doc
: /* Non-nil if the right \"Windows\" key is passed on to Windows.
8697 When non-nil, the Start menu is opened by tapping the key. */);
8698 Vw32_pass_rwindow_to_system
= Qt
;
8700 DEFVAR_LISP ("w32-phantom-key-code",
8701 &Vw32_phantom_key_code
,
8702 doc
: /* Virtual key code used to generate \"phantom\" key presses.
8703 Value is a number between 0 and 255.
8705 Phantom key presses are generated in order to stop the system from
8706 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or
8707 `w32-pass-rwindow-to-system' is nil. */);
8708 /* Although 255 is technically not a valid key code, it works and
8709 means that this hack won't interfere with any real key code. */
8710 XSETINT (Vw32_phantom_key_code
, 255);
8712 DEFVAR_LISP ("w32-enable-num-lock",
8713 &Vw32_enable_num_lock
,
8714 doc
: /* Non-nil if Num Lock should act normally.
8715 Set to nil to see Num Lock as the key `kp-numlock'. */);
8716 Vw32_enable_num_lock
= Qt
;
8718 DEFVAR_LISP ("w32-enable-caps-lock",
8719 &Vw32_enable_caps_lock
,
8720 doc
: /* Non-nil if Caps Lock should act normally.
8721 Set to nil to see Caps Lock as the key `capslock'. */);
8722 Vw32_enable_caps_lock
= Qt
;
8724 DEFVAR_LISP ("w32-scroll-lock-modifier",
8725 &Vw32_scroll_lock_modifier
,
8726 doc
: /* Modifier to use for the Scroll Lock on state.
8727 The value can be hyper, super, meta, alt, control or shift for the
8728 respective modifier, or nil to see Scroll Lock as the key `scroll'.
8729 Any other value will cause the key to be ignored. */);
8730 Vw32_scroll_lock_modifier
= Qt
;
8732 DEFVAR_LISP ("w32-lwindow-modifier",
8733 &Vw32_lwindow_modifier
,
8734 doc
: /* Modifier to use for the left \"Windows\" key.
8735 The value can be hyper, super, meta, alt, control or shift for the
8736 respective modifier, or nil to appear as the key `lwindow'.
8737 Any other value will cause the key to be ignored. */);
8738 Vw32_lwindow_modifier
= Qnil
;
8740 DEFVAR_LISP ("w32-rwindow-modifier",
8741 &Vw32_rwindow_modifier
,
8742 doc
: /* Modifier to use for the right \"Windows\" key.
8743 The value can be hyper, super, meta, alt, control or shift for the
8744 respective modifier, or nil to appear as the key `rwindow'.
8745 Any other value will cause the key to be ignored. */);
8746 Vw32_rwindow_modifier
= Qnil
;
8748 DEFVAR_LISP ("w32-apps-modifier",
8749 &Vw32_apps_modifier
,
8750 doc
: /* Modifier to use for the \"Apps\" key.
8751 The value can be hyper, super, meta, alt, control or shift for the
8752 respective modifier, or nil to appear as the key `apps'.
8753 Any other value will cause the key to be ignored. */);
8754 Vw32_apps_modifier
= Qnil
;
8756 DEFVAR_BOOL ("w32-enable-synthesized-fonts", &w32_enable_synthesized_fonts
,
8757 doc
: /* Non-nil enables selection of artificially italicized and bold fonts. */);
8758 w32_enable_synthesized_fonts
= 0;
8760 DEFVAR_LISP ("w32-enable-palette", &Vw32_enable_palette
,
8761 doc
: /* Non-nil enables Windows palette management to map colors exactly. */);
8762 Vw32_enable_palette
= Qt
;
8764 DEFVAR_INT ("w32-mouse-button-tolerance",
8765 &w32_mouse_button_tolerance
,
8766 doc
: /* Analogue of double click interval for faking middle mouse events.
8767 The value is the minimum time in milliseconds that must elapse between
8768 left/right button down events before they are considered distinct events.
8769 If both mouse buttons are depressed within this interval, a middle mouse
8770 button down event is generated instead. */);
8771 w32_mouse_button_tolerance
= GetDoubleClickTime () / 2;
8773 DEFVAR_INT ("w32-mouse-move-interval",
8774 &w32_mouse_move_interval
,
8775 doc
: /* Minimum interval between mouse move events.
8776 The value is the minimum time in milliseconds that must elapse between
8777 successive mouse move (or scroll bar drag) events before they are
8778 reported as lisp events. */);
8779 w32_mouse_move_interval
= 0;
8781 DEFVAR_BOOL ("w32-pass-extra-mouse-buttons-to-system",
8782 &w32_pass_extra_mouse_buttons_to_system
,
8783 doc
: /* Non-nil if the fourth and fifth mouse buttons are passed to Windows.
8784 Recent versions of Windows support mice with up to five buttons.
8785 Since most applications don't support these extra buttons, most mouse
8786 drivers will allow you to map them to functions at the system level.
8787 If this variable is non-nil, Emacs will pass them on, allowing the
8788 system to handle them. */);
8789 w32_pass_extra_mouse_buttons_to_system
= 0;
8791 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
8792 doc
: /* The shape of the pointer when over text.
8793 Changing the value does not affect existing frames
8794 unless you set the mouse color. */);
8795 Vx_pointer_shape
= Qnil
;
8797 Vx_nontext_pointer_shape
= Qnil
;
8799 Vx_mode_pointer_shape
= Qnil
;
8801 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
8802 doc
: /* The shape of the pointer when Emacs is busy.
8803 This variable takes effect when you create a new frame
8804 or when you set the mouse color. */);
8805 Vx_hourglass_pointer_shape
= Qnil
;
8807 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
8808 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
8809 display_hourglass_p
= 1;
8811 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
8812 doc
: /* *Seconds to wait before displaying an hourglass pointer.
8813 Value must be an integer or float. */);
8814 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
8816 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
8817 &Vx_sensitive_text_pointer_shape
,
8818 doc
: /* The shape of the pointer when over mouse-sensitive text.
8819 This variable takes effect when you create a new frame
8820 or when you set the mouse color. */);
8821 Vx_sensitive_text_pointer_shape
= Qnil
;
8823 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
8824 &Vx_window_horizontal_drag_shape
,
8825 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
8826 This variable takes effect when you create a new frame
8827 or when you set the mouse color. */);
8828 Vx_window_horizontal_drag_shape
= Qnil
;
8830 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
8831 doc
: /* A string indicating the foreground color of the cursor box. */);
8832 Vx_cursor_fore_pixel
= Qnil
;
8834 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size
,
8835 doc
: /* Maximum size for tooltips.
8836 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
8837 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
8839 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
8840 doc
: /* Non-nil if no window manager is in use.
8841 Emacs doesn't try to figure this out; this is always nil
8842 unless you set it to something else. */);
8843 /* We don't have any way to find this out, so set it to nil
8844 and maybe the user would like to set it to t. */
8845 Vx_no_window_manager
= Qnil
;
8847 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
8848 &Vx_pixel_size_width_font_regexp
,
8849 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
8851 Since Emacs gets width of a font matching with this regexp from
8852 PIXEL_SIZE field of the name, font finding mechanism gets faster for
8853 such a font. This is especially effective for such large fonts as
8854 Chinese, Japanese, and Korean. */);
8855 Vx_pixel_size_width_font_regexp
= Qnil
;
8857 DEFVAR_LISP ("w32-bdf-filename-alist",
8858 &Vw32_bdf_filename_alist
,
8859 doc
: /* List of bdf fonts and their corresponding filenames. */);
8860 Vw32_bdf_filename_alist
= Qnil
;
8862 DEFVAR_BOOL ("w32-strict-fontnames",
8863 &w32_strict_fontnames
,
8864 doc
: /* Non-nil means only use fonts that are exact matches for those requested.
8865 Default is nil, which allows old fontnames that are not XLFD compliant,
8866 and allows third-party CJK display to work by specifying false charset
8867 fields to trick Emacs into translating to Big5, SJIS etc.
8868 Setting this to t will prevent wrong fonts being selected when
8869 fontsets are automatically created. */);
8870 w32_strict_fontnames
= 0;
8872 DEFVAR_BOOL ("w32-strict-painting",
8873 &w32_strict_painting
,
8874 doc
: /* Non-nil means use strict rules for repainting frames.
8875 Set this to nil to get the old behavior for repainting; this should
8876 only be necessary if the default setting causes problems. */);
8877 w32_strict_painting
= 1;
8879 DEFVAR_LISP ("w32-charset-info-alist",
8880 &Vw32_charset_info_alist
,
8881 doc
: /* Alist linking Emacs character sets to Windows fonts and codepages.
8882 Each entry should be of the form:
8884 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE))
8886 where CHARSET_NAME is a string used in font names to identify the charset,
8887 WINDOWS_CHARSET is a symbol that can be one of:
8888 w32-charset-ansi, w32-charset-default, w32-charset-symbol,
8889 w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312,
8890 w32-charset-chinesebig5,
8891 w32-charset-johab, w32-charset-hebrew,
8892 w32-charset-arabic, w32-charset-greek, w32-charset-turkish,
8893 w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope,
8894 w32-charset-russian, w32-charset-mac, w32-charset-baltic,
8895 w32-charset-unicode,
8897 CODEPAGE should be an integer specifying the codepage that should be used
8898 to display the character set, t to do no translation and output as Unicode,
8899 or nil to do no translation and output as 8 bit (or multibyte on far-east
8900 versions of Windows) characters. */);
8901 Vw32_charset_info_alist
= Qnil
;
8903 staticpro (&Qw32_charset_ansi
);
8904 Qw32_charset_ansi
= intern ("w32-charset-ansi");
8905 staticpro (&Qw32_charset_symbol
);
8906 Qw32_charset_default
= intern ("w32-charset-default");
8907 staticpro (&Qw32_charset_default
);
8908 Qw32_charset_symbol
= intern ("w32-charset-symbol");
8909 staticpro (&Qw32_charset_shiftjis
);
8910 Qw32_charset_shiftjis
= intern ("w32-charset-shiftjis");
8911 staticpro (&Qw32_charset_hangeul
);
8912 Qw32_charset_hangeul
= intern ("w32-charset-hangeul");
8913 staticpro (&Qw32_charset_chinesebig5
);
8914 Qw32_charset_chinesebig5
= intern ("w32-charset-chinesebig5");
8915 staticpro (&Qw32_charset_gb2312
);
8916 Qw32_charset_gb2312
= intern ("w32-charset-gb2312");
8917 staticpro (&Qw32_charset_oem
);
8918 Qw32_charset_oem
= intern ("w32-charset-oem");
8920 #ifdef JOHAB_CHARSET
8922 static int w32_extra_charsets_defined
= 1;
8923 DEFVAR_BOOL ("w32-extra-charsets-defined", &w32_extra_charsets_defined
,
8924 doc
: /* Internal variable. */);
8926 staticpro (&Qw32_charset_johab
);
8927 Qw32_charset_johab
= intern ("w32-charset-johab");
8928 staticpro (&Qw32_charset_easteurope
);
8929 Qw32_charset_easteurope
= intern ("w32-charset-easteurope");
8930 staticpro (&Qw32_charset_turkish
);
8931 Qw32_charset_turkish
= intern ("w32-charset-turkish");
8932 staticpro (&Qw32_charset_baltic
);
8933 Qw32_charset_baltic
= intern ("w32-charset-baltic");
8934 staticpro (&Qw32_charset_russian
);
8935 Qw32_charset_russian
= intern ("w32-charset-russian");
8936 staticpro (&Qw32_charset_arabic
);
8937 Qw32_charset_arabic
= intern ("w32-charset-arabic");
8938 staticpro (&Qw32_charset_greek
);
8939 Qw32_charset_greek
= intern ("w32-charset-greek");
8940 staticpro (&Qw32_charset_hebrew
);
8941 Qw32_charset_hebrew
= intern ("w32-charset-hebrew");
8942 staticpro (&Qw32_charset_vietnamese
);
8943 Qw32_charset_vietnamese
= intern ("w32-charset-vietnamese");
8944 staticpro (&Qw32_charset_thai
);
8945 Qw32_charset_thai
= intern ("w32-charset-thai");
8946 staticpro (&Qw32_charset_mac
);
8947 Qw32_charset_mac
= intern ("w32-charset-mac");
8951 #ifdef UNICODE_CHARSET
8953 static int w32_unicode_charset_defined
= 1;
8954 DEFVAR_BOOL ("w32-unicode-charset-defined",
8955 &w32_unicode_charset_defined
,
8956 doc
: /* Internal variable. */);
8958 staticpro (&Qw32_charset_unicode
);
8959 Qw32_charset_unicode
= intern ("w32-charset-unicode");
8962 #if 0 /* TODO: Port to W32 */
8963 defsubr (&Sx_change_window_property
);
8964 defsubr (&Sx_delete_window_property
);
8965 defsubr (&Sx_window_property
);
8967 defsubr (&Sxw_display_color_p
);
8968 defsubr (&Sx_display_grayscale_p
);
8969 defsubr (&Sxw_color_defined_p
);
8970 defsubr (&Sxw_color_values
);
8971 defsubr (&Sx_server_max_request_size
);
8972 defsubr (&Sx_server_vendor
);
8973 defsubr (&Sx_server_version
);
8974 defsubr (&Sx_display_pixel_width
);
8975 defsubr (&Sx_display_pixel_height
);
8976 defsubr (&Sx_display_mm_width
);
8977 defsubr (&Sx_display_mm_height
);
8978 defsubr (&Sx_display_screens
);
8979 defsubr (&Sx_display_planes
);
8980 defsubr (&Sx_display_color_cells
);
8981 defsubr (&Sx_display_visual_class
);
8982 defsubr (&Sx_display_backing_store
);
8983 defsubr (&Sx_display_save_under
);
8984 defsubr (&Sx_create_frame
);
8985 defsubr (&Sx_open_connection
);
8986 defsubr (&Sx_close_connection
);
8987 defsubr (&Sx_display_list
);
8988 defsubr (&Sx_synchronize
);
8990 /* W32 specific functions */
8992 defsubr (&Sw32_focus_frame
);
8993 defsubr (&Sw32_select_font
);
8994 defsubr (&Sw32_define_rgb_color
);
8995 defsubr (&Sw32_default_color_map
);
8996 defsubr (&Sw32_load_color_file
);
8997 defsubr (&Sw32_send_sys_command
);
8998 defsubr (&Sw32_shell_execute
);
8999 defsubr (&Sw32_register_hot_key
);
9000 defsubr (&Sw32_unregister_hot_key
);
9001 defsubr (&Sw32_registered_hot_keys
);
9002 defsubr (&Sw32_reconstruct_hot_key
);
9003 defsubr (&Sw32_toggle_lock_key
);
9004 defsubr (&Sw32_find_bdf_fonts
);
9006 defsubr (&Sfile_system_info
);
9007 defsubr (&Sdefault_printer_name
);
9009 /* Setting callback functions for fontset handler. */
9010 get_font_info_func
= w32_get_font_info
;
9012 #if 0 /* This function pointer doesn't seem to be used anywhere.
9013 And the pointer assigned has the wrong type, anyway. */
9014 list_fonts_func
= w32_list_fonts
;
9017 load_font_func
= w32_load_font
;
9018 find_ccl_program_func
= w32_find_ccl_program
;
9019 query_font_func
= w32_query_font
;
9020 set_frame_fontset_func
= x_set_font
;
9021 get_font_repertory_func
= x_get_font_repertory
;
9022 check_window_system_func
= check_w32
;
9025 hourglass_atimer
= NULL
;
9026 hourglass_shown_p
= 0;
9027 defsubr (&Sx_show_tip
);
9028 defsubr (&Sx_hide_tip
);
9030 staticpro (&tip_timer
);
9032 staticpro (&tip_frame
);
9034 last_show_tip_args
= Qnil
;
9035 staticpro (&last_show_tip_args
);
9037 defsubr (&Sx_file_dialog
);
9042 globals_of_w32fns is used to initialize those global variables that
9043 must always be initialized on startup even when the global variable
9044 initialized is non zero (see the function main in emacs.c).
9045 globals_of_w32fns is called from syms_of_w32fns when the global
9046 variable initialized is 0 and directly from main when initialized
9049 void globals_of_w32fns ()
9051 HMODULE user32_lib
= GetModuleHandle ("user32.dll");
9053 TrackMouseEvent not available in all versions of Windows, so must load
9054 it dynamically. Do it once, here, instead of every time it is used.
9056 track_mouse_event_fn
= (TrackMouseEvent_Proc
)
9057 GetProcAddress (user32_lib
, "TrackMouseEvent");
9058 /* ditto for GetClipboardSequenceNumber. */
9059 clipboard_sequence_fn
= (ClipboardSequence_Proc
)
9060 GetProcAddress (user32_lib
, "GetClipboardSequenceNumber");
9062 DEFVAR_INT ("w32-ansi-code-page",
9063 &w32_ansi_code_page
,
9064 doc
: /* The ANSI code page used by the system. */);
9065 w32_ansi_code_page
= GetACP ();
9070 void w32_abort (void) NO_RETURN
;
9076 button
= MessageBox (NULL
,
9077 "A fatal error has occurred!\n\n"
9078 "Would you like to attach a debugger?\n\n"
9079 "Select YES to debug, NO to abort Emacs"
9081 "\n\n(type \"gdb -p <emacs-PID>\" and\n"
9082 "\"continue\" inside GDB before clicking YES.)"
9084 , "Emacs Abort Dialog",
9085 MB_ICONEXCLAMATION
| MB_TASKMODAL
9086 | MB_SETFOREGROUND
| MB_YESNO
);
9091 exit (2); /* tell the compiler we will never return */
9099 /* For convenience when debugging. */
9103 return GetLastError ();
9106 /* arch-tag: 707589ab-b9be-4638-8cdd-74629cc9b446
9107 (do not change this comment) */