1 /* Graphical user interface functions for the Microsoft W32 API.
2 Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 /* Added by Kevin Gallo */
36 #include "intervals.h"
37 #include "dispextern.h"
39 #include "blockinput.h"
41 #include "character.h"
47 #include "termhooks.h"
50 #include "bitmaps/gray.xbm"
58 #define FILE_NAME_TEXT_FIELD edt1
60 #ifdef USE_FONT_BACKEND
64 void syms_of_w32fns ();
65 void globals_of_w32fns ();
67 extern void free_frame_menubar ();
68 extern double atof ();
69 extern int w32_console_toggle_lock_key
P_ ((int, Lisp_Object
));
70 extern void w32_menu_display_help
P_ ((HWND
, HMENU
, UINT
, UINT
));
71 extern void w32_free_menu_strings
P_ ((HWND
));
72 extern XCharStruct
*w32_per_char_metric
P_ ((XFontStruct
*, wchar_t *, int));
76 extern char *lispy_function_keys
[];
78 /* The gray bitmap `bitmaps/gray'. This is done because w32term.c uses
79 it, and including `bitmaps/gray' more than once is a problem when
80 config.h defines `static' as an empty replacement string. */
82 int gray_bitmap_width
= gray_width
;
83 int gray_bitmap_height
= gray_height
;
84 unsigned char *gray_bitmap_bits
= gray_bits
;
86 /* The colormap for converting color names to RGB values */
87 Lisp_Object Vw32_color_map
;
89 /* Non nil if alt key presses are passed on to Windows. */
90 Lisp_Object Vw32_pass_alt_to_system
;
92 /* Non nil if alt key is translated to meta_modifier, nil if it is translated
94 Lisp_Object Vw32_alt_is_meta
;
96 /* If non-zero, the windows virtual key code for an alternative quit key. */
99 /* Non nil if left window key events are passed on to Windows (this only
100 affects whether "tapping" the key opens the Start menu). */
101 Lisp_Object Vw32_pass_lwindow_to_system
;
103 /* Non nil if right window key events are passed on to Windows (this
104 only affects whether "tapping" the key opens the Start menu). */
105 Lisp_Object Vw32_pass_rwindow_to_system
;
107 /* Virtual key code used to generate "phantom" key presses in order
108 to stop system from acting on Windows key events. */
109 Lisp_Object Vw32_phantom_key_code
;
111 /* Modifier associated with the left "Windows" key, or nil to act as a
113 Lisp_Object Vw32_lwindow_modifier
;
115 /* Modifier associated with the right "Windows" key, or nil to act as a
117 Lisp_Object Vw32_rwindow_modifier
;
119 /* Modifier associated with the "Apps" key, or nil to act as a normal
121 Lisp_Object Vw32_apps_modifier
;
123 /* Value is nil if Num Lock acts as a function key. */
124 Lisp_Object Vw32_enable_num_lock
;
126 /* Value is nil if Caps Lock acts as a function key. */
127 Lisp_Object Vw32_enable_caps_lock
;
129 /* Modifier associated with Scroll Lock, or nil to act as a normal key. */
130 Lisp_Object Vw32_scroll_lock_modifier
;
132 /* Switch to control whether we inhibit requests for synthesized bold
133 and italic versions of fonts. */
134 int w32_enable_synthesized_fonts
;
136 /* Enable palette management. */
137 Lisp_Object Vw32_enable_palette
;
139 /* Control how close left/right button down events must be to
140 be converted to a middle button down event. */
141 int w32_mouse_button_tolerance
;
143 /* Minimum interval between mouse movement (and scroll bar drag)
144 events that are passed on to the event loop. */
145 int w32_mouse_move_interval
;
147 /* Flag to indicate if XBUTTON events should be passed on to Windows. */
148 int w32_pass_extra_mouse_buttons_to_system
;
150 /* Non nil if no window manager is in use. */
151 Lisp_Object Vx_no_window_manager
;
153 /* Non-zero means we're allowed to display a hourglass pointer. */
155 int display_hourglass_p
;
157 /* The background and shape of the mouse pointer, and shape when not
158 over text or in the modeline. */
160 Lisp_Object Vx_pointer_shape
, Vx_nontext_pointer_shape
, Vx_mode_pointer_shape
;
161 Lisp_Object Vx_hourglass_pointer_shape
, Vx_window_horizontal_drag_shape
;
163 /* The shape when over mouse-sensitive text. */
165 Lisp_Object Vx_sensitive_text_pointer_shape
;
168 #define IDC_HAND MAKEINTRESOURCE(32649)
171 /* Color of chars displayed in cursor box. */
173 Lisp_Object Vx_cursor_fore_pixel
;
175 /* Nonzero if using Windows. */
177 static int w32_in_use
;
179 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
181 Lisp_Object Vx_pixel_size_width_font_regexp
;
183 /* Alist of bdf fonts and the files that define them. */
184 Lisp_Object Vw32_bdf_filename_alist
;
186 /* A flag to control whether fonts are matched strictly or not. */
187 int w32_strict_fontnames
;
189 /* A flag to control whether we should only repaint if GetUpdateRect
190 indicates there is an update region. */
191 int w32_strict_painting
;
193 /* Associative list linking character set strings to Windows codepages. */
194 Lisp_Object Vw32_charset_info_alist
;
196 /* VIETNAMESE_CHARSET is not defined in some versions of MSVC. */
197 #ifndef VIETNAMESE_CHARSET
198 #define VIETNAMESE_CHARSET 163
202 Lisp_Object Qsuppress_icon
;
203 Lisp_Object Qundefined_color
;
204 Lisp_Object Qcancel_timer
;
210 Lisp_Object Qcontrol
;
213 Lisp_Object Qw32_charset_ansi
;
214 Lisp_Object Qw32_charset_default
;
215 Lisp_Object Qw32_charset_symbol
;
216 Lisp_Object Qw32_charset_shiftjis
;
217 Lisp_Object Qw32_charset_hangeul
;
218 Lisp_Object Qw32_charset_gb2312
;
219 Lisp_Object Qw32_charset_chinesebig5
;
220 Lisp_Object Qw32_charset_oem
;
222 #ifndef JOHAB_CHARSET
223 #define JOHAB_CHARSET 130
226 Lisp_Object Qw32_charset_easteurope
;
227 Lisp_Object Qw32_charset_turkish
;
228 Lisp_Object Qw32_charset_baltic
;
229 Lisp_Object Qw32_charset_russian
;
230 Lisp_Object Qw32_charset_arabic
;
231 Lisp_Object Qw32_charset_greek
;
232 Lisp_Object Qw32_charset_hebrew
;
233 Lisp_Object Qw32_charset_vietnamese
;
234 Lisp_Object Qw32_charset_thai
;
235 Lisp_Object Qw32_charset_johab
;
236 Lisp_Object Qw32_charset_mac
;
239 #ifdef UNICODE_CHARSET
240 Lisp_Object Qw32_charset_unicode
;
243 /* The ANSI codepage. */
244 int w32_ansi_code_page
;
246 /* Prefix for system colors. */
247 #define SYSTEM_COLOR_PREFIX "System"
248 #define SYSTEM_COLOR_PREFIX_LEN (sizeof (SYSTEM_COLOR_PREFIX) - 1)
250 /* State variables for emulating a three button mouse. */
255 static int button_state
= 0;
256 static W32Msg saved_mouse_button_msg
;
257 static unsigned mouse_button_timer
= 0; /* non-zero when timer is active */
258 static W32Msg saved_mouse_move_msg
;
259 static unsigned mouse_move_timer
= 0;
261 /* Window that is tracking the mouse. */
262 static HWND track_mouse_window
;
264 typedef BOOL (WINAPI
* TrackMouseEvent_Proc
)
265 (IN OUT LPTRACKMOUSEEVENT lpEventTrack
);
267 TrackMouseEvent_Proc track_mouse_event_fn
= NULL
;
268 ClipboardSequence_Proc clipboard_sequence_fn
= NULL
;
269 extern AppendMenuW_Proc unicode_append_menu
;
271 /* W95 mousewheel handler */
272 unsigned int msh_mousewheel
= 0;
275 #define MOUSE_BUTTON_ID 1
276 #define MOUSE_MOVE_ID 2
277 #define MENU_FREE_ID 3
278 /* The delay (milliseconds) before a menu is freed after WM_EXITMENULOOP
280 #define MENU_FREE_DELAY 1000
281 static unsigned menu_free_timer
= 0;
283 /* The below are defined in frame.c. */
285 extern Lisp_Object Vwindow_system_version
;
288 int image_cache_refcount
, dpyinfo_refcount
;
292 /* From w32term.c. */
293 extern int w32_num_mouse_buttons
;
294 extern Lisp_Object Vw32_recognize_altgr
;
296 extern HWND w32_system_caret_hwnd
;
298 extern int w32_system_caret_height
;
299 extern int w32_system_caret_x
;
300 extern int w32_system_caret_y
;
301 extern int w32_use_visible_system_caret
;
303 static HWND w32_visible_system_caret_hwnd
;
306 extern HMENU current_popup_menu
;
307 static int menubar_in_use
= 0;
310 /* Error if we are not connected to MS-Windows. */
315 error ("MS-Windows not in use or not initialized");
318 /* Nonzero if we can use mouse menus.
319 You should not call this unless HAVE_MENUS is defined. */
327 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
328 and checking validity for W32. */
331 check_x_frame (frame
)
337 frame
= selected_frame
;
338 CHECK_LIVE_FRAME (frame
);
340 if (! FRAME_W32_P (f
))
341 error ("Non-W32 frame used");
345 /* Let the user specify a display with a frame.
346 nil stands for the selected frame--or, if that is not a w32 frame,
347 the first display on the list. */
349 struct w32_display_info
*
350 check_x_display_info (frame
)
355 struct frame
*sf
= XFRAME (selected_frame
);
357 if (FRAME_W32_P (sf
) && FRAME_LIVE_P (sf
))
358 return FRAME_W32_DISPLAY_INFO (sf
);
360 return &one_w32_display_info
;
362 else if (STRINGP (frame
))
363 return x_display_info_for_name (frame
);
368 CHECK_LIVE_FRAME (frame
);
370 if (! FRAME_W32_P (f
))
371 error ("Non-W32 frame used");
372 return FRAME_W32_DISPLAY_INFO (f
);
376 /* Return the Emacs frame-object corresponding to an w32 window.
377 It could be the frame's main window or an icon window. */
379 /* This function can be called during GC, so use GC_xxx type test macros. */
382 x_window_to_frame (dpyinfo
, wdesc
)
383 struct w32_display_info
*dpyinfo
;
386 Lisp_Object tail
, frame
;
389 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
392 if (!GC_FRAMEP (frame
))
395 if (!FRAME_W32_P (f
) || FRAME_W32_DISPLAY_INFO (f
) != dpyinfo
)
397 if (f
->output_data
.w32
->hourglass_window
== wdesc
)
400 if (FRAME_W32_WINDOW (f
) == wdesc
)
407 static Lisp_Object unwind_create_frame
P_ ((Lisp_Object
));
408 static Lisp_Object unwind_create_tip_frame
P_ ((Lisp_Object
));
409 static void my_create_window
P_ ((struct frame
*));
410 static void my_create_tip_window
P_ ((struct frame
*));
412 /* TODO: Native Input Method support; see x_create_im. */
413 void x_set_foreground_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
414 void x_set_background_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
415 void x_set_mouse_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
416 void x_set_cursor_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
417 void x_set_border_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
418 void x_set_cursor_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
419 void x_set_icon_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
420 void x_set_icon_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
421 void x_explicitly_set_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
422 void x_set_menu_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
423 void x_set_title
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
424 void x_set_tool_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
425 static void x_edge_detection
P_ ((struct frame
*, struct image
*, Lisp_Object
,
431 /* Store the screen positions of frame F into XPTR and YPTR.
432 These are the positions of the containing window manager window,
433 not Emacs's own window. */
436 x_real_positions (f
, xptr
, yptr
)
443 GetClientRect(FRAME_W32_WINDOW(f
), &rect
);
444 AdjustWindowRect(&rect
, f
->output_data
.w32
->dwStyle
, FRAME_EXTERNAL_MENU_BAR(f
));
449 ClientToScreen (FRAME_W32_WINDOW(f
), &pt
);
451 /* Remember x_pixels_diff and y_pixels_diff. */
452 f
->x_pixels_diff
= pt
.x
- rect
.left
;
453 f
->y_pixels_diff
= pt
.y
- rect
.top
;
461 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
,
462 Sw32_define_rgb_color
, 4, 4, 0,
463 doc
: /* Convert RGB numbers to a windows color reference and associate with NAME.
464 This adds or updates a named color to w32-color-map, making it
465 available for use. The original entry's RGB ref is returned, or nil
466 if the entry is new. */)
467 (red
, green
, blue
, name
)
468 Lisp_Object red
, green
, blue
, name
;
471 Lisp_Object oldrgb
= Qnil
;
475 CHECK_NUMBER (green
);
479 XSETINT (rgb
, RGB(XUINT (red
), XUINT (green
), XUINT (blue
)));
483 /* replace existing entry in w32-color-map or add new entry. */
484 entry
= Fassoc (name
, Vw32_color_map
);
487 entry
= Fcons (name
, rgb
);
488 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
492 oldrgb
= Fcdr (entry
);
493 Fsetcdr (entry
, rgb
);
501 DEFUN ("w32-load-color-file", Fw32_load_color_file
,
502 Sw32_load_color_file
, 1, 1, 0,
503 doc
: /* Create an alist of color entries from an external file.
504 Assign this value to w32-color-map to replace the existing color map.
506 The file should define one named RGB color per line like so:
508 where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
510 Lisp_Object filename
;
513 Lisp_Object cmap
= Qnil
;
516 CHECK_STRING (filename
);
517 abspath
= Fexpand_file_name (filename
, Qnil
);
519 fp
= fopen (SDATA (filename
), "rt");
523 int red
, green
, blue
;
528 while (fgets (buf
, sizeof (buf
), fp
) != NULL
) {
529 if (sscanf (buf
, "%u %u %u %n", &red
, &green
, &blue
, &num
) == 3)
531 char *name
= buf
+ num
;
532 num
= strlen (name
) - 1;
533 if (name
[num
] == '\n')
535 cmap
= Fcons (Fcons (build_string (name
),
536 make_number (RGB (red
, green
, blue
))),
548 /* The default colors for the w32 color map */
549 typedef struct colormap_t
555 colormap_t w32_color_map
[] =
557 {"snow" , PALETTERGB (255,250,250)},
558 {"ghost white" , PALETTERGB (248,248,255)},
559 {"GhostWhite" , PALETTERGB (248,248,255)},
560 {"white smoke" , PALETTERGB (245,245,245)},
561 {"WhiteSmoke" , PALETTERGB (245,245,245)},
562 {"gainsboro" , PALETTERGB (220,220,220)},
563 {"floral white" , PALETTERGB (255,250,240)},
564 {"FloralWhite" , PALETTERGB (255,250,240)},
565 {"old lace" , PALETTERGB (253,245,230)},
566 {"OldLace" , PALETTERGB (253,245,230)},
567 {"linen" , PALETTERGB (250,240,230)},
568 {"antique white" , PALETTERGB (250,235,215)},
569 {"AntiqueWhite" , PALETTERGB (250,235,215)},
570 {"papaya whip" , PALETTERGB (255,239,213)},
571 {"PapayaWhip" , PALETTERGB (255,239,213)},
572 {"blanched almond" , PALETTERGB (255,235,205)},
573 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
574 {"bisque" , PALETTERGB (255,228,196)},
575 {"peach puff" , PALETTERGB (255,218,185)},
576 {"PeachPuff" , PALETTERGB (255,218,185)},
577 {"navajo white" , PALETTERGB (255,222,173)},
578 {"NavajoWhite" , PALETTERGB (255,222,173)},
579 {"moccasin" , PALETTERGB (255,228,181)},
580 {"cornsilk" , PALETTERGB (255,248,220)},
581 {"ivory" , PALETTERGB (255,255,240)},
582 {"lemon chiffon" , PALETTERGB (255,250,205)},
583 {"LemonChiffon" , PALETTERGB (255,250,205)},
584 {"seashell" , PALETTERGB (255,245,238)},
585 {"honeydew" , PALETTERGB (240,255,240)},
586 {"mint cream" , PALETTERGB (245,255,250)},
587 {"MintCream" , PALETTERGB (245,255,250)},
588 {"azure" , PALETTERGB (240,255,255)},
589 {"alice blue" , PALETTERGB (240,248,255)},
590 {"AliceBlue" , PALETTERGB (240,248,255)},
591 {"lavender" , PALETTERGB (230,230,250)},
592 {"lavender blush" , PALETTERGB (255,240,245)},
593 {"LavenderBlush" , PALETTERGB (255,240,245)},
594 {"misty rose" , PALETTERGB (255,228,225)},
595 {"MistyRose" , PALETTERGB (255,228,225)},
596 {"white" , PALETTERGB (255,255,255)},
597 {"black" , PALETTERGB ( 0, 0, 0)},
598 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
599 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
600 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
601 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
602 {"dim gray" , PALETTERGB (105,105,105)},
603 {"DimGray" , PALETTERGB (105,105,105)},
604 {"dim grey" , PALETTERGB (105,105,105)},
605 {"DimGrey" , PALETTERGB (105,105,105)},
606 {"slate gray" , PALETTERGB (112,128,144)},
607 {"SlateGray" , PALETTERGB (112,128,144)},
608 {"slate grey" , PALETTERGB (112,128,144)},
609 {"SlateGrey" , PALETTERGB (112,128,144)},
610 {"light slate gray" , PALETTERGB (119,136,153)},
611 {"LightSlateGray" , PALETTERGB (119,136,153)},
612 {"light slate grey" , PALETTERGB (119,136,153)},
613 {"LightSlateGrey" , PALETTERGB (119,136,153)},
614 {"gray" , PALETTERGB (190,190,190)},
615 {"grey" , PALETTERGB (190,190,190)},
616 {"light grey" , PALETTERGB (211,211,211)},
617 {"LightGrey" , PALETTERGB (211,211,211)},
618 {"light gray" , PALETTERGB (211,211,211)},
619 {"LightGray" , PALETTERGB (211,211,211)},
620 {"midnight blue" , PALETTERGB ( 25, 25,112)},
621 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
622 {"navy" , PALETTERGB ( 0, 0,128)},
623 {"navy blue" , PALETTERGB ( 0, 0,128)},
624 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
625 {"cornflower blue" , PALETTERGB (100,149,237)},
626 {"CornflowerBlue" , PALETTERGB (100,149,237)},
627 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
628 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
629 {"slate blue" , PALETTERGB (106, 90,205)},
630 {"SlateBlue" , PALETTERGB (106, 90,205)},
631 {"medium slate blue" , PALETTERGB (123,104,238)},
632 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
633 {"light slate blue" , PALETTERGB (132,112,255)},
634 {"LightSlateBlue" , PALETTERGB (132,112,255)},
635 {"medium blue" , PALETTERGB ( 0, 0,205)},
636 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
637 {"royal blue" , PALETTERGB ( 65,105,225)},
638 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
639 {"blue" , PALETTERGB ( 0, 0,255)},
640 {"dodger blue" , PALETTERGB ( 30,144,255)},
641 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
642 {"deep sky blue" , PALETTERGB ( 0,191,255)},
643 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
644 {"sky blue" , PALETTERGB (135,206,235)},
645 {"SkyBlue" , PALETTERGB (135,206,235)},
646 {"light sky blue" , PALETTERGB (135,206,250)},
647 {"LightSkyBlue" , PALETTERGB (135,206,250)},
648 {"steel blue" , PALETTERGB ( 70,130,180)},
649 {"SteelBlue" , PALETTERGB ( 70,130,180)},
650 {"light steel blue" , PALETTERGB (176,196,222)},
651 {"LightSteelBlue" , PALETTERGB (176,196,222)},
652 {"light blue" , PALETTERGB (173,216,230)},
653 {"LightBlue" , PALETTERGB (173,216,230)},
654 {"powder blue" , PALETTERGB (176,224,230)},
655 {"PowderBlue" , PALETTERGB (176,224,230)},
656 {"pale turquoise" , PALETTERGB (175,238,238)},
657 {"PaleTurquoise" , PALETTERGB (175,238,238)},
658 {"dark turquoise" , PALETTERGB ( 0,206,209)},
659 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
660 {"medium turquoise" , PALETTERGB ( 72,209,204)},
661 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
662 {"turquoise" , PALETTERGB ( 64,224,208)},
663 {"cyan" , PALETTERGB ( 0,255,255)},
664 {"light cyan" , PALETTERGB (224,255,255)},
665 {"LightCyan" , PALETTERGB (224,255,255)},
666 {"cadet blue" , PALETTERGB ( 95,158,160)},
667 {"CadetBlue" , PALETTERGB ( 95,158,160)},
668 {"medium aquamarine" , PALETTERGB (102,205,170)},
669 {"MediumAquamarine" , PALETTERGB (102,205,170)},
670 {"aquamarine" , PALETTERGB (127,255,212)},
671 {"dark green" , PALETTERGB ( 0,100, 0)},
672 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
673 {"dark olive green" , PALETTERGB ( 85,107, 47)},
674 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
675 {"dark sea green" , PALETTERGB (143,188,143)},
676 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
677 {"sea green" , PALETTERGB ( 46,139, 87)},
678 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
679 {"medium sea green" , PALETTERGB ( 60,179,113)},
680 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
681 {"light sea green" , PALETTERGB ( 32,178,170)},
682 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
683 {"pale green" , PALETTERGB (152,251,152)},
684 {"PaleGreen" , PALETTERGB (152,251,152)},
685 {"spring green" , PALETTERGB ( 0,255,127)},
686 {"SpringGreen" , PALETTERGB ( 0,255,127)},
687 {"lawn green" , PALETTERGB (124,252, 0)},
688 {"LawnGreen" , PALETTERGB (124,252, 0)},
689 {"green" , PALETTERGB ( 0,255, 0)},
690 {"chartreuse" , PALETTERGB (127,255, 0)},
691 {"medium spring green" , PALETTERGB ( 0,250,154)},
692 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
693 {"green yellow" , PALETTERGB (173,255, 47)},
694 {"GreenYellow" , PALETTERGB (173,255, 47)},
695 {"lime green" , PALETTERGB ( 50,205, 50)},
696 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
697 {"yellow green" , PALETTERGB (154,205, 50)},
698 {"YellowGreen" , PALETTERGB (154,205, 50)},
699 {"forest green" , PALETTERGB ( 34,139, 34)},
700 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
701 {"olive drab" , PALETTERGB (107,142, 35)},
702 {"OliveDrab" , PALETTERGB (107,142, 35)},
703 {"dark khaki" , PALETTERGB (189,183,107)},
704 {"DarkKhaki" , PALETTERGB (189,183,107)},
705 {"khaki" , PALETTERGB (240,230,140)},
706 {"pale goldenrod" , PALETTERGB (238,232,170)},
707 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
708 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
709 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
710 {"light yellow" , PALETTERGB (255,255,224)},
711 {"LightYellow" , PALETTERGB (255,255,224)},
712 {"yellow" , PALETTERGB (255,255, 0)},
713 {"gold" , PALETTERGB (255,215, 0)},
714 {"light goldenrod" , PALETTERGB (238,221,130)},
715 {"LightGoldenrod" , PALETTERGB (238,221,130)},
716 {"goldenrod" , PALETTERGB (218,165, 32)},
717 {"dark goldenrod" , PALETTERGB (184,134, 11)},
718 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
719 {"rosy brown" , PALETTERGB (188,143,143)},
720 {"RosyBrown" , PALETTERGB (188,143,143)},
721 {"indian red" , PALETTERGB (205, 92, 92)},
722 {"IndianRed" , PALETTERGB (205, 92, 92)},
723 {"saddle brown" , PALETTERGB (139, 69, 19)},
724 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
725 {"sienna" , PALETTERGB (160, 82, 45)},
726 {"peru" , PALETTERGB (205,133, 63)},
727 {"burlywood" , PALETTERGB (222,184,135)},
728 {"beige" , PALETTERGB (245,245,220)},
729 {"wheat" , PALETTERGB (245,222,179)},
730 {"sandy brown" , PALETTERGB (244,164, 96)},
731 {"SandyBrown" , PALETTERGB (244,164, 96)},
732 {"tan" , PALETTERGB (210,180,140)},
733 {"chocolate" , PALETTERGB (210,105, 30)},
734 {"firebrick" , PALETTERGB (178,34, 34)},
735 {"brown" , PALETTERGB (165,42, 42)},
736 {"dark salmon" , PALETTERGB (233,150,122)},
737 {"DarkSalmon" , PALETTERGB (233,150,122)},
738 {"salmon" , PALETTERGB (250,128,114)},
739 {"light salmon" , PALETTERGB (255,160,122)},
740 {"LightSalmon" , PALETTERGB (255,160,122)},
741 {"orange" , PALETTERGB (255,165, 0)},
742 {"dark orange" , PALETTERGB (255,140, 0)},
743 {"DarkOrange" , PALETTERGB (255,140, 0)},
744 {"coral" , PALETTERGB (255,127, 80)},
745 {"light coral" , PALETTERGB (240,128,128)},
746 {"LightCoral" , PALETTERGB (240,128,128)},
747 {"tomato" , PALETTERGB (255, 99, 71)},
748 {"orange red" , PALETTERGB (255, 69, 0)},
749 {"OrangeRed" , PALETTERGB (255, 69, 0)},
750 {"red" , PALETTERGB (255, 0, 0)},
751 {"hot pink" , PALETTERGB (255,105,180)},
752 {"HotPink" , PALETTERGB (255,105,180)},
753 {"deep pink" , PALETTERGB (255, 20,147)},
754 {"DeepPink" , PALETTERGB (255, 20,147)},
755 {"pink" , PALETTERGB (255,192,203)},
756 {"light pink" , PALETTERGB (255,182,193)},
757 {"LightPink" , PALETTERGB (255,182,193)},
758 {"pale violet red" , PALETTERGB (219,112,147)},
759 {"PaleVioletRed" , PALETTERGB (219,112,147)},
760 {"maroon" , PALETTERGB (176, 48, 96)},
761 {"medium violet red" , PALETTERGB (199, 21,133)},
762 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
763 {"violet red" , PALETTERGB (208, 32,144)},
764 {"VioletRed" , PALETTERGB (208, 32,144)},
765 {"magenta" , PALETTERGB (255, 0,255)},
766 {"violet" , PALETTERGB (238,130,238)},
767 {"plum" , PALETTERGB (221,160,221)},
768 {"orchid" , PALETTERGB (218,112,214)},
769 {"medium orchid" , PALETTERGB (186, 85,211)},
770 {"MediumOrchid" , PALETTERGB (186, 85,211)},
771 {"dark orchid" , PALETTERGB (153, 50,204)},
772 {"DarkOrchid" , PALETTERGB (153, 50,204)},
773 {"dark violet" , PALETTERGB (148, 0,211)},
774 {"DarkViolet" , PALETTERGB (148, 0,211)},
775 {"blue violet" , PALETTERGB (138, 43,226)},
776 {"BlueViolet" , PALETTERGB (138, 43,226)},
777 {"purple" , PALETTERGB (160, 32,240)},
778 {"medium purple" , PALETTERGB (147,112,219)},
779 {"MediumPurple" , PALETTERGB (147,112,219)},
780 {"thistle" , PALETTERGB (216,191,216)},
781 {"gray0" , PALETTERGB ( 0, 0, 0)},
782 {"grey0" , PALETTERGB ( 0, 0, 0)},
783 {"dark grey" , PALETTERGB (169,169,169)},
784 {"DarkGrey" , PALETTERGB (169,169,169)},
785 {"dark gray" , PALETTERGB (169,169,169)},
786 {"DarkGray" , PALETTERGB (169,169,169)},
787 {"dark blue" , PALETTERGB ( 0, 0,139)},
788 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
789 {"dark cyan" , PALETTERGB ( 0,139,139)},
790 {"DarkCyan" , PALETTERGB ( 0,139,139)},
791 {"dark magenta" , PALETTERGB (139, 0,139)},
792 {"DarkMagenta" , PALETTERGB (139, 0,139)},
793 {"dark red" , PALETTERGB (139, 0, 0)},
794 {"DarkRed" , PALETTERGB (139, 0, 0)},
795 {"light green" , PALETTERGB (144,238,144)},
796 {"LightGreen" , PALETTERGB (144,238,144)},
799 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
800 0, 0, 0, doc
: /* Return the default color map. */)
804 colormap_t
*pc
= w32_color_map
;
811 for (i
= 0; i
< sizeof (w32_color_map
) / sizeof (w32_color_map
[0]);
813 cmap
= Fcons (Fcons (build_string (pc
->name
),
814 make_number (pc
->colorref
)),
832 color
= Frassq (rgb
, Vw32_color_map
);
837 return (Fcar (color
));
843 w32_color_map_lookup (colorname
)
846 Lisp_Object tail
, ret
= Qnil
;
850 for (tail
= Vw32_color_map
; !NILP (tail
); tail
= Fcdr (tail
))
852 register Lisp_Object elt
, tem
;
855 if (!CONSP (elt
)) continue;
859 if (lstrcmpi (SDATA (tem
), colorname
) == 0)
876 add_system_logical_colors_to_map (system_colors
)
877 Lisp_Object
*system_colors
;
881 /* Other registry operations are done with input blocked. */
884 /* Look for "Control Panel/Colors" under User and Machine registry
886 if (RegOpenKeyEx (HKEY_CURRENT_USER
, "Control Panel\\Colors", 0,
887 KEY_READ
, &colors_key
) == ERROR_SUCCESS
888 || RegOpenKeyEx (HKEY_LOCAL_MACHINE
, "Control Panel\\Colors", 0,
889 KEY_READ
, &colors_key
) == ERROR_SUCCESS
)
892 char color_buffer
[64];
893 char full_name_buffer
[MAX_PATH
+ SYSTEM_COLOR_PREFIX_LEN
];
895 DWORD name_size
, color_size
;
896 char *name_buffer
= full_name_buffer
+ SYSTEM_COLOR_PREFIX_LEN
;
898 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
899 color_size
= sizeof (color_buffer
);
901 strcpy (full_name_buffer
, SYSTEM_COLOR_PREFIX
);
903 while (RegEnumValueA (colors_key
, index
, name_buffer
, &name_size
,
904 NULL
, NULL
, color_buffer
, &color_size
)
908 if (sscanf (color_buffer
, " %u %u %u", &r
, &g
, &b
) == 3)
909 *system_colors
= Fcons (Fcons (build_string (full_name_buffer
),
910 make_number (RGB (r
, g
, b
))),
913 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
914 color_size
= sizeof (color_buffer
);
917 RegCloseKey (colors_key
);
925 x_to_w32_color (colorname
)
928 register Lisp_Object ret
= Qnil
;
932 if (colorname
[0] == '#')
934 /* Could be an old-style RGB Device specification. */
937 color
= colorname
+ 1;
939 size
= strlen(color
);
940 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
948 for (i
= 0; i
< 3; i
++)
954 /* The check for 'x' in the following conditional takes into
955 account the fact that strtol allows a "0x" in front of
956 our numbers, and we don't. */
957 if (!isxdigit(color
[0]) || color
[1] == 'x')
961 value
= strtoul(color
, &end
, 16);
963 if (errno
== ERANGE
|| end
- color
!= size
)
968 value
= value
* 0x10;
979 colorval
|= (value
<< pos
);
984 XSETINT (ret
, colorval
);
991 else if (strnicmp(colorname
, "rgb:", 4) == 0)
999 color
= colorname
+ 4;
1000 for (i
= 0; i
< 3; i
++)
1003 unsigned long value
;
1005 /* The check for 'x' in the following conditional takes into
1006 account the fact that strtol allows a "0x" in front of
1007 our numbers, and we don't. */
1008 if (!isxdigit(color
[0]) || color
[1] == 'x')
1010 value
= strtoul(color
, &end
, 16);
1011 if (errno
== ERANGE
)
1013 switch (end
- color
)
1016 value
= value
* 0x10 + value
;
1029 if (value
== ULONG_MAX
)
1031 colorval
|= (value
<< pos
);
1038 XSETINT (ret
, colorval
);
1046 else if (strnicmp(colorname
, "rgbi:", 5) == 0)
1048 /* This is an RGB Intensity specification. */
1055 color
= colorname
+ 5;
1056 for (i
= 0; i
< 3; i
++)
1062 value
= strtod(color
, &end
);
1063 if (errno
== ERANGE
)
1065 if (value
< 0.0 || value
> 1.0)
1067 val
= (UINT
)(0x100 * value
);
1068 /* We used 0x100 instead of 0xFF to give a continuous
1069 range between 0.0 and 1.0 inclusive. The next statement
1070 fixes the 1.0 case. */
1073 colorval
|= (val
<< pos
);
1080 XSETINT (ret
, colorval
);
1088 /* I am not going to attempt to handle any of the CIE color schemes
1089 or TekHVC, since I don't know the algorithms for conversion to
1092 /* If we fail to lookup the color name in w32_color_map, then check the
1093 colorname to see if it can be crudely approximated: If the X color
1094 ends in a number (e.g., "darkseagreen2"), strip the number and
1095 return the result of looking up the base color name. */
1096 ret
= w32_color_map_lookup (colorname
);
1099 int len
= strlen (colorname
);
1101 if (isdigit (colorname
[len
- 1]))
1103 char *ptr
, *approx
= alloca (len
+ 1);
1105 strcpy (approx
, colorname
);
1106 ptr
= &approx
[len
- 1];
1107 while (ptr
> approx
&& isdigit (*ptr
))
1110 ret
= w32_color_map_lookup (approx
);
1119 w32_regenerate_palette (FRAME_PTR f
)
1121 struct w32_palette_entry
* list
;
1122 LOGPALETTE
* log_palette
;
1123 HPALETTE new_palette
;
1126 /* don't bother trying to create palette if not supported */
1127 if (! FRAME_W32_DISPLAY_INFO (f
)->has_palette
)
1130 log_palette
= (LOGPALETTE
*)
1131 alloca (sizeof (LOGPALETTE
) +
1132 FRAME_W32_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
1133 log_palette
->palVersion
= 0x300;
1134 log_palette
->palNumEntries
= FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1136 list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1138 i
< FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1139 i
++, list
= list
->next
)
1140 log_palette
->palPalEntry
[i
] = list
->entry
;
1142 new_palette
= CreatePalette (log_palette
);
1146 if (FRAME_W32_DISPLAY_INFO (f
)->palette
)
1147 DeleteObject (FRAME_W32_DISPLAY_INFO (f
)->palette
);
1148 FRAME_W32_DISPLAY_INFO (f
)->palette
= new_palette
;
1150 /* Realize display palette and garbage all frames. */
1151 release_frame_dc (f
, get_frame_dc (f
));
1156 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
1157 #define SET_W32_COLOR(pe, color) \
1160 pe.peRed = GetRValue (color); \
1161 pe.peGreen = GetGValue (color); \
1162 pe.peBlue = GetBValue (color); \
1167 /* Keep these around in case we ever want to track color usage. */
1169 w32_map_color (FRAME_PTR f
, COLORREF color
)
1171 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1173 if (NILP (Vw32_enable_palette
))
1176 /* check if color is already mapped */
1179 if (W32_COLOR (list
->entry
) == color
)
1187 /* not already mapped, so add to list and recreate Windows palette */
1188 list
= (struct w32_palette_entry
*)
1189 xmalloc (sizeof (struct w32_palette_entry
));
1190 SET_W32_COLOR (list
->entry
, color
);
1192 list
->next
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1193 FRAME_W32_DISPLAY_INFO (f
)->color_list
= list
;
1194 FRAME_W32_DISPLAY_INFO (f
)->num_colors
++;
1196 /* set flag that palette must be regenerated */
1197 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1201 w32_unmap_color (FRAME_PTR f
, COLORREF color
)
1203 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1204 struct w32_palette_entry
**prev
= &FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1206 if (NILP (Vw32_enable_palette
))
1209 /* check if color is already mapped */
1212 if (W32_COLOR (list
->entry
) == color
)
1214 if (--list
->refcount
== 0)
1218 FRAME_W32_DISPLAY_INFO (f
)->num_colors
--;
1228 /* set flag that palette must be regenerated */
1229 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1234 /* Gamma-correct COLOR on frame F. */
1237 gamma_correct (f
, color
)
1243 *color
= PALETTERGB (
1244 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1245 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1246 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1251 /* Decide if color named COLOR is valid for the display associated with
1252 the selected frame; if so, return the rgb values in COLOR_DEF.
1253 If ALLOC is nonzero, allocate a new colormap cell. */
1256 w32_defined_color (f
, color
, color_def
, alloc
)
1262 register Lisp_Object tem
;
1263 COLORREF w32_color_ref
;
1265 tem
= x_to_w32_color (color
);
1271 /* Apply gamma correction. */
1272 w32_color_ref
= XUINT (tem
);
1273 gamma_correct (f
, &w32_color_ref
);
1274 XSETINT (tem
, w32_color_ref
);
1277 /* Map this color to the palette if it is enabled. */
1278 if (!NILP (Vw32_enable_palette
))
1280 struct w32_palette_entry
* entry
=
1281 one_w32_display_info
.color_list
;
1282 struct w32_palette_entry
** prev
=
1283 &one_w32_display_info
.color_list
;
1285 /* check if color is already mapped */
1288 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1290 prev
= &entry
->next
;
1291 entry
= entry
->next
;
1294 if (entry
== NULL
&& alloc
)
1296 /* not already mapped, so add to list */
1297 entry
= (struct w32_palette_entry
*)
1298 xmalloc (sizeof (struct w32_palette_entry
));
1299 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1302 one_w32_display_info
.num_colors
++;
1304 /* set flag that palette must be regenerated */
1305 one_w32_display_info
.regen_palette
= TRUE
;
1308 /* Ensure COLORREF value is snapped to nearest color in (default)
1309 palette by simulating the PALETTERGB macro. This works whether
1310 or not the display device has a palette. */
1311 w32_color_ref
= XUINT (tem
) | 0x2000000;
1313 color_def
->pixel
= w32_color_ref
;
1314 color_def
->red
= GetRValue (w32_color_ref
) * 256;
1315 color_def
->green
= GetGValue (w32_color_ref
) * 256;
1316 color_def
->blue
= GetBValue (w32_color_ref
) * 256;
1326 /* Given a string ARG naming a color, compute a pixel value from it
1327 suitable for screen F.
1328 If F is not a color screen, return DEF (default) regardless of what
1332 x_decode_color (f
, arg
, def
)
1341 if (strcmp (SDATA (arg
), "black") == 0)
1342 return BLACK_PIX_DEFAULT (f
);
1343 else if (strcmp (SDATA (arg
), "white") == 0)
1344 return WHITE_PIX_DEFAULT (f
);
1346 if ((FRAME_W32_DISPLAY_INFO (f
)->n_planes
* FRAME_W32_DISPLAY_INFO (f
)->n_cbits
) == 1)
1349 /* w32_defined_color is responsible for coping with failures
1350 by looking for a near-miss. */
1351 if (w32_defined_color (f
, SDATA (arg
), &cdef
, 1))
1354 /* defined_color failed; return an ultimate default. */
1360 /* Functions called only from `x_set_frame_param'
1361 to set individual parameters.
1363 If FRAME_W32_WINDOW (f) is 0,
1364 the frame is being created and its window does not exist yet.
1365 In that case, just record the parameter's new value
1366 in the standard place; do not attempt to change the window. */
1369 x_set_foreground_color (f
, arg
, oldval
)
1371 Lisp_Object arg
, oldval
;
1373 struct w32_output
*x
= f
->output_data
.w32
;
1374 PIX_TYPE fg
, old_fg
;
1376 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1377 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
1378 FRAME_FOREGROUND_PIXEL (f
) = fg
;
1380 if (FRAME_W32_WINDOW (f
) != 0)
1382 if (x
->cursor_pixel
== old_fg
)
1383 x
->cursor_pixel
= fg
;
1385 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
1386 if (FRAME_VISIBLE_P (f
))
1392 x_set_background_color (f
, arg
, oldval
)
1394 Lisp_Object arg
, oldval
;
1396 FRAME_BACKGROUND_PIXEL (f
)
1397 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
1399 if (FRAME_W32_WINDOW (f
) != 0)
1401 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
1402 FRAME_BACKGROUND_PIXEL (f
));
1404 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
1406 if (FRAME_VISIBLE_P (f
))
1412 x_set_mouse_color (f
, arg
, oldval
)
1414 Lisp_Object arg
, oldval
;
1416 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
1420 if (!EQ (Qnil
, arg
))
1421 f
->output_data
.w32
->mouse_pixel
1422 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1423 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
1425 /* Don't let pointers be invisible. */
1426 if (mask_color
== f
->output_data
.w32
->mouse_pixel
1427 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
1428 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
1430 #if 0 /* TODO : cursor changes */
1433 /* It's not okay to crash if the user selects a screwy cursor. */
1434 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
1436 if (!EQ (Qnil
, Vx_pointer_shape
))
1438 CHECK_NUMBER (Vx_pointer_shape
);
1439 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
1442 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1443 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
1445 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
1447 CHECK_NUMBER (Vx_nontext_pointer_shape
);
1448 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1449 XINT (Vx_nontext_pointer_shape
));
1452 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
1453 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1455 if (!EQ (Qnil
, Vx_hourglass_pointer_shape
))
1457 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
1458 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1459 XINT (Vx_hourglass_pointer_shape
));
1462 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
1463 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
1465 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1466 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
1468 CHECK_NUMBER (Vx_mode_pointer_shape
);
1469 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1470 XINT (Vx_mode_pointer_shape
));
1473 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1474 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
1476 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
1478 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
1480 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1481 XINT (Vx_sensitive_text_pointer_shape
));
1484 hand_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
1486 if (!NILP (Vx_window_horizontal_drag_shape
))
1488 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
1489 horizontal_drag_cursor
1490 = XCreateFontCursor (FRAME_X_DISPLAY (f
),
1491 XINT (Vx_window_horizontal_drag_shape
));
1494 horizontal_drag_cursor
1495 = XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_sb_h_double_arrow
);
1497 /* Check and report errors with the above calls. */
1498 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
1499 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
1502 XColor fore_color
, back_color
;
1504 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
1505 back_color
.pixel
= mask_color
;
1506 XQueryColor (FRAME_W32_DISPLAY (f
),
1507 DefaultColormap (FRAME_W32_DISPLAY (f
),
1508 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1510 XQueryColor (FRAME_W32_DISPLAY (f
),
1511 DefaultColormap (FRAME_W32_DISPLAY (f
),
1512 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1514 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
1515 &fore_color
, &back_color
);
1516 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
1517 &fore_color
, &back_color
);
1518 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
1519 &fore_color
, &back_color
);
1520 XRecolorCursor (FRAME_W32_DISPLAY (f
), hand_cursor
,
1521 &fore_color
, &back_color
);
1522 XRecolorCursor (FRAME_W32_DISPLAY (f
), hourglass_cursor
,
1523 &fore_color
, &back_color
);
1526 if (FRAME_W32_WINDOW (f
) != 0)
1527 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
1529 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
1530 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
1531 f
->output_data
.w32
->text_cursor
= cursor
;
1533 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
1534 && f
->output_data
.w32
->nontext_cursor
!= 0)
1535 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
1536 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
1538 if (hourglass_cursor
!= f
->output_data
.w32
->hourglass_cursor
1539 && f
->output_data
.w32
->hourglass_cursor
!= 0)
1540 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hourglass_cursor
);
1541 f
->output_data
.w32
->hourglass_cursor
= hourglass_cursor
;
1543 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
1544 && f
->output_data
.w32
->modeline_cursor
!= 0)
1545 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
1546 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
1548 if (hand_cursor
!= f
->output_data
.w32
->hand_cursor
1549 && f
->output_data
.w32
->hand_cursor
!= 0)
1550 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hand_cursor
);
1551 f
->output_data
.w32
->hand_cursor
= hand_cursor
;
1553 XFlush (FRAME_W32_DISPLAY (f
));
1556 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1560 /* Defined in w32term.c. */
1562 x_set_cursor_color (f
, arg
, oldval
)
1564 Lisp_Object arg
, oldval
;
1566 unsigned long fore_pixel
, pixel
;
1568 if (!NILP (Vx_cursor_fore_pixel
))
1569 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1570 WHITE_PIX_DEFAULT (f
));
1572 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1574 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1576 /* Make sure that the cursor color differs from the background color. */
1577 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
1579 pixel
= f
->output_data
.w32
->mouse_pixel
;
1580 if (pixel
== fore_pixel
)
1581 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1584 f
->output_data
.w32
->cursor_foreground_pixel
= fore_pixel
;
1585 f
->output_data
.w32
->cursor_pixel
= pixel
;
1587 if (FRAME_W32_WINDOW (f
) != 0)
1590 /* Update frame's cursor_gc. */
1591 f
->output_data
.w32
->cursor_gc
->foreground
= fore_pixel
;
1592 f
->output_data
.w32
->cursor_gc
->background
= pixel
;
1596 if (FRAME_VISIBLE_P (f
))
1598 x_update_cursor (f
, 0);
1599 x_update_cursor (f
, 1);
1603 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1606 /* Set the border-color of frame F to pixel value PIX.
1607 Note that this does not fully take effect if done before
1611 x_set_border_pixel (f
, pix
)
1616 f
->output_data
.w32
->border_pixel
= pix
;
1618 if (FRAME_W32_WINDOW (f
) != 0 && f
->border_width
> 0)
1620 if (FRAME_VISIBLE_P (f
))
1625 /* Set the border-color of frame F to value described by ARG.
1626 ARG can be a string naming a color.
1627 The border-color is used for the border that is drawn by the server.
1628 Note that this does not fully take effect if done before
1629 F has a window; it must be redone when the window is created. */
1632 x_set_border_color (f
, arg
, oldval
)
1634 Lisp_Object arg
, oldval
;
1639 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1640 x_set_border_pixel (f
, pix
);
1641 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1646 x_set_cursor_type (f
, arg
, oldval
)
1648 Lisp_Object arg
, oldval
;
1650 set_frame_cursor_types (f
, arg
);
1652 /* Make sure the cursor gets redrawn. */
1653 cursor_type_changed
= 1;
1657 x_set_icon_type (f
, arg
, oldval
)
1659 Lisp_Object arg
, oldval
;
1663 if (NILP (arg
) && NILP (oldval
))
1666 if (STRINGP (arg
) && STRINGP (oldval
)
1667 && EQ (Fstring_equal (oldval
, arg
), Qt
))
1670 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
1675 result
= x_bitmap_icon (f
, arg
);
1679 error ("No icon window available");
1686 x_set_icon_name (f
, arg
, oldval
)
1688 Lisp_Object arg
, oldval
;
1692 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1695 else if (!NILP (arg
) || NILP (oldval
))
1701 if (f
->output_data
.w32
->icon_bitmap
!= 0)
1706 result
= x_text_icon (f
,
1707 (char *) SDATA ((!NILP (f
->icon_name
)
1716 error ("No icon window available");
1719 /* If the window was unmapped (and its icon was mapped),
1720 the new icon is not mapped, so map the window in its stead. */
1721 if (FRAME_VISIBLE_P (f
))
1723 #ifdef USE_X_TOOLKIT
1724 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
1726 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
1729 XFlush (FRAME_W32_DISPLAY (f
));
1736 x_set_menu_bar_lines (f
, value
, oldval
)
1738 Lisp_Object value
, oldval
;
1741 int olines
= FRAME_MENU_BAR_LINES (f
);
1743 /* Right now, menu bars don't work properly in minibuf-only frames;
1744 most of the commands try to apply themselves to the minibuffer
1745 frame itself, and get an error because you can't switch buffers
1746 in or split the minibuffer window. */
1747 if (FRAME_MINIBUF_ONLY_P (f
))
1750 if (INTEGERP (value
))
1751 nlines
= XINT (value
);
1755 FRAME_MENU_BAR_LINES (f
) = 0;
1757 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1760 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1761 free_frame_menubar (f
);
1762 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1764 /* Adjust the frame size so that the client (text) dimensions
1765 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
1767 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
1768 do_pending_window_change (0);
1774 /* Set the number of lines used for the tool bar of frame F to VALUE.
1775 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1776 is the old number of tool bar lines. This function changes the
1777 height of all windows on frame F to match the new tool bar height.
1778 The frame's height doesn't change. */
1781 x_set_tool_bar_lines (f
, value
, oldval
)
1783 Lisp_Object value
, oldval
;
1785 int delta
, nlines
, root_height
;
1786 Lisp_Object root_window
;
1788 /* Treat tool bars like menu bars. */
1789 if (FRAME_MINIBUF_ONLY_P (f
))
1792 /* Use VALUE only if an integer >= 0. */
1793 if (INTEGERP (value
) && XINT (value
) >= 0)
1794 nlines
= XFASTINT (value
);
1798 /* Make sure we redisplay all windows in this frame. */
1799 ++windows_or_buffers_changed
;
1801 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
1803 /* Don't resize the tool-bar to more than we have room for. */
1804 root_window
= FRAME_ROOT_WINDOW (f
);
1805 root_height
= WINDOW_TOTAL_LINES (XWINDOW (root_window
));
1806 if (root_height
- delta
< 1)
1808 delta
= root_height
- 1;
1809 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
1812 FRAME_TOOL_BAR_LINES (f
) = nlines
;
1813 change_window_heights (root_window
, delta
);
1816 /* We also have to make sure that the internal border at the top of
1817 the frame, below the menu bar or tool bar, is redrawn when the
1818 tool bar disappears. This is so because the internal border is
1819 below the tool bar if one is displayed, but is below the menu bar
1820 if there isn't a tool bar. The tool bar draws into the area
1821 below the menu bar. */
1822 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
1826 clear_current_matrices (f
);
1827 updating_frame
= NULL
;
1830 /* If the tool bar gets smaller, the internal border below it
1831 has to be cleared. It was formerly part of the display
1832 of the larger tool bar, and updating windows won't clear it. */
1835 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1836 int width
= FRAME_PIXEL_WIDTH (f
);
1837 int y
= nlines
* FRAME_LINE_HEIGHT (f
);
1841 HDC hdc
= get_frame_dc (f
);
1842 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
1843 release_frame_dc (f
, hdc
);
1847 if (WINDOWP (f
->tool_bar_window
))
1848 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1853 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1856 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1857 name; if NAME is a string, set F's name to NAME and set
1858 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1860 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1861 suggesting a new name, which lisp code should override; if
1862 F->explicit_name is set, ignore the new name; otherwise, set it. */
1865 x_set_name (f
, name
, explicit)
1870 /* Make sure that requests from lisp code override requests from
1871 Emacs redisplay code. */
1874 /* If we're switching from explicit to implicit, we had better
1875 update the mode lines and thereby update the title. */
1876 if (f
->explicit_name
&& NILP (name
))
1877 update_mode_lines
= 1;
1879 f
->explicit_name
= ! NILP (name
);
1881 else if (f
->explicit_name
)
1884 /* If NAME is nil, set the name to the w32_id_name. */
1887 /* Check for no change needed in this very common case
1888 before we do any consing. */
1889 if (!strcmp (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
,
1892 name
= build_string (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
);
1895 CHECK_STRING (name
);
1897 /* Don't change the name if it's already NAME. */
1898 if (! NILP (Fstring_equal (name
, f
->name
)))
1903 /* For setting the frame title, the title parameter should override
1904 the name parameter. */
1905 if (! NILP (f
->title
))
1908 if (FRAME_W32_WINDOW (f
))
1910 if (STRING_MULTIBYTE (name
))
1911 name
= ENCODE_SYSTEM (name
);
1914 SetWindowText(FRAME_W32_WINDOW (f
), SDATA (name
));
1919 /* This function should be called when the user's lisp code has
1920 specified a name for the frame; the name will override any set by the
1923 x_explicitly_set_name (f
, arg
, oldval
)
1925 Lisp_Object arg
, oldval
;
1927 x_set_name (f
, arg
, 1);
1930 /* This function should be called by Emacs redisplay code to set the
1931 name; names set this way will never override names set by the user's
1934 x_implicitly_set_name (f
, arg
, oldval
)
1936 Lisp_Object arg
, oldval
;
1938 x_set_name (f
, arg
, 0);
1941 /* Change the title of frame F to NAME.
1942 If NAME is nil, use the frame name as the title.
1944 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1945 name; if NAME is a string, set F's name to NAME and set
1946 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1948 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1949 suggesting a new name, which lisp code should override; if
1950 F->explicit_name is set, ignore the new name; otherwise, set it. */
1953 x_set_title (f
, name
, old_name
)
1955 Lisp_Object name
, old_name
;
1957 /* Don't change the title if it's already NAME. */
1958 if (EQ (name
, f
->title
))
1961 update_mode_lines
= 1;
1968 if (FRAME_W32_WINDOW (f
))
1970 if (STRING_MULTIBYTE (name
))
1971 name
= ENCODE_SYSTEM (name
);
1974 SetWindowText(FRAME_W32_WINDOW (f
), SDATA (name
));
1980 void x_set_scroll_bar_default_width (f
)
1983 int wid
= FRAME_COLUMN_WIDTH (f
);
1985 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
1986 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) +
1991 /* Subroutines of creating a frame. */
1994 /* Return the value of parameter PARAM.
1996 First search ALIST, then Vdefault_frame_alist, then the X defaults
1997 database, using ATTRIBUTE as the attribute name and CLASS as its class.
1999 Convert the resource to the type specified by desired_type.
2001 If no default is specified, return Qunbound. If you call
2002 w32_get_arg, make sure you deal with Qunbound in a reasonable way,
2003 and don't let it get stored in any Lisp-visible variables! */
2006 w32_get_arg (alist
, param
, attribute
, class, type
)
2007 Lisp_Object alist
, param
;
2010 enum resource_types type
;
2012 return x_get_arg (check_x_display_info (Qnil
),
2013 alist
, param
, attribute
, class, type
);
2018 w32_load_cursor (LPCTSTR name
)
2020 /* Try first to load cursor from application resource. */
2021 Cursor cursor
= LoadImage ((HINSTANCE
) GetModuleHandle(NULL
),
2022 name
, IMAGE_CURSOR
, 0, 0,
2023 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
2026 /* Then try to load a shared predefined cursor. */
2027 cursor
= LoadImage (NULL
, name
, IMAGE_CURSOR
, 0, 0,
2028 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
2033 extern LRESULT CALLBACK
w32_wnd_proc ();
2036 w32_init_class (hinst
)
2041 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
2042 wc
.lpfnWndProc
= (WNDPROC
) w32_wnd_proc
;
2044 wc
.cbWndExtra
= WND_EXTRA_BYTES
;
2045 wc
.hInstance
= hinst
;
2046 wc
.hIcon
= LoadIcon (hinst
, EMACS_CLASS
);
2047 wc
.hCursor
= w32_load_cursor (IDC_ARROW
);
2048 wc
.hbrBackground
= NULL
; /* GetStockObject (WHITE_BRUSH); */
2049 wc
.lpszMenuName
= NULL
;
2050 wc
.lpszClassName
= EMACS_CLASS
;
2052 return (RegisterClass (&wc
));
2056 w32_createscrollbar (f
, bar
)
2058 struct scroll_bar
* bar
;
2060 return (CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
2061 /* Position and size of scroll bar. */
2062 XINT(bar
->left
) + VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
2064 XINT(bar
->width
) - VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
2066 FRAME_W32_WINDOW (f
),
2073 w32_createwindow (f
)
2078 Lisp_Object top
= Qunbound
;
2079 Lisp_Object left
= Qunbound
;
2081 rect
.left
= rect
.top
= 0;
2082 rect
.right
= FRAME_PIXEL_WIDTH (f
);
2083 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
2085 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
2086 FRAME_EXTERNAL_MENU_BAR (f
));
2088 /* Do first time app init */
2092 w32_init_class (hinst
);
2095 if (f
->size_hint_flags
& USPosition
|| f
->size_hint_flags
& PPosition
)
2097 XSETINT (left
, f
->left_pos
);
2098 XSETINT (top
, f
->top_pos
);
2100 else if (EQ (left
, Qunbound
) && EQ (top
, Qunbound
))
2102 /* When called with RES_TYPE_NUMBER, w32_get_arg will return zero
2103 for anything that is not a number and is not Qunbound. */
2104 left
= w32_get_arg (Qnil
, Qleft
, "left", "Left", RES_TYPE_NUMBER
);
2105 top
= w32_get_arg (Qnil
, Qtop
, "top", "Top", RES_TYPE_NUMBER
);
2108 FRAME_W32_WINDOW (f
) = hwnd
2109 = CreateWindow (EMACS_CLASS
,
2111 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
2112 EQ (left
, Qunbound
) ? CW_USEDEFAULT
: XINT (left
),
2113 EQ (top
, Qunbound
) ? CW_USEDEFAULT
: XINT (top
),
2114 rect
.right
- rect
.left
,
2115 rect
.bottom
- rect
.top
,
2123 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
2124 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
2125 SetWindowLong (hwnd
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
2126 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->scroll_bar_actual_width
);
2127 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
2129 /* Enable drag-n-drop. */
2130 DragAcceptFiles (hwnd
, TRUE
);
2132 /* Do this to discard the default setting specified by our parent. */
2133 ShowWindow (hwnd
, SW_HIDE
);
2135 /* Update frame positions. */
2136 GetWindowRect (hwnd
, &rect
);
2137 f
->left_pos
= rect
.left
;
2138 f
->top_pos
= rect
.top
;
2143 my_post_msg (wmsg
, hwnd
, msg
, wParam
, lParam
)
2150 wmsg
->msg
.hwnd
= hwnd
;
2151 wmsg
->msg
.message
= msg
;
2152 wmsg
->msg
.wParam
= wParam
;
2153 wmsg
->msg
.lParam
= lParam
;
2154 wmsg
->msg
.time
= GetMessageTime ();
2159 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
2160 between left and right keys as advertised. We test for this
2161 support dynamically, and set a flag when the support is absent. If
2162 absent, we keep track of the left and right control and alt keys
2163 ourselves. This is particularly necessary on keyboards that rely
2164 upon the AltGr key, which is represented as having the left control
2165 and right alt keys pressed. For these keyboards, we need to know
2166 when the left alt key has been pressed in addition to the AltGr key
2167 so that we can properly support M-AltGr-key sequences (such as M-@
2168 on Swedish keyboards). */
2170 #define EMACS_LCONTROL 0
2171 #define EMACS_RCONTROL 1
2172 #define EMACS_LMENU 2
2173 #define EMACS_RMENU 3
2175 static int modifiers
[4];
2176 static int modifiers_recorded
;
2177 static int modifier_key_support_tested
;
2180 test_modifier_support (unsigned int wparam
)
2184 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
2186 if (wparam
== VK_CONTROL
)
2196 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
2197 modifiers_recorded
= 1;
2199 modifiers_recorded
= 0;
2200 modifier_key_support_tested
= 1;
2204 record_keydown (unsigned int wparam
, unsigned int lparam
)
2208 if (!modifier_key_support_tested
)
2209 test_modifier_support (wparam
);
2211 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2214 if (wparam
== VK_CONTROL
)
2215 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2217 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2223 record_keyup (unsigned int wparam
, unsigned int lparam
)
2227 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2230 if (wparam
== VK_CONTROL
)
2231 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2233 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2238 /* Emacs can lose focus while a modifier key has been pressed. When
2239 it regains focus, be conservative and clear all modifiers since
2240 we cannot reconstruct the left and right modifier state. */
2246 if (GetFocus () == NULL
)
2247 /* Emacs doesn't have keyboard focus. Do nothing. */
2250 ctrl
= GetAsyncKeyState (VK_CONTROL
);
2251 alt
= GetAsyncKeyState (VK_MENU
);
2253 if (!(ctrl
& 0x08000))
2254 /* Clear any recorded control modifier state. */
2255 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2257 if (!(alt
& 0x08000))
2258 /* Clear any recorded alt modifier state. */
2259 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2261 /* Update the state of all modifier keys, because modifiers used in
2262 hot-key combinations can get stuck on if Emacs loses focus as a
2263 result of a hot-key being pressed. */
2267 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
2269 GetKeyboardState (keystate
);
2270 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
2271 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
2272 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
2273 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
2274 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
2275 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
2276 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
2277 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
2278 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
2279 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
2280 SetKeyboardState (keystate
);
2284 /* Synchronize modifier state with what is reported with the current
2285 keystroke. Even if we cannot distinguish between left and right
2286 modifier keys, we know that, if no modifiers are set, then neither
2287 the left or right modifier should be set. */
2291 if (!modifiers_recorded
)
2294 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
2295 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2297 if (!(GetKeyState (VK_MENU
) & 0x8000))
2298 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2302 modifier_set (int vkey
)
2304 if (vkey
== VK_CAPITAL
|| vkey
== VK_SCROLL
)
2305 return (GetKeyState (vkey
) & 0x1);
2306 if (!modifiers_recorded
)
2307 return (GetKeyState (vkey
) & 0x8000);
2312 return modifiers
[EMACS_LCONTROL
];
2314 return modifiers
[EMACS_RCONTROL
];
2316 return modifiers
[EMACS_LMENU
];
2318 return modifiers
[EMACS_RMENU
];
2320 return (GetKeyState (vkey
) & 0x8000);
2323 /* Convert between the modifier bits W32 uses and the modifier bits
2327 w32_key_to_modifier (int key
)
2329 Lisp_Object key_mapping
;
2334 key_mapping
= Vw32_lwindow_modifier
;
2337 key_mapping
= Vw32_rwindow_modifier
;
2340 key_mapping
= Vw32_apps_modifier
;
2343 key_mapping
= Vw32_scroll_lock_modifier
;
2349 /* NB. This code runs in the input thread, asychronously to the lisp
2350 thread, so we must be careful to ensure access to lisp data is
2351 thread-safe. The following code is safe because the modifier
2352 variable values are updated atomically from lisp and symbols are
2353 not relocated by GC. Also, we don't have to worry about seeing GC
2355 if (EQ (key_mapping
, Qhyper
))
2356 return hyper_modifier
;
2357 if (EQ (key_mapping
, Qsuper
))
2358 return super_modifier
;
2359 if (EQ (key_mapping
, Qmeta
))
2360 return meta_modifier
;
2361 if (EQ (key_mapping
, Qalt
))
2362 return alt_modifier
;
2363 if (EQ (key_mapping
, Qctrl
))
2364 return ctrl_modifier
;
2365 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
2366 return ctrl_modifier
;
2367 if (EQ (key_mapping
, Qshift
))
2368 return shift_modifier
;
2370 /* Don't generate any modifier if not explicitly requested. */
2375 w32_get_modifiers ()
2377 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
2378 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
2379 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
2380 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
2381 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
2382 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
2383 (modifier_set (VK_MENU
) ?
2384 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
2387 /* We map the VK_* modifiers into console modifier constants
2388 so that we can use the same routines to handle both console
2389 and window input. */
2392 construct_console_modifiers ()
2397 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
2398 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
2399 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
2400 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
2401 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
2402 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
2403 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
2404 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
2405 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
2406 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
2407 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
2413 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
2417 /* Convert to emacs modifiers. */
2418 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
2424 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
2426 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
2429 if (virt_key
== VK_RETURN
)
2430 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
2432 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
2433 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
2435 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
2436 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
2438 if (virt_key
== VK_CLEAR
)
2439 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
2444 /* List of special key combinations which w32 would normally capture,
2445 but emacs should grab instead. Not directly visible to lisp, to
2446 simplify synchronization. Each item is an integer encoding a virtual
2447 key code and modifier combination to capture. */
2448 Lisp_Object w32_grabbed_keys
;
2450 #define HOTKEY(vk,mods) make_number (((vk) & 255) | ((mods) << 8))
2451 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
2452 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
2453 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
2455 #define RAW_HOTKEY_ID(k) ((k) & 0xbfff)
2456 #define RAW_HOTKEY_VK_CODE(k) ((k) & 255)
2457 #define RAW_HOTKEY_MODIFIERS(k) ((k) >> 8)
2459 /* Register hot-keys for reserved key combinations when Emacs has
2460 keyboard focus, since this is the only way Emacs can receive key
2461 combinations like Alt-Tab which are used by the system. */
2464 register_hot_keys (hwnd
)
2467 Lisp_Object keylist
;
2469 /* Use GC_CONSP, since we are called asynchronously. */
2470 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
2472 Lisp_Object key
= XCAR (keylist
);
2474 /* Deleted entries get set to nil. */
2475 if (!INTEGERP (key
))
2478 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
2479 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
2484 unregister_hot_keys (hwnd
)
2487 Lisp_Object keylist
;
2489 /* Use GC_CONSP, since we are called asynchronously. */
2490 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
2492 Lisp_Object key
= XCAR (keylist
);
2494 if (!INTEGERP (key
))
2497 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
2501 /* Main message dispatch loop. */
2504 w32_msg_pump (deferred_msg
* msg_buf
)
2510 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
2512 while (GetMessage (&msg
, NULL
, 0, 0))
2514 if (msg
.hwnd
== NULL
)
2516 switch (msg
.message
)
2519 /* Produced by complete_deferred_msg; just ignore. */
2521 case WM_EMACS_CREATEWINDOW
:
2522 w32_createwindow ((struct frame
*) msg
.wParam
);
2523 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2526 case WM_EMACS_SETLOCALE
:
2527 SetThreadLocale (msg
.wParam
);
2528 /* Reply is not expected. */
2530 case WM_EMACS_SETKEYBOARDLAYOUT
:
2531 result
= (int) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
2532 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2536 case WM_EMACS_REGISTER_HOT_KEY
:
2537 focus_window
= GetFocus ();
2538 if (focus_window
!= NULL
)
2539 RegisterHotKey (focus_window
,
2540 RAW_HOTKEY_ID (msg
.wParam
),
2541 RAW_HOTKEY_MODIFIERS (msg
.wParam
),
2542 RAW_HOTKEY_VK_CODE (msg
.wParam
));
2543 /* Reply is not expected. */
2545 case WM_EMACS_UNREGISTER_HOT_KEY
:
2546 focus_window
= GetFocus ();
2547 if (focus_window
!= NULL
)
2548 UnregisterHotKey (focus_window
, RAW_HOTKEY_ID (msg
.wParam
));
2549 /* Mark item as erased. NB: this code must be
2550 thread-safe. The next line is okay because the cons
2551 cell is never made into garbage and is not relocated by
2553 XSETCAR ((Lisp_Object
) ((EMACS_INT
) msg
.lParam
), Qnil
);
2554 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2557 case WM_EMACS_TOGGLE_LOCK_KEY
:
2559 int vk_code
= (int) msg
.wParam
;
2560 int cur_state
= (GetKeyState (vk_code
) & 1);
2561 Lisp_Object new_state
= (Lisp_Object
) ((EMACS_INT
) msg
.lParam
);
2563 /* NB: This code must be thread-safe. It is safe to
2564 call NILP because symbols are not relocated by GC,
2565 and pointer here is not touched by GC (so the markbit
2566 can't be set). Numbers are safe because they are
2567 immediate values. */
2568 if (NILP (new_state
)
2569 || (NUMBERP (new_state
)
2570 && ((XUINT (new_state
)) & 1) != cur_state
))
2572 one_w32_display_info
.faked_key
= vk_code
;
2574 keybd_event ((BYTE
) vk_code
,
2575 (BYTE
) MapVirtualKey (vk_code
, 0),
2576 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2577 keybd_event ((BYTE
) vk_code
,
2578 (BYTE
) MapVirtualKey (vk_code
, 0),
2579 KEYEVENTF_EXTENDEDKEY
| 0, 0);
2580 keybd_event ((BYTE
) vk_code
,
2581 (BYTE
) MapVirtualKey (vk_code
, 0),
2582 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2583 cur_state
= !cur_state
;
2585 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2591 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
2596 DispatchMessage (&msg
);
2599 /* Exit nested loop when our deferred message has completed. */
2600 if (msg_buf
->completed
)
2605 deferred_msg
* deferred_msg_head
;
2607 static deferred_msg
*
2608 find_deferred_msg (HWND hwnd
, UINT msg
)
2610 deferred_msg
* item
;
2612 /* Don't actually need synchronization for read access, since
2613 modification of single pointer is always atomic. */
2614 /* enter_crit (); */
2616 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2617 if (item
->w32msg
.msg
.hwnd
== hwnd
2618 && item
->w32msg
.msg
.message
== msg
)
2621 /* leave_crit (); */
2627 send_deferred_msg (deferred_msg
* msg_buf
,
2633 /* Only input thread can send deferred messages. */
2634 if (GetCurrentThreadId () != dwWindowsThreadId
)
2637 /* It is an error to send a message that is already deferred. */
2638 if (find_deferred_msg (hwnd
, msg
) != NULL
)
2641 /* Enforced synchronization is not needed because this is the only
2642 function that alters deferred_msg_head, and the following critical
2643 section is guaranteed to only be serially reentered (since only the
2644 input thread can call us). */
2646 /* enter_crit (); */
2648 msg_buf
->completed
= 0;
2649 msg_buf
->next
= deferred_msg_head
;
2650 deferred_msg_head
= msg_buf
;
2651 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
2653 /* leave_crit (); */
2655 /* Start a new nested message loop to process other messages until
2656 this one is completed. */
2657 w32_msg_pump (msg_buf
);
2659 deferred_msg_head
= msg_buf
->next
;
2661 return msg_buf
->result
;
2665 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
2667 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
2669 if (msg_buf
== NULL
)
2670 /* Message may have been cancelled, so don't abort(). */
2673 msg_buf
->result
= result
;
2674 msg_buf
->completed
= 1;
2676 /* Ensure input thread is woken so it notices the completion. */
2677 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2681 cancel_all_deferred_msgs ()
2683 deferred_msg
* item
;
2685 /* Don't actually need synchronization for read access, since
2686 modification of single pointer is always atomic. */
2687 /* enter_crit (); */
2689 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2692 item
->completed
= 1;
2695 /* leave_crit (); */
2697 /* Ensure input thread is woken so it notices the completion. */
2698 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2702 w32_msg_worker (void *arg
)
2705 deferred_msg dummy_buf
;
2707 /* Ensure our message queue is created */
2709 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
2711 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2714 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
2715 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
2716 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
2718 /* This is the inital message loop which should only exit when the
2719 application quits. */
2720 w32_msg_pump (&dummy_buf
);
2726 signal_user_input ()
2728 /* Interrupt any lisp that wants to be interrupted by input. */
2729 if (!NILP (Vthrow_on_input
))
2731 Vquit_flag
= Vthrow_on_input
;
2732 /* If we're inside a function that wants immediate quits,
2734 if (immediate_quit
&& NILP (Vinhibit_quit
))
2744 post_character_message (hwnd
, msg
, wParam
, lParam
, modifiers
)
2754 wmsg
.dwModifiers
= modifiers
;
2756 /* Detect quit_char and set quit-flag directly. Note that we
2757 still need to post a message to ensure the main thread will be
2758 woken up if blocked in sys_select(), but we do NOT want to post
2759 the quit_char message itself (because it will usually be as if
2760 the user had typed quit_char twice). Instead, we post a dummy
2761 message that has no particular effect. */
2764 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
2765 c
= make_ctrl_char (c
) & 0377;
2767 || (wmsg
.dwModifiers
== 0 &&
2768 w32_quit_key
&& wParam
== w32_quit_key
))
2772 /* The choice of message is somewhat arbitrary, as long as
2773 the main thread handler just ignores it. */
2776 /* Interrupt any blocking system calls. */
2779 /* As a safety precaution, forcibly complete any deferred
2780 messages. This is a kludge, but I don't see any particularly
2781 clean way to handle the situation where a deferred message is
2782 "dropped" in the lisp thread, and will thus never be
2783 completed, eg. by the user trying to activate the menubar
2784 when the lisp thread is busy, and then typing C-g when the
2785 menubar doesn't open promptly (with the result that the
2786 menubar never responds at all because the deferred
2787 WM_INITMENU message is never completed). Another problem
2788 situation is when the lisp thread calls SendMessage (to send
2789 a window manager command) when a message has been deferred;
2790 the lisp thread gets blocked indefinitely waiting for the
2791 deferred message to be completed, which itself is waiting for
2792 the lisp thread to respond.
2794 Note that we don't want to block the input thread waiting for
2795 a reponse from the lisp thread (although that would at least
2796 solve the deadlock problem above), because we want to be able
2797 to receive C-g to interrupt the lisp thread. */
2798 cancel_all_deferred_msgs ();
2801 signal_user_input ();
2804 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2807 /* Main window procedure */
2810 w32_wnd_proc (hwnd
, msg
, wParam
, lParam
)
2817 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
2819 int windows_translate
;
2822 /* Note that it is okay to call x_window_to_frame, even though we are
2823 not running in the main lisp thread, because frame deletion
2824 requires the lisp thread to synchronize with this thread. Thus, if
2825 a frame struct is returned, it can be used without concern that the
2826 lisp thread might make it disappear while we are using it.
2828 NB. Walking the frame list in this thread is safe (as long as
2829 writes of Lisp_Object slots are atomic, which they are on Windows).
2830 Although delete-frame can destructively modify the frame list while
2831 we are walking it, a garbage collection cannot occur until after
2832 delete-frame has synchronized with this thread.
2834 It is also safe to use functions that make GDI calls, such as
2835 w32_clear_rect, because these functions must obtain a DC handle
2836 from the frame struct using get_frame_dc which is thread-aware. */
2841 f
= x_window_to_frame (dpyinfo
, hwnd
);
2844 HDC hdc
= get_frame_dc (f
);
2845 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
2846 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
2847 release_frame_dc (f
, hdc
);
2849 #if defined (W32_DEBUG_DISPLAY)
2850 DebPrint (("WM_ERASEBKGND (frame %p): erasing %d,%d-%d,%d\n",
2852 wmsg
.rect
.left
, wmsg
.rect
.top
,
2853 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2854 #endif /* W32_DEBUG_DISPLAY */
2857 case WM_PALETTECHANGED
:
2858 /* ignore our own changes */
2859 if ((HWND
)wParam
!= hwnd
)
2861 f
= x_window_to_frame (dpyinfo
, hwnd
);
2863 /* get_frame_dc will realize our palette and force all
2864 frames to be redrawn if needed. */
2865 release_frame_dc (f
, get_frame_dc (f
));
2870 PAINTSTRUCT paintStruct
;
2872 bzero (&update_rect
, sizeof (update_rect
));
2874 f
= x_window_to_frame (dpyinfo
, hwnd
);
2877 DebPrint (("WM_PAINT received for unknown window %p\n", hwnd
));
2881 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
2882 fails. Apparently this can happen under some
2884 if (GetUpdateRect (hwnd
, &update_rect
, FALSE
) || !w32_strict_painting
)
2887 BeginPaint (hwnd
, &paintStruct
);
2889 /* The rectangles returned by GetUpdateRect and BeginPaint
2890 do not always match. Play it safe by assuming both areas
2892 UnionRect (&(wmsg
.rect
), &update_rect
, &(paintStruct
.rcPaint
));
2894 #if defined (W32_DEBUG_DISPLAY)
2895 DebPrint (("WM_PAINT (frame %p): painting %d,%d-%d,%d\n",
2897 wmsg
.rect
.left
, wmsg
.rect
.top
,
2898 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2899 DebPrint ((" [update region is %d,%d-%d,%d]\n",
2900 update_rect
.left
, update_rect
.top
,
2901 update_rect
.right
, update_rect
.bottom
));
2903 EndPaint (hwnd
, &paintStruct
);
2906 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2911 /* If GetUpdateRect returns 0 (meaning there is no update
2912 region), assume the whole window needs to be repainted. */
2913 GetClientRect(hwnd
, &wmsg
.rect
);
2914 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2918 case WM_INPUTLANGCHANGE
:
2919 /* Inform lisp thread of keyboard layout changes. */
2920 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2922 /* Clear dead keys in the keyboard state; for simplicity only
2923 preserve modifier key states. */
2928 GetKeyboardState (keystate
);
2929 for (i
= 0; i
< 256; i
++)
2946 SetKeyboardState (keystate
);
2951 /* Synchronize hot keys with normal input. */
2952 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
2957 record_keyup (wParam
, lParam
);
2962 /* Ignore keystrokes we fake ourself; see below. */
2963 if (dpyinfo
->faked_key
== wParam
)
2965 dpyinfo
->faked_key
= 0;
2966 /* Make sure TranslateMessage sees them though (as long as
2967 they don't produce WM_CHAR messages). This ensures that
2968 indicator lights are toggled promptly on Windows 9x, for
2970 if (lispy_function_keys
[wParam
] != 0)
2972 windows_translate
= 1;
2978 /* Synchronize modifiers with current keystroke. */
2980 record_keydown (wParam
, lParam
);
2981 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
2983 windows_translate
= 0;
2988 if (NILP (Vw32_pass_lwindow_to_system
))
2990 /* Prevent system from acting on keyup (which opens the
2991 Start menu if no other key was pressed) by simulating a
2992 press of Space which we will ignore. */
2993 if (GetAsyncKeyState (wParam
) & 1)
2995 if (NUMBERP (Vw32_phantom_key_code
))
2996 key
= XUINT (Vw32_phantom_key_code
) & 255;
2999 dpyinfo
->faked_key
= key
;
3000 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
3003 if (!NILP (Vw32_lwindow_modifier
))
3007 if (NILP (Vw32_pass_rwindow_to_system
))
3009 if (GetAsyncKeyState (wParam
) & 1)
3011 if (NUMBERP (Vw32_phantom_key_code
))
3012 key
= XUINT (Vw32_phantom_key_code
) & 255;
3015 dpyinfo
->faked_key
= key
;
3016 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
3019 if (!NILP (Vw32_rwindow_modifier
))
3023 if (!NILP (Vw32_apps_modifier
))
3027 if (NILP (Vw32_pass_alt_to_system
))
3028 /* Prevent DefWindowProc from activating the menu bar if an
3029 Alt key is pressed and released by itself. */
3031 windows_translate
= 1;
3034 /* Decide whether to treat as modifier or function key. */
3035 if (NILP (Vw32_enable_caps_lock
))
3036 goto disable_lock_key
;
3037 windows_translate
= 1;
3040 /* Decide whether to treat as modifier or function key. */
3041 if (NILP (Vw32_enable_num_lock
))
3042 goto disable_lock_key
;
3043 windows_translate
= 1;
3046 /* Decide whether to treat as modifier or function key. */
3047 if (NILP (Vw32_scroll_lock_modifier
))
3048 goto disable_lock_key
;
3049 windows_translate
= 1;
3052 /* Ensure the appropriate lock key state (and indicator light)
3053 remains in the same state. We do this by faking another
3054 press of the relevant key. Apparently, this really is the
3055 only way to toggle the state of the indicator lights. */
3056 dpyinfo
->faked_key
= wParam
;
3057 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3058 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3059 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3060 KEYEVENTF_EXTENDEDKEY
| 0, 0);
3061 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3062 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3063 /* Ensure indicator lights are updated promptly on Windows 9x
3064 (TranslateMessage apparently does this), after forwarding
3066 post_character_message (hwnd
, msg
, wParam
, lParam
,
3067 w32_get_key_modifiers (wParam
, lParam
));
3068 windows_translate
= 1;
3072 case VK_PROCESSKEY
: /* Generated by IME. */
3073 windows_translate
= 1;
3076 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
3077 which is confusing for purposes of key binding; convert
3078 VK_CANCEL events into VK_PAUSE events. */
3082 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
3083 for purposes of key binding; convert these back into
3084 VK_NUMLOCK events, at least when we want to see NumLock key
3085 presses. (Note that there is never any possibility that
3086 VK_PAUSE with Ctrl really is C-Pause as per above.) */
3087 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
3088 wParam
= VK_NUMLOCK
;
3091 /* If not defined as a function key, change it to a WM_CHAR message. */
3092 if (lispy_function_keys
[wParam
] == 0)
3094 DWORD modifiers
= construct_console_modifiers ();
3096 if (!NILP (Vw32_recognize_altgr
)
3097 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
3099 /* Always let TranslateMessage handle AltGr key chords;
3100 for some reason, ToAscii doesn't always process AltGr
3101 chords correctly. */
3102 windows_translate
= 1;
3104 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
3106 /* Handle key chords including any modifiers other
3107 than shift directly, in order to preserve as much
3108 modifier information as possible. */
3109 if ('A' <= wParam
&& wParam
<= 'Z')
3111 /* Don't translate modified alphabetic keystrokes,
3112 so the user doesn't need to constantly switch
3113 layout to type control or meta keystrokes when
3114 the normal layout translates alphabetic
3115 characters to non-ascii characters. */
3116 if (!modifier_set (VK_SHIFT
))
3117 wParam
+= ('a' - 'A');
3122 /* Try to handle other keystrokes by determining the
3123 base character (ie. translating the base key plus
3127 KEY_EVENT_RECORD key
;
3129 key
.bKeyDown
= TRUE
;
3130 key
.wRepeatCount
= 1;
3131 key
.wVirtualKeyCode
= wParam
;
3132 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
3133 key
.uChar
.AsciiChar
= 0;
3134 key
.dwControlKeyState
= modifiers
;
3136 add
= w32_kbd_patch_key (&key
);
3137 /* 0 means an unrecognised keycode, negative means
3138 dead key. Ignore both. */
3141 /* Forward asciified character sequence. */
3142 post_character_message
3143 (hwnd
, WM_CHAR
, key
.uChar
.AsciiChar
, lParam
,
3144 w32_get_key_modifiers (wParam
, lParam
));
3145 w32_kbd_patch_key (&key
);
3152 /* Let TranslateMessage handle everything else. */
3153 windows_translate
= 1;
3159 if (windows_translate
)
3161 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
3163 windows_msg
.time
= GetMessageTime ();
3164 TranslateMessage (&windows_msg
);
3172 post_character_message (hwnd
, msg
, wParam
, lParam
,
3173 w32_get_key_modifiers (wParam
, lParam
));
3176 /* Simulate middle mouse button events when left and right buttons
3177 are used together, but only if user has two button mouse. */
3178 case WM_LBUTTONDOWN
:
3179 case WM_RBUTTONDOWN
:
3180 if (w32_num_mouse_buttons
> 2)
3181 goto handle_plain_button
;
3184 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
3185 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
3187 if (button_state
& this)
3190 if (button_state
== 0)
3193 button_state
|= this;
3195 if (button_state
& other
)
3197 if (mouse_button_timer
)
3199 KillTimer (hwnd
, mouse_button_timer
);
3200 mouse_button_timer
= 0;
3202 /* Generate middle mouse event instead. */
3203 msg
= WM_MBUTTONDOWN
;
3204 button_state
|= MMOUSE
;
3206 else if (button_state
& MMOUSE
)
3208 /* Ignore button event if we've already generated a
3209 middle mouse down event. This happens if the
3210 user releases and press one of the two buttons
3211 after we've faked a middle mouse event. */
3216 /* Flush out saved message. */
3217 post_msg (&saved_mouse_button_msg
);
3219 wmsg
.dwModifiers
= w32_get_modifiers ();
3220 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3221 signal_user_input ();
3223 /* Clear message buffer. */
3224 saved_mouse_button_msg
.msg
.hwnd
= 0;
3228 /* Hold onto message for now. */
3229 mouse_button_timer
=
3230 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
3231 w32_mouse_button_tolerance
, NULL
);
3232 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
3233 saved_mouse_button_msg
.msg
.message
= msg
;
3234 saved_mouse_button_msg
.msg
.wParam
= wParam
;
3235 saved_mouse_button_msg
.msg
.lParam
= lParam
;
3236 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
3237 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
3244 if (w32_num_mouse_buttons
> 2)
3245 goto handle_plain_button
;
3248 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
3249 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
3251 if ((button_state
& this) == 0)
3254 button_state
&= ~this;
3256 if (button_state
& MMOUSE
)
3258 /* Only generate event when second button is released. */
3259 if ((button_state
& other
) == 0)
3262 button_state
&= ~MMOUSE
;
3264 if (button_state
) abort ();
3271 /* Flush out saved message if necessary. */
3272 if (saved_mouse_button_msg
.msg
.hwnd
)
3274 post_msg (&saved_mouse_button_msg
);
3277 wmsg
.dwModifiers
= w32_get_modifiers ();
3278 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3279 signal_user_input ();
3281 /* Always clear message buffer and cancel timer. */
3282 saved_mouse_button_msg
.msg
.hwnd
= 0;
3283 KillTimer (hwnd
, mouse_button_timer
);
3284 mouse_button_timer
= 0;
3286 if (button_state
== 0)
3291 case WM_XBUTTONDOWN
:
3293 if (w32_pass_extra_mouse_buttons_to_system
)
3295 /* else fall through and process them. */
3296 case WM_MBUTTONDOWN
:
3298 handle_plain_button
:
3303 /* Ignore middle and extra buttons as long as the menu is active. */
3304 f
= x_window_to_frame (dpyinfo
, hwnd
);
3305 if (f
&& f
->output_data
.w32
->menubar_active
)
3308 if (parse_button (msg
, HIWORD (wParam
), &button
, &up
))
3310 if (up
) ReleaseCapture ();
3311 else SetCapture (hwnd
);
3312 button
= (button
== 0) ? LMOUSE
:
3313 ((button
== 1) ? MMOUSE
: RMOUSE
);
3315 button_state
&= ~button
;
3317 button_state
|= button
;
3321 wmsg
.dwModifiers
= w32_get_modifiers ();
3322 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3323 signal_user_input ();
3325 /* Need to return true for XBUTTON messages, false for others,
3326 to indicate that we processed the message. */
3327 return (msg
== WM_XBUTTONDOWN
|| msg
== WM_XBUTTONUP
);
3330 /* Ignore mouse movements as long as the menu is active. These
3331 movements are processed by the window manager anyway, and
3332 it's wrong to handle them as if they happened on the
3333 underlying frame. */
3334 f
= x_window_to_frame (dpyinfo
, hwnd
);
3335 if (f
&& f
->output_data
.w32
->menubar_active
)
3338 /* If the mouse has just moved into the frame, start tracking
3339 it, so we will be notified when it leaves the frame. Mouse
3340 tracking only works under W98 and NT4 and later. On earlier
3341 versions, there is no way of telling when the mouse leaves the
3342 frame, so we just have to put up with help-echo and mouse
3343 highlighting remaining while the frame is not active. */
3344 if (track_mouse_event_fn
&& !track_mouse_window
)
3346 TRACKMOUSEEVENT tme
;
3347 tme
.cbSize
= sizeof (tme
);
3348 tme
.dwFlags
= TME_LEAVE
;
3349 tme
.hwndTrack
= hwnd
;
3351 track_mouse_event_fn (&tme
);
3352 track_mouse_window
= hwnd
;
3355 if (w32_mouse_move_interval
<= 0
3356 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
3358 wmsg
.dwModifiers
= w32_get_modifiers ();
3359 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3363 /* Hang onto mouse move and scroll messages for a bit, to avoid
3364 sending such events to Emacs faster than it can process them.
3365 If we get more events before the timer from the first message
3366 expires, we just replace the first message. */
3368 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
3370 SetTimer (hwnd
, MOUSE_MOVE_ID
,
3371 w32_mouse_move_interval
, NULL
);
3373 /* Hold onto message for now. */
3374 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
3375 saved_mouse_move_msg
.msg
.message
= msg
;
3376 saved_mouse_move_msg
.msg
.wParam
= wParam
;
3377 saved_mouse_move_msg
.msg
.lParam
= lParam
;
3378 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
3379 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
3384 wmsg
.dwModifiers
= w32_get_modifiers ();
3385 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3386 signal_user_input ();
3390 wmsg
.dwModifiers
= w32_get_modifiers ();
3391 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3392 signal_user_input ();
3396 /* Flush out saved messages if necessary. */
3397 if (wParam
== mouse_button_timer
)
3399 if (saved_mouse_button_msg
.msg
.hwnd
)
3401 post_msg (&saved_mouse_button_msg
);
3402 signal_user_input ();
3403 saved_mouse_button_msg
.msg
.hwnd
= 0;
3405 KillTimer (hwnd
, mouse_button_timer
);
3406 mouse_button_timer
= 0;
3408 else if (wParam
== mouse_move_timer
)
3410 if (saved_mouse_move_msg
.msg
.hwnd
)
3412 post_msg (&saved_mouse_move_msg
);
3413 saved_mouse_move_msg
.msg
.hwnd
= 0;
3415 KillTimer (hwnd
, mouse_move_timer
);
3416 mouse_move_timer
= 0;
3418 else if (wParam
== menu_free_timer
)
3420 KillTimer (hwnd
, menu_free_timer
);
3421 menu_free_timer
= 0;
3422 f
= x_window_to_frame (dpyinfo
, hwnd
);
3423 /* If a popup menu is active, don't wipe its strings. */
3425 && current_popup_menu
== NULL
)
3427 /* Free memory used by owner-drawn and help-echo strings. */
3428 w32_free_menu_strings (hwnd
);
3429 f
->output_data
.w32
->menubar_active
= 0;
3436 /* Windows doesn't send us focus messages when putting up and
3437 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
3438 The only indication we get that something happened is receiving
3439 this message afterwards. So this is a good time to reset our
3440 keyboard modifiers' state. */
3447 /* We must ensure menu bar is fully constructed and up to date
3448 before allowing user interaction with it. To achieve this
3449 we send this message to the lisp thread and wait for a
3450 reply (whose value is not actually needed) to indicate that
3451 the menu bar is now ready for use, so we can now return.
3453 To remain responsive in the meantime, we enter a nested message
3454 loop that can process all other messages.
3456 However, we skip all this if the message results from calling
3457 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
3458 thread a message because it is blocked on us at this point. We
3459 set menubar_active before calling TrackPopupMenu to indicate
3460 this (there is no possibility of confusion with real menubar
3463 f
= x_window_to_frame (dpyinfo
, hwnd
);
3465 && (f
->output_data
.w32
->menubar_active
3466 /* We can receive this message even in the absence of a
3467 menubar (ie. when the system menu is activated) - in this
3468 case we do NOT want to forward the message, otherwise it
3469 will cause the menubar to suddenly appear when the user
3470 had requested it to be turned off! */
3471 || f
->output_data
.w32
->menubar_widget
== NULL
))
3475 deferred_msg msg_buf
;
3477 /* Detect if message has already been deferred; in this case
3478 we cannot return any sensible value to ignore this. */
3479 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3484 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
3487 case WM_EXITMENULOOP
:
3488 f
= x_window_to_frame (dpyinfo
, hwnd
);
3490 /* If a menu is still active, check again after a short delay,
3491 since Windows often (always?) sends the WM_EXITMENULOOP
3492 before the corresponding WM_COMMAND message.
3493 Don't do this if a popup menu is active, since it is only
3494 menubar menus that require cleaning up in this way.
3496 if (f
&& menubar_in_use
&& current_popup_menu
== NULL
)
3497 menu_free_timer
= SetTimer (hwnd
, MENU_FREE_ID
, MENU_FREE_DELAY
, NULL
);
3501 /* Direct handling of help_echo in menus. Should be safe now
3502 that we generate the help_echo by placing a help event in the
3505 HMENU menu
= (HMENU
) lParam
;
3506 UINT menu_item
= (UINT
) LOWORD (wParam
);
3507 UINT flags
= (UINT
) HIWORD (wParam
);
3509 w32_menu_display_help (hwnd
, menu
, menu_item
, flags
);
3513 case WM_MEASUREITEM
:
3514 f
= x_window_to_frame (dpyinfo
, hwnd
);
3517 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
3519 if (pMis
->CtlType
== ODT_MENU
)
3521 /* Work out dimensions for popup menu titles. */
3522 char * title
= (char *) pMis
->itemData
;
3523 HDC hdc
= GetDC (hwnd
);
3524 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3525 LOGFONT menu_logfont
;
3529 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3530 menu_logfont
.lfWeight
= FW_BOLD
;
3531 menu_font
= CreateFontIndirect (&menu_logfont
);
3532 old_font
= SelectObject (hdc
, menu_font
);
3534 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
3537 if (unicode_append_menu
)
3538 GetTextExtentPoint32W (hdc
, (WCHAR
*) title
,
3539 wcslen ((WCHAR
*) title
),
3542 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
3544 pMis
->itemWidth
= size
.cx
;
3545 if (pMis
->itemHeight
< size
.cy
)
3546 pMis
->itemHeight
= size
.cy
;
3549 pMis
->itemWidth
= 0;
3551 SelectObject (hdc
, old_font
);
3552 DeleteObject (menu_font
);
3553 ReleaseDC (hwnd
, hdc
);
3560 f
= x_window_to_frame (dpyinfo
, hwnd
);
3563 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
3565 if (pDis
->CtlType
== ODT_MENU
)
3567 /* Draw popup menu title. */
3568 char * title
= (char *) pDis
->itemData
;
3571 HDC hdc
= pDis
->hDC
;
3572 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3573 LOGFONT menu_logfont
;
3576 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3577 menu_logfont
.lfWeight
= FW_BOLD
;
3578 menu_font
= CreateFontIndirect (&menu_logfont
);
3579 old_font
= SelectObject (hdc
, menu_font
);
3581 /* Always draw title as if not selected. */
3582 if (unicode_append_menu
)
3585 + GetSystemMetrics (SM_CXMENUCHECK
),
3587 ETO_OPAQUE
, &pDis
->rcItem
,
3589 wcslen ((WCHAR
*) title
), NULL
);
3593 + GetSystemMetrics (SM_CXMENUCHECK
),
3595 ETO_OPAQUE
, &pDis
->rcItem
,
3596 title
, strlen (title
), NULL
);
3598 SelectObject (hdc
, old_font
);
3599 DeleteObject (menu_font
);
3607 /* Still not right - can't distinguish between clicks in the
3608 client area of the frame from clicks forwarded from the scroll
3609 bars - may have to hook WM_NCHITTEST to remember the mouse
3610 position and then check if it is in the client area ourselves. */
3611 case WM_MOUSEACTIVATE
:
3612 /* Discard the mouse click that activates a frame, allowing the
3613 user to click anywhere without changing point (or worse!).
3614 Don't eat mouse clicks on scrollbars though!! */
3615 if (LOWORD (lParam
) == HTCLIENT
)
3616 return MA_ACTIVATEANDEAT
;
3621 /* No longer tracking mouse. */
3622 track_mouse_window
= NULL
;
3624 case WM_ACTIVATEAPP
:
3626 case WM_WINDOWPOSCHANGED
:
3628 /* Inform lisp thread that a frame might have just been obscured
3629 or exposed, so should recheck visibility of all frames. */
3630 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3634 dpyinfo
->faked_key
= 0;
3636 register_hot_keys (hwnd
);
3639 unregister_hot_keys (hwnd
);
3642 /* Relinquish the system caret. */
3643 if (w32_system_caret_hwnd
)
3645 w32_visible_system_caret_hwnd
= NULL
;
3646 w32_system_caret_hwnd
= NULL
;
3652 f
= x_window_to_frame (dpyinfo
, hwnd
);
3653 if (f
&& HIWORD (wParam
) == 0)
3655 if (menu_free_timer
)
3657 KillTimer (hwnd
, menu_free_timer
);
3658 menu_free_timer
= 0;
3664 wmsg
.dwModifiers
= w32_get_modifiers ();
3665 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3669 wmsg
.dwModifiers
= w32_get_modifiers ();
3670 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3673 case WM_WINDOWPOSCHANGING
:
3674 /* Don't restrict the sizing of tip frames. */
3675 if (hwnd
== tip_window
)
3679 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
3681 wp
.length
= sizeof (WINDOWPLACEMENT
);
3682 GetWindowPlacement (hwnd
, &wp
);
3684 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
3691 DWORD internal_border
;
3692 DWORD scrollbar_extra
;
3695 wp
.length
= sizeof(wp
);
3696 GetWindowRect (hwnd
, &wr
);
3700 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
3701 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
3702 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
3703 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
3707 memset (&rect
, 0, sizeof (rect
));
3708 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
3709 GetMenu (hwnd
) != NULL
);
3711 /* Force width and height of client area to be exact
3712 multiples of the character cell dimensions. */
3713 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
3714 - 2 * internal_border
- scrollbar_extra
)
3716 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
3717 - 2 * internal_border
)
3722 /* For right/bottom sizing we can just fix the sizes.
3723 However for top/left sizing we will need to fix the X
3724 and Y positions as well. */
3726 int cx_mintrack
= GetSystemMetrics (SM_CXMINTRACK
);
3727 int cy_mintrack
= GetSystemMetrics (SM_CYMINTRACK
);
3729 lppos
->cx
= max (lppos
->cx
- wdiff
, cx_mintrack
);
3730 lppos
->cy
= max (lppos
->cy
- hdiff
, cy_mintrack
);
3732 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
3733 && (lppos
->flags
& SWP_NOMOVE
) == 0)
3735 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
3742 lppos
->flags
|= SWP_NOMOVE
;
3753 case WM_GETMINMAXINFO
:
3754 /* Hack to allow resizing the Emacs frame above the screen size.
3755 Note that Windows 9x limits coordinates to 16-bits. */
3756 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.x
= 32767;
3757 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.y
= 32767;
3761 if (LOWORD (lParam
) == HTCLIENT
)
3766 case WM_EMACS_SETCURSOR
:
3768 Cursor cursor
= (Cursor
) wParam
;
3774 case WM_EMACS_CREATESCROLLBAR
:
3775 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
3776 (struct scroll_bar
*) lParam
);
3778 case WM_EMACS_SHOWWINDOW
:
3779 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
3781 case WM_EMACS_SETFOREGROUND
:
3783 HWND foreground_window
;
3784 DWORD foreground_thread
, retval
;
3786 /* On NT 5.0, and apparently Windows 98, it is necessary to
3787 attach to the thread that currently has focus in order to
3788 pull the focus away from it. */
3789 foreground_window
= GetForegroundWindow ();
3790 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
3791 if (!foreground_window
3792 || foreground_thread
== GetCurrentThreadId ()
3793 || !AttachThreadInput (GetCurrentThreadId (),
3794 foreground_thread
, TRUE
))
3795 foreground_thread
= 0;
3797 retval
= SetForegroundWindow ((HWND
) wParam
);
3799 /* Detach from the previous foreground thread. */
3800 if (foreground_thread
)
3801 AttachThreadInput (GetCurrentThreadId (),
3802 foreground_thread
, FALSE
);
3807 case WM_EMACS_SETWINDOWPOS
:
3809 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
3810 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
3811 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
3814 case WM_EMACS_DESTROYWINDOW
:
3815 DragAcceptFiles ((HWND
) wParam
, FALSE
);
3816 return DestroyWindow ((HWND
) wParam
);
3818 case WM_EMACS_HIDE_CARET
:
3819 return HideCaret (hwnd
);
3821 case WM_EMACS_SHOW_CARET
:
3822 return ShowCaret (hwnd
);
3824 case WM_EMACS_DESTROY_CARET
:
3825 w32_system_caret_hwnd
= NULL
;
3826 w32_visible_system_caret_hwnd
= NULL
;
3827 return DestroyCaret ();
3829 case WM_EMACS_TRACK_CARET
:
3830 /* If there is currently no system caret, create one. */
3831 if (w32_system_caret_hwnd
== NULL
)
3833 /* Use the default caret width, and avoid changing it
3834 unneccesarily, as it confuses screen reader software. */
3835 w32_system_caret_hwnd
= hwnd
;
3836 CreateCaret (hwnd
, NULL
, 0,
3837 w32_system_caret_height
);
3840 if (!SetCaretPos (w32_system_caret_x
, w32_system_caret_y
))
3842 /* Ensure visible caret gets turned on when requested. */
3843 else if (w32_use_visible_system_caret
3844 && w32_visible_system_caret_hwnd
!= hwnd
)
3846 w32_visible_system_caret_hwnd
= hwnd
;
3847 return ShowCaret (hwnd
);
3849 /* Ensure visible caret gets turned off when requested. */
3850 else if (!w32_use_visible_system_caret
3851 && w32_visible_system_caret_hwnd
)
3853 w32_visible_system_caret_hwnd
= NULL
;
3854 return HideCaret (hwnd
);
3859 case WM_EMACS_TRACKPOPUPMENU
:
3864 pos
= (POINT
*)lParam
;
3865 flags
= TPM_CENTERALIGN
;
3866 if (button_state
& LMOUSE
)
3867 flags
|= TPM_LEFTBUTTON
;
3868 else if (button_state
& RMOUSE
)
3869 flags
|= TPM_RIGHTBUTTON
;
3871 /* Remember we did a SetCapture on the initial mouse down event,
3872 so for safety, we make sure the capture is cancelled now. */
3876 /* Use menubar_active to indicate that WM_INITMENU is from
3877 TrackPopupMenu below, and should be ignored. */
3878 f
= x_window_to_frame (dpyinfo
, hwnd
);
3880 f
->output_data
.w32
->menubar_active
= 1;
3882 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
3886 /* Eat any mouse messages during popupmenu */
3887 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
3889 /* Get the menu selection, if any */
3890 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
3892 retval
= LOWORD (amsg
.wParam
);
3908 /* Check for messages registered at runtime. */
3909 if (msg
== msh_mousewheel
)
3911 wmsg
.dwModifiers
= w32_get_modifiers ();
3912 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3913 signal_user_input ();
3918 return DefWindowProc (hwnd
, msg
, wParam
, lParam
);
3922 /* The most common default return code for handled messages is 0. */
3927 my_create_window (f
)
3932 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
3934 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
3938 /* Create a tooltip window. Unlike my_create_window, we do not do this
3939 indirectly via the Window thread, as we do not need to process Window
3940 messages for the tooltip. Creating tooltips indirectly also creates
3941 deadlocks when tooltips are created for menu items. */
3943 my_create_tip_window (f
)
3948 rect
.left
= rect
.top
= 0;
3949 rect
.right
= FRAME_PIXEL_WIDTH (f
);
3950 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
3952 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
3953 FRAME_EXTERNAL_MENU_BAR (f
));
3955 tip_window
= FRAME_W32_WINDOW (f
)
3956 = CreateWindow (EMACS_CLASS
,
3958 f
->output_data
.w32
->dwStyle
,
3961 rect
.right
- rect
.left
,
3962 rect
.bottom
- rect
.top
,
3963 FRAME_W32_WINDOW (SELECTED_FRAME ()), /* owner */
3970 SetWindowLong (tip_window
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
3971 SetWindowLong (tip_window
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
3972 SetWindowLong (tip_window
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
3973 SetWindowLong (tip_window
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
3975 /* Tip frames have no scrollbars. */
3976 SetWindowLong (tip_window
, WND_SCROLLBAR_INDEX
, 0);
3978 /* Do this to discard the default setting specified by our parent. */
3979 ShowWindow (tip_window
, SW_HIDE
);
3984 /* Create and set up the w32 window for frame F. */
3987 w32_window (f
, window_prompting
, minibuffer_only
)
3989 long window_prompting
;
3990 int minibuffer_only
;
3994 /* Use the resource name as the top-level window name
3995 for looking up resources. Make a non-Lisp copy
3996 for the window manager, so GC relocation won't bother it.
3998 Elsewhere we specify the window name for the window manager. */
4001 char *str
= (char *) SDATA (Vx_resource_name
);
4002 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
4003 strcpy (f
->namebuf
, str
);
4006 my_create_window (f
);
4008 validate_x_resource_name ();
4010 /* x_set_name normally ignores requests to set the name if the
4011 requested name is the same as the current name. This is the one
4012 place where that assumption isn't correct; f->name is set, but
4013 the server hasn't been told. */
4016 int explicit = f
->explicit_name
;
4018 f
->explicit_name
= 0;
4021 x_set_name (f
, name
, explicit);
4026 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
4027 initialize_frame_menubar (f
);
4029 if (FRAME_W32_WINDOW (f
) == 0)
4030 error ("Unable to create window");
4033 /* Handle the icon stuff for this window. Perhaps later we might
4034 want an x_set_icon_position which can be called interactively as
4042 Lisp_Object icon_x
, icon_y
;
4044 /* Set the position of the icon. Note that Windows 95 groups all
4045 icons in the tray. */
4046 icon_x
= w32_get_arg (parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
4047 icon_y
= w32_get_arg (parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
4048 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
4050 CHECK_NUMBER (icon_x
);
4051 CHECK_NUMBER (icon_y
);
4053 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
4054 error ("Both left and top icon corners of icon must be specified");
4058 if (! EQ (icon_x
, Qunbound
))
4059 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
4062 /* Start up iconic or window? */
4063 x_wm_set_window_state
4064 (f
, (EQ (w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
4068 x_text_icon (f
, (char *) SDATA ((!NILP (f
->icon_name
)
4081 XGCValues gc_values
;
4085 /* Create the GC's of this frame.
4086 Note that many default values are used. */
4089 gc_values
.font
= FRAME_FONT (f
);
4091 /* Cursor has cursor-color background, background-color foreground. */
4092 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
4093 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
4094 f
->output_data
.w32
->cursor_gc
4095 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
4096 (GCFont
| GCForeground
| GCBackground
),
4100 f
->output_data
.w32
->white_relief
.gc
= 0;
4101 f
->output_data
.w32
->black_relief
.gc
= 0;
4107 /* Handler for signals raised during x_create_frame and
4108 x_create_top_frame. FRAME is the frame which is partially
4112 unwind_create_frame (frame
)
4115 struct frame
*f
= XFRAME (frame
);
4117 /* If frame is ``official'', nothing to do. */
4118 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
4121 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4124 x_free_frame_resources (f
);
4126 /* Check that reference counts are indeed correct. */
4127 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
4128 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
4136 #ifdef USE_FONT_BACKEND
4138 x_default_font_parameter (f
, parms
)
4142 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4143 Lisp_Object font
= x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font",
4146 if (!STRINGP (font
))
4149 static char *names
[]
4150 = { "Courier New-10",
4151 "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1",
4152 "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1",
4156 for (i
= 0; names
[i
]; i
++)
4158 font
= font_open_by_name (f
, names
[i
]);
4163 error ("No suitable font was found");
4165 x_default_parameter (f
, parms
, Qfont
, font
, "font", "Font", RES_TYPE_STRING
);
4169 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
4171 doc
: /* Make a new window, which is called a \"frame\" in Emacs terms.
4172 Returns an Emacs frame object.
4173 PARAMETERS is an alist of frame parameters.
4174 If the parameters specify that the frame should not have a minibuffer,
4175 and do not specify a specific minibuffer window to use,
4176 then `default-minibuffer-frame' must be a frame whose minibuffer can
4177 be shared by the new frame.
4179 This function is an internal primitive--use `make-frame' instead. */)
4181 Lisp_Object parameters
;
4184 Lisp_Object frame
, tem
;
4186 int minibuffer_only
= 0;
4187 long window_prompting
= 0;
4189 int count
= SPECPDL_INDEX ();
4190 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4191 Lisp_Object display
;
4192 struct w32_display_info
*dpyinfo
= NULL
;
4198 /* Use this general default value to start with
4199 until we know if this frame has a specified name. */
4200 Vx_resource_name
= Vinvocation_name
;
4202 display
= w32_get_arg (parameters
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
4203 if (EQ (display
, Qunbound
))
4205 dpyinfo
= check_x_display_info (display
);
4207 kb
= dpyinfo
->kboard
;
4209 kb
= &the_only_kboard
;
4212 name
= w32_get_arg (parameters
, Qname
, "name", "Name", RES_TYPE_STRING
);
4214 && ! EQ (name
, Qunbound
)
4216 error ("Invalid frame name--not a string or nil");
4219 Vx_resource_name
= name
;
4221 /* See if parent window is specified. */
4222 parent
= w32_get_arg (parameters
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
4223 if (EQ (parent
, Qunbound
))
4225 if (! NILP (parent
))
4226 CHECK_NUMBER (parent
);
4228 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
4229 /* No need to protect DISPLAY because that's not used after passing
4230 it to make_frame_without_minibuffer. */
4232 GCPRO4 (parameters
, parent
, name
, frame
);
4233 tem
= w32_get_arg (parameters
, Qminibuffer
, "minibuffer", "Minibuffer",
4235 if (EQ (tem
, Qnone
) || NILP (tem
))
4236 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
4237 else if (EQ (tem
, Qonly
))
4239 f
= make_minibuffer_frame ();
4240 minibuffer_only
= 1;
4242 else if (WINDOWP (tem
))
4243 f
= make_frame_without_minibuffer (tem
, kb
, display
);
4247 XSETFRAME (frame
, f
);
4249 /* Note that Windows does support scroll bars. */
4250 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
4252 /* By default, make scrollbars the system standard width. */
4253 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
4255 f
->output_method
= output_w32
;
4256 f
->output_data
.w32
=
4257 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
4258 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
4259 FRAME_FONTSET (f
) = -1;
4260 record_unwind_protect (unwind_create_frame
, frame
);
4263 = w32_get_arg (parameters
, Qicon_name
, "iconName", "Title", RES_TYPE_STRING
);
4264 if (! STRINGP (f
->icon_name
))
4265 f
->icon_name
= Qnil
;
4267 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
4269 FRAME_KBOARD (f
) = kb
;
4272 /* Specify the parent under which to make this window. */
4276 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
4277 f
->output_data
.w32
->explicit_parent
= 1;
4281 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4282 f
->output_data
.w32
->explicit_parent
= 0;
4285 /* Set the name; the functions to which we pass f expect the name to
4287 if (EQ (name
, Qunbound
) || NILP (name
))
4289 f
->name
= build_string (dpyinfo
->w32_id_name
);
4290 f
->explicit_name
= 0;
4295 f
->explicit_name
= 1;
4296 /* use the frame's title when getting resources for this frame. */
4297 specbind (Qx_resource_name
, name
);
4300 f
->resx
= dpyinfo
->resx
;
4301 f
->resy
= dpyinfo
->resy
;
4303 #ifdef USE_FONT_BACKEND
4304 if (enable_font_backend
)
4306 /* Perhaps, we must allow frame parameter, say `font-backend',
4307 to specify which font backends to use. */
4308 register_font_driver (&w32font_driver
, f
);
4310 x_default_parameter (f
, parameters
, Qfont_backend
, Qnil
,
4311 "fontBackend", "FontBackend", RES_TYPE_STRING
);
4313 #endif /* USE_FONT_BACKEND */
4315 /* Extract the window parameters from the supplied values
4316 that are needed to determine window geometry. */
4317 #ifdef USE_FONT_BACKEND
4318 if (enable_font_backend
)
4319 x_default_font_parameter (f
, parameters
);
4325 font
= w32_get_arg (parameters
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4328 /* First, try whatever font the caller has specified. */
4331 tem
= Fquery_fontset (font
, Qnil
);
4333 font
= x_new_fontset (f
, tem
);
4335 font
= x_new_font (f
, SDATA (font
));
4337 /* Try out a font which we hope has bold and italic variations. */
4338 if (!STRINGP (font
))
4339 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
4340 if (! STRINGP (font
))
4341 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
4342 /* If those didn't work, look for something which will at least work. */
4343 if (! STRINGP (font
))
4344 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
4346 if (! STRINGP (font
))
4347 font
= build_string ("Fixedsys");
4349 x_default_parameter (f
, parameters
, Qfont
, font
,
4350 "font", "Font", RES_TYPE_STRING
);
4353 x_default_parameter (f
, parameters
, Qborder_width
, make_number (2),
4354 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4355 /* This defaults to 2 in order to match xterm. We recognize either
4356 internalBorderWidth or internalBorder (which is what xterm calls
4358 if (NILP (Fassq (Qinternal_border_width
, parameters
)))
4362 value
= w32_get_arg (parameters
, Qinternal_border_width
,
4363 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
4364 if (! EQ (value
, Qunbound
))
4365 parameters
= Fcons (Fcons (Qinternal_border_width
, value
),
4368 /* Default internalBorderWidth to 0 on Windows to match other programs. */
4369 x_default_parameter (f
, parameters
, Qinternal_border_width
, make_number (0),
4370 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
4371 x_default_parameter (f
, parameters
, Qvertical_scroll_bars
, Qright
,
4372 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
4374 /* Also do the stuff which must be set before the window exists. */
4375 x_default_parameter (f
, parameters
, Qforeground_color
, build_string ("black"),
4376 "foreground", "Foreground", RES_TYPE_STRING
);
4377 x_default_parameter (f
, parameters
, Qbackground_color
, build_string ("white"),
4378 "background", "Background", RES_TYPE_STRING
);
4379 x_default_parameter (f
, parameters
, Qmouse_color
, build_string ("black"),
4380 "pointerColor", "Foreground", RES_TYPE_STRING
);
4381 x_default_parameter (f
, parameters
, Qcursor_color
, build_string ("black"),
4382 "cursorColor", "Foreground", RES_TYPE_STRING
);
4383 x_default_parameter (f
, parameters
, Qborder_color
, build_string ("black"),
4384 "borderColor", "BorderColor", RES_TYPE_STRING
);
4385 x_default_parameter (f
, parameters
, Qscreen_gamma
, Qnil
,
4386 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
4387 x_default_parameter (f
, parameters
, Qline_spacing
, Qnil
,
4388 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
4389 x_default_parameter (f
, parameters
, Qleft_fringe
, Qnil
,
4390 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
4391 x_default_parameter (f
, parameters
, Qright_fringe
, Qnil
,
4392 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
4395 /* Init faces before x_default_parameter is called for scroll-bar
4396 parameters because that function calls x_set_scroll_bar_width,
4397 which calls change_frame_size, which calls Fset_window_buffer,
4398 which runs hooks, which call Fvertical_motion. At the end, we
4399 end up in init_iterator with a null face cache, which should not
4401 init_frame_faces (f
);
4403 x_default_parameter (f
, parameters
, Qmenu_bar_lines
, make_number (1),
4404 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
4405 x_default_parameter (f
, parameters
, Qtool_bar_lines
, make_number (1),
4406 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
4408 x_default_parameter (f
, parameters
, Qbuffer_predicate
, Qnil
,
4409 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
4410 x_default_parameter (f
, parameters
, Qtitle
, Qnil
,
4411 "title", "Title", RES_TYPE_STRING
);
4412 x_default_parameter (f
, parameters
, Qfullscreen
, Qnil
,
4413 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
4415 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
4416 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4418 f
->output_data
.w32
->text_cursor
= w32_load_cursor (IDC_IBEAM
);
4419 f
->output_data
.w32
->nontext_cursor
= w32_load_cursor (IDC_ARROW
);
4420 f
->output_data
.w32
->modeline_cursor
= w32_load_cursor (IDC_ARROW
);
4421 f
->output_data
.w32
->hand_cursor
= w32_load_cursor (IDC_HAND
);
4422 f
->output_data
.w32
->hourglass_cursor
= w32_load_cursor (IDC_WAIT
);
4423 f
->output_data
.w32
->horizontal_drag_cursor
= w32_load_cursor (IDC_SIZEWE
);
4425 window_prompting
= x_figure_window_size (f
, parameters
, 1);
4427 tem
= w32_get_arg (parameters
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
4428 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
4430 w32_window (f
, window_prompting
, minibuffer_only
);
4431 x_icon (f
, parameters
);
4435 /* Now consider the frame official. */
4436 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
4437 Vframe_list
= Fcons (frame
, Vframe_list
);
4439 /* We need to do this after creating the window, so that the
4440 icon-creation functions can say whose icon they're describing. */
4441 x_default_parameter (f
, parameters
, Qicon_type
, Qnil
,
4442 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
4444 x_default_parameter (f
, parameters
, Qauto_raise
, Qnil
,
4445 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4446 x_default_parameter (f
, parameters
, Qauto_lower
, Qnil
,
4447 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4448 x_default_parameter (f
, parameters
, Qcursor_type
, Qbox
,
4449 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4450 x_default_parameter (f
, parameters
, Qscroll_bar_width
, Qnil
,
4451 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
4453 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4454 Change will not be effected unless different from the current
4456 width
= FRAME_COLS (f
);
4457 height
= FRAME_LINES (f
);
4459 FRAME_LINES (f
) = 0;
4460 SET_FRAME_COLS (f
, 0);
4461 change_frame_size (f
, height
, width
, 1, 0, 0);
4463 /* Tell the server what size and position, etc, we want, and how
4464 badly we want them. This should be done after we have the menu
4465 bar so that its size can be taken into account. */
4467 x_wm_set_size_hint (f
, window_prompting
, 0);
4470 /* Make the window appear on the frame and enable display, unless
4471 the caller says not to. However, with explicit parent, Emacs
4472 cannot control visibility, so don't try. */
4473 if (! f
->output_data
.w32
->explicit_parent
)
4475 Lisp_Object visibility
;
4477 visibility
= w32_get_arg (parameters
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
4478 if (EQ (visibility
, Qunbound
))
4481 if (EQ (visibility
, Qicon
))
4482 x_iconify_frame (f
);
4483 else if (! NILP (visibility
))
4484 x_make_frame_visible (f
);
4486 /* Must have been Qnil. */
4491 /* Make sure windows on this frame appear in calls to next-window
4492 and similar functions. */
4493 Vwindow_list
= Qnil
;
4495 return unbind_to (count
, frame
);
4498 /* FRAME is used only to get a handle on the X display. We don't pass the
4499 display info directly because we're called from frame.c, which doesn't
4500 know about that structure. */
4502 x_get_focus_frame (frame
)
4503 struct frame
*frame
;
4505 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
4507 if (! dpyinfo
->w32_focus_frame
)
4510 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
4514 DEFUN ("w32-focus-frame", Fw32_focus_frame
, Sw32_focus_frame
, 1, 1, 0,
4515 doc
: /* Give FRAME input focus, raising to foreground if necessary. */)
4519 x_focus_on_frame (check_x_frame (frame
));
4524 /* Return the charset portion of a font name. */
4525 char * xlfd_charset_of_font (char * fontname
)
4527 char *charset
, *encoding
;
4529 encoding
= strrchr(fontname
, '-');
4530 if (!encoding
|| encoding
== fontname
)
4533 for (charset
= encoding
- 1; charset
>= fontname
; charset
--)
4534 if (*charset
== '-')
4537 if (charset
== fontname
|| strcmp(charset
, "-*-*") == 0)
4543 struct font_info
*w32_load_bdf_font (struct frame
*f
, char *fontname
,
4544 int size
, char* filename
);
4545 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
);
4546 static BOOL
w32_to_x_font (LOGFONT
* lplf
, char * lpxstr
, int len
,
4548 static BOOL
x_to_w32_font (char *lpxstr
, LOGFONT
*lplogfont
);
4550 static struct font_info
*
4551 w32_load_system_font (f
,fontname
,size
)
4556 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4557 Lisp_Object font_names
;
4559 /* Get a list of all the fonts that match this name. Once we
4560 have a list of matching fonts, we compare them against the fonts
4561 we already have loaded by comparing names. */
4562 font_names
= w32_list_fonts (f
, build_string (fontname
), size
, 100);
4564 if (!NILP (font_names
))
4569 /* First check if any are already loaded, as that is cheaper
4570 than loading another one. */
4571 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
4572 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
4573 if (dpyinfo
->font_table
[i
].name
4574 && (!strcmp (dpyinfo
->font_table
[i
].name
,
4575 SDATA (XCAR (tail
)))
4576 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
4577 SDATA (XCAR (tail
)))))
4578 return (dpyinfo
->font_table
+ i
);
4580 fontname
= (char *) SDATA (XCAR (font_names
));
4582 else if (w32_strict_fontnames
)
4584 /* If EnumFontFamiliesEx was available, we got a full list of
4585 fonts back so stop now to avoid the possibility of loading a
4586 random font. If we had to fall back to EnumFontFamilies, the
4587 list is incomplete, so continue whether the font we want was
4589 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
4590 FARPROC enum_font_families_ex
4591 = GetProcAddress (gdi32
, "EnumFontFamiliesExA");
4592 if (enum_font_families_ex
)
4596 /* Load the font and add it to the table. */
4598 char *full_name
, *encoding
, *charset
;
4600 struct font_info
*fontp
;
4606 if (!fontname
|| !x_to_w32_font (fontname
, &lf
))
4609 if (!*lf
.lfFaceName
)
4610 /* If no name was specified for the font, we get a random font
4611 from CreateFontIndirect - this is not particularly
4612 desirable, especially since CreateFontIndirect does not
4613 fill out the missing name in lf, so we never know what we
4617 lf
.lfQuality
= DEFAULT_QUALITY
;
4619 font
= (XFontStruct
*) xmalloc (sizeof (XFontStruct
));
4620 bzero (font
, sizeof (*font
));
4622 /* Set bdf to NULL to indicate that this is a Windows font. */
4627 font
->hfont
= CreateFontIndirect (&lf
);
4629 if (font
->hfont
== NULL
)
4638 codepage
= w32_codepage_for_font (fontname
);
4640 hdc
= GetDC (dpyinfo
->root_window
);
4641 oldobj
= SelectObject (hdc
, font
->hfont
);
4643 ok
= GetTextMetrics (hdc
, &font
->tm
);
4644 if (codepage
== CP_UNICODE
)
4645 font
->double_byte_p
= 1;
4648 /* Unfortunately, some fonts (eg. MingLiU, a big5 ttf font)
4649 don't report themselves as double byte fonts, when
4650 patently they are. So instead of trusting
4651 GetFontLanguageInfo, we check the properties of the
4652 codepage directly, since that is ultimately what we are
4653 working from anyway. */
4654 /* font->double_byte_p = GetFontLanguageInfo(hdc) & GCP_DBCS; */
4656 GetCPInfo (codepage
, &cpi
);
4657 font
->double_byte_p
= cpi
.MaxCharSize
> 1;
4660 SelectObject (hdc
, oldobj
);
4661 ReleaseDC (dpyinfo
->root_window
, hdc
);
4662 /* Fill out details in lf according to the font that was
4664 lf
.lfHeight
= font
->tm
.tmInternalLeading
- font
->tm
.tmHeight
;
4665 lf
.lfWidth
= font
->tm
.tmMaxCharWidth
;
4666 lf
.lfWeight
= font
->tm
.tmWeight
;
4667 lf
.lfItalic
= font
->tm
.tmItalic
;
4668 lf
.lfCharSet
= font
->tm
.tmCharSet
;
4669 lf
.lfPitchAndFamily
= ((font
->tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
)
4670 ? VARIABLE_PITCH
: FIXED_PITCH
);
4671 lf
.lfOutPrecision
= ((font
->tm
.tmPitchAndFamily
& TMPF_VECTOR
)
4672 ? OUT_STROKE_PRECIS
: OUT_STRING_PRECIS
);
4674 w32_cache_char_metrics (font
);
4681 w32_unload_font (dpyinfo
, font
);
4685 /* Find a free slot in the font table. */
4686 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
4687 if (dpyinfo
->font_table
[i
].name
== NULL
)
4690 /* If no free slot found, maybe enlarge the font table. */
4691 if (i
== dpyinfo
->n_fonts
4692 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
4695 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
4696 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
4698 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
4701 fontp
= dpyinfo
->font_table
+ i
;
4702 if (i
== dpyinfo
->n_fonts
)
4705 /* Now fill in the slots of *FONTP. */
4707 bzero (fontp
, sizeof (*fontp
));
4709 fontp
->font_idx
= i
;
4710 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
4711 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
4713 if ((lf
.lfPitchAndFamily
& 0x03) == FIXED_PITCH
)
4715 /* Fixed width font. */
4716 fontp
->average_width
= fontp
->space_width
= FONT_WIDTH (font
);
4722 pcm
= w32_per_char_metric (font
, &space
, ANSI_FONT
);
4724 fontp
->space_width
= pcm
->width
;
4726 fontp
->space_width
= FONT_WIDTH (font
);
4728 fontp
->average_width
= font
->tm
.tmAveCharWidth
;
4731 fontp
->charset
= -1;
4732 charset
= xlfd_charset_of_font (fontname
);
4734 /* Cache the W32 codepage for a font. This makes w32_encode_char
4735 (called for every glyph during redisplay) much faster. */
4736 fontp
->codepage
= codepage
;
4738 /* Work out the font's full name. */
4739 full_name
= (char *)xmalloc (100);
4740 if (full_name
&& w32_to_x_font (&lf
, full_name
, 100, charset
))
4741 fontp
->full_name
= full_name
;
4744 /* If all else fails - just use the name we used to load it. */
4746 fontp
->full_name
= fontp
->name
;
4749 fontp
->size
= FONT_WIDTH (font
);
4750 fontp
->height
= FONT_HEIGHT (font
);
4752 /* The slot `encoding' specifies how to map a character
4753 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
4754 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
4755 (0:0x20..0x7F, 1:0xA0..0xFF,
4756 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
4757 2:0xA020..0xFF7F). For the moment, we don't know which charset
4758 uses this font. So, we set information in fontp->encoding_type
4759 which is never used by any charset. If mapping can't be
4760 decided, set FONT_ENCODING_NOT_DECIDED. */
4762 /* SJIS fonts need to be set to type 4, all others seem to work as
4763 type FONT_ENCODING_NOT_DECIDED. */
4764 encoding
= strrchr (fontp
->name
, '-');
4765 if (encoding
&& strnicmp (encoding
+1, "sjis", 4) == 0)
4766 fontp
->encoding_type
= 4;
4768 fontp
->encoding_type
= FONT_ENCODING_NOT_DECIDED
;
4770 /* The following three values are set to 0 under W32, which is
4771 what they get set to if XGetFontProperty fails under X. */
4772 fontp
->baseline_offset
= 0;
4773 fontp
->relative_compose
= 0;
4774 fontp
->default_ascent
= 0;
4776 /* Set global flag fonts_changed_p to non-zero if the font loaded
4777 has a character with a smaller width than any other character
4778 before, or if the font loaded has a smaller height than any
4779 other font loaded before. If this happens, it will make a
4780 glyph matrix reallocation necessary. */
4781 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
4787 /* Load font named FONTNAME of size SIZE for frame F, and return a
4788 pointer to the structure font_info while allocating it dynamically.
4789 If loading fails, return NULL. */
4791 w32_load_font (f
,fontname
,size
)
4796 Lisp_Object bdf_fonts
;
4797 struct font_info
*retval
= NULL
;
4798 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4800 bdf_fonts
= w32_list_bdf_fonts (build_string (fontname
), 1);
4802 while (!retval
&& CONSP (bdf_fonts
))
4804 char *bdf_name
, *bdf_file
;
4805 Lisp_Object bdf_pair
;
4808 bdf_name
= SDATA (XCAR (bdf_fonts
));
4809 bdf_pair
= Fassoc (XCAR (bdf_fonts
), Vw32_bdf_filename_alist
);
4810 bdf_file
= SDATA (XCDR (bdf_pair
));
4812 // If the font is already loaded, do not load it again.
4813 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
4815 if ((dpyinfo
->font_table
[i
].name
4816 && !strcmp (dpyinfo
->font_table
[i
].name
, bdf_name
))
4817 || (dpyinfo
->font_table
[i
].full_name
4818 && !strcmp (dpyinfo
->font_table
[i
].full_name
, bdf_name
)))
4819 return dpyinfo
->font_table
+ i
;
4822 retval
= w32_load_bdf_font (f
, bdf_name
, size
, bdf_file
);
4824 bdf_fonts
= XCDR (bdf_fonts
);
4830 return w32_load_system_font(f
, fontname
, size
);
4835 w32_unload_font (dpyinfo
, font
)
4836 struct w32_display_info
*dpyinfo
;
4841 if (font
->per_char
) xfree (font
->per_char
);
4842 if (font
->bdf
) w32_free_bdf_font (font
->bdf
);
4844 if (font
->hfont
) DeleteObject(font
->hfont
);
4849 /* The font conversion stuff between x and w32 */
4851 /* X font string is as follows (from faces.el)
4855 * (weight "\\(bold\\|demibold\\|medium\\)") ; 1
4856 * (weight\? "\\([^-]*\\)") ; 1
4857 * (slant "\\([ior]\\)") ; 2
4858 * (slant\? "\\([^-]?\\)") ; 2
4859 * (swidth "\\([^-]*\\)") ; 3
4860 * (adstyle "[^-]*") ; 4
4861 * (pixelsize "[0-9]+")
4862 * (pointsize "[0-9][0-9]+")
4863 * (resx "[0-9][0-9]+")
4864 * (resy "[0-9][0-9]+")
4865 * (spacing "[cmp?*]")
4866 * (avgwidth "[0-9]+")
4867 * (registry "[^-]+")
4868 * (encoding "[^-]+")
4873 x_to_w32_weight (lpw
)
4876 if (!lpw
) return (FW_DONTCARE
);
4878 if (stricmp (lpw
,"heavy") == 0) return FW_HEAVY
;
4879 else if (stricmp (lpw
,"extrabold") == 0) return FW_EXTRABOLD
;
4880 else if (stricmp (lpw
,"bold") == 0) return FW_BOLD
;
4881 else if (stricmp (lpw
,"demibold") == 0) return FW_SEMIBOLD
;
4882 else if (stricmp (lpw
,"semibold") == 0) return FW_SEMIBOLD
;
4883 else if (stricmp (lpw
,"medium") == 0) return FW_MEDIUM
;
4884 else if (stricmp (lpw
,"normal") == 0) return FW_NORMAL
;
4885 else if (stricmp (lpw
,"light") == 0) return FW_LIGHT
;
4886 else if (stricmp (lpw
,"extralight") == 0) return FW_EXTRALIGHT
;
4887 else if (stricmp (lpw
,"thin") == 0) return FW_THIN
;
4894 w32_to_x_weight (fnweight
)
4897 if (fnweight
>= FW_HEAVY
) return "heavy";
4898 if (fnweight
>= FW_EXTRABOLD
) return "extrabold";
4899 if (fnweight
>= FW_BOLD
) return "bold";
4900 if (fnweight
>= FW_SEMIBOLD
) return "demibold";
4901 if (fnweight
>= FW_MEDIUM
) return "medium";
4902 if (fnweight
>= FW_NORMAL
) return "normal";
4903 if (fnweight
>= FW_LIGHT
) return "light";
4904 if (fnweight
>= FW_EXTRALIGHT
) return "extralight";
4905 if (fnweight
>= FW_THIN
) return "thin";
4911 x_to_w32_charset (lpcs
)
4914 Lisp_Object this_entry
, w32_charset
;
4916 int len
= strlen (lpcs
);
4918 /* Support "*-#nnn" format for unknown charsets. */
4919 if (strncmp (lpcs
, "*-#", 3) == 0)
4920 return atoi (lpcs
+ 3);
4922 /* All Windows fonts qualify as unicode. */
4923 if (!strncmp (lpcs
, "iso10646", 8))
4924 return DEFAULT_CHARSET
;
4926 /* Handle wildcards by ignoring them; eg. treat "big5*-*" as "big5". */
4927 charset
= alloca (len
+ 1);
4928 strcpy (charset
, lpcs
);
4929 lpcs
= strchr (charset
, '*');
4933 /* Look through w32-charset-info-alist for the character set.
4934 Format of each entry is
4935 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
4937 this_entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
4939 if (NILP(this_entry
))
4941 /* At startup, we want iso8859-1 fonts to come up properly. */
4942 if (stricmp(charset
, "iso8859-1") == 0)
4943 return ANSI_CHARSET
;
4945 return DEFAULT_CHARSET
;
4948 w32_charset
= Fcar (Fcdr (this_entry
));
4950 /* Translate Lisp symbol to number. */
4951 if (EQ (w32_charset
, Qw32_charset_ansi
))
4952 return ANSI_CHARSET
;
4953 if (EQ (w32_charset
, Qw32_charset_symbol
))
4954 return SYMBOL_CHARSET
;
4955 if (EQ (w32_charset
, Qw32_charset_shiftjis
))
4956 return SHIFTJIS_CHARSET
;
4957 if (EQ (w32_charset
, Qw32_charset_hangeul
))
4958 return HANGEUL_CHARSET
;
4959 if (EQ (w32_charset
, Qw32_charset_chinesebig5
))
4960 return CHINESEBIG5_CHARSET
;
4961 if (EQ (w32_charset
, Qw32_charset_gb2312
))
4962 return GB2312_CHARSET
;
4963 if (EQ (w32_charset
, Qw32_charset_oem
))
4965 #ifdef JOHAB_CHARSET
4966 if (EQ (w32_charset
, Qw32_charset_johab
))
4967 return JOHAB_CHARSET
;
4968 if (EQ (w32_charset
, Qw32_charset_easteurope
))
4969 return EASTEUROPE_CHARSET
;
4970 if (EQ (w32_charset
, Qw32_charset_turkish
))
4971 return TURKISH_CHARSET
;
4972 if (EQ (w32_charset
, Qw32_charset_baltic
))
4973 return BALTIC_CHARSET
;
4974 if (EQ (w32_charset
, Qw32_charset_russian
))
4975 return RUSSIAN_CHARSET
;
4976 if (EQ (w32_charset
, Qw32_charset_arabic
))
4977 return ARABIC_CHARSET
;
4978 if (EQ (w32_charset
, Qw32_charset_greek
))
4979 return GREEK_CHARSET
;
4980 if (EQ (w32_charset
, Qw32_charset_hebrew
))
4981 return HEBREW_CHARSET
;
4982 if (EQ (w32_charset
, Qw32_charset_vietnamese
))
4983 return VIETNAMESE_CHARSET
;
4984 if (EQ (w32_charset
, Qw32_charset_thai
))
4985 return THAI_CHARSET
;
4986 if (EQ (w32_charset
, Qw32_charset_mac
))
4988 #endif /* JOHAB_CHARSET */
4989 #ifdef UNICODE_CHARSET
4990 if (EQ (w32_charset
, Qw32_charset_unicode
))
4991 return UNICODE_CHARSET
;
4994 return DEFAULT_CHARSET
;
4999 w32_to_x_charset (fncharset
, matching
)
5003 static char buf
[32];
5004 Lisp_Object charset_type
;
5009 /* If fully specified, accept it as it is. Otherwise use a
5011 char *wildcard
= strchr (matching
, '*');
5014 else if (strchr (matching
, '-'))
5017 match_len
= strlen (matching
);
5023 /* Handle startup case of w32-charset-info-alist not
5024 being set up yet. */
5025 if (NILP(Vw32_charset_info_alist
))
5027 charset_type
= Qw32_charset_ansi
;
5029 case DEFAULT_CHARSET
:
5030 charset_type
= Qw32_charset_default
;
5032 case SYMBOL_CHARSET
:
5033 charset_type
= Qw32_charset_symbol
;
5035 case SHIFTJIS_CHARSET
:
5036 charset_type
= Qw32_charset_shiftjis
;
5038 case HANGEUL_CHARSET
:
5039 charset_type
= Qw32_charset_hangeul
;
5041 case GB2312_CHARSET
:
5042 charset_type
= Qw32_charset_gb2312
;
5044 case CHINESEBIG5_CHARSET
:
5045 charset_type
= Qw32_charset_chinesebig5
;
5048 charset_type
= Qw32_charset_oem
;
5051 /* More recent versions of Windows (95 and NT4.0) define more
5053 #ifdef EASTEUROPE_CHARSET
5054 case EASTEUROPE_CHARSET
:
5055 charset_type
= Qw32_charset_easteurope
;
5057 case TURKISH_CHARSET
:
5058 charset_type
= Qw32_charset_turkish
;
5060 case BALTIC_CHARSET
:
5061 charset_type
= Qw32_charset_baltic
;
5063 case RUSSIAN_CHARSET
:
5064 charset_type
= Qw32_charset_russian
;
5066 case ARABIC_CHARSET
:
5067 charset_type
= Qw32_charset_arabic
;
5070 charset_type
= Qw32_charset_greek
;
5072 case HEBREW_CHARSET
:
5073 charset_type
= Qw32_charset_hebrew
;
5075 case VIETNAMESE_CHARSET
:
5076 charset_type
= Qw32_charset_vietnamese
;
5079 charset_type
= Qw32_charset_thai
;
5082 charset_type
= Qw32_charset_mac
;
5085 charset_type
= Qw32_charset_johab
;
5089 #ifdef UNICODE_CHARSET
5090 case UNICODE_CHARSET
:
5091 charset_type
= Qw32_charset_unicode
;
5095 /* Encode numerical value of unknown charset. */
5096 sprintf (buf
, "*-#%u", fncharset
);
5102 char * best_match
= NULL
;
5103 int matching_found
= 0;
5105 /* Look through w32-charset-info-alist for the character set.
5106 Prefer ISO codepages, and prefer lower numbers in the ISO
5107 range. Only return charsets for codepages which are installed.
5109 Format of each entry is
5110 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5112 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
5115 Lisp_Object w32_charset
;
5116 Lisp_Object codepage
;
5118 Lisp_Object this_entry
= XCAR (rest
);
5120 /* Skip invalid entries in alist. */
5121 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
5122 || !CONSP (XCDR (this_entry
))
5123 || !SYMBOLP (XCAR (XCDR (this_entry
))))
5126 x_charset
= SDATA (XCAR (this_entry
));
5127 w32_charset
= XCAR (XCDR (this_entry
));
5128 codepage
= XCDR (XCDR (this_entry
));
5130 /* Look for Same charset and a valid codepage (or non-int
5131 which means ignore). */
5132 if (EQ (w32_charset
, charset_type
)
5133 && (!INTEGERP (codepage
) || XINT (codepage
) == CP_DEFAULT
5134 || IsValidCodePage (XINT (codepage
))))
5136 /* If we don't have a match already, then this is the
5140 best_match
= x_charset
;
5141 if (matching
&& !strnicmp (x_charset
, matching
, match_len
))
5144 /* If we already found a match for MATCHING, then
5145 only consider other matches. */
5146 else if (matching_found
5147 && strnicmp (x_charset
, matching
, match_len
))
5149 /* If this matches what we want, and the best so far doesn't,
5150 then this is better. */
5151 else if (!matching_found
&& matching
5152 && !strnicmp (x_charset
, matching
, match_len
))
5154 best_match
= x_charset
;
5157 /* If this is fully specified, and the best so far isn't,
5158 then this is better. */
5159 else if ((!strchr (best_match
, '-') && strchr (x_charset
, '-'))
5160 /* If this is an ISO codepage, and the best so far isn't,
5161 then this is better, but only if it fully specifies the
5163 || (strnicmp (best_match
, "iso", 3) != 0
5164 && strnicmp (x_charset
, "iso", 3) == 0
5165 && strchr (x_charset
, '-')))
5166 best_match
= x_charset
;
5167 /* If both are ISO8859 codepages, choose the one with the
5168 lowest number in the encoding field. */
5169 else if (strnicmp (best_match
, "iso8859-", 8) == 0
5170 && strnicmp (x_charset
, "iso8859-", 8) == 0)
5172 int best_enc
= atoi (best_match
+ 8);
5173 int this_enc
= atoi (x_charset
+ 8);
5174 if (this_enc
> 0 && this_enc
< best_enc
)
5175 best_match
= x_charset
;
5180 /* If no match, encode the numeric value. */
5183 sprintf (buf
, "*-#%u", fncharset
);
5187 strncpy (buf
, best_match
, 31);
5188 /* If the charset is not fully specified, put -0 on the end. */
5189 if (!strchr (best_match
, '-'))
5191 int pos
= strlen (best_match
);
5192 /* Charset specifiers shouldn't be very long. If it is a made
5193 up one, truncating it should not do any harm since it isn't
5194 recognized anyway. */
5197 strcpy (buf
+ pos
, "-0");
5205 /* Return all the X charsets that map to a font. */
5207 w32_to_all_x_charsets (fncharset
)
5210 static char buf
[32];
5211 Lisp_Object charset_type
;
5212 Lisp_Object retval
= Qnil
;
5217 /* Handle startup case of w32-charset-info-alist not
5218 being set up yet. */
5219 if (NILP(Vw32_charset_info_alist
))
5220 return Fcons (build_string ("iso8859-1"), Qnil
);
5222 charset_type
= Qw32_charset_ansi
;
5224 case DEFAULT_CHARSET
:
5225 charset_type
= Qw32_charset_default
;
5227 case SYMBOL_CHARSET
:
5228 charset_type
= Qw32_charset_symbol
;
5230 case SHIFTJIS_CHARSET
:
5231 charset_type
= Qw32_charset_shiftjis
;
5233 case HANGEUL_CHARSET
:
5234 charset_type
= Qw32_charset_hangeul
;
5236 case GB2312_CHARSET
:
5237 charset_type
= Qw32_charset_gb2312
;
5239 case CHINESEBIG5_CHARSET
:
5240 charset_type
= Qw32_charset_chinesebig5
;
5243 charset_type
= Qw32_charset_oem
;
5246 /* More recent versions of Windows (95 and NT4.0) define more
5248 #ifdef EASTEUROPE_CHARSET
5249 case EASTEUROPE_CHARSET
:
5250 charset_type
= Qw32_charset_easteurope
;
5252 case TURKISH_CHARSET
:
5253 charset_type
= Qw32_charset_turkish
;
5255 case BALTIC_CHARSET
:
5256 charset_type
= Qw32_charset_baltic
;
5258 case RUSSIAN_CHARSET
:
5259 charset_type
= Qw32_charset_russian
;
5261 case ARABIC_CHARSET
:
5262 charset_type
= Qw32_charset_arabic
;
5265 charset_type
= Qw32_charset_greek
;
5267 case HEBREW_CHARSET
:
5268 charset_type
= Qw32_charset_hebrew
;
5270 case VIETNAMESE_CHARSET
:
5271 charset_type
= Qw32_charset_vietnamese
;
5274 charset_type
= Qw32_charset_thai
;
5277 charset_type
= Qw32_charset_mac
;
5280 charset_type
= Qw32_charset_johab
;
5284 #ifdef UNICODE_CHARSET
5285 case UNICODE_CHARSET
:
5286 charset_type
= Qw32_charset_unicode
;
5290 /* Encode numerical value of unknown charset. */
5291 sprintf (buf
, "*-#%u", fncharset
);
5292 return Fcons (build_string (buf
), Qnil
);
5297 /* Look through w32-charset-info-alist for the character set.
5298 Only return fully specified charsets for codepages which are
5301 Format of each entry in Vw32_charset_info_alist is
5302 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5304 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
5306 Lisp_Object x_charset
;
5307 Lisp_Object w32_charset
;
5308 Lisp_Object codepage
;
5310 Lisp_Object this_entry
= XCAR (rest
);
5312 /* Skip invalid entries in alist. */
5313 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
5314 || !CONSP (XCDR (this_entry
))
5315 || !SYMBOLP (XCAR (XCDR (this_entry
))))
5318 x_charset
= XCAR (this_entry
);
5319 w32_charset
= XCAR (XCDR (this_entry
));
5320 codepage
= XCDR (XCDR (this_entry
));
5322 if (!strchr (SDATA (x_charset
), '-'))
5325 /* Look for Same charset and a valid codepage (or non-int
5326 which means ignore). */
5327 if (EQ (w32_charset
, charset_type
)
5328 && (!INTEGERP (codepage
) || XINT (codepage
) == CP_DEFAULT
5329 || IsValidCodePage (XINT (codepage
))))
5331 retval
= Fcons (x_charset
, retval
);
5335 /* If no match, encode the numeric value. */
5338 sprintf (buf
, "*-#%u", fncharset
);
5339 return Fcons (build_string (buf
), Qnil
);
5346 /* Get the Windows codepage corresponding to the specified font. The
5347 charset info in the font name is used to look up
5348 w32-charset-to-codepage-alist. */
5350 w32_codepage_for_font (char *fontname
)
5352 Lisp_Object codepage
, entry
;
5353 char *charset_str
, *charset
, *end
;
5355 /* Extract charset part of font string. */
5356 charset
= xlfd_charset_of_font (fontname
);
5361 charset_str
= (char *) alloca (strlen (charset
) + 1);
5362 strcpy (charset_str
, charset
);
5365 /* Remove leading "*-". */
5366 if (strncmp ("*-", charset_str
, 2) == 0)
5367 charset
= charset_str
+ 2;
5370 charset
= charset_str
;
5372 /* Stop match at wildcard (including preceding '-'). */
5373 if (end
= strchr (charset
, '*'))
5375 if (end
> charset
&& *(end
-1) == '-')
5380 if (!strcmp (charset
, "iso10646"))
5383 if (NILP (Vw32_charset_info_alist
))
5386 entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
5390 codepage
= Fcdr (Fcdr (entry
));
5392 if (NILP (codepage
))
5394 else if (XFASTINT (codepage
) == XFASTINT (Qt
))
5396 else if (INTEGERP (codepage
))
5397 return XINT (codepage
);
5404 w32_to_x_font (lplogfont
, lpxstr
, len
, specific_charset
)
5405 LOGFONT
* lplogfont
;
5408 char * specific_charset
;
5412 char height_pixels
[8];
5414 char width_pixels
[8];
5415 char *fontname_dash
;
5416 int display_resy
= (int) one_w32_display_info
.resy
;
5417 int display_resx
= (int) one_w32_display_info
.resx
;
5418 struct coding_system coding
;
5420 if (!lpxstr
) abort ();
5425 if (lplogfont
->lfOutPrecision
== OUT_STRING_PRECIS
)
5426 fonttype
= "raster";
5427 else if (lplogfont
->lfOutPrecision
== OUT_STROKE_PRECIS
)
5428 fonttype
= "outline";
5430 fonttype
= "unknown";
5432 setup_coding_system (Fcheck_coding_system (Vlocale_coding_system
),
5434 coding
.src_multibyte
= 0;
5435 coding
.dst_multibyte
= 1;
5436 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
5437 /* We explicitely disable composition handling because selection
5438 data should not contain any composition sequence. */
5439 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
5441 coding
.dst_bytes
= LF_FACESIZE
* 2;
5442 coding
.destination
= (unsigned char *) xmalloc (coding
.dst_bytes
+ 1);
5443 decode_coding_c_string (&coding
, lplogfont
->lfFaceName
,
5444 strlen(lplogfont
->lfFaceName
), Qnil
);
5445 fontname
= coding
.destination
;
5447 *(fontname
+ coding
.produced
) = '\0';
5449 /* Replace dashes with underscores so the dashes are not
5451 fontname_dash
= fontname
;
5452 while (fontname_dash
= strchr (fontname_dash
, '-'))
5453 *fontname_dash
= '_';
5455 if (lplogfont
->lfHeight
)
5457 sprintf (height_pixels
, "%u", abs (lplogfont
->lfHeight
));
5458 sprintf (height_dpi
, "%u",
5459 abs (lplogfont
->lfHeight
) * 720 / display_resy
);
5463 strcpy (height_pixels
, "*");
5464 strcpy (height_dpi
, "*");
5467 #if 0 /* Never put the width in the xfld. It fails on fonts with
5468 double-width characters. */
5469 if (lplogfont
->lfWidth
)
5470 sprintf (width_pixels
, "%u", lplogfont
->lfWidth
* 10);
5473 strcpy (width_pixels
, "*");
5475 _snprintf (lpxstr
, len
- 1,
5476 "-%s-%s-%s-%c-normal-normal-%s-%s-%d-%d-%c-%s-%s",
5477 fonttype
, /* foundry */
5478 fontname
, /* family */
5479 w32_to_x_weight (lplogfont
->lfWeight
), /* weight */
5480 lplogfont
->lfItalic
?'i':'r', /* slant */
5482 /* add style name */
5483 height_pixels
, /* pixel size */
5484 height_dpi
, /* point size */
5485 display_resx
, /* resx */
5486 display_resy
, /* resy */
5487 ((lplogfont
->lfPitchAndFamily
& 0x3) == VARIABLE_PITCH
)
5488 ? 'p' : 'c', /* spacing */
5489 width_pixels
, /* avg width */
5490 w32_to_x_charset (lplogfont
->lfCharSet
, specific_charset
)
5491 /* charset registry and encoding */
5494 lpxstr
[len
- 1] = 0; /* just to be sure */
5499 x_to_w32_font (lpxstr
, lplogfont
)
5501 LOGFONT
* lplogfont
;
5503 struct coding_system coding
;
5505 if (!lplogfont
) return (FALSE
);
5507 memset (lplogfont
, 0, sizeof (*lplogfont
));
5509 /* Set default value for each field. */
5511 lplogfont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
5512 lplogfont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
5513 lplogfont
->lfQuality
= DEFAULT_QUALITY
;
5515 /* go for maximum quality */
5516 lplogfont
->lfOutPrecision
= OUT_STROKE_PRECIS
;
5517 lplogfont
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
5518 lplogfont
->lfQuality
= PROOF_QUALITY
;
5521 lplogfont
->lfCharSet
= DEFAULT_CHARSET
;
5522 lplogfont
->lfWeight
= FW_DONTCARE
;
5523 lplogfont
->lfPitchAndFamily
= DEFAULT_PITCH
| FF_DONTCARE
;
5528 /* Provide a simple escape mechanism for specifying Windows font names
5529 * directly -- if font spec does not beginning with '-', assume this
5531 * "<font name>[:height in pixels[:width in pixels[:weight]]]"
5537 char name
[50], weight
[20], slant
, pitch
, pixels
[10], height
[10],
5538 width
[10], resy
[10], remainder
[50];
5540 int dpi
= (int) one_w32_display_info
.resy
;
5542 fields
= sscanf (lpxstr
,
5543 "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%49s",
5544 name
, weight
, &slant
, pixels
, height
, resy
, &pitch
, width
, remainder
);
5548 /* In the general case when wildcards cover more than one field,
5549 we don't know which field is which, so don't fill any in.
5550 However, we need to cope with this particular form, which is
5551 generated by font_list_1 (invoked by try_font_list):
5552 "-raster-6x10-*-gb2312*-*"
5553 and make sure to correctly parse the charset field. */
5556 fields
= sscanf (lpxstr
,
5557 "-%*[^-]-%49[^-]-*-%49s",
5560 else if (fields
< 9)
5566 if (fields
> 0 && name
[0] != '*')
5568 Lisp_Object string
= build_string (name
);
5570 (Fcheck_coding_system (Vlocale_coding_system
), &coding
);
5571 coding
.mode
|= (CODING_MODE_SAFE_ENCODING
| CODING_MODE_LAST_BLOCK
);
5572 /* Disable composition/charset annotation. */
5573 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
5574 coding
.dst_bytes
= SCHARS (string
) * 2;
5576 coding
.destination
= (unsigned char *) xmalloc (coding
.dst_bytes
);
5577 encode_coding_object (&coding
, string
, 0, 0,
5578 SCHARS (string
), SBYTES (string
), Qnil
);
5579 if (coding
.produced
>= LF_FACESIZE
)
5580 coding
.produced
= LF_FACESIZE
- 1;
5582 coding
.destination
[coding
.produced
] = '\0';
5584 strcpy (lplogfont
->lfFaceName
, coding
.destination
);
5585 xfree (coding
.destination
);
5589 lplogfont
->lfFaceName
[0] = '\0';
5594 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
5598 lplogfont
->lfItalic
= (fields
> 0 && slant
== 'i');
5602 if (fields
> 0 && pixels
[0] != '*')
5603 lplogfont
->lfHeight
= atoi (pixels
);
5607 if (fields
> 0 && resy
[0] != '*')
5610 if (tem
> 0) dpi
= tem
;
5613 if (fields
> -1 && lplogfont
->lfHeight
== 0 && height
[0] != '*')
5614 lplogfont
->lfHeight
= atoi (height
) * dpi
/ 720;
5619 lplogfont
->lfPitchAndFamily
= VARIABLE_PITCH
| FF_DONTCARE
;
5620 else if (pitch
== 'c')
5621 lplogfont
->lfPitchAndFamily
= FIXED_PITCH
| FF_DONTCARE
;
5626 if (fields
> 0 && width
[0] != '*')
5627 lplogfont
->lfWidth
= atoi (width
) / 10;
5631 /* Strip the trailing '-' if present. (it shouldn't be, as it
5632 fails the test against xlfd-tight-regexp in fontset.el). */
5634 int len
= strlen (remainder
);
5635 if (len
> 0 && remainder
[len
-1] == '-')
5636 remainder
[len
-1] = 0;
5638 encoding
= remainder
;
5640 if (strncmp (encoding
, "*-", 2) == 0)
5643 lplogfont
->lfCharSet
= x_to_w32_charset (encoding
);
5648 char name
[100], height
[10], width
[10], weight
[20];
5650 fields
= sscanf (lpxstr
,
5651 "%99[^:]:%9[^:]:%9[^:]:%19s",
5652 name
, height
, width
, weight
);
5654 if (fields
== EOF
) return (FALSE
);
5658 strncpy (lplogfont
->lfFaceName
,name
, LF_FACESIZE
);
5659 lplogfont
->lfFaceName
[LF_FACESIZE
-1] = 0;
5663 lplogfont
->lfFaceName
[0] = 0;
5669 lplogfont
->lfHeight
= atoi (height
);
5674 lplogfont
->lfWidth
= atoi (width
);
5678 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
5681 /* This makes TrueType fonts work better. */
5682 lplogfont
->lfHeight
= - abs (lplogfont
->lfHeight
);
5687 /* Strip the pixel height and point height from the given xlfd, and
5688 return the pixel height. If no pixel height is specified, calculate
5689 one from the point height, or if that isn't defined either, return
5690 0 (which usually signifies a scalable font).
5693 xlfd_strip_height (char *fontname
)
5695 int pixel_height
, field_number
;
5696 char *read_from
, *write_to
;
5700 pixel_height
= field_number
= 0;
5703 /* Look for height fields. */
5704 for (read_from
= fontname
; *read_from
; read_from
++)
5706 if (*read_from
== '-')
5709 if (field_number
== 7) /* Pixel height. */
5712 write_to
= read_from
;
5714 /* Find end of field. */
5715 for (;*read_from
&& *read_from
!= '-'; read_from
++)
5718 /* Split the fontname at end of field. */
5724 pixel_height
= atoi (write_to
);
5725 /* Blank out field. */
5726 if (read_from
> write_to
)
5731 /* If the pixel height field is at the end (partial xlfd),
5734 return pixel_height
;
5736 /* If we got a pixel height, the point height can be
5737 ignored. Just blank it out and break now. */
5740 /* Find end of point size field. */
5741 for (; *read_from
&& *read_from
!= '-'; read_from
++)
5747 /* Blank out the point size field. */
5748 if (read_from
> write_to
)
5754 return pixel_height
;
5758 /* If the point height is already blank, break now. */
5759 if (*read_from
== '-')
5765 else if (field_number
== 8)
5767 /* If we didn't get a pixel height, try to get the point
5768 height and convert that. */
5770 char *point_size_start
= read_from
++;
5772 /* Find end of field. */
5773 for (; *read_from
&& *read_from
!= '-'; read_from
++)
5782 point_size
= atoi (point_size_start
);
5784 /* Convert to pixel height. */
5785 pixel_height
= point_size
5786 * one_w32_display_info
.height_in
/ 720;
5788 /* Blank out this field and break. */
5796 /* Shift the rest of the font spec into place. */
5797 if (write_to
&& read_from
> write_to
)
5799 for (; *read_from
; read_from
++, write_to
++)
5800 *write_to
= *read_from
;
5804 return pixel_height
;
5807 /* Assume parameter 1 is fully qualified, no wildcards. */
5809 w32_font_match (fontname
, pattern
)
5814 char *font_name_copy
;
5815 char *regex
= alloca (strlen (pattern
) * 2 + 3);
5817 font_name_copy
= alloca (strlen (fontname
) + 1);
5818 strcpy (font_name_copy
, fontname
);
5823 /* Turn pattern into a regexp and do a regexp match. */
5824 for (; *pattern
; pattern
++)
5826 if (*pattern
== '?')
5828 else if (*pattern
== '*')
5839 /* Strip out font heights and compare them seperately, since
5840 rounding error can cause mismatches. This also allows a
5841 comparison between a font that declares only a pixel height and a
5842 pattern that declares the point height.
5845 int font_height
, pattern_height
;
5847 font_height
= xlfd_strip_height (font_name_copy
);
5848 pattern_height
= xlfd_strip_height (regex
);
5850 /* Compare now, and don't bother doing expensive regexp matching
5851 if the heights differ. */
5852 if (font_height
&& pattern_height
&& (font_height
!= pattern_height
))
5856 return (fast_string_match_ignore_case (build_string (regex
),
5857 build_string(font_name_copy
)) >= 0);
5860 /* Callback functions, and a structure holding info they need, for
5861 listing system fonts on W32. We need one set of functions to do the
5862 job properly, but these don't work on NT 3.51 and earlier, so we
5863 have a second set which don't handle character sets properly to
5866 In both cases, there are two passes made. The first pass gets one
5867 font from each family, the second pass lists all the fonts from
5870 typedef struct enumfont_t
5875 XFontStruct
*size_ref
;
5876 Lisp_Object pattern
;
5882 enum_font_maybe_add_to_list (enumfont_t
*, LOGFONT
*, char *, Lisp_Object
);
5886 enum_font_cb2 (lplf
, lptm
, FontType
, lpef
)
5888 NEWTEXTMETRIC
* lptm
;
5892 /* Ignore struck out and underlined versions of fonts. */
5893 if (lplf
->elfLogFont
.lfStrikeOut
|| lplf
->elfLogFont
.lfUnderline
)
5896 /* Only return fonts with names starting with @ if they were
5897 explicitly specified, since Microsoft uses an initial @ to
5898 denote fonts for vertical writing, without providing a more
5899 convenient way of identifying them. */
5900 if (lplf
->elfLogFont
.lfFaceName
[0] == '@'
5901 && lpef
->logfont
.lfFaceName
[0] != '@')
5904 /* Check that the character set matches if it was specified */
5905 if (lpef
->logfont
.lfCharSet
!= DEFAULT_CHARSET
&&
5906 lplf
->elfLogFont
.lfCharSet
!= lpef
->logfont
.lfCharSet
)
5909 if (FontType
== RASTER_FONTTYPE
)
5911 /* DBCS raster fonts have problems displaying, so skip them. */
5912 int charset
= lplf
->elfLogFont
.lfCharSet
;
5913 if (charset
== SHIFTJIS_CHARSET
5914 || charset
== HANGEUL_CHARSET
5915 || charset
== CHINESEBIG5_CHARSET
5916 || charset
== GB2312_CHARSET
5917 #ifdef JOHAB_CHARSET
5918 || charset
== JOHAB_CHARSET
5926 Lisp_Object width
= Qnil
;
5927 Lisp_Object charset_list
= Qnil
;
5928 char *charset
= NULL
;
5930 /* Truetype fonts do not report their true metrics until loaded */
5931 if (FontType
!= RASTER_FONTTYPE
)
5933 if (!NILP (lpef
->pattern
))
5935 /* Scalable fonts are as big as you want them to be. */
5936 lplf
->elfLogFont
.lfHeight
= lpef
->logfont
.lfHeight
;
5937 lplf
->elfLogFont
.lfWidth
= lpef
->logfont
.lfWidth
;
5938 width
= make_number (lpef
->logfont
.lfWidth
);
5942 lplf
->elfLogFont
.lfHeight
= 0;
5943 lplf
->elfLogFont
.lfWidth
= 0;
5947 /* Make sure the height used here is the same as everywhere
5948 else (ie character height, not cell height). */
5949 if (lplf
->elfLogFont
.lfHeight
> 0)
5951 /* lptm can be trusted for RASTER fonts, but not scalable ones. */
5952 if (FontType
== RASTER_FONTTYPE
)
5953 lplf
->elfLogFont
.lfHeight
= lptm
->tmInternalLeading
- lptm
->tmHeight
;
5955 lplf
->elfLogFont
.lfHeight
= -lplf
->elfLogFont
.lfHeight
;
5958 if (!NILP (lpef
->pattern
))
5960 charset
= xlfd_charset_of_font (SDATA (lpef
->pattern
));
5962 /* We already checked charsets above, but DEFAULT_CHARSET
5963 slipped through. So only allow exact matches for DEFAULT_CHARSET. */
5965 && strncmp (charset
, "*-*", 3) != 0
5966 && lpef
->logfont
.lfCharSet
== DEFAULT_CHARSET
5967 && strcmp (charset
, w32_to_x_charset (DEFAULT_CHARSET
, NULL
)) != 0)
5972 charset_list
= Fcons (build_string (charset
), Qnil
);
5974 /* Always prefer unicode. */
5976 = Fcons (build_string ("iso10646-1"),
5977 w32_to_all_x_charsets (lplf
->elfLogFont
.lfCharSet
));
5979 /* Loop through the charsets. */
5980 for ( ; CONSP (charset_list
); charset_list
= Fcdr (charset_list
))
5982 Lisp_Object this_charset
= Fcar (charset_list
);
5983 charset
= SDATA (this_charset
);
5985 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5988 /* List bold and italic variations if w32-enable-synthesized-fonts
5989 is non-nil and this is a plain font. */
5990 if (w32_enable_synthesized_fonts
5991 && lplf
->elfLogFont
.lfWeight
== FW_NORMAL
5992 && lplf
->elfLogFont
.lfItalic
== FALSE
)
5995 lplf
->elfLogFont
.lfWeight
= FW_BOLD
;
5996 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5999 lplf
->elfLogFont
.lfItalic
= TRUE
;
6000 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
6003 lplf
->elfLogFont
.lfWeight
= FW_NORMAL
;
6004 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
6014 enum_font_maybe_add_to_list (lpef
, logfont
, match_charset
, width
)
6017 char * match_charset
;
6022 if (!w32_to_x_font (logfont
, buf
, 100, match_charset
))
6025 if (NILP (lpef
->pattern
)
6026 || w32_font_match (buf
, SDATA (lpef
->pattern
)))
6028 /* Check if we already listed this font. This may happen if
6029 w32_enable_synthesized_fonts is non-nil, and there are real
6030 bold and italic versions of the font. */
6031 Lisp_Object font_name
= build_string (buf
);
6032 if (NILP (Fmember (font_name
, lpef
->list
)))
6034 Lisp_Object entry
= Fcons (font_name
, width
);
6035 lpef
->list
= Fcons (entry
, lpef
->list
);
6043 enum_font_cb1 (lplf
, lptm
, FontType
, lpef
)
6045 NEWTEXTMETRIC
* lptm
;
6049 return EnumFontFamilies (lpef
->hdc
,
6050 lplf
->elfLogFont
.lfFaceName
,
6051 (FONTENUMPROC
) enum_font_cb2
,
6057 enum_fontex_cb2 (lplf
, lptm
, font_type
, lpef
)
6058 ENUMLOGFONTEX
* lplf
;
6059 NEWTEXTMETRICEX
* lptm
;
6063 /* We are not interested in the extra info we get back from the 'Ex
6064 version - only the fact that we get character set variations
6065 enumerated seperately. */
6066 return enum_font_cb2 ((ENUMLOGFONT
*) lplf
, (NEWTEXTMETRIC
*) lptm
,
6071 enum_fontex_cb1 (lplf
, lptm
, font_type
, lpef
)
6072 ENUMLOGFONTEX
* lplf
;
6073 NEWTEXTMETRICEX
* lptm
;
6077 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6078 FARPROC enum_font_families_ex
6079 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6080 /* We don't really expect EnumFontFamiliesEx to disappear once we
6081 get here, so don't bother handling it gracefully. */
6082 if (enum_font_families_ex
== NULL
)
6083 error ("gdi32.dll has disappeared!");
6084 return enum_font_families_ex (lpef
->hdc
,
6086 (FONTENUMPROC
) enum_fontex_cb2
,
6090 /* Interface to fontset handler. (adapted from mw32font.c in Meadow
6091 and xterm.c in Emacs 20.3) */
6093 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
)
6095 char *fontname
, *ptnstr
;
6096 Lisp_Object list
, tem
, newlist
= Qnil
;
6099 list
= Vw32_bdf_filename_alist
;
6100 ptnstr
= SDATA (pattern
);
6102 for ( ; CONSP (list
); list
= XCDR (list
))
6106 fontname
= SDATA (XCAR (tem
));
6107 else if (STRINGP (tem
))
6108 fontname
= SDATA (tem
);
6112 if (w32_font_match (fontname
, ptnstr
))
6114 newlist
= Fcons (XCAR (tem
), newlist
);
6116 if (max_names
>= 0 && n_fonts
>= max_names
)
6125 /* Return a list of names of available fonts matching PATTERN on frame
6126 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
6127 to be listed. Frame F NULL means we have not yet created any
6128 frame, which means we can't get proper size info, as we don't have
6129 a device context to use for GetTextMetrics.
6130 MAXNAMES sets a limit on how many fonts to match. If MAXNAMES is
6131 negative, then all matching fonts are returned. */
6134 w32_list_fonts (f
, pattern
, size
, maxnames
)
6136 Lisp_Object pattern
;
6140 Lisp_Object patterns
, key
= Qnil
, tem
, tpat
;
6141 Lisp_Object list
= Qnil
, newlist
= Qnil
, second_best
= Qnil
;
6142 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
6145 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
6146 if (NILP (patterns
))
6147 patterns
= Fcons (pattern
, Qnil
);
6149 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
6154 tpat
= XCAR (patterns
);
6156 if (!STRINGP (tpat
))
6159 /* Avoid expensive EnumFontFamilies functions if we are not
6160 going to be able to output one of these anyway. */
6161 codepage
= w32_codepage_for_font (SDATA (tpat
));
6162 if (codepage
!= CP_8BIT
&& codepage
!= CP_UNICODE
6163 && codepage
!= CP_DEFAULT
&& codepage
!= CP_UNKNOWN
6164 && !IsValidCodePage(codepage
))
6167 /* See if we cached the result for this particular query.
6168 The cache is an alist of the form:
6169 ((PATTERN (FONTNAME . WIDTH) ...) ...)
6171 if (tem
= XCDR (dpyinfo
->name_list_element
),
6172 !NILP (list
= Fassoc (tpat
, tem
)))
6174 list
= Fcdr_safe (list
);
6175 /* We have a cached list. Don't have to get the list again. */
6180 /* At first, put PATTERN in the cache. */
6185 /* Use EnumFontFamiliesEx where it is available, as it knows
6186 about character sets. Fall back to EnumFontFamilies for
6187 older versions of NT that don't support the 'Ex function. */
6188 x_to_w32_font (SDATA (tpat
), &ef
.logfont
);
6190 LOGFONT font_match_pattern
;
6191 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6192 FARPROC enum_font_families_ex
6193 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6195 /* We do our own pattern matching so we can handle wildcards. */
6196 font_match_pattern
.lfFaceName
[0] = 0;
6197 font_match_pattern
.lfPitchAndFamily
= 0;
6198 /* We can use the charset, because if it is a wildcard it will
6199 be DEFAULT_CHARSET anyway. */
6200 font_match_pattern
.lfCharSet
= ef
.logfont
.lfCharSet
;
6202 ef
.hdc
= GetDC (dpyinfo
->root_window
);
6204 if (enum_font_families_ex
)
6205 enum_font_families_ex (ef
.hdc
,
6206 &font_match_pattern
,
6207 (FONTENUMPROC
) enum_fontex_cb1
,
6210 EnumFontFamilies (ef
.hdc
, NULL
, (FONTENUMPROC
) enum_font_cb1
,
6213 ReleaseDC (dpyinfo
->root_window
, ef
.hdc
);
6219 /* Make a list of the fonts we got back.
6220 Store that in the font cache for the display. */
6221 XSETCDR (dpyinfo
->name_list_element
,
6222 Fcons (Fcons (tpat
, list
),
6223 XCDR (dpyinfo
->name_list_element
)));
6226 if (NILP (list
)) continue; /* Try the remaining alternatives. */
6228 newlist
= second_best
= Qnil
;
6230 /* Make a list of the fonts that have the right width. */
6231 for (; CONSP (list
); list
= XCDR (list
))
6238 if (NILP (XCAR (tem
)))
6242 newlist
= Fcons (XCAR (tem
), newlist
);
6244 if (maxnames
>= 0 && n_fonts
>= maxnames
)
6249 if (!INTEGERP (XCDR (tem
)))
6251 /* Since we don't yet know the size of the font, we must
6252 load it and try GetTextMetrics. */
6253 W32FontStruct thisinfo
;
6258 if (!x_to_w32_font (SDATA (XCAR (tem
)), &lf
))
6262 thisinfo
.bdf
= NULL
;
6263 thisinfo
.hfont
= CreateFontIndirect (&lf
);
6264 if (thisinfo
.hfont
== NULL
)
6267 hdc
= GetDC (dpyinfo
->root_window
);
6268 oldobj
= SelectObject (hdc
, thisinfo
.hfont
);
6269 if (GetTextMetrics (hdc
, &thisinfo
.tm
))
6270 XSETCDR (tem
, make_number (FONT_WIDTH (&thisinfo
)));
6272 XSETCDR (tem
, make_number (0));
6273 SelectObject (hdc
, oldobj
);
6274 ReleaseDC (dpyinfo
->root_window
, hdc
);
6275 DeleteObject(thisinfo
.hfont
);
6278 found_size
= XINT (XCDR (tem
));
6279 if (found_size
== size
)
6281 newlist
= Fcons (XCAR (tem
), newlist
);
6283 if (maxnames
>= 0 && n_fonts
>= maxnames
)
6286 /* keep track of the closest matching size in case
6287 no exact match is found. */
6288 else if (found_size
> 0)
6290 if (NILP (second_best
))
6293 else if (found_size
< size
)
6295 if (XINT (XCDR (second_best
)) > size
6296 || XINT (XCDR (second_best
)) < found_size
)
6301 if (XINT (XCDR (second_best
)) > size
6302 && XINT (XCDR (second_best
)) >
6309 if (!NILP (newlist
))
6311 else if (!NILP (second_best
))
6313 newlist
= Fcons (XCAR (second_best
), Qnil
);
6318 /* Include any bdf fonts. */
6319 if (n_fonts
< maxnames
|| maxnames
< 0)
6321 Lisp_Object combined
[2];
6322 combined
[0] = w32_list_bdf_fonts (pattern
, maxnames
- n_fonts
);
6323 combined
[1] = newlist
;
6324 newlist
= Fnconc(2, combined
);
6331 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
6333 w32_get_font_info (f
, font_idx
)
6337 return (FRAME_W32_FONT_TABLE (f
) + font_idx
);
6342 w32_query_font (struct frame
*f
, char *fontname
)
6345 struct font_info
*pfi
;
6347 pfi
= FRAME_W32_FONT_TABLE (f
);
6349 for (i
= 0; i
< one_w32_display_info
.n_fonts
;i
++, pfi
++)
6351 if (stricmp(pfi
->name
, fontname
) == 0) return pfi
;
6357 /* Find a CCL program for a font specified by FONTP, and set the member
6358 `encoder' of the structure. */
6361 w32_find_ccl_program (fontp
)
6362 struct font_info
*fontp
;
6364 Lisp_Object list
, elt
;
6366 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
6370 && STRINGP (XCAR (elt
))
6371 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
6377 struct ccl_program
*ccl
6378 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
6380 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
6383 fontp
->font_encoder
= ccl
;
6387 /* directory-files from dired.c. */
6388 Lisp_Object Fdirectory_files
P_((Lisp_Object
, Lisp_Object
, Lisp_Object
, Lisp_Object
));
6391 /* Find BDF files in a specified directory. (use GCPRO when calling,
6392 as this calls lisp to get a directory listing). */
6394 w32_find_bdf_fonts_in_dir (Lisp_Object directory
)
6396 Lisp_Object filelist
, list
= Qnil
;
6399 if (!STRINGP(directory
))
6402 filelist
= Fdirectory_files (directory
, Qt
,
6403 build_string (".*\\.[bB][dD][fF]"), Qt
);
6405 for ( ; CONSP(filelist
); filelist
= XCDR (filelist
))
6407 Lisp_Object filename
= XCAR (filelist
);
6408 if (w32_BDF_to_x_font (SDATA (filename
), fontname
, 100))
6409 store_in_alist (&list
, build_string (fontname
), filename
);
6414 DEFUN ("w32-find-bdf-fonts", Fw32_find_bdf_fonts
, Sw32_find_bdf_fonts
,
6416 doc
: /* Return a list of BDF fonts in DIRECTORY.
6417 The list is suitable for appending to `w32-bdf-filename-alist'.
6418 Fonts which do not contain an xlfd description will not be included
6419 in the list. DIRECTORY may be a list of directories. */)
6421 Lisp_Object directory
;
6423 Lisp_Object list
= Qnil
;
6424 struct gcpro gcpro1
, gcpro2
;
6426 if (!CONSP (directory
))
6427 return w32_find_bdf_fonts_in_dir (directory
);
6429 for ( ; CONSP (directory
); directory
= XCDR (directory
))
6431 Lisp_Object pair
[2];
6434 GCPRO2 (directory
, list
);
6435 pair
[1] = w32_find_bdf_fonts_in_dir( XCAR (directory
) );
6436 list
= Fnconc( 2, pair
);
6443 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
6444 doc
: /* Internal function called by `color-defined-p', which see. */)
6446 Lisp_Object color
, frame
;
6449 FRAME_PTR f
= check_x_frame (frame
);
6451 CHECK_STRING (color
);
6453 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
6459 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
6460 doc
: /* Internal function called by `color-values', which see. */)
6462 Lisp_Object color
, frame
;
6465 FRAME_PTR f
= check_x_frame (frame
);
6467 CHECK_STRING (color
);
6469 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
6470 return list3 (make_number ((GetRValue (foo
.pixel
) << 8)
6471 | GetRValue (foo
.pixel
)),
6472 make_number ((GetGValue (foo
.pixel
) << 8)
6473 | GetGValue (foo
.pixel
)),
6474 make_number ((GetBValue (foo
.pixel
) << 8)
6475 | GetBValue (foo
.pixel
)));
6480 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
6481 doc
: /* Internal function called by `display-color-p', which see. */)
6483 Lisp_Object display
;
6485 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6487 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
6493 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
,
6494 Sx_display_grayscale_p
, 0, 1, 0,
6495 doc
: /* Return t if DISPLAY supports shades of gray.
6496 Note that color displays do support shades of gray.
6497 The optional argument DISPLAY specifies which display to ask about.
6498 DISPLAY should be either a frame or a display name (a string).
6499 If omitted or nil, that stands for the selected frame's display. */)
6501 Lisp_Object display
;
6503 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6505 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
6511 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
,
6512 Sx_display_pixel_width
, 0, 1, 0,
6513 doc
: /* Returns the width in pixels of DISPLAY.
6514 The optional argument DISPLAY specifies which display to ask about.
6515 DISPLAY should be either a frame or a display name (a string).
6516 If omitted or nil, that stands for the selected frame's display. */)
6518 Lisp_Object display
;
6520 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6522 return make_number (dpyinfo
->width
);
6525 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
6526 Sx_display_pixel_height
, 0, 1, 0,
6527 doc
: /* Returns the height in pixels of DISPLAY.
6528 The optional argument DISPLAY specifies which display to ask about.
6529 DISPLAY should be either a frame or a display name (a string).
6530 If omitted or nil, that stands for the selected frame's display. */)
6532 Lisp_Object display
;
6534 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6536 return make_number (dpyinfo
->height
);
6539 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
6541 doc
: /* Returns the number of bitplanes of DISPLAY.
6542 The optional argument DISPLAY specifies which display to ask about.
6543 DISPLAY should be either a frame or a display name (a string).
6544 If omitted or nil, that stands for the selected frame's display. */)
6546 Lisp_Object display
;
6548 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6550 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
6553 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
6555 doc
: /* Returns the number of color cells of DISPLAY.
6556 The optional argument DISPLAY specifies which display to ask about.
6557 DISPLAY should be either a frame or a display name (a string).
6558 If omitted or nil, that stands for the selected frame's display. */)
6560 Lisp_Object display
;
6562 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6566 hdc
= GetDC (dpyinfo
->root_window
);
6567 if (dpyinfo
->has_palette
)
6568 cap
= GetDeviceCaps (hdc
, SIZEPALETTE
);
6570 cap
= GetDeviceCaps (hdc
, NUMCOLORS
);
6572 /* We force 24+ bit depths to 24-bit, both to prevent an overflow
6573 and because probably is more meaningful on Windows anyway */
6575 cap
= 1 << min(dpyinfo
->n_planes
* dpyinfo
->n_cbits
, 24);
6577 ReleaseDC (dpyinfo
->root_window
, hdc
);
6579 return make_number (cap
);
6582 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
6583 Sx_server_max_request_size
,
6585 doc
: /* Returns the maximum request size of the server of DISPLAY.
6586 The optional argument DISPLAY specifies which display to ask about.
6587 DISPLAY should be either a frame or a display name (a string).
6588 If omitted or nil, that stands for the selected frame's display. */)
6590 Lisp_Object display
;
6592 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6594 return make_number (1);
6597 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
6598 doc
: /* Returns the "vendor ID" string of the W32 system (Microsoft).
6599 The optional argument DISPLAY specifies which display to ask about.
6600 DISPLAY should be either a frame or a display name (a string).
6601 If omitted or nil, that stands for the selected frame's display. */)
6603 Lisp_Object display
;
6605 return build_string ("Microsoft Corp.");
6608 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
6609 doc
: /* Returns the version numbers of the server of DISPLAY.
6610 The value is a list of three integers: the major and minor
6611 version numbers of the X Protocol in use, and the distributor-specific release
6612 number. See also the function `x-server-vendor'.
6614 The optional argument DISPLAY specifies which display to ask about.
6615 DISPLAY should be either a frame or a display name (a string).
6616 If omitted or nil, that stands for the selected frame's display. */)
6618 Lisp_Object display
;
6620 return Fcons (make_number (w32_major_version
),
6621 Fcons (make_number (w32_minor_version
),
6622 Fcons (make_number (w32_build_number
), Qnil
)));
6625 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
6626 doc
: /* Returns the number of screens on the server of DISPLAY.
6627 The optional argument DISPLAY specifies which display to ask about.
6628 DISPLAY should be either a frame or a display name (a string).
6629 If omitted or nil, that stands for the selected frame's display. */)
6631 Lisp_Object display
;
6633 return make_number (1);
6636 DEFUN ("x-display-mm-height", Fx_display_mm_height
,
6637 Sx_display_mm_height
, 0, 1, 0,
6638 doc
: /* Returns the height in millimeters of DISPLAY.
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
);
6649 hdc
= GetDC (dpyinfo
->root_window
);
6651 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
6653 ReleaseDC (dpyinfo
->root_window
, hdc
);
6655 return make_number (cap
);
6658 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
6659 doc
: /* Returns the width in millimeters of DISPLAY.
6660 The optional argument DISPLAY specifies which display to ask about.
6661 DISPLAY should be either a frame or a display name (a string).
6662 If omitted or nil, that stands for the selected frame's display. */)
6664 Lisp_Object display
;
6666 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6671 hdc
= GetDC (dpyinfo
->root_window
);
6673 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
6675 ReleaseDC (dpyinfo
->root_window
, hdc
);
6677 return make_number (cap
);
6680 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
6681 Sx_display_backing_store
, 0, 1, 0,
6682 doc
: /* Returns an indication of whether DISPLAY does backing store.
6683 The value may be `always', `when-mapped', or `not-useful'.
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 return intern ("not-useful");
6693 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
6694 Sx_display_visual_class
, 0, 1, 0,
6695 doc
: /* Returns the visual class of DISPLAY.
6696 The value is one of the symbols `static-gray', `gray-scale',
6697 `static-color', `pseudo-color', `true-color', or `direct-color'.
6699 The optional argument DISPLAY specifies which display to ask about.
6700 DISPLAY should be either a frame or a display name (a string).
6701 If omitted or nil, that stands for the selected frame's display. */)
6703 Lisp_Object display
;
6705 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6706 Lisp_Object result
= Qnil
;
6708 if (dpyinfo
->has_palette
)
6709 result
= intern ("pseudo-color");
6710 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
6711 result
= intern ("static-grey");
6712 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
6713 result
= intern ("static-color");
6714 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
6715 result
= intern ("true-color");
6720 DEFUN ("x-display-save-under", Fx_display_save_under
,
6721 Sx_display_save_under
, 0, 1, 0,
6722 doc
: /* Returns t if DISPLAY supports the save-under feature.
6723 The optional argument DISPLAY specifies which display to ask about.
6724 DISPLAY should be either a frame or a display name (a string).
6725 If omitted or nil, that stands for the selected frame's display. */)
6727 Lisp_Object display
;
6734 register struct frame
*f
;
6736 return FRAME_PIXEL_WIDTH (f
);
6741 register struct frame
*f
;
6743 return FRAME_PIXEL_HEIGHT (f
);
6748 register struct frame
*f
;
6750 return FRAME_COLUMN_WIDTH (f
);
6755 register struct frame
*f
;
6757 return FRAME_LINE_HEIGHT (f
);
6762 register struct frame
*f
;
6764 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
6767 /* Return the display structure for the display named NAME.
6768 Open a new connection if necessary. */
6770 struct w32_display_info
*
6771 x_display_info_for_name (name
)
6775 struct w32_display_info
*dpyinfo
;
6777 CHECK_STRING (name
);
6779 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
6781 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
6784 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
6789 /* Use this general default value to start with. */
6790 Vx_resource_name
= Vinvocation_name
;
6792 validate_x_resource_name ();
6794 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
6795 (char *) SDATA (Vx_resource_name
));
6798 error ("Cannot connect to server %s", SDATA (name
));
6801 XSETFASTINT (Vwindow_system_version
, 3);
6806 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
6807 1, 3, 0, doc
: /* Open a connection to a server.
6808 DISPLAY is the name of the display to connect to.
6809 Optional second arg XRM-STRING is a string of resources in xrdb format.
6810 If the optional third arg MUST-SUCCEED is non-nil,
6811 terminate Emacs if we can't open the connection. */)
6812 (display
, xrm_string
, must_succeed
)
6813 Lisp_Object display
, xrm_string
, must_succeed
;
6815 unsigned char *xrm_option
;
6816 struct w32_display_info
*dpyinfo
;
6818 /* If initialization has already been done, return now to avoid
6819 overwriting critical parts of one_w32_display_info. */
6823 CHECK_STRING (display
);
6824 if (! NILP (xrm_string
))
6825 CHECK_STRING (xrm_string
);
6827 if (! EQ (Vwindow_system
, intern ("w32")))
6828 error ("Not using Microsoft Windows");
6830 /* Allow color mapping to be defined externally; first look in user's
6831 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
6833 Lisp_Object color_file
;
6834 struct gcpro gcpro1
;
6836 color_file
= build_string("~/rgb.txt");
6838 GCPRO1 (color_file
);
6840 if (NILP (Ffile_readable_p (color_file
)))
6842 Fexpand_file_name (build_string ("rgb.txt"),
6843 Fsymbol_value (intern ("data-directory")));
6845 Vw32_color_map
= Fw32_load_color_file (color_file
);
6849 if (NILP (Vw32_color_map
))
6850 Vw32_color_map
= Fw32_default_color_map ();
6852 /* Merge in system logical colors. */
6853 add_system_logical_colors_to_map (&Vw32_color_map
);
6855 if (! NILP (xrm_string
))
6856 xrm_option
= (unsigned char *) SDATA (xrm_string
);
6858 xrm_option
= (unsigned char *) 0;
6860 /* Use this general default value to start with. */
6861 /* First remove .exe suffix from invocation-name - it looks ugly. */
6863 char basename
[ MAX_PATH
], *str
;
6865 strcpy (basename
, SDATA (Vinvocation_name
));
6866 str
= strrchr (basename
, '.');
6868 Vinvocation_name
= build_string (basename
);
6870 Vx_resource_name
= Vinvocation_name
;
6872 validate_x_resource_name ();
6874 /* This is what opens the connection and sets x_current_display.
6875 This also initializes many symbols, such as those used for input. */
6876 dpyinfo
= w32_term_init (display
, xrm_option
,
6877 (char *) SDATA (Vx_resource_name
));
6881 if (!NILP (must_succeed
))
6882 fatal ("Cannot connect to server %s.\n",
6885 error ("Cannot connect to server %s", SDATA (display
));
6890 XSETFASTINT (Vwindow_system_version
, 3);
6894 DEFUN ("x-close-connection", Fx_close_connection
,
6895 Sx_close_connection
, 1, 1, 0,
6896 doc
: /* Close the connection to DISPLAY's server.
6897 For DISPLAY, specify either a frame or a display name (a string).
6898 If DISPLAY is nil, that stands for the selected frame's display. */)
6900 Lisp_Object display
;
6902 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6905 if (dpyinfo
->reference_count
> 0)
6906 error ("Display still has frames on it");
6909 /* Free the fonts in the font table. */
6910 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
6911 if (dpyinfo
->font_table
[i
].name
)
6913 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
6914 xfree (dpyinfo
->font_table
[i
].full_name
);
6915 xfree (dpyinfo
->font_table
[i
].name
);
6916 w32_unload_font (dpyinfo
, dpyinfo
->font_table
[i
].font
);
6918 x_destroy_all_bitmaps (dpyinfo
);
6920 x_delete_display (dpyinfo
);
6926 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
6927 doc
: /* Return the list of display names that Emacs has connections to. */)
6930 Lisp_Object tail
, result
;
6933 for (tail
= w32_display_name_list
; ! NILP (tail
); tail
= XCDR (tail
))
6934 result
= Fcons (XCAR (XCAR (tail
)), result
);
6939 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
6940 doc
: /* This is a noop on W32 systems. */)
6942 Lisp_Object display
, on
;
6949 /***********************************************************************
6951 ***********************************************************************/
6953 DEFUN ("x-change-window-property", Fx_change_window_property
,
6954 Sx_change_window_property
, 2, 6, 0,
6955 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
6956 VALUE may be a string or a list of conses, numbers and/or strings.
6957 If an element in the list is a string, it is converted to
6958 an Atom and the value of the Atom is used. If an element is a cons,
6959 it is converted to a 32 bit number where the car is the 16 top bits and the
6960 cdr is the lower 16 bits.
6961 FRAME nil or omitted means use the selected frame.
6962 If TYPE is given and non-nil, it is the name of the type of VALUE.
6963 If TYPE is not given or nil, the type is STRING.
6964 FORMAT gives the size in bits of each element if VALUE is a list.
6965 It must be one of 8, 16 or 32.
6966 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
6967 If OUTER_P is non-nil, the property is changed for the outer X window of
6968 FRAME. Default is to change on the edit X window.
6971 (prop
, value
, frame
, type
, format
, outer_p
)
6972 Lisp_Object prop
, value
, frame
, type
, format
, outer_p
;
6974 #if 0 /* TODO : port window properties to W32 */
6975 struct frame
*f
= check_x_frame (frame
);
6978 CHECK_STRING (prop
);
6979 CHECK_STRING (value
);
6982 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
6983 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
6984 prop_atom
, XA_STRING
, 8, PropModeReplace
,
6985 SDATA (value
), SCHARS (value
));
6987 /* Make sure the property is set when we return. */
6988 XFlush (FRAME_W32_DISPLAY (f
));
6997 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
6998 Sx_delete_window_property
, 1, 2, 0,
6999 doc
: /* Remove window property PROP from X window of FRAME.
7000 FRAME nil or omitted means use the selected frame. Value is PROP. */)
7002 Lisp_Object prop
, frame
;
7004 #if 0 /* TODO : port window properties to W32 */
7006 struct frame
*f
= check_x_frame (frame
);
7009 CHECK_STRING (prop
);
7011 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
7012 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
7014 /* Make sure the property is removed when we return. */
7015 XFlush (FRAME_W32_DISPLAY (f
));
7023 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
7025 doc
: /* Value is the value of window property PROP on FRAME.
7026 If FRAME is nil or omitted, use the selected frame. Value is nil
7027 if FRAME hasn't a property with name PROP or if PROP has no string
7030 Lisp_Object prop
, frame
;
7032 #if 0 /* TODO : port window properties to W32 */
7034 struct frame
*f
= check_x_frame (frame
);
7037 Lisp_Object prop_value
= Qnil
;
7038 char *tmp_data
= NULL
;
7041 unsigned long actual_size
, bytes_remaining
;
7043 CHECK_STRING (prop
);
7045 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
7046 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
7047 prop_atom
, 0, 0, False
, XA_STRING
,
7048 &actual_type
, &actual_format
, &actual_size
,
7049 &bytes_remaining
, (unsigned char **) &tmp_data
);
7052 int size
= bytes_remaining
;
7057 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
7058 prop_atom
, 0, bytes_remaining
,
7060 &actual_type
, &actual_format
,
7061 &actual_size
, &bytes_remaining
,
7062 (unsigned char **) &tmp_data
);
7064 prop_value
= make_string (tmp_data
, size
);
7079 /***********************************************************************
7081 ***********************************************************************/
7083 /* If non-null, an asynchronous timer that, when it expires, displays
7084 an hourglass cursor on all frames. */
7086 static struct atimer
*hourglass_atimer
;
7088 /* Non-zero means an hourglass cursor is currently shown. */
7090 static int hourglass_shown_p
;
7092 /* Number of seconds to wait before displaying an hourglass cursor. */
7094 static Lisp_Object Vhourglass_delay
;
7096 /* Default number of seconds to wait before displaying an hourglass
7099 #define DEFAULT_HOURGLASS_DELAY 1
7101 /* Function prototypes. */
7103 static void show_hourglass
P_ ((struct atimer
*));
7104 static void hide_hourglass
P_ ((void));
7107 /* Cancel a currently active hourglass timer, and start a new one. */
7112 #if 0 /* TODO: cursor shape changes. */
7114 int secs
, usecs
= 0;
7116 cancel_hourglass ();
7118 if (INTEGERP (Vhourglass_delay
)
7119 && XINT (Vhourglass_delay
) > 0)
7120 secs
= XFASTINT (Vhourglass_delay
);
7121 else if (FLOATP (Vhourglass_delay
)
7122 && XFLOAT_DATA (Vhourglass_delay
) > 0)
7125 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
7126 secs
= XFASTINT (tem
);
7127 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
7130 secs
= DEFAULT_HOURGLASS_DELAY
;
7132 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
7133 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
7134 show_hourglass
, NULL
);
7139 /* Cancel the hourglass cursor timer if active, hide an hourglass
7145 if (hourglass_atimer
)
7147 cancel_atimer (hourglass_atimer
);
7148 hourglass_atimer
= NULL
;
7151 if (hourglass_shown_p
)
7156 /* Timer function of hourglass_atimer. TIMER is equal to
7159 Display an hourglass cursor on all frames by mapping the frames'
7160 hourglass_window. Set the hourglass_p flag in the frames'
7161 output_data.x structure to indicate that an hourglass cursor is
7162 shown on the frames. */
7165 show_hourglass (timer
)
7166 struct atimer
*timer
;
7168 #if 0 /* TODO: cursor shape changes. */
7169 /* The timer implementation will cancel this timer automatically
7170 after this function has run. Set hourglass_atimer to null
7171 so that we know the timer doesn't have to be canceled. */
7172 hourglass_atimer
= NULL
;
7174 if (!hourglass_shown_p
)
7176 Lisp_Object rest
, frame
;
7180 FOR_EACH_FRAME (rest
, frame
)
7181 if (FRAME_W32_P (XFRAME (frame
)))
7183 struct frame
*f
= XFRAME (frame
);
7185 f
->output_data
.w32
->hourglass_p
= 1;
7187 if (!f
->output_data
.w32
->hourglass_window
)
7189 unsigned long mask
= CWCursor
;
7190 XSetWindowAttributes attrs
;
7192 attrs
.cursor
= f
->output_data
.w32
->hourglass_cursor
;
7194 f
->output_data
.w32
->hourglass_window
7195 = XCreateWindow (FRAME_X_DISPLAY (f
),
7196 FRAME_OUTER_WINDOW (f
),
7197 0, 0, 32000, 32000, 0, 0,
7203 XMapRaised (FRAME_X_DISPLAY (f
),
7204 f
->output_data
.w32
->hourglass_window
);
7205 XFlush (FRAME_X_DISPLAY (f
));
7208 hourglass_shown_p
= 1;
7215 /* Hide the hourglass cursor on all frames, if it is currently shown. */
7220 #if 0 /* TODO: cursor shape changes. */
7221 if (hourglass_shown_p
)
7223 Lisp_Object rest
, frame
;
7226 FOR_EACH_FRAME (rest
, frame
)
7228 struct frame
*f
= XFRAME (frame
);
7231 /* Watch out for newly created frames. */
7232 && f
->output_data
.x
->hourglass_window
)
7234 XUnmapWindow (FRAME_X_DISPLAY (f
),
7235 f
->output_data
.x
->hourglass_window
);
7236 /* Sync here because XTread_socket looks at the
7237 hourglass_p flag that is reset to zero below. */
7238 XSync (FRAME_X_DISPLAY (f
), False
);
7239 f
->output_data
.x
->hourglass_p
= 0;
7243 hourglass_shown_p
= 0;
7251 /***********************************************************************
7253 ***********************************************************************/
7255 static Lisp_Object x_create_tip_frame
P_ ((struct w32_display_info
*,
7256 Lisp_Object
, Lisp_Object
));
7257 static void compute_tip_xy
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
7258 Lisp_Object
, int, int, int *, int *));
7260 /* The frame of a currently visible tooltip. */
7262 Lisp_Object tip_frame
;
7264 /* If non-nil, a timer started that hides the last tooltip when it
7267 Lisp_Object tip_timer
;
7270 /* If non-nil, a vector of 3 elements containing the last args
7271 with which x-show-tip was called. See there. */
7273 Lisp_Object last_show_tip_args
;
7275 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
7277 Lisp_Object Vx_max_tooltip_size
;
7281 unwind_create_tip_frame (frame
)
7284 Lisp_Object deleted
;
7286 deleted
= unwind_create_frame (frame
);
7287 if (EQ (deleted
, Qt
))
7297 /* Create a frame for a tooltip on the display described by DPYINFO.
7298 PARMS is a list of frame parameters. TEXT is the string to
7299 display in the tip frame. Value is the frame.
7301 Note that functions called here, esp. x_default_parameter can
7302 signal errors, for instance when a specified color name is
7303 undefined. We have to make sure that we're in a consistent state
7304 when this happens. */
7307 x_create_tip_frame (dpyinfo
, parms
, text
)
7308 struct w32_display_info
*dpyinfo
;
7309 Lisp_Object parms
, text
;
7312 Lisp_Object frame
, tem
;
7314 long window_prompting
= 0;
7316 int count
= SPECPDL_INDEX ();
7317 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7319 int face_change_count_before
= face_change_count
;
7321 struct buffer
*old_buffer
;
7325 /* Use this general default value to start with until we know if
7326 this frame has a specified name. */
7327 Vx_resource_name
= Vinvocation_name
;
7330 kb
= dpyinfo
->kboard
;
7332 kb
= &the_only_kboard
;
7335 /* Get the name of the frame to use for resource lookup. */
7336 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
7338 && !EQ (name
, Qunbound
)
7340 error ("Invalid frame name--not a string or nil");
7341 Vx_resource_name
= name
;
7344 GCPRO3 (parms
, name
, frame
);
7345 /* Make a frame without minibuffer nor mode-line. */
7347 f
->wants_modeline
= 0;
7348 XSETFRAME (frame
, f
);
7350 buffer
= Fget_buffer_create (build_string (" *tip*"));
7351 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, Qnil
);
7352 old_buffer
= current_buffer
;
7353 set_buffer_internal_1 (XBUFFER (buffer
));
7354 current_buffer
->truncate_lines
= Qnil
;
7355 specbind (Qinhibit_read_only
, Qt
);
7356 specbind (Qinhibit_modification_hooks
, Qt
);
7359 set_buffer_internal_1 (old_buffer
);
7361 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
7362 record_unwind_protect (unwind_create_tip_frame
, frame
);
7364 /* By setting the output method, we're essentially saying that
7365 the frame is live, as per FRAME_LIVE_P. If we get a signal
7366 from this point on, x_destroy_window might screw up reference
7368 f
->output_method
= output_w32
;
7369 f
->output_data
.w32
=
7370 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
7371 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
7373 FRAME_FONTSET (f
) = -1;
7374 f
->icon_name
= Qnil
;
7376 #if 0 /* GLYPH_DEBUG TODO: image support. */
7377 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
7378 dpyinfo_refcount
= dpyinfo
->reference_count
;
7379 #endif /* GLYPH_DEBUG */
7381 FRAME_KBOARD (f
) = kb
;
7383 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
7384 f
->output_data
.w32
->explicit_parent
= 0;
7386 /* Set the name; the functions to which we pass f expect the name to
7388 if (EQ (name
, Qunbound
) || NILP (name
))
7390 f
->name
= build_string (dpyinfo
->w32_id_name
);
7391 f
->explicit_name
= 0;
7396 f
->explicit_name
= 1;
7397 /* use the frame's title when getting resources for this frame. */
7398 specbind (Qx_resource_name
, name
);
7401 f
->resx
= dpyinfo
->resx
;
7402 f
->resy
= dpyinfo
->resy
;
7404 #ifdef USE_FONT_BACKEND
7405 if (enable_font_backend
)
7407 /* Perhaps, we must allow frame parameter, say `font-backend',
7408 to specify which font backends to use. */
7409 register_font_driver (&w32font_driver
, f
);
7411 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
7412 "fontBackend", "FontBackend", RES_TYPE_STRING
);
7414 #endif /* USE_FONT_BACKEND */
7416 /* Extract the window parameters from the supplied values
7417 that are needed to determine window geometry. */
7418 #ifdef USE_FONT_BACKEND
7419 if (enable_font_backend
)
7420 x_default_font_parameter (f
, parms
);
7422 #endif /* USE_FONT_BACKEND */
7426 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
7429 /* First, try whatever font the caller has specified. */
7432 tem
= Fquery_fontset (font
, Qnil
);
7434 font
= x_new_fontset (f
, tem
);
7436 font
= x_new_font (f
, SDATA (font
));
7439 /* Try out a font which we hope has bold and italic variations. */
7440 if (!STRINGP (font
))
7441 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
7442 if (! STRINGP (font
))
7443 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
7444 /* If those didn't work, look for something which will at least work. */
7445 if (! STRINGP (font
))
7446 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
7448 if (! STRINGP (font
))
7449 font
= build_string ("Fixedsys");
7451 x_default_parameter (f
, parms
, Qfont
, font
,
7452 "font", "Font", RES_TYPE_STRING
);
7455 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
7456 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
7457 /* This defaults to 2 in order to match xterm. We recognize either
7458 internalBorderWidth or internalBorder (which is what xterm calls
7460 if (NILP (Fassq (Qinternal_border_width
, parms
)))
7464 value
= w32_get_arg (parms
, Qinternal_border_width
,
7465 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
7466 if (! EQ (value
, Qunbound
))
7467 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
7470 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
7471 "internalBorderWidth", "internalBorderWidth",
7474 /* Also do the stuff which must be set before the window exists. */
7475 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
7476 "foreground", "Foreground", RES_TYPE_STRING
);
7477 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
7478 "background", "Background", RES_TYPE_STRING
);
7479 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
7480 "pointerColor", "Foreground", RES_TYPE_STRING
);
7481 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
7482 "cursorColor", "Foreground", RES_TYPE_STRING
);
7483 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
7484 "borderColor", "BorderColor", RES_TYPE_STRING
);
7486 /* Init faces before x_default_parameter is called for scroll-bar
7487 parameters because that function calls x_set_scroll_bar_width,
7488 which calls change_frame_size, which calls Fset_window_buffer,
7489 which runs hooks, which call Fvertical_motion. At the end, we
7490 end up in init_iterator with a null face cache, which should not
7492 init_frame_faces (f
);
7494 f
->output_data
.w32
->dwStyle
= WS_BORDER
| WS_POPUP
| WS_DISABLED
;
7495 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
7497 window_prompting
= x_figure_window_size (f
, parms
, 0);
7499 /* No fringes on tip frame. */
7501 f
->left_fringe_width
= 0;
7502 f
->right_fringe_width
= 0;
7505 my_create_tip_window (f
);
7510 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
7511 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
7512 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
7513 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
7514 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
7515 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
7517 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
7518 Change will not be effected unless different from the current
7520 width
= FRAME_COLS (f
);
7521 height
= FRAME_LINES (f
);
7522 FRAME_LINES (f
) = 0;
7523 SET_FRAME_COLS (f
, 0);
7524 change_frame_size (f
, height
, width
, 1, 0, 0);
7526 /* Add `tooltip' frame parameter's default value. */
7527 if (NILP (Fframe_parameter (frame
, intern ("tooltip"))))
7528 Fmodify_frame_parameters (frame
, Fcons (Fcons (intern ("tooltip"), Qt
),
7531 /* Set up faces after all frame parameters are known. This call
7532 also merges in face attributes specified for new frames.
7534 Frame parameters may be changed if .Xdefaults contains
7535 specifications for the default font. For example, if there is an
7536 `Emacs.default.attributeBackground: pink', the `background-color'
7537 attribute of the frame get's set, which let's the internal border
7538 of the tooltip frame appear in pink. Prevent this. */
7540 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
7542 /* Set tip_frame here, so that */
7544 call1 (Qface_set_after_frame_default
, frame
);
7546 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
7547 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qbackground_color
, bg
),
7555 /* It is now ok to make the frame official even if we get an error
7556 below. And the frame needs to be on Vframe_list or making it
7557 visible won't work. */
7558 Vframe_list
= Fcons (frame
, Vframe_list
);
7560 /* Now that the frame is official, it counts as a reference to
7562 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
7564 /* Setting attributes of faces of the tooltip frame from resources
7565 and similar will increment face_change_count, which leads to the
7566 clearing of all current matrices. Since this isn't necessary
7567 here, avoid it by resetting face_change_count to the value it
7568 had before we created the tip frame. */
7569 face_change_count
= face_change_count_before
;
7571 /* Discard the unwind_protect. */
7572 return unbind_to (count
, frame
);
7576 /* Compute where to display tip frame F. PARMS is the list of frame
7577 parameters for F. DX and DY are specified offsets from the current
7578 location of the mouse. WIDTH and HEIGHT are the width and height
7579 of the tooltip. Return coordinates relative to the root window of
7580 the display in *ROOT_X, and *ROOT_Y. */
7583 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, root_x
, root_y
)
7585 Lisp_Object parms
, dx
, dy
;
7587 int *root_x
, *root_y
;
7589 Lisp_Object left
, top
;
7591 /* User-specified position? */
7592 left
= Fcdr (Fassq (Qleft
, parms
));
7593 top
= Fcdr (Fassq (Qtop
, parms
));
7595 /* Move the tooltip window where the mouse pointer is. Resize and
7597 if (!INTEGERP (left
) || !INTEGERP (top
))
7609 *root_y
= XINT (top
);
7610 else if (*root_y
+ XINT (dy
) <= 0)
7611 *root_y
= 0; /* Can happen for negative dy */
7612 else if (*root_y
+ XINT (dy
) + height
<= FRAME_W32_DISPLAY_INFO (f
)->height
)
7613 /* It fits below the pointer */
7614 *root_y
+= XINT (dy
);
7615 else if (height
+ XINT (dy
) <= *root_y
)
7616 /* It fits above the pointer. */
7617 *root_y
-= height
+ XINT (dy
);
7619 /* Put it on the top. */
7622 if (INTEGERP (left
))
7623 *root_x
= XINT (left
);
7624 else if (*root_x
+ XINT (dx
) <= 0)
7625 *root_x
= 0; /* Can happen for negative dx */
7626 else if (*root_x
+ XINT (dx
) + width
<= FRAME_W32_DISPLAY_INFO (f
)->width
)
7627 /* It fits to the right of the pointer. */
7628 *root_x
+= XINT (dx
);
7629 else if (width
+ XINT (dx
) <= *root_x
)
7630 /* It fits to the left of the pointer. */
7631 *root_x
-= width
+ XINT (dx
);
7633 /* Put it left justified on the screen -- it ought to fit that way. */
7638 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
7639 doc
: /* Show STRING in a \"tooltip\" window on frame FRAME.
7640 A tooltip window is a small window displaying a string.
7642 This is an internal function; Lisp code should call `tooltip-show'.
7644 FRAME nil or omitted means use the selected frame.
7646 PARMS is an optional list of frame parameters which can be
7647 used to change the tooltip's appearance.
7649 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
7650 means use the default timeout of 5 seconds.
7652 If the list of frame parameters PARMS contains a `left' parameter,
7653 the tooltip is displayed at that x-position. Otherwise it is
7654 displayed at the mouse position, with offset DX added (default is 5 if
7655 DX isn't specified). Likewise for the y-position; if a `top' frame
7656 parameter is specified, it determines the y-position of the tooltip
7657 window, otherwise it is displayed at the mouse position, with offset
7658 DY added (default is -10).
7660 A tooltip's maximum size is specified by `x-max-tooltip-size'.
7661 Text larger than the specified size is clipped. */)
7662 (string
, frame
, parms
, timeout
, dx
, dy
)
7663 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
7668 struct buffer
*old_buffer
;
7669 struct text_pos pos
;
7670 int i
, width
, height
;
7671 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7672 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7673 int count
= SPECPDL_INDEX ();
7675 specbind (Qinhibit_redisplay
, Qt
);
7677 GCPRO4 (string
, parms
, frame
, timeout
);
7679 CHECK_STRING (string
);
7680 f
= check_x_frame (frame
);
7682 timeout
= make_number (5);
7684 CHECK_NATNUM (timeout
);
7687 dx
= make_number (5);
7692 dy
= make_number (-10);
7696 if (NILP (last_show_tip_args
))
7697 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
7699 if (!NILP (tip_frame
))
7701 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
7702 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
7703 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
7705 if (EQ (frame
, last_frame
)
7706 && !NILP (Fequal (last_string
, string
))
7707 && !NILP (Fequal (last_parms
, parms
)))
7709 struct frame
*f
= XFRAME (tip_frame
);
7711 /* Only DX and DY have changed. */
7712 if (!NILP (tip_timer
))
7714 Lisp_Object timer
= tip_timer
;
7716 call1 (Qcancel_timer
, timer
);
7720 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
7721 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
7723 /* Put tooltip in topmost group and in position. */
7724 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
7725 root_x
, root_y
, 0, 0,
7726 SWP_NOSIZE
| SWP_NOACTIVATE
);
7728 /* Ensure tooltip is on top of other topmost windows (eg menus). */
7729 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
7731 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
7738 /* Hide a previous tip, if any. */
7741 ASET (last_show_tip_args
, 0, string
);
7742 ASET (last_show_tip_args
, 1, frame
);
7743 ASET (last_show_tip_args
, 2, parms
);
7745 /* Add default values to frame parameters. */
7746 if (NILP (Fassq (Qname
, parms
)))
7747 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
7748 if (NILP (Fassq (Qinternal_border_width
, parms
)))
7749 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
7750 if (NILP (Fassq (Qborder_width
, parms
)))
7751 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
7752 if (NILP (Fassq (Qborder_color
, parms
)))
7753 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
7754 if (NILP (Fassq (Qbackground_color
, parms
)))
7755 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
7758 /* Block input until the tip has been fully drawn, to avoid crashes
7759 when drawing tips in menus. */
7762 /* Create a frame for the tooltip, and record it in the global
7763 variable tip_frame. */
7764 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
, string
);
7767 /* Set up the frame's root window. */
7768 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7769 w
->left_col
= w
->top_line
= make_number (0);
7771 if (CONSP (Vx_max_tooltip_size
)
7772 && INTEGERP (XCAR (Vx_max_tooltip_size
))
7773 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
7774 && INTEGERP (XCDR (Vx_max_tooltip_size
))
7775 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
7777 w
->total_cols
= XCAR (Vx_max_tooltip_size
);
7778 w
->total_lines
= XCDR (Vx_max_tooltip_size
);
7782 w
->total_cols
= make_number (80);
7783 w
->total_lines
= make_number (40);
7786 FRAME_TOTAL_COLS (f
) = XINT (w
->total_cols
);
7788 w
->pseudo_window_p
= 1;
7790 /* Display the tooltip text in a temporary buffer. */
7791 old_buffer
= current_buffer
;
7792 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
7793 current_buffer
->truncate_lines
= Qnil
;
7794 clear_glyph_matrix (w
->desired_matrix
);
7795 clear_glyph_matrix (w
->current_matrix
);
7796 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
7797 try_window (FRAME_ROOT_WINDOW (f
), pos
, 0);
7799 /* Compute width and height of the tooltip. */
7801 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
7803 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
7807 /* Stop at the first empty row at the end. */
7808 if (!row
->enabled_p
|| !row
->displays_text_p
)
7811 /* Let the row go over the full width of the frame. */
7812 row
->full_width_p
= 1;
7814 #ifdef TODO /* Investigate why some fonts need more width than is
7815 calculated for some tooltips. */
7816 /* There's a glyph at the end of rows that is use to place
7817 the cursor there. Don't include the width of this glyph. */
7818 if (row
->used
[TEXT_AREA
])
7820 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
7821 row_width
= row
->pixel_width
- last
->pixel_width
;
7825 row_width
= row
->pixel_width
;
7827 /* TODO: find why tips do not draw along baseline as instructed. */
7828 height
+= row
->height
;
7829 width
= max (width
, row_width
);
7832 /* Add the frame's internal border to the width and height the X
7833 window should have. */
7834 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
7835 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
7837 /* Move the tooltip window where the mouse pointer is. Resize and
7839 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
7842 /* Adjust Window size to take border into account. */
7844 rect
.left
= rect
.top
= 0;
7846 rect
.bottom
= height
;
7847 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
7848 FRAME_EXTERNAL_MENU_BAR (f
));
7850 /* Position and size tooltip, and put it in the topmost group.
7851 The add-on of 3 to the 5th argument is a kludge: without it,
7852 some fonts cause the last character of the tip to be truncated,
7853 for some obscure reason. */
7854 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
7855 root_x
, root_y
, rect
.right
- rect
.left
+ 3,
7856 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
);
7858 /* Ensure tooltip is on top of other topmost windows (eg menus). */
7859 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
7861 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
7863 /* Let redisplay know that we have made the frame visible already. */
7864 f
->async_visible
= 1;
7866 ShowWindow (FRAME_W32_WINDOW (f
), SW_SHOWNOACTIVATE
);
7869 /* Draw into the window. */
7870 w
->must_be_updated_p
= 1;
7871 update_single_window (w
, 1);
7875 /* Restore original current buffer. */
7876 set_buffer_internal_1 (old_buffer
);
7877 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7880 /* Let the tip disappear after timeout seconds. */
7881 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
7882 intern ("x-hide-tip"));
7885 return unbind_to (count
, Qnil
);
7889 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
7890 doc
: /* Hide the current tooltip window, if there is any.
7891 Value is t if tooltip was open, nil otherwise. */)
7895 Lisp_Object deleted
, frame
, timer
;
7896 struct gcpro gcpro1
, gcpro2
;
7898 /* Return quickly if nothing to do. */
7899 if (NILP (tip_timer
) && NILP (tip_frame
))
7904 GCPRO2 (frame
, timer
);
7905 tip_frame
= tip_timer
= deleted
= Qnil
;
7907 count
= SPECPDL_INDEX ();
7908 specbind (Qinhibit_redisplay
, Qt
);
7909 specbind (Qinhibit_quit
, Qt
);
7912 call1 (Qcancel_timer
, timer
);
7916 Fdelete_frame (frame
, Qnil
);
7921 return unbind_to (count
, deleted
);
7926 /***********************************************************************
7927 File selection dialog
7928 ***********************************************************************/
7929 extern Lisp_Object Qfile_name_history
;
7931 /* Callback for altering the behaviour of the Open File dialog.
7932 Makes the Filename text field contain "Current Directory" and be
7933 read-only when "Directories" is selected in the filter. This
7934 allows us to work around the fact that the standard Open File
7935 dialog does not support directories. */
7937 file_dialog_callback (hwnd
, msg
, wParam
, lParam
)
7943 if (msg
== WM_NOTIFY
)
7945 OFNOTIFY
* notify
= (OFNOTIFY
*)lParam
;
7946 /* Detect when the Filter dropdown is changed. */
7947 if (notify
->hdr
.code
== CDN_TYPECHANGE
7948 || notify
->hdr
.code
== CDN_INITDONE
)
7950 HWND dialog
= GetParent (hwnd
);
7951 HWND edit_control
= GetDlgItem (dialog
, FILE_NAME_TEXT_FIELD
);
7953 /* Directories is in index 2. */
7954 if (notify
->lpOFN
->nFilterIndex
== 2)
7956 CommDlg_OpenSave_SetControlText (dialog
, FILE_NAME_TEXT_FIELD
,
7957 "Current Directory");
7958 EnableWindow (edit_control
, FALSE
);
7962 /* Don't override default filename on init done. */
7963 if (notify
->hdr
.code
== CDN_TYPECHANGE
)
7964 CommDlg_OpenSave_SetControlText (dialog
,
7965 FILE_NAME_TEXT_FIELD
, "");
7966 EnableWindow (edit_control
, TRUE
);
7973 /* Since we compile with _WIN32_WINNT set to 0x0400 (for NT4 compatibility)
7974 we end up with the old file dialogs. Define a big enough struct for the
7975 new dialog to trick GetOpenFileName into giving us the new dialogs on
7976 Windows 2000 and XP. */
7979 OPENFILENAME real_details
;
7986 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
7987 doc
: /* Read file name, prompting with PROMPT in directory DIR.
7988 Use a file selection dialog.
7989 Select DEFAULT-FILENAME in the dialog's file selection box, if
7990 specified. Ensure that file exists if MUSTMATCH is non-nil.
7991 If ONLY-DIR-P is non-nil, the user can only select directories. */)
7992 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
)
7993 Lisp_Object prompt
, dir
, default_filename
, mustmatch
, only_dir_p
;
7995 struct frame
*f
= SELECTED_FRAME ();
7996 Lisp_Object file
= Qnil
;
7997 int count
= SPECPDL_INDEX ();
7998 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
7999 char filename
[MAX_PATH
+ 1];
8000 char init_dir
[MAX_PATH
+ 1];
8001 int default_filter_index
= 1; /* 1: All Files, 2: Directories only */
8003 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
8004 CHECK_STRING (prompt
);
8007 /* Create the dialog with PROMPT as title, using DIR as initial
8008 directory and using "*" as pattern. */
8009 dir
= Fexpand_file_name (dir
, Qnil
);
8010 strncpy (init_dir
, SDATA (ENCODE_FILE (dir
)), MAX_PATH
);
8011 init_dir
[MAX_PATH
] = '\0';
8012 unixtodos_filename (init_dir
);
8014 if (STRINGP (default_filename
))
8016 char *file_name_only
;
8017 char *full_path_name
= SDATA (ENCODE_FILE (default_filename
));
8019 unixtodos_filename (full_path_name
);
8021 file_name_only
= strrchr (full_path_name
, '\\');
8022 if (!file_name_only
)
8023 file_name_only
= full_path_name
;
8027 strncpy (filename
, file_name_only
, MAX_PATH
);
8028 filename
[MAX_PATH
] = '\0';
8034 NEWOPENFILENAME new_file_details
;
8035 BOOL file_opened
= FALSE
;
8036 OPENFILENAME
* file_details
= &new_file_details
.real_details
;
8038 /* Prevent redisplay. */
8039 specbind (Qinhibit_redisplay
, Qt
);
8042 bzero (&new_file_details
, sizeof (new_file_details
));
8043 /* Apparently NT4 crashes if you give it an unexpected size.
8044 I'm not sure about Windows 9x, so play it safe. */
8045 if (w32_major_version
> 4 && w32_major_version
< 95)
8046 file_details
->lStructSize
= sizeof (new_file_details
);
8048 file_details
->lStructSize
= sizeof (file_details
);
8050 file_details
->hwndOwner
= FRAME_W32_WINDOW (f
);
8051 /* Undocumented Bug in Common File Dialog:
8052 If a filter is not specified, shell links are not resolved. */
8053 file_details
->lpstrFilter
= "All Files (*.*)\0*.*\0Directories\0*|*\0\0";
8054 file_details
->lpstrFile
= filename
;
8055 file_details
->nMaxFile
= sizeof (filename
);
8056 file_details
->lpstrInitialDir
= init_dir
;
8057 file_details
->lpstrTitle
= SDATA (prompt
);
8059 if (! NILP (only_dir_p
))
8060 default_filter_index
= 2;
8062 file_details
->nFilterIndex
= default_filter_index
;
8064 file_details
->Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
8065 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
8066 if (!NILP (mustmatch
))
8068 /* Require that the path to the parent directory exists. */
8069 file_details
->Flags
|= OFN_PATHMUSTEXIST
;
8070 /* If we are looking for a file, require that it exists. */
8071 if (NILP (only_dir_p
))
8072 file_details
->Flags
|= OFN_FILEMUSTEXIST
;
8075 file_details
->lpfnHook
= (LPOFNHOOKPROC
) file_dialog_callback
;
8077 file_opened
= GetOpenFileName (file_details
);
8083 dostounix_filename (filename
);
8085 if (file_details
->nFilterIndex
== 2)
8087 /* "Directories" selected - strip dummy file name. */
8088 char * last
= strrchr (filename
, '/');
8092 file
= DECODE_FILE(build_string (filename
));
8094 /* User cancelled the dialog without making a selection. */
8095 else if (!CommDlgExtendedError ())
8097 /* An error occurred, fallback on reading from the mini-buffer. */
8099 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
8100 dir
, mustmatch
, dir
, Qfile_name_history
,
8101 default_filename
, Qnil
);
8103 file
= unbind_to (count
, file
);
8108 /* Make "Cancel" equivalent to C-g. */
8110 Fsignal (Qquit
, Qnil
);
8112 return unbind_to (count
, file
);
8117 /***********************************************************************
8118 w32 specialized functions
8119 ***********************************************************************/
8121 DEFUN ("w32-select-font", Fw32_select_font
, Sw32_select_font
, 0, 2, 0,
8122 doc
: /* Select a font for the named FRAME using the W32 font dialog.
8123 Returns an X-style font string corresponding to the selection.
8125 If FRAME is omitted or nil, it defaults to the selected frame.
8126 If INCLUDE-PROPORTIONAL is non-nil, include proportional fonts
8127 in the font selection dialog. */)
8128 (frame
, include_proportional
)
8129 Lisp_Object frame
, include_proportional
;
8131 FRAME_PTR f
= check_x_frame (frame
);
8139 bzero (&cf
, sizeof (cf
));
8140 bzero (&lf
, sizeof (lf
));
8142 cf
.lStructSize
= sizeof (cf
);
8143 cf
.hwndOwner
= FRAME_W32_WINDOW (f
);
8144 cf
.Flags
= CF_FORCEFONTEXIST
| CF_SCREENFONTS
| CF_NOVERTFONTS
;
8146 /* Unless include_proportional is non-nil, limit the selection to
8147 monospaced fonts. */
8148 if (NILP (include_proportional
))
8149 cf
.Flags
|= CF_FIXEDPITCHONLY
;
8153 /* Initialize as much of the font details as we can from the current
8155 hdc
= GetDC (FRAME_W32_WINDOW (f
));
8156 oldobj
= SelectObject (hdc
, FRAME_FONT (f
)->hfont
);
8157 GetTextFace (hdc
, LF_FACESIZE
, lf
.lfFaceName
);
8158 if (GetTextMetrics (hdc
, &tm
))
8160 lf
.lfHeight
= tm
.tmInternalLeading
- tm
.tmHeight
;
8161 lf
.lfWeight
= tm
.tmWeight
;
8162 lf
.lfItalic
= tm
.tmItalic
;
8163 lf
.lfUnderline
= tm
.tmUnderlined
;
8164 lf
.lfStrikeOut
= tm
.tmStruckOut
;
8165 lf
.lfCharSet
= tm
.tmCharSet
;
8166 cf
.Flags
|= CF_INITTOLOGFONTSTRUCT
;
8168 SelectObject (hdc
, oldobj
);
8169 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
8171 if (!ChooseFont (&cf
) || !w32_to_x_font (&lf
, buf
, 100, NULL
))
8174 return build_string (buf
);
8177 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
,
8178 Sw32_send_sys_command
, 1, 2, 0,
8179 doc
: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND.
8180 Some useful values for COMMAND are #xf030 to maximize frame (#xf020
8181 to minimize), #xf120 to restore frame to original size, and #xf100
8182 to activate the menubar for keyboard access. #xf140 activates the
8183 screen saver if defined.
8185 If optional parameter FRAME is not specified, use selected frame. */)
8187 Lisp_Object command
, frame
;
8189 FRAME_PTR f
= check_x_frame (frame
);
8191 CHECK_NUMBER (command
);
8193 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
8198 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
8199 doc
: /* Get Windows to perform OPERATION on DOCUMENT.
8200 This is a wrapper around the ShellExecute system function, which
8201 invokes the application registered to handle OPERATION for DOCUMENT.
8203 OPERATION is either nil or a string that names a supported operation.
8204 What operations can be used depends on the particular DOCUMENT and its
8205 handler application, but typically it is one of the following common
8208 \"open\" - open DOCUMENT, which could be a file, a directory, or an
8209 executable program. If it is an application, that
8210 application is launched in the current buffer's default
8211 directory. Otherwise, the application associated with
8212 DOCUMENT is launched in the buffer's default directory.
8213 \"print\" - print DOCUMENT, which must be a file
8214 \"explore\" - start the Windows Explorer on DOCUMENT
8215 \"edit\" - launch an editor and open DOCUMENT for editing; which
8216 editor is launched depends on the association for the
8218 \"find\" - initiate search starting from DOCUMENT which must specify
8220 nil - invoke the default OPERATION, or \"open\" if default is
8221 not defined or unavailable
8223 DOCUMENT is typically the name of a document file or a URL, but can
8224 also be a program executable to run, or a directory to open in the
8227 If DOCUMENT is a program executable, the optional arg PARAMETERS can
8228 be a string containing command line parameters that will be passed to
8229 the program; otherwise, PARAMETERS should be nil or unspecified.
8231 Second optional argument SHOW-FLAG can be used to control how the
8232 application will be displayed when it is invoked. If SHOW-FLAG is nil
8233 or unspceified, the application is displayed normally, otherwise it is
8234 an integer representing a ShowWindow flag:
8239 6 - start minimized */)
8240 (operation
, document
, parameters
, show_flag
)
8241 Lisp_Object operation
, document
, parameters
, show_flag
;
8243 Lisp_Object current_dir
;
8245 CHECK_STRING (document
);
8247 /* Encode filename and current directory. */
8248 current_dir
= ENCODE_FILE (current_buffer
->directory
);
8249 document
= ENCODE_FILE (document
);
8250 if ((int) ShellExecute (NULL
,
8251 (STRINGP (operation
) ?
8252 SDATA (operation
) : NULL
),
8254 (STRINGP (parameters
) ?
8255 SDATA (parameters
) : NULL
),
8256 SDATA (current_dir
),
8257 (INTEGERP (show_flag
) ?
8258 XINT (show_flag
) : SW_SHOWDEFAULT
))
8261 error ("ShellExecute failed: %s", w32_strerror (0));
8264 /* Lookup virtual keycode from string representing the name of a
8265 non-ascii keystroke into the corresponding virtual key, using
8266 lispy_function_keys. */
8268 lookup_vk_code (char *key
)
8272 for (i
= 0; i
< 256; i
++)
8273 if (lispy_function_keys
[i
] != 0
8274 && strcmp (lispy_function_keys
[i
], key
) == 0)
8280 /* Convert a one-element vector style key sequence to a hot key
8283 w32_parse_hot_key (key
)
8286 /* Copied from Fdefine_key and store_in_keymap. */
8287 register Lisp_Object c
;
8291 struct gcpro gcpro1
;
8295 if (XFASTINT (Flength (key
)) != 1)
8300 c
= Faref (key
, make_number (0));
8302 if (CONSP (c
) && lucid_event_type_list_p (c
))
8303 c
= Fevent_convert_list (c
);
8307 if (! INTEGERP (c
) && ! SYMBOLP (c
))
8308 error ("Key definition is invalid");
8310 /* Work out the base key and the modifiers. */
8313 c
= parse_modifiers (c
);
8314 lisp_modifiers
= XINT (Fcar (Fcdr (c
)));
8318 vk_code
= lookup_vk_code (SDATA (SYMBOL_NAME (c
)));
8320 else if (INTEGERP (c
))
8322 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
8323 /* Many ascii characters are their own virtual key code. */
8324 vk_code
= XINT (c
) & CHARACTERBITS
;
8327 if (vk_code
< 0 || vk_code
> 255)
8330 if ((lisp_modifiers
& meta_modifier
) != 0
8331 && !NILP (Vw32_alt_is_meta
))
8332 lisp_modifiers
|= alt_modifier
;
8334 /* Supply defs missing from mingw32. */
8336 #define MOD_ALT 0x0001
8337 #define MOD_CONTROL 0x0002
8338 #define MOD_SHIFT 0x0004
8339 #define MOD_WIN 0x0008
8342 /* Convert lisp modifiers to Windows hot-key form. */
8343 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
8344 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
8345 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
8346 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
8348 return HOTKEY (vk_code
, w32_modifiers
);
8351 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
,
8352 Sw32_register_hot_key
, 1, 1, 0,
8353 doc
: /* Register KEY as a hot-key combination.
8354 Certain key combinations like Alt-Tab are reserved for system use on
8355 Windows, and therefore are normally intercepted by the system. However,
8356 most of these key combinations can be received by registering them as
8357 hot-keys, overriding their special meaning.
8359 KEY must be a one element key definition in vector form that would be
8360 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta
8361 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper
8362 is always interpreted as the Windows modifier keys.
8364 The return value is the hotkey-id if registered, otherwise nil. */)
8368 key
= w32_parse_hot_key (key
);
8370 if (NILP (Fmemq (key
, w32_grabbed_keys
)))
8372 /* Reuse an empty slot if possible. */
8373 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
8375 /* Safe to add new key to list, even if we have focus. */
8377 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
8379 XSETCAR (item
, key
);
8381 /* Notify input thread about new hot-key definition, so that it
8382 takes effect without needing to switch focus. */
8383 #ifdef USE_LISP_UNION_TYPE
8384 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
8387 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
8395 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
,
8396 Sw32_unregister_hot_key
, 1, 1, 0,
8397 doc
: /* Unregister KEY as a hot-key combination. */)
8403 if (!INTEGERP (key
))
8404 key
= w32_parse_hot_key (key
);
8406 item
= Fmemq (key
, w32_grabbed_keys
);
8410 /* Notify input thread about hot-key definition being removed, so
8411 that it takes effect without needing focus switch. */
8412 #ifdef USE_LISP_UNION_TYPE
8413 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
8414 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
.i
))
8416 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
8417 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
))
8422 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
8429 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
,
8430 Sw32_registered_hot_keys
, 0, 0, 0,
8431 doc
: /* Return list of registered hot-key IDs. */)
8434 return Fcopy_sequence (w32_grabbed_keys
);
8437 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
,
8438 Sw32_reconstruct_hot_key
, 1, 1, 0,
8439 doc
: /* Convert hot-key ID to a lisp key combination.
8440 usage: (w32-reconstruct-hot-key ID) */)
8442 Lisp_Object hotkeyid
;
8444 int vk_code
, w32_modifiers
;
8447 CHECK_NUMBER (hotkeyid
);
8449 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
8450 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
8452 if (lispy_function_keys
[vk_code
])
8453 key
= intern (lispy_function_keys
[vk_code
]);
8455 key
= make_number (vk_code
);
8457 key
= Fcons (key
, Qnil
);
8458 if (w32_modifiers
& MOD_SHIFT
)
8459 key
= Fcons (Qshift
, key
);
8460 if (w32_modifiers
& MOD_CONTROL
)
8461 key
= Fcons (Qctrl
, key
);
8462 if (w32_modifiers
& MOD_ALT
)
8463 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
8464 if (w32_modifiers
& MOD_WIN
)
8465 key
= Fcons (Qhyper
, key
);
8470 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
,
8471 Sw32_toggle_lock_key
, 1, 2, 0,
8472 doc
: /* Toggle the state of the lock key KEY.
8473 KEY can be `capslock', `kp-numlock', or `scroll'.
8474 If the optional parameter NEW-STATE is a number, then the state of KEY
8475 is set to off if the low bit of NEW-STATE is zero, otherwise on. */)
8477 Lisp_Object key
, new_state
;
8481 if (EQ (key
, intern ("capslock")))
8482 vk_code
= VK_CAPITAL
;
8483 else if (EQ (key
, intern ("kp-numlock")))
8484 vk_code
= VK_NUMLOCK
;
8485 else if (EQ (key
, intern ("scroll")))
8486 vk_code
= VK_SCROLL
;
8490 if (!dwWindowsThreadId
)
8491 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
8493 #ifdef USE_LISP_UNION_TYPE
8494 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
8495 (WPARAM
) vk_code
, (LPARAM
) new_state
.i
))
8497 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
8498 (WPARAM
) vk_code
, (LPARAM
) new_state
))
8502 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
8503 return make_number (msg
.wParam
);
8508 DEFUN ("w32-window-exists-p", Fw32_window_exists_p
, Sw32_window_exists_p
,
8510 doc
: /* Return non-nil if a window exists with the specified CLASS and NAME.
8512 This is a direct interface to the Windows API FindWindow function. */)
8514 Lisp_Object
class, name
;
8519 CHECK_STRING (class);
8521 CHECK_STRING (name
);
8523 hnd
= FindWindow (STRINGP (class) ? ((LPCTSTR
) SDATA (class)) : NULL
,
8524 STRINGP (name
) ? ((LPCTSTR
) SDATA (name
)) : NULL
);
8532 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
8533 doc
: /* Return storage information about the file system FILENAME is on.
8534 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
8535 storage of the file system, FREE is the free storage, and AVAIL is the
8536 storage available to a non-superuser. All 3 numbers are in bytes.
8537 If the underlying system call fails, value is nil. */)
8539 Lisp_Object filename
;
8541 Lisp_Object encoded
, value
;
8543 CHECK_STRING (filename
);
8544 filename
= Fexpand_file_name (filename
, Qnil
);
8545 encoded
= ENCODE_FILE (filename
);
8549 /* Determining the required information on Windows turns out, sadly,
8550 to be more involved than one would hope. The original Win32 api
8551 call for this will return bogus information on some systems, but we
8552 must dynamically probe for the replacement api, since that was
8553 added rather late on. */
8555 HMODULE hKernel
= GetModuleHandle ("kernel32");
8556 BOOL (*pfn_GetDiskFreeSpaceEx
)
8557 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
8558 = (void *) GetProcAddress (hKernel
, "GetDiskFreeSpaceEx");
8560 /* On Windows, we may need to specify the root directory of the
8561 volume holding FILENAME. */
8562 char rootname
[MAX_PATH
];
8563 char *name
= SDATA (encoded
);
8565 /* find the root name of the volume if given */
8566 if (isalpha (name
[0]) && name
[1] == ':')
8568 rootname
[0] = name
[0];
8569 rootname
[1] = name
[1];
8573 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
8575 char *str
= rootname
;
8579 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
8589 if (pfn_GetDiskFreeSpaceEx
)
8591 /* Unsigned large integers cannot be cast to double, so
8592 use signed ones instead. */
8593 LARGE_INTEGER availbytes
;
8594 LARGE_INTEGER freebytes
;
8595 LARGE_INTEGER totalbytes
;
8597 if (pfn_GetDiskFreeSpaceEx(rootname
,
8598 (ULARGE_INTEGER
*)&availbytes
,
8599 (ULARGE_INTEGER
*)&totalbytes
,
8600 (ULARGE_INTEGER
*)&freebytes
))
8601 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
8602 make_float ((double) freebytes
.QuadPart
),
8603 make_float ((double) availbytes
.QuadPart
));
8607 DWORD sectors_per_cluster
;
8608 DWORD bytes_per_sector
;
8609 DWORD free_clusters
;
8610 DWORD total_clusters
;
8612 if (GetDiskFreeSpace(rootname
,
8613 §ors_per_cluster
,
8617 value
= list3 (make_float ((double) total_clusters
8618 * sectors_per_cluster
* bytes_per_sector
),
8619 make_float ((double) free_clusters
8620 * sectors_per_cluster
* bytes_per_sector
),
8621 make_float ((double) free_clusters
8622 * sectors_per_cluster
* bytes_per_sector
));
8629 DEFUN ("default-printer-name", Fdefault_printer_name
, Sdefault_printer_name
,
8630 0, 0, 0, doc
: /* Return the name of Windows default printer device. */)
8633 static char pname_buf
[256];
8636 PRINTER_INFO_2
*ppi2
= NULL
;
8637 DWORD dwNeeded
= 0, dwReturned
= 0;
8639 /* Retrieve the default string from Win.ini (the registry).
8640 * String will be in form "printername,drivername,portname".
8641 * This is the most portable way to get the default printer. */
8642 if (GetProfileString ("windows", "device", ",,", pname_buf
, sizeof (pname_buf
)) <= 0)
8644 /* printername precedes first "," character */
8645 strtok (pname_buf
, ",");
8646 /* We want to know more than the printer name */
8647 if (!OpenPrinter (pname_buf
, &hPrn
, NULL
))
8649 GetPrinter (hPrn
, 2, NULL
, 0, &dwNeeded
);
8652 ClosePrinter (hPrn
);
8655 /* Allocate memory for the PRINTER_INFO_2 struct */
8656 ppi2
= (PRINTER_INFO_2
*) xmalloc (dwNeeded
);
8659 ClosePrinter (hPrn
);
8662 /* Call GetPrinter() again with big enouth memory block */
8663 err
= GetPrinter (hPrn
, 2, (LPBYTE
)ppi2
, dwNeeded
, &dwReturned
);
8664 ClosePrinter (hPrn
);
8673 if (ppi2
->Attributes
& PRINTER_ATTRIBUTE_SHARED
&& ppi2
->pServerName
)
8675 /* a remote printer */
8676 if (*ppi2
->pServerName
== '\\')
8677 _snprintf(pname_buf
, sizeof (pname_buf
), "%s\\%s", ppi2
->pServerName
,
8680 _snprintf(pname_buf
, sizeof (pname_buf
), "\\\\%s\\%s", ppi2
->pServerName
,
8682 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
8686 /* a local printer */
8687 strncpy(pname_buf
, ppi2
->pPortName
, sizeof (pname_buf
));
8688 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
8689 /* `pPortName' can include several ports, delimited by ','.
8690 * we only use the first one. */
8691 strtok(pname_buf
, ",");
8696 return build_string (pname_buf
);
8699 /***********************************************************************
8701 ***********************************************************************/
8703 /* Keep this list in the same order as frame_parms in frame.c.
8704 Use 0 for unsupported frame parameters. */
8706 frame_parm_handler w32_frame_parm_handlers
[] =
8710 x_set_background_color
,
8716 x_set_foreground_color
,
8719 x_set_internal_border_width
,
8720 x_set_menu_bar_lines
,
8722 x_explicitly_set_name
,
8723 x_set_scroll_bar_width
,
8726 x_set_vertical_scroll_bars
,
8728 x_set_tool_bar_lines
,
8729 0, /* x_set_scroll_bar_foreground, */
8730 0, /* x_set_scroll_bar_background, */
8735 0, /* x_set_wait_for_wm, */
8737 #ifdef USE_FONT_BACKEND
8745 globals_of_w32fns ();
8746 /* This is zero if not using MS-Windows. */
8748 track_mouse_window
= NULL
;
8750 w32_visible_system_caret_hwnd
= NULL
;
8752 Qnone
= intern ("none");
8754 Qsuppress_icon
= intern ("suppress-icon");
8755 staticpro (&Qsuppress_icon
);
8756 Qundefined_color
= intern ("undefined-color");
8757 staticpro (&Qundefined_color
);
8758 Qcancel_timer
= intern ("cancel-timer");
8759 staticpro (&Qcancel_timer
);
8761 Qhyper
= intern ("hyper");
8762 staticpro (&Qhyper
);
8763 Qsuper
= intern ("super");
8764 staticpro (&Qsuper
);
8765 Qmeta
= intern ("meta");
8767 Qalt
= intern ("alt");
8769 Qctrl
= intern ("ctrl");
8771 Qcontrol
= intern ("control");
8772 staticpro (&Qcontrol
);
8773 Qshift
= intern ("shift");
8774 staticpro (&Qshift
);
8775 /* This is the end of symbol initialization. */
8777 /* Text property `display' should be nonsticky by default. */
8778 Vtext_property_default_nonsticky
8779 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
8782 Fput (Qundefined_color
, Qerror_conditions
,
8783 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
8784 Fput (Qundefined_color
, Qerror_message
,
8785 build_string ("Undefined color"));
8787 staticpro (&w32_grabbed_keys
);
8788 w32_grabbed_keys
= Qnil
;
8790 DEFVAR_LISP ("w32-color-map", &Vw32_color_map
,
8791 doc
: /* An array of color name mappings for Windows. */);
8792 Vw32_color_map
= Qnil
;
8794 DEFVAR_LISP ("w32-pass-alt-to-system", &Vw32_pass_alt_to_system
,
8795 doc
: /* Non-nil if Alt key presses are passed on to Windows.
8796 When non-nil, for example, Alt pressed and released and then space will
8797 open the System menu. When nil, Emacs processes the Alt key events, and
8798 then silently swallows them. */);
8799 Vw32_pass_alt_to_system
= Qnil
;
8801 DEFVAR_LISP ("w32-alt-is-meta", &Vw32_alt_is_meta
,
8802 doc
: /* Non-nil if the Alt key is to be considered the same as the META key.
8803 When nil, Emacs will translate the Alt key to the ALT modifier, not to META. */);
8804 Vw32_alt_is_meta
= Qt
;
8806 DEFVAR_INT ("w32-quit-key", &w32_quit_key
,
8807 doc
: /* If non-zero, the virtual key code for an alternative quit key. */);
8810 DEFVAR_LISP ("w32-pass-lwindow-to-system",
8811 &Vw32_pass_lwindow_to_system
,
8812 doc
: /* If non-nil, the left \"Windows\" key is passed on to Windows.
8814 When non-nil, the Start menu is opened by tapping the key.
8815 If you set this to nil, the left \"Windows\" key is processed by Emacs
8816 according to the value of `w32-lwindow-modifier', which see.
8818 Note that some combinations of the left \"Windows\" key with other keys are
8819 caught by Windows at low level, and so binding them in Emacs will have no
8820 effect. For example, <lwindow>-r always pops up the Windows Run dialog,
8821 <lwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
8822 the doc string of `w32-phantom-key-code'. */);
8823 Vw32_pass_lwindow_to_system
= Qt
;
8825 DEFVAR_LISP ("w32-pass-rwindow-to-system",
8826 &Vw32_pass_rwindow_to_system
,
8827 doc
: /* If non-nil, the right \"Windows\" key is passed on to Windows.
8829 When non-nil, the Start menu is opened by tapping the key.
8830 If you set this to nil, the right \"Windows\" key is processed by Emacs
8831 according to the value of `w32-rwindow-modifier', which see.
8833 Note that some combinations of the right \"Windows\" key with other keys are
8834 caught by Windows at low level, and so binding them in Emacs will have no
8835 effect. For example, <rwindow>-r always pops up the Windows Run dialog,
8836 <rwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
8837 the doc string of `w32-phantom-key-code'. */);
8838 Vw32_pass_rwindow_to_system
= Qt
;
8840 DEFVAR_LISP ("w32-phantom-key-code",
8841 &Vw32_phantom_key_code
,
8842 doc
: /* Virtual key code used to generate \"phantom\" key presses.
8843 Value is a number between 0 and 255.
8845 Phantom key presses are generated in order to stop the system from
8846 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or
8847 `w32-pass-rwindow-to-system' is nil. */);
8848 /* Although 255 is technically not a valid key code, it works and
8849 means that this hack won't interfere with any real key code. */
8850 XSETINT (Vw32_phantom_key_code
, 255);
8852 DEFVAR_LISP ("w32-enable-num-lock",
8853 &Vw32_enable_num_lock
,
8854 doc
: /* If non-nil, the Num Lock key acts normally.
8855 Set to nil to handle Num Lock as the `kp-numlock' key. */);
8856 Vw32_enable_num_lock
= Qt
;
8858 DEFVAR_LISP ("w32-enable-caps-lock",
8859 &Vw32_enable_caps_lock
,
8860 doc
: /* If non-nil, the Caps Lock key acts normally.
8861 Set to nil to handle Caps Lock as the `capslock' key. */);
8862 Vw32_enable_caps_lock
= Qt
;
8864 DEFVAR_LISP ("w32-scroll-lock-modifier",
8865 &Vw32_scroll_lock_modifier
,
8866 doc
: /* Modifier to use for the Scroll Lock ON state.
8867 The value can be hyper, super, meta, alt, control or shift for the
8868 respective modifier, or nil to handle Scroll Lock as the `scroll' key.
8869 Any other value will cause the Scroll Lock key to be ignored. */);
8870 Vw32_scroll_lock_modifier
= Qt
;
8872 DEFVAR_LISP ("w32-lwindow-modifier",
8873 &Vw32_lwindow_modifier
,
8874 doc
: /* Modifier to use for the left \"Windows\" key.
8875 The value can be hyper, super, meta, alt, control or shift for the
8876 respective modifier, or nil to appear as the `lwindow' key.
8877 Any other value will cause the key to be ignored. */);
8878 Vw32_lwindow_modifier
= Qnil
;
8880 DEFVAR_LISP ("w32-rwindow-modifier",
8881 &Vw32_rwindow_modifier
,
8882 doc
: /* Modifier to use for the right \"Windows\" key.
8883 The value can be hyper, super, meta, alt, control or shift for the
8884 respective modifier, or nil to appear as the `rwindow' key.
8885 Any other value will cause the key to be ignored. */);
8886 Vw32_rwindow_modifier
= Qnil
;
8888 DEFVAR_LISP ("w32-apps-modifier",
8889 &Vw32_apps_modifier
,
8890 doc
: /* Modifier to use for the \"Apps\" key.
8891 The value can be hyper, super, meta, alt, control or shift for the
8892 respective modifier, or nil to appear as the `apps' key.
8893 Any other value will cause the key to be ignored. */);
8894 Vw32_apps_modifier
= Qnil
;
8896 DEFVAR_BOOL ("w32-enable-synthesized-fonts", &w32_enable_synthesized_fonts
,
8897 doc
: /* Non-nil enables selection of artificially italicized and bold fonts. */);
8898 w32_enable_synthesized_fonts
= 0;
8900 DEFVAR_LISP ("w32-enable-palette", &Vw32_enable_palette
,
8901 doc
: /* Non-nil enables Windows palette management to map colors exactly. */);
8902 Vw32_enable_palette
= Qt
;
8904 DEFVAR_INT ("w32-mouse-button-tolerance",
8905 &w32_mouse_button_tolerance
,
8906 doc
: /* Analogue of double click interval for faking middle mouse events.
8907 The value is the minimum time in milliseconds that must elapse between
8908 left and right button down events before they are considered distinct events.
8909 If both mouse buttons are depressed within this interval, a middle mouse
8910 button down event is generated instead. */);
8911 w32_mouse_button_tolerance
= GetDoubleClickTime () / 2;
8913 DEFVAR_INT ("w32-mouse-move-interval",
8914 &w32_mouse_move_interval
,
8915 doc
: /* Minimum interval between mouse move events.
8916 The value is the minimum time in milliseconds that must elapse between
8917 successive mouse move (or scroll bar drag) events before they are
8918 reported as lisp events. */);
8919 w32_mouse_move_interval
= 0;
8921 DEFVAR_BOOL ("w32-pass-extra-mouse-buttons-to-system",
8922 &w32_pass_extra_mouse_buttons_to_system
,
8923 doc
: /* If non-nil, the fourth and fifth mouse buttons are passed to Windows.
8924 Recent versions of Windows support mice with up to five buttons.
8925 Since most applications don't support these extra buttons, most mouse
8926 drivers will allow you to map them to functions at the system level.
8927 If this variable is non-nil, Emacs will pass them on, allowing the
8928 system to handle them. */);
8929 w32_pass_extra_mouse_buttons_to_system
= 0;
8931 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
8932 doc
: /* The shape of the pointer when over text.
8933 Changing the value does not affect existing frames
8934 unless you set the mouse color. */);
8935 Vx_pointer_shape
= Qnil
;
8937 Vx_nontext_pointer_shape
= Qnil
;
8939 Vx_mode_pointer_shape
= Qnil
;
8941 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
8942 doc
: /* The shape of the pointer when Emacs is busy.
8943 This variable takes effect when you create a new frame
8944 or when you set the mouse color. */);
8945 Vx_hourglass_pointer_shape
= Qnil
;
8947 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
8948 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
8949 display_hourglass_p
= 1;
8951 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
8952 doc
: /* *Seconds to wait before displaying an hourglass pointer.
8953 Value must be an integer or float. */);
8954 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
8956 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
8957 &Vx_sensitive_text_pointer_shape
,
8958 doc
: /* The shape of the pointer when over mouse-sensitive text.
8959 This variable takes effect when you create a new frame
8960 or when you set the mouse color. */);
8961 Vx_sensitive_text_pointer_shape
= Qnil
;
8963 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
8964 &Vx_window_horizontal_drag_shape
,
8965 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
8966 This variable takes effect when you create a new frame
8967 or when you set the mouse color. */);
8968 Vx_window_horizontal_drag_shape
= Qnil
;
8970 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
8971 doc
: /* A string indicating the foreground color of the cursor box. */);
8972 Vx_cursor_fore_pixel
= Qnil
;
8974 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size
,
8975 doc
: /* Maximum size for tooltips.
8976 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
8977 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
8979 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
8980 doc
: /* Non-nil if no window manager is in use.
8981 Emacs doesn't try to figure this out; this is always nil
8982 unless you set it to something else. */);
8983 /* We don't have any way to find this out, so set it to nil
8984 and maybe the user would like to set it to t. */
8985 Vx_no_window_manager
= Qnil
;
8987 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
8988 &Vx_pixel_size_width_font_regexp
,
8989 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
8991 Since Emacs gets width of a font matching with this regexp from
8992 PIXEL_SIZE field of the name, font finding mechanism gets faster for
8993 such a font. This is especially effective for such large fonts as
8994 Chinese, Japanese, and Korean. */);
8995 Vx_pixel_size_width_font_regexp
= Qnil
;
8997 DEFVAR_LISP ("w32-bdf-filename-alist",
8998 &Vw32_bdf_filename_alist
,
8999 doc
: /* List of bdf fonts and their corresponding filenames. */);
9000 Vw32_bdf_filename_alist
= Qnil
;
9002 DEFVAR_BOOL ("w32-strict-fontnames",
9003 &w32_strict_fontnames
,
9004 doc
: /* Non-nil means only use fonts that are exact matches for those requested.
9005 Default is nil, which allows old fontnames that are not XLFD compliant,
9006 and allows third-party CJK display to work by specifying false charset
9007 fields to trick Emacs into translating to Big5, SJIS etc.
9008 Setting this to t will prevent wrong fonts being selected when
9009 fontsets are automatically created. */);
9010 w32_strict_fontnames
= 0;
9012 DEFVAR_BOOL ("w32-strict-painting",
9013 &w32_strict_painting
,
9014 doc
: /* Non-nil means use strict rules for repainting frames.
9015 Set this to nil to get the old behavior for repainting; this should
9016 only be necessary if the default setting causes problems. */);
9017 w32_strict_painting
= 1;
9019 DEFVAR_LISP ("w32-charset-info-alist",
9020 &Vw32_charset_info_alist
,
9021 doc
: /* Alist linking Emacs character sets to Windows fonts and codepages.
9022 Each entry should be of the form:
9024 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE))
9026 where CHARSET_NAME is a string used in font names to identify the charset,
9027 WINDOWS_CHARSET is a symbol that can be one of:
9028 w32-charset-ansi, w32-charset-default, w32-charset-symbol,
9029 w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312,
9030 w32-charset-chinesebig5,
9031 w32-charset-johab, w32-charset-hebrew,
9032 w32-charset-arabic, w32-charset-greek, w32-charset-turkish,
9033 w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope,
9034 w32-charset-russian, w32-charset-mac, w32-charset-baltic,
9035 w32-charset-unicode,
9037 CODEPAGE should be an integer specifying the codepage that should be used
9038 to display the character set, t to do no translation and output as Unicode,
9039 or nil to do no translation and output as 8 bit (or multibyte on far-east
9040 versions of Windows) characters. */);
9041 Vw32_charset_info_alist
= Qnil
;
9043 staticpro (&Qw32_charset_ansi
);
9044 Qw32_charset_ansi
= intern ("w32-charset-ansi");
9045 staticpro (&Qw32_charset_symbol
);
9046 Qw32_charset_default
= intern ("w32-charset-default");
9047 staticpro (&Qw32_charset_default
);
9048 Qw32_charset_symbol
= intern ("w32-charset-symbol");
9049 staticpro (&Qw32_charset_shiftjis
);
9050 Qw32_charset_shiftjis
= intern ("w32-charset-shiftjis");
9051 staticpro (&Qw32_charset_hangeul
);
9052 Qw32_charset_hangeul
= intern ("w32-charset-hangeul");
9053 staticpro (&Qw32_charset_chinesebig5
);
9054 Qw32_charset_chinesebig5
= intern ("w32-charset-chinesebig5");
9055 staticpro (&Qw32_charset_gb2312
);
9056 Qw32_charset_gb2312
= intern ("w32-charset-gb2312");
9057 staticpro (&Qw32_charset_oem
);
9058 Qw32_charset_oem
= intern ("w32-charset-oem");
9060 #ifdef JOHAB_CHARSET
9062 static int w32_extra_charsets_defined
= 1;
9063 DEFVAR_BOOL ("w32-extra-charsets-defined", &w32_extra_charsets_defined
,
9064 doc
: /* Internal variable. */);
9066 staticpro (&Qw32_charset_johab
);
9067 Qw32_charset_johab
= intern ("w32-charset-johab");
9068 staticpro (&Qw32_charset_easteurope
);
9069 Qw32_charset_easteurope
= intern ("w32-charset-easteurope");
9070 staticpro (&Qw32_charset_turkish
);
9071 Qw32_charset_turkish
= intern ("w32-charset-turkish");
9072 staticpro (&Qw32_charset_baltic
);
9073 Qw32_charset_baltic
= intern ("w32-charset-baltic");
9074 staticpro (&Qw32_charset_russian
);
9075 Qw32_charset_russian
= intern ("w32-charset-russian");
9076 staticpro (&Qw32_charset_arabic
);
9077 Qw32_charset_arabic
= intern ("w32-charset-arabic");
9078 staticpro (&Qw32_charset_greek
);
9079 Qw32_charset_greek
= intern ("w32-charset-greek");
9080 staticpro (&Qw32_charset_hebrew
);
9081 Qw32_charset_hebrew
= intern ("w32-charset-hebrew");
9082 staticpro (&Qw32_charset_vietnamese
);
9083 Qw32_charset_vietnamese
= intern ("w32-charset-vietnamese");
9084 staticpro (&Qw32_charset_thai
);
9085 Qw32_charset_thai
= intern ("w32-charset-thai");
9086 staticpro (&Qw32_charset_mac
);
9087 Qw32_charset_mac
= intern ("w32-charset-mac");
9091 #ifdef UNICODE_CHARSET
9093 static int w32_unicode_charset_defined
= 1;
9094 DEFVAR_BOOL ("w32-unicode-charset-defined",
9095 &w32_unicode_charset_defined
,
9096 doc
: /* Internal variable. */);
9098 staticpro (&Qw32_charset_unicode
);
9099 Qw32_charset_unicode
= intern ("w32-charset-unicode");
9103 #if 0 /* TODO: Port to W32 */
9104 defsubr (&Sx_change_window_property
);
9105 defsubr (&Sx_delete_window_property
);
9106 defsubr (&Sx_window_property
);
9108 defsubr (&Sxw_display_color_p
);
9109 defsubr (&Sx_display_grayscale_p
);
9110 defsubr (&Sxw_color_defined_p
);
9111 defsubr (&Sxw_color_values
);
9112 defsubr (&Sx_server_max_request_size
);
9113 defsubr (&Sx_server_vendor
);
9114 defsubr (&Sx_server_version
);
9115 defsubr (&Sx_display_pixel_width
);
9116 defsubr (&Sx_display_pixel_height
);
9117 defsubr (&Sx_display_mm_width
);
9118 defsubr (&Sx_display_mm_height
);
9119 defsubr (&Sx_display_screens
);
9120 defsubr (&Sx_display_planes
);
9121 defsubr (&Sx_display_color_cells
);
9122 defsubr (&Sx_display_visual_class
);
9123 defsubr (&Sx_display_backing_store
);
9124 defsubr (&Sx_display_save_under
);
9125 defsubr (&Sx_create_frame
);
9126 defsubr (&Sx_open_connection
);
9127 defsubr (&Sx_close_connection
);
9128 defsubr (&Sx_display_list
);
9129 defsubr (&Sx_synchronize
);
9131 /* W32 specific functions */
9133 defsubr (&Sw32_focus_frame
);
9134 defsubr (&Sw32_select_font
);
9135 defsubr (&Sw32_define_rgb_color
);
9136 defsubr (&Sw32_default_color_map
);
9137 defsubr (&Sw32_load_color_file
);
9138 defsubr (&Sw32_send_sys_command
);
9139 defsubr (&Sw32_shell_execute
);
9140 defsubr (&Sw32_register_hot_key
);
9141 defsubr (&Sw32_unregister_hot_key
);
9142 defsubr (&Sw32_registered_hot_keys
);
9143 defsubr (&Sw32_reconstruct_hot_key
);
9144 defsubr (&Sw32_toggle_lock_key
);
9145 defsubr (&Sw32_window_exists_p
);
9146 defsubr (&Sw32_find_bdf_fonts
);
9148 defsubr (&Sfile_system_info
);
9149 defsubr (&Sdefault_printer_name
);
9151 /* Setting callback functions for fontset handler. */
9152 get_font_info_func
= w32_get_font_info
;
9154 #if 0 /* This function pointer doesn't seem to be used anywhere.
9155 And the pointer assigned has the wrong type, anyway. */
9156 list_fonts_func
= w32_list_fonts
;
9159 load_font_func
= w32_load_font
;
9160 find_ccl_program_func
= w32_find_ccl_program
;
9161 query_font_func
= w32_query_font
;
9162 set_frame_fontset_func
= x_set_font
;
9163 get_font_repertory_func
= x_get_font_repertory
;
9164 check_window_system_func
= check_w32
;
9167 hourglass_atimer
= NULL
;
9168 hourglass_shown_p
= 0;
9169 defsubr (&Sx_show_tip
);
9170 defsubr (&Sx_hide_tip
);
9172 staticpro (&tip_timer
);
9174 staticpro (&tip_frame
);
9176 last_show_tip_args
= Qnil
;
9177 staticpro (&last_show_tip_args
);
9179 defsubr (&Sx_file_dialog
);
9184 globals_of_w32fns is used to initialize those global variables that
9185 must always be initialized on startup even when the global variable
9186 initialized is non zero (see the function main in emacs.c).
9187 globals_of_w32fns is called from syms_of_w32fns when the global
9188 variable initialized is 0 and directly from main when initialized
9191 void globals_of_w32fns ()
9193 HMODULE user32_lib
= GetModuleHandle ("user32.dll");
9195 TrackMouseEvent not available in all versions of Windows, so must load
9196 it dynamically. Do it once, here, instead of every time it is used.
9198 track_mouse_event_fn
= (TrackMouseEvent_Proc
)
9199 GetProcAddress (user32_lib
, "TrackMouseEvent");
9200 /* ditto for GetClipboardSequenceNumber. */
9201 clipboard_sequence_fn
= (ClipboardSequence_Proc
)
9202 GetProcAddress (user32_lib
, "GetClipboardSequenceNumber");
9204 DEFVAR_INT ("w32-ansi-code-page",
9205 &w32_ansi_code_page
,
9206 doc
: /* The ANSI code page used by the system. */);
9207 w32_ansi_code_page
= GetACP ();
9212 void w32_abort (void) NO_RETURN
;
9218 button
= MessageBox (NULL
,
9219 "A fatal error has occurred!\n\n"
9220 "Would you like to attach a debugger?\n\n"
9221 "Select YES to debug, NO to abort Emacs"
9223 "\n\n(type \"gdb -p <emacs-PID>\" and\n"
9224 "\"continue\" inside GDB before clicking YES.)"
9226 , "Emacs Abort Dialog",
9227 MB_ICONEXCLAMATION
| MB_TASKMODAL
9228 | MB_SETFOREGROUND
| MB_YESNO
);
9233 exit (2); /* tell the compiler we will never return */
9241 /* For convenience when debugging. */
9245 return GetLastError ();
9248 /* arch-tag: 707589ab-b9be-4638-8cdd-74629cc9b446
9249 (do not change this comment) */