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, 2008
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 /* Added by Kevin Gallo */
38 #include "intervals.h"
39 #include "dispextern.h"
41 #include "blockinput.h"
43 #include "character.h"
49 #include "termhooks.h"
52 #include "bitmaps/gray.xbm"
63 #define FILE_NAME_TEXT_FIELD edt1
65 #ifdef USE_FONT_BACKEND
69 void syms_of_w32fns ();
70 void globals_of_w32fns ();
72 extern void free_frame_menubar ();
73 extern double atof ();
74 extern int w32_console_toggle_lock_key
P_ ((int, Lisp_Object
));
75 extern void w32_menu_display_help
P_ ((HWND
, HMENU
, UINT
, UINT
));
76 extern void w32_free_menu_strings
P_ ((HWND
));
77 extern XCharStruct
*w32_per_char_metric
P_ ((XFontStruct
*, wchar_t *, int));
81 extern char *lispy_function_keys
[];
83 /* The colormap for converting color names to RGB values */
84 Lisp_Object Vw32_color_map
;
86 /* Non nil if alt key presses are passed on to Windows. */
87 Lisp_Object Vw32_pass_alt_to_system
;
89 /* Non nil if alt key is translated to meta_modifier, nil if it is translated
91 Lisp_Object Vw32_alt_is_meta
;
93 /* If non-zero, the windows virtual key code for an alternative quit key. */
96 /* Non nil if left window key events are passed on to Windows (this only
97 affects whether "tapping" the key opens the Start menu). */
98 Lisp_Object Vw32_pass_lwindow_to_system
;
100 /* Non nil if right window key events are passed on to Windows (this
101 only affects whether "tapping" the key opens the Start menu). */
102 Lisp_Object Vw32_pass_rwindow_to_system
;
104 /* Virtual key code used to generate "phantom" key presses in order
105 to stop system from acting on Windows key events. */
106 Lisp_Object Vw32_phantom_key_code
;
108 /* Modifier associated with the left "Windows" key, or nil to act as a
110 Lisp_Object Vw32_lwindow_modifier
;
112 /* Modifier associated with the right "Windows" key, or nil to act as a
114 Lisp_Object Vw32_rwindow_modifier
;
116 /* Modifier associated with the "Apps" key, or nil to act as a normal
118 Lisp_Object Vw32_apps_modifier
;
120 /* Value is nil if Num Lock acts as a function key. */
121 Lisp_Object Vw32_enable_num_lock
;
123 /* Value is nil if Caps Lock acts as a function key. */
124 Lisp_Object Vw32_enable_caps_lock
;
126 /* Modifier associated with Scroll Lock, or nil to act as a normal key. */
127 Lisp_Object Vw32_scroll_lock_modifier
;
129 /* Switch to control whether we inhibit requests for synthesized bold
130 and italic versions of fonts. */
131 int w32_enable_synthesized_fonts
;
133 /* Enable palette management. */
134 Lisp_Object Vw32_enable_palette
;
136 /* Control how close left/right button down events must be to
137 be converted to a middle button down event. */
138 int w32_mouse_button_tolerance
;
140 /* Minimum interval between mouse movement (and scroll bar drag)
141 events that are passed on to the event loop. */
142 int w32_mouse_move_interval
;
144 /* Flag to indicate if XBUTTON events should be passed on to Windows. */
145 static int w32_pass_extra_mouse_buttons_to_system
;
147 /* Flag to indicate if media keys should be passed on to Windows. */
148 static int w32_pass_multimedia_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 static int w32_strict_fontnames
;
189 /* A flag to control whether we should only repaint if GetUpdateRect
190 indicates there is an update region. */
191 static int w32_strict_painting
;
193 /* Associative list linking character set strings to Windows codepages. */
194 static 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 /* Multi-monitor API definitions that are not pulled from the headers
265 since we are compiling for NT 4. */
266 #ifndef MONITOR_DEFAULT_TO_NEAREST
267 #define MONITOR_DEFAULT_TO_NEAREST 2
269 /* MinGW headers define MONITORINFO unconditionally, but MSVC ones don't.
270 To avoid a compile error on one or the other, redefine with a new name. */
279 typedef BOOL (WINAPI
* TrackMouseEvent_Proc
)
280 (IN OUT LPTRACKMOUSEEVENT lpEventTrack
);
281 typedef LONG (WINAPI
* ImmGetCompositionString_Proc
)
282 (IN HIMC context
, IN DWORD index
, OUT LPVOID buffer
, IN DWORD bufLen
);
283 typedef HIMC (WINAPI
* ImmGetContext_Proc
) (IN HWND window
);
284 typedef HMONITOR (WINAPI
* MonitorFromPoint_Proc
) (IN POINT pt
, IN DWORD flags
);
285 typedef BOOL (WINAPI
* GetMonitorInfo_Proc
)
286 (IN HMONITOR monitor
, OUT
struct MONITOR_INFO
* info
);
288 TrackMouseEvent_Proc track_mouse_event_fn
= NULL
;
289 ClipboardSequence_Proc clipboard_sequence_fn
= NULL
;
290 ImmGetCompositionString_Proc get_composition_string_fn
= NULL
;
291 ImmGetContext_Proc get_ime_context_fn
= NULL
;
292 MonitorFromPoint_Proc monitor_from_point_fn
= NULL
;
293 GetMonitorInfo_Proc get_monitor_info_fn
= NULL
;
295 extern AppendMenuW_Proc unicode_append_menu
;
297 /* Flag to selectively ignore WM_IME_CHAR messages. */
298 static int ignore_ime_char
= 0;
300 /* W95 mousewheel handler */
301 unsigned int msh_mousewheel
= 0;
304 #define MOUSE_BUTTON_ID 1
305 #define MOUSE_MOVE_ID 2
306 #define MENU_FREE_ID 3
307 /* The delay (milliseconds) before a menu is freed after WM_EXITMENULOOP
309 #define MENU_FREE_DELAY 1000
310 static unsigned menu_free_timer
= 0;
312 /* The below are defined in frame.c. */
314 extern Lisp_Object Vwindow_system_version
;
317 int image_cache_refcount
, dpyinfo_refcount
;
321 /* From w32term.c. */
322 extern int w32_num_mouse_buttons
;
323 extern Lisp_Object Vw32_recognize_altgr
;
325 extern HWND w32_system_caret_hwnd
;
327 extern int w32_system_caret_height
;
328 extern int w32_system_caret_x
;
329 extern int w32_system_caret_y
;
330 extern int w32_use_visible_system_caret
;
332 static HWND w32_visible_system_caret_hwnd
;
335 extern HMENU current_popup_menu
;
336 static int menubar_in_use
= 0;
338 /* From w32uniscribe.h */
339 #ifdef USE_FONT_BACKEND
340 extern void syms_of_w32uniscribe ();
341 extern int uniscribe_available
;
345 /* Error if we are not connected to MS-Windows. */
350 error ("MS-Windows not in use or not initialized");
353 /* Nonzero if we can use mouse menus.
354 You should not call this unless HAVE_MENUS is defined. */
362 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
363 and checking validity for W32. */
366 check_x_frame (frame
)
372 frame
= selected_frame
;
373 CHECK_LIVE_FRAME (frame
);
375 if (! FRAME_W32_P (f
))
376 error ("Non-W32 frame used");
380 /* Let the user specify a display with a frame.
381 nil stands for the selected frame--or, if that is not a w32 frame,
382 the first display on the list. */
384 struct w32_display_info
*
385 check_x_display_info (frame
)
390 struct frame
*sf
= XFRAME (selected_frame
);
392 if (FRAME_W32_P (sf
) && FRAME_LIVE_P (sf
))
393 return FRAME_W32_DISPLAY_INFO (sf
);
395 return &one_w32_display_info
;
397 else if (STRINGP (frame
))
398 return x_display_info_for_name (frame
);
403 CHECK_LIVE_FRAME (frame
);
405 if (! FRAME_W32_P (f
))
406 error ("Non-W32 frame used");
407 return FRAME_W32_DISPLAY_INFO (f
);
411 /* Return the Emacs frame-object corresponding to an w32 window.
412 It could be the frame's main window or an icon window. */
414 /* This function can be called during GC, so use GC_xxx type test macros. */
417 x_window_to_frame (dpyinfo
, wdesc
)
418 struct w32_display_info
*dpyinfo
;
421 Lisp_Object tail
, frame
;
424 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
430 if (!FRAME_W32_P (f
) || FRAME_W32_DISPLAY_INFO (f
) != dpyinfo
)
432 if (f
->output_data
.w32
->hourglass_window
== wdesc
)
435 if (FRAME_W32_WINDOW (f
) == wdesc
)
442 static Lisp_Object unwind_create_frame
P_ ((Lisp_Object
));
443 static Lisp_Object unwind_create_tip_frame
P_ ((Lisp_Object
));
444 static void my_create_window
P_ ((struct frame
*));
445 static void my_create_tip_window
P_ ((struct frame
*));
447 /* TODO: Native Input Method support; see x_create_im. */
448 void x_set_foreground_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
449 void x_set_background_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
450 void x_set_mouse_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
451 void x_set_cursor_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
452 void x_set_border_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
453 void x_set_cursor_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
454 void x_set_icon_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
455 void x_set_icon_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
456 void x_explicitly_set_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
457 void x_set_menu_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
458 void x_set_title
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
459 void x_set_tool_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
460 static void x_edge_detection
P_ ((struct frame
*, struct image
*, Lisp_Object
,
466 /* Store the screen positions of frame F into XPTR and YPTR.
467 These are the positions of the containing window manager window,
468 not Emacs's own window. */
471 x_real_positions (f
, xptr
, yptr
)
478 /* Get the bounds of the WM window. */
479 GetWindowRect (FRAME_W32_WINDOW (f
), &rect
);
484 /* Convert (0, 0) in the client area to screen co-ordinates. */
485 ClientToScreen (FRAME_W32_WINDOW (f
), &pt
);
487 /* Remember x_pixels_diff and y_pixels_diff. */
488 f
->x_pixels_diff
= pt
.x
- rect
.left
;
489 f
->y_pixels_diff
= pt
.y
- rect
.top
;
497 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
,
498 Sw32_define_rgb_color
, 4, 4, 0,
499 doc
: /* Convert RGB numbers to a windows color reference and associate with NAME.
500 This adds or updates a named color to `w32-color-map', making it
501 available for use. The original entry's RGB ref is returned, or nil
502 if the entry is new. */)
503 (red
, green
, blue
, name
)
504 Lisp_Object red
, green
, blue
, name
;
507 Lisp_Object oldrgb
= Qnil
;
511 CHECK_NUMBER (green
);
515 XSETINT (rgb
, RGB (XUINT (red
), XUINT (green
), XUINT (blue
)));
519 /* replace existing entry in w32-color-map or add new entry. */
520 entry
= Fassoc (name
, Vw32_color_map
);
523 entry
= Fcons (name
, rgb
);
524 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
528 oldrgb
= Fcdr (entry
);
529 Fsetcdr (entry
, rgb
);
537 DEFUN ("w32-load-color-file", Fw32_load_color_file
,
538 Sw32_load_color_file
, 1, 1, 0,
539 doc
: /* Create an alist of color entries from an external file.
540 Assign this value to `w32-color-map' to replace the existing color map.
542 The file should define one named RGB color per line like so:
544 where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
546 Lisp_Object filename
;
549 Lisp_Object cmap
= Qnil
;
552 CHECK_STRING (filename
);
553 abspath
= Fexpand_file_name (filename
, Qnil
);
555 fp
= fopen (SDATA (filename
), "rt");
559 int red
, green
, blue
;
564 while (fgets (buf
, sizeof (buf
), fp
) != NULL
) {
565 if (sscanf (buf
, "%u %u %u %n", &red
, &green
, &blue
, &num
) == 3)
567 char *name
= buf
+ num
;
568 num
= strlen (name
) - 1;
569 if (name
[num
] == '\n')
571 cmap
= Fcons (Fcons (build_string (name
),
572 make_number (RGB (red
, green
, blue
))),
584 /* The default colors for the w32 color map */
585 typedef struct colormap_t
591 colormap_t w32_color_map
[] =
593 {"snow" , PALETTERGB (255,250,250)},
594 {"ghost white" , PALETTERGB (248,248,255)},
595 {"GhostWhite" , PALETTERGB (248,248,255)},
596 {"white smoke" , PALETTERGB (245,245,245)},
597 {"WhiteSmoke" , PALETTERGB (245,245,245)},
598 {"gainsboro" , PALETTERGB (220,220,220)},
599 {"floral white" , PALETTERGB (255,250,240)},
600 {"FloralWhite" , PALETTERGB (255,250,240)},
601 {"old lace" , PALETTERGB (253,245,230)},
602 {"OldLace" , PALETTERGB (253,245,230)},
603 {"linen" , PALETTERGB (250,240,230)},
604 {"antique white" , PALETTERGB (250,235,215)},
605 {"AntiqueWhite" , PALETTERGB (250,235,215)},
606 {"papaya whip" , PALETTERGB (255,239,213)},
607 {"PapayaWhip" , PALETTERGB (255,239,213)},
608 {"blanched almond" , PALETTERGB (255,235,205)},
609 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
610 {"bisque" , PALETTERGB (255,228,196)},
611 {"peach puff" , PALETTERGB (255,218,185)},
612 {"PeachPuff" , PALETTERGB (255,218,185)},
613 {"navajo white" , PALETTERGB (255,222,173)},
614 {"NavajoWhite" , PALETTERGB (255,222,173)},
615 {"moccasin" , PALETTERGB (255,228,181)},
616 {"cornsilk" , PALETTERGB (255,248,220)},
617 {"ivory" , PALETTERGB (255,255,240)},
618 {"lemon chiffon" , PALETTERGB (255,250,205)},
619 {"LemonChiffon" , PALETTERGB (255,250,205)},
620 {"seashell" , PALETTERGB (255,245,238)},
621 {"honeydew" , PALETTERGB (240,255,240)},
622 {"mint cream" , PALETTERGB (245,255,250)},
623 {"MintCream" , PALETTERGB (245,255,250)},
624 {"azure" , PALETTERGB (240,255,255)},
625 {"alice blue" , PALETTERGB (240,248,255)},
626 {"AliceBlue" , PALETTERGB (240,248,255)},
627 {"lavender" , PALETTERGB (230,230,250)},
628 {"lavender blush" , PALETTERGB (255,240,245)},
629 {"LavenderBlush" , PALETTERGB (255,240,245)},
630 {"misty rose" , PALETTERGB (255,228,225)},
631 {"MistyRose" , PALETTERGB (255,228,225)},
632 {"white" , PALETTERGB (255,255,255)},
633 {"black" , PALETTERGB ( 0, 0, 0)},
634 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
635 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
636 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
637 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
638 {"dim gray" , PALETTERGB (105,105,105)},
639 {"DimGray" , PALETTERGB (105,105,105)},
640 {"dim grey" , PALETTERGB (105,105,105)},
641 {"DimGrey" , PALETTERGB (105,105,105)},
642 {"slate gray" , PALETTERGB (112,128,144)},
643 {"SlateGray" , PALETTERGB (112,128,144)},
644 {"slate grey" , PALETTERGB (112,128,144)},
645 {"SlateGrey" , PALETTERGB (112,128,144)},
646 {"light slate gray" , PALETTERGB (119,136,153)},
647 {"LightSlateGray" , PALETTERGB (119,136,153)},
648 {"light slate grey" , PALETTERGB (119,136,153)},
649 {"LightSlateGrey" , PALETTERGB (119,136,153)},
650 {"gray" , PALETTERGB (190,190,190)},
651 {"grey" , PALETTERGB (190,190,190)},
652 {"light grey" , PALETTERGB (211,211,211)},
653 {"LightGrey" , PALETTERGB (211,211,211)},
654 {"light gray" , PALETTERGB (211,211,211)},
655 {"LightGray" , PALETTERGB (211,211,211)},
656 {"midnight blue" , PALETTERGB ( 25, 25,112)},
657 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
658 {"navy" , PALETTERGB ( 0, 0,128)},
659 {"navy blue" , PALETTERGB ( 0, 0,128)},
660 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
661 {"cornflower blue" , PALETTERGB (100,149,237)},
662 {"CornflowerBlue" , PALETTERGB (100,149,237)},
663 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
664 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
665 {"slate blue" , PALETTERGB (106, 90,205)},
666 {"SlateBlue" , PALETTERGB (106, 90,205)},
667 {"medium slate blue" , PALETTERGB (123,104,238)},
668 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
669 {"light slate blue" , PALETTERGB (132,112,255)},
670 {"LightSlateBlue" , PALETTERGB (132,112,255)},
671 {"medium blue" , PALETTERGB ( 0, 0,205)},
672 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
673 {"royal blue" , PALETTERGB ( 65,105,225)},
674 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
675 {"blue" , PALETTERGB ( 0, 0,255)},
676 {"dodger blue" , PALETTERGB ( 30,144,255)},
677 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
678 {"deep sky blue" , PALETTERGB ( 0,191,255)},
679 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
680 {"sky blue" , PALETTERGB (135,206,235)},
681 {"SkyBlue" , PALETTERGB (135,206,235)},
682 {"light sky blue" , PALETTERGB (135,206,250)},
683 {"LightSkyBlue" , PALETTERGB (135,206,250)},
684 {"steel blue" , PALETTERGB ( 70,130,180)},
685 {"SteelBlue" , PALETTERGB ( 70,130,180)},
686 {"light steel blue" , PALETTERGB (176,196,222)},
687 {"LightSteelBlue" , PALETTERGB (176,196,222)},
688 {"light blue" , PALETTERGB (173,216,230)},
689 {"LightBlue" , PALETTERGB (173,216,230)},
690 {"powder blue" , PALETTERGB (176,224,230)},
691 {"PowderBlue" , PALETTERGB (176,224,230)},
692 {"pale turquoise" , PALETTERGB (175,238,238)},
693 {"PaleTurquoise" , PALETTERGB (175,238,238)},
694 {"dark turquoise" , PALETTERGB ( 0,206,209)},
695 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
696 {"medium turquoise" , PALETTERGB ( 72,209,204)},
697 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
698 {"turquoise" , PALETTERGB ( 64,224,208)},
699 {"cyan" , PALETTERGB ( 0,255,255)},
700 {"light cyan" , PALETTERGB (224,255,255)},
701 {"LightCyan" , PALETTERGB (224,255,255)},
702 {"cadet blue" , PALETTERGB ( 95,158,160)},
703 {"CadetBlue" , PALETTERGB ( 95,158,160)},
704 {"medium aquamarine" , PALETTERGB (102,205,170)},
705 {"MediumAquamarine" , PALETTERGB (102,205,170)},
706 {"aquamarine" , PALETTERGB (127,255,212)},
707 {"dark green" , PALETTERGB ( 0,100, 0)},
708 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
709 {"dark olive green" , PALETTERGB ( 85,107, 47)},
710 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
711 {"dark sea green" , PALETTERGB (143,188,143)},
712 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
713 {"sea green" , PALETTERGB ( 46,139, 87)},
714 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
715 {"medium sea green" , PALETTERGB ( 60,179,113)},
716 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
717 {"light sea green" , PALETTERGB ( 32,178,170)},
718 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
719 {"pale green" , PALETTERGB (152,251,152)},
720 {"PaleGreen" , PALETTERGB (152,251,152)},
721 {"spring green" , PALETTERGB ( 0,255,127)},
722 {"SpringGreen" , PALETTERGB ( 0,255,127)},
723 {"lawn green" , PALETTERGB (124,252, 0)},
724 {"LawnGreen" , PALETTERGB (124,252, 0)},
725 {"green" , PALETTERGB ( 0,255, 0)},
726 {"chartreuse" , PALETTERGB (127,255, 0)},
727 {"medium spring green" , PALETTERGB ( 0,250,154)},
728 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
729 {"green yellow" , PALETTERGB (173,255, 47)},
730 {"GreenYellow" , PALETTERGB (173,255, 47)},
731 {"lime green" , PALETTERGB ( 50,205, 50)},
732 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
733 {"yellow green" , PALETTERGB (154,205, 50)},
734 {"YellowGreen" , PALETTERGB (154,205, 50)},
735 {"forest green" , PALETTERGB ( 34,139, 34)},
736 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
737 {"olive drab" , PALETTERGB (107,142, 35)},
738 {"OliveDrab" , PALETTERGB (107,142, 35)},
739 {"dark khaki" , PALETTERGB (189,183,107)},
740 {"DarkKhaki" , PALETTERGB (189,183,107)},
741 {"khaki" , PALETTERGB (240,230,140)},
742 {"pale goldenrod" , PALETTERGB (238,232,170)},
743 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
744 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
745 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
746 {"light yellow" , PALETTERGB (255,255,224)},
747 {"LightYellow" , PALETTERGB (255,255,224)},
748 {"yellow" , PALETTERGB (255,255, 0)},
749 {"gold" , PALETTERGB (255,215, 0)},
750 {"light goldenrod" , PALETTERGB (238,221,130)},
751 {"LightGoldenrod" , PALETTERGB (238,221,130)},
752 {"goldenrod" , PALETTERGB (218,165, 32)},
753 {"dark goldenrod" , PALETTERGB (184,134, 11)},
754 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
755 {"rosy brown" , PALETTERGB (188,143,143)},
756 {"RosyBrown" , PALETTERGB (188,143,143)},
757 {"indian red" , PALETTERGB (205, 92, 92)},
758 {"IndianRed" , PALETTERGB (205, 92, 92)},
759 {"saddle brown" , PALETTERGB (139, 69, 19)},
760 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
761 {"sienna" , PALETTERGB (160, 82, 45)},
762 {"peru" , PALETTERGB (205,133, 63)},
763 {"burlywood" , PALETTERGB (222,184,135)},
764 {"beige" , PALETTERGB (245,245,220)},
765 {"wheat" , PALETTERGB (245,222,179)},
766 {"sandy brown" , PALETTERGB (244,164, 96)},
767 {"SandyBrown" , PALETTERGB (244,164, 96)},
768 {"tan" , PALETTERGB (210,180,140)},
769 {"chocolate" , PALETTERGB (210,105, 30)},
770 {"firebrick" , PALETTERGB (178,34, 34)},
771 {"brown" , PALETTERGB (165,42, 42)},
772 {"dark salmon" , PALETTERGB (233,150,122)},
773 {"DarkSalmon" , PALETTERGB (233,150,122)},
774 {"salmon" , PALETTERGB (250,128,114)},
775 {"light salmon" , PALETTERGB (255,160,122)},
776 {"LightSalmon" , PALETTERGB (255,160,122)},
777 {"orange" , PALETTERGB (255,165, 0)},
778 {"dark orange" , PALETTERGB (255,140, 0)},
779 {"DarkOrange" , PALETTERGB (255,140, 0)},
780 {"coral" , PALETTERGB (255,127, 80)},
781 {"light coral" , PALETTERGB (240,128,128)},
782 {"LightCoral" , PALETTERGB (240,128,128)},
783 {"tomato" , PALETTERGB (255, 99, 71)},
784 {"orange red" , PALETTERGB (255, 69, 0)},
785 {"OrangeRed" , PALETTERGB (255, 69, 0)},
786 {"red" , PALETTERGB (255, 0, 0)},
787 {"hot pink" , PALETTERGB (255,105,180)},
788 {"HotPink" , PALETTERGB (255,105,180)},
789 {"deep pink" , PALETTERGB (255, 20,147)},
790 {"DeepPink" , PALETTERGB (255, 20,147)},
791 {"pink" , PALETTERGB (255,192,203)},
792 {"light pink" , PALETTERGB (255,182,193)},
793 {"LightPink" , PALETTERGB (255,182,193)},
794 {"pale violet red" , PALETTERGB (219,112,147)},
795 {"PaleVioletRed" , PALETTERGB (219,112,147)},
796 {"maroon" , PALETTERGB (176, 48, 96)},
797 {"medium violet red" , PALETTERGB (199, 21,133)},
798 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
799 {"violet red" , PALETTERGB (208, 32,144)},
800 {"VioletRed" , PALETTERGB (208, 32,144)},
801 {"magenta" , PALETTERGB (255, 0,255)},
802 {"violet" , PALETTERGB (238,130,238)},
803 {"plum" , PALETTERGB (221,160,221)},
804 {"orchid" , PALETTERGB (218,112,214)},
805 {"medium orchid" , PALETTERGB (186, 85,211)},
806 {"MediumOrchid" , PALETTERGB (186, 85,211)},
807 {"dark orchid" , PALETTERGB (153, 50,204)},
808 {"DarkOrchid" , PALETTERGB (153, 50,204)},
809 {"dark violet" , PALETTERGB (148, 0,211)},
810 {"DarkViolet" , PALETTERGB (148, 0,211)},
811 {"blue violet" , PALETTERGB (138, 43,226)},
812 {"BlueViolet" , PALETTERGB (138, 43,226)},
813 {"purple" , PALETTERGB (160, 32,240)},
814 {"medium purple" , PALETTERGB (147,112,219)},
815 {"MediumPurple" , PALETTERGB (147,112,219)},
816 {"thistle" , PALETTERGB (216,191,216)},
817 {"gray0" , PALETTERGB ( 0, 0, 0)},
818 {"grey0" , PALETTERGB ( 0, 0, 0)},
819 {"dark grey" , PALETTERGB (169,169,169)},
820 {"DarkGrey" , PALETTERGB (169,169,169)},
821 {"dark gray" , PALETTERGB (169,169,169)},
822 {"DarkGray" , PALETTERGB (169,169,169)},
823 {"dark blue" , PALETTERGB ( 0, 0,139)},
824 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
825 {"dark cyan" , PALETTERGB ( 0,139,139)},
826 {"DarkCyan" , PALETTERGB ( 0,139,139)},
827 {"dark magenta" , PALETTERGB (139, 0,139)},
828 {"DarkMagenta" , PALETTERGB (139, 0,139)},
829 {"dark red" , PALETTERGB (139, 0, 0)},
830 {"DarkRed" , PALETTERGB (139, 0, 0)},
831 {"light green" , PALETTERGB (144,238,144)},
832 {"LightGreen" , PALETTERGB (144,238,144)},
835 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
836 0, 0, 0, doc
: /* Return the default color map. */)
840 colormap_t
*pc
= w32_color_map
;
847 for (i
= 0; i
< sizeof (w32_color_map
) / sizeof (w32_color_map
[0]);
849 cmap
= Fcons (Fcons (build_string (pc
->name
),
850 make_number (pc
->colorref
)),
868 color
= Frassq (rgb
, Vw32_color_map
);
873 return (Fcar (color
));
879 w32_color_map_lookup (colorname
)
882 Lisp_Object tail
, ret
= Qnil
;
886 for (tail
= Vw32_color_map
; CONSP (tail
); tail
= XCDR (tail
))
888 register Lisp_Object elt
, tem
;
891 if (!CONSP (elt
)) continue;
895 if (lstrcmpi (SDATA (tem
), colorname
) == 0)
912 add_system_logical_colors_to_map (system_colors
)
913 Lisp_Object
*system_colors
;
917 /* Other registry operations are done with input blocked. */
920 /* Look for "Control Panel/Colors" under User and Machine registry
922 if (RegOpenKeyEx (HKEY_CURRENT_USER
, "Control Panel\\Colors", 0,
923 KEY_READ
, &colors_key
) == ERROR_SUCCESS
924 || RegOpenKeyEx (HKEY_LOCAL_MACHINE
, "Control Panel\\Colors", 0,
925 KEY_READ
, &colors_key
) == ERROR_SUCCESS
)
928 char color_buffer
[64];
929 char full_name_buffer
[MAX_PATH
+ SYSTEM_COLOR_PREFIX_LEN
];
931 DWORD name_size
, color_size
;
932 char *name_buffer
= full_name_buffer
+ SYSTEM_COLOR_PREFIX_LEN
;
934 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
935 color_size
= sizeof (color_buffer
);
937 strcpy (full_name_buffer
, SYSTEM_COLOR_PREFIX
);
939 while (RegEnumValueA (colors_key
, index
, name_buffer
, &name_size
,
940 NULL
, NULL
, color_buffer
, &color_size
)
944 if (sscanf (color_buffer
, " %u %u %u", &r
, &g
, &b
) == 3)
945 *system_colors
= Fcons (Fcons (build_string (full_name_buffer
),
946 make_number (RGB (r
, g
, b
))),
949 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
950 color_size
= sizeof (color_buffer
);
953 RegCloseKey (colors_key
);
961 x_to_w32_color (colorname
)
964 register Lisp_Object ret
= Qnil
;
968 if (colorname
[0] == '#')
970 /* Could be an old-style RGB Device specification. */
973 color
= colorname
+ 1;
975 size
= strlen (color
);
976 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
984 for (i
= 0; i
< 3; i
++)
990 /* The check for 'x' in the following conditional takes into
991 account the fact that strtol allows a "0x" in front of
992 our numbers, and we don't. */
993 if (!isxdigit (color
[0]) || color
[1] == 'x')
997 value
= strtoul (color
, &end
, 16);
999 if (errno
== ERANGE
|| end
- color
!= size
)
1004 value
= value
* 0x10;
1015 colorval
|= (value
<< pos
);
1020 XSETINT (ret
, colorval
);
1027 else if (strnicmp (colorname
, "rgb:", 4) == 0)
1035 color
= colorname
+ 4;
1036 for (i
= 0; i
< 3; i
++)
1039 unsigned long value
;
1041 /* The check for 'x' in the following conditional takes into
1042 account the fact that strtol allows a "0x" in front of
1043 our numbers, and we don't. */
1044 if (!isxdigit (color
[0]) || color
[1] == 'x')
1046 value
= strtoul (color
, &end
, 16);
1047 if (errno
== ERANGE
)
1049 switch (end
- color
)
1052 value
= value
* 0x10 + value
;
1065 if (value
== ULONG_MAX
)
1067 colorval
|= (value
<< pos
);
1074 XSETINT (ret
, colorval
);
1082 else if (strnicmp (colorname
, "rgbi:", 5) == 0)
1084 /* This is an RGB Intensity specification. */
1091 color
= colorname
+ 5;
1092 for (i
= 0; i
< 3; i
++)
1098 value
= strtod (color
, &end
);
1099 if (errno
== ERANGE
)
1101 if (value
< 0.0 || value
> 1.0)
1103 val
= (UINT
)(0x100 * value
);
1104 /* We used 0x100 instead of 0xFF to give a continuous
1105 range between 0.0 and 1.0 inclusive. The next statement
1106 fixes the 1.0 case. */
1109 colorval
|= (val
<< pos
);
1116 XSETINT (ret
, colorval
);
1124 /* I am not going to attempt to handle any of the CIE color schemes
1125 or TekHVC, since I don't know the algorithms for conversion to
1128 /* If we fail to lookup the color name in w32_color_map, then check the
1129 colorname to see if it can be crudely approximated: If the X color
1130 ends in a number (e.g., "darkseagreen2"), strip the number and
1131 return the result of looking up the base color name. */
1132 ret
= w32_color_map_lookup (colorname
);
1135 int len
= strlen (colorname
);
1137 if (isdigit (colorname
[len
- 1]))
1139 char *ptr
, *approx
= alloca (len
+ 1);
1141 strcpy (approx
, colorname
);
1142 ptr
= &approx
[len
- 1];
1143 while (ptr
> approx
&& isdigit (*ptr
))
1146 ret
= w32_color_map_lookup (approx
);
1155 w32_regenerate_palette (FRAME_PTR f
)
1157 struct w32_palette_entry
* list
;
1158 LOGPALETTE
* log_palette
;
1159 HPALETTE new_palette
;
1162 /* don't bother trying to create palette if not supported */
1163 if (! FRAME_W32_DISPLAY_INFO (f
)->has_palette
)
1166 log_palette
= (LOGPALETTE
*)
1167 alloca (sizeof (LOGPALETTE
) +
1168 FRAME_W32_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
1169 log_palette
->palVersion
= 0x300;
1170 log_palette
->palNumEntries
= FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1172 list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1174 i
< FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1175 i
++, list
= list
->next
)
1176 log_palette
->palPalEntry
[i
] = list
->entry
;
1178 new_palette
= CreatePalette (log_palette
);
1182 if (FRAME_W32_DISPLAY_INFO (f
)->palette
)
1183 DeleteObject (FRAME_W32_DISPLAY_INFO (f
)->palette
);
1184 FRAME_W32_DISPLAY_INFO (f
)->palette
= new_palette
;
1186 /* Realize display palette and garbage all frames. */
1187 release_frame_dc (f
, get_frame_dc (f
));
1192 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
1193 #define SET_W32_COLOR(pe, color) \
1196 pe.peRed = GetRValue (color); \
1197 pe.peGreen = GetGValue (color); \
1198 pe.peBlue = GetBValue (color); \
1203 /* Keep these around in case we ever want to track color usage. */
1205 w32_map_color (FRAME_PTR f
, COLORREF color
)
1207 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1209 if (NILP (Vw32_enable_palette
))
1212 /* check if color is already mapped */
1215 if (W32_COLOR (list
->entry
) == color
)
1223 /* not already mapped, so add to list and recreate Windows palette */
1224 list
= (struct w32_palette_entry
*)
1225 xmalloc (sizeof (struct w32_palette_entry
));
1226 SET_W32_COLOR (list
->entry
, color
);
1228 list
->next
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1229 FRAME_W32_DISPLAY_INFO (f
)->color_list
= list
;
1230 FRAME_W32_DISPLAY_INFO (f
)->num_colors
++;
1232 /* set flag that palette must be regenerated */
1233 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1237 w32_unmap_color (FRAME_PTR f
, COLORREF color
)
1239 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1240 struct w32_palette_entry
**prev
= &FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1242 if (NILP (Vw32_enable_palette
))
1245 /* check if color is already mapped */
1248 if (W32_COLOR (list
->entry
) == color
)
1250 if (--list
->refcount
== 0)
1254 FRAME_W32_DISPLAY_INFO (f
)->num_colors
--;
1264 /* set flag that palette must be regenerated */
1265 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1270 /* Gamma-correct COLOR on frame F. */
1273 gamma_correct (f
, color
)
1279 *color
= PALETTERGB (
1280 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1281 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1282 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1287 /* Decide if color named COLOR is valid for the display associated with
1288 the selected frame; if so, return the rgb values in COLOR_DEF.
1289 If ALLOC is nonzero, allocate a new colormap cell. */
1292 w32_defined_color (f
, color
, color_def
, alloc
)
1298 register Lisp_Object tem
;
1299 COLORREF w32_color_ref
;
1301 tem
= x_to_w32_color (color
);
1307 /* Apply gamma correction. */
1308 w32_color_ref
= XUINT (tem
);
1309 gamma_correct (f
, &w32_color_ref
);
1310 XSETINT (tem
, w32_color_ref
);
1313 /* Map this color to the palette if it is enabled. */
1314 if (!NILP (Vw32_enable_palette
))
1316 struct w32_palette_entry
* entry
=
1317 one_w32_display_info
.color_list
;
1318 struct w32_palette_entry
** prev
=
1319 &one_w32_display_info
.color_list
;
1321 /* check if color is already mapped */
1324 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1326 prev
= &entry
->next
;
1327 entry
= entry
->next
;
1330 if (entry
== NULL
&& alloc
)
1332 /* not already mapped, so add to list */
1333 entry
= (struct w32_palette_entry
*)
1334 xmalloc (sizeof (struct w32_palette_entry
));
1335 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1338 one_w32_display_info
.num_colors
++;
1340 /* set flag that palette must be regenerated */
1341 one_w32_display_info
.regen_palette
= TRUE
;
1344 /* Ensure COLORREF value is snapped to nearest color in (default)
1345 palette by simulating the PALETTERGB macro. This works whether
1346 or not the display device has a palette. */
1347 w32_color_ref
= XUINT (tem
) | 0x2000000;
1349 color_def
->pixel
= w32_color_ref
;
1350 color_def
->red
= GetRValue (w32_color_ref
) * 256;
1351 color_def
->green
= GetGValue (w32_color_ref
) * 256;
1352 color_def
->blue
= GetBValue (w32_color_ref
) * 256;
1362 /* Given a string ARG naming a color, compute a pixel value from it
1363 suitable for screen F.
1364 If F is not a color screen, return DEF (default) regardless of what
1368 x_decode_color (f
, arg
, def
)
1377 if (strcmp (SDATA (arg
), "black") == 0)
1378 return BLACK_PIX_DEFAULT (f
);
1379 else if (strcmp (SDATA (arg
), "white") == 0)
1380 return WHITE_PIX_DEFAULT (f
);
1382 if ((FRAME_W32_DISPLAY_INFO (f
)->n_planes
* FRAME_W32_DISPLAY_INFO (f
)->n_cbits
) == 1)
1385 /* w32_defined_color is responsible for coping with failures
1386 by looking for a near-miss. */
1387 if (w32_defined_color (f
, SDATA (arg
), &cdef
, 1))
1390 /* defined_color failed; return an ultimate default. */
1396 /* Functions called only from `x_set_frame_param'
1397 to set individual parameters.
1399 If FRAME_W32_WINDOW (f) is 0,
1400 the frame is being created and its window does not exist yet.
1401 In that case, just record the parameter's new value
1402 in the standard place; do not attempt to change the window. */
1405 x_set_foreground_color (f
, arg
, oldval
)
1407 Lisp_Object arg
, oldval
;
1409 struct w32_output
*x
= f
->output_data
.w32
;
1410 PIX_TYPE fg
, old_fg
;
1412 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1413 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
1414 FRAME_FOREGROUND_PIXEL (f
) = fg
;
1416 if (FRAME_W32_WINDOW (f
) != 0)
1418 if (x
->cursor_pixel
== old_fg
)
1419 x
->cursor_pixel
= fg
;
1421 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
1422 if (FRAME_VISIBLE_P (f
))
1428 x_set_background_color (f
, arg
, oldval
)
1430 Lisp_Object arg
, oldval
;
1432 FRAME_BACKGROUND_PIXEL (f
)
1433 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
1435 if (FRAME_W32_WINDOW (f
) != 0)
1437 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
1438 FRAME_BACKGROUND_PIXEL (f
));
1440 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
1442 if (FRAME_VISIBLE_P (f
))
1448 x_set_mouse_color (f
, arg
, oldval
)
1450 Lisp_Object arg
, oldval
;
1452 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
1456 if (!EQ (Qnil
, arg
))
1457 f
->output_data
.w32
->mouse_pixel
1458 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1459 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
1461 /* Don't let pointers be invisible. */
1462 if (mask_color
== f
->output_data
.w32
->mouse_pixel
1463 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
1464 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
1466 #if 0 /* TODO : cursor changes */
1469 /* It's not okay to crash if the user selects a screwy cursor. */
1470 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
1472 if (!EQ (Qnil
, Vx_pointer_shape
))
1474 CHECK_NUMBER (Vx_pointer_shape
);
1475 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
1478 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1479 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
1481 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
1483 CHECK_NUMBER (Vx_nontext_pointer_shape
);
1484 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1485 XINT (Vx_nontext_pointer_shape
));
1488 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
1489 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1491 if (!EQ (Qnil
, Vx_hourglass_pointer_shape
))
1493 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
1494 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1495 XINT (Vx_hourglass_pointer_shape
));
1498 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
1499 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
1501 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1502 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
1504 CHECK_NUMBER (Vx_mode_pointer_shape
);
1505 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1506 XINT (Vx_mode_pointer_shape
));
1509 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1510 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
1512 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
1514 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
1516 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1517 XINT (Vx_sensitive_text_pointer_shape
));
1520 hand_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
1522 if (!NILP (Vx_window_horizontal_drag_shape
))
1524 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
1525 horizontal_drag_cursor
1526 = XCreateFontCursor (FRAME_X_DISPLAY (f
),
1527 XINT (Vx_window_horizontal_drag_shape
));
1530 horizontal_drag_cursor
1531 = XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_sb_h_double_arrow
);
1533 /* Check and report errors with the above calls. */
1534 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
1535 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
1538 XColor fore_color
, back_color
;
1540 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
1541 back_color
.pixel
= mask_color
;
1542 XQueryColor (FRAME_W32_DISPLAY (f
),
1543 DefaultColormap (FRAME_W32_DISPLAY (f
),
1544 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1546 XQueryColor (FRAME_W32_DISPLAY (f
),
1547 DefaultColormap (FRAME_W32_DISPLAY (f
),
1548 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1550 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
1551 &fore_color
, &back_color
);
1552 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
1553 &fore_color
, &back_color
);
1554 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
1555 &fore_color
, &back_color
);
1556 XRecolorCursor (FRAME_W32_DISPLAY (f
), hand_cursor
,
1557 &fore_color
, &back_color
);
1558 XRecolorCursor (FRAME_W32_DISPLAY (f
), hourglass_cursor
,
1559 &fore_color
, &back_color
);
1562 if (FRAME_W32_WINDOW (f
) != 0)
1563 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
1565 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
1566 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
1567 f
->output_data
.w32
->text_cursor
= cursor
;
1569 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
1570 && f
->output_data
.w32
->nontext_cursor
!= 0)
1571 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
1572 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
1574 if (hourglass_cursor
!= f
->output_data
.w32
->hourglass_cursor
1575 && f
->output_data
.w32
->hourglass_cursor
!= 0)
1576 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hourglass_cursor
);
1577 f
->output_data
.w32
->hourglass_cursor
= hourglass_cursor
;
1579 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
1580 && f
->output_data
.w32
->modeline_cursor
!= 0)
1581 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
1582 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
1584 if (hand_cursor
!= f
->output_data
.w32
->hand_cursor
1585 && f
->output_data
.w32
->hand_cursor
!= 0)
1586 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hand_cursor
);
1587 f
->output_data
.w32
->hand_cursor
= hand_cursor
;
1589 XFlush (FRAME_W32_DISPLAY (f
));
1592 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1597 x_set_cursor_color (f
, arg
, oldval
)
1599 Lisp_Object arg
, oldval
;
1601 unsigned long fore_pixel
, pixel
;
1603 if (!NILP (Vx_cursor_fore_pixel
))
1604 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1605 WHITE_PIX_DEFAULT (f
));
1607 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1609 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1611 /* Make sure that the cursor color differs from the background color. */
1612 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
1614 pixel
= f
->output_data
.w32
->mouse_pixel
;
1615 if (pixel
== fore_pixel
)
1616 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1619 f
->output_data
.w32
->cursor_foreground_pixel
= fore_pixel
;
1620 f
->output_data
.w32
->cursor_pixel
= pixel
;
1622 if (FRAME_W32_WINDOW (f
) != 0)
1625 /* Update frame's cursor_gc. */
1626 f
->output_data
.w32
->cursor_gc
->foreground
= fore_pixel
;
1627 f
->output_data
.w32
->cursor_gc
->background
= pixel
;
1631 if (FRAME_VISIBLE_P (f
))
1633 x_update_cursor (f
, 0);
1634 x_update_cursor (f
, 1);
1638 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1641 /* Set the border-color of frame F to pixel value PIX.
1642 Note that this does not fully take effect if done before
1646 x_set_border_pixel (f
, pix
)
1651 f
->output_data
.w32
->border_pixel
= pix
;
1653 if (FRAME_W32_WINDOW (f
) != 0 && f
->border_width
> 0)
1655 if (FRAME_VISIBLE_P (f
))
1660 /* Set the border-color of frame F to value described by ARG.
1661 ARG can be a string naming a color.
1662 The border-color is used for the border that is drawn by the server.
1663 Note that this does not fully take effect if done before
1664 F has a window; it must be redone when the window is created. */
1667 x_set_border_color (f
, arg
, oldval
)
1669 Lisp_Object arg
, oldval
;
1674 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1675 x_set_border_pixel (f
, pix
);
1676 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1681 x_set_cursor_type (f
, arg
, oldval
)
1683 Lisp_Object arg
, oldval
;
1685 set_frame_cursor_types (f
, arg
);
1687 /* Make sure the cursor gets redrawn. */
1688 cursor_type_changed
= 1;
1692 x_set_icon_type (f
, arg
, oldval
)
1694 Lisp_Object arg
, oldval
;
1698 if (NILP (arg
) && NILP (oldval
))
1701 if (STRINGP (arg
) && STRINGP (oldval
)
1702 && EQ (Fstring_equal (oldval
, arg
), Qt
))
1705 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
1710 result
= x_bitmap_icon (f
, arg
);
1714 error ("No icon window available");
1721 x_set_icon_name (f
, arg
, oldval
)
1723 Lisp_Object arg
, oldval
;
1727 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1730 else if (!NILP (arg
) || NILP (oldval
))
1736 if (f
->output_data
.w32
->icon_bitmap
!= 0)
1741 result
= x_text_icon (f
,
1742 (char *) SDATA ((!NILP (f
->icon_name
)
1751 error ("No icon window available");
1754 /* If the window was unmapped (and its icon was mapped),
1755 the new icon is not mapped, so map the window in its stead. */
1756 if (FRAME_VISIBLE_P (f
))
1758 #ifdef USE_X_TOOLKIT
1759 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
1761 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
1764 XFlush (FRAME_W32_DISPLAY (f
));
1771 x_set_menu_bar_lines (f
, value
, oldval
)
1773 Lisp_Object value
, oldval
;
1776 int olines
= FRAME_MENU_BAR_LINES (f
);
1778 /* Right now, menu bars don't work properly in minibuf-only frames;
1779 most of the commands try to apply themselves to the minibuffer
1780 frame itself, and get an error because you can't switch buffers
1781 in or split the minibuffer window. */
1782 if (FRAME_MINIBUF_ONLY_P (f
))
1785 if (INTEGERP (value
))
1786 nlines
= XINT (value
);
1790 FRAME_MENU_BAR_LINES (f
) = 0;
1792 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1795 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1796 free_frame_menubar (f
);
1797 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1799 /* Adjust the frame size so that the client (text) dimensions
1800 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
1802 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
1803 do_pending_window_change (0);
1809 /* Set the number of lines used for the tool bar of frame F to VALUE.
1810 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1811 is the old number of tool bar lines. This function changes the
1812 height of all windows on frame F to match the new tool bar height.
1813 The frame's height doesn't change. */
1816 x_set_tool_bar_lines (f
, value
, oldval
)
1818 Lisp_Object value
, oldval
;
1820 int delta
, nlines
, root_height
;
1821 Lisp_Object root_window
;
1823 /* Treat tool bars like menu bars. */
1824 if (FRAME_MINIBUF_ONLY_P (f
))
1827 /* Use VALUE only if an integer >= 0. */
1828 if (INTEGERP (value
) && XINT (value
) >= 0)
1829 nlines
= XFASTINT (value
);
1833 /* Make sure we redisplay all windows in this frame. */
1834 ++windows_or_buffers_changed
;
1836 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
1838 /* Don't resize the tool-bar to more than we have room for. */
1839 root_window
= FRAME_ROOT_WINDOW (f
);
1840 root_height
= WINDOW_TOTAL_LINES (XWINDOW (root_window
));
1841 if (root_height
- delta
< 1)
1843 delta
= root_height
- 1;
1844 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
1847 FRAME_TOOL_BAR_LINES (f
) = nlines
;
1848 change_window_heights (root_window
, delta
);
1851 /* We also have to make sure that the internal border at the top of
1852 the frame, below the menu bar or tool bar, is redrawn when the
1853 tool bar disappears. This is so because the internal border is
1854 below the tool bar if one is displayed, but is below the menu bar
1855 if there isn't a tool bar. The tool bar draws into the area
1856 below the menu bar. */
1857 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
1860 clear_current_matrices (f
);
1863 /* If the tool bar gets smaller, the internal border below it
1864 has to be cleared. It was formerly part of the display
1865 of the larger tool bar, and updating windows won't clear it. */
1868 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1869 int width
= FRAME_PIXEL_WIDTH (f
);
1870 int y
= nlines
* FRAME_LINE_HEIGHT (f
);
1874 HDC hdc
= get_frame_dc (f
);
1875 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
1876 release_frame_dc (f
, hdc
);
1880 if (WINDOWP (f
->tool_bar_window
))
1881 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1886 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1889 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1890 name; if NAME is a string, set F's name to NAME and set
1891 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1893 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1894 suggesting a new name, which lisp code should override; if
1895 F->explicit_name is set, ignore the new name; otherwise, set it. */
1898 x_set_name (f
, name
, explicit)
1903 /* Make sure that requests from lisp code override requests from
1904 Emacs redisplay code. */
1907 /* If we're switching from explicit to implicit, we had better
1908 update the mode lines and thereby update the title. */
1909 if (f
->explicit_name
&& NILP (name
))
1910 update_mode_lines
= 1;
1912 f
->explicit_name
= ! NILP (name
);
1914 else if (f
->explicit_name
)
1917 /* If NAME is nil, set the name to the w32_id_name. */
1920 /* Check for no change needed in this very common case
1921 before we do any consing. */
1922 if (!strcmp (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
,
1925 name
= build_string (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
);
1928 CHECK_STRING (name
);
1930 /* Don't change the name if it's already NAME. */
1931 if (! NILP (Fstring_equal (name
, f
->name
)))
1936 /* For setting the frame title, the title parameter should override
1937 the name parameter. */
1938 if (! NILP (f
->title
))
1941 if (FRAME_W32_WINDOW (f
))
1943 if (STRING_MULTIBYTE (name
))
1944 name
= ENCODE_SYSTEM (name
);
1947 SetWindowText (FRAME_W32_WINDOW (f
), SDATA (name
));
1952 /* This function should be called when the user's lisp code has
1953 specified a name for the frame; the name will override any set by the
1956 x_explicitly_set_name (f
, arg
, oldval
)
1958 Lisp_Object arg
, oldval
;
1960 x_set_name (f
, arg
, 1);
1963 /* This function should be called by Emacs redisplay code to set the
1964 name; names set this way will never override names set by the user's
1967 x_implicitly_set_name (f
, arg
, oldval
)
1969 Lisp_Object arg
, oldval
;
1971 x_set_name (f
, arg
, 0);
1974 /* Change the title of frame F to NAME.
1975 If NAME is nil, use the frame name as the title. */
1978 x_set_title (f
, name
, old_name
)
1980 Lisp_Object name
, old_name
;
1982 /* Don't change the title if it's already NAME. */
1983 if (EQ (name
, f
->title
))
1986 update_mode_lines
= 1;
1993 if (FRAME_W32_WINDOW (f
))
1995 if (STRING_MULTIBYTE (name
))
1996 name
= ENCODE_SYSTEM (name
);
1999 SetWindowText (FRAME_W32_WINDOW (f
), SDATA (name
));
2005 void x_set_scroll_bar_default_width (f
)
2008 int wid
= FRAME_COLUMN_WIDTH (f
);
2010 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
2011 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) +
2016 /* Subroutines of creating a frame. */
2019 /* Return the value of parameter PARAM.
2021 First search ALIST, then Vdefault_frame_alist, then the X defaults
2022 database, using ATTRIBUTE as the attribute name and CLASS as its class.
2024 Convert the resource to the type specified by desired_type.
2026 If no default is specified, return Qunbound. If you call
2027 w32_get_arg, make sure you deal with Qunbound in a reasonable way,
2028 and don't let it get stored in any Lisp-visible variables! */
2031 w32_get_arg (alist
, param
, attribute
, class, type
)
2032 Lisp_Object alist
, param
;
2035 enum resource_types type
;
2037 return x_get_arg (check_x_display_info (Qnil
),
2038 alist
, param
, attribute
, class, type
);
2043 w32_load_cursor (LPCTSTR name
)
2045 /* Try first to load cursor from application resource. */
2046 Cursor cursor
= LoadImage ((HINSTANCE
) GetModuleHandle (NULL
),
2047 name
, IMAGE_CURSOR
, 0, 0,
2048 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
2051 /* Then try to load a shared predefined cursor. */
2052 cursor
= LoadImage (NULL
, name
, IMAGE_CURSOR
, 0, 0,
2053 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
2058 extern LRESULT CALLBACK
w32_wnd_proc ();
2061 w32_init_class (hinst
)
2066 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
2067 wc
.lpfnWndProc
= (WNDPROC
) w32_wnd_proc
;
2069 wc
.cbWndExtra
= WND_EXTRA_BYTES
;
2070 wc
.hInstance
= hinst
;
2071 wc
.hIcon
= LoadIcon (hinst
, EMACS_CLASS
);
2072 wc
.hCursor
= w32_load_cursor (IDC_ARROW
);
2073 wc
.hbrBackground
= NULL
; /* GetStockObject (WHITE_BRUSH); */
2074 wc
.lpszMenuName
= NULL
;
2075 wc
.lpszClassName
= EMACS_CLASS
;
2077 return (RegisterClass (&wc
));
2081 w32_createscrollbar (f
, bar
)
2083 struct scroll_bar
* bar
;
2085 return (CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
2086 /* Position and size of scroll bar. */
2087 XINT (bar
->left
) + VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
2089 XINT (bar
->width
) - VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
2091 FRAME_W32_WINDOW (f
),
2098 w32_createwindow (f
)
2103 Lisp_Object top
= Qunbound
;
2104 Lisp_Object left
= Qunbound
;
2106 rect
.left
= rect
.top
= 0;
2107 rect
.right
= FRAME_PIXEL_WIDTH (f
);
2108 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
2110 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
2111 FRAME_EXTERNAL_MENU_BAR (f
));
2113 /* Do first time app init */
2117 w32_init_class (hinst
);
2120 if (f
->size_hint_flags
& USPosition
|| f
->size_hint_flags
& PPosition
)
2122 XSETINT (left
, f
->left_pos
);
2123 XSETINT (top
, f
->top_pos
);
2125 else if (EQ (left
, Qunbound
) && EQ (top
, Qunbound
))
2127 /* When called with RES_TYPE_NUMBER, w32_get_arg will return zero
2128 for anything that is not a number and is not Qunbound. */
2129 left
= w32_get_arg (Qnil
, Qleft
, "left", "Left", RES_TYPE_NUMBER
);
2130 top
= w32_get_arg (Qnil
, Qtop
, "top", "Top", RES_TYPE_NUMBER
);
2133 FRAME_W32_WINDOW (f
) = hwnd
2134 = CreateWindow (EMACS_CLASS
,
2136 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
2137 EQ (left
, Qunbound
) ? CW_USEDEFAULT
: XINT (left
),
2138 EQ (top
, Qunbound
) ? CW_USEDEFAULT
: XINT (top
),
2139 rect
.right
- rect
.left
,
2140 rect
.bottom
- rect
.top
,
2148 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
2149 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
2150 SetWindowLong (hwnd
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
2151 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->scroll_bar_actual_width
);
2152 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
2154 /* Enable drag-n-drop. */
2155 DragAcceptFiles (hwnd
, TRUE
);
2157 /* Do this to discard the default setting specified by our parent. */
2158 ShowWindow (hwnd
, SW_HIDE
);
2160 /* Update frame positions. */
2161 GetWindowRect (hwnd
, &rect
);
2162 f
->left_pos
= rect
.left
;
2163 f
->top_pos
= rect
.top
;
2168 my_post_msg (wmsg
, hwnd
, msg
, wParam
, lParam
)
2175 wmsg
->msg
.hwnd
= hwnd
;
2176 wmsg
->msg
.message
= msg
;
2177 wmsg
->msg
.wParam
= wParam
;
2178 wmsg
->msg
.lParam
= lParam
;
2179 wmsg
->msg
.time
= GetMessageTime ();
2184 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
2185 between left and right keys as advertised. We test for this
2186 support dynamically, and set a flag when the support is absent. If
2187 absent, we keep track of the left and right control and alt keys
2188 ourselves. This is particularly necessary on keyboards that rely
2189 upon the AltGr key, which is represented as having the left control
2190 and right alt keys pressed. For these keyboards, we need to know
2191 when the left alt key has been pressed in addition to the AltGr key
2192 so that we can properly support M-AltGr-key sequences (such as M-@
2193 on Swedish keyboards). */
2195 #define EMACS_LCONTROL 0
2196 #define EMACS_RCONTROL 1
2197 #define EMACS_LMENU 2
2198 #define EMACS_RMENU 3
2200 static int modifiers
[4];
2201 static int modifiers_recorded
;
2202 static int modifier_key_support_tested
;
2205 test_modifier_support (unsigned int wparam
)
2209 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
2211 if (wparam
== VK_CONTROL
)
2221 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
2222 modifiers_recorded
= 1;
2224 modifiers_recorded
= 0;
2225 modifier_key_support_tested
= 1;
2229 record_keydown (unsigned int wparam
, unsigned int lparam
)
2233 if (!modifier_key_support_tested
)
2234 test_modifier_support (wparam
);
2236 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2239 if (wparam
== VK_CONTROL
)
2240 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2242 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2248 record_keyup (unsigned int wparam
, unsigned int lparam
)
2252 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2255 if (wparam
== VK_CONTROL
)
2256 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2258 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2263 /* Emacs can lose focus while a modifier key has been pressed. When
2264 it regains focus, be conservative and clear all modifiers since
2265 we cannot reconstruct the left and right modifier state. */
2271 if (GetFocus () == NULL
)
2272 /* Emacs doesn't have keyboard focus. Do nothing. */
2275 ctrl
= GetAsyncKeyState (VK_CONTROL
);
2276 alt
= GetAsyncKeyState (VK_MENU
);
2278 if (!(ctrl
& 0x08000))
2279 /* Clear any recorded control modifier state. */
2280 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2282 if (!(alt
& 0x08000))
2283 /* Clear any recorded alt modifier state. */
2284 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2286 /* Update the state of all modifier keys, because modifiers used in
2287 hot-key combinations can get stuck on if Emacs loses focus as a
2288 result of a hot-key being pressed. */
2292 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
2294 GetKeyboardState (keystate
);
2295 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
2296 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
2297 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
2298 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
2299 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
2300 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
2301 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
2302 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
2303 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
2304 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
2305 SetKeyboardState (keystate
);
2309 /* Synchronize modifier state with what is reported with the current
2310 keystroke. Even if we cannot distinguish between left and right
2311 modifier keys, we know that, if no modifiers are set, then neither
2312 the left or right modifier should be set. */
2316 if (!modifiers_recorded
)
2319 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
2320 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2322 if (!(GetKeyState (VK_MENU
) & 0x8000))
2323 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2327 modifier_set (int vkey
)
2329 if (vkey
== VK_CAPITAL
|| vkey
== VK_SCROLL
)
2330 return (GetKeyState (vkey
) & 0x1);
2331 if (!modifiers_recorded
)
2332 return (GetKeyState (vkey
) & 0x8000);
2337 return modifiers
[EMACS_LCONTROL
];
2339 return modifiers
[EMACS_RCONTROL
];
2341 return modifiers
[EMACS_LMENU
];
2343 return modifiers
[EMACS_RMENU
];
2345 return (GetKeyState (vkey
) & 0x8000);
2348 /* Convert between the modifier bits W32 uses and the modifier bits
2352 w32_key_to_modifier (int key
)
2354 Lisp_Object key_mapping
;
2359 key_mapping
= Vw32_lwindow_modifier
;
2362 key_mapping
= Vw32_rwindow_modifier
;
2365 key_mapping
= Vw32_apps_modifier
;
2368 key_mapping
= Vw32_scroll_lock_modifier
;
2374 /* NB. This code runs in the input thread, asychronously to the lisp
2375 thread, so we must be careful to ensure access to lisp data is
2376 thread-safe. The following code is safe because the modifier
2377 variable values are updated atomically from lisp and symbols are
2378 not relocated by GC. Also, we don't have to worry about seeing GC
2380 if (EQ (key_mapping
, Qhyper
))
2381 return hyper_modifier
;
2382 if (EQ (key_mapping
, Qsuper
))
2383 return super_modifier
;
2384 if (EQ (key_mapping
, Qmeta
))
2385 return meta_modifier
;
2386 if (EQ (key_mapping
, Qalt
))
2387 return alt_modifier
;
2388 if (EQ (key_mapping
, Qctrl
))
2389 return ctrl_modifier
;
2390 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
2391 return ctrl_modifier
;
2392 if (EQ (key_mapping
, Qshift
))
2393 return shift_modifier
;
2395 /* Don't generate any modifier if not explicitly requested. */
2400 w32_get_modifiers ()
2402 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
2403 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
2404 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
2405 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
2406 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
2407 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
2408 (modifier_set (VK_MENU
) ?
2409 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
2412 /* We map the VK_* modifiers into console modifier constants
2413 so that we can use the same routines to handle both console
2414 and window input. */
2417 construct_console_modifiers ()
2422 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
2423 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
2424 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
2425 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
2426 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
2427 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
2428 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
2429 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
2430 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
2431 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
2432 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
2438 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
2442 /* Convert to emacs modifiers. */
2443 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
2449 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
2451 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
2454 if (virt_key
== VK_RETURN
)
2455 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
2457 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
2458 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
2460 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
2461 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
2463 if (virt_key
== VK_CLEAR
)
2464 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
2469 /* List of special key combinations which w32 would normally capture,
2470 but Emacs should grab instead. Not directly visible to lisp, to
2471 simplify synchronization. Each item is an integer encoding a virtual
2472 key code and modifier combination to capture. */
2473 static Lisp_Object w32_grabbed_keys
;
2475 #define HOTKEY(vk, mods) make_number (((vk) & 255) | ((mods) << 8))
2476 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
2477 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
2478 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
2480 #define RAW_HOTKEY_ID(k) ((k) & 0xbfff)
2481 #define RAW_HOTKEY_VK_CODE(k) ((k) & 255)
2482 #define RAW_HOTKEY_MODIFIERS(k) ((k) >> 8)
2484 /* Register hot-keys for reserved key combinations when Emacs has
2485 keyboard focus, since this is the only way Emacs can receive key
2486 combinations like Alt-Tab which are used by the system. */
2489 register_hot_keys (hwnd
)
2492 Lisp_Object keylist
;
2494 /* Use CONSP, since we are called asynchronously. */
2495 for (keylist
= w32_grabbed_keys
; CONSP (keylist
); keylist
= XCDR (keylist
))
2497 Lisp_Object key
= XCAR (keylist
);
2499 /* Deleted entries get set to nil. */
2500 if (!INTEGERP (key
))
2503 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
2504 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
2509 unregister_hot_keys (hwnd
)
2512 Lisp_Object keylist
;
2514 for (keylist
= w32_grabbed_keys
; CONSP (keylist
); keylist
= XCDR (keylist
))
2516 Lisp_Object key
= XCAR (keylist
);
2518 if (!INTEGERP (key
))
2521 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
2525 /* Main message dispatch loop. */
2528 w32_msg_pump (deferred_msg
* msg_buf
)
2534 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
2536 while (GetMessage (&msg
, NULL
, 0, 0))
2538 if (msg
.hwnd
== NULL
)
2540 switch (msg
.message
)
2543 /* Produced by complete_deferred_msg; just ignore. */
2545 case WM_EMACS_CREATEWINDOW
:
2546 /* Initialize COM for this window. Even though we don't use it,
2547 some third party shell extensions can cause it to be used in
2548 system dialogs, which causes a crash if it is not initialized.
2549 This is a known bug in Windows, which was fixed long ago, but
2550 the patch for XP is not publically available until XP SP3,
2551 and older versions will never be patched. */
2552 CoInitialize (NULL
);
2553 w32_createwindow ((struct frame
*) msg
.wParam
);
2554 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2557 case WM_EMACS_SETLOCALE
:
2558 SetThreadLocale (msg
.wParam
);
2559 /* Reply is not expected. */
2561 case WM_EMACS_SETKEYBOARDLAYOUT
:
2562 result
= (int) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
2563 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2567 case WM_EMACS_REGISTER_HOT_KEY
:
2568 focus_window
= GetFocus ();
2569 if (focus_window
!= NULL
)
2570 RegisterHotKey (focus_window
,
2571 RAW_HOTKEY_ID (msg
.wParam
),
2572 RAW_HOTKEY_MODIFIERS (msg
.wParam
),
2573 RAW_HOTKEY_VK_CODE (msg
.wParam
));
2574 /* Reply is not expected. */
2576 case WM_EMACS_UNREGISTER_HOT_KEY
:
2577 focus_window
= GetFocus ();
2578 if (focus_window
!= NULL
)
2579 UnregisterHotKey (focus_window
, RAW_HOTKEY_ID (msg
.wParam
));
2580 /* Mark item as erased. NB: this code must be
2581 thread-safe. The next line is okay because the cons
2582 cell is never made into garbage and is not relocated by
2584 XSETCAR ((Lisp_Object
) ((EMACS_INT
) msg
.lParam
), Qnil
);
2585 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2588 case WM_EMACS_TOGGLE_LOCK_KEY
:
2590 int vk_code
= (int) msg
.wParam
;
2591 int cur_state
= (GetKeyState (vk_code
) & 1);
2592 Lisp_Object new_state
= (Lisp_Object
) ((EMACS_INT
) msg
.lParam
);
2594 /* NB: This code must be thread-safe. It is safe to
2595 call NILP because symbols are not relocated by GC,
2596 and pointer here is not touched by GC (so the markbit
2597 can't be set). Numbers are safe because they are
2598 immediate values. */
2599 if (NILP (new_state
)
2600 || (NUMBERP (new_state
)
2601 && ((XUINT (new_state
)) & 1) != cur_state
))
2603 one_w32_display_info
.faked_key
= vk_code
;
2605 keybd_event ((BYTE
) vk_code
,
2606 (BYTE
) MapVirtualKey (vk_code
, 0),
2607 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2608 keybd_event ((BYTE
) vk_code
,
2609 (BYTE
) MapVirtualKey (vk_code
, 0),
2610 KEYEVENTF_EXTENDEDKEY
| 0, 0);
2611 keybd_event ((BYTE
) vk_code
,
2612 (BYTE
) MapVirtualKey (vk_code
, 0),
2613 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2614 cur_state
= !cur_state
;
2616 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2622 /* Broadcast messages make it here, so you need to be looking
2623 for something in particular for this to be useful. */
2625 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
2631 DispatchMessage (&msg
);
2634 /* Exit nested loop when our deferred message has completed. */
2635 if (msg_buf
->completed
)
2640 deferred_msg
* deferred_msg_head
;
2642 static deferred_msg
*
2643 find_deferred_msg (HWND hwnd
, UINT msg
)
2645 deferred_msg
* item
;
2647 /* Don't actually need synchronization for read access, since
2648 modification of single pointer is always atomic. */
2649 /* enter_crit (); */
2651 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2652 if (item
->w32msg
.msg
.hwnd
== hwnd
2653 && item
->w32msg
.msg
.message
== msg
)
2656 /* leave_crit (); */
2662 send_deferred_msg (deferred_msg
* msg_buf
,
2668 /* Only input thread can send deferred messages. */
2669 if (GetCurrentThreadId () != dwWindowsThreadId
)
2672 /* It is an error to send a message that is already deferred. */
2673 if (find_deferred_msg (hwnd
, msg
) != NULL
)
2676 /* Enforced synchronization is not needed because this is the only
2677 function that alters deferred_msg_head, and the following critical
2678 section is guaranteed to only be serially reentered (since only the
2679 input thread can call us). */
2681 /* enter_crit (); */
2683 msg_buf
->completed
= 0;
2684 msg_buf
->next
= deferred_msg_head
;
2685 deferred_msg_head
= msg_buf
;
2686 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
2688 /* leave_crit (); */
2690 /* Start a new nested message loop to process other messages until
2691 this one is completed. */
2692 w32_msg_pump (msg_buf
);
2694 deferred_msg_head
= msg_buf
->next
;
2696 return msg_buf
->result
;
2700 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
2702 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
2704 if (msg_buf
== NULL
)
2705 /* Message may have been cancelled, so don't abort. */
2708 msg_buf
->result
= result
;
2709 msg_buf
->completed
= 1;
2711 /* Ensure input thread is woken so it notices the completion. */
2712 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2716 cancel_all_deferred_msgs ()
2718 deferred_msg
* item
;
2720 /* Don't actually need synchronization for read access, since
2721 modification of single pointer is always atomic. */
2722 /* enter_crit (); */
2724 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2727 item
->completed
= 1;
2730 /* leave_crit (); */
2732 /* Ensure input thread is woken so it notices the completion. */
2733 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2737 w32_msg_worker (void *arg
)
2740 deferred_msg dummy_buf
;
2742 /* Ensure our message queue is created */
2744 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
2746 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2749 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
2750 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
2751 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
2753 /* This is the inital message loop which should only exit when the
2754 application quits. */
2755 w32_msg_pump (&dummy_buf
);
2761 signal_user_input ()
2763 /* Interrupt any lisp that wants to be interrupted by input. */
2764 if (!NILP (Vthrow_on_input
))
2766 Vquit_flag
= Vthrow_on_input
;
2767 /* If we're inside a function that wants immediate quits,
2769 if (immediate_quit
&& NILP (Vinhibit_quit
))
2779 post_character_message (hwnd
, msg
, wParam
, lParam
, modifiers
)
2789 wmsg
.dwModifiers
= modifiers
;
2791 /* Detect quit_char and set quit-flag directly. Note that we
2792 still need to post a message to ensure the main thread will be
2793 woken up if blocked in sys_select, but we do NOT want to post
2794 the quit_char message itself (because it will usually be as if
2795 the user had typed quit_char twice). Instead, we post a dummy
2796 message that has no particular effect. */
2799 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
2800 c
= make_ctrl_char (c
) & 0377;
2802 || (wmsg
.dwModifiers
== 0 &&
2803 w32_quit_key
&& wParam
== w32_quit_key
))
2807 /* The choice of message is somewhat arbitrary, as long as
2808 the main thread handler just ignores it. */
2811 /* Interrupt any blocking system calls. */
2814 /* As a safety precaution, forcibly complete any deferred
2815 messages. This is a kludge, but I don't see any particularly
2816 clean way to handle the situation where a deferred message is
2817 "dropped" in the lisp thread, and will thus never be
2818 completed, eg. by the user trying to activate the menubar
2819 when the lisp thread is busy, and then typing C-g when the
2820 menubar doesn't open promptly (with the result that the
2821 menubar never responds at all because the deferred
2822 WM_INITMENU message is never completed). Another problem
2823 situation is when the lisp thread calls SendMessage (to send
2824 a window manager command) when a message has been deferred;
2825 the lisp thread gets blocked indefinitely waiting for the
2826 deferred message to be completed, which itself is waiting for
2827 the lisp thread to respond.
2829 Note that we don't want to block the input thread waiting for
2830 a reponse from the lisp thread (although that would at least
2831 solve the deadlock problem above), because we want to be able
2832 to receive C-g to interrupt the lisp thread. */
2833 cancel_all_deferred_msgs ();
2836 signal_user_input ();
2839 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2842 /* Main window procedure */
2845 w32_wnd_proc (hwnd
, msg
, wParam
, lParam
)
2852 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
2854 int windows_translate
;
2857 /* Note that it is okay to call x_window_to_frame, even though we are
2858 not running in the main lisp thread, because frame deletion
2859 requires the lisp thread to synchronize with this thread. Thus, if
2860 a frame struct is returned, it can be used without concern that the
2861 lisp thread might make it disappear while we are using it.
2863 NB. Walking the frame list in this thread is safe (as long as
2864 writes of Lisp_Object slots are atomic, which they are on Windows).
2865 Although delete-frame can destructively modify the frame list while
2866 we are walking it, a garbage collection cannot occur until after
2867 delete-frame has synchronized with this thread.
2869 It is also safe to use functions that make GDI calls, such as
2870 w32_clear_rect, because these functions must obtain a DC handle
2871 from the frame struct using get_frame_dc which is thread-aware. */
2876 f
= x_window_to_frame (dpyinfo
, hwnd
);
2879 HDC hdc
= get_frame_dc (f
);
2880 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
2881 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
2882 release_frame_dc (f
, hdc
);
2884 #if defined (W32_DEBUG_DISPLAY)
2885 DebPrint (("WM_ERASEBKGND (frame %p): erasing %d,%d-%d,%d\n",
2887 wmsg
.rect
.left
, wmsg
.rect
.top
,
2888 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2889 #endif /* W32_DEBUG_DISPLAY */
2892 case WM_PALETTECHANGED
:
2893 /* ignore our own changes */
2894 if ((HWND
)wParam
!= hwnd
)
2896 f
= x_window_to_frame (dpyinfo
, hwnd
);
2898 /* get_frame_dc will realize our palette and force all
2899 frames to be redrawn if needed. */
2900 release_frame_dc (f
, get_frame_dc (f
));
2905 PAINTSTRUCT paintStruct
;
2907 bzero (&update_rect
, sizeof (update_rect
));
2909 f
= x_window_to_frame (dpyinfo
, hwnd
);
2912 DebPrint (("WM_PAINT received for unknown window %p\n", hwnd
));
2916 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
2917 fails. Apparently this can happen under some
2919 if (GetUpdateRect (hwnd
, &update_rect
, FALSE
) || !w32_strict_painting
)
2922 BeginPaint (hwnd
, &paintStruct
);
2924 /* The rectangles returned by GetUpdateRect and BeginPaint
2925 do not always match. Play it safe by assuming both areas
2927 UnionRect (&(wmsg
.rect
), &update_rect
, &(paintStruct
.rcPaint
));
2929 #if defined (W32_DEBUG_DISPLAY)
2930 DebPrint (("WM_PAINT (frame %p): painting %d,%d-%d,%d\n",
2932 wmsg
.rect
.left
, wmsg
.rect
.top
,
2933 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2934 DebPrint ((" [update region is %d,%d-%d,%d]\n",
2935 update_rect
.left
, update_rect
.top
,
2936 update_rect
.right
, update_rect
.bottom
));
2938 EndPaint (hwnd
, &paintStruct
);
2941 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2946 /* If GetUpdateRect returns 0 (meaning there is no update
2947 region), assume the whole window needs to be repainted. */
2948 GetClientRect (hwnd
, &wmsg
.rect
);
2949 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2953 case WM_INPUTLANGCHANGE
:
2954 /* Inform lisp thread of keyboard layout changes. */
2955 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2957 /* Clear dead keys in the keyboard state; for simplicity only
2958 preserve modifier key states. */
2963 GetKeyboardState (keystate
);
2964 for (i
= 0; i
< 256; i
++)
2981 SetKeyboardState (keystate
);
2986 /* Synchronize hot keys with normal input. */
2987 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
2992 record_keyup (wParam
, lParam
);
2997 /* Ignore keystrokes we fake ourself; see below. */
2998 if (dpyinfo
->faked_key
== wParam
)
3000 dpyinfo
->faked_key
= 0;
3001 /* Make sure TranslateMessage sees them though (as long as
3002 they don't produce WM_CHAR messages). This ensures that
3003 indicator lights are toggled promptly on Windows 9x, for
3005 if (wParam
< 256 && lispy_function_keys
[wParam
])
3007 windows_translate
= 1;
3013 /* Synchronize modifiers with current keystroke. */
3015 record_keydown (wParam
, lParam
);
3016 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
3018 windows_translate
= 0;
3023 if (NILP (Vw32_pass_lwindow_to_system
))
3025 /* Prevent system from acting on keyup (which opens the
3026 Start menu if no other key was pressed) by simulating a
3027 press of Space which we will ignore. */
3028 if (GetAsyncKeyState (wParam
) & 1)
3030 if (NUMBERP (Vw32_phantom_key_code
))
3031 key
= XUINT (Vw32_phantom_key_code
) & 255;
3034 dpyinfo
->faked_key
= key
;
3035 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
3038 if (!NILP (Vw32_lwindow_modifier
))
3042 if (NILP (Vw32_pass_rwindow_to_system
))
3044 if (GetAsyncKeyState (wParam
) & 1)
3046 if (NUMBERP (Vw32_phantom_key_code
))
3047 key
= XUINT (Vw32_phantom_key_code
) & 255;
3050 dpyinfo
->faked_key
= key
;
3051 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
3054 if (!NILP (Vw32_rwindow_modifier
))
3058 if (!NILP (Vw32_apps_modifier
))
3062 if (NILP (Vw32_pass_alt_to_system
))
3063 /* Prevent DefWindowProc from activating the menu bar if an
3064 Alt key is pressed and released by itself. */
3066 windows_translate
= 1;
3069 /* Decide whether to treat as modifier or function key. */
3070 if (NILP (Vw32_enable_caps_lock
))
3071 goto disable_lock_key
;
3072 windows_translate
= 1;
3075 /* Decide whether to treat as modifier or function key. */
3076 if (NILP (Vw32_enable_num_lock
))
3077 goto disable_lock_key
;
3078 windows_translate
= 1;
3081 /* Decide whether to treat as modifier or function key. */
3082 if (NILP (Vw32_scroll_lock_modifier
))
3083 goto disable_lock_key
;
3084 windows_translate
= 1;
3087 /* Ensure the appropriate lock key state (and indicator light)
3088 remains in the same state. We do this by faking another
3089 press of the relevant key. Apparently, this really is the
3090 only way to toggle the state of the indicator lights. */
3091 dpyinfo
->faked_key
= wParam
;
3092 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3093 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3094 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3095 KEYEVENTF_EXTENDEDKEY
| 0, 0);
3096 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3097 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3098 /* Ensure indicator lights are updated promptly on Windows 9x
3099 (TranslateMessage apparently does this), after forwarding
3101 post_character_message (hwnd
, msg
, wParam
, lParam
,
3102 w32_get_key_modifiers (wParam
, lParam
));
3103 windows_translate
= 1;
3107 case VK_PROCESSKEY
: /* Generated by IME. */
3108 windows_translate
= 1;
3111 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
3112 which is confusing for purposes of key binding; convert
3113 VK_CANCEL events into VK_PAUSE events. */
3117 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
3118 for purposes of key binding; convert these back into
3119 VK_NUMLOCK events, at least when we want to see NumLock key
3120 presses. (Note that there is never any possibility that
3121 VK_PAUSE with Ctrl really is C-Pause as per above.) */
3122 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
3123 wParam
= VK_NUMLOCK
;
3126 /* If not defined as a function key, change it to a WM_CHAR message. */
3127 if (wParam
> 255 || !lispy_function_keys
[wParam
])
3129 DWORD modifiers
= construct_console_modifiers ();
3131 if (!NILP (Vw32_recognize_altgr
)
3132 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
3134 /* Always let TranslateMessage handle AltGr key chords;
3135 for some reason, ToAscii doesn't always process AltGr
3136 chords correctly. */
3137 windows_translate
= 1;
3139 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
3141 /* Handle key chords including any modifiers other
3142 than shift directly, in order to preserve as much
3143 modifier information as possible. */
3144 if ('A' <= wParam
&& wParam
<= 'Z')
3146 /* Don't translate modified alphabetic keystrokes,
3147 so the user doesn't need to constantly switch
3148 layout to type control or meta keystrokes when
3149 the normal layout translates alphabetic
3150 characters to non-ascii characters. */
3151 if (!modifier_set (VK_SHIFT
))
3152 wParam
+= ('a' - 'A');
3157 /* Try to handle other keystrokes by determining the
3158 base character (ie. translating the base key plus
3162 KEY_EVENT_RECORD key
;
3164 key
.bKeyDown
= TRUE
;
3165 key
.wRepeatCount
= 1;
3166 key
.wVirtualKeyCode
= wParam
;
3167 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
3168 key
.uChar
.AsciiChar
= 0;
3169 key
.dwControlKeyState
= modifiers
;
3171 add
= w32_kbd_patch_key (&key
);
3172 /* 0 means an unrecognised keycode, negative means
3173 dead key. Ignore both. */
3176 /* Forward asciified character sequence. */
3177 post_character_message
3179 (unsigned char) key
.uChar
.AsciiChar
, lParam
,
3180 w32_get_key_modifiers (wParam
, lParam
));
3181 w32_kbd_patch_key (&key
);
3188 /* Let TranslateMessage handle everything else. */
3189 windows_translate
= 1;
3195 if (windows_translate
)
3197 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
3198 windows_msg
.time
= GetMessageTime ();
3199 TranslateMessage (&windows_msg
);
3207 post_character_message (hwnd
, msg
, wParam
, lParam
,
3208 w32_get_key_modifiers (wParam
, lParam
));
3212 /* WM_UNICHAR looks promising from the docs, but the exact
3213 circumstances in which TranslateMessage sends it is one of those
3214 Microsoft secret API things that EU and US courts are supposed
3215 to have put a stop to already. Spy++ shows it being sent to Notepad
3216 and other MS apps, but never to Emacs.
3218 Some third party IMEs send it in accordance with the official
3219 documentation though, so handle it here.
3221 UNICODE_NOCHAR is used to test for support for this message.
3222 TRUE indicates that the message is supported. */
3223 if (wParam
== UNICODE_NOCHAR
)
3228 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3229 signal_user_input ();
3230 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3235 /* If we can't get the IME result as unicode, use default processing,
3236 which will at least allow characters decodable in the system locale
3238 if (!get_composition_string_fn
)
3241 else if (!ignore_ime_char
)
3246 HIMC context
= get_ime_context_fn (hwnd
);
3247 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3248 /* Get buffer size. */
3249 size
= get_composition_string_fn (context
, GCS_RESULTSTR
, buffer
, 0);
3250 buffer
= alloca(size
);
3251 size
= get_composition_string_fn (context
, GCS_RESULTSTR
,
3253 signal_user_input ();
3254 for (i
= 0; i
< size
/ sizeof (wchar_t); i
++)
3256 my_post_msg (&wmsg
, hwnd
, WM_UNICHAR
, (WPARAM
) buffer
[i
],
3259 /* We output the whole string above, so ignore following ones
3260 until we are notified of the end of composition. */
3261 ignore_ime_char
= 1;
3265 case WM_IME_ENDCOMPOSITION
:
3266 ignore_ime_char
= 0;
3269 /* Simulate middle mouse button events when left and right buttons
3270 are used together, but only if user has two button mouse. */
3271 case WM_LBUTTONDOWN
:
3272 case WM_RBUTTONDOWN
:
3273 if (w32_num_mouse_buttons
> 2)
3274 goto handle_plain_button
;
3277 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
3278 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
3280 if (button_state
& this)
3283 if (button_state
== 0)
3286 button_state
|= this;
3288 if (button_state
& other
)
3290 if (mouse_button_timer
)
3292 KillTimer (hwnd
, mouse_button_timer
);
3293 mouse_button_timer
= 0;
3295 /* Generate middle mouse event instead. */
3296 msg
= WM_MBUTTONDOWN
;
3297 button_state
|= MMOUSE
;
3299 else if (button_state
& MMOUSE
)
3301 /* Ignore button event if we've already generated a
3302 middle mouse down event. This happens if the
3303 user releases and press one of the two buttons
3304 after we've faked a middle mouse event. */
3309 /* Flush out saved message. */
3310 post_msg (&saved_mouse_button_msg
);
3312 wmsg
.dwModifiers
= w32_get_modifiers ();
3313 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3314 signal_user_input ();
3316 /* Clear message buffer. */
3317 saved_mouse_button_msg
.msg
.hwnd
= 0;
3321 /* Hold onto message for now. */
3322 mouse_button_timer
=
3323 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
3324 w32_mouse_button_tolerance
, NULL
);
3325 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
3326 saved_mouse_button_msg
.msg
.message
= msg
;
3327 saved_mouse_button_msg
.msg
.wParam
= wParam
;
3328 saved_mouse_button_msg
.msg
.lParam
= lParam
;
3329 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
3330 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
3337 if (w32_num_mouse_buttons
> 2)
3338 goto handle_plain_button
;
3341 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
3342 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
3344 if ((button_state
& this) == 0)
3347 button_state
&= ~this;
3349 if (button_state
& MMOUSE
)
3351 /* Only generate event when second button is released. */
3352 if ((button_state
& other
) == 0)
3355 button_state
&= ~MMOUSE
;
3357 if (button_state
) abort ();
3364 /* Flush out saved message if necessary. */
3365 if (saved_mouse_button_msg
.msg
.hwnd
)
3367 post_msg (&saved_mouse_button_msg
);
3370 wmsg
.dwModifiers
= w32_get_modifiers ();
3371 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3372 signal_user_input ();
3374 /* Always clear message buffer and cancel timer. */
3375 saved_mouse_button_msg
.msg
.hwnd
= 0;
3376 KillTimer (hwnd
, mouse_button_timer
);
3377 mouse_button_timer
= 0;
3379 if (button_state
== 0)
3384 case WM_XBUTTONDOWN
:
3386 if (w32_pass_extra_mouse_buttons_to_system
)
3388 /* else fall through and process them. */
3389 case WM_MBUTTONDOWN
:
3391 handle_plain_button
:
3396 /* Ignore middle and extra buttons as long as the menu is active. */
3397 f
= x_window_to_frame (dpyinfo
, hwnd
);
3398 if (f
&& f
->output_data
.w32
->menubar_active
)
3401 if (parse_button (msg
, HIWORD (wParam
), &button
, &up
))
3403 if (up
) ReleaseCapture ();
3404 else SetCapture (hwnd
);
3405 button
= (button
== 0) ? LMOUSE
:
3406 ((button
== 1) ? MMOUSE
: RMOUSE
);
3408 button_state
&= ~button
;
3410 button_state
|= button
;
3414 wmsg
.dwModifiers
= w32_get_modifiers ();
3415 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3416 signal_user_input ();
3418 /* Need to return true for XBUTTON messages, false for others,
3419 to indicate that we processed the message. */
3420 return (msg
== WM_XBUTTONDOWN
|| msg
== WM_XBUTTONUP
);
3423 /* Ignore mouse movements as long as the menu is active. These
3424 movements are processed by the window manager anyway, and
3425 it's wrong to handle them as if they happened on the
3426 underlying frame. */
3427 f
= x_window_to_frame (dpyinfo
, hwnd
);
3428 if (f
&& f
->output_data
.w32
->menubar_active
)
3431 /* If the mouse has just moved into the frame, start tracking
3432 it, so we will be notified when it leaves the frame. Mouse
3433 tracking only works under W98 and NT4 and later. On earlier
3434 versions, there is no way of telling when the mouse leaves the
3435 frame, so we just have to put up with help-echo and mouse
3436 highlighting remaining while the frame is not active. */
3437 if (track_mouse_event_fn
&& !track_mouse_window
)
3439 TRACKMOUSEEVENT tme
;
3440 tme
.cbSize
= sizeof (tme
);
3441 tme
.dwFlags
= TME_LEAVE
;
3442 tme
.hwndTrack
= hwnd
;
3444 track_mouse_event_fn (&tme
);
3445 track_mouse_window
= hwnd
;
3448 if (w32_mouse_move_interval
<= 0
3449 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
3451 wmsg
.dwModifiers
= w32_get_modifiers ();
3452 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3456 /* Hang onto mouse move and scroll messages for a bit, to avoid
3457 sending such events to Emacs faster than it can process them.
3458 If we get more events before the timer from the first message
3459 expires, we just replace the first message. */
3461 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
3463 SetTimer (hwnd
, MOUSE_MOVE_ID
,
3464 w32_mouse_move_interval
, NULL
);
3466 /* Hold onto message for now. */
3467 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
3468 saved_mouse_move_msg
.msg
.message
= msg
;
3469 saved_mouse_move_msg
.msg
.wParam
= wParam
;
3470 saved_mouse_move_msg
.msg
.lParam
= lParam
;
3471 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
3472 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
3478 wmsg
.dwModifiers
= w32_get_modifiers ();
3479 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3480 signal_user_input ();
3484 if (w32_pass_multimedia_buttons_to_system
)
3486 /* Otherwise, pass to lisp, the same way we do with mousehwheel. */
3487 case WM_MOUSEHWHEEL
:
3488 wmsg
.dwModifiers
= w32_get_modifiers ();
3489 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3490 signal_user_input ();
3491 /* Non-zero must be returned when WM_MOUSEHWHEEL messages are
3492 handled, to prevent the system trying to handle it by faking
3493 scroll bar events. */
3497 /* Flush out saved messages if necessary. */
3498 if (wParam
== mouse_button_timer
)
3500 if (saved_mouse_button_msg
.msg
.hwnd
)
3502 post_msg (&saved_mouse_button_msg
);
3503 signal_user_input ();
3504 saved_mouse_button_msg
.msg
.hwnd
= 0;
3506 KillTimer (hwnd
, mouse_button_timer
);
3507 mouse_button_timer
= 0;
3509 else if (wParam
== mouse_move_timer
)
3511 if (saved_mouse_move_msg
.msg
.hwnd
)
3513 post_msg (&saved_mouse_move_msg
);
3514 saved_mouse_move_msg
.msg
.hwnd
= 0;
3516 KillTimer (hwnd
, mouse_move_timer
);
3517 mouse_move_timer
= 0;
3519 else if (wParam
== menu_free_timer
)
3521 KillTimer (hwnd
, menu_free_timer
);
3522 menu_free_timer
= 0;
3523 f
= x_window_to_frame (dpyinfo
, hwnd
);
3524 /* If a popup menu is active, don't wipe its strings. */
3526 && current_popup_menu
== NULL
)
3528 /* Free memory used by owner-drawn and help-echo strings. */
3529 w32_free_menu_strings (hwnd
);
3530 f
->output_data
.w32
->menubar_active
= 0;
3537 /* Windows doesn't send us focus messages when putting up and
3538 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
3539 The only indication we get that something happened is receiving
3540 this message afterwards. So this is a good time to reset our
3541 keyboard modifiers' state. */
3548 /* We must ensure menu bar is fully constructed and up to date
3549 before allowing user interaction with it. To achieve this
3550 we send this message to the lisp thread and wait for a
3551 reply (whose value is not actually needed) to indicate that
3552 the menu bar is now ready for use, so we can now return.
3554 To remain responsive in the meantime, we enter a nested message
3555 loop that can process all other messages.
3557 However, we skip all this if the message results from calling
3558 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
3559 thread a message because it is blocked on us at this point. We
3560 set menubar_active before calling TrackPopupMenu to indicate
3561 this (there is no possibility of confusion with real menubar
3564 f
= x_window_to_frame (dpyinfo
, hwnd
);
3566 && (f
->output_data
.w32
->menubar_active
3567 /* We can receive this message even in the absence of a
3568 menubar (ie. when the system menu is activated) - in this
3569 case we do NOT want to forward the message, otherwise it
3570 will cause the menubar to suddenly appear when the user
3571 had requested it to be turned off! */
3572 || f
->output_data
.w32
->menubar_widget
== NULL
))
3576 deferred_msg msg_buf
;
3578 /* Detect if message has already been deferred; in this case
3579 we cannot return any sensible value to ignore this. */
3580 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3585 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
3588 case WM_EXITMENULOOP
:
3589 f
= x_window_to_frame (dpyinfo
, hwnd
);
3591 /* If a menu is still active, check again after a short delay,
3592 since Windows often (always?) sends the WM_EXITMENULOOP
3593 before the corresponding WM_COMMAND message.
3594 Don't do this if a popup menu is active, since it is only
3595 menubar menus that require cleaning up in this way.
3597 if (f
&& menubar_in_use
&& current_popup_menu
== NULL
)
3598 menu_free_timer
= SetTimer (hwnd
, MENU_FREE_ID
, MENU_FREE_DELAY
, NULL
);
3602 /* Direct handling of help_echo in menus. Should be safe now
3603 that we generate the help_echo by placing a help event in the
3606 HMENU menu
= (HMENU
) lParam
;
3607 UINT menu_item
= (UINT
) LOWORD (wParam
);
3608 UINT flags
= (UINT
) HIWORD (wParam
);
3610 w32_menu_display_help (hwnd
, menu
, menu_item
, flags
);
3614 case WM_MEASUREITEM
:
3615 f
= x_window_to_frame (dpyinfo
, hwnd
);
3618 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
3620 if (pMis
->CtlType
== ODT_MENU
)
3622 /* Work out dimensions for popup menu titles. */
3623 char * title
= (char *) pMis
->itemData
;
3624 HDC hdc
= GetDC (hwnd
);
3625 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3626 LOGFONT menu_logfont
;
3630 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3631 menu_logfont
.lfWeight
= FW_BOLD
;
3632 menu_font
= CreateFontIndirect (&menu_logfont
);
3633 old_font
= SelectObject (hdc
, menu_font
);
3635 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
3638 if (unicode_append_menu
)
3639 GetTextExtentPoint32W (hdc
, (WCHAR
*) title
,
3640 wcslen ((WCHAR
*) title
),
3643 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
3645 pMis
->itemWidth
= size
.cx
;
3646 if (pMis
->itemHeight
< size
.cy
)
3647 pMis
->itemHeight
= size
.cy
;
3650 pMis
->itemWidth
= 0;
3652 SelectObject (hdc
, old_font
);
3653 DeleteObject (menu_font
);
3654 ReleaseDC (hwnd
, hdc
);
3661 f
= x_window_to_frame (dpyinfo
, hwnd
);
3664 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
3666 if (pDis
->CtlType
== ODT_MENU
)
3668 /* Draw popup menu title. */
3669 char * title
= (char *) pDis
->itemData
;
3672 HDC hdc
= pDis
->hDC
;
3673 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3674 LOGFONT menu_logfont
;
3677 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3678 menu_logfont
.lfWeight
= FW_BOLD
;
3679 menu_font
= CreateFontIndirect (&menu_logfont
);
3680 old_font
= SelectObject (hdc
, menu_font
);
3682 /* Always draw title as if not selected. */
3683 if (unicode_append_menu
)
3686 + GetSystemMetrics (SM_CXMENUCHECK
),
3688 ETO_OPAQUE
, &pDis
->rcItem
,
3690 wcslen ((WCHAR
*) title
), NULL
);
3694 + GetSystemMetrics (SM_CXMENUCHECK
),
3696 ETO_OPAQUE
, &pDis
->rcItem
,
3697 title
, strlen (title
), NULL
);
3699 SelectObject (hdc
, old_font
);
3700 DeleteObject (menu_font
);
3708 /* Still not right - can't distinguish between clicks in the
3709 client area of the frame from clicks forwarded from the scroll
3710 bars - may have to hook WM_NCHITTEST to remember the mouse
3711 position and then check if it is in the client area ourselves. */
3712 case WM_MOUSEACTIVATE
:
3713 /* Discard the mouse click that activates a frame, allowing the
3714 user to click anywhere without changing point (or worse!).
3715 Don't eat mouse clicks on scrollbars though!! */
3716 if (LOWORD (lParam
) == HTCLIENT
)
3717 return MA_ACTIVATEANDEAT
;
3722 /* No longer tracking mouse. */
3723 track_mouse_window
= NULL
;
3725 case WM_ACTIVATEAPP
:
3727 case WM_WINDOWPOSCHANGED
:
3729 /* Inform lisp thread that a frame might have just been obscured
3730 or exposed, so should recheck visibility of all frames. */
3731 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3735 dpyinfo
->faked_key
= 0;
3737 register_hot_keys (hwnd
);
3740 unregister_hot_keys (hwnd
);
3743 /* Relinquish the system caret. */
3744 if (w32_system_caret_hwnd
)
3746 w32_visible_system_caret_hwnd
= NULL
;
3747 w32_system_caret_hwnd
= NULL
;
3753 f
= x_window_to_frame (dpyinfo
, hwnd
);
3754 if (f
&& HIWORD (wParam
) == 0)
3756 if (menu_free_timer
)
3758 KillTimer (hwnd
, menu_free_timer
);
3759 menu_free_timer
= 0;
3765 wmsg
.dwModifiers
= w32_get_modifiers ();
3766 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3774 wmsg
.dwModifiers
= w32_get_modifiers ();
3775 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3778 case WM_WINDOWPOSCHANGING
:
3779 /* Don't restrict the sizing of tip frames. */
3780 if (hwnd
== tip_window
)
3784 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
3786 wp
.length
= sizeof (WINDOWPLACEMENT
);
3787 GetWindowPlacement (hwnd
, &wp
);
3789 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
3796 DWORD internal_border
;
3797 DWORD scrollbar_extra
;
3800 wp
.length
= sizeof (wp
);
3801 GetWindowRect (hwnd
, &wr
);
3805 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
3806 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
3807 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
3808 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
3812 memset (&rect
, 0, sizeof (rect
));
3813 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
3814 GetMenu (hwnd
) != NULL
);
3816 /* Force width and height of client area to be exact
3817 multiples of the character cell dimensions. */
3818 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
3819 - 2 * internal_border
- scrollbar_extra
)
3821 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
3822 - 2 * internal_border
)
3827 /* For right/bottom sizing we can just fix the sizes.
3828 However for top/left sizing we will need to fix the X
3829 and Y positions as well. */
3831 int cx_mintrack
= GetSystemMetrics (SM_CXMINTRACK
);
3832 int cy_mintrack
= GetSystemMetrics (SM_CYMINTRACK
);
3834 lppos
->cx
= max (lppos
->cx
- wdiff
, cx_mintrack
);
3835 lppos
->cy
= max (lppos
->cy
- hdiff
, cy_mintrack
);
3837 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
3838 && (lppos
->flags
& SWP_NOMOVE
) == 0)
3840 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
3847 lppos
->flags
|= SWP_NOMOVE
;
3858 case WM_GETMINMAXINFO
:
3859 /* Hack to allow resizing the Emacs frame above the screen size.
3860 Note that Windows 9x limits coordinates to 16-bits. */
3861 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.x
= 32767;
3862 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.y
= 32767;
3866 if (LOWORD (lParam
) == HTCLIENT
)
3871 case WM_EMACS_SETCURSOR
:
3873 Cursor cursor
= (Cursor
) wParam
;
3879 case WM_EMACS_CREATESCROLLBAR
:
3880 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
3881 (struct scroll_bar
*) lParam
);
3883 case WM_EMACS_SHOWWINDOW
:
3884 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
3886 case WM_EMACS_SETFOREGROUND
:
3888 HWND foreground_window
;
3889 DWORD foreground_thread
, retval
;
3891 /* On NT 5.0, and apparently Windows 98, it is necessary to
3892 attach to the thread that currently has focus in order to
3893 pull the focus away from it. */
3894 foreground_window
= GetForegroundWindow ();
3895 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
3896 if (!foreground_window
3897 || foreground_thread
== GetCurrentThreadId ()
3898 || !AttachThreadInput (GetCurrentThreadId (),
3899 foreground_thread
, TRUE
))
3900 foreground_thread
= 0;
3902 retval
= SetForegroundWindow ((HWND
) wParam
);
3904 /* Detach from the previous foreground thread. */
3905 if (foreground_thread
)
3906 AttachThreadInput (GetCurrentThreadId (),
3907 foreground_thread
, FALSE
);
3912 case WM_EMACS_SETWINDOWPOS
:
3914 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
3915 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
3916 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
3919 case WM_EMACS_DESTROYWINDOW
:
3920 DragAcceptFiles ((HWND
) wParam
, FALSE
);
3921 return DestroyWindow ((HWND
) wParam
);
3923 case WM_EMACS_HIDE_CARET
:
3924 return HideCaret (hwnd
);
3926 case WM_EMACS_SHOW_CARET
:
3927 return ShowCaret (hwnd
);
3929 case WM_EMACS_DESTROY_CARET
:
3930 w32_system_caret_hwnd
= NULL
;
3931 w32_visible_system_caret_hwnd
= NULL
;
3932 return DestroyCaret ();
3934 case WM_EMACS_TRACK_CARET
:
3935 /* If there is currently no system caret, create one. */
3936 if (w32_system_caret_hwnd
== NULL
)
3938 /* Use the default caret width, and avoid changing it
3939 unneccesarily, as it confuses screen reader software. */
3940 w32_system_caret_hwnd
= hwnd
;
3941 CreateCaret (hwnd
, NULL
, 0,
3942 w32_system_caret_height
);
3945 if (!SetCaretPos (w32_system_caret_x
, w32_system_caret_y
))
3947 /* Ensure visible caret gets turned on when requested. */
3948 else if (w32_use_visible_system_caret
3949 && w32_visible_system_caret_hwnd
!= hwnd
)
3951 w32_visible_system_caret_hwnd
= hwnd
;
3952 return ShowCaret (hwnd
);
3954 /* Ensure visible caret gets turned off when requested. */
3955 else if (!w32_use_visible_system_caret
3956 && w32_visible_system_caret_hwnd
)
3958 w32_visible_system_caret_hwnd
= NULL
;
3959 return HideCaret (hwnd
);
3964 case WM_EMACS_TRACKPOPUPMENU
:
3969 pos
= (POINT
*)lParam
;
3970 flags
= TPM_CENTERALIGN
;
3971 if (button_state
& LMOUSE
)
3972 flags
|= TPM_LEFTBUTTON
;
3973 else if (button_state
& RMOUSE
)
3974 flags
|= TPM_RIGHTBUTTON
;
3976 /* Remember we did a SetCapture on the initial mouse down event,
3977 so for safety, we make sure the capture is cancelled now. */
3981 /* Use menubar_active to indicate that WM_INITMENU is from
3982 TrackPopupMenu below, and should be ignored. */
3983 f
= x_window_to_frame (dpyinfo
, hwnd
);
3985 f
->output_data
.w32
->menubar_active
= 1;
3987 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
3991 /* Eat any mouse messages during popupmenu */
3992 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
3994 /* Get the menu selection, if any */
3995 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
3997 retval
= LOWORD (amsg
.wParam
);
4013 /* Check for messages registered at runtime. */
4014 if (msg
== msh_mousewheel
)
4016 wmsg
.dwModifiers
= w32_get_modifiers ();
4017 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4018 signal_user_input ();
4023 return DefWindowProc (hwnd
, msg
, wParam
, lParam
);
4027 /* The most common default return code for handled messages is 0. */
4032 my_create_window (f
)
4037 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
4039 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
4043 /* Create a tooltip window. Unlike my_create_window, we do not do this
4044 indirectly via the Window thread, as we do not need to process Window
4045 messages for the tooltip. Creating tooltips indirectly also creates
4046 deadlocks when tooltips are created for menu items. */
4048 my_create_tip_window (f
)
4053 rect
.left
= rect
.top
= 0;
4054 rect
.right
= FRAME_PIXEL_WIDTH (f
);
4055 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
4057 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
4058 FRAME_EXTERNAL_MENU_BAR (f
));
4060 tip_window
= FRAME_W32_WINDOW (f
)
4061 = CreateWindow (EMACS_CLASS
,
4063 f
->output_data
.w32
->dwStyle
,
4066 rect
.right
- rect
.left
,
4067 rect
.bottom
- rect
.top
,
4068 FRAME_W32_WINDOW (SELECTED_FRAME ()), /* owner */
4075 SetWindowLong (tip_window
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
4076 SetWindowLong (tip_window
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
4077 SetWindowLong (tip_window
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
4078 SetWindowLong (tip_window
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
4080 /* Tip frames have no scrollbars. */
4081 SetWindowLong (tip_window
, WND_SCROLLBAR_INDEX
, 0);
4083 /* Do this to discard the default setting specified by our parent. */
4084 ShowWindow (tip_window
, SW_HIDE
);
4089 /* Create and set up the w32 window for frame F. */
4092 w32_window (f
, window_prompting
, minibuffer_only
)
4094 long window_prompting
;
4095 int minibuffer_only
;
4099 /* Use the resource name as the top-level window name
4100 for looking up resources. Make a non-Lisp copy
4101 for the window manager, so GC relocation won't bother it.
4103 Elsewhere we specify the window name for the window manager. */
4106 char *str
= (char *) SDATA (Vx_resource_name
);
4107 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
4108 strcpy (f
->namebuf
, str
);
4111 my_create_window (f
);
4113 validate_x_resource_name ();
4115 /* x_set_name normally ignores requests to set the name if the
4116 requested name is the same as the current name. This is the one
4117 place where that assumption isn't correct; f->name is set, but
4118 the server hasn't been told. */
4121 int explicit = f
->explicit_name
;
4123 f
->explicit_name
= 0;
4126 x_set_name (f
, name
, explicit);
4131 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
4132 initialize_frame_menubar (f
);
4134 if (FRAME_W32_WINDOW (f
) == 0)
4135 error ("Unable to create window");
4138 /* Handle the icon stuff for this window. Perhaps later we might
4139 want an x_set_icon_position which can be called interactively as
4147 Lisp_Object icon_x
, icon_y
;
4149 /* Set the position of the icon. Note that Windows 95 groups all
4150 icons in the tray. */
4151 icon_x
= w32_get_arg (parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
4152 icon_y
= w32_get_arg (parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
4153 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
4155 CHECK_NUMBER (icon_x
);
4156 CHECK_NUMBER (icon_y
);
4158 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
4159 error ("Both left and top icon corners of icon must be specified");
4163 if (! EQ (icon_x
, Qunbound
))
4164 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
4167 /* Start up iconic or window? */
4168 x_wm_set_window_state
4169 (f
, (EQ (w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
4173 x_text_icon (f
, (char *) SDATA ((!NILP (f
->icon_name
)
4186 XGCValues gc_values
;
4190 /* Create the GC's of this frame.
4191 Note that many default values are used. */
4194 gc_values
.font
= FRAME_FONT (f
);
4196 /* Cursor has cursor-color background, background-color foreground. */
4197 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
4198 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
4199 f
->output_data
.w32
->cursor_gc
4200 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
4201 (GCFont
| GCForeground
| GCBackground
),
4205 f
->output_data
.w32
->white_relief
.gc
= 0;
4206 f
->output_data
.w32
->black_relief
.gc
= 0;
4212 /* Handler for signals raised during x_create_frame and
4213 x_create_top_frame. FRAME is the frame which is partially
4217 unwind_create_frame (frame
)
4220 struct frame
*f
= XFRAME (frame
);
4222 /* If frame is ``official'', nothing to do. */
4223 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
4226 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4229 x_free_frame_resources (f
);
4231 /* Check that reference counts are indeed correct. */
4232 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
4233 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
4241 #ifdef USE_FONT_BACKEND
4243 x_default_font_parameter (f
, parms
)
4247 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4248 Lisp_Object font
= x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font",
4251 if (!STRINGP (font
))
4254 static char *names
[]
4255 = { "Courier New-10",
4256 "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1",
4257 "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1",
4261 for (i
= 0; names
[i
]; i
++)
4263 font
= font_open_by_name (f
, names
[i
]);
4268 error ("No suitable font was found");
4270 x_default_parameter (f
, parms
, Qfont
, font
, "font", "Font", RES_TYPE_STRING
);
4274 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
4276 doc
: /* Make a new window, which is called a \"frame\" in Emacs terms.
4277 Return an Emacs frame object.
4278 PARAMETERS is an alist of frame parameters.
4279 If the parameters specify that the frame should not have a minibuffer,
4280 and do not specify a specific minibuffer window to use,
4281 then `default-minibuffer-frame' must be a frame whose minibuffer can
4282 be shared by the new frame.
4284 This function is an internal primitive--use `make-frame' instead. */)
4286 Lisp_Object parameters
;
4289 Lisp_Object frame
, tem
;
4291 int minibuffer_only
= 0;
4292 long window_prompting
= 0;
4294 int count
= SPECPDL_INDEX ();
4295 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4296 Lisp_Object display
;
4297 struct w32_display_info
*dpyinfo
= NULL
;
4303 /* Make copy of frame parameters because the original is in pure
4305 parameters
= Fcopy_alist (parameters
);
4307 /* Use this general default value to start with
4308 until we know if this frame has a specified name. */
4309 Vx_resource_name
= Vinvocation_name
;
4311 display
= w32_get_arg (parameters
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
4312 if (EQ (display
, Qunbound
))
4314 dpyinfo
= check_x_display_info (display
);
4316 kb
= dpyinfo
->terminal
->kboard
;
4318 kb
= &the_only_kboard
;
4321 name
= w32_get_arg (parameters
, Qname
, "name", "Name", RES_TYPE_STRING
);
4323 && ! EQ (name
, Qunbound
)
4325 error ("Invalid frame name--not a string or nil");
4328 Vx_resource_name
= name
;
4330 /* See if parent window is specified. */
4331 parent
= w32_get_arg (parameters
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
4332 if (EQ (parent
, Qunbound
))
4334 if (! NILP (parent
))
4335 CHECK_NUMBER (parent
);
4337 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
4338 /* No need to protect DISPLAY because that's not used after passing
4339 it to make_frame_without_minibuffer. */
4341 GCPRO4 (parameters
, parent
, name
, frame
);
4342 tem
= w32_get_arg (parameters
, Qminibuffer
, "minibuffer", "Minibuffer",
4344 if (EQ (tem
, Qnone
) || NILP (tem
))
4345 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
4346 else if (EQ (tem
, Qonly
))
4348 f
= make_minibuffer_frame ();
4349 minibuffer_only
= 1;
4351 else if (WINDOWP (tem
))
4352 f
= make_frame_without_minibuffer (tem
, kb
, display
);
4356 XSETFRAME (frame
, f
);
4358 /* Note that Windows does support scroll bars. */
4359 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
4361 /* By default, make scrollbars the system standard width. */
4362 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
4364 f
->terminal
= dpyinfo
->terminal
;
4365 f
->terminal
->reference_count
++;
4367 f
->output_method
= output_w32
;
4368 f
->output_data
.w32
=
4369 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
4370 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
4371 FRAME_FONTSET (f
) = -1;
4372 record_unwind_protect (unwind_create_frame
, frame
);
4375 = w32_get_arg (parameters
, Qicon_name
, "iconName", "Title", RES_TYPE_STRING
);
4376 if (! STRINGP (f
->icon_name
))
4377 f
->icon_name
= Qnil
;
4379 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
4381 FRAME_KBOARD (f
) = kb
;
4384 /* Specify the parent under which to make this window. */
4388 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
4389 f
->output_data
.w32
->explicit_parent
= 1;
4393 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4394 f
->output_data
.w32
->explicit_parent
= 0;
4397 /* Set the name; the functions to which we pass f expect the name to
4399 if (EQ (name
, Qunbound
) || NILP (name
))
4401 f
->name
= build_string (dpyinfo
->w32_id_name
);
4402 f
->explicit_name
= 0;
4407 f
->explicit_name
= 1;
4408 /* use the frame's title when getting resources for this frame. */
4409 specbind (Qx_resource_name
, name
);
4412 f
->resx
= dpyinfo
->resx
;
4413 f
->resy
= dpyinfo
->resy
;
4415 #ifdef USE_FONT_BACKEND
4416 if (enable_font_backend
)
4418 /* Perhaps, we must allow frame parameter, say `font-backend',
4419 to specify which font backends to use. */
4420 if (uniscribe_available
)
4421 register_font_driver (&uniscribe_font_driver
, f
);
4422 register_font_driver (&w32font_driver
, f
);
4424 x_default_parameter (f
, parameters
, Qfont_backend
, Qnil
,
4425 "fontBackend", "FontBackend", RES_TYPE_STRING
);
4427 #endif /* USE_FONT_BACKEND */
4429 /* Extract the window parameters from the supplied values
4430 that are needed to determine window geometry. */
4431 #ifdef USE_FONT_BACKEND
4432 if (enable_font_backend
)
4433 x_default_font_parameter (f
, parameters
);
4439 font
= w32_get_arg (parameters
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4442 /* First, try whatever font the caller has specified. */
4445 tem
= Fquery_fontset (font
, Qnil
);
4447 font
= x_new_fontset (f
, tem
);
4449 font
= x_new_font (f
, SDATA (font
));
4451 /* Try out a font which we hope has bold and italic variations. */
4452 if (!STRINGP (font
))
4453 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
4454 if (! STRINGP (font
))
4455 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
4456 /* If those didn't work, look for something which will at least work. */
4457 if (! STRINGP (font
))
4458 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
4460 if (! STRINGP (font
))
4461 font
= build_string ("Fixedsys");
4463 x_default_parameter (f
, parameters
, Qfont
, font
,
4464 "font", "Font", RES_TYPE_STRING
);
4467 x_default_parameter (f
, parameters
, Qborder_width
, make_number (2),
4468 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4469 /* This defaults to 2 in order to match xterm. We recognize either
4470 internalBorderWidth or internalBorder (which is what xterm calls
4472 if (NILP (Fassq (Qinternal_border_width
, parameters
)))
4476 value
= w32_get_arg (parameters
, Qinternal_border_width
,
4477 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
4478 if (! EQ (value
, Qunbound
))
4479 parameters
= Fcons (Fcons (Qinternal_border_width
, value
),
4482 /* Default internalBorderWidth to 0 on Windows to match other programs. */
4483 x_default_parameter (f
, parameters
, Qinternal_border_width
, make_number (0),
4484 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
4485 x_default_parameter (f
, parameters
, Qvertical_scroll_bars
, Qright
,
4486 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
4488 /* Also do the stuff which must be set before the window exists. */
4489 x_default_parameter (f
, parameters
, Qforeground_color
, build_string ("black"),
4490 "foreground", "Foreground", RES_TYPE_STRING
);
4491 x_default_parameter (f
, parameters
, Qbackground_color
, build_string ("white"),
4492 "background", "Background", RES_TYPE_STRING
);
4493 x_default_parameter (f
, parameters
, Qmouse_color
, build_string ("black"),
4494 "pointerColor", "Foreground", RES_TYPE_STRING
);
4495 x_default_parameter (f
, parameters
, Qcursor_color
, build_string ("black"),
4496 "cursorColor", "Foreground", RES_TYPE_STRING
);
4497 x_default_parameter (f
, parameters
, Qborder_color
, build_string ("black"),
4498 "borderColor", "BorderColor", RES_TYPE_STRING
);
4499 x_default_parameter (f
, parameters
, Qscreen_gamma
, Qnil
,
4500 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
4501 x_default_parameter (f
, parameters
, Qline_spacing
, Qnil
,
4502 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
4503 x_default_parameter (f
, parameters
, Qleft_fringe
, Qnil
,
4504 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
4505 x_default_parameter (f
, parameters
, Qright_fringe
, Qnil
,
4506 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
4509 /* Init faces before x_default_parameter is called for scroll-bar
4510 parameters because that function calls x_set_scroll_bar_width,
4511 which calls change_frame_size, which calls Fset_window_buffer,
4512 which runs hooks, which call Fvertical_motion. At the end, we
4513 end up in init_iterator with a null face cache, which should not
4515 init_frame_faces (f
);
4517 x_default_parameter (f
, parameters
, Qmenu_bar_lines
, make_number (1),
4518 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
4519 x_default_parameter (f
, parameters
, Qtool_bar_lines
, make_number (1),
4520 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
4522 x_default_parameter (f
, parameters
, Qbuffer_predicate
, Qnil
,
4523 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
4524 x_default_parameter (f
, parameters
, Qtitle
, Qnil
,
4525 "title", "Title", RES_TYPE_STRING
);
4526 x_default_parameter (f
, parameters
, Qfullscreen
, Qnil
,
4527 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
4529 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
4530 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4532 f
->output_data
.w32
->text_cursor
= w32_load_cursor (IDC_IBEAM
);
4533 f
->output_data
.w32
->nontext_cursor
= w32_load_cursor (IDC_ARROW
);
4534 f
->output_data
.w32
->modeline_cursor
= w32_load_cursor (IDC_ARROW
);
4535 f
->output_data
.w32
->hand_cursor
= w32_load_cursor (IDC_HAND
);
4536 f
->output_data
.w32
->hourglass_cursor
= w32_load_cursor (IDC_WAIT
);
4537 f
->output_data
.w32
->horizontal_drag_cursor
= w32_load_cursor (IDC_SIZEWE
);
4539 window_prompting
= x_figure_window_size (f
, parameters
, 1);
4541 tem
= w32_get_arg (parameters
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
4542 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
4544 w32_window (f
, window_prompting
, minibuffer_only
);
4545 x_icon (f
, parameters
);
4549 /* Now consider the frame official. */
4550 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
4551 Vframe_list
= Fcons (frame
, Vframe_list
);
4553 /* We need to do this after creating the window, so that the
4554 icon-creation functions can say whose icon they're describing. */
4555 x_default_parameter (f
, parameters
, Qicon_type
, Qnil
,
4556 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
4558 x_default_parameter (f
, parameters
, Qauto_raise
, Qnil
,
4559 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4560 x_default_parameter (f
, parameters
, Qauto_lower
, Qnil
,
4561 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4562 x_default_parameter (f
, parameters
, Qcursor_type
, Qbox
,
4563 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4564 x_default_parameter (f
, parameters
, Qscroll_bar_width
, Qnil
,
4565 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
4567 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4568 Change will not be effected unless different from the current
4570 width
= FRAME_COLS (f
);
4571 height
= FRAME_LINES (f
);
4573 FRAME_LINES (f
) = 0;
4574 SET_FRAME_COLS (f
, 0);
4575 change_frame_size (f
, height
, width
, 1, 0, 0);
4577 /* Tell the server what size and position, etc, we want, and how
4578 badly we want them. This should be done after we have the menu
4579 bar so that its size can be taken into account. */
4581 x_wm_set_size_hint (f
, window_prompting
, 0);
4584 /* Make the window appear on the frame and enable display, unless
4585 the caller says not to. However, with explicit parent, Emacs
4586 cannot control visibility, so don't try. */
4587 if (! f
->output_data
.w32
->explicit_parent
)
4589 Lisp_Object visibility
;
4591 visibility
= w32_get_arg (parameters
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
4592 if (EQ (visibility
, Qunbound
))
4595 if (EQ (visibility
, Qicon
))
4596 x_iconify_frame (f
);
4597 else if (! NILP (visibility
))
4598 x_make_frame_visible (f
);
4600 /* Must have been Qnil. */
4604 /* Initialize `default-minibuffer-frame' in case this is the first
4605 frame on this terminal. */
4606 if (FRAME_HAS_MINIBUF_P (f
)
4607 && (!FRAMEP (kb
->Vdefault_minibuffer_frame
)
4608 || !FRAME_LIVE_P (XFRAME (kb
->Vdefault_minibuffer_frame
))))
4609 kb
->Vdefault_minibuffer_frame
= frame
;
4611 /* All remaining specified parameters, which have not been "used"
4612 by x_get_arg and friends, now go in the misc. alist of the frame. */
4613 for (tem
= parameters
; CONSP (tem
); tem
= XCDR (tem
))
4614 if (CONSP (XCAR (tem
)) && !NILP (XCAR (XCAR (tem
))))
4615 f
->param_alist
= Fcons (XCAR (tem
), f
->param_alist
);
4619 /* Make sure windows on this frame appear in calls to next-window
4620 and similar functions. */
4621 Vwindow_list
= Qnil
;
4623 return unbind_to (count
, frame
);
4626 /* FRAME is used only to get a handle on the X display. We don't pass the
4627 display info directly because we're called from frame.c, which doesn't
4628 know about that structure. */
4630 x_get_focus_frame (frame
)
4631 struct frame
*frame
;
4633 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
4635 if (! dpyinfo
->w32_focus_frame
)
4638 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
4642 DEFUN ("x-focus-frame", Fx_focus_frame
, Sx_focus_frame
, 1, 1, 0,
4643 doc
: /* Give FRAME input focus, raising to foreground if necessary. */)
4647 x_focus_on_frame (check_x_frame (frame
));
4652 /* Return the charset portion of a font name. */
4654 xlfd_charset_of_font (char * fontname
)
4656 char *charset
, *encoding
;
4658 encoding
= strrchr (fontname
, '-');
4659 if (!encoding
|| encoding
== fontname
)
4662 for (charset
= encoding
- 1; charset
>= fontname
; charset
--)
4663 if (*charset
== '-')
4666 if (charset
== fontname
|| strcmp (charset
, "-*-*") == 0)
4672 struct font_info
*w32_load_bdf_font (struct frame
*f
, char *fontname
,
4673 int size
, char* filename
);
4674 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
);
4675 static BOOL
w32_to_x_font (LOGFONT
* lplf
, char * lpxstr
, int len
,
4677 static BOOL
x_to_w32_font (char *lpxstr
, LOGFONT
*lplogfont
);
4679 static struct font_info
*
4680 w32_load_system_font (f
, fontname
, size
)
4685 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4686 Lisp_Object font_names
;
4688 /* Get a list of all the fonts that match this name. Once we
4689 have a list of matching fonts, we compare them against the fonts
4690 we already have loaded by comparing names. */
4691 font_names
= w32_list_fonts (f
, build_string (fontname
), size
, 100);
4693 if (!NILP (font_names
))
4698 /* First check if any are already loaded, as that is cheaper
4699 than loading another one. */
4700 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
4701 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
4702 if (dpyinfo
->font_table
[i
].name
4703 && (!strcmp (dpyinfo
->font_table
[i
].name
,
4704 SDATA (XCAR (tail
)))
4705 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
4706 SDATA (XCAR (tail
)))))
4707 return (dpyinfo
->font_table
+ i
);
4709 fontname
= (char *) SDATA (XCAR (font_names
));
4711 else if (w32_strict_fontnames
)
4713 /* If EnumFontFamiliesEx was available, we got a full list of
4714 fonts back so stop now to avoid the possibility of loading a
4715 random font. If we had to fall back to EnumFontFamilies, the
4716 list is incomplete, so continue whether the font we want was
4718 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
4719 FARPROC enum_font_families_ex
4720 = GetProcAddress (gdi32
, "EnumFontFamiliesExA");
4721 if (enum_font_families_ex
)
4725 /* Load the font and add it to the table. */
4727 char *full_name
, *encoding
, *charset
;
4729 struct font_info
*fontp
;
4735 if (!fontname
|| !x_to_w32_font (fontname
, &lf
))
4738 if (!*lf
.lfFaceName
)
4739 /* If no name was specified for the font, we get a random font
4740 from CreateFontIndirect - this is not particularly
4741 desirable, especially since CreateFontIndirect does not
4742 fill out the missing name in lf, so we never know what we
4746 lf
.lfQuality
= DEFAULT_QUALITY
;
4748 font
= (XFontStruct
*) xmalloc (sizeof (XFontStruct
));
4749 bzero (font
, sizeof (*font
));
4751 /* Set bdf to NULL to indicate that this is a Windows font. */
4756 font
->hfont
= CreateFontIndirect (&lf
);
4758 if (font
->hfont
== NULL
)
4767 codepage
= w32_codepage_for_font (fontname
);
4769 hdc
= GetDC (dpyinfo
->root_window
);
4770 oldobj
= SelectObject (hdc
, font
->hfont
);
4772 ok
= GetTextMetrics (hdc
, &font
->tm
);
4773 if (codepage
== CP_UNICODE
)
4774 font
->double_byte_p
= 1;
4777 /* Unfortunately, some fonts (eg. MingLiU, a big5 ttf font)
4778 don't report themselves as double byte fonts, when
4779 patently they are. So instead of trusting
4780 GetFontLanguageInfo, we check the properties of the
4781 codepage directly, since that is ultimately what we are
4782 working from anyway. */
4783 /* font->double_byte_p = GetFontLanguageInfo (hdc) & GCP_DBCS; */
4785 GetCPInfo (codepage
, &cpi
);
4786 font
->double_byte_p
= cpi
.MaxCharSize
> 1;
4789 SelectObject (hdc
, oldobj
);
4790 ReleaseDC (dpyinfo
->root_window
, hdc
);
4791 /* Fill out details in lf according to the font that was
4793 lf
.lfHeight
= font
->tm
.tmInternalLeading
- font
->tm
.tmHeight
;
4794 lf
.lfWidth
= font
->tm
.tmMaxCharWidth
;
4795 lf
.lfWeight
= font
->tm
.tmWeight
;
4796 lf
.lfItalic
= font
->tm
.tmItalic
;
4797 lf
.lfCharSet
= font
->tm
.tmCharSet
;
4798 lf
.lfPitchAndFamily
= ((font
->tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
)
4799 ? VARIABLE_PITCH
: FIXED_PITCH
);
4800 lf
.lfOutPrecision
= ((font
->tm
.tmPitchAndFamily
& TMPF_VECTOR
)
4801 ? OUT_STROKE_PRECIS
: OUT_STRING_PRECIS
);
4803 w32_cache_char_metrics (font
);
4810 w32_unload_font (dpyinfo
, font
);
4814 /* Find a free slot in the font table. */
4815 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
4816 if (dpyinfo
->font_table
[i
].name
== NULL
)
4819 /* If no free slot found, maybe enlarge the font table. */
4820 if (i
== dpyinfo
->n_fonts
4821 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
4824 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
4825 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
4827 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
4830 fontp
= dpyinfo
->font_table
+ i
;
4831 if (i
== dpyinfo
->n_fonts
)
4834 /* Now fill in the slots of *FONTP. */
4836 bzero (fontp
, sizeof (*fontp
));
4838 fontp
->font_idx
= i
;
4839 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
4840 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
4842 if ((lf
.lfPitchAndFamily
& 0x03) == FIXED_PITCH
)
4844 /* Fixed width font. */
4845 fontp
->average_width
= fontp
->space_width
= FONT_AVG_WIDTH (font
);
4851 pcm
= w32_per_char_metric (font
, &space
, ANSI_FONT
);
4853 fontp
->space_width
= pcm
->width
;
4855 fontp
->space_width
= FONT_AVG_WIDTH (font
);
4857 fontp
->average_width
= font
->tm
.tmAveCharWidth
;
4860 fontp
->charset
= -1;
4861 charset
= xlfd_charset_of_font (fontname
);
4863 /* Cache the W32 codepage for a font. This makes w32_encode_char
4864 (called for every glyph during redisplay) much faster. */
4865 fontp
->codepage
= codepage
;
4867 /* Work out the font's full name. */
4868 full_name
= (char *)xmalloc (100);
4869 if (full_name
&& w32_to_x_font (&lf
, full_name
, 100, charset
))
4870 fontp
->full_name
= full_name
;
4873 /* If all else fails - just use the name we used to load it. */
4875 fontp
->full_name
= fontp
->name
;
4878 fontp
->size
= FONT_WIDTH (font
);
4879 fontp
->height
= FONT_HEIGHT (font
);
4881 /* The slot `encoding' specifies how to map a character
4882 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
4883 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
4884 (0:0x20..0x7F, 1:0xA0..0xFF,
4885 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
4886 2:0xA020..0xFF7F). For the moment, we don't know which charset
4887 uses this font. So, we set information in fontp->encoding_type
4888 which is never used by any charset. If mapping can't be
4889 decided, set FONT_ENCODING_NOT_DECIDED. */
4891 /* SJIS fonts need to be set to type 4, all others seem to work as
4892 type FONT_ENCODING_NOT_DECIDED. */
4893 encoding
= strrchr (fontp
->name
, '-');
4894 if (encoding
&& strnicmp (encoding
+1, "sjis", 4) == 0)
4895 fontp
->encoding_type
= 4;
4897 fontp
->encoding_type
= FONT_ENCODING_NOT_DECIDED
;
4899 /* The following three values are set to 0 under W32, which is
4900 what they get set to if XGetFontProperty fails under X. */
4901 fontp
->baseline_offset
= 0;
4902 fontp
->relative_compose
= 0;
4903 fontp
->default_ascent
= 0;
4905 /* Set global flag fonts_changed_p to non-zero if the font loaded
4906 has a character with a smaller width than any other character
4907 before, or if the font loaded has a smaller height than any
4908 other font loaded before. If this happens, it will make a
4909 glyph matrix reallocation necessary. */
4910 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
4916 /* Load font named FONTNAME of size SIZE for frame F, and return a
4917 pointer to the structure font_info while allocating it dynamically.
4918 If loading fails, return NULL. */
4920 w32_load_font (f
, fontname
, size
)
4925 Lisp_Object bdf_fonts
;
4926 struct font_info
*retval
= NULL
;
4927 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4929 bdf_fonts
= w32_list_bdf_fonts (build_string (fontname
), 1);
4931 while (!retval
&& CONSP (bdf_fonts
))
4933 char *bdf_name
, *bdf_file
;
4934 Lisp_Object bdf_pair
;
4937 bdf_name
= SDATA (XCAR (bdf_fonts
));
4938 bdf_pair
= Fassoc (XCAR (bdf_fonts
), Vw32_bdf_filename_alist
);
4939 bdf_file
= SDATA (XCDR (bdf_pair
));
4941 /* If the font is already loaded, do not load it again. */
4942 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
4944 if ((dpyinfo
->font_table
[i
].name
4945 && !strcmp (dpyinfo
->font_table
[i
].name
, bdf_name
))
4946 || (dpyinfo
->font_table
[i
].full_name
4947 && !strcmp (dpyinfo
->font_table
[i
].full_name
, bdf_name
)))
4948 return dpyinfo
->font_table
+ i
;
4951 retval
= w32_load_bdf_font (f
, bdf_name
, size
, bdf_file
);
4953 bdf_fonts
= XCDR (bdf_fonts
);
4959 return w32_load_system_font (f
, fontname
, size
);
4964 w32_unload_font (dpyinfo
, font
)
4965 struct w32_display_info
*dpyinfo
;
4970 if (font
->per_char
) xfree (font
->per_char
);
4971 if (font
->bdf
) w32_free_bdf_font (font
->bdf
);
4973 if (font
->hfont
) DeleteObject (font
->hfont
);
4978 /* The font conversion stuff between x and w32 */
4980 /* X font string is as follows (from faces.el)
4984 * (weight "\\(bold\\|demibold\\|medium\\)") ; 1
4985 * (weight\? "\\([^-]*\\)") ; 1
4986 * (slant "\\([ior]\\)") ; 2
4987 * (slant\? "\\([^-]?\\)") ; 2
4988 * (swidth "\\([^-]*\\)") ; 3
4989 * (adstyle "[^-]*") ; 4
4990 * (pixelsize "[0-9]+")
4991 * (pointsize "[0-9][0-9]+")
4992 * (resx "[0-9][0-9]+")
4993 * (resy "[0-9][0-9]+")
4994 * (spacing "[cmp?*]")
4995 * (avgwidth "[0-9]+")
4996 * (registry "[^-]+")
4997 * (encoding "[^-]+")
5002 x_to_w32_weight (lpw
)
5005 if (!lpw
) return (FW_DONTCARE
);
5007 if (stricmp (lpw
, "heavy") == 0) return FW_HEAVY
;
5008 else if (stricmp (lpw
, "extrabold") == 0) return FW_EXTRABOLD
;
5009 else if (stricmp (lpw
, "bold") == 0) return FW_BOLD
;
5010 else if (stricmp (lpw
, "demibold") == 0) return FW_SEMIBOLD
;
5011 else if (stricmp (lpw
, "semibold") == 0) return FW_SEMIBOLD
;
5012 else if (stricmp (lpw
, "medium") == 0) return FW_MEDIUM
;
5013 else if (stricmp (lpw
, "normal") == 0) return FW_NORMAL
;
5014 else if (stricmp (lpw
, "light") == 0) return FW_LIGHT
;
5015 else if (stricmp (lpw
, "extralight") == 0) return FW_EXTRALIGHT
;
5016 else if (stricmp (lpw
, "thin") == 0) return FW_THIN
;
5023 w32_to_x_weight (fnweight
)
5026 if (fnweight
>= FW_HEAVY
) return "heavy";
5027 if (fnweight
>= FW_EXTRABOLD
) return "extrabold";
5028 if (fnweight
>= FW_BOLD
) return "bold";
5029 if (fnweight
>= FW_SEMIBOLD
) return "demibold";
5030 if (fnweight
>= FW_MEDIUM
) return "medium";
5031 if (fnweight
>= FW_NORMAL
) return "normal";
5032 if (fnweight
>= FW_LIGHT
) return "light";
5033 if (fnweight
>= FW_EXTRALIGHT
) return "extralight";
5034 if (fnweight
>= FW_THIN
) return "thin";
5040 x_to_w32_charset (lpcs
)
5043 Lisp_Object this_entry
, w32_charset
;
5045 int len
= strlen (lpcs
);
5047 /* Support "*-#nnn" format for unknown charsets. */
5048 if (strncmp (lpcs
, "*-#", 3) == 0)
5049 return atoi (lpcs
+ 3);
5051 /* All Windows fonts qualify as unicode. */
5052 if (!strncmp (lpcs
, "iso10646", 8))
5053 return DEFAULT_CHARSET
;
5055 /* Handle wildcards by ignoring them; eg. treat "big5*-*" as "big5". */
5056 charset
= alloca (len
+ 1);
5057 strcpy (charset
, lpcs
);
5058 lpcs
= strchr (charset
, '*');
5062 /* Look through w32-charset-info-alist for the character set.
5063 Format of each entry is
5064 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5066 this_entry
= Fassoc (build_string (charset
), Vw32_charset_info_alist
);
5068 if (NILP (this_entry
))
5070 /* At startup, we want iso8859-1 fonts to come up properly. */
5071 if (stricmp (charset
, "iso8859-1") == 0)
5072 return ANSI_CHARSET
;
5074 return DEFAULT_CHARSET
;
5077 w32_charset
= Fcar (Fcdr (this_entry
));
5079 /* Translate Lisp symbol to number. */
5080 if (EQ (w32_charset
, Qw32_charset_ansi
))
5081 return ANSI_CHARSET
;
5082 if (EQ (w32_charset
, Qw32_charset_symbol
))
5083 return SYMBOL_CHARSET
;
5084 if (EQ (w32_charset
, Qw32_charset_shiftjis
))
5085 return SHIFTJIS_CHARSET
;
5086 if (EQ (w32_charset
, Qw32_charset_hangeul
))
5087 return HANGEUL_CHARSET
;
5088 if (EQ (w32_charset
, Qw32_charset_chinesebig5
))
5089 return CHINESEBIG5_CHARSET
;
5090 if (EQ (w32_charset
, Qw32_charset_gb2312
))
5091 return GB2312_CHARSET
;
5092 if (EQ (w32_charset
, Qw32_charset_oem
))
5094 #ifdef JOHAB_CHARSET
5095 if (EQ (w32_charset
, Qw32_charset_johab
))
5096 return JOHAB_CHARSET
;
5097 if (EQ (w32_charset
, Qw32_charset_easteurope
))
5098 return EASTEUROPE_CHARSET
;
5099 if (EQ (w32_charset
, Qw32_charset_turkish
))
5100 return TURKISH_CHARSET
;
5101 if (EQ (w32_charset
, Qw32_charset_baltic
))
5102 return BALTIC_CHARSET
;
5103 if (EQ (w32_charset
, Qw32_charset_russian
))
5104 return RUSSIAN_CHARSET
;
5105 if (EQ (w32_charset
, Qw32_charset_arabic
))
5106 return ARABIC_CHARSET
;
5107 if (EQ (w32_charset
, Qw32_charset_greek
))
5108 return GREEK_CHARSET
;
5109 if (EQ (w32_charset
, Qw32_charset_hebrew
))
5110 return HEBREW_CHARSET
;
5111 if (EQ (w32_charset
, Qw32_charset_vietnamese
))
5112 return VIETNAMESE_CHARSET
;
5113 if (EQ (w32_charset
, Qw32_charset_thai
))
5114 return THAI_CHARSET
;
5115 if (EQ (w32_charset
, Qw32_charset_mac
))
5117 #endif /* JOHAB_CHARSET */
5118 #ifdef UNICODE_CHARSET
5119 if (EQ (w32_charset
, Qw32_charset_unicode
))
5120 return UNICODE_CHARSET
;
5123 return DEFAULT_CHARSET
;
5128 w32_to_x_charset (fncharset
, matching
)
5132 static char buf
[32];
5133 Lisp_Object charset_type
;
5138 /* If fully specified, accept it as it is. Otherwise use a
5140 char *wildcard
= strchr (matching
, '*');
5143 else if (strchr (matching
, '-'))
5146 match_len
= strlen (matching
);
5152 /* Handle startup case of w32-charset-info-alist not
5153 being set up yet. */
5154 if (NILP (Vw32_charset_info_alist
))
5156 charset_type
= Qw32_charset_ansi
;
5158 case DEFAULT_CHARSET
:
5159 charset_type
= Qw32_charset_default
;
5161 case SYMBOL_CHARSET
:
5162 charset_type
= Qw32_charset_symbol
;
5164 case SHIFTJIS_CHARSET
:
5165 charset_type
= Qw32_charset_shiftjis
;
5167 case HANGEUL_CHARSET
:
5168 charset_type
= Qw32_charset_hangeul
;
5170 case GB2312_CHARSET
:
5171 charset_type
= Qw32_charset_gb2312
;
5173 case CHINESEBIG5_CHARSET
:
5174 charset_type
= Qw32_charset_chinesebig5
;
5177 charset_type
= Qw32_charset_oem
;
5180 /* More recent versions of Windows (95 and NT4.0) define more
5182 #ifdef EASTEUROPE_CHARSET
5183 case EASTEUROPE_CHARSET
:
5184 charset_type
= Qw32_charset_easteurope
;
5186 case TURKISH_CHARSET
:
5187 charset_type
= Qw32_charset_turkish
;
5189 case BALTIC_CHARSET
:
5190 charset_type
= Qw32_charset_baltic
;
5192 case RUSSIAN_CHARSET
:
5193 charset_type
= Qw32_charset_russian
;
5195 case ARABIC_CHARSET
:
5196 charset_type
= Qw32_charset_arabic
;
5199 charset_type
= Qw32_charset_greek
;
5201 case HEBREW_CHARSET
:
5202 charset_type
= Qw32_charset_hebrew
;
5204 case VIETNAMESE_CHARSET
:
5205 charset_type
= Qw32_charset_vietnamese
;
5208 charset_type
= Qw32_charset_thai
;
5211 charset_type
= Qw32_charset_mac
;
5214 charset_type
= Qw32_charset_johab
;
5218 #ifdef UNICODE_CHARSET
5219 case UNICODE_CHARSET
:
5220 charset_type
= Qw32_charset_unicode
;
5224 /* Encode numerical value of unknown charset. */
5225 sprintf (buf
, "*-#%u", fncharset
);
5231 char * best_match
= NULL
;
5232 int matching_found
= 0;
5234 /* Look through w32-charset-info-alist for the character set.
5235 Prefer ISO codepages, and prefer lower numbers in the ISO
5236 range. Only return charsets for codepages which are installed.
5238 Format of each entry is
5239 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5241 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
5244 Lisp_Object w32_charset
;
5245 Lisp_Object codepage
;
5247 Lisp_Object this_entry
= XCAR (rest
);
5249 /* Skip invalid entries in alist. */
5250 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
5251 || !CONSP (XCDR (this_entry
))
5252 || !SYMBOLP (XCAR (XCDR (this_entry
))))
5255 x_charset
= SDATA (XCAR (this_entry
));
5256 w32_charset
= XCAR (XCDR (this_entry
));
5257 codepage
= XCDR (XCDR (this_entry
));
5259 /* Look for Same charset and a valid codepage (or non-int
5260 which means ignore). */
5261 if (EQ (w32_charset
, charset_type
)
5262 && (!INTEGERP (codepage
) || XINT (codepage
) == CP_DEFAULT
5263 || IsValidCodePage (XINT (codepage
))))
5265 /* If we don't have a match already, then this is the
5269 best_match
= x_charset
;
5270 if (matching
&& !strnicmp (x_charset
, matching
, match_len
))
5273 /* If we already found a match for MATCHING, then
5274 only consider other matches. */
5275 else if (matching_found
5276 && strnicmp (x_charset
, matching
, match_len
))
5278 /* If this matches what we want, and the best so far doesn't,
5279 then this is better. */
5280 else if (!matching_found
&& matching
5281 && !strnicmp (x_charset
, matching
, match_len
))
5283 best_match
= x_charset
;
5286 /* If this is fully specified, and the best so far isn't,
5287 then this is better. */
5288 else if ((!strchr (best_match
, '-') && strchr (x_charset
, '-'))
5289 /* If this is an ISO codepage, and the best so far isn't,
5290 then this is better, but only if it fully specifies the
5292 || (strnicmp (best_match
, "iso", 3) != 0
5293 && strnicmp (x_charset
, "iso", 3) == 0
5294 && strchr (x_charset
, '-')))
5295 best_match
= x_charset
;
5296 /* If both are ISO8859 codepages, choose the one with the
5297 lowest number in the encoding field. */
5298 else if (strnicmp (best_match
, "iso8859-", 8) == 0
5299 && strnicmp (x_charset
, "iso8859-", 8) == 0)
5301 int best_enc
= atoi (best_match
+ 8);
5302 int this_enc
= atoi (x_charset
+ 8);
5303 if (this_enc
> 0 && this_enc
< best_enc
)
5304 best_match
= x_charset
;
5309 /* If no match, encode the numeric value. */
5312 sprintf (buf
, "*-#%u", fncharset
);
5316 strncpy (buf
, best_match
, 31);
5317 /* If the charset is not fully specified, put -0 on the end. */
5318 if (!strchr (best_match
, '-'))
5320 int pos
= strlen (best_match
);
5321 /* Charset specifiers shouldn't be very long. If it is a made
5322 up one, truncating it should not do any harm since it isn't
5323 recognized anyway. */
5326 strcpy (buf
+ pos
, "-0");
5334 /* Return all the X charsets that map to a font. */
5336 w32_to_all_x_charsets (fncharset
)
5339 static char buf
[32];
5340 Lisp_Object charset_type
;
5341 Lisp_Object retval
= Qnil
;
5346 /* Handle startup case of w32-charset-info-alist not
5347 being set up yet. */
5348 if (NILP (Vw32_charset_info_alist
))
5349 return Fcons (build_string ("iso8859-1"), Qnil
);
5351 charset_type
= Qw32_charset_ansi
;
5353 case DEFAULT_CHARSET
:
5354 charset_type
= Qw32_charset_default
;
5356 case SYMBOL_CHARSET
:
5357 charset_type
= Qw32_charset_symbol
;
5359 case SHIFTJIS_CHARSET
:
5360 charset_type
= Qw32_charset_shiftjis
;
5362 case HANGEUL_CHARSET
:
5363 charset_type
= Qw32_charset_hangeul
;
5365 case GB2312_CHARSET
:
5366 charset_type
= Qw32_charset_gb2312
;
5368 case CHINESEBIG5_CHARSET
:
5369 charset_type
= Qw32_charset_chinesebig5
;
5372 charset_type
= Qw32_charset_oem
;
5375 /* More recent versions of Windows (95 and NT4.0) define more
5377 #ifdef EASTEUROPE_CHARSET
5378 case EASTEUROPE_CHARSET
:
5379 charset_type
= Qw32_charset_easteurope
;
5381 case TURKISH_CHARSET
:
5382 charset_type
= Qw32_charset_turkish
;
5384 case BALTIC_CHARSET
:
5385 charset_type
= Qw32_charset_baltic
;
5387 case RUSSIAN_CHARSET
:
5388 charset_type
= Qw32_charset_russian
;
5390 case ARABIC_CHARSET
:
5391 charset_type
= Qw32_charset_arabic
;
5394 charset_type
= Qw32_charset_greek
;
5396 case HEBREW_CHARSET
:
5397 charset_type
= Qw32_charset_hebrew
;
5399 case VIETNAMESE_CHARSET
:
5400 charset_type
= Qw32_charset_vietnamese
;
5403 charset_type
= Qw32_charset_thai
;
5406 charset_type
= Qw32_charset_mac
;
5409 charset_type
= Qw32_charset_johab
;
5413 #ifdef UNICODE_CHARSET
5414 case UNICODE_CHARSET
:
5415 charset_type
= Qw32_charset_unicode
;
5419 /* Encode numerical value of unknown charset. */
5420 sprintf (buf
, "*-#%u", fncharset
);
5421 return Fcons (build_string (buf
), Qnil
);
5426 /* Look through w32-charset-info-alist for the character set.
5427 Only return fully specified charsets for codepages which are
5430 Format of each entry in Vw32_charset_info_alist is
5431 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5433 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
5435 Lisp_Object x_charset
;
5436 Lisp_Object w32_charset
;
5437 Lisp_Object codepage
;
5439 Lisp_Object this_entry
= XCAR (rest
);
5441 /* Skip invalid entries in alist. */
5442 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
5443 || !CONSP (XCDR (this_entry
))
5444 || !SYMBOLP (XCAR (XCDR (this_entry
))))
5447 x_charset
= XCAR (this_entry
);
5448 w32_charset
= XCAR (XCDR (this_entry
));
5449 codepage
= XCDR (XCDR (this_entry
));
5451 if (!strchr (SDATA (x_charset
), '-'))
5454 /* Look for Same charset and a valid codepage (or non-int
5455 which means ignore). */
5456 if (EQ (w32_charset
, charset_type
)
5457 && (!INTEGERP (codepage
) || XINT (codepage
) == CP_DEFAULT
5458 || IsValidCodePage (XINT (codepage
))))
5460 retval
= Fcons (x_charset
, retval
);
5464 /* If no match, encode the numeric value. */
5467 sprintf (buf
, "*-#%u", fncharset
);
5468 return Fcons (build_string (buf
), Qnil
);
5475 /* Get the Windows codepage corresponding to the specified font. The
5476 charset info in the font name is used to look up
5477 w32-charset-to-codepage-alist. */
5479 w32_codepage_for_font (char *fontname
)
5481 Lisp_Object codepage
, entry
;
5482 char *charset_str
, *charset
, *end
;
5484 /* Extract charset part of font string. */
5485 charset
= xlfd_charset_of_font (fontname
);
5490 charset_str
= (char *) alloca (strlen (charset
) + 1);
5491 strcpy (charset_str
, charset
);
5494 /* Remove leading "*-". */
5495 if (strncmp ("*-", charset_str
, 2) == 0)
5496 charset
= charset_str
+ 2;
5499 charset
= charset_str
;
5501 /* Stop match at wildcard (including preceding '-'). */
5502 if (end
= strchr (charset
, '*'))
5504 if (end
> charset
&& *(end
-1) == '-')
5509 if (!strcmp (charset
, "iso10646"))
5512 if (NILP (Vw32_charset_info_alist
))
5515 entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
5519 codepage
= Fcdr (Fcdr (entry
));
5521 if (NILP (codepage
))
5523 else if (XFASTINT (codepage
) == XFASTINT (Qt
))
5525 else if (INTEGERP (codepage
))
5526 return XINT (codepage
);
5533 w32_to_x_font (lplogfont
, lpxstr
, len
, specific_charset
)
5534 LOGFONT
* lplogfont
;
5537 char * specific_charset
;
5541 char height_pixels
[8];
5543 char width_pixels
[8];
5544 char *fontname_dash
;
5545 int display_resy
= (int) one_w32_display_info
.resy
;
5546 int display_resx
= (int) one_w32_display_info
.resx
;
5547 struct coding_system coding
;
5549 if (!lpxstr
) abort ();
5554 if (lplogfont
->lfOutPrecision
== OUT_STRING_PRECIS
)
5555 fonttype
= "raster";
5556 else if (lplogfont
->lfOutPrecision
== OUT_STROKE_PRECIS
)
5557 fonttype
= "outline";
5559 fonttype
= "unknown";
5561 setup_coding_system (Fcheck_coding_system (Vlocale_coding_system
),
5563 coding
.src_multibyte
= 0;
5564 coding
.dst_multibyte
= 1;
5565 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
5566 /* We explicitely disable composition handling because selection
5567 data should not contain any composition sequence. */
5568 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
5570 coding
.dst_bytes
= LF_FACESIZE
* 2;
5571 coding
.destination
= (unsigned char *) xmalloc (coding
.dst_bytes
+ 1);
5572 decode_coding_c_string (&coding
, lplogfont
->lfFaceName
,
5573 strlen(lplogfont
->lfFaceName
), Qnil
);
5574 fontname
= coding
.destination
;
5576 *(fontname
+ coding
.produced
) = '\0';
5578 /* Replace dashes with underscores so the dashes are not
5580 fontname_dash
= fontname
;
5581 while (fontname_dash
= strchr (fontname_dash
, '-'))
5582 *fontname_dash
= '_';
5584 if (lplogfont
->lfHeight
)
5586 sprintf (height_pixels
, "%u", eabs (lplogfont
->lfHeight
));
5587 sprintf (height_dpi
, "%u",
5588 eabs (lplogfont
->lfHeight
) * 720 / display_resy
);
5592 strcpy (height_pixels
, "*");
5593 strcpy (height_dpi
, "*");
5596 #if 0 /* Never put the width in the xfld. It fails on fonts with
5597 double-width characters. */
5598 if (lplogfont
->lfWidth
)
5599 sprintf (width_pixels
, "%u", lplogfont
->lfWidth
* 10);
5602 strcpy (width_pixels
, "*");
5604 _snprintf (lpxstr
, len
- 1,
5605 "-%s-%s-%s-%c-normal-normal-%s-%s-%d-%d-%c-%s-%s",
5606 fonttype
, /* foundry */
5607 fontname
, /* family */
5608 w32_to_x_weight (lplogfont
->lfWeight
), /* weight */
5609 lplogfont
->lfItalic
?'i':'r', /* slant */
5611 /* add style name */
5612 height_pixels
, /* pixel size */
5613 height_dpi
, /* point size */
5614 display_resx
, /* resx */
5615 display_resy
, /* resy */
5616 ((lplogfont
->lfPitchAndFamily
& 0x3) == VARIABLE_PITCH
)
5617 ? 'p' : 'c', /* spacing */
5618 width_pixels
, /* avg width */
5619 w32_to_x_charset (lplogfont
->lfCharSet
, specific_charset
)
5620 /* charset registry and encoding */
5623 lpxstr
[len
- 1] = 0; /* just to be sure */
5628 x_to_w32_font (lpxstr
, lplogfont
)
5630 LOGFONT
* lplogfont
;
5632 struct coding_system coding
;
5634 if (!lplogfont
) return (FALSE
);
5636 memset (lplogfont
, 0, sizeof (*lplogfont
));
5638 /* Set default value for each field. */
5640 lplogfont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
5641 lplogfont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
5642 lplogfont
->lfQuality
= DEFAULT_QUALITY
;
5644 /* go for maximum quality */
5645 lplogfont
->lfOutPrecision
= OUT_STROKE_PRECIS
;
5646 lplogfont
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
5647 lplogfont
->lfQuality
= PROOF_QUALITY
;
5650 lplogfont
->lfCharSet
= DEFAULT_CHARSET
;
5651 lplogfont
->lfWeight
= FW_DONTCARE
;
5652 lplogfont
->lfPitchAndFamily
= DEFAULT_PITCH
| FF_DONTCARE
;
5657 /* Provide a simple escape mechanism for specifying Windows font names
5658 * directly -- if font spec does not beginning with '-', assume this
5660 * "<font name>[:height in pixels[:width in pixels[:weight]]]"
5666 char name
[50], weight
[20], slant
, pitch
, pixels
[10], height
[10],
5667 width
[10], resy
[10], remainder
[50];
5669 int dpi
= (int) one_w32_display_info
.resy
;
5671 fields
= sscanf (lpxstr
,
5672 "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%49s",
5673 name
, weight
, &slant
, pixels
, height
, resy
, &pitch
, width
, remainder
);
5677 /* In the general case when wildcards cover more than one field,
5678 we don't know which field is which, so don't fill any in.
5679 However, we need to cope with this particular form, which is
5680 generated by font_list_1 (invoked by try_font_list):
5681 "-raster-6x10-*-gb2312*-*"
5682 and make sure to correctly parse the charset field. */
5685 fields
= sscanf (lpxstr
,
5686 "-%*[^-]-%49[^-]-*-%49s",
5689 else if (fields
< 9)
5695 if (fields
> 0 && name
[0] != '*')
5697 Lisp_Object string
= build_string (name
);
5699 (Fcheck_coding_system (Vlocale_coding_system
), &coding
);
5700 coding
.mode
|= (CODING_MODE_SAFE_ENCODING
| CODING_MODE_LAST_BLOCK
);
5701 /* Disable composition/charset annotation. */
5702 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
5703 coding
.dst_bytes
= SCHARS (string
) * 2;
5705 coding
.destination
= (unsigned char *) xmalloc (coding
.dst_bytes
);
5706 encode_coding_object (&coding
, string
, 0, 0,
5707 SCHARS (string
), SBYTES (string
), Qnil
);
5708 if (coding
.produced
>= LF_FACESIZE
)
5709 coding
.produced
= LF_FACESIZE
- 1;
5711 coding
.destination
[coding
.produced
] = '\0';
5713 strcpy (lplogfont
->lfFaceName
, coding
.destination
);
5714 xfree (coding
.destination
);
5718 lplogfont
->lfFaceName
[0] = '\0';
5723 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
5727 lplogfont
->lfItalic
= (fields
> 0 && slant
== 'i');
5731 if (fields
> 0 && pixels
[0] != '*')
5732 lplogfont
->lfHeight
= atoi (pixels
);
5736 if (fields
> 0 && resy
[0] != '*')
5739 if (tem
> 0) dpi
= tem
;
5742 if (fields
> -1 && lplogfont
->lfHeight
== 0 && height
[0] != '*')
5743 lplogfont
->lfHeight
= atoi (height
) * dpi
/ 720;
5748 lplogfont
->lfPitchAndFamily
= VARIABLE_PITCH
| FF_DONTCARE
;
5749 else if (pitch
== 'c')
5750 lplogfont
->lfPitchAndFamily
= FIXED_PITCH
| FF_DONTCARE
;
5755 if (fields
> 0 && width
[0] != '*')
5756 lplogfont
->lfWidth
= atoi (width
) / 10;
5760 /* Strip the trailing '-' if present. (it shouldn't be, as it
5761 fails the test against xlfd-tight-regexp in fontset.el). */
5763 int len
= strlen (remainder
);
5764 if (len
> 0 && remainder
[len
-1] == '-')
5765 remainder
[len
-1] = 0;
5767 encoding
= remainder
;
5769 if (strncmp (encoding
, "*-", 2) == 0)
5772 lplogfont
->lfCharSet
= x_to_w32_charset (encoding
);
5777 char name
[100], height
[10], width
[10], weight
[20];
5779 fields
= sscanf (lpxstr
,
5780 "%99[^:]:%9[^:]:%9[^:]:%19s",
5781 name
, height
, width
, weight
);
5783 if (fields
== EOF
) return (FALSE
);
5787 strncpy (lplogfont
->lfFaceName
, name
, LF_FACESIZE
);
5788 lplogfont
->lfFaceName
[LF_FACESIZE
-1] = 0;
5792 lplogfont
->lfFaceName
[0] = 0;
5798 lplogfont
->lfHeight
= atoi (height
);
5803 lplogfont
->lfWidth
= atoi (width
);
5807 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
5810 /* This makes TrueType fonts work better. */
5811 lplogfont
->lfHeight
= - eabs (lplogfont
->lfHeight
);
5816 /* Strip the pixel height and point height from the given xlfd, and
5817 return the pixel height. If no pixel height is specified, calculate
5818 one from the point height, or if that isn't defined either, return
5819 0 (which usually signifies a scalable font).
5822 xlfd_strip_height (char *fontname
)
5824 int pixel_height
, field_number
;
5825 char *read_from
, *write_to
;
5829 pixel_height
= field_number
= 0;
5832 /* Look for height fields. */
5833 for (read_from
= fontname
; *read_from
; read_from
++)
5835 if (*read_from
== '-')
5838 if (field_number
== 7) /* Pixel height. */
5841 write_to
= read_from
;
5843 /* Find end of field. */
5844 for (;*read_from
&& *read_from
!= '-'; read_from
++)
5847 /* Split the fontname at end of field. */
5853 pixel_height
= atoi (write_to
);
5854 /* Blank out field. */
5855 if (read_from
> write_to
)
5860 /* If the pixel height field is at the end (partial xlfd),
5863 return pixel_height
;
5865 /* If we got a pixel height, the point height can be
5866 ignored. Just blank it out and break now. */
5869 /* Find end of point size field. */
5870 for (; *read_from
&& *read_from
!= '-'; read_from
++)
5876 /* Blank out the point size field. */
5877 if (read_from
> write_to
)
5883 return pixel_height
;
5887 /* If the point height is already blank, break now. */
5888 if (*read_from
== '-')
5894 else if (field_number
== 8)
5896 /* If we didn't get a pixel height, try to get the point
5897 height and convert that. */
5899 char *point_size_start
= read_from
++;
5901 /* Find end of field. */
5902 for (; *read_from
&& *read_from
!= '-'; read_from
++)
5911 point_size
= atoi (point_size_start
);
5913 /* Convert to pixel height. */
5914 pixel_height
= point_size
5915 * one_w32_display_info
.height_in
/ 720;
5917 /* Blank out this field and break. */
5925 /* Shift the rest of the font spec into place. */
5926 if (write_to
&& read_from
> write_to
)
5928 for (; *read_from
; read_from
++, write_to
++)
5929 *write_to
= *read_from
;
5933 return pixel_height
;
5936 /* Assume parameter 1 is fully qualified, no wildcards. */
5938 w32_font_match (fontname
, pattern
)
5943 char *font_name_copy
;
5944 char *regex
= alloca (strlen (pattern
) * 2 + 3);
5946 font_name_copy
= alloca (strlen (fontname
) + 1);
5947 strcpy (font_name_copy
, fontname
);
5952 /* Turn pattern into a regexp and do a regexp match. */
5953 for (; *pattern
; pattern
++)
5955 if (*pattern
== '?')
5957 else if (*pattern
== '*')
5968 /* Strip out font heights and compare them seperately, since
5969 rounding error can cause mismatches. This also allows a
5970 comparison between a font that declares only a pixel height and a
5971 pattern that declares the point height.
5974 int font_height
, pattern_height
;
5976 font_height
= xlfd_strip_height (font_name_copy
);
5977 pattern_height
= xlfd_strip_height (regex
);
5979 /* Compare now, and don't bother doing expensive regexp matching
5980 if the heights differ. */
5981 if (font_height
&& pattern_height
&& (font_height
!= pattern_height
))
5985 return (fast_string_match_ignore_case (build_string (regex
),
5986 build_string (font_name_copy
)) >= 0);
5989 /* Callback functions, and a structure holding info they need, for
5990 listing system fonts on W32. We need one set of functions to do the
5991 job properly, but these don't work on NT 3.51 and earlier, so we
5992 have a second set which don't handle character sets properly to
5995 In both cases, there are two passes made. The first pass gets one
5996 font from each family, the second pass lists all the fonts from
5999 typedef struct enumfont_t
6004 XFontStruct
*size_ref
;
6005 Lisp_Object pattern
;
6011 enum_font_maybe_add_to_list (enumfont_t
*, LOGFONT
*, char *, Lisp_Object
);
6015 enum_font_cb2 (lplf
, lptm
, FontType
, lpef
)
6017 NEWTEXTMETRIC
* lptm
;
6021 /* Ignore struck out and underlined versions of fonts. */
6022 if (lplf
->elfLogFont
.lfStrikeOut
|| lplf
->elfLogFont
.lfUnderline
)
6025 /* Only return fonts with names starting with @ if they were
6026 explicitly specified, since Microsoft uses an initial @ to
6027 denote fonts for vertical writing, without providing a more
6028 convenient way of identifying them. */
6029 if (lplf
->elfLogFont
.lfFaceName
[0] == '@'
6030 && lpef
->logfont
.lfFaceName
[0] != '@')
6033 /* Check that the character set matches if it was specified */
6034 if (lpef
->logfont
.lfCharSet
!= DEFAULT_CHARSET
&&
6035 lplf
->elfLogFont
.lfCharSet
!= lpef
->logfont
.lfCharSet
)
6038 if (FontType
== RASTER_FONTTYPE
)
6040 /* DBCS raster fonts have problems displaying, so skip them. */
6041 int charset
= lplf
->elfLogFont
.lfCharSet
;
6042 if (charset
== SHIFTJIS_CHARSET
6043 || charset
== HANGEUL_CHARSET
6044 || charset
== CHINESEBIG5_CHARSET
6045 || charset
== GB2312_CHARSET
6046 #ifdef JOHAB_CHARSET
6047 || charset
== JOHAB_CHARSET
6055 Lisp_Object width
= Qnil
;
6056 Lisp_Object charset_list
= Qnil
;
6057 char *charset
= NULL
;
6059 /* Truetype fonts do not report their true metrics until loaded */
6060 if (FontType
!= RASTER_FONTTYPE
)
6062 if (!NILP (lpef
->pattern
))
6064 /* Scalable fonts are as big as you want them to be. */
6065 lplf
->elfLogFont
.lfHeight
= lpef
->logfont
.lfHeight
;
6066 lplf
->elfLogFont
.lfWidth
= lpef
->logfont
.lfWidth
;
6067 width
= make_number (lpef
->logfont
.lfWidth
);
6071 lplf
->elfLogFont
.lfHeight
= 0;
6072 lplf
->elfLogFont
.lfWidth
= 0;
6076 /* Make sure the height used here is the same as everywhere
6077 else (ie character height, not cell height). */
6078 if (lplf
->elfLogFont
.lfHeight
> 0)
6080 /* lptm can be trusted for RASTER fonts, but not scalable ones. */
6081 if (FontType
== RASTER_FONTTYPE
)
6082 lplf
->elfLogFont
.lfHeight
= lptm
->tmInternalLeading
- lptm
->tmHeight
;
6084 lplf
->elfLogFont
.lfHeight
= -lplf
->elfLogFont
.lfHeight
;
6087 if (!NILP (lpef
->pattern
))
6089 charset
= xlfd_charset_of_font (SDATA (lpef
->pattern
));
6091 /* We already checked charsets above, but DEFAULT_CHARSET
6092 slipped through. So only allow exact matches for DEFAULT_CHARSET. */
6094 && strncmp (charset
, "*-*", 3) != 0
6095 && lpef
->logfont
.lfCharSet
== DEFAULT_CHARSET
6096 && strcmp (charset
, w32_to_x_charset (DEFAULT_CHARSET
, NULL
)) != 0)
6099 /* Reject raster fonts if we are looking for a unicode font. */
6101 && FontType
== RASTER_FONTTYPE
6102 && strncmp (charset
, "iso10646", 8) == 0)
6107 charset_list
= Fcons (build_string (charset
), Qnil
);
6109 /* Always prefer unicode. */
6111 = Fcons (build_string ("iso10646-1"),
6112 w32_to_all_x_charsets (lplf
->elfLogFont
.lfCharSet
));
6114 /* Loop through the charsets. */
6115 for ( ; CONSP (charset_list
); charset_list
= Fcdr (charset_list
))
6117 Lisp_Object this_charset
= Fcar (charset_list
);
6118 charset
= SDATA (this_charset
);
6120 /* Don't list raster fonts as unicode. */
6122 && FontType
== RASTER_FONTTYPE
6123 && strncmp (charset
, "iso10646", 8) == 0)
6126 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
6129 /* List bold and italic variations if w32-enable-synthesized-fonts
6130 is non-nil and this is a plain font. */
6131 if (w32_enable_synthesized_fonts
6132 && lplf
->elfLogFont
.lfWeight
== FW_NORMAL
6133 && lplf
->elfLogFont
.lfItalic
== FALSE
)
6136 lplf
->elfLogFont
.lfWeight
= FW_BOLD
;
6137 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
6140 lplf
->elfLogFont
.lfItalic
= TRUE
;
6141 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
6144 lplf
->elfLogFont
.lfWeight
= FW_NORMAL
;
6145 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
6155 enum_font_maybe_add_to_list (lpef
, logfont
, match_charset
, width
)
6158 char * match_charset
;
6163 if (!w32_to_x_font (logfont
, buf
, 100, match_charset
))
6166 if (NILP (lpef
->pattern
)
6167 || w32_font_match (buf
, SDATA (lpef
->pattern
)))
6169 /* Check if we already listed this font. This may happen if
6170 w32_enable_synthesized_fonts is non-nil, and there are real
6171 bold and italic versions of the font. */
6172 Lisp_Object font_name
= build_string (buf
);
6173 if (NILP (Fmember (font_name
, lpef
->list
)))
6175 Lisp_Object entry
= Fcons (font_name
, width
);
6176 lpef
->list
= Fcons (entry
, lpef
->list
);
6184 enum_font_cb1 (lplf
, lptm
, FontType
, lpef
)
6186 NEWTEXTMETRIC
* lptm
;
6190 return EnumFontFamilies (lpef
->hdc
,
6191 lplf
->elfLogFont
.lfFaceName
,
6192 (FONTENUMPROC
) enum_font_cb2
,
6198 enum_fontex_cb2 (lplf
, lptm
, font_type
, lpef
)
6199 ENUMLOGFONTEX
* lplf
;
6200 NEWTEXTMETRICEX
* lptm
;
6204 /* We are not interested in the extra info we get back from the 'Ex
6205 version - only the fact that we get character set variations
6206 enumerated seperately. */
6207 return enum_font_cb2 ((ENUMLOGFONT
*) lplf
, (NEWTEXTMETRIC
*) lptm
,
6212 enum_fontex_cb1 (lplf
, lptm
, font_type
, lpef
)
6213 ENUMLOGFONTEX
* lplf
;
6214 NEWTEXTMETRICEX
* lptm
;
6218 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6219 FARPROC enum_font_families_ex
6220 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6221 /* We don't really expect EnumFontFamiliesEx to disappear once we
6222 get here, so don't bother handling it gracefully. */
6223 if (enum_font_families_ex
== NULL
)
6224 error ("gdi32.dll has disappeared!");
6225 return enum_font_families_ex (lpef
->hdc
,
6227 (FONTENUMPROC
) enum_fontex_cb2
,
6231 /* Interface to fontset handler. (adapted from mw32font.c in Meadow
6232 and xterm.c in Emacs 20.3) */
6235 w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
)
6237 char *fontname
, *ptnstr
;
6238 Lisp_Object list
, tem
, newlist
= Qnil
;
6241 list
= Vw32_bdf_filename_alist
;
6242 ptnstr
= SDATA (pattern
);
6244 for ( ; CONSP (list
); list
= XCDR (list
))
6248 fontname
= SDATA (XCAR (tem
));
6249 else if (STRINGP (tem
))
6250 fontname
= SDATA (tem
);
6254 if (w32_font_match (fontname
, ptnstr
))
6256 newlist
= Fcons (XCAR (tem
), newlist
);
6258 if (max_names
>= 0 && n_fonts
>= max_names
)
6267 /* Return a list of names of available fonts matching PATTERN on frame
6268 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
6269 to be listed. Frame F NULL means we have not yet created any
6270 frame, which means we can't get proper size info, as we don't have
6271 a device context to use for GetTextMetrics.
6272 MAXNAMES sets a limit on how many fonts to match. If MAXNAMES is
6273 negative, then all matching fonts are returned. */
6276 w32_list_fonts (f
, pattern
, size
, maxnames
)
6278 Lisp_Object pattern
;
6282 Lisp_Object patterns
, key
= Qnil
, tem
, tpat
;
6283 Lisp_Object list
= Qnil
, newlist
= Qnil
, second_best
= Qnil
;
6284 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
6287 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
6288 if (NILP (patterns
))
6289 patterns
= Fcons (pattern
, Qnil
);
6291 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
6296 tpat
= XCAR (patterns
);
6298 if (!STRINGP (tpat
))
6301 /* Avoid expensive EnumFontFamilies functions if we are not
6302 going to be able to output one of these anyway. */
6303 codepage
= w32_codepage_for_font (SDATA (tpat
));
6304 if (codepage
!= CP_8BIT
&& codepage
!= CP_UNICODE
6305 && codepage
!= CP_DEFAULT
&& codepage
!= CP_UNKNOWN
6306 && !IsValidCodePage (codepage
))
6309 /* See if we cached the result for this particular query.
6310 The cache is an alist of the form:
6311 ((PATTERN (FONTNAME . WIDTH) ...) ...)
6313 if (tem
= XCDR (dpyinfo
->name_list_element
),
6314 !NILP (list
= Fassoc (tpat
, tem
)))
6316 list
= Fcdr_safe (list
);
6317 /* We have a cached list. Don't have to get the list again. */
6322 /* At first, put PATTERN in the cache. */
6327 /* Use EnumFontFamiliesEx where it is available, as it knows
6328 about character sets. Fall back to EnumFontFamilies for
6329 older versions of NT that don't support the 'Ex function. */
6330 x_to_w32_font (SDATA (tpat
), &ef
.logfont
);
6332 LOGFONT font_match_pattern
;
6333 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6334 FARPROC enum_font_families_ex
6335 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6337 /* We do our own pattern matching so we can handle wildcards. */
6338 font_match_pattern
.lfFaceName
[0] = 0;
6339 font_match_pattern
.lfPitchAndFamily
= 0;
6340 /* We can use the charset, because if it is a wildcard it will
6341 be DEFAULT_CHARSET anyway. */
6342 font_match_pattern
.lfCharSet
= ef
.logfont
.lfCharSet
;
6344 ef
.hdc
= GetDC (dpyinfo
->root_window
);
6346 if (enum_font_families_ex
)
6347 enum_font_families_ex (ef
.hdc
,
6348 &font_match_pattern
,
6349 (FONTENUMPROC
) enum_fontex_cb1
,
6352 EnumFontFamilies (ef
.hdc
, NULL
, (FONTENUMPROC
) enum_font_cb1
,
6355 ReleaseDC (dpyinfo
->root_window
, ef
.hdc
);
6361 /* Make a list of the fonts we got back.
6362 Store that in the font cache for the display. */
6363 XSETCDR (dpyinfo
->name_list_element
,
6364 Fcons (Fcons (tpat
, list
),
6365 XCDR (dpyinfo
->name_list_element
)));
6368 if (NILP (list
)) continue; /* Try the remaining alternatives. */
6370 newlist
= second_best
= Qnil
;
6372 /* Make a list of the fonts that have the right width. */
6373 for (; CONSP (list
); list
= XCDR (list
))
6380 if (NILP (XCAR (tem
)))
6384 newlist
= Fcons (XCAR (tem
), newlist
);
6386 if (maxnames
>= 0 && n_fonts
>= maxnames
)
6391 if (!INTEGERP (XCDR (tem
)))
6393 /* Since we don't yet know the size of the font, we must
6394 load it and try GetTextMetrics. */
6395 W32FontStruct thisinfo
;
6400 if (!x_to_w32_font (SDATA (XCAR (tem
)), &lf
))
6404 thisinfo
.bdf
= NULL
;
6405 thisinfo
.hfont
= CreateFontIndirect (&lf
);
6406 if (thisinfo
.hfont
== NULL
)
6409 hdc
= GetDC (dpyinfo
->root_window
);
6410 oldobj
= SelectObject (hdc
, thisinfo
.hfont
);
6411 if (GetTextMetrics (hdc
, &thisinfo
.tm
))
6412 XSETCDR (tem
, make_number (FONT_AVG_WIDTH (&thisinfo
)));
6414 XSETCDR (tem
, make_number (0));
6415 SelectObject (hdc
, oldobj
);
6416 ReleaseDC (dpyinfo
->root_window
, hdc
);
6417 DeleteObject (thisinfo
.hfont
);
6420 found_size
= XINT (XCDR (tem
));
6421 if (found_size
== size
)
6423 newlist
= Fcons (XCAR (tem
), newlist
);
6425 if (maxnames
>= 0 && n_fonts
>= maxnames
)
6428 /* keep track of the closest matching size in case
6429 no exact match is found. */
6430 else if (found_size
> 0)
6432 if (NILP (second_best
))
6435 else if (found_size
< size
)
6437 if (XINT (XCDR (second_best
)) > size
6438 || XINT (XCDR (second_best
)) < found_size
)
6443 if (XINT (XCDR (second_best
)) > size
6444 && XINT (XCDR (second_best
)) >
6451 if (!NILP (newlist
))
6453 else if (!NILP (second_best
))
6455 newlist
= Fcons (XCAR (second_best
), Qnil
);
6460 /* Include any bdf fonts. */
6461 if (n_fonts
< maxnames
|| maxnames
< 0)
6463 Lisp_Object combined
[2];
6464 combined
[0] = w32_list_bdf_fonts (pattern
, maxnames
- n_fonts
);
6465 combined
[1] = newlist
;
6466 newlist
= Fnconc (2, combined
);
6473 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
6475 w32_get_font_info (f
, font_idx
)
6479 return (FRAME_W32_FONT_TABLE (f
) + font_idx
);
6484 w32_query_font (struct frame
*f
, char *fontname
)
6487 struct font_info
*pfi
;
6489 pfi
= FRAME_W32_FONT_TABLE (f
);
6491 for (i
= 0; i
< one_w32_display_info
.n_fonts
;i
++, pfi
++)
6493 if (stricmp (pfi
->name
, fontname
) == 0) return pfi
;
6499 /* Find a CCL program for a font specified by FONTP, and set the member
6500 `encoder' of the structure. */
6503 w32_find_ccl_program (fontp
)
6504 struct font_info
*fontp
;
6506 Lisp_Object list
, elt
;
6508 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
6512 && STRINGP (XCAR (elt
))
6513 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
6519 struct ccl_program
*ccl
6520 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
6522 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
6525 fontp
->font_encoder
= ccl
;
6529 /* directory-files from dired.c. */
6530 Lisp_Object Fdirectory_files
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
, Lisp_Object
));
6533 /* Find BDF files in a specified directory. (use GCPRO when calling,
6534 as this calls lisp to get a directory listing). */
6536 w32_find_bdf_fonts_in_dir (Lisp_Object directory
)
6538 Lisp_Object filelist
, list
= Qnil
;
6541 if (!STRINGP (directory
))
6544 filelist
= Fdirectory_files (directory
, Qt
,
6545 build_string (".*\\.[bB][dD][fF]"), Qt
);
6547 for ( ; CONSP (filelist
); filelist
= XCDR (filelist
))
6549 Lisp_Object filename
= XCAR (filelist
);
6550 if (w32_BDF_to_x_font (SDATA (filename
), fontname
, 100))
6551 store_in_alist (&list
, build_string (fontname
), filename
);
6556 DEFUN ("w32-find-bdf-fonts", Fw32_find_bdf_fonts
, Sw32_find_bdf_fonts
,
6558 doc
: /* Return a list of BDF fonts in DIRECTORY.
6559 The list is suitable for appending to `w32-bdf-filename-alist'.
6560 Fonts which do not contain an xlfd description will not be included
6561 in the list. DIRECTORY may be a list of directories. */)
6563 Lisp_Object directory
;
6565 Lisp_Object list
= Qnil
;
6566 struct gcpro gcpro1
, gcpro2
;
6568 if (!CONSP (directory
))
6569 return w32_find_bdf_fonts_in_dir (directory
);
6571 for ( ; CONSP (directory
); directory
= XCDR (directory
))
6573 Lisp_Object pair
[2];
6576 GCPRO2 (directory
, list
);
6577 pair
[1] = w32_find_bdf_fonts_in_dir ( XCAR (directory
) );
6578 list
= Fnconc ( 2, pair
);
6585 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
6586 doc
: /* Internal function called by `color-defined-p', which see. */)
6588 Lisp_Object color
, frame
;
6591 FRAME_PTR f
= check_x_frame (frame
);
6593 CHECK_STRING (color
);
6595 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
6601 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
6602 doc
: /* Internal function called by `color-values', which see. */)
6604 Lisp_Object color
, frame
;
6607 FRAME_PTR f
= check_x_frame (frame
);
6609 CHECK_STRING (color
);
6611 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
6612 return list3 (make_number ((GetRValue (foo
.pixel
) << 8)
6613 | GetRValue (foo
.pixel
)),
6614 make_number ((GetGValue (foo
.pixel
) << 8)
6615 | GetGValue (foo
.pixel
)),
6616 make_number ((GetBValue (foo
.pixel
) << 8)
6617 | GetBValue (foo
.pixel
)));
6622 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
6623 doc
: /* Internal function called by `display-color-p', which see. */)
6625 Lisp_Object display
;
6627 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6629 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
6635 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
,
6636 Sx_display_grayscale_p
, 0, 1, 0,
6637 doc
: /* Return t if DISPLAY supports shades of gray.
6638 Note that color displays do support shades of gray.
6639 The optional argument DISPLAY specifies which display to ask about.
6640 DISPLAY should be either a frame or a display name (a string).
6641 If omitted or nil, that stands for the selected frame's display. */)
6643 Lisp_Object display
;
6645 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6647 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
6653 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
,
6654 Sx_display_pixel_width
, 0, 1, 0,
6655 doc
: /* Return the width in pixels of DISPLAY.
6656 The optional argument DISPLAY specifies which display to ask about.
6657 DISPLAY should be either a frame or a display name (a string).
6658 If omitted or nil, that stands for the selected frame's display. */)
6660 Lisp_Object display
;
6662 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6664 return make_number (dpyinfo
->width
);
6667 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
6668 Sx_display_pixel_height
, 0, 1, 0,
6669 doc
: /* Return the height in pixels of DISPLAY.
6670 The optional argument DISPLAY specifies which display to ask about.
6671 DISPLAY should be either a frame or a display name (a string).
6672 If omitted or nil, that stands for the selected frame's display. */)
6674 Lisp_Object display
;
6676 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6678 return make_number (dpyinfo
->height
);
6681 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
6683 doc
: /* Return the number of bitplanes of DISPLAY.
6684 The optional argument DISPLAY specifies which display to ask about.
6685 DISPLAY should be either a frame or a display name (a string).
6686 If omitted or nil, that stands for the selected frame's display. */)
6688 Lisp_Object display
;
6690 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6692 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
6695 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
6697 doc
: /* Return the number of color cells of DISPLAY.
6698 The optional argument DISPLAY specifies which display to ask about.
6699 DISPLAY should be either a frame or a display name (a string).
6700 If omitted or nil, that stands for the selected frame's display. */)
6702 Lisp_Object display
;
6704 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6708 hdc
= GetDC (dpyinfo
->root_window
);
6709 if (dpyinfo
->has_palette
)
6710 cap
= GetDeviceCaps (hdc
, SIZEPALETTE
);
6712 cap
= GetDeviceCaps (hdc
, NUMCOLORS
);
6714 /* We force 24+ bit depths to 24-bit, both to prevent an overflow
6715 and because probably is more meaningful on Windows anyway */
6717 cap
= 1 << min (dpyinfo
->n_planes
* dpyinfo
->n_cbits
, 24);
6719 ReleaseDC (dpyinfo
->root_window
, hdc
);
6721 return make_number (cap
);
6724 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
6725 Sx_server_max_request_size
,
6727 doc
: /* Return the maximum request size of the server of DISPLAY.
6728 The optional argument DISPLAY specifies which display to ask about.
6729 DISPLAY should be either a frame or a display name (a string).
6730 If omitted or nil, that stands for the selected frame's display. */)
6732 Lisp_Object display
;
6734 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6736 return make_number (1);
6739 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
6740 doc
: /* Return the "vendor ID" string of the W32 system (Microsoft).
6741 The optional argument DISPLAY specifies which display to ask about.
6742 DISPLAY should be either a frame or a display name (a string).
6743 If omitted or nil, that stands for the selected frame's display. */)
6745 Lisp_Object display
;
6747 return build_string ("Microsoft Corp.");
6750 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
6751 doc
: /* Return the version numbers of the server of DISPLAY.
6752 The value is a list of three integers: the major and minor
6753 version numbers of the X Protocol in use, and the distributor-specific
6754 release number. See also the function `x-server-vendor'.
6756 The optional argument DISPLAY specifies which display to ask about.
6757 DISPLAY should be either a frame or a display name (a string).
6758 If omitted or nil, that stands for the selected frame's display. */)
6760 Lisp_Object display
;
6762 return Fcons (make_number (w32_major_version
),
6763 Fcons (make_number (w32_minor_version
),
6764 Fcons (make_number (w32_build_number
), Qnil
)));
6767 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
6768 doc
: /* Return the number of screens on the server of DISPLAY.
6769 The optional argument DISPLAY specifies which display to ask about.
6770 DISPLAY should be either a frame or a display name (a string).
6771 If omitted or nil, that stands for the selected frame's display. */)
6773 Lisp_Object display
;
6775 return make_number (1);
6778 DEFUN ("x-display-mm-height", Fx_display_mm_height
,
6779 Sx_display_mm_height
, 0, 1, 0,
6780 doc
: /* Return the height in millimeters of DISPLAY.
6781 The optional argument DISPLAY specifies which display to ask about.
6782 DISPLAY should be either a frame or a display name (a string).
6783 If omitted or nil, that stands for the selected frame's display. */)
6785 Lisp_Object display
;
6787 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6791 hdc
= GetDC (dpyinfo
->root_window
);
6793 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
6795 ReleaseDC (dpyinfo
->root_window
, hdc
);
6797 return make_number (cap
);
6800 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
6801 doc
: /* Return the width in millimeters of DISPLAY.
6802 The optional argument DISPLAY specifies which display to ask about.
6803 DISPLAY should be either a frame or a display name (a string).
6804 If omitted or nil, that stands for the selected frame's display. */)
6806 Lisp_Object display
;
6808 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6813 hdc
= GetDC (dpyinfo
->root_window
);
6815 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
6817 ReleaseDC (dpyinfo
->root_window
, hdc
);
6819 return make_number (cap
);
6822 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
6823 Sx_display_backing_store
, 0, 1, 0,
6824 doc
: /* Return an indication of whether DISPLAY does backing store.
6825 The value may be `always', `when-mapped', or `not-useful'.
6826 The optional argument DISPLAY specifies which display to ask about.
6827 DISPLAY should be either a frame or a display name (a string).
6828 If omitted or nil, that stands for the selected frame's display. */)
6830 Lisp_Object display
;
6832 return intern ("not-useful");
6835 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
6836 Sx_display_visual_class
, 0, 1, 0,
6837 doc
: /* Return the visual class of DISPLAY.
6838 The value is one of the symbols `static-gray', `gray-scale',
6839 `static-color', `pseudo-color', `true-color', or `direct-color'.
6841 The optional argument DISPLAY specifies which display to ask about.
6842 DISPLAY should be either a frame or a display name (a string).
6843 If omitted or nil, that stands for the selected frame's display. */)
6845 Lisp_Object display
;
6847 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6848 Lisp_Object result
= Qnil
;
6850 if (dpyinfo
->has_palette
)
6851 result
= intern ("pseudo-color");
6852 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
6853 result
= intern ("static-grey");
6854 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
6855 result
= intern ("static-color");
6856 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
6857 result
= intern ("true-color");
6862 DEFUN ("x-display-save-under", Fx_display_save_under
,
6863 Sx_display_save_under
, 0, 1, 0,
6864 doc
: /* Return t if DISPLAY supports the save-under feature.
6865 The optional argument DISPLAY specifies which display to ask about.
6866 DISPLAY should be either a frame or a display name (a string).
6867 If omitted or nil, that stands for the selected frame's display. */)
6869 Lisp_Object display
;
6876 register struct frame
*f
;
6878 return FRAME_PIXEL_WIDTH (f
);
6883 register struct frame
*f
;
6885 return FRAME_PIXEL_HEIGHT (f
);
6890 register struct frame
*f
;
6892 return FRAME_COLUMN_WIDTH (f
);
6897 register struct frame
*f
;
6899 return FRAME_LINE_HEIGHT (f
);
6904 register struct frame
*f
;
6906 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
6909 /* Return the display structure for the display named NAME.
6910 Open a new connection if necessary. */
6912 struct w32_display_info
*
6913 x_display_info_for_name (name
)
6917 struct w32_display_info
*dpyinfo
;
6919 CHECK_STRING (name
);
6921 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
6923 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
6926 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
6931 /* Use this general default value to start with. */
6932 Vx_resource_name
= Vinvocation_name
;
6934 validate_x_resource_name ();
6936 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
6937 (char *) SDATA (Vx_resource_name
));
6940 error ("Cannot connect to server %s", SDATA (name
));
6943 XSETFASTINT (Vwindow_system_version
, 3);
6948 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
6949 1, 3, 0, doc
: /* Open a connection to a server.
6950 DISPLAY is the name of the display to connect to.
6951 Optional second arg XRM-STRING is a string of resources in xrdb format.
6952 If the optional third arg MUST-SUCCEED is non-nil,
6953 terminate Emacs if we can't open the connection. */)
6954 (display
, xrm_string
, must_succeed
)
6955 Lisp_Object display
, xrm_string
, must_succeed
;
6957 unsigned char *xrm_option
;
6958 struct w32_display_info
*dpyinfo
;
6960 /* If initialization has already been done, return now to avoid
6961 overwriting critical parts of one_w32_display_info. */
6965 CHECK_STRING (display
);
6966 if (! NILP (xrm_string
))
6967 CHECK_STRING (xrm_string
);
6970 if (! EQ (Vwindow_system
, intern ("w32")))
6971 error ("Not using Microsoft Windows");
6974 /* Allow color mapping to be defined externally; first look in user's
6975 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
6977 Lisp_Object color_file
;
6978 struct gcpro gcpro1
;
6980 color_file
= build_string ("~/rgb.txt");
6982 GCPRO1 (color_file
);
6984 if (NILP (Ffile_readable_p (color_file
)))
6986 Fexpand_file_name (build_string ("rgb.txt"),
6987 Fsymbol_value (intern ("data-directory")));
6989 Vw32_color_map
= Fw32_load_color_file (color_file
);
6993 if (NILP (Vw32_color_map
))
6994 Vw32_color_map
= Fw32_default_color_map ();
6996 /* Merge in system logical colors. */
6997 add_system_logical_colors_to_map (&Vw32_color_map
);
6999 if (! NILP (xrm_string
))
7000 xrm_option
= (unsigned char *) SDATA (xrm_string
);
7002 xrm_option
= (unsigned char *) 0;
7004 /* Use this general default value to start with. */
7005 /* First remove .exe suffix from invocation-name - it looks ugly. */
7007 char basename
[ MAX_PATH
], *str
;
7009 strcpy (basename
, SDATA (Vinvocation_name
));
7010 str
= strrchr (basename
, '.');
7012 Vinvocation_name
= build_string (basename
);
7014 Vx_resource_name
= Vinvocation_name
;
7016 validate_x_resource_name ();
7018 /* This is what opens the connection and sets x_current_display.
7019 This also initializes many symbols, such as those used for input. */
7020 dpyinfo
= w32_term_init (display
, xrm_option
,
7021 (char *) SDATA (Vx_resource_name
));
7025 if (!NILP (must_succeed
))
7026 fatal ("Cannot connect to server %s.\n",
7029 error ("Cannot connect to server %s", SDATA (display
));
7034 XSETFASTINT (Vwindow_system_version
, 3);
7038 DEFUN ("x-close-connection", Fx_close_connection
,
7039 Sx_close_connection
, 1, 1, 0,
7040 doc
: /* Close the connection to DISPLAY's server.
7041 For DISPLAY, specify either a frame or a display name (a string).
7042 If DISPLAY is nil, that stands for the selected frame's display. */)
7044 Lisp_Object display
;
7046 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7049 if (dpyinfo
->reference_count
> 0)
7050 error ("Display still has frames on it");
7053 /* Free the fonts in the font table. */
7054 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
7055 if (dpyinfo
->font_table
[i
].name
)
7057 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
7058 xfree (dpyinfo
->font_table
[i
].full_name
);
7059 xfree (dpyinfo
->font_table
[i
].name
);
7060 w32_unload_font (dpyinfo
, dpyinfo
->font_table
[i
].font
);
7062 x_destroy_all_bitmaps (dpyinfo
);
7064 x_delete_display (dpyinfo
);
7070 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
7071 doc
: /* Return the list of display names that Emacs has connections to. */)
7074 Lisp_Object tail
, result
;
7077 for (tail
= w32_display_name_list
; CONSP (tail
); tail
= XCDR (tail
))
7078 result
= Fcons (XCAR (XCAR (tail
)), result
);
7083 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
7084 doc
: /* This is a noop on W32 systems. */)
7086 Lisp_Object display
, on
;
7093 /***********************************************************************
7095 ***********************************************************************/
7097 DEFUN ("x-change-window-property", Fx_change_window_property
,
7098 Sx_change_window_property
, 2, 6, 0,
7099 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
7100 VALUE may be a string or a list of conses, numbers and/or strings.
7101 If an element in the list is a string, it is converted to
7102 an Atom and the value of the Atom is used. If an element is a cons,
7103 it is converted to a 32 bit number where the car is the 16 top bits and the
7104 cdr is the lower 16 bits.
7105 FRAME nil or omitted means use the selected frame.
7106 If TYPE is given and non-nil, it is the name of the type of VALUE.
7107 If TYPE is not given or nil, the type is STRING.
7108 FORMAT gives the size in bits of each element if VALUE is a list.
7109 It must be one of 8, 16 or 32.
7110 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
7111 If OUTER_P is non-nil, the property is changed for the outer X window of
7112 FRAME. Default is to change on the edit X window.
7115 (prop
, value
, frame
, type
, format
, outer_p
)
7116 Lisp_Object prop
, value
, frame
, type
, format
, outer_p
;
7118 #if 0 /* TODO : port window properties to W32 */
7119 struct frame
*f
= check_x_frame (frame
);
7122 CHECK_STRING (prop
);
7123 CHECK_STRING (value
);
7126 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
7127 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
7128 prop_atom
, XA_STRING
, 8, PropModeReplace
,
7129 SDATA (value
), SCHARS (value
));
7131 /* Make sure the property is set when we return. */
7132 XFlush (FRAME_W32_DISPLAY (f
));
7141 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
7142 Sx_delete_window_property
, 1, 2, 0,
7143 doc
: /* Remove window property PROP from X window of FRAME.
7144 FRAME nil or omitted means use the selected frame. Value is PROP. */)
7146 Lisp_Object prop
, frame
;
7148 #if 0 /* TODO : port window properties to W32 */
7150 struct frame
*f
= check_x_frame (frame
);
7153 CHECK_STRING (prop
);
7155 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
7156 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
7158 /* Make sure the property is removed when we return. */
7159 XFlush (FRAME_W32_DISPLAY (f
));
7167 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
7169 doc
: /* Value is the value of window property PROP on FRAME.
7170 If FRAME is nil or omitted, use the selected frame. Value is nil
7171 if FRAME hasn't a property with name PROP or if PROP has no string
7174 Lisp_Object prop
, frame
;
7176 #if 0 /* TODO : port window properties to W32 */
7178 struct frame
*f
= check_x_frame (frame
);
7181 Lisp_Object prop_value
= Qnil
;
7182 char *tmp_data
= NULL
;
7185 unsigned long actual_size
, bytes_remaining
;
7187 CHECK_STRING (prop
);
7189 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
7190 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
7191 prop_atom
, 0, 0, False
, XA_STRING
,
7192 &actual_type
, &actual_format
, &actual_size
,
7193 &bytes_remaining
, (unsigned char **) &tmp_data
);
7196 int size
= bytes_remaining
;
7201 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
7202 prop_atom
, 0, bytes_remaining
,
7204 &actual_type
, &actual_format
,
7205 &actual_size
, &bytes_remaining
,
7206 (unsigned char **) &tmp_data
);
7208 prop_value
= make_string (tmp_data
, size
);
7223 /***********************************************************************
7225 ***********************************************************************/
7227 /* If non-null, an asynchronous timer that, when it expires, displays
7228 an hourglass cursor on all frames. */
7230 static struct atimer
*hourglass_atimer
;
7232 /* Non-zero means an hourglass cursor is currently shown. */
7234 static int hourglass_shown_p
;
7236 /* Number of seconds to wait before displaying an hourglass cursor. */
7238 static Lisp_Object Vhourglass_delay
;
7240 /* Default number of seconds to wait before displaying an hourglass
7243 #define DEFAULT_HOURGLASS_DELAY 1
7245 /* Function prototypes. */
7247 static void show_hourglass
P_ ((struct atimer
*));
7248 static void hide_hourglass
P_ ((void));
7251 /* Cancel a currently active hourglass timer, and start a new one. */
7256 #if 0 /* TODO: cursor shape changes. */
7258 int secs
, usecs
= 0;
7260 cancel_hourglass ();
7262 if (INTEGERP (Vhourglass_delay
)
7263 && XINT (Vhourglass_delay
) > 0)
7264 secs
= XFASTINT (Vhourglass_delay
);
7265 else if (FLOATP (Vhourglass_delay
)
7266 && XFLOAT_DATA (Vhourglass_delay
) > 0)
7269 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
7270 secs
= XFASTINT (tem
);
7271 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
7274 secs
= DEFAULT_HOURGLASS_DELAY
;
7276 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
7277 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
7278 show_hourglass
, NULL
);
7283 /* Cancel the hourglass cursor timer if active, hide an hourglass
7289 if (hourglass_atimer
)
7291 cancel_atimer (hourglass_atimer
);
7292 hourglass_atimer
= NULL
;
7295 if (hourglass_shown_p
)
7300 /* Timer function of hourglass_atimer. TIMER is equal to
7303 Display an hourglass cursor on all frames by mapping the frames'
7304 hourglass_window. Set the hourglass_p flag in the frames'
7305 output_data.x structure to indicate that an hourglass cursor is
7306 shown on the frames. */
7309 show_hourglass (timer
)
7310 struct atimer
*timer
;
7312 #if 0 /* TODO: cursor shape changes. */
7313 /* The timer implementation will cancel this timer automatically
7314 after this function has run. Set hourglass_atimer to null
7315 so that we know the timer doesn't have to be canceled. */
7316 hourglass_atimer
= NULL
;
7318 if (!hourglass_shown_p
)
7320 Lisp_Object rest
, frame
;
7324 FOR_EACH_FRAME (rest
, frame
)
7325 if (FRAME_W32_P (XFRAME (frame
)))
7327 struct frame
*f
= XFRAME (frame
);
7329 f
->output_data
.w32
->hourglass_p
= 1;
7331 if (!f
->output_data
.w32
->hourglass_window
)
7333 unsigned long mask
= CWCursor
;
7334 XSetWindowAttributes attrs
;
7336 attrs
.cursor
= f
->output_data
.w32
->hourglass_cursor
;
7338 f
->output_data
.w32
->hourglass_window
7339 = XCreateWindow (FRAME_X_DISPLAY (f
),
7340 FRAME_OUTER_WINDOW (f
),
7341 0, 0, 32000, 32000, 0, 0,
7347 XMapRaised (FRAME_X_DISPLAY (f
),
7348 f
->output_data
.w32
->hourglass_window
);
7349 XFlush (FRAME_X_DISPLAY (f
));
7352 hourglass_shown_p
= 1;
7359 /* Hide the hourglass cursor on all frames, if it is currently shown. */
7364 #if 0 /* TODO: cursor shape changes. */
7365 if (hourglass_shown_p
)
7367 Lisp_Object rest
, frame
;
7370 FOR_EACH_FRAME (rest
, frame
)
7372 struct frame
*f
= XFRAME (frame
);
7375 /* Watch out for newly created frames. */
7376 && f
->output_data
.x
->hourglass_window
)
7378 XUnmapWindow (FRAME_X_DISPLAY (f
),
7379 f
->output_data
.x
->hourglass_window
);
7380 /* Sync here because XTread_socket looks at the
7381 hourglass_p flag that is reset to zero below. */
7382 XSync (FRAME_X_DISPLAY (f
), False
);
7383 f
->output_data
.x
->hourglass_p
= 0;
7387 hourglass_shown_p
= 0;
7395 /***********************************************************************
7397 ***********************************************************************/
7399 static Lisp_Object x_create_tip_frame
P_ ((struct w32_display_info
*,
7400 Lisp_Object
, Lisp_Object
));
7401 static void compute_tip_xy
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
7402 Lisp_Object
, int, int, int *, int *));
7404 /* The frame of a currently visible tooltip. */
7406 Lisp_Object tip_frame
;
7408 /* If non-nil, a timer started that hides the last tooltip when it
7411 Lisp_Object tip_timer
;
7414 /* If non-nil, a vector of 3 elements containing the last args
7415 with which x-show-tip was called. See there. */
7417 Lisp_Object last_show_tip_args
;
7419 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
7421 Lisp_Object Vx_max_tooltip_size
;
7425 unwind_create_tip_frame (frame
)
7428 Lisp_Object deleted
;
7430 deleted
= unwind_create_frame (frame
);
7431 if (EQ (deleted
, Qt
))
7441 /* Create a frame for a tooltip on the display described by DPYINFO.
7442 PARMS is a list of frame parameters. TEXT is the string to
7443 display in the tip frame. Value is the frame.
7445 Note that functions called here, esp. x_default_parameter can
7446 signal errors, for instance when a specified color name is
7447 undefined. We have to make sure that we're in a consistent state
7448 when this happens. */
7451 x_create_tip_frame (dpyinfo
, parms
, text
)
7452 struct w32_display_info
*dpyinfo
;
7453 Lisp_Object parms
, text
;
7456 Lisp_Object frame
, tem
;
7458 long window_prompting
= 0;
7460 int count
= SPECPDL_INDEX ();
7461 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7463 int face_change_count_before
= face_change_count
;
7465 struct buffer
*old_buffer
;
7469 /* Use this general default value to start with until we know if
7470 this frame has a specified name. */
7471 Vx_resource_name
= Vinvocation_name
;
7474 kb
= dpyinfo
->terminal
->kboard
;
7476 kb
= &the_only_kboard
;
7479 /* Get the name of the frame to use for resource lookup. */
7480 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
7482 && !EQ (name
, Qunbound
)
7484 error ("Invalid frame name--not a string or nil");
7485 Vx_resource_name
= name
;
7488 GCPRO3 (parms
, name
, frame
);
7489 /* Make a frame without minibuffer nor mode-line. */
7491 f
->wants_modeline
= 0;
7492 XSETFRAME (frame
, f
);
7494 buffer
= Fget_buffer_create (build_string (" *tip*"));
7495 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, Qnil
);
7496 old_buffer
= current_buffer
;
7497 set_buffer_internal_1 (XBUFFER (buffer
));
7498 current_buffer
->truncate_lines
= Qnil
;
7499 specbind (Qinhibit_read_only
, Qt
);
7500 specbind (Qinhibit_modification_hooks
, Qt
);
7503 set_buffer_internal_1 (old_buffer
);
7505 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
7506 record_unwind_protect (unwind_create_tip_frame
, frame
);
7508 /* By setting the output method, we're essentially saying that
7509 the frame is live, as per FRAME_LIVE_P. If we get a signal
7510 from this point on, x_destroy_window might screw up reference
7512 f
->terminal
= dpyinfo
->terminal
;
7513 f
->terminal
->reference_count
++;
7514 f
->output_method
= output_w32
;
7515 f
->output_data
.w32
=
7516 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
7517 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
7519 FRAME_FONTSET (f
) = -1;
7520 f
->icon_name
= Qnil
;
7522 #if 0 /* GLYPH_DEBUG TODO: image support. */
7523 image_cache_refcount
= FRAME_IMAGE_CACHE (f
)->refcount
;
7524 dpyinfo_refcount
= dpyinfo
->reference_count
;
7525 #endif /* GLYPH_DEBUG */
7527 FRAME_KBOARD (f
) = kb
;
7529 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
7530 f
->output_data
.w32
->explicit_parent
= 0;
7532 /* Set the name; the functions to which we pass f expect the name to
7534 if (EQ (name
, Qunbound
) || NILP (name
))
7536 f
->name
= build_string (dpyinfo
->w32_id_name
);
7537 f
->explicit_name
= 0;
7542 f
->explicit_name
= 1;
7543 /* use the frame's title when getting resources for this frame. */
7544 specbind (Qx_resource_name
, name
);
7547 f
->resx
= dpyinfo
->resx
;
7548 f
->resy
= dpyinfo
->resy
;
7550 #ifdef USE_FONT_BACKEND
7551 if (enable_font_backend
)
7553 /* Perhaps, we must allow frame parameter, say `font-backend',
7554 to specify which font backends to use. */
7555 register_font_driver (&w32font_driver
, f
);
7557 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
7558 "fontBackend", "FontBackend", RES_TYPE_STRING
);
7560 #endif /* USE_FONT_BACKEND */
7562 /* Extract the window parameters from the supplied values
7563 that are needed to determine window geometry. */
7564 #ifdef USE_FONT_BACKEND
7565 if (enable_font_backend
)
7566 x_default_font_parameter (f
, parms
);
7568 #endif /* USE_FONT_BACKEND */
7572 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
7575 /* First, try whatever font the caller has specified. */
7578 tem
= Fquery_fontset (font
, Qnil
);
7580 font
= x_new_fontset (f
, tem
);
7582 font
= x_new_font (f
, SDATA (font
));
7585 /* Try out a font which we hope has bold and italic variations. */
7586 if (!STRINGP (font
))
7587 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
7588 if (! STRINGP (font
))
7589 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
7590 /* If those didn't work, look for something which will at least work. */
7591 if (! STRINGP (font
))
7592 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
7594 if (! STRINGP (font
))
7595 font
= build_string ("Fixedsys");
7597 x_default_parameter (f
, parms
, Qfont
, font
,
7598 "font", "Font", RES_TYPE_STRING
);
7601 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
7602 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
7603 /* This defaults to 2 in order to match xterm. We recognize either
7604 internalBorderWidth or internalBorder (which is what xterm calls
7606 if (NILP (Fassq (Qinternal_border_width
, parms
)))
7610 value
= w32_get_arg (parms
, Qinternal_border_width
,
7611 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
7612 if (! EQ (value
, Qunbound
))
7613 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
7616 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
7617 "internalBorderWidth", "internalBorderWidth",
7620 /* Also do the stuff which must be set before the window exists. */
7621 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
7622 "foreground", "Foreground", RES_TYPE_STRING
);
7623 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
7624 "background", "Background", RES_TYPE_STRING
);
7625 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
7626 "pointerColor", "Foreground", RES_TYPE_STRING
);
7627 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
7628 "cursorColor", "Foreground", RES_TYPE_STRING
);
7629 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
7630 "borderColor", "BorderColor", RES_TYPE_STRING
);
7632 /* Init faces before x_default_parameter is called for scroll-bar
7633 parameters because that function calls x_set_scroll_bar_width,
7634 which calls change_frame_size, which calls Fset_window_buffer,
7635 which runs hooks, which call Fvertical_motion. At the end, we
7636 end up in init_iterator with a null face cache, which should not
7638 init_frame_faces (f
);
7640 f
->output_data
.w32
->dwStyle
= WS_BORDER
| WS_POPUP
| WS_DISABLED
;
7641 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
7643 window_prompting
= x_figure_window_size (f
, parms
, 0);
7645 /* No fringes on tip frame. */
7647 f
->left_fringe_width
= 0;
7648 f
->right_fringe_width
= 0;
7651 my_create_tip_window (f
);
7656 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
7657 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
7658 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
7659 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
7660 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
7661 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
7663 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
7664 Change will not be effected unless different from the current
7666 width
= FRAME_COLS (f
);
7667 height
= FRAME_LINES (f
);
7668 FRAME_LINES (f
) = 0;
7669 SET_FRAME_COLS (f
, 0);
7670 change_frame_size (f
, height
, width
, 1, 0, 0);
7672 /* Add `tooltip' frame parameter's default value. */
7673 if (NILP (Fframe_parameter (frame
, intern ("tooltip"))))
7674 Fmodify_frame_parameters (frame
, Fcons (Fcons (intern ("tooltip"), Qt
),
7677 /* Set up faces after all frame parameters are known. This call
7678 also merges in face attributes specified for new frames.
7680 Frame parameters may be changed if .Xdefaults contains
7681 specifications for the default font. For example, if there is an
7682 `Emacs.default.attributeBackground: pink', the `background-color'
7683 attribute of the frame get's set, which let's the internal border
7684 of the tooltip frame appear in pink. Prevent this. */
7686 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
7688 /* Set tip_frame here, so that */
7690 call1 (Qface_set_after_frame_default
, frame
);
7692 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
7693 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qbackground_color
, bg
),
7701 /* It is now ok to make the frame official even if we get an error
7702 below. And the frame needs to be on Vframe_list or making it
7703 visible won't work. */
7704 Vframe_list
= Fcons (frame
, Vframe_list
);
7706 /* Now that the frame is official, it counts as a reference to
7708 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
7710 /* Setting attributes of faces of the tooltip frame from resources
7711 and similar will increment face_change_count, which leads to the
7712 clearing of all current matrices. Since this isn't necessary
7713 here, avoid it by resetting face_change_count to the value it
7714 had before we created the tip frame. */
7715 face_change_count
= face_change_count_before
;
7717 /* Discard the unwind_protect. */
7718 return unbind_to (count
, frame
);
7722 /* Compute where to display tip frame F. PARMS is the list of frame
7723 parameters for F. DX and DY are specified offsets from the current
7724 location of the mouse. WIDTH and HEIGHT are the width and height
7725 of the tooltip. Return coordinates relative to the root window of
7726 the display in *ROOT_X, and *ROOT_Y. */
7729 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, root_x
, root_y
)
7731 Lisp_Object parms
, dx
, dy
;
7733 int *root_x
, *root_y
;
7735 Lisp_Object left
, top
;
7736 int min_x
, min_y
, max_x
, max_y
;
7738 /* User-specified position? */
7739 left
= Fcdr (Fassq (Qleft
, parms
));
7740 top
= Fcdr (Fassq (Qtop
, parms
));
7742 /* Move the tooltip window where the mouse pointer is. Resize and
7744 if (!INTEGERP (left
) || !INTEGERP (top
))
7748 /* Default min and max values. */
7751 max_x
= FRAME_W32_DISPLAY_INFO (f
)->width
;
7752 max_y
= FRAME_W32_DISPLAY_INFO (f
)->height
;
7760 /* If multiple monitor support is available, constrain the tip onto
7761 the current monitor. This improves the above by allowing negative
7762 co-ordinates if monitor positions are such that they are valid, and
7763 snaps a tooltip onto a single monitor if we are close to the edge
7764 where it would otherwise flow onto the other monitor (or into
7765 nothingness if there is a gap in the overlap). */
7766 if (monitor_from_point_fn
&& get_monitor_info_fn
)
7768 struct MONITOR_INFO info
;
7770 = monitor_from_point_fn (pt
, MONITOR_DEFAULT_TO_NEAREST
);
7771 info
.cbSize
= sizeof (info
);
7773 if (get_monitor_info_fn (monitor
, &info
))
7775 min_x
= info
.rcWork
.left
;
7776 min_y
= info
.rcWork
.top
;
7777 max_x
= info
.rcWork
.right
;
7778 max_y
= info
.rcWork
.bottom
;
7784 *root_y
= XINT (top
);
7785 else if (*root_y
+ XINT (dy
) <= min_y
)
7786 *root_y
= min_y
; /* Can happen for negative dy */
7787 else if (*root_y
+ XINT (dy
) + height
<= max_y
)
7788 /* It fits below the pointer */
7789 *root_y
+= XINT (dy
);
7790 else if (height
+ XINT (dy
) + min_y
<= *root_y
)
7791 /* It fits above the pointer. */
7792 *root_y
-= height
+ XINT (dy
);
7794 /* Put it on the top. */
7797 if (INTEGERP (left
))
7798 *root_x
= XINT (left
);
7799 else if (*root_x
+ XINT (dx
) <= min_x
)
7800 *root_x
= 0; /* Can happen for negative dx */
7801 else if (*root_x
+ XINT (dx
) + width
<= max_x
)
7802 /* It fits to the right of the pointer. */
7803 *root_x
+= XINT (dx
);
7804 else if (width
+ XINT (dx
) + min_x
<= *root_x
)
7805 /* It fits to the left of the pointer. */
7806 *root_x
-= width
+ XINT (dx
);
7808 /* Put it left justified on the screen -- it ought to fit that way. */
7813 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
7814 doc
: /* Show STRING in a \"tooltip\" window on frame FRAME.
7815 A tooltip window is a small window displaying a string.
7817 This is an internal function; Lisp code should call `tooltip-show'.
7819 FRAME nil or omitted means use the selected frame.
7821 PARMS is an optional list of frame parameters which can be
7822 used to change the tooltip's appearance.
7824 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
7825 means use the default timeout of 5 seconds.
7827 If the list of frame parameters PARMS contains a `left' parameter,
7828 the tooltip is displayed at that x-position. Otherwise it is
7829 displayed at the mouse position, with offset DX added (default is 5 if
7830 DX isn't specified). Likewise for the y-position; if a `top' frame
7831 parameter is specified, it determines the y-position of the tooltip
7832 window, otherwise it is displayed at the mouse position, with offset
7833 DY added (default is -10).
7835 A tooltip's maximum size is specified by `x-max-tooltip-size'.
7836 Text larger than the specified size is clipped. */)
7837 (string
, frame
, parms
, timeout
, dx
, dy
)
7838 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
7843 struct buffer
*old_buffer
;
7844 struct text_pos pos
;
7845 int i
, width
, height
;
7846 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7847 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7848 int count
= SPECPDL_INDEX ();
7850 specbind (Qinhibit_redisplay
, Qt
);
7852 GCPRO4 (string
, parms
, frame
, timeout
);
7854 CHECK_STRING (string
);
7855 f
= check_x_frame (frame
);
7857 timeout
= make_number (5);
7859 CHECK_NATNUM (timeout
);
7862 dx
= make_number (5);
7867 dy
= make_number (-10);
7871 if (NILP (last_show_tip_args
))
7872 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
7874 if (!NILP (tip_frame
))
7876 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
7877 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
7878 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
7880 if (EQ (frame
, last_frame
)
7881 && !NILP (Fequal (last_string
, string
))
7882 && !NILP (Fequal (last_parms
, parms
)))
7884 struct frame
*f
= XFRAME (tip_frame
);
7886 /* Only DX and DY have changed. */
7887 if (!NILP (tip_timer
))
7889 Lisp_Object timer
= tip_timer
;
7891 call1 (Qcancel_timer
, timer
);
7895 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
7896 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
7898 /* Put tooltip in topmost group and in position. */
7899 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
7900 root_x
, root_y
, 0, 0,
7901 SWP_NOSIZE
| SWP_NOACTIVATE
);
7903 /* Ensure tooltip is on top of other topmost windows (eg menus). */
7904 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
7906 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
7913 /* Hide a previous tip, if any. */
7916 ASET (last_show_tip_args
, 0, string
);
7917 ASET (last_show_tip_args
, 1, frame
);
7918 ASET (last_show_tip_args
, 2, parms
);
7920 /* Add default values to frame parameters. */
7921 if (NILP (Fassq (Qname
, parms
)))
7922 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
7923 if (NILP (Fassq (Qinternal_border_width
, parms
)))
7924 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
7925 if (NILP (Fassq (Qborder_width
, parms
)))
7926 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
7927 if (NILP (Fassq (Qborder_color
, parms
)))
7928 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
7929 if (NILP (Fassq (Qbackground_color
, parms
)))
7930 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
7933 /* Block input until the tip has been fully drawn, to avoid crashes
7934 when drawing tips in menus. */
7937 /* Create a frame for the tooltip, and record it in the global
7938 variable tip_frame. */
7939 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
, string
);
7942 /* Set up the frame's root window. */
7943 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7944 w
->left_col
= w
->top_line
= make_number (0);
7946 if (CONSP (Vx_max_tooltip_size
)
7947 && INTEGERP (XCAR (Vx_max_tooltip_size
))
7948 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
7949 && INTEGERP (XCDR (Vx_max_tooltip_size
))
7950 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
7952 w
->total_cols
= XCAR (Vx_max_tooltip_size
);
7953 w
->total_lines
= XCDR (Vx_max_tooltip_size
);
7957 w
->total_cols
= make_number (80);
7958 w
->total_lines
= make_number (40);
7961 FRAME_TOTAL_COLS (f
) = XINT (w
->total_cols
);
7963 w
->pseudo_window_p
= 1;
7965 /* Display the tooltip text in a temporary buffer. */
7966 old_buffer
= current_buffer
;
7967 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
7968 current_buffer
->truncate_lines
= Qnil
;
7969 clear_glyph_matrix (w
->desired_matrix
);
7970 clear_glyph_matrix (w
->current_matrix
);
7971 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
7972 try_window (FRAME_ROOT_WINDOW (f
), pos
, 0);
7974 /* Compute width and height of the tooltip. */
7976 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
7978 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
7982 /* Stop at the first empty row at the end. */
7983 if (!row
->enabled_p
|| !row
->displays_text_p
)
7986 /* Let the row go over the full width of the frame. */
7987 row
->full_width_p
= 1;
7989 #ifdef TODO /* Investigate why some fonts need more width than is
7990 calculated for some tooltips. */
7991 /* There's a glyph at the end of rows that is use to place
7992 the cursor there. Don't include the width of this glyph. */
7993 if (row
->used
[TEXT_AREA
])
7995 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
7996 row_width
= row
->pixel_width
- last
->pixel_width
;
8000 row_width
= row
->pixel_width
;
8002 /* TODO: find why tips do not draw along baseline as instructed. */
8003 height
+= row
->height
;
8004 width
= max (width
, row_width
);
8007 /* Add the frame's internal border to the width and height the X
8008 window should have. */
8009 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
8010 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
8012 /* Move the tooltip window where the mouse pointer is. Resize and
8014 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
8017 /* Adjust Window size to take border into account. */
8019 rect
.left
= rect
.top
= 0;
8021 rect
.bottom
= height
;
8022 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
8023 FRAME_EXTERNAL_MENU_BAR (f
));
8025 /* Position and size tooltip, and put it in the topmost group.
8026 The add-on of 3 to the 5th argument is a kludge: without it,
8027 some fonts cause the last character of the tip to be truncated,
8028 for some obscure reason. */
8029 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
8030 root_x
, root_y
, rect
.right
- rect
.left
+ 3,
8031 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
);
8033 /* Ensure tooltip is on top of other topmost windows (eg menus). */
8034 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
8036 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
8038 /* Let redisplay know that we have made the frame visible already. */
8039 f
->async_visible
= 1;
8041 ShowWindow (FRAME_W32_WINDOW (f
), SW_SHOWNOACTIVATE
);
8044 /* Draw into the window. */
8045 w
->must_be_updated_p
= 1;
8046 update_single_window (w
, 1);
8050 /* Restore original current buffer. */
8051 set_buffer_internal_1 (old_buffer
);
8052 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
8055 /* Let the tip disappear after timeout seconds. */
8056 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
8057 intern ("x-hide-tip"));
8060 return unbind_to (count
, Qnil
);
8064 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
8065 doc
: /* Hide the current tooltip window, if there is any.
8066 Value is t if tooltip was open, nil otherwise. */)
8070 Lisp_Object deleted
, frame
, timer
;
8071 struct gcpro gcpro1
, gcpro2
;
8073 /* Return quickly if nothing to do. */
8074 if (NILP (tip_timer
) && NILP (tip_frame
))
8079 GCPRO2 (frame
, timer
);
8080 tip_frame
= tip_timer
= deleted
= Qnil
;
8082 count
= SPECPDL_INDEX ();
8083 specbind (Qinhibit_redisplay
, Qt
);
8084 specbind (Qinhibit_quit
, Qt
);
8087 call1 (Qcancel_timer
, timer
);
8091 Fdelete_frame (frame
, Qnil
);
8096 return unbind_to (count
, deleted
);
8101 /***********************************************************************
8102 File selection dialog
8103 ***********************************************************************/
8104 extern Lisp_Object Qfile_name_history
;
8106 /* Callback for altering the behaviour of the Open File dialog.
8107 Makes the Filename text field contain "Current Directory" and be
8108 read-only when "Directories" is selected in the filter. This
8109 allows us to work around the fact that the standard Open File
8110 dialog does not support directories. */
8112 file_dialog_callback (hwnd
, msg
, wParam
, lParam
)
8118 if (msg
== WM_NOTIFY
)
8120 OFNOTIFY
* notify
= (OFNOTIFY
*)lParam
;
8121 /* Detect when the Filter dropdown is changed. */
8122 if (notify
->hdr
.code
== CDN_TYPECHANGE
8123 || notify
->hdr
.code
== CDN_INITDONE
)
8125 HWND dialog
= GetParent (hwnd
);
8126 HWND edit_control
= GetDlgItem (dialog
, FILE_NAME_TEXT_FIELD
);
8128 /* Directories is in index 2. */
8129 if (notify
->lpOFN
->nFilterIndex
== 2)
8131 CommDlg_OpenSave_SetControlText (dialog
, FILE_NAME_TEXT_FIELD
,
8132 "Current Directory");
8133 EnableWindow (edit_control
, FALSE
);
8137 /* Don't override default filename on init done. */
8138 if (notify
->hdr
.code
== CDN_TYPECHANGE
)
8139 CommDlg_OpenSave_SetControlText (dialog
,
8140 FILE_NAME_TEXT_FIELD
, "");
8141 EnableWindow (edit_control
, TRUE
);
8148 /* Since we compile with _WIN32_WINNT set to 0x0400 (for NT4 compatibility)
8149 we end up with the old file dialogs. Define a big enough struct for the
8150 new dialog to trick GetOpenFileName into giving us the new dialogs on
8151 Windows 2000 and XP. */
8154 OPENFILENAME real_details
;
8161 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
8162 doc
: /* Read file name, prompting with PROMPT in directory DIR.
8163 Use a file selection dialog.
8164 Select DEFAULT-FILENAME in the dialog's file selection box, if
8165 specified. Ensure that file exists if MUSTMATCH is non-nil.
8166 If ONLY-DIR-P is non-nil, the user can only select directories. */)
8167 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
)
8168 Lisp_Object prompt
, dir
, default_filename
, mustmatch
, only_dir_p
;
8170 struct frame
*f
= SELECTED_FRAME ();
8171 Lisp_Object file
= Qnil
;
8172 int count
= SPECPDL_INDEX ();
8173 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
8174 char filename
[MAX_PATH
+ 1];
8175 char init_dir
[MAX_PATH
+ 1];
8176 int default_filter_index
= 1; /* 1: All Files, 2: Directories only */
8178 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
8179 CHECK_STRING (prompt
);
8182 /* Create the dialog with PROMPT as title, using DIR as initial
8183 directory and using "*" as pattern. */
8184 dir
= Fexpand_file_name (dir
, Qnil
);
8185 strncpy (init_dir
, SDATA (ENCODE_FILE (dir
)), MAX_PATH
);
8186 init_dir
[MAX_PATH
] = '\0';
8187 unixtodos_filename (init_dir
);
8189 if (STRINGP (default_filename
))
8191 char *file_name_only
;
8192 char *full_path_name
= SDATA (ENCODE_FILE (default_filename
));
8194 unixtodos_filename (full_path_name
);
8196 file_name_only
= strrchr (full_path_name
, '\\');
8197 if (!file_name_only
)
8198 file_name_only
= full_path_name
;
8202 strncpy (filename
, file_name_only
, MAX_PATH
);
8203 filename
[MAX_PATH
] = '\0';
8209 NEWOPENFILENAME new_file_details
;
8210 BOOL file_opened
= FALSE
;
8211 OPENFILENAME
* file_details
= &new_file_details
.real_details
;
8213 /* Prevent redisplay. */
8214 specbind (Qinhibit_redisplay
, Qt
);
8217 bzero (&new_file_details
, sizeof (new_file_details
));
8218 /* Apparently NT4 crashes if you give it an unexpected size.
8219 I'm not sure about Windows 9x, so play it safe. */
8220 if (w32_major_version
> 4 && w32_major_version
< 95)
8221 file_details
->lStructSize
= sizeof (NEWOPENFILENAME
);
8223 file_details
->lStructSize
= sizeof (OPENFILENAME
);
8225 file_details
->hwndOwner
= FRAME_W32_WINDOW (f
);
8226 /* Undocumented Bug in Common File Dialog:
8227 If a filter is not specified, shell links are not resolved. */
8228 file_details
->lpstrFilter
= "All Files (*.*)\0*.*\0Directories\0*|*\0\0";
8229 file_details
->lpstrFile
= filename
;
8230 file_details
->nMaxFile
= sizeof (filename
);
8231 file_details
->lpstrInitialDir
= init_dir
;
8232 file_details
->lpstrTitle
= SDATA (prompt
);
8234 if (! NILP (only_dir_p
))
8235 default_filter_index
= 2;
8237 file_details
->nFilterIndex
= default_filter_index
;
8239 file_details
->Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
8240 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
8241 if (!NILP (mustmatch
))
8243 /* Require that the path to the parent directory exists. */
8244 file_details
->Flags
|= OFN_PATHMUSTEXIST
;
8245 /* If we are looking for a file, require that it exists. */
8246 if (NILP (only_dir_p
))
8247 file_details
->Flags
|= OFN_FILEMUSTEXIST
;
8250 file_details
->lpfnHook
= (LPOFNHOOKPROC
) file_dialog_callback
;
8252 file_opened
= GetOpenFileName (file_details
);
8258 dostounix_filename (filename
);
8260 if (file_details
->nFilterIndex
== 2)
8262 /* "Directories" selected - strip dummy file name. */
8263 char * last
= strrchr (filename
, '/');
8267 file
= DECODE_FILE (build_string (filename
));
8269 /* User cancelled the dialog without making a selection. */
8270 else if (!CommDlgExtendedError ())
8272 /* An error occurred, fallback on reading from the mini-buffer. */
8274 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
8275 dir
, mustmatch
, dir
, Qfile_name_history
,
8276 default_filename
, Qnil
);
8278 file
= unbind_to (count
, file
);
8283 /* Make "Cancel" equivalent to C-g. */
8285 Fsignal (Qquit
, Qnil
);
8287 return unbind_to (count
, file
);
8292 /***********************************************************************
8293 w32 specialized functions
8294 ***********************************************************************/
8296 DEFUN ("w32-select-font", Fw32_select_font
, Sw32_select_font
, 0, 2, 0,
8297 doc
: /* Select a font for the named FRAME using the W32 font dialog.
8298 Return an X-style font string corresponding to the selection.
8300 If FRAME is omitted or nil, it defaults to the selected frame.
8301 If INCLUDE-PROPORTIONAL is non-nil, include proportional fonts
8302 in the font selection dialog. */)
8303 (frame
, include_proportional
)
8304 Lisp_Object frame
, include_proportional
;
8306 FRAME_PTR f
= check_x_frame (frame
);
8314 bzero (&cf
, sizeof (cf
));
8315 bzero (&lf
, sizeof (lf
));
8317 cf
.lStructSize
= sizeof (cf
);
8318 cf
.hwndOwner
= FRAME_W32_WINDOW (f
);
8319 cf
.Flags
= CF_FORCEFONTEXIST
| CF_SCREENFONTS
| CF_NOVERTFONTS
;
8321 /* Unless include_proportional is non-nil, limit the selection to
8322 monospaced fonts. */
8323 if (NILP (include_proportional
))
8324 cf
.Flags
|= CF_FIXEDPITCHONLY
;
8328 /* Initialize as much of the font details as we can from the current
8330 hdc
= GetDC (FRAME_W32_WINDOW (f
));
8331 oldobj
= SelectObject (hdc
, FRAME_FONT (f
)->hfont
);
8332 GetTextFace (hdc
, LF_FACESIZE
, lf
.lfFaceName
);
8333 if (GetTextMetrics (hdc
, &tm
))
8335 lf
.lfHeight
= tm
.tmInternalLeading
- tm
.tmHeight
;
8336 lf
.lfWeight
= tm
.tmWeight
;
8337 lf
.lfItalic
= tm
.tmItalic
;
8338 lf
.lfUnderline
= tm
.tmUnderlined
;
8339 lf
.lfStrikeOut
= tm
.tmStruckOut
;
8340 lf
.lfCharSet
= tm
.tmCharSet
;
8341 cf
.Flags
|= CF_INITTOLOGFONTSTRUCT
;
8343 SelectObject (hdc
, oldobj
);
8344 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
8346 if (!ChooseFont (&cf
) || !w32_to_x_font (&lf
, buf
, 100, NULL
))
8349 return build_string (buf
);
8352 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
,
8353 Sw32_send_sys_command
, 1, 2, 0,
8354 doc
: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND.
8355 Some useful values for COMMAND are #xf030 to maximize frame (#xf020
8356 to minimize), #xf120 to restore frame to original size, and #xf100
8357 to activate the menubar for keyboard access. #xf140 activates the
8358 screen saver if defined.
8360 If optional parameter FRAME is not specified, use selected frame. */)
8362 Lisp_Object command
, frame
;
8364 FRAME_PTR f
= check_x_frame (frame
);
8366 CHECK_NUMBER (command
);
8368 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
8373 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
8374 doc
: /* Get Windows to perform OPERATION on DOCUMENT.
8375 This is a wrapper around the ShellExecute system function, which
8376 invokes the application registered to handle OPERATION for DOCUMENT.
8378 OPERATION is either nil or a string that names a supported operation.
8379 What operations can be used depends on the particular DOCUMENT and its
8380 handler application, but typically it is one of the following common
8383 \"open\" - open DOCUMENT, which could be a file, a directory, or an
8384 executable program. If it is an application, that
8385 application is launched in the current buffer's default
8386 directory. Otherwise, the application associated with
8387 DOCUMENT is launched in the buffer's default directory.
8388 \"print\" - print DOCUMENT, which must be a file
8389 \"explore\" - start the Windows Explorer on DOCUMENT
8390 \"edit\" - launch an editor and open DOCUMENT for editing; which
8391 editor is launched depends on the association for the
8393 \"find\" - initiate search starting from DOCUMENT which must specify
8395 nil - invoke the default OPERATION, or \"open\" if default is
8396 not defined or unavailable
8398 DOCUMENT is typically the name of a document file or a URL, but can
8399 also be a program executable to run, or a directory to open in the
8402 If DOCUMENT is a program executable, the optional third arg PARAMETERS
8403 can be a string containing command line parameters that will be passed
8404 to the program; otherwise, PARAMETERS should be nil or unspecified.
8406 Optional fourth argument SHOW-FLAG can be used to control how the
8407 application will be displayed when it is invoked. If SHOW-FLAG is nil
8408 or unspecified, the application is displayed normally, otherwise it is
8409 an integer representing a ShowWindow flag:
8414 6 - start minimized */)
8415 (operation
, document
, parameters
, show_flag
)
8416 Lisp_Object operation
, document
, parameters
, show_flag
;
8418 Lisp_Object current_dir
;
8420 CHECK_STRING (document
);
8422 /* Encode filename, current directory and parameters. */
8423 current_dir
= ENCODE_FILE (current_buffer
->directory
);
8424 document
= ENCODE_FILE (document
);
8425 if (STRINGP (parameters
))
8426 parameters
= ENCODE_SYSTEM (parameters
);
8428 if ((int) ShellExecute (NULL
,
8429 (STRINGP (operation
) ?
8430 SDATA (operation
) : NULL
),
8432 (STRINGP (parameters
) ?
8433 SDATA (parameters
) : NULL
),
8434 SDATA (current_dir
),
8435 (INTEGERP (show_flag
) ?
8436 XINT (show_flag
) : SW_SHOWDEFAULT
))
8439 error ("ShellExecute failed: %s", w32_strerror (0));
8442 /* Lookup virtual keycode from string representing the name of a
8443 non-ascii keystroke into the corresponding virtual key, using
8444 lispy_function_keys. */
8446 lookup_vk_code (char *key
)
8450 for (i
= 0; i
< 256; i
++)
8451 if (lispy_function_keys
[i
]
8452 && strcmp (lispy_function_keys
[i
], key
) == 0)
8458 /* Convert a one-element vector style key sequence to a hot key
8461 w32_parse_hot_key (key
)
8464 /* Copied from Fdefine_key and store_in_keymap. */
8465 register Lisp_Object c
;
8469 struct gcpro gcpro1
;
8473 if (XFASTINT (Flength (key
)) != 1)
8478 c
= Faref (key
, make_number (0));
8480 if (CONSP (c
) && lucid_event_type_list_p (c
))
8481 c
= Fevent_convert_list (c
);
8485 if (! INTEGERP (c
) && ! SYMBOLP (c
))
8486 error ("Key definition is invalid");
8488 /* Work out the base key and the modifiers. */
8491 c
= parse_modifiers (c
);
8492 lisp_modifiers
= XINT (Fcar (Fcdr (c
)));
8496 vk_code
= lookup_vk_code (SDATA (SYMBOL_NAME (c
)));
8498 else if (INTEGERP (c
))
8500 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
8501 /* Many ascii characters are their own virtual key code. */
8502 vk_code
= XINT (c
) & CHARACTERBITS
;
8505 if (vk_code
< 0 || vk_code
> 255)
8508 if ((lisp_modifiers
& meta_modifier
) != 0
8509 && !NILP (Vw32_alt_is_meta
))
8510 lisp_modifiers
|= alt_modifier
;
8512 /* Supply defs missing from mingw32. */
8514 #define MOD_ALT 0x0001
8515 #define MOD_CONTROL 0x0002
8516 #define MOD_SHIFT 0x0004
8517 #define MOD_WIN 0x0008
8520 /* Convert lisp modifiers to Windows hot-key form. */
8521 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
8522 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
8523 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
8524 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
8526 return HOTKEY (vk_code
, w32_modifiers
);
8529 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
,
8530 Sw32_register_hot_key
, 1, 1, 0,
8531 doc
: /* Register KEY as a hot-key combination.
8532 Certain key combinations like Alt-Tab are reserved for system use on
8533 Windows, and therefore are normally intercepted by the system. However,
8534 most of these key combinations can be received by registering them as
8535 hot-keys, overriding their special meaning.
8537 KEY must be a one element key definition in vector form that would be
8538 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta
8539 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper
8540 is always interpreted as the Windows modifier keys.
8542 The return value is the hotkey-id if registered, otherwise nil. */)
8546 key
= w32_parse_hot_key (key
);
8548 if (!NILP (key
) && NILP (Fmemq (key
, w32_grabbed_keys
)))
8550 /* Reuse an empty slot if possible. */
8551 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
8553 /* Safe to add new key to list, even if we have focus. */
8555 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
8557 XSETCAR (item
, key
);
8559 /* Notify input thread about new hot-key definition, so that it
8560 takes effect without needing to switch focus. */
8561 #ifdef USE_LISP_UNION_TYPE
8562 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
8565 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
8573 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
,
8574 Sw32_unregister_hot_key
, 1, 1, 0,
8575 doc
: /* Unregister KEY as a hot-key combination. */)
8581 if (!INTEGERP (key
))
8582 key
= w32_parse_hot_key (key
);
8584 item
= Fmemq (key
, w32_grabbed_keys
);
8588 /* Notify input thread about hot-key definition being removed, so
8589 that it takes effect without needing focus switch. */
8590 #ifdef USE_LISP_UNION_TYPE
8591 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
8592 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
.i
))
8594 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
8595 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
))
8599 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
8606 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
,
8607 Sw32_registered_hot_keys
, 0, 0, 0,
8608 doc
: /* Return list of registered hot-key IDs. */)
8611 return Fdelq (Qnil
, Fcopy_sequence (w32_grabbed_keys
));
8614 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
,
8615 Sw32_reconstruct_hot_key
, 1, 1, 0,
8616 doc
: /* Convert hot-key ID to a lisp key combination.
8617 usage: (w32-reconstruct-hot-key ID) */)
8619 Lisp_Object hotkeyid
;
8621 int vk_code
, w32_modifiers
;
8624 CHECK_NUMBER (hotkeyid
);
8626 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
8627 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
8629 if (vk_code
< 256 && lispy_function_keys
[vk_code
])
8630 key
= intern (lispy_function_keys
[vk_code
]);
8632 key
= make_number (vk_code
);
8634 key
= Fcons (key
, Qnil
);
8635 if (w32_modifiers
& MOD_SHIFT
)
8636 key
= Fcons (Qshift
, key
);
8637 if (w32_modifiers
& MOD_CONTROL
)
8638 key
= Fcons (Qctrl
, key
);
8639 if (w32_modifiers
& MOD_ALT
)
8640 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
8641 if (w32_modifiers
& MOD_WIN
)
8642 key
= Fcons (Qhyper
, key
);
8647 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
,
8648 Sw32_toggle_lock_key
, 1, 2, 0,
8649 doc
: /* Toggle the state of the lock key KEY.
8650 KEY can be `capslock', `kp-numlock', or `scroll'.
8651 If the optional parameter NEW-STATE is a number, then the state of KEY
8652 is set to off if the low bit of NEW-STATE is zero, otherwise on. */)
8654 Lisp_Object key
, new_state
;
8658 if (EQ (key
, intern ("capslock")))
8659 vk_code
= VK_CAPITAL
;
8660 else if (EQ (key
, intern ("kp-numlock")))
8661 vk_code
= VK_NUMLOCK
;
8662 else if (EQ (key
, intern ("scroll")))
8663 vk_code
= VK_SCROLL
;
8667 if (!dwWindowsThreadId
)
8668 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
8670 #ifdef USE_LISP_UNION_TYPE
8671 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
8672 (WPARAM
) vk_code
, (LPARAM
) new_state
.i
))
8674 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
8675 (WPARAM
) vk_code
, (LPARAM
) new_state
))
8679 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
8680 return make_number (msg
.wParam
);
8685 DEFUN ("w32-window-exists-p", Fw32_window_exists_p
, Sw32_window_exists_p
,
8687 doc
: /* Return non-nil if a window exists with the specified CLASS and NAME.
8689 This is a direct interface to the Windows API FindWindow function. */)
8691 Lisp_Object
class, name
;
8696 CHECK_STRING (class);
8698 CHECK_STRING (name
);
8700 hnd
= FindWindow (STRINGP (class) ? ((LPCTSTR
) SDATA (class)) : NULL
,
8701 STRINGP (name
) ? ((LPCTSTR
) SDATA (name
)) : NULL
);
8709 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
8710 doc
: /* Return storage information about the file system FILENAME is on.
8711 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
8712 storage of the file system, FREE is the free storage, and AVAIL is the
8713 storage available to a non-superuser. All 3 numbers are in bytes.
8714 If the underlying system call fails, value is nil. */)
8716 Lisp_Object filename
;
8718 Lisp_Object encoded
, value
;
8720 CHECK_STRING (filename
);
8721 filename
= Fexpand_file_name (filename
, Qnil
);
8722 encoded
= ENCODE_FILE (filename
);
8726 /* Determining the required information on Windows turns out, sadly,
8727 to be more involved than one would hope. The original Win32 api
8728 call for this will return bogus information on some systems, but we
8729 must dynamically probe for the replacement api, since that was
8730 added rather late on. */
8732 HMODULE hKernel
= GetModuleHandle ("kernel32");
8733 BOOL (*pfn_GetDiskFreeSpaceEx
)
8734 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
8735 = (void *) GetProcAddress (hKernel
, "GetDiskFreeSpaceEx");
8737 /* On Windows, we may need to specify the root directory of the
8738 volume holding FILENAME. */
8739 char rootname
[MAX_PATH
];
8740 char *name
= SDATA (encoded
);
8742 /* find the root name of the volume if given */
8743 if (isalpha (name
[0]) && name
[1] == ':')
8745 rootname
[0] = name
[0];
8746 rootname
[1] = name
[1];
8750 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
8752 char *str
= rootname
;
8756 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
8766 if (pfn_GetDiskFreeSpaceEx
)
8768 /* Unsigned large integers cannot be cast to double, so
8769 use signed ones instead. */
8770 LARGE_INTEGER availbytes
;
8771 LARGE_INTEGER freebytes
;
8772 LARGE_INTEGER totalbytes
;
8774 if (pfn_GetDiskFreeSpaceEx (rootname
,
8775 (ULARGE_INTEGER
*)&availbytes
,
8776 (ULARGE_INTEGER
*)&totalbytes
,
8777 (ULARGE_INTEGER
*)&freebytes
))
8778 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
8779 make_float ((double) freebytes
.QuadPart
),
8780 make_float ((double) availbytes
.QuadPart
));
8784 DWORD sectors_per_cluster
;
8785 DWORD bytes_per_sector
;
8786 DWORD free_clusters
;
8787 DWORD total_clusters
;
8789 if (GetDiskFreeSpace (rootname
,
8790 §ors_per_cluster
,
8794 value
= list3 (make_float ((double) total_clusters
8795 * sectors_per_cluster
* bytes_per_sector
),
8796 make_float ((double) free_clusters
8797 * sectors_per_cluster
* bytes_per_sector
),
8798 make_float ((double) free_clusters
8799 * sectors_per_cluster
* bytes_per_sector
));
8806 DEFUN ("default-printer-name", Fdefault_printer_name
, Sdefault_printer_name
,
8807 0, 0, 0, doc
: /* Return the name of Windows default printer device. */)
8810 static char pname_buf
[256];
8813 PRINTER_INFO_2
*ppi2
= NULL
;
8814 DWORD dwNeeded
= 0, dwReturned
= 0;
8816 /* Retrieve the default string from Win.ini (the registry).
8817 * String will be in form "printername,drivername,portname".
8818 * This is the most portable way to get the default printer. */
8819 if (GetProfileString ("windows", "device", ",,", pname_buf
, sizeof (pname_buf
)) <= 0)
8821 /* printername precedes first "," character */
8822 strtok (pname_buf
, ",");
8823 /* We want to know more than the printer name */
8824 if (!OpenPrinter (pname_buf
, &hPrn
, NULL
))
8826 GetPrinter (hPrn
, 2, NULL
, 0, &dwNeeded
);
8829 ClosePrinter (hPrn
);
8832 /* Allocate memory for the PRINTER_INFO_2 struct */
8833 ppi2
= (PRINTER_INFO_2
*) xmalloc (dwNeeded
);
8836 ClosePrinter (hPrn
);
8839 /* Call GetPrinter again with big enouth memory block */
8840 err
= GetPrinter (hPrn
, 2, (LPBYTE
)ppi2
, dwNeeded
, &dwReturned
);
8841 ClosePrinter (hPrn
);
8850 if (ppi2
->Attributes
& PRINTER_ATTRIBUTE_SHARED
&& ppi2
->pServerName
)
8852 /* a remote printer */
8853 if (*ppi2
->pServerName
== '\\')
8854 _snprintf (pname_buf
, sizeof (pname_buf
), "%s\\%s", ppi2
->pServerName
,
8857 _snprintf (pname_buf
, sizeof (pname_buf
), "\\\\%s\\%s", ppi2
->pServerName
,
8859 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
8863 /* a local printer */
8864 strncpy (pname_buf
, ppi2
->pPortName
, sizeof (pname_buf
));
8865 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
8866 /* `pPortName' can include several ports, delimited by ','.
8867 * we only use the first one. */
8868 strtok (pname_buf
, ",");
8873 return build_string (pname_buf
);
8876 /***********************************************************************
8878 ***********************************************************************/
8880 /* Keep this list in the same order as frame_parms in frame.c.
8881 Use 0 for unsupported frame parameters. */
8883 frame_parm_handler w32_frame_parm_handlers
[] =
8887 x_set_background_color
,
8893 x_set_foreground_color
,
8896 x_set_internal_border_width
,
8897 x_set_menu_bar_lines
,
8899 x_explicitly_set_name
,
8900 x_set_scroll_bar_width
,
8903 x_set_vertical_scroll_bars
,
8905 x_set_tool_bar_lines
,
8906 0, /* x_set_scroll_bar_foreground, */
8907 0, /* x_set_scroll_bar_background, */
8912 0, /* x_set_wait_for_wm, */
8914 #ifdef USE_FONT_BACKEND
8922 globals_of_w32fns ();
8923 /* This is zero if not using MS-Windows. */
8925 track_mouse_window
= NULL
;
8927 w32_visible_system_caret_hwnd
= NULL
;
8929 DEFSYM (Qnone
, "none");
8930 DEFSYM (Qsuppress_icon
, "suppress-icon");
8931 DEFSYM (Qundefined_color
, "undefined-color");
8932 DEFSYM (Qcancel_timer
, "cancel-timer");
8933 DEFSYM (Qhyper
, "hyper");
8934 DEFSYM (Qsuper
, "super");
8935 DEFSYM (Qmeta
, "meta");
8936 DEFSYM (Qalt
, "alt");
8937 DEFSYM (Qctrl
, "ctrl");
8938 DEFSYM (Qcontrol
, "control");
8939 DEFSYM (Qshift
, "shift");
8940 /* This is the end of symbol initialization. */
8942 /* Text property `display' should be nonsticky by default. */
8943 Vtext_property_default_nonsticky
8944 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
8947 Fput (Qundefined_color
, Qerror_conditions
,
8948 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
8949 Fput (Qundefined_color
, Qerror_message
,
8950 build_string ("Undefined color"));
8952 staticpro (&w32_grabbed_keys
);
8953 w32_grabbed_keys
= Qnil
;
8955 DEFVAR_LISP ("w32-color-map", &Vw32_color_map
,
8956 doc
: /* An array of color name mappings for Windows. */);
8957 Vw32_color_map
= Qnil
;
8959 DEFVAR_LISP ("w32-pass-alt-to-system", &Vw32_pass_alt_to_system
,
8960 doc
: /* Non-nil if Alt key presses are passed on to Windows.
8961 When non-nil, for example, Alt pressed and released and then space will
8962 open the System menu. When nil, Emacs processes the Alt key events, and
8963 then silently swallows them. */);
8964 Vw32_pass_alt_to_system
= Qnil
;
8966 DEFVAR_LISP ("w32-alt-is-meta", &Vw32_alt_is_meta
,
8967 doc
: /* Non-nil if the Alt key is to be considered the same as the META key.
8968 When nil, Emacs will translate the Alt key to the ALT modifier, not to META. */);
8969 Vw32_alt_is_meta
= Qt
;
8971 DEFVAR_INT ("w32-quit-key", &w32_quit_key
,
8972 doc
: /* If non-zero, the virtual key code for an alternative quit key. */);
8975 DEFVAR_LISP ("w32-pass-lwindow-to-system",
8976 &Vw32_pass_lwindow_to_system
,
8977 doc
: /* If non-nil, the left \"Windows\" key is passed on to Windows.
8979 When non-nil, the Start menu is opened by tapping the key.
8980 If you set this to nil, the left \"Windows\" key is processed by Emacs
8981 according to the value of `w32-lwindow-modifier', which see.
8983 Note that some combinations of the left \"Windows\" key with other keys are
8984 caught by Windows at low level, and so binding them in Emacs will have no
8985 effect. For example, <lwindow>-r always pops up the Windows Run dialog,
8986 <lwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
8987 the doc string of `w32-phantom-key-code'. */);
8988 Vw32_pass_lwindow_to_system
= Qt
;
8990 DEFVAR_LISP ("w32-pass-rwindow-to-system",
8991 &Vw32_pass_rwindow_to_system
,
8992 doc
: /* If non-nil, the right \"Windows\" key is passed on to Windows.
8994 When non-nil, the Start menu is opened by tapping the key.
8995 If you set this to nil, the right \"Windows\" key is processed by Emacs
8996 according to the value of `w32-rwindow-modifier', which see.
8998 Note that some combinations of the right \"Windows\" key with other keys are
8999 caught by Windows at low level, and so binding them in Emacs will have no
9000 effect. For example, <rwindow>-r always pops up the Windows Run dialog,
9001 <rwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
9002 the doc string of `w32-phantom-key-code'. */);
9003 Vw32_pass_rwindow_to_system
= Qt
;
9005 DEFVAR_LISP ("w32-phantom-key-code",
9006 &Vw32_phantom_key_code
,
9007 doc
: /* Virtual key code used to generate \"phantom\" key presses.
9008 Value is a number between 0 and 255.
9010 Phantom key presses are generated in order to stop the system from
9011 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or
9012 `w32-pass-rwindow-to-system' is nil. */);
9013 /* Although 255 is technically not a valid key code, it works and
9014 means that this hack won't interfere with any real key code. */
9015 XSETINT (Vw32_phantom_key_code
, 255);
9017 DEFVAR_LISP ("w32-enable-num-lock",
9018 &Vw32_enable_num_lock
,
9019 doc
: /* If non-nil, the Num Lock key acts normally.
9020 Set to nil to handle Num Lock as the `kp-numlock' key. */);
9021 Vw32_enable_num_lock
= Qt
;
9023 DEFVAR_LISP ("w32-enable-caps-lock",
9024 &Vw32_enable_caps_lock
,
9025 doc
: /* If non-nil, the Caps Lock key acts normally.
9026 Set to nil to handle Caps Lock as the `capslock' key. */);
9027 Vw32_enable_caps_lock
= Qt
;
9029 DEFVAR_LISP ("w32-scroll-lock-modifier",
9030 &Vw32_scroll_lock_modifier
,
9031 doc
: /* Modifier to use for the Scroll Lock ON state.
9032 The value can be hyper, super, meta, alt, control or shift for the
9033 respective modifier, or nil to handle Scroll Lock as the `scroll' key.
9034 Any other value will cause the Scroll Lock key to be ignored. */);
9035 Vw32_scroll_lock_modifier
= Qt
;
9037 DEFVAR_LISP ("w32-lwindow-modifier",
9038 &Vw32_lwindow_modifier
,
9039 doc
: /* Modifier to use for the left \"Windows\" key.
9040 The value can be hyper, super, meta, alt, control or shift for the
9041 respective modifier, or nil to appear as the `lwindow' key.
9042 Any other value will cause the key to be ignored. */);
9043 Vw32_lwindow_modifier
= Qnil
;
9045 DEFVAR_LISP ("w32-rwindow-modifier",
9046 &Vw32_rwindow_modifier
,
9047 doc
: /* Modifier to use for the right \"Windows\" key.
9048 The value can be hyper, super, meta, alt, control or shift for the
9049 respective modifier, or nil to appear as the `rwindow' key.
9050 Any other value will cause the key to be ignored. */);
9051 Vw32_rwindow_modifier
= Qnil
;
9053 DEFVAR_LISP ("w32-apps-modifier",
9054 &Vw32_apps_modifier
,
9055 doc
: /* Modifier to use for the \"Apps\" key.
9056 The value can be hyper, super, meta, alt, control or shift for the
9057 respective modifier, or nil to appear as the `apps' key.
9058 Any other value will cause the key to be ignored. */);
9059 Vw32_apps_modifier
= Qnil
;
9061 DEFVAR_BOOL ("w32-enable-synthesized-fonts", &w32_enable_synthesized_fonts
,
9062 doc
: /* Non-nil enables selection of artificially italicized and bold fonts. */);
9063 w32_enable_synthesized_fonts
= 0;
9065 DEFVAR_LISP ("w32-enable-palette", &Vw32_enable_palette
,
9066 doc
: /* Non-nil enables Windows palette management to map colors exactly. */);
9067 Vw32_enable_palette
= Qt
;
9069 DEFVAR_INT ("w32-mouse-button-tolerance",
9070 &w32_mouse_button_tolerance
,
9071 doc
: /* Analogue of double click interval for faking middle mouse events.
9072 The value is the minimum time in milliseconds that must elapse between
9073 left and right button down events before they are considered distinct events.
9074 If both mouse buttons are depressed within this interval, a middle mouse
9075 button down event is generated instead. */);
9076 w32_mouse_button_tolerance
= GetDoubleClickTime () / 2;
9078 DEFVAR_INT ("w32-mouse-move-interval",
9079 &w32_mouse_move_interval
,
9080 doc
: /* Minimum interval between mouse move events.
9081 The value is the minimum time in milliseconds that must elapse between
9082 successive mouse move (or scroll bar drag) events before they are
9083 reported as lisp events. */);
9084 w32_mouse_move_interval
= 0;
9086 DEFVAR_BOOL ("w32-pass-extra-mouse-buttons-to-system",
9087 &w32_pass_extra_mouse_buttons_to_system
,
9088 doc
: /* If non-nil, the fourth and fifth mouse buttons are passed to Windows.
9089 Recent versions of Windows support mice with up to five buttons.
9090 Since most applications don't support these extra buttons, most mouse
9091 drivers will allow you to map them to functions at the system level.
9092 If this variable is non-nil, Emacs will pass them on, allowing the
9093 system to handle them. */);
9094 w32_pass_extra_mouse_buttons_to_system
= 0;
9096 DEFVAR_BOOL ("w32-pass-multimedia-buttons-to-system",
9097 &w32_pass_multimedia_buttons_to_system
,
9098 doc
: /* If non-nil, media buttons are passed to Windows.
9099 Some modern keyboards contain buttons for controlling media players, web
9100 browsers and other applications. Generally these buttons are handled on a
9101 system wide basis, but by setting this to nil they are made available
9102 to Emacs for binding. Depending on your keyboard, additional keys that
9103 may be available are:
9105 browser-back, browser-forward, browser-refresh, browser-stop,
9106 browser-search, browser-favorites, browser-home,
9107 mail, mail-reply, mail-forward, mail-send,
9109 help, find, new, open, close, save, print, undo, redo, copy, cut, paste,
9110 spell-check, correction-list, toggle-dictate-command,
9111 media-next, media-previous, media-stop, media-play-pause, media-select,
9112 media-play, media-pause, media-record, media-fast-forward, media-rewind,
9113 media-channel-up, media-channel-down,
9114 volume-mute, volume-up, volume-down,
9115 mic-volume-mute, mic-volume-down, mic-volume-up, mic-toggle,
9116 bass-down, bass-boost, bass-up, treble-down, treble-up */);
9117 w32_pass_multimedia_buttons_to_system
= 1;
9119 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
9120 doc
: /* The shape of the pointer when over text.
9121 Changing the value does not affect existing frames
9122 unless you set the mouse color. */);
9123 Vx_pointer_shape
= Qnil
;
9125 Vx_nontext_pointer_shape
= Qnil
;
9127 Vx_mode_pointer_shape
= Qnil
;
9129 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
9130 doc
: /* The shape of the pointer when Emacs is busy.
9131 This variable takes effect when you create a new frame
9132 or when you set the mouse color. */);
9133 Vx_hourglass_pointer_shape
= Qnil
;
9135 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
9136 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
9137 display_hourglass_p
= 1;
9139 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
9140 doc
: /* *Seconds to wait before displaying an hourglass pointer.
9141 Value must be an integer or float. */);
9142 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
9144 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
9145 &Vx_sensitive_text_pointer_shape
,
9146 doc
: /* The shape of the pointer when over mouse-sensitive text.
9147 This variable takes effect when you create a new frame
9148 or when you set the mouse color. */);
9149 Vx_sensitive_text_pointer_shape
= Qnil
;
9151 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
9152 &Vx_window_horizontal_drag_shape
,
9153 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
9154 This variable takes effect when you create a new frame
9155 or when you set the mouse color. */);
9156 Vx_window_horizontal_drag_shape
= Qnil
;
9158 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
9159 doc
: /* A string indicating the foreground color of the cursor box. */);
9160 Vx_cursor_fore_pixel
= Qnil
;
9162 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size
,
9163 doc
: /* Maximum size for tooltips.
9164 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
9165 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
9167 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
9168 doc
: /* Non-nil if no window manager is in use.
9169 Emacs doesn't try to figure this out; this is always nil
9170 unless you set it to something else. */);
9171 /* We don't have any way to find this out, so set it to nil
9172 and maybe the user would like to set it to t. */
9173 Vx_no_window_manager
= Qnil
;
9175 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
9176 &Vx_pixel_size_width_font_regexp
,
9177 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
9179 Since Emacs gets width of a font matching with this regexp from
9180 PIXEL_SIZE field of the name, font finding mechanism gets faster for
9181 such a font. This is especially effective for such large fonts as
9182 Chinese, Japanese, and Korean. */);
9183 Vx_pixel_size_width_font_regexp
= Qnil
;
9185 DEFVAR_LISP ("w32-bdf-filename-alist",
9186 &Vw32_bdf_filename_alist
,
9187 doc
: /* List of bdf fonts and their corresponding filenames. */);
9188 Vw32_bdf_filename_alist
= Qnil
;
9190 DEFVAR_BOOL ("w32-strict-fontnames",
9191 &w32_strict_fontnames
,
9192 doc
: /* Non-nil means only use fonts that are exact matches for those requested.
9193 Default is nil, which allows old fontnames that are not XLFD compliant,
9194 and allows third-party CJK display to work by specifying false charset
9195 fields to trick Emacs into translating to Big5, SJIS etc.
9196 Setting this to t will prevent wrong fonts being selected when
9197 fontsets are automatically created. */);
9198 w32_strict_fontnames
= 0;
9200 DEFVAR_BOOL ("w32-strict-painting",
9201 &w32_strict_painting
,
9202 doc
: /* Non-nil means use strict rules for repainting frames.
9203 Set this to nil to get the old behavior for repainting; this should
9204 only be necessary if the default setting causes problems. */);
9205 w32_strict_painting
= 1;
9207 DEFVAR_LISP ("w32-charset-info-alist",
9208 &Vw32_charset_info_alist
,
9209 doc
: /* Alist linking Emacs character sets to Windows fonts and codepages.
9210 Each entry should be of the form:
9212 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE))
9214 where CHARSET_NAME is a string used in font names to identify the charset,
9215 WINDOWS_CHARSET is a symbol that can be one of:
9216 w32-charset-ansi, w32-charset-default, w32-charset-symbol,
9217 w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312,
9218 w32-charset-chinesebig5,
9219 w32-charset-johab, w32-charset-hebrew,
9220 w32-charset-arabic, w32-charset-greek, w32-charset-turkish,
9221 w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope,
9222 w32-charset-russian, w32-charset-mac, w32-charset-baltic,
9223 w32-charset-unicode,
9225 CODEPAGE should be an integer specifying the codepage that should be used
9226 to display the character set, t to do no translation and output as Unicode,
9227 or nil to do no translation and output as 8 bit (or multibyte on far-east
9228 versions of Windows) characters. */);
9229 Vw32_charset_info_alist
= Qnil
;
9231 DEFSYM (Qw32_charset_ansi
, "w32-charset-ansi");
9232 DEFSYM (Qw32_charset_symbol
, "w32-charset-symbol");
9233 DEFSYM (Qw32_charset_default
, "w32-charset-default");
9234 DEFSYM (Qw32_charset_shiftjis
, "w32-charset-shiftjis");
9235 DEFSYM (Qw32_charset_hangeul
, "w32-charset-hangeul");
9236 DEFSYM (Qw32_charset_chinesebig5
, "w32-charset-chinesebig5");
9237 DEFSYM (Qw32_charset_gb2312
, "w32-charset-gb2312");
9238 DEFSYM (Qw32_charset_oem
, "w32-charset-oem");
9240 #ifdef JOHAB_CHARSET
9242 static int w32_extra_charsets_defined
= 1;
9243 DEFVAR_BOOL ("w32-extra-charsets-defined", &w32_extra_charsets_defined
,
9244 doc
: /* Internal variable. */);
9246 DEFSYM (Qw32_charset_johab
, "w32-charset-johab");
9247 DEFSYM (Qw32_charset_easteurope
, "w32-charset-easteurope");
9248 DEFSYM (Qw32_charset_turkish
, "w32-charset-turkish");
9249 DEFSYM (Qw32_charset_baltic
, "w32-charset-baltic");
9250 DEFSYM (Qw32_charset_russian
, "w32-charset-russian");
9251 DEFSYM (Qw32_charset_arabic
, "w32-charset-arabic");
9252 DEFSYM (Qw32_charset_greek
, "w32-charset-greek");
9253 DEFSYM (Qw32_charset_hebrew
, "w32-charset-hebrew");
9254 DEFSYM (Qw32_charset_vietnamese
, "w32-charset-vietnamese");
9255 DEFSYM (Qw32_charset_thai
, "w32-charset-thai");
9256 DEFSYM (Qw32_charset_mac
, "w32-charset-mac");
9260 #ifdef UNICODE_CHARSET
9262 static int w32_unicode_charset_defined
= 1;
9263 DEFVAR_BOOL ("w32-unicode-charset-defined",
9264 &w32_unicode_charset_defined
,
9265 doc
: /* Internal variable. */);
9266 DEFSYM (Qw32_charset_unicode
, "w32-charset-unicode");
9270 #if 0 /* TODO: Port to W32 */
9271 defsubr (&Sx_change_window_property
);
9272 defsubr (&Sx_delete_window_property
);
9273 defsubr (&Sx_window_property
);
9275 defsubr (&Sxw_display_color_p
);
9276 defsubr (&Sx_display_grayscale_p
);
9277 defsubr (&Sxw_color_defined_p
);
9278 defsubr (&Sxw_color_values
);
9279 defsubr (&Sx_server_max_request_size
);
9280 defsubr (&Sx_server_vendor
);
9281 defsubr (&Sx_server_version
);
9282 defsubr (&Sx_display_pixel_width
);
9283 defsubr (&Sx_display_pixel_height
);
9284 defsubr (&Sx_display_mm_width
);
9285 defsubr (&Sx_display_mm_height
);
9286 defsubr (&Sx_display_screens
);
9287 defsubr (&Sx_display_planes
);
9288 defsubr (&Sx_display_color_cells
);
9289 defsubr (&Sx_display_visual_class
);
9290 defsubr (&Sx_display_backing_store
);
9291 defsubr (&Sx_display_save_under
);
9292 defsubr (&Sx_create_frame
);
9293 defsubr (&Sx_open_connection
);
9294 defsubr (&Sx_close_connection
);
9295 defsubr (&Sx_display_list
);
9296 defsubr (&Sx_synchronize
);
9297 defsubr (&Sx_focus_frame
);
9299 /* W32 specific functions */
9301 defsubr (&Sw32_select_font
);
9302 defsubr (&Sw32_define_rgb_color
);
9303 defsubr (&Sw32_default_color_map
);
9304 defsubr (&Sw32_load_color_file
);
9305 defsubr (&Sw32_send_sys_command
);
9306 defsubr (&Sw32_shell_execute
);
9307 defsubr (&Sw32_register_hot_key
);
9308 defsubr (&Sw32_unregister_hot_key
);
9309 defsubr (&Sw32_registered_hot_keys
);
9310 defsubr (&Sw32_reconstruct_hot_key
);
9311 defsubr (&Sw32_toggle_lock_key
);
9312 defsubr (&Sw32_window_exists_p
);
9313 defsubr (&Sw32_find_bdf_fonts
);
9315 defsubr (&Sfile_system_info
);
9316 defsubr (&Sdefault_printer_name
);
9318 /* Setting callback functions for fontset handler. */
9319 get_font_info_func
= w32_get_font_info
;
9321 #if 0 /* This function pointer doesn't seem to be used anywhere.
9322 And the pointer assigned has the wrong type, anyway. */
9323 list_fonts_func
= w32_list_fonts
;
9326 load_font_func
= w32_load_font
;
9327 find_ccl_program_func
= w32_find_ccl_program
;
9328 query_font_func
= w32_query_font
;
9329 set_frame_fontset_func
= x_set_font
;
9330 get_font_repertory_func
= x_get_font_repertory
;
9331 check_window_system_func
= check_w32
;
9334 hourglass_atimer
= NULL
;
9335 hourglass_shown_p
= 0;
9336 defsubr (&Sx_show_tip
);
9337 defsubr (&Sx_hide_tip
);
9339 staticpro (&tip_timer
);
9341 staticpro (&tip_frame
);
9343 last_show_tip_args
= Qnil
;
9344 staticpro (&last_show_tip_args
);
9346 defsubr (&Sx_file_dialog
);
9351 globals_of_w32fns is used to initialize those global variables that
9352 must always be initialized on startup even when the global variable
9353 initialized is non zero (see the function main in emacs.c).
9354 globals_of_w32fns is called from syms_of_w32fns when the global
9355 variable initialized is 0 and directly from main when initialized
9359 globals_of_w32fns ()
9361 HMODULE user32_lib
= GetModuleHandle ("user32.dll");
9363 TrackMouseEvent not available in all versions of Windows, so must load
9364 it dynamically. Do it once, here, instead of every time it is used.
9366 track_mouse_event_fn
= (TrackMouseEvent_Proc
)
9367 GetProcAddress (user32_lib
, "TrackMouseEvent");
9368 /* ditto for GetClipboardSequenceNumber. */
9369 clipboard_sequence_fn
= (ClipboardSequence_Proc
)
9370 GetProcAddress (user32_lib
, "GetClipboardSequenceNumber");
9372 monitor_from_point_fn
= (MonitorFromPoint_Proc
)
9373 GetProcAddress (user32_lib
, "MonitorFromPoint");
9374 get_monitor_info_fn
= (GetMonitorInfo_Proc
)
9375 GetProcAddress (user32_lib
, "GetMonitorInfoA");
9378 HMODULE imm32_lib
= GetModuleHandle ("imm32.dll");
9379 get_composition_string_fn
= (ImmGetCompositionString_Proc
)
9380 GetProcAddress (imm32_lib
, "ImmGetCompositionStringW");
9381 get_ime_context_fn
= (ImmGetContext_Proc
)
9382 GetProcAddress (imm32_lib
, "ImmGetContext");
9384 DEFVAR_INT ("w32-ansi-code-page",
9385 &w32_ansi_code_page
,
9386 doc
: /* The ANSI code page used by the system. */);
9387 w32_ansi_code_page
= GetACP ();
9389 /* MessageBox does not work without this when linked to comctl32.dll 6.0. */
9390 InitCommonControls ();
9391 #ifdef USE_FONT_BACKEND
9392 syms_of_w32uniscribe ();
9402 button
= MessageBox (NULL
,
9403 "A fatal error has occurred!\n\n"
9404 "Would you like to attach a debugger?\n\n"
9405 "Select YES to debug, NO to abort Emacs"
9407 "\n\n(type \"gdb -p <emacs-PID>\" and\n"
9408 "\"continue\" inside GDB before clicking YES.)"
9410 , "Emacs Abort Dialog",
9411 MB_ICONEXCLAMATION
| MB_TASKMODAL
9412 | MB_SETFOREGROUND
| MB_YESNO
);
9417 exit (2); /* tell the compiler we will never return */
9425 /* For convenience when debugging. */
9429 return GetLastError ();
9432 /* arch-tag: 707589ab-b9be-4638-8cdd-74629cc9b446
9433 (do not change this comment) */