1 /* Graphical user interface functions for the Microsoft W32 API.
2 Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 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 #ifdef USE_FONT_BACKEND
64 void syms_of_w32fns ();
65 void globals_of_w32fns ();
67 extern void free_frame_menubar ();
68 extern double atof ();
69 extern int w32_console_toggle_lock_key
P_ ((int, Lisp_Object
));
70 extern void w32_menu_display_help
P_ ((HWND
, HMENU
, UINT
, UINT
));
71 extern void w32_free_menu_strings
P_ ((HWND
));
72 extern XCharStruct
*w32_per_char_metric
P_ ((XFontStruct
*, wchar_t *, int));
76 extern char *lispy_function_keys
[];
78 /* The gray bitmap `bitmaps/gray'. This is done because w32term.c uses
79 it, and including `bitmaps/gray' more than once is a problem when
80 config.h defines `static' as an empty replacement string. */
82 int gray_bitmap_width
= gray_width
;
83 int gray_bitmap_height
= gray_height
;
84 unsigned char *gray_bitmap_bits
= gray_bits
;
86 /* The colormap for converting color names to RGB values */
87 Lisp_Object Vw32_color_map
;
89 /* Non nil if alt key presses are passed on to Windows. */
90 Lisp_Object Vw32_pass_alt_to_system
;
92 /* Non nil if alt key is translated to meta_modifier, nil if it is translated
94 Lisp_Object Vw32_alt_is_meta
;
96 /* If non-zero, the windows virtual key code for an alternative quit key. */
99 /* Non nil if left window key events are passed on to Windows (this only
100 affects whether "tapping" the key opens the Start menu). */
101 Lisp_Object Vw32_pass_lwindow_to_system
;
103 /* Non nil if right window key events are passed on to Windows (this
104 only affects whether "tapping" the key opens the Start menu). */
105 Lisp_Object Vw32_pass_rwindow_to_system
;
107 /* Virtual key code used to generate "phantom" key presses in order
108 to stop system from acting on Windows key events. */
109 Lisp_Object Vw32_phantom_key_code
;
111 /* Modifier associated with the left "Windows" key, or nil to act as a
113 Lisp_Object Vw32_lwindow_modifier
;
115 /* Modifier associated with the right "Windows" key, or nil to act as a
117 Lisp_Object Vw32_rwindow_modifier
;
119 /* Modifier associated with the "Apps" key, or nil to act as a normal
121 Lisp_Object Vw32_apps_modifier
;
123 /* Value is nil if Num Lock acts as a function key. */
124 Lisp_Object Vw32_enable_num_lock
;
126 /* Value is nil if Caps Lock acts as a function key. */
127 Lisp_Object Vw32_enable_caps_lock
;
129 /* Modifier associated with Scroll Lock, or nil to act as a normal key. */
130 Lisp_Object Vw32_scroll_lock_modifier
;
132 /* Switch to control whether we inhibit requests for synthesized bold
133 and italic versions of fonts. */
134 int w32_enable_synthesized_fonts
;
136 /* Enable palette management. */
137 Lisp_Object Vw32_enable_palette
;
139 /* Control how close left/right button down events must be to
140 be converted to a middle button down event. */
141 int w32_mouse_button_tolerance
;
143 /* Minimum interval between mouse movement (and scroll bar drag)
144 events that are passed on to the event loop. */
145 int w32_mouse_move_interval
;
147 /* Flag to indicate if XBUTTON events should be passed on to Windows. */
148 int w32_pass_extra_mouse_buttons_to_system
;
150 /* Non nil if no window manager is in use. */
151 Lisp_Object Vx_no_window_manager
;
153 /* Non-zero means we're allowed to display a hourglass pointer. */
155 int display_hourglass_p
;
157 /* The background and shape of the mouse pointer, and shape when not
158 over text or in the modeline. */
160 Lisp_Object Vx_pointer_shape
, Vx_nontext_pointer_shape
, Vx_mode_pointer_shape
;
161 Lisp_Object Vx_hourglass_pointer_shape
, Vx_window_horizontal_drag_shape
;
163 /* The shape when over mouse-sensitive text. */
165 Lisp_Object Vx_sensitive_text_pointer_shape
;
168 #define IDC_HAND MAKEINTRESOURCE(32649)
171 /* Color of chars displayed in cursor box. */
173 Lisp_Object Vx_cursor_fore_pixel
;
175 /* Nonzero if using Windows. */
177 static int w32_in_use
;
179 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
181 Lisp_Object Vx_pixel_size_width_font_regexp
;
183 /* Alist of bdf fonts and the files that define them. */
184 Lisp_Object Vw32_bdf_filename_alist
;
186 /* A flag to control whether fonts are matched strictly or not. */
187 int w32_strict_fontnames
;
189 /* A flag to control whether we should only repaint if GetUpdateRect
190 indicates there is an update region. */
191 int w32_strict_painting
;
193 /* Associative list linking character set strings to Windows codepages. */
194 Lisp_Object Vw32_charset_info_alist
;
196 /* VIETNAMESE_CHARSET is not defined in some versions of MSVC. */
197 #ifndef VIETNAMESE_CHARSET
198 #define VIETNAMESE_CHARSET 163
202 Lisp_Object Qsuppress_icon
;
203 Lisp_Object Qundefined_color
;
204 Lisp_Object Qcancel_timer
;
210 Lisp_Object Qcontrol
;
213 Lisp_Object Qw32_charset_ansi
;
214 Lisp_Object Qw32_charset_default
;
215 Lisp_Object Qw32_charset_symbol
;
216 Lisp_Object Qw32_charset_shiftjis
;
217 Lisp_Object Qw32_charset_hangeul
;
218 Lisp_Object Qw32_charset_gb2312
;
219 Lisp_Object Qw32_charset_chinesebig5
;
220 Lisp_Object Qw32_charset_oem
;
222 #ifndef JOHAB_CHARSET
223 #define JOHAB_CHARSET 130
226 Lisp_Object Qw32_charset_easteurope
;
227 Lisp_Object Qw32_charset_turkish
;
228 Lisp_Object Qw32_charset_baltic
;
229 Lisp_Object Qw32_charset_russian
;
230 Lisp_Object Qw32_charset_arabic
;
231 Lisp_Object Qw32_charset_greek
;
232 Lisp_Object Qw32_charset_hebrew
;
233 Lisp_Object Qw32_charset_vietnamese
;
234 Lisp_Object Qw32_charset_thai
;
235 Lisp_Object Qw32_charset_johab
;
236 Lisp_Object Qw32_charset_mac
;
239 #ifdef UNICODE_CHARSET
240 Lisp_Object Qw32_charset_unicode
;
243 /* The ANSI codepage. */
244 int w32_ansi_code_page
;
246 /* Prefix for system colors. */
247 #define SYSTEM_COLOR_PREFIX "System"
248 #define SYSTEM_COLOR_PREFIX_LEN (sizeof (SYSTEM_COLOR_PREFIX) - 1)
250 /* State variables for emulating a three button mouse. */
255 static int button_state
= 0;
256 static W32Msg saved_mouse_button_msg
;
257 static unsigned mouse_button_timer
= 0; /* non-zero when timer is active */
258 static W32Msg saved_mouse_move_msg
;
259 static unsigned mouse_move_timer
= 0;
261 /* Window that is tracking the mouse. */
262 static HWND track_mouse_window
;
264 typedef BOOL (WINAPI
* TrackMouseEvent_Proc
)
265 (IN OUT LPTRACKMOUSEEVENT lpEventTrack
);
267 TrackMouseEvent_Proc track_mouse_event_fn
= NULL
;
268 ClipboardSequence_Proc clipboard_sequence_fn
= NULL
;
269 extern AppendMenuW_Proc unicode_append_menu
;
271 /* W95 mousewheel handler */
272 unsigned int msh_mousewheel
= 0;
275 #define MOUSE_BUTTON_ID 1
276 #define MOUSE_MOVE_ID 2
277 #define MENU_FREE_ID 3
278 /* The delay (milliseconds) before a menu is freed after WM_EXITMENULOOP
280 #define MENU_FREE_DELAY 1000
281 static unsigned menu_free_timer
= 0;
283 /* The below are defined in frame.c. */
285 extern Lisp_Object Vwindow_system_version
;
288 int image_cache_refcount
, dpyinfo_refcount
;
292 /* From w32term.c. */
293 extern int w32_num_mouse_buttons
;
294 extern Lisp_Object Vw32_recognize_altgr
;
296 extern HWND w32_system_caret_hwnd
;
298 extern int w32_system_caret_height
;
299 extern int w32_system_caret_x
;
300 extern int w32_system_caret_y
;
301 extern int w32_use_visible_system_caret
;
303 static HWND w32_visible_system_caret_hwnd
;
306 extern HMENU current_popup_menu
;
307 static int menubar_in_use
= 0;
310 /* Error if we are not connected to MS-Windows. */
315 error ("MS-Windows not in use or not initialized");
318 /* Nonzero if we can use mouse menus.
319 You should not call this unless HAVE_MENUS is defined. */
327 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
328 and checking validity for W32. */
331 check_x_frame (frame
)
337 frame
= selected_frame
;
338 CHECK_LIVE_FRAME (frame
);
340 if (! FRAME_W32_P (f
))
341 error ("Non-W32 frame used");
345 /* Let the user specify a display with a frame.
346 nil stands for the selected frame--or, if that is not a w32 frame,
347 the first display on the list. */
349 struct w32_display_info
*
350 check_x_display_info (frame
)
355 struct frame
*sf
= XFRAME (selected_frame
);
357 if (FRAME_W32_P (sf
) && FRAME_LIVE_P (sf
))
358 return FRAME_W32_DISPLAY_INFO (sf
);
360 return &one_w32_display_info
;
362 else if (STRINGP (frame
))
363 return x_display_info_for_name (frame
);
368 CHECK_LIVE_FRAME (frame
);
370 if (! FRAME_W32_P (f
))
371 error ("Non-W32 frame used");
372 return FRAME_W32_DISPLAY_INFO (f
);
376 /* Return the Emacs frame-object corresponding to an w32 window.
377 It could be the frame's main window or an icon window. */
379 /* This function can be called during GC, so use GC_xxx type test macros. */
382 x_window_to_frame (dpyinfo
, wdesc
)
383 struct w32_display_info
*dpyinfo
;
386 Lisp_Object tail
, frame
;
389 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
392 if (!GC_FRAMEP (frame
))
395 if (!FRAME_W32_P (f
) || FRAME_W32_DISPLAY_INFO (f
) != dpyinfo
)
397 if (f
->output_data
.w32
->hourglass_window
== wdesc
)
400 if (FRAME_W32_WINDOW (f
) == wdesc
)
407 static Lisp_Object unwind_create_frame
P_ ((Lisp_Object
));
408 static Lisp_Object unwind_create_tip_frame
P_ ((Lisp_Object
));
409 static void my_create_window
P_ ((struct frame
*));
410 static void my_create_tip_window
P_ ((struct frame
*));
412 /* TODO: Native Input Method support; see x_create_im. */
413 void x_set_foreground_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
414 void x_set_background_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
415 void x_set_mouse_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
416 void x_set_cursor_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
417 void x_set_border_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
418 void x_set_cursor_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
419 void x_set_icon_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
420 void x_set_icon_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
421 void x_explicitly_set_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
422 void x_set_menu_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
423 void x_set_title
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
424 void x_set_tool_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
425 static void x_edge_detection
P_ ((struct frame
*, struct image
*, Lisp_Object
,
431 /* Store the screen positions of frame F into XPTR and YPTR.
432 These are the positions of the containing window manager window,
433 not Emacs's own window. */
436 x_real_positions (f
, xptr
, yptr
)
443 GetClientRect(FRAME_W32_WINDOW(f
), &rect
);
444 AdjustWindowRect(&rect
, f
->output_data
.w32
->dwStyle
, FRAME_EXTERNAL_MENU_BAR(f
));
449 ClientToScreen (FRAME_W32_WINDOW(f
), &pt
);
451 /* Remember x_pixels_diff and y_pixels_diff. */
452 f
->x_pixels_diff
= pt
.x
- rect
.left
;
453 f
->y_pixels_diff
= pt
.y
- rect
.top
;
461 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
,
462 Sw32_define_rgb_color
, 4, 4, 0,
463 doc
: /* Convert RGB numbers to a windows color reference and associate with NAME.
464 This adds or updates a named color to w32-color-map, making it
465 available for use. The original entry's RGB ref is returned, or nil
466 if the entry is new. */)
467 (red
, green
, blue
, name
)
468 Lisp_Object red
, green
, blue
, name
;
471 Lisp_Object oldrgb
= Qnil
;
475 CHECK_NUMBER (green
);
479 XSETINT (rgb
, RGB(XUINT (red
), XUINT (green
), XUINT (blue
)));
483 /* replace existing entry in w32-color-map or add new entry. */
484 entry
= Fassoc (name
, Vw32_color_map
);
487 entry
= Fcons (name
, rgb
);
488 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
492 oldrgb
= Fcdr (entry
);
493 Fsetcdr (entry
, rgb
);
501 DEFUN ("w32-load-color-file", Fw32_load_color_file
,
502 Sw32_load_color_file
, 1, 1, 0,
503 doc
: /* Create an alist of color entries from an external file.
504 Assign this value to w32-color-map to replace the existing color map.
506 The file should define one named RGB color per line like so:
508 where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
510 Lisp_Object filename
;
513 Lisp_Object cmap
= Qnil
;
516 CHECK_STRING (filename
);
517 abspath
= Fexpand_file_name (filename
, Qnil
);
519 fp
= fopen (SDATA (filename
), "rt");
523 int red
, green
, blue
;
528 while (fgets (buf
, sizeof (buf
), fp
) != NULL
) {
529 if (sscanf (buf
, "%u %u %u %n", &red
, &green
, &blue
, &num
) == 3)
531 char *name
= buf
+ num
;
532 num
= strlen (name
) - 1;
533 if (name
[num
] == '\n')
535 cmap
= Fcons (Fcons (build_string (name
),
536 make_number (RGB (red
, green
, blue
))),
548 /* The default colors for the w32 color map */
549 typedef struct colormap_t
555 colormap_t w32_color_map
[] =
557 {"snow" , PALETTERGB (255,250,250)},
558 {"ghost white" , PALETTERGB (248,248,255)},
559 {"GhostWhite" , PALETTERGB (248,248,255)},
560 {"white smoke" , PALETTERGB (245,245,245)},
561 {"WhiteSmoke" , PALETTERGB (245,245,245)},
562 {"gainsboro" , PALETTERGB (220,220,220)},
563 {"floral white" , PALETTERGB (255,250,240)},
564 {"FloralWhite" , PALETTERGB (255,250,240)},
565 {"old lace" , PALETTERGB (253,245,230)},
566 {"OldLace" , PALETTERGB (253,245,230)},
567 {"linen" , PALETTERGB (250,240,230)},
568 {"antique white" , PALETTERGB (250,235,215)},
569 {"AntiqueWhite" , PALETTERGB (250,235,215)},
570 {"papaya whip" , PALETTERGB (255,239,213)},
571 {"PapayaWhip" , PALETTERGB (255,239,213)},
572 {"blanched almond" , PALETTERGB (255,235,205)},
573 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
574 {"bisque" , PALETTERGB (255,228,196)},
575 {"peach puff" , PALETTERGB (255,218,185)},
576 {"PeachPuff" , PALETTERGB (255,218,185)},
577 {"navajo white" , PALETTERGB (255,222,173)},
578 {"NavajoWhite" , PALETTERGB (255,222,173)},
579 {"moccasin" , PALETTERGB (255,228,181)},
580 {"cornsilk" , PALETTERGB (255,248,220)},
581 {"ivory" , PALETTERGB (255,255,240)},
582 {"lemon chiffon" , PALETTERGB (255,250,205)},
583 {"LemonChiffon" , PALETTERGB (255,250,205)},
584 {"seashell" , PALETTERGB (255,245,238)},
585 {"honeydew" , PALETTERGB (240,255,240)},
586 {"mint cream" , PALETTERGB (245,255,250)},
587 {"MintCream" , PALETTERGB (245,255,250)},
588 {"azure" , PALETTERGB (240,255,255)},
589 {"alice blue" , PALETTERGB (240,248,255)},
590 {"AliceBlue" , PALETTERGB (240,248,255)},
591 {"lavender" , PALETTERGB (230,230,250)},
592 {"lavender blush" , PALETTERGB (255,240,245)},
593 {"LavenderBlush" , PALETTERGB (255,240,245)},
594 {"misty rose" , PALETTERGB (255,228,225)},
595 {"MistyRose" , PALETTERGB (255,228,225)},
596 {"white" , PALETTERGB (255,255,255)},
597 {"black" , PALETTERGB ( 0, 0, 0)},
598 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
599 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
600 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
601 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
602 {"dim gray" , PALETTERGB (105,105,105)},
603 {"DimGray" , PALETTERGB (105,105,105)},
604 {"dim grey" , PALETTERGB (105,105,105)},
605 {"DimGrey" , PALETTERGB (105,105,105)},
606 {"slate gray" , PALETTERGB (112,128,144)},
607 {"SlateGray" , PALETTERGB (112,128,144)},
608 {"slate grey" , PALETTERGB (112,128,144)},
609 {"SlateGrey" , PALETTERGB (112,128,144)},
610 {"light slate gray" , PALETTERGB (119,136,153)},
611 {"LightSlateGray" , PALETTERGB (119,136,153)},
612 {"light slate grey" , PALETTERGB (119,136,153)},
613 {"LightSlateGrey" , PALETTERGB (119,136,153)},
614 {"gray" , PALETTERGB (190,190,190)},
615 {"grey" , PALETTERGB (190,190,190)},
616 {"light grey" , PALETTERGB (211,211,211)},
617 {"LightGrey" , PALETTERGB (211,211,211)},
618 {"light gray" , PALETTERGB (211,211,211)},
619 {"LightGray" , PALETTERGB (211,211,211)},
620 {"midnight blue" , PALETTERGB ( 25, 25,112)},
621 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
622 {"navy" , PALETTERGB ( 0, 0,128)},
623 {"navy blue" , PALETTERGB ( 0, 0,128)},
624 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
625 {"cornflower blue" , PALETTERGB (100,149,237)},
626 {"CornflowerBlue" , PALETTERGB (100,149,237)},
627 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
628 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
629 {"slate blue" , PALETTERGB (106, 90,205)},
630 {"SlateBlue" , PALETTERGB (106, 90,205)},
631 {"medium slate blue" , PALETTERGB (123,104,238)},
632 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
633 {"light slate blue" , PALETTERGB (132,112,255)},
634 {"LightSlateBlue" , PALETTERGB (132,112,255)},
635 {"medium blue" , PALETTERGB ( 0, 0,205)},
636 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
637 {"royal blue" , PALETTERGB ( 65,105,225)},
638 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
639 {"blue" , PALETTERGB ( 0, 0,255)},
640 {"dodger blue" , PALETTERGB ( 30,144,255)},
641 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
642 {"deep sky blue" , PALETTERGB ( 0,191,255)},
643 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
644 {"sky blue" , PALETTERGB (135,206,235)},
645 {"SkyBlue" , PALETTERGB (135,206,235)},
646 {"light sky blue" , PALETTERGB (135,206,250)},
647 {"LightSkyBlue" , PALETTERGB (135,206,250)},
648 {"steel blue" , PALETTERGB ( 70,130,180)},
649 {"SteelBlue" , PALETTERGB ( 70,130,180)},
650 {"light steel blue" , PALETTERGB (176,196,222)},
651 {"LightSteelBlue" , PALETTERGB (176,196,222)},
652 {"light blue" , PALETTERGB (173,216,230)},
653 {"LightBlue" , PALETTERGB (173,216,230)},
654 {"powder blue" , PALETTERGB (176,224,230)},
655 {"PowderBlue" , PALETTERGB (176,224,230)},
656 {"pale turquoise" , PALETTERGB (175,238,238)},
657 {"PaleTurquoise" , PALETTERGB (175,238,238)},
658 {"dark turquoise" , PALETTERGB ( 0,206,209)},
659 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
660 {"medium turquoise" , PALETTERGB ( 72,209,204)},
661 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
662 {"turquoise" , PALETTERGB ( 64,224,208)},
663 {"cyan" , PALETTERGB ( 0,255,255)},
664 {"light cyan" , PALETTERGB (224,255,255)},
665 {"LightCyan" , PALETTERGB (224,255,255)},
666 {"cadet blue" , PALETTERGB ( 95,158,160)},
667 {"CadetBlue" , PALETTERGB ( 95,158,160)},
668 {"medium aquamarine" , PALETTERGB (102,205,170)},
669 {"MediumAquamarine" , PALETTERGB (102,205,170)},
670 {"aquamarine" , PALETTERGB (127,255,212)},
671 {"dark green" , PALETTERGB ( 0,100, 0)},
672 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
673 {"dark olive green" , PALETTERGB ( 85,107, 47)},
674 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
675 {"dark sea green" , PALETTERGB (143,188,143)},
676 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
677 {"sea green" , PALETTERGB ( 46,139, 87)},
678 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
679 {"medium sea green" , PALETTERGB ( 60,179,113)},
680 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
681 {"light sea green" , PALETTERGB ( 32,178,170)},
682 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
683 {"pale green" , PALETTERGB (152,251,152)},
684 {"PaleGreen" , PALETTERGB (152,251,152)},
685 {"spring green" , PALETTERGB ( 0,255,127)},
686 {"SpringGreen" , PALETTERGB ( 0,255,127)},
687 {"lawn green" , PALETTERGB (124,252, 0)},
688 {"LawnGreen" , PALETTERGB (124,252, 0)},
689 {"green" , PALETTERGB ( 0,255, 0)},
690 {"chartreuse" , PALETTERGB (127,255, 0)},
691 {"medium spring green" , PALETTERGB ( 0,250,154)},
692 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
693 {"green yellow" , PALETTERGB (173,255, 47)},
694 {"GreenYellow" , PALETTERGB (173,255, 47)},
695 {"lime green" , PALETTERGB ( 50,205, 50)},
696 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
697 {"yellow green" , PALETTERGB (154,205, 50)},
698 {"YellowGreen" , PALETTERGB (154,205, 50)},
699 {"forest green" , PALETTERGB ( 34,139, 34)},
700 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
701 {"olive drab" , PALETTERGB (107,142, 35)},
702 {"OliveDrab" , PALETTERGB (107,142, 35)},
703 {"dark khaki" , PALETTERGB (189,183,107)},
704 {"DarkKhaki" , PALETTERGB (189,183,107)},
705 {"khaki" , PALETTERGB (240,230,140)},
706 {"pale goldenrod" , PALETTERGB (238,232,170)},
707 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
708 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
709 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
710 {"light yellow" , PALETTERGB (255,255,224)},
711 {"LightYellow" , PALETTERGB (255,255,224)},
712 {"yellow" , PALETTERGB (255,255, 0)},
713 {"gold" , PALETTERGB (255,215, 0)},
714 {"light goldenrod" , PALETTERGB (238,221,130)},
715 {"LightGoldenrod" , PALETTERGB (238,221,130)},
716 {"goldenrod" , PALETTERGB (218,165, 32)},
717 {"dark goldenrod" , PALETTERGB (184,134, 11)},
718 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
719 {"rosy brown" , PALETTERGB (188,143,143)},
720 {"RosyBrown" , PALETTERGB (188,143,143)},
721 {"indian red" , PALETTERGB (205, 92, 92)},
722 {"IndianRed" , PALETTERGB (205, 92, 92)},
723 {"saddle brown" , PALETTERGB (139, 69, 19)},
724 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
725 {"sienna" , PALETTERGB (160, 82, 45)},
726 {"peru" , PALETTERGB (205,133, 63)},
727 {"burlywood" , PALETTERGB (222,184,135)},
728 {"beige" , PALETTERGB (245,245,220)},
729 {"wheat" , PALETTERGB (245,222,179)},
730 {"sandy brown" , PALETTERGB (244,164, 96)},
731 {"SandyBrown" , PALETTERGB (244,164, 96)},
732 {"tan" , PALETTERGB (210,180,140)},
733 {"chocolate" , PALETTERGB (210,105, 30)},
734 {"firebrick" , PALETTERGB (178,34, 34)},
735 {"brown" , PALETTERGB (165,42, 42)},
736 {"dark salmon" , PALETTERGB (233,150,122)},
737 {"DarkSalmon" , PALETTERGB (233,150,122)},
738 {"salmon" , PALETTERGB (250,128,114)},
739 {"light salmon" , PALETTERGB (255,160,122)},
740 {"LightSalmon" , PALETTERGB (255,160,122)},
741 {"orange" , PALETTERGB (255,165, 0)},
742 {"dark orange" , PALETTERGB (255,140, 0)},
743 {"DarkOrange" , PALETTERGB (255,140, 0)},
744 {"coral" , PALETTERGB (255,127, 80)},
745 {"light coral" , PALETTERGB (240,128,128)},
746 {"LightCoral" , PALETTERGB (240,128,128)},
747 {"tomato" , PALETTERGB (255, 99, 71)},
748 {"orange red" , PALETTERGB (255, 69, 0)},
749 {"OrangeRed" , PALETTERGB (255, 69, 0)},
750 {"red" , PALETTERGB (255, 0, 0)},
751 {"hot pink" , PALETTERGB (255,105,180)},
752 {"HotPink" , PALETTERGB (255,105,180)},
753 {"deep pink" , PALETTERGB (255, 20,147)},
754 {"DeepPink" , PALETTERGB (255, 20,147)},
755 {"pink" , PALETTERGB (255,192,203)},
756 {"light pink" , PALETTERGB (255,182,193)},
757 {"LightPink" , PALETTERGB (255,182,193)},
758 {"pale violet red" , PALETTERGB (219,112,147)},
759 {"PaleVioletRed" , PALETTERGB (219,112,147)},
760 {"maroon" , PALETTERGB (176, 48, 96)},
761 {"medium violet red" , PALETTERGB (199, 21,133)},
762 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
763 {"violet red" , PALETTERGB (208, 32,144)},
764 {"VioletRed" , PALETTERGB (208, 32,144)},
765 {"magenta" , PALETTERGB (255, 0,255)},
766 {"violet" , PALETTERGB (238,130,238)},
767 {"plum" , PALETTERGB (221,160,221)},
768 {"orchid" , PALETTERGB (218,112,214)},
769 {"medium orchid" , PALETTERGB (186, 85,211)},
770 {"MediumOrchid" , PALETTERGB (186, 85,211)},
771 {"dark orchid" , PALETTERGB (153, 50,204)},
772 {"DarkOrchid" , PALETTERGB (153, 50,204)},
773 {"dark violet" , PALETTERGB (148, 0,211)},
774 {"DarkViolet" , PALETTERGB (148, 0,211)},
775 {"blue violet" , PALETTERGB (138, 43,226)},
776 {"BlueViolet" , PALETTERGB (138, 43,226)},
777 {"purple" , PALETTERGB (160, 32,240)},
778 {"medium purple" , PALETTERGB (147,112,219)},
779 {"MediumPurple" , PALETTERGB (147,112,219)},
780 {"thistle" , PALETTERGB (216,191,216)},
781 {"gray0" , PALETTERGB ( 0, 0, 0)},
782 {"grey0" , PALETTERGB ( 0, 0, 0)},
783 {"dark grey" , PALETTERGB (169,169,169)},
784 {"DarkGrey" , PALETTERGB (169,169,169)},
785 {"dark gray" , PALETTERGB (169,169,169)},
786 {"DarkGray" , PALETTERGB (169,169,169)},
787 {"dark blue" , PALETTERGB ( 0, 0,139)},
788 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
789 {"dark cyan" , PALETTERGB ( 0,139,139)},
790 {"DarkCyan" , PALETTERGB ( 0,139,139)},
791 {"dark magenta" , PALETTERGB (139, 0,139)},
792 {"DarkMagenta" , PALETTERGB (139, 0,139)},
793 {"dark red" , PALETTERGB (139, 0, 0)},
794 {"DarkRed" , PALETTERGB (139, 0, 0)},
795 {"light green" , PALETTERGB (144,238,144)},
796 {"LightGreen" , PALETTERGB (144,238,144)},
799 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
800 0, 0, 0, doc
: /* Return the default color map. */)
804 colormap_t
*pc
= w32_color_map
;
811 for (i
= 0; i
< sizeof (w32_color_map
) / sizeof (w32_color_map
[0]);
813 cmap
= Fcons (Fcons (build_string (pc
->name
),
814 make_number (pc
->colorref
)),
832 color
= Frassq (rgb
, Vw32_color_map
);
837 return (Fcar (color
));
843 w32_color_map_lookup (colorname
)
846 Lisp_Object tail
, ret
= Qnil
;
850 for (tail
= Vw32_color_map
; !NILP (tail
); tail
= Fcdr (tail
))
852 register Lisp_Object elt
, tem
;
855 if (!CONSP (elt
)) continue;
859 if (lstrcmpi (SDATA (tem
), colorname
) == 0)
876 add_system_logical_colors_to_map (system_colors
)
877 Lisp_Object
*system_colors
;
881 /* Other registry operations are done with input blocked. */
884 /* Look for "Control Panel/Colors" under User and Machine registry
886 if (RegOpenKeyEx (HKEY_CURRENT_USER
, "Control Panel\\Colors", 0,
887 KEY_READ
, &colors_key
) == ERROR_SUCCESS
888 || RegOpenKeyEx (HKEY_LOCAL_MACHINE
, "Control Panel\\Colors", 0,
889 KEY_READ
, &colors_key
) == ERROR_SUCCESS
)
892 char color_buffer
[64];
893 char full_name_buffer
[MAX_PATH
+ SYSTEM_COLOR_PREFIX_LEN
];
895 DWORD name_size
, color_size
;
896 char *name_buffer
= full_name_buffer
+ SYSTEM_COLOR_PREFIX_LEN
;
898 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
899 color_size
= sizeof (color_buffer
);
901 strcpy (full_name_buffer
, SYSTEM_COLOR_PREFIX
);
903 while (RegEnumValueA (colors_key
, index
, name_buffer
, &name_size
,
904 NULL
, NULL
, color_buffer
, &color_size
)
908 if (sscanf (color_buffer
, " %u %u %u", &r
, &g
, &b
) == 3)
909 *system_colors
= Fcons (Fcons (build_string (full_name_buffer
),
910 make_number (RGB (r
, g
, b
))),
913 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
914 color_size
= sizeof (color_buffer
);
917 RegCloseKey (colors_key
);
925 x_to_w32_color (colorname
)
928 register Lisp_Object ret
= Qnil
;
932 if (colorname
[0] == '#')
934 /* Could be an old-style RGB Device specification. */
937 color
= colorname
+ 1;
939 size
= strlen(color
);
940 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
948 for (i
= 0; i
< 3; i
++)
954 /* The check for 'x' in the following conditional takes into
955 account the fact that strtol allows a "0x" in front of
956 our numbers, and we don't. */
957 if (!isxdigit(color
[0]) || color
[1] == 'x')
961 value
= strtoul(color
, &end
, 16);
963 if (errno
== ERANGE
|| end
- color
!= size
)
968 value
= value
* 0x10;
979 colorval
|= (value
<< pos
);
984 XSETINT (ret
, colorval
);
991 else if (strnicmp(colorname
, "rgb:", 4) == 0)
999 color
= colorname
+ 4;
1000 for (i
= 0; i
< 3; i
++)
1003 unsigned long value
;
1005 /* The check for 'x' in the following conditional takes into
1006 account the fact that strtol allows a "0x" in front of
1007 our numbers, and we don't. */
1008 if (!isxdigit(color
[0]) || color
[1] == 'x')
1010 value
= strtoul(color
, &end
, 16);
1011 if (errno
== ERANGE
)
1013 switch (end
- color
)
1016 value
= value
* 0x10 + value
;
1029 if (value
== ULONG_MAX
)
1031 colorval
|= (value
<< pos
);
1038 XSETINT (ret
, colorval
);
1046 else if (strnicmp(colorname
, "rgbi:", 5) == 0)
1048 /* This is an RGB Intensity specification. */
1055 color
= colorname
+ 5;
1056 for (i
= 0; i
< 3; i
++)
1062 value
= strtod(color
, &end
);
1063 if (errno
== ERANGE
)
1065 if (value
< 0.0 || value
> 1.0)
1067 val
= (UINT
)(0x100 * value
);
1068 /* We used 0x100 instead of 0xFF to give a continuous
1069 range between 0.0 and 1.0 inclusive. The next statement
1070 fixes the 1.0 case. */
1073 colorval
|= (val
<< pos
);
1080 XSETINT (ret
, colorval
);
1088 /* I am not going to attempt to handle any of the CIE color schemes
1089 or TekHVC, since I don't know the algorithms for conversion to
1092 /* If we fail to lookup the color name in w32_color_map, then check the
1093 colorname to see if it can be crudely approximated: If the X color
1094 ends in a number (e.g., "darkseagreen2"), strip the number and
1095 return the result of looking up the base color name. */
1096 ret
= w32_color_map_lookup (colorname
);
1099 int len
= strlen (colorname
);
1101 if (isdigit (colorname
[len
- 1]))
1103 char *ptr
, *approx
= alloca (len
+ 1);
1105 strcpy (approx
, colorname
);
1106 ptr
= &approx
[len
- 1];
1107 while (ptr
> approx
&& isdigit (*ptr
))
1110 ret
= w32_color_map_lookup (approx
);
1119 w32_regenerate_palette (FRAME_PTR f
)
1121 struct w32_palette_entry
* list
;
1122 LOGPALETTE
* log_palette
;
1123 HPALETTE new_palette
;
1126 /* don't bother trying to create palette if not supported */
1127 if (! FRAME_W32_DISPLAY_INFO (f
)->has_palette
)
1130 log_palette
= (LOGPALETTE
*)
1131 alloca (sizeof (LOGPALETTE
) +
1132 FRAME_W32_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
1133 log_palette
->palVersion
= 0x300;
1134 log_palette
->palNumEntries
= FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1136 list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1138 i
< FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1139 i
++, list
= list
->next
)
1140 log_palette
->palPalEntry
[i
] = list
->entry
;
1142 new_palette
= CreatePalette (log_palette
);
1146 if (FRAME_W32_DISPLAY_INFO (f
)->palette
)
1147 DeleteObject (FRAME_W32_DISPLAY_INFO (f
)->palette
);
1148 FRAME_W32_DISPLAY_INFO (f
)->palette
= new_palette
;
1150 /* Realize display palette and garbage all frames. */
1151 release_frame_dc (f
, get_frame_dc (f
));
1156 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
1157 #define SET_W32_COLOR(pe, color) \
1160 pe.peRed = GetRValue (color); \
1161 pe.peGreen = GetGValue (color); \
1162 pe.peBlue = GetBValue (color); \
1167 /* Keep these around in case we ever want to track color usage. */
1169 w32_map_color (FRAME_PTR f
, COLORREF color
)
1171 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1173 if (NILP (Vw32_enable_palette
))
1176 /* check if color is already mapped */
1179 if (W32_COLOR (list
->entry
) == color
)
1187 /* not already mapped, so add to list and recreate Windows palette */
1188 list
= (struct w32_palette_entry
*)
1189 xmalloc (sizeof (struct w32_palette_entry
));
1190 SET_W32_COLOR (list
->entry
, color
);
1192 list
->next
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1193 FRAME_W32_DISPLAY_INFO (f
)->color_list
= list
;
1194 FRAME_W32_DISPLAY_INFO (f
)->num_colors
++;
1196 /* set flag that palette must be regenerated */
1197 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1201 w32_unmap_color (FRAME_PTR f
, COLORREF color
)
1203 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1204 struct w32_palette_entry
**prev
= &FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1206 if (NILP (Vw32_enable_palette
))
1209 /* check if color is already mapped */
1212 if (W32_COLOR (list
->entry
) == color
)
1214 if (--list
->refcount
== 0)
1218 FRAME_W32_DISPLAY_INFO (f
)->num_colors
--;
1228 /* set flag that palette must be regenerated */
1229 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1234 /* Gamma-correct COLOR on frame F. */
1237 gamma_correct (f
, color
)
1243 *color
= PALETTERGB (
1244 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1245 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1246 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1251 /* Decide if color named COLOR is valid for the display associated with
1252 the selected frame; if so, return the rgb values in COLOR_DEF.
1253 If ALLOC is nonzero, allocate a new colormap cell. */
1256 w32_defined_color (f
, color
, color_def
, alloc
)
1262 register Lisp_Object tem
;
1263 COLORREF w32_color_ref
;
1265 tem
= x_to_w32_color (color
);
1271 /* Apply gamma correction. */
1272 w32_color_ref
= XUINT (tem
);
1273 gamma_correct (f
, &w32_color_ref
);
1274 XSETINT (tem
, w32_color_ref
);
1277 /* Map this color to the palette if it is enabled. */
1278 if (!NILP (Vw32_enable_palette
))
1280 struct w32_palette_entry
* entry
=
1281 one_w32_display_info
.color_list
;
1282 struct w32_palette_entry
** prev
=
1283 &one_w32_display_info
.color_list
;
1285 /* check if color is already mapped */
1288 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1290 prev
= &entry
->next
;
1291 entry
= entry
->next
;
1294 if (entry
== NULL
&& alloc
)
1296 /* not already mapped, so add to list */
1297 entry
= (struct w32_palette_entry
*)
1298 xmalloc (sizeof (struct w32_palette_entry
));
1299 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1302 one_w32_display_info
.num_colors
++;
1304 /* set flag that palette must be regenerated */
1305 one_w32_display_info
.regen_palette
= TRUE
;
1308 /* Ensure COLORREF value is snapped to nearest color in (default)
1309 palette by simulating the PALETTERGB macro. This works whether
1310 or not the display device has a palette. */
1311 w32_color_ref
= XUINT (tem
) | 0x2000000;
1313 color_def
->pixel
= w32_color_ref
;
1314 color_def
->red
= GetRValue (w32_color_ref
) * 256;
1315 color_def
->green
= GetGValue (w32_color_ref
) * 256;
1316 color_def
->blue
= GetBValue (w32_color_ref
) * 256;
1326 /* Given a string ARG naming a color, compute a pixel value from it
1327 suitable for screen F.
1328 If F is not a color screen, return DEF (default) regardless of what
1332 x_decode_color (f
, arg
, def
)
1341 if (strcmp (SDATA (arg
), "black") == 0)
1342 return BLACK_PIX_DEFAULT (f
);
1343 else if (strcmp (SDATA (arg
), "white") == 0)
1344 return WHITE_PIX_DEFAULT (f
);
1346 if ((FRAME_W32_DISPLAY_INFO (f
)->n_planes
* FRAME_W32_DISPLAY_INFO (f
)->n_cbits
) == 1)
1349 /* w32_defined_color is responsible for coping with failures
1350 by looking for a near-miss. */
1351 if (w32_defined_color (f
, SDATA (arg
), &cdef
, 1))
1354 /* defined_color failed; return an ultimate default. */
1360 /* Functions called only from `x_set_frame_param'
1361 to set individual parameters.
1363 If FRAME_W32_WINDOW (f) is 0,
1364 the frame is being created and its window does not exist yet.
1365 In that case, just record the parameter's new value
1366 in the standard place; do not attempt to change the window. */
1369 x_set_foreground_color (f
, arg
, oldval
)
1371 Lisp_Object arg
, oldval
;
1373 struct w32_output
*x
= f
->output_data
.w32
;
1374 PIX_TYPE fg
, old_fg
;
1376 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1377 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
1378 FRAME_FOREGROUND_PIXEL (f
) = fg
;
1380 if (FRAME_W32_WINDOW (f
) != 0)
1382 if (x
->cursor_pixel
== old_fg
)
1383 x
->cursor_pixel
= fg
;
1385 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
1386 if (FRAME_VISIBLE_P (f
))
1392 x_set_background_color (f
, arg
, oldval
)
1394 Lisp_Object arg
, oldval
;
1396 FRAME_BACKGROUND_PIXEL (f
)
1397 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
1399 if (FRAME_W32_WINDOW (f
) != 0)
1401 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
1402 FRAME_BACKGROUND_PIXEL (f
));
1404 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
1406 if (FRAME_VISIBLE_P (f
))
1412 x_set_mouse_color (f
, arg
, oldval
)
1414 Lisp_Object arg
, oldval
;
1416 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
1420 if (!EQ (Qnil
, arg
))
1421 f
->output_data
.w32
->mouse_pixel
1422 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1423 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
1425 /* Don't let pointers be invisible. */
1426 if (mask_color
== f
->output_data
.w32
->mouse_pixel
1427 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
1428 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
1430 #if 0 /* TODO : cursor changes */
1433 /* It's not okay to crash if the user selects a screwy cursor. */
1434 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
1436 if (!EQ (Qnil
, Vx_pointer_shape
))
1438 CHECK_NUMBER (Vx_pointer_shape
);
1439 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
1442 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1443 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
1445 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
1447 CHECK_NUMBER (Vx_nontext_pointer_shape
);
1448 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1449 XINT (Vx_nontext_pointer_shape
));
1452 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
1453 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1455 if (!EQ (Qnil
, Vx_hourglass_pointer_shape
))
1457 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
1458 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1459 XINT (Vx_hourglass_pointer_shape
));
1462 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
1463 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
1465 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1466 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
1468 CHECK_NUMBER (Vx_mode_pointer_shape
);
1469 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1470 XINT (Vx_mode_pointer_shape
));
1473 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1474 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
1476 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
1478 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
1480 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1481 XINT (Vx_sensitive_text_pointer_shape
));
1484 hand_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
1486 if (!NILP (Vx_window_horizontal_drag_shape
))
1488 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
1489 horizontal_drag_cursor
1490 = XCreateFontCursor (FRAME_X_DISPLAY (f
),
1491 XINT (Vx_window_horizontal_drag_shape
));
1494 horizontal_drag_cursor
1495 = XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_sb_h_double_arrow
);
1497 /* Check and report errors with the above calls. */
1498 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
1499 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
1502 XColor fore_color
, back_color
;
1504 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
1505 back_color
.pixel
= mask_color
;
1506 XQueryColor (FRAME_W32_DISPLAY (f
),
1507 DefaultColormap (FRAME_W32_DISPLAY (f
),
1508 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1510 XQueryColor (FRAME_W32_DISPLAY (f
),
1511 DefaultColormap (FRAME_W32_DISPLAY (f
),
1512 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1514 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
1515 &fore_color
, &back_color
);
1516 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
1517 &fore_color
, &back_color
);
1518 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
1519 &fore_color
, &back_color
);
1520 XRecolorCursor (FRAME_W32_DISPLAY (f
), hand_cursor
,
1521 &fore_color
, &back_color
);
1522 XRecolorCursor (FRAME_W32_DISPLAY (f
), hourglass_cursor
,
1523 &fore_color
, &back_color
);
1526 if (FRAME_W32_WINDOW (f
) != 0)
1527 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
1529 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
1530 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
1531 f
->output_data
.w32
->text_cursor
= cursor
;
1533 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
1534 && f
->output_data
.w32
->nontext_cursor
!= 0)
1535 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
1536 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
1538 if (hourglass_cursor
!= f
->output_data
.w32
->hourglass_cursor
1539 && f
->output_data
.w32
->hourglass_cursor
!= 0)
1540 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hourglass_cursor
);
1541 f
->output_data
.w32
->hourglass_cursor
= hourglass_cursor
;
1543 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
1544 && f
->output_data
.w32
->modeline_cursor
!= 0)
1545 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
1546 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
1548 if (hand_cursor
!= f
->output_data
.w32
->hand_cursor
1549 && f
->output_data
.w32
->hand_cursor
!= 0)
1550 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hand_cursor
);
1551 f
->output_data
.w32
->hand_cursor
= hand_cursor
;
1553 XFlush (FRAME_W32_DISPLAY (f
));
1556 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1560 /* Defined in w32term.c. */
1562 x_set_cursor_color (f
, arg
, oldval
)
1564 Lisp_Object arg
, oldval
;
1566 unsigned long fore_pixel
, pixel
;
1568 if (!NILP (Vx_cursor_fore_pixel
))
1569 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1570 WHITE_PIX_DEFAULT (f
));
1572 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1574 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1576 /* Make sure that the cursor color differs from the background color. */
1577 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
1579 pixel
= f
->output_data
.w32
->mouse_pixel
;
1580 if (pixel
== fore_pixel
)
1581 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1584 f
->output_data
.w32
->cursor_foreground_pixel
= fore_pixel
;
1585 f
->output_data
.w32
->cursor_pixel
= pixel
;
1587 if (FRAME_W32_WINDOW (f
) != 0)
1590 /* Update frame's cursor_gc. */
1591 f
->output_data
.w32
->cursor_gc
->foreground
= fore_pixel
;
1592 f
->output_data
.w32
->cursor_gc
->background
= pixel
;
1596 if (FRAME_VISIBLE_P (f
))
1598 x_update_cursor (f
, 0);
1599 x_update_cursor (f
, 1);
1603 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1606 /* Set the border-color of frame F to pixel value PIX.
1607 Note that this does not fully take effect if done before
1611 x_set_border_pixel (f
, pix
)
1616 f
->output_data
.w32
->border_pixel
= pix
;
1618 if (FRAME_W32_WINDOW (f
) != 0 && f
->border_width
> 0)
1620 if (FRAME_VISIBLE_P (f
))
1625 /* Set the border-color of frame F to value described by ARG.
1626 ARG can be a string naming a color.
1627 The border-color is used for the border that is drawn by the server.
1628 Note that this does not fully take effect if done before
1629 F has a window; it must be redone when the window is created. */
1632 x_set_border_color (f
, arg
, oldval
)
1634 Lisp_Object arg
, oldval
;
1639 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1640 x_set_border_pixel (f
, pix
);
1641 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1646 x_set_cursor_type (f
, arg
, oldval
)
1648 Lisp_Object arg
, oldval
;
1650 set_frame_cursor_types (f
, arg
);
1652 /* Make sure the cursor gets redrawn. */
1653 cursor_type_changed
= 1;
1657 x_set_icon_type (f
, arg
, oldval
)
1659 Lisp_Object arg
, oldval
;
1663 if (NILP (arg
) && NILP (oldval
))
1666 if (STRINGP (arg
) && STRINGP (oldval
)
1667 && EQ (Fstring_equal (oldval
, arg
), Qt
))
1670 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
1675 result
= x_bitmap_icon (f
, arg
);
1679 error ("No icon window available");
1686 x_set_icon_name (f
, arg
, oldval
)
1688 Lisp_Object arg
, oldval
;
1692 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1695 else if (!NILP (arg
) || NILP (oldval
))
1701 if (f
->output_data
.w32
->icon_bitmap
!= 0)
1706 result
= x_text_icon (f
,
1707 (char *) SDATA ((!NILP (f
->icon_name
)
1716 error ("No icon window available");
1719 /* If the window was unmapped (and its icon was mapped),
1720 the new icon is not mapped, so map the window in its stead. */
1721 if (FRAME_VISIBLE_P (f
))
1723 #ifdef USE_X_TOOLKIT
1724 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
1726 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
1729 XFlush (FRAME_W32_DISPLAY (f
));
1736 x_set_menu_bar_lines (f
, value
, oldval
)
1738 Lisp_Object value
, oldval
;
1741 int olines
= FRAME_MENU_BAR_LINES (f
);
1743 /* Right now, menu bars don't work properly in minibuf-only frames;
1744 most of the commands try to apply themselves to the minibuffer
1745 frame itself, and get an error because you can't switch buffers
1746 in or split the minibuffer window. */
1747 if (FRAME_MINIBUF_ONLY_P (f
))
1750 if (INTEGERP (value
))
1751 nlines
= XINT (value
);
1755 FRAME_MENU_BAR_LINES (f
) = 0;
1757 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1760 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1761 free_frame_menubar (f
);
1762 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1764 /* Adjust the frame size so that the client (text) dimensions
1765 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
1767 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
1768 do_pending_window_change (0);
1774 /* Set the number of lines used for the tool bar of frame F to VALUE.
1775 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1776 is the old number of tool bar lines. This function changes the
1777 height of all windows on frame F to match the new tool bar height.
1778 The frame's height doesn't change. */
1781 x_set_tool_bar_lines (f
, value
, oldval
)
1783 Lisp_Object value
, oldval
;
1785 int delta
, nlines
, root_height
;
1786 Lisp_Object root_window
;
1788 /* Treat tool bars like menu bars. */
1789 if (FRAME_MINIBUF_ONLY_P (f
))
1792 /* Use VALUE only if an integer >= 0. */
1793 if (INTEGERP (value
) && XINT (value
) >= 0)
1794 nlines
= XFASTINT (value
);
1798 /* Make sure we redisplay all windows in this frame. */
1799 ++windows_or_buffers_changed
;
1801 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
1803 /* Don't resize the tool-bar to more than we have room for. */
1804 root_window
= FRAME_ROOT_WINDOW (f
);
1805 root_height
= WINDOW_TOTAL_LINES (XWINDOW (root_window
));
1806 if (root_height
- delta
< 1)
1808 delta
= root_height
- 1;
1809 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
1812 FRAME_TOOL_BAR_LINES (f
) = nlines
;
1813 change_window_heights (root_window
, delta
);
1816 /* We also have to make sure that the internal border at the top of
1817 the frame, below the menu bar or tool bar, is redrawn when the
1818 tool bar disappears. This is so because the internal border is
1819 below the tool bar if one is displayed, but is below the menu bar
1820 if there isn't a tool bar. The tool bar draws into the area
1821 below the menu bar. */
1822 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
1826 clear_current_matrices (f
);
1827 updating_frame
= NULL
;
1830 /* If the tool bar gets smaller, the internal border below it
1831 has to be cleared. It was formerly part of the display
1832 of the larger tool bar, and updating windows won't clear it. */
1835 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1836 int width
= FRAME_PIXEL_WIDTH (f
);
1837 int y
= nlines
* FRAME_LINE_HEIGHT (f
);
1841 HDC hdc
= get_frame_dc (f
);
1842 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
1843 release_frame_dc (f
, hdc
);
1847 if (WINDOWP (f
->tool_bar_window
))
1848 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1853 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1856 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1857 name; if NAME is a string, set F's name to NAME and set
1858 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1860 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1861 suggesting a new name, which lisp code should override; if
1862 F->explicit_name is set, ignore the new name; otherwise, set it. */
1865 x_set_name (f
, name
, explicit)
1870 /* Make sure that requests from lisp code override requests from
1871 Emacs redisplay code. */
1874 /* If we're switching from explicit to implicit, we had better
1875 update the mode lines and thereby update the title. */
1876 if (f
->explicit_name
&& NILP (name
))
1877 update_mode_lines
= 1;
1879 f
->explicit_name
= ! NILP (name
);
1881 else if (f
->explicit_name
)
1884 /* If NAME is nil, set the name to the w32_id_name. */
1887 /* Check for no change needed in this very common case
1888 before we do any consing. */
1889 if (!strcmp (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
,
1892 name
= build_string (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
);
1895 CHECK_STRING (name
);
1897 /* Don't change the name if it's already NAME. */
1898 if (! NILP (Fstring_equal (name
, f
->name
)))
1903 /* For setting the frame title, the title parameter should override
1904 the name parameter. */
1905 if (! NILP (f
->title
))
1908 if (FRAME_W32_WINDOW (f
))
1910 if (STRING_MULTIBYTE (name
))
1911 name
= ENCODE_SYSTEM (name
);
1914 SetWindowText(FRAME_W32_WINDOW (f
), SDATA (name
));
1919 /* This function should be called when the user's lisp code has
1920 specified a name for the frame; the name will override any set by the
1923 x_explicitly_set_name (f
, arg
, oldval
)
1925 Lisp_Object arg
, oldval
;
1927 x_set_name (f
, arg
, 1);
1930 /* This function should be called by Emacs redisplay code to set the
1931 name; names set this way will never override names set by the user's
1934 x_implicitly_set_name (f
, arg
, oldval
)
1936 Lisp_Object arg
, oldval
;
1938 x_set_name (f
, arg
, 0);
1941 /* Change the title of frame F to NAME.
1942 If NAME is nil, use the frame name as the title.
1944 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1945 name; if NAME is a string, set F's name to NAME and set
1946 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1948 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1949 suggesting a new name, which lisp code should override; if
1950 F->explicit_name is set, ignore the new name; otherwise, set it. */
1953 x_set_title (f
, name
, old_name
)
1955 Lisp_Object name
, old_name
;
1957 /* Don't change the title if it's already NAME. */
1958 if (EQ (name
, f
->title
))
1961 update_mode_lines
= 1;
1968 if (FRAME_W32_WINDOW (f
))
1970 if (STRING_MULTIBYTE (name
))
1971 name
= ENCODE_SYSTEM (name
);
1974 SetWindowText(FRAME_W32_WINDOW (f
), SDATA (name
));
1980 void x_set_scroll_bar_default_width (f
)
1983 int wid
= FRAME_COLUMN_WIDTH (f
);
1985 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
1986 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) +
1991 /* Subroutines of creating a frame. */
1994 /* Return the value of parameter PARAM.
1996 First search ALIST, then Vdefault_frame_alist, then the X defaults
1997 database, using ATTRIBUTE as the attribute name and CLASS as its class.
1999 Convert the resource to the type specified by desired_type.
2001 If no default is specified, return Qunbound. If you call
2002 w32_get_arg, make sure you deal with Qunbound in a reasonable way,
2003 and don't let it get stored in any Lisp-visible variables! */
2006 w32_get_arg (alist
, param
, attribute
, class, type
)
2007 Lisp_Object alist
, param
;
2010 enum resource_types type
;
2012 return x_get_arg (check_x_display_info (Qnil
),
2013 alist
, param
, attribute
, class, type
);
2018 w32_load_cursor (LPCTSTR name
)
2020 /* Try first to load cursor from application resource. */
2021 Cursor cursor
= LoadImage ((HINSTANCE
) GetModuleHandle(NULL
),
2022 name
, IMAGE_CURSOR
, 0, 0,
2023 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
2026 /* Then try to load a shared predefined cursor. */
2027 cursor
= LoadImage (NULL
, name
, IMAGE_CURSOR
, 0, 0,
2028 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
2033 extern LRESULT CALLBACK
w32_wnd_proc ();
2036 w32_init_class (hinst
)
2041 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
2042 wc
.lpfnWndProc
= (WNDPROC
) w32_wnd_proc
;
2044 wc
.cbWndExtra
= WND_EXTRA_BYTES
;
2045 wc
.hInstance
= hinst
;
2046 wc
.hIcon
= LoadIcon (hinst
, EMACS_CLASS
);
2047 wc
.hCursor
= w32_load_cursor (IDC_ARROW
);
2048 wc
.hbrBackground
= NULL
; /* GetStockObject (WHITE_BRUSH); */
2049 wc
.lpszMenuName
= NULL
;
2050 wc
.lpszClassName
= EMACS_CLASS
;
2052 return (RegisterClass (&wc
));
2056 w32_createscrollbar (f
, bar
)
2058 struct scroll_bar
* bar
;
2060 return (CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
2061 /* Position and size of scroll bar. */
2062 XINT(bar
->left
) + VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
2064 XINT(bar
->width
) - VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
2066 FRAME_W32_WINDOW (f
),
2073 w32_createwindow (f
)
2078 Lisp_Object top
= Qunbound
;
2079 Lisp_Object left
= Qunbound
;
2081 rect
.left
= rect
.top
= 0;
2082 rect
.right
= FRAME_PIXEL_WIDTH (f
);
2083 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
2085 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
2086 FRAME_EXTERNAL_MENU_BAR (f
));
2088 /* Do first time app init */
2092 w32_init_class (hinst
);
2095 if (f
->size_hint_flags
& USPosition
|| f
->size_hint_flags
& PPosition
)
2097 XSETINT (left
, f
->left_pos
);
2098 XSETINT (top
, f
->top_pos
);
2100 else if (EQ (left
, Qunbound
) && EQ (top
, Qunbound
))
2102 /* When called with RES_TYPE_NUMBER, w32_get_arg will return zero
2103 for anything that is not a number and is not Qunbound. */
2104 left
= w32_get_arg (Qnil
, Qleft
, "left", "Left", RES_TYPE_NUMBER
);
2105 top
= w32_get_arg (Qnil
, Qtop
, "top", "Top", RES_TYPE_NUMBER
);
2108 FRAME_W32_WINDOW (f
) = hwnd
2109 = CreateWindow (EMACS_CLASS
,
2111 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
2112 EQ (left
, Qunbound
) ? CW_USEDEFAULT
: XINT (left
),
2113 EQ (top
, Qunbound
) ? CW_USEDEFAULT
: XINT (top
),
2114 rect
.right
- rect
.left
,
2115 rect
.bottom
- rect
.top
,
2123 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
2124 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
2125 SetWindowLong (hwnd
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
2126 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->scroll_bar_actual_width
);
2127 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
2129 /* Enable drag-n-drop. */
2130 DragAcceptFiles (hwnd
, TRUE
);
2132 /* Do this to discard the default setting specified by our parent. */
2133 ShowWindow (hwnd
, SW_HIDE
);
2135 /* Update frame positions. */
2136 GetWindowRect (hwnd
, &rect
);
2137 f
->left_pos
= rect
.left
;
2138 f
->top_pos
= rect
.top
;
2143 my_post_msg (wmsg
, hwnd
, msg
, wParam
, lParam
)
2150 wmsg
->msg
.hwnd
= hwnd
;
2151 wmsg
->msg
.message
= msg
;
2152 wmsg
->msg
.wParam
= wParam
;
2153 wmsg
->msg
.lParam
= lParam
;
2154 wmsg
->msg
.time
= GetMessageTime ();
2159 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
2160 between left and right keys as advertised. We test for this
2161 support dynamically, and set a flag when the support is absent. If
2162 absent, we keep track of the left and right control and alt keys
2163 ourselves. This is particularly necessary on keyboards that rely
2164 upon the AltGr key, which is represented as having the left control
2165 and right alt keys pressed. For these keyboards, we need to know
2166 when the left alt key has been pressed in addition to the AltGr key
2167 so that we can properly support M-AltGr-key sequences (such as M-@
2168 on Swedish keyboards). */
2170 #define EMACS_LCONTROL 0
2171 #define EMACS_RCONTROL 1
2172 #define EMACS_LMENU 2
2173 #define EMACS_RMENU 3
2175 static int modifiers
[4];
2176 static int modifiers_recorded
;
2177 static int modifier_key_support_tested
;
2180 test_modifier_support (unsigned int wparam
)
2184 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
2186 if (wparam
== VK_CONTROL
)
2196 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
2197 modifiers_recorded
= 1;
2199 modifiers_recorded
= 0;
2200 modifier_key_support_tested
= 1;
2204 record_keydown (unsigned int wparam
, unsigned int lparam
)
2208 if (!modifier_key_support_tested
)
2209 test_modifier_support (wparam
);
2211 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2214 if (wparam
== VK_CONTROL
)
2215 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2217 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2223 record_keyup (unsigned int wparam
, unsigned int lparam
)
2227 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2230 if (wparam
== VK_CONTROL
)
2231 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2233 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2238 /* Emacs can lose focus while a modifier key has been pressed. When
2239 it regains focus, be conservative and clear all modifiers since
2240 we cannot reconstruct the left and right modifier state. */
2246 if (GetFocus () == NULL
)
2247 /* Emacs doesn't have keyboard focus. Do nothing. */
2250 ctrl
= GetAsyncKeyState (VK_CONTROL
);
2251 alt
= GetAsyncKeyState (VK_MENU
);
2253 if (!(ctrl
& 0x08000))
2254 /* Clear any recorded control modifier state. */
2255 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2257 if (!(alt
& 0x08000))
2258 /* Clear any recorded alt modifier state. */
2259 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2261 /* Update the state of all modifier keys, because modifiers used in
2262 hot-key combinations can get stuck on if Emacs loses focus as a
2263 result of a hot-key being pressed. */
2267 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
2269 GetKeyboardState (keystate
);
2270 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
2271 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
2272 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
2273 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
2274 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
2275 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
2276 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
2277 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
2278 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
2279 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
2280 SetKeyboardState (keystate
);
2284 /* Synchronize modifier state with what is reported with the current
2285 keystroke. Even if we cannot distinguish between left and right
2286 modifier keys, we know that, if no modifiers are set, then neither
2287 the left or right modifier should be set. */
2291 if (!modifiers_recorded
)
2294 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
2295 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2297 if (!(GetKeyState (VK_MENU
) & 0x8000))
2298 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2302 modifier_set (int vkey
)
2304 if (vkey
== VK_CAPITAL
|| vkey
== VK_SCROLL
)
2305 return (GetKeyState (vkey
) & 0x1);
2306 if (!modifiers_recorded
)
2307 return (GetKeyState (vkey
) & 0x8000);
2312 return modifiers
[EMACS_LCONTROL
];
2314 return modifiers
[EMACS_RCONTROL
];
2316 return modifiers
[EMACS_LMENU
];
2318 return modifiers
[EMACS_RMENU
];
2320 return (GetKeyState (vkey
) & 0x8000);
2323 /* Convert between the modifier bits W32 uses and the modifier bits
2327 w32_key_to_modifier (int key
)
2329 Lisp_Object key_mapping
;
2334 key_mapping
= Vw32_lwindow_modifier
;
2337 key_mapping
= Vw32_rwindow_modifier
;
2340 key_mapping
= Vw32_apps_modifier
;
2343 key_mapping
= Vw32_scroll_lock_modifier
;
2349 /* NB. This code runs in the input thread, asychronously to the lisp
2350 thread, so we must be careful to ensure access to lisp data is
2351 thread-safe. The following code is safe because the modifier
2352 variable values are updated atomically from lisp and symbols are
2353 not relocated by GC. Also, we don't have to worry about seeing GC
2355 if (EQ (key_mapping
, Qhyper
))
2356 return hyper_modifier
;
2357 if (EQ (key_mapping
, Qsuper
))
2358 return super_modifier
;
2359 if (EQ (key_mapping
, Qmeta
))
2360 return meta_modifier
;
2361 if (EQ (key_mapping
, Qalt
))
2362 return alt_modifier
;
2363 if (EQ (key_mapping
, Qctrl
))
2364 return ctrl_modifier
;
2365 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
2366 return ctrl_modifier
;
2367 if (EQ (key_mapping
, Qshift
))
2368 return shift_modifier
;
2370 /* Don't generate any modifier if not explicitly requested. */
2375 w32_get_modifiers ()
2377 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
2378 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
2379 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
2380 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
2381 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
2382 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
2383 (modifier_set (VK_MENU
) ?
2384 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
2387 /* We map the VK_* modifiers into console modifier constants
2388 so that we can use the same routines to handle both console
2389 and window input. */
2392 construct_console_modifiers ()
2397 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
2398 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
2399 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
2400 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
2401 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
2402 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
2403 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
2404 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
2405 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
2406 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
2407 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
2413 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
2417 /* Convert to emacs modifiers. */
2418 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
2424 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
2426 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
2429 if (virt_key
== VK_RETURN
)
2430 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
2432 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
2433 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
2435 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
2436 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
2438 if (virt_key
== VK_CLEAR
)
2439 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
2444 /* List of special key combinations which w32 would normally capture,
2445 but emacs should grab instead. Not directly visible to lisp, to
2446 simplify synchronization. Each item is an integer encoding a virtual
2447 key code and modifier combination to capture. */
2448 Lisp_Object w32_grabbed_keys
;
2450 #define HOTKEY(vk,mods) make_number (((vk) & 255) | ((mods) << 8))
2451 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
2452 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
2453 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
2455 #define RAW_HOTKEY_ID(k) ((k) & 0xbfff)
2456 #define RAW_HOTKEY_VK_CODE(k) ((k) & 255)
2457 #define RAW_HOTKEY_MODIFIERS(k) ((k) >> 8)
2459 /* Register hot-keys for reserved key combinations when Emacs has
2460 keyboard focus, since this is the only way Emacs can receive key
2461 combinations like Alt-Tab which are used by the system. */
2464 register_hot_keys (hwnd
)
2467 Lisp_Object keylist
;
2469 /* Use GC_CONSP, since we are called asynchronously. */
2470 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
2472 Lisp_Object key
= XCAR (keylist
);
2474 /* Deleted entries get set to nil. */
2475 if (!INTEGERP (key
))
2478 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
2479 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
2484 unregister_hot_keys (hwnd
)
2487 Lisp_Object keylist
;
2489 /* Use GC_CONSP, since we are called asynchronously. */
2490 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
2492 Lisp_Object key
= XCAR (keylist
);
2494 if (!INTEGERP (key
))
2497 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
2501 /* Main message dispatch loop. */
2504 w32_msg_pump (deferred_msg
* msg_buf
)
2510 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
2512 while (GetMessage (&msg
, NULL
, 0, 0))
2514 if (msg
.hwnd
== NULL
)
2516 switch (msg
.message
)
2519 /* Produced by complete_deferred_msg; just ignore. */
2521 case WM_EMACS_CREATEWINDOW
:
2522 w32_createwindow ((struct frame
*) msg
.wParam
);
2523 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2526 case WM_EMACS_SETLOCALE
:
2527 SetThreadLocale (msg
.wParam
);
2528 /* Reply is not expected. */
2530 case WM_EMACS_SETKEYBOARDLAYOUT
:
2531 result
= (int) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
2532 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2536 case WM_EMACS_REGISTER_HOT_KEY
:
2537 focus_window
= GetFocus ();
2538 if (focus_window
!= NULL
)
2539 RegisterHotKey (focus_window
,
2540 RAW_HOTKEY_ID (msg
.wParam
),
2541 RAW_HOTKEY_MODIFIERS (msg
.wParam
),
2542 RAW_HOTKEY_VK_CODE (msg
.wParam
));
2543 /* Reply is not expected. */
2545 case WM_EMACS_UNREGISTER_HOT_KEY
:
2546 focus_window
= GetFocus ();
2547 if (focus_window
!= NULL
)
2548 UnregisterHotKey (focus_window
, RAW_HOTKEY_ID (msg
.wParam
));
2549 /* Mark item as erased. NB: this code must be
2550 thread-safe. The next line is okay because the cons
2551 cell is never made into garbage and is not relocated by
2553 XSETCAR ((Lisp_Object
) ((EMACS_INT
) msg
.lParam
), Qnil
);
2554 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2557 case WM_EMACS_TOGGLE_LOCK_KEY
:
2559 int vk_code
= (int) msg
.wParam
;
2560 int cur_state
= (GetKeyState (vk_code
) & 1);
2561 Lisp_Object new_state
= (Lisp_Object
) ((EMACS_INT
) msg
.lParam
);
2563 /* NB: This code must be thread-safe. It is safe to
2564 call NILP because symbols are not relocated by GC,
2565 and pointer here is not touched by GC (so the markbit
2566 can't be set). Numbers are safe because they are
2567 immediate values. */
2568 if (NILP (new_state
)
2569 || (NUMBERP (new_state
)
2570 && ((XUINT (new_state
)) & 1) != cur_state
))
2572 one_w32_display_info
.faked_key
= vk_code
;
2574 keybd_event ((BYTE
) vk_code
,
2575 (BYTE
) MapVirtualKey (vk_code
, 0),
2576 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2577 keybd_event ((BYTE
) vk_code
,
2578 (BYTE
) MapVirtualKey (vk_code
, 0),
2579 KEYEVENTF_EXTENDEDKEY
| 0, 0);
2580 keybd_event ((BYTE
) vk_code
,
2581 (BYTE
) MapVirtualKey (vk_code
, 0),
2582 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2583 cur_state
= !cur_state
;
2585 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2591 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
2596 DispatchMessage (&msg
);
2599 /* Exit nested loop when our deferred message has completed. */
2600 if (msg_buf
->completed
)
2605 deferred_msg
* deferred_msg_head
;
2607 static deferred_msg
*
2608 find_deferred_msg (HWND hwnd
, UINT msg
)
2610 deferred_msg
* item
;
2612 /* Don't actually need synchronization for read access, since
2613 modification of single pointer is always atomic. */
2614 /* enter_crit (); */
2616 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2617 if (item
->w32msg
.msg
.hwnd
== hwnd
2618 && item
->w32msg
.msg
.message
== msg
)
2621 /* leave_crit (); */
2627 send_deferred_msg (deferred_msg
* msg_buf
,
2633 /* Only input thread can send deferred messages. */
2634 if (GetCurrentThreadId () != dwWindowsThreadId
)
2637 /* It is an error to send a message that is already deferred. */
2638 if (find_deferred_msg (hwnd
, msg
) != NULL
)
2641 /* Enforced synchronization is not needed because this is the only
2642 function that alters deferred_msg_head, and the following critical
2643 section is guaranteed to only be serially reentered (since only the
2644 input thread can call us). */
2646 /* enter_crit (); */
2648 msg_buf
->completed
= 0;
2649 msg_buf
->next
= deferred_msg_head
;
2650 deferred_msg_head
= msg_buf
;
2651 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
2653 /* leave_crit (); */
2655 /* Start a new nested message loop to process other messages until
2656 this one is completed. */
2657 w32_msg_pump (msg_buf
);
2659 deferred_msg_head
= msg_buf
->next
;
2661 return msg_buf
->result
;
2665 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
2667 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
2669 if (msg_buf
== NULL
)
2670 /* Message may have been cancelled, so don't abort(). */
2673 msg_buf
->result
= result
;
2674 msg_buf
->completed
= 1;
2676 /* Ensure input thread is woken so it notices the completion. */
2677 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2681 cancel_all_deferred_msgs ()
2683 deferred_msg
* item
;
2685 /* Don't actually need synchronization for read access, since
2686 modification of single pointer is always atomic. */
2687 /* enter_crit (); */
2689 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2692 item
->completed
= 1;
2695 /* leave_crit (); */
2697 /* Ensure input thread is woken so it notices the completion. */
2698 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2702 w32_msg_worker (void *arg
)
2705 deferred_msg dummy_buf
;
2707 /* Ensure our message queue is created */
2709 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
2711 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2714 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
2715 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
2716 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
2718 /* This is the inital message loop which should only exit when the
2719 application quits. */
2720 w32_msg_pump (&dummy_buf
);
2726 signal_user_input ()
2728 /* Interrupt any lisp that wants to be interrupted by input. */
2729 if (!NILP (Vthrow_on_input
))
2731 Vquit_flag
= Vthrow_on_input
;
2732 /* If we're inside a function that wants immediate quits,
2734 if (immediate_quit
&& NILP (Vinhibit_quit
))
2744 post_character_message (hwnd
, msg
, wParam
, lParam
, modifiers
)
2754 wmsg
.dwModifiers
= modifiers
;
2756 /* Detect quit_char and set quit-flag directly. Note that we
2757 still need to post a message to ensure the main thread will be
2758 woken up if blocked in sys_select(), but we do NOT want to post
2759 the quit_char message itself (because it will usually be as if
2760 the user had typed quit_char twice). Instead, we post a dummy
2761 message that has no particular effect. */
2764 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
2765 c
= make_ctrl_char (c
) & 0377;
2767 || (wmsg
.dwModifiers
== 0 &&
2768 w32_quit_key
&& wParam
== w32_quit_key
))
2772 /* The choice of message is somewhat arbitrary, as long as
2773 the main thread handler just ignores it. */
2776 /* Interrupt any blocking system calls. */
2779 /* As a safety precaution, forcibly complete any deferred
2780 messages. This is a kludge, but I don't see any particularly
2781 clean way to handle the situation where a deferred message is
2782 "dropped" in the lisp thread, and will thus never be
2783 completed, eg. by the user trying to activate the menubar
2784 when the lisp thread is busy, and then typing C-g when the
2785 menubar doesn't open promptly (with the result that the
2786 menubar never responds at all because the deferred
2787 WM_INITMENU message is never completed). Another problem
2788 situation is when the lisp thread calls SendMessage (to send
2789 a window manager command) when a message has been deferred;
2790 the lisp thread gets blocked indefinitely waiting for the
2791 deferred message to be completed, which itself is waiting for
2792 the lisp thread to respond.
2794 Note that we don't want to block the input thread waiting for
2795 a reponse from the lisp thread (although that would at least
2796 solve the deadlock problem above), because we want to be able
2797 to receive C-g to interrupt the lisp thread. */
2798 cancel_all_deferred_msgs ();
2801 signal_user_input ();
2804 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2807 /* Main window procedure */
2810 w32_wnd_proc (hwnd
, msg
, wParam
, lParam
)
2817 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
2819 int windows_translate
;
2822 /* Note that it is okay to call x_window_to_frame, even though we are
2823 not running in the main lisp thread, because frame deletion
2824 requires the lisp thread to synchronize with this thread. Thus, if
2825 a frame struct is returned, it can be used without concern that the
2826 lisp thread might make it disappear while we are using it.
2828 NB. Walking the frame list in this thread is safe (as long as
2829 writes of Lisp_Object slots are atomic, which they are on Windows).
2830 Although delete-frame can destructively modify the frame list while
2831 we are walking it, a garbage collection cannot occur until after
2832 delete-frame has synchronized with this thread.
2834 It is also safe to use functions that make GDI calls, such as
2835 w32_clear_rect, because these functions must obtain a DC handle
2836 from the frame struct using get_frame_dc which is thread-aware. */
2841 f
= x_window_to_frame (dpyinfo
, hwnd
);
2844 HDC hdc
= get_frame_dc (f
);
2845 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
2846 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
2847 release_frame_dc (f
, hdc
);
2849 #if defined (W32_DEBUG_DISPLAY)
2850 DebPrint (("WM_ERASEBKGND (frame %p): erasing %d,%d-%d,%d\n",
2852 wmsg
.rect
.left
, wmsg
.rect
.top
,
2853 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2854 #endif /* W32_DEBUG_DISPLAY */
2857 case WM_PALETTECHANGED
:
2858 /* ignore our own changes */
2859 if ((HWND
)wParam
!= hwnd
)
2861 f
= x_window_to_frame (dpyinfo
, hwnd
);
2863 /* get_frame_dc will realize our palette and force all
2864 frames to be redrawn if needed. */
2865 release_frame_dc (f
, get_frame_dc (f
));
2870 PAINTSTRUCT paintStruct
;
2872 bzero (&update_rect
, sizeof (update_rect
));
2874 f
= x_window_to_frame (dpyinfo
, hwnd
);
2877 DebPrint (("WM_PAINT received for unknown window %p\n", hwnd
));
2881 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
2882 fails. Apparently this can happen under some
2884 if (GetUpdateRect (hwnd
, &update_rect
, FALSE
) || !w32_strict_painting
)
2887 BeginPaint (hwnd
, &paintStruct
);
2889 /* The rectangles returned by GetUpdateRect and BeginPaint
2890 do not always match. Play it safe by assuming both areas
2892 UnionRect (&(wmsg
.rect
), &update_rect
, &(paintStruct
.rcPaint
));
2894 #if defined (W32_DEBUG_DISPLAY)
2895 DebPrint (("WM_PAINT (frame %p): painting %d,%d-%d,%d\n",
2897 wmsg
.rect
.left
, wmsg
.rect
.top
,
2898 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2899 DebPrint ((" [update region is %d,%d-%d,%d]\n",
2900 update_rect
.left
, update_rect
.top
,
2901 update_rect
.right
, update_rect
.bottom
));
2903 EndPaint (hwnd
, &paintStruct
);
2906 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2911 /* If GetUpdateRect returns 0 (meaning there is no update
2912 region), assume the whole window needs to be repainted. */
2913 GetClientRect(hwnd
, &wmsg
.rect
);
2914 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2918 case WM_INPUTLANGCHANGE
:
2919 /* Inform lisp thread of keyboard layout changes. */
2920 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2922 /* Clear dead keys in the keyboard state; for simplicity only
2923 preserve modifier key states. */
2928 GetKeyboardState (keystate
);
2929 for (i
= 0; i
< 256; i
++)
2946 SetKeyboardState (keystate
);
2951 /* Synchronize hot keys with normal input. */
2952 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
2957 record_keyup (wParam
, lParam
);
2962 /* Ignore keystrokes we fake ourself; see below. */
2963 if (dpyinfo
->faked_key
== wParam
)
2965 dpyinfo
->faked_key
= 0;
2966 /* Make sure TranslateMessage sees them though (as long as
2967 they don't produce WM_CHAR messages). This ensures that
2968 indicator lights are toggled promptly on Windows 9x, for
2970 if (lispy_function_keys
[wParam
] != 0)
2972 windows_translate
= 1;
2978 /* Synchronize modifiers with current keystroke. */
2980 record_keydown (wParam
, lParam
);
2981 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
2983 windows_translate
= 0;
2988 if (NILP (Vw32_pass_lwindow_to_system
))
2990 /* Prevent system from acting on keyup (which opens the
2991 Start menu if no other key was pressed) by simulating a
2992 press of Space which we will ignore. */
2993 if (GetAsyncKeyState (wParam
) & 1)
2995 if (NUMBERP (Vw32_phantom_key_code
))
2996 key
= XUINT (Vw32_phantom_key_code
) & 255;
2999 dpyinfo
->faked_key
= key
;
3000 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
3003 if (!NILP (Vw32_lwindow_modifier
))
3007 if (NILP (Vw32_pass_rwindow_to_system
))
3009 if (GetAsyncKeyState (wParam
) & 1)
3011 if (NUMBERP (Vw32_phantom_key_code
))
3012 key
= XUINT (Vw32_phantom_key_code
) & 255;
3015 dpyinfo
->faked_key
= key
;
3016 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
3019 if (!NILP (Vw32_rwindow_modifier
))
3023 if (!NILP (Vw32_apps_modifier
))
3027 if (NILP (Vw32_pass_alt_to_system
))
3028 /* Prevent DefWindowProc from activating the menu bar if an
3029 Alt key is pressed and released by itself. */
3031 windows_translate
= 1;
3034 /* Decide whether to treat as modifier or function key. */
3035 if (NILP (Vw32_enable_caps_lock
))
3036 goto disable_lock_key
;
3037 windows_translate
= 1;
3040 /* Decide whether to treat as modifier or function key. */
3041 if (NILP (Vw32_enable_num_lock
))
3042 goto disable_lock_key
;
3043 windows_translate
= 1;
3046 /* Decide whether to treat as modifier or function key. */
3047 if (NILP (Vw32_scroll_lock_modifier
))
3048 goto disable_lock_key
;
3049 windows_translate
= 1;
3052 /* Ensure the appropriate lock key state (and indicator light)
3053 remains in the same state. We do this by faking another
3054 press of the relevant key. Apparently, this really is the
3055 only way to toggle the state of the indicator lights. */
3056 dpyinfo
->faked_key
= wParam
;
3057 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3058 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3059 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3060 KEYEVENTF_EXTENDEDKEY
| 0, 0);
3061 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3062 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3063 /* Ensure indicator lights are updated promptly on Windows 9x
3064 (TranslateMessage apparently does this), after forwarding
3066 post_character_message (hwnd
, msg
, wParam
, lParam
,
3067 w32_get_key_modifiers (wParam
, lParam
));
3068 windows_translate
= 1;
3072 case VK_PROCESSKEY
: /* Generated by IME. */
3073 windows_translate
= 1;
3076 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
3077 which is confusing for purposes of key binding; convert
3078 VK_CANCEL events into VK_PAUSE events. */
3082 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
3083 for purposes of key binding; convert these back into
3084 VK_NUMLOCK events, at least when we want to see NumLock key
3085 presses. (Note that there is never any possibility that
3086 VK_PAUSE with Ctrl really is C-Pause as per above.) */
3087 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
3088 wParam
= VK_NUMLOCK
;
3091 /* If not defined as a function key, change it to a WM_CHAR message. */
3092 if (lispy_function_keys
[wParam
] == 0)
3094 DWORD modifiers
= construct_console_modifiers ();
3096 if (!NILP (Vw32_recognize_altgr
)
3097 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
3099 /* Always let TranslateMessage handle AltGr key chords;
3100 for some reason, ToAscii doesn't always process AltGr
3101 chords correctly. */
3102 windows_translate
= 1;
3104 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
3106 /* Handle key chords including any modifiers other
3107 than shift directly, in order to preserve as much
3108 modifier information as possible. */
3109 if ('A' <= wParam
&& wParam
<= 'Z')
3111 /* Don't translate modified alphabetic keystrokes,
3112 so the user doesn't need to constantly switch
3113 layout to type control or meta keystrokes when
3114 the normal layout translates alphabetic
3115 characters to non-ascii characters. */
3116 if (!modifier_set (VK_SHIFT
))
3117 wParam
+= ('a' - 'A');
3122 /* Try to handle other keystrokes by determining the
3123 base character (ie. translating the base key plus
3127 KEY_EVENT_RECORD key
;
3129 key
.bKeyDown
= TRUE
;
3130 key
.wRepeatCount
= 1;
3131 key
.wVirtualKeyCode
= wParam
;
3132 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
3133 key
.uChar
.AsciiChar
= 0;
3134 key
.dwControlKeyState
= modifiers
;
3136 add
= w32_kbd_patch_key (&key
);
3137 /* 0 means an unrecognised keycode, negative means
3138 dead key. Ignore both. */
3141 /* Forward asciified character sequence. */
3142 post_character_message
3143 (hwnd
, WM_CHAR
, key
.uChar
.AsciiChar
, lParam
,
3144 w32_get_key_modifiers (wParam
, lParam
));
3145 w32_kbd_patch_key (&key
);
3152 /* Let TranslateMessage handle everything else. */
3153 windows_translate
= 1;
3159 if (windows_translate
)
3161 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
3163 windows_msg
.time
= GetMessageTime ();
3164 TranslateMessage (&windows_msg
);
3172 post_character_message (hwnd
, msg
, wParam
, lParam
,
3173 w32_get_key_modifiers (wParam
, lParam
));
3176 /* Simulate middle mouse button events when left and right buttons
3177 are used together, but only if user has two button mouse. */
3178 case WM_LBUTTONDOWN
:
3179 case WM_RBUTTONDOWN
:
3180 if (w32_num_mouse_buttons
> 2)
3181 goto handle_plain_button
;
3184 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
3185 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
3187 if (button_state
& this)
3190 if (button_state
== 0)
3193 button_state
|= this;
3195 if (button_state
& other
)
3197 if (mouse_button_timer
)
3199 KillTimer (hwnd
, mouse_button_timer
);
3200 mouse_button_timer
= 0;
3202 /* Generate middle mouse event instead. */
3203 msg
= WM_MBUTTONDOWN
;
3204 button_state
|= MMOUSE
;
3206 else if (button_state
& MMOUSE
)
3208 /* Ignore button event if we've already generated a
3209 middle mouse down event. This happens if the
3210 user releases and press one of the two buttons
3211 after we've faked a middle mouse event. */
3216 /* Flush out saved message. */
3217 post_msg (&saved_mouse_button_msg
);
3219 wmsg
.dwModifiers
= w32_get_modifiers ();
3220 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3221 signal_user_input ();
3223 /* Clear message buffer. */
3224 saved_mouse_button_msg
.msg
.hwnd
= 0;
3228 /* Hold onto message for now. */
3229 mouse_button_timer
=
3230 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
3231 w32_mouse_button_tolerance
, NULL
);
3232 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
3233 saved_mouse_button_msg
.msg
.message
= msg
;
3234 saved_mouse_button_msg
.msg
.wParam
= wParam
;
3235 saved_mouse_button_msg
.msg
.lParam
= lParam
;
3236 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
3237 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
3244 if (w32_num_mouse_buttons
> 2)
3245 goto handle_plain_button
;
3248 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
3249 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
3251 if ((button_state
& this) == 0)
3254 button_state
&= ~this;
3256 if (button_state
& MMOUSE
)
3258 /* Only generate event when second button is released. */
3259 if ((button_state
& other
) == 0)
3262 button_state
&= ~MMOUSE
;
3264 if (button_state
) abort ();
3271 /* Flush out saved message if necessary. */
3272 if (saved_mouse_button_msg
.msg
.hwnd
)
3274 post_msg (&saved_mouse_button_msg
);
3277 wmsg
.dwModifiers
= w32_get_modifiers ();
3278 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3279 signal_user_input ();
3281 /* Always clear message buffer and cancel timer. */
3282 saved_mouse_button_msg
.msg
.hwnd
= 0;
3283 KillTimer (hwnd
, mouse_button_timer
);
3284 mouse_button_timer
= 0;
3286 if (button_state
== 0)
3291 case WM_XBUTTONDOWN
:
3293 if (w32_pass_extra_mouse_buttons_to_system
)
3295 /* else fall through and process them. */
3296 case WM_MBUTTONDOWN
:
3298 handle_plain_button
:
3303 /* Ignore middle and extra buttons as long as the menu is active. */
3304 f
= x_window_to_frame (dpyinfo
, hwnd
);
3305 if (f
&& f
->output_data
.w32
->menubar_active
)
3308 if (parse_button (msg
, HIWORD (wParam
), &button
, &up
))
3310 if (up
) ReleaseCapture ();
3311 else SetCapture (hwnd
);
3312 button
= (button
== 0) ? LMOUSE
:
3313 ((button
== 1) ? MMOUSE
: RMOUSE
);
3315 button_state
&= ~button
;
3317 button_state
|= button
;
3321 wmsg
.dwModifiers
= w32_get_modifiers ();
3322 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3323 signal_user_input ();
3325 /* Need to return true for XBUTTON messages, false for others,
3326 to indicate that we processed the message. */
3327 return (msg
== WM_XBUTTONDOWN
|| msg
== WM_XBUTTONUP
);
3330 /* Ignore mouse movements as long as the menu is active. These
3331 movements are processed by the window manager anyway, and
3332 it's wrong to handle them as if they happened on the
3333 underlying frame. */
3334 f
= x_window_to_frame (dpyinfo
, hwnd
);
3335 if (f
&& f
->output_data
.w32
->menubar_active
)
3338 /* If the mouse has just moved into the frame, start tracking
3339 it, so we will be notified when it leaves the frame. Mouse
3340 tracking only works under W98 and NT4 and later. On earlier
3341 versions, there is no way of telling when the mouse leaves the
3342 frame, so we just have to put up with help-echo and mouse
3343 highlighting remaining while the frame is not active. */
3344 if (track_mouse_event_fn
&& !track_mouse_window
)
3346 TRACKMOUSEEVENT tme
;
3347 tme
.cbSize
= sizeof (tme
);
3348 tme
.dwFlags
= TME_LEAVE
;
3349 tme
.hwndTrack
= hwnd
;
3351 track_mouse_event_fn (&tme
);
3352 track_mouse_window
= hwnd
;
3355 if (w32_mouse_move_interval
<= 0
3356 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
3358 wmsg
.dwModifiers
= w32_get_modifiers ();
3359 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3363 /* Hang onto mouse move and scroll messages for a bit, to avoid
3364 sending such events to Emacs faster than it can process them.
3365 If we get more events before the timer from the first message
3366 expires, we just replace the first message. */
3368 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
3370 SetTimer (hwnd
, MOUSE_MOVE_ID
,
3371 w32_mouse_move_interval
, NULL
);
3373 /* Hold onto message for now. */
3374 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
3375 saved_mouse_move_msg
.msg
.message
= msg
;
3376 saved_mouse_move_msg
.msg
.wParam
= wParam
;
3377 saved_mouse_move_msg
.msg
.lParam
= lParam
;
3378 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
3379 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
3384 wmsg
.dwModifiers
= w32_get_modifiers ();
3385 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3386 signal_user_input ();
3390 wmsg
.dwModifiers
= w32_get_modifiers ();
3391 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3392 signal_user_input ();
3396 /* Flush out saved messages if necessary. */
3397 if (wParam
== mouse_button_timer
)
3399 if (saved_mouse_button_msg
.msg
.hwnd
)
3401 post_msg (&saved_mouse_button_msg
);
3402 signal_user_input ();
3403 saved_mouse_button_msg
.msg
.hwnd
= 0;
3405 KillTimer (hwnd
, mouse_button_timer
);
3406 mouse_button_timer
= 0;
3408 else if (wParam
== mouse_move_timer
)
3410 if (saved_mouse_move_msg
.msg
.hwnd
)
3412 post_msg (&saved_mouse_move_msg
);
3413 saved_mouse_move_msg
.msg
.hwnd
= 0;
3415 KillTimer (hwnd
, mouse_move_timer
);
3416 mouse_move_timer
= 0;
3418 else if (wParam
== menu_free_timer
)
3420 KillTimer (hwnd
, menu_free_timer
);
3421 menu_free_timer
= 0;
3422 f
= x_window_to_frame (dpyinfo
, hwnd
);
3423 /* If a popup menu is active, don't wipe its strings. */
3425 && current_popup_menu
== NULL
)
3427 /* Free memory used by owner-drawn and help-echo strings. */
3428 w32_free_menu_strings (hwnd
);
3429 f
->output_data
.w32
->menubar_active
= 0;
3436 /* Windows doesn't send us focus messages when putting up and
3437 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
3438 The only indication we get that something happened is receiving
3439 this message afterwards. So this is a good time to reset our
3440 keyboard modifiers' state. */
3447 /* We must ensure menu bar is fully constructed and up to date
3448 before allowing user interaction with it. To achieve this
3449 we send this message to the lisp thread and wait for a
3450 reply (whose value is not actually needed) to indicate that
3451 the menu bar is now ready for use, so we can now return.
3453 To remain responsive in the meantime, we enter a nested message
3454 loop that can process all other messages.
3456 However, we skip all this if the message results from calling
3457 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
3458 thread a message because it is blocked on us at this point. We
3459 set menubar_active before calling TrackPopupMenu to indicate
3460 this (there is no possibility of confusion with real menubar
3463 f
= x_window_to_frame (dpyinfo
, hwnd
);
3465 && (f
->output_data
.w32
->menubar_active
3466 /* We can receive this message even in the absence of a
3467 menubar (ie. when the system menu is activated) - in this
3468 case we do NOT want to forward the message, otherwise it
3469 will cause the menubar to suddenly appear when the user
3470 had requested it to be turned off! */
3471 || f
->output_data
.w32
->menubar_widget
== NULL
))
3475 deferred_msg msg_buf
;
3477 /* Detect if message has already been deferred; in this case
3478 we cannot return any sensible value to ignore this. */
3479 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3484 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
3487 case WM_EXITMENULOOP
:
3488 f
= x_window_to_frame (dpyinfo
, hwnd
);
3490 /* If a menu is still active, check again after a short delay,
3491 since Windows often (always?) sends the WM_EXITMENULOOP
3492 before the corresponding WM_COMMAND message.
3493 Don't do this if a popup menu is active, since it is only
3494 menubar menus that require cleaning up in this way.
3496 if (f
&& menubar_in_use
&& current_popup_menu
== NULL
)
3497 menu_free_timer
= SetTimer (hwnd
, MENU_FREE_ID
, MENU_FREE_DELAY
, NULL
);
3501 /* Direct handling of help_echo in menus. Should be safe now
3502 that we generate the help_echo by placing a help event in the
3505 HMENU menu
= (HMENU
) lParam
;
3506 UINT menu_item
= (UINT
) LOWORD (wParam
);
3507 UINT flags
= (UINT
) HIWORD (wParam
);
3509 w32_menu_display_help (hwnd
, menu
, menu_item
, flags
);
3513 case WM_MEASUREITEM
:
3514 f
= x_window_to_frame (dpyinfo
, hwnd
);
3517 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
3519 if (pMis
->CtlType
== ODT_MENU
)
3521 /* Work out dimensions for popup menu titles. */
3522 char * title
= (char *) pMis
->itemData
;
3523 HDC hdc
= GetDC (hwnd
);
3524 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3525 LOGFONT menu_logfont
;
3529 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3530 menu_logfont
.lfWeight
= FW_BOLD
;
3531 menu_font
= CreateFontIndirect (&menu_logfont
);
3532 old_font
= SelectObject (hdc
, menu_font
);
3534 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
3537 if (unicode_append_menu
)
3538 GetTextExtentPoint32W (hdc
, (WCHAR
*) title
,
3539 wcslen ((WCHAR
*) title
),
3542 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
3544 pMis
->itemWidth
= size
.cx
;
3545 if (pMis
->itemHeight
< size
.cy
)
3546 pMis
->itemHeight
= size
.cy
;
3549 pMis
->itemWidth
= 0;
3551 SelectObject (hdc
, old_font
);
3552 DeleteObject (menu_font
);
3553 ReleaseDC (hwnd
, hdc
);
3560 f
= x_window_to_frame (dpyinfo
, hwnd
);
3563 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
3565 if (pDis
->CtlType
== ODT_MENU
)
3567 /* Draw popup menu title. */
3568 char * title
= (char *) pDis
->itemData
;
3571 HDC hdc
= pDis
->hDC
;
3572 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3573 LOGFONT menu_logfont
;
3576 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3577 menu_logfont
.lfWeight
= FW_BOLD
;
3578 menu_font
= CreateFontIndirect (&menu_logfont
);
3579 old_font
= SelectObject (hdc
, menu_font
);
3581 /* Always draw title as if not selected. */
3582 if (unicode_append_menu
)
3585 + GetSystemMetrics (SM_CXMENUCHECK
),
3587 ETO_OPAQUE
, &pDis
->rcItem
,
3589 wcslen ((WCHAR
*) title
), NULL
);
3593 + GetSystemMetrics (SM_CXMENUCHECK
),
3595 ETO_OPAQUE
, &pDis
->rcItem
,
3596 title
, strlen (title
), NULL
);
3598 SelectObject (hdc
, old_font
);
3599 DeleteObject (menu_font
);
3607 /* Still not right - can't distinguish between clicks in the
3608 client area of the frame from clicks forwarded from the scroll
3609 bars - may have to hook WM_NCHITTEST to remember the mouse
3610 position and then check if it is in the client area ourselves. */
3611 case WM_MOUSEACTIVATE
:
3612 /* Discard the mouse click that activates a frame, allowing the
3613 user to click anywhere without changing point (or worse!).
3614 Don't eat mouse clicks on scrollbars though!! */
3615 if (LOWORD (lParam
) == HTCLIENT
)
3616 return MA_ACTIVATEANDEAT
;
3621 /* No longer tracking mouse. */
3622 track_mouse_window
= NULL
;
3624 case WM_ACTIVATEAPP
:
3626 case WM_WINDOWPOSCHANGED
:
3628 /* Inform lisp thread that a frame might have just been obscured
3629 or exposed, so should recheck visibility of all frames. */
3630 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3634 dpyinfo
->faked_key
= 0;
3636 register_hot_keys (hwnd
);
3639 unregister_hot_keys (hwnd
);
3642 /* Relinquish the system caret. */
3643 if (w32_system_caret_hwnd
)
3645 w32_visible_system_caret_hwnd
= NULL
;
3646 w32_system_caret_hwnd
= NULL
;
3652 f
= x_window_to_frame (dpyinfo
, hwnd
);
3653 if (f
&& HIWORD (wParam
) == 0)
3655 if (menu_free_timer
)
3657 KillTimer (hwnd
, menu_free_timer
);
3658 menu_free_timer
= 0;
3664 wmsg
.dwModifiers
= w32_get_modifiers ();
3665 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3669 wmsg
.dwModifiers
= w32_get_modifiers ();
3670 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3673 case WM_WINDOWPOSCHANGING
:
3674 /* Don't restrict the sizing of tip frames. */
3675 if (hwnd
== tip_window
)
3679 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
3681 wp
.length
= sizeof (WINDOWPLACEMENT
);
3682 GetWindowPlacement (hwnd
, &wp
);
3684 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
3691 DWORD internal_border
;
3692 DWORD scrollbar_extra
;
3695 wp
.length
= sizeof(wp
);
3696 GetWindowRect (hwnd
, &wr
);
3700 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
3701 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
3702 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
3703 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
3707 memset (&rect
, 0, sizeof (rect
));
3708 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
3709 GetMenu (hwnd
) != NULL
);
3711 /* Force width and height of client area to be exact
3712 multiples of the character cell dimensions. */
3713 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
3714 - 2 * internal_border
- scrollbar_extra
)
3716 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
3717 - 2 * internal_border
)
3722 /* For right/bottom sizing we can just fix the sizes.
3723 However for top/left sizing we will need to fix the X
3724 and Y positions as well. */
3726 int cx_mintrack
= GetSystemMetrics (SM_CXMINTRACK
);
3727 int cy_mintrack
= GetSystemMetrics (SM_CYMINTRACK
);
3729 lppos
->cx
= max (lppos
->cx
- wdiff
, cx_mintrack
);
3730 lppos
->cy
= max (lppos
->cy
- hdiff
, cy_mintrack
);
3732 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
3733 && (lppos
->flags
& SWP_NOMOVE
) == 0)
3735 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
3742 lppos
->flags
|= SWP_NOMOVE
;
3753 case WM_GETMINMAXINFO
:
3754 /* Hack to allow resizing the Emacs frame above the screen size.
3755 Note that Windows 9x limits coordinates to 16-bits. */
3756 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.x
= 32767;
3757 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.y
= 32767;
3761 if (LOWORD (lParam
) == HTCLIENT
)
3766 case WM_EMACS_SETCURSOR
:
3768 Cursor cursor
= (Cursor
) wParam
;
3774 case WM_EMACS_CREATESCROLLBAR
:
3775 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
3776 (struct scroll_bar
*) lParam
);
3778 case WM_EMACS_SHOWWINDOW
:
3779 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
3781 case WM_EMACS_SETFOREGROUND
:
3783 HWND foreground_window
;
3784 DWORD foreground_thread
, retval
;
3786 /* On NT 5.0, and apparently Windows 98, it is necessary to
3787 attach to the thread that currently has focus in order to
3788 pull the focus away from it. */
3789 foreground_window
= GetForegroundWindow ();
3790 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
3791 if (!foreground_window
3792 || foreground_thread
== GetCurrentThreadId ()
3793 || !AttachThreadInput (GetCurrentThreadId (),
3794 foreground_thread
, TRUE
))
3795 foreground_thread
= 0;
3797 retval
= SetForegroundWindow ((HWND
) wParam
);
3799 /* Detach from the previous foreground thread. */
3800 if (foreground_thread
)
3801 AttachThreadInput (GetCurrentThreadId (),
3802 foreground_thread
, FALSE
);
3807 case WM_EMACS_SETWINDOWPOS
:
3809 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
3810 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
3811 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
3814 case WM_EMACS_DESTROYWINDOW
:
3815 DragAcceptFiles ((HWND
) wParam
, FALSE
);
3816 return DestroyWindow ((HWND
) wParam
);
3818 case WM_EMACS_HIDE_CARET
:
3819 return HideCaret (hwnd
);
3821 case WM_EMACS_SHOW_CARET
:
3822 return ShowCaret (hwnd
);
3824 case WM_EMACS_DESTROY_CARET
:
3825 w32_system_caret_hwnd
= NULL
;
3826 w32_visible_system_caret_hwnd
= NULL
;
3827 return DestroyCaret ();
3829 case WM_EMACS_TRACK_CARET
:
3830 /* If there is currently no system caret, create one. */
3831 if (w32_system_caret_hwnd
== NULL
)
3833 /* Use the default caret width, and avoid changing it
3834 unneccesarily, as it confuses screen reader software. */
3835 w32_system_caret_hwnd
= hwnd
;
3836 CreateCaret (hwnd
, NULL
, 0,
3837 w32_system_caret_height
);
3840 if (!SetCaretPos (w32_system_caret_x
, w32_system_caret_y
))
3842 /* Ensure visible caret gets turned on when requested. */
3843 else if (w32_use_visible_system_caret
3844 && w32_visible_system_caret_hwnd
!= hwnd
)
3846 w32_visible_system_caret_hwnd
= hwnd
;
3847 return ShowCaret (hwnd
);
3849 /* Ensure visible caret gets turned off when requested. */
3850 else if (!w32_use_visible_system_caret
3851 && w32_visible_system_caret_hwnd
)
3853 w32_visible_system_caret_hwnd
= NULL
;
3854 return HideCaret (hwnd
);
3859 case WM_EMACS_TRACKPOPUPMENU
:
3864 pos
= (POINT
*)lParam
;
3865 flags
= TPM_CENTERALIGN
;
3866 if (button_state
& LMOUSE
)
3867 flags
|= TPM_LEFTBUTTON
;
3868 else if (button_state
& RMOUSE
)
3869 flags
|= TPM_RIGHTBUTTON
;
3871 /* Remember we did a SetCapture on the initial mouse down event,
3872 so for safety, we make sure the capture is cancelled now. */
3876 /* Use menubar_active to indicate that WM_INITMENU is from
3877 TrackPopupMenu below, and should be ignored. */
3878 f
= x_window_to_frame (dpyinfo
, hwnd
);
3880 f
->output_data
.w32
->menubar_active
= 1;
3882 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
3886 /* Eat any mouse messages during popupmenu */
3887 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
3889 /* Get the menu selection, if any */
3890 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
3892 retval
= LOWORD (amsg
.wParam
);
3908 /* Check for messages registered at runtime. */
3909 if (msg
== msh_mousewheel
)
3911 wmsg
.dwModifiers
= w32_get_modifiers ();
3912 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3913 signal_user_input ();
3918 return DefWindowProc (hwnd
, msg
, wParam
, lParam
);
3922 /* The most common default return code for handled messages is 0. */
3927 my_create_window (f
)
3932 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
3934 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
3938 /* Create a tooltip window. Unlike my_create_window, we do not do this
3939 indirectly via the Window thread, as we do not need to process Window
3940 messages for the tooltip. Creating tooltips indirectly also creates
3941 deadlocks when tooltips are created for menu items. */
3943 my_create_tip_window (f
)
3948 rect
.left
= rect
.top
= 0;
3949 rect
.right
= FRAME_PIXEL_WIDTH (f
);
3950 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
3952 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
3953 FRAME_EXTERNAL_MENU_BAR (f
));
3955 tip_window
= FRAME_W32_WINDOW (f
)
3956 = CreateWindow (EMACS_CLASS
,
3958 f
->output_data
.w32
->dwStyle
,
3961 rect
.right
- rect
.left
,
3962 rect
.bottom
- rect
.top
,
3963 FRAME_W32_WINDOW (SELECTED_FRAME ()), /* owner */
3970 SetWindowLong (tip_window
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
3971 SetWindowLong (tip_window
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
3972 SetWindowLong (tip_window
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
3973 SetWindowLong (tip_window
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
3975 /* Tip frames have no scrollbars. */
3976 SetWindowLong (tip_window
, WND_SCROLLBAR_INDEX
, 0);
3978 /* Do this to discard the default setting specified by our parent. */
3979 ShowWindow (tip_window
, SW_HIDE
);
3984 /* Create and set up the w32 window for frame F. */
3987 w32_window (f
, window_prompting
, minibuffer_only
)
3989 long window_prompting
;
3990 int minibuffer_only
;
3994 /* Use the resource name as the top-level window name
3995 for looking up resources. Make a non-Lisp copy
3996 for the window manager, so GC relocation won't bother it.
3998 Elsewhere we specify the window name for the window manager. */
4001 char *str
= (char *) SDATA (Vx_resource_name
);
4002 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
4003 strcpy (f
->namebuf
, str
);
4006 my_create_window (f
);
4008 validate_x_resource_name ();
4010 /* x_set_name normally ignores requests to set the name if the
4011 requested name is the same as the current name. This is the one
4012 place where that assumption isn't correct; f->name is set, but
4013 the server hasn't been told. */
4016 int explicit = f
->explicit_name
;
4018 f
->explicit_name
= 0;
4021 x_set_name (f
, name
, explicit);
4026 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
4027 initialize_frame_menubar (f
);
4029 if (FRAME_W32_WINDOW (f
) == 0)
4030 error ("Unable to create window");
4033 /* Handle the icon stuff for this window. Perhaps later we might
4034 want an x_set_icon_position which can be called interactively as
4042 Lisp_Object icon_x
, icon_y
;
4044 /* Set the position of the icon. Note that Windows 95 groups all
4045 icons in the tray. */
4046 icon_x
= w32_get_arg (parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
4047 icon_y
= w32_get_arg (parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
4048 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
4050 CHECK_NUMBER (icon_x
);
4051 CHECK_NUMBER (icon_y
);
4053 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
4054 error ("Both left and top icon corners of icon must be specified");
4058 if (! EQ (icon_x
, Qunbound
))
4059 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
4062 /* Start up iconic or window? */
4063 x_wm_set_window_state
4064 (f
, (EQ (w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
4068 x_text_icon (f
, (char *) SDATA ((!NILP (f
->icon_name
)
4081 XGCValues gc_values
;
4085 /* Create the GC's of this frame.
4086 Note that many default values are used. */
4089 gc_values
.font
= FRAME_FONT (f
);
4091 /* Cursor has cursor-color background, background-color foreground. */
4092 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
4093 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
4094 f
->output_data
.w32
->cursor_gc
4095 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
4096 (GCFont
| GCForeground
| GCBackground
),
4100 f
->output_data
.w32
->white_relief
.gc
= 0;
4101 f
->output_data
.w32
->black_relief
.gc
= 0;
4107 /* Handler for signals raised during x_create_frame and
4108 x_create_top_frame. FRAME is the frame which is partially
4112 unwind_create_frame (frame
)
4115 struct frame
*f
= XFRAME (frame
);
4117 /* If frame is ``official'', nothing to do. */
4118 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
4121 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4124 x_free_frame_resources (f
);
4126 /* Check that reference counts are indeed correct. */
4127 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
4128 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
4136 #ifdef USE_FONT_BACKEND
4138 x_default_font_parameter (f
, parms
)
4142 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4143 Lisp_Object font
= x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font",
4146 if (!STRINGP (font
))
4149 static char *names
[]
4150 = { "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1",
4151 "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1",
4152 "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1",
4156 for (i
= 0; names
[i
]; i
++)
4158 font
= font_open_by_name (f
, names
[i
]);
4163 error ("No suitable font was found");
4165 x_default_parameter (f
, parms
, Qfont
, font
, "font", "Font", RES_TYPE_STRING
);
4169 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
4171 doc
: /* Make a new window, which is called a \"frame\" in Emacs terms.
4172 Returns an Emacs frame object.
4173 PARAMETERS is an alist of frame parameters.
4174 If the parameters specify that the frame should not have a minibuffer,
4175 and do not specify a specific minibuffer window to use,
4176 then `default-minibuffer-frame' must be a frame whose minibuffer can
4177 be shared by the new frame.
4179 This function is an internal primitive--use `make-frame' instead. */)
4181 Lisp_Object parameters
;
4184 Lisp_Object frame
, tem
;
4186 int minibuffer_only
= 0;
4187 long window_prompting
= 0;
4189 int count
= SPECPDL_INDEX ();
4190 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4191 Lisp_Object display
;
4192 struct w32_display_info
*dpyinfo
= NULL
;
4198 /* Use this general default value to start with
4199 until we know if this frame has a specified name. */
4200 Vx_resource_name
= Vinvocation_name
;
4202 display
= w32_get_arg (parameters
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
4203 if (EQ (display
, Qunbound
))
4205 dpyinfo
= check_x_display_info (display
);
4207 kb
= dpyinfo
->kboard
;
4209 kb
= &the_only_kboard
;
4212 name
= w32_get_arg (parameters
, Qname
, "name", "Name", RES_TYPE_STRING
);
4214 && ! EQ (name
, Qunbound
)
4216 error ("Invalid frame name--not a string or nil");
4219 Vx_resource_name
= name
;
4221 /* See if parent window is specified. */
4222 parent
= w32_get_arg (parameters
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
4223 if (EQ (parent
, Qunbound
))
4225 if (! NILP (parent
))
4226 CHECK_NUMBER (parent
);
4228 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
4229 /* No need to protect DISPLAY because that's not used after passing
4230 it to make_frame_without_minibuffer. */
4232 GCPRO4 (parameters
, parent
, name
, frame
);
4233 tem
= w32_get_arg (parameters
, Qminibuffer
, "minibuffer", "Minibuffer",
4235 if (EQ (tem
, Qnone
) || NILP (tem
))
4236 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
4237 else if (EQ (tem
, Qonly
))
4239 f
= make_minibuffer_frame ();
4240 minibuffer_only
= 1;
4242 else if (WINDOWP (tem
))
4243 f
= make_frame_without_minibuffer (tem
, kb
, display
);
4247 XSETFRAME (frame
, f
);
4249 /* Note that Windows does support scroll bars. */
4250 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
4252 /* By default, make scrollbars the system standard width. */
4253 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
4255 f
->output_method
= output_w32
;
4256 f
->output_data
.w32
=
4257 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
4258 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
4259 FRAME_FONTSET (f
) = -1;
4260 record_unwind_protect (unwind_create_frame
, frame
);
4263 = w32_get_arg (parameters
, Qicon_name
, "iconName", "Title", RES_TYPE_STRING
);
4264 if (! STRINGP (f
->icon_name
))
4265 f
->icon_name
= Qnil
;
4267 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
4269 FRAME_KBOARD (f
) = kb
;
4272 /* Specify the parent under which to make this window. */
4276 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
4277 f
->output_data
.w32
->explicit_parent
= 1;
4281 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4282 f
->output_data
.w32
->explicit_parent
= 0;
4285 /* Set the name; the functions to which we pass f expect the name to
4287 if (EQ (name
, Qunbound
) || NILP (name
))
4289 f
->name
= build_string (dpyinfo
->w32_id_name
);
4290 f
->explicit_name
= 0;
4295 f
->explicit_name
= 1;
4296 /* use the frame's title when getting resources for this frame. */
4297 specbind (Qx_resource_name
, name
);
4300 #ifdef USE_FONT_BACKEND
4301 if (enable_font_backend
)
4303 /* Perhaps, we must allow frame parameter, say `font-backend',
4304 to specify which font backends to use. */
4305 register_font_driver (&w32font_driver
, f
);
4307 x_default_parameter (f
, parameters
, Qfont_backend
, Qnil
,
4308 "fontBackend", "FontBackend", RES_TYPE_STRING
);
4310 #endif /* USE_FONT_BACKEND */
4312 /* Extract the window parameters from the supplied values
4313 that are needed to determine window geometry. */
4314 #ifdef USE_FONT_BACKEND
4315 if (enable_font_backend
)
4316 x_default_font_parameter (f
, parameters
);
4322 font
= w32_get_arg (parameters
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4325 /* First, try whatever font the caller has specified. */
4328 tem
= Fquery_fontset (font
, Qnil
);
4330 font
= x_new_fontset (f
, tem
);
4332 font
= x_new_font (f
, SDATA (font
));
4334 /* Try out a font which we hope has bold and italic variations. */
4335 if (!STRINGP (font
))
4336 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
4337 if (! STRINGP (font
))
4338 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
4339 /* If those didn't work, look for something which will at least work. */
4340 if (! STRINGP (font
))
4341 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
4343 if (! STRINGP (font
))
4344 font
= build_string ("Fixedsys");
4346 x_default_parameter (f
, parameters
, Qfont
, font
,
4347 "font", "Font", RES_TYPE_STRING
);
4350 x_default_parameter (f
, parameters
, Qborder_width
, make_number (2),
4351 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4352 /* This defaults to 2 in order to match xterm. We recognize either
4353 internalBorderWidth or internalBorder (which is what xterm calls
4355 if (NILP (Fassq (Qinternal_border_width
, parameters
)))
4359 value
= w32_get_arg (parameters
, Qinternal_border_width
,
4360 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
4361 if (! EQ (value
, Qunbound
))
4362 parameters
= Fcons (Fcons (Qinternal_border_width
, value
),
4365 /* Default internalBorderWidth to 0 on Windows to match other programs. */
4366 x_default_parameter (f
, parameters
, Qinternal_border_width
, make_number (0),
4367 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
4368 x_default_parameter (f
, parameters
, Qvertical_scroll_bars
, Qright
,
4369 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
4371 /* Also do the stuff which must be set before the window exists. */
4372 x_default_parameter (f
, parameters
, Qforeground_color
, build_string ("black"),
4373 "foreground", "Foreground", RES_TYPE_STRING
);
4374 x_default_parameter (f
, parameters
, Qbackground_color
, build_string ("white"),
4375 "background", "Background", RES_TYPE_STRING
);
4376 x_default_parameter (f
, parameters
, Qmouse_color
, build_string ("black"),
4377 "pointerColor", "Foreground", RES_TYPE_STRING
);
4378 x_default_parameter (f
, parameters
, Qcursor_color
, build_string ("black"),
4379 "cursorColor", "Foreground", RES_TYPE_STRING
);
4380 x_default_parameter (f
, parameters
, Qborder_color
, build_string ("black"),
4381 "borderColor", "BorderColor", RES_TYPE_STRING
);
4382 x_default_parameter (f
, parameters
, Qscreen_gamma
, Qnil
,
4383 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
4384 x_default_parameter (f
, parameters
, Qline_spacing
, Qnil
,
4385 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
4386 x_default_parameter (f
, parameters
, Qleft_fringe
, Qnil
,
4387 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
4388 x_default_parameter (f
, parameters
, Qright_fringe
, Qnil
,
4389 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
4392 /* Init faces before x_default_parameter is called for scroll-bar
4393 parameters because that function calls x_set_scroll_bar_width,
4394 which calls change_frame_size, which calls Fset_window_buffer,
4395 which runs hooks, which call Fvertical_motion. At the end, we
4396 end up in init_iterator with a null face cache, which should not
4398 init_frame_faces (f
);
4400 x_default_parameter (f
, parameters
, Qmenu_bar_lines
, make_number (1),
4401 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
4402 x_default_parameter (f
, parameters
, Qtool_bar_lines
, make_number (1),
4403 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
4405 x_default_parameter (f
, parameters
, Qbuffer_predicate
, Qnil
,
4406 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
4407 x_default_parameter (f
, parameters
, Qtitle
, Qnil
,
4408 "title", "Title", RES_TYPE_STRING
);
4409 x_default_parameter (f
, parameters
, Qfullscreen
, Qnil
,
4410 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
4412 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
4413 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4415 f
->output_data
.w32
->text_cursor
= w32_load_cursor (IDC_IBEAM
);
4416 f
->output_data
.w32
->nontext_cursor
= w32_load_cursor (IDC_ARROW
);
4417 f
->output_data
.w32
->modeline_cursor
= w32_load_cursor (IDC_ARROW
);
4418 f
->output_data
.w32
->hand_cursor
= w32_load_cursor (IDC_HAND
);
4419 f
->output_data
.w32
->hourglass_cursor
= w32_load_cursor (IDC_WAIT
);
4420 f
->output_data
.w32
->horizontal_drag_cursor
= w32_load_cursor (IDC_SIZEWE
);
4422 window_prompting
= x_figure_window_size (f
, parameters
, 1);
4424 tem
= w32_get_arg (parameters
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
4425 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
4427 w32_window (f
, window_prompting
, minibuffer_only
);
4428 x_icon (f
, parameters
);
4432 /* Now consider the frame official. */
4433 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
4434 Vframe_list
= Fcons (frame
, Vframe_list
);
4436 /* We need to do this after creating the window, so that the
4437 icon-creation functions can say whose icon they're describing. */
4438 x_default_parameter (f
, parameters
, Qicon_type
, Qnil
,
4439 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
4441 x_default_parameter (f
, parameters
, Qauto_raise
, Qnil
,
4442 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4443 x_default_parameter (f
, parameters
, Qauto_lower
, Qnil
,
4444 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4445 x_default_parameter (f
, parameters
, Qcursor_type
, Qbox
,
4446 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4447 x_default_parameter (f
, parameters
, Qscroll_bar_width
, Qnil
,
4448 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
4450 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4451 Change will not be effected unless different from the current
4453 width
= FRAME_COLS (f
);
4454 height
= FRAME_LINES (f
);
4456 FRAME_LINES (f
) = 0;
4457 SET_FRAME_COLS (f
, 0);
4458 change_frame_size (f
, height
, width
, 1, 0, 0);
4460 /* Tell the server what size and position, etc, we want, and how
4461 badly we want them. This should be done after we have the menu
4462 bar so that its size can be taken into account. */
4464 x_wm_set_size_hint (f
, window_prompting
, 0);
4467 /* Make the window appear on the frame and enable display, unless
4468 the caller says not to. However, with explicit parent, Emacs
4469 cannot control visibility, so don't try. */
4470 if (! f
->output_data
.w32
->explicit_parent
)
4472 Lisp_Object visibility
;
4474 visibility
= w32_get_arg (parameters
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
4475 if (EQ (visibility
, Qunbound
))
4478 if (EQ (visibility
, Qicon
))
4479 x_iconify_frame (f
);
4480 else if (! NILP (visibility
))
4481 x_make_frame_visible (f
);
4483 /* Must have been Qnil. */
4488 /* Make sure windows on this frame appear in calls to next-window
4489 and similar functions. */
4490 Vwindow_list
= Qnil
;
4492 return unbind_to (count
, frame
);
4495 /* FRAME is used only to get a handle on the X display. We don't pass the
4496 display info directly because we're called from frame.c, which doesn't
4497 know about that structure. */
4499 x_get_focus_frame (frame
)
4500 struct frame
*frame
;
4502 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
4504 if (! dpyinfo
->w32_focus_frame
)
4507 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
4511 DEFUN ("w32-focus-frame", Fw32_focus_frame
, Sw32_focus_frame
, 1, 1, 0,
4512 doc
: /* Give FRAME input focus, raising to foreground if necessary. */)
4516 x_focus_on_frame (check_x_frame (frame
));
4521 /* Return the charset portion of a font name. */
4522 char * xlfd_charset_of_font (char * fontname
)
4524 char *charset
, *encoding
;
4526 encoding
= strrchr(fontname
, '-');
4527 if (!encoding
|| encoding
== fontname
)
4530 for (charset
= encoding
- 1; charset
>= fontname
; charset
--)
4531 if (*charset
== '-')
4534 if (charset
== fontname
|| strcmp(charset
, "-*-*") == 0)
4540 struct font_info
*w32_load_bdf_font (struct frame
*f
, char *fontname
,
4541 int size
, char* filename
);
4542 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
);
4543 static BOOL
w32_to_x_font (LOGFONT
* lplf
, char * lpxstr
, int len
,
4545 static BOOL
x_to_w32_font (char *lpxstr
, LOGFONT
*lplogfont
);
4547 static struct font_info
*
4548 w32_load_system_font (f
,fontname
,size
)
4553 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4554 Lisp_Object font_names
;
4556 /* Get a list of all the fonts that match this name. Once we
4557 have a list of matching fonts, we compare them against the fonts
4558 we already have loaded by comparing names. */
4559 font_names
= w32_list_fonts (f
, build_string (fontname
), size
, 100);
4561 if (!NILP (font_names
))
4566 /* First check if any are already loaded, as that is cheaper
4567 than loading another one. */
4568 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
4569 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
4570 if (dpyinfo
->font_table
[i
].name
4571 && (!strcmp (dpyinfo
->font_table
[i
].name
,
4572 SDATA (XCAR (tail
)))
4573 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
4574 SDATA (XCAR (tail
)))))
4575 return (dpyinfo
->font_table
+ i
);
4577 fontname
= (char *) SDATA (XCAR (font_names
));
4579 else if (w32_strict_fontnames
)
4581 /* If EnumFontFamiliesEx was available, we got a full list of
4582 fonts back so stop now to avoid the possibility of loading a
4583 random font. If we had to fall back to EnumFontFamilies, the
4584 list is incomplete, so continue whether the font we want was
4586 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
4587 FARPROC enum_font_families_ex
4588 = GetProcAddress (gdi32
, "EnumFontFamiliesExA");
4589 if (enum_font_families_ex
)
4593 /* Load the font and add it to the table. */
4595 char *full_name
, *encoding
, *charset
;
4597 struct font_info
*fontp
;
4603 if (!fontname
|| !x_to_w32_font (fontname
, &lf
))
4606 if (!*lf
.lfFaceName
)
4607 /* If no name was specified for the font, we get a random font
4608 from CreateFontIndirect - this is not particularly
4609 desirable, especially since CreateFontIndirect does not
4610 fill out the missing name in lf, so we never know what we
4614 lf
.lfQuality
= DEFAULT_QUALITY
;
4616 font
= (XFontStruct
*) xmalloc (sizeof (XFontStruct
));
4617 bzero (font
, sizeof (*font
));
4619 /* Set bdf to NULL to indicate that this is a Windows font. */
4624 font
->hfont
= CreateFontIndirect (&lf
);
4626 if (font
->hfont
== NULL
)
4635 codepage
= w32_codepage_for_font (fontname
);
4637 hdc
= GetDC (dpyinfo
->root_window
);
4638 oldobj
= SelectObject (hdc
, font
->hfont
);
4640 ok
= GetTextMetrics (hdc
, &font
->tm
);
4641 if (codepage
== CP_UNICODE
)
4642 font
->double_byte_p
= 1;
4645 /* Unfortunately, some fonts (eg. MingLiU, a big5 ttf font)
4646 don't report themselves as double byte fonts, when
4647 patently they are. So instead of trusting
4648 GetFontLanguageInfo, we check the properties of the
4649 codepage directly, since that is ultimately what we are
4650 working from anyway. */
4651 /* font->double_byte_p = GetFontLanguageInfo(hdc) & GCP_DBCS; */
4653 GetCPInfo (codepage
, &cpi
);
4654 font
->double_byte_p
= cpi
.MaxCharSize
> 1;
4657 SelectObject (hdc
, oldobj
);
4658 ReleaseDC (dpyinfo
->root_window
, hdc
);
4659 /* Fill out details in lf according to the font that was
4661 lf
.lfHeight
= font
->tm
.tmInternalLeading
- font
->tm
.tmHeight
;
4662 lf
.lfWidth
= font
->tm
.tmMaxCharWidth
;
4663 lf
.lfWeight
= font
->tm
.tmWeight
;
4664 lf
.lfItalic
= font
->tm
.tmItalic
;
4665 lf
.lfCharSet
= font
->tm
.tmCharSet
;
4666 lf
.lfPitchAndFamily
= ((font
->tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
)
4667 ? VARIABLE_PITCH
: FIXED_PITCH
);
4668 lf
.lfOutPrecision
= ((font
->tm
.tmPitchAndFamily
& TMPF_VECTOR
)
4669 ? OUT_STROKE_PRECIS
: OUT_STRING_PRECIS
);
4671 w32_cache_char_metrics (font
);
4678 w32_unload_font (dpyinfo
, font
);
4682 /* Find a free slot in the font table. */
4683 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
4684 if (dpyinfo
->font_table
[i
].name
== NULL
)
4687 /* If no free slot found, maybe enlarge the font table. */
4688 if (i
== dpyinfo
->n_fonts
4689 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
4692 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
4693 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
4695 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
4698 fontp
= dpyinfo
->font_table
+ i
;
4699 if (i
== dpyinfo
->n_fonts
)
4702 /* Now fill in the slots of *FONTP. */
4704 bzero (fontp
, sizeof (*fontp
));
4706 fontp
->font_idx
= i
;
4707 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
4708 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
4710 if ((lf
.lfPitchAndFamily
& 0x03) == FIXED_PITCH
)
4712 /* Fixed width font. */
4713 fontp
->average_width
= fontp
->space_width
= FONT_WIDTH (font
);
4719 pcm
= w32_per_char_metric (font
, &space
, ANSI_FONT
);
4721 fontp
->space_width
= pcm
->width
;
4723 fontp
->space_width
= FONT_WIDTH (font
);
4725 fontp
->average_width
= font
->tm
.tmAveCharWidth
;
4728 fontp
->charset
= -1;
4729 charset
= xlfd_charset_of_font (fontname
);
4731 /* Cache the W32 codepage for a font. This makes w32_encode_char
4732 (called for every glyph during redisplay) much faster. */
4733 fontp
->codepage
= codepage
;
4735 /* Work out the font's full name. */
4736 full_name
= (char *)xmalloc (100);
4737 if (full_name
&& w32_to_x_font (&lf
, full_name
, 100, charset
))
4738 fontp
->full_name
= full_name
;
4741 /* If all else fails - just use the name we used to load it. */
4743 fontp
->full_name
= fontp
->name
;
4746 fontp
->size
= FONT_WIDTH (font
);
4747 fontp
->height
= FONT_HEIGHT (font
);
4749 /* The slot `encoding' specifies how to map a character
4750 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
4751 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
4752 (0:0x20..0x7F, 1:0xA0..0xFF,
4753 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
4754 2:0xA020..0xFF7F). For the moment, we don't know which charset
4755 uses this font. So, we set information in fontp->encoding_type
4756 which is never used by any charset. If mapping can't be
4757 decided, set FONT_ENCODING_NOT_DECIDED. */
4759 /* SJIS fonts need to be set to type 4, all others seem to work as
4760 type FONT_ENCODING_NOT_DECIDED. */
4761 encoding
= strrchr (fontp
->name
, '-');
4762 if (encoding
&& strnicmp (encoding
+1, "sjis", 4) == 0)
4763 fontp
->encoding_type
= 4;
4765 fontp
->encoding_type
= FONT_ENCODING_NOT_DECIDED
;
4767 /* The following three values are set to 0 under W32, which is
4768 what they get set to if XGetFontProperty fails under X. */
4769 fontp
->baseline_offset
= 0;
4770 fontp
->relative_compose
= 0;
4771 fontp
->default_ascent
= 0;
4773 /* Set global flag fonts_changed_p to non-zero if the font loaded
4774 has a character with a smaller width than any other character
4775 before, or if the font loaded has a smaller height than any
4776 other font loaded before. If this happens, it will make a
4777 glyph matrix reallocation necessary. */
4778 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
4784 /* Load font named FONTNAME of size SIZE for frame F, and return a
4785 pointer to the structure font_info while allocating it dynamically.
4786 If loading fails, return NULL. */
4788 w32_load_font (f
,fontname
,size
)
4793 Lisp_Object bdf_fonts
;
4794 struct font_info
*retval
= NULL
;
4795 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4797 bdf_fonts
= w32_list_bdf_fonts (build_string (fontname
), 1);
4799 while (!retval
&& CONSP (bdf_fonts
))
4801 char *bdf_name
, *bdf_file
;
4802 Lisp_Object bdf_pair
;
4805 bdf_name
= SDATA (XCAR (bdf_fonts
));
4806 bdf_pair
= Fassoc (XCAR (bdf_fonts
), Vw32_bdf_filename_alist
);
4807 bdf_file
= SDATA (XCDR (bdf_pair
));
4809 // If the font is already loaded, do not load it again.
4810 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
4812 if ((dpyinfo
->font_table
[i
].name
4813 && !strcmp (dpyinfo
->font_table
[i
].name
, bdf_name
))
4814 || (dpyinfo
->font_table
[i
].full_name
4815 && !strcmp (dpyinfo
->font_table
[i
].full_name
, bdf_name
)))
4816 return dpyinfo
->font_table
+ i
;
4819 retval
= w32_load_bdf_font (f
, bdf_name
, size
, bdf_file
);
4821 bdf_fonts
= XCDR (bdf_fonts
);
4827 return w32_load_system_font(f
, fontname
, size
);
4832 w32_unload_font (dpyinfo
, font
)
4833 struct w32_display_info
*dpyinfo
;
4838 if (font
->per_char
) xfree (font
->per_char
);
4839 if (font
->bdf
) w32_free_bdf_font (font
->bdf
);
4841 if (font
->hfont
) DeleteObject(font
->hfont
);
4846 /* The font conversion stuff between x and w32 */
4848 /* X font string is as follows (from faces.el)
4852 * (weight "\\(bold\\|demibold\\|medium\\)") ; 1
4853 * (weight\? "\\([^-]*\\)") ; 1
4854 * (slant "\\([ior]\\)") ; 2
4855 * (slant\? "\\([^-]?\\)") ; 2
4856 * (swidth "\\([^-]*\\)") ; 3
4857 * (adstyle "[^-]*") ; 4
4858 * (pixelsize "[0-9]+")
4859 * (pointsize "[0-9][0-9]+")
4860 * (resx "[0-9][0-9]+")
4861 * (resy "[0-9][0-9]+")
4862 * (spacing "[cmp?*]")
4863 * (avgwidth "[0-9]+")
4864 * (registry "[^-]+")
4865 * (encoding "[^-]+")
4870 x_to_w32_weight (lpw
)
4873 if (!lpw
) return (FW_DONTCARE
);
4875 if (stricmp (lpw
,"heavy") == 0) return FW_HEAVY
;
4876 else if (stricmp (lpw
,"extrabold") == 0) return FW_EXTRABOLD
;
4877 else if (stricmp (lpw
,"bold") == 0) return FW_BOLD
;
4878 else if (stricmp (lpw
,"demibold") == 0) return FW_SEMIBOLD
;
4879 else if (stricmp (lpw
,"semibold") == 0) return FW_SEMIBOLD
;
4880 else if (stricmp (lpw
,"medium") == 0) return FW_MEDIUM
;
4881 else if (stricmp (lpw
,"normal") == 0) return FW_NORMAL
;
4882 else if (stricmp (lpw
,"light") == 0) return FW_LIGHT
;
4883 else if (stricmp (lpw
,"extralight") == 0) return FW_EXTRALIGHT
;
4884 else if (stricmp (lpw
,"thin") == 0) return FW_THIN
;
4891 w32_to_x_weight (fnweight
)
4894 if (fnweight
>= FW_HEAVY
) return "heavy";
4895 if (fnweight
>= FW_EXTRABOLD
) return "extrabold";
4896 if (fnweight
>= FW_BOLD
) return "bold";
4897 if (fnweight
>= FW_SEMIBOLD
) return "demibold";
4898 if (fnweight
>= FW_MEDIUM
) return "medium";
4899 if (fnweight
>= FW_NORMAL
) return "normal";
4900 if (fnweight
>= FW_LIGHT
) return "light";
4901 if (fnweight
>= FW_EXTRALIGHT
) return "extralight";
4902 if (fnweight
>= FW_THIN
) return "thin";
4908 x_to_w32_charset (lpcs
)
4911 Lisp_Object this_entry
, w32_charset
;
4913 int len
= strlen (lpcs
);
4915 /* Support "*-#nnn" format for unknown charsets. */
4916 if (strncmp (lpcs
, "*-#", 3) == 0)
4917 return atoi (lpcs
+ 3);
4919 /* All Windows fonts qualify as unicode. */
4920 if (!strncmp (lpcs
, "iso10646", 8))
4921 return DEFAULT_CHARSET
;
4923 /* Handle wildcards by ignoring them; eg. treat "big5*-*" as "big5". */
4924 charset
= alloca (len
+ 1);
4925 strcpy (charset
, lpcs
);
4926 lpcs
= strchr (charset
, '*');
4930 /* Look through w32-charset-info-alist for the character set.
4931 Format of each entry is
4932 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
4934 this_entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
4936 if (NILP(this_entry
))
4938 /* At startup, we want iso8859-1 fonts to come up properly. */
4939 if (stricmp(charset
, "iso8859-1") == 0)
4940 return ANSI_CHARSET
;
4942 return DEFAULT_CHARSET
;
4945 w32_charset
= Fcar (Fcdr (this_entry
));
4947 /* Translate Lisp symbol to number. */
4948 if (EQ (w32_charset
, Qw32_charset_ansi
))
4949 return ANSI_CHARSET
;
4950 if (EQ (w32_charset
, Qw32_charset_symbol
))
4951 return SYMBOL_CHARSET
;
4952 if (EQ (w32_charset
, Qw32_charset_shiftjis
))
4953 return SHIFTJIS_CHARSET
;
4954 if (EQ (w32_charset
, Qw32_charset_hangeul
))
4955 return HANGEUL_CHARSET
;
4956 if (EQ (w32_charset
, Qw32_charset_chinesebig5
))
4957 return CHINESEBIG5_CHARSET
;
4958 if (EQ (w32_charset
, Qw32_charset_gb2312
))
4959 return GB2312_CHARSET
;
4960 if (EQ (w32_charset
, Qw32_charset_oem
))
4962 #ifdef JOHAB_CHARSET
4963 if (EQ (w32_charset
, Qw32_charset_johab
))
4964 return JOHAB_CHARSET
;
4965 if (EQ (w32_charset
, Qw32_charset_easteurope
))
4966 return EASTEUROPE_CHARSET
;
4967 if (EQ (w32_charset
, Qw32_charset_turkish
))
4968 return TURKISH_CHARSET
;
4969 if (EQ (w32_charset
, Qw32_charset_baltic
))
4970 return BALTIC_CHARSET
;
4971 if (EQ (w32_charset
, Qw32_charset_russian
))
4972 return RUSSIAN_CHARSET
;
4973 if (EQ (w32_charset
, Qw32_charset_arabic
))
4974 return ARABIC_CHARSET
;
4975 if (EQ (w32_charset
, Qw32_charset_greek
))
4976 return GREEK_CHARSET
;
4977 if (EQ (w32_charset
, Qw32_charset_hebrew
))
4978 return HEBREW_CHARSET
;
4979 if (EQ (w32_charset
, Qw32_charset_vietnamese
))
4980 return VIETNAMESE_CHARSET
;
4981 if (EQ (w32_charset
, Qw32_charset_thai
))
4982 return THAI_CHARSET
;
4983 if (EQ (w32_charset
, Qw32_charset_mac
))
4985 #endif /* JOHAB_CHARSET */
4986 #ifdef UNICODE_CHARSET
4987 if (EQ (w32_charset
, Qw32_charset_unicode
))
4988 return UNICODE_CHARSET
;
4991 return DEFAULT_CHARSET
;
4996 w32_to_x_charset (fncharset
, matching
)
5000 static char buf
[32];
5001 Lisp_Object charset_type
;
5006 /* If fully specified, accept it as it is. Otherwise use a
5008 char *wildcard
= strchr (matching
, '*');
5011 else if (strchr (matching
, '-'))
5014 match_len
= strlen (matching
);
5020 /* Handle startup case of w32-charset-info-alist not
5021 being set up yet. */
5022 if (NILP(Vw32_charset_info_alist
))
5024 charset_type
= Qw32_charset_ansi
;
5026 case DEFAULT_CHARSET
:
5027 charset_type
= Qw32_charset_default
;
5029 case SYMBOL_CHARSET
:
5030 charset_type
= Qw32_charset_symbol
;
5032 case SHIFTJIS_CHARSET
:
5033 charset_type
= Qw32_charset_shiftjis
;
5035 case HANGEUL_CHARSET
:
5036 charset_type
= Qw32_charset_hangeul
;
5038 case GB2312_CHARSET
:
5039 charset_type
= Qw32_charset_gb2312
;
5041 case CHINESEBIG5_CHARSET
:
5042 charset_type
= Qw32_charset_chinesebig5
;
5045 charset_type
= Qw32_charset_oem
;
5048 /* More recent versions of Windows (95 and NT4.0) define more
5050 #ifdef EASTEUROPE_CHARSET
5051 case EASTEUROPE_CHARSET
:
5052 charset_type
= Qw32_charset_easteurope
;
5054 case TURKISH_CHARSET
:
5055 charset_type
= Qw32_charset_turkish
;
5057 case BALTIC_CHARSET
:
5058 charset_type
= Qw32_charset_baltic
;
5060 case RUSSIAN_CHARSET
:
5061 charset_type
= Qw32_charset_russian
;
5063 case ARABIC_CHARSET
:
5064 charset_type
= Qw32_charset_arabic
;
5067 charset_type
= Qw32_charset_greek
;
5069 case HEBREW_CHARSET
:
5070 charset_type
= Qw32_charset_hebrew
;
5072 case VIETNAMESE_CHARSET
:
5073 charset_type
= Qw32_charset_vietnamese
;
5076 charset_type
= Qw32_charset_thai
;
5079 charset_type
= Qw32_charset_mac
;
5082 charset_type
= Qw32_charset_johab
;
5086 #ifdef UNICODE_CHARSET
5087 case UNICODE_CHARSET
:
5088 charset_type
= Qw32_charset_unicode
;
5092 /* Encode numerical value of unknown charset. */
5093 sprintf (buf
, "*-#%u", fncharset
);
5099 char * best_match
= NULL
;
5100 int matching_found
= 0;
5102 /* Look through w32-charset-info-alist for the character set.
5103 Prefer ISO codepages, and prefer lower numbers in the ISO
5104 range. Only return charsets for codepages which are installed.
5106 Format of each entry is
5107 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5109 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
5112 Lisp_Object w32_charset
;
5113 Lisp_Object codepage
;
5115 Lisp_Object this_entry
= XCAR (rest
);
5117 /* Skip invalid entries in alist. */
5118 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
5119 || !CONSP (XCDR (this_entry
))
5120 || !SYMBOLP (XCAR (XCDR (this_entry
))))
5123 x_charset
= SDATA (XCAR (this_entry
));
5124 w32_charset
= XCAR (XCDR (this_entry
));
5125 codepage
= XCDR (XCDR (this_entry
));
5127 /* Look for Same charset and a valid codepage (or non-int
5128 which means ignore). */
5129 if (EQ (w32_charset
, charset_type
)
5130 && (!INTEGERP (codepage
) || XINT (codepage
) == CP_DEFAULT
5131 || IsValidCodePage (XINT (codepage
))))
5133 /* If we don't have a match already, then this is the
5137 best_match
= x_charset
;
5138 if (matching
&& !strnicmp (x_charset
, matching
, match_len
))
5141 /* If we already found a match for MATCHING, then
5142 only consider other matches. */
5143 else if (matching_found
5144 && strnicmp (x_charset
, matching
, match_len
))
5146 /* If this matches what we want, and the best so far doesn't,
5147 then this is better. */
5148 else if (!matching_found
&& matching
5149 && !strnicmp (x_charset
, matching
, match_len
))
5151 best_match
= x_charset
;
5154 /* If this is fully specified, and the best so far isn't,
5155 then this is better. */
5156 else if ((!strchr (best_match
, '-') && strchr (x_charset
, '-'))
5157 /* If this is an ISO codepage, and the best so far isn't,
5158 then this is better, but only if it fully specifies the
5160 || (strnicmp (best_match
, "iso", 3) != 0
5161 && strnicmp (x_charset
, "iso", 3) == 0
5162 && strchr (x_charset
, '-')))
5163 best_match
= x_charset
;
5164 /* If both are ISO8859 codepages, choose the one with the
5165 lowest number in the encoding field. */
5166 else if (strnicmp (best_match
, "iso8859-", 8) == 0
5167 && strnicmp (x_charset
, "iso8859-", 8) == 0)
5169 int best_enc
= atoi (best_match
+ 8);
5170 int this_enc
= atoi (x_charset
+ 8);
5171 if (this_enc
> 0 && this_enc
< best_enc
)
5172 best_match
= x_charset
;
5177 /* If no match, encode the numeric value. */
5180 sprintf (buf
, "*-#%u", fncharset
);
5184 strncpy (buf
, best_match
, 31);
5185 /* If the charset is not fully specified, put -0 on the end. */
5186 if (!strchr (best_match
, '-'))
5188 int pos
= strlen (best_match
);
5189 /* Charset specifiers shouldn't be very long. If it is a made
5190 up one, truncating it should not do any harm since it isn't
5191 recognized anyway. */
5194 strcpy (buf
+ pos
, "-0");
5202 /* Return all the X charsets that map to a font. */
5204 w32_to_all_x_charsets (fncharset
)
5207 static char buf
[32];
5208 Lisp_Object charset_type
;
5209 Lisp_Object retval
= Qnil
;
5214 /* Handle startup case of w32-charset-info-alist not
5215 being set up yet. */
5216 if (NILP(Vw32_charset_info_alist
))
5217 return Fcons (build_string ("iso8859-1"), Qnil
);
5219 charset_type
= Qw32_charset_ansi
;
5221 case DEFAULT_CHARSET
:
5222 charset_type
= Qw32_charset_default
;
5224 case SYMBOL_CHARSET
:
5225 charset_type
= Qw32_charset_symbol
;
5227 case SHIFTJIS_CHARSET
:
5228 charset_type
= Qw32_charset_shiftjis
;
5230 case HANGEUL_CHARSET
:
5231 charset_type
= Qw32_charset_hangeul
;
5233 case GB2312_CHARSET
:
5234 charset_type
= Qw32_charset_gb2312
;
5236 case CHINESEBIG5_CHARSET
:
5237 charset_type
= Qw32_charset_chinesebig5
;
5240 charset_type
= Qw32_charset_oem
;
5243 /* More recent versions of Windows (95 and NT4.0) define more
5245 #ifdef EASTEUROPE_CHARSET
5246 case EASTEUROPE_CHARSET
:
5247 charset_type
= Qw32_charset_easteurope
;
5249 case TURKISH_CHARSET
:
5250 charset_type
= Qw32_charset_turkish
;
5252 case BALTIC_CHARSET
:
5253 charset_type
= Qw32_charset_baltic
;
5255 case RUSSIAN_CHARSET
:
5256 charset_type
= Qw32_charset_russian
;
5258 case ARABIC_CHARSET
:
5259 charset_type
= Qw32_charset_arabic
;
5262 charset_type
= Qw32_charset_greek
;
5264 case HEBREW_CHARSET
:
5265 charset_type
= Qw32_charset_hebrew
;
5267 case VIETNAMESE_CHARSET
:
5268 charset_type
= Qw32_charset_vietnamese
;
5271 charset_type
= Qw32_charset_thai
;
5274 charset_type
= Qw32_charset_mac
;
5277 charset_type
= Qw32_charset_johab
;
5281 #ifdef UNICODE_CHARSET
5282 case UNICODE_CHARSET
:
5283 charset_type
= Qw32_charset_unicode
;
5287 /* Encode numerical value of unknown charset. */
5288 sprintf (buf
, "*-#%u", fncharset
);
5289 return Fcons (build_string (buf
), Qnil
);
5294 /* Look through w32-charset-info-alist for the character set.
5295 Only return fully specified charsets for codepages which are
5298 Format of each entry in Vw32_charset_info_alist is
5299 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5301 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
5303 Lisp_Object x_charset
;
5304 Lisp_Object w32_charset
;
5305 Lisp_Object codepage
;
5307 Lisp_Object this_entry
= XCAR (rest
);
5309 /* Skip invalid entries in alist. */
5310 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
5311 || !CONSP (XCDR (this_entry
))
5312 || !SYMBOLP (XCAR (XCDR (this_entry
))))
5315 x_charset
= XCAR (this_entry
);
5316 w32_charset
= XCAR (XCDR (this_entry
));
5317 codepage
= XCDR (XCDR (this_entry
));
5319 if (!strchr (SDATA (x_charset
), '-'))
5322 /* Look for Same charset and a valid codepage (or non-int
5323 which means ignore). */
5324 if (EQ (w32_charset
, charset_type
)
5325 && (!INTEGERP (codepage
) || XINT (codepage
) == CP_DEFAULT
5326 || IsValidCodePage (XINT (codepage
))))
5328 retval
= Fcons (x_charset
, retval
);
5332 /* If no match, encode the numeric value. */
5335 sprintf (buf
, "*-#%u", fncharset
);
5336 return Fcons (build_string (buf
), Qnil
);
5343 /* Get the Windows codepage corresponding to the specified font. The
5344 charset info in the font name is used to look up
5345 w32-charset-to-codepage-alist. */
5347 w32_codepage_for_font (char *fontname
)
5349 Lisp_Object codepage
, entry
;
5350 char *charset_str
, *charset
, *end
;
5352 /* Extract charset part of font string. */
5353 charset
= xlfd_charset_of_font (fontname
);
5358 charset_str
= (char *) alloca (strlen (charset
) + 1);
5359 strcpy (charset_str
, charset
);
5362 /* Remove leading "*-". */
5363 if (strncmp ("*-", charset_str
, 2) == 0)
5364 charset
= charset_str
+ 2;
5367 charset
= charset_str
;
5369 /* Stop match at wildcard (including preceding '-'). */
5370 if (end
= strchr (charset
, '*'))
5372 if (end
> charset
&& *(end
-1) == '-')
5377 if (!strcmp (charset
, "iso10646"))
5380 if (NILP (Vw32_charset_info_alist
))
5383 entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
5387 codepage
= Fcdr (Fcdr (entry
));
5389 if (NILP (codepage
))
5391 else if (XFASTINT (codepage
) == XFASTINT (Qt
))
5393 else if (INTEGERP (codepage
))
5394 return XINT (codepage
);
5401 w32_to_x_font (lplogfont
, lpxstr
, len
, specific_charset
)
5402 LOGFONT
* lplogfont
;
5405 char * specific_charset
;
5409 char height_pixels
[8];
5411 char width_pixels
[8];
5412 char *fontname_dash
;
5413 int display_resy
= (int) one_w32_display_info
.resy
;
5414 int display_resx
= (int) one_w32_display_info
.resx
;
5415 struct coding_system coding
;
5417 if (!lpxstr
) abort ();
5422 if (lplogfont
->lfOutPrecision
== OUT_STRING_PRECIS
)
5423 fonttype
= "raster";
5424 else if (lplogfont
->lfOutPrecision
== OUT_STROKE_PRECIS
)
5425 fonttype
= "outline";
5427 fonttype
= "unknown";
5429 setup_coding_system (Fcheck_coding_system (Vlocale_coding_system
),
5431 coding
.src_multibyte
= 0;
5432 coding
.dst_multibyte
= 1;
5433 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
5434 /* We explicitely disable composition handling because selection
5435 data should not contain any composition sequence. */
5436 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
5438 coding
.dst_bytes
= LF_FACESIZE
* 2;
5439 coding
.destination
= (unsigned char *) xmalloc (coding
.dst_bytes
+ 1);
5440 decode_coding_c_string (&coding
, lplogfont
->lfFaceName
,
5441 strlen(lplogfont
->lfFaceName
), Qnil
);
5442 fontname
= coding
.destination
;
5444 *(fontname
+ coding
.produced
) = '\0';
5446 /* Replace dashes with underscores so the dashes are not
5448 fontname_dash
= fontname
;
5449 while (fontname_dash
= strchr (fontname_dash
, '-'))
5450 *fontname_dash
= '_';
5452 if (lplogfont
->lfHeight
)
5454 sprintf (height_pixels
, "%u", abs (lplogfont
->lfHeight
));
5455 sprintf (height_dpi
, "%u",
5456 abs (lplogfont
->lfHeight
) * 720 / display_resy
);
5460 strcpy (height_pixels
, "*");
5461 strcpy (height_dpi
, "*");
5464 #if 0 /* Never put the width in the xfld. It fails on fonts with
5465 double-width characters. */
5466 if (lplogfont
->lfWidth
)
5467 sprintf (width_pixels
, "%u", lplogfont
->lfWidth
* 10);
5470 strcpy (width_pixels
, "*");
5472 _snprintf (lpxstr
, len
- 1,
5473 "-%s-%s-%s-%c-normal-normal-%s-%s-%d-%d-%c-%s-%s",
5474 fonttype
, /* foundry */
5475 fontname
, /* family */
5476 w32_to_x_weight (lplogfont
->lfWeight
), /* weight */
5477 lplogfont
->lfItalic
?'i':'r', /* slant */
5479 /* add style name */
5480 height_pixels
, /* pixel size */
5481 height_dpi
, /* point size */
5482 display_resx
, /* resx */
5483 display_resy
, /* resy */
5484 ((lplogfont
->lfPitchAndFamily
& 0x3) == VARIABLE_PITCH
)
5485 ? 'p' : 'c', /* spacing */
5486 width_pixels
, /* avg width */
5487 w32_to_x_charset (lplogfont
->lfCharSet
, specific_charset
)
5488 /* charset registry and encoding */
5491 lpxstr
[len
- 1] = 0; /* just to be sure */
5496 x_to_w32_font (lpxstr
, lplogfont
)
5498 LOGFONT
* lplogfont
;
5500 struct coding_system coding
;
5502 if (!lplogfont
) return (FALSE
);
5504 memset (lplogfont
, 0, sizeof (*lplogfont
));
5506 /* Set default value for each field. */
5508 lplogfont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
5509 lplogfont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
5510 lplogfont
->lfQuality
= DEFAULT_QUALITY
;
5512 /* go for maximum quality */
5513 lplogfont
->lfOutPrecision
= OUT_STROKE_PRECIS
;
5514 lplogfont
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
5515 lplogfont
->lfQuality
= PROOF_QUALITY
;
5518 lplogfont
->lfCharSet
= DEFAULT_CHARSET
;
5519 lplogfont
->lfWeight
= FW_DONTCARE
;
5520 lplogfont
->lfPitchAndFamily
= DEFAULT_PITCH
| FF_DONTCARE
;
5525 /* Provide a simple escape mechanism for specifying Windows font names
5526 * directly -- if font spec does not beginning with '-', assume this
5528 * "<font name>[:height in pixels[:width in pixels[:weight]]]"
5534 char name
[50], weight
[20], slant
, pitch
, pixels
[10], height
[10],
5535 width
[10], resy
[10], remainder
[50];
5537 int dpi
= (int) one_w32_display_info
.resy
;
5539 fields
= sscanf (lpxstr
,
5540 "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%49s",
5541 name
, weight
, &slant
, pixels
, height
, resy
, &pitch
, width
, remainder
);
5545 /* In the general case when wildcards cover more than one field,
5546 we don't know which field is which, so don't fill any in.
5547 However, we need to cope with this particular form, which is
5548 generated by font_list_1 (invoked by try_font_list):
5549 "-raster-6x10-*-gb2312*-*"
5550 and make sure to correctly parse the charset field. */
5553 fields
= sscanf (lpxstr
,
5554 "-%*[^-]-%49[^-]-*-%49s",
5557 else if (fields
< 9)
5563 if (fields
> 0 && name
[0] != '*')
5565 Lisp_Object string
= build_string (name
);
5567 (Fcheck_coding_system (Vlocale_coding_system
), &coding
);
5568 coding
.mode
|= (CODING_MODE_SAFE_ENCODING
| CODING_MODE_LAST_BLOCK
);
5569 /* Disable composition/charset annotation. */
5570 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
5571 coding
.dst_bytes
= SCHARS (string
) * 2;
5573 coding
.destination
= (unsigned char *) xmalloc (coding
.dst_bytes
);
5574 encode_coding_object (&coding
, string
, 0, 0,
5575 SCHARS (string
), SBYTES (string
), Qnil
);
5576 if (coding
.produced
>= LF_FACESIZE
)
5577 coding
.produced
= LF_FACESIZE
- 1;
5579 coding
.destination
[coding
.produced
] = '\0';
5581 strcpy (lplogfont
->lfFaceName
, coding
.destination
);
5582 xfree (coding
.destination
);
5586 lplogfont
->lfFaceName
[0] = '\0';
5591 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
5595 lplogfont
->lfItalic
= (fields
> 0 && slant
== 'i');
5599 if (fields
> 0 && pixels
[0] != '*')
5600 lplogfont
->lfHeight
= atoi (pixels
);
5604 if (fields
> 0 && resy
[0] != '*')
5607 if (tem
> 0) dpi
= tem
;
5610 if (fields
> -1 && lplogfont
->lfHeight
== 0 && height
[0] != '*')
5611 lplogfont
->lfHeight
= atoi (height
) * dpi
/ 720;
5616 lplogfont
->lfPitchAndFamily
= VARIABLE_PITCH
| FF_DONTCARE
;
5617 else if (pitch
== 'c')
5618 lplogfont
->lfPitchAndFamily
= FIXED_PITCH
| FF_DONTCARE
;
5623 if (fields
> 0 && width
[0] != '*')
5624 lplogfont
->lfWidth
= atoi (width
) / 10;
5628 /* Strip the trailing '-' if present. (it shouldn't be, as it
5629 fails the test against xlfd-tight-regexp in fontset.el). */
5631 int len
= strlen (remainder
);
5632 if (len
> 0 && remainder
[len
-1] == '-')
5633 remainder
[len
-1] = 0;
5635 encoding
= remainder
;
5637 if (strncmp (encoding
, "*-", 2) == 0)
5640 lplogfont
->lfCharSet
= x_to_w32_charset (encoding
);
5645 char name
[100], height
[10], width
[10], weight
[20];
5647 fields
= sscanf (lpxstr
,
5648 "%99[^:]:%9[^:]:%9[^:]:%19s",
5649 name
, height
, width
, weight
);
5651 if (fields
== EOF
) return (FALSE
);
5655 strncpy (lplogfont
->lfFaceName
,name
, LF_FACESIZE
);
5656 lplogfont
->lfFaceName
[LF_FACESIZE
-1] = 0;
5660 lplogfont
->lfFaceName
[0] = 0;
5666 lplogfont
->lfHeight
= atoi (height
);
5671 lplogfont
->lfWidth
= atoi (width
);
5675 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
5678 /* This makes TrueType fonts work better. */
5679 lplogfont
->lfHeight
= - abs (lplogfont
->lfHeight
);
5684 /* Strip the pixel height and point height from the given xlfd, and
5685 return the pixel height. If no pixel height is specified, calculate
5686 one from the point height, or if that isn't defined either, return
5687 0 (which usually signifies a scalable font).
5690 xlfd_strip_height (char *fontname
)
5692 int pixel_height
, field_number
;
5693 char *read_from
, *write_to
;
5697 pixel_height
= field_number
= 0;
5700 /* Look for height fields. */
5701 for (read_from
= fontname
; *read_from
; read_from
++)
5703 if (*read_from
== '-')
5706 if (field_number
== 7) /* Pixel height. */
5709 write_to
= read_from
;
5711 /* Find end of field. */
5712 for (;*read_from
&& *read_from
!= '-'; read_from
++)
5715 /* Split the fontname at end of field. */
5721 pixel_height
= atoi (write_to
);
5722 /* Blank out field. */
5723 if (read_from
> write_to
)
5728 /* If the pixel height field is at the end (partial xlfd),
5731 return pixel_height
;
5733 /* If we got a pixel height, the point height can be
5734 ignored. Just blank it out and break now. */
5737 /* Find end of point size field. */
5738 for (; *read_from
&& *read_from
!= '-'; read_from
++)
5744 /* Blank out the point size field. */
5745 if (read_from
> write_to
)
5751 return pixel_height
;
5755 /* If the point height is already blank, break now. */
5756 if (*read_from
== '-')
5762 else if (field_number
== 8)
5764 /* If we didn't get a pixel height, try to get the point
5765 height and convert that. */
5767 char *point_size_start
= read_from
++;
5769 /* Find end of field. */
5770 for (; *read_from
&& *read_from
!= '-'; read_from
++)
5779 point_size
= atoi (point_size_start
);
5781 /* Convert to pixel height. */
5782 pixel_height
= point_size
5783 * one_w32_display_info
.height_in
/ 720;
5785 /* Blank out this field and break. */
5793 /* Shift the rest of the font spec into place. */
5794 if (write_to
&& read_from
> write_to
)
5796 for (; *read_from
; read_from
++, write_to
++)
5797 *write_to
= *read_from
;
5801 return pixel_height
;
5804 /* Assume parameter 1 is fully qualified, no wildcards. */
5806 w32_font_match (fontname
, pattern
)
5811 char *font_name_copy
;
5812 char *regex
= alloca (strlen (pattern
) * 2 + 3);
5814 font_name_copy
= alloca (strlen (fontname
) + 1);
5815 strcpy (font_name_copy
, fontname
);
5820 /* Turn pattern into a regexp and do a regexp match. */
5821 for (; *pattern
; pattern
++)
5823 if (*pattern
== '?')
5825 else if (*pattern
== '*')
5836 /* Strip out font heights and compare them seperately, since
5837 rounding error can cause mismatches. This also allows a
5838 comparison between a font that declares only a pixel height and a
5839 pattern that declares the point height.
5842 int font_height
, pattern_height
;
5844 font_height
= xlfd_strip_height (font_name_copy
);
5845 pattern_height
= xlfd_strip_height (regex
);
5847 /* Compare now, and don't bother doing expensive regexp matching
5848 if the heights differ. */
5849 if (font_height
&& pattern_height
&& (font_height
!= pattern_height
))
5853 return (fast_string_match_ignore_case (build_string (regex
),
5854 build_string(font_name_copy
)) >= 0);
5857 /* Callback functions, and a structure holding info they need, for
5858 listing system fonts on W32. We need one set of functions to do the
5859 job properly, but these don't work on NT 3.51 and earlier, so we
5860 have a second set which don't handle character sets properly to
5863 In both cases, there are two passes made. The first pass gets one
5864 font from each family, the second pass lists all the fonts from
5867 typedef struct enumfont_t
5872 XFontStruct
*size_ref
;
5873 Lisp_Object pattern
;
5879 enum_font_maybe_add_to_list (enumfont_t
*, LOGFONT
*, char *, Lisp_Object
);
5883 enum_font_cb2 (lplf
, lptm
, FontType
, lpef
)
5885 NEWTEXTMETRIC
* lptm
;
5889 /* Ignore struck out and underlined versions of fonts. */
5890 if (lplf
->elfLogFont
.lfStrikeOut
|| lplf
->elfLogFont
.lfUnderline
)
5893 /* Only return fonts with names starting with @ if they were
5894 explicitly specified, since Microsoft uses an initial @ to
5895 denote fonts for vertical writing, without providing a more
5896 convenient way of identifying them. */
5897 if (lplf
->elfLogFont
.lfFaceName
[0] == '@'
5898 && lpef
->logfont
.lfFaceName
[0] != '@')
5901 /* Check that the character set matches if it was specified */
5902 if (lpef
->logfont
.lfCharSet
!= DEFAULT_CHARSET
&&
5903 lplf
->elfLogFont
.lfCharSet
!= lpef
->logfont
.lfCharSet
)
5906 if (FontType
== RASTER_FONTTYPE
)
5908 /* DBCS raster fonts have problems displaying, so skip them. */
5909 int charset
= lplf
->elfLogFont
.lfCharSet
;
5910 if (charset
== SHIFTJIS_CHARSET
5911 || charset
== HANGEUL_CHARSET
5912 || charset
== CHINESEBIG5_CHARSET
5913 || charset
== GB2312_CHARSET
5914 #ifdef JOHAB_CHARSET
5915 || charset
== JOHAB_CHARSET
5923 Lisp_Object width
= Qnil
;
5924 Lisp_Object charset_list
= Qnil
;
5925 char *charset
= NULL
;
5927 /* Truetype fonts do not report their true metrics until loaded */
5928 if (FontType
!= RASTER_FONTTYPE
)
5930 if (!NILP (lpef
->pattern
))
5932 /* Scalable fonts are as big as you want them to be. */
5933 lplf
->elfLogFont
.lfHeight
= lpef
->logfont
.lfHeight
;
5934 lplf
->elfLogFont
.lfWidth
= lpef
->logfont
.lfWidth
;
5935 width
= make_number (lpef
->logfont
.lfWidth
);
5939 lplf
->elfLogFont
.lfHeight
= 0;
5940 lplf
->elfLogFont
.lfWidth
= 0;
5944 /* Make sure the height used here is the same as everywhere
5945 else (ie character height, not cell height). */
5946 if (lplf
->elfLogFont
.lfHeight
> 0)
5948 /* lptm can be trusted for RASTER fonts, but not scalable ones. */
5949 if (FontType
== RASTER_FONTTYPE
)
5950 lplf
->elfLogFont
.lfHeight
= lptm
->tmInternalLeading
- lptm
->tmHeight
;
5952 lplf
->elfLogFont
.lfHeight
= -lplf
->elfLogFont
.lfHeight
;
5955 if (!NILP (lpef
->pattern
))
5957 charset
= xlfd_charset_of_font (SDATA (lpef
->pattern
));
5959 /* We already checked charsets above, but DEFAULT_CHARSET
5960 slipped through. So only allow exact matches for DEFAULT_CHARSET. */
5962 && strncmp (charset
, "*-*", 3) != 0
5963 && lpef
->logfont
.lfCharSet
== DEFAULT_CHARSET
5964 && strcmp (charset
, w32_to_x_charset (DEFAULT_CHARSET
, NULL
)) != 0)
5969 charset_list
= Fcons (build_string (charset
), Qnil
);
5971 /* Always prefer unicode. */
5973 = Fcons (build_string ("iso10646-1"),
5974 w32_to_all_x_charsets (lplf
->elfLogFont
.lfCharSet
));
5976 /* Loop through the charsets. */
5977 for ( ; CONSP (charset_list
); charset_list
= Fcdr (charset_list
))
5979 Lisp_Object this_charset
= Fcar (charset_list
);
5980 charset
= SDATA (this_charset
);
5982 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5985 /* List bold and italic variations if w32-enable-synthesized-fonts
5986 is non-nil and this is a plain font. */
5987 if (w32_enable_synthesized_fonts
5988 && lplf
->elfLogFont
.lfWeight
== FW_NORMAL
5989 && lplf
->elfLogFont
.lfItalic
== FALSE
)
5992 lplf
->elfLogFont
.lfWeight
= FW_BOLD
;
5993 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5996 lplf
->elfLogFont
.lfItalic
= TRUE
;
5997 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
6000 lplf
->elfLogFont
.lfWeight
= FW_NORMAL
;
6001 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
6011 enum_font_maybe_add_to_list (lpef
, logfont
, match_charset
, width
)
6014 char * match_charset
;
6019 if (!w32_to_x_font (logfont
, buf
, 100, match_charset
))
6022 if (NILP (lpef
->pattern
)
6023 || w32_font_match (buf
, SDATA (lpef
->pattern
)))
6025 /* Check if we already listed this font. This may happen if
6026 w32_enable_synthesized_fonts is non-nil, and there are real
6027 bold and italic versions of the font. */
6028 Lisp_Object font_name
= build_string (buf
);
6029 if (NILP (Fmember (font_name
, lpef
->list
)))
6031 Lisp_Object entry
= Fcons (font_name
, width
);
6032 lpef
->list
= Fcons (entry
, lpef
->list
);
6040 enum_font_cb1 (lplf
, lptm
, FontType
, lpef
)
6042 NEWTEXTMETRIC
* lptm
;
6046 return EnumFontFamilies (lpef
->hdc
,
6047 lplf
->elfLogFont
.lfFaceName
,
6048 (FONTENUMPROC
) enum_font_cb2
,
6054 enum_fontex_cb2 (lplf
, lptm
, font_type
, lpef
)
6055 ENUMLOGFONTEX
* lplf
;
6056 NEWTEXTMETRICEX
* lptm
;
6060 /* We are not interested in the extra info we get back from the 'Ex
6061 version - only the fact that we get character set variations
6062 enumerated seperately. */
6063 return enum_font_cb2 ((ENUMLOGFONT
*) lplf
, (NEWTEXTMETRIC
*) lptm
,
6068 enum_fontex_cb1 (lplf
, lptm
, font_type
, lpef
)
6069 ENUMLOGFONTEX
* lplf
;
6070 NEWTEXTMETRICEX
* lptm
;
6074 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6075 FARPROC enum_font_families_ex
6076 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6077 /* We don't really expect EnumFontFamiliesEx to disappear once we
6078 get here, so don't bother handling it gracefully. */
6079 if (enum_font_families_ex
== NULL
)
6080 error ("gdi32.dll has disappeared!");
6081 return enum_font_families_ex (lpef
->hdc
,
6083 (FONTENUMPROC
) enum_fontex_cb2
,
6087 /* Interface to fontset handler. (adapted from mw32font.c in Meadow
6088 and xterm.c in Emacs 20.3) */
6090 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
)
6092 char *fontname
, *ptnstr
;
6093 Lisp_Object list
, tem
, newlist
= Qnil
;
6096 list
= Vw32_bdf_filename_alist
;
6097 ptnstr
= SDATA (pattern
);
6099 for ( ; CONSP (list
); list
= XCDR (list
))
6103 fontname
= SDATA (XCAR (tem
));
6104 else if (STRINGP (tem
))
6105 fontname
= SDATA (tem
);
6109 if (w32_font_match (fontname
, ptnstr
))
6111 newlist
= Fcons (XCAR (tem
), newlist
);
6113 if (max_names
>= 0 && n_fonts
>= max_names
)
6122 /* Return a list of names of available fonts matching PATTERN on frame
6123 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
6124 to be listed. Frame F NULL means we have not yet created any
6125 frame, which means we can't get proper size info, as we don't have
6126 a device context to use for GetTextMetrics.
6127 MAXNAMES sets a limit on how many fonts to match. If MAXNAMES is
6128 negative, then all matching fonts are returned. */
6131 w32_list_fonts (f
, pattern
, size
, maxnames
)
6133 Lisp_Object pattern
;
6137 Lisp_Object patterns
, key
= Qnil
, tem
, tpat
;
6138 Lisp_Object list
= Qnil
, newlist
= Qnil
, second_best
= Qnil
;
6139 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
6142 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
6143 if (NILP (patterns
))
6144 patterns
= Fcons (pattern
, Qnil
);
6146 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
6151 tpat
= XCAR (patterns
);
6153 if (!STRINGP (tpat
))
6156 /* Avoid expensive EnumFontFamilies functions if we are not
6157 going to be able to output one of these anyway. */
6158 codepage
= w32_codepage_for_font (SDATA (tpat
));
6159 if (codepage
!= CP_8BIT
&& codepage
!= CP_UNICODE
6160 && codepage
!= CP_DEFAULT
&& codepage
!= CP_UNKNOWN
6161 && !IsValidCodePage(codepage
))
6164 /* See if we cached the result for this particular query.
6165 The cache is an alist of the form:
6166 ((PATTERN (FONTNAME . WIDTH) ...) ...)
6168 if (tem
= XCDR (dpyinfo
->name_list_element
),
6169 !NILP (list
= Fassoc (tpat
, tem
)))
6171 list
= Fcdr_safe (list
);
6172 /* We have a cached list. Don't have to get the list again. */
6177 /* At first, put PATTERN in the cache. */
6182 /* Use EnumFontFamiliesEx where it is available, as it knows
6183 about character sets. Fall back to EnumFontFamilies for
6184 older versions of NT that don't support the 'Ex function. */
6185 x_to_w32_font (SDATA (tpat
), &ef
.logfont
);
6187 LOGFONT font_match_pattern
;
6188 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6189 FARPROC enum_font_families_ex
6190 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6192 /* We do our own pattern matching so we can handle wildcards. */
6193 font_match_pattern
.lfFaceName
[0] = 0;
6194 font_match_pattern
.lfPitchAndFamily
= 0;
6195 /* We can use the charset, because if it is a wildcard it will
6196 be DEFAULT_CHARSET anyway. */
6197 font_match_pattern
.lfCharSet
= ef
.logfont
.lfCharSet
;
6199 ef
.hdc
= GetDC (dpyinfo
->root_window
);
6201 if (enum_font_families_ex
)
6202 enum_font_families_ex (ef
.hdc
,
6203 &font_match_pattern
,
6204 (FONTENUMPROC
) enum_fontex_cb1
,
6207 EnumFontFamilies (ef
.hdc
, NULL
, (FONTENUMPROC
) enum_font_cb1
,
6210 ReleaseDC (dpyinfo
->root_window
, ef
.hdc
);
6216 /* Make a list of the fonts we got back.
6217 Store that in the font cache for the display. */
6218 XSETCDR (dpyinfo
->name_list_element
,
6219 Fcons (Fcons (tpat
, list
),
6220 XCDR (dpyinfo
->name_list_element
)));
6223 if (NILP (list
)) continue; /* Try the remaining alternatives. */
6225 newlist
= second_best
= Qnil
;
6227 /* Make a list of the fonts that have the right width. */
6228 for (; CONSP (list
); list
= XCDR (list
))
6235 if (NILP (XCAR (tem
)))
6239 newlist
= Fcons (XCAR (tem
), newlist
);
6241 if (maxnames
>= 0 && n_fonts
>= maxnames
)
6246 if (!INTEGERP (XCDR (tem
)))
6248 /* Since we don't yet know the size of the font, we must
6249 load it and try GetTextMetrics. */
6250 W32FontStruct thisinfo
;
6255 if (!x_to_w32_font (SDATA (XCAR (tem
)), &lf
))
6259 thisinfo
.bdf
= NULL
;
6260 thisinfo
.hfont
= CreateFontIndirect (&lf
);
6261 if (thisinfo
.hfont
== NULL
)
6264 hdc
= GetDC (dpyinfo
->root_window
);
6265 oldobj
= SelectObject (hdc
, thisinfo
.hfont
);
6266 if (GetTextMetrics (hdc
, &thisinfo
.tm
))
6267 XSETCDR (tem
, make_number (FONT_WIDTH (&thisinfo
)));
6269 XSETCDR (tem
, make_number (0));
6270 SelectObject (hdc
, oldobj
);
6271 ReleaseDC (dpyinfo
->root_window
, hdc
);
6272 DeleteObject(thisinfo
.hfont
);
6275 found_size
= XINT (XCDR (tem
));
6276 if (found_size
== size
)
6278 newlist
= Fcons (XCAR (tem
), newlist
);
6280 if (maxnames
>= 0 && n_fonts
>= maxnames
)
6283 /* keep track of the closest matching size in case
6284 no exact match is found. */
6285 else if (found_size
> 0)
6287 if (NILP (second_best
))
6290 else if (found_size
< size
)
6292 if (XINT (XCDR (second_best
)) > size
6293 || XINT (XCDR (second_best
)) < found_size
)
6298 if (XINT (XCDR (second_best
)) > size
6299 && XINT (XCDR (second_best
)) >
6306 if (!NILP (newlist
))
6308 else if (!NILP (second_best
))
6310 newlist
= Fcons (XCAR (second_best
), Qnil
);
6315 /* Include any bdf fonts. */
6316 if (n_fonts
< maxnames
|| maxnames
< 0)
6318 Lisp_Object combined
[2];
6319 combined
[0] = w32_list_bdf_fonts (pattern
, maxnames
- n_fonts
);
6320 combined
[1] = newlist
;
6321 newlist
= Fnconc(2, combined
);
6328 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
6330 w32_get_font_info (f
, font_idx
)
6334 return (FRAME_W32_FONT_TABLE (f
) + font_idx
);
6339 w32_query_font (struct frame
*f
, char *fontname
)
6342 struct font_info
*pfi
;
6344 pfi
= FRAME_W32_FONT_TABLE (f
);
6346 for (i
= 0; i
< one_w32_display_info
.n_fonts
;i
++, pfi
++)
6348 if (stricmp(pfi
->name
, fontname
) == 0) return pfi
;
6354 /* Find a CCL program for a font specified by FONTP, and set the member
6355 `encoder' of the structure. */
6358 w32_find_ccl_program (fontp
)
6359 struct font_info
*fontp
;
6361 Lisp_Object list
, elt
;
6363 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
6367 && STRINGP (XCAR (elt
))
6368 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
6374 struct ccl_program
*ccl
6375 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
6377 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
6380 fontp
->font_encoder
= ccl
;
6384 /* directory-files from dired.c. */
6385 Lisp_Object Fdirectory_files
P_((Lisp_Object
, Lisp_Object
, Lisp_Object
, Lisp_Object
));
6388 /* Find BDF files in a specified directory. (use GCPRO when calling,
6389 as this calls lisp to get a directory listing). */
6391 w32_find_bdf_fonts_in_dir (Lisp_Object directory
)
6393 Lisp_Object filelist
, list
= Qnil
;
6396 if (!STRINGP(directory
))
6399 filelist
= Fdirectory_files (directory
, Qt
,
6400 build_string (".*\\.[bB][dD][fF]"), Qt
);
6402 for ( ; CONSP(filelist
); filelist
= XCDR (filelist
))
6404 Lisp_Object filename
= XCAR (filelist
);
6405 if (w32_BDF_to_x_font (SDATA (filename
), fontname
, 100))
6406 store_in_alist (&list
, build_string (fontname
), filename
);
6411 DEFUN ("w32-find-bdf-fonts", Fw32_find_bdf_fonts
, Sw32_find_bdf_fonts
,
6413 doc
: /* Return a list of BDF fonts in DIRECTORY.
6414 The list is suitable for appending to `w32-bdf-filename-alist'.
6415 Fonts which do not contain an xlfd description will not be included
6416 in the list. DIRECTORY may be a list of directories. */)
6418 Lisp_Object directory
;
6420 Lisp_Object list
= Qnil
;
6421 struct gcpro gcpro1
, gcpro2
;
6423 if (!CONSP (directory
))
6424 return w32_find_bdf_fonts_in_dir (directory
);
6426 for ( ; CONSP (directory
); directory
= XCDR (directory
))
6428 Lisp_Object pair
[2];
6431 GCPRO2 (directory
, list
);
6432 pair
[1] = w32_find_bdf_fonts_in_dir( XCAR (directory
) );
6433 list
= Fnconc( 2, pair
);
6440 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
6441 doc
: /* Internal function called by `color-defined-p', which see. */)
6443 Lisp_Object color
, frame
;
6446 FRAME_PTR f
= check_x_frame (frame
);
6448 CHECK_STRING (color
);
6450 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
6456 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
6457 doc
: /* Internal function called by `color-values', which see. */)
6459 Lisp_Object color
, frame
;
6462 FRAME_PTR f
= check_x_frame (frame
);
6464 CHECK_STRING (color
);
6466 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
6467 return list3 (make_number ((GetRValue (foo
.pixel
) << 8)
6468 | GetRValue (foo
.pixel
)),
6469 make_number ((GetGValue (foo
.pixel
) << 8)
6470 | GetGValue (foo
.pixel
)),
6471 make_number ((GetBValue (foo
.pixel
) << 8)
6472 | GetBValue (foo
.pixel
)));
6477 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
6478 doc
: /* Internal function called by `display-color-p', which see. */)
6480 Lisp_Object display
;
6482 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6484 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
6490 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
,
6491 Sx_display_grayscale_p
, 0, 1, 0,
6492 doc
: /* Return t if DISPLAY supports shades of gray.
6493 Note that color displays do support shades of gray.
6494 The optional argument DISPLAY specifies which display to ask about.
6495 DISPLAY should be either a frame or a display name (a string).
6496 If omitted or nil, that stands for the selected frame's display. */)
6498 Lisp_Object display
;
6500 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6502 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
6508 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
,
6509 Sx_display_pixel_width
, 0, 1, 0,
6510 doc
: /* Returns the width in pixels of DISPLAY.
6511 The optional argument DISPLAY specifies which display to ask about.
6512 DISPLAY should be either a frame or a display name (a string).
6513 If omitted or nil, that stands for the selected frame's display. */)
6515 Lisp_Object display
;
6517 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6519 return make_number (dpyinfo
->width
);
6522 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
6523 Sx_display_pixel_height
, 0, 1, 0,
6524 doc
: /* Returns the height in pixels of DISPLAY.
6525 The optional argument DISPLAY specifies which display to ask about.
6526 DISPLAY should be either a frame or a display name (a string).
6527 If omitted or nil, that stands for the selected frame's display. */)
6529 Lisp_Object display
;
6531 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6533 return make_number (dpyinfo
->height
);
6536 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
6538 doc
: /* Returns the number of bitplanes of DISPLAY.
6539 The optional argument DISPLAY specifies which display to ask about.
6540 DISPLAY should be either a frame or a display name (a string).
6541 If omitted or nil, that stands for the selected frame's display. */)
6543 Lisp_Object display
;
6545 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6547 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
6550 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
6552 doc
: /* Returns the number of color cells of DISPLAY.
6553 The optional argument DISPLAY specifies which display to ask about.
6554 DISPLAY should be either a frame or a display name (a string).
6555 If omitted or nil, that stands for the selected frame's display. */)
6557 Lisp_Object display
;
6559 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6563 hdc
= GetDC (dpyinfo
->root_window
);
6564 if (dpyinfo
->has_palette
)
6565 cap
= GetDeviceCaps (hdc
, SIZEPALETTE
);
6567 cap
= GetDeviceCaps (hdc
, NUMCOLORS
);
6569 /* We force 24+ bit depths to 24-bit, both to prevent an overflow
6570 and because probably is more meaningful on Windows anyway */
6572 cap
= 1 << min(dpyinfo
->n_planes
* dpyinfo
->n_cbits
, 24);
6574 ReleaseDC (dpyinfo
->root_window
, hdc
);
6576 return make_number (cap
);
6579 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
6580 Sx_server_max_request_size
,
6582 doc
: /* Returns the maximum request size of the server of DISPLAY.
6583 The optional argument DISPLAY specifies which display to ask about.
6584 DISPLAY should be either a frame or a display name (a string).
6585 If omitted or nil, that stands for the selected frame's display. */)
6587 Lisp_Object display
;
6589 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6591 return make_number (1);
6594 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
6595 doc
: /* Returns the "vendor ID" string of the W32 system (Microsoft).
6596 The optional argument DISPLAY specifies which display to ask about.
6597 DISPLAY should be either a frame or a display name (a string).
6598 If omitted or nil, that stands for the selected frame's display. */)
6600 Lisp_Object display
;
6602 return build_string ("Microsoft Corp.");
6605 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
6606 doc
: /* Returns the version numbers of the server of DISPLAY.
6607 The value is a list of three integers: the major and minor
6608 version numbers of the X Protocol in use, and the distributor-specific release
6609 number. See also the function `x-server-vendor'.
6611 The optional argument DISPLAY specifies which display to ask about.
6612 DISPLAY should be either a frame or a display name (a string).
6613 If omitted or nil, that stands for the selected frame's display. */)
6615 Lisp_Object display
;
6617 return Fcons (make_number (w32_major_version
),
6618 Fcons (make_number (w32_minor_version
),
6619 Fcons (make_number (w32_build_number
), Qnil
)));
6622 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
6623 doc
: /* Returns the number of screens on the server of DISPLAY.
6624 The optional argument DISPLAY specifies which display to ask about.
6625 DISPLAY should be either a frame or a display name (a string).
6626 If omitted or nil, that stands for the selected frame's display. */)
6628 Lisp_Object display
;
6630 return make_number (1);
6633 DEFUN ("x-display-mm-height", Fx_display_mm_height
,
6634 Sx_display_mm_height
, 0, 1, 0,
6635 doc
: /* Returns the height in millimeters of DISPLAY.
6636 The optional argument DISPLAY specifies which display to ask about.
6637 DISPLAY should be either a frame or a display name (a string).
6638 If omitted or nil, that stands for the selected frame's display. */)
6640 Lisp_Object display
;
6642 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6646 hdc
= GetDC (dpyinfo
->root_window
);
6648 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
6650 ReleaseDC (dpyinfo
->root_window
, hdc
);
6652 return make_number (cap
);
6655 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
6656 doc
: /* Returns the width in millimeters of DISPLAY.
6657 The optional argument DISPLAY specifies which display to ask about.
6658 DISPLAY should be either a frame or a display name (a string).
6659 If omitted or nil, that stands for the selected frame's display. */)
6661 Lisp_Object display
;
6663 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6668 hdc
= GetDC (dpyinfo
->root_window
);
6670 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
6672 ReleaseDC (dpyinfo
->root_window
, hdc
);
6674 return make_number (cap
);
6677 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
6678 Sx_display_backing_store
, 0, 1, 0,
6679 doc
: /* Returns an indication of whether DISPLAY does backing store.
6680 The value may be `always', `when-mapped', or `not-useful'.
6681 The optional argument DISPLAY specifies which display to ask about.
6682 DISPLAY should be either a frame or a display name (a string).
6683 If omitted or nil, that stands for the selected frame's display. */)
6685 Lisp_Object display
;
6687 return intern ("not-useful");
6690 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
6691 Sx_display_visual_class
, 0, 1, 0,
6692 doc
: /* Returns the visual class of DISPLAY.
6693 The value is one of the symbols `static-gray', `gray-scale',
6694 `static-color', `pseudo-color', `true-color', or `direct-color'.
6696 The optional argument DISPLAY specifies which display to ask about.
6697 DISPLAY should be either a frame or a display name (a string).
6698 If omitted or nil, that stands for the selected frame's display. */)
6700 Lisp_Object display
;
6702 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6703 Lisp_Object result
= Qnil
;
6705 if (dpyinfo
->has_palette
)
6706 result
= intern ("pseudo-color");
6707 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
6708 result
= intern ("static-grey");
6709 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
6710 result
= intern ("static-color");
6711 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
6712 result
= intern ("true-color");
6717 DEFUN ("x-display-save-under", Fx_display_save_under
,
6718 Sx_display_save_under
, 0, 1, 0,
6719 doc
: /* Returns t if DISPLAY supports the save-under feature.
6720 The optional argument DISPLAY specifies which display to ask about.
6721 DISPLAY should be either a frame or a display name (a string).
6722 If omitted or nil, that stands for the selected frame's display. */)
6724 Lisp_Object display
;
6731 register struct frame
*f
;
6733 return FRAME_PIXEL_WIDTH (f
);
6738 register struct frame
*f
;
6740 return FRAME_PIXEL_HEIGHT (f
);
6745 register struct frame
*f
;
6747 return FRAME_COLUMN_WIDTH (f
);
6752 register struct frame
*f
;
6754 return FRAME_LINE_HEIGHT (f
);
6759 register struct frame
*f
;
6761 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
6764 /* Return the display structure for the display named NAME.
6765 Open a new connection if necessary. */
6767 struct w32_display_info
*
6768 x_display_info_for_name (name
)
6772 struct w32_display_info
*dpyinfo
;
6774 CHECK_STRING (name
);
6776 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
6778 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
6781 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
6786 /* Use this general default value to start with. */
6787 Vx_resource_name
= Vinvocation_name
;
6789 validate_x_resource_name ();
6791 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
6792 (char *) SDATA (Vx_resource_name
));
6795 error ("Cannot connect to server %s", SDATA (name
));
6798 XSETFASTINT (Vwindow_system_version
, 3);
6803 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
6804 1, 3, 0, doc
: /* Open a connection to a server.
6805 DISPLAY is the name of the display to connect to.
6806 Optional second arg XRM-STRING is a string of resources in xrdb format.
6807 If the optional third arg MUST-SUCCEED is non-nil,
6808 terminate Emacs if we can't open the connection. */)
6809 (display
, xrm_string
, must_succeed
)
6810 Lisp_Object display
, xrm_string
, must_succeed
;
6812 unsigned char *xrm_option
;
6813 struct w32_display_info
*dpyinfo
;
6815 /* If initialization has already been done, return now to avoid
6816 overwriting critical parts of one_w32_display_info. */
6820 CHECK_STRING (display
);
6821 if (! NILP (xrm_string
))
6822 CHECK_STRING (xrm_string
);
6824 if (! EQ (Vwindow_system
, intern ("w32")))
6825 error ("Not using Microsoft Windows");
6827 /* Allow color mapping to be defined externally; first look in user's
6828 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
6830 Lisp_Object color_file
;
6831 struct gcpro gcpro1
;
6833 color_file
= build_string("~/rgb.txt");
6835 GCPRO1 (color_file
);
6837 if (NILP (Ffile_readable_p (color_file
)))
6839 Fexpand_file_name (build_string ("rgb.txt"),
6840 Fsymbol_value (intern ("data-directory")));
6842 Vw32_color_map
= Fw32_load_color_file (color_file
);
6846 if (NILP (Vw32_color_map
))
6847 Vw32_color_map
= Fw32_default_color_map ();
6849 /* Merge in system logical colors. */
6850 add_system_logical_colors_to_map (&Vw32_color_map
);
6852 if (! NILP (xrm_string
))
6853 xrm_option
= (unsigned char *) SDATA (xrm_string
);
6855 xrm_option
= (unsigned char *) 0;
6857 /* Use this general default value to start with. */
6858 /* First remove .exe suffix from invocation-name - it looks ugly. */
6860 char basename
[ MAX_PATH
], *str
;
6862 strcpy (basename
, SDATA (Vinvocation_name
));
6863 str
= strrchr (basename
, '.');
6865 Vinvocation_name
= build_string (basename
);
6867 Vx_resource_name
= Vinvocation_name
;
6869 validate_x_resource_name ();
6871 /* This is what opens the connection and sets x_current_display.
6872 This also initializes many symbols, such as those used for input. */
6873 dpyinfo
= w32_term_init (display
, xrm_option
,
6874 (char *) SDATA (Vx_resource_name
));
6878 if (!NILP (must_succeed
))
6879 fatal ("Cannot connect to server %s.\n",
6882 error ("Cannot connect to server %s", SDATA (display
));
6887 XSETFASTINT (Vwindow_system_version
, 3);
6891 DEFUN ("x-close-connection", Fx_close_connection
,
6892 Sx_close_connection
, 1, 1, 0,
6893 doc
: /* Close the connection to DISPLAY's server.
6894 For DISPLAY, specify either a frame or a display name (a string).
6895 If DISPLAY is nil, that stands for the selected frame's display. */)
6897 Lisp_Object display
;
6899 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6902 if (dpyinfo
->reference_count
> 0)
6903 error ("Display still has frames on it");
6906 /* Free the fonts in the font table. */
6907 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
6908 if (dpyinfo
->font_table
[i
].name
)
6910 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
6911 xfree (dpyinfo
->font_table
[i
].full_name
);
6912 xfree (dpyinfo
->font_table
[i
].name
);
6913 w32_unload_font (dpyinfo
, dpyinfo
->font_table
[i
].font
);
6915 x_destroy_all_bitmaps (dpyinfo
);
6917 x_delete_display (dpyinfo
);
6923 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
6924 doc
: /* Return the list of display names that Emacs has connections to. */)
6927 Lisp_Object tail
, result
;
6930 for (tail
= w32_display_name_list
; ! NILP (tail
); tail
= XCDR (tail
))
6931 result
= Fcons (XCAR (XCAR (tail
)), result
);
6936 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
6937 doc
: /* This is a noop on W32 systems. */)
6939 Lisp_Object display
, on
;
6946 /***********************************************************************
6948 ***********************************************************************/
6950 DEFUN ("x-change-window-property", Fx_change_window_property
,
6951 Sx_change_window_property
, 2, 6, 0,
6952 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
6953 VALUE may be a string or a list of conses, numbers and/or strings.
6954 If an element in the list is a string, it is converted to
6955 an Atom and the value of the Atom is used. If an element is a cons,
6956 it is converted to a 32 bit number where the car is the 16 top bits and the
6957 cdr is the lower 16 bits.
6958 FRAME nil or omitted means use the selected frame.
6959 If TYPE is given and non-nil, it is the name of the type of VALUE.
6960 If TYPE is not given or nil, the type is STRING.
6961 FORMAT gives the size in bits of each element if VALUE is a list.
6962 It must be one of 8, 16 or 32.
6963 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
6964 If OUTER_P is non-nil, the property is changed for the outer X window of
6965 FRAME. Default is to change on the edit X window.
6968 (prop
, value
, frame
, type
, format
, outer_p
)
6969 Lisp_Object prop
, value
, frame
, type
, format
, outer_p
;
6971 #if 0 /* TODO : port window properties to W32 */
6972 struct frame
*f
= check_x_frame (frame
);
6975 CHECK_STRING (prop
);
6976 CHECK_STRING (value
);
6979 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
6980 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
6981 prop_atom
, XA_STRING
, 8, PropModeReplace
,
6982 SDATA (value
), SCHARS (value
));
6984 /* Make sure the property is set when we return. */
6985 XFlush (FRAME_W32_DISPLAY (f
));
6994 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
6995 Sx_delete_window_property
, 1, 2, 0,
6996 doc
: /* Remove window property PROP from X window of FRAME.
6997 FRAME nil or omitted means use the selected frame. Value is PROP. */)
6999 Lisp_Object prop
, frame
;
7001 #if 0 /* TODO : port window properties to W32 */
7003 struct frame
*f
= check_x_frame (frame
);
7006 CHECK_STRING (prop
);
7008 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
7009 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
7011 /* Make sure the property is removed when we return. */
7012 XFlush (FRAME_W32_DISPLAY (f
));
7020 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
7022 doc
: /* Value is the value of window property PROP on FRAME.
7023 If FRAME is nil or omitted, use the selected frame. Value is nil
7024 if FRAME hasn't a property with name PROP or if PROP has no string
7027 Lisp_Object prop
, frame
;
7029 #if 0 /* TODO : port window properties to W32 */
7031 struct frame
*f
= check_x_frame (frame
);
7034 Lisp_Object prop_value
= Qnil
;
7035 char *tmp_data
= NULL
;
7038 unsigned long actual_size
, bytes_remaining
;
7040 CHECK_STRING (prop
);
7042 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
7043 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
7044 prop_atom
, 0, 0, False
, XA_STRING
,
7045 &actual_type
, &actual_format
, &actual_size
,
7046 &bytes_remaining
, (unsigned char **) &tmp_data
);
7049 int size
= bytes_remaining
;
7054 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
7055 prop_atom
, 0, bytes_remaining
,
7057 &actual_type
, &actual_format
,
7058 &actual_size
, &bytes_remaining
,
7059 (unsigned char **) &tmp_data
);
7061 prop_value
= make_string (tmp_data
, size
);
7076 /***********************************************************************
7078 ***********************************************************************/
7080 /* If non-null, an asynchronous timer that, when it expires, displays
7081 an hourglass cursor on all frames. */
7083 static struct atimer
*hourglass_atimer
;
7085 /* Non-zero means an hourglass cursor is currently shown. */
7087 static int hourglass_shown_p
;
7089 /* Number of seconds to wait before displaying an hourglass cursor. */
7091 static Lisp_Object Vhourglass_delay
;
7093 /* Default number of seconds to wait before displaying an hourglass
7096 #define DEFAULT_HOURGLASS_DELAY 1
7098 /* Function prototypes. */
7100 static void show_hourglass
P_ ((struct atimer
*));
7101 static void hide_hourglass
P_ ((void));
7104 /* Cancel a currently active hourglass timer, and start a new one. */
7109 #if 0 /* TODO: cursor shape changes. */
7111 int secs
, usecs
= 0;
7113 cancel_hourglass ();
7115 if (INTEGERP (Vhourglass_delay
)
7116 && XINT (Vhourglass_delay
) > 0)
7117 secs
= XFASTINT (Vhourglass_delay
);
7118 else if (FLOATP (Vhourglass_delay
)
7119 && XFLOAT_DATA (Vhourglass_delay
) > 0)
7122 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
7123 secs
= XFASTINT (tem
);
7124 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
7127 secs
= DEFAULT_HOURGLASS_DELAY
;
7129 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
7130 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
7131 show_hourglass
, NULL
);
7136 /* Cancel the hourglass cursor timer if active, hide an hourglass
7142 if (hourglass_atimer
)
7144 cancel_atimer (hourglass_atimer
);
7145 hourglass_atimer
= NULL
;
7148 if (hourglass_shown_p
)
7153 /* Timer function of hourglass_atimer. TIMER is equal to
7156 Display an hourglass cursor on all frames by mapping the frames'
7157 hourglass_window. Set the hourglass_p flag in the frames'
7158 output_data.x structure to indicate that an hourglass cursor is
7159 shown on the frames. */
7162 show_hourglass (timer
)
7163 struct atimer
*timer
;
7165 #if 0 /* TODO: cursor shape changes. */
7166 /* The timer implementation will cancel this timer automatically
7167 after this function has run. Set hourglass_atimer to null
7168 so that we know the timer doesn't have to be canceled. */
7169 hourglass_atimer
= NULL
;
7171 if (!hourglass_shown_p
)
7173 Lisp_Object rest
, frame
;
7177 FOR_EACH_FRAME (rest
, frame
)
7178 if (FRAME_W32_P (XFRAME (frame
)))
7180 struct frame
*f
= XFRAME (frame
);
7182 f
->output_data
.w32
->hourglass_p
= 1;
7184 if (!f
->output_data
.w32
->hourglass_window
)
7186 unsigned long mask
= CWCursor
;
7187 XSetWindowAttributes attrs
;
7189 attrs
.cursor
= f
->output_data
.w32
->hourglass_cursor
;
7191 f
->output_data
.w32
->hourglass_window
7192 = XCreateWindow (FRAME_X_DISPLAY (f
),
7193 FRAME_OUTER_WINDOW (f
),
7194 0, 0, 32000, 32000, 0, 0,
7200 XMapRaised (FRAME_X_DISPLAY (f
),
7201 f
->output_data
.w32
->hourglass_window
);
7202 XFlush (FRAME_X_DISPLAY (f
));
7205 hourglass_shown_p
= 1;
7212 /* Hide the hourglass cursor on all frames, if it is currently shown. */
7217 #if 0 /* TODO: cursor shape changes. */
7218 if (hourglass_shown_p
)
7220 Lisp_Object rest
, frame
;
7223 FOR_EACH_FRAME (rest
, frame
)
7225 struct frame
*f
= XFRAME (frame
);
7228 /* Watch out for newly created frames. */
7229 && f
->output_data
.x
->hourglass_window
)
7231 XUnmapWindow (FRAME_X_DISPLAY (f
),
7232 f
->output_data
.x
->hourglass_window
);
7233 /* Sync here because XTread_socket looks at the
7234 hourglass_p flag that is reset to zero below. */
7235 XSync (FRAME_X_DISPLAY (f
), False
);
7236 f
->output_data
.x
->hourglass_p
= 0;
7240 hourglass_shown_p
= 0;
7248 /***********************************************************************
7250 ***********************************************************************/
7252 static Lisp_Object x_create_tip_frame
P_ ((struct w32_display_info
*,
7253 Lisp_Object
, Lisp_Object
));
7254 static void compute_tip_xy
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
7255 Lisp_Object
, int, int, int *, int *));
7257 /* The frame of a currently visible tooltip. */
7259 Lisp_Object tip_frame
;
7261 /* If non-nil, a timer started that hides the last tooltip when it
7264 Lisp_Object tip_timer
;
7267 /* If non-nil, a vector of 3 elements containing the last args
7268 with which x-show-tip was called. See there. */
7270 Lisp_Object last_show_tip_args
;
7272 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
7274 Lisp_Object Vx_max_tooltip_size
;
7278 unwind_create_tip_frame (frame
)
7281 Lisp_Object deleted
;
7283 deleted
= unwind_create_frame (frame
);
7284 if (EQ (deleted
, Qt
))
7294 /* Create a frame for a tooltip on the display described by DPYINFO.
7295 PARMS is a list of frame parameters. TEXT is the string to
7296 display in the tip frame. Value is the frame.
7298 Note that functions called here, esp. x_default_parameter can
7299 signal errors, for instance when a specified color name is
7300 undefined. We have to make sure that we're in a consistent state
7301 when this happens. */
7304 x_create_tip_frame (dpyinfo
, parms
, text
)
7305 struct w32_display_info
*dpyinfo
;
7306 Lisp_Object parms
, text
;
7309 Lisp_Object frame
, tem
;
7311 long window_prompting
= 0;
7313 int count
= SPECPDL_INDEX ();
7314 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7316 int face_change_count_before
= face_change_count
;
7318 struct buffer
*old_buffer
;
7322 /* Use this general default value to start with until we know if
7323 this frame has a specified name. */
7324 Vx_resource_name
= Vinvocation_name
;
7327 kb
= dpyinfo
->kboard
;
7329 kb
= &the_only_kboard
;
7332 /* Get the name of the frame to use for resource lookup. */
7333 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
7335 && !EQ (name
, Qunbound
)
7337 error ("Invalid frame name--not a string or nil");
7338 Vx_resource_name
= name
;
7341 GCPRO3 (parms
, name
, frame
);
7342 /* Make a frame without minibuffer nor mode-line. */
7344 f
->wants_modeline
= 0;
7345 XSETFRAME (frame
, f
);
7347 buffer
= Fget_buffer_create (build_string (" *tip*"));
7348 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, Qnil
);
7349 old_buffer
= current_buffer
;
7350 set_buffer_internal_1 (XBUFFER (buffer
));
7351 current_buffer
->truncate_lines
= Qnil
;
7352 specbind (Qinhibit_read_only
, Qt
);
7353 specbind (Qinhibit_modification_hooks
, Qt
);
7356 set_buffer_internal_1 (old_buffer
);
7358 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
7359 record_unwind_protect (unwind_create_tip_frame
, frame
);
7361 /* By setting the output method, we're essentially saying that
7362 the frame is live, as per FRAME_LIVE_P. If we get a signal
7363 from this point on, x_destroy_window might screw up reference
7365 f
->output_method
= output_w32
;
7366 f
->output_data
.w32
=
7367 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
7368 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
7370 FRAME_FONTSET (f
) = -1;
7371 f
->icon_name
= Qnil
;
7373 #if 0 /* GLYPH_DEBUG TODO: image support. */
7374 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
7375 dpyinfo_refcount
= dpyinfo
->reference_count
;
7376 #endif /* GLYPH_DEBUG */
7378 FRAME_KBOARD (f
) = kb
;
7380 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
7381 f
->output_data
.w32
->explicit_parent
= 0;
7383 /* Set the name; the functions to which we pass f expect the name to
7385 if (EQ (name
, Qunbound
) || NILP (name
))
7387 f
->name
= build_string (dpyinfo
->w32_id_name
);
7388 f
->explicit_name
= 0;
7393 f
->explicit_name
= 1;
7394 /* use the frame's title when getting resources for this frame. */
7395 specbind (Qx_resource_name
, name
);
7398 #ifdef USE_FONT_BACKEND
7399 if (enable_font_backend
)
7401 /* Perhaps, we must allow frame parameter, say `font-backend',
7402 to specify which font backends to use. */
7403 register_font_driver (&w32font_driver
, f
);
7405 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
7406 "fontBackend", "FontBackend", RES_TYPE_STRING
);
7408 #endif /* USE_FONT_BACKEND */
7410 /* Extract the window parameters from the supplied values
7411 that are needed to determine window geometry. */
7412 #ifdef USE_FONT_BACKEND
7413 if (enable_font_backend
)
7414 x_default_font_parameter (f
, parms
);
7416 #endif /* USE_FONT_BACKEND */
7420 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
7423 /* First, try whatever font the caller has specified. */
7426 tem
= Fquery_fontset (font
, Qnil
);
7428 font
= x_new_fontset (f
, tem
);
7430 font
= x_new_font (f
, SDATA (font
));
7433 /* Try out a font which we hope has bold and italic variations. */
7434 if (!STRINGP (font
))
7435 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
7436 if (! STRINGP (font
))
7437 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
7438 /* If those didn't work, look for something which will at least work. */
7439 if (! STRINGP (font
))
7440 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
7442 if (! STRINGP (font
))
7443 font
= build_string ("Fixedsys");
7445 x_default_parameter (f
, parms
, Qfont
, font
,
7446 "font", "Font", RES_TYPE_STRING
);
7449 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
7450 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
7451 /* This defaults to 2 in order to match xterm. We recognize either
7452 internalBorderWidth or internalBorder (which is what xterm calls
7454 if (NILP (Fassq (Qinternal_border_width
, parms
)))
7458 value
= w32_get_arg (parms
, Qinternal_border_width
,
7459 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
7460 if (! EQ (value
, Qunbound
))
7461 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
7464 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
7465 "internalBorderWidth", "internalBorderWidth",
7468 /* Also do the stuff which must be set before the window exists. */
7469 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
7470 "foreground", "Foreground", RES_TYPE_STRING
);
7471 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
7472 "background", "Background", RES_TYPE_STRING
);
7473 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
7474 "pointerColor", "Foreground", RES_TYPE_STRING
);
7475 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
7476 "cursorColor", "Foreground", RES_TYPE_STRING
);
7477 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
7478 "borderColor", "BorderColor", RES_TYPE_STRING
);
7480 /* Init faces before x_default_parameter is called for scroll-bar
7481 parameters because that function calls x_set_scroll_bar_width,
7482 which calls change_frame_size, which calls Fset_window_buffer,
7483 which runs hooks, which call Fvertical_motion. At the end, we
7484 end up in init_iterator with a null face cache, which should not
7486 init_frame_faces (f
);
7488 f
->output_data
.w32
->dwStyle
= WS_BORDER
| WS_POPUP
| WS_DISABLED
;
7489 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
7491 window_prompting
= x_figure_window_size (f
, parms
, 0);
7493 /* No fringes on tip frame. */
7495 f
->left_fringe_width
= 0;
7496 f
->right_fringe_width
= 0;
7499 my_create_tip_window (f
);
7504 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
7505 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
7506 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
7507 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
7508 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
7509 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
7511 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
7512 Change will not be effected unless different from the current
7514 width
= FRAME_COLS (f
);
7515 height
= FRAME_LINES (f
);
7516 FRAME_LINES (f
) = 0;
7517 SET_FRAME_COLS (f
, 0);
7518 change_frame_size (f
, height
, width
, 1, 0, 0);
7520 /* Add `tooltip' frame parameter's default value. */
7521 if (NILP (Fframe_parameter (frame
, intern ("tooltip"))))
7522 Fmodify_frame_parameters (frame
, Fcons (Fcons (intern ("tooltip"), Qt
),
7525 /* Set up faces after all frame parameters are known. This call
7526 also merges in face attributes specified for new frames.
7528 Frame parameters may be changed if .Xdefaults contains
7529 specifications for the default font. For example, if there is an
7530 `Emacs.default.attributeBackground: pink', the `background-color'
7531 attribute of the frame get's set, which let's the internal border
7532 of the tooltip frame appear in pink. Prevent this. */
7534 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
7536 /* Set tip_frame here, so that */
7538 call1 (Qface_set_after_frame_default
, frame
);
7540 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
7541 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qbackground_color
, bg
),
7549 /* It is now ok to make the frame official even if we get an error
7550 below. And the frame needs to be on Vframe_list or making it
7551 visible won't work. */
7552 Vframe_list
= Fcons (frame
, Vframe_list
);
7554 /* Now that the frame is official, it counts as a reference to
7556 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
7558 /* Setting attributes of faces of the tooltip frame from resources
7559 and similar will increment face_change_count, which leads to the
7560 clearing of all current matrices. Since this isn't necessary
7561 here, avoid it by resetting face_change_count to the value it
7562 had before we created the tip frame. */
7563 face_change_count
= face_change_count_before
;
7565 /* Discard the unwind_protect. */
7566 return unbind_to (count
, frame
);
7570 /* Compute where to display tip frame F. PARMS is the list of frame
7571 parameters for F. DX and DY are specified offsets from the current
7572 location of the mouse. WIDTH and HEIGHT are the width and height
7573 of the tooltip. Return coordinates relative to the root window of
7574 the display in *ROOT_X, and *ROOT_Y. */
7577 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, root_x
, root_y
)
7579 Lisp_Object parms
, dx
, dy
;
7581 int *root_x
, *root_y
;
7583 Lisp_Object left
, top
;
7585 /* User-specified position? */
7586 left
= Fcdr (Fassq (Qleft
, parms
));
7587 top
= Fcdr (Fassq (Qtop
, parms
));
7589 /* Move the tooltip window where the mouse pointer is. Resize and
7591 if (!INTEGERP (left
) || !INTEGERP (top
))
7603 *root_y
= XINT (top
);
7604 else if (*root_y
+ XINT (dy
) <= 0)
7605 *root_y
= 0; /* Can happen for negative dy */
7606 else if (*root_y
+ XINT (dy
) + height
<= FRAME_W32_DISPLAY_INFO (f
)->height
)
7607 /* It fits below the pointer */
7608 *root_y
+= XINT (dy
);
7609 else if (height
+ XINT (dy
) <= *root_y
)
7610 /* It fits above the pointer. */
7611 *root_y
-= height
+ XINT (dy
);
7613 /* Put it on the top. */
7616 if (INTEGERP (left
))
7617 *root_x
= XINT (left
);
7618 else if (*root_x
+ XINT (dx
) <= 0)
7619 *root_x
= 0; /* Can happen for negative dx */
7620 else if (*root_x
+ XINT (dx
) + width
<= FRAME_W32_DISPLAY_INFO (f
)->width
)
7621 /* It fits to the right of the pointer. */
7622 *root_x
+= XINT (dx
);
7623 else if (width
+ XINT (dx
) <= *root_x
)
7624 /* It fits to the left of the pointer. */
7625 *root_x
-= width
+ XINT (dx
);
7627 /* Put it left justified on the screen -- it ought to fit that way. */
7632 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
7633 doc
: /* Show STRING in a \"tooltip\" window on frame FRAME.
7634 A tooltip window is a small window displaying a string.
7636 This is an internal function; Lisp code should call `tooltip-show'.
7638 FRAME nil or omitted means use the selected frame.
7640 PARMS is an optional list of frame parameters which can be
7641 used to change the tooltip's appearance.
7643 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
7644 means use the default timeout of 5 seconds.
7646 If the list of frame parameters PARMS contains a `left' parameter,
7647 the tooltip is displayed at that x-position. Otherwise it is
7648 displayed at the mouse position, with offset DX added (default is 5 if
7649 DX isn't specified). Likewise for the y-position; if a `top' frame
7650 parameter is specified, it determines the y-position of the tooltip
7651 window, otherwise it is displayed at the mouse position, with offset
7652 DY added (default is -10).
7654 A tooltip's maximum size is specified by `x-max-tooltip-size'.
7655 Text larger than the specified size is clipped. */)
7656 (string
, frame
, parms
, timeout
, dx
, dy
)
7657 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
7662 struct buffer
*old_buffer
;
7663 struct text_pos pos
;
7664 int i
, width
, height
;
7665 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7666 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7667 int count
= SPECPDL_INDEX ();
7669 specbind (Qinhibit_redisplay
, Qt
);
7671 GCPRO4 (string
, parms
, frame
, timeout
);
7673 CHECK_STRING (string
);
7674 f
= check_x_frame (frame
);
7676 timeout
= make_number (5);
7678 CHECK_NATNUM (timeout
);
7681 dx
= make_number (5);
7686 dy
= make_number (-10);
7690 if (NILP (last_show_tip_args
))
7691 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
7693 if (!NILP (tip_frame
))
7695 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
7696 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
7697 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
7699 if (EQ (frame
, last_frame
)
7700 && !NILP (Fequal (last_string
, string
))
7701 && !NILP (Fequal (last_parms
, parms
)))
7703 struct frame
*f
= XFRAME (tip_frame
);
7705 /* Only DX and DY have changed. */
7706 if (!NILP (tip_timer
))
7708 Lisp_Object timer
= tip_timer
;
7710 call1 (Qcancel_timer
, timer
);
7714 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
7715 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
7717 /* Put tooltip in topmost group and in position. */
7718 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
7719 root_x
, root_y
, 0, 0,
7720 SWP_NOSIZE
| SWP_NOACTIVATE
);
7722 /* Ensure tooltip is on top of other topmost windows (eg menus). */
7723 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
7725 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
7732 /* Hide a previous tip, if any. */
7735 ASET (last_show_tip_args
, 0, string
);
7736 ASET (last_show_tip_args
, 1, frame
);
7737 ASET (last_show_tip_args
, 2, parms
);
7739 /* Add default values to frame parameters. */
7740 if (NILP (Fassq (Qname
, parms
)))
7741 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
7742 if (NILP (Fassq (Qinternal_border_width
, parms
)))
7743 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
7744 if (NILP (Fassq (Qborder_width
, parms
)))
7745 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
7746 if (NILP (Fassq (Qborder_color
, parms
)))
7747 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
7748 if (NILP (Fassq (Qbackground_color
, parms
)))
7749 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
7752 /* Block input until the tip has been fully drawn, to avoid crashes
7753 when drawing tips in menus. */
7756 /* Create a frame for the tooltip, and record it in the global
7757 variable tip_frame. */
7758 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
, string
);
7761 /* Set up the frame's root window. */
7762 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7763 w
->left_col
= w
->top_line
= make_number (0);
7765 if (CONSP (Vx_max_tooltip_size
)
7766 && INTEGERP (XCAR (Vx_max_tooltip_size
))
7767 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
7768 && INTEGERP (XCDR (Vx_max_tooltip_size
))
7769 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
7771 w
->total_cols
= XCAR (Vx_max_tooltip_size
);
7772 w
->total_lines
= XCDR (Vx_max_tooltip_size
);
7776 w
->total_cols
= make_number (80);
7777 w
->total_lines
= make_number (40);
7780 FRAME_TOTAL_COLS (f
) = XINT (w
->total_cols
);
7782 w
->pseudo_window_p
= 1;
7784 /* Display the tooltip text in a temporary buffer. */
7785 old_buffer
= current_buffer
;
7786 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
7787 current_buffer
->truncate_lines
= Qnil
;
7788 clear_glyph_matrix (w
->desired_matrix
);
7789 clear_glyph_matrix (w
->current_matrix
);
7790 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
7791 try_window (FRAME_ROOT_WINDOW (f
), pos
, 0);
7793 /* Compute width and height of the tooltip. */
7795 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
7797 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
7801 /* Stop at the first empty row at the end. */
7802 if (!row
->enabled_p
|| !row
->displays_text_p
)
7805 /* Let the row go over the full width of the frame. */
7806 row
->full_width_p
= 1;
7808 #ifdef TODO /* Investigate why some fonts need more width than is
7809 calculated for some tooltips. */
7810 /* There's a glyph at the end of rows that is use to place
7811 the cursor there. Don't include the width of this glyph. */
7812 if (row
->used
[TEXT_AREA
])
7814 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
7815 row_width
= row
->pixel_width
- last
->pixel_width
;
7819 row_width
= row
->pixel_width
;
7821 /* TODO: find why tips do not draw along baseline as instructed. */
7822 height
+= row
->height
;
7823 width
= max (width
, row_width
);
7826 /* Add the frame's internal border to the width and height the X
7827 window should have. */
7828 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
7829 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
7831 /* Move the tooltip window where the mouse pointer is. Resize and
7833 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
7836 /* Adjust Window size to take border into account. */
7838 rect
.left
= rect
.top
= 0;
7840 rect
.bottom
= height
;
7841 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
7842 FRAME_EXTERNAL_MENU_BAR (f
));
7844 /* Position and size tooltip, and put it in the topmost group.
7845 The add-on of 3 to the 5th argument is a kludge: without it,
7846 some fonts cause the last character of the tip to be truncated,
7847 for some obscure reason. */
7848 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
7849 root_x
, root_y
, rect
.right
- rect
.left
+ 3,
7850 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
);
7852 /* Ensure tooltip is on top of other topmost windows (eg menus). */
7853 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
7855 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
7857 /* Let redisplay know that we have made the frame visible already. */
7858 f
->async_visible
= 1;
7860 ShowWindow (FRAME_W32_WINDOW (f
), SW_SHOWNOACTIVATE
);
7863 /* Draw into the window. */
7864 w
->must_be_updated_p
= 1;
7865 update_single_window (w
, 1);
7869 /* Restore original current buffer. */
7870 set_buffer_internal_1 (old_buffer
);
7871 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7874 /* Let the tip disappear after timeout seconds. */
7875 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
7876 intern ("x-hide-tip"));
7879 return unbind_to (count
, Qnil
);
7883 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
7884 doc
: /* Hide the current tooltip window, if there is any.
7885 Value is t if tooltip was open, nil otherwise. */)
7889 Lisp_Object deleted
, frame
, timer
;
7890 struct gcpro gcpro1
, gcpro2
;
7892 /* Return quickly if nothing to do. */
7893 if (NILP (tip_timer
) && NILP (tip_frame
))
7898 GCPRO2 (frame
, timer
);
7899 tip_frame
= tip_timer
= deleted
= Qnil
;
7901 count
= SPECPDL_INDEX ();
7902 specbind (Qinhibit_redisplay
, Qt
);
7903 specbind (Qinhibit_quit
, Qt
);
7906 call1 (Qcancel_timer
, timer
);
7910 Fdelete_frame (frame
, Qnil
);
7915 return unbind_to (count
, deleted
);
7920 /***********************************************************************
7921 File selection dialog
7922 ***********************************************************************/
7923 extern Lisp_Object Qfile_name_history
;
7925 /* Callback for altering the behaviour of the Open File dialog.
7926 Makes the Filename text field contain "Current Directory" and be
7927 read-only when "Directories" is selected in the filter. This
7928 allows us to work around the fact that the standard Open File
7929 dialog does not support directories. */
7931 file_dialog_callback (hwnd
, msg
, wParam
, lParam
)
7937 if (msg
== WM_NOTIFY
)
7939 OFNOTIFY
* notify
= (OFNOTIFY
*)lParam
;
7940 /* Detect when the Filter dropdown is changed. */
7941 if (notify
->hdr
.code
== CDN_TYPECHANGE
7942 || notify
->hdr
.code
== CDN_INITDONE
)
7944 HWND dialog
= GetParent (hwnd
);
7945 HWND edit_control
= GetDlgItem (dialog
, FILE_NAME_TEXT_FIELD
);
7947 /* Directories is in index 2. */
7948 if (notify
->lpOFN
->nFilterIndex
== 2)
7950 CommDlg_OpenSave_SetControlText (dialog
, FILE_NAME_TEXT_FIELD
,
7951 "Current Directory");
7952 EnableWindow (edit_control
, FALSE
);
7956 /* Don't override default filename on init done. */
7957 if (notify
->hdr
.code
== CDN_TYPECHANGE
)
7958 CommDlg_OpenSave_SetControlText (dialog
,
7959 FILE_NAME_TEXT_FIELD
, "");
7960 EnableWindow (edit_control
, TRUE
);
7967 /* Since we compile with _WIN32_WINNT set to 0x0400 (for NT4 compatibility)
7968 we end up with the old file dialogs. Define a big enough struct for the
7969 new dialog to trick GetOpenFileName into giving us the new dialogs on
7970 Windows 2000 and XP. */
7973 OPENFILENAME real_details
;
7980 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
7981 doc
: /* Read file name, prompting with PROMPT in directory DIR.
7982 Use a file selection dialog.
7983 Select DEFAULT-FILENAME in the dialog's file selection box, if
7984 specified. Ensure that file exists if MUSTMATCH is non-nil.
7985 If ONLY-DIR-P is non-nil, the user can only select directories. */)
7986 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
)
7987 Lisp_Object prompt
, dir
, default_filename
, mustmatch
, only_dir_p
;
7989 struct frame
*f
= SELECTED_FRAME ();
7990 Lisp_Object file
= Qnil
;
7991 int count
= SPECPDL_INDEX ();
7992 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
7993 char filename
[MAX_PATH
+ 1];
7994 char init_dir
[MAX_PATH
+ 1];
7995 int default_filter_index
= 1; /* 1: All Files, 2: Directories only */
7997 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
7998 CHECK_STRING (prompt
);
8001 /* Create the dialog with PROMPT as title, using DIR as initial
8002 directory and using "*" as pattern. */
8003 dir
= Fexpand_file_name (dir
, Qnil
);
8004 strncpy (init_dir
, SDATA (ENCODE_FILE (dir
)), MAX_PATH
);
8005 init_dir
[MAX_PATH
] = '\0';
8006 unixtodos_filename (init_dir
);
8008 if (STRINGP (default_filename
))
8010 char *file_name_only
;
8011 char *full_path_name
= SDATA (ENCODE_FILE (default_filename
));
8013 unixtodos_filename (full_path_name
);
8015 file_name_only
= strrchr (full_path_name
, '\\');
8016 if (!file_name_only
)
8017 file_name_only
= full_path_name
;
8021 strncpy (filename
, file_name_only
, MAX_PATH
);
8022 filename
[MAX_PATH
] = '\0';
8028 NEWOPENFILENAME new_file_details
;
8029 BOOL file_opened
= FALSE
;
8030 OPENFILENAME
* file_details
= &new_file_details
.real_details
;
8032 /* Prevent redisplay. */
8033 specbind (Qinhibit_redisplay
, Qt
);
8036 bzero (&new_file_details
, sizeof (new_file_details
));
8037 /* Apparently NT4 crashes if you give it an unexpected size.
8038 I'm not sure about Windows 9x, so play it safe. */
8039 if (w32_major_version
> 4 && w32_major_version
< 95)
8040 file_details
->lStructSize
= sizeof (new_file_details
);
8042 file_details
->lStructSize
= sizeof (file_details
);
8044 file_details
->hwndOwner
= FRAME_W32_WINDOW (f
);
8045 /* Undocumented Bug in Common File Dialog:
8046 If a filter is not specified, shell links are not resolved. */
8047 file_details
->lpstrFilter
= "All Files (*.*)\0*.*\0Directories\0*|*\0\0";
8048 file_details
->lpstrFile
= filename
;
8049 file_details
->nMaxFile
= sizeof (filename
);
8050 file_details
->lpstrInitialDir
= init_dir
;
8051 file_details
->lpstrTitle
= SDATA (prompt
);
8053 if (! NILP (only_dir_p
))
8054 default_filter_index
= 2;
8056 file_details
->nFilterIndex
= default_filter_index
;
8058 file_details
->Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
8059 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
8060 if (!NILP (mustmatch
))
8062 /* Require that the path to the parent directory exists. */
8063 file_details
->Flags
|= OFN_PATHMUSTEXIST
;
8064 /* If we are looking for a file, require that it exists. */
8065 if (NILP (only_dir_p
))
8066 file_details
->Flags
|= OFN_FILEMUSTEXIST
;
8069 file_details
->lpfnHook
= (LPOFNHOOKPROC
) file_dialog_callback
;
8071 file_opened
= GetOpenFileName (file_details
);
8077 dostounix_filename (filename
);
8079 if (file_details
->nFilterIndex
== 2)
8081 /* "Directories" selected - strip dummy file name. */
8082 char * last
= strrchr (filename
, '/');
8086 file
= DECODE_FILE(build_string (filename
));
8088 /* User cancelled the dialog without making a selection. */
8089 else if (!CommDlgExtendedError ())
8091 /* An error occurred, fallback on reading from the mini-buffer. */
8093 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
8094 dir
, mustmatch
, dir
, Qfile_name_history
,
8095 default_filename
, Qnil
);
8097 file
= unbind_to (count
, file
);
8102 /* Make "Cancel" equivalent to C-g. */
8104 Fsignal (Qquit
, Qnil
);
8106 return unbind_to (count
, file
);
8111 /***********************************************************************
8112 w32 specialized functions
8113 ***********************************************************************/
8115 DEFUN ("w32-select-font", Fw32_select_font
, Sw32_select_font
, 0, 2, 0,
8116 doc
: /* Select a font for the named FRAME using the W32 font dialog.
8117 Returns an X-style font string corresponding to the selection.
8119 If FRAME is omitted or nil, it defaults to the selected frame.
8120 If INCLUDE-PROPORTIONAL is non-nil, include proportional fonts
8121 in the font selection dialog. */)
8122 (frame
, include_proportional
)
8123 Lisp_Object frame
, include_proportional
;
8125 FRAME_PTR f
= check_x_frame (frame
);
8133 bzero (&cf
, sizeof (cf
));
8134 bzero (&lf
, sizeof (lf
));
8136 cf
.lStructSize
= sizeof (cf
);
8137 cf
.hwndOwner
= FRAME_W32_WINDOW (f
);
8138 cf
.Flags
= CF_FORCEFONTEXIST
| CF_SCREENFONTS
| CF_NOVERTFONTS
;
8140 /* Unless include_proportional is non-nil, limit the selection to
8141 monospaced fonts. */
8142 if (NILP (include_proportional
))
8143 cf
.Flags
|= CF_FIXEDPITCHONLY
;
8147 /* Initialize as much of the font details as we can from the current
8149 hdc
= GetDC (FRAME_W32_WINDOW (f
));
8150 oldobj
= SelectObject (hdc
, FRAME_FONT (f
)->hfont
);
8151 GetTextFace (hdc
, LF_FACESIZE
, lf
.lfFaceName
);
8152 if (GetTextMetrics (hdc
, &tm
))
8154 lf
.lfHeight
= tm
.tmInternalLeading
- tm
.tmHeight
;
8155 lf
.lfWeight
= tm
.tmWeight
;
8156 lf
.lfItalic
= tm
.tmItalic
;
8157 lf
.lfUnderline
= tm
.tmUnderlined
;
8158 lf
.lfStrikeOut
= tm
.tmStruckOut
;
8159 lf
.lfCharSet
= tm
.tmCharSet
;
8160 cf
.Flags
|= CF_INITTOLOGFONTSTRUCT
;
8162 SelectObject (hdc
, oldobj
);
8163 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
8165 if (!ChooseFont (&cf
) || !w32_to_x_font (&lf
, buf
, 100, NULL
))
8168 return build_string (buf
);
8171 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
,
8172 Sw32_send_sys_command
, 1, 2, 0,
8173 doc
: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND.
8174 Some useful values for COMMAND are #xf030 to maximize frame (#xf020
8175 to minimize), #xf120 to restore frame to original size, and #xf100
8176 to activate the menubar for keyboard access. #xf140 activates the
8177 screen saver if defined.
8179 If optional parameter FRAME is not specified, use selected frame. */)
8181 Lisp_Object command
, frame
;
8183 FRAME_PTR f
= check_x_frame (frame
);
8185 CHECK_NUMBER (command
);
8187 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
8192 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
8193 doc
: /* Get Windows to perform OPERATION on DOCUMENT.
8194 This is a wrapper around the ShellExecute system function, which
8195 invokes the application registered to handle OPERATION for DOCUMENT.
8197 OPERATION is either nil or a string that names a supported operation.
8198 What operations can be used depends on the particular DOCUMENT and its
8199 handler application, but typically it is one of the following common
8202 \"open\" - open DOCUMENT, which could be a file, a directory, or an
8203 executable program. If it is an application, that
8204 application is launched in the current buffer's default
8205 directory. Otherwise, the application associated with
8206 DOCUMENT is launched in the buffer's default directory.
8207 \"print\" - print DOCUMENT, which must be a file
8208 \"explore\" - start the Windows Explorer on DOCUMENT
8209 \"edit\" - launch an editor and open DOCUMENT for editing; which
8210 editor is launched depends on the association for the
8212 \"find\" - initiate search starting from DOCUMENT which must specify
8214 nil - invoke the default OPERATION, or \"open\" if default is
8215 not defined or unavailable
8217 DOCUMENT is typically the name of a document file or a URL, but can
8218 also be a program executable to run, or a directory to open in the
8221 If DOCUMENT is a program executable, the optional arg PARAMETERS can
8222 be a string containing command line parameters that will be passed to
8223 the program; otherwise, PARAMETERS should be nil or unspecified.
8225 Second optional argument SHOW-FLAG can be used to control how the
8226 application will be displayed when it is invoked. If SHOW-FLAG is nil
8227 or unspceified, the application is displayed normally, otherwise it is
8228 an integer representing a ShowWindow flag:
8233 6 - start minimized */)
8234 (operation
, document
, parameters
, show_flag
)
8235 Lisp_Object operation
, document
, parameters
, show_flag
;
8237 Lisp_Object current_dir
;
8239 CHECK_STRING (document
);
8241 /* Encode filename and current directory. */
8242 current_dir
= ENCODE_FILE (current_buffer
->directory
);
8243 document
= ENCODE_FILE (document
);
8244 if ((int) ShellExecute (NULL
,
8245 (STRINGP (operation
) ?
8246 SDATA (operation
) : NULL
),
8248 (STRINGP (parameters
) ?
8249 SDATA (parameters
) : NULL
),
8250 SDATA (current_dir
),
8251 (INTEGERP (show_flag
) ?
8252 XINT (show_flag
) : SW_SHOWDEFAULT
))
8255 error ("ShellExecute failed: %s", w32_strerror (0));
8258 /* Lookup virtual keycode from string representing the name of a
8259 non-ascii keystroke into the corresponding virtual key, using
8260 lispy_function_keys. */
8262 lookup_vk_code (char *key
)
8266 for (i
= 0; i
< 256; i
++)
8267 if (lispy_function_keys
[i
] != 0
8268 && strcmp (lispy_function_keys
[i
], key
) == 0)
8274 /* Convert a one-element vector style key sequence to a hot key
8277 w32_parse_hot_key (key
)
8280 /* Copied from Fdefine_key and store_in_keymap. */
8281 register Lisp_Object c
;
8285 struct gcpro gcpro1
;
8289 if (XFASTINT (Flength (key
)) != 1)
8294 c
= Faref (key
, make_number (0));
8296 if (CONSP (c
) && lucid_event_type_list_p (c
))
8297 c
= Fevent_convert_list (c
);
8301 if (! INTEGERP (c
) && ! SYMBOLP (c
))
8302 error ("Key definition is invalid");
8304 /* Work out the base key and the modifiers. */
8307 c
= parse_modifiers (c
);
8308 lisp_modifiers
= XINT (Fcar (Fcdr (c
)));
8312 vk_code
= lookup_vk_code (SDATA (SYMBOL_NAME (c
)));
8314 else if (INTEGERP (c
))
8316 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
8317 /* Many ascii characters are their own virtual key code. */
8318 vk_code
= XINT (c
) & CHARACTERBITS
;
8321 if (vk_code
< 0 || vk_code
> 255)
8324 if ((lisp_modifiers
& meta_modifier
) != 0
8325 && !NILP (Vw32_alt_is_meta
))
8326 lisp_modifiers
|= alt_modifier
;
8328 /* Supply defs missing from mingw32. */
8330 #define MOD_ALT 0x0001
8331 #define MOD_CONTROL 0x0002
8332 #define MOD_SHIFT 0x0004
8333 #define MOD_WIN 0x0008
8336 /* Convert lisp modifiers to Windows hot-key form. */
8337 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
8338 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
8339 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
8340 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
8342 return HOTKEY (vk_code
, w32_modifiers
);
8345 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
,
8346 Sw32_register_hot_key
, 1, 1, 0,
8347 doc
: /* Register KEY as a hot-key combination.
8348 Certain key combinations like Alt-Tab are reserved for system use on
8349 Windows, and therefore are normally intercepted by the system. However,
8350 most of these key combinations can be received by registering them as
8351 hot-keys, overriding their special meaning.
8353 KEY must be a one element key definition in vector form that would be
8354 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta
8355 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper
8356 is always interpreted as the Windows modifier keys.
8358 The return value is the hotkey-id if registered, otherwise nil. */)
8362 key
= w32_parse_hot_key (key
);
8364 if (NILP (Fmemq (key
, w32_grabbed_keys
)))
8366 /* Reuse an empty slot if possible. */
8367 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
8369 /* Safe to add new key to list, even if we have focus. */
8371 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
8373 XSETCAR (item
, key
);
8375 /* Notify input thread about new hot-key definition, so that it
8376 takes effect without needing to switch focus. */
8377 #ifdef USE_LISP_UNION_TYPE
8378 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
8381 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
8389 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
,
8390 Sw32_unregister_hot_key
, 1, 1, 0,
8391 doc
: /* Unregister KEY as a hot-key combination. */)
8397 if (!INTEGERP (key
))
8398 key
= w32_parse_hot_key (key
);
8400 item
= Fmemq (key
, w32_grabbed_keys
);
8404 /* Notify input thread about hot-key definition being removed, so
8405 that it takes effect without needing focus switch. */
8406 #ifdef USE_LISP_UNION_TYPE
8407 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
8408 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
.i
))
8410 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
8411 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
))
8416 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
8423 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
,
8424 Sw32_registered_hot_keys
, 0, 0, 0,
8425 doc
: /* Return list of registered hot-key IDs. */)
8428 return Fcopy_sequence (w32_grabbed_keys
);
8431 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
,
8432 Sw32_reconstruct_hot_key
, 1, 1, 0,
8433 doc
: /* Convert hot-key ID to a lisp key combination.
8434 usage: (w32-reconstruct-hot-key ID) */)
8436 Lisp_Object hotkeyid
;
8438 int vk_code
, w32_modifiers
;
8441 CHECK_NUMBER (hotkeyid
);
8443 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
8444 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
8446 if (lispy_function_keys
[vk_code
])
8447 key
= intern (lispy_function_keys
[vk_code
]);
8449 key
= make_number (vk_code
);
8451 key
= Fcons (key
, Qnil
);
8452 if (w32_modifiers
& MOD_SHIFT
)
8453 key
= Fcons (Qshift
, key
);
8454 if (w32_modifiers
& MOD_CONTROL
)
8455 key
= Fcons (Qctrl
, key
);
8456 if (w32_modifiers
& MOD_ALT
)
8457 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
8458 if (w32_modifiers
& MOD_WIN
)
8459 key
= Fcons (Qhyper
, key
);
8464 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
,
8465 Sw32_toggle_lock_key
, 1, 2, 0,
8466 doc
: /* Toggle the state of the lock key KEY.
8467 KEY can be `capslock', `kp-numlock', or `scroll'.
8468 If the optional parameter NEW-STATE is a number, then the state of KEY
8469 is set to off if the low bit of NEW-STATE is zero, otherwise on. */)
8471 Lisp_Object key
, new_state
;
8475 if (EQ (key
, intern ("capslock")))
8476 vk_code
= VK_CAPITAL
;
8477 else if (EQ (key
, intern ("kp-numlock")))
8478 vk_code
= VK_NUMLOCK
;
8479 else if (EQ (key
, intern ("scroll")))
8480 vk_code
= VK_SCROLL
;
8484 if (!dwWindowsThreadId
)
8485 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
8487 #ifdef USE_LISP_UNION_TYPE
8488 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
8489 (WPARAM
) vk_code
, (LPARAM
) new_state
.i
))
8491 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
8492 (WPARAM
) vk_code
, (LPARAM
) new_state
))
8496 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
8497 return make_number (msg
.wParam
);
8502 DEFUN ("w32-window-exists-p", Fw32_window_exists_p
, Sw32_window_exists_p
,
8504 doc
: /* Return non-nil if a window exists with the specified CLASS and NAME.
8506 This is a direct interface to the Windows API FindWindow function. */)
8508 Lisp_Object
class, name
;
8513 CHECK_STRING (class);
8515 CHECK_STRING (name
);
8517 hnd
= FindWindow (STRINGP (class) ? ((LPCTSTR
) SDATA (class)) : NULL
,
8518 STRINGP (name
) ? ((LPCTSTR
) SDATA (name
)) : NULL
);
8526 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
8527 doc
: /* Return storage information about the file system FILENAME is on.
8528 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
8529 storage of the file system, FREE is the free storage, and AVAIL is the
8530 storage available to a non-superuser. All 3 numbers are in bytes.
8531 If the underlying system call fails, value is nil. */)
8533 Lisp_Object filename
;
8535 Lisp_Object encoded
, value
;
8537 CHECK_STRING (filename
);
8538 filename
= Fexpand_file_name (filename
, Qnil
);
8539 encoded
= ENCODE_FILE (filename
);
8543 /* Determining the required information on Windows turns out, sadly,
8544 to be more involved than one would hope. The original Win32 api
8545 call for this will return bogus information on some systems, but we
8546 must dynamically probe for the replacement api, since that was
8547 added rather late on. */
8549 HMODULE hKernel
= GetModuleHandle ("kernel32");
8550 BOOL (*pfn_GetDiskFreeSpaceEx
)
8551 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
8552 = (void *) GetProcAddress (hKernel
, "GetDiskFreeSpaceEx");
8554 /* On Windows, we may need to specify the root directory of the
8555 volume holding FILENAME. */
8556 char rootname
[MAX_PATH
];
8557 char *name
= SDATA (encoded
);
8559 /* find the root name of the volume if given */
8560 if (isalpha (name
[0]) && name
[1] == ':')
8562 rootname
[0] = name
[0];
8563 rootname
[1] = name
[1];
8567 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
8569 char *str
= rootname
;
8573 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
8583 if (pfn_GetDiskFreeSpaceEx
)
8585 /* Unsigned large integers cannot be cast to double, so
8586 use signed ones instead. */
8587 LARGE_INTEGER availbytes
;
8588 LARGE_INTEGER freebytes
;
8589 LARGE_INTEGER totalbytes
;
8591 if (pfn_GetDiskFreeSpaceEx(rootname
,
8592 (ULARGE_INTEGER
*)&availbytes
,
8593 (ULARGE_INTEGER
*)&totalbytes
,
8594 (ULARGE_INTEGER
*)&freebytes
))
8595 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
8596 make_float ((double) freebytes
.QuadPart
),
8597 make_float ((double) availbytes
.QuadPart
));
8601 DWORD sectors_per_cluster
;
8602 DWORD bytes_per_sector
;
8603 DWORD free_clusters
;
8604 DWORD total_clusters
;
8606 if (GetDiskFreeSpace(rootname
,
8607 §ors_per_cluster
,
8611 value
= list3 (make_float ((double) total_clusters
8612 * sectors_per_cluster
* bytes_per_sector
),
8613 make_float ((double) free_clusters
8614 * sectors_per_cluster
* bytes_per_sector
),
8615 make_float ((double) free_clusters
8616 * sectors_per_cluster
* bytes_per_sector
));
8623 DEFUN ("default-printer-name", Fdefault_printer_name
, Sdefault_printer_name
,
8624 0, 0, 0, doc
: /* Return the name of Windows default printer device. */)
8627 static char pname_buf
[256];
8630 PRINTER_INFO_2
*ppi2
= NULL
;
8631 DWORD dwNeeded
= 0, dwReturned
= 0;
8633 /* Retrieve the default string from Win.ini (the registry).
8634 * String will be in form "printername,drivername,portname".
8635 * This is the most portable way to get the default printer. */
8636 if (GetProfileString ("windows", "device", ",,", pname_buf
, sizeof (pname_buf
)) <= 0)
8638 /* printername precedes first "," character */
8639 strtok (pname_buf
, ",");
8640 /* We want to know more than the printer name */
8641 if (!OpenPrinter (pname_buf
, &hPrn
, NULL
))
8643 GetPrinter (hPrn
, 2, NULL
, 0, &dwNeeded
);
8646 ClosePrinter (hPrn
);
8649 /* Allocate memory for the PRINTER_INFO_2 struct */
8650 ppi2
= (PRINTER_INFO_2
*) xmalloc (dwNeeded
);
8653 ClosePrinter (hPrn
);
8656 /* Call GetPrinter() again with big enouth memory block */
8657 err
= GetPrinter (hPrn
, 2, (LPBYTE
)ppi2
, dwNeeded
, &dwReturned
);
8658 ClosePrinter (hPrn
);
8667 if (ppi2
->Attributes
& PRINTER_ATTRIBUTE_SHARED
&& ppi2
->pServerName
)
8669 /* a remote printer */
8670 if (*ppi2
->pServerName
== '\\')
8671 _snprintf(pname_buf
, sizeof (pname_buf
), "%s\\%s", ppi2
->pServerName
,
8674 _snprintf(pname_buf
, sizeof (pname_buf
), "\\\\%s\\%s", ppi2
->pServerName
,
8676 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
8680 /* a local printer */
8681 strncpy(pname_buf
, ppi2
->pPortName
, sizeof (pname_buf
));
8682 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
8683 /* `pPortName' can include several ports, delimited by ','.
8684 * we only use the first one. */
8685 strtok(pname_buf
, ",");
8690 return build_string (pname_buf
);
8693 /***********************************************************************
8695 ***********************************************************************/
8697 /* Keep this list in the same order as frame_parms in frame.c.
8698 Use 0 for unsupported frame parameters. */
8700 frame_parm_handler w32_frame_parm_handlers
[] =
8704 x_set_background_color
,
8710 x_set_foreground_color
,
8713 x_set_internal_border_width
,
8714 x_set_menu_bar_lines
,
8716 x_explicitly_set_name
,
8717 x_set_scroll_bar_width
,
8720 x_set_vertical_scroll_bars
,
8722 x_set_tool_bar_lines
,
8723 0, /* x_set_scroll_bar_foreground, */
8724 0, /* x_set_scroll_bar_background, */
8729 0, /* x_set_wait_for_wm, */
8731 #ifdef USE_FONT_BACKEND
8739 globals_of_w32fns ();
8740 /* This is zero if not using MS-Windows. */
8742 track_mouse_window
= NULL
;
8744 w32_visible_system_caret_hwnd
= NULL
;
8746 Qnone
= intern ("none");
8748 Qsuppress_icon
= intern ("suppress-icon");
8749 staticpro (&Qsuppress_icon
);
8750 Qundefined_color
= intern ("undefined-color");
8751 staticpro (&Qundefined_color
);
8752 Qcancel_timer
= intern ("cancel-timer");
8753 staticpro (&Qcancel_timer
);
8755 Qhyper
= intern ("hyper");
8756 staticpro (&Qhyper
);
8757 Qsuper
= intern ("super");
8758 staticpro (&Qsuper
);
8759 Qmeta
= intern ("meta");
8761 Qalt
= intern ("alt");
8763 Qctrl
= intern ("ctrl");
8765 Qcontrol
= intern ("control");
8766 staticpro (&Qcontrol
);
8767 Qshift
= intern ("shift");
8768 staticpro (&Qshift
);
8769 /* This is the end of symbol initialization. */
8771 /* Text property `display' should be nonsticky by default. */
8772 Vtext_property_default_nonsticky
8773 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
8776 Fput (Qundefined_color
, Qerror_conditions
,
8777 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
8778 Fput (Qundefined_color
, Qerror_message
,
8779 build_string ("Undefined color"));
8781 staticpro (&w32_grabbed_keys
);
8782 w32_grabbed_keys
= Qnil
;
8784 DEFVAR_LISP ("w32-color-map", &Vw32_color_map
,
8785 doc
: /* An array of color name mappings for Windows. */);
8786 Vw32_color_map
= Qnil
;
8788 DEFVAR_LISP ("w32-pass-alt-to-system", &Vw32_pass_alt_to_system
,
8789 doc
: /* Non-nil if Alt key presses are passed on to Windows.
8790 When non-nil, for example, Alt pressed and released and then space will
8791 open the System menu. When nil, Emacs processes the Alt key events, and
8792 then silently swallows them. */);
8793 Vw32_pass_alt_to_system
= Qnil
;
8795 DEFVAR_LISP ("w32-alt-is-meta", &Vw32_alt_is_meta
,
8796 doc
: /* Non-nil if the Alt key is to be considered the same as the META key.
8797 When nil, Emacs will translate the Alt key to the ALT modifier, not to META. */);
8798 Vw32_alt_is_meta
= Qt
;
8800 DEFVAR_INT ("w32-quit-key", &w32_quit_key
,
8801 doc
: /* If non-zero, the virtual key code for an alternative quit key. */);
8804 DEFVAR_LISP ("w32-pass-lwindow-to-system",
8805 &Vw32_pass_lwindow_to_system
,
8806 doc
: /* If non-nil, the left \"Windows\" key is passed on to Windows.
8808 When non-nil, the Start menu is opened by tapping the key.
8809 If you set this to nil, the left \"Windows\" key is processed by Emacs
8810 according to the value of `w32-lwindow-modifier', which see.
8812 Note that some combinations of the left \"Windows\" key with other keys are
8813 caught by Windows at low level, and so binding them in Emacs will have no
8814 effect. For example, <lwindow>-r always pops up the Windows Run dialog,
8815 <lwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
8816 the doc string of `w32-phantom-key-code'. */);
8817 Vw32_pass_lwindow_to_system
= Qt
;
8819 DEFVAR_LISP ("w32-pass-rwindow-to-system",
8820 &Vw32_pass_rwindow_to_system
,
8821 doc
: /* If non-nil, the right \"Windows\" key is passed on to Windows.
8823 When non-nil, the Start menu is opened by tapping the key.
8824 If you set this to nil, the right \"Windows\" key is processed by Emacs
8825 according to the value of `w32-rwindow-modifier', which see.
8827 Note that some combinations of the right \"Windows\" key with other keys are
8828 caught by Windows at low level, and so binding them in Emacs will have no
8829 effect. For example, <rwindow>-r always pops up the Windows Run dialog,
8830 <rwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
8831 the doc string of `w32-phantom-key-code'. */);
8832 Vw32_pass_rwindow_to_system
= Qt
;
8834 DEFVAR_LISP ("w32-phantom-key-code",
8835 &Vw32_phantom_key_code
,
8836 doc
: /* Virtual key code used to generate \"phantom\" key presses.
8837 Value is a number between 0 and 255.
8839 Phantom key presses are generated in order to stop the system from
8840 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or
8841 `w32-pass-rwindow-to-system' is nil. */);
8842 /* Although 255 is technically not a valid key code, it works and
8843 means that this hack won't interfere with any real key code. */
8844 XSETINT (Vw32_phantom_key_code
, 255);
8846 DEFVAR_LISP ("w32-enable-num-lock",
8847 &Vw32_enable_num_lock
,
8848 doc
: /* If non-nil, the Num Lock key acts normally.
8849 Set to nil to handle Num Lock as the `kp-numlock' key. */);
8850 Vw32_enable_num_lock
= Qt
;
8852 DEFVAR_LISP ("w32-enable-caps-lock",
8853 &Vw32_enable_caps_lock
,
8854 doc
: /* If non-nil, the Caps Lock key acts normally.
8855 Set to nil to handle Caps Lock as the `capslock' key. */);
8856 Vw32_enable_caps_lock
= Qt
;
8858 DEFVAR_LISP ("w32-scroll-lock-modifier",
8859 &Vw32_scroll_lock_modifier
,
8860 doc
: /* Modifier to use for the Scroll Lock ON state.
8861 The value can be hyper, super, meta, alt, control or shift for the
8862 respective modifier, or nil to handle Scroll Lock as the `scroll' key.
8863 Any other value will cause the Scroll Lock key to be ignored. */);
8864 Vw32_scroll_lock_modifier
= Qt
;
8866 DEFVAR_LISP ("w32-lwindow-modifier",
8867 &Vw32_lwindow_modifier
,
8868 doc
: /* Modifier to use for the left \"Windows\" key.
8869 The value can be hyper, super, meta, alt, control or shift for the
8870 respective modifier, or nil to appear as the `lwindow' key.
8871 Any other value will cause the key to be ignored. */);
8872 Vw32_lwindow_modifier
= Qnil
;
8874 DEFVAR_LISP ("w32-rwindow-modifier",
8875 &Vw32_rwindow_modifier
,
8876 doc
: /* Modifier to use for the right \"Windows\" key.
8877 The value can be hyper, super, meta, alt, control or shift for the
8878 respective modifier, or nil to appear as the `rwindow' key.
8879 Any other value will cause the key to be ignored. */);
8880 Vw32_rwindow_modifier
= Qnil
;
8882 DEFVAR_LISP ("w32-apps-modifier",
8883 &Vw32_apps_modifier
,
8884 doc
: /* Modifier to use for the \"Apps\" key.
8885 The value can be hyper, super, meta, alt, control or shift for the
8886 respective modifier, or nil to appear as the `apps' key.
8887 Any other value will cause the key to be ignored. */);
8888 Vw32_apps_modifier
= Qnil
;
8890 DEFVAR_BOOL ("w32-enable-synthesized-fonts", &w32_enable_synthesized_fonts
,
8891 doc
: /* Non-nil enables selection of artificially italicized and bold fonts. */);
8892 w32_enable_synthesized_fonts
= 0;
8894 DEFVAR_LISP ("w32-enable-palette", &Vw32_enable_palette
,
8895 doc
: /* Non-nil enables Windows palette management to map colors exactly. */);
8896 Vw32_enable_palette
= Qt
;
8898 DEFVAR_INT ("w32-mouse-button-tolerance",
8899 &w32_mouse_button_tolerance
,
8900 doc
: /* Analogue of double click interval for faking middle mouse events.
8901 The value is the minimum time in milliseconds that must elapse between
8902 left and right button down events before they are considered distinct events.
8903 If both mouse buttons are depressed within this interval, a middle mouse
8904 button down event is generated instead. */);
8905 w32_mouse_button_tolerance
= GetDoubleClickTime () / 2;
8907 DEFVAR_INT ("w32-mouse-move-interval",
8908 &w32_mouse_move_interval
,
8909 doc
: /* Minimum interval between mouse move events.
8910 The value is the minimum time in milliseconds that must elapse between
8911 successive mouse move (or scroll bar drag) events before they are
8912 reported as lisp events. */);
8913 w32_mouse_move_interval
= 0;
8915 DEFVAR_BOOL ("w32-pass-extra-mouse-buttons-to-system",
8916 &w32_pass_extra_mouse_buttons_to_system
,
8917 doc
: /* If non-nil, the fourth and fifth mouse buttons are passed to Windows.
8918 Recent versions of Windows support mice with up to five buttons.
8919 Since most applications don't support these extra buttons, most mouse
8920 drivers will allow you to map them to functions at the system level.
8921 If this variable is non-nil, Emacs will pass them on, allowing the
8922 system to handle them. */);
8923 w32_pass_extra_mouse_buttons_to_system
= 0;
8925 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
8926 doc
: /* The shape of the pointer when over text.
8927 Changing the value does not affect existing frames
8928 unless you set the mouse color. */);
8929 Vx_pointer_shape
= Qnil
;
8931 Vx_nontext_pointer_shape
= Qnil
;
8933 Vx_mode_pointer_shape
= Qnil
;
8935 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
8936 doc
: /* The shape of the pointer when Emacs is busy.
8937 This variable takes effect when you create a new frame
8938 or when you set the mouse color. */);
8939 Vx_hourglass_pointer_shape
= Qnil
;
8941 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
8942 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
8943 display_hourglass_p
= 1;
8945 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
8946 doc
: /* *Seconds to wait before displaying an hourglass pointer.
8947 Value must be an integer or float. */);
8948 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
8950 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
8951 &Vx_sensitive_text_pointer_shape
,
8952 doc
: /* The shape of the pointer when over mouse-sensitive text.
8953 This variable takes effect when you create a new frame
8954 or when you set the mouse color. */);
8955 Vx_sensitive_text_pointer_shape
= Qnil
;
8957 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
8958 &Vx_window_horizontal_drag_shape
,
8959 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
8960 This variable takes effect when you create a new frame
8961 or when you set the mouse color. */);
8962 Vx_window_horizontal_drag_shape
= Qnil
;
8964 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
8965 doc
: /* A string indicating the foreground color of the cursor box. */);
8966 Vx_cursor_fore_pixel
= Qnil
;
8968 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size
,
8969 doc
: /* Maximum size for tooltips.
8970 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
8971 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
8973 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
8974 doc
: /* Non-nil if no window manager is in use.
8975 Emacs doesn't try to figure this out; this is always nil
8976 unless you set it to something else. */);
8977 /* We don't have any way to find this out, so set it to nil
8978 and maybe the user would like to set it to t. */
8979 Vx_no_window_manager
= Qnil
;
8981 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
8982 &Vx_pixel_size_width_font_regexp
,
8983 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
8985 Since Emacs gets width of a font matching with this regexp from
8986 PIXEL_SIZE field of the name, font finding mechanism gets faster for
8987 such a font. This is especially effective for such large fonts as
8988 Chinese, Japanese, and Korean. */);
8989 Vx_pixel_size_width_font_regexp
= Qnil
;
8991 DEFVAR_LISP ("w32-bdf-filename-alist",
8992 &Vw32_bdf_filename_alist
,
8993 doc
: /* List of bdf fonts and their corresponding filenames. */);
8994 Vw32_bdf_filename_alist
= Qnil
;
8996 DEFVAR_BOOL ("w32-strict-fontnames",
8997 &w32_strict_fontnames
,
8998 doc
: /* Non-nil means only use fonts that are exact matches for those requested.
8999 Default is nil, which allows old fontnames that are not XLFD compliant,
9000 and allows third-party CJK display to work by specifying false charset
9001 fields to trick Emacs into translating to Big5, SJIS etc.
9002 Setting this to t will prevent wrong fonts being selected when
9003 fontsets are automatically created. */);
9004 w32_strict_fontnames
= 0;
9006 DEFVAR_BOOL ("w32-strict-painting",
9007 &w32_strict_painting
,
9008 doc
: /* Non-nil means use strict rules for repainting frames.
9009 Set this to nil to get the old behavior for repainting; this should
9010 only be necessary if the default setting causes problems. */);
9011 w32_strict_painting
= 1;
9013 DEFVAR_LISP ("w32-charset-info-alist",
9014 &Vw32_charset_info_alist
,
9015 doc
: /* Alist linking Emacs character sets to Windows fonts and codepages.
9016 Each entry should be of the form:
9018 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE))
9020 where CHARSET_NAME is a string used in font names to identify the charset,
9021 WINDOWS_CHARSET is a symbol that can be one of:
9022 w32-charset-ansi, w32-charset-default, w32-charset-symbol,
9023 w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312,
9024 w32-charset-chinesebig5,
9025 w32-charset-johab, w32-charset-hebrew,
9026 w32-charset-arabic, w32-charset-greek, w32-charset-turkish,
9027 w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope,
9028 w32-charset-russian, w32-charset-mac, w32-charset-baltic,
9029 w32-charset-unicode,
9031 CODEPAGE should be an integer specifying the codepage that should be used
9032 to display the character set, t to do no translation and output as Unicode,
9033 or nil to do no translation and output as 8 bit (or multibyte on far-east
9034 versions of Windows) characters. */);
9035 Vw32_charset_info_alist
= Qnil
;
9037 staticpro (&Qw32_charset_ansi
);
9038 Qw32_charset_ansi
= intern ("w32-charset-ansi");
9039 staticpro (&Qw32_charset_symbol
);
9040 Qw32_charset_default
= intern ("w32-charset-default");
9041 staticpro (&Qw32_charset_default
);
9042 Qw32_charset_symbol
= intern ("w32-charset-symbol");
9043 staticpro (&Qw32_charset_shiftjis
);
9044 Qw32_charset_shiftjis
= intern ("w32-charset-shiftjis");
9045 staticpro (&Qw32_charset_hangeul
);
9046 Qw32_charset_hangeul
= intern ("w32-charset-hangeul");
9047 staticpro (&Qw32_charset_chinesebig5
);
9048 Qw32_charset_chinesebig5
= intern ("w32-charset-chinesebig5");
9049 staticpro (&Qw32_charset_gb2312
);
9050 Qw32_charset_gb2312
= intern ("w32-charset-gb2312");
9051 staticpro (&Qw32_charset_oem
);
9052 Qw32_charset_oem
= intern ("w32-charset-oem");
9054 #ifdef JOHAB_CHARSET
9056 static int w32_extra_charsets_defined
= 1;
9057 DEFVAR_BOOL ("w32-extra-charsets-defined", &w32_extra_charsets_defined
,
9058 doc
: /* Internal variable. */);
9060 staticpro (&Qw32_charset_johab
);
9061 Qw32_charset_johab
= intern ("w32-charset-johab");
9062 staticpro (&Qw32_charset_easteurope
);
9063 Qw32_charset_easteurope
= intern ("w32-charset-easteurope");
9064 staticpro (&Qw32_charset_turkish
);
9065 Qw32_charset_turkish
= intern ("w32-charset-turkish");
9066 staticpro (&Qw32_charset_baltic
);
9067 Qw32_charset_baltic
= intern ("w32-charset-baltic");
9068 staticpro (&Qw32_charset_russian
);
9069 Qw32_charset_russian
= intern ("w32-charset-russian");
9070 staticpro (&Qw32_charset_arabic
);
9071 Qw32_charset_arabic
= intern ("w32-charset-arabic");
9072 staticpro (&Qw32_charset_greek
);
9073 Qw32_charset_greek
= intern ("w32-charset-greek");
9074 staticpro (&Qw32_charset_hebrew
);
9075 Qw32_charset_hebrew
= intern ("w32-charset-hebrew");
9076 staticpro (&Qw32_charset_vietnamese
);
9077 Qw32_charset_vietnamese
= intern ("w32-charset-vietnamese");
9078 staticpro (&Qw32_charset_thai
);
9079 Qw32_charset_thai
= intern ("w32-charset-thai");
9080 staticpro (&Qw32_charset_mac
);
9081 Qw32_charset_mac
= intern ("w32-charset-mac");
9085 #ifdef UNICODE_CHARSET
9087 static int w32_unicode_charset_defined
= 1;
9088 DEFVAR_BOOL ("w32-unicode-charset-defined",
9089 &w32_unicode_charset_defined
,
9090 doc
: /* Internal variable. */);
9092 staticpro (&Qw32_charset_unicode
);
9093 Qw32_charset_unicode
= intern ("w32-charset-unicode");
9097 #if 0 /* TODO: Port to W32 */
9098 defsubr (&Sx_change_window_property
);
9099 defsubr (&Sx_delete_window_property
);
9100 defsubr (&Sx_window_property
);
9102 defsubr (&Sxw_display_color_p
);
9103 defsubr (&Sx_display_grayscale_p
);
9104 defsubr (&Sxw_color_defined_p
);
9105 defsubr (&Sxw_color_values
);
9106 defsubr (&Sx_server_max_request_size
);
9107 defsubr (&Sx_server_vendor
);
9108 defsubr (&Sx_server_version
);
9109 defsubr (&Sx_display_pixel_width
);
9110 defsubr (&Sx_display_pixel_height
);
9111 defsubr (&Sx_display_mm_width
);
9112 defsubr (&Sx_display_mm_height
);
9113 defsubr (&Sx_display_screens
);
9114 defsubr (&Sx_display_planes
);
9115 defsubr (&Sx_display_color_cells
);
9116 defsubr (&Sx_display_visual_class
);
9117 defsubr (&Sx_display_backing_store
);
9118 defsubr (&Sx_display_save_under
);
9119 defsubr (&Sx_create_frame
);
9120 defsubr (&Sx_open_connection
);
9121 defsubr (&Sx_close_connection
);
9122 defsubr (&Sx_display_list
);
9123 defsubr (&Sx_synchronize
);
9125 /* W32 specific functions */
9127 defsubr (&Sw32_focus_frame
);
9128 defsubr (&Sw32_select_font
);
9129 defsubr (&Sw32_define_rgb_color
);
9130 defsubr (&Sw32_default_color_map
);
9131 defsubr (&Sw32_load_color_file
);
9132 defsubr (&Sw32_send_sys_command
);
9133 defsubr (&Sw32_shell_execute
);
9134 defsubr (&Sw32_register_hot_key
);
9135 defsubr (&Sw32_unregister_hot_key
);
9136 defsubr (&Sw32_registered_hot_keys
);
9137 defsubr (&Sw32_reconstruct_hot_key
);
9138 defsubr (&Sw32_toggle_lock_key
);
9139 defsubr (&Sw32_window_exists_p
);
9140 defsubr (&Sw32_find_bdf_fonts
);
9142 defsubr (&Sfile_system_info
);
9143 defsubr (&Sdefault_printer_name
);
9145 /* Setting callback functions for fontset handler. */
9146 get_font_info_func
= w32_get_font_info
;
9148 #if 0 /* This function pointer doesn't seem to be used anywhere.
9149 And the pointer assigned has the wrong type, anyway. */
9150 list_fonts_func
= w32_list_fonts
;
9153 load_font_func
= w32_load_font
;
9154 find_ccl_program_func
= w32_find_ccl_program
;
9155 query_font_func
= w32_query_font
;
9156 set_frame_fontset_func
= x_set_font
;
9157 get_font_repertory_func
= x_get_font_repertory
;
9158 check_window_system_func
= check_w32
;
9161 hourglass_atimer
= NULL
;
9162 hourglass_shown_p
= 0;
9163 defsubr (&Sx_show_tip
);
9164 defsubr (&Sx_hide_tip
);
9166 staticpro (&tip_timer
);
9168 staticpro (&tip_frame
);
9170 last_show_tip_args
= Qnil
;
9171 staticpro (&last_show_tip_args
);
9173 defsubr (&Sx_file_dialog
);
9178 globals_of_w32fns is used to initialize those global variables that
9179 must always be initialized on startup even when the global variable
9180 initialized is non zero (see the function main in emacs.c).
9181 globals_of_w32fns is called from syms_of_w32fns when the global
9182 variable initialized is 0 and directly from main when initialized
9185 void globals_of_w32fns ()
9187 HMODULE user32_lib
= GetModuleHandle ("user32.dll");
9189 TrackMouseEvent not available in all versions of Windows, so must load
9190 it dynamically. Do it once, here, instead of every time it is used.
9192 track_mouse_event_fn
= (TrackMouseEvent_Proc
)
9193 GetProcAddress (user32_lib
, "TrackMouseEvent");
9194 /* ditto for GetClipboardSequenceNumber. */
9195 clipboard_sequence_fn
= (ClipboardSequence_Proc
)
9196 GetProcAddress (user32_lib
, "GetClipboardSequenceNumber");
9198 DEFVAR_INT ("w32-ansi-code-page",
9199 &w32_ansi_code_page
,
9200 doc
: /* The ANSI code page used by the system. */);
9201 w32_ansi_code_page
= GetACP ();
9206 void w32_abort (void) NO_RETURN
;
9212 button
= MessageBox (NULL
,
9213 "A fatal error has occurred!\n\n"
9214 "Would you like to attach a debugger?\n\n"
9215 "Select YES to debug, NO to abort Emacs"
9217 "\n\n(type \"gdb -p <emacs-PID>\" and\n"
9218 "\"continue\" inside GDB before clicking YES.)"
9220 , "Emacs Abort Dialog",
9221 MB_ICONEXCLAMATION
| MB_TASKMODAL
9222 | MB_SETFOREGROUND
| MB_YESNO
);
9227 exit (2); /* tell the compiler we will never return */
9235 /* For convenience when debugging. */
9239 return GetLastError ();
9242 /* arch-tag: 707589ab-b9be-4638-8cdd-74629cc9b446
9243 (do not change this comment) */