1 /* Graphical user interface functions for the Microsoft W32 API.
2 Copyright (C) 1989, 1992, 93, 94, 95, 96, 97, 98, 99, 2000, 01, 04
3 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., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* Added by Kevin Gallo */
33 #include "dispextern.h"
40 #include "intervals.h"
41 #include "blockinput.h"
44 #include "termhooks.h"
49 #include "bitmaps/gray.xbm"
57 #define FILE_NAME_TEXT_FIELD edt1
59 void syms_of_w32fns ();
60 void globals_of_w32fns ();
62 extern void free_frame_menubar ();
63 extern double atof ();
64 extern int w32_console_toggle_lock_key
P_ ((int, Lisp_Object
));
65 extern void w32_menu_display_help
P_ ((HWND
, HMENU
, UINT
, UINT
));
66 extern void w32_free_menu_strings
P_ ((HWND
));
70 extern char *lispy_function_keys
[];
72 /* The gray bitmap `bitmaps/gray'. This is done because w32term.c uses
73 it, and including `bitmaps/gray' more than once is a problem when
74 config.h defines `static' as an empty replacement string. */
76 int gray_bitmap_width
= gray_width
;
77 int gray_bitmap_height
= gray_height
;
78 unsigned char *gray_bitmap_bits
= gray_bits
;
80 /* The colormap for converting color names to RGB values */
81 Lisp_Object Vw32_color_map
;
83 /* Non nil if alt key presses are passed on to Windows. */
84 Lisp_Object Vw32_pass_alt_to_system
;
86 /* Non nil if alt key is translated to meta_modifier, nil if it is translated
88 Lisp_Object Vw32_alt_is_meta
;
90 /* If non-zero, the windows virtual key code for an alternative quit key. */
93 /* Non nil if left window key events are passed on to Windows (this only
94 affects whether "tapping" the key opens the Start menu). */
95 Lisp_Object Vw32_pass_lwindow_to_system
;
97 /* Non nil if right window key events are passed on to Windows (this
98 only affects whether "tapping" the key opens the Start menu). */
99 Lisp_Object Vw32_pass_rwindow_to_system
;
101 /* Virtual key code used to generate "phantom" key presses in order
102 to stop system from acting on Windows key events. */
103 Lisp_Object Vw32_phantom_key_code
;
105 /* Modifier associated with the left "Windows" key, or nil to act as a
107 Lisp_Object Vw32_lwindow_modifier
;
109 /* Modifier associated with the right "Windows" key, or nil to act as a
111 Lisp_Object Vw32_rwindow_modifier
;
113 /* Modifier associated with the "Apps" key, or nil to act as a normal
115 Lisp_Object Vw32_apps_modifier
;
117 /* Value is nil if Num Lock acts as a function key. */
118 Lisp_Object Vw32_enable_num_lock
;
120 /* Value is nil if Caps Lock acts as a function key. */
121 Lisp_Object Vw32_enable_caps_lock
;
123 /* Modifier associated with Scroll Lock, or nil to act as a normal key. */
124 Lisp_Object Vw32_scroll_lock_modifier
;
126 /* Switch to control whether we inhibit requests for synthesized bold
127 and italic versions of fonts. */
128 int w32_enable_synthesized_fonts
;
130 /* Enable palette management. */
131 Lisp_Object Vw32_enable_palette
;
133 /* Control how close left/right button down events must be to
134 be converted to a middle button down event. */
135 int w32_mouse_button_tolerance
;
137 /* Minimum interval between mouse movement (and scroll bar drag)
138 events that are passed on to the event loop. */
139 int w32_mouse_move_interval
;
141 /* Flag to indicate if XBUTTON events should be passed on to Windows. */
142 int w32_pass_extra_mouse_buttons_to_system
;
144 /* Non nil if no window manager is in use. */
145 Lisp_Object Vx_no_window_manager
;
147 /* Non-zero means we're allowed to display a hourglass pointer. */
149 int display_hourglass_p
;
151 /* The background and shape of the mouse pointer, and shape when not
152 over text or in the modeline. */
154 Lisp_Object Vx_pointer_shape
, Vx_nontext_pointer_shape
, Vx_mode_pointer_shape
;
155 Lisp_Object Vx_hourglass_pointer_shape
, Vx_window_horizontal_drag_shape
, Vx_hand_shape
;
157 /* The shape when over mouse-sensitive text. */
159 Lisp_Object Vx_sensitive_text_pointer_shape
;
162 #define IDC_HAND MAKEINTRESOURCE(32649)
165 /* Color of chars displayed in cursor box. */
167 Lisp_Object Vx_cursor_fore_pixel
;
169 /* Nonzero if using Windows. */
171 static int w32_in_use
;
173 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
175 Lisp_Object Vx_pixel_size_width_font_regexp
;
177 /* Alist of bdf fonts and the files that define them. */
178 Lisp_Object Vw32_bdf_filename_alist
;
180 /* A flag to control whether fonts are matched strictly or not. */
181 int w32_strict_fontnames
;
183 /* A flag to control whether we should only repaint if GetUpdateRect
184 indicates there is an update region. */
185 int w32_strict_painting
;
187 /* Associative list linking character set strings to Windows codepages. */
188 Lisp_Object Vw32_charset_info_alist
;
190 /* VIETNAMESE_CHARSET is not defined in some versions of MSVC. */
191 #ifndef VIETNAMESE_CHARSET
192 #define VIETNAMESE_CHARSET 163
196 Lisp_Object Qsuppress_icon
;
197 Lisp_Object Qundefined_color
;
198 Lisp_Object Qcancel_timer
;
204 Lisp_Object Qcontrol
;
207 Lisp_Object Qw32_charset_ansi
;
208 Lisp_Object Qw32_charset_default
;
209 Lisp_Object Qw32_charset_symbol
;
210 Lisp_Object Qw32_charset_shiftjis
;
211 Lisp_Object Qw32_charset_hangeul
;
212 Lisp_Object Qw32_charset_gb2312
;
213 Lisp_Object Qw32_charset_chinesebig5
;
214 Lisp_Object Qw32_charset_oem
;
216 #ifndef JOHAB_CHARSET
217 #define JOHAB_CHARSET 130
220 Lisp_Object Qw32_charset_easteurope
;
221 Lisp_Object Qw32_charset_turkish
;
222 Lisp_Object Qw32_charset_baltic
;
223 Lisp_Object Qw32_charset_russian
;
224 Lisp_Object Qw32_charset_arabic
;
225 Lisp_Object Qw32_charset_greek
;
226 Lisp_Object Qw32_charset_hebrew
;
227 Lisp_Object Qw32_charset_vietnamese
;
228 Lisp_Object Qw32_charset_thai
;
229 Lisp_Object Qw32_charset_johab
;
230 Lisp_Object Qw32_charset_mac
;
233 #ifdef UNICODE_CHARSET
234 Lisp_Object Qw32_charset_unicode
;
237 /* The ANSI codepage. */
238 int w32_ansi_code_page
;
240 /* Prefix for system colors. */
241 #define SYSTEM_COLOR_PREFIX "System"
242 #define SYSTEM_COLOR_PREFIX_LEN (sizeof (SYSTEM_COLOR_PREFIX) - 1)
244 /* State variables for emulating a three button mouse. */
249 static int button_state
= 0;
250 static W32Msg saved_mouse_button_msg
;
251 static unsigned mouse_button_timer
= 0; /* non-zero when timer is active */
252 static W32Msg saved_mouse_move_msg
;
253 static unsigned mouse_move_timer
= 0;
255 /* Window that is tracking the mouse. */
256 static HWND track_mouse_window
;
258 typedef BOOL (WINAPI
* TrackMouseEvent_Proc
)
259 (IN OUT LPTRACKMOUSEEVENT lpEventTrack
);
261 TrackMouseEvent_Proc track_mouse_event_fn
= NULL
;
262 ClipboardSequence_Proc clipboard_sequence_fn
= NULL
;
264 /* W95 mousewheel handler */
265 unsigned int msh_mousewheel
= 0;
268 #define MOUSE_BUTTON_ID 1
269 #define MOUSE_MOVE_ID 2
270 #define MENU_FREE_ID 3
271 /* The delay (milliseconds) before a menu is freed after WM_EXITMENULOOP
273 #define MENU_FREE_DELAY 1000
274 static unsigned menu_free_timer
= 0;
276 /* The below are defined in frame.c. */
278 extern Lisp_Object Vwindow_system_version
;
281 int image_cache_refcount
, dpyinfo_refcount
;
285 /* From w32term.c. */
286 extern int w32_num_mouse_buttons
;
287 extern Lisp_Object Vw32_recognize_altgr
;
289 extern HWND w32_system_caret_hwnd
;
291 extern int w32_system_caret_height
;
292 extern int w32_system_caret_x
;
293 extern int w32_system_caret_y
;
294 extern int w32_use_visible_system_caret
;
296 static HWND w32_visible_system_caret_hwnd
;
299 /* Error if we are not connected to MS-Windows. */
304 error ("MS-Windows not in use or not initialized");
307 /* Nonzero if we can use mouse menus.
308 You should not call this unless HAVE_MENUS is defined. */
316 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
317 and checking validity for W32. */
320 check_x_frame (frame
)
326 frame
= selected_frame
;
327 CHECK_LIVE_FRAME (frame
);
329 if (! FRAME_W32_P (f
))
330 error ("non-w32 frame used");
334 /* Let the user specify a display with a frame.
335 nil stands for the selected frame--or, if that is not a w32 frame,
336 the first display on the list. */
338 struct w32_display_info
*
339 check_x_display_info (frame
)
344 struct frame
*sf
= XFRAME (selected_frame
);
346 if (FRAME_W32_P (sf
) && FRAME_LIVE_P (sf
))
347 return FRAME_W32_DISPLAY_INFO (sf
);
349 return &one_w32_display_info
;
351 else if (STRINGP (frame
))
352 return x_display_info_for_name (frame
);
357 CHECK_LIVE_FRAME (frame
);
359 if (! FRAME_W32_P (f
))
360 error ("non-w32 frame used");
361 return FRAME_W32_DISPLAY_INFO (f
);
365 /* Return the Emacs frame-object corresponding to an w32 window.
366 It could be the frame's main window or an icon window. */
368 /* This function can be called during GC, so use GC_xxx type test macros. */
371 x_window_to_frame (dpyinfo
, wdesc
)
372 struct w32_display_info
*dpyinfo
;
375 Lisp_Object tail
, frame
;
378 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
381 if (!GC_FRAMEP (frame
))
384 if (!FRAME_W32_P (f
) || FRAME_W32_DISPLAY_INFO (f
) != dpyinfo
)
386 if (f
->output_data
.w32
->hourglass_window
== wdesc
)
389 if (FRAME_W32_WINDOW (f
) == wdesc
)
396 BOOL my_show_window
P_ ((struct frame
*, HWND
, int));
397 void my_set_window_pos
P_ ((HWND
, HWND
, int, int, int, int, UINT
));
398 static Lisp_Object unwind_create_frame
P_ ((Lisp_Object
));
399 static Lisp_Object unwind_create_tip_frame
P_ ((Lisp_Object
));
401 /* TODO: Native Input Method support; see x_create_im. */
402 void x_set_foreground_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
403 void x_set_background_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
404 void x_set_mouse_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
405 void x_set_cursor_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
406 void x_set_border_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
407 void x_set_cursor_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
408 void x_set_icon_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
409 void x_set_icon_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
410 void x_explicitly_set_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
411 void x_set_menu_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
412 void x_set_title
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
413 void x_set_tool_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
414 static void x_edge_detection
P_ ((struct frame
*, struct image
*, Lisp_Object
,
420 /* Store the screen positions of frame F into XPTR and YPTR.
421 These are the positions of the containing window manager window,
422 not Emacs's own window. */
425 x_real_positions (f
, xptr
, yptr
)
432 GetClientRect(FRAME_W32_WINDOW(f
), &rect
);
433 AdjustWindowRect(&rect
, f
->output_data
.w32
->dwStyle
, FRAME_EXTERNAL_MENU_BAR(f
));
438 ClientToScreen (FRAME_W32_WINDOW(f
), &pt
);
440 /* Remember x_pixels_diff and y_pixels_diff. */
441 f
->x_pixels_diff
= pt
.x
- rect
.left
;
442 f
->y_pixels_diff
= pt
.y
- rect
.top
;
450 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
,
451 Sw32_define_rgb_color
, 4, 4, 0,
452 doc
: /* Convert RGB numbers to a windows color reference and associate with NAME.
453 This adds or updates a named color to w32-color-map, making it
454 available for use. The original entry's RGB ref is returned, or nil
455 if the entry is new. */)
456 (red
, green
, blue
, name
)
457 Lisp_Object red
, green
, blue
, name
;
460 Lisp_Object oldrgb
= Qnil
;
464 CHECK_NUMBER (green
);
468 XSETINT (rgb
, RGB(XUINT (red
), XUINT (green
), XUINT (blue
)));
472 /* replace existing entry in w32-color-map or add new entry. */
473 entry
= Fassoc (name
, Vw32_color_map
);
476 entry
= Fcons (name
, rgb
);
477 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
481 oldrgb
= Fcdr (entry
);
482 Fsetcdr (entry
, rgb
);
490 DEFUN ("w32-load-color-file", Fw32_load_color_file
,
491 Sw32_load_color_file
, 1, 1, 0,
492 doc
: /* Create an alist of color entries from an external file.
493 Assign this value to w32-color-map to replace the existing color map.
495 The file should define one named RGB color per line like so:
497 where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
499 Lisp_Object filename
;
502 Lisp_Object cmap
= Qnil
;
505 CHECK_STRING (filename
);
506 abspath
= Fexpand_file_name (filename
, Qnil
);
508 fp
= fopen (SDATA (filename
), "rt");
512 int red
, green
, blue
;
517 while (fgets (buf
, sizeof (buf
), fp
) != NULL
) {
518 if (sscanf (buf
, "%u %u %u %n", &red
, &green
, &blue
, &num
) == 3)
520 char *name
= buf
+ num
;
521 num
= strlen (name
) - 1;
522 if (name
[num
] == '\n')
524 cmap
= Fcons (Fcons (build_string (name
),
525 make_number (RGB (red
, green
, blue
))),
537 /* The default colors for the w32 color map */
538 typedef struct colormap_t
544 colormap_t w32_color_map
[] =
546 {"snow" , PALETTERGB (255,250,250)},
547 {"ghost white" , PALETTERGB (248,248,255)},
548 {"GhostWhite" , PALETTERGB (248,248,255)},
549 {"white smoke" , PALETTERGB (245,245,245)},
550 {"WhiteSmoke" , PALETTERGB (245,245,245)},
551 {"gainsboro" , PALETTERGB (220,220,220)},
552 {"floral white" , PALETTERGB (255,250,240)},
553 {"FloralWhite" , PALETTERGB (255,250,240)},
554 {"old lace" , PALETTERGB (253,245,230)},
555 {"OldLace" , PALETTERGB (253,245,230)},
556 {"linen" , PALETTERGB (250,240,230)},
557 {"antique white" , PALETTERGB (250,235,215)},
558 {"AntiqueWhite" , PALETTERGB (250,235,215)},
559 {"papaya whip" , PALETTERGB (255,239,213)},
560 {"PapayaWhip" , PALETTERGB (255,239,213)},
561 {"blanched almond" , PALETTERGB (255,235,205)},
562 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
563 {"bisque" , PALETTERGB (255,228,196)},
564 {"peach puff" , PALETTERGB (255,218,185)},
565 {"PeachPuff" , PALETTERGB (255,218,185)},
566 {"navajo white" , PALETTERGB (255,222,173)},
567 {"NavajoWhite" , PALETTERGB (255,222,173)},
568 {"moccasin" , PALETTERGB (255,228,181)},
569 {"cornsilk" , PALETTERGB (255,248,220)},
570 {"ivory" , PALETTERGB (255,255,240)},
571 {"lemon chiffon" , PALETTERGB (255,250,205)},
572 {"LemonChiffon" , PALETTERGB (255,250,205)},
573 {"seashell" , PALETTERGB (255,245,238)},
574 {"honeydew" , PALETTERGB (240,255,240)},
575 {"mint cream" , PALETTERGB (245,255,250)},
576 {"MintCream" , PALETTERGB (245,255,250)},
577 {"azure" , PALETTERGB (240,255,255)},
578 {"alice blue" , PALETTERGB (240,248,255)},
579 {"AliceBlue" , PALETTERGB (240,248,255)},
580 {"lavender" , PALETTERGB (230,230,250)},
581 {"lavender blush" , PALETTERGB (255,240,245)},
582 {"LavenderBlush" , PALETTERGB (255,240,245)},
583 {"misty rose" , PALETTERGB (255,228,225)},
584 {"MistyRose" , PALETTERGB (255,228,225)},
585 {"white" , PALETTERGB (255,255,255)},
586 {"black" , PALETTERGB ( 0, 0, 0)},
587 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
588 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
589 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
590 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
591 {"dim gray" , PALETTERGB (105,105,105)},
592 {"DimGray" , PALETTERGB (105,105,105)},
593 {"dim grey" , PALETTERGB (105,105,105)},
594 {"DimGrey" , PALETTERGB (105,105,105)},
595 {"slate gray" , PALETTERGB (112,128,144)},
596 {"SlateGray" , PALETTERGB (112,128,144)},
597 {"slate grey" , PALETTERGB (112,128,144)},
598 {"SlateGrey" , PALETTERGB (112,128,144)},
599 {"light slate gray" , PALETTERGB (119,136,153)},
600 {"LightSlateGray" , PALETTERGB (119,136,153)},
601 {"light slate grey" , PALETTERGB (119,136,153)},
602 {"LightSlateGrey" , PALETTERGB (119,136,153)},
603 {"gray" , PALETTERGB (190,190,190)},
604 {"grey" , PALETTERGB (190,190,190)},
605 {"light grey" , PALETTERGB (211,211,211)},
606 {"LightGrey" , PALETTERGB (211,211,211)},
607 {"light gray" , PALETTERGB (211,211,211)},
608 {"LightGray" , PALETTERGB (211,211,211)},
609 {"midnight blue" , PALETTERGB ( 25, 25,112)},
610 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
611 {"navy" , PALETTERGB ( 0, 0,128)},
612 {"navy blue" , PALETTERGB ( 0, 0,128)},
613 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
614 {"cornflower blue" , PALETTERGB (100,149,237)},
615 {"CornflowerBlue" , PALETTERGB (100,149,237)},
616 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
617 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
618 {"slate blue" , PALETTERGB (106, 90,205)},
619 {"SlateBlue" , PALETTERGB (106, 90,205)},
620 {"medium slate blue" , PALETTERGB (123,104,238)},
621 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
622 {"light slate blue" , PALETTERGB (132,112,255)},
623 {"LightSlateBlue" , PALETTERGB (132,112,255)},
624 {"medium blue" , PALETTERGB ( 0, 0,205)},
625 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
626 {"royal blue" , PALETTERGB ( 65,105,225)},
627 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
628 {"blue" , PALETTERGB ( 0, 0,255)},
629 {"dodger blue" , PALETTERGB ( 30,144,255)},
630 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
631 {"deep sky blue" , PALETTERGB ( 0,191,255)},
632 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
633 {"sky blue" , PALETTERGB (135,206,235)},
634 {"SkyBlue" , PALETTERGB (135,206,235)},
635 {"light sky blue" , PALETTERGB (135,206,250)},
636 {"LightSkyBlue" , PALETTERGB (135,206,250)},
637 {"steel blue" , PALETTERGB ( 70,130,180)},
638 {"SteelBlue" , PALETTERGB ( 70,130,180)},
639 {"light steel blue" , PALETTERGB (176,196,222)},
640 {"LightSteelBlue" , PALETTERGB (176,196,222)},
641 {"light blue" , PALETTERGB (173,216,230)},
642 {"LightBlue" , PALETTERGB (173,216,230)},
643 {"powder blue" , PALETTERGB (176,224,230)},
644 {"PowderBlue" , PALETTERGB (176,224,230)},
645 {"pale turquoise" , PALETTERGB (175,238,238)},
646 {"PaleTurquoise" , PALETTERGB (175,238,238)},
647 {"dark turquoise" , PALETTERGB ( 0,206,209)},
648 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
649 {"medium turquoise" , PALETTERGB ( 72,209,204)},
650 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
651 {"turquoise" , PALETTERGB ( 64,224,208)},
652 {"cyan" , PALETTERGB ( 0,255,255)},
653 {"light cyan" , PALETTERGB (224,255,255)},
654 {"LightCyan" , PALETTERGB (224,255,255)},
655 {"cadet blue" , PALETTERGB ( 95,158,160)},
656 {"CadetBlue" , PALETTERGB ( 95,158,160)},
657 {"medium aquamarine" , PALETTERGB (102,205,170)},
658 {"MediumAquamarine" , PALETTERGB (102,205,170)},
659 {"aquamarine" , PALETTERGB (127,255,212)},
660 {"dark green" , PALETTERGB ( 0,100, 0)},
661 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
662 {"dark olive green" , PALETTERGB ( 85,107, 47)},
663 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
664 {"dark sea green" , PALETTERGB (143,188,143)},
665 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
666 {"sea green" , PALETTERGB ( 46,139, 87)},
667 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
668 {"medium sea green" , PALETTERGB ( 60,179,113)},
669 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
670 {"light sea green" , PALETTERGB ( 32,178,170)},
671 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
672 {"pale green" , PALETTERGB (152,251,152)},
673 {"PaleGreen" , PALETTERGB (152,251,152)},
674 {"spring green" , PALETTERGB ( 0,255,127)},
675 {"SpringGreen" , PALETTERGB ( 0,255,127)},
676 {"lawn green" , PALETTERGB (124,252, 0)},
677 {"LawnGreen" , PALETTERGB (124,252, 0)},
678 {"green" , PALETTERGB ( 0,255, 0)},
679 {"chartreuse" , PALETTERGB (127,255, 0)},
680 {"medium spring green" , PALETTERGB ( 0,250,154)},
681 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
682 {"green yellow" , PALETTERGB (173,255, 47)},
683 {"GreenYellow" , PALETTERGB (173,255, 47)},
684 {"lime green" , PALETTERGB ( 50,205, 50)},
685 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
686 {"yellow green" , PALETTERGB (154,205, 50)},
687 {"YellowGreen" , PALETTERGB (154,205, 50)},
688 {"forest green" , PALETTERGB ( 34,139, 34)},
689 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
690 {"olive drab" , PALETTERGB (107,142, 35)},
691 {"OliveDrab" , PALETTERGB (107,142, 35)},
692 {"dark khaki" , PALETTERGB (189,183,107)},
693 {"DarkKhaki" , PALETTERGB (189,183,107)},
694 {"khaki" , PALETTERGB (240,230,140)},
695 {"pale goldenrod" , PALETTERGB (238,232,170)},
696 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
697 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
698 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
699 {"light yellow" , PALETTERGB (255,255,224)},
700 {"LightYellow" , PALETTERGB (255,255,224)},
701 {"yellow" , PALETTERGB (255,255, 0)},
702 {"gold" , PALETTERGB (255,215, 0)},
703 {"light goldenrod" , PALETTERGB (238,221,130)},
704 {"LightGoldenrod" , PALETTERGB (238,221,130)},
705 {"goldenrod" , PALETTERGB (218,165, 32)},
706 {"dark goldenrod" , PALETTERGB (184,134, 11)},
707 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
708 {"rosy brown" , PALETTERGB (188,143,143)},
709 {"RosyBrown" , PALETTERGB (188,143,143)},
710 {"indian red" , PALETTERGB (205, 92, 92)},
711 {"IndianRed" , PALETTERGB (205, 92, 92)},
712 {"saddle brown" , PALETTERGB (139, 69, 19)},
713 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
714 {"sienna" , PALETTERGB (160, 82, 45)},
715 {"peru" , PALETTERGB (205,133, 63)},
716 {"burlywood" , PALETTERGB (222,184,135)},
717 {"beige" , PALETTERGB (245,245,220)},
718 {"wheat" , PALETTERGB (245,222,179)},
719 {"sandy brown" , PALETTERGB (244,164, 96)},
720 {"SandyBrown" , PALETTERGB (244,164, 96)},
721 {"tan" , PALETTERGB (210,180,140)},
722 {"chocolate" , PALETTERGB (210,105, 30)},
723 {"firebrick" , PALETTERGB (178,34, 34)},
724 {"brown" , PALETTERGB (165,42, 42)},
725 {"dark salmon" , PALETTERGB (233,150,122)},
726 {"DarkSalmon" , PALETTERGB (233,150,122)},
727 {"salmon" , PALETTERGB (250,128,114)},
728 {"light salmon" , PALETTERGB (255,160,122)},
729 {"LightSalmon" , PALETTERGB (255,160,122)},
730 {"orange" , PALETTERGB (255,165, 0)},
731 {"dark orange" , PALETTERGB (255,140, 0)},
732 {"DarkOrange" , PALETTERGB (255,140, 0)},
733 {"coral" , PALETTERGB (255,127, 80)},
734 {"light coral" , PALETTERGB (240,128,128)},
735 {"LightCoral" , PALETTERGB (240,128,128)},
736 {"tomato" , PALETTERGB (255, 99, 71)},
737 {"orange red" , PALETTERGB (255, 69, 0)},
738 {"OrangeRed" , PALETTERGB (255, 69, 0)},
739 {"red" , PALETTERGB (255, 0, 0)},
740 {"hot pink" , PALETTERGB (255,105,180)},
741 {"HotPink" , PALETTERGB (255,105,180)},
742 {"deep pink" , PALETTERGB (255, 20,147)},
743 {"DeepPink" , PALETTERGB (255, 20,147)},
744 {"pink" , PALETTERGB (255,192,203)},
745 {"light pink" , PALETTERGB (255,182,193)},
746 {"LightPink" , PALETTERGB (255,182,193)},
747 {"pale violet red" , PALETTERGB (219,112,147)},
748 {"PaleVioletRed" , PALETTERGB (219,112,147)},
749 {"maroon" , PALETTERGB (176, 48, 96)},
750 {"medium violet red" , PALETTERGB (199, 21,133)},
751 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
752 {"violet red" , PALETTERGB (208, 32,144)},
753 {"VioletRed" , PALETTERGB (208, 32,144)},
754 {"magenta" , PALETTERGB (255, 0,255)},
755 {"violet" , PALETTERGB (238,130,238)},
756 {"plum" , PALETTERGB (221,160,221)},
757 {"orchid" , PALETTERGB (218,112,214)},
758 {"medium orchid" , PALETTERGB (186, 85,211)},
759 {"MediumOrchid" , PALETTERGB (186, 85,211)},
760 {"dark orchid" , PALETTERGB (153, 50,204)},
761 {"DarkOrchid" , PALETTERGB (153, 50,204)},
762 {"dark violet" , PALETTERGB (148, 0,211)},
763 {"DarkViolet" , PALETTERGB (148, 0,211)},
764 {"blue violet" , PALETTERGB (138, 43,226)},
765 {"BlueViolet" , PALETTERGB (138, 43,226)},
766 {"purple" , PALETTERGB (160, 32,240)},
767 {"medium purple" , PALETTERGB (147,112,219)},
768 {"MediumPurple" , PALETTERGB (147,112,219)},
769 {"thistle" , PALETTERGB (216,191,216)},
770 {"gray0" , PALETTERGB ( 0, 0, 0)},
771 {"grey0" , PALETTERGB ( 0, 0, 0)},
772 {"dark grey" , PALETTERGB (169,169,169)},
773 {"DarkGrey" , PALETTERGB (169,169,169)},
774 {"dark gray" , PALETTERGB (169,169,169)},
775 {"DarkGray" , PALETTERGB (169,169,169)},
776 {"dark blue" , PALETTERGB ( 0, 0,139)},
777 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
778 {"dark cyan" , PALETTERGB ( 0,139,139)},
779 {"DarkCyan" , PALETTERGB ( 0,139,139)},
780 {"dark magenta" , PALETTERGB (139, 0,139)},
781 {"DarkMagenta" , PALETTERGB (139, 0,139)},
782 {"dark red" , PALETTERGB (139, 0, 0)},
783 {"DarkRed" , PALETTERGB (139, 0, 0)},
784 {"light green" , PALETTERGB (144,238,144)},
785 {"LightGreen" , PALETTERGB (144,238,144)},
788 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
789 0, 0, 0, doc
: /* Return the default color map. */)
793 colormap_t
*pc
= w32_color_map
;
800 for (i
= 0; i
< sizeof (w32_color_map
) / sizeof (w32_color_map
[0]);
802 cmap
= Fcons (Fcons (build_string (pc
->name
),
803 make_number (pc
->colorref
)),
821 color
= Frassq (rgb
, Vw32_color_map
);
826 return (Fcar (color
));
832 w32_color_map_lookup (colorname
)
835 Lisp_Object tail
, ret
= Qnil
;
839 for (tail
= Vw32_color_map
; !NILP (tail
); tail
= Fcdr (tail
))
841 register Lisp_Object elt
, tem
;
844 if (!CONSP (elt
)) continue;
848 if (lstrcmpi (SDATA (tem
), colorname
) == 0)
865 add_system_logical_colors_to_map (system_colors
)
866 Lisp_Object
*system_colors
;
870 /* Other registry operations are done with input blocked. */
873 /* Look for "Control Panel/Colors" under User and Machine registry
875 if (RegOpenKeyEx (HKEY_CURRENT_USER
, "Control Panel\\Colors", 0,
876 KEY_READ
, &colors_key
) == ERROR_SUCCESS
877 || RegOpenKeyEx (HKEY_LOCAL_MACHINE
, "Control Panel\\Colors", 0,
878 KEY_READ
, &colors_key
) == ERROR_SUCCESS
)
881 char color_buffer
[64];
882 char full_name_buffer
[MAX_PATH
+ SYSTEM_COLOR_PREFIX_LEN
];
884 DWORD name_size
, color_size
;
885 char *name_buffer
= full_name_buffer
+ SYSTEM_COLOR_PREFIX_LEN
;
887 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
888 color_size
= sizeof (color_buffer
);
890 strcpy (full_name_buffer
, SYSTEM_COLOR_PREFIX
);
892 while (RegEnumValueA (colors_key
, index
, name_buffer
, &name_size
,
893 NULL
, NULL
, color_buffer
, &color_size
)
897 if (sscanf (color_buffer
, " %u %u %u", &r
, &g
, &b
) == 3)
898 *system_colors
= Fcons (Fcons (build_string (full_name_buffer
),
899 make_number (RGB (r
, g
, b
))),
902 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
903 color_size
= sizeof (color_buffer
);
906 RegCloseKey (colors_key
);
914 x_to_w32_color (colorname
)
917 register Lisp_Object ret
= Qnil
;
921 if (colorname
[0] == '#')
923 /* Could be an old-style RGB Device specification. */
926 color
= colorname
+ 1;
928 size
= strlen(color
);
929 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
937 for (i
= 0; i
< 3; i
++)
943 /* The check for 'x' in the following conditional takes into
944 account the fact that strtol allows a "0x" in front of
945 our numbers, and we don't. */
946 if (!isxdigit(color
[0]) || color
[1] == 'x')
950 value
= strtoul(color
, &end
, 16);
952 if (errno
== ERANGE
|| end
- color
!= size
)
957 value
= value
* 0x10;
968 colorval
|= (value
<< pos
);
973 XSETINT (ret
, colorval
);
980 else if (strnicmp(colorname
, "rgb:", 4) == 0)
988 color
= colorname
+ 4;
989 for (i
= 0; i
< 3; i
++)
994 /* The check for 'x' in the following conditional takes into
995 account the fact that strtol allows a "0x" in front of
996 our numbers, and we don't. */
997 if (!isxdigit(color
[0]) || color
[1] == 'x')
999 value
= strtoul(color
, &end
, 16);
1000 if (errno
== ERANGE
)
1002 switch (end
- color
)
1005 value
= value
* 0x10 + value
;
1018 if (value
== ULONG_MAX
)
1020 colorval
|= (value
<< pos
);
1027 XSETINT (ret
, colorval
);
1035 else if (strnicmp(colorname
, "rgbi:", 5) == 0)
1037 /* This is an RGB Intensity specification. */
1044 color
= colorname
+ 5;
1045 for (i
= 0; i
< 3; i
++)
1051 value
= strtod(color
, &end
);
1052 if (errno
== ERANGE
)
1054 if (value
< 0.0 || value
> 1.0)
1056 val
= (UINT
)(0x100 * value
);
1057 /* We used 0x100 instead of 0xFF to give a continuous
1058 range between 0.0 and 1.0 inclusive. The next statement
1059 fixes the 1.0 case. */
1062 colorval
|= (val
<< pos
);
1069 XSETINT (ret
, colorval
);
1077 /* I am not going to attempt to handle any of the CIE color schemes
1078 or TekHVC, since I don't know the algorithms for conversion to
1081 /* If we fail to lookup the color name in w32_color_map, then check the
1082 colorname to see if it can be crudely approximated: If the X color
1083 ends in a number (e.g., "darkseagreen2"), strip the number and
1084 return the result of looking up the base color name. */
1085 ret
= w32_color_map_lookup (colorname
);
1088 int len
= strlen (colorname
);
1090 if (isdigit (colorname
[len
- 1]))
1092 char *ptr
, *approx
= alloca (len
+ 1);
1094 strcpy (approx
, colorname
);
1095 ptr
= &approx
[len
- 1];
1096 while (ptr
> approx
&& isdigit (*ptr
))
1099 ret
= w32_color_map_lookup (approx
);
1108 w32_regenerate_palette (FRAME_PTR f
)
1110 struct w32_palette_entry
* list
;
1111 LOGPALETTE
* log_palette
;
1112 HPALETTE new_palette
;
1115 /* don't bother trying to create palette if not supported */
1116 if (! FRAME_W32_DISPLAY_INFO (f
)->has_palette
)
1119 log_palette
= (LOGPALETTE
*)
1120 alloca (sizeof (LOGPALETTE
) +
1121 FRAME_W32_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
1122 log_palette
->palVersion
= 0x300;
1123 log_palette
->palNumEntries
= FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1125 list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1127 i
< FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1128 i
++, list
= list
->next
)
1129 log_palette
->palPalEntry
[i
] = list
->entry
;
1131 new_palette
= CreatePalette (log_palette
);
1135 if (FRAME_W32_DISPLAY_INFO (f
)->palette
)
1136 DeleteObject (FRAME_W32_DISPLAY_INFO (f
)->palette
);
1137 FRAME_W32_DISPLAY_INFO (f
)->palette
= new_palette
;
1139 /* Realize display palette and garbage all frames. */
1140 release_frame_dc (f
, get_frame_dc (f
));
1145 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
1146 #define SET_W32_COLOR(pe, color) \
1149 pe.peRed = GetRValue (color); \
1150 pe.peGreen = GetGValue (color); \
1151 pe.peBlue = GetBValue (color); \
1156 /* Keep these around in case we ever want to track color usage. */
1158 w32_map_color (FRAME_PTR f
, COLORREF color
)
1160 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1162 if (NILP (Vw32_enable_palette
))
1165 /* check if color is already mapped */
1168 if (W32_COLOR (list
->entry
) == color
)
1176 /* not already mapped, so add to list and recreate Windows palette */
1177 list
= (struct w32_palette_entry
*)
1178 xmalloc (sizeof (struct w32_palette_entry
));
1179 SET_W32_COLOR (list
->entry
, color
);
1181 list
->next
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1182 FRAME_W32_DISPLAY_INFO (f
)->color_list
= list
;
1183 FRAME_W32_DISPLAY_INFO (f
)->num_colors
++;
1185 /* set flag that palette must be regenerated */
1186 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1190 w32_unmap_color (FRAME_PTR f
, COLORREF color
)
1192 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1193 struct w32_palette_entry
**prev
= &FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1195 if (NILP (Vw32_enable_palette
))
1198 /* check if color is already mapped */
1201 if (W32_COLOR (list
->entry
) == color
)
1203 if (--list
->refcount
== 0)
1207 FRAME_W32_DISPLAY_INFO (f
)->num_colors
--;
1217 /* set flag that palette must be regenerated */
1218 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1223 /* Gamma-correct COLOR on frame F. */
1226 gamma_correct (f
, color
)
1232 *color
= PALETTERGB (
1233 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1234 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1235 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1240 /* Decide if color named COLOR is valid for the display associated with
1241 the selected frame; if so, return the rgb values in COLOR_DEF.
1242 If ALLOC is nonzero, allocate a new colormap cell. */
1245 w32_defined_color (f
, color
, color_def
, alloc
)
1251 register Lisp_Object tem
;
1252 COLORREF w32_color_ref
;
1254 tem
= x_to_w32_color (color
);
1260 /* Apply gamma correction. */
1261 w32_color_ref
= XUINT (tem
);
1262 gamma_correct (f
, &w32_color_ref
);
1263 XSETINT (tem
, w32_color_ref
);
1266 /* Map this color to the palette if it is enabled. */
1267 if (!NILP (Vw32_enable_palette
))
1269 struct w32_palette_entry
* entry
=
1270 one_w32_display_info
.color_list
;
1271 struct w32_palette_entry
** prev
=
1272 &one_w32_display_info
.color_list
;
1274 /* check if color is already mapped */
1277 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1279 prev
= &entry
->next
;
1280 entry
= entry
->next
;
1283 if (entry
== NULL
&& alloc
)
1285 /* not already mapped, so add to list */
1286 entry
= (struct w32_palette_entry
*)
1287 xmalloc (sizeof (struct w32_palette_entry
));
1288 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1291 one_w32_display_info
.num_colors
++;
1293 /* set flag that palette must be regenerated */
1294 one_w32_display_info
.regen_palette
= TRUE
;
1297 /* Ensure COLORREF value is snapped to nearest color in (default)
1298 palette by simulating the PALETTERGB macro. This works whether
1299 or not the display device has a palette. */
1300 w32_color_ref
= XUINT (tem
) | 0x2000000;
1302 color_def
->pixel
= w32_color_ref
;
1303 color_def
->red
= GetRValue (w32_color_ref
) * 256;
1304 color_def
->green
= GetGValue (w32_color_ref
) * 256;
1305 color_def
->blue
= GetBValue (w32_color_ref
) * 256;
1315 /* Given a string ARG naming a color, compute a pixel value from it
1316 suitable for screen F.
1317 If F is not a color screen, return DEF (default) regardless of what
1321 x_decode_color (f
, arg
, def
)
1330 if (strcmp (SDATA (arg
), "black") == 0)
1331 return BLACK_PIX_DEFAULT (f
);
1332 else if (strcmp (SDATA (arg
), "white") == 0)
1333 return WHITE_PIX_DEFAULT (f
);
1335 if ((FRAME_W32_DISPLAY_INFO (f
)->n_planes
* FRAME_W32_DISPLAY_INFO (f
)->n_cbits
) == 1)
1338 /* w32_defined_color is responsible for coping with failures
1339 by looking for a near-miss. */
1340 if (w32_defined_color (f
, SDATA (arg
), &cdef
, 1))
1343 /* defined_color failed; return an ultimate default. */
1349 /* Functions called only from `x_set_frame_param'
1350 to set individual parameters.
1352 If FRAME_W32_WINDOW (f) is 0,
1353 the frame is being created and its window does not exist yet.
1354 In that case, just record the parameter's new value
1355 in the standard place; do not attempt to change the window. */
1358 x_set_foreground_color (f
, arg
, oldval
)
1360 Lisp_Object arg
, oldval
;
1362 struct w32_output
*x
= f
->output_data
.w32
;
1363 PIX_TYPE fg
, old_fg
;
1365 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1366 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
1367 FRAME_FOREGROUND_PIXEL (f
) = fg
;
1369 if (FRAME_W32_WINDOW (f
) != 0)
1371 if (x
->cursor_pixel
== old_fg
)
1372 x
->cursor_pixel
= fg
;
1374 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
1375 if (FRAME_VISIBLE_P (f
))
1381 x_set_background_color (f
, arg
, oldval
)
1383 Lisp_Object arg
, oldval
;
1385 FRAME_BACKGROUND_PIXEL (f
)
1386 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
1388 if (FRAME_W32_WINDOW (f
) != 0)
1390 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
1391 FRAME_BACKGROUND_PIXEL (f
));
1393 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
1395 if (FRAME_VISIBLE_P (f
))
1401 x_set_mouse_color (f
, arg
, oldval
)
1403 Lisp_Object arg
, oldval
;
1405 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
1409 if (!EQ (Qnil
, arg
))
1410 f
->output_data
.w32
->mouse_pixel
1411 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1412 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
1414 /* Don't let pointers be invisible. */
1415 if (mask_color
== f
->output_data
.w32
->mouse_pixel
1416 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
1417 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
1419 #if 0 /* TODO : cursor changes */
1422 /* It's not okay to crash if the user selects a screwy cursor. */
1423 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
1425 if (!EQ (Qnil
, Vx_pointer_shape
))
1427 CHECK_NUMBER (Vx_pointer_shape
);
1428 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
1431 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1432 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
1434 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
1436 CHECK_NUMBER (Vx_nontext_pointer_shape
);
1437 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1438 XINT (Vx_nontext_pointer_shape
));
1441 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
1442 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1444 if (!EQ (Qnil
, Vx_hourglass_pointer_shape
))
1446 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
1447 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1448 XINT (Vx_hourglass_pointer_shape
));
1451 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
1452 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
1454 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1455 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
1457 CHECK_NUMBER (Vx_mode_pointer_shape
);
1458 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1459 XINT (Vx_mode_pointer_shape
));
1462 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1463 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
1465 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
1467 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
1469 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1470 XINT (Vx_sensitive_text_pointer_shape
));
1473 hand_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
1475 if (!NILP (Vx_window_horizontal_drag_shape
))
1477 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
1478 horizontal_drag_cursor
1479 = XCreateFontCursor (FRAME_X_DISPLAY (f
),
1480 XINT (Vx_window_horizontal_drag_shape
));
1483 horizontal_drag_cursor
1484 = XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_sb_h_double_arrow
);
1486 /* Check and report errors with the above calls. */
1487 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
1488 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
1491 XColor fore_color
, back_color
;
1493 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
1494 back_color
.pixel
= mask_color
;
1495 XQueryColor (FRAME_W32_DISPLAY (f
),
1496 DefaultColormap (FRAME_W32_DISPLAY (f
),
1497 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1499 XQueryColor (FRAME_W32_DISPLAY (f
),
1500 DefaultColormap (FRAME_W32_DISPLAY (f
),
1501 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1503 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
1504 &fore_color
, &back_color
);
1505 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
1506 &fore_color
, &back_color
);
1507 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
1508 &fore_color
, &back_color
);
1509 XRecolorCursor (FRAME_W32_DISPLAY (f
), hand_cursor
,
1510 &fore_color
, &back_color
);
1511 XRecolorCursor (FRAME_W32_DISPLAY (f
), hourglass_cursor
,
1512 &fore_color
, &back_color
);
1515 if (FRAME_W32_WINDOW (f
) != 0)
1516 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
1518 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
1519 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
1520 f
->output_data
.w32
->text_cursor
= cursor
;
1522 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
1523 && f
->output_data
.w32
->nontext_cursor
!= 0)
1524 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
1525 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
1527 if (hourglass_cursor
!= f
->output_data
.w32
->hourglass_cursor
1528 && f
->output_data
.w32
->hourglass_cursor
!= 0)
1529 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hourglass_cursor
);
1530 f
->output_data
.w32
->hourglass_cursor
= hourglass_cursor
;
1532 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
1533 && f
->output_data
.w32
->modeline_cursor
!= 0)
1534 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
1535 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
1537 if (hand_cursor
!= f
->output_data
.w32
->hand_cursor
1538 && f
->output_data
.w32
->hand_cursor
!= 0)
1539 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hand_cursor
);
1540 f
->output_data
.w32
->hand_cursor
= hand_cursor
;
1542 XFlush (FRAME_W32_DISPLAY (f
));
1545 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1549 /* Defined in w32term.c. */
1551 x_set_cursor_color (f
, arg
, oldval
)
1553 Lisp_Object arg
, oldval
;
1555 unsigned long fore_pixel
, pixel
;
1557 if (!NILP (Vx_cursor_fore_pixel
))
1558 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1559 WHITE_PIX_DEFAULT (f
));
1561 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1563 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1565 /* Make sure that the cursor color differs from the background color. */
1566 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
1568 pixel
= f
->output_data
.w32
->mouse_pixel
;
1569 if (pixel
== fore_pixel
)
1570 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1573 f
->output_data
.w32
->cursor_foreground_pixel
= fore_pixel
;
1574 f
->output_data
.w32
->cursor_pixel
= pixel
;
1576 if (FRAME_W32_WINDOW (f
) != 0)
1579 /* Update frame's cursor_gc. */
1580 f
->output_data
.w32
->cursor_gc
->foreground
= fore_pixel
;
1581 f
->output_data
.w32
->cursor_gc
->background
= pixel
;
1585 if (FRAME_VISIBLE_P (f
))
1587 x_update_cursor (f
, 0);
1588 x_update_cursor (f
, 1);
1592 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1595 /* Set the border-color of frame F to pixel value PIX.
1596 Note that this does not fully take effect if done before
1600 x_set_border_pixel (f
, pix
)
1605 f
->output_data
.w32
->border_pixel
= pix
;
1607 if (FRAME_W32_WINDOW (f
) != 0 && f
->border_width
> 0)
1609 if (FRAME_VISIBLE_P (f
))
1614 /* Set the border-color of frame F to value described by ARG.
1615 ARG can be a string naming a color.
1616 The border-color is used for the border that is drawn by the server.
1617 Note that this does not fully take effect if done before
1618 F has a window; it must be redone when the window is created. */
1621 x_set_border_color (f
, arg
, oldval
)
1623 Lisp_Object arg
, oldval
;
1628 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1629 x_set_border_pixel (f
, pix
);
1630 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1635 x_set_cursor_type (f
, arg
, oldval
)
1637 Lisp_Object arg
, oldval
;
1639 set_frame_cursor_types (f
, arg
);
1641 /* Make sure the cursor gets redrawn. */
1642 cursor_type_changed
= 1;
1646 x_set_icon_type (f
, arg
, oldval
)
1648 Lisp_Object arg
, oldval
;
1652 if (NILP (arg
) && NILP (oldval
))
1655 if (STRINGP (arg
) && STRINGP (oldval
)
1656 && EQ (Fstring_equal (oldval
, arg
), Qt
))
1659 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
1664 result
= x_bitmap_icon (f
, arg
);
1668 error ("No icon window available");
1675 x_set_icon_name (f
, arg
, oldval
)
1677 Lisp_Object arg
, oldval
;
1681 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1684 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
1690 if (f
->output_data
.w32
->icon_bitmap
!= 0)
1695 result
= x_text_icon (f
,
1696 (char *) SDATA ((!NILP (f
->icon_name
)
1705 error ("No icon window available");
1708 /* If the window was unmapped (and its icon was mapped),
1709 the new icon is not mapped, so map the window in its stead. */
1710 if (FRAME_VISIBLE_P (f
))
1712 #ifdef USE_X_TOOLKIT
1713 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
1715 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
1718 XFlush (FRAME_W32_DISPLAY (f
));
1725 x_set_menu_bar_lines (f
, value
, oldval
)
1727 Lisp_Object value
, oldval
;
1730 int olines
= FRAME_MENU_BAR_LINES (f
);
1732 /* Right now, menu bars don't work properly in minibuf-only frames;
1733 most of the commands try to apply themselves to the minibuffer
1734 frame itself, and get an error because you can't switch buffers
1735 in or split the minibuffer window. */
1736 if (FRAME_MINIBUF_ONLY_P (f
))
1739 if (INTEGERP (value
))
1740 nlines
= XINT (value
);
1744 FRAME_MENU_BAR_LINES (f
) = 0;
1746 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1749 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1750 free_frame_menubar (f
);
1751 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1753 /* Adjust the frame size so that the client (text) dimensions
1754 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
1756 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
1757 do_pending_window_change (0);
1763 /* Set the number of lines used for the tool bar of frame F to VALUE.
1764 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1765 is the old number of tool bar lines. This function changes the
1766 height of all windows on frame F to match the new tool bar height.
1767 The frame's height doesn't change. */
1770 x_set_tool_bar_lines (f
, value
, oldval
)
1772 Lisp_Object value
, oldval
;
1774 int delta
, nlines
, root_height
;
1775 Lisp_Object root_window
;
1777 /* Treat tool bars like menu bars. */
1778 if (FRAME_MINIBUF_ONLY_P (f
))
1781 /* Use VALUE only if an integer >= 0. */
1782 if (INTEGERP (value
) && XINT (value
) >= 0)
1783 nlines
= XFASTINT (value
);
1787 /* Make sure we redisplay all windows in this frame. */
1788 ++windows_or_buffers_changed
;
1790 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
1792 /* Don't resize the tool-bar to more than we have room for. */
1793 root_window
= FRAME_ROOT_WINDOW (f
);
1794 root_height
= WINDOW_TOTAL_LINES (XWINDOW (root_window
));
1795 if (root_height
- delta
< 1)
1797 delta
= root_height
- 1;
1798 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
1801 FRAME_TOOL_BAR_LINES (f
) = nlines
;
1802 change_window_heights (root_window
, delta
);
1805 /* We also have to make sure that the internal border at the top of
1806 the frame, below the menu bar or tool bar, is redrawn when the
1807 tool bar disappears. This is so because the internal border is
1808 below the tool bar if one is displayed, but is below the menu bar
1809 if there isn't a tool bar. The tool bar draws into the area
1810 below the menu bar. */
1811 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
1815 clear_current_matrices (f
);
1816 updating_frame
= NULL
;
1819 /* If the tool bar gets smaller, the internal border below it
1820 has to be cleared. It was formerly part of the display
1821 of the larger tool bar, and updating windows won't clear it. */
1824 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1825 int width
= FRAME_PIXEL_WIDTH (f
);
1826 int y
= nlines
* FRAME_LINE_HEIGHT (f
);
1830 HDC hdc
= get_frame_dc (f
);
1831 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
1832 release_frame_dc (f
, hdc
);
1836 if (WINDOWP (f
->tool_bar_window
))
1837 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1842 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1845 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1846 name; if NAME is a string, set F's name to NAME and set
1847 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1849 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1850 suggesting a new name, which lisp code should override; if
1851 F->explicit_name is set, ignore the new name; otherwise, set it. */
1854 x_set_name (f
, name
, explicit)
1859 /* Make sure that requests from lisp code override requests from
1860 Emacs redisplay code. */
1863 /* If we're switching from explicit to implicit, we had better
1864 update the mode lines and thereby update the title. */
1865 if (f
->explicit_name
&& NILP (name
))
1866 update_mode_lines
= 1;
1868 f
->explicit_name
= ! NILP (name
);
1870 else if (f
->explicit_name
)
1873 /* If NAME is nil, set the name to the w32_id_name. */
1876 /* Check for no change needed in this very common case
1877 before we do any consing. */
1878 if (!strcmp (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
,
1881 name
= build_string (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
);
1884 CHECK_STRING (name
);
1886 /* Don't change the name if it's already NAME. */
1887 if (! NILP (Fstring_equal (name
, f
->name
)))
1892 /* For setting the frame title, the title parameter should override
1893 the name parameter. */
1894 if (! NILP (f
->title
))
1897 if (FRAME_W32_WINDOW (f
))
1899 if (STRING_MULTIBYTE (name
))
1900 name
= ENCODE_SYSTEM (name
);
1903 SetWindowText(FRAME_W32_WINDOW (f
), SDATA (name
));
1908 /* This function should be called when the user's lisp code has
1909 specified a name for the frame; the name will override any set by the
1912 x_explicitly_set_name (f
, arg
, oldval
)
1914 Lisp_Object arg
, oldval
;
1916 x_set_name (f
, arg
, 1);
1919 /* This function should be called by Emacs redisplay code to set the
1920 name; names set this way will never override names set by the user's
1923 x_implicitly_set_name (f
, arg
, oldval
)
1925 Lisp_Object arg
, oldval
;
1927 x_set_name (f
, arg
, 0);
1930 /* Change the title of frame F to NAME.
1931 If NAME is nil, use the frame name as the title.
1933 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1934 name; if NAME is a string, set F's name to NAME and set
1935 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1937 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1938 suggesting a new name, which lisp code should override; if
1939 F->explicit_name is set, ignore the new name; otherwise, set it. */
1942 x_set_title (f
, name
, old_name
)
1944 Lisp_Object name
, old_name
;
1946 /* Don't change the title if it's already NAME. */
1947 if (EQ (name
, f
->title
))
1950 update_mode_lines
= 1;
1957 if (FRAME_W32_WINDOW (f
))
1959 if (STRING_MULTIBYTE (name
))
1960 name
= ENCODE_SYSTEM (name
);
1963 SetWindowText(FRAME_W32_WINDOW (f
), SDATA (name
));
1969 void x_set_scroll_bar_default_width (f
)
1972 int wid
= FRAME_COLUMN_WIDTH (f
);
1974 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
1975 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) +
1980 /* Subroutines of creating a frame. */
1983 /* Return the value of parameter PARAM.
1985 First search ALIST, then Vdefault_frame_alist, then the X defaults
1986 database, using ATTRIBUTE as the attribute name and CLASS as its class.
1988 Convert the resource to the type specified by desired_type.
1990 If no default is specified, return Qunbound. If you call
1991 w32_get_arg, make sure you deal with Qunbound in a reasonable way,
1992 and don't let it get stored in any Lisp-visible variables! */
1995 w32_get_arg (alist
, param
, attribute
, class, type
)
1996 Lisp_Object alist
, param
;
1999 enum resource_types type
;
2001 return x_get_arg (check_x_display_info (Qnil
),
2002 alist
, param
, attribute
, class, type
);
2007 w32_load_cursor (LPCTSTR name
)
2009 /* Try first to load cursor from application resource. */
2010 Cursor cursor
= LoadImage ((HINSTANCE
) GetModuleHandle(NULL
),
2011 name
, IMAGE_CURSOR
, 0, 0,
2012 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
2015 /* Then try to load a shared predefined cursor. */
2016 cursor
= LoadImage (NULL
, name
, IMAGE_CURSOR
, 0, 0,
2017 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
2022 extern LRESULT CALLBACK
w32_wnd_proc ();
2025 w32_init_class (hinst
)
2030 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
2031 wc
.lpfnWndProc
= (WNDPROC
) w32_wnd_proc
;
2033 wc
.cbWndExtra
= WND_EXTRA_BYTES
;
2034 wc
.hInstance
= hinst
;
2035 wc
.hIcon
= LoadIcon (hinst
, EMACS_CLASS
);
2036 wc
.hCursor
= w32_load_cursor (IDC_ARROW
);
2037 wc
.hbrBackground
= NULL
; /* GetStockObject (WHITE_BRUSH); */
2038 wc
.lpszMenuName
= NULL
;
2039 wc
.lpszClassName
= EMACS_CLASS
;
2041 return (RegisterClass (&wc
));
2045 w32_createscrollbar (f
, bar
)
2047 struct scroll_bar
* bar
;
2049 return (CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
2050 /* Position and size of scroll bar. */
2051 XINT(bar
->left
) + VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
2053 XINT(bar
->width
) - VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
2055 FRAME_W32_WINDOW (f
),
2062 w32_createwindow (f
)
2068 rect
.left
= rect
.top
= 0;
2069 rect
.right
= FRAME_PIXEL_WIDTH (f
);
2070 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
2072 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
2073 FRAME_EXTERNAL_MENU_BAR (f
));
2075 /* Do first time app init */
2079 w32_init_class (hinst
);
2082 FRAME_W32_WINDOW (f
) = hwnd
2083 = CreateWindow (EMACS_CLASS
,
2085 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
2088 rect
.right
- rect
.left
,
2089 rect
.bottom
- rect
.top
,
2097 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
2098 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
2099 SetWindowLong (hwnd
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
2100 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->scroll_bar_actual_width
);
2101 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
2103 /* Enable drag-n-drop. */
2104 DragAcceptFiles (hwnd
, TRUE
);
2106 /* Do this to discard the default setting specified by our parent. */
2107 ShowWindow (hwnd
, SW_HIDE
);
2112 my_post_msg (wmsg
, hwnd
, msg
, wParam
, lParam
)
2119 wmsg
->msg
.hwnd
= hwnd
;
2120 wmsg
->msg
.message
= msg
;
2121 wmsg
->msg
.wParam
= wParam
;
2122 wmsg
->msg
.lParam
= lParam
;
2123 wmsg
->msg
.time
= GetMessageTime ();
2128 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
2129 between left and right keys as advertised. We test for this
2130 support dynamically, and set a flag when the support is absent. If
2131 absent, we keep track of the left and right control and alt keys
2132 ourselves. This is particularly necessary on keyboards that rely
2133 upon the AltGr key, which is represented as having the left control
2134 and right alt keys pressed. For these keyboards, we need to know
2135 when the left alt key has been pressed in addition to the AltGr key
2136 so that we can properly support M-AltGr-key sequences (such as M-@
2137 on Swedish keyboards). */
2139 #define EMACS_LCONTROL 0
2140 #define EMACS_RCONTROL 1
2141 #define EMACS_LMENU 2
2142 #define EMACS_RMENU 3
2144 static int modifiers
[4];
2145 static int modifiers_recorded
;
2146 static int modifier_key_support_tested
;
2149 test_modifier_support (unsigned int wparam
)
2153 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
2155 if (wparam
== VK_CONTROL
)
2165 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
2166 modifiers_recorded
= 1;
2168 modifiers_recorded
= 0;
2169 modifier_key_support_tested
= 1;
2173 record_keydown (unsigned int wparam
, unsigned int lparam
)
2177 if (!modifier_key_support_tested
)
2178 test_modifier_support (wparam
);
2180 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2183 if (wparam
== VK_CONTROL
)
2184 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2186 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2192 record_keyup (unsigned int wparam
, unsigned int lparam
)
2196 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2199 if (wparam
== VK_CONTROL
)
2200 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2202 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2207 /* Emacs can lose focus while a modifier key has been pressed. When
2208 it regains focus, be conservative and clear all modifiers since
2209 we cannot reconstruct the left and right modifier state. */
2215 if (GetFocus () == NULL
)
2216 /* Emacs doesn't have keyboard focus. Do nothing. */
2219 ctrl
= GetAsyncKeyState (VK_CONTROL
);
2220 alt
= GetAsyncKeyState (VK_MENU
);
2222 if (!(ctrl
& 0x08000))
2223 /* Clear any recorded control modifier state. */
2224 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2226 if (!(alt
& 0x08000))
2227 /* Clear any recorded alt modifier state. */
2228 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2230 /* Update the state of all modifier keys, because modifiers used in
2231 hot-key combinations can get stuck on if Emacs loses focus as a
2232 result of a hot-key being pressed. */
2236 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
2238 GetKeyboardState (keystate
);
2239 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
2240 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
2241 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
2242 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
2243 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
2244 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
2245 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
2246 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
2247 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
2248 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
2249 SetKeyboardState (keystate
);
2253 /* Synchronize modifier state with what is reported with the current
2254 keystroke. Even if we cannot distinguish between left and right
2255 modifier keys, we know that, if no modifiers are set, then neither
2256 the left or right modifier should be set. */
2260 if (!modifiers_recorded
)
2263 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
2264 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2266 if (!(GetKeyState (VK_MENU
) & 0x8000))
2267 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2271 modifier_set (int vkey
)
2273 if (vkey
== VK_CAPITAL
|| vkey
== VK_SCROLL
)
2274 return (GetKeyState (vkey
) & 0x1);
2275 if (!modifiers_recorded
)
2276 return (GetKeyState (vkey
) & 0x8000);
2281 return modifiers
[EMACS_LCONTROL
];
2283 return modifiers
[EMACS_RCONTROL
];
2285 return modifiers
[EMACS_LMENU
];
2287 return modifiers
[EMACS_RMENU
];
2289 return (GetKeyState (vkey
) & 0x8000);
2292 /* Convert between the modifier bits W32 uses and the modifier bits
2296 w32_key_to_modifier (int key
)
2298 Lisp_Object key_mapping
;
2303 key_mapping
= Vw32_lwindow_modifier
;
2306 key_mapping
= Vw32_rwindow_modifier
;
2309 key_mapping
= Vw32_apps_modifier
;
2312 key_mapping
= Vw32_scroll_lock_modifier
;
2318 /* NB. This code runs in the input thread, asychronously to the lisp
2319 thread, so we must be careful to ensure access to lisp data is
2320 thread-safe. The following code is safe because the modifier
2321 variable values are updated atomically from lisp and symbols are
2322 not relocated by GC. Also, we don't have to worry about seeing GC
2324 if (EQ (key_mapping
, Qhyper
))
2325 return hyper_modifier
;
2326 if (EQ (key_mapping
, Qsuper
))
2327 return super_modifier
;
2328 if (EQ (key_mapping
, Qmeta
))
2329 return meta_modifier
;
2330 if (EQ (key_mapping
, Qalt
))
2331 return alt_modifier
;
2332 if (EQ (key_mapping
, Qctrl
))
2333 return ctrl_modifier
;
2334 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
2335 return ctrl_modifier
;
2336 if (EQ (key_mapping
, Qshift
))
2337 return shift_modifier
;
2339 /* Don't generate any modifier if not explicitly requested. */
2344 w32_get_modifiers ()
2346 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
2347 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
2348 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
2349 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
2350 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
2351 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
2352 (modifier_set (VK_MENU
) ?
2353 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
2356 /* We map the VK_* modifiers into console modifier constants
2357 so that we can use the same routines to handle both console
2358 and window input. */
2361 construct_console_modifiers ()
2366 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
2367 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
2368 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
2369 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
2370 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
2371 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
2372 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
2373 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
2374 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
2375 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
2376 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
2382 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
2386 /* Convert to emacs modifiers. */
2387 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
2393 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
2395 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
2398 if (virt_key
== VK_RETURN
)
2399 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
2401 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
2402 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
2404 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
2405 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
2407 if (virt_key
== VK_CLEAR
)
2408 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
2413 /* List of special key combinations which w32 would normally capture,
2414 but emacs should grab instead. Not directly visible to lisp, to
2415 simplify synchronization. Each item is an integer encoding a virtual
2416 key code and modifier combination to capture. */
2417 Lisp_Object w32_grabbed_keys
;
2419 #define HOTKEY(vk,mods) make_number (((vk) & 255) | ((mods) << 8))
2420 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
2421 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
2422 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
2424 #define RAW_HOTKEY_ID(k) ((k) & 0xbfff)
2425 #define RAW_HOTKEY_VK_CODE(k) ((k) & 255)
2426 #define RAW_HOTKEY_MODIFIERS(k) ((k) >> 8)
2428 /* Register hot-keys for reserved key combinations when Emacs has
2429 keyboard focus, since this is the only way Emacs can receive key
2430 combinations like Alt-Tab which are used by the system. */
2433 register_hot_keys (hwnd
)
2436 Lisp_Object keylist
;
2438 /* Use GC_CONSP, since we are called asynchronously. */
2439 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
2441 Lisp_Object key
= XCAR (keylist
);
2443 /* Deleted entries get set to nil. */
2444 if (!INTEGERP (key
))
2447 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
2448 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
2453 unregister_hot_keys (hwnd
)
2456 Lisp_Object keylist
;
2458 /* Use GC_CONSP, since we are called asynchronously. */
2459 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
2461 Lisp_Object key
= XCAR (keylist
);
2463 if (!INTEGERP (key
))
2466 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
2470 /* Main message dispatch loop. */
2473 w32_msg_pump (deferred_msg
* msg_buf
)
2479 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
2481 while (GetMessage (&msg
, NULL
, 0, 0))
2483 if (msg
.hwnd
== NULL
)
2485 switch (msg
.message
)
2488 /* Produced by complete_deferred_msg; just ignore. */
2490 case WM_EMACS_CREATEWINDOW
:
2491 w32_createwindow ((struct frame
*) msg
.wParam
);
2492 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2495 case WM_EMACS_SETLOCALE
:
2496 SetThreadLocale (msg
.wParam
);
2497 /* Reply is not expected. */
2499 case WM_EMACS_SETKEYBOARDLAYOUT
:
2500 result
= (int) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
2501 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2505 case WM_EMACS_REGISTER_HOT_KEY
:
2506 focus_window
= GetFocus ();
2507 if (focus_window
!= NULL
)
2508 RegisterHotKey (focus_window
,
2509 RAW_HOTKEY_ID (msg
.wParam
),
2510 RAW_HOTKEY_MODIFIERS (msg
.wParam
),
2511 RAW_HOTKEY_VK_CODE (msg
.wParam
));
2512 /* Reply is not expected. */
2514 case WM_EMACS_UNREGISTER_HOT_KEY
:
2515 focus_window
= GetFocus ();
2516 if (focus_window
!= NULL
)
2517 UnregisterHotKey (focus_window
, RAW_HOTKEY_ID (msg
.wParam
));
2518 /* Mark item as erased. NB: this code must be
2519 thread-safe. The next line is okay because the cons
2520 cell is never made into garbage and is not relocated by
2522 XSETCAR ((Lisp_Object
) ((EMACS_INT
) msg
.lParam
), Qnil
);
2523 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2526 case WM_EMACS_TOGGLE_LOCK_KEY
:
2528 int vk_code
= (int) msg
.wParam
;
2529 int cur_state
= (GetKeyState (vk_code
) & 1);
2530 Lisp_Object new_state
= (Lisp_Object
) ((EMACS_INT
) msg
.lParam
);
2532 /* NB: This code must be thread-safe. It is safe to
2533 call NILP because symbols are not relocated by GC,
2534 and pointer here is not touched by GC (so the markbit
2535 can't be set). Numbers are safe because they are
2536 immediate values. */
2537 if (NILP (new_state
)
2538 || (NUMBERP (new_state
)
2539 && ((XUINT (new_state
)) & 1) != cur_state
))
2541 one_w32_display_info
.faked_key
= vk_code
;
2543 keybd_event ((BYTE
) vk_code
,
2544 (BYTE
) MapVirtualKey (vk_code
, 0),
2545 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2546 keybd_event ((BYTE
) vk_code
,
2547 (BYTE
) MapVirtualKey (vk_code
, 0),
2548 KEYEVENTF_EXTENDEDKEY
| 0, 0);
2549 keybd_event ((BYTE
) vk_code
,
2550 (BYTE
) MapVirtualKey (vk_code
, 0),
2551 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2552 cur_state
= !cur_state
;
2554 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2560 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
2565 DispatchMessage (&msg
);
2568 /* Exit nested loop when our deferred message has completed. */
2569 if (msg_buf
->completed
)
2574 deferred_msg
* deferred_msg_head
;
2576 static deferred_msg
*
2577 find_deferred_msg (HWND hwnd
, UINT msg
)
2579 deferred_msg
* item
;
2581 /* Don't actually need synchronization for read access, since
2582 modification of single pointer is always atomic. */
2583 /* enter_crit (); */
2585 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2586 if (item
->w32msg
.msg
.hwnd
== hwnd
2587 && item
->w32msg
.msg
.message
== msg
)
2590 /* leave_crit (); */
2596 send_deferred_msg (deferred_msg
* msg_buf
,
2602 /* Only input thread can send deferred messages. */
2603 if (GetCurrentThreadId () != dwWindowsThreadId
)
2606 /* It is an error to send a message that is already deferred. */
2607 if (find_deferred_msg (hwnd
, msg
) != NULL
)
2610 /* Enforced synchronization is not needed because this is the only
2611 function that alters deferred_msg_head, and the following critical
2612 section is guaranteed to only be serially reentered (since only the
2613 input thread can call us). */
2615 /* enter_crit (); */
2617 msg_buf
->completed
= 0;
2618 msg_buf
->next
= deferred_msg_head
;
2619 deferred_msg_head
= msg_buf
;
2620 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
2622 /* leave_crit (); */
2624 /* Start a new nested message loop to process other messages until
2625 this one is completed. */
2626 w32_msg_pump (msg_buf
);
2628 deferred_msg_head
= msg_buf
->next
;
2630 return msg_buf
->result
;
2634 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
2636 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
2638 if (msg_buf
== NULL
)
2639 /* Message may have been cancelled, so don't abort(). */
2642 msg_buf
->result
= result
;
2643 msg_buf
->completed
= 1;
2645 /* Ensure input thread is woken so it notices the completion. */
2646 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2650 cancel_all_deferred_msgs ()
2652 deferred_msg
* item
;
2654 /* Don't actually need synchronization for read access, since
2655 modification of single pointer is always atomic. */
2656 /* enter_crit (); */
2658 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2661 item
->completed
= 1;
2664 /* leave_crit (); */
2666 /* Ensure input thread is woken so it notices the completion. */
2667 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2675 deferred_msg dummy_buf
;
2677 /* Ensure our message queue is created */
2679 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
2681 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2684 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
2685 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
2686 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
2688 /* This is the inital message loop which should only exit when the
2689 application quits. */
2690 w32_msg_pump (&dummy_buf
);
2696 post_character_message (hwnd
, msg
, wParam
, lParam
, modifiers
)
2706 wmsg
.dwModifiers
= modifiers
;
2708 /* Detect quit_char and set quit-flag directly. Note that we
2709 still need to post a message to ensure the main thread will be
2710 woken up if blocked in sys_select(), but we do NOT want to post
2711 the quit_char message itself (because it will usually be as if
2712 the user had typed quit_char twice). Instead, we post a dummy
2713 message that has no particular effect. */
2716 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
2717 c
= make_ctrl_char (c
) & 0377;
2719 || (wmsg
.dwModifiers
== 0 &&
2720 w32_quit_key
&& wParam
== w32_quit_key
))
2724 /* The choice of message is somewhat arbitrary, as long as
2725 the main thread handler just ignores it. */
2728 /* Interrupt any blocking system calls. */
2731 /* As a safety precaution, forcibly complete any deferred
2732 messages. This is a kludge, but I don't see any particularly
2733 clean way to handle the situation where a deferred message is
2734 "dropped" in the lisp thread, and will thus never be
2735 completed, eg. by the user trying to activate the menubar
2736 when the lisp thread is busy, and then typing C-g when the
2737 menubar doesn't open promptly (with the result that the
2738 menubar never responds at all because the deferred
2739 WM_INITMENU message is never completed). Another problem
2740 situation is when the lisp thread calls SendMessage (to send
2741 a window manager command) when a message has been deferred;
2742 the lisp thread gets blocked indefinitely waiting for the
2743 deferred message to be completed, which itself is waiting for
2744 the lisp thread to respond.
2746 Note that we don't want to block the input thread waiting for
2747 a reponse from the lisp thread (although that would at least
2748 solve the deadlock problem above), because we want to be able
2749 to receive C-g to interrupt the lisp thread. */
2750 cancel_all_deferred_msgs ();
2754 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2757 /* Main window procedure */
2760 w32_wnd_proc (hwnd
, msg
, wParam
, lParam
)
2767 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
2769 int windows_translate
;
2772 /* Note that it is okay to call x_window_to_frame, even though we are
2773 not running in the main lisp thread, because frame deletion
2774 requires the lisp thread to synchronize with this thread. Thus, if
2775 a frame struct is returned, it can be used without concern that the
2776 lisp thread might make it disappear while we are using it.
2778 NB. Walking the frame list in this thread is safe (as long as
2779 writes of Lisp_Object slots are atomic, which they are on Windows).
2780 Although delete-frame can destructively modify the frame list while
2781 we are walking it, a garbage collection cannot occur until after
2782 delete-frame has synchronized with this thread.
2784 It is also safe to use functions that make GDI calls, such as
2785 w32_clear_rect, because these functions must obtain a DC handle
2786 from the frame struct using get_frame_dc which is thread-aware. */
2791 f
= x_window_to_frame (dpyinfo
, hwnd
);
2794 HDC hdc
= get_frame_dc (f
);
2795 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
2796 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
2797 release_frame_dc (f
, hdc
);
2799 #if defined (W32_DEBUG_DISPLAY)
2800 DebPrint (("WM_ERASEBKGND (frame %p): erasing %d,%d-%d,%d\n",
2802 wmsg
.rect
.left
, wmsg
.rect
.top
,
2803 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2804 #endif /* W32_DEBUG_DISPLAY */
2807 case WM_PALETTECHANGED
:
2808 /* ignore our own changes */
2809 if ((HWND
)wParam
!= hwnd
)
2811 f
= x_window_to_frame (dpyinfo
, hwnd
);
2813 /* get_frame_dc will realize our palette and force all
2814 frames to be redrawn if needed. */
2815 release_frame_dc (f
, get_frame_dc (f
));
2820 PAINTSTRUCT paintStruct
;
2822 bzero (&update_rect
, sizeof (update_rect
));
2824 f
= x_window_to_frame (dpyinfo
, hwnd
);
2827 DebPrint (("WM_PAINT received for unknown window %p\n", hwnd
));
2831 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
2832 fails. Apparently this can happen under some
2834 if (GetUpdateRect (hwnd
, &update_rect
, FALSE
) || !w32_strict_painting
)
2837 BeginPaint (hwnd
, &paintStruct
);
2839 /* The rectangles returned by GetUpdateRect and BeginPaint
2840 do not always match. Play it safe by assuming both areas
2842 UnionRect (&(wmsg
.rect
), &update_rect
, &(paintStruct
.rcPaint
));
2844 #if defined (W32_DEBUG_DISPLAY)
2845 DebPrint (("WM_PAINT (frame %p): painting %d,%d-%d,%d\n",
2847 wmsg
.rect
.left
, wmsg
.rect
.top
,
2848 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2849 DebPrint ((" [update region is %d,%d-%d,%d]\n",
2850 update_rect
.left
, update_rect
.top
,
2851 update_rect
.right
, update_rect
.bottom
));
2853 EndPaint (hwnd
, &paintStruct
);
2856 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2861 /* If GetUpdateRect returns 0 (meaning there is no update
2862 region), assume the whole window needs to be repainted. */
2863 GetClientRect(hwnd
, &wmsg
.rect
);
2864 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2868 case WM_INPUTLANGCHANGE
:
2869 /* Inform lisp thread of keyboard layout changes. */
2870 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2872 /* Clear dead keys in the keyboard state; for simplicity only
2873 preserve modifier key states. */
2878 GetKeyboardState (keystate
);
2879 for (i
= 0; i
< 256; i
++)
2896 SetKeyboardState (keystate
);
2901 /* Synchronize hot keys with normal input. */
2902 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
2907 record_keyup (wParam
, lParam
);
2912 /* Ignore keystrokes we fake ourself; see below. */
2913 if (dpyinfo
->faked_key
== wParam
)
2915 dpyinfo
->faked_key
= 0;
2916 /* Make sure TranslateMessage sees them though (as long as
2917 they don't produce WM_CHAR messages). This ensures that
2918 indicator lights are toggled promptly on Windows 9x, for
2920 if (lispy_function_keys
[wParam
] != 0)
2922 windows_translate
= 1;
2928 /* Synchronize modifiers with current keystroke. */
2930 record_keydown (wParam
, lParam
);
2931 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
2933 windows_translate
= 0;
2938 if (NILP (Vw32_pass_lwindow_to_system
))
2940 /* Prevent system from acting on keyup (which opens the
2941 Start menu if no other key was pressed) by simulating a
2942 press of Space which we will ignore. */
2943 if (GetAsyncKeyState (wParam
) & 1)
2945 if (NUMBERP (Vw32_phantom_key_code
))
2946 key
= XUINT (Vw32_phantom_key_code
) & 255;
2949 dpyinfo
->faked_key
= key
;
2950 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
2953 if (!NILP (Vw32_lwindow_modifier
))
2957 if (NILP (Vw32_pass_rwindow_to_system
))
2959 if (GetAsyncKeyState (wParam
) & 1)
2961 if (NUMBERP (Vw32_phantom_key_code
))
2962 key
= XUINT (Vw32_phantom_key_code
) & 255;
2965 dpyinfo
->faked_key
= key
;
2966 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
2969 if (!NILP (Vw32_rwindow_modifier
))
2973 if (!NILP (Vw32_apps_modifier
))
2977 if (NILP (Vw32_pass_alt_to_system
))
2978 /* Prevent DefWindowProc from activating the menu bar if an
2979 Alt key is pressed and released by itself. */
2981 windows_translate
= 1;
2984 /* Decide whether to treat as modifier or function key. */
2985 if (NILP (Vw32_enable_caps_lock
))
2986 goto disable_lock_key
;
2987 windows_translate
= 1;
2990 /* Decide whether to treat as modifier or function key. */
2991 if (NILP (Vw32_enable_num_lock
))
2992 goto disable_lock_key
;
2993 windows_translate
= 1;
2996 /* Decide whether to treat as modifier or function key. */
2997 if (NILP (Vw32_scroll_lock_modifier
))
2998 goto disable_lock_key
;
2999 windows_translate
= 1;
3002 /* Ensure the appropriate lock key state (and indicator light)
3003 remains in the same state. We do this by faking another
3004 press of the relevant key. Apparently, this really is the
3005 only way to toggle the state of the indicator lights. */
3006 dpyinfo
->faked_key
= wParam
;
3007 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3008 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3009 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3010 KEYEVENTF_EXTENDEDKEY
| 0, 0);
3011 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3012 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3013 /* Ensure indicator lights are updated promptly on Windows 9x
3014 (TranslateMessage apparently does this), after forwarding
3016 post_character_message (hwnd
, msg
, wParam
, lParam
,
3017 w32_get_key_modifiers (wParam
, lParam
));
3018 windows_translate
= 1;
3022 case VK_PROCESSKEY
: /* Generated by IME. */
3023 windows_translate
= 1;
3026 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
3027 which is confusing for purposes of key binding; convert
3028 VK_CANCEL events into VK_PAUSE events. */
3032 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
3033 for purposes of key binding; convert these back into
3034 VK_NUMLOCK events, at least when we want to see NumLock key
3035 presses. (Note that there is never any possibility that
3036 VK_PAUSE with Ctrl really is C-Pause as per above.) */
3037 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
3038 wParam
= VK_NUMLOCK
;
3041 /* If not defined as a function key, change it to a WM_CHAR message. */
3042 if (lispy_function_keys
[wParam
] == 0)
3044 DWORD modifiers
= construct_console_modifiers ();
3046 if (!NILP (Vw32_recognize_altgr
)
3047 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
3049 /* Always let TranslateMessage handle AltGr key chords;
3050 for some reason, ToAscii doesn't always process AltGr
3051 chords correctly. */
3052 windows_translate
= 1;
3054 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
3056 /* Handle key chords including any modifiers other
3057 than shift directly, in order to preserve as much
3058 modifier information as possible. */
3059 if ('A' <= wParam
&& wParam
<= 'Z')
3061 /* Don't translate modified alphabetic keystrokes,
3062 so the user doesn't need to constantly switch
3063 layout to type control or meta keystrokes when
3064 the normal layout translates alphabetic
3065 characters to non-ascii characters. */
3066 if (!modifier_set (VK_SHIFT
))
3067 wParam
+= ('a' - 'A');
3072 /* Try to handle other keystrokes by determining the
3073 base character (ie. translating the base key plus
3077 KEY_EVENT_RECORD key
;
3079 key
.bKeyDown
= TRUE
;
3080 key
.wRepeatCount
= 1;
3081 key
.wVirtualKeyCode
= wParam
;
3082 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
3083 key
.uChar
.AsciiChar
= 0;
3084 key
.dwControlKeyState
= modifiers
;
3086 add
= w32_kbd_patch_key (&key
);
3087 /* 0 means an unrecognised keycode, negative means
3088 dead key. Ignore both. */
3091 /* Forward asciified character sequence. */
3092 post_character_message
3093 (hwnd
, WM_CHAR
, key
.uChar
.AsciiChar
, lParam
,
3094 w32_get_key_modifiers (wParam
, lParam
));
3095 w32_kbd_patch_key (&key
);
3102 /* Let TranslateMessage handle everything else. */
3103 windows_translate
= 1;
3109 if (windows_translate
)
3111 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
3113 windows_msg
.time
= GetMessageTime ();
3114 TranslateMessage (&windows_msg
);
3122 post_character_message (hwnd
, msg
, wParam
, lParam
,
3123 w32_get_key_modifiers (wParam
, lParam
));
3126 /* Simulate middle mouse button events when left and right buttons
3127 are used together, but only if user has two button mouse. */
3128 case WM_LBUTTONDOWN
:
3129 case WM_RBUTTONDOWN
:
3130 if (w32_num_mouse_buttons
> 2)
3131 goto handle_plain_button
;
3134 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
3135 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
3137 if (button_state
& this)
3140 if (button_state
== 0)
3143 button_state
|= this;
3145 if (button_state
& other
)
3147 if (mouse_button_timer
)
3149 KillTimer (hwnd
, mouse_button_timer
);
3150 mouse_button_timer
= 0;
3152 /* Generate middle mouse event instead. */
3153 msg
= WM_MBUTTONDOWN
;
3154 button_state
|= MMOUSE
;
3156 else if (button_state
& MMOUSE
)
3158 /* Ignore button event if we've already generated a
3159 middle mouse down event. This happens if the
3160 user releases and press one of the two buttons
3161 after we've faked a middle mouse event. */
3166 /* Flush out saved message. */
3167 post_msg (&saved_mouse_button_msg
);
3169 wmsg
.dwModifiers
= w32_get_modifiers ();
3170 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3172 /* Clear message buffer. */
3173 saved_mouse_button_msg
.msg
.hwnd
= 0;
3177 /* Hold onto message for now. */
3178 mouse_button_timer
=
3179 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
3180 w32_mouse_button_tolerance
, NULL
);
3181 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
3182 saved_mouse_button_msg
.msg
.message
= msg
;
3183 saved_mouse_button_msg
.msg
.wParam
= wParam
;
3184 saved_mouse_button_msg
.msg
.lParam
= lParam
;
3185 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
3186 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
3193 if (w32_num_mouse_buttons
> 2)
3194 goto handle_plain_button
;
3197 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
3198 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
3200 if ((button_state
& this) == 0)
3203 button_state
&= ~this;
3205 if (button_state
& MMOUSE
)
3207 /* Only generate event when second button is released. */
3208 if ((button_state
& other
) == 0)
3211 button_state
&= ~MMOUSE
;
3213 if (button_state
) abort ();
3220 /* Flush out saved message if necessary. */
3221 if (saved_mouse_button_msg
.msg
.hwnd
)
3223 post_msg (&saved_mouse_button_msg
);
3226 wmsg
.dwModifiers
= w32_get_modifiers ();
3227 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3229 /* Always clear message buffer and cancel timer. */
3230 saved_mouse_button_msg
.msg
.hwnd
= 0;
3231 KillTimer (hwnd
, mouse_button_timer
);
3232 mouse_button_timer
= 0;
3234 if (button_state
== 0)
3239 case WM_XBUTTONDOWN
:
3241 if (w32_pass_extra_mouse_buttons_to_system
)
3243 /* else fall through and process them. */
3244 case WM_MBUTTONDOWN
:
3246 handle_plain_button
:
3251 if (parse_button (msg
, HIWORD (wParam
), &button
, &up
))
3253 if (up
) ReleaseCapture ();
3254 else SetCapture (hwnd
);
3255 button
= (button
== 0) ? LMOUSE
:
3256 ((button
== 1) ? MMOUSE
: RMOUSE
);
3258 button_state
&= ~button
;
3260 button_state
|= button
;
3264 wmsg
.dwModifiers
= w32_get_modifiers ();
3265 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3267 /* Need to return true for XBUTTON messages, false for others,
3268 to indicate that we processed the message. */
3269 return (msg
== WM_XBUTTONDOWN
|| msg
== WM_XBUTTONUP
);
3272 /* If the mouse has just moved into the frame, start tracking
3273 it, so we will be notified when it leaves the frame. Mouse
3274 tracking only works under W98 and NT4 and later. On earlier
3275 versions, there is no way of telling when the mouse leaves the
3276 frame, so we just have to put up with help-echo and mouse
3277 highlighting remaining while the frame is not active. */
3278 if (track_mouse_event_fn
&& !track_mouse_window
)
3280 TRACKMOUSEEVENT tme
;
3281 tme
.cbSize
= sizeof (tme
);
3282 tme
.dwFlags
= TME_LEAVE
;
3283 tme
.hwndTrack
= hwnd
;
3285 track_mouse_event_fn (&tme
);
3286 track_mouse_window
= hwnd
;
3289 if (w32_mouse_move_interval
<= 0
3290 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
3292 wmsg
.dwModifiers
= w32_get_modifiers ();
3293 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3297 /* Hang onto mouse move and scroll messages for a bit, to avoid
3298 sending such events to Emacs faster than it can process them.
3299 If we get more events before the timer from the first message
3300 expires, we just replace the first message. */
3302 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
3304 SetTimer (hwnd
, MOUSE_MOVE_ID
,
3305 w32_mouse_move_interval
, NULL
);
3307 /* Hold onto message for now. */
3308 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
3309 saved_mouse_move_msg
.msg
.message
= msg
;
3310 saved_mouse_move_msg
.msg
.wParam
= wParam
;
3311 saved_mouse_move_msg
.msg
.lParam
= lParam
;
3312 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
3313 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
3318 wmsg
.dwModifiers
= w32_get_modifiers ();
3319 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3323 wmsg
.dwModifiers
= w32_get_modifiers ();
3324 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3328 /* Flush out saved messages if necessary. */
3329 if (wParam
== mouse_button_timer
)
3331 if (saved_mouse_button_msg
.msg
.hwnd
)
3333 post_msg (&saved_mouse_button_msg
);
3334 saved_mouse_button_msg
.msg
.hwnd
= 0;
3336 KillTimer (hwnd
, mouse_button_timer
);
3337 mouse_button_timer
= 0;
3339 else if (wParam
== mouse_move_timer
)
3341 if (saved_mouse_move_msg
.msg
.hwnd
)
3343 post_msg (&saved_mouse_move_msg
);
3344 saved_mouse_move_msg
.msg
.hwnd
= 0;
3346 KillTimer (hwnd
, mouse_move_timer
);
3347 mouse_move_timer
= 0;
3349 else if (wParam
== menu_free_timer
)
3351 KillTimer (hwnd
, menu_free_timer
);
3352 menu_free_timer
= 0;
3353 f
= x_window_to_frame (dpyinfo
, hwnd
);
3354 if (!f
->output_data
.w32
->menu_command_in_progress
)
3356 /* Free memory used by owner-drawn and help-echo strings. */
3357 w32_free_menu_strings (hwnd
);
3358 f
->output_data
.w32
->menubar_active
= 0;
3364 /* Windows doesn't send us focus messages when putting up and
3365 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
3366 The only indication we get that something happened is receiving
3367 this message afterwards. So this is a good time to reset our
3368 keyboard modifiers' state. */
3375 /* We must ensure menu bar is fully constructed and up to date
3376 before allowing user interaction with it. To achieve this
3377 we send this message to the lisp thread and wait for a
3378 reply (whose value is not actually needed) to indicate that
3379 the menu bar is now ready for use, so we can now return.
3381 To remain responsive in the meantime, we enter a nested message
3382 loop that can process all other messages.
3384 However, we skip all this if the message results from calling
3385 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
3386 thread a message because it is blocked on us at this point. We
3387 set menubar_active before calling TrackPopupMenu to indicate
3388 this (there is no possibility of confusion with real menubar
3391 f
= x_window_to_frame (dpyinfo
, hwnd
);
3393 && (f
->output_data
.w32
->menubar_active
3394 /* We can receive this message even in the absence of a
3395 menubar (ie. when the system menu is activated) - in this
3396 case we do NOT want to forward the message, otherwise it
3397 will cause the menubar to suddenly appear when the user
3398 had requested it to be turned off! */
3399 || f
->output_data
.w32
->menubar_widget
== NULL
))
3403 deferred_msg msg_buf
;
3405 /* Detect if message has already been deferred; in this case
3406 we cannot return any sensible value to ignore this. */
3407 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3410 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
3413 case WM_EXITMENULOOP
:
3414 f
= x_window_to_frame (dpyinfo
, hwnd
);
3416 /* If a menu command is not already in progress, check again
3417 after a short delay, since Windows often (always?) sends the
3418 WM_EXITMENULOOP before the corresponding WM_COMMAND message. */
3419 if (f
&& !f
->output_data
.w32
->menu_command_in_progress
)
3420 menu_free_timer
= SetTimer (hwnd
, MENU_FREE_ID
, MENU_FREE_DELAY
, NULL
);
3424 /* Direct handling of help_echo in menus. Should be safe now
3425 that we generate the help_echo by placing a help event in the
3428 HMENU menu
= (HMENU
) lParam
;
3429 UINT menu_item
= (UINT
) LOWORD (wParam
);
3430 UINT flags
= (UINT
) HIWORD (wParam
);
3432 w32_menu_display_help (hwnd
, menu
, menu_item
, flags
);
3436 case WM_MEASUREITEM
:
3437 f
= x_window_to_frame (dpyinfo
, hwnd
);
3440 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
3442 if (pMis
->CtlType
== ODT_MENU
)
3444 /* Work out dimensions for popup menu titles. */
3445 char * title
= (char *) pMis
->itemData
;
3446 HDC hdc
= GetDC (hwnd
);
3447 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3448 LOGFONT menu_logfont
;
3452 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3453 menu_logfont
.lfWeight
= FW_BOLD
;
3454 menu_font
= CreateFontIndirect (&menu_logfont
);
3455 old_font
= SelectObject (hdc
, menu_font
);
3457 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
3460 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
3461 pMis
->itemWidth
= size
.cx
;
3462 if (pMis
->itemHeight
< size
.cy
)
3463 pMis
->itemHeight
= size
.cy
;
3466 pMis
->itemWidth
= 0;
3468 SelectObject (hdc
, old_font
);
3469 DeleteObject (menu_font
);
3470 ReleaseDC (hwnd
, hdc
);
3477 f
= x_window_to_frame (dpyinfo
, hwnd
);
3480 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
3482 if (pDis
->CtlType
== ODT_MENU
)
3484 /* Draw popup menu title. */
3485 char * title
= (char *) pDis
->itemData
;
3488 HDC hdc
= pDis
->hDC
;
3489 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3490 LOGFONT menu_logfont
;
3493 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3494 menu_logfont
.lfWeight
= FW_BOLD
;
3495 menu_font
= CreateFontIndirect (&menu_logfont
);
3496 old_font
= SelectObject (hdc
, menu_font
);
3498 /* Always draw title as if not selected. */
3501 + GetSystemMetrics (SM_CXMENUCHECK
),
3503 ETO_OPAQUE
, &pDis
->rcItem
,
3504 title
, strlen (title
), NULL
);
3506 SelectObject (hdc
, old_font
);
3507 DeleteObject (menu_font
);
3515 /* Still not right - can't distinguish between clicks in the
3516 client area of the frame from clicks forwarded from the scroll
3517 bars - may have to hook WM_NCHITTEST to remember the mouse
3518 position and then check if it is in the client area ourselves. */
3519 case WM_MOUSEACTIVATE
:
3520 /* Discard the mouse click that activates a frame, allowing the
3521 user to click anywhere without changing point (or worse!).
3522 Don't eat mouse clicks on scrollbars though!! */
3523 if (LOWORD (lParam
) == HTCLIENT
)
3524 return MA_ACTIVATEANDEAT
;
3529 /* No longer tracking mouse. */
3530 track_mouse_window
= NULL
;
3532 case WM_ACTIVATEAPP
:
3534 case WM_WINDOWPOSCHANGED
:
3536 /* Inform lisp thread that a frame might have just been obscured
3537 or exposed, so should recheck visibility of all frames. */
3538 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3542 dpyinfo
->faked_key
= 0;
3544 register_hot_keys (hwnd
);
3547 unregister_hot_keys (hwnd
);
3550 /* Relinquish the system caret. */
3551 if (w32_system_caret_hwnd
)
3553 w32_visible_system_caret_hwnd
= NULL
;
3554 w32_system_caret_hwnd
= NULL
;
3559 f
= x_window_to_frame (dpyinfo
, hwnd
);
3560 if (f
&& HIWORD (wParam
) == 0)
3562 f
->output_data
.w32
->menu_command_in_progress
= 1;
3563 if (menu_free_timer
)
3565 KillTimer (hwnd
, menu_free_timer
);
3566 menu_free_timer
= 0;
3572 wmsg
.dwModifiers
= w32_get_modifiers ();
3573 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3577 wmsg
.dwModifiers
= w32_get_modifiers ();
3578 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3581 case WM_WINDOWPOSCHANGING
:
3582 /* Don't restrict the sizing of tip frames. */
3583 if (hwnd
== tip_window
)
3587 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
3589 wp
.length
= sizeof (WINDOWPLACEMENT
);
3590 GetWindowPlacement (hwnd
, &wp
);
3592 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
3599 DWORD internal_border
;
3600 DWORD scrollbar_extra
;
3603 wp
.length
= sizeof(wp
);
3604 GetWindowRect (hwnd
, &wr
);
3608 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
3609 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
3610 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
3611 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
3615 memset (&rect
, 0, sizeof (rect
));
3616 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
3617 GetMenu (hwnd
) != NULL
);
3619 /* Force width and height of client area to be exact
3620 multiples of the character cell dimensions. */
3621 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
3622 - 2 * internal_border
- scrollbar_extra
)
3624 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
3625 - 2 * internal_border
)
3630 /* For right/bottom sizing we can just fix the sizes.
3631 However for top/left sizing we will need to fix the X
3632 and Y positions as well. */
3637 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
3638 && (lppos
->flags
& SWP_NOMOVE
) == 0)
3640 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
3647 lppos
->flags
|= SWP_NOMOVE
;
3658 case WM_GETMINMAXINFO
:
3659 /* Hack to correct bug that allows Emacs frames to be resized
3660 below the Minimum Tracking Size. */
3661 ((LPMINMAXINFO
) lParam
)->ptMinTrackSize
.y
++;
3662 /* Hack to allow resizing the Emacs frame above the screen size.
3663 Note that Windows 9x limits coordinates to 16-bits. */
3664 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.x
= 32767;
3665 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.y
= 32767;
3669 if (LOWORD (lParam
) == HTCLIENT
)
3674 case WM_EMACS_SETCURSOR
:
3676 Cursor cursor
= (Cursor
) wParam
;
3682 case WM_EMACS_CREATESCROLLBAR
:
3683 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
3684 (struct scroll_bar
*) lParam
);
3686 case WM_EMACS_SHOWWINDOW
:
3687 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
3689 case WM_EMACS_SETFOREGROUND
:
3691 HWND foreground_window
;
3692 DWORD foreground_thread
, retval
;
3694 /* On NT 5.0, and apparently Windows 98, it is necessary to
3695 attach to the thread that currently has focus in order to
3696 pull the focus away from it. */
3697 foreground_window
= GetForegroundWindow ();
3698 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
3699 if (!foreground_window
3700 || foreground_thread
== GetCurrentThreadId ()
3701 || !AttachThreadInput (GetCurrentThreadId (),
3702 foreground_thread
, TRUE
))
3703 foreground_thread
= 0;
3705 retval
= SetForegroundWindow ((HWND
) wParam
);
3707 /* Detach from the previous foreground thread. */
3708 if (foreground_thread
)
3709 AttachThreadInput (GetCurrentThreadId (),
3710 foreground_thread
, FALSE
);
3715 case WM_EMACS_SETWINDOWPOS
:
3717 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
3718 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
3719 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
3722 case WM_EMACS_DESTROYWINDOW
:
3723 DragAcceptFiles ((HWND
) wParam
, FALSE
);
3724 return DestroyWindow ((HWND
) wParam
);
3726 case WM_EMACS_HIDE_CARET
:
3727 return HideCaret (hwnd
);
3729 case WM_EMACS_SHOW_CARET
:
3730 return ShowCaret (hwnd
);
3732 case WM_EMACS_DESTROY_CARET
:
3733 w32_system_caret_hwnd
= NULL
;
3734 w32_visible_system_caret_hwnd
= NULL
;
3735 return DestroyCaret ();
3737 case WM_EMACS_TRACK_CARET
:
3738 /* If there is currently no system caret, create one. */
3739 if (w32_system_caret_hwnd
== NULL
)
3741 /* Use the default caret width, and avoid changing it
3742 unneccesarily, as it confuses screen reader software. */
3743 w32_system_caret_hwnd
= hwnd
;
3744 CreateCaret (hwnd
, NULL
, 0,
3745 w32_system_caret_height
);
3748 if (!SetCaretPos (w32_system_caret_x
, w32_system_caret_y
))
3750 /* Ensure visible caret gets turned on when requested. */
3751 else if (w32_use_visible_system_caret
3752 && w32_visible_system_caret_hwnd
!= hwnd
)
3754 w32_visible_system_caret_hwnd
= hwnd
;
3755 return ShowCaret (hwnd
);
3757 /* Ensure visible caret gets turned off when requested. */
3758 else if (!w32_use_visible_system_caret
3759 && w32_visible_system_caret_hwnd
)
3761 w32_visible_system_caret_hwnd
= NULL
;
3762 return HideCaret (hwnd
);
3767 case WM_EMACS_TRACKPOPUPMENU
:
3772 pos
= (POINT
*)lParam
;
3773 flags
= TPM_CENTERALIGN
;
3774 if (button_state
& LMOUSE
)
3775 flags
|= TPM_LEFTBUTTON
;
3776 else if (button_state
& RMOUSE
)
3777 flags
|= TPM_RIGHTBUTTON
;
3779 /* Remember we did a SetCapture on the initial mouse down event,
3780 so for safety, we make sure the capture is cancelled now. */
3784 /* Use menubar_active to indicate that WM_INITMENU is from
3785 TrackPopupMenu below, and should be ignored. */
3786 f
= x_window_to_frame (dpyinfo
, hwnd
);
3788 f
->output_data
.w32
->menubar_active
= 1;
3790 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
3794 /* Eat any mouse messages during popupmenu */
3795 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
3797 /* Get the menu selection, if any */
3798 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
3800 retval
= LOWORD (amsg
.wParam
);
3816 /* Check for messages registered at runtime. */
3817 if (msg
== msh_mousewheel
)
3819 wmsg
.dwModifiers
= w32_get_modifiers ();
3820 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3825 return DefWindowProc (hwnd
, msg
, wParam
, lParam
);
3829 /* The most common default return code for handled messages is 0. */
3834 my_create_window (f
)
3839 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
3841 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
3845 /* Create a tooltip window. Unlike my_create_window, we do not do this
3846 indirectly via the Window thread, as we do not need to process Window
3847 messages for the tooltip. Creating tooltips indirectly also creates
3848 deadlocks when tooltips are created for menu items. */
3850 my_create_tip_window (f
)
3855 rect
.left
= rect
.top
= 0;
3856 rect
.right
= FRAME_PIXEL_WIDTH (f
);
3857 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
3859 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
3860 FRAME_EXTERNAL_MENU_BAR (f
));
3862 tip_window
= FRAME_W32_WINDOW (f
)
3863 = CreateWindow (EMACS_CLASS
,
3865 f
->output_data
.w32
->dwStyle
,
3868 rect
.right
- rect
.left
,
3869 rect
.bottom
- rect
.top
,
3870 FRAME_W32_WINDOW (SELECTED_FRAME ()), /* owner */
3877 SetWindowLong (tip_window
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
3878 SetWindowLong (tip_window
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
3879 SetWindowLong (tip_window
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
3880 SetWindowLong (tip_window
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
3882 /* Tip frames have no scrollbars. */
3883 SetWindowLong (tip_window
, WND_SCROLLBAR_INDEX
, 0);
3885 /* Do this to discard the default setting specified by our parent. */
3886 ShowWindow (tip_window
, SW_HIDE
);
3891 /* Create and set up the w32 window for frame F. */
3894 w32_window (f
, window_prompting
, minibuffer_only
)
3896 long window_prompting
;
3897 int minibuffer_only
;
3901 /* Use the resource name as the top-level window name
3902 for looking up resources. Make a non-Lisp copy
3903 for the window manager, so GC relocation won't bother it.
3905 Elsewhere we specify the window name for the window manager. */
3908 char *str
= (char *) SDATA (Vx_resource_name
);
3909 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
3910 strcpy (f
->namebuf
, str
);
3913 my_create_window (f
);
3915 validate_x_resource_name ();
3917 /* x_set_name normally ignores requests to set the name if the
3918 requested name is the same as the current name. This is the one
3919 place where that assumption isn't correct; f->name is set, but
3920 the server hasn't been told. */
3923 int explicit = f
->explicit_name
;
3925 f
->explicit_name
= 0;
3928 x_set_name (f
, name
, explicit);
3933 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
3934 initialize_frame_menubar (f
);
3936 if (FRAME_W32_WINDOW (f
) == 0)
3937 error ("Unable to create window");
3940 /* Handle the icon stuff for this window. Perhaps later we might
3941 want an x_set_icon_position which can be called interactively as
3949 Lisp_Object icon_x
, icon_y
;
3951 /* Set the position of the icon. Note that Windows 95 groups all
3952 icons in the tray. */
3953 icon_x
= w32_get_arg (parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
3954 icon_y
= w32_get_arg (parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
3955 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
3957 CHECK_NUMBER (icon_x
);
3958 CHECK_NUMBER (icon_y
);
3960 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
3961 error ("Both left and top icon corners of icon must be specified");
3965 if (! EQ (icon_x
, Qunbound
))
3966 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
3969 /* Start up iconic or window? */
3970 x_wm_set_window_state
3971 (f
, (EQ (w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
3975 x_text_icon (f
, (char *) SDATA ((!NILP (f
->icon_name
)
3988 XGCValues gc_values
;
3992 /* Create the GC's of this frame.
3993 Note that many default values are used. */
3996 gc_values
.font
= FRAME_FONT (f
);
3998 /* Cursor has cursor-color background, background-color foreground. */
3999 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
4000 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
4001 f
->output_data
.w32
->cursor_gc
4002 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
4003 (GCFont
| GCForeground
| GCBackground
),
4007 f
->output_data
.w32
->white_relief
.gc
= 0;
4008 f
->output_data
.w32
->black_relief
.gc
= 0;
4014 /* Handler for signals raised during x_create_frame and
4015 x_create_top_frame. FRAME is the frame which is partially
4019 unwind_create_frame (frame
)
4022 struct frame
*f
= XFRAME (frame
);
4024 /* If frame is ``official'', nothing to do. */
4025 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
4028 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4031 x_free_frame_resources (f
);
4033 /* Check that reference counts are indeed correct. */
4034 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
4035 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
4044 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
4046 doc
: /* Make a new window, which is called a \"frame\" in Emacs terms.
4047 Returns an Emacs frame object.
4048 PARAMETERS is an alist of frame parameters.
4049 If the parameters specify that the frame should not have a minibuffer,
4050 and do not specify a specific minibuffer window to use,
4051 then `default-minibuffer-frame' must be a frame whose minibuffer can
4052 be shared by the new frame.
4054 This function is an internal primitive--use `make-frame' instead. */)
4056 Lisp_Object parameters
;
4059 Lisp_Object frame
, tem
;
4061 int minibuffer_only
= 0;
4062 long window_prompting
= 0;
4064 int count
= SPECPDL_INDEX ();
4065 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4066 Lisp_Object display
;
4067 struct w32_display_info
*dpyinfo
= NULL
;
4073 /* Use this general default value to start with
4074 until we know if this frame has a specified name. */
4075 Vx_resource_name
= Vinvocation_name
;
4077 display
= w32_get_arg (parameters
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
4078 if (EQ (display
, Qunbound
))
4080 dpyinfo
= check_x_display_info (display
);
4082 kb
= dpyinfo
->kboard
;
4084 kb
= &the_only_kboard
;
4087 name
= w32_get_arg (parameters
, Qname
, "name", "Name", RES_TYPE_STRING
);
4089 && ! EQ (name
, Qunbound
)
4091 error ("Invalid frame name--not a string or nil");
4094 Vx_resource_name
= name
;
4096 /* See if parent window is specified. */
4097 parent
= w32_get_arg (parameters
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
4098 if (EQ (parent
, Qunbound
))
4100 if (! NILP (parent
))
4101 CHECK_NUMBER (parent
);
4103 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
4104 /* No need to protect DISPLAY because that's not used after passing
4105 it to make_frame_without_minibuffer. */
4107 GCPRO4 (parameters
, parent
, name
, frame
);
4108 tem
= w32_get_arg (parameters
, Qminibuffer
, "minibuffer", "Minibuffer",
4110 if (EQ (tem
, Qnone
) || NILP (tem
))
4111 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
4112 else if (EQ (tem
, Qonly
))
4114 f
= make_minibuffer_frame ();
4115 minibuffer_only
= 1;
4117 else if (WINDOWP (tem
))
4118 f
= make_frame_without_minibuffer (tem
, kb
, display
);
4122 XSETFRAME (frame
, f
);
4124 /* Note that Windows does support scroll bars. */
4125 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
4127 /* By default, make scrollbars the system standard width. */
4128 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
4130 f
->output_method
= output_w32
;
4131 f
->output_data
.w32
=
4132 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
4133 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
4134 FRAME_FONTSET (f
) = -1;
4135 record_unwind_protect (unwind_create_frame
, frame
);
4138 = w32_get_arg (parameters
, Qicon_name
, "iconName", "Title", RES_TYPE_STRING
);
4139 if (! STRINGP (f
->icon_name
))
4140 f
->icon_name
= Qnil
;
4142 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
4144 FRAME_KBOARD (f
) = kb
;
4147 /* Specify the parent under which to make this window. */
4151 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
4152 f
->output_data
.w32
->explicit_parent
= 1;
4156 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4157 f
->output_data
.w32
->explicit_parent
= 0;
4160 /* Set the name; the functions to which we pass f expect the name to
4162 if (EQ (name
, Qunbound
) || NILP (name
))
4164 f
->name
= build_string (dpyinfo
->w32_id_name
);
4165 f
->explicit_name
= 0;
4170 f
->explicit_name
= 1;
4171 /* use the frame's title when getting resources for this frame. */
4172 specbind (Qx_resource_name
, name
);
4175 /* Extract the window parameters from the supplied values
4176 that are needed to determine window geometry. */
4180 font
= w32_get_arg (parameters
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4183 /* First, try whatever font the caller has specified. */
4186 tem
= Fquery_fontset (font
, Qnil
);
4188 font
= x_new_fontset (f
, SDATA (tem
));
4190 font
= x_new_font (f
, SDATA (font
));
4192 /* Try out a font which we hope has bold and italic variations. */
4193 if (!STRINGP (font
))
4194 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
4195 if (! STRINGP (font
))
4196 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
4197 /* If those didn't work, look for something which will at least work. */
4198 if (! STRINGP (font
))
4199 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
4201 if (! STRINGP (font
))
4202 font
= build_string ("Fixedsys");
4204 x_default_parameter (f
, parameters
, Qfont
, font
,
4205 "font", "Font", RES_TYPE_STRING
);
4208 x_default_parameter (f
, parameters
, Qborder_width
, make_number (2),
4209 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4210 /* This defaults to 2 in order to match xterm. We recognize either
4211 internalBorderWidth or internalBorder (which is what xterm calls
4213 if (NILP (Fassq (Qinternal_border_width
, parameters
)))
4217 value
= w32_get_arg (parameters
, Qinternal_border_width
,
4218 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
4219 if (! EQ (value
, Qunbound
))
4220 parameters
= Fcons (Fcons (Qinternal_border_width
, value
),
4223 /* Default internalBorderWidth to 0 on Windows to match other programs. */
4224 x_default_parameter (f
, parameters
, Qinternal_border_width
, make_number (0),
4225 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
4226 x_default_parameter (f
, parameters
, Qvertical_scroll_bars
, Qright
,
4227 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
4229 /* Also do the stuff which must be set before the window exists. */
4230 x_default_parameter (f
, parameters
, Qforeground_color
, build_string ("black"),
4231 "foreground", "Foreground", RES_TYPE_STRING
);
4232 x_default_parameter (f
, parameters
, Qbackground_color
, build_string ("white"),
4233 "background", "Background", RES_TYPE_STRING
);
4234 x_default_parameter (f
, parameters
, Qmouse_color
, build_string ("black"),
4235 "pointerColor", "Foreground", RES_TYPE_STRING
);
4236 x_default_parameter (f
, parameters
, Qcursor_color
, build_string ("black"),
4237 "cursorColor", "Foreground", RES_TYPE_STRING
);
4238 x_default_parameter (f
, parameters
, Qborder_color
, build_string ("black"),
4239 "borderColor", "BorderColor", RES_TYPE_STRING
);
4240 x_default_parameter (f
, parameters
, Qscreen_gamma
, Qnil
,
4241 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
4242 x_default_parameter (f
, parameters
, Qline_spacing
, Qnil
,
4243 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
4244 x_default_parameter (f
, parameters
, Qleft_fringe
, Qnil
,
4245 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
4246 x_default_parameter (f
, parameters
, Qright_fringe
, Qnil
,
4247 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
4250 /* Init faces before x_default_parameter is called for scroll-bar
4251 parameters because that function calls x_set_scroll_bar_width,
4252 which calls change_frame_size, which calls Fset_window_buffer,
4253 which runs hooks, which call Fvertical_motion. At the end, we
4254 end up in init_iterator with a null face cache, which should not
4256 init_frame_faces (f
);
4258 x_default_parameter (f
, parameters
, Qmenu_bar_lines
, make_number (1),
4259 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
4260 x_default_parameter (f
, parameters
, Qtool_bar_lines
, make_number (1),
4261 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
4263 x_default_parameter (f
, parameters
, Qbuffer_predicate
, Qnil
,
4264 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
4265 x_default_parameter (f
, parameters
, Qtitle
, Qnil
,
4266 "title", "Title", RES_TYPE_STRING
);
4267 x_default_parameter (f
, parameters
, Qfullscreen
, Qnil
,
4268 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
4270 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
4271 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4273 f
->output_data
.w32
->text_cursor
= w32_load_cursor (IDC_IBEAM
);
4274 f
->output_data
.w32
->nontext_cursor
= w32_load_cursor (IDC_ARROW
);
4275 f
->output_data
.w32
->modeline_cursor
= w32_load_cursor (IDC_ARROW
);
4276 f
->output_data
.w32
->hand_cursor
= w32_load_cursor (IDC_HAND
);
4277 f
->output_data
.w32
->hourglass_cursor
= w32_load_cursor (IDC_WAIT
);
4278 f
->output_data
.w32
->horizontal_drag_cursor
= w32_load_cursor (IDC_SIZEWE
);
4280 window_prompting
= x_figure_window_size (f
, parameters
, 1);
4282 tem
= w32_get_arg (parameters
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
4283 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
4285 w32_window (f
, window_prompting
, minibuffer_only
);
4286 x_icon (f
, parameters
);
4290 /* Now consider the frame official. */
4291 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
4292 Vframe_list
= Fcons (frame
, Vframe_list
);
4294 /* We need to do this after creating the window, so that the
4295 icon-creation functions can say whose icon they're describing. */
4296 x_default_parameter (f
, parameters
, Qicon_type
, Qnil
,
4297 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
4299 x_default_parameter (f
, parameters
, Qauto_raise
, Qnil
,
4300 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4301 x_default_parameter (f
, parameters
, Qauto_lower
, Qnil
,
4302 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4303 x_default_parameter (f
, parameters
, Qcursor_type
, Qbox
,
4304 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4305 x_default_parameter (f
, parameters
, Qscroll_bar_width
, Qnil
,
4306 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
4308 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4309 Change will not be effected unless different from the current
4311 width
= FRAME_COLS (f
);
4312 height
= FRAME_LINES (f
);
4314 FRAME_LINES (f
) = 0;
4315 SET_FRAME_COLS (f
, 0);
4316 change_frame_size (f
, height
, width
, 1, 0, 0);
4318 /* Tell the server what size and position, etc, we want, and how
4319 badly we want them. This should be done after we have the menu
4320 bar so that its size can be taken into account. */
4322 x_wm_set_size_hint (f
, window_prompting
, 0);
4325 /* Avoid a bug that causes the new frame to never become visible if
4326 an echo area message is displayed during the following call1. */
4327 specbind(Qredisplay_dont_pause
, Qt
);
4329 /* Set up faces after all frame parameters are known. This call
4330 also merges in face attributes specified for new frames. If we
4331 don't do this, the `menu' face for instance won't have the right
4332 colors, and the menu bar won't appear in the specified colors for
4334 call1 (Qface_set_after_frame_default
, frame
);
4336 /* Make the window appear on the frame and enable display, unless
4337 the caller says not to. However, with explicit parent, Emacs
4338 cannot control visibility, so don't try. */
4339 if (! f
->output_data
.w32
->explicit_parent
)
4341 Lisp_Object visibility
;
4343 visibility
= w32_get_arg (parameters
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
4344 if (EQ (visibility
, Qunbound
))
4347 if (EQ (visibility
, Qicon
))
4348 x_iconify_frame (f
);
4349 else if (! NILP (visibility
))
4350 x_make_frame_visible (f
);
4352 /* Must have been Qnil. */
4357 /* Make sure windows on this frame appear in calls to next-window
4358 and similar functions. */
4359 Vwindow_list
= Qnil
;
4361 return unbind_to (count
, frame
);
4364 /* FRAME is used only to get a handle on the X display. We don't pass the
4365 display info directly because we're called from frame.c, which doesn't
4366 know about that structure. */
4368 x_get_focus_frame (frame
)
4369 struct frame
*frame
;
4371 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
4373 if (! dpyinfo
->w32_focus_frame
)
4376 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
4380 DEFUN ("w32-focus-frame", Fw32_focus_frame
, Sw32_focus_frame
, 1, 1, 0,
4381 doc
: /* Give FRAME input focus, raising to foreground if necessary. */)
4385 x_focus_on_frame (check_x_frame (frame
));
4390 /* Return the charset portion of a font name. */
4391 char * xlfd_charset_of_font (char * fontname
)
4393 char *charset
, *encoding
;
4395 encoding
= strrchr(fontname
, '-');
4396 if (!encoding
|| encoding
== fontname
)
4399 for (charset
= encoding
- 1; charset
>= fontname
; charset
--)
4400 if (*charset
== '-')
4403 if (charset
== fontname
|| strcmp(charset
, "-*-*") == 0)
4409 struct font_info
*w32_load_bdf_font (struct frame
*f
, char *fontname
,
4410 int size
, char* filename
);
4411 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
);
4412 static BOOL
w32_to_x_font (LOGFONT
* lplf
, char * lpxstr
, int len
,
4414 static BOOL
x_to_w32_font (char *lpxstr
, LOGFONT
*lplogfont
);
4416 static struct font_info
*
4417 w32_load_system_font (f
,fontname
,size
)
4422 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4423 Lisp_Object font_names
;
4425 /* Get a list of all the fonts that match this name. Once we
4426 have a list of matching fonts, we compare them against the fonts
4427 we already have loaded by comparing names. */
4428 font_names
= w32_list_fonts (f
, build_string (fontname
), size
, 100);
4430 if (!NILP (font_names
))
4435 /* First check if any are already loaded, as that is cheaper
4436 than loading another one. */
4437 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
4438 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
4439 if (dpyinfo
->font_table
[i
].name
4440 && (!strcmp (dpyinfo
->font_table
[i
].name
,
4441 SDATA (XCAR (tail
)))
4442 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
4443 SDATA (XCAR (tail
)))))
4444 return (dpyinfo
->font_table
+ i
);
4446 fontname
= (char *) SDATA (XCAR (font_names
));
4448 else if (w32_strict_fontnames
)
4450 /* If EnumFontFamiliesEx was available, we got a full list of
4451 fonts back so stop now to avoid the possibility of loading a
4452 random font. If we had to fall back to EnumFontFamilies, the
4453 list is incomplete, so continue whether the font we want was
4455 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
4456 FARPROC enum_font_families_ex
4457 = GetProcAddress (gdi32
, "EnumFontFamiliesExA");
4458 if (enum_font_families_ex
)
4462 /* Load the font and add it to the table. */
4464 char *full_name
, *encoding
, *charset
;
4466 struct font_info
*fontp
;
4472 if (!fontname
|| !x_to_w32_font (fontname
, &lf
))
4475 if (!*lf
.lfFaceName
)
4476 /* If no name was specified for the font, we get a random font
4477 from CreateFontIndirect - this is not particularly
4478 desirable, especially since CreateFontIndirect does not
4479 fill out the missing name in lf, so we never know what we
4483 lf
.lfQuality
= DEFAULT_QUALITY
;
4485 font
= (XFontStruct
*) xmalloc (sizeof (XFontStruct
));
4486 bzero (font
, sizeof (*font
));
4488 /* Set bdf to NULL to indicate that this is a Windows font. */
4493 font
->hfont
= CreateFontIndirect (&lf
);
4495 if (font
->hfont
== NULL
)
4504 codepage
= w32_codepage_for_font (fontname
);
4506 hdc
= GetDC (dpyinfo
->root_window
);
4507 oldobj
= SelectObject (hdc
, font
->hfont
);
4509 ok
= GetTextMetrics (hdc
, &font
->tm
);
4510 if (codepage
== CP_UNICODE
)
4511 font
->double_byte_p
= 1;
4514 /* Unfortunately, some fonts (eg. MingLiU, a big5 ttf font)
4515 don't report themselves as double byte fonts, when
4516 patently they are. So instead of trusting
4517 GetFontLanguageInfo, we check the properties of the
4518 codepage directly, since that is ultimately what we are
4519 working from anyway. */
4520 /* font->double_byte_p = GetFontLanguageInfo(hdc) & GCP_DBCS; */
4522 GetCPInfo (codepage
, &cpi
);
4523 font
->double_byte_p
= cpi
.MaxCharSize
> 1;
4526 SelectObject (hdc
, oldobj
);
4527 ReleaseDC (dpyinfo
->root_window
, hdc
);
4528 /* Fill out details in lf according to the font that was
4530 lf
.lfHeight
= font
->tm
.tmInternalLeading
- font
->tm
.tmHeight
;
4531 lf
.lfWidth
= font
->tm
.tmAveCharWidth
;
4532 lf
.lfWeight
= font
->tm
.tmWeight
;
4533 lf
.lfItalic
= font
->tm
.tmItalic
;
4534 lf
.lfCharSet
= font
->tm
.tmCharSet
;
4535 lf
.lfPitchAndFamily
= ((font
->tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
)
4536 ? VARIABLE_PITCH
: FIXED_PITCH
);
4537 lf
.lfOutPrecision
= ((font
->tm
.tmPitchAndFamily
& TMPF_VECTOR
)
4538 ? OUT_STROKE_PRECIS
: OUT_STRING_PRECIS
);
4540 w32_cache_char_metrics (font
);
4547 w32_unload_font (dpyinfo
, font
);
4551 /* Find a free slot in the font table. */
4552 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
4553 if (dpyinfo
->font_table
[i
].name
== NULL
)
4556 /* If no free slot found, maybe enlarge the font table. */
4557 if (i
== dpyinfo
->n_fonts
4558 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
4561 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
4562 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
4564 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
4567 fontp
= dpyinfo
->font_table
+ i
;
4568 if (i
== dpyinfo
->n_fonts
)
4571 /* Now fill in the slots of *FONTP. */
4573 bzero (fontp
, sizeof (*fontp
));
4575 fontp
->font_idx
= i
;
4576 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
4577 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
4579 charset
= xlfd_charset_of_font (fontname
);
4581 /* Cache the W32 codepage for a font. This makes w32_encode_char
4582 (called for every glyph during redisplay) much faster. */
4583 fontp
->codepage
= codepage
;
4585 /* Work out the font's full name. */
4586 full_name
= (char *)xmalloc (100);
4587 if (full_name
&& w32_to_x_font (&lf
, full_name
, 100, charset
))
4588 fontp
->full_name
= full_name
;
4591 /* If all else fails - just use the name we used to load it. */
4593 fontp
->full_name
= fontp
->name
;
4596 fontp
->size
= FONT_WIDTH (font
);
4597 fontp
->height
= FONT_HEIGHT (font
);
4599 /* The slot `encoding' specifies how to map a character
4600 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
4601 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
4602 (0:0x20..0x7F, 1:0xA0..0xFF,
4603 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
4604 2:0xA020..0xFF7F). For the moment, we don't know which charset
4605 uses this font. So, we set information in fontp->encoding[1]
4606 which is never used by any charset. If mapping can't be
4607 decided, set FONT_ENCODING_NOT_DECIDED. */
4609 /* SJIS fonts need to be set to type 4, all others seem to work as
4610 type FONT_ENCODING_NOT_DECIDED. */
4611 encoding
= strrchr (fontp
->name
, '-');
4612 if (encoding
&& strnicmp (encoding
+1, "sjis", 4) == 0)
4613 fontp
->encoding
[1] = 4;
4615 fontp
->encoding
[1] = FONT_ENCODING_NOT_DECIDED
;
4617 /* The following three values are set to 0 under W32, which is
4618 what they get set to if XGetFontProperty fails under X. */
4619 fontp
->baseline_offset
= 0;
4620 fontp
->relative_compose
= 0;
4621 fontp
->default_ascent
= 0;
4623 /* Set global flag fonts_changed_p to non-zero if the font loaded
4624 has a character with a smaller width than any other character
4625 before, or if the font loaded has a smaller height than any
4626 other font loaded before. If this happens, it will make a
4627 glyph matrix reallocation necessary. */
4628 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
4634 /* Load font named FONTNAME of size SIZE for frame F, and return a
4635 pointer to the structure font_info while allocating it dynamically.
4636 If loading fails, return NULL. */
4638 w32_load_font (f
,fontname
,size
)
4643 Lisp_Object bdf_fonts
;
4644 struct font_info
*retval
= NULL
;
4645 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4647 bdf_fonts
= w32_list_bdf_fonts (build_string (fontname
), 1);
4649 while (!retval
&& CONSP (bdf_fonts
))
4651 char *bdf_name
, *bdf_file
;
4652 Lisp_Object bdf_pair
;
4655 bdf_name
= SDATA (XCAR (bdf_fonts
));
4656 bdf_pair
= Fassoc (XCAR (bdf_fonts
), Vw32_bdf_filename_alist
);
4657 bdf_file
= SDATA (XCDR (bdf_pair
));
4659 // If the font is already loaded, do not load it again.
4660 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
4662 if ((dpyinfo
->font_table
[i
].name
4663 && !strcmp (dpyinfo
->font_table
[i
].name
, bdf_name
))
4664 || (dpyinfo
->font_table
[i
].full_name
4665 && !strcmp (dpyinfo
->font_table
[i
].full_name
, bdf_name
)))
4666 return dpyinfo
->font_table
[i
];
4669 retval
= w32_load_bdf_font (f
, bdf_name
, size
, bdf_file
);
4671 bdf_fonts
= XCDR (bdf_fonts
);
4677 return w32_load_system_font(f
, fontname
, size
);
4682 w32_unload_font (dpyinfo
, font
)
4683 struct w32_display_info
*dpyinfo
;
4688 if (font
->per_char
) xfree (font
->per_char
);
4689 if (font
->bdf
) w32_free_bdf_font (font
->bdf
);
4691 if (font
->hfont
) DeleteObject(font
->hfont
);
4696 /* The font conversion stuff between x and w32 */
4698 /* X font string is as follows (from faces.el)
4702 * (weight "\\(bold\\|demibold\\|medium\\)") ; 1
4703 * (weight\? "\\([^-]*\\)") ; 1
4704 * (slant "\\([ior]\\)") ; 2
4705 * (slant\? "\\([^-]?\\)") ; 2
4706 * (swidth "\\([^-]*\\)") ; 3
4707 * (adstyle "[^-]*") ; 4
4708 * (pixelsize "[0-9]+")
4709 * (pointsize "[0-9][0-9]+")
4710 * (resx "[0-9][0-9]+")
4711 * (resy "[0-9][0-9]+")
4712 * (spacing "[cmp?*]")
4713 * (avgwidth "[0-9]+")
4714 * (registry "[^-]+")
4715 * (encoding "[^-]+")
4720 x_to_w32_weight (lpw
)
4723 if (!lpw
) return (FW_DONTCARE
);
4725 if (stricmp (lpw
,"heavy") == 0) return FW_HEAVY
;
4726 else if (stricmp (lpw
,"extrabold") == 0) return FW_EXTRABOLD
;
4727 else if (stricmp (lpw
,"bold") == 0) return FW_BOLD
;
4728 else if (stricmp (lpw
,"demibold") == 0) return FW_SEMIBOLD
;
4729 else if (stricmp (lpw
,"semibold") == 0) return FW_SEMIBOLD
;
4730 else if (stricmp (lpw
,"medium") == 0) return FW_MEDIUM
;
4731 else if (stricmp (lpw
,"normal") == 0) return FW_NORMAL
;
4732 else if (stricmp (lpw
,"light") == 0) return FW_LIGHT
;
4733 else if (stricmp (lpw
,"extralight") == 0) return FW_EXTRALIGHT
;
4734 else if (stricmp (lpw
,"thin") == 0) return FW_THIN
;
4741 w32_to_x_weight (fnweight
)
4744 if (fnweight
>= FW_HEAVY
) return "heavy";
4745 if (fnweight
>= FW_EXTRABOLD
) return "extrabold";
4746 if (fnweight
>= FW_BOLD
) return "bold";
4747 if (fnweight
>= FW_SEMIBOLD
) return "demibold";
4748 if (fnweight
>= FW_MEDIUM
) return "medium";
4749 if (fnweight
>= FW_NORMAL
) return "normal";
4750 if (fnweight
>= FW_LIGHT
) return "light";
4751 if (fnweight
>= FW_EXTRALIGHT
) return "extralight";
4752 if (fnweight
>= FW_THIN
) return "thin";
4758 x_to_w32_charset (lpcs
)
4761 Lisp_Object this_entry
, w32_charset
;
4763 int len
= strlen (lpcs
);
4765 /* Support "*-#nnn" format for unknown charsets. */
4766 if (strncmp (lpcs
, "*-#", 3) == 0)
4767 return atoi (lpcs
+ 3);
4769 /* Handle wildcards by ignoring them; eg. treat "big5*-*" as "big5". */
4770 charset
= alloca (len
+ 1);
4771 strcpy (charset
, lpcs
);
4772 lpcs
= strchr (charset
, '*');
4776 /* Look through w32-charset-info-alist for the character set.
4777 Format of each entry is
4778 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
4780 this_entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
4782 if (NILP(this_entry
))
4784 /* At startup, we want iso8859-1 fonts to come up properly. */
4785 if (stricmp(charset
, "iso8859-1") == 0)
4786 return ANSI_CHARSET
;
4788 return DEFAULT_CHARSET
;
4791 w32_charset
= Fcar (Fcdr (this_entry
));
4793 /* Translate Lisp symbol to number. */
4794 if (EQ (w32_charset
, Qw32_charset_ansi
))
4795 return ANSI_CHARSET
;
4796 if (EQ (w32_charset
, Qw32_charset_symbol
))
4797 return SYMBOL_CHARSET
;
4798 if (EQ (w32_charset
, Qw32_charset_shiftjis
))
4799 return SHIFTJIS_CHARSET
;
4800 if (EQ (w32_charset
, Qw32_charset_hangeul
))
4801 return HANGEUL_CHARSET
;
4802 if (EQ (w32_charset
, Qw32_charset_chinesebig5
))
4803 return CHINESEBIG5_CHARSET
;
4804 if (EQ (w32_charset
, Qw32_charset_gb2312
))
4805 return GB2312_CHARSET
;
4806 if (EQ (w32_charset
, Qw32_charset_oem
))
4808 #ifdef JOHAB_CHARSET
4809 if (EQ (w32_charset
, Qw32_charset_johab
))
4810 return JOHAB_CHARSET
;
4811 if (EQ (w32_charset
, Qw32_charset_easteurope
))
4812 return EASTEUROPE_CHARSET
;
4813 if (EQ (w32_charset
, Qw32_charset_turkish
))
4814 return TURKISH_CHARSET
;
4815 if (EQ (w32_charset
, Qw32_charset_baltic
))
4816 return BALTIC_CHARSET
;
4817 if (EQ (w32_charset
, Qw32_charset_russian
))
4818 return RUSSIAN_CHARSET
;
4819 if (EQ (w32_charset
, Qw32_charset_arabic
))
4820 return ARABIC_CHARSET
;
4821 if (EQ (w32_charset
, Qw32_charset_greek
))
4822 return GREEK_CHARSET
;
4823 if (EQ (w32_charset
, Qw32_charset_hebrew
))
4824 return HEBREW_CHARSET
;
4825 if (EQ (w32_charset
, Qw32_charset_vietnamese
))
4826 return VIETNAMESE_CHARSET
;
4827 if (EQ (w32_charset
, Qw32_charset_thai
))
4828 return THAI_CHARSET
;
4829 if (EQ (w32_charset
, Qw32_charset_mac
))
4831 #endif /* JOHAB_CHARSET */
4832 #ifdef UNICODE_CHARSET
4833 if (EQ (w32_charset
, Qw32_charset_unicode
))
4834 return UNICODE_CHARSET
;
4837 return DEFAULT_CHARSET
;
4842 w32_to_x_charset (fncharset
)
4845 static char buf
[32];
4846 Lisp_Object charset_type
;
4851 /* Handle startup case of w32-charset-info-alist not
4852 being set up yet. */
4853 if (NILP(Vw32_charset_info_alist
))
4855 charset_type
= Qw32_charset_ansi
;
4857 case DEFAULT_CHARSET
:
4858 charset_type
= Qw32_charset_default
;
4860 case SYMBOL_CHARSET
:
4861 charset_type
= Qw32_charset_symbol
;
4863 case SHIFTJIS_CHARSET
:
4864 charset_type
= Qw32_charset_shiftjis
;
4866 case HANGEUL_CHARSET
:
4867 charset_type
= Qw32_charset_hangeul
;
4869 case GB2312_CHARSET
:
4870 charset_type
= Qw32_charset_gb2312
;
4872 case CHINESEBIG5_CHARSET
:
4873 charset_type
= Qw32_charset_chinesebig5
;
4876 charset_type
= Qw32_charset_oem
;
4879 /* More recent versions of Windows (95 and NT4.0) define more
4881 #ifdef EASTEUROPE_CHARSET
4882 case EASTEUROPE_CHARSET
:
4883 charset_type
= Qw32_charset_easteurope
;
4885 case TURKISH_CHARSET
:
4886 charset_type
= Qw32_charset_turkish
;
4888 case BALTIC_CHARSET
:
4889 charset_type
= Qw32_charset_baltic
;
4891 case RUSSIAN_CHARSET
:
4892 charset_type
= Qw32_charset_russian
;
4894 case ARABIC_CHARSET
:
4895 charset_type
= Qw32_charset_arabic
;
4898 charset_type
= Qw32_charset_greek
;
4900 case HEBREW_CHARSET
:
4901 charset_type
= Qw32_charset_hebrew
;
4903 case VIETNAMESE_CHARSET
:
4904 charset_type
= Qw32_charset_vietnamese
;
4907 charset_type
= Qw32_charset_thai
;
4910 charset_type
= Qw32_charset_mac
;
4913 charset_type
= Qw32_charset_johab
;
4917 #ifdef UNICODE_CHARSET
4918 case UNICODE_CHARSET
:
4919 charset_type
= Qw32_charset_unicode
;
4923 /* Encode numerical value of unknown charset. */
4924 sprintf (buf
, "*-#%u", fncharset
);
4930 char * best_match
= NULL
;
4932 /* Look through w32-charset-info-alist for the character set.
4933 Prefer ISO codepages, and prefer lower numbers in the ISO
4934 range. Only return charsets for codepages which are installed.
4936 Format of each entry is
4937 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
4939 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
4942 Lisp_Object w32_charset
;
4943 Lisp_Object codepage
;
4945 Lisp_Object this_entry
= XCAR (rest
);
4947 /* Skip invalid entries in alist. */
4948 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
4949 || !CONSP (XCDR (this_entry
))
4950 || !SYMBOLP (XCAR (XCDR (this_entry
))))
4953 x_charset
= SDATA (XCAR (this_entry
));
4954 w32_charset
= XCAR (XCDR (this_entry
));
4955 codepage
= XCDR (XCDR (this_entry
));
4957 /* Look for Same charset and a valid codepage (or non-int
4958 which means ignore). */
4959 if (EQ (w32_charset
, charset_type
)
4960 && (!INTEGERP (codepage
) || XINT (codepage
) == CP_DEFAULT
4961 || IsValidCodePage (XINT (codepage
))))
4963 /* If we don't have a match already, then this is the
4966 best_match
= x_charset
;
4967 /* If this is an ISO codepage, and the best so far isn't,
4968 then this is better. */
4969 else if (strnicmp (best_match
, "iso", 3) != 0
4970 && strnicmp (x_charset
, "iso", 3) == 0)
4971 best_match
= x_charset
;
4972 /* If both are ISO8859 codepages, choose the one with the
4973 lowest number in the encoding field. */
4974 else if (strnicmp (best_match
, "iso8859-", 8) == 0
4975 && strnicmp (x_charset
, "iso8859-", 8) == 0)
4977 int best_enc
= atoi (best_match
+ 8);
4978 int this_enc
= atoi (x_charset
+ 8);
4979 if (this_enc
> 0 && this_enc
< best_enc
)
4980 best_match
= x_charset
;
4985 /* If no match, encode the numeric value. */
4988 sprintf (buf
, "*-#%u", fncharset
);
4992 strncpy(buf
, best_match
, 31);
4999 /* Return all the X charsets that map to a font. */
5001 w32_to_all_x_charsets (fncharset
)
5004 static char buf
[32];
5005 Lisp_Object charset_type
;
5006 Lisp_Object retval
= Qnil
;
5011 /* Handle startup case of w32-charset-info-alist not
5012 being set up yet. */
5013 if (NILP(Vw32_charset_info_alist
))
5014 return Fcons (build_string ("iso8859-1"), Qnil
);
5016 charset_type
= Qw32_charset_ansi
;
5018 case DEFAULT_CHARSET
:
5019 charset_type
= Qw32_charset_default
;
5021 case SYMBOL_CHARSET
:
5022 charset_type
= Qw32_charset_symbol
;
5024 case SHIFTJIS_CHARSET
:
5025 charset_type
= Qw32_charset_shiftjis
;
5027 case HANGEUL_CHARSET
:
5028 charset_type
= Qw32_charset_hangeul
;
5030 case GB2312_CHARSET
:
5031 charset_type
= Qw32_charset_gb2312
;
5033 case CHINESEBIG5_CHARSET
:
5034 charset_type
= Qw32_charset_chinesebig5
;
5037 charset_type
= Qw32_charset_oem
;
5040 /* More recent versions of Windows (95 and NT4.0) define more
5042 #ifdef EASTEUROPE_CHARSET
5043 case EASTEUROPE_CHARSET
:
5044 charset_type
= Qw32_charset_easteurope
;
5046 case TURKISH_CHARSET
:
5047 charset_type
= Qw32_charset_turkish
;
5049 case BALTIC_CHARSET
:
5050 charset_type
= Qw32_charset_baltic
;
5052 case RUSSIAN_CHARSET
:
5053 charset_type
= Qw32_charset_russian
;
5055 case ARABIC_CHARSET
:
5056 charset_type
= Qw32_charset_arabic
;
5059 charset_type
= Qw32_charset_greek
;
5061 case HEBREW_CHARSET
:
5062 charset_type
= Qw32_charset_hebrew
;
5064 case VIETNAMESE_CHARSET
:
5065 charset_type
= Qw32_charset_vietnamese
;
5068 charset_type
= Qw32_charset_thai
;
5071 charset_type
= Qw32_charset_mac
;
5074 charset_type
= Qw32_charset_johab
;
5078 #ifdef UNICODE_CHARSET
5079 case UNICODE_CHARSET
:
5080 charset_type
= Qw32_charset_unicode
;
5084 /* Encode numerical value of unknown charset. */
5085 sprintf (buf
, "*-#%u", fncharset
);
5086 return Fcons (build_string (buf
), Qnil
);
5091 /* Look through w32-charset-info-alist for the character set.
5092 Only return charsets for codepages which are installed.
5094 Format of each entry in Vw32_charset_info_alist is
5095 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5097 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
5099 Lisp_Object x_charset
;
5100 Lisp_Object w32_charset
;
5101 Lisp_Object codepage
;
5103 Lisp_Object this_entry
= XCAR (rest
);
5105 /* Skip invalid entries in alist. */
5106 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
5107 || !CONSP (XCDR (this_entry
))
5108 || !SYMBOLP (XCAR (XCDR (this_entry
))))
5111 x_charset
= XCAR (this_entry
);
5112 w32_charset
= XCAR (XCDR (this_entry
));
5113 codepage
= XCDR (XCDR (this_entry
));
5115 /* Look for Same charset and a valid codepage (or non-int
5116 which means ignore). */
5117 if (EQ (w32_charset
, charset_type
)
5118 && (!INTEGERP (codepage
) || XINT (codepage
) == CP_DEFAULT
5119 || IsValidCodePage (XINT (codepage
))))
5121 retval
= Fcons (x_charset
, retval
);
5125 /* If no match, encode the numeric value. */
5128 sprintf (buf
, "*-#%u", fncharset
);
5129 return Fcons (build_string (buf
), Qnil
);
5136 /* Get the Windows codepage corresponding to the specified font. The
5137 charset info in the font name is used to look up
5138 w32-charset-to-codepage-alist. */
5140 w32_codepage_for_font (char *fontname
)
5142 Lisp_Object codepage
, entry
;
5143 char *charset_str
, *charset
, *end
;
5145 if (NILP (Vw32_charset_info_alist
))
5148 /* Extract charset part of font string. */
5149 charset
= xlfd_charset_of_font (fontname
);
5154 charset_str
= (char *) alloca (strlen (charset
) + 1);
5155 strcpy (charset_str
, charset
);
5158 /* Remove leading "*-". */
5159 if (strncmp ("*-", charset_str
, 2) == 0)
5160 charset
= charset_str
+ 2;
5163 charset
= charset_str
;
5165 /* Stop match at wildcard (including preceding '-'). */
5166 if (end
= strchr (charset
, '*'))
5168 if (end
> charset
&& *(end
-1) == '-')
5173 entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
5177 codepage
= Fcdr (Fcdr (entry
));
5179 if (NILP (codepage
))
5181 else if (XFASTINT (codepage
) == XFASTINT (Qt
))
5183 else if (INTEGERP (codepage
))
5184 return XINT (codepage
);
5191 w32_to_x_font (lplogfont
, lpxstr
, len
, specific_charset
)
5192 LOGFONT
* lplogfont
;
5195 char * specific_charset
;
5199 char height_pixels
[8];
5201 char width_pixels
[8];
5202 char *fontname_dash
;
5203 int display_resy
= (int) one_w32_display_info
.resy
;
5204 int display_resx
= (int) one_w32_display_info
.resx
;
5206 struct coding_system coding
;
5208 if (!lpxstr
) abort ();
5213 if (lplogfont
->lfOutPrecision
== OUT_STRING_PRECIS
)
5214 fonttype
= "raster";
5215 else if (lplogfont
->lfOutPrecision
== OUT_STROKE_PRECIS
)
5216 fonttype
= "outline";
5218 fonttype
= "unknown";
5220 setup_coding_system (Fcheck_coding_system (Vlocale_coding_system
),
5222 coding
.src_multibyte
= 0;
5223 coding
.dst_multibyte
= 1;
5224 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
5225 /* We explicitely disable composition handling because selection
5226 data should not contain any composition sequence. */
5227 coding
.composing
= COMPOSITION_DISABLED
;
5228 bufsz
= decoding_buffer_size (&coding
, LF_FACESIZE
);
5230 fontname
= alloca(sizeof(*fontname
) * bufsz
);
5231 decode_coding (&coding
, lplogfont
->lfFaceName
, fontname
,
5232 strlen(lplogfont
->lfFaceName
), bufsz
- 1);
5233 *(fontname
+ coding
.produced
) = '\0';
5235 /* Replace dashes with underscores so the dashes are not
5237 fontname_dash
= fontname
;
5238 while (fontname_dash
= strchr (fontname_dash
, '-'))
5239 *fontname_dash
= '_';
5241 if (lplogfont
->lfHeight
)
5243 sprintf (height_pixels
, "%u", abs (lplogfont
->lfHeight
));
5244 sprintf (height_dpi
, "%u",
5245 abs (lplogfont
->lfHeight
) * 720 / display_resy
);
5249 strcpy (height_pixels
, "*");
5250 strcpy (height_dpi
, "*");
5252 if (lplogfont
->lfWidth
)
5253 sprintf (width_pixels
, "%u", lplogfont
->lfWidth
* 10);
5255 strcpy (width_pixels
, "*");
5257 _snprintf (lpxstr
, len
- 1,
5258 "-%s-%s-%s-%c-normal-normal-%s-%s-%d-%d-%c-%s-%s",
5259 fonttype
, /* foundry */
5260 fontname
, /* family */
5261 w32_to_x_weight (lplogfont
->lfWeight
), /* weight */
5262 lplogfont
->lfItalic
?'i':'r', /* slant */
5264 /* add style name */
5265 height_pixels
, /* pixel size */
5266 height_dpi
, /* point size */
5267 display_resx
, /* resx */
5268 display_resy
, /* resy */
5269 ((lplogfont
->lfPitchAndFamily
& 0x3) == VARIABLE_PITCH
)
5270 ? 'p' : 'c', /* spacing */
5271 width_pixels
, /* avg width */
5272 specific_charset
? specific_charset
5273 : w32_to_x_charset (lplogfont
->lfCharSet
)
5274 /* charset registry and encoding */
5277 lpxstr
[len
- 1] = 0; /* just to be sure */
5282 x_to_w32_font (lpxstr
, lplogfont
)
5284 LOGFONT
* lplogfont
;
5286 struct coding_system coding
;
5288 if (!lplogfont
) return (FALSE
);
5290 memset (lplogfont
, 0, sizeof (*lplogfont
));
5292 /* Set default value for each field. */
5294 lplogfont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
5295 lplogfont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
5296 lplogfont
->lfQuality
= DEFAULT_QUALITY
;
5298 /* go for maximum quality */
5299 lplogfont
->lfOutPrecision
= OUT_STROKE_PRECIS
;
5300 lplogfont
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
5301 lplogfont
->lfQuality
= PROOF_QUALITY
;
5304 lplogfont
->lfCharSet
= DEFAULT_CHARSET
;
5305 lplogfont
->lfWeight
= FW_DONTCARE
;
5306 lplogfont
->lfPitchAndFamily
= DEFAULT_PITCH
| FF_DONTCARE
;
5311 /* Provide a simple escape mechanism for specifying Windows font names
5312 * directly -- if font spec does not beginning with '-', assume this
5314 * "<font name>[:height in pixels[:width in pixels[:weight]]]"
5320 char name
[50], weight
[20], slant
, pitch
, pixels
[10], height
[10],
5321 width
[10], resy
[10], remainder
[50];
5323 int dpi
= (int) one_w32_display_info
.resy
;
5325 fields
= sscanf (lpxstr
,
5326 "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%49s",
5327 name
, weight
, &slant
, pixels
, height
, resy
, &pitch
, width
, remainder
);
5331 /* In the general case when wildcards cover more than one field,
5332 we don't know which field is which, so don't fill any in.
5333 However, we need to cope with this particular form, which is
5334 generated by font_list_1 (invoked by try_font_list):
5335 "-raster-6x10-*-gb2312*-*"
5336 and make sure to correctly parse the charset field. */
5339 fields
= sscanf (lpxstr
,
5340 "-%*[^-]-%49[^-]-*-%49s",
5343 else if (fields
< 9)
5349 if (fields
> 0 && name
[0] != '*')
5355 (Fcheck_coding_system (Vlocale_coding_system
), &coding
);
5356 coding
.src_multibyte
= 1;
5357 coding
.dst_multibyte
= 1;
5358 /* Need to set COMPOSITION_DISABLED, otherwise Emacs crashes in
5359 encode_coding_iso2022 trying to dereference a null pointer. */
5360 coding
.composing
= COMPOSITION_DISABLED
;
5361 if (coding
.type
== coding_type_iso2022
)
5362 coding
.flags
|= CODING_FLAG_ISO_SAFE
;
5363 bufsize
= encoding_buffer_size (&coding
, strlen (name
));
5364 buf
= (unsigned char *) alloca (bufsize
);
5365 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
5366 encode_coding (&coding
, name
, buf
, strlen (name
), bufsize
);
5367 if (coding
.produced
>= LF_FACESIZE
)
5368 coding
.produced
= LF_FACESIZE
- 1;
5369 buf
[coding
.produced
] = 0;
5370 strcpy (lplogfont
->lfFaceName
, buf
);
5374 lplogfont
->lfFaceName
[0] = '\0';
5379 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
5383 lplogfont
->lfItalic
= (fields
> 0 && slant
== 'i');
5387 if (fields
> 0 && pixels
[0] != '*')
5388 lplogfont
->lfHeight
= atoi (pixels
);
5392 if (fields
> 0 && resy
[0] != '*')
5395 if (tem
> 0) dpi
= tem
;
5398 if (fields
> -1 && lplogfont
->lfHeight
== 0 && height
[0] != '*')
5399 lplogfont
->lfHeight
= atoi (height
) * dpi
/ 720;
5402 lplogfont
->lfPitchAndFamily
=
5403 (fields
> 0 && pitch
== 'p') ? VARIABLE_PITCH
: FIXED_PITCH
;
5407 if (fields
> 0 && width
[0] != '*')
5408 lplogfont
->lfWidth
= atoi (width
) / 10;
5412 /* Strip the trailing '-' if present. (it shouldn't be, as it
5413 fails the test against xlfd-tight-regexp in fontset.el). */
5415 int len
= strlen (remainder
);
5416 if (len
> 0 && remainder
[len
-1] == '-')
5417 remainder
[len
-1] = 0;
5419 encoding
= remainder
;
5421 if (strncmp (encoding
, "*-", 2) == 0)
5424 lplogfont
->lfCharSet
= x_to_w32_charset (encoding
);
5429 char name
[100], height
[10], width
[10], weight
[20];
5431 fields
= sscanf (lpxstr
,
5432 "%99[^:]:%9[^:]:%9[^:]:%19s",
5433 name
, height
, width
, weight
);
5435 if (fields
== EOF
) return (FALSE
);
5439 strncpy (lplogfont
->lfFaceName
,name
, LF_FACESIZE
);
5440 lplogfont
->lfFaceName
[LF_FACESIZE
-1] = 0;
5444 lplogfont
->lfFaceName
[0] = 0;
5450 lplogfont
->lfHeight
= atoi (height
);
5455 lplogfont
->lfWidth
= atoi (width
);
5459 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
5462 /* This makes TrueType fonts work better. */
5463 lplogfont
->lfHeight
= - abs (lplogfont
->lfHeight
);
5468 /* Strip the pixel height and point height from the given xlfd, and
5469 return the pixel height. If no pixel height is specified, calculate
5470 one from the point height, or if that isn't defined either, return
5471 0 (which usually signifies a scalable font).
5474 xlfd_strip_height (char *fontname
)
5476 int pixel_height
, field_number
;
5477 char *read_from
, *write_to
;
5481 pixel_height
= field_number
= 0;
5484 /* Look for height fields. */
5485 for (read_from
= fontname
; *read_from
; read_from
++)
5487 if (*read_from
== '-')
5490 if (field_number
== 7) /* Pixel height. */
5493 write_to
= read_from
;
5495 /* Find end of field. */
5496 for (;*read_from
&& *read_from
!= '-'; read_from
++)
5499 /* Split the fontname at end of field. */
5505 pixel_height
= atoi (write_to
);
5506 /* Blank out field. */
5507 if (read_from
> write_to
)
5512 /* If the pixel height field is at the end (partial xlfd),
5515 return pixel_height
;
5517 /* If we got a pixel height, the point height can be
5518 ignored. Just blank it out and break now. */
5521 /* Find end of point size field. */
5522 for (; *read_from
&& *read_from
!= '-'; read_from
++)
5528 /* Blank out the point size field. */
5529 if (read_from
> write_to
)
5535 return pixel_height
;
5539 /* If the point height is already blank, break now. */
5540 if (*read_from
== '-')
5546 else if (field_number
== 8)
5548 /* If we didn't get a pixel height, try to get the point
5549 height and convert that. */
5551 char *point_size_start
= read_from
++;
5553 /* Find end of field. */
5554 for (; *read_from
&& *read_from
!= '-'; read_from
++)
5563 point_size
= atoi (point_size_start
);
5565 /* Convert to pixel height. */
5566 pixel_height
= point_size
5567 * one_w32_display_info
.height_in
/ 720;
5569 /* Blank out this field and break. */
5577 /* Shift the rest of the font spec into place. */
5578 if (write_to
&& read_from
> write_to
)
5580 for (; *read_from
; read_from
++, write_to
++)
5581 *write_to
= *read_from
;
5585 return pixel_height
;
5588 /* Assume parameter 1 is fully qualified, no wildcards. */
5590 w32_font_match (fontname
, pattern
)
5594 char *regex
= alloca (strlen (pattern
) * 2 + 3);
5595 char *font_name_copy
= alloca (strlen (fontname
) + 1);
5598 /* Copy fontname so we can modify it during comparison. */
5599 strcpy (font_name_copy
, fontname
);
5604 /* Turn pattern into a regexp and do a regexp match. */
5605 for (; *pattern
; pattern
++)
5607 if (*pattern
== '?')
5609 else if (*pattern
== '*')
5620 /* Strip out font heights and compare them seperately, since
5621 rounding error can cause mismatches. This also allows a
5622 comparison between a font that declares only a pixel height and a
5623 pattern that declares the point height.
5626 int font_height
, pattern_height
;
5628 font_height
= xlfd_strip_height (font_name_copy
);
5629 pattern_height
= xlfd_strip_height (regex
);
5631 /* Compare now, and don't bother doing expensive regexp matching
5632 if the heights differ. */
5633 if (font_height
&& pattern_height
&& (font_height
!= pattern_height
))
5637 return (fast_c_string_match_ignore_case (build_string (regex
),
5638 font_name_copy
) >= 0);
5641 /* Callback functions, and a structure holding info they need, for
5642 listing system fonts on W32. We need one set of functions to do the
5643 job properly, but these don't work on NT 3.51 and earlier, so we
5644 have a second set which don't handle character sets properly to
5647 In both cases, there are two passes made. The first pass gets one
5648 font from each family, the second pass lists all the fonts from
5651 typedef struct enumfont_t
5656 XFontStruct
*size_ref
;
5657 Lisp_Object pattern
;
5663 enum_font_maybe_add_to_list (enumfont_t
*, LOGFONT
*, char *, Lisp_Object
);
5667 enum_font_cb2 (lplf
, lptm
, FontType
, lpef
)
5669 NEWTEXTMETRIC
* lptm
;
5673 /* Ignore struck out and underlined versions of fonts. */
5674 if (lplf
->elfLogFont
.lfStrikeOut
|| lplf
->elfLogFont
.lfUnderline
)
5677 /* Only return fonts with names starting with @ if they were
5678 explicitly specified, since Microsoft uses an initial @ to
5679 denote fonts for vertical writing, without providing a more
5680 convenient way of identifying them. */
5681 if (lplf
->elfLogFont
.lfFaceName
[0] == '@'
5682 && lpef
->logfont
.lfFaceName
[0] != '@')
5685 /* Check that the character set matches if it was specified */
5686 if (lpef
->logfont
.lfCharSet
!= DEFAULT_CHARSET
&&
5687 lplf
->elfLogFont
.lfCharSet
!= lpef
->logfont
.lfCharSet
)
5690 if (FontType
== RASTER_FONTTYPE
)
5692 /* DBCS raster fonts have problems displaying, so skip them. */
5693 int charset
= lplf
->elfLogFont
.lfCharSet
;
5694 if (charset
== SHIFTJIS_CHARSET
5695 || charset
== HANGEUL_CHARSET
5696 || charset
== CHINESEBIG5_CHARSET
5697 || charset
== GB2312_CHARSET
5698 #ifdef JOHAB_CHARSET
5699 || charset
== JOHAB_CHARSET
5707 Lisp_Object width
= Qnil
;
5708 Lisp_Object charset_list
= Qnil
;
5709 char *charset
= NULL
;
5711 /* Truetype fonts do not report their true metrics until loaded */
5712 if (FontType
!= RASTER_FONTTYPE
)
5714 if (!NILP (lpef
->pattern
))
5716 /* Scalable fonts are as big as you want them to be. */
5717 lplf
->elfLogFont
.lfHeight
= lpef
->logfont
.lfHeight
;
5718 lplf
->elfLogFont
.lfWidth
= lpef
->logfont
.lfWidth
;
5719 width
= make_number (lpef
->logfont
.lfWidth
);
5723 lplf
->elfLogFont
.lfHeight
= 0;
5724 lplf
->elfLogFont
.lfWidth
= 0;
5728 /* Make sure the height used here is the same as everywhere
5729 else (ie character height, not cell height). */
5730 if (lplf
->elfLogFont
.lfHeight
> 0)
5732 /* lptm can be trusted for RASTER fonts, but not scalable ones. */
5733 if (FontType
== RASTER_FONTTYPE
)
5734 lplf
->elfLogFont
.lfHeight
= lptm
->tmInternalLeading
- lptm
->tmHeight
;
5736 lplf
->elfLogFont
.lfHeight
= -lplf
->elfLogFont
.lfHeight
;
5739 if (!NILP (lpef
->pattern
))
5741 charset
= xlfd_charset_of_font (SDATA (lpef
->pattern
));
5743 /* We already checked charsets above, but DEFAULT_CHARSET
5744 slipped through. So only allow exact matches for DEFAULT_CHARSET. */
5746 && strncmp (charset
, "*-*", 3) != 0
5747 && lpef
->logfont
.lfCharSet
== DEFAULT_CHARSET
5748 && strcmp (charset
, w32_to_x_charset (DEFAULT_CHARSET
)) != 0)
5753 charset_list
= Fcons (build_string (charset
), Qnil
);
5755 charset_list
= w32_to_all_x_charsets (lplf
->elfLogFont
.lfCharSet
);
5757 /* Loop through the charsets. */
5758 for ( ; CONSP (charset_list
); charset_list
= Fcdr (charset_list
))
5760 Lisp_Object this_charset
= Fcar (charset_list
);
5761 charset
= SDATA (this_charset
);
5763 /* List bold and italic variations if w32-enable-synthesized-fonts
5764 is non-nil and this is a plain font. */
5765 if (w32_enable_synthesized_fonts
5766 && lplf
->elfLogFont
.lfWeight
== FW_NORMAL
5767 && lplf
->elfLogFont
.lfItalic
== FALSE
)
5769 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5772 lplf
->elfLogFont
.lfWeight
= FW_BOLD
;
5773 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5776 lplf
->elfLogFont
.lfItalic
= TRUE
;
5777 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5780 lplf
->elfLogFont
.lfWeight
= FW_NORMAL
;
5781 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5785 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5794 enum_font_maybe_add_to_list (lpef
, logfont
, match_charset
, width
)
5797 char * match_charset
;
5802 if (!w32_to_x_font (logfont
, buf
, 100, match_charset
))
5805 if (NILP (lpef
->pattern
)
5806 || w32_font_match (buf
, SDATA (lpef
->pattern
)))
5808 /* Check if we already listed this font. This may happen if
5809 w32_enable_synthesized_fonts is non-nil, and there are real
5810 bold and italic versions of the font. */
5811 Lisp_Object font_name
= build_string (buf
);
5812 if (NILP (Fmember (font_name
, lpef
->list
)))
5814 Lisp_Object entry
= Fcons (font_name
, width
);
5815 lpef
->list
= Fcons (entry
, lpef
->list
);
5823 enum_font_cb1 (lplf
, lptm
, FontType
, lpef
)
5825 NEWTEXTMETRIC
* lptm
;
5829 return EnumFontFamilies (lpef
->hdc
,
5830 lplf
->elfLogFont
.lfFaceName
,
5831 (FONTENUMPROC
) enum_font_cb2
,
5837 enum_fontex_cb2 (lplf
, lptm
, font_type
, lpef
)
5838 ENUMLOGFONTEX
* lplf
;
5839 NEWTEXTMETRICEX
* lptm
;
5843 /* We are not interested in the extra info we get back from the 'Ex
5844 version - only the fact that we get character set variations
5845 enumerated seperately. */
5846 return enum_font_cb2 ((ENUMLOGFONT
*) lplf
, (NEWTEXTMETRIC
*) lptm
,
5851 enum_fontex_cb1 (lplf
, lptm
, font_type
, lpef
)
5852 ENUMLOGFONTEX
* lplf
;
5853 NEWTEXTMETRICEX
* lptm
;
5857 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
5858 FARPROC enum_font_families_ex
5859 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
5860 /* We don't really expect EnumFontFamiliesEx to disappear once we
5861 get here, so don't bother handling it gracefully. */
5862 if (enum_font_families_ex
== NULL
)
5863 error ("gdi32.dll has disappeared!");
5864 return enum_font_families_ex (lpef
->hdc
,
5866 (FONTENUMPROC
) enum_fontex_cb2
,
5870 /* Interface to fontset handler. (adapted from mw32font.c in Meadow
5871 and xterm.c in Emacs 20.3) */
5873 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
)
5875 char *fontname
, *ptnstr
;
5876 Lisp_Object list
, tem
, newlist
= Qnil
;
5879 list
= Vw32_bdf_filename_alist
;
5880 ptnstr
= SDATA (pattern
);
5882 for ( ; CONSP (list
); list
= XCDR (list
))
5886 fontname
= SDATA (XCAR (tem
));
5887 else if (STRINGP (tem
))
5888 fontname
= SDATA (tem
);
5892 if (w32_font_match (fontname
, ptnstr
))
5894 newlist
= Fcons (XCAR (tem
), newlist
);
5896 if (max_names
>= 0 && n_fonts
>= max_names
)
5905 /* Return a list of names of available fonts matching PATTERN on frame
5906 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
5907 to be listed. Frame F NULL means we have not yet created any
5908 frame, which means we can't get proper size info, as we don't have
5909 a device context to use for GetTextMetrics.
5910 MAXNAMES sets a limit on how many fonts to match. If MAXNAMES is
5911 negative, then all matching fonts are returned. */
5914 w32_list_fonts (f
, pattern
, size
, maxnames
)
5916 Lisp_Object pattern
;
5920 Lisp_Object patterns
, key
= Qnil
, tem
, tpat
;
5921 Lisp_Object list
= Qnil
, newlist
= Qnil
, second_best
= Qnil
;
5922 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
5925 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
5926 if (NILP (patterns
))
5927 patterns
= Fcons (pattern
, Qnil
);
5929 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
5934 tpat
= XCAR (patterns
);
5936 if (!STRINGP (tpat
))
5939 /* Avoid expensive EnumFontFamilies functions if we are not
5940 going to be able to output one of these anyway. */
5941 codepage
= w32_codepage_for_font (SDATA (tpat
));
5942 if (codepage
!= CP_8BIT
&& codepage
!= CP_UNICODE
5943 && codepage
!= CP_DEFAULT
&& codepage
!= CP_UNKNOWN
5944 && !IsValidCodePage(codepage
))
5947 /* See if we cached the result for this particular query.
5948 The cache is an alist of the form:
5949 ((PATTERN (FONTNAME . WIDTH) ...) ...)
5951 if (tem
= XCDR (dpyinfo
->name_list_element
),
5952 !NILP (list
= Fassoc (tpat
, tem
)))
5954 list
= Fcdr_safe (list
);
5955 /* We have a cached list. Don't have to get the list again. */
5960 /* At first, put PATTERN in the cache. */
5965 /* Use EnumFontFamiliesEx where it is available, as it knows
5966 about character sets. Fall back to EnumFontFamilies for
5967 older versions of NT that don't support the 'Ex function. */
5968 x_to_w32_font (SDATA (tpat
), &ef
.logfont
);
5970 LOGFONT font_match_pattern
;
5971 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
5972 FARPROC enum_font_families_ex
5973 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
5975 /* We do our own pattern matching so we can handle wildcards. */
5976 font_match_pattern
.lfFaceName
[0] = 0;
5977 font_match_pattern
.lfPitchAndFamily
= 0;
5978 /* We can use the charset, because if it is a wildcard it will
5979 be DEFAULT_CHARSET anyway. */
5980 font_match_pattern
.lfCharSet
= ef
.logfont
.lfCharSet
;
5982 ef
.hdc
= GetDC (dpyinfo
->root_window
);
5984 if (enum_font_families_ex
)
5985 enum_font_families_ex (ef
.hdc
,
5986 &font_match_pattern
,
5987 (FONTENUMPROC
) enum_fontex_cb1
,
5990 EnumFontFamilies (ef
.hdc
, NULL
, (FONTENUMPROC
) enum_font_cb1
,
5993 ReleaseDC (dpyinfo
->root_window
, ef
.hdc
);
5999 /* Make a list of the fonts we got back.
6000 Store that in the font cache for the display. */
6001 XSETCDR (dpyinfo
->name_list_element
,
6002 Fcons (Fcons (tpat
, list
),
6003 XCDR (dpyinfo
->name_list_element
)));
6006 if (NILP (list
)) continue; /* Try the remaining alternatives. */
6008 newlist
= second_best
= Qnil
;
6010 /* Make a list of the fonts that have the right width. */
6011 for (; CONSP (list
); list
= XCDR (list
))
6018 if (NILP (XCAR (tem
)))
6022 newlist
= Fcons (XCAR (tem
), newlist
);
6024 if (maxnames
>= 0 && n_fonts
>= maxnames
)
6029 if (!INTEGERP (XCDR (tem
)))
6031 /* Since we don't yet know the size of the font, we must
6032 load it and try GetTextMetrics. */
6033 W32FontStruct thisinfo
;
6038 if (!x_to_w32_font (SDATA (XCAR (tem
)), &lf
))
6042 thisinfo
.bdf
= NULL
;
6043 thisinfo
.hfont
= CreateFontIndirect (&lf
);
6044 if (thisinfo
.hfont
== NULL
)
6047 hdc
= GetDC (dpyinfo
->root_window
);
6048 oldobj
= SelectObject (hdc
, thisinfo
.hfont
);
6049 if (GetTextMetrics (hdc
, &thisinfo
.tm
))
6050 XSETCDR (tem
, make_number (FONT_WIDTH (&thisinfo
)));
6052 XSETCDR (tem
, make_number (0));
6053 SelectObject (hdc
, oldobj
);
6054 ReleaseDC (dpyinfo
->root_window
, hdc
);
6055 DeleteObject(thisinfo
.hfont
);
6058 found_size
= XINT (XCDR (tem
));
6059 if (found_size
== size
)
6061 newlist
= Fcons (XCAR (tem
), newlist
);
6063 if (maxnames
>= 0 && n_fonts
>= maxnames
)
6066 /* keep track of the closest matching size in case
6067 no exact match is found. */
6068 else if (found_size
> 0)
6070 if (NILP (second_best
))
6073 else if (found_size
< size
)
6075 if (XINT (XCDR (second_best
)) > size
6076 || XINT (XCDR (second_best
)) < found_size
)
6081 if (XINT (XCDR (second_best
)) > size
6082 && XINT (XCDR (second_best
)) >
6089 if (!NILP (newlist
))
6091 else if (!NILP (second_best
))
6093 newlist
= Fcons (XCAR (second_best
), Qnil
);
6098 /* Include any bdf fonts. */
6099 if (n_fonts
< maxnames
|| maxnames
< 0)
6101 Lisp_Object combined
[2];
6102 combined
[0] = w32_list_bdf_fonts (pattern
, maxnames
- n_fonts
);
6103 combined
[1] = newlist
;
6104 newlist
= Fnconc(2, combined
);
6111 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
6113 w32_get_font_info (f
, font_idx
)
6117 return (FRAME_W32_FONT_TABLE (f
) + font_idx
);
6122 w32_query_font (struct frame
*f
, char *fontname
)
6125 struct font_info
*pfi
;
6127 pfi
= FRAME_W32_FONT_TABLE (f
);
6129 for (i
= 0; i
< one_w32_display_info
.n_fonts
;i
++, pfi
++)
6131 if (strcmp(pfi
->name
, fontname
) == 0) return pfi
;
6137 /* Find a CCL program for a font specified by FONTP, and set the member
6138 `encoder' of the structure. */
6141 w32_find_ccl_program (fontp
)
6142 struct font_info
*fontp
;
6144 Lisp_Object list
, elt
;
6146 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
6150 && STRINGP (XCAR (elt
))
6151 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
6157 struct ccl_program
*ccl
6158 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
6160 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
6163 fontp
->font_encoder
= ccl
;
6167 /* directory-files from dired.c. */
6168 Lisp_Object Fdirectory_files
P_((Lisp_Object
, Lisp_Object
, Lisp_Object
, Lisp_Object
));
6171 /* Find BDF files in a specified directory. (use GCPRO when calling,
6172 as this calls lisp to get a directory listing). */
6174 w32_find_bdf_fonts_in_dir (Lisp_Object directory
)
6176 Lisp_Object filelist
, list
= Qnil
;
6179 if (!STRINGP(directory
))
6182 filelist
= Fdirectory_files (directory
, Qt
,
6183 build_string (".*\\.[bB][dD][fF]"), Qt
);
6185 for ( ; CONSP(filelist
); filelist
= XCDR (filelist
))
6187 Lisp_Object filename
= XCAR (filelist
);
6188 if (w32_BDF_to_x_font (SDATA (filename
), fontname
, 100))
6189 store_in_alist (&list
, build_string (fontname
), filename
);
6194 DEFUN ("w32-find-bdf-fonts", Fw32_find_bdf_fonts
, Sw32_find_bdf_fonts
,
6196 doc
: /* Return a list of BDF fonts in DIRECTORY.
6197 The list is suitable for appending to `w32-bdf-filename-alist'.
6198 Fonts which do not contain an xlfd description will not be included
6199 in the list. DIRECTORY may be a list of directories. */)
6201 Lisp_Object directory
;
6203 Lisp_Object list
= Qnil
;
6204 struct gcpro gcpro1
, gcpro2
;
6206 if (!CONSP (directory
))
6207 return w32_find_bdf_fonts_in_dir (directory
);
6209 for ( ; CONSP (directory
); directory
= XCDR (directory
))
6211 Lisp_Object pair
[2];
6214 GCPRO2 (directory
, list
);
6215 pair
[1] = w32_find_bdf_fonts_in_dir( XCAR (directory
) );
6216 list
= Fnconc( 2, pair
);
6223 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
6224 doc
: /* Internal function called by `color-defined-p', which see. */)
6226 Lisp_Object color
, frame
;
6229 FRAME_PTR f
= check_x_frame (frame
);
6231 CHECK_STRING (color
);
6233 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
6239 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
6240 doc
: /* Internal function called by `color-values', which see. */)
6242 Lisp_Object color
, frame
;
6245 FRAME_PTR f
= check_x_frame (frame
);
6247 CHECK_STRING (color
);
6249 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
6253 rgb
[0] = make_number ((GetRValue (foo
.pixel
) << 8)
6254 | GetRValue (foo
.pixel
));
6255 rgb
[1] = make_number ((GetGValue (foo
.pixel
) << 8)
6256 | GetGValue (foo
.pixel
));
6257 rgb
[2] = make_number ((GetBValue (foo
.pixel
) << 8)
6258 | GetBValue (foo
.pixel
));
6259 return Flist (3, rgb
);
6265 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
6266 doc
: /* Internal function called by `display-color-p', which see. */)
6268 Lisp_Object display
;
6270 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6272 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
6278 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
,
6279 Sx_display_grayscale_p
, 0, 1, 0,
6280 doc
: /* Return t if DISPLAY supports shades of gray.
6281 Note that color displays do support shades of gray.
6282 The optional argument DISPLAY specifies which display to ask about.
6283 DISPLAY should be either a frame or a display name (a string).
6284 If omitted or nil, that stands for the selected frame's display. */)
6286 Lisp_Object display
;
6288 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6290 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
6296 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
,
6297 Sx_display_pixel_width
, 0, 1, 0,
6298 doc
: /* Returns the width in pixels of DISPLAY.
6299 The optional argument DISPLAY specifies which display to ask about.
6300 DISPLAY should be either a frame or a display name (a string).
6301 If omitted or nil, that stands for the selected frame's display. */)
6303 Lisp_Object display
;
6305 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6307 return make_number (dpyinfo
->width
);
6310 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
6311 Sx_display_pixel_height
, 0, 1, 0,
6312 doc
: /* Returns the height in pixels of DISPLAY.
6313 The optional argument DISPLAY specifies which display to ask about.
6314 DISPLAY should be either a frame or a display name (a string).
6315 If omitted or nil, that stands for the selected frame's display. */)
6317 Lisp_Object display
;
6319 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6321 return make_number (dpyinfo
->height
);
6324 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
6326 doc
: /* Returns the number of bitplanes of DISPLAY.
6327 The optional argument DISPLAY specifies which display to ask about.
6328 DISPLAY should be either a frame or a display name (a string).
6329 If omitted or nil, that stands for the selected frame's display. */)
6331 Lisp_Object display
;
6333 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6335 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
6338 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
6340 doc
: /* Returns the number of color cells of DISPLAY.
6341 The optional argument DISPLAY specifies which display to ask about.
6342 DISPLAY should be either a frame or a display name (a string).
6343 If omitted or nil, that stands for the selected frame's display. */)
6345 Lisp_Object display
;
6347 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6351 hdc
= GetDC (dpyinfo
->root_window
);
6352 if (dpyinfo
->has_palette
)
6353 cap
= GetDeviceCaps (hdc
, SIZEPALETTE
);
6355 cap
= GetDeviceCaps (hdc
, NUMCOLORS
);
6357 /* We force 24+ bit depths to 24-bit, both to prevent an overflow
6358 and because probably is more meaningful on Windows anyway */
6360 cap
= 1 << min(dpyinfo
->n_planes
* dpyinfo
->n_cbits
, 24);
6362 ReleaseDC (dpyinfo
->root_window
, hdc
);
6364 return make_number (cap
);
6367 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
6368 Sx_server_max_request_size
,
6370 doc
: /* Returns the maximum request size of the server of DISPLAY.
6371 The optional argument DISPLAY specifies which display to ask about.
6372 DISPLAY should be either a frame or a display name (a string).
6373 If omitted or nil, that stands for the selected frame's display. */)
6375 Lisp_Object display
;
6377 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6379 return make_number (1);
6382 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
6383 doc
: /* Returns the vendor ID string of the W32 system (Microsoft).
6384 The optional argument DISPLAY specifies which display to ask about.
6385 DISPLAY should be either a frame or a display name (a string).
6386 If omitted or nil, that stands for the selected frame's display. */)
6388 Lisp_Object display
;
6390 return build_string ("Microsoft Corp.");
6393 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
6394 doc
: /* Returns the version numbers of the server of DISPLAY.
6395 The value is a list of three integers: the major and minor
6396 version numbers, and the vendor-specific release
6397 number. See also the function `x-server-vendor'.
6399 The optional argument DISPLAY specifies which display to ask about.
6400 DISPLAY should be either a frame or a display name (a string).
6401 If omitted or nil, that stands for the selected frame's display. */)
6403 Lisp_Object display
;
6405 return Fcons (make_number (w32_major_version
),
6406 Fcons (make_number (w32_minor_version
),
6407 Fcons (make_number (w32_build_number
), Qnil
)));
6410 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
6411 doc
: /* Returns the number of screens on the server of DISPLAY.
6412 The optional argument DISPLAY specifies which display to ask about.
6413 DISPLAY should be either a frame or a display name (a string).
6414 If omitted or nil, that stands for the selected frame's display. */)
6416 Lisp_Object display
;
6418 return make_number (1);
6421 DEFUN ("x-display-mm-height", Fx_display_mm_height
,
6422 Sx_display_mm_height
, 0, 1, 0,
6423 doc
: /* Returns the height in millimeters of DISPLAY.
6424 The optional argument DISPLAY specifies which display to ask about.
6425 DISPLAY should be either a frame or a display name (a string).
6426 If omitted or nil, that stands for the selected frame's display. */)
6428 Lisp_Object display
;
6430 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6434 hdc
= GetDC (dpyinfo
->root_window
);
6436 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
6438 ReleaseDC (dpyinfo
->root_window
, hdc
);
6440 return make_number (cap
);
6443 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
6444 doc
: /* Returns the width in millimeters of DISPLAY.
6445 The optional argument DISPLAY specifies which display to ask about.
6446 DISPLAY should be either a frame or a display name (a string).
6447 If omitted or nil, that stands for the selected frame's display. */)
6449 Lisp_Object display
;
6451 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6456 hdc
= GetDC (dpyinfo
->root_window
);
6458 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
6460 ReleaseDC (dpyinfo
->root_window
, hdc
);
6462 return make_number (cap
);
6465 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
6466 Sx_display_backing_store
, 0, 1, 0,
6467 doc
: /* Returns an indication of whether DISPLAY does backing store.
6468 The value may be `always', `when-mapped', or `not-useful'.
6469 The optional argument DISPLAY specifies which display to ask about.
6470 DISPLAY should be either a frame or a display name (a string).
6471 If omitted or nil, that stands for the selected frame's display. */)
6473 Lisp_Object display
;
6475 return intern ("not-useful");
6478 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
6479 Sx_display_visual_class
, 0, 1, 0,
6480 doc
: /* Returns the visual class of DISPLAY.
6481 The value is one of the symbols `static-gray', `gray-scale',
6482 `static-color', `pseudo-color', `true-color', or `direct-color'.
6484 The optional argument DISPLAY specifies which display to ask about.
6485 DISPLAY should be either a frame or a display name (a string).
6486 If omitted or nil, that stands for the selected frame's display. */)
6488 Lisp_Object display
;
6490 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6491 Lisp_Object result
= Qnil
;
6493 if (dpyinfo
->has_palette
)
6494 result
= intern ("pseudo-color");
6495 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
6496 result
= intern ("static-grey");
6497 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
6498 result
= intern ("static-color");
6499 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
6500 result
= intern ("true-color");
6505 DEFUN ("x-display-save-under", Fx_display_save_under
,
6506 Sx_display_save_under
, 0, 1, 0,
6507 doc
: /* Returns t if DISPLAY supports the save-under feature.
6508 The optional argument DISPLAY specifies which display to ask about.
6509 DISPLAY should be either a frame or a display name (a string).
6510 If omitted or nil, that stands for the selected frame's display. */)
6512 Lisp_Object display
;
6519 register struct frame
*f
;
6521 return FRAME_PIXEL_WIDTH (f
);
6526 register struct frame
*f
;
6528 return FRAME_PIXEL_HEIGHT (f
);
6533 register struct frame
*f
;
6535 return FRAME_COLUMN_WIDTH (f
);
6540 register struct frame
*f
;
6542 return FRAME_LINE_HEIGHT (f
);
6547 register struct frame
*f
;
6549 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
6552 /* Return the display structure for the display named NAME.
6553 Open a new connection if necessary. */
6555 struct w32_display_info
*
6556 x_display_info_for_name (name
)
6560 struct w32_display_info
*dpyinfo
;
6562 CHECK_STRING (name
);
6564 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
6566 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
6569 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
6574 /* Use this general default value to start with. */
6575 Vx_resource_name
= Vinvocation_name
;
6577 validate_x_resource_name ();
6579 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
6580 (char *) SDATA (Vx_resource_name
));
6583 error ("Cannot connect to server %s", SDATA (name
));
6586 XSETFASTINT (Vwindow_system_version
, 3);
6591 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
6592 1, 3, 0, doc
: /* Open a connection to a server.
6593 DISPLAY is the name of the display to connect to.
6594 Optional second arg XRM-STRING is a string of resources in xrdb format.
6595 If the optional third arg MUST-SUCCEED is non-nil,
6596 terminate Emacs if we can't open the connection. */)
6597 (display
, xrm_string
, must_succeed
)
6598 Lisp_Object display
, xrm_string
, must_succeed
;
6600 unsigned char *xrm_option
;
6601 struct w32_display_info
*dpyinfo
;
6603 /* If initialization has already been done, return now to avoid
6604 overwriting critical parts of one_w32_display_info. */
6608 CHECK_STRING (display
);
6609 if (! NILP (xrm_string
))
6610 CHECK_STRING (xrm_string
);
6612 if (! EQ (Vwindow_system
, intern ("w32")))
6613 error ("Not using Microsoft Windows");
6615 /* Allow color mapping to be defined externally; first look in user's
6616 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
6618 Lisp_Object color_file
;
6619 struct gcpro gcpro1
;
6621 color_file
= build_string("~/rgb.txt");
6623 GCPRO1 (color_file
);
6625 if (NILP (Ffile_readable_p (color_file
)))
6627 Fexpand_file_name (build_string ("rgb.txt"),
6628 Fsymbol_value (intern ("data-directory")));
6630 Vw32_color_map
= Fw32_load_color_file (color_file
);
6634 if (NILP (Vw32_color_map
))
6635 Vw32_color_map
= Fw32_default_color_map ();
6637 /* Merge in system logical colors. */
6638 add_system_logical_colors_to_map (&Vw32_color_map
);
6640 if (! NILP (xrm_string
))
6641 xrm_option
= (unsigned char *) SDATA (xrm_string
);
6643 xrm_option
= (unsigned char *) 0;
6645 /* Use this general default value to start with. */
6646 /* First remove .exe suffix from invocation-name - it looks ugly. */
6648 char basename
[ MAX_PATH
], *str
;
6650 strcpy (basename
, SDATA (Vinvocation_name
));
6651 str
= strrchr (basename
, '.');
6653 Vinvocation_name
= build_string (basename
);
6655 Vx_resource_name
= Vinvocation_name
;
6657 validate_x_resource_name ();
6659 /* This is what opens the connection and sets x_current_display.
6660 This also initializes many symbols, such as those used for input. */
6661 dpyinfo
= w32_term_init (display
, xrm_option
,
6662 (char *) SDATA (Vx_resource_name
));
6666 if (!NILP (must_succeed
))
6667 fatal ("Cannot connect to server %s.\n",
6670 error ("Cannot connect to server %s", SDATA (display
));
6675 XSETFASTINT (Vwindow_system_version
, 3);
6679 DEFUN ("x-close-connection", Fx_close_connection
,
6680 Sx_close_connection
, 1, 1, 0,
6681 doc
: /* Close the connection to DISPLAY's server.
6682 For DISPLAY, specify either a frame or a display name (a string).
6683 If DISPLAY is nil, that stands for the selected frame's display. */)
6685 Lisp_Object display
;
6687 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6690 if (dpyinfo
->reference_count
> 0)
6691 error ("Display still has frames on it");
6694 /* Free the fonts in the font table. */
6695 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
6696 if (dpyinfo
->font_table
[i
].name
)
6698 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
6699 xfree (dpyinfo
->font_table
[i
].full_name
);
6700 xfree (dpyinfo
->font_table
[i
].name
);
6701 w32_unload_font (dpyinfo
, dpyinfo
->font_table
[i
].font
);
6703 x_destroy_all_bitmaps (dpyinfo
);
6705 x_delete_display (dpyinfo
);
6711 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
6712 doc
: /* Return the list of display names that Emacs has connections to. */)
6715 Lisp_Object tail
, result
;
6718 for (tail
= w32_display_name_list
; ! NILP (tail
); tail
= XCDR (tail
))
6719 result
= Fcons (XCAR (XCAR (tail
)), result
);
6724 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
6725 doc
: /* This is a noop on W32 systems. */)
6727 Lisp_Object display
, on
;
6734 /***********************************************************************
6736 ***********************************************************************/
6738 DEFUN ("x-change-window-property", Fx_change_window_property
,
6739 Sx_change_window_property
, 2, 6, 0,
6740 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
6741 VALUE may be a string or a list of conses, numbers and/or strings.
6742 If an element in the list is a string, it is converted to
6743 an Atom and the value of the Atom is used. If an element is a cons,
6744 it is converted to a 32 bit number where the car is the 16 top bits and the
6745 cdr is the lower 16 bits.
6746 FRAME nil or omitted means use the selected frame.
6747 If TYPE is given and non-nil, it is the name of the type of VALUE.
6748 If TYPE is not given or nil, the type is STRING.
6749 FORMAT gives the size in bits of each element if VALUE is a list.
6750 It must be one of 8, 16 or 32.
6751 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
6752 If OUTER_P is non-nil, the property is changed for the outer X window of
6753 FRAME. Default is to change on the edit X window.
6756 (prop
, value
, frame
, type
, format
, outer_p
)
6757 Lisp_Object prop
, value
, frame
, type
, format
, outer_p
;
6759 #if 0 /* TODO : port window properties to W32 */
6760 struct frame
*f
= check_x_frame (frame
);
6763 CHECK_STRING (prop
);
6764 CHECK_STRING (value
);
6767 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
6768 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
6769 prop_atom
, XA_STRING
, 8, PropModeReplace
,
6770 SDATA (value
), SCHARS (value
));
6772 /* Make sure the property is set when we return. */
6773 XFlush (FRAME_W32_DISPLAY (f
));
6782 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
6783 Sx_delete_window_property
, 1, 2, 0,
6784 doc
: /* Remove window property PROP from X window of FRAME.
6785 FRAME nil or omitted means use the selected frame. Value is PROP. */)
6787 Lisp_Object prop
, frame
;
6789 #if 0 /* TODO : port window properties to W32 */
6791 struct frame
*f
= check_x_frame (frame
);
6794 CHECK_STRING (prop
);
6796 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
6797 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
6799 /* Make sure the property is removed when we return. */
6800 XFlush (FRAME_W32_DISPLAY (f
));
6808 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
6810 doc
: /* Value is the value of window property PROP on FRAME.
6811 If FRAME is nil or omitted, use the selected frame. Value is nil
6812 if FRAME hasn't a property with name PROP or if PROP has no string
6815 Lisp_Object prop
, frame
;
6817 #if 0 /* TODO : port window properties to W32 */
6819 struct frame
*f
= check_x_frame (frame
);
6822 Lisp_Object prop_value
= Qnil
;
6823 char *tmp_data
= NULL
;
6826 unsigned long actual_size
, bytes_remaining
;
6828 CHECK_STRING (prop
);
6830 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
6831 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
6832 prop_atom
, 0, 0, False
, XA_STRING
,
6833 &actual_type
, &actual_format
, &actual_size
,
6834 &bytes_remaining
, (unsigned char **) &tmp_data
);
6837 int size
= bytes_remaining
;
6842 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
6843 prop_atom
, 0, bytes_remaining
,
6845 &actual_type
, &actual_format
,
6846 &actual_size
, &bytes_remaining
,
6847 (unsigned char **) &tmp_data
);
6849 prop_value
= make_string (tmp_data
, size
);
6864 /***********************************************************************
6866 ***********************************************************************/
6868 /* If non-null, an asynchronous timer that, when it expires, displays
6869 an hourglass cursor on all frames. */
6871 static struct atimer
*hourglass_atimer
;
6873 /* Non-zero means an hourglass cursor is currently shown. */
6875 static int hourglass_shown_p
;
6877 /* Number of seconds to wait before displaying an hourglass cursor. */
6879 static Lisp_Object Vhourglass_delay
;
6881 /* Default number of seconds to wait before displaying an hourglass
6884 #define DEFAULT_HOURGLASS_DELAY 1
6886 /* Function prototypes. */
6888 static void show_hourglass
P_ ((struct atimer
*));
6889 static void hide_hourglass
P_ ((void));
6892 /* Cancel a currently active hourglass timer, and start a new one. */
6897 #if 0 /* TODO: cursor shape changes. */
6899 int secs
, usecs
= 0;
6901 cancel_hourglass ();
6903 if (INTEGERP (Vhourglass_delay
)
6904 && XINT (Vhourglass_delay
) > 0)
6905 secs
= XFASTINT (Vhourglass_delay
);
6906 else if (FLOATP (Vhourglass_delay
)
6907 && XFLOAT_DATA (Vhourglass_delay
) > 0)
6910 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
6911 secs
= XFASTINT (tem
);
6912 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
6915 secs
= DEFAULT_HOURGLASS_DELAY
;
6917 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
6918 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
6919 show_hourglass
, NULL
);
6924 /* Cancel the hourglass cursor timer if active, hide an hourglass
6930 if (hourglass_atimer
)
6932 cancel_atimer (hourglass_atimer
);
6933 hourglass_atimer
= NULL
;
6936 if (hourglass_shown_p
)
6941 /* Timer function of hourglass_atimer. TIMER is equal to
6944 Display an hourglass cursor on all frames by mapping the frames'
6945 hourglass_window. Set the hourglass_p flag in the frames'
6946 output_data.x structure to indicate that an hourglass cursor is
6947 shown on the frames. */
6950 show_hourglass (timer
)
6951 struct atimer
*timer
;
6953 #if 0 /* TODO: cursor shape changes. */
6954 /* The timer implementation will cancel this timer automatically
6955 after this function has run. Set hourglass_atimer to null
6956 so that we know the timer doesn't have to be canceled. */
6957 hourglass_atimer
= NULL
;
6959 if (!hourglass_shown_p
)
6961 Lisp_Object rest
, frame
;
6965 FOR_EACH_FRAME (rest
, frame
)
6966 if (FRAME_W32_P (XFRAME (frame
)))
6968 struct frame
*f
= XFRAME (frame
);
6970 f
->output_data
.w32
->hourglass_p
= 1;
6972 if (!f
->output_data
.w32
->hourglass_window
)
6974 unsigned long mask
= CWCursor
;
6975 XSetWindowAttributes attrs
;
6977 attrs
.cursor
= f
->output_data
.w32
->hourglass_cursor
;
6979 f
->output_data
.w32
->hourglass_window
6980 = XCreateWindow (FRAME_X_DISPLAY (f
),
6981 FRAME_OUTER_WINDOW (f
),
6982 0, 0, 32000, 32000, 0, 0,
6988 XMapRaised (FRAME_X_DISPLAY (f
),
6989 f
->output_data
.w32
->hourglass_window
);
6990 XFlush (FRAME_X_DISPLAY (f
));
6993 hourglass_shown_p
= 1;
7000 /* Hide the hourglass cursor on all frames, if it is currently shown. */
7005 #if 0 /* TODO: cursor shape changes. */
7006 if (hourglass_shown_p
)
7008 Lisp_Object rest
, frame
;
7011 FOR_EACH_FRAME (rest
, frame
)
7013 struct frame
*f
= XFRAME (frame
);
7016 /* Watch out for newly created frames. */
7017 && f
->output_data
.x
->hourglass_window
)
7019 XUnmapWindow (FRAME_X_DISPLAY (f
),
7020 f
->output_data
.x
->hourglass_window
);
7021 /* Sync here because XTread_socket looks at the
7022 hourglass_p flag that is reset to zero below. */
7023 XSync (FRAME_X_DISPLAY (f
), False
);
7024 f
->output_data
.x
->hourglass_p
= 0;
7028 hourglass_shown_p
= 0;
7036 /***********************************************************************
7038 ***********************************************************************/
7040 static Lisp_Object x_create_tip_frame
P_ ((struct w32_display_info
*,
7041 Lisp_Object
, Lisp_Object
));
7042 static void compute_tip_xy
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
7043 Lisp_Object
, int, int, int *, int *));
7045 /* The frame of a currently visible tooltip. */
7047 Lisp_Object tip_frame
;
7049 /* If non-nil, a timer started that hides the last tooltip when it
7052 Lisp_Object tip_timer
;
7055 /* If non-nil, a vector of 3 elements containing the last args
7056 with which x-show-tip was called. See there. */
7058 Lisp_Object last_show_tip_args
;
7060 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
7062 Lisp_Object Vx_max_tooltip_size
;
7066 unwind_create_tip_frame (frame
)
7069 Lisp_Object deleted
;
7071 deleted
= unwind_create_frame (frame
);
7072 if (EQ (deleted
, Qt
))
7082 /* Create a frame for a tooltip on the display described by DPYINFO.
7083 PARMS is a list of frame parameters. TEXT is the string to
7084 display in the tip frame. Value is the frame.
7086 Note that functions called here, esp. x_default_parameter can
7087 signal errors, for instance when a specified color name is
7088 undefined. We have to make sure that we're in a consistent state
7089 when this happens. */
7092 x_create_tip_frame (dpyinfo
, parms
, text
)
7093 struct w32_display_info
*dpyinfo
;
7094 Lisp_Object parms
, text
;
7097 Lisp_Object frame
, tem
;
7099 long window_prompting
= 0;
7101 int count
= SPECPDL_INDEX ();
7102 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7104 int face_change_count_before
= face_change_count
;
7106 struct buffer
*old_buffer
;
7110 /* Use this general default value to start with until we know if
7111 this frame has a specified name. */
7112 Vx_resource_name
= Vinvocation_name
;
7115 kb
= dpyinfo
->kboard
;
7117 kb
= &the_only_kboard
;
7120 /* Get the name of the frame to use for resource lookup. */
7121 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
7123 && !EQ (name
, Qunbound
)
7125 error ("Invalid frame name--not a string or nil");
7126 Vx_resource_name
= name
;
7129 GCPRO3 (parms
, name
, frame
);
7130 /* Make a frame without minibuffer nor mode-line. */
7132 f
->wants_modeline
= 0;
7133 XSETFRAME (frame
, f
);
7135 buffer
= Fget_buffer_create (build_string (" *tip*"));
7136 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, Qnil
);
7137 old_buffer
= current_buffer
;
7138 set_buffer_internal_1 (XBUFFER (buffer
));
7139 current_buffer
->truncate_lines
= Qnil
;
7140 specbind (Qinhibit_read_only
, Qt
);
7141 specbind (Qinhibit_modification_hooks
, Qt
);
7144 set_buffer_internal_1 (old_buffer
);
7146 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
7147 record_unwind_protect (unwind_create_tip_frame
, frame
);
7149 /* By setting the output method, we're essentially saying that
7150 the frame is live, as per FRAME_LIVE_P. If we get a signal
7151 from this point on, x_destroy_window might screw up reference
7153 f
->output_method
= output_w32
;
7154 f
->output_data
.w32
=
7155 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
7156 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
7158 FRAME_FONTSET (f
) = -1;
7159 f
->icon_name
= Qnil
;
7161 #if 0 /* GLYPH_DEBUG TODO: image support. */
7162 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
7163 dpyinfo_refcount
= dpyinfo
->reference_count
;
7164 #endif /* GLYPH_DEBUG */
7166 FRAME_KBOARD (f
) = kb
;
7168 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
7169 f
->output_data
.w32
->explicit_parent
= 0;
7171 /* Set the name; the functions to which we pass f expect the name to
7173 if (EQ (name
, Qunbound
) || NILP (name
))
7175 f
->name
= build_string (dpyinfo
->w32_id_name
);
7176 f
->explicit_name
= 0;
7181 f
->explicit_name
= 1;
7182 /* use the frame's title when getting resources for this frame. */
7183 specbind (Qx_resource_name
, name
);
7186 /* Extract the window parameters from the supplied values
7187 that are needed to determine window geometry. */
7191 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
7194 /* First, try whatever font the caller has specified. */
7197 tem
= Fquery_fontset (font
, Qnil
);
7199 font
= x_new_fontset (f
, SDATA (tem
));
7201 font
= x_new_font (f
, SDATA (font
));
7204 /* Try out a font which we hope has bold and italic variations. */
7205 if (!STRINGP (font
))
7206 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
7207 if (! STRINGP (font
))
7208 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
7209 /* If those didn't work, look for something which will at least work. */
7210 if (! STRINGP (font
))
7211 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
7213 if (! STRINGP (font
))
7214 font
= build_string ("Fixedsys");
7216 x_default_parameter (f
, parms
, Qfont
, font
,
7217 "font", "Font", RES_TYPE_STRING
);
7220 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
7221 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
7222 /* This defaults to 2 in order to match xterm. We recognize either
7223 internalBorderWidth or internalBorder (which is what xterm calls
7225 if (NILP (Fassq (Qinternal_border_width
, parms
)))
7229 value
= w32_get_arg (parms
, Qinternal_border_width
,
7230 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
7231 if (! EQ (value
, Qunbound
))
7232 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
7235 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
7236 "internalBorderWidth", "internalBorderWidth",
7239 /* Also do the stuff which must be set before the window exists. */
7240 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
7241 "foreground", "Foreground", RES_TYPE_STRING
);
7242 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
7243 "background", "Background", RES_TYPE_STRING
);
7244 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
7245 "pointerColor", "Foreground", RES_TYPE_STRING
);
7246 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
7247 "cursorColor", "Foreground", RES_TYPE_STRING
);
7248 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
7249 "borderColor", "BorderColor", RES_TYPE_STRING
);
7251 /* Init faces before x_default_parameter is called for scroll-bar
7252 parameters because that function calls x_set_scroll_bar_width,
7253 which calls change_frame_size, which calls Fset_window_buffer,
7254 which runs hooks, which call Fvertical_motion. At the end, we
7255 end up in init_iterator with a null face cache, which should not
7257 init_frame_faces (f
);
7259 f
->output_data
.w32
->dwStyle
= WS_BORDER
| WS_POPUP
| WS_DISABLED
;
7260 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
7262 window_prompting
= x_figure_window_size (f
, parms
, 0);
7264 /* No fringes on tip frame. */
7266 f
->left_fringe_width
= 0;
7267 f
->right_fringe_width
= 0;
7270 my_create_tip_window (f
);
7275 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
7276 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
7277 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
7278 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
7279 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
7280 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
7282 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
7283 Change will not be effected unless different from the current
7285 width
= FRAME_COLS (f
);
7286 height
= FRAME_LINES (f
);
7287 FRAME_LINES (f
) = 0;
7288 SET_FRAME_COLS (f
, 0);
7289 change_frame_size (f
, height
, width
, 1, 0, 0);
7291 /* Add `tooltip' frame parameter's default value. */
7292 if (NILP (Fframe_parameter (frame
, intern ("tooltip"))))
7293 Fmodify_frame_parameters (frame
, Fcons (Fcons (intern ("tooltip"), Qt
),
7296 /* Set up faces after all frame parameters are known. This call
7297 also merges in face attributes specified for new frames.
7299 Frame parameters may be changed if .Xdefaults contains
7300 specifications for the default font. For example, if there is an
7301 `Emacs.default.attributeBackground: pink', the `background-color'
7302 attribute of the frame get's set, which let's the internal border
7303 of the tooltip frame appear in pink. Prevent this. */
7305 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
7307 /* Set tip_frame here, so that */
7309 call1 (Qface_set_after_frame_default
, frame
);
7311 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
7312 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qbackground_color
, bg
),
7320 /* It is now ok to make the frame official even if we get an error
7321 below. And the frame needs to be on Vframe_list or making it
7322 visible won't work. */
7323 Vframe_list
= Fcons (frame
, Vframe_list
);
7325 /* Now that the frame is official, it counts as a reference to
7327 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
7329 /* Setting attributes of faces of the tooltip frame from resources
7330 and similar will increment face_change_count, which leads to the
7331 clearing of all current matrices. Since this isn't necessary
7332 here, avoid it by resetting face_change_count to the value it
7333 had before we created the tip frame. */
7334 face_change_count
= face_change_count_before
;
7336 /* Discard the unwind_protect. */
7337 return unbind_to (count
, frame
);
7341 /* Compute where to display tip frame F. PARMS is the list of frame
7342 parameters for F. DX and DY are specified offsets from the current
7343 location of the mouse. WIDTH and HEIGHT are the width and height
7344 of the tooltip. Return coordinates relative to the root window of
7345 the display in *ROOT_X, and *ROOT_Y. */
7348 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, root_x
, root_y
)
7350 Lisp_Object parms
, dx
, dy
;
7352 int *root_x
, *root_y
;
7354 Lisp_Object left
, top
;
7356 /* User-specified position? */
7357 left
= Fcdr (Fassq (Qleft
, parms
));
7358 top
= Fcdr (Fassq (Qtop
, parms
));
7360 /* Move the tooltip window where the mouse pointer is. Resize and
7362 if (!INTEGERP (left
) || !INTEGERP (top
))
7374 *root_y
= XINT (top
);
7375 else if (*root_y
+ XINT (dy
) - height
< 0)
7376 *root_y
-= XINT (dy
);
7380 *root_y
+= XINT (dy
);
7383 if (INTEGERP (left
))
7384 *root_x
= XINT (left
);
7385 else if (*root_x
+ XINT (dx
) + width
<= FRAME_W32_DISPLAY_INFO (f
)->width
)
7386 /* It fits to the right of the pointer. */
7387 *root_x
+= XINT (dx
);
7388 else if (width
+ XINT (dx
) <= *root_x
)
7389 /* It fits to the left of the pointer. */
7390 *root_x
-= width
+ XINT (dx
);
7392 /* Put it left justified on the screen -- it ought to fit that way. */
7397 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
7398 doc
: /* Show STRING in a \"tooltip\" window on frame FRAME.
7399 A tooltip window is a small window displaying a string.
7401 FRAME nil or omitted means use the selected frame.
7403 PARMS is an optional list of frame parameters which can be
7404 used to change the tooltip's appearance.
7406 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
7407 means use the default timeout of 5 seconds.
7409 If the list of frame parameters PARMS contains a `left' parameter,
7410 the tooltip is displayed at that x-position. Otherwise it is
7411 displayed at the mouse position, with offset DX added (default is 5 if
7412 DX isn't specified). Likewise for the y-position; if a `top' frame
7413 parameter is specified, it determines the y-position of the tooltip
7414 window, otherwise it is displayed at the mouse position, with offset
7415 DY added (default is -10).
7417 A tooltip's maximum size is specified by `x-max-tooltip-size'.
7418 Text larger than the specified size is clipped. */)
7419 (string
, frame
, parms
, timeout
, dx
, dy
)
7420 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
7425 struct buffer
*old_buffer
;
7426 struct text_pos pos
;
7427 int i
, width
, height
;
7428 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7429 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7430 int count
= SPECPDL_INDEX ();
7432 specbind (Qinhibit_redisplay
, Qt
);
7434 GCPRO4 (string
, parms
, frame
, timeout
);
7436 CHECK_STRING (string
);
7437 f
= check_x_frame (frame
);
7439 timeout
= make_number (5);
7441 CHECK_NATNUM (timeout
);
7444 dx
= make_number (5);
7449 dy
= make_number (-10);
7453 if (NILP (last_show_tip_args
))
7454 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
7456 if (!NILP (tip_frame
))
7458 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
7459 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
7460 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
7462 if (EQ (frame
, last_frame
)
7463 && !NILP (Fequal (last_string
, string
))
7464 && !NILP (Fequal (last_parms
, parms
)))
7466 struct frame
*f
= XFRAME (tip_frame
);
7468 /* Only DX and DY have changed. */
7469 if (!NILP (tip_timer
))
7471 Lisp_Object timer
= tip_timer
;
7473 call1 (Qcancel_timer
, timer
);
7477 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
7478 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
7480 /* Put tooltip in topmost group and in position. */
7481 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
7482 root_x
, root_y
, 0, 0,
7483 SWP_NOSIZE
| SWP_NOACTIVATE
);
7485 /* Ensure tooltip is on top of other topmost windows (eg menus). */
7486 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
7488 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
7495 /* Hide a previous tip, if any. */
7498 ASET (last_show_tip_args
, 0, string
);
7499 ASET (last_show_tip_args
, 1, frame
);
7500 ASET (last_show_tip_args
, 2, parms
);
7502 /* Add default values to frame parameters. */
7503 if (NILP (Fassq (Qname
, parms
)))
7504 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
7505 if (NILP (Fassq (Qinternal_border_width
, parms
)))
7506 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
7507 if (NILP (Fassq (Qborder_width
, parms
)))
7508 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
7509 if (NILP (Fassq (Qborder_color
, parms
)))
7510 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
7511 if (NILP (Fassq (Qbackground_color
, parms
)))
7512 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
7515 /* Block input until the tip has been fully drawn, to avoid crashes
7516 when drawing tips in menus. */
7519 /* Create a frame for the tooltip, and record it in the global
7520 variable tip_frame. */
7521 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
, string
);
7524 /* Set up the frame's root window. */
7525 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7526 w
->left_col
= w
->top_line
= make_number (0);
7528 if (CONSP (Vx_max_tooltip_size
)
7529 && INTEGERP (XCAR (Vx_max_tooltip_size
))
7530 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
7531 && INTEGERP (XCDR (Vx_max_tooltip_size
))
7532 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
7534 w
->total_cols
= XCAR (Vx_max_tooltip_size
);
7535 w
->total_lines
= XCDR (Vx_max_tooltip_size
);
7539 w
->total_cols
= make_number (80);
7540 w
->total_lines
= make_number (40);
7543 FRAME_TOTAL_COLS (f
) = XINT (w
->total_cols
);
7545 w
->pseudo_window_p
= 1;
7547 /* Display the tooltip text in a temporary buffer. */
7548 old_buffer
= current_buffer
;
7549 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
7550 current_buffer
->truncate_lines
= Qnil
;
7551 clear_glyph_matrix (w
->desired_matrix
);
7552 clear_glyph_matrix (w
->current_matrix
);
7553 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
7554 try_window (FRAME_ROOT_WINDOW (f
), pos
);
7556 /* Compute width and height of the tooltip. */
7558 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
7560 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
7564 /* Stop at the first empty row at the end. */
7565 if (!row
->enabled_p
|| !row
->displays_text_p
)
7568 /* Let the row go over the full width of the frame. */
7569 row
->full_width_p
= 1;
7571 #ifdef TODO /* Investigate why some fonts need more width than is
7572 calculated for some tooltips. */
7573 /* There's a glyph at the end of rows that is use to place
7574 the cursor there. Don't include the width of this glyph. */
7575 if (row
->used
[TEXT_AREA
])
7577 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
7578 row_width
= row
->pixel_width
- last
->pixel_width
;
7582 row_width
= row
->pixel_width
;
7584 /* TODO: find why tips do not draw along baseline as instructed. */
7585 height
+= row
->height
;
7586 width
= max (width
, row_width
);
7589 /* Add the frame's internal border to the width and height the X
7590 window should have. */
7591 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
7592 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
7594 /* Move the tooltip window where the mouse pointer is. Resize and
7596 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
7599 /* Adjust Window size to take border into account. */
7601 rect
.left
= rect
.top
= 0;
7603 rect
.bottom
= height
;
7604 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
7605 FRAME_EXTERNAL_MENU_BAR (f
));
7607 /* Position and size tooltip, and put it in the topmost group. */
7608 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
7609 root_x
, root_y
, rect
.right
- rect
.left
,
7610 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
);
7612 /* Ensure tooltip is on top of other topmost windows (eg menus). */
7613 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
7615 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
7617 /* Let redisplay know that we have made the frame visible already. */
7618 f
->async_visible
= 1;
7620 ShowWindow (FRAME_W32_WINDOW (f
), SW_SHOWNOACTIVATE
);
7623 /* Draw into the window. */
7624 w
->must_be_updated_p
= 1;
7625 update_single_window (w
, 1);
7629 /* Restore original current buffer. */
7630 set_buffer_internal_1 (old_buffer
);
7631 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7634 /* Let the tip disappear after timeout seconds. */
7635 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
7636 intern ("x-hide-tip"));
7639 return unbind_to (count
, Qnil
);
7643 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
7644 doc
: /* Hide the current tooltip window, if there is any.
7645 Value is t if tooltip was open, nil otherwise. */)
7649 Lisp_Object deleted
, frame
, timer
;
7650 struct gcpro gcpro1
, gcpro2
;
7652 /* Return quickly if nothing to do. */
7653 if (NILP (tip_timer
) && NILP (tip_frame
))
7658 GCPRO2 (frame
, timer
);
7659 tip_frame
= tip_timer
= deleted
= Qnil
;
7661 count
= SPECPDL_INDEX ();
7662 specbind (Qinhibit_redisplay
, Qt
);
7663 specbind (Qinhibit_quit
, Qt
);
7666 call1 (Qcancel_timer
, timer
);
7670 Fdelete_frame (frame
, Qnil
);
7675 return unbind_to (count
, deleted
);
7680 /***********************************************************************
7681 File selection dialog
7682 ***********************************************************************/
7683 extern Lisp_Object Qfile_name_history
;
7685 /* Callback for altering the behaviour of the Open File dialog.
7686 Makes the Filename text field contain "Current Directory" and be
7687 read-only when "Directories" is selected in the filter. This
7688 allows us to work around the fact that the standard Open File
7689 dialog does not support directories. */
7691 file_dialog_callback (hwnd
, msg
, wParam
, lParam
)
7697 if (msg
== WM_NOTIFY
)
7699 OFNOTIFY
* notify
= (OFNOTIFY
*)lParam
;
7700 /* Detect when the Filter dropdown is changed. */
7701 if (notify
->hdr
.code
== CDN_TYPECHANGE
7702 || notify
->hdr
.code
== CDN_INITDONE
)
7704 HWND dialog
= GetParent (hwnd
);
7705 HWND edit_control
= GetDlgItem (dialog
, FILE_NAME_TEXT_FIELD
);
7707 /* Directories is in index 2. */
7708 if (notify
->lpOFN
->nFilterIndex
== 2)
7710 CommDlg_OpenSave_SetControlText (dialog
, FILE_NAME_TEXT_FIELD
,
7711 "Current Directory");
7712 EnableWindow (edit_control
, FALSE
);
7716 /* Don't override default filename on init done. */
7717 if (notify
->hdr
.code
== CDN_TYPECHANGE
)
7718 CommDlg_OpenSave_SetControlText (dialog
,
7719 FILE_NAME_TEXT_FIELD
, "");
7720 EnableWindow (edit_control
, TRUE
);
7727 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 4, 0,
7728 doc
: /* Read file name, prompting with PROMPT in directory DIR.
7729 Use a file selection dialog.
7730 Select DEFAULT-FILENAME in the dialog's file selection box, if
7731 specified. Ensure that file exists if MUSTMATCH is non-nil. */)
7732 (prompt
, dir
, default_filename
, mustmatch
)
7733 Lisp_Object prompt
, dir
, default_filename
, mustmatch
;
7735 struct frame
*f
= SELECTED_FRAME ();
7736 Lisp_Object file
= Qnil
;
7737 int count
= SPECPDL_INDEX ();
7738 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
7739 char filename
[MAX_PATH
+ 1];
7740 char init_dir
[MAX_PATH
+ 1];
7741 int default_filter_index
= 1; /* 1: All Files, 2: Directories only */
7743 GCPRO5 (prompt
, dir
, default_filename
, mustmatch
, file
);
7744 CHECK_STRING (prompt
);
7747 /* Create the dialog with PROMPT as title, using DIR as initial
7748 directory and using "*" as pattern. */
7749 dir
= Fexpand_file_name (dir
, Qnil
);
7750 strncpy (init_dir
, SDATA (ENCODE_FILE (dir
)), MAX_PATH
);
7751 init_dir
[MAX_PATH
] = '\0';
7752 unixtodos_filename (init_dir
);
7754 if (STRINGP (default_filename
))
7756 char *file_name_only
;
7757 char *full_path_name
= SDATA (ENCODE_FILE (default_filename
));
7759 unixtodos_filename (full_path_name
);
7761 file_name_only
= strrchr (full_path_name
, '\\');
7762 if (!file_name_only
)
7763 file_name_only
= full_path_name
;
7767 strncpy (filename
, file_name_only
, MAX_PATH
);
7768 filename
[MAX_PATH
] = '\0';
7774 OPENFILENAME file_details
;
7776 /* Prevent redisplay. */
7777 specbind (Qinhibit_redisplay
, Qt
);
7780 bzero (&file_details
, sizeof (file_details
));
7781 file_details
.lStructSize
= sizeof (file_details
);
7782 file_details
.hwndOwner
= FRAME_W32_WINDOW (f
);
7783 /* Undocumented Bug in Common File Dialog:
7784 If a filter is not specified, shell links are not resolved. */
7785 file_details
.lpstrFilter
= "All Files (*.*)\0*.*\0Directories\0*|*\0\0";
7786 file_details
.lpstrFile
= filename
;
7787 file_details
.nMaxFile
= sizeof (filename
);
7788 file_details
.lpstrInitialDir
= init_dir
;
7789 file_details
.lpstrTitle
= SDATA (prompt
);
7791 /* If prompt starts with Dired, default to directories only. */
7792 /* A bit hacky, but there doesn't seem to be a better way to
7794 if (strncmp (file_details
.lpstrTitle
, "Dired", 5) == 0)
7795 default_filter_index
= 2;
7797 file_details
.nFilterIndex
= default_filter_index
;
7799 file_details
.Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
7800 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
7801 if (!NILP (mustmatch
))
7802 file_details
.Flags
|= OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
;
7804 file_details
.lpfnHook
= (LPOFNHOOKPROC
) file_dialog_callback
;
7806 if (GetOpenFileName (&file_details
))
7808 dostounix_filename (filename
);
7809 if (file_details
.nFilterIndex
== 2)
7811 /* "Directories" selected - strip dummy file name. */
7812 char * last
= strrchr (filename
, '/');
7816 file
= DECODE_FILE(build_string (filename
));
7818 /* User cancelled the dialog without making a selection. */
7819 else if (!CommDlgExtendedError ())
7821 /* An error occurred, fallback on reading from the mini-buffer. */
7823 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
7824 dir
, mustmatch
, dir
, Qfile_name_history
,
7825 default_filename
, Qnil
);
7828 file
= unbind_to (count
, file
);
7833 /* Make "Cancel" equivalent to C-g. */
7835 Fsignal (Qquit
, Qnil
);
7837 return unbind_to (count
, file
);
7842 /***********************************************************************
7843 w32 specialized functions
7844 ***********************************************************************/
7846 DEFUN ("w32-select-font", Fw32_select_font
, Sw32_select_font
, 0, 2, 0,
7847 doc
: /* Select a font using the W32 font dialog.
7848 Returns an X font string corresponding to the selection. */)
7849 (frame
, include_proportional
)
7850 Lisp_Object frame
, include_proportional
;
7852 FRAME_PTR f
= check_x_frame (frame
);
7860 bzero (&cf
, sizeof (cf
));
7861 bzero (&lf
, sizeof (lf
));
7863 cf
.lStructSize
= sizeof (cf
);
7864 cf
.hwndOwner
= FRAME_W32_WINDOW (f
);
7865 cf
.Flags
= CF_FORCEFONTEXIST
| CF_SCREENFONTS
| CF_NOVERTFONTS
;
7867 /* Unless include_proportional is non-nil, limit the selection to
7868 monospaced fonts. */
7869 if (NILP (include_proportional
))
7870 cf
.Flags
|= CF_FIXEDPITCHONLY
;
7874 /* Initialize as much of the font details as we can from the current
7876 hdc
= GetDC (FRAME_W32_WINDOW (f
));
7877 oldobj
= SelectObject (hdc
, FRAME_FONT (f
)->hfont
);
7878 GetTextFace (hdc
, LF_FACESIZE
, lf
.lfFaceName
);
7879 if (GetTextMetrics (hdc
, &tm
))
7881 lf
.lfHeight
= tm
.tmInternalLeading
- tm
.tmHeight
;
7882 lf
.lfWeight
= tm
.tmWeight
;
7883 lf
.lfItalic
= tm
.tmItalic
;
7884 lf
.lfUnderline
= tm
.tmUnderlined
;
7885 lf
.lfStrikeOut
= tm
.tmStruckOut
;
7886 lf
.lfCharSet
= tm
.tmCharSet
;
7887 cf
.Flags
|= CF_INITTOLOGFONTSTRUCT
;
7889 SelectObject (hdc
, oldobj
);
7890 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
7892 if (!ChooseFont (&cf
) || !w32_to_x_font (&lf
, buf
, 100, NULL
))
7895 return build_string (buf
);
7898 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
,
7899 Sw32_send_sys_command
, 1, 2, 0,
7900 doc
: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND.
7901 Some useful values for COMMAND are #xf030 to maximize frame (#xf020
7902 to minimize), #xf120 to restore frame to original size, and #xf100
7903 to activate the menubar for keyboard access. #xf140 activates the
7904 screen saver if defined.
7906 If optional parameter FRAME is not specified, use selected frame. */)
7908 Lisp_Object command
, frame
;
7910 FRAME_PTR f
= check_x_frame (frame
);
7912 CHECK_NUMBER (command
);
7914 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
7919 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
7920 doc
: /* Get Windows to perform OPERATION on DOCUMENT.
7921 This is a wrapper around the ShellExecute system function, which
7922 invokes the application registered to handle OPERATION for DOCUMENT.
7923 OPERATION is typically \"open\", \"print\" or \"explore\" (but can be
7924 nil for the default action), and DOCUMENT is typically the name of a
7925 document file or URL, but can also be a program executable to run or
7926 a directory to open in the Windows Explorer.
7928 If DOCUMENT is a program executable, PARAMETERS can be a string
7929 containing command line parameters, but otherwise should be nil.
7931 SHOW-FLAG can be used to control whether the invoked application is hidden
7932 or minimized. If SHOW-FLAG is nil, the application is displayed normally,
7933 otherwise it is an integer representing a ShowWindow flag:
7938 6 - start minimized */)
7939 (operation
, document
, parameters
, show_flag
)
7940 Lisp_Object operation
, document
, parameters
, show_flag
;
7942 Lisp_Object current_dir
;
7944 CHECK_STRING (document
);
7946 /* Encode filename and current directory. */
7947 current_dir
= ENCODE_FILE (current_buffer
->directory
);
7948 document
= ENCODE_FILE (document
);
7949 if ((int) ShellExecute (NULL
,
7950 (STRINGP (operation
) ?
7951 SDATA (operation
) : NULL
),
7953 (STRINGP (parameters
) ?
7954 SDATA (parameters
) : NULL
),
7955 SDATA (current_dir
),
7956 (INTEGERP (show_flag
) ?
7957 XINT (show_flag
) : SW_SHOWDEFAULT
))
7960 error ("ShellExecute failed: %s", w32_strerror (0));
7963 /* Lookup virtual keycode from string representing the name of a
7964 non-ascii keystroke into the corresponding virtual key, using
7965 lispy_function_keys. */
7967 lookup_vk_code (char *key
)
7971 for (i
= 0; i
< 256; i
++)
7972 if (lispy_function_keys
[i
] != 0
7973 && strcmp (lispy_function_keys
[i
], key
) == 0)
7979 /* Convert a one-element vector style key sequence to a hot key
7982 w32_parse_hot_key (key
)
7985 /* Copied from Fdefine_key and store_in_keymap. */
7986 register Lisp_Object c
;
7990 struct gcpro gcpro1
;
7994 if (XFASTINT (Flength (key
)) != 1)
7999 c
= Faref (key
, make_number (0));
8001 if (CONSP (c
) && lucid_event_type_list_p (c
))
8002 c
= Fevent_convert_list (c
);
8006 if (! INTEGERP (c
) && ! SYMBOLP (c
))
8007 error ("Key definition is invalid");
8009 /* Work out the base key and the modifiers. */
8012 c
= parse_modifiers (c
);
8013 lisp_modifiers
= XINT (Fcar (Fcdr (c
)));
8017 vk_code
= lookup_vk_code (SDATA (SYMBOL_NAME (c
)));
8019 else if (INTEGERP (c
))
8021 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
8022 /* Many ascii characters are their own virtual key code. */
8023 vk_code
= XINT (c
) & CHARACTERBITS
;
8026 if (vk_code
< 0 || vk_code
> 255)
8029 if ((lisp_modifiers
& meta_modifier
) != 0
8030 && !NILP (Vw32_alt_is_meta
))
8031 lisp_modifiers
|= alt_modifier
;
8033 /* Supply defs missing from mingw32. */
8035 #define MOD_ALT 0x0001
8036 #define MOD_CONTROL 0x0002
8037 #define MOD_SHIFT 0x0004
8038 #define MOD_WIN 0x0008
8041 /* Convert lisp modifiers to Windows hot-key form. */
8042 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
8043 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
8044 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
8045 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
8047 return HOTKEY (vk_code
, w32_modifiers
);
8050 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
,
8051 Sw32_register_hot_key
, 1, 1, 0,
8052 doc
: /* Register KEY as a hot-key combination.
8053 Certain key combinations like Alt-Tab are reserved for system use on
8054 Windows, and therefore are normally intercepted by the system. However,
8055 most of these key combinations can be received by registering them as
8056 hot-keys, overriding their special meaning.
8058 KEY must be a one element key definition in vector form that would be
8059 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta
8060 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper
8061 is always interpreted as the Windows modifier keys.
8063 The return value is the hotkey-id if registered, otherwise nil. */)
8067 key
= w32_parse_hot_key (key
);
8069 if (NILP (Fmemq (key
, w32_grabbed_keys
)))
8071 /* Reuse an empty slot if possible. */
8072 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
8074 /* Safe to add new key to list, even if we have focus. */
8076 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
8078 XSETCAR (item
, key
);
8080 /* Notify input thread about new hot-key definition, so that it
8081 takes effect without needing to switch focus. */
8082 #ifdef USE_LISP_UNION_TYPE
8083 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
8086 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
8094 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
,
8095 Sw32_unregister_hot_key
, 1, 1, 0,
8096 doc
: /* Unregister KEY as a hot-key combination. */)
8102 if (!INTEGERP (key
))
8103 key
= w32_parse_hot_key (key
);
8105 item
= Fmemq (key
, w32_grabbed_keys
);
8109 /* Notify input thread about hot-key definition being removed, so
8110 that it takes effect without needing focus switch. */
8111 #ifdef USE_LISP_UNION_TYPE
8112 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
8113 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
.i
))
8115 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
8116 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
))
8121 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
8128 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
,
8129 Sw32_registered_hot_keys
, 0, 0, 0,
8130 doc
: /* Return list of registered hot-key IDs. */)
8133 return Fcopy_sequence (w32_grabbed_keys
);
8136 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
,
8137 Sw32_reconstruct_hot_key
, 1, 1, 0,
8138 doc
: /* Convert hot-key ID to a lisp key combination.
8139 usage: (w32-reconstruct-hot-key ID) */)
8141 Lisp_Object hotkeyid
;
8143 int vk_code
, w32_modifiers
;
8146 CHECK_NUMBER (hotkeyid
);
8148 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
8149 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
8151 if (lispy_function_keys
[vk_code
])
8152 key
= intern (lispy_function_keys
[vk_code
]);
8154 key
= make_number (vk_code
);
8156 key
= Fcons (key
, Qnil
);
8157 if (w32_modifiers
& MOD_SHIFT
)
8158 key
= Fcons (Qshift
, key
);
8159 if (w32_modifiers
& MOD_CONTROL
)
8160 key
= Fcons (Qctrl
, key
);
8161 if (w32_modifiers
& MOD_ALT
)
8162 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
8163 if (w32_modifiers
& MOD_WIN
)
8164 key
= Fcons (Qhyper
, key
);
8169 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
,
8170 Sw32_toggle_lock_key
, 1, 2, 0,
8171 doc
: /* Toggle the state of the lock key KEY.
8172 KEY can be `capslock', `kp-numlock', or `scroll'.
8173 If the optional parameter NEW-STATE is a number, then the state of KEY
8174 is set to off if the low bit of NEW-STATE is zero, otherwise on. */)
8176 Lisp_Object key
, new_state
;
8180 if (EQ (key
, intern ("capslock")))
8181 vk_code
= VK_CAPITAL
;
8182 else if (EQ (key
, intern ("kp-numlock")))
8183 vk_code
= VK_NUMLOCK
;
8184 else if (EQ (key
, intern ("scroll")))
8185 vk_code
= VK_SCROLL
;
8189 if (!dwWindowsThreadId
)
8190 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
8192 #ifdef USE_LISP_UNION_TYPE
8193 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
8194 (WPARAM
) vk_code
, (LPARAM
) new_state
.i
))
8196 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
8197 (WPARAM
) vk_code
, (LPARAM
) new_state
))
8201 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
8202 return make_number (msg
.wParam
);
8207 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
8208 doc
: /* Return storage information about the file system FILENAME is on.
8209 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
8210 storage of the file system, FREE is the free storage, and AVAIL is the
8211 storage available to a non-superuser. All 3 numbers are in bytes.
8212 If the underlying system call fails, value is nil. */)
8214 Lisp_Object filename
;
8216 Lisp_Object encoded
, value
;
8218 CHECK_STRING (filename
);
8219 filename
= Fexpand_file_name (filename
, Qnil
);
8220 encoded
= ENCODE_FILE (filename
);
8224 /* Determining the required information on Windows turns out, sadly,
8225 to be more involved than one would hope. The original Win32 api
8226 call for this will return bogus information on some systems, but we
8227 must dynamically probe for the replacement api, since that was
8228 added rather late on. */
8230 HMODULE hKernel
= GetModuleHandle ("kernel32");
8231 BOOL (*pfn_GetDiskFreeSpaceEx
)
8232 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
8233 = (void *) GetProcAddress (hKernel
, "GetDiskFreeSpaceEx");
8235 /* On Windows, we may need to specify the root directory of the
8236 volume holding FILENAME. */
8237 char rootname
[MAX_PATH
];
8238 char *name
= SDATA (encoded
);
8240 /* find the root name of the volume if given */
8241 if (isalpha (name
[0]) && name
[1] == ':')
8243 rootname
[0] = name
[0];
8244 rootname
[1] = name
[1];
8248 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
8250 char *str
= rootname
;
8254 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
8264 if (pfn_GetDiskFreeSpaceEx
)
8266 /* Unsigned large integers cannot be cast to double, so
8267 use signed ones instead. */
8268 LARGE_INTEGER availbytes
;
8269 LARGE_INTEGER freebytes
;
8270 LARGE_INTEGER totalbytes
;
8272 if (pfn_GetDiskFreeSpaceEx(rootname
,
8273 (ULARGE_INTEGER
*)&availbytes
,
8274 (ULARGE_INTEGER
*)&totalbytes
,
8275 (ULARGE_INTEGER
*)&freebytes
))
8276 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
8277 make_float ((double) freebytes
.QuadPart
),
8278 make_float ((double) availbytes
.QuadPart
));
8282 DWORD sectors_per_cluster
;
8283 DWORD bytes_per_sector
;
8284 DWORD free_clusters
;
8285 DWORD total_clusters
;
8287 if (GetDiskFreeSpace(rootname
,
8288 §ors_per_cluster
,
8292 value
= list3 (make_float ((double) total_clusters
8293 * sectors_per_cluster
* bytes_per_sector
),
8294 make_float ((double) free_clusters
8295 * sectors_per_cluster
* bytes_per_sector
),
8296 make_float ((double) free_clusters
8297 * sectors_per_cluster
* bytes_per_sector
));
8304 DEFUN ("default-printer-name", Fdefault_printer_name
, Sdefault_printer_name
,
8305 0, 0, 0, doc
: /* Return the name of Windows default printer device. */)
8308 static char pname_buf
[256];
8311 PRINTER_INFO_2
*ppi2
= NULL
;
8312 DWORD dwNeeded
= 0, dwReturned
= 0;
8314 /* Retrieve the default string from Win.ini (the registry).
8315 * String will be in form "printername,drivername,portname".
8316 * This is the most portable way to get the default printer. */
8317 if (GetProfileString ("windows", "device", ",,", pname_buf
, sizeof (pname_buf
)) <= 0)
8319 /* printername precedes first "," character */
8320 strtok (pname_buf
, ",");
8321 /* We want to know more than the printer name */
8322 if (!OpenPrinter (pname_buf
, &hPrn
, NULL
))
8324 GetPrinter (hPrn
, 2, NULL
, 0, &dwNeeded
);
8327 ClosePrinter (hPrn
);
8330 /* Allocate memory for the PRINTER_INFO_2 struct */
8331 ppi2
= (PRINTER_INFO_2
*) xmalloc (dwNeeded
);
8334 ClosePrinter (hPrn
);
8337 /* Call GetPrinter() again with big enouth memory block */
8338 err
= GetPrinter (hPrn
, 2, (LPBYTE
)ppi2
, dwNeeded
, &dwReturned
);
8339 ClosePrinter (hPrn
);
8348 if (ppi2
->Attributes
& PRINTER_ATTRIBUTE_SHARED
&& ppi2
->pServerName
)
8350 /* a remote printer */
8351 if (*ppi2
->pServerName
== '\\')
8352 _snprintf(pname_buf
, sizeof (pname_buf
), "%s\\%s", ppi2
->pServerName
,
8355 _snprintf(pname_buf
, sizeof (pname_buf
), "\\\\%s\\%s", ppi2
->pServerName
,
8357 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
8361 /* a local printer */
8362 strncpy(pname_buf
, ppi2
->pPortName
, sizeof (pname_buf
));
8363 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
8364 /* `pPortName' can include several ports, delimited by ','.
8365 * we only use the first one. */
8366 strtok(pname_buf
, ",");
8371 return build_string (pname_buf
);
8374 /***********************************************************************
8376 ***********************************************************************/
8378 /* Keep this list in the same order as frame_parms in frame.c.
8379 Use 0 for unsupported frame parameters. */
8381 frame_parm_handler w32_frame_parm_handlers
[] =
8385 x_set_background_color
,
8391 x_set_foreground_color
,
8394 x_set_internal_border_width
,
8395 x_set_menu_bar_lines
,
8397 x_explicitly_set_name
,
8398 x_set_scroll_bar_width
,
8401 x_set_vertical_scroll_bars
,
8403 x_set_tool_bar_lines
,
8404 0, /* x_set_scroll_bar_foreground, */
8405 0, /* x_set_scroll_bar_background, */
8410 0, /* x_set_wait_for_wm, */
8417 globals_of_w32fns ();
8418 /* This is zero if not using MS-Windows. */
8420 track_mouse_window
= NULL
;
8422 w32_visible_system_caret_hwnd
= NULL
;
8424 Qnone
= intern ("none");
8426 Qsuppress_icon
= intern ("suppress-icon");
8427 staticpro (&Qsuppress_icon
);
8428 Qundefined_color
= intern ("undefined-color");
8429 staticpro (&Qundefined_color
);
8430 Qcancel_timer
= intern ("cancel-timer");
8431 staticpro (&Qcancel_timer
);
8433 Qhyper
= intern ("hyper");
8434 staticpro (&Qhyper
);
8435 Qsuper
= intern ("super");
8436 staticpro (&Qsuper
);
8437 Qmeta
= intern ("meta");
8439 Qalt
= intern ("alt");
8441 Qctrl
= intern ("ctrl");
8443 Qcontrol
= intern ("control");
8444 staticpro (&Qcontrol
);
8445 Qshift
= intern ("shift");
8446 staticpro (&Qshift
);
8447 /* This is the end of symbol initialization. */
8449 /* Text property `display' should be nonsticky by default. */
8450 Vtext_property_default_nonsticky
8451 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
8454 Fput (Qundefined_color
, Qerror_conditions
,
8455 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
8456 Fput (Qundefined_color
, Qerror_message
,
8457 build_string ("Undefined color"));
8459 staticpro (&w32_grabbed_keys
);
8460 w32_grabbed_keys
= Qnil
;
8462 DEFVAR_LISP ("w32-color-map", &Vw32_color_map
,
8463 doc
: /* An array of color name mappings for Windows. */);
8464 Vw32_color_map
= Qnil
;
8466 DEFVAR_LISP ("w32-pass-alt-to-system", &Vw32_pass_alt_to_system
,
8467 doc
: /* Non-nil if alt key presses are passed on to Windows.
8468 When non-nil, for example, alt pressed and released and then space will
8469 open the System menu. When nil, Emacs silently swallows alt key events. */);
8470 Vw32_pass_alt_to_system
= Qnil
;
8472 DEFVAR_LISP ("w32-alt-is-meta", &Vw32_alt_is_meta
,
8473 doc
: /* Non-nil if the alt key is to be considered the same as the meta key.
8474 When nil, Emacs will translate the alt key to the Alt modifier, and not Meta. */);
8475 Vw32_alt_is_meta
= Qt
;
8477 DEFVAR_INT ("w32-quit-key", &w32_quit_key
,
8478 doc
: /* If non-zero, the virtual key code for an alternative quit key. */);
8481 DEFVAR_LISP ("w32-pass-lwindow-to-system",
8482 &Vw32_pass_lwindow_to_system
,
8483 doc
: /* Non-nil if the left \"Windows\" key is passed on to Windows.
8484 When non-nil, the Start menu is opened by tapping the key. */);
8485 Vw32_pass_lwindow_to_system
= Qt
;
8487 DEFVAR_LISP ("w32-pass-rwindow-to-system",
8488 &Vw32_pass_rwindow_to_system
,
8489 doc
: /* Non-nil if the right \"Windows\" key is passed on to Windows.
8490 When non-nil, the Start menu is opened by tapping the key. */);
8491 Vw32_pass_rwindow_to_system
= Qt
;
8493 DEFVAR_LISP ("w32-phantom-key-code",
8494 &Vw32_phantom_key_code
,
8495 doc
: /* Virtual key code used to generate \"phantom\" key presses.
8496 Value is a number between 0 and 255.
8498 Phantom key presses are generated in order to stop the system from
8499 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or
8500 `w32-pass-rwindow-to-system' is nil. */);
8501 /* Although 255 is technically not a valid key code, it works and
8502 means that this hack won't interfere with any real key code. */
8503 XSETINT (Vw32_phantom_key_code
, 255);
8505 DEFVAR_LISP ("w32-enable-num-lock",
8506 &Vw32_enable_num_lock
,
8507 doc
: /* Non-nil if Num Lock should act normally.
8508 Set to nil to see Num Lock as the key `kp-numlock'. */);
8509 Vw32_enable_num_lock
= Qt
;
8511 DEFVAR_LISP ("w32-enable-caps-lock",
8512 &Vw32_enable_caps_lock
,
8513 doc
: /* Non-nil if Caps Lock should act normally.
8514 Set to nil to see Caps Lock as the key `capslock'. */);
8515 Vw32_enable_caps_lock
= Qt
;
8517 DEFVAR_LISP ("w32-scroll-lock-modifier",
8518 &Vw32_scroll_lock_modifier
,
8519 doc
: /* Modifier to use for the Scroll Lock on state.
8520 The value can be hyper, super, meta, alt, control or shift for the
8521 respective modifier, or nil to see Scroll Lock as the key `scroll'.
8522 Any other value will cause the key to be ignored. */);
8523 Vw32_scroll_lock_modifier
= Qt
;
8525 DEFVAR_LISP ("w32-lwindow-modifier",
8526 &Vw32_lwindow_modifier
,
8527 doc
: /* Modifier to use for the left \"Windows\" key.
8528 The value can be hyper, super, meta, alt, control or shift for the
8529 respective modifier, or nil to appear as the key `lwindow'.
8530 Any other value will cause the key to be ignored. */);
8531 Vw32_lwindow_modifier
= Qnil
;
8533 DEFVAR_LISP ("w32-rwindow-modifier",
8534 &Vw32_rwindow_modifier
,
8535 doc
: /* Modifier to use for the right \"Windows\" key.
8536 The value can be hyper, super, meta, alt, control or shift for the
8537 respective modifier, or nil to appear as the key `rwindow'.
8538 Any other value will cause the key to be ignored. */);
8539 Vw32_rwindow_modifier
= Qnil
;
8541 DEFVAR_LISP ("w32-apps-modifier",
8542 &Vw32_apps_modifier
,
8543 doc
: /* Modifier to use for the \"Apps\" key.
8544 The value can be hyper, super, meta, alt, control or shift for the
8545 respective modifier, or nil to appear as the key `apps'.
8546 Any other value will cause the key to be ignored. */);
8547 Vw32_apps_modifier
= Qnil
;
8549 DEFVAR_BOOL ("w32-enable-synthesized-fonts", &w32_enable_synthesized_fonts
,
8550 doc
: /* Non-nil enables selection of artificially italicized and bold fonts. */);
8551 w32_enable_synthesized_fonts
= 0;
8553 DEFVAR_LISP ("w32-enable-palette", &Vw32_enable_palette
,
8554 doc
: /* Non-nil enables Windows palette management to map colors exactly. */);
8555 Vw32_enable_palette
= Qt
;
8557 DEFVAR_INT ("w32-mouse-button-tolerance",
8558 &w32_mouse_button_tolerance
,
8559 doc
: /* Analogue of double click interval for faking middle mouse events.
8560 The value is the minimum time in milliseconds that must elapse between
8561 left/right button down events before they are considered distinct events.
8562 If both mouse buttons are depressed within this interval, a middle mouse
8563 button down event is generated instead. */);
8564 w32_mouse_button_tolerance
= GetDoubleClickTime () / 2;
8566 DEFVAR_INT ("w32-mouse-move-interval",
8567 &w32_mouse_move_interval
,
8568 doc
: /* Minimum interval between mouse move events.
8569 The value is the minimum time in milliseconds that must elapse between
8570 successive mouse move (or scroll bar drag) events before they are
8571 reported as lisp events. */);
8572 w32_mouse_move_interval
= 0;
8574 DEFVAR_BOOL ("w32-pass-extra-mouse-buttons-to-system",
8575 &w32_pass_extra_mouse_buttons_to_system
,
8576 doc
: /* Non-nil if the fourth and fifth mouse buttons are passed to Windows.
8577 Recent versions of Windows support mice with up to five buttons.
8578 Since most applications don't support these extra buttons, most mouse
8579 drivers will allow you to map them to functions at the system level.
8580 If this variable is non-nil, Emacs will pass them on, allowing the
8581 system to handle them. */);
8582 w32_pass_extra_mouse_buttons_to_system
= 0;
8584 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
8585 doc
: /* The shape of the pointer when over text.
8586 Changing the value does not affect existing frames
8587 unless you set the mouse color. */);
8588 Vx_pointer_shape
= Qnil
;
8590 Vx_nontext_pointer_shape
= Qnil
;
8592 Vx_mode_pointer_shape
= Qnil
;
8594 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
8595 doc
: /* The shape of the pointer when Emacs is busy.
8596 This variable takes effect when you create a new frame
8597 or when you set the mouse color. */);
8598 Vx_hourglass_pointer_shape
= Qnil
;
8600 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
8601 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
8602 display_hourglass_p
= 1;
8604 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
8605 doc
: /* *Seconds to wait before displaying an hourglass pointer.
8606 Value must be an integer or float. */);
8607 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
8609 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
8610 &Vx_sensitive_text_pointer_shape
,
8611 doc
: /* The shape of the pointer when over mouse-sensitive text.
8612 This variable takes effect when you create a new frame
8613 or when you set the mouse color. */);
8614 Vx_sensitive_text_pointer_shape
= Qnil
;
8616 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
8617 &Vx_window_horizontal_drag_shape
,
8618 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
8619 This variable takes effect when you create a new frame
8620 or when you set the mouse color. */);
8621 Vx_window_horizontal_drag_shape
= Qnil
;
8623 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
8624 doc
: /* A string indicating the foreground color of the cursor box. */);
8625 Vx_cursor_fore_pixel
= Qnil
;
8627 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size
,
8628 doc
: /* Maximum size for tooltips.
8629 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
8630 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
8632 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
8633 doc
: /* Non-nil if no window manager is in use.
8634 Emacs doesn't try to figure this out; this is always nil
8635 unless you set it to something else. */);
8636 /* We don't have any way to find this out, so set it to nil
8637 and maybe the user would like to set it to t. */
8638 Vx_no_window_manager
= Qnil
;
8640 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
8641 &Vx_pixel_size_width_font_regexp
,
8642 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
8644 Since Emacs gets width of a font matching with this regexp from
8645 PIXEL_SIZE field of the name, font finding mechanism gets faster for
8646 such a font. This is especially effective for such large fonts as
8647 Chinese, Japanese, and Korean. */);
8648 Vx_pixel_size_width_font_regexp
= Qnil
;
8650 DEFVAR_LISP ("w32-bdf-filename-alist",
8651 &Vw32_bdf_filename_alist
,
8652 doc
: /* List of bdf fonts and their corresponding filenames. */);
8653 Vw32_bdf_filename_alist
= Qnil
;
8655 DEFVAR_BOOL ("w32-strict-fontnames",
8656 &w32_strict_fontnames
,
8657 doc
: /* Non-nil means only use fonts that are exact matches for those requested.
8658 Default is nil, which allows old fontnames that are not XLFD compliant,
8659 and allows third-party CJK display to work by specifying false charset
8660 fields to trick Emacs into translating to Big5, SJIS etc.
8661 Setting this to t will prevent wrong fonts being selected when
8662 fontsets are automatically created. */);
8663 w32_strict_fontnames
= 0;
8665 DEFVAR_BOOL ("w32-strict-painting",
8666 &w32_strict_painting
,
8667 doc
: /* Non-nil means use strict rules for repainting frames.
8668 Set this to nil to get the old behaviour for repainting; this should
8669 only be necessary if the default setting causes problems. */);
8670 w32_strict_painting
= 1;
8672 DEFVAR_LISP ("w32-charset-info-alist",
8673 &Vw32_charset_info_alist
,
8674 doc
: /* Alist linking Emacs character sets to Windows fonts and codepages.
8675 Each entry should be of the form:
8677 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE))
8679 where CHARSET_NAME is a string used in font names to identify the charset,
8680 WINDOWS_CHARSET is a symbol that can be one of:
8681 w32-charset-ansi, w32-charset-default, w32-charset-symbol,
8682 w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312,
8683 w32-charset-chinesebig5,
8684 w32-charset-johab, w32-charset-hebrew,
8685 w32-charset-arabic, w32-charset-greek, w32-charset-turkish,
8686 w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope,
8687 w32-charset-russian, w32-charset-mac, w32-charset-baltic,
8688 w32-charset-unicode,
8690 CODEPAGE should be an integer specifying the codepage that should be used
8691 to display the character set, t to do no translation and output as Unicode,
8692 or nil to do no translation and output as 8 bit (or multibyte on far-east
8693 versions of Windows) characters. */);
8694 Vw32_charset_info_alist
= Qnil
;
8696 staticpro (&Qw32_charset_ansi
);
8697 Qw32_charset_ansi
= intern ("w32-charset-ansi");
8698 staticpro (&Qw32_charset_symbol
);
8699 Qw32_charset_symbol
= intern ("w32-charset-symbol");
8700 staticpro (&Qw32_charset_shiftjis
);
8701 Qw32_charset_shiftjis
= intern ("w32-charset-shiftjis");
8702 staticpro (&Qw32_charset_hangeul
);
8703 Qw32_charset_hangeul
= intern ("w32-charset-hangeul");
8704 staticpro (&Qw32_charset_chinesebig5
);
8705 Qw32_charset_chinesebig5
= intern ("w32-charset-chinesebig5");
8706 staticpro (&Qw32_charset_gb2312
);
8707 Qw32_charset_gb2312
= intern ("w32-charset-gb2312");
8708 staticpro (&Qw32_charset_oem
);
8709 Qw32_charset_oem
= intern ("w32-charset-oem");
8711 #ifdef JOHAB_CHARSET
8713 static int w32_extra_charsets_defined
= 1;
8714 DEFVAR_BOOL ("w32-extra-charsets-defined", &w32_extra_charsets_defined
,
8715 doc
: /* Internal variable. */);
8717 staticpro (&Qw32_charset_johab
);
8718 Qw32_charset_johab
= intern ("w32-charset-johab");
8719 staticpro (&Qw32_charset_easteurope
);
8720 Qw32_charset_easteurope
= intern ("w32-charset-easteurope");
8721 staticpro (&Qw32_charset_turkish
);
8722 Qw32_charset_turkish
= intern ("w32-charset-turkish");
8723 staticpro (&Qw32_charset_baltic
);
8724 Qw32_charset_baltic
= intern ("w32-charset-baltic");
8725 staticpro (&Qw32_charset_russian
);
8726 Qw32_charset_russian
= intern ("w32-charset-russian");
8727 staticpro (&Qw32_charset_arabic
);
8728 Qw32_charset_arabic
= intern ("w32-charset-arabic");
8729 staticpro (&Qw32_charset_greek
);
8730 Qw32_charset_greek
= intern ("w32-charset-greek");
8731 staticpro (&Qw32_charset_hebrew
);
8732 Qw32_charset_hebrew
= intern ("w32-charset-hebrew");
8733 staticpro (&Qw32_charset_vietnamese
);
8734 Qw32_charset_vietnamese
= intern ("w32-charset-vietnamese");
8735 staticpro (&Qw32_charset_thai
);
8736 Qw32_charset_thai
= intern ("w32-charset-thai");
8737 staticpro (&Qw32_charset_mac
);
8738 Qw32_charset_mac
= intern ("w32-charset-mac");
8742 #ifdef UNICODE_CHARSET
8744 static int w32_unicode_charset_defined
= 1;
8745 DEFVAR_BOOL ("w32-unicode-charset-defined",
8746 &w32_unicode_charset_defined
,
8747 doc
: /* Internal variable. */);
8749 staticpro (&Qw32_charset_unicode
);
8750 Qw32_charset_unicode
= intern ("w32-charset-unicode");
8753 #if 0 /* TODO: Port to W32 */
8754 defsubr (&Sx_change_window_property
);
8755 defsubr (&Sx_delete_window_property
);
8756 defsubr (&Sx_window_property
);
8758 defsubr (&Sxw_display_color_p
);
8759 defsubr (&Sx_display_grayscale_p
);
8760 defsubr (&Sxw_color_defined_p
);
8761 defsubr (&Sxw_color_values
);
8762 defsubr (&Sx_server_max_request_size
);
8763 defsubr (&Sx_server_vendor
);
8764 defsubr (&Sx_server_version
);
8765 defsubr (&Sx_display_pixel_width
);
8766 defsubr (&Sx_display_pixel_height
);
8767 defsubr (&Sx_display_mm_width
);
8768 defsubr (&Sx_display_mm_height
);
8769 defsubr (&Sx_display_screens
);
8770 defsubr (&Sx_display_planes
);
8771 defsubr (&Sx_display_color_cells
);
8772 defsubr (&Sx_display_visual_class
);
8773 defsubr (&Sx_display_backing_store
);
8774 defsubr (&Sx_display_save_under
);
8775 defsubr (&Sx_create_frame
);
8776 defsubr (&Sx_open_connection
);
8777 defsubr (&Sx_close_connection
);
8778 defsubr (&Sx_display_list
);
8779 defsubr (&Sx_synchronize
);
8781 /* W32 specific functions */
8783 defsubr (&Sw32_focus_frame
);
8784 defsubr (&Sw32_select_font
);
8785 defsubr (&Sw32_define_rgb_color
);
8786 defsubr (&Sw32_default_color_map
);
8787 defsubr (&Sw32_load_color_file
);
8788 defsubr (&Sw32_send_sys_command
);
8789 defsubr (&Sw32_shell_execute
);
8790 defsubr (&Sw32_register_hot_key
);
8791 defsubr (&Sw32_unregister_hot_key
);
8792 defsubr (&Sw32_registered_hot_keys
);
8793 defsubr (&Sw32_reconstruct_hot_key
);
8794 defsubr (&Sw32_toggle_lock_key
);
8795 defsubr (&Sw32_find_bdf_fonts
);
8797 defsubr (&Sfile_system_info
);
8798 defsubr (&Sdefault_printer_name
);
8800 /* Setting callback functions for fontset handler. */
8801 get_font_info_func
= w32_get_font_info
;
8803 #if 0 /* This function pointer doesn't seem to be used anywhere.
8804 And the pointer assigned has the wrong type, anyway. */
8805 list_fonts_func
= w32_list_fonts
;
8808 load_font_func
= w32_load_font
;
8809 find_ccl_program_func
= w32_find_ccl_program
;
8810 query_font_func
= w32_query_font
;
8811 set_frame_fontset_func
= x_set_font
;
8812 check_window_system_func
= check_w32
;
8815 hourglass_atimer
= NULL
;
8816 hourglass_shown_p
= 0;
8817 defsubr (&Sx_show_tip
);
8818 defsubr (&Sx_hide_tip
);
8820 staticpro (&tip_timer
);
8822 staticpro (&tip_frame
);
8824 last_show_tip_args
= Qnil
;
8825 staticpro (&last_show_tip_args
);
8827 defsubr (&Sx_file_dialog
);
8832 globals_of_w32fns is used to initialize those global variables that
8833 must always be initialized on startup even when the global variable
8834 initialized is non zero (see the function main in emacs.c).
8835 globals_of_w32fns is called from syms_of_w32fns when the global
8836 variable initialized is 0 and directly from main when initialized
8839 void globals_of_w32fns ()
8841 HMODULE user32_lib
= GetModuleHandle ("user32.dll");
8843 TrackMouseEvent not available in all versions of Windows, so must load
8844 it dynamically. Do it once, here, instead of every time it is used.
8846 track_mouse_event_fn
= (TrackMouseEvent_Proc
)
8847 GetProcAddress (user32_lib
, "TrackMouseEvent");
8848 /* ditto for GetClipboardSequenceNumber. */
8849 clipboard_sequence_fn
= (ClipboardSequence_Proc
)
8850 GetProcAddress (user32_lib
, "GetClipboardSequenceNumber");
8852 DEFVAR_INT ("w32-ansi-code-page",
8853 &w32_ansi_code_page
,
8854 doc
: /* The ANSI code page used by the system. */);
8855 w32_ansi_code_page
= GetACP ();
8864 button
= MessageBox (NULL
,
8865 "A fatal error has occurred!\n\n"
8866 "Select Abort to exit, Retry to debug, Ignore to continue",
8867 "Emacs Abort Dialog",
8868 MB_ICONEXCLAMATION
| MB_TASKMODAL
8869 | MB_SETFOREGROUND
| MB_ABORTRETRYIGNORE
);
8884 /* For convenience when debugging. */
8888 return GetLastError ();
8891 /* arch-tag: 707589ab-b9be-4638-8cdd-74629cc9b446
8892 (do not change this comment) */