1 /* Graphical user interface functions for the Microsoft W32 API.
2 Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 /* Added by Kevin Gallo */
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
));
67 extern XCharStruct
*w32_per_char_metric
P_ ((XFontStruct
*, wchar_t *, int));
71 extern char *lispy_function_keys
[];
73 /* The gray bitmap `bitmaps/gray'. This is done because w32term.c uses
74 it, and including `bitmaps/gray' more than once is a problem when
75 config.h defines `static' as an empty replacement string. */
77 int gray_bitmap_width
= gray_width
;
78 int gray_bitmap_height
= gray_height
;
79 unsigned char *gray_bitmap_bits
= gray_bits
;
81 /* The colormap for converting color names to RGB values */
82 Lisp_Object Vw32_color_map
;
84 /* Non nil if alt key presses are passed on to Windows. */
85 Lisp_Object Vw32_pass_alt_to_system
;
87 /* Non nil if alt key is translated to meta_modifier, nil if it is translated
89 Lisp_Object Vw32_alt_is_meta
;
91 /* If non-zero, the windows virtual key code for an alternative quit key. */
94 /* Non nil if left window key events are passed on to Windows (this only
95 affects whether "tapping" the key opens the Start menu). */
96 Lisp_Object Vw32_pass_lwindow_to_system
;
98 /* Non nil if right window key events are passed on to Windows (this
99 only affects whether "tapping" the key opens the Start menu). */
100 Lisp_Object Vw32_pass_rwindow_to_system
;
102 /* Virtual key code used to generate "phantom" key presses in order
103 to stop system from acting on Windows key events. */
104 Lisp_Object Vw32_phantom_key_code
;
106 /* Modifier associated with the left "Windows" key, or nil to act as a
108 Lisp_Object Vw32_lwindow_modifier
;
110 /* Modifier associated with the right "Windows" key, or nil to act as a
112 Lisp_Object Vw32_rwindow_modifier
;
114 /* Modifier associated with the "Apps" key, or nil to act as a normal
116 Lisp_Object Vw32_apps_modifier
;
118 /* Value is nil if Num Lock acts as a function key. */
119 Lisp_Object Vw32_enable_num_lock
;
121 /* Value is nil if Caps Lock acts as a function key. */
122 Lisp_Object Vw32_enable_caps_lock
;
124 /* Modifier associated with Scroll Lock, or nil to act as a normal key. */
125 Lisp_Object Vw32_scroll_lock_modifier
;
127 /* Switch to control whether we inhibit requests for synthesized bold
128 and italic versions of fonts. */
129 int w32_enable_synthesized_fonts
;
131 /* Enable palette management. */
132 Lisp_Object Vw32_enable_palette
;
134 /* Control how close left/right button down events must be to
135 be converted to a middle button down event. */
136 int w32_mouse_button_tolerance
;
138 /* Minimum interval between mouse movement (and scroll bar drag)
139 events that are passed on to the event loop. */
140 int w32_mouse_move_interval
;
142 /* Flag to indicate if XBUTTON events should be passed on to Windows. */
143 int w32_pass_extra_mouse_buttons_to_system
;
145 /* Non nil if no window manager is in use. */
146 Lisp_Object Vx_no_window_manager
;
148 /* Non-zero means we're allowed to display a hourglass pointer. */
150 int display_hourglass_p
;
152 /* The background and shape of the mouse pointer, and shape when not
153 over text or in the modeline. */
155 Lisp_Object Vx_pointer_shape
, Vx_nontext_pointer_shape
, Vx_mode_pointer_shape
;
156 Lisp_Object Vx_hourglass_pointer_shape
, Vx_window_horizontal_drag_shape
;
158 /* The shape when over mouse-sensitive text. */
160 Lisp_Object Vx_sensitive_text_pointer_shape
;
163 #define IDC_HAND MAKEINTRESOURCE(32649)
166 /* Color of chars displayed in cursor box. */
168 Lisp_Object Vx_cursor_fore_pixel
;
170 /* Nonzero if using Windows. */
172 static int w32_in_use
;
174 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
176 Lisp_Object Vx_pixel_size_width_font_regexp
;
178 /* Alist of bdf fonts and the files that define them. */
179 Lisp_Object Vw32_bdf_filename_alist
;
181 /* A flag to control whether fonts are matched strictly or not. */
182 int w32_strict_fontnames
;
184 /* A flag to control whether we should only repaint if GetUpdateRect
185 indicates there is an update region. */
186 int w32_strict_painting
;
188 /* Associative list linking character set strings to Windows codepages. */
189 Lisp_Object Vw32_charset_info_alist
;
191 /* VIETNAMESE_CHARSET is not defined in some versions of MSVC. */
192 #ifndef VIETNAMESE_CHARSET
193 #define VIETNAMESE_CHARSET 163
197 Lisp_Object Qsuppress_icon
;
198 Lisp_Object Qundefined_color
;
199 Lisp_Object Qcancel_timer
;
205 Lisp_Object Qcontrol
;
208 Lisp_Object Qw32_charset_ansi
;
209 Lisp_Object Qw32_charset_default
;
210 Lisp_Object Qw32_charset_symbol
;
211 Lisp_Object Qw32_charset_shiftjis
;
212 Lisp_Object Qw32_charset_hangeul
;
213 Lisp_Object Qw32_charset_gb2312
;
214 Lisp_Object Qw32_charset_chinesebig5
;
215 Lisp_Object Qw32_charset_oem
;
217 #ifndef JOHAB_CHARSET
218 #define JOHAB_CHARSET 130
221 Lisp_Object Qw32_charset_easteurope
;
222 Lisp_Object Qw32_charset_turkish
;
223 Lisp_Object Qw32_charset_baltic
;
224 Lisp_Object Qw32_charset_russian
;
225 Lisp_Object Qw32_charset_arabic
;
226 Lisp_Object Qw32_charset_greek
;
227 Lisp_Object Qw32_charset_hebrew
;
228 Lisp_Object Qw32_charset_vietnamese
;
229 Lisp_Object Qw32_charset_thai
;
230 Lisp_Object Qw32_charset_johab
;
231 Lisp_Object Qw32_charset_mac
;
234 #ifdef UNICODE_CHARSET
235 Lisp_Object Qw32_charset_unicode
;
238 /* The ANSI codepage. */
239 int w32_ansi_code_page
;
241 /* Prefix for system colors. */
242 #define SYSTEM_COLOR_PREFIX "System"
243 #define SYSTEM_COLOR_PREFIX_LEN (sizeof (SYSTEM_COLOR_PREFIX) - 1)
245 /* State variables for emulating a three button mouse. */
250 static int button_state
= 0;
251 static W32Msg saved_mouse_button_msg
;
252 static unsigned mouse_button_timer
= 0; /* non-zero when timer is active */
253 static W32Msg saved_mouse_move_msg
;
254 static unsigned mouse_move_timer
= 0;
256 /* Window that is tracking the mouse. */
257 static HWND track_mouse_window
;
259 typedef BOOL (WINAPI
* TrackMouseEvent_Proc
)
260 (IN OUT LPTRACKMOUSEEVENT lpEventTrack
);
262 TrackMouseEvent_Proc track_mouse_event_fn
= NULL
;
263 ClipboardSequence_Proc clipboard_sequence_fn
= NULL
;
264 extern AppendMenuW_Proc unicode_append_menu
;
266 /* W95 mousewheel handler */
267 unsigned int msh_mousewheel
= 0;
270 #define MOUSE_BUTTON_ID 1
271 #define MOUSE_MOVE_ID 2
272 #define MENU_FREE_ID 3
273 /* The delay (milliseconds) before a menu is freed after WM_EXITMENULOOP
275 #define MENU_FREE_DELAY 1000
276 static unsigned menu_free_timer
= 0;
278 /* The below are defined in frame.c. */
280 extern Lisp_Object Vwindow_system_version
;
283 int image_cache_refcount
, dpyinfo_refcount
;
287 /* From w32term.c. */
288 extern int w32_num_mouse_buttons
;
289 extern Lisp_Object Vw32_recognize_altgr
;
291 extern HWND w32_system_caret_hwnd
;
293 extern int w32_system_caret_height
;
294 extern int w32_system_caret_x
;
295 extern int w32_system_caret_y
;
296 extern int w32_use_visible_system_caret
;
298 static HWND w32_visible_system_caret_hwnd
;
301 extern HMENU current_popup_menu
;
302 static int menubar_in_use
= 0;
305 /* Error if we are not connected to MS-Windows. */
310 error ("MS-Windows not in use or not initialized");
313 /* Nonzero if we can use mouse menus.
314 You should not call this unless HAVE_MENUS is defined. */
322 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
323 and checking validity for W32. */
326 check_x_frame (frame
)
332 frame
= selected_frame
;
333 CHECK_LIVE_FRAME (frame
);
335 if (! FRAME_W32_P (f
))
336 error ("Non-W32 frame used");
340 /* Let the user specify a display with a frame.
341 nil stands for the selected frame--or, if that is not a w32 frame,
342 the first display on the list. */
344 struct w32_display_info
*
345 check_x_display_info (frame
)
350 struct frame
*sf
= XFRAME (selected_frame
);
352 if (FRAME_W32_P (sf
) && FRAME_LIVE_P (sf
))
353 return FRAME_W32_DISPLAY_INFO (sf
);
355 return &one_w32_display_info
;
357 else if (STRINGP (frame
))
358 return x_display_info_for_name (frame
);
363 CHECK_LIVE_FRAME (frame
);
365 if (! FRAME_W32_P (f
))
366 error ("Non-W32 frame used");
367 return FRAME_W32_DISPLAY_INFO (f
);
371 /* Return the Emacs frame-object corresponding to an w32 window.
372 It could be the frame's main window or an icon window. */
374 /* This function can be called during GC, so use GC_xxx type test macros. */
377 x_window_to_frame (dpyinfo
, wdesc
)
378 struct w32_display_info
*dpyinfo
;
381 Lisp_Object tail
, frame
;
384 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
387 if (!GC_FRAMEP (frame
))
390 if (!FRAME_W32_P (f
) || FRAME_W32_DISPLAY_INFO (f
) != dpyinfo
)
392 if (f
->output_data
.w32
->hourglass_window
== wdesc
)
395 if (FRAME_W32_WINDOW (f
) == wdesc
)
402 static Lisp_Object unwind_create_frame
P_ ((Lisp_Object
));
403 static Lisp_Object unwind_create_tip_frame
P_ ((Lisp_Object
));
404 static void my_create_window
P_ ((struct frame
*));
405 static void my_create_tip_window
P_ ((struct frame
*));
407 /* TODO: Native Input Method support; see x_create_im. */
408 void x_set_foreground_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
409 void x_set_background_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
410 void x_set_mouse_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
411 void x_set_cursor_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
412 void x_set_border_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
413 void x_set_cursor_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
414 void x_set_icon_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
415 void x_set_icon_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
416 void x_explicitly_set_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
417 void x_set_menu_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
418 void x_set_title
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
419 void x_set_tool_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
420 static void x_edge_detection
P_ ((struct frame
*, struct image
*, Lisp_Object
,
426 /* Store the screen positions of frame F into XPTR and YPTR.
427 These are the positions of the containing window manager window,
428 not Emacs's own window. */
431 x_real_positions (f
, xptr
, yptr
)
438 GetClientRect(FRAME_W32_WINDOW(f
), &rect
);
439 AdjustWindowRect(&rect
, f
->output_data
.w32
->dwStyle
, FRAME_EXTERNAL_MENU_BAR(f
));
444 ClientToScreen (FRAME_W32_WINDOW(f
), &pt
);
446 /* Remember x_pixels_diff and y_pixels_diff. */
447 f
->x_pixels_diff
= pt
.x
- rect
.left
;
448 f
->y_pixels_diff
= pt
.y
- rect
.top
;
456 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
,
457 Sw32_define_rgb_color
, 4, 4, 0,
458 doc
: /* Convert RGB numbers to a windows color reference and associate with NAME.
459 This adds or updates a named color to w32-color-map, making it
460 available for use. The original entry's RGB ref is returned, or nil
461 if the entry is new. */)
462 (red
, green
, blue
, name
)
463 Lisp_Object red
, green
, blue
, name
;
466 Lisp_Object oldrgb
= Qnil
;
470 CHECK_NUMBER (green
);
474 XSETINT (rgb
, RGB(XUINT (red
), XUINT (green
), XUINT (blue
)));
478 /* replace existing entry in w32-color-map or add new entry. */
479 entry
= Fassoc (name
, Vw32_color_map
);
482 entry
= Fcons (name
, rgb
);
483 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
487 oldrgb
= Fcdr (entry
);
488 Fsetcdr (entry
, rgb
);
496 DEFUN ("w32-load-color-file", Fw32_load_color_file
,
497 Sw32_load_color_file
, 1, 1, 0,
498 doc
: /* Create an alist of color entries from an external file.
499 Assign this value to w32-color-map to replace the existing color map.
501 The file should define one named RGB color per line like so:
503 where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
505 Lisp_Object filename
;
508 Lisp_Object cmap
= Qnil
;
511 CHECK_STRING (filename
);
512 abspath
= Fexpand_file_name (filename
, Qnil
);
514 fp
= fopen (SDATA (filename
), "rt");
518 int red
, green
, blue
;
523 while (fgets (buf
, sizeof (buf
), fp
) != NULL
) {
524 if (sscanf (buf
, "%u %u %u %n", &red
, &green
, &blue
, &num
) == 3)
526 char *name
= buf
+ num
;
527 num
= strlen (name
) - 1;
528 if (name
[num
] == '\n')
530 cmap
= Fcons (Fcons (build_string (name
),
531 make_number (RGB (red
, green
, blue
))),
543 /* The default colors for the w32 color map */
544 typedef struct colormap_t
550 colormap_t w32_color_map
[] =
552 {"snow" , PALETTERGB (255,250,250)},
553 {"ghost white" , PALETTERGB (248,248,255)},
554 {"GhostWhite" , PALETTERGB (248,248,255)},
555 {"white smoke" , PALETTERGB (245,245,245)},
556 {"WhiteSmoke" , PALETTERGB (245,245,245)},
557 {"gainsboro" , PALETTERGB (220,220,220)},
558 {"floral white" , PALETTERGB (255,250,240)},
559 {"FloralWhite" , PALETTERGB (255,250,240)},
560 {"old lace" , PALETTERGB (253,245,230)},
561 {"OldLace" , PALETTERGB (253,245,230)},
562 {"linen" , PALETTERGB (250,240,230)},
563 {"antique white" , PALETTERGB (250,235,215)},
564 {"AntiqueWhite" , PALETTERGB (250,235,215)},
565 {"papaya whip" , PALETTERGB (255,239,213)},
566 {"PapayaWhip" , PALETTERGB (255,239,213)},
567 {"blanched almond" , PALETTERGB (255,235,205)},
568 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
569 {"bisque" , PALETTERGB (255,228,196)},
570 {"peach puff" , PALETTERGB (255,218,185)},
571 {"PeachPuff" , PALETTERGB (255,218,185)},
572 {"navajo white" , PALETTERGB (255,222,173)},
573 {"NavajoWhite" , PALETTERGB (255,222,173)},
574 {"moccasin" , PALETTERGB (255,228,181)},
575 {"cornsilk" , PALETTERGB (255,248,220)},
576 {"ivory" , PALETTERGB (255,255,240)},
577 {"lemon chiffon" , PALETTERGB (255,250,205)},
578 {"LemonChiffon" , PALETTERGB (255,250,205)},
579 {"seashell" , PALETTERGB (255,245,238)},
580 {"honeydew" , PALETTERGB (240,255,240)},
581 {"mint cream" , PALETTERGB (245,255,250)},
582 {"MintCream" , PALETTERGB (245,255,250)},
583 {"azure" , PALETTERGB (240,255,255)},
584 {"alice blue" , PALETTERGB (240,248,255)},
585 {"AliceBlue" , PALETTERGB (240,248,255)},
586 {"lavender" , PALETTERGB (230,230,250)},
587 {"lavender blush" , PALETTERGB (255,240,245)},
588 {"LavenderBlush" , PALETTERGB (255,240,245)},
589 {"misty rose" , PALETTERGB (255,228,225)},
590 {"MistyRose" , PALETTERGB (255,228,225)},
591 {"white" , PALETTERGB (255,255,255)},
592 {"black" , PALETTERGB ( 0, 0, 0)},
593 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
594 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
595 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
596 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
597 {"dim gray" , PALETTERGB (105,105,105)},
598 {"DimGray" , PALETTERGB (105,105,105)},
599 {"dim grey" , PALETTERGB (105,105,105)},
600 {"DimGrey" , PALETTERGB (105,105,105)},
601 {"slate gray" , PALETTERGB (112,128,144)},
602 {"SlateGray" , PALETTERGB (112,128,144)},
603 {"slate grey" , PALETTERGB (112,128,144)},
604 {"SlateGrey" , PALETTERGB (112,128,144)},
605 {"light slate gray" , PALETTERGB (119,136,153)},
606 {"LightSlateGray" , PALETTERGB (119,136,153)},
607 {"light slate grey" , PALETTERGB (119,136,153)},
608 {"LightSlateGrey" , PALETTERGB (119,136,153)},
609 {"gray" , PALETTERGB (190,190,190)},
610 {"grey" , PALETTERGB (190,190,190)},
611 {"light grey" , PALETTERGB (211,211,211)},
612 {"LightGrey" , PALETTERGB (211,211,211)},
613 {"light gray" , PALETTERGB (211,211,211)},
614 {"LightGray" , PALETTERGB (211,211,211)},
615 {"midnight blue" , PALETTERGB ( 25, 25,112)},
616 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
617 {"navy" , PALETTERGB ( 0, 0,128)},
618 {"navy blue" , PALETTERGB ( 0, 0,128)},
619 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
620 {"cornflower blue" , PALETTERGB (100,149,237)},
621 {"CornflowerBlue" , PALETTERGB (100,149,237)},
622 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
623 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
624 {"slate blue" , PALETTERGB (106, 90,205)},
625 {"SlateBlue" , PALETTERGB (106, 90,205)},
626 {"medium slate blue" , PALETTERGB (123,104,238)},
627 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
628 {"light slate blue" , PALETTERGB (132,112,255)},
629 {"LightSlateBlue" , PALETTERGB (132,112,255)},
630 {"medium blue" , PALETTERGB ( 0, 0,205)},
631 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
632 {"royal blue" , PALETTERGB ( 65,105,225)},
633 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
634 {"blue" , PALETTERGB ( 0, 0,255)},
635 {"dodger blue" , PALETTERGB ( 30,144,255)},
636 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
637 {"deep sky blue" , PALETTERGB ( 0,191,255)},
638 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
639 {"sky blue" , PALETTERGB (135,206,235)},
640 {"SkyBlue" , PALETTERGB (135,206,235)},
641 {"light sky blue" , PALETTERGB (135,206,250)},
642 {"LightSkyBlue" , PALETTERGB (135,206,250)},
643 {"steel blue" , PALETTERGB ( 70,130,180)},
644 {"SteelBlue" , PALETTERGB ( 70,130,180)},
645 {"light steel blue" , PALETTERGB (176,196,222)},
646 {"LightSteelBlue" , PALETTERGB (176,196,222)},
647 {"light blue" , PALETTERGB (173,216,230)},
648 {"LightBlue" , PALETTERGB (173,216,230)},
649 {"powder blue" , PALETTERGB (176,224,230)},
650 {"PowderBlue" , PALETTERGB (176,224,230)},
651 {"pale turquoise" , PALETTERGB (175,238,238)},
652 {"PaleTurquoise" , PALETTERGB (175,238,238)},
653 {"dark turquoise" , PALETTERGB ( 0,206,209)},
654 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
655 {"medium turquoise" , PALETTERGB ( 72,209,204)},
656 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
657 {"turquoise" , PALETTERGB ( 64,224,208)},
658 {"cyan" , PALETTERGB ( 0,255,255)},
659 {"light cyan" , PALETTERGB (224,255,255)},
660 {"LightCyan" , PALETTERGB (224,255,255)},
661 {"cadet blue" , PALETTERGB ( 95,158,160)},
662 {"CadetBlue" , PALETTERGB ( 95,158,160)},
663 {"medium aquamarine" , PALETTERGB (102,205,170)},
664 {"MediumAquamarine" , PALETTERGB (102,205,170)},
665 {"aquamarine" , PALETTERGB (127,255,212)},
666 {"dark green" , PALETTERGB ( 0,100, 0)},
667 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
668 {"dark olive green" , PALETTERGB ( 85,107, 47)},
669 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
670 {"dark sea green" , PALETTERGB (143,188,143)},
671 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
672 {"sea green" , PALETTERGB ( 46,139, 87)},
673 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
674 {"medium sea green" , PALETTERGB ( 60,179,113)},
675 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
676 {"light sea green" , PALETTERGB ( 32,178,170)},
677 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
678 {"pale green" , PALETTERGB (152,251,152)},
679 {"PaleGreen" , PALETTERGB (152,251,152)},
680 {"spring green" , PALETTERGB ( 0,255,127)},
681 {"SpringGreen" , PALETTERGB ( 0,255,127)},
682 {"lawn green" , PALETTERGB (124,252, 0)},
683 {"LawnGreen" , PALETTERGB (124,252, 0)},
684 {"green" , PALETTERGB ( 0,255, 0)},
685 {"chartreuse" , PALETTERGB (127,255, 0)},
686 {"medium spring green" , PALETTERGB ( 0,250,154)},
687 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
688 {"green yellow" , PALETTERGB (173,255, 47)},
689 {"GreenYellow" , PALETTERGB (173,255, 47)},
690 {"lime green" , PALETTERGB ( 50,205, 50)},
691 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
692 {"yellow green" , PALETTERGB (154,205, 50)},
693 {"YellowGreen" , PALETTERGB (154,205, 50)},
694 {"forest green" , PALETTERGB ( 34,139, 34)},
695 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
696 {"olive drab" , PALETTERGB (107,142, 35)},
697 {"OliveDrab" , PALETTERGB (107,142, 35)},
698 {"dark khaki" , PALETTERGB (189,183,107)},
699 {"DarkKhaki" , PALETTERGB (189,183,107)},
700 {"khaki" , PALETTERGB (240,230,140)},
701 {"pale goldenrod" , PALETTERGB (238,232,170)},
702 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
703 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
704 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
705 {"light yellow" , PALETTERGB (255,255,224)},
706 {"LightYellow" , PALETTERGB (255,255,224)},
707 {"yellow" , PALETTERGB (255,255, 0)},
708 {"gold" , PALETTERGB (255,215, 0)},
709 {"light goldenrod" , PALETTERGB (238,221,130)},
710 {"LightGoldenrod" , PALETTERGB (238,221,130)},
711 {"goldenrod" , PALETTERGB (218,165, 32)},
712 {"dark goldenrod" , PALETTERGB (184,134, 11)},
713 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
714 {"rosy brown" , PALETTERGB (188,143,143)},
715 {"RosyBrown" , PALETTERGB (188,143,143)},
716 {"indian red" , PALETTERGB (205, 92, 92)},
717 {"IndianRed" , PALETTERGB (205, 92, 92)},
718 {"saddle brown" , PALETTERGB (139, 69, 19)},
719 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
720 {"sienna" , PALETTERGB (160, 82, 45)},
721 {"peru" , PALETTERGB (205,133, 63)},
722 {"burlywood" , PALETTERGB (222,184,135)},
723 {"beige" , PALETTERGB (245,245,220)},
724 {"wheat" , PALETTERGB (245,222,179)},
725 {"sandy brown" , PALETTERGB (244,164, 96)},
726 {"SandyBrown" , PALETTERGB (244,164, 96)},
727 {"tan" , PALETTERGB (210,180,140)},
728 {"chocolate" , PALETTERGB (210,105, 30)},
729 {"firebrick" , PALETTERGB (178,34, 34)},
730 {"brown" , PALETTERGB (165,42, 42)},
731 {"dark salmon" , PALETTERGB (233,150,122)},
732 {"DarkSalmon" , PALETTERGB (233,150,122)},
733 {"salmon" , PALETTERGB (250,128,114)},
734 {"light salmon" , PALETTERGB (255,160,122)},
735 {"LightSalmon" , PALETTERGB (255,160,122)},
736 {"orange" , PALETTERGB (255,165, 0)},
737 {"dark orange" , PALETTERGB (255,140, 0)},
738 {"DarkOrange" , PALETTERGB (255,140, 0)},
739 {"coral" , PALETTERGB (255,127, 80)},
740 {"light coral" , PALETTERGB (240,128,128)},
741 {"LightCoral" , PALETTERGB (240,128,128)},
742 {"tomato" , PALETTERGB (255, 99, 71)},
743 {"orange red" , PALETTERGB (255, 69, 0)},
744 {"OrangeRed" , PALETTERGB (255, 69, 0)},
745 {"red" , PALETTERGB (255, 0, 0)},
746 {"hot pink" , PALETTERGB (255,105,180)},
747 {"HotPink" , PALETTERGB (255,105,180)},
748 {"deep pink" , PALETTERGB (255, 20,147)},
749 {"DeepPink" , PALETTERGB (255, 20,147)},
750 {"pink" , PALETTERGB (255,192,203)},
751 {"light pink" , PALETTERGB (255,182,193)},
752 {"LightPink" , PALETTERGB (255,182,193)},
753 {"pale violet red" , PALETTERGB (219,112,147)},
754 {"PaleVioletRed" , PALETTERGB (219,112,147)},
755 {"maroon" , PALETTERGB (176, 48, 96)},
756 {"medium violet red" , PALETTERGB (199, 21,133)},
757 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
758 {"violet red" , PALETTERGB (208, 32,144)},
759 {"VioletRed" , PALETTERGB (208, 32,144)},
760 {"magenta" , PALETTERGB (255, 0,255)},
761 {"violet" , PALETTERGB (238,130,238)},
762 {"plum" , PALETTERGB (221,160,221)},
763 {"orchid" , PALETTERGB (218,112,214)},
764 {"medium orchid" , PALETTERGB (186, 85,211)},
765 {"MediumOrchid" , PALETTERGB (186, 85,211)},
766 {"dark orchid" , PALETTERGB (153, 50,204)},
767 {"DarkOrchid" , PALETTERGB (153, 50,204)},
768 {"dark violet" , PALETTERGB (148, 0,211)},
769 {"DarkViolet" , PALETTERGB (148, 0,211)},
770 {"blue violet" , PALETTERGB (138, 43,226)},
771 {"BlueViolet" , PALETTERGB (138, 43,226)},
772 {"purple" , PALETTERGB (160, 32,240)},
773 {"medium purple" , PALETTERGB (147,112,219)},
774 {"MediumPurple" , PALETTERGB (147,112,219)},
775 {"thistle" , PALETTERGB (216,191,216)},
776 {"gray0" , PALETTERGB ( 0, 0, 0)},
777 {"grey0" , PALETTERGB ( 0, 0, 0)},
778 {"dark grey" , PALETTERGB (169,169,169)},
779 {"DarkGrey" , PALETTERGB (169,169,169)},
780 {"dark gray" , PALETTERGB (169,169,169)},
781 {"DarkGray" , PALETTERGB (169,169,169)},
782 {"dark blue" , PALETTERGB ( 0, 0,139)},
783 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
784 {"dark cyan" , PALETTERGB ( 0,139,139)},
785 {"DarkCyan" , PALETTERGB ( 0,139,139)},
786 {"dark magenta" , PALETTERGB (139, 0,139)},
787 {"DarkMagenta" , PALETTERGB (139, 0,139)},
788 {"dark red" , PALETTERGB (139, 0, 0)},
789 {"DarkRed" , PALETTERGB (139, 0, 0)},
790 {"light green" , PALETTERGB (144,238,144)},
791 {"LightGreen" , PALETTERGB (144,238,144)},
794 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
795 0, 0, 0, doc
: /* Return the default color map. */)
799 colormap_t
*pc
= w32_color_map
;
806 for (i
= 0; i
< sizeof (w32_color_map
) / sizeof (w32_color_map
[0]);
808 cmap
= Fcons (Fcons (build_string (pc
->name
),
809 make_number (pc
->colorref
)),
827 color
= Frassq (rgb
, Vw32_color_map
);
832 return (Fcar (color
));
838 w32_color_map_lookup (colorname
)
841 Lisp_Object tail
, ret
= Qnil
;
845 for (tail
= Vw32_color_map
; !NILP (tail
); tail
= Fcdr (tail
))
847 register Lisp_Object elt
, tem
;
850 if (!CONSP (elt
)) continue;
854 if (lstrcmpi (SDATA (tem
), colorname
) == 0)
871 add_system_logical_colors_to_map (system_colors
)
872 Lisp_Object
*system_colors
;
876 /* Other registry operations are done with input blocked. */
879 /* Look for "Control Panel/Colors" under User and Machine registry
881 if (RegOpenKeyEx (HKEY_CURRENT_USER
, "Control Panel\\Colors", 0,
882 KEY_READ
, &colors_key
) == ERROR_SUCCESS
883 || RegOpenKeyEx (HKEY_LOCAL_MACHINE
, "Control Panel\\Colors", 0,
884 KEY_READ
, &colors_key
) == ERROR_SUCCESS
)
887 char color_buffer
[64];
888 char full_name_buffer
[MAX_PATH
+ SYSTEM_COLOR_PREFIX_LEN
];
890 DWORD name_size
, color_size
;
891 char *name_buffer
= full_name_buffer
+ SYSTEM_COLOR_PREFIX_LEN
;
893 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
894 color_size
= sizeof (color_buffer
);
896 strcpy (full_name_buffer
, SYSTEM_COLOR_PREFIX
);
898 while (RegEnumValueA (colors_key
, index
, name_buffer
, &name_size
,
899 NULL
, NULL
, color_buffer
, &color_size
)
903 if (sscanf (color_buffer
, " %u %u %u", &r
, &g
, &b
) == 3)
904 *system_colors
= Fcons (Fcons (build_string (full_name_buffer
),
905 make_number (RGB (r
, g
, b
))),
908 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
909 color_size
= sizeof (color_buffer
);
912 RegCloseKey (colors_key
);
920 x_to_w32_color (colorname
)
923 register Lisp_Object ret
= Qnil
;
927 if (colorname
[0] == '#')
929 /* Could be an old-style RGB Device specification. */
932 color
= colorname
+ 1;
934 size
= strlen(color
);
935 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
943 for (i
= 0; i
< 3; i
++)
949 /* The check for 'x' in the following conditional takes into
950 account the fact that strtol allows a "0x" in front of
951 our numbers, and we don't. */
952 if (!isxdigit(color
[0]) || color
[1] == 'x')
956 value
= strtoul(color
, &end
, 16);
958 if (errno
== ERANGE
|| end
- color
!= size
)
963 value
= value
* 0x10;
974 colorval
|= (value
<< pos
);
979 XSETINT (ret
, colorval
);
986 else if (strnicmp(colorname
, "rgb:", 4) == 0)
994 color
= colorname
+ 4;
995 for (i
= 0; i
< 3; i
++)
1000 /* The check for 'x' in the following conditional takes into
1001 account the fact that strtol allows a "0x" in front of
1002 our numbers, and we don't. */
1003 if (!isxdigit(color
[0]) || color
[1] == 'x')
1005 value
= strtoul(color
, &end
, 16);
1006 if (errno
== ERANGE
)
1008 switch (end
- color
)
1011 value
= value
* 0x10 + value
;
1024 if (value
== ULONG_MAX
)
1026 colorval
|= (value
<< pos
);
1033 XSETINT (ret
, colorval
);
1041 else if (strnicmp(colorname
, "rgbi:", 5) == 0)
1043 /* This is an RGB Intensity specification. */
1050 color
= colorname
+ 5;
1051 for (i
= 0; i
< 3; i
++)
1057 value
= strtod(color
, &end
);
1058 if (errno
== ERANGE
)
1060 if (value
< 0.0 || value
> 1.0)
1062 val
= (UINT
)(0x100 * value
);
1063 /* We used 0x100 instead of 0xFF to give a continuous
1064 range between 0.0 and 1.0 inclusive. The next statement
1065 fixes the 1.0 case. */
1068 colorval
|= (val
<< pos
);
1075 XSETINT (ret
, colorval
);
1083 /* I am not going to attempt to handle any of the CIE color schemes
1084 or TekHVC, since I don't know the algorithms for conversion to
1087 /* If we fail to lookup the color name in w32_color_map, then check the
1088 colorname to see if it can be crudely approximated: If the X color
1089 ends in a number (e.g., "darkseagreen2"), strip the number and
1090 return the result of looking up the base color name. */
1091 ret
= w32_color_map_lookup (colorname
);
1094 int len
= strlen (colorname
);
1096 if (isdigit (colorname
[len
- 1]))
1098 char *ptr
, *approx
= alloca (len
+ 1);
1100 strcpy (approx
, colorname
);
1101 ptr
= &approx
[len
- 1];
1102 while (ptr
> approx
&& isdigit (*ptr
))
1105 ret
= w32_color_map_lookup (approx
);
1114 w32_regenerate_palette (FRAME_PTR f
)
1116 struct w32_palette_entry
* list
;
1117 LOGPALETTE
* log_palette
;
1118 HPALETTE new_palette
;
1121 /* don't bother trying to create palette if not supported */
1122 if (! FRAME_W32_DISPLAY_INFO (f
)->has_palette
)
1125 log_palette
= (LOGPALETTE
*)
1126 alloca (sizeof (LOGPALETTE
) +
1127 FRAME_W32_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
1128 log_palette
->palVersion
= 0x300;
1129 log_palette
->palNumEntries
= FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1131 list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1133 i
< FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1134 i
++, list
= list
->next
)
1135 log_palette
->palPalEntry
[i
] = list
->entry
;
1137 new_palette
= CreatePalette (log_palette
);
1141 if (FRAME_W32_DISPLAY_INFO (f
)->palette
)
1142 DeleteObject (FRAME_W32_DISPLAY_INFO (f
)->palette
);
1143 FRAME_W32_DISPLAY_INFO (f
)->palette
= new_palette
;
1145 /* Realize display palette and garbage all frames. */
1146 release_frame_dc (f
, get_frame_dc (f
));
1151 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
1152 #define SET_W32_COLOR(pe, color) \
1155 pe.peRed = GetRValue (color); \
1156 pe.peGreen = GetGValue (color); \
1157 pe.peBlue = GetBValue (color); \
1162 /* Keep these around in case we ever want to track color usage. */
1164 w32_map_color (FRAME_PTR f
, COLORREF color
)
1166 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1168 if (NILP (Vw32_enable_palette
))
1171 /* check if color is already mapped */
1174 if (W32_COLOR (list
->entry
) == color
)
1182 /* not already mapped, so add to list and recreate Windows palette */
1183 list
= (struct w32_palette_entry
*)
1184 xmalloc (sizeof (struct w32_palette_entry
));
1185 SET_W32_COLOR (list
->entry
, color
);
1187 list
->next
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1188 FRAME_W32_DISPLAY_INFO (f
)->color_list
= list
;
1189 FRAME_W32_DISPLAY_INFO (f
)->num_colors
++;
1191 /* set flag that palette must be regenerated */
1192 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1196 w32_unmap_color (FRAME_PTR f
, COLORREF color
)
1198 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1199 struct w32_palette_entry
**prev
= &FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1201 if (NILP (Vw32_enable_palette
))
1204 /* check if color is already mapped */
1207 if (W32_COLOR (list
->entry
) == color
)
1209 if (--list
->refcount
== 0)
1213 FRAME_W32_DISPLAY_INFO (f
)->num_colors
--;
1223 /* set flag that palette must be regenerated */
1224 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1229 /* Gamma-correct COLOR on frame F. */
1232 gamma_correct (f
, color
)
1238 *color
= PALETTERGB (
1239 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1240 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1241 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1246 /* Decide if color named COLOR is valid for the display associated with
1247 the selected frame; if so, return the rgb values in COLOR_DEF.
1248 If ALLOC is nonzero, allocate a new colormap cell. */
1251 w32_defined_color (f
, color
, color_def
, alloc
)
1257 register Lisp_Object tem
;
1258 COLORREF w32_color_ref
;
1260 tem
= x_to_w32_color (color
);
1266 /* Apply gamma correction. */
1267 w32_color_ref
= XUINT (tem
);
1268 gamma_correct (f
, &w32_color_ref
);
1269 XSETINT (tem
, w32_color_ref
);
1272 /* Map this color to the palette if it is enabled. */
1273 if (!NILP (Vw32_enable_palette
))
1275 struct w32_palette_entry
* entry
=
1276 one_w32_display_info
.color_list
;
1277 struct w32_palette_entry
** prev
=
1278 &one_w32_display_info
.color_list
;
1280 /* check if color is already mapped */
1283 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1285 prev
= &entry
->next
;
1286 entry
= entry
->next
;
1289 if (entry
== NULL
&& alloc
)
1291 /* not already mapped, so add to list */
1292 entry
= (struct w32_palette_entry
*)
1293 xmalloc (sizeof (struct w32_palette_entry
));
1294 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1297 one_w32_display_info
.num_colors
++;
1299 /* set flag that palette must be regenerated */
1300 one_w32_display_info
.regen_palette
= TRUE
;
1303 /* Ensure COLORREF value is snapped to nearest color in (default)
1304 palette by simulating the PALETTERGB macro. This works whether
1305 or not the display device has a palette. */
1306 w32_color_ref
= XUINT (tem
) | 0x2000000;
1308 color_def
->pixel
= w32_color_ref
;
1309 color_def
->red
= GetRValue (w32_color_ref
) * 256;
1310 color_def
->green
= GetGValue (w32_color_ref
) * 256;
1311 color_def
->blue
= GetBValue (w32_color_ref
) * 256;
1321 /* Given a string ARG naming a color, compute a pixel value from it
1322 suitable for screen F.
1323 If F is not a color screen, return DEF (default) regardless of what
1327 x_decode_color (f
, arg
, def
)
1336 if (strcmp (SDATA (arg
), "black") == 0)
1337 return BLACK_PIX_DEFAULT (f
);
1338 else if (strcmp (SDATA (arg
), "white") == 0)
1339 return WHITE_PIX_DEFAULT (f
);
1341 if ((FRAME_W32_DISPLAY_INFO (f
)->n_planes
* FRAME_W32_DISPLAY_INFO (f
)->n_cbits
) == 1)
1344 /* w32_defined_color is responsible for coping with failures
1345 by looking for a near-miss. */
1346 if (w32_defined_color (f
, SDATA (arg
), &cdef
, 1))
1349 /* defined_color failed; return an ultimate default. */
1355 /* Functions called only from `x_set_frame_param'
1356 to set individual parameters.
1358 If FRAME_W32_WINDOW (f) is 0,
1359 the frame is being created and its window does not exist yet.
1360 In that case, just record the parameter's new value
1361 in the standard place; do not attempt to change the window. */
1364 x_set_foreground_color (f
, arg
, oldval
)
1366 Lisp_Object arg
, oldval
;
1368 struct w32_output
*x
= f
->output_data
.w32
;
1369 PIX_TYPE fg
, old_fg
;
1371 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1372 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
1373 FRAME_FOREGROUND_PIXEL (f
) = fg
;
1375 if (FRAME_W32_WINDOW (f
) != 0)
1377 if (x
->cursor_pixel
== old_fg
)
1378 x
->cursor_pixel
= fg
;
1380 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
1381 if (FRAME_VISIBLE_P (f
))
1387 x_set_background_color (f
, arg
, oldval
)
1389 Lisp_Object arg
, oldval
;
1391 FRAME_BACKGROUND_PIXEL (f
)
1392 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
1394 if (FRAME_W32_WINDOW (f
) != 0)
1396 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
1397 FRAME_BACKGROUND_PIXEL (f
));
1399 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
1401 if (FRAME_VISIBLE_P (f
))
1407 x_set_mouse_color (f
, arg
, oldval
)
1409 Lisp_Object arg
, oldval
;
1411 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
1415 if (!EQ (Qnil
, arg
))
1416 f
->output_data
.w32
->mouse_pixel
1417 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1418 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
1420 /* Don't let pointers be invisible. */
1421 if (mask_color
== f
->output_data
.w32
->mouse_pixel
1422 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
1423 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
1425 #if 0 /* TODO : cursor changes */
1428 /* It's not okay to crash if the user selects a screwy cursor. */
1429 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
1431 if (!EQ (Qnil
, Vx_pointer_shape
))
1433 CHECK_NUMBER (Vx_pointer_shape
);
1434 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
1437 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1438 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
1440 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
1442 CHECK_NUMBER (Vx_nontext_pointer_shape
);
1443 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1444 XINT (Vx_nontext_pointer_shape
));
1447 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
1448 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1450 if (!EQ (Qnil
, Vx_hourglass_pointer_shape
))
1452 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
1453 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1454 XINT (Vx_hourglass_pointer_shape
));
1457 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
1458 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
1460 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1461 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
1463 CHECK_NUMBER (Vx_mode_pointer_shape
);
1464 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1465 XINT (Vx_mode_pointer_shape
));
1468 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1469 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
1471 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
1473 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
1475 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1476 XINT (Vx_sensitive_text_pointer_shape
));
1479 hand_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
1481 if (!NILP (Vx_window_horizontal_drag_shape
))
1483 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
1484 horizontal_drag_cursor
1485 = XCreateFontCursor (FRAME_X_DISPLAY (f
),
1486 XINT (Vx_window_horizontal_drag_shape
));
1489 horizontal_drag_cursor
1490 = XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_sb_h_double_arrow
);
1492 /* Check and report errors with the above calls. */
1493 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
1494 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
1497 XColor fore_color
, back_color
;
1499 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
1500 back_color
.pixel
= mask_color
;
1501 XQueryColor (FRAME_W32_DISPLAY (f
),
1502 DefaultColormap (FRAME_W32_DISPLAY (f
),
1503 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1505 XQueryColor (FRAME_W32_DISPLAY (f
),
1506 DefaultColormap (FRAME_W32_DISPLAY (f
),
1507 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1509 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
1510 &fore_color
, &back_color
);
1511 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
1512 &fore_color
, &back_color
);
1513 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
1514 &fore_color
, &back_color
);
1515 XRecolorCursor (FRAME_W32_DISPLAY (f
), hand_cursor
,
1516 &fore_color
, &back_color
);
1517 XRecolorCursor (FRAME_W32_DISPLAY (f
), hourglass_cursor
,
1518 &fore_color
, &back_color
);
1521 if (FRAME_W32_WINDOW (f
) != 0)
1522 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
1524 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
1525 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
1526 f
->output_data
.w32
->text_cursor
= cursor
;
1528 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
1529 && f
->output_data
.w32
->nontext_cursor
!= 0)
1530 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
1531 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
1533 if (hourglass_cursor
!= f
->output_data
.w32
->hourglass_cursor
1534 && f
->output_data
.w32
->hourglass_cursor
!= 0)
1535 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hourglass_cursor
);
1536 f
->output_data
.w32
->hourglass_cursor
= hourglass_cursor
;
1538 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
1539 && f
->output_data
.w32
->modeline_cursor
!= 0)
1540 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
1541 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
1543 if (hand_cursor
!= f
->output_data
.w32
->hand_cursor
1544 && f
->output_data
.w32
->hand_cursor
!= 0)
1545 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hand_cursor
);
1546 f
->output_data
.w32
->hand_cursor
= hand_cursor
;
1548 XFlush (FRAME_W32_DISPLAY (f
));
1551 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1555 /* Defined in w32term.c. */
1557 x_set_cursor_color (f
, arg
, oldval
)
1559 Lisp_Object arg
, oldval
;
1561 unsigned long fore_pixel
, pixel
;
1563 if (!NILP (Vx_cursor_fore_pixel
))
1564 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1565 WHITE_PIX_DEFAULT (f
));
1567 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1569 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1571 /* Make sure that the cursor color differs from the background color. */
1572 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
1574 pixel
= f
->output_data
.w32
->mouse_pixel
;
1575 if (pixel
== fore_pixel
)
1576 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1579 f
->output_data
.w32
->cursor_foreground_pixel
= fore_pixel
;
1580 f
->output_data
.w32
->cursor_pixel
= pixel
;
1582 if (FRAME_W32_WINDOW (f
) != 0)
1585 /* Update frame's cursor_gc. */
1586 f
->output_data
.w32
->cursor_gc
->foreground
= fore_pixel
;
1587 f
->output_data
.w32
->cursor_gc
->background
= pixel
;
1591 if (FRAME_VISIBLE_P (f
))
1593 x_update_cursor (f
, 0);
1594 x_update_cursor (f
, 1);
1598 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1601 /* Set the border-color of frame F to pixel value PIX.
1602 Note that this does not fully take effect if done before
1606 x_set_border_pixel (f
, pix
)
1611 f
->output_data
.w32
->border_pixel
= pix
;
1613 if (FRAME_W32_WINDOW (f
) != 0 && f
->border_width
> 0)
1615 if (FRAME_VISIBLE_P (f
))
1620 /* Set the border-color of frame F to value described by ARG.
1621 ARG can be a string naming a color.
1622 The border-color is used for the border that is drawn by the server.
1623 Note that this does not fully take effect if done before
1624 F has a window; it must be redone when the window is created. */
1627 x_set_border_color (f
, arg
, oldval
)
1629 Lisp_Object arg
, oldval
;
1634 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1635 x_set_border_pixel (f
, pix
);
1636 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1641 x_set_cursor_type (f
, arg
, oldval
)
1643 Lisp_Object arg
, oldval
;
1645 set_frame_cursor_types (f
, arg
);
1647 /* Make sure the cursor gets redrawn. */
1648 cursor_type_changed
= 1;
1652 x_set_icon_type (f
, arg
, oldval
)
1654 Lisp_Object arg
, oldval
;
1658 if (NILP (arg
) && NILP (oldval
))
1661 if (STRINGP (arg
) && STRINGP (oldval
)
1662 && EQ (Fstring_equal (oldval
, arg
), Qt
))
1665 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
1670 result
= x_bitmap_icon (f
, arg
);
1674 error ("No icon window available");
1681 x_set_icon_name (f
, arg
, oldval
)
1683 Lisp_Object arg
, oldval
;
1687 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1690 else if (!NILP (arg
) || NILP (oldval
))
1696 if (f
->output_data
.w32
->icon_bitmap
!= 0)
1701 result
= x_text_icon (f
,
1702 (char *) SDATA ((!NILP (f
->icon_name
)
1711 error ("No icon window available");
1714 /* If the window was unmapped (and its icon was mapped),
1715 the new icon is not mapped, so map the window in its stead. */
1716 if (FRAME_VISIBLE_P (f
))
1718 #ifdef USE_X_TOOLKIT
1719 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
1721 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
1724 XFlush (FRAME_W32_DISPLAY (f
));
1731 x_set_menu_bar_lines (f
, value
, oldval
)
1733 Lisp_Object value
, oldval
;
1736 int olines
= FRAME_MENU_BAR_LINES (f
);
1738 /* Right now, menu bars don't work properly in minibuf-only frames;
1739 most of the commands try to apply themselves to the minibuffer
1740 frame itself, and get an error because you can't switch buffers
1741 in or split the minibuffer window. */
1742 if (FRAME_MINIBUF_ONLY_P (f
))
1745 if (INTEGERP (value
))
1746 nlines
= XINT (value
);
1750 FRAME_MENU_BAR_LINES (f
) = 0;
1752 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1755 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1756 free_frame_menubar (f
);
1757 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1759 /* Adjust the frame size so that the client (text) dimensions
1760 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
1762 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
1763 do_pending_window_change (0);
1769 /* Set the number of lines used for the tool bar of frame F to VALUE.
1770 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1771 is the old number of tool bar lines. This function changes the
1772 height of all windows on frame F to match the new tool bar height.
1773 The frame's height doesn't change. */
1776 x_set_tool_bar_lines (f
, value
, oldval
)
1778 Lisp_Object value
, oldval
;
1780 int delta
, nlines
, root_height
;
1781 Lisp_Object root_window
;
1783 /* Treat tool bars like menu bars. */
1784 if (FRAME_MINIBUF_ONLY_P (f
))
1787 /* Use VALUE only if an integer >= 0. */
1788 if (INTEGERP (value
) && XINT (value
) >= 0)
1789 nlines
= XFASTINT (value
);
1793 /* Make sure we redisplay all windows in this frame. */
1794 ++windows_or_buffers_changed
;
1796 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
1798 /* Don't resize the tool-bar to more than we have room for. */
1799 root_window
= FRAME_ROOT_WINDOW (f
);
1800 root_height
= WINDOW_TOTAL_LINES (XWINDOW (root_window
));
1801 if (root_height
- delta
< 1)
1803 delta
= root_height
- 1;
1804 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
1807 FRAME_TOOL_BAR_LINES (f
) = nlines
;
1808 change_window_heights (root_window
, delta
);
1811 /* We also have to make sure that the internal border at the top of
1812 the frame, below the menu bar or tool bar, is redrawn when the
1813 tool bar disappears. This is so because the internal border is
1814 below the tool bar if one is displayed, but is below the menu bar
1815 if there isn't a tool bar. The tool bar draws into the area
1816 below the menu bar. */
1817 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
1820 clear_current_matrices (f
);
1823 /* If the tool bar gets smaller, the internal border below it
1824 has to be cleared. It was formerly part of the display
1825 of the larger tool bar, and updating windows won't clear it. */
1828 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1829 int width
= FRAME_PIXEL_WIDTH (f
);
1830 int y
= nlines
* FRAME_LINE_HEIGHT (f
);
1834 HDC hdc
= get_frame_dc (f
);
1835 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
1836 release_frame_dc (f
, hdc
);
1840 if (WINDOWP (f
->tool_bar_window
))
1841 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1846 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1849 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1850 name; if NAME is a string, set F's name to NAME and set
1851 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1853 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1854 suggesting a new name, which lisp code should override; if
1855 F->explicit_name is set, ignore the new name; otherwise, set it. */
1858 x_set_name (f
, name
, explicit)
1863 /* Make sure that requests from lisp code override requests from
1864 Emacs redisplay code. */
1867 /* If we're switching from explicit to implicit, we had better
1868 update the mode lines and thereby update the title. */
1869 if (f
->explicit_name
&& NILP (name
))
1870 update_mode_lines
= 1;
1872 f
->explicit_name
= ! NILP (name
);
1874 else if (f
->explicit_name
)
1877 /* If NAME is nil, set the name to the w32_id_name. */
1880 /* Check for no change needed in this very common case
1881 before we do any consing. */
1882 if (!strcmp (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
,
1885 name
= build_string (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
);
1888 CHECK_STRING (name
);
1890 /* Don't change the name if it's already NAME. */
1891 if (! NILP (Fstring_equal (name
, f
->name
)))
1896 /* For setting the frame title, the title parameter should override
1897 the name parameter. */
1898 if (! NILP (f
->title
))
1901 if (FRAME_W32_WINDOW (f
))
1903 if (STRING_MULTIBYTE (name
))
1904 name
= ENCODE_SYSTEM (name
);
1907 SetWindowText(FRAME_W32_WINDOW (f
), SDATA (name
));
1912 /* This function should be called when the user's lisp code has
1913 specified a name for the frame; the name will override any set by the
1916 x_explicitly_set_name (f
, arg
, oldval
)
1918 Lisp_Object arg
, oldval
;
1920 x_set_name (f
, arg
, 1);
1923 /* This function should be called by Emacs redisplay code to set the
1924 name; names set this way will never override names set by the user's
1927 x_implicitly_set_name (f
, arg
, oldval
)
1929 Lisp_Object arg
, oldval
;
1931 x_set_name (f
, arg
, 0);
1934 /* Change the title of frame F to NAME.
1935 If NAME is nil, use the frame name as the title.
1937 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1938 name; if NAME is a string, set F's name to NAME and set
1939 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1941 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1942 suggesting a new name, which lisp code should override; if
1943 F->explicit_name is set, ignore the new name; otherwise, set it. */
1946 x_set_title (f
, name
, old_name
)
1948 Lisp_Object name
, old_name
;
1950 /* Don't change the title if it's already NAME. */
1951 if (EQ (name
, f
->title
))
1954 update_mode_lines
= 1;
1961 if (FRAME_W32_WINDOW (f
))
1963 if (STRING_MULTIBYTE (name
))
1964 name
= ENCODE_SYSTEM (name
);
1967 SetWindowText(FRAME_W32_WINDOW (f
), SDATA (name
));
1973 void x_set_scroll_bar_default_width (f
)
1976 int wid
= FRAME_COLUMN_WIDTH (f
);
1978 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
1979 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) +
1984 /* Subroutines of creating a frame. */
1987 /* Return the value of parameter PARAM.
1989 First search ALIST, then Vdefault_frame_alist, then the X defaults
1990 database, using ATTRIBUTE as the attribute name and CLASS as its class.
1992 Convert the resource to the type specified by desired_type.
1994 If no default is specified, return Qunbound. If you call
1995 w32_get_arg, make sure you deal with Qunbound in a reasonable way,
1996 and don't let it get stored in any Lisp-visible variables! */
1999 w32_get_arg (alist
, param
, attribute
, class, type
)
2000 Lisp_Object alist
, param
;
2003 enum resource_types type
;
2005 return x_get_arg (check_x_display_info (Qnil
),
2006 alist
, param
, attribute
, class, type
);
2011 w32_load_cursor (LPCTSTR name
)
2013 /* Try first to load cursor from application resource. */
2014 Cursor cursor
= LoadImage ((HINSTANCE
) GetModuleHandle(NULL
),
2015 name
, IMAGE_CURSOR
, 0, 0,
2016 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
2019 /* Then try to load a shared predefined cursor. */
2020 cursor
= LoadImage (NULL
, name
, IMAGE_CURSOR
, 0, 0,
2021 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
2026 extern LRESULT CALLBACK
w32_wnd_proc ();
2029 w32_init_class (hinst
)
2034 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
2035 wc
.lpfnWndProc
= (WNDPROC
) w32_wnd_proc
;
2037 wc
.cbWndExtra
= WND_EXTRA_BYTES
;
2038 wc
.hInstance
= hinst
;
2039 wc
.hIcon
= LoadIcon (hinst
, EMACS_CLASS
);
2040 wc
.hCursor
= w32_load_cursor (IDC_ARROW
);
2041 wc
.hbrBackground
= NULL
; /* GetStockObject (WHITE_BRUSH); */
2042 wc
.lpszMenuName
= NULL
;
2043 wc
.lpszClassName
= EMACS_CLASS
;
2045 return (RegisterClass (&wc
));
2049 w32_createscrollbar (f
, bar
)
2051 struct scroll_bar
* bar
;
2053 return (CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
2054 /* Position and size of scroll bar. */
2055 XINT(bar
->left
) + VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
2057 XINT(bar
->width
) - VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
2059 FRAME_W32_WINDOW (f
),
2066 w32_createwindow (f
)
2071 Lisp_Object top
= Qunbound
;
2072 Lisp_Object left
= Qunbound
;
2074 rect
.left
= rect
.top
= 0;
2075 rect
.right
= FRAME_PIXEL_WIDTH (f
);
2076 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
2078 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
2079 FRAME_EXTERNAL_MENU_BAR (f
));
2081 /* Do first time app init */
2085 w32_init_class (hinst
);
2088 if (f
->size_hint_flags
& USPosition
|| f
->size_hint_flags
& PPosition
)
2090 XSETINT (left
, f
->left_pos
);
2091 XSETINT (top
, f
->top_pos
);
2093 else if (EQ (left
, Qunbound
) && EQ (top
, Qunbound
))
2095 /* When called with RES_TYPE_NUMBER, w32_get_arg will return zero
2096 for anything that is not a number and is not Qunbound. */
2097 left
= w32_get_arg (Qnil
, Qleft
, "left", "Left", RES_TYPE_NUMBER
);
2098 top
= w32_get_arg (Qnil
, Qtop
, "top", "Top", RES_TYPE_NUMBER
);
2101 FRAME_W32_WINDOW (f
) = hwnd
2102 = CreateWindow (EMACS_CLASS
,
2104 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
2105 EQ (left
, Qunbound
) ? CW_USEDEFAULT
: XINT (left
),
2106 EQ (top
, Qunbound
) ? CW_USEDEFAULT
: XINT (top
),
2107 rect
.right
- rect
.left
,
2108 rect
.bottom
- rect
.top
,
2116 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
2117 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
2118 SetWindowLong (hwnd
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
2119 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->scroll_bar_actual_width
);
2120 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
2122 /* Enable drag-n-drop. */
2123 DragAcceptFiles (hwnd
, TRUE
);
2125 /* Do this to discard the default setting specified by our parent. */
2126 ShowWindow (hwnd
, SW_HIDE
);
2128 /* Update frame positions. */
2129 GetWindowRect (hwnd
, &rect
);
2130 f
->left_pos
= rect
.left
;
2131 f
->top_pos
= rect
.top
;
2136 my_post_msg (wmsg
, hwnd
, msg
, wParam
, lParam
)
2143 wmsg
->msg
.hwnd
= hwnd
;
2144 wmsg
->msg
.message
= msg
;
2145 wmsg
->msg
.wParam
= wParam
;
2146 wmsg
->msg
.lParam
= lParam
;
2147 wmsg
->msg
.time
= GetMessageTime ();
2152 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
2153 between left and right keys as advertised. We test for this
2154 support dynamically, and set a flag when the support is absent. If
2155 absent, we keep track of the left and right control and alt keys
2156 ourselves. This is particularly necessary on keyboards that rely
2157 upon the AltGr key, which is represented as having the left control
2158 and right alt keys pressed. For these keyboards, we need to know
2159 when the left alt key has been pressed in addition to the AltGr key
2160 so that we can properly support M-AltGr-key sequences (such as M-@
2161 on Swedish keyboards). */
2163 #define EMACS_LCONTROL 0
2164 #define EMACS_RCONTROL 1
2165 #define EMACS_LMENU 2
2166 #define EMACS_RMENU 3
2168 static int modifiers
[4];
2169 static int modifiers_recorded
;
2170 static int modifier_key_support_tested
;
2173 test_modifier_support (unsigned int wparam
)
2177 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
2179 if (wparam
== VK_CONTROL
)
2189 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
2190 modifiers_recorded
= 1;
2192 modifiers_recorded
= 0;
2193 modifier_key_support_tested
= 1;
2197 record_keydown (unsigned int wparam
, unsigned int lparam
)
2201 if (!modifier_key_support_tested
)
2202 test_modifier_support (wparam
);
2204 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2207 if (wparam
== VK_CONTROL
)
2208 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2210 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2216 record_keyup (unsigned int wparam
, unsigned int lparam
)
2220 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2223 if (wparam
== VK_CONTROL
)
2224 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2226 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2231 /* Emacs can lose focus while a modifier key has been pressed. When
2232 it regains focus, be conservative and clear all modifiers since
2233 we cannot reconstruct the left and right modifier state. */
2239 if (GetFocus () == NULL
)
2240 /* Emacs doesn't have keyboard focus. Do nothing. */
2243 ctrl
= GetAsyncKeyState (VK_CONTROL
);
2244 alt
= GetAsyncKeyState (VK_MENU
);
2246 if (!(ctrl
& 0x08000))
2247 /* Clear any recorded control modifier state. */
2248 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2250 if (!(alt
& 0x08000))
2251 /* Clear any recorded alt modifier state. */
2252 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2254 /* Update the state of all modifier keys, because modifiers used in
2255 hot-key combinations can get stuck on if Emacs loses focus as a
2256 result of a hot-key being pressed. */
2260 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
2262 GetKeyboardState (keystate
);
2263 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
2264 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
2265 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
2266 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
2267 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
2268 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
2269 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
2270 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
2271 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
2272 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
2273 SetKeyboardState (keystate
);
2277 /* Synchronize modifier state with what is reported with the current
2278 keystroke. Even if we cannot distinguish between left and right
2279 modifier keys, we know that, if no modifiers are set, then neither
2280 the left or right modifier should be set. */
2284 if (!modifiers_recorded
)
2287 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
2288 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2290 if (!(GetKeyState (VK_MENU
) & 0x8000))
2291 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2295 modifier_set (int vkey
)
2297 if (vkey
== VK_CAPITAL
|| vkey
== VK_SCROLL
)
2298 return (GetKeyState (vkey
) & 0x1);
2299 if (!modifiers_recorded
)
2300 return (GetKeyState (vkey
) & 0x8000);
2305 return modifiers
[EMACS_LCONTROL
];
2307 return modifiers
[EMACS_RCONTROL
];
2309 return modifiers
[EMACS_LMENU
];
2311 return modifiers
[EMACS_RMENU
];
2313 return (GetKeyState (vkey
) & 0x8000);
2316 /* Convert between the modifier bits W32 uses and the modifier bits
2320 w32_key_to_modifier (int key
)
2322 Lisp_Object key_mapping
;
2327 key_mapping
= Vw32_lwindow_modifier
;
2330 key_mapping
= Vw32_rwindow_modifier
;
2333 key_mapping
= Vw32_apps_modifier
;
2336 key_mapping
= Vw32_scroll_lock_modifier
;
2342 /* NB. This code runs in the input thread, asychronously to the lisp
2343 thread, so we must be careful to ensure access to lisp data is
2344 thread-safe. The following code is safe because the modifier
2345 variable values are updated atomically from lisp and symbols are
2346 not relocated by GC. Also, we don't have to worry about seeing GC
2348 if (EQ (key_mapping
, Qhyper
))
2349 return hyper_modifier
;
2350 if (EQ (key_mapping
, Qsuper
))
2351 return super_modifier
;
2352 if (EQ (key_mapping
, Qmeta
))
2353 return meta_modifier
;
2354 if (EQ (key_mapping
, Qalt
))
2355 return alt_modifier
;
2356 if (EQ (key_mapping
, Qctrl
))
2357 return ctrl_modifier
;
2358 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
2359 return ctrl_modifier
;
2360 if (EQ (key_mapping
, Qshift
))
2361 return shift_modifier
;
2363 /* Don't generate any modifier if not explicitly requested. */
2368 w32_get_modifiers ()
2370 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
2371 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
2372 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
2373 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
2374 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
2375 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
2376 (modifier_set (VK_MENU
) ?
2377 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
2380 /* We map the VK_* modifiers into console modifier constants
2381 so that we can use the same routines to handle both console
2382 and window input. */
2385 construct_console_modifiers ()
2390 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
2391 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
2392 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
2393 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
2394 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
2395 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
2396 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
2397 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
2398 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
2399 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
2400 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
2406 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
2410 /* Convert to emacs modifiers. */
2411 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
2417 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
2419 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
2422 if (virt_key
== VK_RETURN
)
2423 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
2425 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
2426 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
2428 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
2429 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
2431 if (virt_key
== VK_CLEAR
)
2432 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
2437 /* List of special key combinations which w32 would normally capture,
2438 but emacs should grab instead. Not directly visible to lisp, to
2439 simplify synchronization. Each item is an integer encoding a virtual
2440 key code and modifier combination to capture. */
2441 Lisp_Object w32_grabbed_keys
;
2443 #define HOTKEY(vk,mods) make_number (((vk) & 255) | ((mods) << 8))
2444 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
2445 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
2446 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
2448 #define RAW_HOTKEY_ID(k) ((k) & 0xbfff)
2449 #define RAW_HOTKEY_VK_CODE(k) ((k) & 255)
2450 #define RAW_HOTKEY_MODIFIERS(k) ((k) >> 8)
2452 /* Register hot-keys for reserved key combinations when Emacs has
2453 keyboard focus, since this is the only way Emacs can receive key
2454 combinations like Alt-Tab which are used by the system. */
2457 register_hot_keys (hwnd
)
2460 Lisp_Object keylist
;
2462 /* Use GC_CONSP, since we are called asynchronously. */
2463 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
2465 Lisp_Object key
= XCAR (keylist
);
2467 /* Deleted entries get set to nil. */
2468 if (!INTEGERP (key
))
2471 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
2472 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
2477 unregister_hot_keys (hwnd
)
2480 Lisp_Object keylist
;
2482 /* Use GC_CONSP, since we are called asynchronously. */
2483 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
2485 Lisp_Object key
= XCAR (keylist
);
2487 if (!INTEGERP (key
))
2490 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
2494 /* Main message dispatch loop. */
2497 w32_msg_pump (deferred_msg
* msg_buf
)
2503 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
2505 while (GetMessage (&msg
, NULL
, 0, 0))
2507 if (msg
.hwnd
== NULL
)
2509 switch (msg
.message
)
2512 /* Produced by complete_deferred_msg; just ignore. */
2514 case WM_EMACS_CREATEWINDOW
:
2515 w32_createwindow ((struct frame
*) msg
.wParam
);
2516 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2519 case WM_EMACS_SETLOCALE
:
2520 SetThreadLocale (msg
.wParam
);
2521 /* Reply is not expected. */
2523 case WM_EMACS_SETKEYBOARDLAYOUT
:
2524 result
= (int) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
2525 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2529 case WM_EMACS_REGISTER_HOT_KEY
:
2530 focus_window
= GetFocus ();
2531 if (focus_window
!= NULL
)
2532 RegisterHotKey (focus_window
,
2533 RAW_HOTKEY_ID (msg
.wParam
),
2534 RAW_HOTKEY_MODIFIERS (msg
.wParam
),
2535 RAW_HOTKEY_VK_CODE (msg
.wParam
));
2536 /* Reply is not expected. */
2538 case WM_EMACS_UNREGISTER_HOT_KEY
:
2539 focus_window
= GetFocus ();
2540 if (focus_window
!= NULL
)
2541 UnregisterHotKey (focus_window
, RAW_HOTKEY_ID (msg
.wParam
));
2542 /* Mark item as erased. NB: this code must be
2543 thread-safe. The next line is okay because the cons
2544 cell is never made into garbage and is not relocated by
2546 XSETCAR ((Lisp_Object
) ((EMACS_INT
) msg
.lParam
), Qnil
);
2547 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2550 case WM_EMACS_TOGGLE_LOCK_KEY
:
2552 int vk_code
= (int) msg
.wParam
;
2553 int cur_state
= (GetKeyState (vk_code
) & 1);
2554 Lisp_Object new_state
= (Lisp_Object
) ((EMACS_INT
) msg
.lParam
);
2556 /* NB: This code must be thread-safe. It is safe to
2557 call NILP because symbols are not relocated by GC,
2558 and pointer here is not touched by GC (so the markbit
2559 can't be set). Numbers are safe because they are
2560 immediate values. */
2561 if (NILP (new_state
)
2562 || (NUMBERP (new_state
)
2563 && ((XUINT (new_state
)) & 1) != cur_state
))
2565 one_w32_display_info
.faked_key
= vk_code
;
2567 keybd_event ((BYTE
) vk_code
,
2568 (BYTE
) MapVirtualKey (vk_code
, 0),
2569 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2570 keybd_event ((BYTE
) vk_code
,
2571 (BYTE
) MapVirtualKey (vk_code
, 0),
2572 KEYEVENTF_EXTENDEDKEY
| 0, 0);
2573 keybd_event ((BYTE
) vk_code
,
2574 (BYTE
) MapVirtualKey (vk_code
, 0),
2575 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2576 cur_state
= !cur_state
;
2578 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2584 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
2589 DispatchMessage (&msg
);
2592 /* Exit nested loop when our deferred message has completed. */
2593 if (msg_buf
->completed
)
2598 deferred_msg
* deferred_msg_head
;
2600 static deferred_msg
*
2601 find_deferred_msg (HWND hwnd
, UINT msg
)
2603 deferred_msg
* item
;
2605 /* Don't actually need synchronization for read access, since
2606 modification of single pointer is always atomic. */
2607 /* enter_crit (); */
2609 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2610 if (item
->w32msg
.msg
.hwnd
== hwnd
2611 && item
->w32msg
.msg
.message
== msg
)
2614 /* leave_crit (); */
2620 send_deferred_msg (deferred_msg
* msg_buf
,
2626 /* Only input thread can send deferred messages. */
2627 if (GetCurrentThreadId () != dwWindowsThreadId
)
2630 /* It is an error to send a message that is already deferred. */
2631 if (find_deferred_msg (hwnd
, msg
) != NULL
)
2634 /* Enforced synchronization is not needed because this is the only
2635 function that alters deferred_msg_head, and the following critical
2636 section is guaranteed to only be serially reentered (since only the
2637 input thread can call us). */
2639 /* enter_crit (); */
2641 msg_buf
->completed
= 0;
2642 msg_buf
->next
= deferred_msg_head
;
2643 deferred_msg_head
= msg_buf
;
2644 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
2646 /* leave_crit (); */
2648 /* Start a new nested message loop to process other messages until
2649 this one is completed. */
2650 w32_msg_pump (msg_buf
);
2652 deferred_msg_head
= msg_buf
->next
;
2654 return msg_buf
->result
;
2658 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
2660 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
2662 if (msg_buf
== NULL
)
2663 /* Message may have been cancelled, so don't abort(). */
2666 msg_buf
->result
= result
;
2667 msg_buf
->completed
= 1;
2669 /* Ensure input thread is woken so it notices the completion. */
2670 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2674 cancel_all_deferred_msgs ()
2676 deferred_msg
* item
;
2678 /* Don't actually need synchronization for read access, since
2679 modification of single pointer is always atomic. */
2680 /* enter_crit (); */
2682 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2685 item
->completed
= 1;
2688 /* leave_crit (); */
2690 /* Ensure input thread is woken so it notices the completion. */
2691 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2695 w32_msg_worker (void *arg
)
2698 deferred_msg dummy_buf
;
2700 /* Ensure our message queue is created */
2702 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
2704 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2707 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
2708 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
2709 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
2711 /* This is the inital message loop which should only exit when the
2712 application quits. */
2713 w32_msg_pump (&dummy_buf
);
2719 signal_user_input ()
2721 /* Interrupt any lisp that wants to be interrupted by input. */
2722 if (!NILP (Vthrow_on_input
))
2724 Vquit_flag
= Vthrow_on_input
;
2725 /* If we're inside a function that wants immediate quits,
2727 if (immediate_quit
&& NILP (Vinhibit_quit
))
2737 post_character_message (hwnd
, msg
, wParam
, lParam
, modifiers
)
2747 wmsg
.dwModifiers
= modifiers
;
2749 /* Detect quit_char and set quit-flag directly. Note that we
2750 still need to post a message to ensure the main thread will be
2751 woken up if blocked in sys_select(), but we do NOT want to post
2752 the quit_char message itself (because it will usually be as if
2753 the user had typed quit_char twice). Instead, we post a dummy
2754 message that has no particular effect. */
2757 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
2758 c
= make_ctrl_char (c
) & 0377;
2760 || (wmsg
.dwModifiers
== 0 &&
2761 w32_quit_key
&& wParam
== w32_quit_key
))
2765 /* The choice of message is somewhat arbitrary, as long as
2766 the main thread handler just ignores it. */
2769 /* Interrupt any blocking system calls. */
2772 /* As a safety precaution, forcibly complete any deferred
2773 messages. This is a kludge, but I don't see any particularly
2774 clean way to handle the situation where a deferred message is
2775 "dropped" in the lisp thread, and will thus never be
2776 completed, eg. by the user trying to activate the menubar
2777 when the lisp thread is busy, and then typing C-g when the
2778 menubar doesn't open promptly (with the result that the
2779 menubar never responds at all because the deferred
2780 WM_INITMENU message is never completed). Another problem
2781 situation is when the lisp thread calls SendMessage (to send
2782 a window manager command) when a message has been deferred;
2783 the lisp thread gets blocked indefinitely waiting for the
2784 deferred message to be completed, which itself is waiting for
2785 the lisp thread to respond.
2787 Note that we don't want to block the input thread waiting for
2788 a reponse from the lisp thread (although that would at least
2789 solve the deadlock problem above), because we want to be able
2790 to receive C-g to interrupt the lisp thread. */
2791 cancel_all_deferred_msgs ();
2794 signal_user_input ();
2797 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2800 /* Main window procedure */
2803 w32_wnd_proc (hwnd
, msg
, wParam
, lParam
)
2810 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
2812 int windows_translate
;
2815 /* Note that it is okay to call x_window_to_frame, even though we are
2816 not running in the main lisp thread, because frame deletion
2817 requires the lisp thread to synchronize with this thread. Thus, if
2818 a frame struct is returned, it can be used without concern that the
2819 lisp thread might make it disappear while we are using it.
2821 NB. Walking the frame list in this thread is safe (as long as
2822 writes of Lisp_Object slots are atomic, which they are on Windows).
2823 Although delete-frame can destructively modify the frame list while
2824 we are walking it, a garbage collection cannot occur until after
2825 delete-frame has synchronized with this thread.
2827 It is also safe to use functions that make GDI calls, such as
2828 w32_clear_rect, because these functions must obtain a DC handle
2829 from the frame struct using get_frame_dc which is thread-aware. */
2834 f
= x_window_to_frame (dpyinfo
, hwnd
);
2837 HDC hdc
= get_frame_dc (f
);
2838 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
2839 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
2840 release_frame_dc (f
, hdc
);
2842 #if defined (W32_DEBUG_DISPLAY)
2843 DebPrint (("WM_ERASEBKGND (frame %p): erasing %d,%d-%d,%d\n",
2845 wmsg
.rect
.left
, wmsg
.rect
.top
,
2846 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2847 #endif /* W32_DEBUG_DISPLAY */
2850 case WM_PALETTECHANGED
:
2851 /* ignore our own changes */
2852 if ((HWND
)wParam
!= hwnd
)
2854 f
= x_window_to_frame (dpyinfo
, hwnd
);
2856 /* get_frame_dc will realize our palette and force all
2857 frames to be redrawn if needed. */
2858 release_frame_dc (f
, get_frame_dc (f
));
2863 PAINTSTRUCT paintStruct
;
2865 bzero (&update_rect
, sizeof (update_rect
));
2867 f
= x_window_to_frame (dpyinfo
, hwnd
);
2870 DebPrint (("WM_PAINT received for unknown window %p\n", hwnd
));
2874 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
2875 fails. Apparently this can happen under some
2877 if (GetUpdateRect (hwnd
, &update_rect
, FALSE
) || !w32_strict_painting
)
2880 BeginPaint (hwnd
, &paintStruct
);
2882 /* The rectangles returned by GetUpdateRect and BeginPaint
2883 do not always match. Play it safe by assuming both areas
2885 UnionRect (&(wmsg
.rect
), &update_rect
, &(paintStruct
.rcPaint
));
2887 #if defined (W32_DEBUG_DISPLAY)
2888 DebPrint (("WM_PAINT (frame %p): painting %d,%d-%d,%d\n",
2890 wmsg
.rect
.left
, wmsg
.rect
.top
,
2891 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2892 DebPrint ((" [update region is %d,%d-%d,%d]\n",
2893 update_rect
.left
, update_rect
.top
,
2894 update_rect
.right
, update_rect
.bottom
));
2896 EndPaint (hwnd
, &paintStruct
);
2899 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2904 /* If GetUpdateRect returns 0 (meaning there is no update
2905 region), assume the whole window needs to be repainted. */
2906 GetClientRect(hwnd
, &wmsg
.rect
);
2907 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2911 case WM_INPUTLANGCHANGE
:
2912 /* Inform lisp thread of keyboard layout changes. */
2913 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2915 /* Clear dead keys in the keyboard state; for simplicity only
2916 preserve modifier key states. */
2921 GetKeyboardState (keystate
);
2922 for (i
= 0; i
< 256; i
++)
2939 SetKeyboardState (keystate
);
2944 /* Synchronize hot keys with normal input. */
2945 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
2950 record_keyup (wParam
, lParam
);
2955 /* Ignore keystrokes we fake ourself; see below. */
2956 if (dpyinfo
->faked_key
== wParam
)
2958 dpyinfo
->faked_key
= 0;
2959 /* Make sure TranslateMessage sees them though (as long as
2960 they don't produce WM_CHAR messages). This ensures that
2961 indicator lights are toggled promptly on Windows 9x, for
2963 if (lispy_function_keys
[wParam
] != 0)
2965 windows_translate
= 1;
2971 /* Synchronize modifiers with current keystroke. */
2973 record_keydown (wParam
, lParam
);
2974 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
2976 windows_translate
= 0;
2981 if (NILP (Vw32_pass_lwindow_to_system
))
2983 /* Prevent system from acting on keyup (which opens the
2984 Start menu if no other key was pressed) by simulating a
2985 press of Space which we will ignore. */
2986 if (GetAsyncKeyState (wParam
) & 1)
2988 if (NUMBERP (Vw32_phantom_key_code
))
2989 key
= XUINT (Vw32_phantom_key_code
) & 255;
2992 dpyinfo
->faked_key
= key
;
2993 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
2996 if (!NILP (Vw32_lwindow_modifier
))
3000 if (NILP (Vw32_pass_rwindow_to_system
))
3002 if (GetAsyncKeyState (wParam
) & 1)
3004 if (NUMBERP (Vw32_phantom_key_code
))
3005 key
= XUINT (Vw32_phantom_key_code
) & 255;
3008 dpyinfo
->faked_key
= key
;
3009 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
3012 if (!NILP (Vw32_rwindow_modifier
))
3016 if (!NILP (Vw32_apps_modifier
))
3020 if (NILP (Vw32_pass_alt_to_system
))
3021 /* Prevent DefWindowProc from activating the menu bar if an
3022 Alt key is pressed and released by itself. */
3024 windows_translate
= 1;
3027 /* Decide whether to treat as modifier or function key. */
3028 if (NILP (Vw32_enable_caps_lock
))
3029 goto disable_lock_key
;
3030 windows_translate
= 1;
3033 /* Decide whether to treat as modifier or function key. */
3034 if (NILP (Vw32_enable_num_lock
))
3035 goto disable_lock_key
;
3036 windows_translate
= 1;
3039 /* Decide whether to treat as modifier or function key. */
3040 if (NILP (Vw32_scroll_lock_modifier
))
3041 goto disable_lock_key
;
3042 windows_translate
= 1;
3045 /* Ensure the appropriate lock key state (and indicator light)
3046 remains in the same state. We do this by faking another
3047 press of the relevant key. Apparently, this really is the
3048 only way to toggle the state of the indicator lights. */
3049 dpyinfo
->faked_key
= wParam
;
3050 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3051 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3052 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3053 KEYEVENTF_EXTENDEDKEY
| 0, 0);
3054 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3055 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3056 /* Ensure indicator lights are updated promptly on Windows 9x
3057 (TranslateMessage apparently does this), after forwarding
3059 post_character_message (hwnd
, msg
, wParam
, lParam
,
3060 w32_get_key_modifiers (wParam
, lParam
));
3061 windows_translate
= 1;
3065 case VK_PROCESSKEY
: /* Generated by IME. */
3066 windows_translate
= 1;
3069 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
3070 which is confusing for purposes of key binding; convert
3071 VK_CANCEL events into VK_PAUSE events. */
3075 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
3076 for purposes of key binding; convert these back into
3077 VK_NUMLOCK events, at least when we want to see NumLock key
3078 presses. (Note that there is never any possibility that
3079 VK_PAUSE with Ctrl really is C-Pause as per above.) */
3080 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
3081 wParam
= VK_NUMLOCK
;
3084 /* If not defined as a function key, change it to a WM_CHAR message. */
3085 if (lispy_function_keys
[wParam
] == 0)
3087 DWORD modifiers
= construct_console_modifiers ();
3089 if (!NILP (Vw32_recognize_altgr
)
3090 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
3092 /* Always let TranslateMessage handle AltGr key chords;
3093 for some reason, ToAscii doesn't always process AltGr
3094 chords correctly. */
3095 windows_translate
= 1;
3097 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
3099 /* Handle key chords including any modifiers other
3100 than shift directly, in order to preserve as much
3101 modifier information as possible. */
3102 if ('A' <= wParam
&& wParam
<= 'Z')
3104 /* Don't translate modified alphabetic keystrokes,
3105 so the user doesn't need to constantly switch
3106 layout to type control or meta keystrokes when
3107 the normal layout translates alphabetic
3108 characters to non-ascii characters. */
3109 if (!modifier_set (VK_SHIFT
))
3110 wParam
+= ('a' - 'A');
3115 /* Try to handle other keystrokes by determining the
3116 base character (ie. translating the base key plus
3120 KEY_EVENT_RECORD key
;
3122 key
.bKeyDown
= TRUE
;
3123 key
.wRepeatCount
= 1;
3124 key
.wVirtualKeyCode
= wParam
;
3125 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
3126 key
.uChar
.AsciiChar
= 0;
3127 key
.dwControlKeyState
= modifiers
;
3129 add
= w32_kbd_patch_key (&key
);
3130 /* 0 means an unrecognised keycode, negative means
3131 dead key. Ignore both. */
3134 /* Forward asciified character sequence. */
3135 post_character_message
3136 (hwnd
, WM_CHAR
, key
.uChar
.AsciiChar
, lParam
,
3137 w32_get_key_modifiers (wParam
, lParam
));
3138 w32_kbd_patch_key (&key
);
3145 /* Let TranslateMessage handle everything else. */
3146 windows_translate
= 1;
3152 if (windows_translate
)
3154 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
3156 windows_msg
.time
= GetMessageTime ();
3157 TranslateMessage (&windows_msg
);
3165 post_character_message (hwnd
, msg
, wParam
, lParam
,
3166 w32_get_key_modifiers (wParam
, lParam
));
3169 /* Simulate middle mouse button events when left and right buttons
3170 are used together, but only if user has two button mouse. */
3171 case WM_LBUTTONDOWN
:
3172 case WM_RBUTTONDOWN
:
3173 if (w32_num_mouse_buttons
> 2)
3174 goto handle_plain_button
;
3177 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
3178 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
3180 if (button_state
& this)
3183 if (button_state
== 0)
3186 button_state
|= this;
3188 if (button_state
& other
)
3190 if (mouse_button_timer
)
3192 KillTimer (hwnd
, mouse_button_timer
);
3193 mouse_button_timer
= 0;
3195 /* Generate middle mouse event instead. */
3196 msg
= WM_MBUTTONDOWN
;
3197 button_state
|= MMOUSE
;
3199 else if (button_state
& MMOUSE
)
3201 /* Ignore button event if we've already generated a
3202 middle mouse down event. This happens if the
3203 user releases and press one of the two buttons
3204 after we've faked a middle mouse event. */
3209 /* Flush out saved message. */
3210 post_msg (&saved_mouse_button_msg
);
3212 wmsg
.dwModifiers
= w32_get_modifiers ();
3213 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3214 signal_user_input ();
3216 /* Clear message buffer. */
3217 saved_mouse_button_msg
.msg
.hwnd
= 0;
3221 /* Hold onto message for now. */
3222 mouse_button_timer
=
3223 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
3224 w32_mouse_button_tolerance
, NULL
);
3225 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
3226 saved_mouse_button_msg
.msg
.message
= msg
;
3227 saved_mouse_button_msg
.msg
.wParam
= wParam
;
3228 saved_mouse_button_msg
.msg
.lParam
= lParam
;
3229 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
3230 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
3237 if (w32_num_mouse_buttons
> 2)
3238 goto handle_plain_button
;
3241 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
3242 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
3244 if ((button_state
& this) == 0)
3247 button_state
&= ~this;
3249 if (button_state
& MMOUSE
)
3251 /* Only generate event when second button is released. */
3252 if ((button_state
& other
) == 0)
3255 button_state
&= ~MMOUSE
;
3257 if (button_state
) abort ();
3264 /* Flush out saved message if necessary. */
3265 if (saved_mouse_button_msg
.msg
.hwnd
)
3267 post_msg (&saved_mouse_button_msg
);
3270 wmsg
.dwModifiers
= w32_get_modifiers ();
3271 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3272 signal_user_input ();
3274 /* Always clear message buffer and cancel timer. */
3275 saved_mouse_button_msg
.msg
.hwnd
= 0;
3276 KillTimer (hwnd
, mouse_button_timer
);
3277 mouse_button_timer
= 0;
3279 if (button_state
== 0)
3284 case WM_XBUTTONDOWN
:
3286 if (w32_pass_extra_mouse_buttons_to_system
)
3288 /* else fall through and process them. */
3289 case WM_MBUTTONDOWN
:
3291 handle_plain_button
:
3296 /* Ignore middle and extra buttons as long as the menu is active. */
3297 f
= x_window_to_frame (dpyinfo
, hwnd
);
3298 if (f
&& f
->output_data
.w32
->menubar_active
)
3301 if (parse_button (msg
, HIWORD (wParam
), &button
, &up
))
3303 if (up
) ReleaseCapture ();
3304 else SetCapture (hwnd
);
3305 button
= (button
== 0) ? LMOUSE
:
3306 ((button
== 1) ? MMOUSE
: RMOUSE
);
3308 button_state
&= ~button
;
3310 button_state
|= button
;
3314 wmsg
.dwModifiers
= w32_get_modifiers ();
3315 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3316 signal_user_input ();
3318 /* Need to return true for XBUTTON messages, false for others,
3319 to indicate that we processed the message. */
3320 return (msg
== WM_XBUTTONDOWN
|| msg
== WM_XBUTTONUP
);
3323 /* Ignore mouse movements as long as the menu is active. These
3324 movements are processed by the window manager anyway, and
3325 it's wrong to handle them as if they happened on the
3326 underlying frame. */
3327 f
= x_window_to_frame (dpyinfo
, hwnd
);
3328 if (f
&& f
->output_data
.w32
->menubar_active
)
3331 /* If the mouse has just moved into the frame, start tracking
3332 it, so we will be notified when it leaves the frame. Mouse
3333 tracking only works under W98 and NT4 and later. On earlier
3334 versions, there is no way of telling when the mouse leaves the
3335 frame, so we just have to put up with help-echo and mouse
3336 highlighting remaining while the frame is not active. */
3337 if (track_mouse_event_fn
&& !track_mouse_window
)
3339 TRACKMOUSEEVENT tme
;
3340 tme
.cbSize
= sizeof (tme
);
3341 tme
.dwFlags
= TME_LEAVE
;
3342 tme
.hwndTrack
= hwnd
;
3344 track_mouse_event_fn (&tme
);
3345 track_mouse_window
= hwnd
;
3348 if (w32_mouse_move_interval
<= 0
3349 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
3351 wmsg
.dwModifiers
= w32_get_modifiers ();
3352 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3356 /* Hang onto mouse move and scroll messages for a bit, to avoid
3357 sending such events to Emacs faster than it can process them.
3358 If we get more events before the timer from the first message
3359 expires, we just replace the first message. */
3361 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
3363 SetTimer (hwnd
, MOUSE_MOVE_ID
,
3364 w32_mouse_move_interval
, NULL
);
3366 /* Hold onto message for now. */
3367 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
3368 saved_mouse_move_msg
.msg
.message
= msg
;
3369 saved_mouse_move_msg
.msg
.wParam
= wParam
;
3370 saved_mouse_move_msg
.msg
.lParam
= lParam
;
3371 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
3372 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
3377 wmsg
.dwModifiers
= w32_get_modifiers ();
3378 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3379 signal_user_input ();
3383 wmsg
.dwModifiers
= w32_get_modifiers ();
3384 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3385 signal_user_input ();
3389 /* Flush out saved messages if necessary. */
3390 if (wParam
== mouse_button_timer
)
3392 if (saved_mouse_button_msg
.msg
.hwnd
)
3394 post_msg (&saved_mouse_button_msg
);
3395 signal_user_input ();
3396 saved_mouse_button_msg
.msg
.hwnd
= 0;
3398 KillTimer (hwnd
, mouse_button_timer
);
3399 mouse_button_timer
= 0;
3401 else if (wParam
== mouse_move_timer
)
3403 if (saved_mouse_move_msg
.msg
.hwnd
)
3405 post_msg (&saved_mouse_move_msg
);
3406 saved_mouse_move_msg
.msg
.hwnd
= 0;
3408 KillTimer (hwnd
, mouse_move_timer
);
3409 mouse_move_timer
= 0;
3411 else if (wParam
== menu_free_timer
)
3413 KillTimer (hwnd
, menu_free_timer
);
3414 menu_free_timer
= 0;
3415 f
= x_window_to_frame (dpyinfo
, hwnd
);
3416 /* If a popup menu is active, don't wipe its strings. */
3418 && current_popup_menu
== NULL
)
3420 /* Free memory used by owner-drawn and help-echo strings. */
3421 w32_free_menu_strings (hwnd
);
3422 f
->output_data
.w32
->menubar_active
= 0;
3429 /* Windows doesn't send us focus messages when putting up and
3430 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
3431 The only indication we get that something happened is receiving
3432 this message afterwards. So this is a good time to reset our
3433 keyboard modifiers' state. */
3440 /* We must ensure menu bar is fully constructed and up to date
3441 before allowing user interaction with it. To achieve this
3442 we send this message to the lisp thread and wait for a
3443 reply (whose value is not actually needed) to indicate that
3444 the menu bar is now ready for use, so we can now return.
3446 To remain responsive in the meantime, we enter a nested message
3447 loop that can process all other messages.
3449 However, we skip all this if the message results from calling
3450 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
3451 thread a message because it is blocked on us at this point. We
3452 set menubar_active before calling TrackPopupMenu to indicate
3453 this (there is no possibility of confusion with real menubar
3456 f
= x_window_to_frame (dpyinfo
, hwnd
);
3458 && (f
->output_data
.w32
->menubar_active
3459 /* We can receive this message even in the absence of a
3460 menubar (ie. when the system menu is activated) - in this
3461 case we do NOT want to forward the message, otherwise it
3462 will cause the menubar to suddenly appear when the user
3463 had requested it to be turned off! */
3464 || f
->output_data
.w32
->menubar_widget
== NULL
))
3468 deferred_msg msg_buf
;
3470 /* Detect if message has already been deferred; in this case
3471 we cannot return any sensible value to ignore this. */
3472 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3477 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
3480 case WM_EXITMENULOOP
:
3481 f
= x_window_to_frame (dpyinfo
, hwnd
);
3483 /* If a menu is still active, check again after a short delay,
3484 since Windows often (always?) sends the WM_EXITMENULOOP
3485 before the corresponding WM_COMMAND message.
3486 Don't do this if a popup menu is active, since it is only
3487 menubar menus that require cleaning up in this way.
3489 if (f
&& menubar_in_use
&& current_popup_menu
== NULL
)
3490 menu_free_timer
= SetTimer (hwnd
, MENU_FREE_ID
, MENU_FREE_DELAY
, NULL
);
3494 /* Direct handling of help_echo in menus. Should be safe now
3495 that we generate the help_echo by placing a help event in the
3498 HMENU menu
= (HMENU
) lParam
;
3499 UINT menu_item
= (UINT
) LOWORD (wParam
);
3500 UINT flags
= (UINT
) HIWORD (wParam
);
3502 w32_menu_display_help (hwnd
, menu
, menu_item
, flags
);
3506 case WM_MEASUREITEM
:
3507 f
= x_window_to_frame (dpyinfo
, hwnd
);
3510 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
3512 if (pMis
->CtlType
== ODT_MENU
)
3514 /* Work out dimensions for popup menu titles. */
3515 char * title
= (char *) pMis
->itemData
;
3516 HDC hdc
= GetDC (hwnd
);
3517 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3518 LOGFONT menu_logfont
;
3522 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3523 menu_logfont
.lfWeight
= FW_BOLD
;
3524 menu_font
= CreateFontIndirect (&menu_logfont
);
3525 old_font
= SelectObject (hdc
, menu_font
);
3527 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
3530 if (unicode_append_menu
)
3531 GetTextExtentPoint32W (hdc
, (WCHAR
*) title
,
3532 wcslen ((WCHAR
*) title
),
3535 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
3537 pMis
->itemWidth
= size
.cx
;
3538 if (pMis
->itemHeight
< size
.cy
)
3539 pMis
->itemHeight
= size
.cy
;
3542 pMis
->itemWidth
= 0;
3544 SelectObject (hdc
, old_font
);
3545 DeleteObject (menu_font
);
3546 ReleaseDC (hwnd
, hdc
);
3553 f
= x_window_to_frame (dpyinfo
, hwnd
);
3556 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
3558 if (pDis
->CtlType
== ODT_MENU
)
3560 /* Draw popup menu title. */
3561 char * title
= (char *) pDis
->itemData
;
3564 HDC hdc
= pDis
->hDC
;
3565 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3566 LOGFONT menu_logfont
;
3569 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3570 menu_logfont
.lfWeight
= FW_BOLD
;
3571 menu_font
= CreateFontIndirect (&menu_logfont
);
3572 old_font
= SelectObject (hdc
, menu_font
);
3574 /* Always draw title as if not selected. */
3575 if (unicode_append_menu
)
3578 + GetSystemMetrics (SM_CXMENUCHECK
),
3580 ETO_OPAQUE
, &pDis
->rcItem
,
3582 wcslen ((WCHAR
*) title
), NULL
);
3586 + GetSystemMetrics (SM_CXMENUCHECK
),
3588 ETO_OPAQUE
, &pDis
->rcItem
,
3589 title
, strlen (title
), NULL
);
3591 SelectObject (hdc
, old_font
);
3592 DeleteObject (menu_font
);
3600 /* Still not right - can't distinguish between clicks in the
3601 client area of the frame from clicks forwarded from the scroll
3602 bars - may have to hook WM_NCHITTEST to remember the mouse
3603 position and then check if it is in the client area ourselves. */
3604 case WM_MOUSEACTIVATE
:
3605 /* Discard the mouse click that activates a frame, allowing the
3606 user to click anywhere without changing point (or worse!).
3607 Don't eat mouse clicks on scrollbars though!! */
3608 if (LOWORD (lParam
) == HTCLIENT
)
3609 return MA_ACTIVATEANDEAT
;
3614 /* No longer tracking mouse. */
3615 track_mouse_window
= NULL
;
3617 case WM_ACTIVATEAPP
:
3619 case WM_WINDOWPOSCHANGED
:
3621 /* Inform lisp thread that a frame might have just been obscured
3622 or exposed, so should recheck visibility of all frames. */
3623 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3627 dpyinfo
->faked_key
= 0;
3629 register_hot_keys (hwnd
);
3632 unregister_hot_keys (hwnd
);
3635 /* Relinquish the system caret. */
3636 if (w32_system_caret_hwnd
)
3638 w32_visible_system_caret_hwnd
= NULL
;
3639 w32_system_caret_hwnd
= NULL
;
3645 f
= x_window_to_frame (dpyinfo
, hwnd
);
3646 if (f
&& HIWORD (wParam
) == 0)
3648 if (menu_free_timer
)
3650 KillTimer (hwnd
, menu_free_timer
);
3651 menu_free_timer
= 0;
3657 wmsg
.dwModifiers
= w32_get_modifiers ();
3658 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3662 wmsg
.dwModifiers
= w32_get_modifiers ();
3663 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3666 case WM_WINDOWPOSCHANGING
:
3667 /* Don't restrict the sizing of tip frames. */
3668 if (hwnd
== tip_window
)
3672 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
3674 wp
.length
= sizeof (WINDOWPLACEMENT
);
3675 GetWindowPlacement (hwnd
, &wp
);
3677 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
3684 DWORD internal_border
;
3685 DWORD scrollbar_extra
;
3688 wp
.length
= sizeof(wp
);
3689 GetWindowRect (hwnd
, &wr
);
3693 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
3694 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
3695 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
3696 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
3700 memset (&rect
, 0, sizeof (rect
));
3701 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
3702 GetMenu (hwnd
) != NULL
);
3704 /* Force width and height of client area to be exact
3705 multiples of the character cell dimensions. */
3706 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
3707 - 2 * internal_border
- scrollbar_extra
)
3709 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
3710 - 2 * internal_border
)
3715 /* For right/bottom sizing we can just fix the sizes.
3716 However for top/left sizing we will need to fix the X
3717 and Y positions as well. */
3719 int cx_mintrack
= GetSystemMetrics (SM_CXMINTRACK
);
3720 int cy_mintrack
= GetSystemMetrics (SM_CYMINTRACK
);
3722 lppos
->cx
= max (lppos
->cx
- wdiff
, cx_mintrack
);
3723 lppos
->cy
= max (lppos
->cy
- hdiff
, cy_mintrack
);
3725 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
3726 && (lppos
->flags
& SWP_NOMOVE
) == 0)
3728 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
3735 lppos
->flags
|= SWP_NOMOVE
;
3746 case WM_GETMINMAXINFO
:
3747 /* Hack to allow resizing the Emacs frame above the screen size.
3748 Note that Windows 9x limits coordinates to 16-bits. */
3749 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.x
= 32767;
3750 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.y
= 32767;
3754 if (LOWORD (lParam
) == HTCLIENT
)
3759 case WM_EMACS_SETCURSOR
:
3761 Cursor cursor
= (Cursor
) wParam
;
3767 case WM_EMACS_CREATESCROLLBAR
:
3768 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
3769 (struct scroll_bar
*) lParam
);
3771 case WM_EMACS_SHOWWINDOW
:
3772 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
3774 case WM_EMACS_SETFOREGROUND
:
3776 HWND foreground_window
;
3777 DWORD foreground_thread
, retval
;
3779 /* On NT 5.0, and apparently Windows 98, it is necessary to
3780 attach to the thread that currently has focus in order to
3781 pull the focus away from it. */
3782 foreground_window
= GetForegroundWindow ();
3783 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
3784 if (!foreground_window
3785 || foreground_thread
== GetCurrentThreadId ()
3786 || !AttachThreadInput (GetCurrentThreadId (),
3787 foreground_thread
, TRUE
))
3788 foreground_thread
= 0;
3790 retval
= SetForegroundWindow ((HWND
) wParam
);
3792 /* Detach from the previous foreground thread. */
3793 if (foreground_thread
)
3794 AttachThreadInput (GetCurrentThreadId (),
3795 foreground_thread
, FALSE
);
3800 case WM_EMACS_SETWINDOWPOS
:
3802 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
3803 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
3804 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
3807 case WM_EMACS_DESTROYWINDOW
:
3808 DragAcceptFiles ((HWND
) wParam
, FALSE
);
3809 return DestroyWindow ((HWND
) wParam
);
3811 case WM_EMACS_HIDE_CARET
:
3812 return HideCaret (hwnd
);
3814 case WM_EMACS_SHOW_CARET
:
3815 return ShowCaret (hwnd
);
3817 case WM_EMACS_DESTROY_CARET
:
3818 w32_system_caret_hwnd
= NULL
;
3819 w32_visible_system_caret_hwnd
= NULL
;
3820 return DestroyCaret ();
3822 case WM_EMACS_TRACK_CARET
:
3823 /* If there is currently no system caret, create one. */
3824 if (w32_system_caret_hwnd
== NULL
)
3826 /* Use the default caret width, and avoid changing it
3827 unneccesarily, as it confuses screen reader software. */
3828 w32_system_caret_hwnd
= hwnd
;
3829 CreateCaret (hwnd
, NULL
, 0,
3830 w32_system_caret_height
);
3833 if (!SetCaretPos (w32_system_caret_x
, w32_system_caret_y
))
3835 /* Ensure visible caret gets turned on when requested. */
3836 else if (w32_use_visible_system_caret
3837 && w32_visible_system_caret_hwnd
!= hwnd
)
3839 w32_visible_system_caret_hwnd
= hwnd
;
3840 return ShowCaret (hwnd
);
3842 /* Ensure visible caret gets turned off when requested. */
3843 else if (!w32_use_visible_system_caret
3844 && w32_visible_system_caret_hwnd
)
3846 w32_visible_system_caret_hwnd
= NULL
;
3847 return HideCaret (hwnd
);
3852 case WM_EMACS_TRACKPOPUPMENU
:
3857 pos
= (POINT
*)lParam
;
3858 flags
= TPM_CENTERALIGN
;
3859 if (button_state
& LMOUSE
)
3860 flags
|= TPM_LEFTBUTTON
;
3861 else if (button_state
& RMOUSE
)
3862 flags
|= TPM_RIGHTBUTTON
;
3864 /* Remember we did a SetCapture on the initial mouse down event,
3865 so for safety, we make sure the capture is cancelled now. */
3869 /* Use menubar_active to indicate that WM_INITMENU is from
3870 TrackPopupMenu below, and should be ignored. */
3871 f
= x_window_to_frame (dpyinfo
, hwnd
);
3873 f
->output_data
.w32
->menubar_active
= 1;
3875 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
3879 /* Eat any mouse messages during popupmenu */
3880 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
3882 /* Get the menu selection, if any */
3883 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
3885 retval
= LOWORD (amsg
.wParam
);
3901 /* Check for messages registered at runtime. */
3902 if (msg
== msh_mousewheel
)
3904 wmsg
.dwModifiers
= w32_get_modifiers ();
3905 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3906 signal_user_input ();
3911 return DefWindowProc (hwnd
, msg
, wParam
, lParam
);
3915 /* The most common default return code for handled messages is 0. */
3920 my_create_window (f
)
3925 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
3927 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
3931 /* Create a tooltip window. Unlike my_create_window, we do not do this
3932 indirectly via the Window thread, as we do not need to process Window
3933 messages for the tooltip. Creating tooltips indirectly also creates
3934 deadlocks when tooltips are created for menu items. */
3936 my_create_tip_window (f
)
3941 rect
.left
= rect
.top
= 0;
3942 rect
.right
= FRAME_PIXEL_WIDTH (f
);
3943 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
3945 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
3946 FRAME_EXTERNAL_MENU_BAR (f
));
3948 tip_window
= FRAME_W32_WINDOW (f
)
3949 = CreateWindow (EMACS_CLASS
,
3951 f
->output_data
.w32
->dwStyle
,
3954 rect
.right
- rect
.left
,
3955 rect
.bottom
- rect
.top
,
3956 FRAME_W32_WINDOW (SELECTED_FRAME ()), /* owner */
3963 SetWindowLong (tip_window
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
3964 SetWindowLong (tip_window
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
3965 SetWindowLong (tip_window
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
3966 SetWindowLong (tip_window
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
3968 /* Tip frames have no scrollbars. */
3969 SetWindowLong (tip_window
, WND_SCROLLBAR_INDEX
, 0);
3971 /* Do this to discard the default setting specified by our parent. */
3972 ShowWindow (tip_window
, SW_HIDE
);
3977 /* Create and set up the w32 window for frame F. */
3980 w32_window (f
, window_prompting
, minibuffer_only
)
3982 long window_prompting
;
3983 int minibuffer_only
;
3987 /* Use the resource name as the top-level window name
3988 for looking up resources. Make a non-Lisp copy
3989 for the window manager, so GC relocation won't bother it.
3991 Elsewhere we specify the window name for the window manager. */
3994 char *str
= (char *) SDATA (Vx_resource_name
);
3995 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
3996 strcpy (f
->namebuf
, str
);
3999 my_create_window (f
);
4001 validate_x_resource_name ();
4003 /* x_set_name normally ignores requests to set the name if the
4004 requested name is the same as the current name. This is the one
4005 place where that assumption isn't correct; f->name is set, but
4006 the server hasn't been told. */
4009 int explicit = f
->explicit_name
;
4011 f
->explicit_name
= 0;
4014 x_set_name (f
, name
, explicit);
4019 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
4020 initialize_frame_menubar (f
);
4022 if (FRAME_W32_WINDOW (f
) == 0)
4023 error ("Unable to create window");
4026 /* Handle the icon stuff for this window. Perhaps later we might
4027 want an x_set_icon_position which can be called interactively as
4035 Lisp_Object icon_x
, icon_y
;
4037 /* Set the position of the icon. Note that Windows 95 groups all
4038 icons in the tray. */
4039 icon_x
= w32_get_arg (parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
4040 icon_y
= w32_get_arg (parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
4041 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
4043 CHECK_NUMBER (icon_x
);
4044 CHECK_NUMBER (icon_y
);
4046 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
4047 error ("Both left and top icon corners of icon must be specified");
4051 if (! EQ (icon_x
, Qunbound
))
4052 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
4055 /* Start up iconic or window? */
4056 x_wm_set_window_state
4057 (f
, (EQ (w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
4061 x_text_icon (f
, (char *) SDATA ((!NILP (f
->icon_name
)
4074 XGCValues gc_values
;
4078 /* Create the GC's of this frame.
4079 Note that many default values are used. */
4082 gc_values
.font
= FRAME_FONT (f
);
4084 /* Cursor has cursor-color background, background-color foreground. */
4085 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
4086 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
4087 f
->output_data
.w32
->cursor_gc
4088 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
4089 (GCFont
| GCForeground
| GCBackground
),
4093 f
->output_data
.w32
->white_relief
.gc
= 0;
4094 f
->output_data
.w32
->black_relief
.gc
= 0;
4100 /* Handler for signals raised during x_create_frame and
4101 x_create_top_frame. FRAME is the frame which is partially
4105 unwind_create_frame (frame
)
4108 struct frame
*f
= XFRAME (frame
);
4110 /* If frame is ``official'', nothing to do. */
4111 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
4114 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4117 x_free_frame_resources (f
);
4119 /* Check that reference counts are indeed correct. */
4120 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
4121 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
4130 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
4132 doc
: /* Make a new window, which is called a \"frame\" in Emacs terms.
4133 Returns an Emacs frame object.
4134 PARAMETERS is an alist of frame parameters.
4135 If the parameters specify that the frame should not have a minibuffer,
4136 and do not specify a specific minibuffer window to use,
4137 then `default-minibuffer-frame' must be a frame whose minibuffer can
4138 be shared by the new frame.
4140 This function is an internal primitive--use `make-frame' instead. */)
4142 Lisp_Object parameters
;
4145 Lisp_Object frame
, tem
;
4147 int minibuffer_only
= 0;
4148 long window_prompting
= 0;
4150 int count
= SPECPDL_INDEX ();
4151 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4152 Lisp_Object display
;
4153 struct w32_display_info
*dpyinfo
= NULL
;
4159 /* Use this general default value to start with
4160 until we know if this frame has a specified name. */
4161 Vx_resource_name
= Vinvocation_name
;
4163 display
= w32_get_arg (parameters
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
4164 if (EQ (display
, Qunbound
))
4166 dpyinfo
= check_x_display_info (display
);
4168 kb
= dpyinfo
->kboard
;
4170 kb
= &the_only_kboard
;
4173 name
= w32_get_arg (parameters
, Qname
, "name", "Name", RES_TYPE_STRING
);
4175 && ! EQ (name
, Qunbound
)
4177 error ("Invalid frame name--not a string or nil");
4180 Vx_resource_name
= name
;
4182 /* See if parent window is specified. */
4183 parent
= w32_get_arg (parameters
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
4184 if (EQ (parent
, Qunbound
))
4186 if (! NILP (parent
))
4187 CHECK_NUMBER (parent
);
4189 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
4190 /* No need to protect DISPLAY because that's not used after passing
4191 it to make_frame_without_minibuffer. */
4193 GCPRO4 (parameters
, parent
, name
, frame
);
4194 tem
= w32_get_arg (parameters
, Qminibuffer
, "minibuffer", "Minibuffer",
4196 if (EQ (tem
, Qnone
) || NILP (tem
))
4197 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
4198 else if (EQ (tem
, Qonly
))
4200 f
= make_minibuffer_frame ();
4201 minibuffer_only
= 1;
4203 else if (WINDOWP (tem
))
4204 f
= make_frame_without_minibuffer (tem
, kb
, display
);
4208 XSETFRAME (frame
, f
);
4210 /* Note that Windows does support scroll bars. */
4211 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
4213 /* By default, make scrollbars the system standard width. */
4214 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
4216 f
->terminal
= dpyinfo
->terminal
;
4217 f
->terminal
->reference_count
++;
4219 f
->output_method
= output_w32
;
4220 f
->output_data
.w32
=
4221 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
4222 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
4223 FRAME_FONTSET (f
) = -1;
4224 record_unwind_protect (unwind_create_frame
, frame
);
4227 = w32_get_arg (parameters
, Qicon_name
, "iconName", "Title", RES_TYPE_STRING
);
4228 if (! STRINGP (f
->icon_name
))
4229 f
->icon_name
= Qnil
;
4231 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
4233 FRAME_KBOARD (f
) = kb
;
4236 /* Specify the parent under which to make this window. */
4240 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
4241 f
->output_data
.w32
->explicit_parent
= 1;
4245 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4246 f
->output_data
.w32
->explicit_parent
= 0;
4249 /* Set the name; the functions to which we pass f expect the name to
4251 if (EQ (name
, Qunbound
) || NILP (name
))
4253 f
->name
= build_string (dpyinfo
->w32_id_name
);
4254 f
->explicit_name
= 0;
4259 f
->explicit_name
= 1;
4260 /* use the frame's title when getting resources for this frame. */
4261 specbind (Qx_resource_name
, name
);
4264 /* Extract the window parameters from the supplied values
4265 that are needed to determine window geometry. */
4269 font
= w32_get_arg (parameters
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4272 /* First, try whatever font the caller has specified. */
4275 tem
= Fquery_fontset (font
, Qnil
);
4277 font
= x_new_fontset (f
, SDATA (tem
));
4279 font
= x_new_font (f
, SDATA (font
));
4281 /* Try out a font which we hope has bold and italic variations. */
4282 if (!STRINGP (font
))
4283 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
4284 if (! STRINGP (font
))
4285 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
4286 /* If those didn't work, look for something which will at least work. */
4287 if (! STRINGP (font
))
4288 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
4290 if (! STRINGP (font
))
4291 font
= build_string ("Fixedsys");
4293 x_default_parameter (f
, parameters
, Qfont
, font
,
4294 "font", "Font", RES_TYPE_STRING
);
4297 x_default_parameter (f
, parameters
, Qborder_width
, make_number (2),
4298 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4299 /* This defaults to 2 in order to match xterm. We recognize either
4300 internalBorderWidth or internalBorder (which is what xterm calls
4302 if (NILP (Fassq (Qinternal_border_width
, parameters
)))
4306 value
= w32_get_arg (parameters
, Qinternal_border_width
,
4307 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
4308 if (! EQ (value
, Qunbound
))
4309 parameters
= Fcons (Fcons (Qinternal_border_width
, value
),
4312 /* Default internalBorderWidth to 0 on Windows to match other programs. */
4313 x_default_parameter (f
, parameters
, Qinternal_border_width
, make_number (0),
4314 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
4315 x_default_parameter (f
, parameters
, Qvertical_scroll_bars
, Qright
,
4316 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
4318 /* Also do the stuff which must be set before the window exists. */
4319 x_default_parameter (f
, parameters
, Qforeground_color
, build_string ("black"),
4320 "foreground", "Foreground", RES_TYPE_STRING
);
4321 x_default_parameter (f
, parameters
, Qbackground_color
, build_string ("white"),
4322 "background", "Background", RES_TYPE_STRING
);
4323 x_default_parameter (f
, parameters
, Qmouse_color
, build_string ("black"),
4324 "pointerColor", "Foreground", RES_TYPE_STRING
);
4325 x_default_parameter (f
, parameters
, Qcursor_color
, build_string ("black"),
4326 "cursorColor", "Foreground", RES_TYPE_STRING
);
4327 x_default_parameter (f
, parameters
, Qborder_color
, build_string ("black"),
4328 "borderColor", "BorderColor", RES_TYPE_STRING
);
4329 x_default_parameter (f
, parameters
, Qscreen_gamma
, Qnil
,
4330 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
4331 x_default_parameter (f
, parameters
, Qline_spacing
, Qnil
,
4332 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
4333 x_default_parameter (f
, parameters
, Qleft_fringe
, Qnil
,
4334 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
4335 x_default_parameter (f
, parameters
, Qright_fringe
, Qnil
,
4336 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
4339 /* Init faces before x_default_parameter is called for scroll-bar
4340 parameters because that function calls x_set_scroll_bar_width,
4341 which calls change_frame_size, which calls Fset_window_buffer,
4342 which runs hooks, which call Fvertical_motion. At the end, we
4343 end up in init_iterator with a null face cache, which should not
4345 init_frame_faces (f
);
4347 x_default_parameter (f
, parameters
, Qmenu_bar_lines
, make_number (1),
4348 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
4349 x_default_parameter (f
, parameters
, Qtool_bar_lines
, make_number (1),
4350 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
4352 x_default_parameter (f
, parameters
, Qbuffer_predicate
, Qnil
,
4353 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
4354 x_default_parameter (f
, parameters
, Qtitle
, Qnil
,
4355 "title", "Title", RES_TYPE_STRING
);
4356 x_default_parameter (f
, parameters
, Qfullscreen
, Qnil
,
4357 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
4359 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
4360 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4362 f
->output_data
.w32
->text_cursor
= w32_load_cursor (IDC_IBEAM
);
4363 f
->output_data
.w32
->nontext_cursor
= w32_load_cursor (IDC_ARROW
);
4364 f
->output_data
.w32
->modeline_cursor
= w32_load_cursor (IDC_ARROW
);
4365 f
->output_data
.w32
->hand_cursor
= w32_load_cursor (IDC_HAND
);
4366 f
->output_data
.w32
->hourglass_cursor
= w32_load_cursor (IDC_WAIT
);
4367 f
->output_data
.w32
->horizontal_drag_cursor
= w32_load_cursor (IDC_SIZEWE
);
4369 window_prompting
= x_figure_window_size (f
, parameters
, 1);
4371 tem
= w32_get_arg (parameters
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
4372 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
4374 w32_window (f
, window_prompting
, minibuffer_only
);
4375 x_icon (f
, parameters
);
4379 /* Now consider the frame official. */
4380 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
4381 Vframe_list
= Fcons (frame
, Vframe_list
);
4383 /* We need to do this after creating the window, so that the
4384 icon-creation functions can say whose icon they're describing. */
4385 x_default_parameter (f
, parameters
, Qicon_type
, Qnil
,
4386 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
4388 x_default_parameter (f
, parameters
, Qauto_raise
, Qnil
,
4389 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4390 x_default_parameter (f
, parameters
, Qauto_lower
, Qnil
,
4391 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4392 x_default_parameter (f
, parameters
, Qcursor_type
, Qbox
,
4393 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4394 x_default_parameter (f
, parameters
, Qscroll_bar_width
, Qnil
,
4395 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
4397 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4398 Change will not be effected unless different from the current
4400 width
= FRAME_COLS (f
);
4401 height
= FRAME_LINES (f
);
4403 FRAME_LINES (f
) = 0;
4404 SET_FRAME_COLS (f
, 0);
4405 change_frame_size (f
, height
, width
, 1, 0, 0);
4407 /* Tell the server what size and position, etc, we want, and how
4408 badly we want them. This should be done after we have the menu
4409 bar so that its size can be taken into account. */
4411 x_wm_set_size_hint (f
, window_prompting
, 0);
4414 /* Make the window appear on the frame and enable display, unless
4415 the caller says not to. However, with explicit parent, Emacs
4416 cannot control visibility, so don't try. */
4417 if (! f
->output_data
.w32
->explicit_parent
)
4419 Lisp_Object visibility
;
4421 visibility
= w32_get_arg (parameters
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
4422 if (EQ (visibility
, Qunbound
))
4425 if (EQ (visibility
, Qicon
))
4426 x_iconify_frame (f
);
4427 else if (! NILP (visibility
))
4428 x_make_frame_visible (f
);
4430 /* Must have been Qnil. */
4434 /* Initialize `default-minibuffer-frame' in case this is the first
4435 frame on this terminal. */
4436 if (FRAME_HAS_MINIBUF_P (f
)
4437 && (!FRAMEP (kb
->Vdefault_minibuffer_frame
)
4438 || !FRAME_LIVE_P (XFRAME (kb
->Vdefault_minibuffer_frame
))))
4439 kb
->Vdefault_minibuffer_frame
= frame
;
4441 /* All remaining specified parameters, which have not been "used"
4442 by x_get_arg and friends, now go in the misc. alist of the frame. */
4443 for (tem
= parameters
; !NILP (tem
); tem
= XCDR (tem
))
4444 if (CONSP (XCAR (tem
)) && !NILP (XCAR (XCAR (tem
))))
4445 f
->param_alist
= Fcons (XCAR (tem
), f
->param_alist
);
4447 store_frame_param (f
, Qwindow_system
, Qw32
);
4451 /* Make sure windows on this frame appear in calls to next-window
4452 and similar functions. */
4453 Vwindow_list
= Qnil
;
4455 return unbind_to (count
, frame
);
4458 /* FRAME is used only to get a handle on the X display. We don't pass the
4459 display info directly because we're called from frame.c, which doesn't
4460 know about that structure. */
4462 x_get_focus_frame (frame
)
4463 struct frame
*frame
;
4465 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
4467 if (! dpyinfo
->w32_focus_frame
)
4470 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
4474 DEFUN ("w32-focus-frame", Fw32_focus_frame
, Sw32_focus_frame
, 1, 1, 0,
4475 doc
: /* Give FRAME input focus, raising to foreground if necessary. */)
4479 x_focus_on_frame (check_x_frame (frame
));
4484 /* Return the charset portion of a font name. */
4485 char * xlfd_charset_of_font (char * fontname
)
4487 char *charset
, *encoding
;
4489 encoding
= strrchr(fontname
, '-');
4490 if (!encoding
|| encoding
== fontname
)
4493 for (charset
= encoding
- 1; charset
>= fontname
; charset
--)
4494 if (*charset
== '-')
4497 if (charset
== fontname
|| strcmp(charset
, "-*-*") == 0)
4503 struct font_info
*w32_load_bdf_font (struct frame
*f
, char *fontname
,
4504 int size
, char* filename
);
4505 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
);
4506 static BOOL
w32_to_x_font (LOGFONT
* lplf
, char * lpxstr
, int len
,
4508 static BOOL
x_to_w32_font (char *lpxstr
, LOGFONT
*lplogfont
);
4510 static struct font_info
*
4511 w32_load_system_font (f
,fontname
,size
)
4516 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4517 Lisp_Object font_names
;
4519 /* Get a list of all the fonts that match this name. Once we
4520 have a list of matching fonts, we compare them against the fonts
4521 we already have loaded by comparing names. */
4522 font_names
= w32_list_fonts (f
, build_string (fontname
), size
, 100);
4524 if (!NILP (font_names
))
4529 /* First check if any are already loaded, as that is cheaper
4530 than loading another one. */
4531 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
4532 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
4533 if (dpyinfo
->font_table
[i
].name
4534 && (!strcmp (dpyinfo
->font_table
[i
].name
,
4535 SDATA (XCAR (tail
)))
4536 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
4537 SDATA (XCAR (tail
)))))
4538 return (dpyinfo
->font_table
+ i
);
4540 fontname
= (char *) SDATA (XCAR (font_names
));
4542 else if (w32_strict_fontnames
)
4544 /* If EnumFontFamiliesEx was available, we got a full list of
4545 fonts back so stop now to avoid the possibility of loading a
4546 random font. If we had to fall back to EnumFontFamilies, the
4547 list is incomplete, so continue whether the font we want was
4549 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
4550 FARPROC enum_font_families_ex
4551 = GetProcAddress (gdi32
, "EnumFontFamiliesExA");
4552 if (enum_font_families_ex
)
4556 /* Load the font and add it to the table. */
4558 char *full_name
, *encoding
, *charset
;
4560 struct font_info
*fontp
;
4566 if (!fontname
|| !x_to_w32_font (fontname
, &lf
))
4569 if (!*lf
.lfFaceName
)
4570 /* If no name was specified for the font, we get a random font
4571 from CreateFontIndirect - this is not particularly
4572 desirable, especially since CreateFontIndirect does not
4573 fill out the missing name in lf, so we never know what we
4577 lf
.lfQuality
= DEFAULT_QUALITY
;
4579 font
= (XFontStruct
*) xmalloc (sizeof (XFontStruct
));
4580 bzero (font
, sizeof (*font
));
4582 /* Set bdf to NULL to indicate that this is a Windows font. */
4587 font
->hfont
= CreateFontIndirect (&lf
);
4589 if (font
->hfont
== NULL
)
4598 codepage
= w32_codepage_for_font (fontname
);
4600 hdc
= GetDC (dpyinfo
->root_window
);
4601 oldobj
= SelectObject (hdc
, font
->hfont
);
4603 ok
= GetTextMetrics (hdc
, &font
->tm
);
4604 if (codepage
== CP_UNICODE
)
4605 font
->double_byte_p
= 1;
4608 /* Unfortunately, some fonts (eg. MingLiU, a big5 ttf font)
4609 don't report themselves as double byte fonts, when
4610 patently they are. So instead of trusting
4611 GetFontLanguageInfo, we check the properties of the
4612 codepage directly, since that is ultimately what we are
4613 working from anyway. */
4614 /* font->double_byte_p = GetFontLanguageInfo(hdc) & GCP_DBCS; */
4616 GetCPInfo (codepage
, &cpi
);
4617 font
->double_byte_p
= cpi
.MaxCharSize
> 1;
4620 SelectObject (hdc
, oldobj
);
4621 ReleaseDC (dpyinfo
->root_window
, hdc
);
4622 /* Fill out details in lf according to the font that was
4624 lf
.lfHeight
= font
->tm
.tmInternalLeading
- font
->tm
.tmHeight
;
4625 lf
.lfWidth
= font
->tm
.tmMaxCharWidth
;
4626 lf
.lfWeight
= font
->tm
.tmWeight
;
4627 lf
.lfItalic
= font
->tm
.tmItalic
;
4628 lf
.lfCharSet
= font
->tm
.tmCharSet
;
4629 lf
.lfPitchAndFamily
= ((font
->tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
)
4630 ? VARIABLE_PITCH
: FIXED_PITCH
);
4631 lf
.lfOutPrecision
= ((font
->tm
.tmPitchAndFamily
& TMPF_VECTOR
)
4632 ? OUT_STROKE_PRECIS
: OUT_STRING_PRECIS
);
4634 w32_cache_char_metrics (font
);
4641 w32_unload_font (dpyinfo
, font
);
4645 /* Find a free slot in the font table. */
4646 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
4647 if (dpyinfo
->font_table
[i
].name
== NULL
)
4650 /* If no free slot found, maybe enlarge the font table. */
4651 if (i
== dpyinfo
->n_fonts
4652 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
4655 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
4656 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
4658 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
4661 fontp
= dpyinfo
->font_table
+ i
;
4662 if (i
== dpyinfo
->n_fonts
)
4665 /* Now fill in the slots of *FONTP. */
4667 bzero (fontp
, sizeof (*fontp
));
4669 fontp
->font_idx
= i
;
4670 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
4671 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
4673 if (lf
.lfPitchAndFamily
== FIXED_PITCH
)
4675 /* Fixed width font. */
4676 fontp
->average_width
= fontp
->space_width
= FONT_WIDTH (font
);
4682 pcm
= w32_per_char_metric (font
, &space
, ANSI_FONT
);
4684 fontp
->space_width
= pcm
->width
;
4686 fontp
->space_width
= FONT_WIDTH (font
);
4688 fontp
->average_width
= font
->tm
.tmAveCharWidth
;
4691 charset
= xlfd_charset_of_font (fontname
);
4693 /* Cache the W32 codepage for a font. This makes w32_encode_char
4694 (called for every glyph during redisplay) much faster. */
4695 fontp
->codepage
= codepage
;
4697 /* Work out the font's full name. */
4698 full_name
= (char *)xmalloc (100);
4699 if (full_name
&& w32_to_x_font (&lf
, full_name
, 100, charset
))
4700 fontp
->full_name
= full_name
;
4703 /* If all else fails - just use the name we used to load it. */
4705 fontp
->full_name
= fontp
->name
;
4708 fontp
->size
= FONT_WIDTH (font
);
4709 fontp
->height
= FONT_HEIGHT (font
);
4711 /* The slot `encoding' specifies how to map a character
4712 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
4713 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
4714 (0:0x20..0x7F, 1:0xA0..0xFF,
4715 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
4716 2:0xA020..0xFF7F). For the moment, we don't know which charset
4717 uses this font. So, we set information in fontp->encoding[1]
4718 which is never used by any charset. If mapping can't be
4719 decided, set FONT_ENCODING_NOT_DECIDED. */
4721 /* SJIS fonts need to be set to type 4, all others seem to work as
4722 type FONT_ENCODING_NOT_DECIDED. */
4723 encoding
= strrchr (fontp
->name
, '-');
4724 if (encoding
&& strnicmp (encoding
+1, "sjis", 4) == 0)
4725 fontp
->encoding
[1] = 4;
4727 fontp
->encoding
[1] = FONT_ENCODING_NOT_DECIDED
;
4729 /* The following three values are set to 0 under W32, which is
4730 what they get set to if XGetFontProperty fails under X. */
4731 fontp
->baseline_offset
= 0;
4732 fontp
->relative_compose
= 0;
4733 fontp
->default_ascent
= 0;
4735 /* Set global flag fonts_changed_p to non-zero if the font loaded
4736 has a character with a smaller width than any other character
4737 before, or if the font loaded has a smaller height than any
4738 other font loaded before. If this happens, it will make a
4739 glyph matrix reallocation necessary. */
4740 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
4746 /* Load font named FONTNAME of size SIZE for frame F, and return a
4747 pointer to the structure font_info while allocating it dynamically.
4748 If loading fails, return NULL. */
4750 w32_load_font (f
,fontname
,size
)
4755 Lisp_Object bdf_fonts
;
4756 struct font_info
*retval
= NULL
;
4757 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4759 bdf_fonts
= w32_list_bdf_fonts (build_string (fontname
), 1);
4761 while (!retval
&& CONSP (bdf_fonts
))
4763 char *bdf_name
, *bdf_file
;
4764 Lisp_Object bdf_pair
;
4767 bdf_name
= SDATA (XCAR (bdf_fonts
));
4768 bdf_pair
= Fassoc (XCAR (bdf_fonts
), Vw32_bdf_filename_alist
);
4769 bdf_file
= SDATA (XCDR (bdf_pair
));
4771 // If the font is already loaded, do not load it again.
4772 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
4774 if ((dpyinfo
->font_table
[i
].name
4775 && !strcmp (dpyinfo
->font_table
[i
].name
, bdf_name
))
4776 || (dpyinfo
->font_table
[i
].full_name
4777 && !strcmp (dpyinfo
->font_table
[i
].full_name
, bdf_name
)))
4778 return dpyinfo
->font_table
+ i
;
4781 retval
= w32_load_bdf_font (f
, bdf_name
, size
, bdf_file
);
4783 bdf_fonts
= XCDR (bdf_fonts
);
4789 return w32_load_system_font(f
, fontname
, size
);
4794 w32_unload_font (dpyinfo
, font
)
4795 struct w32_display_info
*dpyinfo
;
4800 if (font
->per_char
) xfree (font
->per_char
);
4801 if (font
->bdf
) w32_free_bdf_font (font
->bdf
);
4803 if (font
->hfont
) DeleteObject(font
->hfont
);
4808 /* The font conversion stuff between x and w32 */
4810 /* X font string is as follows (from faces.el)
4814 * (weight "\\(bold\\|demibold\\|medium\\)") ; 1
4815 * (weight\? "\\([^-]*\\)") ; 1
4816 * (slant "\\([ior]\\)") ; 2
4817 * (slant\? "\\([^-]?\\)") ; 2
4818 * (swidth "\\([^-]*\\)") ; 3
4819 * (adstyle "[^-]*") ; 4
4820 * (pixelsize "[0-9]+")
4821 * (pointsize "[0-9][0-9]+")
4822 * (resx "[0-9][0-9]+")
4823 * (resy "[0-9][0-9]+")
4824 * (spacing "[cmp?*]")
4825 * (avgwidth "[0-9]+")
4826 * (registry "[^-]+")
4827 * (encoding "[^-]+")
4832 x_to_w32_weight (lpw
)
4835 if (!lpw
) return (FW_DONTCARE
);
4837 if (stricmp (lpw
,"heavy") == 0) return FW_HEAVY
;
4838 else if (stricmp (lpw
,"extrabold") == 0) return FW_EXTRABOLD
;
4839 else if (stricmp (lpw
,"bold") == 0) return FW_BOLD
;
4840 else if (stricmp (lpw
,"demibold") == 0) return FW_SEMIBOLD
;
4841 else if (stricmp (lpw
,"semibold") == 0) return FW_SEMIBOLD
;
4842 else if (stricmp (lpw
,"medium") == 0) return FW_MEDIUM
;
4843 else if (stricmp (lpw
,"normal") == 0) return FW_NORMAL
;
4844 else if (stricmp (lpw
,"light") == 0) return FW_LIGHT
;
4845 else if (stricmp (lpw
,"extralight") == 0) return FW_EXTRALIGHT
;
4846 else if (stricmp (lpw
,"thin") == 0) return FW_THIN
;
4853 w32_to_x_weight (fnweight
)
4856 if (fnweight
>= FW_HEAVY
) return "heavy";
4857 if (fnweight
>= FW_EXTRABOLD
) return "extrabold";
4858 if (fnweight
>= FW_BOLD
) return "bold";
4859 if (fnweight
>= FW_SEMIBOLD
) return "demibold";
4860 if (fnweight
>= FW_MEDIUM
) return "medium";
4861 if (fnweight
>= FW_NORMAL
) return "normal";
4862 if (fnweight
>= FW_LIGHT
) return "light";
4863 if (fnweight
>= FW_EXTRALIGHT
) return "extralight";
4864 if (fnweight
>= FW_THIN
) return "thin";
4870 x_to_w32_charset (lpcs
)
4873 Lisp_Object this_entry
, w32_charset
;
4875 int len
= strlen (lpcs
);
4877 /* Support "*-#nnn" format for unknown charsets. */
4878 if (strncmp (lpcs
, "*-#", 3) == 0)
4879 return atoi (lpcs
+ 3);
4881 /* Handle wildcards by ignoring them; eg. treat "big5*-*" as "big5". */
4882 charset
= alloca (len
+ 1);
4883 strcpy (charset
, lpcs
);
4884 lpcs
= strchr (charset
, '*');
4888 /* Look through w32-charset-info-alist for the character set.
4889 Format of each entry is
4890 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
4892 this_entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
4894 if (NILP(this_entry
))
4896 /* At startup, we want iso8859-1 fonts to come up properly. */
4897 if (stricmp(charset
, "iso8859-1") == 0)
4898 return ANSI_CHARSET
;
4900 return DEFAULT_CHARSET
;
4903 w32_charset
= Fcar (Fcdr (this_entry
));
4905 /* Translate Lisp symbol to number. */
4906 if (EQ (w32_charset
, Qw32_charset_ansi
))
4907 return ANSI_CHARSET
;
4908 if (EQ (w32_charset
, Qw32_charset_symbol
))
4909 return SYMBOL_CHARSET
;
4910 if (EQ (w32_charset
, Qw32_charset_shiftjis
))
4911 return SHIFTJIS_CHARSET
;
4912 if (EQ (w32_charset
, Qw32_charset_hangeul
))
4913 return HANGEUL_CHARSET
;
4914 if (EQ (w32_charset
, Qw32_charset_chinesebig5
))
4915 return CHINESEBIG5_CHARSET
;
4916 if (EQ (w32_charset
, Qw32_charset_gb2312
))
4917 return GB2312_CHARSET
;
4918 if (EQ (w32_charset
, Qw32_charset_oem
))
4920 #ifdef JOHAB_CHARSET
4921 if (EQ (w32_charset
, Qw32_charset_johab
))
4922 return JOHAB_CHARSET
;
4923 if (EQ (w32_charset
, Qw32_charset_easteurope
))
4924 return EASTEUROPE_CHARSET
;
4925 if (EQ (w32_charset
, Qw32_charset_turkish
))
4926 return TURKISH_CHARSET
;
4927 if (EQ (w32_charset
, Qw32_charset_baltic
))
4928 return BALTIC_CHARSET
;
4929 if (EQ (w32_charset
, Qw32_charset_russian
))
4930 return RUSSIAN_CHARSET
;
4931 if (EQ (w32_charset
, Qw32_charset_arabic
))
4932 return ARABIC_CHARSET
;
4933 if (EQ (w32_charset
, Qw32_charset_greek
))
4934 return GREEK_CHARSET
;
4935 if (EQ (w32_charset
, Qw32_charset_hebrew
))
4936 return HEBREW_CHARSET
;
4937 if (EQ (w32_charset
, Qw32_charset_vietnamese
))
4938 return VIETNAMESE_CHARSET
;
4939 if (EQ (w32_charset
, Qw32_charset_thai
))
4940 return THAI_CHARSET
;
4941 if (EQ (w32_charset
, Qw32_charset_mac
))
4943 #endif /* JOHAB_CHARSET */
4944 #ifdef UNICODE_CHARSET
4945 if (EQ (w32_charset
, Qw32_charset_unicode
))
4946 return UNICODE_CHARSET
;
4949 return DEFAULT_CHARSET
;
4954 w32_to_x_charset (fncharset
)
4957 static char buf
[32];
4958 Lisp_Object charset_type
;
4963 /* Handle startup case of w32-charset-info-alist not
4964 being set up yet. */
4965 if (NILP(Vw32_charset_info_alist
))
4967 charset_type
= Qw32_charset_ansi
;
4969 case DEFAULT_CHARSET
:
4970 charset_type
= Qw32_charset_default
;
4972 case SYMBOL_CHARSET
:
4973 charset_type
= Qw32_charset_symbol
;
4975 case SHIFTJIS_CHARSET
:
4976 charset_type
= Qw32_charset_shiftjis
;
4978 case HANGEUL_CHARSET
:
4979 charset_type
= Qw32_charset_hangeul
;
4981 case GB2312_CHARSET
:
4982 charset_type
= Qw32_charset_gb2312
;
4984 case CHINESEBIG5_CHARSET
:
4985 charset_type
= Qw32_charset_chinesebig5
;
4988 charset_type
= Qw32_charset_oem
;
4991 /* More recent versions of Windows (95 and NT4.0) define more
4993 #ifdef EASTEUROPE_CHARSET
4994 case EASTEUROPE_CHARSET
:
4995 charset_type
= Qw32_charset_easteurope
;
4997 case TURKISH_CHARSET
:
4998 charset_type
= Qw32_charset_turkish
;
5000 case BALTIC_CHARSET
:
5001 charset_type
= Qw32_charset_baltic
;
5003 case RUSSIAN_CHARSET
:
5004 charset_type
= Qw32_charset_russian
;
5006 case ARABIC_CHARSET
:
5007 charset_type
= Qw32_charset_arabic
;
5010 charset_type
= Qw32_charset_greek
;
5012 case HEBREW_CHARSET
:
5013 charset_type
= Qw32_charset_hebrew
;
5015 case VIETNAMESE_CHARSET
:
5016 charset_type
= Qw32_charset_vietnamese
;
5019 charset_type
= Qw32_charset_thai
;
5022 charset_type
= Qw32_charset_mac
;
5025 charset_type
= Qw32_charset_johab
;
5029 #ifdef UNICODE_CHARSET
5030 case UNICODE_CHARSET
:
5031 charset_type
= Qw32_charset_unicode
;
5035 /* Encode numerical value of unknown charset. */
5036 sprintf (buf
, "*-#%u", fncharset
);
5042 char * best_match
= NULL
;
5044 /* Look through w32-charset-info-alist for the character set.
5045 Prefer ISO codepages, and prefer lower numbers in the ISO
5046 range. Only return charsets for codepages which are installed.
5048 Format of each entry is
5049 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5051 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
5054 Lisp_Object w32_charset
;
5055 Lisp_Object codepage
;
5057 Lisp_Object this_entry
= XCAR (rest
);
5059 /* Skip invalid entries in alist. */
5060 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
5061 || !CONSP (XCDR (this_entry
))
5062 || !SYMBOLP (XCAR (XCDR (this_entry
))))
5065 x_charset
= SDATA (XCAR (this_entry
));
5066 w32_charset
= XCAR (XCDR (this_entry
));
5067 codepage
= XCDR (XCDR (this_entry
));
5069 /* Look for Same charset and a valid codepage (or non-int
5070 which means ignore). */
5071 if (EQ (w32_charset
, charset_type
)
5072 && (!INTEGERP (codepage
) || XINT (codepage
) == CP_DEFAULT
5073 || IsValidCodePage (XINT (codepage
))))
5075 /* If we don't have a match already, then this is the
5078 best_match
= x_charset
;
5079 /* If this is an ISO codepage, and the best so far isn't,
5080 then this is better. */
5081 else if (strnicmp (best_match
, "iso", 3) != 0
5082 && strnicmp (x_charset
, "iso", 3) == 0)
5083 best_match
= x_charset
;
5084 /* If both are ISO8859 codepages, choose the one with the
5085 lowest number in the encoding field. */
5086 else if (strnicmp (best_match
, "iso8859-", 8) == 0
5087 && strnicmp (x_charset
, "iso8859-", 8) == 0)
5089 int best_enc
= atoi (best_match
+ 8);
5090 int this_enc
= atoi (x_charset
+ 8);
5091 if (this_enc
> 0 && this_enc
< best_enc
)
5092 best_match
= x_charset
;
5097 /* If no match, encode the numeric value. */
5100 sprintf (buf
, "*-#%u", fncharset
);
5104 strncpy(buf
, best_match
, 31);
5111 /* Return all the X charsets that map to a font. */
5113 w32_to_all_x_charsets (fncharset
)
5116 static char buf
[32];
5117 Lisp_Object charset_type
;
5118 Lisp_Object retval
= Qnil
;
5123 /* Handle startup case of w32-charset-info-alist not
5124 being set up yet. */
5125 if (NILP(Vw32_charset_info_alist
))
5126 return Fcons (build_string ("iso8859-1"), Qnil
);
5128 charset_type
= Qw32_charset_ansi
;
5130 case DEFAULT_CHARSET
:
5131 charset_type
= Qw32_charset_default
;
5133 case SYMBOL_CHARSET
:
5134 charset_type
= Qw32_charset_symbol
;
5136 case SHIFTJIS_CHARSET
:
5137 charset_type
= Qw32_charset_shiftjis
;
5139 case HANGEUL_CHARSET
:
5140 charset_type
= Qw32_charset_hangeul
;
5142 case GB2312_CHARSET
:
5143 charset_type
= Qw32_charset_gb2312
;
5145 case CHINESEBIG5_CHARSET
:
5146 charset_type
= Qw32_charset_chinesebig5
;
5149 charset_type
= Qw32_charset_oem
;
5152 /* More recent versions of Windows (95 and NT4.0) define more
5154 #ifdef EASTEUROPE_CHARSET
5155 case EASTEUROPE_CHARSET
:
5156 charset_type
= Qw32_charset_easteurope
;
5158 case TURKISH_CHARSET
:
5159 charset_type
= Qw32_charset_turkish
;
5161 case BALTIC_CHARSET
:
5162 charset_type
= Qw32_charset_baltic
;
5164 case RUSSIAN_CHARSET
:
5165 charset_type
= Qw32_charset_russian
;
5167 case ARABIC_CHARSET
:
5168 charset_type
= Qw32_charset_arabic
;
5171 charset_type
= Qw32_charset_greek
;
5173 case HEBREW_CHARSET
:
5174 charset_type
= Qw32_charset_hebrew
;
5176 case VIETNAMESE_CHARSET
:
5177 charset_type
= Qw32_charset_vietnamese
;
5180 charset_type
= Qw32_charset_thai
;
5183 charset_type
= Qw32_charset_mac
;
5186 charset_type
= Qw32_charset_johab
;
5190 #ifdef UNICODE_CHARSET
5191 case UNICODE_CHARSET
:
5192 charset_type
= Qw32_charset_unicode
;
5196 /* Encode numerical value of unknown charset. */
5197 sprintf (buf
, "*-#%u", fncharset
);
5198 return Fcons (build_string (buf
), Qnil
);
5203 /* Look through w32-charset-info-alist for the character set.
5204 Only return charsets for codepages which are installed.
5206 Format of each entry in Vw32_charset_info_alist is
5207 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5209 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
5211 Lisp_Object x_charset
;
5212 Lisp_Object w32_charset
;
5213 Lisp_Object codepage
;
5215 Lisp_Object this_entry
= XCAR (rest
);
5217 /* Skip invalid entries in alist. */
5218 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
5219 || !CONSP (XCDR (this_entry
))
5220 || !SYMBOLP (XCAR (XCDR (this_entry
))))
5223 x_charset
= XCAR (this_entry
);
5224 w32_charset
= XCAR (XCDR (this_entry
));
5225 codepage
= XCDR (XCDR (this_entry
));
5227 /* Look for Same charset and a valid codepage (or non-int
5228 which means ignore). */
5229 if (EQ (w32_charset
, charset_type
)
5230 && (!INTEGERP (codepage
) || XINT (codepage
) == CP_DEFAULT
5231 || IsValidCodePage (XINT (codepage
))))
5233 retval
= Fcons (x_charset
, retval
);
5237 /* If no match, encode the numeric value. */
5240 sprintf (buf
, "*-#%u", fncharset
);
5241 return Fcons (build_string (buf
), Qnil
);
5248 /* Get the Windows codepage corresponding to the specified font. The
5249 charset info in the font name is used to look up
5250 w32-charset-to-codepage-alist. */
5252 w32_codepage_for_font (char *fontname
)
5254 Lisp_Object codepage
, entry
;
5255 char *charset_str
, *charset
, *end
;
5257 if (NILP (Vw32_charset_info_alist
))
5260 /* Extract charset part of font string. */
5261 charset
= xlfd_charset_of_font (fontname
);
5266 charset_str
= (char *) alloca (strlen (charset
) + 1);
5267 strcpy (charset_str
, charset
);
5270 /* Remove leading "*-". */
5271 if (strncmp ("*-", charset_str
, 2) == 0)
5272 charset
= charset_str
+ 2;
5275 charset
= charset_str
;
5277 /* Stop match at wildcard (including preceding '-'). */
5278 if (end
= strchr (charset
, '*'))
5280 if (end
> charset
&& *(end
-1) == '-')
5285 entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
5289 codepage
= Fcdr (Fcdr (entry
));
5291 if (NILP (codepage
))
5293 else if (XFASTINT (codepage
) == XFASTINT (Qt
))
5295 else if (INTEGERP (codepage
))
5296 return XINT (codepage
);
5303 w32_to_x_font (lplogfont
, lpxstr
, len
, specific_charset
)
5304 LOGFONT
* lplogfont
;
5307 char * specific_charset
;
5311 char height_pixels
[8];
5313 char width_pixels
[8];
5314 char *fontname_dash
;
5315 int display_resy
= (int) one_w32_display_info
.resy
;
5316 int display_resx
= (int) one_w32_display_info
.resx
;
5318 struct coding_system coding
;
5320 if (!lpxstr
) abort ();
5325 if (lplogfont
->lfOutPrecision
== OUT_STRING_PRECIS
)
5326 fonttype
= "raster";
5327 else if (lplogfont
->lfOutPrecision
== OUT_STROKE_PRECIS
)
5328 fonttype
= "outline";
5330 fonttype
= "unknown";
5332 setup_coding_system (Fcheck_coding_system (Vlocale_coding_system
),
5334 coding
.src_multibyte
= 0;
5335 coding
.dst_multibyte
= 1;
5336 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
5337 /* We explicitely disable composition handling because selection
5338 data should not contain any composition sequence. */
5339 coding
.composing
= COMPOSITION_DISABLED
;
5340 bufsz
= decoding_buffer_size (&coding
, LF_FACESIZE
);
5342 fontname
= alloca(sizeof(*fontname
) * bufsz
);
5343 decode_coding (&coding
, lplogfont
->lfFaceName
, fontname
,
5344 strlen(lplogfont
->lfFaceName
), bufsz
- 1);
5345 *(fontname
+ coding
.produced
) = '\0';
5347 /* Replace dashes with underscores so the dashes are not
5349 fontname_dash
= fontname
;
5350 while (fontname_dash
= strchr (fontname_dash
, '-'))
5351 *fontname_dash
= '_';
5353 if (lplogfont
->lfHeight
)
5355 sprintf (height_pixels
, "%u", abs (lplogfont
->lfHeight
));
5356 sprintf (height_dpi
, "%u",
5357 abs (lplogfont
->lfHeight
) * 720 / display_resy
);
5361 strcpy (height_pixels
, "*");
5362 strcpy (height_dpi
, "*");
5365 #if 0 /* Never put the width in the xfld. It fails on fonts with
5366 double-width characters. */
5367 if (lplogfont
->lfWidth
)
5368 sprintf (width_pixels
, "%u", lplogfont
->lfWidth
* 10);
5371 strcpy (width_pixels
, "*");
5373 _snprintf (lpxstr
, len
- 1,
5374 "-%s-%s-%s-%c-normal-normal-%s-%s-%d-%d-%c-%s-%s",
5375 fonttype
, /* foundry */
5376 fontname
, /* family */
5377 w32_to_x_weight (lplogfont
->lfWeight
), /* weight */
5378 lplogfont
->lfItalic
?'i':'r', /* slant */
5380 /* add style name */
5381 height_pixels
, /* pixel size */
5382 height_dpi
, /* point size */
5383 display_resx
, /* resx */
5384 display_resy
, /* resy */
5385 ((lplogfont
->lfPitchAndFamily
& 0x3) == VARIABLE_PITCH
)
5386 ? 'p' : 'c', /* spacing */
5387 width_pixels
, /* avg width */
5388 specific_charset
? specific_charset
5389 : w32_to_x_charset (lplogfont
->lfCharSet
)
5390 /* charset registry and encoding */
5393 lpxstr
[len
- 1] = 0; /* just to be sure */
5398 x_to_w32_font (lpxstr
, lplogfont
)
5400 LOGFONT
* lplogfont
;
5402 struct coding_system coding
;
5404 if (!lplogfont
) return (FALSE
);
5406 memset (lplogfont
, 0, sizeof (*lplogfont
));
5408 /* Set default value for each field. */
5410 lplogfont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
5411 lplogfont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
5412 lplogfont
->lfQuality
= DEFAULT_QUALITY
;
5414 /* go for maximum quality */
5415 lplogfont
->lfOutPrecision
= OUT_STROKE_PRECIS
;
5416 lplogfont
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
5417 lplogfont
->lfQuality
= PROOF_QUALITY
;
5420 lplogfont
->lfCharSet
= DEFAULT_CHARSET
;
5421 lplogfont
->lfWeight
= FW_DONTCARE
;
5422 lplogfont
->lfPitchAndFamily
= DEFAULT_PITCH
| FF_DONTCARE
;
5427 /* Provide a simple escape mechanism for specifying Windows font names
5428 * directly -- if font spec does not beginning with '-', assume this
5430 * "<font name>[:height in pixels[:width in pixels[:weight]]]"
5436 char name
[50], weight
[20], slant
, pitch
, pixels
[10], height
[10],
5437 width
[10], resy
[10], remainder
[50];
5439 int dpi
= (int) one_w32_display_info
.resy
;
5441 fields
= sscanf (lpxstr
,
5442 "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%49s",
5443 name
, weight
, &slant
, pixels
, height
, resy
, &pitch
, width
, remainder
);
5447 /* In the general case when wildcards cover more than one field,
5448 we don't know which field is which, so don't fill any in.
5449 However, we need to cope with this particular form, which is
5450 generated by font_list_1 (invoked by try_font_list):
5451 "-raster-6x10-*-gb2312*-*"
5452 and make sure to correctly parse the charset field. */
5455 fields
= sscanf (lpxstr
,
5456 "-%*[^-]-%49[^-]-*-%49s",
5459 else if (fields
< 9)
5465 if (fields
> 0 && name
[0] != '*')
5471 (Fcheck_coding_system (Vlocale_coding_system
), &coding
);
5472 coding
.src_multibyte
= 1;
5473 coding
.dst_multibyte
= 0;
5474 /* Need to set COMPOSITION_DISABLED, otherwise Emacs crashes in
5475 encode_coding_iso2022 trying to dereference a null pointer. */
5476 coding
.composing
= COMPOSITION_DISABLED
;
5477 if (coding
.type
== coding_type_iso2022
)
5478 coding
.flags
|= CODING_FLAG_ISO_SAFE
;
5479 bufsize
= encoding_buffer_size (&coding
, strlen (name
));
5480 buf
= (unsigned char *) alloca (bufsize
);
5481 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
5482 encode_coding (&coding
, name
, buf
, strlen (name
), bufsize
);
5483 if (coding
.produced
>= LF_FACESIZE
)
5484 coding
.produced
= LF_FACESIZE
- 1;
5485 buf
[coding
.produced
] = 0;
5486 strcpy (lplogfont
->lfFaceName
, buf
);
5490 lplogfont
->lfFaceName
[0] = '\0';
5495 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
5499 lplogfont
->lfItalic
= (fields
> 0 && slant
== 'i');
5503 if (fields
> 0 && pixels
[0] != '*')
5504 lplogfont
->lfHeight
= atoi (pixels
);
5508 if (fields
> 0 && resy
[0] != '*')
5511 if (tem
> 0) dpi
= tem
;
5514 if (fields
> -1 && lplogfont
->lfHeight
== 0 && height
[0] != '*')
5515 lplogfont
->lfHeight
= atoi (height
) * dpi
/ 720;
5518 lplogfont
->lfPitchAndFamily
=
5519 (fields
> 0 && pitch
== 'p') ? VARIABLE_PITCH
: FIXED_PITCH
;
5523 if (fields
> 0 && width
[0] != '*')
5524 lplogfont
->lfWidth
= atoi (width
) / 10;
5528 /* Strip the trailing '-' if present. (it shouldn't be, as it
5529 fails the test against xlfd-tight-regexp in fontset.el). */
5531 int len
= strlen (remainder
);
5532 if (len
> 0 && remainder
[len
-1] == '-')
5533 remainder
[len
-1] = 0;
5535 encoding
= remainder
;
5537 if (strncmp (encoding
, "*-", 2) == 0)
5540 lplogfont
->lfCharSet
= x_to_w32_charset (encoding
);
5545 char name
[100], height
[10], width
[10], weight
[20];
5547 fields
= sscanf (lpxstr
,
5548 "%99[^:]:%9[^:]:%9[^:]:%19s",
5549 name
, height
, width
, weight
);
5551 if (fields
== EOF
) return (FALSE
);
5555 strncpy (lplogfont
->lfFaceName
,name
, LF_FACESIZE
);
5556 lplogfont
->lfFaceName
[LF_FACESIZE
-1] = 0;
5560 lplogfont
->lfFaceName
[0] = 0;
5566 lplogfont
->lfHeight
= atoi (height
);
5571 lplogfont
->lfWidth
= atoi (width
);
5575 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
5578 /* This makes TrueType fonts work better. */
5579 lplogfont
->lfHeight
= - abs (lplogfont
->lfHeight
);
5584 /* Strip the pixel height and point height from the given xlfd, and
5585 return the pixel height. If no pixel height is specified, calculate
5586 one from the point height, or if that isn't defined either, return
5587 0 (which usually signifies a scalable font).
5590 xlfd_strip_height (char *fontname
)
5592 int pixel_height
, field_number
;
5593 char *read_from
, *write_to
;
5597 pixel_height
= field_number
= 0;
5600 /* Look for height fields. */
5601 for (read_from
= fontname
; *read_from
; read_from
++)
5603 if (*read_from
== '-')
5606 if (field_number
== 7) /* Pixel height. */
5609 write_to
= read_from
;
5611 /* Find end of field. */
5612 for (;*read_from
&& *read_from
!= '-'; read_from
++)
5615 /* Split the fontname at end of field. */
5621 pixel_height
= atoi (write_to
);
5622 /* Blank out field. */
5623 if (read_from
> write_to
)
5628 /* If the pixel height field is at the end (partial xlfd),
5631 return pixel_height
;
5633 /* If we got a pixel height, the point height can be
5634 ignored. Just blank it out and break now. */
5637 /* Find end of point size field. */
5638 for (; *read_from
&& *read_from
!= '-'; read_from
++)
5644 /* Blank out the point size field. */
5645 if (read_from
> write_to
)
5651 return pixel_height
;
5655 /* If the point height is already blank, break now. */
5656 if (*read_from
== '-')
5662 else if (field_number
== 8)
5664 /* If we didn't get a pixel height, try to get the point
5665 height and convert that. */
5667 char *point_size_start
= read_from
++;
5669 /* Find end of field. */
5670 for (; *read_from
&& *read_from
!= '-'; read_from
++)
5679 point_size
= atoi (point_size_start
);
5681 /* Convert to pixel height. */
5682 pixel_height
= point_size
5683 * one_w32_display_info
.height_in
/ 720;
5685 /* Blank out this field and break. */
5693 /* Shift the rest of the font spec into place. */
5694 if (write_to
&& read_from
> write_to
)
5696 for (; *read_from
; read_from
++, write_to
++)
5697 *write_to
= *read_from
;
5701 return pixel_height
;
5704 /* Assume parameter 1 is fully qualified, no wildcards. */
5706 w32_font_match (fontname
, pattern
)
5711 char *font_name_copy
;
5712 char *regex
= alloca (strlen (pattern
) * 2 + 3);
5714 font_name_copy
= alloca (strlen (fontname
) + 1);
5715 strcpy (font_name_copy
, fontname
);
5720 /* Turn pattern into a regexp and do a regexp match. */
5721 for (; *pattern
; pattern
++)
5723 if (*pattern
== '?')
5725 else if (*pattern
== '*')
5736 /* Strip out font heights and compare them seperately, since
5737 rounding error can cause mismatches. This also allows a
5738 comparison between a font that declares only a pixel height and a
5739 pattern that declares the point height.
5742 int font_height
, pattern_height
;
5744 font_height
= xlfd_strip_height (font_name_copy
);
5745 pattern_height
= xlfd_strip_height (regex
);
5747 /* Compare now, and don't bother doing expensive regexp matching
5748 if the heights differ. */
5749 if (font_height
&& pattern_height
&& (font_height
!= pattern_height
))
5753 return (fast_string_match_ignore_case (build_string (regex
),
5754 build_string(font_name_copy
)) >= 0);
5757 /* Callback functions, and a structure holding info they need, for
5758 listing system fonts on W32. We need one set of functions to do the
5759 job properly, but these don't work on NT 3.51 and earlier, so we
5760 have a second set which don't handle character sets properly to
5763 In both cases, there are two passes made. The first pass gets one
5764 font from each family, the second pass lists all the fonts from
5767 typedef struct enumfont_t
5772 XFontStruct
*size_ref
;
5773 Lisp_Object pattern
;
5779 enum_font_maybe_add_to_list (enumfont_t
*, LOGFONT
*, char *, Lisp_Object
);
5783 enum_font_cb2 (lplf
, lptm
, FontType
, lpef
)
5785 NEWTEXTMETRIC
* lptm
;
5789 /* Ignore struck out and underlined versions of fonts. */
5790 if (lplf
->elfLogFont
.lfStrikeOut
|| lplf
->elfLogFont
.lfUnderline
)
5793 /* Only return fonts with names starting with @ if they were
5794 explicitly specified, since Microsoft uses an initial @ to
5795 denote fonts for vertical writing, without providing a more
5796 convenient way of identifying them. */
5797 if (lplf
->elfLogFont
.lfFaceName
[0] == '@'
5798 && lpef
->logfont
.lfFaceName
[0] != '@')
5801 /* Check that the character set matches if it was specified */
5802 if (lpef
->logfont
.lfCharSet
!= DEFAULT_CHARSET
&&
5803 lplf
->elfLogFont
.lfCharSet
!= lpef
->logfont
.lfCharSet
)
5806 if (FontType
== RASTER_FONTTYPE
)
5808 /* DBCS raster fonts have problems displaying, so skip them. */
5809 int charset
= lplf
->elfLogFont
.lfCharSet
;
5810 if (charset
== SHIFTJIS_CHARSET
5811 || charset
== HANGEUL_CHARSET
5812 || charset
== CHINESEBIG5_CHARSET
5813 || charset
== GB2312_CHARSET
5814 #ifdef JOHAB_CHARSET
5815 || charset
== JOHAB_CHARSET
5823 Lisp_Object width
= Qnil
;
5824 Lisp_Object charset_list
= Qnil
;
5825 char *charset
= NULL
;
5827 /* Truetype fonts do not report their true metrics until loaded */
5828 if (FontType
!= RASTER_FONTTYPE
)
5830 if (!NILP (lpef
->pattern
))
5832 /* Scalable fonts are as big as you want them to be. */
5833 lplf
->elfLogFont
.lfHeight
= lpef
->logfont
.lfHeight
;
5834 lplf
->elfLogFont
.lfWidth
= lpef
->logfont
.lfWidth
;
5835 width
= make_number (lpef
->logfont
.lfWidth
);
5839 lplf
->elfLogFont
.lfHeight
= 0;
5840 lplf
->elfLogFont
.lfWidth
= 0;
5844 /* Make sure the height used here is the same as everywhere
5845 else (ie character height, not cell height). */
5846 if (lplf
->elfLogFont
.lfHeight
> 0)
5848 /* lptm can be trusted for RASTER fonts, but not scalable ones. */
5849 if (FontType
== RASTER_FONTTYPE
)
5850 lplf
->elfLogFont
.lfHeight
= lptm
->tmInternalLeading
- lptm
->tmHeight
;
5852 lplf
->elfLogFont
.lfHeight
= -lplf
->elfLogFont
.lfHeight
;
5855 if (!NILP (lpef
->pattern
))
5857 charset
= xlfd_charset_of_font (SDATA (lpef
->pattern
));
5859 /* We already checked charsets above, but DEFAULT_CHARSET
5860 slipped through. So only allow exact matches for DEFAULT_CHARSET. */
5862 && strncmp (charset
, "*-*", 3) != 0
5863 && lpef
->logfont
.lfCharSet
== DEFAULT_CHARSET
5864 && strcmp (charset
, w32_to_x_charset (DEFAULT_CHARSET
)) != 0)
5869 charset_list
= Fcons (build_string (charset
), Qnil
);
5871 charset_list
= w32_to_all_x_charsets (lplf
->elfLogFont
.lfCharSet
);
5873 /* Loop through the charsets. */
5874 for ( ; CONSP (charset_list
); charset_list
= Fcdr (charset_list
))
5876 Lisp_Object this_charset
= Fcar (charset_list
);
5877 charset
= SDATA (this_charset
);
5879 /* List bold and italic variations if w32-enable-synthesized-fonts
5880 is non-nil and this is a plain font. */
5881 if (w32_enable_synthesized_fonts
5882 && lplf
->elfLogFont
.lfWeight
== FW_NORMAL
5883 && lplf
->elfLogFont
.lfItalic
== FALSE
)
5885 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5888 lplf
->elfLogFont
.lfWeight
= FW_BOLD
;
5889 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5892 lplf
->elfLogFont
.lfItalic
= TRUE
;
5893 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5896 lplf
->elfLogFont
.lfWeight
= FW_NORMAL
;
5897 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5901 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5910 enum_font_maybe_add_to_list (lpef
, logfont
, match_charset
, width
)
5913 char * match_charset
;
5918 if (!w32_to_x_font (logfont
, buf
, 100, match_charset
))
5921 if (NILP (lpef
->pattern
)
5922 || w32_font_match (buf
, SDATA (lpef
->pattern
)))
5924 /* Check if we already listed this font. This may happen if
5925 w32_enable_synthesized_fonts is non-nil, and there are real
5926 bold and italic versions of the font. */
5927 Lisp_Object font_name
= build_string (buf
);
5928 if (NILP (Fmember (font_name
, lpef
->list
)))
5930 Lisp_Object entry
= Fcons (font_name
, width
);
5931 lpef
->list
= Fcons (entry
, lpef
->list
);
5939 enum_font_cb1 (lplf
, lptm
, FontType
, lpef
)
5941 NEWTEXTMETRIC
* lptm
;
5945 return EnumFontFamilies (lpef
->hdc
,
5946 lplf
->elfLogFont
.lfFaceName
,
5947 (FONTENUMPROC
) enum_font_cb2
,
5953 enum_fontex_cb2 (lplf
, lptm
, font_type
, lpef
)
5954 ENUMLOGFONTEX
* lplf
;
5955 NEWTEXTMETRICEX
* lptm
;
5959 /* We are not interested in the extra info we get back from the 'Ex
5960 version - only the fact that we get character set variations
5961 enumerated seperately. */
5962 return enum_font_cb2 ((ENUMLOGFONT
*) lplf
, (NEWTEXTMETRIC
*) lptm
,
5967 enum_fontex_cb1 (lplf
, lptm
, font_type
, lpef
)
5968 ENUMLOGFONTEX
* lplf
;
5969 NEWTEXTMETRICEX
* lptm
;
5973 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
5974 FARPROC enum_font_families_ex
5975 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
5976 /* We don't really expect EnumFontFamiliesEx to disappear once we
5977 get here, so don't bother handling it gracefully. */
5978 if (enum_font_families_ex
== NULL
)
5979 error ("gdi32.dll has disappeared!");
5980 return enum_font_families_ex (lpef
->hdc
,
5982 (FONTENUMPROC
) enum_fontex_cb2
,
5986 /* Interface to fontset handler. (adapted from mw32font.c in Meadow
5987 and xterm.c in Emacs 20.3) */
5989 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
)
5991 char *fontname
, *ptnstr
;
5992 Lisp_Object list
, tem
, newlist
= Qnil
;
5995 list
= Vw32_bdf_filename_alist
;
5996 ptnstr
= SDATA (pattern
);
5998 for ( ; CONSP (list
); list
= XCDR (list
))
6002 fontname
= SDATA (XCAR (tem
));
6003 else if (STRINGP (tem
))
6004 fontname
= SDATA (tem
);
6008 if (w32_font_match (fontname
, ptnstr
))
6010 newlist
= Fcons (XCAR (tem
), newlist
);
6012 if (max_names
>= 0 && n_fonts
>= max_names
)
6021 /* Return a list of names of available fonts matching PATTERN on frame
6022 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
6023 to be listed. Frame F NULL means we have not yet created any
6024 frame, which means we can't get proper size info, as we don't have
6025 a device context to use for GetTextMetrics.
6026 MAXNAMES sets a limit on how many fonts to match. If MAXNAMES is
6027 negative, then all matching fonts are returned. */
6030 w32_list_fonts (f
, pattern
, size
, maxnames
)
6032 Lisp_Object pattern
;
6036 Lisp_Object patterns
, key
= Qnil
, tem
, tpat
;
6037 Lisp_Object list
= Qnil
, newlist
= Qnil
, second_best
= Qnil
;
6038 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
6041 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
6042 if (NILP (patterns
))
6043 patterns
= Fcons (pattern
, Qnil
);
6045 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
6050 tpat
= XCAR (patterns
);
6052 if (!STRINGP (tpat
))
6055 /* Avoid expensive EnumFontFamilies functions if we are not
6056 going to be able to output one of these anyway. */
6057 codepage
= w32_codepage_for_font (SDATA (tpat
));
6058 if (codepage
!= CP_8BIT
&& codepage
!= CP_UNICODE
6059 && codepage
!= CP_DEFAULT
&& codepage
!= CP_UNKNOWN
6060 && !IsValidCodePage(codepage
))
6063 /* See if we cached the result for this particular query.
6064 The cache is an alist of the form:
6065 ((PATTERN (FONTNAME . WIDTH) ...) ...)
6067 if (tem
= XCDR (dpyinfo
->name_list_element
),
6068 !NILP (list
= Fassoc (tpat
, tem
)))
6070 list
= Fcdr_safe (list
);
6071 /* We have a cached list. Don't have to get the list again. */
6076 /* At first, put PATTERN in the cache. */
6081 /* Use EnumFontFamiliesEx where it is available, as it knows
6082 about character sets. Fall back to EnumFontFamilies for
6083 older versions of NT that don't support the 'Ex function. */
6084 x_to_w32_font (SDATA (tpat
), &ef
.logfont
);
6086 LOGFONT font_match_pattern
;
6087 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6088 FARPROC enum_font_families_ex
6089 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6091 /* We do our own pattern matching so we can handle wildcards. */
6092 font_match_pattern
.lfFaceName
[0] = 0;
6093 font_match_pattern
.lfPitchAndFamily
= 0;
6094 /* We can use the charset, because if it is a wildcard it will
6095 be DEFAULT_CHARSET anyway. */
6096 font_match_pattern
.lfCharSet
= ef
.logfont
.lfCharSet
;
6098 ef
.hdc
= GetDC (dpyinfo
->root_window
);
6100 if (enum_font_families_ex
)
6101 enum_font_families_ex (ef
.hdc
,
6102 &font_match_pattern
,
6103 (FONTENUMPROC
) enum_fontex_cb1
,
6106 EnumFontFamilies (ef
.hdc
, NULL
, (FONTENUMPROC
) enum_font_cb1
,
6109 ReleaseDC (dpyinfo
->root_window
, ef
.hdc
);
6115 /* Make a list of the fonts we got back.
6116 Store that in the font cache for the display. */
6117 XSETCDR (dpyinfo
->name_list_element
,
6118 Fcons (Fcons (tpat
, list
),
6119 XCDR (dpyinfo
->name_list_element
)));
6122 if (NILP (list
)) continue; /* Try the remaining alternatives. */
6124 newlist
= second_best
= Qnil
;
6126 /* Make a list of the fonts that have the right width. */
6127 for (; CONSP (list
); list
= XCDR (list
))
6134 if (NILP (XCAR (tem
)))
6138 newlist
= Fcons (XCAR (tem
), newlist
);
6140 if (maxnames
>= 0 && n_fonts
>= maxnames
)
6145 if (!INTEGERP (XCDR (tem
)))
6147 /* Since we don't yet know the size of the font, we must
6148 load it and try GetTextMetrics. */
6149 W32FontStruct thisinfo
;
6154 if (!x_to_w32_font (SDATA (XCAR (tem
)), &lf
))
6158 thisinfo
.bdf
= NULL
;
6159 thisinfo
.hfont
= CreateFontIndirect (&lf
);
6160 if (thisinfo
.hfont
== NULL
)
6163 hdc
= GetDC (dpyinfo
->root_window
);
6164 oldobj
= SelectObject (hdc
, thisinfo
.hfont
);
6165 if (GetTextMetrics (hdc
, &thisinfo
.tm
))
6166 XSETCDR (tem
, make_number (FONT_WIDTH (&thisinfo
)));
6168 XSETCDR (tem
, make_number (0));
6169 SelectObject (hdc
, oldobj
);
6170 ReleaseDC (dpyinfo
->root_window
, hdc
);
6171 DeleteObject(thisinfo
.hfont
);
6174 found_size
= XINT (XCDR (tem
));
6175 if (found_size
== size
)
6177 newlist
= Fcons (XCAR (tem
), newlist
);
6179 if (maxnames
>= 0 && n_fonts
>= maxnames
)
6182 /* keep track of the closest matching size in case
6183 no exact match is found. */
6184 else if (found_size
> 0)
6186 if (NILP (second_best
))
6189 else if (found_size
< size
)
6191 if (XINT (XCDR (second_best
)) > size
6192 || XINT (XCDR (second_best
)) < found_size
)
6197 if (XINT (XCDR (second_best
)) > size
6198 && XINT (XCDR (second_best
)) >
6205 if (!NILP (newlist
))
6207 else if (!NILP (second_best
))
6209 newlist
= Fcons (XCAR (second_best
), Qnil
);
6214 /* Include any bdf fonts. */
6215 if (n_fonts
< maxnames
|| maxnames
< 0)
6217 Lisp_Object combined
[2];
6218 combined
[0] = w32_list_bdf_fonts (pattern
, maxnames
- n_fonts
);
6219 combined
[1] = newlist
;
6220 newlist
= Fnconc(2, combined
);
6227 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
6229 w32_get_font_info (f
, font_idx
)
6233 return (FRAME_W32_FONT_TABLE (f
) + font_idx
);
6238 w32_query_font (struct frame
*f
, char *fontname
)
6241 struct font_info
*pfi
;
6243 pfi
= FRAME_W32_FONT_TABLE (f
);
6245 for (i
= 0; i
< one_w32_display_info
.n_fonts
;i
++, pfi
++)
6247 if (stricmp(pfi
->name
, fontname
) == 0) return pfi
;
6253 /* Find a CCL program for a font specified by FONTP, and set the member
6254 `encoder' of the structure. */
6257 w32_find_ccl_program (fontp
)
6258 struct font_info
*fontp
;
6260 Lisp_Object list
, elt
;
6262 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
6266 && STRINGP (XCAR (elt
))
6267 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
6273 struct ccl_program
*ccl
6274 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
6276 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
6279 fontp
->font_encoder
= ccl
;
6283 /* directory-files from dired.c. */
6284 Lisp_Object Fdirectory_files
P_((Lisp_Object
, Lisp_Object
, Lisp_Object
, Lisp_Object
));
6287 /* Find BDF files in a specified directory. (use GCPRO when calling,
6288 as this calls lisp to get a directory listing). */
6290 w32_find_bdf_fonts_in_dir (Lisp_Object directory
)
6292 Lisp_Object filelist
, list
= Qnil
;
6295 if (!STRINGP(directory
))
6298 filelist
= Fdirectory_files (directory
, Qt
,
6299 build_string (".*\\.[bB][dD][fF]"), Qt
);
6301 for ( ; CONSP(filelist
); filelist
= XCDR (filelist
))
6303 Lisp_Object filename
= XCAR (filelist
);
6304 if (w32_BDF_to_x_font (SDATA (filename
), fontname
, 100))
6305 store_in_alist (&list
, build_string (fontname
), filename
);
6310 DEFUN ("w32-find-bdf-fonts", Fw32_find_bdf_fonts
, Sw32_find_bdf_fonts
,
6312 doc
: /* Return a list of BDF fonts in DIRECTORY.
6313 The list is suitable for appending to `w32-bdf-filename-alist'.
6314 Fonts which do not contain an xlfd description will not be included
6315 in the list. DIRECTORY may be a list of directories. */)
6317 Lisp_Object directory
;
6319 Lisp_Object list
= Qnil
;
6320 struct gcpro gcpro1
, gcpro2
;
6322 if (!CONSP (directory
))
6323 return w32_find_bdf_fonts_in_dir (directory
);
6325 for ( ; CONSP (directory
); directory
= XCDR (directory
))
6327 Lisp_Object pair
[2];
6330 GCPRO2 (directory
, list
);
6331 pair
[1] = w32_find_bdf_fonts_in_dir( XCAR (directory
) );
6332 list
= Fnconc( 2, pair
);
6339 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
6340 doc
: /* Internal function called by `color-defined-p', which see. */)
6342 Lisp_Object color
, frame
;
6345 FRAME_PTR f
= check_x_frame (frame
);
6347 CHECK_STRING (color
);
6349 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
6355 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
6356 doc
: /* Internal function called by `color-values', which see. */)
6358 Lisp_Object color
, frame
;
6361 FRAME_PTR f
= check_x_frame (frame
);
6363 CHECK_STRING (color
);
6365 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
6366 return list3 (make_number ((GetRValue (foo
.pixel
) << 8)
6367 | GetRValue (foo
.pixel
)),
6368 make_number ((GetGValue (foo
.pixel
) << 8)
6369 | GetGValue (foo
.pixel
)),
6370 make_number ((GetBValue (foo
.pixel
) << 8)
6371 | GetBValue (foo
.pixel
)));
6376 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
6377 doc
: /* Internal function called by `display-color-p', which see. */)
6379 Lisp_Object display
;
6381 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6383 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
6389 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
,
6390 Sx_display_grayscale_p
, 0, 1, 0,
6391 doc
: /* Return t if DISPLAY supports shades of gray.
6392 Note that color displays do support shades of gray.
6393 The optional argument DISPLAY specifies which display to ask about.
6394 DISPLAY should be either a frame or a display name (a string).
6395 If omitted or nil, that stands for the selected frame's display. */)
6397 Lisp_Object display
;
6399 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6401 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
6407 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
,
6408 Sx_display_pixel_width
, 0, 1, 0,
6409 doc
: /* Returns the width in pixels of DISPLAY.
6410 The optional argument DISPLAY specifies which display to ask about.
6411 DISPLAY should be either a frame or a display name (a string).
6412 If omitted or nil, that stands for the selected frame's display. */)
6414 Lisp_Object display
;
6416 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6418 return make_number (dpyinfo
->width
);
6421 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
6422 Sx_display_pixel_height
, 0, 1, 0,
6423 doc
: /* Returns the height in pixels 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
);
6432 return make_number (dpyinfo
->height
);
6435 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
6437 doc
: /* Returns the number of bitplanes of DISPLAY.
6438 The optional argument DISPLAY specifies which display to ask about.
6439 DISPLAY should be either a frame or a display name (a string).
6440 If omitted or nil, that stands for the selected frame's display. */)
6442 Lisp_Object display
;
6444 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6446 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
6449 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
6451 doc
: /* Returns the number of color cells of DISPLAY.
6452 The optional argument DISPLAY specifies which display to ask about.
6453 DISPLAY should be either a frame or a display name (a string).
6454 If omitted or nil, that stands for the selected frame's display. */)
6456 Lisp_Object display
;
6458 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6462 hdc
= GetDC (dpyinfo
->root_window
);
6463 if (dpyinfo
->has_palette
)
6464 cap
= GetDeviceCaps (hdc
, SIZEPALETTE
);
6466 cap
= GetDeviceCaps (hdc
, NUMCOLORS
);
6468 /* We force 24+ bit depths to 24-bit, both to prevent an overflow
6469 and because probably is more meaningful on Windows anyway */
6471 cap
= 1 << min(dpyinfo
->n_planes
* dpyinfo
->n_cbits
, 24);
6473 ReleaseDC (dpyinfo
->root_window
, hdc
);
6475 return make_number (cap
);
6478 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
6479 Sx_server_max_request_size
,
6481 doc
: /* Returns the maximum request size of the server of DISPLAY.
6482 The optional argument DISPLAY specifies which display to ask about.
6483 DISPLAY should be either a frame or a display name (a string).
6484 If omitted or nil, that stands for the selected frame's display. */)
6486 Lisp_Object display
;
6488 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6490 return make_number (1);
6493 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
6494 doc
: /* Returns the "vendor ID" string of the W32 system (Microsoft).
6495 The optional argument DISPLAY specifies which display to ask about.
6496 DISPLAY should be either a frame or a display name (a string).
6497 If omitted or nil, that stands for the selected frame's display. */)
6499 Lisp_Object display
;
6501 return build_string ("Microsoft Corp.");
6504 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
6505 doc
: /* Returns the version numbers of the server of DISPLAY.
6506 The value is a list of three integers: the major and minor
6507 version numbers of the X Protocol in use, and the distributor-specific release
6508 number. See also the function `x-server-vendor'.
6510 The optional argument DISPLAY specifies which display to ask about.
6511 DISPLAY should be either a frame or a display name (a string).
6512 If omitted or nil, that stands for the selected frame's display. */)
6514 Lisp_Object display
;
6516 return Fcons (make_number (w32_major_version
),
6517 Fcons (make_number (w32_minor_version
),
6518 Fcons (make_number (w32_build_number
), Qnil
)));
6521 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
6522 doc
: /* Returns the number of screens on the server of DISPLAY.
6523 The optional argument DISPLAY specifies which display to ask about.
6524 DISPLAY should be either a frame or a display name (a string).
6525 If omitted or nil, that stands for the selected frame's display. */)
6527 Lisp_Object display
;
6529 return make_number (1);
6532 DEFUN ("x-display-mm-height", Fx_display_mm_height
,
6533 Sx_display_mm_height
, 0, 1, 0,
6534 doc
: /* Returns the height in millimeters of DISPLAY.
6535 The optional argument DISPLAY specifies which display to ask about.
6536 DISPLAY should be either a frame or a display name (a string).
6537 If omitted or nil, that stands for the selected frame's display. */)
6539 Lisp_Object display
;
6541 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6545 hdc
= GetDC (dpyinfo
->root_window
);
6547 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
6549 ReleaseDC (dpyinfo
->root_window
, hdc
);
6551 return make_number (cap
);
6554 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
6555 doc
: /* Returns the width in millimeters of DISPLAY.
6556 The optional argument DISPLAY specifies which display to ask about.
6557 DISPLAY should be either a frame or a display name (a string).
6558 If omitted or nil, that stands for the selected frame's display. */)
6560 Lisp_Object display
;
6562 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6567 hdc
= GetDC (dpyinfo
->root_window
);
6569 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
6571 ReleaseDC (dpyinfo
->root_window
, hdc
);
6573 return make_number (cap
);
6576 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
6577 Sx_display_backing_store
, 0, 1, 0,
6578 doc
: /* Returns an indication of whether DISPLAY does backing store.
6579 The value may be `always', `when-mapped', or `not-useful'.
6580 The optional argument DISPLAY specifies which display to ask about.
6581 DISPLAY should be either a frame or a display name (a string).
6582 If omitted or nil, that stands for the selected frame's display. */)
6584 Lisp_Object display
;
6586 return intern ("not-useful");
6589 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
6590 Sx_display_visual_class
, 0, 1, 0,
6591 doc
: /* Returns the visual class of DISPLAY.
6592 The value is one of the symbols `static-gray', `gray-scale',
6593 `static-color', `pseudo-color', `true-color', or `direct-color'.
6595 The optional argument DISPLAY specifies which display to ask about.
6596 DISPLAY should be either a frame or a display name (a string).
6597 If omitted or nil, that stands for the selected frame's display. */)
6599 Lisp_Object display
;
6601 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6602 Lisp_Object result
= Qnil
;
6604 if (dpyinfo
->has_palette
)
6605 result
= intern ("pseudo-color");
6606 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
6607 result
= intern ("static-grey");
6608 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
6609 result
= intern ("static-color");
6610 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
6611 result
= intern ("true-color");
6616 DEFUN ("x-display-save-under", Fx_display_save_under
,
6617 Sx_display_save_under
, 0, 1, 0,
6618 doc
: /* Returns t if DISPLAY supports the save-under feature.
6619 The optional argument DISPLAY specifies which display to ask about.
6620 DISPLAY should be either a frame or a display name (a string).
6621 If omitted or nil, that stands for the selected frame's display. */)
6623 Lisp_Object display
;
6630 register struct frame
*f
;
6632 return FRAME_PIXEL_WIDTH (f
);
6637 register struct frame
*f
;
6639 return FRAME_PIXEL_HEIGHT (f
);
6644 register struct frame
*f
;
6646 return FRAME_COLUMN_WIDTH (f
);
6651 register struct frame
*f
;
6653 return FRAME_LINE_HEIGHT (f
);
6658 register struct frame
*f
;
6660 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
6663 /* Return the display structure for the display named NAME.
6664 Open a new connection if necessary. */
6666 struct w32_display_info
*
6667 x_display_info_for_name (name
)
6671 struct w32_display_info
*dpyinfo
;
6673 CHECK_STRING (name
);
6675 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
6677 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
6680 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
6685 /* Use this general default value to start with. */
6686 Vx_resource_name
= Vinvocation_name
;
6688 validate_x_resource_name ();
6690 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
6691 (char *) SDATA (Vx_resource_name
));
6694 error ("Cannot connect to server %s", SDATA (name
));
6697 XSETFASTINT (Vwindow_system_version
, 3);
6702 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
6703 1, 3, 0, doc
: /* Open a connection to a server.
6704 DISPLAY is the name of the display to connect to.
6705 Optional second arg XRM-STRING is a string of resources in xrdb format.
6706 If the optional third arg MUST-SUCCEED is non-nil,
6707 terminate Emacs if we can't open the connection. */)
6708 (display
, xrm_string
, must_succeed
)
6709 Lisp_Object display
, xrm_string
, must_succeed
;
6711 unsigned char *xrm_option
;
6712 struct w32_display_info
*dpyinfo
;
6714 /* If initialization has already been done, return now to avoid
6715 overwriting critical parts of one_w32_display_info. */
6719 CHECK_STRING (display
);
6720 if (! NILP (xrm_string
))
6721 CHECK_STRING (xrm_string
);
6724 if (! EQ (Vwindow_system
, intern ("w32")))
6725 error ("Not using Microsoft Windows");
6728 /* Allow color mapping to be defined externally; first look in user's
6729 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
6731 Lisp_Object color_file
;
6732 struct gcpro gcpro1
;
6734 color_file
= build_string("~/rgb.txt");
6736 GCPRO1 (color_file
);
6738 if (NILP (Ffile_readable_p (color_file
)))
6740 Fexpand_file_name (build_string ("rgb.txt"),
6741 Fsymbol_value (intern ("data-directory")));
6743 Vw32_color_map
= Fw32_load_color_file (color_file
);
6747 if (NILP (Vw32_color_map
))
6748 Vw32_color_map
= Fw32_default_color_map ();
6750 /* Merge in system logical colors. */
6751 add_system_logical_colors_to_map (&Vw32_color_map
);
6753 if (! NILP (xrm_string
))
6754 xrm_option
= (unsigned char *) SDATA (xrm_string
);
6756 xrm_option
= (unsigned char *) 0;
6758 /* Use this general default value to start with. */
6759 /* First remove .exe suffix from invocation-name - it looks ugly. */
6761 char basename
[ MAX_PATH
], *str
;
6763 strcpy (basename
, SDATA (Vinvocation_name
));
6764 str
= strrchr (basename
, '.');
6766 Vinvocation_name
= build_string (basename
);
6768 Vx_resource_name
= Vinvocation_name
;
6770 validate_x_resource_name ();
6772 /* This is what opens the connection and sets x_current_display.
6773 This also initializes many symbols, such as those used for input. */
6774 dpyinfo
= w32_term_init (display
, xrm_option
,
6775 (char *) SDATA (Vx_resource_name
));
6779 if (!NILP (must_succeed
))
6780 fatal ("Cannot connect to server %s.\n",
6783 error ("Cannot connect to server %s", SDATA (display
));
6788 XSETFASTINT (Vwindow_system_version
, 3);
6792 DEFUN ("x-close-connection", Fx_close_connection
,
6793 Sx_close_connection
, 1, 1, 0,
6794 doc
: /* Close the connection to DISPLAY's server.
6795 For DISPLAY, specify either a frame or a display name (a string).
6796 If DISPLAY is nil, that stands for the selected frame's display. */)
6798 Lisp_Object display
;
6800 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6803 if (dpyinfo
->reference_count
> 0)
6804 error ("Display still has frames on it");
6807 /* Free the fonts in the font table. */
6808 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
6809 if (dpyinfo
->font_table
[i
].name
)
6811 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
6812 xfree (dpyinfo
->font_table
[i
].full_name
);
6813 xfree (dpyinfo
->font_table
[i
].name
);
6814 w32_unload_font (dpyinfo
, dpyinfo
->font_table
[i
].font
);
6816 x_destroy_all_bitmaps (dpyinfo
);
6818 x_delete_display (dpyinfo
);
6824 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
6825 doc
: /* Return the list of display names that Emacs has connections to. */)
6828 Lisp_Object tail
, result
;
6831 for (tail
= w32_display_name_list
; ! NILP (tail
); tail
= XCDR (tail
))
6832 result
= Fcons (XCAR (XCAR (tail
)), result
);
6837 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
6838 doc
: /* This is a noop on W32 systems. */)
6840 Lisp_Object display
, on
;
6847 /***********************************************************************
6849 ***********************************************************************/
6851 DEFUN ("x-change-window-property", Fx_change_window_property
,
6852 Sx_change_window_property
, 2, 6, 0,
6853 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
6854 VALUE may be a string or a list of conses, numbers and/or strings.
6855 If an element in the list is a string, it is converted to
6856 an Atom and the value of the Atom is used. If an element is a cons,
6857 it is converted to a 32 bit number where the car is the 16 top bits and the
6858 cdr is the lower 16 bits.
6859 FRAME nil or omitted means use the selected frame.
6860 If TYPE is given and non-nil, it is the name of the type of VALUE.
6861 If TYPE is not given or nil, the type is STRING.
6862 FORMAT gives the size in bits of each element if VALUE is a list.
6863 It must be one of 8, 16 or 32.
6864 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
6865 If OUTER_P is non-nil, the property is changed for the outer X window of
6866 FRAME. Default is to change on the edit X window.
6869 (prop
, value
, frame
, type
, format
, outer_p
)
6870 Lisp_Object prop
, value
, frame
, type
, format
, outer_p
;
6872 #if 0 /* TODO : port window properties to W32 */
6873 struct frame
*f
= check_x_frame (frame
);
6876 CHECK_STRING (prop
);
6877 CHECK_STRING (value
);
6880 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
6881 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
6882 prop_atom
, XA_STRING
, 8, PropModeReplace
,
6883 SDATA (value
), SCHARS (value
));
6885 /* Make sure the property is set when we return. */
6886 XFlush (FRAME_W32_DISPLAY (f
));
6895 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
6896 Sx_delete_window_property
, 1, 2, 0,
6897 doc
: /* Remove window property PROP from X window of FRAME.
6898 FRAME nil or omitted means use the selected frame. Value is PROP. */)
6900 Lisp_Object prop
, frame
;
6902 #if 0 /* TODO : port window properties to W32 */
6904 struct frame
*f
= check_x_frame (frame
);
6907 CHECK_STRING (prop
);
6909 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
6910 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
6912 /* Make sure the property is removed when we return. */
6913 XFlush (FRAME_W32_DISPLAY (f
));
6921 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
6923 doc
: /* Value is the value of window property PROP on FRAME.
6924 If FRAME is nil or omitted, use the selected frame. Value is nil
6925 if FRAME hasn't a property with name PROP or if PROP has no string
6928 Lisp_Object prop
, frame
;
6930 #if 0 /* TODO : port window properties to W32 */
6932 struct frame
*f
= check_x_frame (frame
);
6935 Lisp_Object prop_value
= Qnil
;
6936 char *tmp_data
= NULL
;
6939 unsigned long actual_size
, bytes_remaining
;
6941 CHECK_STRING (prop
);
6943 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
6944 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
6945 prop_atom
, 0, 0, False
, XA_STRING
,
6946 &actual_type
, &actual_format
, &actual_size
,
6947 &bytes_remaining
, (unsigned char **) &tmp_data
);
6950 int size
= bytes_remaining
;
6955 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
6956 prop_atom
, 0, bytes_remaining
,
6958 &actual_type
, &actual_format
,
6959 &actual_size
, &bytes_remaining
,
6960 (unsigned char **) &tmp_data
);
6962 prop_value
= make_string (tmp_data
, size
);
6977 /***********************************************************************
6979 ***********************************************************************/
6981 /* If non-null, an asynchronous timer that, when it expires, displays
6982 an hourglass cursor on all frames. */
6984 static struct atimer
*hourglass_atimer
;
6986 /* Non-zero means an hourglass cursor is currently shown. */
6988 static int hourglass_shown_p
;
6990 /* Number of seconds to wait before displaying an hourglass cursor. */
6992 static Lisp_Object Vhourglass_delay
;
6994 /* Default number of seconds to wait before displaying an hourglass
6997 #define DEFAULT_HOURGLASS_DELAY 1
6999 /* Function prototypes. */
7001 static void show_hourglass
P_ ((struct atimer
*));
7002 static void hide_hourglass
P_ ((void));
7005 /* Cancel a currently active hourglass timer, and start a new one. */
7010 #if 0 /* TODO: cursor shape changes. */
7012 int secs
, usecs
= 0;
7014 cancel_hourglass ();
7016 if (INTEGERP (Vhourglass_delay
)
7017 && XINT (Vhourglass_delay
) > 0)
7018 secs
= XFASTINT (Vhourglass_delay
);
7019 else if (FLOATP (Vhourglass_delay
)
7020 && XFLOAT_DATA (Vhourglass_delay
) > 0)
7023 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
7024 secs
= XFASTINT (tem
);
7025 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
7028 secs
= DEFAULT_HOURGLASS_DELAY
;
7030 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
7031 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
7032 show_hourglass
, NULL
);
7037 /* Cancel the hourglass cursor timer if active, hide an hourglass
7043 if (hourglass_atimer
)
7045 cancel_atimer (hourglass_atimer
);
7046 hourglass_atimer
= NULL
;
7049 if (hourglass_shown_p
)
7054 /* Timer function of hourglass_atimer. TIMER is equal to
7057 Display an hourglass cursor on all frames by mapping the frames'
7058 hourglass_window. Set the hourglass_p flag in the frames'
7059 output_data.x structure to indicate that an hourglass cursor is
7060 shown on the frames. */
7063 show_hourglass (timer
)
7064 struct atimer
*timer
;
7066 #if 0 /* TODO: cursor shape changes. */
7067 /* The timer implementation will cancel this timer automatically
7068 after this function has run. Set hourglass_atimer to null
7069 so that we know the timer doesn't have to be canceled. */
7070 hourglass_atimer
= NULL
;
7072 if (!hourglass_shown_p
)
7074 Lisp_Object rest
, frame
;
7078 FOR_EACH_FRAME (rest
, frame
)
7079 if (FRAME_W32_P (XFRAME (frame
)))
7081 struct frame
*f
= XFRAME (frame
);
7083 f
->output_data
.w32
->hourglass_p
= 1;
7085 if (!f
->output_data
.w32
->hourglass_window
)
7087 unsigned long mask
= CWCursor
;
7088 XSetWindowAttributes attrs
;
7090 attrs
.cursor
= f
->output_data
.w32
->hourglass_cursor
;
7092 f
->output_data
.w32
->hourglass_window
7093 = XCreateWindow (FRAME_X_DISPLAY (f
),
7094 FRAME_OUTER_WINDOW (f
),
7095 0, 0, 32000, 32000, 0, 0,
7101 XMapRaised (FRAME_X_DISPLAY (f
),
7102 f
->output_data
.w32
->hourglass_window
);
7103 XFlush (FRAME_X_DISPLAY (f
));
7106 hourglass_shown_p
= 1;
7113 /* Hide the hourglass cursor on all frames, if it is currently shown. */
7118 #if 0 /* TODO: cursor shape changes. */
7119 if (hourglass_shown_p
)
7121 Lisp_Object rest
, frame
;
7124 FOR_EACH_FRAME (rest
, frame
)
7126 struct frame
*f
= XFRAME (frame
);
7129 /* Watch out for newly created frames. */
7130 && f
->output_data
.x
->hourglass_window
)
7132 XUnmapWindow (FRAME_X_DISPLAY (f
),
7133 f
->output_data
.x
->hourglass_window
);
7134 /* Sync here because XTread_socket looks at the
7135 hourglass_p flag that is reset to zero below. */
7136 XSync (FRAME_X_DISPLAY (f
), False
);
7137 f
->output_data
.x
->hourglass_p
= 0;
7141 hourglass_shown_p
= 0;
7149 /***********************************************************************
7151 ***********************************************************************/
7153 static Lisp_Object x_create_tip_frame
P_ ((struct w32_display_info
*,
7154 Lisp_Object
, Lisp_Object
));
7155 static void compute_tip_xy
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
7156 Lisp_Object
, int, int, int *, int *));
7158 /* The frame of a currently visible tooltip. */
7160 Lisp_Object tip_frame
;
7162 /* If non-nil, a timer started that hides the last tooltip when it
7165 Lisp_Object tip_timer
;
7168 /* If non-nil, a vector of 3 elements containing the last args
7169 with which x-show-tip was called. See there. */
7171 Lisp_Object last_show_tip_args
;
7173 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
7175 Lisp_Object Vx_max_tooltip_size
;
7179 unwind_create_tip_frame (frame
)
7182 Lisp_Object deleted
;
7184 deleted
= unwind_create_frame (frame
);
7185 if (EQ (deleted
, Qt
))
7195 /* Create a frame for a tooltip on the display described by DPYINFO.
7196 PARMS is a list of frame parameters. TEXT is the string to
7197 display in the tip frame. Value is the frame.
7199 Note that functions called here, esp. x_default_parameter can
7200 signal errors, for instance when a specified color name is
7201 undefined. We have to make sure that we're in a consistent state
7202 when this happens. */
7205 x_create_tip_frame (dpyinfo
, parms
, text
)
7206 struct w32_display_info
*dpyinfo
;
7207 Lisp_Object parms
, text
;
7210 Lisp_Object frame
, tem
;
7212 long window_prompting
= 0;
7214 int count
= SPECPDL_INDEX ();
7215 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7217 int face_change_count_before
= face_change_count
;
7219 struct buffer
*old_buffer
;
7223 /* Use this general default value to start with until we know if
7224 this frame has a specified name. */
7225 Vx_resource_name
= Vinvocation_name
;
7228 kb
= dpyinfo
->kboard
;
7230 kb
= &the_only_kboard
;
7233 /* Get the name of the frame to use for resource lookup. */
7234 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
7236 && !EQ (name
, Qunbound
)
7238 error ("Invalid frame name--not a string or nil");
7239 Vx_resource_name
= name
;
7242 GCPRO3 (parms
, name
, frame
);
7243 /* Make a frame without minibuffer nor mode-line. */
7245 f
->wants_modeline
= 0;
7246 XSETFRAME (frame
, f
);
7248 buffer
= Fget_buffer_create (build_string (" *tip*"));
7249 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, Qnil
);
7250 old_buffer
= current_buffer
;
7251 set_buffer_internal_1 (XBUFFER (buffer
));
7252 current_buffer
->truncate_lines
= Qnil
;
7253 specbind (Qinhibit_read_only
, Qt
);
7254 specbind (Qinhibit_modification_hooks
, Qt
);
7257 set_buffer_internal_1 (old_buffer
);
7259 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
7260 record_unwind_protect (unwind_create_tip_frame
, frame
);
7262 /* By setting the output method, we're essentially saying that
7263 the frame is live, as per FRAME_LIVE_P. If we get a signal
7264 from this point on, x_destroy_window might screw up reference
7266 f
->terminal
= dpyinfo
->terminal
;
7267 f
->terminal
->reference_count
++;
7268 f
->output_method
= output_w32
;
7269 f
->output_data
.w32
=
7270 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
7271 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
7273 FRAME_FONTSET (f
) = -1;
7274 f
->icon_name
= Qnil
;
7276 #if 0 /* GLYPH_DEBUG TODO: image support. */
7277 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
7278 dpyinfo_refcount
= dpyinfo
->reference_count
;
7279 #endif /* GLYPH_DEBUG */
7281 FRAME_KBOARD (f
) = kb
;
7283 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
7284 f
->output_data
.w32
->explicit_parent
= 0;
7286 /* Set the name; the functions to which we pass f expect the name to
7288 if (EQ (name
, Qunbound
) || NILP (name
))
7290 f
->name
= build_string (dpyinfo
->w32_id_name
);
7291 f
->explicit_name
= 0;
7296 f
->explicit_name
= 1;
7297 /* use the frame's title when getting resources for this frame. */
7298 specbind (Qx_resource_name
, name
);
7301 /* Extract the window parameters from the supplied values
7302 that are needed to determine window geometry. */
7306 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
7309 /* First, try whatever font the caller has specified. */
7312 tem
= Fquery_fontset (font
, Qnil
);
7314 font
= x_new_fontset (f
, SDATA (tem
));
7316 font
= x_new_font (f
, SDATA (font
));
7319 /* Try out a font which we hope has bold and italic variations. */
7320 if (!STRINGP (font
))
7321 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
7322 if (! STRINGP (font
))
7323 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
7324 /* If those didn't work, look for something which will at least work. */
7325 if (! STRINGP (font
))
7326 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
7328 if (! STRINGP (font
))
7329 font
= build_string ("Fixedsys");
7331 x_default_parameter (f
, parms
, Qfont
, font
,
7332 "font", "Font", RES_TYPE_STRING
);
7335 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
7336 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
7337 /* This defaults to 2 in order to match xterm. We recognize either
7338 internalBorderWidth or internalBorder (which is what xterm calls
7340 if (NILP (Fassq (Qinternal_border_width
, parms
)))
7344 value
= w32_get_arg (parms
, Qinternal_border_width
,
7345 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
7346 if (! EQ (value
, Qunbound
))
7347 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
7350 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
7351 "internalBorderWidth", "internalBorderWidth",
7354 /* Also do the stuff which must be set before the window exists. */
7355 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
7356 "foreground", "Foreground", RES_TYPE_STRING
);
7357 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
7358 "background", "Background", RES_TYPE_STRING
);
7359 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
7360 "pointerColor", "Foreground", RES_TYPE_STRING
);
7361 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
7362 "cursorColor", "Foreground", RES_TYPE_STRING
);
7363 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
7364 "borderColor", "BorderColor", RES_TYPE_STRING
);
7366 /* Init faces before x_default_parameter is called for scroll-bar
7367 parameters because that function calls x_set_scroll_bar_width,
7368 which calls change_frame_size, which calls Fset_window_buffer,
7369 which runs hooks, which call Fvertical_motion. At the end, we
7370 end up in init_iterator with a null face cache, which should not
7372 init_frame_faces (f
);
7374 f
->output_data
.w32
->dwStyle
= WS_BORDER
| WS_POPUP
| WS_DISABLED
;
7375 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
7377 window_prompting
= x_figure_window_size (f
, parms
, 0);
7379 /* No fringes on tip frame. */
7381 f
->left_fringe_width
= 0;
7382 f
->right_fringe_width
= 0;
7385 my_create_tip_window (f
);
7390 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
7391 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
7392 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
7393 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
7394 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
7395 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
7397 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
7398 Change will not be effected unless different from the current
7400 width
= FRAME_COLS (f
);
7401 height
= FRAME_LINES (f
);
7402 FRAME_LINES (f
) = 0;
7403 SET_FRAME_COLS (f
, 0);
7404 change_frame_size (f
, height
, width
, 1, 0, 0);
7406 /* Add `tooltip' frame parameter's default value. */
7407 if (NILP (Fframe_parameter (frame
, intern ("tooltip"))))
7408 Fmodify_frame_parameters (frame
, Fcons (Fcons (intern ("tooltip"), Qt
),
7411 /* Set up faces after all frame parameters are known. This call
7412 also merges in face attributes specified for new frames.
7414 Frame parameters may be changed if .Xdefaults contains
7415 specifications for the default font. For example, if there is an
7416 `Emacs.default.attributeBackground: pink', the `background-color'
7417 attribute of the frame get's set, which let's the internal border
7418 of the tooltip frame appear in pink. Prevent this. */
7420 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
7422 /* Set tip_frame here, so that */
7424 call1 (Qface_set_after_frame_default
, frame
);
7426 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
7427 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qbackground_color
, bg
),
7435 /* It is now ok to make the frame official even if we get an error
7436 below. And the frame needs to be on Vframe_list or making it
7437 visible won't work. */
7438 Vframe_list
= Fcons (frame
, Vframe_list
);
7440 /* Now that the frame is official, it counts as a reference to
7442 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
7444 /* Setting attributes of faces of the tooltip frame from resources
7445 and similar will increment face_change_count, which leads to the
7446 clearing of all current matrices. Since this isn't necessary
7447 here, avoid it by resetting face_change_count to the value it
7448 had before we created the tip frame. */
7449 face_change_count
= face_change_count_before
;
7451 /* Discard the unwind_protect. */
7452 return unbind_to (count
, frame
);
7456 /* Compute where to display tip frame F. PARMS is the list of frame
7457 parameters for F. DX and DY are specified offsets from the current
7458 location of the mouse. WIDTH and HEIGHT are the width and height
7459 of the tooltip. Return coordinates relative to the root window of
7460 the display in *ROOT_X, and *ROOT_Y. */
7463 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, root_x
, root_y
)
7465 Lisp_Object parms
, dx
, dy
;
7467 int *root_x
, *root_y
;
7469 Lisp_Object left
, top
;
7471 /* User-specified position? */
7472 left
= Fcdr (Fassq (Qleft
, parms
));
7473 top
= Fcdr (Fassq (Qtop
, parms
));
7475 /* Move the tooltip window where the mouse pointer is. Resize and
7477 if (!INTEGERP (left
) || !INTEGERP (top
))
7489 *root_y
= XINT (top
);
7490 else if (*root_y
+ XINT (dy
) <= 0)
7491 *root_y
= 0; /* Can happen for negative dy */
7492 else if (*root_y
+ XINT (dy
) + height
<= FRAME_W32_DISPLAY_INFO (f
)->height
)
7493 /* It fits below the pointer */
7494 *root_y
+= XINT (dy
);
7495 else if (height
+ XINT (dy
) <= *root_y
)
7496 /* It fits above the pointer. */
7497 *root_y
-= height
+ XINT (dy
);
7499 /* Put it on the top. */
7502 if (INTEGERP (left
))
7503 *root_x
= XINT (left
);
7504 else if (*root_x
+ XINT (dx
) <= 0)
7505 *root_x
= 0; /* Can happen for negative dx */
7506 else if (*root_x
+ XINT (dx
) + width
<= FRAME_W32_DISPLAY_INFO (f
)->width
)
7507 /* It fits to the right of the pointer. */
7508 *root_x
+= XINT (dx
);
7509 else if (width
+ XINT (dx
) <= *root_x
)
7510 /* It fits to the left of the pointer. */
7511 *root_x
-= width
+ XINT (dx
);
7513 /* Put it left justified on the screen -- it ought to fit that way. */
7518 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
7519 doc
: /* Show STRING in a \"tooltip\" window on frame FRAME.
7520 A tooltip window is a small window displaying a string.
7522 This is an internal function; Lisp code should call `tooltip-show'.
7524 FRAME nil or omitted means use the selected frame.
7526 PARMS is an optional list of frame parameters which can be
7527 used to change the tooltip's appearance.
7529 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
7530 means use the default timeout of 5 seconds.
7532 If the list of frame parameters PARMS contains a `left' parameter,
7533 the tooltip is displayed at that x-position. Otherwise it is
7534 displayed at the mouse position, with offset DX added (default is 5 if
7535 DX isn't specified). Likewise for the y-position; if a `top' frame
7536 parameter is specified, it determines the y-position of the tooltip
7537 window, otherwise it is displayed at the mouse position, with offset
7538 DY added (default is -10).
7540 A tooltip's maximum size is specified by `x-max-tooltip-size'.
7541 Text larger than the specified size is clipped. */)
7542 (string
, frame
, parms
, timeout
, dx
, dy
)
7543 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
7548 struct buffer
*old_buffer
;
7549 struct text_pos pos
;
7550 int i
, width
, height
;
7551 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7552 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7553 int count
= SPECPDL_INDEX ();
7555 specbind (Qinhibit_redisplay
, Qt
);
7557 GCPRO4 (string
, parms
, frame
, timeout
);
7559 CHECK_STRING (string
);
7560 f
= check_x_frame (frame
);
7562 timeout
= make_number (5);
7564 CHECK_NATNUM (timeout
);
7567 dx
= make_number (5);
7572 dy
= make_number (-10);
7576 if (NILP (last_show_tip_args
))
7577 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
7579 if (!NILP (tip_frame
))
7581 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
7582 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
7583 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
7585 if (EQ (frame
, last_frame
)
7586 && !NILP (Fequal (last_string
, string
))
7587 && !NILP (Fequal (last_parms
, parms
)))
7589 struct frame
*f
= XFRAME (tip_frame
);
7591 /* Only DX and DY have changed. */
7592 if (!NILP (tip_timer
))
7594 Lisp_Object timer
= tip_timer
;
7596 call1 (Qcancel_timer
, timer
);
7600 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
7601 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
7603 /* Put tooltip in topmost group and in position. */
7604 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
7605 root_x
, root_y
, 0, 0,
7606 SWP_NOSIZE
| SWP_NOACTIVATE
);
7608 /* Ensure tooltip is on top of other topmost windows (eg menus). */
7609 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
7611 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
7618 /* Hide a previous tip, if any. */
7621 ASET (last_show_tip_args
, 0, string
);
7622 ASET (last_show_tip_args
, 1, frame
);
7623 ASET (last_show_tip_args
, 2, parms
);
7625 /* Add default values to frame parameters. */
7626 if (NILP (Fassq (Qname
, parms
)))
7627 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
7628 if (NILP (Fassq (Qinternal_border_width
, parms
)))
7629 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
7630 if (NILP (Fassq (Qborder_width
, parms
)))
7631 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
7632 if (NILP (Fassq (Qborder_color
, parms
)))
7633 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
7634 if (NILP (Fassq (Qbackground_color
, parms
)))
7635 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
7638 /* Block input until the tip has been fully drawn, to avoid crashes
7639 when drawing tips in menus. */
7642 /* Create a frame for the tooltip, and record it in the global
7643 variable tip_frame. */
7644 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
, string
);
7647 /* Set up the frame's root window. */
7648 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7649 w
->left_col
= w
->top_line
= make_number (0);
7651 if (CONSP (Vx_max_tooltip_size
)
7652 && INTEGERP (XCAR (Vx_max_tooltip_size
))
7653 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
7654 && INTEGERP (XCDR (Vx_max_tooltip_size
))
7655 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
7657 w
->total_cols
= XCAR (Vx_max_tooltip_size
);
7658 w
->total_lines
= XCDR (Vx_max_tooltip_size
);
7662 w
->total_cols
= make_number (80);
7663 w
->total_lines
= make_number (40);
7666 FRAME_TOTAL_COLS (f
) = XINT (w
->total_cols
);
7668 w
->pseudo_window_p
= 1;
7670 /* Display the tooltip text in a temporary buffer. */
7671 old_buffer
= current_buffer
;
7672 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
7673 current_buffer
->truncate_lines
= Qnil
;
7674 clear_glyph_matrix (w
->desired_matrix
);
7675 clear_glyph_matrix (w
->current_matrix
);
7676 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
7677 try_window (FRAME_ROOT_WINDOW (f
), pos
, 0);
7679 /* Compute width and height of the tooltip. */
7681 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
7683 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
7687 /* Stop at the first empty row at the end. */
7688 if (!row
->enabled_p
|| !row
->displays_text_p
)
7691 /* Let the row go over the full width of the frame. */
7692 row
->full_width_p
= 1;
7694 #ifdef TODO /* Investigate why some fonts need more width than is
7695 calculated for some tooltips. */
7696 /* There's a glyph at the end of rows that is use to place
7697 the cursor there. Don't include the width of this glyph. */
7698 if (row
->used
[TEXT_AREA
])
7700 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
7701 row_width
= row
->pixel_width
- last
->pixel_width
;
7705 row_width
= row
->pixel_width
;
7707 /* TODO: find why tips do not draw along baseline as instructed. */
7708 height
+= row
->height
;
7709 width
= max (width
, row_width
);
7712 /* Add the frame's internal border to the width and height the X
7713 window should have. */
7714 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
7715 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
7717 /* Move the tooltip window where the mouse pointer is. Resize and
7719 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
7722 /* Adjust Window size to take border into account. */
7724 rect
.left
= rect
.top
= 0;
7726 rect
.bottom
= height
;
7727 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
7728 FRAME_EXTERNAL_MENU_BAR (f
));
7730 /* Position and size tooltip, and put it in the topmost group.
7731 The add-on of 3 to the 5th argument is a kludge: without it,
7732 some fonts cause the last character of the tip to be truncated,
7733 for some obscure reason. */
7734 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
7735 root_x
, root_y
, rect
.right
- rect
.left
+ 3,
7736 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
);
7738 /* Ensure tooltip is on top of other topmost windows (eg menus). */
7739 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
7741 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
7743 /* Let redisplay know that we have made the frame visible already. */
7744 f
->async_visible
= 1;
7746 ShowWindow (FRAME_W32_WINDOW (f
), SW_SHOWNOACTIVATE
);
7749 /* Draw into the window. */
7750 w
->must_be_updated_p
= 1;
7751 update_single_window (w
, 1);
7755 /* Restore original current buffer. */
7756 set_buffer_internal_1 (old_buffer
);
7757 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7760 /* Let the tip disappear after timeout seconds. */
7761 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
7762 intern ("x-hide-tip"));
7765 return unbind_to (count
, Qnil
);
7769 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
7770 doc
: /* Hide the current tooltip window, if there is any.
7771 Value is t if tooltip was open, nil otherwise. */)
7775 Lisp_Object deleted
, frame
, timer
;
7776 struct gcpro gcpro1
, gcpro2
;
7778 /* Return quickly if nothing to do. */
7779 if (NILP (tip_timer
) && NILP (tip_frame
))
7784 GCPRO2 (frame
, timer
);
7785 tip_frame
= tip_timer
= deleted
= Qnil
;
7787 count
= SPECPDL_INDEX ();
7788 specbind (Qinhibit_redisplay
, Qt
);
7789 specbind (Qinhibit_quit
, Qt
);
7792 call1 (Qcancel_timer
, timer
);
7796 Fdelete_frame (frame
, Qnil
);
7801 return unbind_to (count
, deleted
);
7806 /***********************************************************************
7807 File selection dialog
7808 ***********************************************************************/
7809 extern Lisp_Object Qfile_name_history
;
7811 /* Callback for altering the behaviour of the Open File dialog.
7812 Makes the Filename text field contain "Current Directory" and be
7813 read-only when "Directories" is selected in the filter. This
7814 allows us to work around the fact that the standard Open File
7815 dialog does not support directories. */
7817 file_dialog_callback (hwnd
, msg
, wParam
, lParam
)
7823 if (msg
== WM_NOTIFY
)
7825 OFNOTIFY
* notify
= (OFNOTIFY
*)lParam
;
7826 /* Detect when the Filter dropdown is changed. */
7827 if (notify
->hdr
.code
== CDN_TYPECHANGE
7828 || notify
->hdr
.code
== CDN_INITDONE
)
7830 HWND dialog
= GetParent (hwnd
);
7831 HWND edit_control
= GetDlgItem (dialog
, FILE_NAME_TEXT_FIELD
);
7833 /* Directories is in index 2. */
7834 if (notify
->lpOFN
->nFilterIndex
== 2)
7836 CommDlg_OpenSave_SetControlText (dialog
, FILE_NAME_TEXT_FIELD
,
7837 "Current Directory");
7838 EnableWindow (edit_control
, FALSE
);
7842 /* Don't override default filename on init done. */
7843 if (notify
->hdr
.code
== CDN_TYPECHANGE
)
7844 CommDlg_OpenSave_SetControlText (dialog
,
7845 FILE_NAME_TEXT_FIELD
, "");
7846 EnableWindow (edit_control
, TRUE
);
7853 /* Since we compile with _WIN32_WINNT set to 0x0400 (for NT4 compatibility)
7854 we end up with the old file dialogs. Define a big enough struct for the
7855 new dialog to trick GetOpenFileName into giving us the new dialogs on
7856 Windows 2000 and XP. */
7859 OPENFILENAME real_details
;
7866 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
7867 doc
: /* Read file name, prompting with PROMPT in directory DIR.
7868 Use a file selection dialog.
7869 Select DEFAULT-FILENAME in the dialog's file selection box, if
7870 specified. Ensure that file exists if MUSTMATCH is non-nil.
7871 If ONLY-DIR-P is non-nil, the user can only select directories. */)
7872 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
)
7873 Lisp_Object prompt
, dir
, default_filename
, mustmatch
, only_dir_p
;
7875 struct frame
*f
= SELECTED_FRAME ();
7876 Lisp_Object file
= Qnil
;
7877 int count
= SPECPDL_INDEX ();
7878 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
7879 char filename
[MAX_PATH
+ 1];
7880 char init_dir
[MAX_PATH
+ 1];
7881 int default_filter_index
= 1; /* 1: All Files, 2: Directories only */
7883 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
7884 CHECK_STRING (prompt
);
7887 /* Create the dialog with PROMPT as title, using DIR as initial
7888 directory and using "*" as pattern. */
7889 dir
= Fexpand_file_name (dir
, Qnil
);
7890 strncpy (init_dir
, SDATA (ENCODE_FILE (dir
)), MAX_PATH
);
7891 init_dir
[MAX_PATH
] = '\0';
7892 unixtodos_filename (init_dir
);
7894 if (STRINGP (default_filename
))
7896 char *file_name_only
;
7897 char *full_path_name
= SDATA (ENCODE_FILE (default_filename
));
7899 unixtodos_filename (full_path_name
);
7901 file_name_only
= strrchr (full_path_name
, '\\');
7902 if (!file_name_only
)
7903 file_name_only
= full_path_name
;
7907 strncpy (filename
, file_name_only
, MAX_PATH
);
7908 filename
[MAX_PATH
] = '\0';
7914 NEWOPENFILENAME new_file_details
;
7915 BOOL file_opened
= FALSE
;
7916 OPENFILENAME
* file_details
= &new_file_details
.real_details
;
7918 /* Prevent redisplay. */
7919 specbind (Qinhibit_redisplay
, Qt
);
7922 bzero (&new_file_details
, sizeof (new_file_details
));
7923 /* Apparently NT4 crashes if you give it an unexpected size.
7924 I'm not sure about Windows 9x, so play it safe. */
7925 if (w32_major_version
> 4 && w32_major_version
< 95)
7926 file_details
->lStructSize
= sizeof (new_file_details
);
7928 file_details
->lStructSize
= sizeof (file_details
);
7930 file_details
->hwndOwner
= FRAME_W32_WINDOW (f
);
7931 /* Undocumented Bug in Common File Dialog:
7932 If a filter is not specified, shell links are not resolved. */
7933 file_details
->lpstrFilter
= "All Files (*.*)\0*.*\0Directories\0*|*\0\0";
7934 file_details
->lpstrFile
= filename
;
7935 file_details
->nMaxFile
= sizeof (filename
);
7936 file_details
->lpstrInitialDir
= init_dir
;
7937 file_details
->lpstrTitle
= SDATA (prompt
);
7939 if (! NILP (only_dir_p
))
7940 default_filter_index
= 2;
7942 file_details
->nFilterIndex
= default_filter_index
;
7944 file_details
->Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
7945 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
7946 if (!NILP (mustmatch
))
7948 /* Require that the path to the parent directory exists. */
7949 file_details
->Flags
|= OFN_PATHMUSTEXIST
;
7950 /* If we are looking for a file, require that it exists. */
7951 if (NILP (only_dir_p
))
7952 file_details
->Flags
|= OFN_FILEMUSTEXIST
;
7955 file_details
->lpfnHook
= (LPOFNHOOKPROC
) file_dialog_callback
;
7957 file_opened
= GetOpenFileName (file_details
);
7963 dostounix_filename (filename
);
7965 if (file_details
->nFilterIndex
== 2)
7967 /* "Directories" selected - strip dummy file name. */
7968 char * last
= strrchr (filename
, '/');
7972 file
= DECODE_FILE(build_string (filename
));
7974 /* User cancelled the dialog without making a selection. */
7975 else if (!CommDlgExtendedError ())
7977 /* An error occurred, fallback on reading from the mini-buffer. */
7979 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
7980 dir
, mustmatch
, dir
, Qfile_name_history
,
7981 default_filename
, Qnil
);
7983 file
= unbind_to (count
, file
);
7988 /* Make "Cancel" equivalent to C-g. */
7990 Fsignal (Qquit
, Qnil
);
7992 return unbind_to (count
, file
);
7997 /***********************************************************************
7998 w32 specialized functions
7999 ***********************************************************************/
8001 DEFUN ("w32-select-font", Fw32_select_font
, Sw32_select_font
, 0, 2, 0,
8002 doc
: /* Select a font for the named FRAME using the W32 font dialog.
8003 Returns an X-style font string corresponding to the selection.
8005 If FRAME is omitted or nil, it defaults to the selected frame.
8006 If INCLUDE-PROPORTIONAL is non-nil, include proportional fonts
8007 in the font selection dialog. */)
8008 (frame
, include_proportional
)
8009 Lisp_Object frame
, include_proportional
;
8011 FRAME_PTR f
= check_x_frame (frame
);
8019 bzero (&cf
, sizeof (cf
));
8020 bzero (&lf
, sizeof (lf
));
8022 cf
.lStructSize
= sizeof (cf
);
8023 cf
.hwndOwner
= FRAME_W32_WINDOW (f
);
8024 cf
.Flags
= CF_FORCEFONTEXIST
| CF_SCREENFONTS
| CF_NOVERTFONTS
;
8026 /* Unless include_proportional is non-nil, limit the selection to
8027 monospaced fonts. */
8028 if (NILP (include_proportional
))
8029 cf
.Flags
|= CF_FIXEDPITCHONLY
;
8033 /* Initialize as much of the font details as we can from the current
8035 hdc
= GetDC (FRAME_W32_WINDOW (f
));
8036 oldobj
= SelectObject (hdc
, FRAME_FONT (f
)->hfont
);
8037 GetTextFace (hdc
, LF_FACESIZE
, lf
.lfFaceName
);
8038 if (GetTextMetrics (hdc
, &tm
))
8040 lf
.lfHeight
= tm
.tmInternalLeading
- tm
.tmHeight
;
8041 lf
.lfWeight
= tm
.tmWeight
;
8042 lf
.lfItalic
= tm
.tmItalic
;
8043 lf
.lfUnderline
= tm
.tmUnderlined
;
8044 lf
.lfStrikeOut
= tm
.tmStruckOut
;
8045 lf
.lfCharSet
= tm
.tmCharSet
;
8046 cf
.Flags
|= CF_INITTOLOGFONTSTRUCT
;
8048 SelectObject (hdc
, oldobj
);
8049 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
8051 if (!ChooseFont (&cf
) || !w32_to_x_font (&lf
, buf
, 100, NULL
))
8054 return build_string (buf
);
8057 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
,
8058 Sw32_send_sys_command
, 1, 2, 0,
8059 doc
: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND.
8060 Some useful values for COMMAND are #xf030 to maximize frame (#xf020
8061 to minimize), #xf120 to restore frame to original size, and #xf100
8062 to activate the menubar for keyboard access. #xf140 activates the
8063 screen saver if defined.
8065 If optional parameter FRAME is not specified, use selected frame. */)
8067 Lisp_Object command
, frame
;
8069 FRAME_PTR f
= check_x_frame (frame
);
8071 CHECK_NUMBER (command
);
8073 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
8078 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
8079 doc
: /* Get Windows to perform OPERATION on DOCUMENT.
8080 This is a wrapper around the ShellExecute system function, which
8081 invokes the application registered to handle OPERATION for DOCUMENT.
8083 OPERATION is either nil or a string that names a supported operation.
8084 What operations can be used depends on the particular DOCUMENT and its
8085 handler application, but typically it is one of the following common
8088 \"open\" - open DOCUMENT, which could be a file, a directory, or an
8089 executable program. If it is an application, that
8090 application is launched in the current buffer's default
8091 directory. Otherwise, the application associated with
8092 DOCUMENT is launched in the buffer's default directory.
8093 \"print\" - print DOCUMENT, which must be a file
8094 \"explore\" - start the Windows Explorer on DOCUMENT
8095 \"edit\" - launch an editor and open DOCUMENT for editing; which
8096 editor is launched depends on the association for the
8098 \"find\" - initiate search starting from DOCUMENT which must specify
8100 nil - invoke the default OPERATION, or \"open\" if default is
8101 not defined or unavailable
8103 DOCUMENT is typically the name of a document file or a URL, but can
8104 also be a program executable to run, or a directory to open in the
8107 If DOCUMENT is a program executable, the optional arg PARAMETERS can
8108 be a string containing command line parameters that will be passed to
8109 the program; otherwise, PARAMETERS should be nil or unspecified.
8111 Second optional argument SHOW-FLAG can be used to control how the
8112 application will be displayed when it is invoked. If SHOW-FLAG is nil
8113 or unspceified, the application is displayed normally, otherwise it is
8114 an integer representing a ShowWindow flag:
8119 6 - start minimized */)
8120 (operation
, document
, parameters
, show_flag
)
8121 Lisp_Object operation
, document
, parameters
, show_flag
;
8123 Lisp_Object current_dir
;
8125 CHECK_STRING (document
);
8127 /* Encode filename and current directory. */
8128 current_dir
= ENCODE_FILE (current_buffer
->directory
);
8129 document
= ENCODE_FILE (document
);
8130 if ((int) ShellExecute (NULL
,
8131 (STRINGP (operation
) ?
8132 SDATA (operation
) : NULL
),
8134 (STRINGP (parameters
) ?
8135 SDATA (parameters
) : NULL
),
8136 SDATA (current_dir
),
8137 (INTEGERP (show_flag
) ?
8138 XINT (show_flag
) : SW_SHOWDEFAULT
))
8141 error ("ShellExecute failed: %s", w32_strerror (0));
8144 /* Lookup virtual keycode from string representing the name of a
8145 non-ascii keystroke into the corresponding virtual key, using
8146 lispy_function_keys. */
8148 lookup_vk_code (char *key
)
8152 for (i
= 0; i
< 256; i
++)
8153 if (lispy_function_keys
[i
] != 0
8154 && strcmp (lispy_function_keys
[i
], key
) == 0)
8160 /* Convert a one-element vector style key sequence to a hot key
8163 w32_parse_hot_key (key
)
8166 /* Copied from Fdefine_key and store_in_keymap. */
8167 register Lisp_Object c
;
8171 struct gcpro gcpro1
;
8175 if (XFASTINT (Flength (key
)) != 1)
8180 c
= Faref (key
, make_number (0));
8182 if (CONSP (c
) && lucid_event_type_list_p (c
))
8183 c
= Fevent_convert_list (c
);
8187 if (! INTEGERP (c
) && ! SYMBOLP (c
))
8188 error ("Key definition is invalid");
8190 /* Work out the base key and the modifiers. */
8193 c
= parse_modifiers (c
);
8194 lisp_modifiers
= XINT (Fcar (Fcdr (c
)));
8198 vk_code
= lookup_vk_code (SDATA (SYMBOL_NAME (c
)));
8200 else if (INTEGERP (c
))
8202 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
8203 /* Many ascii characters are their own virtual key code. */
8204 vk_code
= XINT (c
) & CHARACTERBITS
;
8207 if (vk_code
< 0 || vk_code
> 255)
8210 if ((lisp_modifiers
& meta_modifier
) != 0
8211 && !NILP (Vw32_alt_is_meta
))
8212 lisp_modifiers
|= alt_modifier
;
8214 /* Supply defs missing from mingw32. */
8216 #define MOD_ALT 0x0001
8217 #define MOD_CONTROL 0x0002
8218 #define MOD_SHIFT 0x0004
8219 #define MOD_WIN 0x0008
8222 /* Convert lisp modifiers to Windows hot-key form. */
8223 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
8224 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
8225 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
8226 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
8228 return HOTKEY (vk_code
, w32_modifiers
);
8231 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
,
8232 Sw32_register_hot_key
, 1, 1, 0,
8233 doc
: /* Register KEY as a hot-key combination.
8234 Certain key combinations like Alt-Tab are reserved for system use on
8235 Windows, and therefore are normally intercepted by the system. However,
8236 most of these key combinations can be received by registering them as
8237 hot-keys, overriding their special meaning.
8239 KEY must be a one element key definition in vector form that would be
8240 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta
8241 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper
8242 is always interpreted as the Windows modifier keys.
8244 The return value is the hotkey-id if registered, otherwise nil. */)
8248 key
= w32_parse_hot_key (key
);
8250 if (NILP (Fmemq (key
, w32_grabbed_keys
)))
8252 /* Reuse an empty slot if possible. */
8253 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
8255 /* Safe to add new key to list, even if we have focus. */
8257 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
8259 XSETCAR (item
, key
);
8261 /* Notify input thread about new hot-key definition, so that it
8262 takes effect without needing to switch focus. */
8263 #ifdef USE_LISP_UNION_TYPE
8264 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
8267 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
8275 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
,
8276 Sw32_unregister_hot_key
, 1, 1, 0,
8277 doc
: /* Unregister KEY as a hot-key combination. */)
8283 if (!INTEGERP (key
))
8284 key
= w32_parse_hot_key (key
);
8286 item
= Fmemq (key
, w32_grabbed_keys
);
8290 /* Notify input thread about hot-key definition being removed, so
8291 that it takes effect without needing focus switch. */
8292 #ifdef USE_LISP_UNION_TYPE
8293 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
8294 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
.i
))
8296 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
8297 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
))
8302 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
8309 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
,
8310 Sw32_registered_hot_keys
, 0, 0, 0,
8311 doc
: /* Return list of registered hot-key IDs. */)
8314 return Fcopy_sequence (w32_grabbed_keys
);
8317 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
,
8318 Sw32_reconstruct_hot_key
, 1, 1, 0,
8319 doc
: /* Convert hot-key ID to a lisp key combination.
8320 usage: (w32-reconstruct-hot-key ID) */)
8322 Lisp_Object hotkeyid
;
8324 int vk_code
, w32_modifiers
;
8327 CHECK_NUMBER (hotkeyid
);
8329 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
8330 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
8332 if (lispy_function_keys
[vk_code
])
8333 key
= intern (lispy_function_keys
[vk_code
]);
8335 key
= make_number (vk_code
);
8337 key
= Fcons (key
, Qnil
);
8338 if (w32_modifiers
& MOD_SHIFT
)
8339 key
= Fcons (Qshift
, key
);
8340 if (w32_modifiers
& MOD_CONTROL
)
8341 key
= Fcons (Qctrl
, key
);
8342 if (w32_modifiers
& MOD_ALT
)
8343 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
8344 if (w32_modifiers
& MOD_WIN
)
8345 key
= Fcons (Qhyper
, key
);
8350 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
,
8351 Sw32_toggle_lock_key
, 1, 2, 0,
8352 doc
: /* Toggle the state of the lock key KEY.
8353 KEY can be `capslock', `kp-numlock', or `scroll'.
8354 If the optional parameter NEW-STATE is a number, then the state of KEY
8355 is set to off if the low bit of NEW-STATE is zero, otherwise on. */)
8357 Lisp_Object key
, new_state
;
8361 if (EQ (key
, intern ("capslock")))
8362 vk_code
= VK_CAPITAL
;
8363 else if (EQ (key
, intern ("kp-numlock")))
8364 vk_code
= VK_NUMLOCK
;
8365 else if (EQ (key
, intern ("scroll")))
8366 vk_code
= VK_SCROLL
;
8370 if (!dwWindowsThreadId
)
8371 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
8373 #ifdef USE_LISP_UNION_TYPE
8374 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
8375 (WPARAM
) vk_code
, (LPARAM
) new_state
.i
))
8377 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
8378 (WPARAM
) vk_code
, (LPARAM
) new_state
))
8382 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
8383 return make_number (msg
.wParam
);
8388 DEFUN ("w32-window-exists-p", Fw32_window_exists_p
, Sw32_window_exists_p
,
8390 doc
: /* Return non-nil if a window exists with the specified CLASS and NAME.
8392 This is a direct interface to the Windows API FindWindow function. */)
8394 Lisp_Object
class, name
;
8399 CHECK_STRING (class);
8401 CHECK_STRING (name
);
8403 hnd
= FindWindow (STRINGP (class) ? ((LPCTSTR
) SDATA (class)) : NULL
,
8404 STRINGP (name
) ? ((LPCTSTR
) SDATA (name
)) : NULL
);
8412 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
8413 doc
: /* Return storage information about the file system FILENAME is on.
8414 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
8415 storage of the file system, FREE is the free storage, and AVAIL is the
8416 storage available to a non-superuser. All 3 numbers are in bytes.
8417 If the underlying system call fails, value is nil. */)
8419 Lisp_Object filename
;
8421 Lisp_Object encoded
, value
;
8423 CHECK_STRING (filename
);
8424 filename
= Fexpand_file_name (filename
, Qnil
);
8425 encoded
= ENCODE_FILE (filename
);
8429 /* Determining the required information on Windows turns out, sadly,
8430 to be more involved than one would hope. The original Win32 api
8431 call for this will return bogus information on some systems, but we
8432 must dynamically probe for the replacement api, since that was
8433 added rather late on. */
8435 HMODULE hKernel
= GetModuleHandle ("kernel32");
8436 BOOL (*pfn_GetDiskFreeSpaceEx
)
8437 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
8438 = (void *) GetProcAddress (hKernel
, "GetDiskFreeSpaceEx");
8440 /* On Windows, we may need to specify the root directory of the
8441 volume holding FILENAME. */
8442 char rootname
[MAX_PATH
];
8443 char *name
= SDATA (encoded
);
8445 /* find the root name of the volume if given */
8446 if (isalpha (name
[0]) && name
[1] == ':')
8448 rootname
[0] = name
[0];
8449 rootname
[1] = name
[1];
8453 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
8455 char *str
= rootname
;
8459 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
8469 if (pfn_GetDiskFreeSpaceEx
)
8471 /* Unsigned large integers cannot be cast to double, so
8472 use signed ones instead. */
8473 LARGE_INTEGER availbytes
;
8474 LARGE_INTEGER freebytes
;
8475 LARGE_INTEGER totalbytes
;
8477 if (pfn_GetDiskFreeSpaceEx(rootname
,
8478 (ULARGE_INTEGER
*)&availbytes
,
8479 (ULARGE_INTEGER
*)&totalbytes
,
8480 (ULARGE_INTEGER
*)&freebytes
))
8481 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
8482 make_float ((double) freebytes
.QuadPart
),
8483 make_float ((double) availbytes
.QuadPart
));
8487 DWORD sectors_per_cluster
;
8488 DWORD bytes_per_sector
;
8489 DWORD free_clusters
;
8490 DWORD total_clusters
;
8492 if (GetDiskFreeSpace(rootname
,
8493 §ors_per_cluster
,
8497 value
= list3 (make_float ((double) total_clusters
8498 * sectors_per_cluster
* bytes_per_sector
),
8499 make_float ((double) free_clusters
8500 * sectors_per_cluster
* bytes_per_sector
),
8501 make_float ((double) free_clusters
8502 * sectors_per_cluster
* bytes_per_sector
));
8509 DEFUN ("default-printer-name", Fdefault_printer_name
, Sdefault_printer_name
,
8510 0, 0, 0, doc
: /* Return the name of Windows default printer device. */)
8513 static char pname_buf
[256];
8516 PRINTER_INFO_2
*ppi2
= NULL
;
8517 DWORD dwNeeded
= 0, dwReturned
= 0;
8519 /* Retrieve the default string from Win.ini (the registry).
8520 * String will be in form "printername,drivername,portname".
8521 * This is the most portable way to get the default printer. */
8522 if (GetProfileString ("windows", "device", ",,", pname_buf
, sizeof (pname_buf
)) <= 0)
8524 /* printername precedes first "," character */
8525 strtok (pname_buf
, ",");
8526 /* We want to know more than the printer name */
8527 if (!OpenPrinter (pname_buf
, &hPrn
, NULL
))
8529 GetPrinter (hPrn
, 2, NULL
, 0, &dwNeeded
);
8532 ClosePrinter (hPrn
);
8535 /* Allocate memory for the PRINTER_INFO_2 struct */
8536 ppi2
= (PRINTER_INFO_2
*) xmalloc (dwNeeded
);
8539 ClosePrinter (hPrn
);
8542 /* Call GetPrinter() again with big enouth memory block */
8543 err
= GetPrinter (hPrn
, 2, (LPBYTE
)ppi2
, dwNeeded
, &dwReturned
);
8544 ClosePrinter (hPrn
);
8553 if (ppi2
->Attributes
& PRINTER_ATTRIBUTE_SHARED
&& ppi2
->pServerName
)
8555 /* a remote printer */
8556 if (*ppi2
->pServerName
== '\\')
8557 _snprintf(pname_buf
, sizeof (pname_buf
), "%s\\%s", ppi2
->pServerName
,
8560 _snprintf(pname_buf
, sizeof (pname_buf
), "\\\\%s\\%s", ppi2
->pServerName
,
8562 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
8566 /* a local printer */
8567 strncpy(pname_buf
, ppi2
->pPortName
, sizeof (pname_buf
));
8568 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
8569 /* `pPortName' can include several ports, delimited by ','.
8570 * we only use the first one. */
8571 strtok(pname_buf
, ",");
8576 return build_string (pname_buf
);
8579 /***********************************************************************
8581 ***********************************************************************/
8583 /* Keep this list in the same order as frame_parms in frame.c.
8584 Use 0 for unsupported frame parameters. */
8586 frame_parm_handler w32_frame_parm_handlers
[] =
8590 x_set_background_color
,
8596 x_set_foreground_color
,
8599 x_set_internal_border_width
,
8600 x_set_menu_bar_lines
,
8602 x_explicitly_set_name
,
8603 x_set_scroll_bar_width
,
8606 x_set_vertical_scroll_bars
,
8608 x_set_tool_bar_lines
,
8609 0, /* x_set_scroll_bar_foreground, */
8610 0, /* x_set_scroll_bar_background, */
8615 0, /* x_set_wait_for_wm, */
8622 globals_of_w32fns ();
8623 /* This is zero if not using MS-Windows. */
8625 track_mouse_window
= NULL
;
8627 w32_visible_system_caret_hwnd
= NULL
;
8629 Qnone
= intern ("none");
8631 Qsuppress_icon
= intern ("suppress-icon");
8632 staticpro (&Qsuppress_icon
);
8633 Qundefined_color
= intern ("undefined-color");
8634 staticpro (&Qundefined_color
);
8635 Qcancel_timer
= intern ("cancel-timer");
8636 staticpro (&Qcancel_timer
);
8638 Qhyper
= intern ("hyper");
8639 staticpro (&Qhyper
);
8640 Qsuper
= intern ("super");
8641 staticpro (&Qsuper
);
8642 Qmeta
= intern ("meta");
8644 Qalt
= intern ("alt");
8646 Qctrl
= intern ("ctrl");
8648 Qcontrol
= intern ("control");
8649 staticpro (&Qcontrol
);
8650 Qshift
= intern ("shift");
8651 staticpro (&Qshift
);
8652 /* This is the end of symbol initialization. */
8654 /* Text property `display' should be nonsticky by default. */
8655 Vtext_property_default_nonsticky
8656 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
8659 Fput (Qundefined_color
, Qerror_conditions
,
8660 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
8661 Fput (Qundefined_color
, Qerror_message
,
8662 build_string ("Undefined color"));
8664 staticpro (&w32_grabbed_keys
);
8665 w32_grabbed_keys
= Qnil
;
8667 DEFVAR_LISP ("w32-color-map", &Vw32_color_map
,
8668 doc
: /* An array of color name mappings for Windows. */);
8669 Vw32_color_map
= Qnil
;
8671 DEFVAR_LISP ("w32-pass-alt-to-system", &Vw32_pass_alt_to_system
,
8672 doc
: /* Non-nil if Alt key presses are passed on to Windows.
8673 When non-nil, for example, Alt pressed and released and then space will
8674 open the System menu. When nil, Emacs processes the Alt key events, and
8675 then silently swallows them. */);
8676 Vw32_pass_alt_to_system
= Qnil
;
8678 DEFVAR_LISP ("w32-alt-is-meta", &Vw32_alt_is_meta
,
8679 doc
: /* Non-nil if the Alt key is to be considered the same as the META key.
8680 When nil, Emacs will translate the Alt key to the ALT modifier, not to META. */);
8681 Vw32_alt_is_meta
= Qt
;
8683 DEFVAR_INT ("w32-quit-key", &w32_quit_key
,
8684 doc
: /* If non-zero, the virtual key code for an alternative quit key. */);
8687 DEFVAR_LISP ("w32-pass-lwindow-to-system",
8688 &Vw32_pass_lwindow_to_system
,
8689 doc
: /* If non-nil, the left \"Windows\" key is passed on to Windows.
8691 When non-nil, the Start menu is opened by tapping the key.
8692 If you set this to nil, the left \"Windows\" key is processed by Emacs
8693 according to the value of `w32-lwindow-modifier', which see.
8695 Note that some combinations of the left \"Windows\" key with other keys are
8696 caught by Windows at low level, and so binding them in Emacs will have no
8697 effect. For example, <lwindow>-r always pops up the Windows Run dialog,
8698 <lwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
8699 the doc string of `w32-phantom-key-code'. */);
8700 Vw32_pass_lwindow_to_system
= Qt
;
8702 DEFVAR_LISP ("w32-pass-rwindow-to-system",
8703 &Vw32_pass_rwindow_to_system
,
8704 doc
: /* If non-nil, the right \"Windows\" key is passed on to Windows.
8706 When non-nil, the Start menu is opened by tapping the key.
8707 If you set this to nil, the right \"Windows\" key is processed by Emacs
8708 according to the value of `w32-rwindow-modifier', which see.
8710 Note that some combinations of the right \"Windows\" key with other keys are
8711 caught by Windows at low level, and so binding them in Emacs will have no
8712 effect. For example, <rwindow>-r always pops up the Windows Run dialog,
8713 <rwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
8714 the doc string of `w32-phantom-key-code'. */);
8715 Vw32_pass_rwindow_to_system
= Qt
;
8717 DEFVAR_LISP ("w32-phantom-key-code",
8718 &Vw32_phantom_key_code
,
8719 doc
: /* Virtual key code used to generate \"phantom\" key presses.
8720 Value is a number between 0 and 255.
8722 Phantom key presses are generated in order to stop the system from
8723 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or
8724 `w32-pass-rwindow-to-system' is nil. */);
8725 /* Although 255 is technically not a valid key code, it works and
8726 means that this hack won't interfere with any real key code. */
8727 XSETINT (Vw32_phantom_key_code
, 255);
8729 DEFVAR_LISP ("w32-enable-num-lock",
8730 &Vw32_enable_num_lock
,
8731 doc
: /* If non-nil, the Num Lock key acts normally.
8732 Set to nil to handle Num Lock as the `kp-numlock' key. */);
8733 Vw32_enable_num_lock
= Qt
;
8735 DEFVAR_LISP ("w32-enable-caps-lock",
8736 &Vw32_enable_caps_lock
,
8737 doc
: /* If non-nil, the Caps Lock key acts normally.
8738 Set to nil to handle Caps Lock as the `capslock' key. */);
8739 Vw32_enable_caps_lock
= Qt
;
8741 DEFVAR_LISP ("w32-scroll-lock-modifier",
8742 &Vw32_scroll_lock_modifier
,
8743 doc
: /* Modifier to use for the Scroll Lock ON state.
8744 The value can be hyper, super, meta, alt, control or shift for the
8745 respective modifier, or nil to handle Scroll Lock as the `scroll' key.
8746 Any other value will cause the Scroll Lock key to be ignored. */);
8747 Vw32_scroll_lock_modifier
= Qt
;
8749 DEFVAR_LISP ("w32-lwindow-modifier",
8750 &Vw32_lwindow_modifier
,
8751 doc
: /* Modifier to use for the left \"Windows\" key.
8752 The value can be hyper, super, meta, alt, control or shift for the
8753 respective modifier, or nil to appear as the `lwindow' key.
8754 Any other value will cause the key to be ignored. */);
8755 Vw32_lwindow_modifier
= Qnil
;
8757 DEFVAR_LISP ("w32-rwindow-modifier",
8758 &Vw32_rwindow_modifier
,
8759 doc
: /* Modifier to use for the right \"Windows\" key.
8760 The value can be hyper, super, meta, alt, control or shift for the
8761 respective modifier, or nil to appear as the `rwindow' key.
8762 Any other value will cause the key to be ignored. */);
8763 Vw32_rwindow_modifier
= Qnil
;
8765 DEFVAR_LISP ("w32-apps-modifier",
8766 &Vw32_apps_modifier
,
8767 doc
: /* Modifier to use for the \"Apps\" key.
8768 The value can be hyper, super, meta, alt, control or shift for the
8769 respective modifier, or nil to appear as the `apps' key.
8770 Any other value will cause the key to be ignored. */);
8771 Vw32_apps_modifier
= Qnil
;
8773 DEFVAR_BOOL ("w32-enable-synthesized-fonts", &w32_enable_synthesized_fonts
,
8774 doc
: /* Non-nil enables selection of artificially italicized and bold fonts. */);
8775 w32_enable_synthesized_fonts
= 0;
8777 DEFVAR_LISP ("w32-enable-palette", &Vw32_enable_palette
,
8778 doc
: /* Non-nil enables Windows palette management to map colors exactly. */);
8779 Vw32_enable_palette
= Qt
;
8781 DEFVAR_INT ("w32-mouse-button-tolerance",
8782 &w32_mouse_button_tolerance
,
8783 doc
: /* Analogue of double click interval for faking middle mouse events.
8784 The value is the minimum time in milliseconds that must elapse between
8785 left and right button down events before they are considered distinct events.
8786 If both mouse buttons are depressed within this interval, a middle mouse
8787 button down event is generated instead. */);
8788 w32_mouse_button_tolerance
= GetDoubleClickTime () / 2;
8790 DEFVAR_INT ("w32-mouse-move-interval",
8791 &w32_mouse_move_interval
,
8792 doc
: /* Minimum interval between mouse move events.
8793 The value is the minimum time in milliseconds that must elapse between
8794 successive mouse move (or scroll bar drag) events before they are
8795 reported as lisp events. */);
8796 w32_mouse_move_interval
= 0;
8798 DEFVAR_BOOL ("w32-pass-extra-mouse-buttons-to-system",
8799 &w32_pass_extra_mouse_buttons_to_system
,
8800 doc
: /* If non-nil, the fourth and fifth mouse buttons are passed to Windows.
8801 Recent versions of Windows support mice with up to five buttons.
8802 Since most applications don't support these extra buttons, most mouse
8803 drivers will allow you to map them to functions at the system level.
8804 If this variable is non-nil, Emacs will pass them on, allowing the
8805 system to handle them. */);
8806 w32_pass_extra_mouse_buttons_to_system
= 0;
8808 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
8809 doc
: /* The shape of the pointer when over text.
8810 Changing the value does not affect existing frames
8811 unless you set the mouse color. */);
8812 Vx_pointer_shape
= Qnil
;
8814 Vx_nontext_pointer_shape
= Qnil
;
8816 Vx_mode_pointer_shape
= Qnil
;
8818 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
8819 doc
: /* The shape of the pointer when Emacs is busy.
8820 This variable takes effect when you create a new frame
8821 or when you set the mouse color. */);
8822 Vx_hourglass_pointer_shape
= Qnil
;
8824 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
8825 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
8826 display_hourglass_p
= 1;
8828 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
8829 doc
: /* *Seconds to wait before displaying an hourglass pointer.
8830 Value must be an integer or float. */);
8831 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
8833 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
8834 &Vx_sensitive_text_pointer_shape
,
8835 doc
: /* The shape of the pointer when over mouse-sensitive text.
8836 This variable takes effect when you create a new frame
8837 or when you set the mouse color. */);
8838 Vx_sensitive_text_pointer_shape
= Qnil
;
8840 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
8841 &Vx_window_horizontal_drag_shape
,
8842 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
8843 This variable takes effect when you create a new frame
8844 or when you set the mouse color. */);
8845 Vx_window_horizontal_drag_shape
= Qnil
;
8847 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
8848 doc
: /* A string indicating the foreground color of the cursor box. */);
8849 Vx_cursor_fore_pixel
= Qnil
;
8851 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size
,
8852 doc
: /* Maximum size for tooltips.
8853 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
8854 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
8856 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
8857 doc
: /* Non-nil if no window manager is in use.
8858 Emacs doesn't try to figure this out; this is always nil
8859 unless you set it to something else. */);
8860 /* We don't have any way to find this out, so set it to nil
8861 and maybe the user would like to set it to t. */
8862 Vx_no_window_manager
= Qnil
;
8864 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
8865 &Vx_pixel_size_width_font_regexp
,
8866 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
8868 Since Emacs gets width of a font matching with this regexp from
8869 PIXEL_SIZE field of the name, font finding mechanism gets faster for
8870 such a font. This is especially effective for such large fonts as
8871 Chinese, Japanese, and Korean. */);
8872 Vx_pixel_size_width_font_regexp
= Qnil
;
8874 DEFVAR_LISP ("w32-bdf-filename-alist",
8875 &Vw32_bdf_filename_alist
,
8876 doc
: /* List of bdf fonts and their corresponding filenames. */);
8877 Vw32_bdf_filename_alist
= Qnil
;
8879 DEFVAR_BOOL ("w32-strict-fontnames",
8880 &w32_strict_fontnames
,
8881 doc
: /* Non-nil means only use fonts that are exact matches for those requested.
8882 Default is nil, which allows old fontnames that are not XLFD compliant,
8883 and allows third-party CJK display to work by specifying false charset
8884 fields to trick Emacs into translating to Big5, SJIS etc.
8885 Setting this to t will prevent wrong fonts being selected when
8886 fontsets are automatically created. */);
8887 w32_strict_fontnames
= 0;
8889 DEFVAR_BOOL ("w32-strict-painting",
8890 &w32_strict_painting
,
8891 doc
: /* Non-nil means use strict rules for repainting frames.
8892 Set this to nil to get the old behavior for repainting; this should
8893 only be necessary if the default setting causes problems. */);
8894 w32_strict_painting
= 1;
8896 DEFVAR_LISP ("w32-charset-info-alist",
8897 &Vw32_charset_info_alist
,
8898 doc
: /* Alist linking Emacs character sets to Windows fonts and codepages.
8899 Each entry should be of the form:
8901 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE))
8903 where CHARSET_NAME is a string used in font names to identify the charset,
8904 WINDOWS_CHARSET is a symbol that can be one of:
8905 w32-charset-ansi, w32-charset-default, w32-charset-symbol,
8906 w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312,
8907 w32-charset-chinesebig5,
8908 w32-charset-johab, w32-charset-hebrew,
8909 w32-charset-arabic, w32-charset-greek, w32-charset-turkish,
8910 w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope,
8911 w32-charset-russian, w32-charset-mac, w32-charset-baltic,
8912 w32-charset-unicode,
8914 CODEPAGE should be an integer specifying the codepage that should be used
8915 to display the character set, t to do no translation and output as Unicode,
8916 or nil to do no translation and output as 8 bit (or multibyte on far-east
8917 versions of Windows) characters. */);
8918 Vw32_charset_info_alist
= Qnil
;
8920 staticpro (&Qw32_charset_ansi
);
8921 Qw32_charset_ansi
= intern ("w32-charset-ansi");
8922 staticpro (&Qw32_charset_symbol
);
8923 Qw32_charset_default
= intern ("w32-charset-default");
8924 staticpro (&Qw32_charset_default
);
8925 Qw32_charset_symbol
= intern ("w32-charset-symbol");
8926 staticpro (&Qw32_charset_shiftjis
);
8927 Qw32_charset_shiftjis
= intern ("w32-charset-shiftjis");
8928 staticpro (&Qw32_charset_hangeul
);
8929 Qw32_charset_hangeul
= intern ("w32-charset-hangeul");
8930 staticpro (&Qw32_charset_chinesebig5
);
8931 Qw32_charset_chinesebig5
= intern ("w32-charset-chinesebig5");
8932 staticpro (&Qw32_charset_gb2312
);
8933 Qw32_charset_gb2312
= intern ("w32-charset-gb2312");
8934 staticpro (&Qw32_charset_oem
);
8935 Qw32_charset_oem
= intern ("w32-charset-oem");
8937 #ifdef JOHAB_CHARSET
8939 static int w32_extra_charsets_defined
= 1;
8940 DEFVAR_BOOL ("w32-extra-charsets-defined", &w32_extra_charsets_defined
,
8941 doc
: /* Internal variable. */);
8943 staticpro (&Qw32_charset_johab
);
8944 Qw32_charset_johab
= intern ("w32-charset-johab");
8945 staticpro (&Qw32_charset_easteurope
);
8946 Qw32_charset_easteurope
= intern ("w32-charset-easteurope");
8947 staticpro (&Qw32_charset_turkish
);
8948 Qw32_charset_turkish
= intern ("w32-charset-turkish");
8949 staticpro (&Qw32_charset_baltic
);
8950 Qw32_charset_baltic
= intern ("w32-charset-baltic");
8951 staticpro (&Qw32_charset_russian
);
8952 Qw32_charset_russian
= intern ("w32-charset-russian");
8953 staticpro (&Qw32_charset_arabic
);
8954 Qw32_charset_arabic
= intern ("w32-charset-arabic");
8955 staticpro (&Qw32_charset_greek
);
8956 Qw32_charset_greek
= intern ("w32-charset-greek");
8957 staticpro (&Qw32_charset_hebrew
);
8958 Qw32_charset_hebrew
= intern ("w32-charset-hebrew");
8959 staticpro (&Qw32_charset_vietnamese
);
8960 Qw32_charset_vietnamese
= intern ("w32-charset-vietnamese");
8961 staticpro (&Qw32_charset_thai
);
8962 Qw32_charset_thai
= intern ("w32-charset-thai");
8963 staticpro (&Qw32_charset_mac
);
8964 Qw32_charset_mac
= intern ("w32-charset-mac");
8968 #ifdef UNICODE_CHARSET
8970 static int w32_unicode_charset_defined
= 1;
8971 DEFVAR_BOOL ("w32-unicode-charset-defined",
8972 &w32_unicode_charset_defined
,
8973 doc
: /* Internal variable. */);
8975 staticpro (&Qw32_charset_unicode
);
8976 Qw32_charset_unicode
= intern ("w32-charset-unicode");
8980 #if 0 /* TODO: Port to W32 */
8981 defsubr (&Sx_change_window_property
);
8982 defsubr (&Sx_delete_window_property
);
8983 defsubr (&Sx_window_property
);
8985 defsubr (&Sxw_display_color_p
);
8986 defsubr (&Sx_display_grayscale_p
);
8987 defsubr (&Sxw_color_defined_p
);
8988 defsubr (&Sxw_color_values
);
8989 defsubr (&Sx_server_max_request_size
);
8990 defsubr (&Sx_server_vendor
);
8991 defsubr (&Sx_server_version
);
8992 defsubr (&Sx_display_pixel_width
);
8993 defsubr (&Sx_display_pixel_height
);
8994 defsubr (&Sx_display_mm_width
);
8995 defsubr (&Sx_display_mm_height
);
8996 defsubr (&Sx_display_screens
);
8997 defsubr (&Sx_display_planes
);
8998 defsubr (&Sx_display_color_cells
);
8999 defsubr (&Sx_display_visual_class
);
9000 defsubr (&Sx_display_backing_store
);
9001 defsubr (&Sx_display_save_under
);
9002 defsubr (&Sx_create_frame
);
9003 defsubr (&Sx_open_connection
);
9004 defsubr (&Sx_close_connection
);
9005 defsubr (&Sx_display_list
);
9006 defsubr (&Sx_synchronize
);
9008 /* W32 specific functions */
9010 defsubr (&Sw32_focus_frame
);
9011 defsubr (&Sw32_select_font
);
9012 defsubr (&Sw32_define_rgb_color
);
9013 defsubr (&Sw32_default_color_map
);
9014 defsubr (&Sw32_load_color_file
);
9015 defsubr (&Sw32_send_sys_command
);
9016 defsubr (&Sw32_shell_execute
);
9017 defsubr (&Sw32_register_hot_key
);
9018 defsubr (&Sw32_unregister_hot_key
);
9019 defsubr (&Sw32_registered_hot_keys
);
9020 defsubr (&Sw32_reconstruct_hot_key
);
9021 defsubr (&Sw32_toggle_lock_key
);
9022 defsubr (&Sw32_window_exists_p
);
9023 defsubr (&Sw32_find_bdf_fonts
);
9025 defsubr (&Sfile_system_info
);
9026 defsubr (&Sdefault_printer_name
);
9028 /* Setting callback functions for fontset handler. */
9029 get_font_info_func
= w32_get_font_info
;
9031 #if 0 /* This function pointer doesn't seem to be used anywhere.
9032 And the pointer assigned has the wrong type, anyway. */
9033 list_fonts_func
= w32_list_fonts
;
9036 load_font_func
= w32_load_font
;
9037 find_ccl_program_func
= w32_find_ccl_program
;
9038 query_font_func
= w32_query_font
;
9039 set_frame_fontset_func
= x_set_font
;
9040 check_window_system_func
= check_w32
;
9043 hourglass_atimer
= NULL
;
9044 hourglass_shown_p
= 0;
9045 defsubr (&Sx_show_tip
);
9046 defsubr (&Sx_hide_tip
);
9048 staticpro (&tip_timer
);
9050 staticpro (&tip_frame
);
9052 last_show_tip_args
= Qnil
;
9053 staticpro (&last_show_tip_args
);
9055 defsubr (&Sx_file_dialog
);
9060 globals_of_w32fns is used to initialize those global variables that
9061 must always be initialized on startup even when the global variable
9062 initialized is non zero (see the function main in emacs.c).
9063 globals_of_w32fns is called from syms_of_w32fns when the global
9064 variable initialized is 0 and directly from main when initialized
9067 void globals_of_w32fns ()
9069 HMODULE user32_lib
= GetModuleHandle ("user32.dll");
9071 TrackMouseEvent not available in all versions of Windows, so must load
9072 it dynamically. Do it once, here, instead of every time it is used.
9074 track_mouse_event_fn
= (TrackMouseEvent_Proc
)
9075 GetProcAddress (user32_lib
, "TrackMouseEvent");
9076 /* ditto for GetClipboardSequenceNumber. */
9077 clipboard_sequence_fn
= (ClipboardSequence_Proc
)
9078 GetProcAddress (user32_lib
, "GetClipboardSequenceNumber");
9080 DEFVAR_INT ("w32-ansi-code-page",
9081 &w32_ansi_code_page
,
9082 doc
: /* The ANSI code page used by the system. */);
9083 w32_ansi_code_page
= GetACP ();
9088 void w32_abort (void) NO_RETURN
;
9094 button
= MessageBox (NULL
,
9095 "A fatal error has occurred!\n\n"
9096 "Would you like to attach a debugger?\n\n"
9097 "Select YES to debug, NO to abort Emacs"
9099 "\n\n(type \"gdb -p <emacs-PID>\" and\n"
9100 "\"continue\" inside GDB before clicking YES.)"
9102 , "Emacs Abort Dialog",
9103 MB_ICONEXCLAMATION
| MB_TASKMODAL
9104 | MB_SETFOREGROUND
| MB_YESNO
);
9109 exit (2); /* tell the compiler we will never return */
9117 /* For convenience when debugging. */
9121 return GetLastError ();
9124 /* arch-tag: 707589ab-b9be-4638-8cdd-74629cc9b446
9125 (do not change this comment) */