1 /* Graphical user interface functions for the Microsoft W32 API.
2 Copyright (C) 1989, 92, 93, 94, 95, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* Added by Kevin Gallo */
36 #include "intervals.h"
37 #include "dispextern.h"
39 #include "blockinput.h"
41 #include "character.h"
47 #include "termhooks.h"
50 #include "bitmaps/gray.xbm"
58 #define FILE_NAME_TEXT_FIELD edt1
60 void syms_of_w32fns ();
61 void globals_of_w32fns ();
63 extern void free_frame_menubar ();
64 extern double atof ();
65 extern int w32_console_toggle_lock_key
P_ ((int, Lisp_Object
));
66 extern void w32_menu_display_help
P_ ((HWND
, HMENU
, UINT
, UINT
));
67 extern void w32_free_menu_strings
P_ ((HWND
));
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. */
92 Lisp_Object Vw32_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 Lisp_Object Vw32_mouse_button_tolerance
;
138 /* Minimum interval between mouse movement (and scroll bar drag)
139 events that are passed on to the event loop. */
140 Lisp_Object Vw32_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
, Vx_hand_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 /* Prefix for system colors. */
239 #define SYSTEM_COLOR_PREFIX "System"
240 #define SYSTEM_COLOR_PREFIX_LEN (sizeof (SYSTEM_COLOR_PREFIX) - 1)
242 /* State variables for emulating a three button mouse. */
247 static int button_state
= 0;
248 static W32Msg saved_mouse_button_msg
;
249 static unsigned mouse_button_timer
= 0; /* non-zero when timer is active */
250 static W32Msg saved_mouse_move_msg
;
251 static unsigned mouse_move_timer
= 0;
253 /* Window that is tracking the mouse. */
254 static HWND track_mouse_window
;
256 typedef BOOL (WINAPI
* TrackMouseEvent_Proc
)
257 (IN OUT LPTRACKMOUSEEVENT lpEventTrack
);
259 TrackMouseEvent_Proc track_mouse_event_fn
= NULL
;
260 ClipboardSequence_Proc clipboard_sequence_fn
= NULL
;
262 /* W95 mousewheel handler */
263 unsigned int msh_mousewheel
= 0;
266 #define MOUSE_BUTTON_ID 1
267 #define MOUSE_MOVE_ID 2
268 #define MENU_FREE_ID 3
269 /* The delay (milliseconds) before a menu is freed after WM_EXITMENULOOP
271 #define MENU_FREE_DELAY 1000
272 static unsigned menu_free_timer
= 0;
274 /* The below are defined in frame.c. */
276 extern Lisp_Object Vwindow_system_version
;
279 int image_cache_refcount
, dpyinfo_refcount
;
283 /* From w32term.c. */
284 extern Lisp_Object Vw32_num_mouse_buttons
;
285 extern Lisp_Object Vw32_recognize_altgr
;
287 extern HWND w32_system_caret_hwnd
;
289 extern int w32_system_caret_height
;
290 extern int w32_system_caret_x
;
291 extern int w32_system_caret_y
;
292 extern int w32_use_visible_system_caret
;
294 static HWND w32_visible_system_caret_hwnd
;
297 /* Error if we are not connected to MS-Windows. */
302 error ("MS-Windows not in use or not initialized");
305 /* Nonzero if we can use mouse menus.
306 You should not call this unless HAVE_MENUS is defined. */
314 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
315 and checking validity for W32. */
318 check_x_frame (frame
)
324 frame
= selected_frame
;
325 CHECK_LIVE_FRAME (frame
);
327 if (! FRAME_W32_P (f
))
328 error ("non-w32 frame used");
332 /* Let the user specify a display with a frame.
333 nil stands for the selected frame--or, if that is not a w32 frame,
334 the first display on the list. */
336 struct w32_display_info
*
337 check_x_display_info (frame
)
342 struct frame
*sf
= XFRAME (selected_frame
);
344 if (FRAME_W32_P (sf
) && FRAME_LIVE_P (sf
))
345 return FRAME_W32_DISPLAY_INFO (sf
);
347 return &one_w32_display_info
;
349 else if (STRINGP (frame
))
350 return x_display_info_for_name (frame
);
355 CHECK_LIVE_FRAME (frame
);
357 if (! FRAME_W32_P (f
))
358 error ("non-w32 frame used");
359 return FRAME_W32_DISPLAY_INFO (f
);
363 /* Return the Emacs frame-object corresponding to an w32 window.
364 It could be the frame's main window or an icon window. */
366 /* This function can be called during GC, so use GC_xxx type test macros. */
369 x_window_to_frame (dpyinfo
, wdesc
)
370 struct w32_display_info
*dpyinfo
;
373 Lisp_Object tail
, frame
;
376 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
379 if (!GC_FRAMEP (frame
))
382 if (!FRAME_W32_P (f
) || FRAME_W32_DISPLAY_INFO (f
) != dpyinfo
)
384 if (f
->output_data
.w32
->hourglass_window
== wdesc
)
387 if (FRAME_W32_WINDOW (f
) == wdesc
)
394 BOOL my_show_window
P_ ((struct frame
*, HWND
, int));
395 void my_set_window_pos
P_ ((HWND
, HWND
, int, int, int, int, UINT
));
396 static Lisp_Object unwind_create_frame
P_ ((Lisp_Object
));
397 static Lisp_Object unwind_create_tip_frame
P_ ((Lisp_Object
));
399 /* TODO: Native Input Method support; see x_create_im. */
400 void x_set_foreground_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
401 void x_set_background_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
402 void x_set_mouse_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
403 void x_set_cursor_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
404 void x_set_border_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
405 void x_set_cursor_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
406 void x_set_icon_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
407 void x_set_icon_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
408 void x_explicitly_set_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
409 void x_set_menu_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
410 void x_set_title
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
411 void x_set_tool_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
412 static void x_edge_detection
P_ ((struct frame
*, struct image
*, Lisp_Object
,
418 /* Store the screen positions of frame F into XPTR and YPTR.
419 These are the positions of the containing window manager window,
420 not Emacs's own window. */
423 x_real_positions (f
, xptr
, yptr
)
430 GetClientRect(FRAME_W32_WINDOW(f
), &rect
);
431 AdjustWindowRect(&rect
, f
->output_data
.w32
->dwStyle
, FRAME_EXTERNAL_MENU_BAR(f
));
436 ClientToScreen (FRAME_W32_WINDOW(f
), &pt
);
438 /* Remember x_pixels_diff and y_pixels_diff. */
439 f
->x_pixels_diff
= pt
.x
- rect
.left
;
440 f
->y_pixels_diff
= pt
.y
- rect
.top
;
448 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
,
449 Sw32_define_rgb_color
, 4, 4, 0,
450 doc
: /* Convert RGB numbers to a windows color reference and associate with NAME.
451 This adds or updates a named color to w32-color-map, making it
452 available for use. The original entry's RGB ref is returned, or nil
453 if the entry is new. */)
454 (red
, green
, blue
, name
)
455 Lisp_Object red
, green
, blue
, name
;
458 Lisp_Object oldrgb
= Qnil
;
462 CHECK_NUMBER (green
);
466 XSET (rgb
, Lisp_Int
, RGB(XUINT (red
), XUINT (green
), XUINT (blue
)));
470 /* replace existing entry in w32-color-map or add new entry. */
471 entry
= Fassoc (name
, Vw32_color_map
);
474 entry
= Fcons (name
, rgb
);
475 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
479 oldrgb
= Fcdr (entry
);
480 Fsetcdr (entry
, rgb
);
488 DEFUN ("w32-load-color-file", Fw32_load_color_file
,
489 Sw32_load_color_file
, 1, 1, 0,
490 doc
: /* Create an alist of color entries from an external file.
491 Assign this value to w32-color-map to replace the existing color map.
493 The file should define one named RGB color per line like so:
495 where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
497 Lisp_Object filename
;
500 Lisp_Object cmap
= Qnil
;
503 CHECK_STRING (filename
);
504 abspath
= Fexpand_file_name (filename
, Qnil
);
506 fp
= fopen (SDATA (filename
), "rt");
510 int red
, green
, blue
;
515 while (fgets (buf
, sizeof (buf
), fp
) != NULL
) {
516 if (sscanf (buf
, "%u %u %u %n", &red
, &green
, &blue
, &num
) == 3)
518 char *name
= buf
+ num
;
519 num
= strlen (name
) - 1;
520 if (name
[num
] == '\n')
522 cmap
= Fcons (Fcons (build_string (name
),
523 make_number (RGB (red
, green
, blue
))),
535 /* The default colors for the w32 color map */
536 typedef struct colormap_t
542 colormap_t w32_color_map
[] =
544 {"snow" , PALETTERGB (255,250,250)},
545 {"ghost white" , PALETTERGB (248,248,255)},
546 {"GhostWhite" , PALETTERGB (248,248,255)},
547 {"white smoke" , PALETTERGB (245,245,245)},
548 {"WhiteSmoke" , PALETTERGB (245,245,245)},
549 {"gainsboro" , PALETTERGB (220,220,220)},
550 {"floral white" , PALETTERGB (255,250,240)},
551 {"FloralWhite" , PALETTERGB (255,250,240)},
552 {"old lace" , PALETTERGB (253,245,230)},
553 {"OldLace" , PALETTERGB (253,245,230)},
554 {"linen" , PALETTERGB (250,240,230)},
555 {"antique white" , PALETTERGB (250,235,215)},
556 {"AntiqueWhite" , PALETTERGB (250,235,215)},
557 {"papaya whip" , PALETTERGB (255,239,213)},
558 {"PapayaWhip" , PALETTERGB (255,239,213)},
559 {"blanched almond" , PALETTERGB (255,235,205)},
560 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
561 {"bisque" , PALETTERGB (255,228,196)},
562 {"peach puff" , PALETTERGB (255,218,185)},
563 {"PeachPuff" , PALETTERGB (255,218,185)},
564 {"navajo white" , PALETTERGB (255,222,173)},
565 {"NavajoWhite" , PALETTERGB (255,222,173)},
566 {"moccasin" , PALETTERGB (255,228,181)},
567 {"cornsilk" , PALETTERGB (255,248,220)},
568 {"ivory" , PALETTERGB (255,255,240)},
569 {"lemon chiffon" , PALETTERGB (255,250,205)},
570 {"LemonChiffon" , PALETTERGB (255,250,205)},
571 {"seashell" , PALETTERGB (255,245,238)},
572 {"honeydew" , PALETTERGB (240,255,240)},
573 {"mint cream" , PALETTERGB (245,255,250)},
574 {"MintCream" , PALETTERGB (245,255,250)},
575 {"azure" , PALETTERGB (240,255,255)},
576 {"alice blue" , PALETTERGB (240,248,255)},
577 {"AliceBlue" , PALETTERGB (240,248,255)},
578 {"lavender" , PALETTERGB (230,230,250)},
579 {"lavender blush" , PALETTERGB (255,240,245)},
580 {"LavenderBlush" , PALETTERGB (255,240,245)},
581 {"misty rose" , PALETTERGB (255,228,225)},
582 {"MistyRose" , PALETTERGB (255,228,225)},
583 {"white" , PALETTERGB (255,255,255)},
584 {"black" , PALETTERGB ( 0, 0, 0)},
585 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
586 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
587 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
588 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
589 {"dim gray" , PALETTERGB (105,105,105)},
590 {"DimGray" , PALETTERGB (105,105,105)},
591 {"dim grey" , PALETTERGB (105,105,105)},
592 {"DimGrey" , PALETTERGB (105,105,105)},
593 {"slate gray" , PALETTERGB (112,128,144)},
594 {"SlateGray" , PALETTERGB (112,128,144)},
595 {"slate grey" , PALETTERGB (112,128,144)},
596 {"SlateGrey" , PALETTERGB (112,128,144)},
597 {"light slate gray" , PALETTERGB (119,136,153)},
598 {"LightSlateGray" , PALETTERGB (119,136,153)},
599 {"light slate grey" , PALETTERGB (119,136,153)},
600 {"LightSlateGrey" , PALETTERGB (119,136,153)},
601 {"gray" , PALETTERGB (190,190,190)},
602 {"grey" , PALETTERGB (190,190,190)},
603 {"light grey" , PALETTERGB (211,211,211)},
604 {"LightGrey" , PALETTERGB (211,211,211)},
605 {"light gray" , PALETTERGB (211,211,211)},
606 {"LightGray" , PALETTERGB (211,211,211)},
607 {"midnight blue" , PALETTERGB ( 25, 25,112)},
608 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
609 {"navy" , PALETTERGB ( 0, 0,128)},
610 {"navy blue" , PALETTERGB ( 0, 0,128)},
611 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
612 {"cornflower blue" , PALETTERGB (100,149,237)},
613 {"CornflowerBlue" , PALETTERGB (100,149,237)},
614 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
615 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
616 {"slate blue" , PALETTERGB (106, 90,205)},
617 {"SlateBlue" , PALETTERGB (106, 90,205)},
618 {"medium slate blue" , PALETTERGB (123,104,238)},
619 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
620 {"light slate blue" , PALETTERGB (132,112,255)},
621 {"LightSlateBlue" , PALETTERGB (132,112,255)},
622 {"medium blue" , PALETTERGB ( 0, 0,205)},
623 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
624 {"royal blue" , PALETTERGB ( 65,105,225)},
625 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
626 {"blue" , PALETTERGB ( 0, 0,255)},
627 {"dodger blue" , PALETTERGB ( 30,144,255)},
628 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
629 {"deep sky blue" , PALETTERGB ( 0,191,255)},
630 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
631 {"sky blue" , PALETTERGB (135,206,235)},
632 {"SkyBlue" , PALETTERGB (135,206,235)},
633 {"light sky blue" , PALETTERGB (135,206,250)},
634 {"LightSkyBlue" , PALETTERGB (135,206,250)},
635 {"steel blue" , PALETTERGB ( 70,130,180)},
636 {"SteelBlue" , PALETTERGB ( 70,130,180)},
637 {"light steel blue" , PALETTERGB (176,196,222)},
638 {"LightSteelBlue" , PALETTERGB (176,196,222)},
639 {"light blue" , PALETTERGB (173,216,230)},
640 {"LightBlue" , PALETTERGB (173,216,230)},
641 {"powder blue" , PALETTERGB (176,224,230)},
642 {"PowderBlue" , PALETTERGB (176,224,230)},
643 {"pale turquoise" , PALETTERGB (175,238,238)},
644 {"PaleTurquoise" , PALETTERGB (175,238,238)},
645 {"dark turquoise" , PALETTERGB ( 0,206,209)},
646 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
647 {"medium turquoise" , PALETTERGB ( 72,209,204)},
648 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
649 {"turquoise" , PALETTERGB ( 64,224,208)},
650 {"cyan" , PALETTERGB ( 0,255,255)},
651 {"light cyan" , PALETTERGB (224,255,255)},
652 {"LightCyan" , PALETTERGB (224,255,255)},
653 {"cadet blue" , PALETTERGB ( 95,158,160)},
654 {"CadetBlue" , PALETTERGB ( 95,158,160)},
655 {"medium aquamarine" , PALETTERGB (102,205,170)},
656 {"MediumAquamarine" , PALETTERGB (102,205,170)},
657 {"aquamarine" , PALETTERGB (127,255,212)},
658 {"dark green" , PALETTERGB ( 0,100, 0)},
659 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
660 {"dark olive green" , PALETTERGB ( 85,107, 47)},
661 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
662 {"dark sea green" , PALETTERGB (143,188,143)},
663 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
664 {"sea green" , PALETTERGB ( 46,139, 87)},
665 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
666 {"medium sea green" , PALETTERGB ( 60,179,113)},
667 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
668 {"light sea green" , PALETTERGB ( 32,178,170)},
669 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
670 {"pale green" , PALETTERGB (152,251,152)},
671 {"PaleGreen" , PALETTERGB (152,251,152)},
672 {"spring green" , PALETTERGB ( 0,255,127)},
673 {"SpringGreen" , PALETTERGB ( 0,255,127)},
674 {"lawn green" , PALETTERGB (124,252, 0)},
675 {"LawnGreen" , PALETTERGB (124,252, 0)},
676 {"green" , PALETTERGB ( 0,255, 0)},
677 {"chartreuse" , PALETTERGB (127,255, 0)},
678 {"medium spring green" , PALETTERGB ( 0,250,154)},
679 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
680 {"green yellow" , PALETTERGB (173,255, 47)},
681 {"GreenYellow" , PALETTERGB (173,255, 47)},
682 {"lime green" , PALETTERGB ( 50,205, 50)},
683 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
684 {"yellow green" , PALETTERGB (154,205, 50)},
685 {"YellowGreen" , PALETTERGB (154,205, 50)},
686 {"forest green" , PALETTERGB ( 34,139, 34)},
687 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
688 {"olive drab" , PALETTERGB (107,142, 35)},
689 {"OliveDrab" , PALETTERGB (107,142, 35)},
690 {"dark khaki" , PALETTERGB (189,183,107)},
691 {"DarkKhaki" , PALETTERGB (189,183,107)},
692 {"khaki" , PALETTERGB (240,230,140)},
693 {"pale goldenrod" , PALETTERGB (238,232,170)},
694 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
695 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
696 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
697 {"light yellow" , PALETTERGB (255,255,224)},
698 {"LightYellow" , PALETTERGB (255,255,224)},
699 {"yellow" , PALETTERGB (255,255, 0)},
700 {"gold" , PALETTERGB (255,215, 0)},
701 {"light goldenrod" , PALETTERGB (238,221,130)},
702 {"LightGoldenrod" , PALETTERGB (238,221,130)},
703 {"goldenrod" , PALETTERGB (218,165, 32)},
704 {"dark goldenrod" , PALETTERGB (184,134, 11)},
705 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
706 {"rosy brown" , PALETTERGB (188,143,143)},
707 {"RosyBrown" , PALETTERGB (188,143,143)},
708 {"indian red" , PALETTERGB (205, 92, 92)},
709 {"IndianRed" , PALETTERGB (205, 92, 92)},
710 {"saddle brown" , PALETTERGB (139, 69, 19)},
711 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
712 {"sienna" , PALETTERGB (160, 82, 45)},
713 {"peru" , PALETTERGB (205,133, 63)},
714 {"burlywood" , PALETTERGB (222,184,135)},
715 {"beige" , PALETTERGB (245,245,220)},
716 {"wheat" , PALETTERGB (245,222,179)},
717 {"sandy brown" , PALETTERGB (244,164, 96)},
718 {"SandyBrown" , PALETTERGB (244,164, 96)},
719 {"tan" , PALETTERGB (210,180,140)},
720 {"chocolate" , PALETTERGB (210,105, 30)},
721 {"firebrick" , PALETTERGB (178,34, 34)},
722 {"brown" , PALETTERGB (165,42, 42)},
723 {"dark salmon" , PALETTERGB (233,150,122)},
724 {"DarkSalmon" , PALETTERGB (233,150,122)},
725 {"salmon" , PALETTERGB (250,128,114)},
726 {"light salmon" , PALETTERGB (255,160,122)},
727 {"LightSalmon" , PALETTERGB (255,160,122)},
728 {"orange" , PALETTERGB (255,165, 0)},
729 {"dark orange" , PALETTERGB (255,140, 0)},
730 {"DarkOrange" , PALETTERGB (255,140, 0)},
731 {"coral" , PALETTERGB (255,127, 80)},
732 {"light coral" , PALETTERGB (240,128,128)},
733 {"LightCoral" , PALETTERGB (240,128,128)},
734 {"tomato" , PALETTERGB (255, 99, 71)},
735 {"orange red" , PALETTERGB (255, 69, 0)},
736 {"OrangeRed" , PALETTERGB (255, 69, 0)},
737 {"red" , PALETTERGB (255, 0, 0)},
738 {"hot pink" , PALETTERGB (255,105,180)},
739 {"HotPink" , PALETTERGB (255,105,180)},
740 {"deep pink" , PALETTERGB (255, 20,147)},
741 {"DeepPink" , PALETTERGB (255, 20,147)},
742 {"pink" , PALETTERGB (255,192,203)},
743 {"light pink" , PALETTERGB (255,182,193)},
744 {"LightPink" , PALETTERGB (255,182,193)},
745 {"pale violet red" , PALETTERGB (219,112,147)},
746 {"PaleVioletRed" , PALETTERGB (219,112,147)},
747 {"maroon" , PALETTERGB (176, 48, 96)},
748 {"medium violet red" , PALETTERGB (199, 21,133)},
749 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
750 {"violet red" , PALETTERGB (208, 32,144)},
751 {"VioletRed" , PALETTERGB (208, 32,144)},
752 {"magenta" , PALETTERGB (255, 0,255)},
753 {"violet" , PALETTERGB (238,130,238)},
754 {"plum" , PALETTERGB (221,160,221)},
755 {"orchid" , PALETTERGB (218,112,214)},
756 {"medium orchid" , PALETTERGB (186, 85,211)},
757 {"MediumOrchid" , PALETTERGB (186, 85,211)},
758 {"dark orchid" , PALETTERGB (153, 50,204)},
759 {"DarkOrchid" , PALETTERGB (153, 50,204)},
760 {"dark violet" , PALETTERGB (148, 0,211)},
761 {"DarkViolet" , PALETTERGB (148, 0,211)},
762 {"blue violet" , PALETTERGB (138, 43,226)},
763 {"BlueViolet" , PALETTERGB (138, 43,226)},
764 {"purple" , PALETTERGB (160, 32,240)},
765 {"medium purple" , PALETTERGB (147,112,219)},
766 {"MediumPurple" , PALETTERGB (147,112,219)},
767 {"thistle" , PALETTERGB (216,191,216)},
768 {"gray0" , PALETTERGB ( 0, 0, 0)},
769 {"grey0" , PALETTERGB ( 0, 0, 0)},
770 {"dark grey" , PALETTERGB (169,169,169)},
771 {"DarkGrey" , PALETTERGB (169,169,169)},
772 {"dark gray" , PALETTERGB (169,169,169)},
773 {"DarkGray" , PALETTERGB (169,169,169)},
774 {"dark blue" , PALETTERGB ( 0, 0,139)},
775 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
776 {"dark cyan" , PALETTERGB ( 0,139,139)},
777 {"DarkCyan" , PALETTERGB ( 0,139,139)},
778 {"dark magenta" , PALETTERGB (139, 0,139)},
779 {"DarkMagenta" , PALETTERGB (139, 0,139)},
780 {"dark red" , PALETTERGB (139, 0, 0)},
781 {"DarkRed" , PALETTERGB (139, 0, 0)},
782 {"light green" , PALETTERGB (144,238,144)},
783 {"LightGreen" , PALETTERGB (144,238,144)},
786 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
787 0, 0, 0, doc
: /* Return the default color map. */)
791 colormap_t
*pc
= w32_color_map
;
798 for (i
= 0; i
< sizeof (w32_color_map
) / sizeof (w32_color_map
[0]);
800 cmap
= Fcons (Fcons (build_string (pc
->name
),
801 make_number (pc
->colorref
)),
819 color
= Frassq (rgb
, Vw32_color_map
);
824 return (Fcar (color
));
830 w32_color_map_lookup (colorname
)
833 Lisp_Object tail
, ret
= Qnil
;
837 for (tail
= Vw32_color_map
; !NILP (tail
); tail
= Fcdr (tail
))
839 register Lisp_Object elt
, tem
;
842 if (!CONSP (elt
)) continue;
846 if (lstrcmpi (SDATA (tem
), colorname
) == 0)
848 ret
= XUINT (Fcdr (elt
));
863 add_system_logical_colors_to_map (system_colors
)
864 Lisp_Object
*system_colors
;
868 /* Other registry operations are done with input blocked. */
871 /* Look for "Control Panel/Colors" under User and Machine registry
873 if (RegOpenKeyEx (HKEY_CURRENT_USER
, "Control Panel\\Colors", 0,
874 KEY_READ
, &colors_key
) == ERROR_SUCCESS
875 || RegOpenKeyEx (HKEY_LOCAL_MACHINE
, "Control Panel\\Colors", 0,
876 KEY_READ
, &colors_key
) == ERROR_SUCCESS
)
879 char color_buffer
[64];
880 char full_name_buffer
[MAX_PATH
+ SYSTEM_COLOR_PREFIX_LEN
];
882 DWORD name_size
, color_size
;
883 char *name_buffer
= full_name_buffer
+ SYSTEM_COLOR_PREFIX_LEN
;
885 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
886 color_size
= sizeof (color_buffer
);
888 strcpy (full_name_buffer
, SYSTEM_COLOR_PREFIX
);
890 while (RegEnumValueA (colors_key
, index
, name_buffer
, &name_size
,
891 NULL
, NULL
, color_buffer
, &color_size
)
895 if (sscanf (color_buffer
, " %u %u %u", &r
, &g
, &b
) == 3)
896 *system_colors
= Fcons (Fcons (build_string (full_name_buffer
),
897 make_number (RGB (r
, g
, b
))),
900 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
901 color_size
= sizeof (color_buffer
);
904 RegCloseKey (colors_key
);
912 x_to_w32_color (colorname
)
915 register Lisp_Object ret
= Qnil
;
919 if (colorname
[0] == '#')
921 /* Could be an old-style RGB Device specification. */
924 color
= colorname
+ 1;
926 size
= strlen(color
);
927 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
935 for (i
= 0; i
< 3; i
++)
941 /* The check for 'x' in the following conditional takes into
942 account the fact that strtol allows a "0x" in front of
943 our numbers, and we don't. */
944 if (!isxdigit(color
[0]) || color
[1] == 'x')
948 value
= strtoul(color
, &end
, 16);
950 if (errno
== ERANGE
|| end
- color
!= size
)
955 value
= value
* 0x10;
966 colorval
|= (value
<< pos
);
977 else if (strnicmp(colorname
, "rgb:", 4) == 0)
985 color
= colorname
+ 4;
986 for (i
= 0; i
< 3; i
++)
991 /* The check for 'x' in the following conditional takes into
992 account the fact that strtol allows a "0x" in front of
993 our numbers, and we don't. */
994 if (!isxdigit(color
[0]) || color
[1] == 'x')
996 value
= strtoul(color
, &end
, 16);
1002 value
= value
* 0x10 + value
;
1015 if (value
== ULONG_MAX
)
1017 colorval
|= (value
<< pos
);
1031 else if (strnicmp(colorname
, "rgbi:", 5) == 0)
1033 /* This is an RGB Intensity specification. */
1040 color
= colorname
+ 5;
1041 for (i
= 0; i
< 3; i
++)
1047 value
= strtod(color
, &end
);
1048 if (errno
== ERANGE
)
1050 if (value
< 0.0 || value
> 1.0)
1052 val
= (UINT
)(0x100 * value
);
1053 /* We used 0x100 instead of 0xFF to give a continuous
1054 range between 0.0 and 1.0 inclusive. The next statement
1055 fixes the 1.0 case. */
1058 colorval
|= (val
<< pos
);
1072 /* I am not going to attempt to handle any of the CIE color schemes
1073 or TekHVC, since I don't know the algorithms for conversion to
1076 /* If we fail to lookup the color name in w32_color_map, then check the
1077 colorname to see if it can be crudely approximated: If the X color
1078 ends in a number (e.g., "darkseagreen2"), strip the number and
1079 return the result of looking up the base color name. */
1080 ret
= w32_color_map_lookup (colorname
);
1083 int len
= strlen (colorname
);
1085 if (isdigit (colorname
[len
- 1]))
1087 char *ptr
, *approx
= alloca (len
+ 1);
1089 strcpy (approx
, colorname
);
1090 ptr
= &approx
[len
- 1];
1091 while (ptr
> approx
&& isdigit (*ptr
))
1094 ret
= w32_color_map_lookup (approx
);
1103 w32_regenerate_palette (FRAME_PTR f
)
1105 struct w32_palette_entry
* list
;
1106 LOGPALETTE
* log_palette
;
1107 HPALETTE new_palette
;
1110 /* don't bother trying to create palette if not supported */
1111 if (! FRAME_W32_DISPLAY_INFO (f
)->has_palette
)
1114 log_palette
= (LOGPALETTE
*)
1115 alloca (sizeof (LOGPALETTE
) +
1116 FRAME_W32_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
1117 log_palette
->palVersion
= 0x300;
1118 log_palette
->palNumEntries
= FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1120 list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1122 i
< FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1123 i
++, list
= list
->next
)
1124 log_palette
->palPalEntry
[i
] = list
->entry
;
1126 new_palette
= CreatePalette (log_palette
);
1130 if (FRAME_W32_DISPLAY_INFO (f
)->palette
)
1131 DeleteObject (FRAME_W32_DISPLAY_INFO (f
)->palette
);
1132 FRAME_W32_DISPLAY_INFO (f
)->palette
= new_palette
;
1134 /* Realize display palette and garbage all frames. */
1135 release_frame_dc (f
, get_frame_dc (f
));
1140 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
1141 #define SET_W32_COLOR(pe, color) \
1144 pe.peRed = GetRValue (color); \
1145 pe.peGreen = GetGValue (color); \
1146 pe.peBlue = GetBValue (color); \
1151 /* Keep these around in case we ever want to track color usage. */
1153 w32_map_color (FRAME_PTR f
, COLORREF color
)
1155 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1157 if (NILP (Vw32_enable_palette
))
1160 /* check if color is already mapped */
1163 if (W32_COLOR (list
->entry
) == color
)
1171 /* not already mapped, so add to list and recreate Windows palette */
1172 list
= (struct w32_palette_entry
*)
1173 xmalloc (sizeof (struct w32_palette_entry
));
1174 SET_W32_COLOR (list
->entry
, color
);
1176 list
->next
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1177 FRAME_W32_DISPLAY_INFO (f
)->color_list
= list
;
1178 FRAME_W32_DISPLAY_INFO (f
)->num_colors
++;
1180 /* set flag that palette must be regenerated */
1181 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1185 w32_unmap_color (FRAME_PTR f
, COLORREF color
)
1187 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1188 struct w32_palette_entry
**prev
= &FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1190 if (NILP (Vw32_enable_palette
))
1193 /* check if color is already mapped */
1196 if (W32_COLOR (list
->entry
) == color
)
1198 if (--list
->refcount
== 0)
1202 FRAME_W32_DISPLAY_INFO (f
)->num_colors
--;
1212 /* set flag that palette must be regenerated */
1213 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1218 /* Gamma-correct COLOR on frame F. */
1221 gamma_correct (f
, color
)
1227 *color
= PALETTERGB (
1228 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1229 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1230 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1235 /* Decide if color named COLOR is valid for the display associated with
1236 the selected frame; if so, return the rgb values in COLOR_DEF.
1237 If ALLOC is nonzero, allocate a new colormap cell. */
1240 w32_defined_color (f
, color
, color_def
, alloc
)
1246 register Lisp_Object tem
;
1247 COLORREF w32_color_ref
;
1249 tem
= x_to_w32_color (color
);
1255 /* Apply gamma correction. */
1256 w32_color_ref
= XUINT (tem
);
1257 gamma_correct (f
, &w32_color_ref
);
1258 XSETINT (tem
, w32_color_ref
);
1261 /* Map this color to the palette if it is enabled. */
1262 if (!NILP (Vw32_enable_palette
))
1264 struct w32_palette_entry
* entry
=
1265 one_w32_display_info
.color_list
;
1266 struct w32_palette_entry
** prev
=
1267 &one_w32_display_info
.color_list
;
1269 /* check if color is already mapped */
1272 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1274 prev
= &entry
->next
;
1275 entry
= entry
->next
;
1278 if (entry
== NULL
&& alloc
)
1280 /* not already mapped, so add to list */
1281 entry
= (struct w32_palette_entry
*)
1282 xmalloc (sizeof (struct w32_palette_entry
));
1283 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1286 one_w32_display_info
.num_colors
++;
1288 /* set flag that palette must be regenerated */
1289 one_w32_display_info
.regen_palette
= TRUE
;
1292 /* Ensure COLORREF value is snapped to nearest color in (default)
1293 palette by simulating the PALETTERGB macro. This works whether
1294 or not the display device has a palette. */
1295 w32_color_ref
= XUINT (tem
) | 0x2000000;
1297 color_def
->pixel
= w32_color_ref
;
1298 color_def
->red
= GetRValue (w32_color_ref
) * 256;
1299 color_def
->green
= GetGValue (w32_color_ref
) * 256;
1300 color_def
->blue
= GetBValue (w32_color_ref
) * 256;
1310 /* Given a string ARG naming a color, compute a pixel value from it
1311 suitable for screen F.
1312 If F is not a color screen, return DEF (default) regardless of what
1316 x_decode_color (f
, arg
, def
)
1325 if (strcmp (SDATA (arg
), "black") == 0)
1326 return BLACK_PIX_DEFAULT (f
);
1327 else if (strcmp (SDATA (arg
), "white") == 0)
1328 return WHITE_PIX_DEFAULT (f
);
1330 if ((FRAME_W32_DISPLAY_INFO (f
)->n_planes
* FRAME_W32_DISPLAY_INFO (f
)->n_cbits
) == 1)
1333 /* w32_defined_color is responsible for coping with failures
1334 by looking for a near-miss. */
1335 if (w32_defined_color (f
, SDATA (arg
), &cdef
, 1))
1338 /* defined_color failed; return an ultimate default. */
1344 /* Functions called only from `x_set_frame_param'
1345 to set individual parameters.
1347 If FRAME_W32_WINDOW (f) is 0,
1348 the frame is being created and its window does not exist yet.
1349 In that case, just record the parameter's new value
1350 in the standard place; do not attempt to change the window. */
1353 x_set_foreground_color (f
, arg
, oldval
)
1355 Lisp_Object arg
, oldval
;
1357 struct w32_output
*x
= f
->output_data
.w32
;
1358 PIX_TYPE fg
, old_fg
;
1360 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1361 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
1362 FRAME_FOREGROUND_PIXEL (f
) = fg
;
1364 if (FRAME_W32_WINDOW (f
) != 0)
1366 if (x
->cursor_pixel
== old_fg
)
1367 x
->cursor_pixel
= fg
;
1369 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
1370 if (FRAME_VISIBLE_P (f
))
1376 x_set_background_color (f
, arg
, oldval
)
1378 Lisp_Object arg
, oldval
;
1380 FRAME_BACKGROUND_PIXEL (f
)
1381 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
1383 if (FRAME_W32_WINDOW (f
) != 0)
1385 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
1386 FRAME_BACKGROUND_PIXEL (f
));
1388 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
1390 if (FRAME_VISIBLE_P (f
))
1396 x_set_mouse_color (f
, arg
, oldval
)
1398 Lisp_Object arg
, oldval
;
1400 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
1404 if (!EQ (Qnil
, arg
))
1405 f
->output_data
.w32
->mouse_pixel
1406 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1407 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
1409 /* Don't let pointers be invisible. */
1410 if (mask_color
== f
->output_data
.w32
->mouse_pixel
1411 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
1412 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
1414 #if 0 /* TODO : cursor changes */
1417 /* It's not okay to crash if the user selects a screwy cursor. */
1418 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
1420 if (!EQ (Qnil
, Vx_pointer_shape
))
1422 CHECK_NUMBER (Vx_pointer_shape
);
1423 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
1426 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1427 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
1429 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
1431 CHECK_NUMBER (Vx_nontext_pointer_shape
);
1432 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1433 XINT (Vx_nontext_pointer_shape
));
1436 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
1437 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1439 if (!EQ (Qnil
, Vx_hourglass_pointer_shape
))
1441 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
1442 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1443 XINT (Vx_hourglass_pointer_shape
));
1446 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
1447 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
1449 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1450 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
1452 CHECK_NUMBER (Vx_mode_pointer_shape
);
1453 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1454 XINT (Vx_mode_pointer_shape
));
1457 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1458 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
1460 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
1462 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
1464 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1465 XINT (Vx_sensitive_text_pointer_shape
));
1468 hand_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
1470 if (!NILP (Vx_window_horizontal_drag_shape
))
1472 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
1473 horizontal_drag_cursor
1474 = XCreateFontCursor (FRAME_X_DISPLAY (f
),
1475 XINT (Vx_window_horizontal_drag_shape
));
1478 horizontal_drag_cursor
1479 = XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_sb_h_double_arrow
);
1481 /* Check and report errors with the above calls. */
1482 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
1483 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
1486 XColor fore_color
, back_color
;
1488 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
1489 back_color
.pixel
= mask_color
;
1490 XQueryColor (FRAME_W32_DISPLAY (f
),
1491 DefaultColormap (FRAME_W32_DISPLAY (f
),
1492 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1494 XQueryColor (FRAME_W32_DISPLAY (f
),
1495 DefaultColormap (FRAME_W32_DISPLAY (f
),
1496 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1498 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
1499 &fore_color
, &back_color
);
1500 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
1501 &fore_color
, &back_color
);
1502 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
1503 &fore_color
, &back_color
);
1504 XRecolorCursor (FRAME_W32_DISPLAY (f
), hand_cursor
,
1505 &fore_color
, &back_color
);
1506 XRecolorCursor (FRAME_W32_DISPLAY (f
), hourglass_cursor
,
1507 &fore_color
, &back_color
);
1510 if (FRAME_W32_WINDOW (f
) != 0)
1511 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
1513 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
1514 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
1515 f
->output_data
.w32
->text_cursor
= cursor
;
1517 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
1518 && f
->output_data
.w32
->nontext_cursor
!= 0)
1519 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
1520 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
1522 if (hourglass_cursor
!= f
->output_data
.w32
->hourglass_cursor
1523 && f
->output_data
.w32
->hourglass_cursor
!= 0)
1524 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hourglass_cursor
);
1525 f
->output_data
.w32
->hourglass_cursor
= hourglass_cursor
;
1527 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
1528 && f
->output_data
.w32
->modeline_cursor
!= 0)
1529 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
1530 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
1532 if (hand_cursor
!= f
->output_data
.w32
->hand_cursor
1533 && f
->output_data
.w32
->hand_cursor
!= 0)
1534 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hand_cursor
);
1535 f
->output_data
.w32
->hand_cursor
= hand_cursor
;
1537 XFlush (FRAME_W32_DISPLAY (f
));
1540 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1544 /* Defined in w32term.c. */
1546 x_set_cursor_color (f
, arg
, oldval
)
1548 Lisp_Object arg
, oldval
;
1550 unsigned long fore_pixel
, pixel
;
1552 if (!NILP (Vx_cursor_fore_pixel
))
1553 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1554 WHITE_PIX_DEFAULT (f
));
1556 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1558 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1560 /* Make sure that the cursor color differs from the background color. */
1561 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
1563 pixel
= f
->output_data
.w32
->mouse_pixel
;
1564 if (pixel
== fore_pixel
)
1565 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1568 f
->output_data
.w32
->cursor_foreground_pixel
= fore_pixel
;
1569 f
->output_data
.w32
->cursor_pixel
= pixel
;
1571 if (FRAME_W32_WINDOW (f
) != 0)
1574 /* Update frame's cursor_gc. */
1575 f
->output_data
.w32
->cursor_gc
->foreground
= fore_pixel
;
1576 f
->output_data
.w32
->cursor_gc
->background
= pixel
;
1580 if (FRAME_VISIBLE_P (f
))
1582 x_update_cursor (f
, 0);
1583 x_update_cursor (f
, 1);
1587 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1590 /* Set the border-color of frame F to pixel value PIX.
1591 Note that this does not fully take effect if done before
1595 x_set_border_pixel (f
, pix
)
1600 f
->output_data
.w32
->border_pixel
= pix
;
1602 if (FRAME_W32_WINDOW (f
) != 0 && f
->border_width
> 0)
1604 if (FRAME_VISIBLE_P (f
))
1609 /* Set the border-color of frame F to value described by ARG.
1610 ARG can be a string naming a color.
1611 The border-color is used for the border that is drawn by the server.
1612 Note that this does not fully take effect if done before
1613 F has a window; it must be redone when the window is created. */
1616 x_set_border_color (f
, arg
, oldval
)
1618 Lisp_Object arg
, oldval
;
1623 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1624 x_set_border_pixel (f
, pix
);
1625 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1630 x_set_cursor_type (f
, arg
, oldval
)
1632 Lisp_Object arg
, oldval
;
1634 set_frame_cursor_types (f
, arg
);
1636 /* Make sure the cursor gets redrawn. */
1637 cursor_type_changed
= 1;
1641 x_set_icon_type (f
, arg
, oldval
)
1643 Lisp_Object arg
, oldval
;
1647 if (NILP (arg
) && NILP (oldval
))
1650 if (STRINGP (arg
) && STRINGP (oldval
)
1651 && EQ (Fstring_equal (oldval
, arg
), Qt
))
1654 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
1659 result
= x_bitmap_icon (f
, arg
);
1663 error ("No icon window available");
1670 x_set_icon_name (f
, arg
, oldval
)
1672 Lisp_Object arg
, oldval
;
1676 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1679 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
1685 if (f
->output_data
.w32
->icon_bitmap
!= 0)
1690 result
= x_text_icon (f
,
1691 (char *) SDATA ((!NILP (f
->icon_name
)
1700 error ("No icon window available");
1703 /* If the window was unmapped (and its icon was mapped),
1704 the new icon is not mapped, so map the window in its stead. */
1705 if (FRAME_VISIBLE_P (f
))
1707 #ifdef USE_X_TOOLKIT
1708 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
1710 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
1713 XFlush (FRAME_W32_DISPLAY (f
));
1720 x_set_menu_bar_lines (f
, value
, oldval
)
1722 Lisp_Object value
, oldval
;
1725 int olines
= FRAME_MENU_BAR_LINES (f
);
1727 /* Right now, menu bars don't work properly in minibuf-only frames;
1728 most of the commands try to apply themselves to the minibuffer
1729 frame itself, and get an error because you can't switch buffers
1730 in or split the minibuffer window. */
1731 if (FRAME_MINIBUF_ONLY_P (f
))
1734 if (INTEGERP (value
))
1735 nlines
= XINT (value
);
1739 FRAME_MENU_BAR_LINES (f
) = 0;
1741 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1744 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1745 free_frame_menubar (f
);
1746 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1748 /* Adjust the frame size so that the client (text) dimensions
1749 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
1751 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
1752 do_pending_window_change (0);
1758 /* Set the number of lines used for the tool bar of frame F to VALUE.
1759 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1760 is the old number of tool bar lines. This function changes the
1761 height of all windows on frame F to match the new tool bar height.
1762 The frame's height doesn't change. */
1765 x_set_tool_bar_lines (f
, value
, oldval
)
1767 Lisp_Object value
, oldval
;
1769 int delta
, nlines
, root_height
;
1770 Lisp_Object root_window
;
1772 /* Treat tool bars like menu bars. */
1773 if (FRAME_MINIBUF_ONLY_P (f
))
1776 /* Use VALUE only if an integer >= 0. */
1777 if (INTEGERP (value
) && XINT (value
) >= 0)
1778 nlines
= XFASTINT (value
);
1782 /* Make sure we redisplay all windows in this frame. */
1783 ++windows_or_buffers_changed
;
1785 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
1787 /* Don't resize the tool-bar to more than we have room for. */
1788 root_window
= FRAME_ROOT_WINDOW (f
);
1789 root_height
= WINDOW_TOTAL_LINES (XWINDOW (root_window
));
1790 if (root_height
- delta
< 1)
1792 delta
= root_height
- 1;
1793 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
1796 FRAME_TOOL_BAR_LINES (f
) = nlines
;
1797 change_window_heights (root_window
, delta
);
1800 /* We also have to make sure that the internal border at the top of
1801 the frame, below the menu bar or tool bar, is redrawn when the
1802 tool bar disappears. This is so because the internal border is
1803 below the tool bar if one is displayed, but is below the menu bar
1804 if there isn't a tool bar. The tool bar draws into the area
1805 below the menu bar. */
1806 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
1810 clear_current_matrices (f
);
1811 updating_frame
= NULL
;
1814 /* If the tool bar gets smaller, the internal border below it
1815 has to be cleared. It was formerly part of the display
1816 of the larger tool bar, and updating windows won't clear it. */
1819 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1820 int width
= FRAME_PIXEL_WIDTH (f
);
1821 int y
= nlines
* FRAME_LINE_HEIGHT (f
);
1825 HDC hdc
= get_frame_dc (f
);
1826 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
1827 release_frame_dc (f
, hdc
);
1831 if (WINDOWP (f
->tool_bar_window
))
1832 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1837 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1840 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1841 name; if NAME is a string, set F's name to NAME and set
1842 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1844 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1845 suggesting a new name, which lisp code should override; if
1846 F->explicit_name is set, ignore the new name; otherwise, set it. */
1849 x_set_name (f
, name
, explicit)
1854 /* Make sure that requests from lisp code override requests from
1855 Emacs redisplay code. */
1858 /* If we're switching from explicit to implicit, we had better
1859 update the mode lines and thereby update the title. */
1860 if (f
->explicit_name
&& NILP (name
))
1861 update_mode_lines
= 1;
1863 f
->explicit_name
= ! NILP (name
);
1865 else if (f
->explicit_name
)
1868 /* If NAME is nil, set the name to the w32_id_name. */
1871 /* Check for no change needed in this very common case
1872 before we do any consing. */
1873 if (!strcmp (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
,
1876 name
= build_string (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
);
1879 CHECK_STRING (name
);
1881 /* Don't change the name if it's already NAME. */
1882 if (! NILP (Fstring_equal (name
, f
->name
)))
1887 /* For setting the frame title, the title parameter should override
1888 the name parameter. */
1889 if (! NILP (f
->title
))
1892 if (FRAME_W32_WINDOW (f
))
1894 if (STRING_MULTIBYTE (name
))
1895 name
= ENCODE_SYSTEM (name
);
1898 SetWindowText(FRAME_W32_WINDOW (f
), SDATA (name
));
1903 /* This function should be called when the user's lisp code has
1904 specified a name for the frame; the name will override any set by the
1907 x_explicitly_set_name (f
, arg
, oldval
)
1909 Lisp_Object arg
, oldval
;
1911 x_set_name (f
, arg
, 1);
1914 /* This function should be called by Emacs redisplay code to set the
1915 name; names set this way will never override names set by the user's
1918 x_implicitly_set_name (f
, arg
, oldval
)
1920 Lisp_Object arg
, oldval
;
1922 x_set_name (f
, arg
, 0);
1925 /* Change the title of frame F to NAME.
1926 If NAME is nil, use the frame name as the title.
1928 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1929 name; if NAME is a string, set F's name to NAME and set
1930 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1932 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1933 suggesting a new name, which lisp code should override; if
1934 F->explicit_name is set, ignore the new name; otherwise, set it. */
1937 x_set_title (f
, name
, old_name
)
1939 Lisp_Object name
, old_name
;
1941 /* Don't change the title if it's already NAME. */
1942 if (EQ (name
, f
->title
))
1945 update_mode_lines
= 1;
1952 if (FRAME_W32_WINDOW (f
))
1954 if (STRING_MULTIBYTE (name
))
1955 name
= ENCODE_SYSTEM (name
);
1958 SetWindowText(FRAME_W32_WINDOW (f
), SDATA (name
));
1964 void x_set_scroll_bar_default_width (f
)
1967 int wid
= FRAME_COLUMN_WIDTH (f
);
1969 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
1970 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) +
1975 /* Subroutines of creating a frame. */
1978 /* Return the value of parameter PARAM.
1980 First search ALIST, then Vdefault_frame_alist, then the X defaults
1981 database, using ATTRIBUTE as the attribute name and CLASS as its class.
1983 Convert the resource to the type specified by desired_type.
1985 If no default is specified, return Qunbound. If you call
1986 w32_get_arg, make sure you deal with Qunbound in a reasonable way,
1987 and don't let it get stored in any Lisp-visible variables! */
1990 w32_get_arg (alist
, param
, attribute
, class, type
)
1991 Lisp_Object alist
, param
;
1994 enum resource_types type
;
1996 return x_get_arg (check_x_display_info (Qnil
),
1997 alist
, param
, attribute
, class, type
);
2002 w32_load_cursor (LPCTSTR name
)
2004 /* Try first to load cursor from application resource. */
2005 Cursor cursor
= LoadImage ((HINSTANCE
) GetModuleHandle(NULL
),
2006 name
, IMAGE_CURSOR
, 0, 0,
2007 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
2010 /* Then try to load a shared predefined cursor. */
2011 cursor
= LoadImage (NULL
, name
, IMAGE_CURSOR
, 0, 0,
2012 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
2017 extern LRESULT CALLBACK
w32_wnd_proc ();
2020 w32_init_class (hinst
)
2025 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
2026 wc
.lpfnWndProc
= (WNDPROC
) w32_wnd_proc
;
2028 wc
.cbWndExtra
= WND_EXTRA_BYTES
;
2029 wc
.hInstance
= hinst
;
2030 wc
.hIcon
= LoadIcon (hinst
, EMACS_CLASS
);
2031 wc
.hCursor
= w32_load_cursor (IDC_ARROW
);
2032 wc
.hbrBackground
= NULL
; /* GetStockObject (WHITE_BRUSH); */
2033 wc
.lpszMenuName
= NULL
;
2034 wc
.lpszClassName
= EMACS_CLASS
;
2036 return (RegisterClass (&wc
));
2040 w32_createscrollbar (f
, bar
)
2042 struct scroll_bar
* bar
;
2044 return (CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
2045 /* Position and size of scroll bar. */
2046 XINT(bar
->left
) + VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
2048 XINT(bar
->width
) - VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
2050 FRAME_W32_WINDOW (f
),
2057 w32_createwindow (f
)
2063 rect
.left
= rect
.top
= 0;
2064 rect
.right
= FRAME_PIXEL_WIDTH (f
);
2065 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
2067 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
2068 FRAME_EXTERNAL_MENU_BAR (f
));
2070 /* Do first time app init */
2074 w32_init_class (hinst
);
2077 FRAME_W32_WINDOW (f
) = hwnd
2078 = CreateWindow (EMACS_CLASS
,
2080 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
2083 rect
.right
- rect
.left
,
2084 rect
.bottom
- rect
.top
,
2092 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
2093 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
2094 SetWindowLong (hwnd
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
2095 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->scroll_bar_actual_width
);
2096 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
2098 /* Enable drag-n-drop. */
2099 DragAcceptFiles (hwnd
, TRUE
);
2101 /* Do this to discard the default setting specified by our parent. */
2102 ShowWindow (hwnd
, SW_HIDE
);
2107 my_post_msg (wmsg
, hwnd
, msg
, wParam
, lParam
)
2114 wmsg
->msg
.hwnd
= hwnd
;
2115 wmsg
->msg
.message
= msg
;
2116 wmsg
->msg
.wParam
= wParam
;
2117 wmsg
->msg
.lParam
= lParam
;
2118 wmsg
->msg
.time
= GetMessageTime ();
2123 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
2124 between left and right keys as advertised. We test for this
2125 support dynamically, and set a flag when the support is absent. If
2126 absent, we keep track of the left and right control and alt keys
2127 ourselves. This is particularly necessary on keyboards that rely
2128 upon the AltGr key, which is represented as having the left control
2129 and right alt keys pressed. For these keyboards, we need to know
2130 when the left alt key has been pressed in addition to the AltGr key
2131 so that we can properly support M-AltGr-key sequences (such as M-@
2132 on Swedish keyboards). */
2134 #define EMACS_LCONTROL 0
2135 #define EMACS_RCONTROL 1
2136 #define EMACS_LMENU 2
2137 #define EMACS_RMENU 3
2139 static int modifiers
[4];
2140 static int modifiers_recorded
;
2141 static int modifier_key_support_tested
;
2144 test_modifier_support (unsigned int wparam
)
2148 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
2150 if (wparam
== VK_CONTROL
)
2160 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
2161 modifiers_recorded
= 1;
2163 modifiers_recorded
= 0;
2164 modifier_key_support_tested
= 1;
2168 record_keydown (unsigned int wparam
, unsigned int lparam
)
2172 if (!modifier_key_support_tested
)
2173 test_modifier_support (wparam
);
2175 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2178 if (wparam
== VK_CONTROL
)
2179 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2181 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2187 record_keyup (unsigned int wparam
, unsigned int lparam
)
2191 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2194 if (wparam
== VK_CONTROL
)
2195 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2197 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2202 /* Emacs can lose focus while a modifier key has been pressed. When
2203 it regains focus, be conservative and clear all modifiers since
2204 we cannot reconstruct the left and right modifier state. */
2210 if (GetFocus () == NULL
)
2211 /* Emacs doesn't have keyboard focus. Do nothing. */
2214 ctrl
= GetAsyncKeyState (VK_CONTROL
);
2215 alt
= GetAsyncKeyState (VK_MENU
);
2217 if (!(ctrl
& 0x08000))
2218 /* Clear any recorded control modifier state. */
2219 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2221 if (!(alt
& 0x08000))
2222 /* Clear any recorded alt modifier state. */
2223 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2225 /* Update the state of all modifier keys, because modifiers used in
2226 hot-key combinations can get stuck on if Emacs loses focus as a
2227 result of a hot-key being pressed. */
2231 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
2233 GetKeyboardState (keystate
);
2234 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
2235 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
2236 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
2237 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
2238 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
2239 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
2240 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
2241 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
2242 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
2243 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
2244 SetKeyboardState (keystate
);
2248 /* Synchronize modifier state with what is reported with the current
2249 keystroke. Even if we cannot distinguish between left and right
2250 modifier keys, we know that, if no modifiers are set, then neither
2251 the left or right modifier should be set. */
2255 if (!modifiers_recorded
)
2258 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
2259 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2261 if (!(GetKeyState (VK_MENU
) & 0x8000))
2262 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2266 modifier_set (int vkey
)
2268 if (vkey
== VK_CAPITAL
|| vkey
== VK_SCROLL
)
2269 return (GetKeyState (vkey
) & 0x1);
2270 if (!modifiers_recorded
)
2271 return (GetKeyState (vkey
) & 0x8000);
2276 return modifiers
[EMACS_LCONTROL
];
2278 return modifiers
[EMACS_RCONTROL
];
2280 return modifiers
[EMACS_LMENU
];
2282 return modifiers
[EMACS_RMENU
];
2284 return (GetKeyState (vkey
) & 0x8000);
2287 /* Convert between the modifier bits W32 uses and the modifier bits
2291 w32_key_to_modifier (int key
)
2293 Lisp_Object key_mapping
;
2298 key_mapping
= Vw32_lwindow_modifier
;
2301 key_mapping
= Vw32_rwindow_modifier
;
2304 key_mapping
= Vw32_apps_modifier
;
2307 key_mapping
= Vw32_scroll_lock_modifier
;
2313 /* NB. This code runs in the input thread, asychronously to the lisp
2314 thread, so we must be careful to ensure access to lisp data is
2315 thread-safe. The following code is safe because the modifier
2316 variable values are updated atomically from lisp and symbols are
2317 not relocated by GC. Also, we don't have to worry about seeing GC
2319 if (EQ (key_mapping
, Qhyper
))
2320 return hyper_modifier
;
2321 if (EQ (key_mapping
, Qsuper
))
2322 return super_modifier
;
2323 if (EQ (key_mapping
, Qmeta
))
2324 return meta_modifier
;
2325 if (EQ (key_mapping
, Qalt
))
2326 return alt_modifier
;
2327 if (EQ (key_mapping
, Qctrl
))
2328 return ctrl_modifier
;
2329 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
2330 return ctrl_modifier
;
2331 if (EQ (key_mapping
, Qshift
))
2332 return shift_modifier
;
2334 /* Don't generate any modifier if not explicitly requested. */
2339 w32_get_modifiers ()
2341 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
2342 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
2343 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
2344 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
2345 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
2346 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
2347 (modifier_set (VK_MENU
) ?
2348 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
2351 /* We map the VK_* modifiers into console modifier constants
2352 so that we can use the same routines to handle both console
2353 and window input. */
2356 construct_console_modifiers ()
2361 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
2362 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
2363 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
2364 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
2365 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
2366 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
2367 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
2368 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
2369 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
2370 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
2371 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
2377 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
2381 /* Convert to emacs modifiers. */
2382 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
2388 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
2390 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
2393 if (virt_key
== VK_RETURN
)
2394 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
2396 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
2397 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
2399 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
2400 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
2402 if (virt_key
== VK_CLEAR
)
2403 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
2408 /* List of special key combinations which w32 would normally capture,
2409 but emacs should grab instead. Not directly visible to lisp, to
2410 simplify synchronization. Each item is an integer encoding a virtual
2411 key code and modifier combination to capture. */
2412 Lisp_Object w32_grabbed_keys
;
2414 #define HOTKEY(vk,mods) make_number (((vk) & 255) | ((mods) << 8))
2415 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
2416 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
2417 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
2419 /* Register hot-keys for reserved key combinations when Emacs has
2420 keyboard focus, since this is the only way Emacs can receive key
2421 combinations like Alt-Tab which are used by the system. */
2424 register_hot_keys (hwnd
)
2427 Lisp_Object keylist
;
2429 /* Use GC_CONSP, since we are called asynchronously. */
2430 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
2432 Lisp_Object key
= XCAR (keylist
);
2434 /* Deleted entries get set to nil. */
2435 if (!INTEGERP (key
))
2438 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
2439 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
2444 unregister_hot_keys (hwnd
)
2447 Lisp_Object keylist
;
2449 /* Use GC_CONSP, since we are called asynchronously. */
2450 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
2452 Lisp_Object key
= XCAR (keylist
);
2454 if (!INTEGERP (key
))
2457 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
2461 /* Main message dispatch loop. */
2464 w32_msg_pump (deferred_msg
* msg_buf
)
2470 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
2472 while (GetMessage (&msg
, NULL
, 0, 0))
2474 if (msg
.hwnd
== NULL
)
2476 switch (msg
.message
)
2479 /* Produced by complete_deferred_msg; just ignore. */
2481 case WM_EMACS_CREATEWINDOW
:
2482 w32_createwindow ((struct frame
*) msg
.wParam
);
2483 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2486 case WM_EMACS_SETLOCALE
:
2487 SetThreadLocale (msg
.wParam
);
2488 /* Reply is not expected. */
2490 case WM_EMACS_SETKEYBOARDLAYOUT
:
2491 result
= (int) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
2492 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2496 case WM_EMACS_REGISTER_HOT_KEY
:
2497 focus_window
= GetFocus ();
2498 if (focus_window
!= NULL
)
2499 RegisterHotKey (focus_window
,
2500 HOTKEY_ID (msg
.wParam
),
2501 HOTKEY_MODIFIERS (msg
.wParam
),
2502 HOTKEY_VK_CODE (msg
.wParam
));
2503 /* Reply is not expected. */
2505 case WM_EMACS_UNREGISTER_HOT_KEY
:
2506 focus_window
= GetFocus ();
2507 if (focus_window
!= NULL
)
2508 UnregisterHotKey (focus_window
, HOTKEY_ID (msg
.wParam
));
2509 /* Mark item as erased. NB: this code must be
2510 thread-safe. The next line is okay because the cons
2511 cell is never made into garbage and is not relocated by
2513 XSETCAR ((Lisp_Object
) msg
.lParam
, Qnil
);
2514 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2517 case WM_EMACS_TOGGLE_LOCK_KEY
:
2519 int vk_code
= (int) msg
.wParam
;
2520 int cur_state
= (GetKeyState (vk_code
) & 1);
2521 Lisp_Object new_state
= (Lisp_Object
) msg
.lParam
;
2523 /* NB: This code must be thread-safe. It is safe to
2524 call NILP because symbols are not relocated by GC,
2525 and pointer here is not touched by GC (so the markbit
2526 can't be set). Numbers are safe because they are
2527 immediate values. */
2528 if (NILP (new_state
)
2529 || (NUMBERP (new_state
)
2530 && ((XUINT (new_state
)) & 1) != cur_state
))
2532 one_w32_display_info
.faked_key
= vk_code
;
2534 keybd_event ((BYTE
) vk_code
,
2535 (BYTE
) MapVirtualKey (vk_code
, 0),
2536 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2537 keybd_event ((BYTE
) vk_code
,
2538 (BYTE
) MapVirtualKey (vk_code
, 0),
2539 KEYEVENTF_EXTENDEDKEY
| 0, 0);
2540 keybd_event ((BYTE
) vk_code
,
2541 (BYTE
) MapVirtualKey (vk_code
, 0),
2542 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2543 cur_state
= !cur_state
;
2545 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2551 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
2556 DispatchMessage (&msg
);
2559 /* Exit nested loop when our deferred message has completed. */
2560 if (msg_buf
->completed
)
2565 deferred_msg
* deferred_msg_head
;
2567 static deferred_msg
*
2568 find_deferred_msg (HWND hwnd
, UINT msg
)
2570 deferred_msg
* item
;
2572 /* Don't actually need synchronization for read access, since
2573 modification of single pointer is always atomic. */
2574 /* enter_crit (); */
2576 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2577 if (item
->w32msg
.msg
.hwnd
== hwnd
2578 && item
->w32msg
.msg
.message
== msg
)
2581 /* leave_crit (); */
2587 send_deferred_msg (deferred_msg
* msg_buf
,
2593 /* Only input thread can send deferred messages. */
2594 if (GetCurrentThreadId () != dwWindowsThreadId
)
2597 /* It is an error to send a message that is already deferred. */
2598 if (find_deferred_msg (hwnd
, msg
) != NULL
)
2601 /* Enforced synchronization is not needed because this is the only
2602 function that alters deferred_msg_head, and the following critical
2603 section is guaranteed to only be serially reentered (since only the
2604 input thread can call us). */
2606 /* enter_crit (); */
2608 msg_buf
->completed
= 0;
2609 msg_buf
->next
= deferred_msg_head
;
2610 deferred_msg_head
= msg_buf
;
2611 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
2613 /* leave_crit (); */
2615 /* Start a new nested message loop to process other messages until
2616 this one is completed. */
2617 w32_msg_pump (msg_buf
);
2619 deferred_msg_head
= msg_buf
->next
;
2621 return msg_buf
->result
;
2625 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
2627 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
2629 if (msg_buf
== NULL
)
2630 /* Message may have been cancelled, so don't abort(). */
2633 msg_buf
->result
= result
;
2634 msg_buf
->completed
= 1;
2636 /* Ensure input thread is woken so it notices the completion. */
2637 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2641 cancel_all_deferred_msgs ()
2643 deferred_msg
* item
;
2645 /* Don't actually need synchronization for read access, since
2646 modification of single pointer is always atomic. */
2647 /* enter_crit (); */
2649 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2652 item
->completed
= 1;
2655 /* leave_crit (); */
2657 /* Ensure input thread is woken so it notices the completion. */
2658 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2666 deferred_msg dummy_buf
;
2668 /* Ensure our message queue is created */
2670 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
2672 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2675 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
2676 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
2677 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
2679 /* This is the inital message loop which should only exit when the
2680 application quits. */
2681 w32_msg_pump (&dummy_buf
);
2687 post_character_message (hwnd
, msg
, wParam
, lParam
, modifiers
)
2697 wmsg
.dwModifiers
= modifiers
;
2699 /* Detect quit_char and set quit-flag directly. Note that we
2700 still need to post a message to ensure the main thread will be
2701 woken up if blocked in sys_select(), but we do NOT want to post
2702 the quit_char message itself (because it will usually be as if
2703 the user had typed quit_char twice). Instead, we post a dummy
2704 message that has no particular effect. */
2707 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
2708 c
= make_ctrl_char (c
) & 0377;
2710 || (wmsg
.dwModifiers
== 0 &&
2711 XFASTINT (Vw32_quit_key
) && wParam
== XFASTINT (Vw32_quit_key
)))
2715 /* The choice of message is somewhat arbitrary, as long as
2716 the main thread handler just ignores it. */
2719 /* Interrupt any blocking system calls. */
2722 /* As a safety precaution, forcibly complete any deferred
2723 messages. This is a kludge, but I don't see any particularly
2724 clean way to handle the situation where a deferred message is
2725 "dropped" in the lisp thread, and will thus never be
2726 completed, eg. by the user trying to activate the menubar
2727 when the lisp thread is busy, and then typing C-g when the
2728 menubar doesn't open promptly (with the result that the
2729 menubar never responds at all because the deferred
2730 WM_INITMENU message is never completed). Another problem
2731 situation is when the lisp thread calls SendMessage (to send
2732 a window manager command) when a message has been deferred;
2733 the lisp thread gets blocked indefinitely waiting for the
2734 deferred message to be completed, which itself is waiting for
2735 the lisp thread to respond.
2737 Note that we don't want to block the input thread waiting for
2738 a reponse from the lisp thread (although that would at least
2739 solve the deadlock problem above), because we want to be able
2740 to receive C-g to interrupt the lisp thread. */
2741 cancel_all_deferred_msgs ();
2745 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2748 /* Main window procedure */
2751 w32_wnd_proc (hwnd
, msg
, wParam
, lParam
)
2758 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
2760 int windows_translate
;
2763 /* Note that it is okay to call x_window_to_frame, even though we are
2764 not running in the main lisp thread, because frame deletion
2765 requires the lisp thread to synchronize with this thread. Thus, if
2766 a frame struct is returned, it can be used without concern that the
2767 lisp thread might make it disappear while we are using it.
2769 NB. Walking the frame list in this thread is safe (as long as
2770 writes of Lisp_Object slots are atomic, which they are on Windows).
2771 Although delete-frame can destructively modify the frame list while
2772 we are walking it, a garbage collection cannot occur until after
2773 delete-frame has synchronized with this thread.
2775 It is also safe to use functions that make GDI calls, such as
2776 w32_clear_rect, because these functions must obtain a DC handle
2777 from the frame struct using get_frame_dc which is thread-aware. */
2782 f
= x_window_to_frame (dpyinfo
, hwnd
);
2785 HDC hdc
= get_frame_dc (f
);
2786 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
2787 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
2788 release_frame_dc (f
, hdc
);
2790 #if defined (W32_DEBUG_DISPLAY)
2791 DebPrint (("WM_ERASEBKGND (frame %p): erasing %d,%d-%d,%d\n",
2793 wmsg
.rect
.left
, wmsg
.rect
.top
,
2794 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2795 #endif /* W32_DEBUG_DISPLAY */
2798 case WM_PALETTECHANGED
:
2799 /* ignore our own changes */
2800 if ((HWND
)wParam
!= hwnd
)
2802 f
= x_window_to_frame (dpyinfo
, hwnd
);
2804 /* get_frame_dc will realize our palette and force all
2805 frames to be redrawn if needed. */
2806 release_frame_dc (f
, get_frame_dc (f
));
2811 PAINTSTRUCT paintStruct
;
2813 bzero (&update_rect
, sizeof (update_rect
));
2815 f
= x_window_to_frame (dpyinfo
, hwnd
);
2818 DebPrint (("WM_PAINT received for unknown window %p\n", hwnd
));
2822 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
2823 fails. Apparently this can happen under some
2825 if (GetUpdateRect (hwnd
, &update_rect
, FALSE
) || !w32_strict_painting
)
2828 BeginPaint (hwnd
, &paintStruct
);
2830 /* The rectangles returned by GetUpdateRect and BeginPaint
2831 do not always match. Play it safe by assuming both areas
2833 UnionRect (&(wmsg
.rect
), &update_rect
, &(paintStruct
.rcPaint
));
2835 #if defined (W32_DEBUG_DISPLAY)
2836 DebPrint (("WM_PAINT (frame %p): painting %d,%d-%d,%d\n",
2838 wmsg
.rect
.left
, wmsg
.rect
.top
,
2839 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2840 DebPrint ((" [update region is %d,%d-%d,%d]\n",
2841 update_rect
.left
, update_rect
.top
,
2842 update_rect
.right
, update_rect
.bottom
));
2844 EndPaint (hwnd
, &paintStruct
);
2847 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2852 /* If GetUpdateRect returns 0 (meaning there is no update
2853 region), assume the whole window needs to be repainted. */
2854 GetClientRect(hwnd
, &wmsg
.rect
);
2855 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2859 case WM_INPUTLANGCHANGE
:
2860 /* Inform lisp thread of keyboard layout changes. */
2861 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2863 /* Clear dead keys in the keyboard state; for simplicity only
2864 preserve modifier key states. */
2869 GetKeyboardState (keystate
);
2870 for (i
= 0; i
< 256; i
++)
2887 SetKeyboardState (keystate
);
2892 /* Synchronize hot keys with normal input. */
2893 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
2898 record_keyup (wParam
, lParam
);
2903 /* Ignore keystrokes we fake ourself; see below. */
2904 if (dpyinfo
->faked_key
== wParam
)
2906 dpyinfo
->faked_key
= 0;
2907 /* Make sure TranslateMessage sees them though (as long as
2908 they don't produce WM_CHAR messages). This ensures that
2909 indicator lights are toggled promptly on Windows 9x, for
2911 if (lispy_function_keys
[wParam
] != 0)
2913 windows_translate
= 1;
2919 /* Synchronize modifiers with current keystroke. */
2921 record_keydown (wParam
, lParam
);
2922 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
2924 windows_translate
= 0;
2929 if (NILP (Vw32_pass_lwindow_to_system
))
2931 /* Prevent system from acting on keyup (which opens the
2932 Start menu if no other key was pressed) by simulating a
2933 press of Space which we will ignore. */
2934 if (GetAsyncKeyState (wParam
) & 1)
2936 if (NUMBERP (Vw32_phantom_key_code
))
2937 key
= XUINT (Vw32_phantom_key_code
) & 255;
2940 dpyinfo
->faked_key
= key
;
2941 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
2944 if (!NILP (Vw32_lwindow_modifier
))
2948 if (NILP (Vw32_pass_rwindow_to_system
))
2950 if (GetAsyncKeyState (wParam
) & 1)
2952 if (NUMBERP (Vw32_phantom_key_code
))
2953 key
= XUINT (Vw32_phantom_key_code
) & 255;
2956 dpyinfo
->faked_key
= key
;
2957 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
2960 if (!NILP (Vw32_rwindow_modifier
))
2964 if (!NILP (Vw32_apps_modifier
))
2968 if (NILP (Vw32_pass_alt_to_system
))
2969 /* Prevent DefWindowProc from activating the menu bar if an
2970 Alt key is pressed and released by itself. */
2972 windows_translate
= 1;
2975 /* Decide whether to treat as modifier or function key. */
2976 if (NILP (Vw32_enable_caps_lock
))
2977 goto disable_lock_key
;
2978 windows_translate
= 1;
2981 /* Decide whether to treat as modifier or function key. */
2982 if (NILP (Vw32_enable_num_lock
))
2983 goto disable_lock_key
;
2984 windows_translate
= 1;
2987 /* Decide whether to treat as modifier or function key. */
2988 if (NILP (Vw32_scroll_lock_modifier
))
2989 goto disable_lock_key
;
2990 windows_translate
= 1;
2993 /* Ensure the appropriate lock key state (and indicator light)
2994 remains in the same state. We do this by faking another
2995 press of the relevant key. Apparently, this really is the
2996 only way to toggle the state of the indicator lights. */
2997 dpyinfo
->faked_key
= wParam
;
2998 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
2999 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3000 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3001 KEYEVENTF_EXTENDEDKEY
| 0, 0);
3002 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3003 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3004 /* Ensure indicator lights are updated promptly on Windows 9x
3005 (TranslateMessage apparently does this), after forwarding
3007 post_character_message (hwnd
, msg
, wParam
, lParam
,
3008 w32_get_key_modifiers (wParam
, lParam
));
3009 windows_translate
= 1;
3013 case VK_PROCESSKEY
: /* Generated by IME. */
3014 windows_translate
= 1;
3017 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
3018 which is confusing for purposes of key binding; convert
3019 VK_CANCEL events into VK_PAUSE events. */
3023 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
3024 for purposes of key binding; convert these back into
3025 VK_NUMLOCK events, at least when we want to see NumLock key
3026 presses. (Note that there is never any possibility that
3027 VK_PAUSE with Ctrl really is C-Pause as per above.) */
3028 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
3029 wParam
= VK_NUMLOCK
;
3032 /* If not defined as a function key, change it to a WM_CHAR message. */
3033 if (lispy_function_keys
[wParam
] == 0)
3035 DWORD modifiers
= construct_console_modifiers ();
3037 if (!NILP (Vw32_recognize_altgr
)
3038 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
3040 /* Always let TranslateMessage handle AltGr key chords;
3041 for some reason, ToAscii doesn't always process AltGr
3042 chords correctly. */
3043 windows_translate
= 1;
3045 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
3047 /* Handle key chords including any modifiers other
3048 than shift directly, in order to preserve as much
3049 modifier information as possible. */
3050 if ('A' <= wParam
&& wParam
<= 'Z')
3052 /* Don't translate modified alphabetic keystrokes,
3053 so the user doesn't need to constantly switch
3054 layout to type control or meta keystrokes when
3055 the normal layout translates alphabetic
3056 characters to non-ascii characters. */
3057 if (!modifier_set (VK_SHIFT
))
3058 wParam
+= ('a' - 'A');
3063 /* Try to handle other keystrokes by determining the
3064 base character (ie. translating the base key plus
3068 KEY_EVENT_RECORD key
;
3070 key
.bKeyDown
= TRUE
;
3071 key
.wRepeatCount
= 1;
3072 key
.wVirtualKeyCode
= wParam
;
3073 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
3074 key
.uChar
.AsciiChar
= 0;
3075 key
.dwControlKeyState
= modifiers
;
3077 add
= w32_kbd_patch_key (&key
);
3078 /* 0 means an unrecognised keycode, negative means
3079 dead key. Ignore both. */
3082 /* Forward asciified character sequence. */
3083 post_character_message
3084 (hwnd
, WM_CHAR
, key
.uChar
.AsciiChar
, lParam
,
3085 w32_get_key_modifiers (wParam
, lParam
));
3086 w32_kbd_patch_key (&key
);
3093 /* Let TranslateMessage handle everything else. */
3094 windows_translate
= 1;
3100 if (windows_translate
)
3102 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
3104 windows_msg
.time
= GetMessageTime ();
3105 TranslateMessage (&windows_msg
);
3113 post_character_message (hwnd
, msg
, wParam
, lParam
,
3114 w32_get_key_modifiers (wParam
, lParam
));
3117 /* Simulate middle mouse button events when left and right buttons
3118 are used together, but only if user has two button mouse. */
3119 case WM_LBUTTONDOWN
:
3120 case WM_RBUTTONDOWN
:
3121 if (XINT (Vw32_num_mouse_buttons
) > 2)
3122 goto handle_plain_button
;
3125 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
3126 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
3128 if (button_state
& this)
3131 if (button_state
== 0)
3134 button_state
|= this;
3136 if (button_state
& other
)
3138 if (mouse_button_timer
)
3140 KillTimer (hwnd
, mouse_button_timer
);
3141 mouse_button_timer
= 0;
3143 /* Generate middle mouse event instead. */
3144 msg
= WM_MBUTTONDOWN
;
3145 button_state
|= MMOUSE
;
3147 else if (button_state
& MMOUSE
)
3149 /* Ignore button event if we've already generated a
3150 middle mouse down event. This happens if the
3151 user releases and press one of the two buttons
3152 after we've faked a middle mouse event. */
3157 /* Flush out saved message. */
3158 post_msg (&saved_mouse_button_msg
);
3160 wmsg
.dwModifiers
= w32_get_modifiers ();
3161 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3163 /* Clear message buffer. */
3164 saved_mouse_button_msg
.msg
.hwnd
= 0;
3168 /* Hold onto message for now. */
3169 mouse_button_timer
=
3170 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
3171 XINT (Vw32_mouse_button_tolerance
), NULL
);
3172 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
3173 saved_mouse_button_msg
.msg
.message
= msg
;
3174 saved_mouse_button_msg
.msg
.wParam
= wParam
;
3175 saved_mouse_button_msg
.msg
.lParam
= lParam
;
3176 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
3177 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
3184 if (XINT (Vw32_num_mouse_buttons
) > 2)
3185 goto handle_plain_button
;
3188 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
3189 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
3191 if ((button_state
& this) == 0)
3194 button_state
&= ~this;
3196 if (button_state
& MMOUSE
)
3198 /* Only generate event when second button is released. */
3199 if ((button_state
& other
) == 0)
3202 button_state
&= ~MMOUSE
;
3204 if (button_state
) abort ();
3211 /* Flush out saved message if necessary. */
3212 if (saved_mouse_button_msg
.msg
.hwnd
)
3214 post_msg (&saved_mouse_button_msg
);
3217 wmsg
.dwModifiers
= w32_get_modifiers ();
3218 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3220 /* Always clear message buffer and cancel timer. */
3221 saved_mouse_button_msg
.msg
.hwnd
= 0;
3222 KillTimer (hwnd
, mouse_button_timer
);
3223 mouse_button_timer
= 0;
3225 if (button_state
== 0)
3230 case WM_XBUTTONDOWN
:
3232 if (w32_pass_extra_mouse_buttons_to_system
)
3234 /* else fall through and process them. */
3235 case WM_MBUTTONDOWN
:
3237 handle_plain_button
:
3242 if (parse_button (msg
, HIWORD (wParam
), &button
, &up
))
3244 if (up
) ReleaseCapture ();
3245 else SetCapture (hwnd
);
3246 button
= (button
== 0) ? LMOUSE
:
3247 ((button
== 1) ? MMOUSE
: RMOUSE
);
3249 button_state
&= ~button
;
3251 button_state
|= button
;
3255 wmsg
.dwModifiers
= w32_get_modifiers ();
3256 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3258 /* Need to return true for XBUTTON messages, false for others,
3259 to indicate that we processed the message. */
3260 return (msg
== WM_XBUTTONDOWN
|| msg
== WM_XBUTTONUP
);
3263 /* If the mouse has just moved into the frame, start tracking
3264 it, so we will be notified when it leaves the frame. Mouse
3265 tracking only works under W98 and NT4 and later. On earlier
3266 versions, there is no way of telling when the mouse leaves the
3267 frame, so we just have to put up with help-echo and mouse
3268 highlighting remaining while the frame is not active. */
3269 if (track_mouse_event_fn
&& !track_mouse_window
)
3271 TRACKMOUSEEVENT tme
;
3272 tme
.cbSize
= sizeof (tme
);
3273 tme
.dwFlags
= TME_LEAVE
;
3274 tme
.hwndTrack
= hwnd
;
3276 track_mouse_event_fn (&tme
);
3277 track_mouse_window
= hwnd
;
3280 if (XINT (Vw32_mouse_move_interval
) <= 0
3281 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
3283 wmsg
.dwModifiers
= w32_get_modifiers ();
3284 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3288 /* Hang onto mouse move and scroll messages for a bit, to avoid
3289 sending such events to Emacs faster than it can process them.
3290 If we get more events before the timer from the first message
3291 expires, we just replace the first message. */
3293 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
3295 SetTimer (hwnd
, MOUSE_MOVE_ID
,
3296 XINT (Vw32_mouse_move_interval
), NULL
);
3298 /* Hold onto message for now. */
3299 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
3300 saved_mouse_move_msg
.msg
.message
= msg
;
3301 saved_mouse_move_msg
.msg
.wParam
= wParam
;
3302 saved_mouse_move_msg
.msg
.lParam
= lParam
;
3303 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
3304 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
3309 wmsg
.dwModifiers
= w32_get_modifiers ();
3310 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3314 wmsg
.dwModifiers
= w32_get_modifiers ();
3315 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3319 /* Flush out saved messages if necessary. */
3320 if (wParam
== mouse_button_timer
)
3322 if (saved_mouse_button_msg
.msg
.hwnd
)
3324 post_msg (&saved_mouse_button_msg
);
3325 saved_mouse_button_msg
.msg
.hwnd
= 0;
3327 KillTimer (hwnd
, mouse_button_timer
);
3328 mouse_button_timer
= 0;
3330 else if (wParam
== mouse_move_timer
)
3332 if (saved_mouse_move_msg
.msg
.hwnd
)
3334 post_msg (&saved_mouse_move_msg
);
3335 saved_mouse_move_msg
.msg
.hwnd
= 0;
3337 KillTimer (hwnd
, mouse_move_timer
);
3338 mouse_move_timer
= 0;
3340 else if (wParam
== menu_free_timer
)
3342 KillTimer (hwnd
, menu_free_timer
);
3343 menu_free_timer
= 0;
3344 f
= x_window_to_frame (dpyinfo
, hwnd
);
3345 if (!f
->output_data
.w32
->menu_command_in_progress
)
3347 /* Free memory used by owner-drawn and help-echo strings. */
3348 w32_free_menu_strings (hwnd
);
3349 f
->output_data
.w32
->menubar_active
= 0;
3355 /* Windows doesn't send us focus messages when putting up and
3356 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
3357 The only indication we get that something happened is receiving
3358 this message afterwards. So this is a good time to reset our
3359 keyboard modifiers' state. */
3366 /* We must ensure menu bar is fully constructed and up to date
3367 before allowing user interaction with it. To achieve this
3368 we send this message to the lisp thread and wait for a
3369 reply (whose value is not actually needed) to indicate that
3370 the menu bar is now ready for use, so we can now return.
3372 To remain responsive in the meantime, we enter a nested message
3373 loop that can process all other messages.
3375 However, we skip all this if the message results from calling
3376 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
3377 thread a message because it is blocked on us at this point. We
3378 set menubar_active before calling TrackPopupMenu to indicate
3379 this (there is no possibility of confusion with real menubar
3382 f
= x_window_to_frame (dpyinfo
, hwnd
);
3384 && (f
->output_data
.w32
->menubar_active
3385 /* We can receive this message even in the absence of a
3386 menubar (ie. when the system menu is activated) - in this
3387 case we do NOT want to forward the message, otherwise it
3388 will cause the menubar to suddenly appear when the user
3389 had requested it to be turned off! */
3390 || f
->output_data
.w32
->menubar_widget
== NULL
))
3394 deferred_msg msg_buf
;
3396 /* Detect if message has already been deferred; in this case
3397 we cannot return any sensible value to ignore this. */
3398 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3401 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
3404 case WM_EXITMENULOOP
:
3405 f
= x_window_to_frame (dpyinfo
, hwnd
);
3407 /* If a menu command is not already in progress, check again
3408 after a short delay, since Windows often (always?) sends the
3409 WM_EXITMENULOOP before the corresponding WM_COMMAND message. */
3410 if (f
&& !f
->output_data
.w32
->menu_command_in_progress
)
3411 menu_free_timer
= SetTimer (hwnd
, MENU_FREE_ID
, MENU_FREE_DELAY
, NULL
);
3415 /* Direct handling of help_echo in menus. Should be safe now
3416 that we generate the help_echo by placing a help event in the
3419 HMENU menu
= (HMENU
) lParam
;
3420 UINT menu_item
= (UINT
) LOWORD (wParam
);
3421 UINT flags
= (UINT
) HIWORD (wParam
);
3423 w32_menu_display_help (hwnd
, menu
, menu_item
, flags
);
3427 case WM_MEASUREITEM
:
3428 f
= x_window_to_frame (dpyinfo
, hwnd
);
3431 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
3433 if (pMis
->CtlType
== ODT_MENU
)
3435 /* Work out dimensions for popup menu titles. */
3436 char * title
= (char *) pMis
->itemData
;
3437 HDC hdc
= GetDC (hwnd
);
3438 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3439 LOGFONT menu_logfont
;
3443 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3444 menu_logfont
.lfWeight
= FW_BOLD
;
3445 menu_font
= CreateFontIndirect (&menu_logfont
);
3446 old_font
= SelectObject (hdc
, menu_font
);
3448 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
3451 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
3452 pMis
->itemWidth
= size
.cx
;
3453 if (pMis
->itemHeight
< size
.cy
)
3454 pMis
->itemHeight
= size
.cy
;
3457 pMis
->itemWidth
= 0;
3459 SelectObject (hdc
, old_font
);
3460 DeleteObject (menu_font
);
3461 ReleaseDC (hwnd
, hdc
);
3468 f
= x_window_to_frame (dpyinfo
, hwnd
);
3471 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
3473 if (pDis
->CtlType
== ODT_MENU
)
3475 /* Draw popup menu title. */
3476 char * title
= (char *) pDis
->itemData
;
3479 HDC hdc
= pDis
->hDC
;
3480 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3481 LOGFONT menu_logfont
;
3484 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3485 menu_logfont
.lfWeight
= FW_BOLD
;
3486 menu_font
= CreateFontIndirect (&menu_logfont
);
3487 old_font
= SelectObject (hdc
, menu_font
);
3489 /* Always draw title as if not selected. */
3492 + GetSystemMetrics (SM_CXMENUCHECK
),
3494 ETO_OPAQUE
, &pDis
->rcItem
,
3495 title
, strlen (title
), NULL
);
3497 SelectObject (hdc
, old_font
);
3498 DeleteObject (menu_font
);
3506 /* Still not right - can't distinguish between clicks in the
3507 client area of the frame from clicks forwarded from the scroll
3508 bars - may have to hook WM_NCHITTEST to remember the mouse
3509 position and then check if it is in the client area ourselves. */
3510 case WM_MOUSEACTIVATE
:
3511 /* Discard the mouse click that activates a frame, allowing the
3512 user to click anywhere without changing point (or worse!).
3513 Don't eat mouse clicks on scrollbars though!! */
3514 if (LOWORD (lParam
) == HTCLIENT
)
3515 return MA_ACTIVATEANDEAT
;
3520 /* No longer tracking mouse. */
3521 track_mouse_window
= NULL
;
3523 case WM_ACTIVATEAPP
:
3525 case WM_WINDOWPOSCHANGED
:
3527 /* Inform lisp thread that a frame might have just been obscured
3528 or exposed, so should recheck visibility of all frames. */
3529 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3533 dpyinfo
->faked_key
= 0;
3535 register_hot_keys (hwnd
);
3538 unregister_hot_keys (hwnd
);
3541 /* Relinquish the system caret. */
3542 if (w32_system_caret_hwnd
)
3544 w32_visible_system_caret_hwnd
= NULL
;
3545 w32_system_caret_hwnd
= NULL
;
3550 f
= x_window_to_frame (dpyinfo
, hwnd
);
3551 if (f
&& HIWORD (wParam
) == 0)
3553 f
->output_data
.w32
->menu_command_in_progress
= 1;
3554 if (menu_free_timer
)
3556 KillTimer (hwnd
, menu_free_timer
);
3557 menu_free_timer
= 0;
3563 wmsg
.dwModifiers
= w32_get_modifiers ();
3564 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3568 wmsg
.dwModifiers
= w32_get_modifiers ();
3569 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3572 case WM_WINDOWPOSCHANGING
:
3573 /* Don't restrict the sizing of tip frames. */
3574 if (hwnd
== tip_window
)
3578 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
3580 wp
.length
= sizeof (WINDOWPLACEMENT
);
3581 GetWindowPlacement (hwnd
, &wp
);
3583 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
3590 DWORD internal_border
;
3591 DWORD scrollbar_extra
;
3594 wp
.length
= sizeof(wp
);
3595 GetWindowRect (hwnd
, &wr
);
3599 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
3600 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
3601 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
3602 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
3606 memset (&rect
, 0, sizeof (rect
));
3607 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
3608 GetMenu (hwnd
) != NULL
);
3610 /* Force width and height of client area to be exact
3611 multiples of the character cell dimensions. */
3612 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
3613 - 2 * internal_border
- scrollbar_extra
)
3615 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
3616 - 2 * internal_border
)
3621 /* For right/bottom sizing we can just fix the sizes.
3622 However for top/left sizing we will need to fix the X
3623 and Y positions as well. */
3628 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
3629 && (lppos
->flags
& SWP_NOMOVE
) == 0)
3631 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
3638 lppos
->flags
|= SWP_NOMOVE
;
3649 case WM_GETMINMAXINFO
:
3650 /* Hack to correct bug that allows Emacs frames to be resized
3651 below the Minimum Tracking Size. */
3652 ((LPMINMAXINFO
) lParam
)->ptMinTrackSize
.y
++;
3653 /* Hack to allow resizing the Emacs frame above the screen size.
3654 Note that Windows 9x limits coordinates to 16-bits. */
3655 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.x
= 32767;
3656 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.y
= 32767;
3660 if (LOWORD (lParam
) == HTCLIENT
)
3665 case WM_EMACS_SETCURSOR
:
3667 Cursor cursor
= (Cursor
) wParam
;
3673 case WM_EMACS_CREATESCROLLBAR
:
3674 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
3675 (struct scroll_bar
*) lParam
);
3677 case WM_EMACS_SHOWWINDOW
:
3678 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
3680 case WM_EMACS_SETFOREGROUND
:
3682 HWND foreground_window
;
3683 DWORD foreground_thread
, retval
;
3685 /* On NT 5.0, and apparently Windows 98, it is necessary to
3686 attach to the thread that currently has focus in order to
3687 pull the focus away from it. */
3688 foreground_window
= GetForegroundWindow ();
3689 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
3690 if (!foreground_window
3691 || foreground_thread
== GetCurrentThreadId ()
3692 || !AttachThreadInput (GetCurrentThreadId (),
3693 foreground_thread
, TRUE
))
3694 foreground_thread
= 0;
3696 retval
= SetForegroundWindow ((HWND
) wParam
);
3698 /* Detach from the previous foreground thread. */
3699 if (foreground_thread
)
3700 AttachThreadInput (GetCurrentThreadId (),
3701 foreground_thread
, FALSE
);
3706 case WM_EMACS_SETWINDOWPOS
:
3708 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
3709 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
3710 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
3713 case WM_EMACS_DESTROYWINDOW
:
3714 DragAcceptFiles ((HWND
) wParam
, FALSE
);
3715 return DestroyWindow ((HWND
) wParam
);
3717 case WM_EMACS_HIDE_CARET
:
3718 return HideCaret (hwnd
);
3720 case WM_EMACS_SHOW_CARET
:
3721 return ShowCaret (hwnd
);
3723 case WM_EMACS_DESTROY_CARET
:
3724 w32_system_caret_hwnd
= NULL
;
3725 w32_visible_system_caret_hwnd
= NULL
;
3726 return DestroyCaret ();
3728 case WM_EMACS_TRACK_CARET
:
3729 /* If there is currently no system caret, create one. */
3730 if (w32_system_caret_hwnd
== NULL
)
3732 /* Use the default caret width, and avoid changing it
3733 unneccesarily, as it confuses screen reader software. */
3734 w32_system_caret_hwnd
= hwnd
;
3735 CreateCaret (hwnd
, NULL
, 0,
3736 w32_system_caret_height
);
3739 if (!SetCaretPos (w32_system_caret_x
, w32_system_caret_y
))
3741 /* Ensure visible caret gets turned on when requested. */
3742 else if (w32_use_visible_system_caret
3743 && w32_visible_system_caret_hwnd
!= hwnd
)
3745 w32_visible_system_caret_hwnd
= hwnd
;
3746 return ShowCaret (hwnd
);
3748 /* Ensure visible caret gets turned off when requested. */
3749 else if (!w32_use_visible_system_caret
3750 && w32_visible_system_caret_hwnd
)
3752 w32_visible_system_caret_hwnd
= NULL
;
3753 return HideCaret (hwnd
);
3758 case WM_EMACS_TRACKPOPUPMENU
:
3763 pos
= (POINT
*)lParam
;
3764 flags
= TPM_CENTERALIGN
;
3765 if (button_state
& LMOUSE
)
3766 flags
|= TPM_LEFTBUTTON
;
3767 else if (button_state
& RMOUSE
)
3768 flags
|= TPM_RIGHTBUTTON
;
3770 /* Remember we did a SetCapture on the initial mouse down event,
3771 so for safety, we make sure the capture is cancelled now. */
3775 /* Use menubar_active to indicate that WM_INITMENU is from
3776 TrackPopupMenu below, and should be ignored. */
3777 f
= x_window_to_frame (dpyinfo
, hwnd
);
3779 f
->output_data
.w32
->menubar_active
= 1;
3781 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
3785 /* Eat any mouse messages during popupmenu */
3786 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
3788 /* Get the menu selection, if any */
3789 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
3791 retval
= LOWORD (amsg
.wParam
);
3807 /* Check for messages registered at runtime. */
3808 if (msg
== msh_mousewheel
)
3810 wmsg
.dwModifiers
= w32_get_modifiers ();
3811 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3816 return DefWindowProc (hwnd
, msg
, wParam
, lParam
);
3820 /* The most common default return code for handled messages is 0. */
3825 my_create_window (f
)
3830 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
3832 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
3836 /* Create a tooltip window. Unlike my_create_window, we do not do this
3837 indirectly via the Window thread, as we do not need to process Window
3838 messages for the tooltip. Creating tooltips indirectly also creates
3839 deadlocks when tooltips are created for menu items. */
3841 my_create_tip_window (f
)
3846 rect
.left
= rect
.top
= 0;
3847 rect
.right
= FRAME_PIXEL_WIDTH (f
);
3848 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
3850 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
3851 FRAME_EXTERNAL_MENU_BAR (f
));
3853 tip_window
= FRAME_W32_WINDOW (f
)
3854 = CreateWindow (EMACS_CLASS
,
3856 f
->output_data
.w32
->dwStyle
,
3859 rect
.right
- rect
.left
,
3860 rect
.bottom
- rect
.top
,
3861 FRAME_W32_WINDOW (SELECTED_FRAME ()), /* owner */
3868 SetWindowLong (tip_window
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
3869 SetWindowLong (tip_window
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
3870 SetWindowLong (tip_window
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
3871 SetWindowLong (tip_window
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
3873 /* Tip frames have no scrollbars. */
3874 SetWindowLong (tip_window
, WND_SCROLLBAR_INDEX
, 0);
3876 /* Do this to discard the default setting specified by our parent. */
3877 ShowWindow (tip_window
, SW_HIDE
);
3882 /* Create and set up the w32 window for frame F. */
3885 w32_window (f
, window_prompting
, minibuffer_only
)
3887 long window_prompting
;
3888 int minibuffer_only
;
3892 /* Use the resource name as the top-level window name
3893 for looking up resources. Make a non-Lisp copy
3894 for the window manager, so GC relocation won't bother it.
3896 Elsewhere we specify the window name for the window manager. */
3899 char *str
= (char *) SDATA (Vx_resource_name
);
3900 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
3901 strcpy (f
->namebuf
, str
);
3904 my_create_window (f
);
3906 validate_x_resource_name ();
3908 /* x_set_name normally ignores requests to set the name if the
3909 requested name is the same as the current name. This is the one
3910 place where that assumption isn't correct; f->name is set, but
3911 the server hasn't been told. */
3914 int explicit = f
->explicit_name
;
3916 f
->explicit_name
= 0;
3919 x_set_name (f
, name
, explicit);
3924 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
3925 initialize_frame_menubar (f
);
3927 if (FRAME_W32_WINDOW (f
) == 0)
3928 error ("Unable to create window");
3931 /* Handle the icon stuff for this window. Perhaps later we might
3932 want an x_set_icon_position which can be called interactively as
3940 Lisp_Object icon_x
, icon_y
;
3942 /* Set the position of the icon. Note that Windows 95 groups all
3943 icons in the tray. */
3944 icon_x
= w32_get_arg (parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
3945 icon_y
= w32_get_arg (parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
3946 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
3948 CHECK_NUMBER (icon_x
);
3949 CHECK_NUMBER (icon_y
);
3951 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
3952 error ("Both left and top icon corners of icon must be specified");
3956 if (! EQ (icon_x
, Qunbound
))
3957 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
3960 /* Start up iconic or window? */
3961 x_wm_set_window_state
3962 (f
, (EQ (w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
3966 x_text_icon (f
, (char *) SDATA ((!NILP (f
->icon_name
)
3979 XGCValues gc_values
;
3983 /* Create the GC's of this frame.
3984 Note that many default values are used. */
3987 gc_values
.font
= FRAME_FONT (f
);
3989 /* Cursor has cursor-color background, background-color foreground. */
3990 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
3991 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
3992 f
->output_data
.w32
->cursor_gc
3993 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
3994 (GCFont
| GCForeground
| GCBackground
),
3998 f
->output_data
.w32
->white_relief
.gc
= 0;
3999 f
->output_data
.w32
->black_relief
.gc
= 0;
4005 /* Handler for signals raised during x_create_frame and
4006 x_create_top_frame. FRAME is the frame which is partially
4010 unwind_create_frame (frame
)
4013 struct frame
*f
= XFRAME (frame
);
4015 /* If frame is ``official'', nothing to do. */
4016 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
4019 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4022 x_free_frame_resources (f
);
4024 /* Check that reference counts are indeed correct. */
4025 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
4026 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
4035 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
4037 doc
: /* Make a new window, which is called a \"frame\" in Emacs terms.
4038 Returns an Emacs frame object.
4039 ALIST is an alist of frame parameters.
4040 If the parameters specify that the frame should not have a minibuffer,
4041 and do not specify a specific minibuffer window to use,
4042 then `default-minibuffer-frame' must be a frame whose minibuffer can
4043 be shared by the new frame.
4045 This function is an internal primitive--use `make-frame' instead. */)
4050 Lisp_Object frame
, tem
;
4052 int minibuffer_only
= 0;
4053 long window_prompting
= 0;
4055 int count
= SPECPDL_INDEX ();
4056 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4057 Lisp_Object display
;
4058 struct w32_display_info
*dpyinfo
= NULL
;
4064 /* Use this general default value to start with
4065 until we know if this frame has a specified name. */
4066 Vx_resource_name
= Vinvocation_name
;
4068 display
= w32_get_arg (parms
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
4069 if (EQ (display
, Qunbound
))
4071 dpyinfo
= check_x_display_info (display
);
4073 kb
= dpyinfo
->kboard
;
4075 kb
= &the_only_kboard
;
4078 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
4080 && ! EQ (name
, Qunbound
)
4082 error ("Invalid frame name--not a string or nil");
4085 Vx_resource_name
= name
;
4087 /* See if parent window is specified. */
4088 parent
= w32_get_arg (parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
4089 if (EQ (parent
, Qunbound
))
4091 if (! NILP (parent
))
4092 CHECK_NUMBER (parent
);
4094 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
4095 /* No need to protect DISPLAY because that's not used after passing
4096 it to make_frame_without_minibuffer. */
4098 GCPRO4 (parms
, parent
, name
, frame
);
4099 tem
= w32_get_arg (parms
, Qminibuffer
, "minibuffer", "Minibuffer",
4101 if (EQ (tem
, Qnone
) || NILP (tem
))
4102 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
4103 else if (EQ (tem
, Qonly
))
4105 f
= make_minibuffer_frame ();
4106 minibuffer_only
= 1;
4108 else if (WINDOWP (tem
))
4109 f
= make_frame_without_minibuffer (tem
, kb
, display
);
4113 XSETFRAME (frame
, f
);
4115 /* Note that Windows does support scroll bars. */
4116 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
4118 /* By default, make scrollbars the system standard width. */
4119 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
4121 f
->output_method
= output_w32
;
4122 f
->output_data
.w32
=
4123 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
4124 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
4125 FRAME_FONTSET (f
) = -1;
4126 record_unwind_protect (unwind_create_frame
, frame
);
4129 = w32_get_arg (parms
, Qicon_name
, "iconName", "Title", RES_TYPE_STRING
);
4130 if (! STRINGP (f
->icon_name
))
4131 f
->icon_name
= Qnil
;
4133 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
4135 FRAME_KBOARD (f
) = kb
;
4138 /* Specify the parent under which to make this window. */
4142 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
4143 f
->output_data
.w32
->explicit_parent
= 1;
4147 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4148 f
->output_data
.w32
->explicit_parent
= 0;
4151 /* Set the name; the functions to which we pass f expect the name to
4153 if (EQ (name
, Qunbound
) || NILP (name
))
4155 f
->name
= build_string (dpyinfo
->w32_id_name
);
4156 f
->explicit_name
= 0;
4161 f
->explicit_name
= 1;
4162 /* use the frame's title when getting resources for this frame. */
4163 specbind (Qx_resource_name
, name
);
4166 /* Extract the window parameters from the supplied values
4167 that are needed to determine window geometry. */
4171 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4174 /* First, try whatever font the caller has specified. */
4177 tem
= Fquery_fontset (font
, Qnil
);
4179 font
= x_new_fontset (f
, tem
);
4181 font
= x_new_font (f
, SDATA (font
));
4183 /* Try out a font which we hope has bold and italic variations. */
4184 if (!STRINGP (font
))
4185 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
4186 if (! STRINGP (font
))
4187 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
4188 /* If those didn't work, look for something which will at least work. */
4189 if (! STRINGP (font
))
4190 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
4192 if (! STRINGP (font
))
4193 font
= build_string ("Fixedsys");
4195 x_default_parameter (f
, parms
, Qfont
, font
,
4196 "font", "Font", RES_TYPE_STRING
);
4199 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
4200 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4201 /* This defaults to 2 in order to match xterm. We recognize either
4202 internalBorderWidth or internalBorder (which is what xterm calls
4204 if (NILP (Fassq (Qinternal_border_width
, parms
)))
4208 value
= w32_get_arg (parms
, Qinternal_border_width
,
4209 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
4210 if (! EQ (value
, Qunbound
))
4211 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
4214 /* Default internalBorderWidth to 0 on Windows to match other programs. */
4215 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (0),
4216 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
4217 x_default_parameter (f
, parms
, Qvertical_scroll_bars
, Qright
,
4218 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
4220 /* Also do the stuff which must be set before the window exists. */
4221 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
4222 "foreground", "Foreground", RES_TYPE_STRING
);
4223 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
4224 "background", "Background", RES_TYPE_STRING
);
4225 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
4226 "pointerColor", "Foreground", RES_TYPE_STRING
);
4227 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
4228 "cursorColor", "Foreground", RES_TYPE_STRING
);
4229 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
4230 "borderColor", "BorderColor", RES_TYPE_STRING
);
4231 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
4232 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
4233 x_default_parameter (f
, parms
, Qline_spacing
, Qnil
,
4234 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
4235 x_default_parameter (f
, parms
, Qleft_fringe
, Qnil
,
4236 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
4237 x_default_parameter (f
, parms
, Qright_fringe
, Qnil
,
4238 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
4241 /* Init faces before x_default_parameter is called for scroll-bar
4242 parameters because that function calls x_set_scroll_bar_width,
4243 which calls change_frame_size, which calls Fset_window_buffer,
4244 which runs hooks, which call Fvertical_motion. At the end, we
4245 end up in init_iterator with a null face cache, which should not
4247 init_frame_faces (f
);
4249 x_default_parameter (f
, parms
, Qmenu_bar_lines
, make_number (1),
4250 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
4251 x_default_parameter (f
, parms
, Qtool_bar_lines
, make_number (1),
4252 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
4254 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
4255 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
4256 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
4257 "title", "Title", RES_TYPE_STRING
);
4258 x_default_parameter (f
, parms
, Qfullscreen
, Qnil
,
4259 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
4261 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
4262 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4264 f
->output_data
.w32
->text_cursor
= w32_load_cursor (IDC_IBEAM
);
4265 f
->output_data
.w32
->nontext_cursor
= w32_load_cursor (IDC_ARROW
);
4266 f
->output_data
.w32
->modeline_cursor
= w32_load_cursor (IDC_ARROW
);
4267 f
->output_data
.w32
->hand_cursor
= w32_load_cursor (IDC_HAND
);
4268 f
->output_data
.w32
->hourglass_cursor
= w32_load_cursor (IDC_WAIT
);
4269 f
->output_data
.w32
->horizontal_drag_cursor
= w32_load_cursor (IDC_SIZEWE
);
4271 window_prompting
= x_figure_window_size (f
, parms
, 1);
4273 tem
= w32_get_arg (parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
4274 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
4276 w32_window (f
, window_prompting
, minibuffer_only
);
4281 /* Now consider the frame official. */
4282 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
4283 Vframe_list
= Fcons (frame
, Vframe_list
);
4285 /* We need to do this after creating the window, so that the
4286 icon-creation functions can say whose icon they're describing. */
4287 x_default_parameter (f
, parms
, Qicon_type
, Qnil
,
4288 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
4290 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
4291 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4292 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
4293 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4294 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
4295 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4296 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
4297 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
4299 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4300 Change will not be effected unless different from the current
4302 width
= FRAME_COLS (f
);
4303 height
= FRAME_LINES (f
);
4305 FRAME_LINES (f
) = 0;
4306 SET_FRAME_COLS (f
, 0);
4307 change_frame_size (f
, height
, width
, 1, 0, 0);
4309 /* Tell the server what size and position, etc, we want, and how
4310 badly we want them. This should be done after we have the menu
4311 bar so that its size can be taken into account. */
4313 x_wm_set_size_hint (f
, window_prompting
, 0);
4316 /* Avoid a bug that causes the new frame to never become visible if
4317 an echo area message is displayed during the following call1. */
4318 specbind(Qredisplay_dont_pause
, Qt
);
4320 /* Set up faces after all frame parameters are known. This call
4321 also merges in face attributes specified for new frames. If we
4322 don't do this, the `menu' face for instance won't have the right
4323 colors, and the menu bar won't appear in the specified colors for
4325 call1 (Qface_set_after_frame_default
, frame
);
4327 /* Make the window appear on the frame and enable display, unless
4328 the caller says not to. However, with explicit parent, Emacs
4329 cannot control visibility, so don't try. */
4330 if (! f
->output_data
.w32
->explicit_parent
)
4332 Lisp_Object visibility
;
4334 visibility
= w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
4335 if (EQ (visibility
, Qunbound
))
4338 if (EQ (visibility
, Qicon
))
4339 x_iconify_frame (f
);
4340 else if (! NILP (visibility
))
4341 x_make_frame_visible (f
);
4343 /* Must have been Qnil. */
4348 /* Make sure windows on this frame appear in calls to next-window
4349 and similar functions. */
4350 Vwindow_list
= Qnil
;
4352 return unbind_to (count
, frame
);
4355 /* FRAME is used only to get a handle on the X display. We don't pass the
4356 display info directly because we're called from frame.c, which doesn't
4357 know about that structure. */
4359 x_get_focus_frame (frame
)
4360 struct frame
*frame
;
4362 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
4364 if (! dpyinfo
->w32_focus_frame
)
4367 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
4371 DEFUN ("w32-focus-frame", Fw32_focus_frame
, Sw32_focus_frame
, 1, 1, 0,
4372 doc
: /* Give FRAME input focus, raising to foreground if necessary. */)
4376 x_focus_on_frame (check_x_frame (frame
));
4381 /* Return the charset portion of a font name. */
4382 char * xlfd_charset_of_font (char * fontname
)
4384 char *charset
, *encoding
;
4386 encoding
= strrchr(fontname
, '-');
4387 if (!encoding
|| encoding
== fontname
)
4390 for (charset
= encoding
- 1; charset
>= fontname
; charset
--)
4391 if (*charset
== '-')
4394 if (charset
== fontname
|| strcmp(charset
, "-*-*") == 0)
4400 struct font_info
*w32_load_bdf_font (struct frame
*f
, char *fontname
,
4401 int size
, char* filename
);
4402 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
);
4403 static BOOL
w32_to_x_font (LOGFONT
* lplf
, char * lpxstr
, int len
,
4405 static BOOL
x_to_w32_font (char *lpxstr
, LOGFONT
*lplogfont
);
4407 static struct font_info
*
4408 w32_load_system_font (f
,fontname
,size
)
4413 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4414 Lisp_Object font_names
;
4416 /* Get a list of all the fonts that match this name. Once we
4417 have a list of matching fonts, we compare them against the fonts
4418 we already have loaded by comparing names. */
4419 font_names
= w32_list_fonts (f
, build_string (fontname
), size
, 100);
4421 if (!NILP (font_names
))
4426 /* First check if any are already loaded, as that is cheaper
4427 than loading another one. */
4428 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
4429 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
4430 if (dpyinfo
->font_table
[i
].name
4431 && (!strcmp (dpyinfo
->font_table
[i
].name
,
4432 SDATA (XCAR (tail
)))
4433 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
4434 SDATA (XCAR (tail
)))))
4435 return (dpyinfo
->font_table
+ i
);
4437 fontname
= (char *) SDATA (XCAR (font_names
));
4439 else if (w32_strict_fontnames
)
4441 /* If EnumFontFamiliesEx was available, we got a full list of
4442 fonts back so stop now to avoid the possibility of loading a
4443 random font. If we had to fall back to EnumFontFamilies, the
4444 list is incomplete, so continue whether the font we want was
4446 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
4447 FARPROC enum_font_families_ex
4448 = GetProcAddress (gdi32
, "EnumFontFamiliesExA");
4449 if (enum_font_families_ex
)
4453 /* Load the font and add it to the table. */
4455 char *full_name
, *encoding
, *charset
;
4457 struct font_info
*fontp
;
4463 if (!fontname
|| !x_to_w32_font (fontname
, &lf
))
4466 if (!*lf
.lfFaceName
)
4467 /* If no name was specified for the font, we get a random font
4468 from CreateFontIndirect - this is not particularly
4469 desirable, especially since CreateFontIndirect does not
4470 fill out the missing name in lf, so we never know what we
4474 lf
.lfQuality
= DEFAULT_QUALITY
;
4476 font
= (XFontStruct
*) xmalloc (sizeof (XFontStruct
));
4477 bzero (font
, sizeof (*font
));
4479 /* Set bdf to NULL to indicate that this is a Windows font. */
4484 font
->hfont
= CreateFontIndirect (&lf
);
4486 if (font
->hfont
== NULL
)
4495 codepage
= w32_codepage_for_font (fontname
);
4497 hdc
= GetDC (dpyinfo
->root_window
);
4498 oldobj
= SelectObject (hdc
, font
->hfont
);
4500 ok
= GetTextMetrics (hdc
, &font
->tm
);
4501 if (codepage
== CP_UNICODE
)
4502 font
->double_byte_p
= 1;
4505 /* Unfortunately, some fonts (eg. MingLiU, a big5 ttf font)
4506 don't report themselves as double byte fonts, when
4507 patently they are. So instead of trusting
4508 GetFontLanguageInfo, we check the properties of the
4509 codepage directly, since that is ultimately what we are
4510 working from anyway. */
4511 /* font->double_byte_p = GetFontLanguageInfo(hdc) & GCP_DBCS; */
4513 GetCPInfo (codepage
, &cpi
);
4514 font
->double_byte_p
= cpi
.MaxCharSize
> 1;
4517 SelectObject (hdc
, oldobj
);
4518 ReleaseDC (dpyinfo
->root_window
, hdc
);
4519 /* Fill out details in lf according to the font that was
4521 lf
.lfHeight
= font
->tm
.tmInternalLeading
- font
->tm
.tmHeight
;
4522 lf
.lfWidth
= font
->tm
.tmAveCharWidth
;
4523 lf
.lfWeight
= font
->tm
.tmWeight
;
4524 lf
.lfItalic
= font
->tm
.tmItalic
;
4525 lf
.lfCharSet
= font
->tm
.tmCharSet
;
4526 lf
.lfPitchAndFamily
= ((font
->tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
)
4527 ? VARIABLE_PITCH
: FIXED_PITCH
);
4528 lf
.lfOutPrecision
= ((font
->tm
.tmPitchAndFamily
& TMPF_VECTOR
)
4529 ? OUT_STROKE_PRECIS
: OUT_STRING_PRECIS
);
4531 w32_cache_char_metrics (font
);
4538 w32_unload_font (dpyinfo
, font
);
4542 /* Find a free slot in the font table. */
4543 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
4544 if (dpyinfo
->font_table
[i
].name
== NULL
)
4547 /* If no free slot found, maybe enlarge the font table. */
4548 if (i
== dpyinfo
->n_fonts
4549 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
4552 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
4553 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
4555 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
4558 fontp
= dpyinfo
->font_table
+ i
;
4559 if (i
== dpyinfo
->n_fonts
)
4562 /* Now fill in the slots of *FONTP. */
4564 bzero (fontp
, sizeof (*fontp
));
4566 fontp
->font_idx
= i
;
4567 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
4568 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
4570 fontp
->charset
= -1;
4571 charset
= xlfd_charset_of_font (fontname
);
4573 /* Cache the W32 codepage for a font. This makes w32_encode_char
4574 (called for every glyph during redisplay) much faster. */
4575 fontp
->codepage
= codepage
;
4577 /* Work out the font's full name. */
4578 full_name
= (char *)xmalloc (100);
4579 if (full_name
&& w32_to_x_font (&lf
, full_name
, 100, charset
))
4580 fontp
->full_name
= full_name
;
4583 /* If all else fails - just use the name we used to load it. */
4585 fontp
->full_name
= fontp
->name
;
4588 fontp
->size
= FONT_WIDTH (font
);
4589 fontp
->height
= FONT_HEIGHT (font
);
4591 /* The slot `encoding' specifies how to map a character
4592 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
4593 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
4594 (0:0x20..0x7F, 1:0xA0..0xFF,
4595 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
4596 2:0xA020..0xFF7F). For the moment, we don't know which charset
4597 uses this font. So, we set information in fontp->encoding_type
4598 which is never used by any charset. If mapping can't be
4599 decided, set FONT_ENCODING_NOT_DECIDED. */
4601 /* SJIS fonts need to be set to type 4, all others seem to work as
4602 type FONT_ENCODING_NOT_DECIDED. */
4603 encoding
= strrchr (fontp
->name
, '-');
4604 if (encoding
&& strnicmp (encoding
+1, "sjis", 4) == 0)
4605 fontp
->encoding_type
= 4;
4607 fontp
->encoding_type
= FONT_ENCODING_NOT_DECIDED
;
4609 /* The following three values are set to 0 under W32, which is
4610 what they get set to if XGetFontProperty fails under X. */
4611 fontp
->baseline_offset
= 0;
4612 fontp
->relative_compose
= 0;
4613 fontp
->default_ascent
= 0;
4615 /* Set global flag fonts_changed_p to non-zero if the font loaded
4616 has a character with a smaller width than any other character
4617 before, or if the font loaded has a smaller height than any
4618 other font loaded before. If this happens, it will make a
4619 glyph matrix reallocation necessary. */
4620 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
4626 /* Load font named FONTNAME of size SIZE for frame F, and return a
4627 pointer to the structure font_info while allocating it dynamically.
4628 If loading fails, return NULL. */
4630 w32_load_font (f
,fontname
,size
)
4635 Lisp_Object bdf_fonts
;
4636 struct font_info
*retval
= NULL
;
4638 bdf_fonts
= w32_list_bdf_fonts (build_string (fontname
), 1);
4640 while (!retval
&& CONSP (bdf_fonts
))
4642 char *bdf_name
, *bdf_file
;
4643 Lisp_Object bdf_pair
;
4645 bdf_name
= SDATA (XCAR (bdf_fonts
));
4646 bdf_pair
= Fassoc (XCAR (bdf_fonts
), Vw32_bdf_filename_alist
);
4647 bdf_file
= SDATA (XCDR (bdf_pair
));
4649 retval
= w32_load_bdf_font (f
, bdf_name
, size
, bdf_file
);
4651 bdf_fonts
= XCDR (bdf_fonts
);
4657 return w32_load_system_font(f
, fontname
, size
);
4662 w32_unload_font (dpyinfo
, font
)
4663 struct w32_display_info
*dpyinfo
;
4668 if (font
->per_char
) xfree (font
->per_char
);
4669 if (font
->bdf
) w32_free_bdf_font (font
->bdf
);
4671 if (font
->hfont
) DeleteObject(font
->hfont
);
4676 /* The font conversion stuff between x and w32 */
4678 /* X font string is as follows (from faces.el)
4682 * (weight "\\(bold\\|demibold\\|medium\\)") ; 1
4683 * (weight\? "\\([^-]*\\)") ; 1
4684 * (slant "\\([ior]\\)") ; 2
4685 * (slant\? "\\([^-]?\\)") ; 2
4686 * (swidth "\\([^-]*\\)") ; 3
4687 * (adstyle "[^-]*") ; 4
4688 * (pixelsize "[0-9]+")
4689 * (pointsize "[0-9][0-9]+")
4690 * (resx "[0-9][0-9]+")
4691 * (resy "[0-9][0-9]+")
4692 * (spacing "[cmp?*]")
4693 * (avgwidth "[0-9]+")
4694 * (registry "[^-]+")
4695 * (encoding "[^-]+")
4700 x_to_w32_weight (lpw
)
4703 if (!lpw
) return (FW_DONTCARE
);
4705 if (stricmp (lpw
,"heavy") == 0) return FW_HEAVY
;
4706 else if (stricmp (lpw
,"extrabold") == 0) return FW_EXTRABOLD
;
4707 else if (stricmp (lpw
,"bold") == 0) return FW_BOLD
;
4708 else if (stricmp (lpw
,"demibold") == 0) return FW_SEMIBOLD
;
4709 else if (stricmp (lpw
,"semibold") == 0) return FW_SEMIBOLD
;
4710 else if (stricmp (lpw
,"medium") == 0) return FW_MEDIUM
;
4711 else if (stricmp (lpw
,"normal") == 0) return FW_NORMAL
;
4712 else if (stricmp (lpw
,"light") == 0) return FW_LIGHT
;
4713 else if (stricmp (lpw
,"extralight") == 0) return FW_EXTRALIGHT
;
4714 else if (stricmp (lpw
,"thin") == 0) return FW_THIN
;
4721 w32_to_x_weight (fnweight
)
4724 if (fnweight
>= FW_HEAVY
) return "heavy";
4725 if (fnweight
>= FW_EXTRABOLD
) return "extrabold";
4726 if (fnweight
>= FW_BOLD
) return "bold";
4727 if (fnweight
>= FW_SEMIBOLD
) return "demibold";
4728 if (fnweight
>= FW_MEDIUM
) return "medium";
4729 if (fnweight
>= FW_NORMAL
) return "normal";
4730 if (fnweight
>= FW_LIGHT
) return "light";
4731 if (fnweight
>= FW_EXTRALIGHT
) return "extralight";
4732 if (fnweight
>= FW_THIN
) return "thin";
4738 x_to_w32_charset (lpcs
)
4741 Lisp_Object this_entry
, w32_charset
;
4743 int len
= strlen (lpcs
);
4745 /* Support "*-#nnn" format for unknown charsets. */
4746 if (strncmp (lpcs
, "*-#", 3) == 0)
4747 return atoi (lpcs
+ 3);
4749 /* All Windows fonts qualify as unicode. */
4750 if (!strncmp (lpcs
, "iso10646", 8))
4751 return DEFAULT_CHARSET
;
4753 /* Handle wildcards by ignoring them; eg. treat "big5*-*" as "big5". */
4754 charset
= alloca (len
+ 1);
4755 strcpy (charset
, lpcs
);
4756 lpcs
= strchr (charset
, '*');
4760 /* Look through w32-charset-info-alist for the character set.
4761 Format of each entry is
4762 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
4764 this_entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
4766 if (NILP(this_entry
))
4768 /* At startup, we want iso8859-1 fonts to come up properly. */
4769 if (stricmp(charset
, "iso8859-1") == 0)
4770 return ANSI_CHARSET
;
4772 return DEFAULT_CHARSET
;
4775 w32_charset
= Fcar (Fcdr (this_entry
));
4777 /* Translate Lisp symbol to number. */
4778 if (w32_charset
== Qw32_charset_ansi
)
4779 return ANSI_CHARSET
;
4780 if (w32_charset
== Qw32_charset_symbol
)
4781 return SYMBOL_CHARSET
;
4782 if (w32_charset
== Qw32_charset_shiftjis
)
4783 return SHIFTJIS_CHARSET
;
4784 if (w32_charset
== Qw32_charset_hangeul
)
4785 return HANGEUL_CHARSET
;
4786 if (w32_charset
== Qw32_charset_chinesebig5
)
4787 return CHINESEBIG5_CHARSET
;
4788 if (w32_charset
== Qw32_charset_gb2312
)
4789 return GB2312_CHARSET
;
4790 if (w32_charset
== Qw32_charset_oem
)
4792 #ifdef JOHAB_CHARSET
4793 if (w32_charset
== Qw32_charset_johab
)
4794 return JOHAB_CHARSET
;
4795 if (w32_charset
== Qw32_charset_easteurope
)
4796 return EASTEUROPE_CHARSET
;
4797 if (w32_charset
== Qw32_charset_turkish
)
4798 return TURKISH_CHARSET
;
4799 if (w32_charset
== Qw32_charset_baltic
)
4800 return BALTIC_CHARSET
;
4801 if (w32_charset
== Qw32_charset_russian
)
4802 return RUSSIAN_CHARSET
;
4803 if (w32_charset
== Qw32_charset_arabic
)
4804 return ARABIC_CHARSET
;
4805 if (w32_charset
== Qw32_charset_greek
)
4806 return GREEK_CHARSET
;
4807 if (w32_charset
== Qw32_charset_hebrew
)
4808 return HEBREW_CHARSET
;
4809 if (w32_charset
== Qw32_charset_vietnamese
)
4810 return VIETNAMESE_CHARSET
;
4811 if (w32_charset
== Qw32_charset_thai
)
4812 return THAI_CHARSET
;
4813 if (w32_charset
== Qw32_charset_mac
)
4815 #endif /* JOHAB_CHARSET */
4816 #ifdef UNICODE_CHARSET
4817 if (w32_charset
== Qw32_charset_unicode
)
4818 return UNICODE_CHARSET
;
4821 return DEFAULT_CHARSET
;
4826 w32_to_x_charset (fncharset
, matching
)
4830 static char buf
[32];
4831 Lisp_Object charset_type
;
4836 /* If fully specified, accept it as it is. Otherwise use a
4838 char *wildcard
= strchr (matching
, '*');
4841 else if (strchr (matching
, '-'))
4844 match_len
= strlen (matching
);
4850 /* Handle startup case of w32-charset-info-alist not
4851 being set up yet. */
4852 if (NILP(Vw32_charset_info_alist
))
4854 charset_type
= Qw32_charset_ansi
;
4856 case DEFAULT_CHARSET
:
4857 charset_type
= Qw32_charset_default
;
4859 case SYMBOL_CHARSET
:
4860 charset_type
= Qw32_charset_symbol
;
4862 case SHIFTJIS_CHARSET
:
4863 charset_type
= Qw32_charset_shiftjis
;
4865 case HANGEUL_CHARSET
:
4866 charset_type
= Qw32_charset_hangeul
;
4868 case GB2312_CHARSET
:
4869 charset_type
= Qw32_charset_gb2312
;
4871 case CHINESEBIG5_CHARSET
:
4872 charset_type
= Qw32_charset_chinesebig5
;
4875 charset_type
= Qw32_charset_oem
;
4878 /* More recent versions of Windows (95 and NT4.0) define more
4880 #ifdef EASTEUROPE_CHARSET
4881 case EASTEUROPE_CHARSET
:
4882 charset_type
= Qw32_charset_easteurope
;
4884 case TURKISH_CHARSET
:
4885 charset_type
= Qw32_charset_turkish
;
4887 case BALTIC_CHARSET
:
4888 charset_type
= Qw32_charset_baltic
;
4890 case RUSSIAN_CHARSET
:
4891 charset_type
= Qw32_charset_russian
;
4893 case ARABIC_CHARSET
:
4894 charset_type
= Qw32_charset_arabic
;
4897 charset_type
= Qw32_charset_greek
;
4899 case HEBREW_CHARSET
:
4900 charset_type
= Qw32_charset_hebrew
;
4902 case VIETNAMESE_CHARSET
:
4903 charset_type
= Qw32_charset_vietnamese
;
4906 charset_type
= Qw32_charset_thai
;
4909 charset_type
= Qw32_charset_mac
;
4912 charset_type
= Qw32_charset_johab
;
4916 #ifdef UNICODE_CHARSET
4917 case UNICODE_CHARSET
:
4918 charset_type
= Qw32_charset_unicode
;
4922 /* Encode numerical value of unknown charset. */
4923 sprintf (buf
, "*-#%u", fncharset
);
4929 char * best_match
= NULL
;
4930 int matching_found
= 0;
4932 /* Look through w32-charset-info-alist for the character set.
4933 Prefer ISO codepages, and prefer lower numbers in the ISO
4934 range. Only return charsets for codepages which are installed.
4936 Format of each entry is
4937 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
4939 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
4942 Lisp_Object w32_charset
;
4943 Lisp_Object codepage
;
4945 Lisp_Object this_entry
= XCAR (rest
);
4947 /* Skip invalid entries in alist. */
4948 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
4949 || !CONSP (XCDR (this_entry
))
4950 || !SYMBOLP (XCAR (XCDR (this_entry
))))
4953 x_charset
= SDATA (XCAR (this_entry
));
4954 w32_charset
= XCAR (XCDR (this_entry
));
4955 codepage
= XCDR (XCDR (this_entry
));
4957 /* Look for Same charset and a valid codepage (or non-int
4958 which means ignore). */
4959 if (w32_charset
== charset_type
4960 && (!INTEGERP (codepage
) || codepage
== CP_DEFAULT
4961 || IsValidCodePage (XINT (codepage
))))
4963 /* If we don't have a match already, then this is the
4967 best_match
= x_charset
;
4968 if (matching
&& !strnicmp (x_charset
, matching
, match_len
))
4971 /* If we already found a match for MATCHING, then
4972 only consider other matches. */
4973 else if (matching_found
4974 && strnicmp (x_charset
, matching
, match_len
))
4976 /* If this matches what we want, and the best so far doesn't,
4977 then this is better. */
4978 else if (!matching_found
&& matching
4979 && !strnicmp (x_charset
, matching
, match_len
))
4981 best_match
= x_charset
;
4984 /* If this is fully specified, and the best so far isn't,
4985 then this is better. */
4986 else if ((!strchr (best_match
, '-') && strchr (x_charset
, '-'))
4987 /* If this is an ISO codepage, and the best so far isn't,
4988 then this is better, but only if it fully specifies the
4990 || (strnicmp (best_match
, "iso", 3) != 0
4991 && strnicmp (x_charset
, "iso", 3) == 0
4992 && strchr (x_charset
, '-')))
4993 best_match
= x_charset
;
4994 /* If both are ISO8859 codepages, choose the one with the
4995 lowest number in the encoding field. */
4996 else if (strnicmp (best_match
, "iso8859-", 8) == 0
4997 && strnicmp (x_charset
, "iso8859-", 8) == 0)
4999 int best_enc
= atoi (best_match
+ 8);
5000 int this_enc
= atoi (x_charset
+ 8);
5001 if (this_enc
> 0 && this_enc
< best_enc
)
5002 best_match
= x_charset
;
5007 /* If no match, encode the numeric value. */
5010 sprintf (buf
, "*-#%u", fncharset
);
5014 strncpy (buf
, best_match
, 31);
5015 /* If the charset is not fully specified, put -0 on the end. */
5016 if (!strchr (best_match
, '-'))
5018 int pos
= strlen (best_match
);
5019 /* Charset specifiers shouldn't be very long. If it is a made
5020 up one, truncating it should not do any harm since it isn't
5021 recognized anyway. */
5024 strcpy (buf
+ pos
, "-0");
5032 /* Return all the X charsets that map to a font. */
5034 w32_to_all_x_charsets (fncharset
)
5037 static char buf
[32];
5038 Lisp_Object charset_type
;
5039 Lisp_Object retval
= Qnil
;
5044 /* Handle startup case of w32-charset-info-alist not
5045 being set up yet. */
5046 if (NILP(Vw32_charset_info_alist
))
5047 return Fcons (build_string ("iso8859-1"), Qnil
);
5049 charset_type
= Qw32_charset_ansi
;
5051 case DEFAULT_CHARSET
:
5052 charset_type
= Qw32_charset_default
;
5054 case SYMBOL_CHARSET
:
5055 charset_type
= Qw32_charset_symbol
;
5057 case SHIFTJIS_CHARSET
:
5058 charset_type
= Qw32_charset_shiftjis
;
5060 case HANGEUL_CHARSET
:
5061 charset_type
= Qw32_charset_hangeul
;
5063 case GB2312_CHARSET
:
5064 charset_type
= Qw32_charset_gb2312
;
5066 case CHINESEBIG5_CHARSET
:
5067 charset_type
= Qw32_charset_chinesebig5
;
5070 charset_type
= Qw32_charset_oem
;
5073 /* More recent versions of Windows (95 and NT4.0) define more
5075 #ifdef EASTEUROPE_CHARSET
5076 case EASTEUROPE_CHARSET
:
5077 charset_type
= Qw32_charset_easteurope
;
5079 case TURKISH_CHARSET
:
5080 charset_type
= Qw32_charset_turkish
;
5082 case BALTIC_CHARSET
:
5083 charset_type
= Qw32_charset_baltic
;
5085 case RUSSIAN_CHARSET
:
5086 charset_type
= Qw32_charset_russian
;
5088 case ARABIC_CHARSET
:
5089 charset_type
= Qw32_charset_arabic
;
5092 charset_type
= Qw32_charset_greek
;
5094 case HEBREW_CHARSET
:
5095 charset_type
= Qw32_charset_hebrew
;
5097 case VIETNAMESE_CHARSET
:
5098 charset_type
= Qw32_charset_vietnamese
;
5101 charset_type
= Qw32_charset_thai
;
5104 charset_type
= Qw32_charset_mac
;
5107 charset_type
= Qw32_charset_johab
;
5111 #ifdef UNICODE_CHARSET
5112 case UNICODE_CHARSET
:
5113 charset_type
= Qw32_charset_unicode
;
5117 /* Encode numerical value of unknown charset. */
5118 sprintf (buf
, "*-#%u", fncharset
);
5119 return Fcons (build_string (buf
), Qnil
);
5124 /* Look through w32-charset-info-alist for the character set.
5125 Only return fully specified charsets for codepages which are
5128 Format of each entry in Vw32_charset_info_alist is
5129 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5131 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
5133 Lisp_Object x_charset
;
5134 Lisp_Object w32_charset
;
5135 Lisp_Object codepage
;
5137 Lisp_Object this_entry
= XCAR (rest
);
5139 /* Skip invalid entries in alist. */
5140 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
5141 || !CONSP (XCDR (this_entry
))
5142 || !SYMBOLP (XCAR (XCDR (this_entry
))))
5145 x_charset
= XCAR (this_entry
);
5146 w32_charset
= XCAR (XCDR (this_entry
));
5147 codepage
= XCDR (XCDR (this_entry
));
5149 if (!strchr (SDATA (x_charset
), '-'))
5152 /* Look for Same charset and a valid codepage (or non-int
5153 which means ignore). */
5154 if (w32_charset
== charset_type
5155 && (!INTEGERP (codepage
) || codepage
== CP_DEFAULT
5156 || IsValidCodePage (XINT (codepage
))))
5158 retval
= Fcons (x_charset
, retval
);
5162 /* If no match, encode the numeric value. */
5165 sprintf (buf
, "*-#%u", fncharset
);
5166 return Fcons (build_string (buf
), Qnil
);
5173 /* Get the Windows codepage corresponding to the specified font. The
5174 charset info in the font name is used to look up
5175 w32-charset-to-codepage-alist. */
5177 w32_codepage_for_font (char *fontname
)
5179 Lisp_Object codepage
, entry
;
5180 char *charset_str
, *charset
, *end
;
5182 /* Extract charset part of font string. */
5183 charset
= xlfd_charset_of_font (fontname
);
5188 charset_str
= (char *) alloca (strlen (charset
) + 1);
5189 strcpy (charset_str
, charset
);
5192 /* Remove leading "*-". */
5193 if (strncmp ("*-", charset_str
, 2) == 0)
5194 charset
= charset_str
+ 2;
5197 charset
= charset_str
;
5199 /* Stop match at wildcard (including preceding '-'). */
5200 if (end
= strchr (charset
, '*'))
5202 if (end
> charset
&& *(end
-1) == '-')
5207 if (!strcmp (charset
, "iso10646"))
5210 if (NILP (Vw32_charset_info_alist
))
5213 entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
5217 codepage
= Fcdr (Fcdr (entry
));
5219 if (NILP (codepage
))
5221 else if (XFASTINT (codepage
) == XFASTINT (Qt
))
5223 else if (INTEGERP (codepage
))
5224 return XINT (codepage
);
5231 w32_to_x_font (lplogfont
, lpxstr
, len
, specific_charset
)
5232 LOGFONT
* lplogfont
;
5235 char * specific_charset
;
5239 char height_pixels
[8];
5241 char width_pixels
[8];
5242 char *fontname_dash
;
5243 int display_resy
= (int) one_w32_display_info
.resy
;
5244 int display_resx
= (int) one_w32_display_info
.resx
;
5245 struct coding_system coding
;
5247 if (!lpxstr
) abort ();
5252 if (lplogfont
->lfOutPrecision
== OUT_STRING_PRECIS
)
5253 fonttype
= "raster";
5254 else if (lplogfont
->lfOutPrecision
== OUT_STROKE_PRECIS
)
5255 fonttype
= "outline";
5257 fonttype
= "unknown";
5259 setup_coding_system (Fcheck_coding_system (Vlocale_coding_system
),
5261 coding
.src_multibyte
= 0;
5262 coding
.dst_multibyte
= 1;
5263 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
5264 /* We explicitely disable composition handling because selection
5265 data should not contain any composition sequence. */
5266 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
5268 coding
.dst_bytes
= LF_FACESIZE
* 2;
5269 coding
.destination
= (unsigned char *) xmalloc (coding
.dst_bytes
+ 1);
5270 decode_coding_c_string (&coding
, lplogfont
->lfFaceName
,
5271 strlen(lplogfont
->lfFaceName
), Qnil
);
5272 fontname
= coding
.destination
;
5274 *(fontname
+ coding
.produced
) = '\0';
5276 /* Replace dashes with underscores so the dashes are not
5278 fontname_dash
= fontname
;
5279 while (fontname_dash
= strchr (fontname_dash
, '-'))
5280 *fontname_dash
= '_';
5282 if (lplogfont
->lfHeight
)
5284 sprintf (height_pixels
, "%u", abs (lplogfont
->lfHeight
));
5285 sprintf (height_dpi
, "%u",
5286 abs (lplogfont
->lfHeight
) * 720 / display_resy
);
5290 strcpy (height_pixels
, "*");
5291 strcpy (height_dpi
, "*");
5293 if (lplogfont
->lfWidth
)
5294 sprintf (width_pixels
, "%u", lplogfont
->lfWidth
* 10);
5296 strcpy (width_pixels
, "*");
5298 _snprintf (lpxstr
, len
- 1,
5299 "-%s-%s-%s-%c-normal-normal-%s-%s-%d-%d-%c-%s-%s",
5300 fonttype
, /* foundry */
5301 fontname
, /* family */
5302 w32_to_x_weight (lplogfont
->lfWeight
), /* weight */
5303 lplogfont
->lfItalic
?'i':'r', /* slant */
5305 /* add style name */
5306 height_pixels
, /* pixel size */
5307 height_dpi
, /* point size */
5308 display_resx
, /* resx */
5309 display_resy
, /* resy */
5310 ((lplogfont
->lfPitchAndFamily
& 0x3) == VARIABLE_PITCH
)
5311 ? 'p' : 'c', /* spacing */
5312 width_pixels
, /* avg width */
5313 w32_to_x_charset (lplogfont
->lfCharSet
, specific_charset
)
5314 /* charset registry and encoding */
5317 lpxstr
[len
- 1] = 0; /* just to be sure */
5322 x_to_w32_font (lpxstr
, lplogfont
)
5324 LOGFONT
* lplogfont
;
5326 struct coding_system coding
;
5328 if (!lplogfont
) return (FALSE
);
5330 memset (lplogfont
, 0, sizeof (*lplogfont
));
5332 /* Set default value for each field. */
5334 lplogfont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
5335 lplogfont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
5336 lplogfont
->lfQuality
= DEFAULT_QUALITY
;
5338 /* go for maximum quality */
5339 lplogfont
->lfOutPrecision
= OUT_STROKE_PRECIS
;
5340 lplogfont
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
5341 lplogfont
->lfQuality
= PROOF_QUALITY
;
5344 lplogfont
->lfCharSet
= DEFAULT_CHARSET
;
5345 lplogfont
->lfWeight
= FW_DONTCARE
;
5346 lplogfont
->lfPitchAndFamily
= DEFAULT_PITCH
| FF_DONTCARE
;
5351 /* Provide a simple escape mechanism for specifying Windows font names
5352 * directly -- if font spec does not beginning with '-', assume this
5354 * "<font name>[:height in pixels[:width in pixels[:weight]]]"
5360 char name
[50], weight
[20], slant
, pitch
, pixels
[10], height
[10],
5361 width
[10], resy
[10], remainder
[50];
5363 int dpi
= (int) one_w32_display_info
.resy
;
5365 fields
= sscanf (lpxstr
,
5366 "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%49s",
5367 name
, weight
, &slant
, pixels
, height
, resy
, &pitch
, width
, remainder
);
5371 /* In the general case when wildcards cover more than one field,
5372 we don't know which field is which, so don't fill any in.
5373 However, we need to cope with this particular form, which is
5374 generated by font_list_1 (invoked by try_font_list):
5375 "-raster-6x10-*-gb2312*-*"
5376 and make sure to correctly parse the charset field. */
5379 fields
= sscanf (lpxstr
,
5380 "-%*[^-]-%49[^-]-*-%49s",
5383 else if (fields
< 9)
5389 if (fields
> 0 && name
[0] != '*')
5392 (Fcheck_coding_system (Vlocale_coding_system
), &coding
);
5393 coding
.src_multibyte
= 1;
5394 coding
.dst_multibyte
= 1;
5395 coding
.dst_bytes
= strlen (name
) * 2;
5396 coding
.destination
= (unsigned char *) xmalloc (coding
.dst_bytes
);
5397 /* Disable composition/charset annotation. */
5398 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
5399 if (coding
.type
== coding_type_iso2022
)
5400 coding
.flags
|= CODING_FLAG_ISO_SAFE
;
5401 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
5402 encode_coding_object (&coding
, build_string (name
), 0, 0,
5403 strlen (name
), coding
.dst_bytes
, Qnil
);
5404 if (coding
.produced
>= LF_FACESIZE
)
5405 coding
.produced
= LF_FACESIZE
- 1;
5407 coding
.destination
[coding
.produced
] = '\0';
5409 strcpy (lplogfont
->lfFaceName
, coding
.destination
);
5410 xfree (coding
.destination
);
5414 lplogfont
->lfFaceName
[0] = '\0';
5419 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
5423 lplogfont
->lfItalic
= (fields
> 0 && slant
== 'i');
5427 if (fields
> 0 && pixels
[0] != '*')
5428 lplogfont
->lfHeight
= atoi (pixels
);
5432 if (fields
> 0 && resy
[0] != '*')
5435 if (tem
> 0) dpi
= tem
;
5438 if (fields
> -1 && lplogfont
->lfHeight
== 0 && height
[0] != '*')
5439 lplogfont
->lfHeight
= atoi (height
) * dpi
/ 720;
5442 lplogfont
->lfPitchAndFamily
=
5443 (fields
> 0 && pitch
== 'p') ? VARIABLE_PITCH
: FIXED_PITCH
;
5447 if (fields
> 0 && width
[0] != '*')
5448 lplogfont
->lfWidth
= atoi (width
) / 10;
5452 /* Strip the trailing '-' if present. (it shouldn't be, as it
5453 fails the test against xlfd-tight-regexp in fontset.el). */
5455 int len
= strlen (remainder
);
5456 if (len
> 0 && remainder
[len
-1] == '-')
5457 remainder
[len
-1] = 0;
5459 encoding
= remainder
;
5461 if (strncmp (encoding
, "*-", 2) == 0)
5464 lplogfont
->lfCharSet
= x_to_w32_charset (encoding
);
5469 char name
[100], height
[10], width
[10], weight
[20];
5471 fields
= sscanf (lpxstr
,
5472 "%99[^:]:%9[^:]:%9[^:]:%19s",
5473 name
, height
, width
, weight
);
5475 if (fields
== EOF
) return (FALSE
);
5479 strncpy (lplogfont
->lfFaceName
,name
, LF_FACESIZE
);
5480 lplogfont
->lfFaceName
[LF_FACESIZE
-1] = 0;
5484 lplogfont
->lfFaceName
[0] = 0;
5490 lplogfont
->lfHeight
= atoi (height
);
5495 lplogfont
->lfWidth
= atoi (width
);
5499 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
5502 /* This makes TrueType fonts work better. */
5503 lplogfont
->lfHeight
= - abs (lplogfont
->lfHeight
);
5508 /* Strip the pixel height and point height from the given xlfd, and
5509 return the pixel height. If no pixel height is specified, calculate
5510 one from the point height, or if that isn't defined either, return
5511 0 (which usually signifies a scalable font).
5514 xlfd_strip_height (char *fontname
)
5516 int pixel_height
, field_number
;
5517 char *read_from
, *write_to
;
5521 pixel_height
= field_number
= 0;
5524 /* Look for height fields. */
5525 for (read_from
= fontname
; *read_from
; read_from
++)
5527 if (*read_from
== '-')
5530 if (field_number
== 7) /* Pixel height. */
5533 write_to
= read_from
;
5535 /* Find end of field. */
5536 for (;*read_from
&& *read_from
!= '-'; read_from
++)
5539 /* Split the fontname at end of field. */
5545 pixel_height
= atoi (write_to
);
5546 /* Blank out field. */
5547 if (read_from
> write_to
)
5552 /* If the pixel height field is at the end (partial xlfd),
5555 return pixel_height
;
5557 /* If we got a pixel height, the point height can be
5558 ignored. Just blank it out and break now. */
5561 /* Find end of point size field. */
5562 for (; *read_from
&& *read_from
!= '-'; read_from
++)
5568 /* Blank out the point size field. */
5569 if (read_from
> write_to
)
5575 return pixel_height
;
5579 /* If the point height is already blank, break now. */
5580 if (*read_from
== '-')
5586 else if (field_number
== 8)
5588 /* If we didn't get a pixel height, try to get the point
5589 height and convert that. */
5591 char *point_size_start
= read_from
++;
5593 /* Find end of field. */
5594 for (; *read_from
&& *read_from
!= '-'; read_from
++)
5603 point_size
= atoi (point_size_start
);
5605 /* Convert to pixel height. */
5606 pixel_height
= point_size
5607 * one_w32_display_info
.height_in
/ 720;
5609 /* Blank out this field and break. */
5617 /* Shift the rest of the font spec into place. */
5618 if (write_to
&& read_from
> write_to
)
5620 for (; *read_from
; read_from
++, write_to
++)
5621 *write_to
= *read_from
;
5625 return pixel_height
;
5628 /* Assume parameter 1 is fully qualified, no wildcards. */
5630 w32_font_match (fontname
, pattern
)
5634 char *regex
= alloca (strlen (pattern
) * 2 + 3);
5635 char *font_name_copy
= alloca (strlen (fontname
) + 1);
5638 /* Copy fontname so we can modify it during comparison. */
5639 strcpy (font_name_copy
, fontname
);
5644 /* Turn pattern into a regexp and do a regexp match. */
5645 for (; *pattern
; pattern
++)
5647 if (*pattern
== '?')
5649 else if (*pattern
== '*')
5660 /* Strip out font heights and compare them seperately, since
5661 rounding error can cause mismatches. This also allows a
5662 comparison between a font that declares only a pixel height and a
5663 pattern that declares the point height.
5666 int font_height
, pattern_height
;
5668 font_height
= xlfd_strip_height (font_name_copy
);
5669 pattern_height
= xlfd_strip_height (regex
);
5671 /* Compare now, and don't bother doing expensive regexp matching
5672 if the heights differ. */
5673 if (font_height
&& pattern_height
&& (font_height
!= pattern_height
))
5677 return (fast_c_string_match_ignore_case (build_string (regex
),
5678 font_name_copy
) >= 0);
5681 /* Callback functions, and a structure holding info they need, for
5682 listing system fonts on W32. We need one set of functions to do the
5683 job properly, but these don't work on NT 3.51 and earlier, so we
5684 have a second set which don't handle character sets properly to
5687 In both cases, there are two passes made. The first pass gets one
5688 font from each family, the second pass lists all the fonts from
5691 typedef struct enumfont_t
5696 XFontStruct
*size_ref
;
5697 Lisp_Object pattern
;
5703 enum_font_maybe_add_to_list (enumfont_t
*, LOGFONT
*, char *, Lisp_Object
);
5707 enum_font_cb2 (lplf
, lptm
, FontType
, lpef
)
5709 NEWTEXTMETRIC
* lptm
;
5713 /* Ignore struck out and underlined versions of fonts. */
5714 if (lplf
->elfLogFont
.lfStrikeOut
|| lplf
->elfLogFont
.lfUnderline
)
5717 /* Only return fonts with names starting with @ if they were
5718 explicitly specified, since Microsoft uses an initial @ to
5719 denote fonts for vertical writing, without providing a more
5720 convenient way of identifying them. */
5721 if (lplf
->elfLogFont
.lfFaceName
[0] == '@'
5722 && lpef
->logfont
.lfFaceName
[0] != '@')
5725 /* Check that the character set matches if it was specified */
5726 if (lpef
->logfont
.lfCharSet
!= DEFAULT_CHARSET
&&
5727 lplf
->elfLogFont
.lfCharSet
!= lpef
->logfont
.lfCharSet
)
5730 if (FontType
== RASTER_FONTTYPE
)
5732 /* DBCS raster fonts have problems displaying, so skip them. */
5733 int charset
= lplf
->elfLogFont
.lfCharSet
;
5734 if (charset
== SHIFTJIS_CHARSET
5735 || charset
== HANGEUL_CHARSET
5736 || charset
== CHINESEBIG5_CHARSET
5737 || charset
== GB2312_CHARSET
5738 #ifdef JOHAB_CHARSET
5739 || charset
== JOHAB_CHARSET
5747 Lisp_Object width
= Qnil
;
5748 Lisp_Object charset_list
= Qnil
;
5749 char *charset
= NULL
;
5751 /* Truetype fonts do not report their true metrics until loaded */
5752 if (FontType
!= RASTER_FONTTYPE
)
5754 if (!NILP (lpef
->pattern
))
5756 /* Scalable fonts are as big as you want them to be. */
5757 lplf
->elfLogFont
.lfHeight
= lpef
->logfont
.lfHeight
;
5758 lplf
->elfLogFont
.lfWidth
= lpef
->logfont
.lfWidth
;
5759 width
= make_number (lpef
->logfont
.lfWidth
);
5763 lplf
->elfLogFont
.lfHeight
= 0;
5764 lplf
->elfLogFont
.lfWidth
= 0;
5768 /* Make sure the height used here is the same as everywhere
5769 else (ie character height, not cell height). */
5770 if (lplf
->elfLogFont
.lfHeight
> 0)
5772 /* lptm can be trusted for RASTER fonts, but not scalable ones. */
5773 if (FontType
== RASTER_FONTTYPE
)
5774 lplf
->elfLogFont
.lfHeight
= lptm
->tmInternalLeading
- lptm
->tmHeight
;
5776 lplf
->elfLogFont
.lfHeight
= -lplf
->elfLogFont
.lfHeight
;
5779 if (!NILP (lpef
->pattern
))
5781 charset
= xlfd_charset_of_font (SDATA (lpef
->pattern
));
5783 /* We already checked charsets above, but DEFAULT_CHARSET
5784 slipped through. So only allow exact matches for DEFAULT_CHARSET. */
5786 && strncmp (charset
, "*-*", 3) != 0
5787 && lpef
->logfont
.lfCharSet
== DEFAULT_CHARSET
5788 && strcmp (charset
, w32_to_x_charset (DEFAULT_CHARSET
, NULL
)) != 0)
5793 charset_list
= Fcons (build_string (charset
), Qnil
);
5795 /* Always prefer unicode. */
5797 = Fcons (build_string ("iso10646-1"),
5798 w32_to_all_x_charsets (lplf
->elfLogFont
.lfCharSet
));
5800 /* Loop through the charsets. */
5801 for ( ; CONSP (charset_list
); charset_list
= Fcdr (charset_list
))
5803 Lisp_Object this_charset
= Fcar (charset_list
);
5804 charset
= SDATA (this_charset
);
5806 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5809 /* List bold and italic variations if w32-enable-synthesized-fonts
5810 is non-nil and this is a plain font. */
5811 if (w32_enable_synthesized_fonts
5812 && lplf
->elfLogFont
.lfWeight
== FW_NORMAL
5813 && lplf
->elfLogFont
.lfItalic
== FALSE
)
5816 lplf
->elfLogFont
.lfWeight
= FW_BOLD
;
5817 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5820 lplf
->elfLogFont
.lfItalic
= TRUE
;
5821 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5824 lplf
->elfLogFont
.lfWeight
= FW_NORMAL
;
5825 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5835 enum_font_maybe_add_to_list (lpef
, logfont
, match_charset
, width
)
5838 char * match_charset
;
5843 if (!w32_to_x_font (logfont
, buf
, 100, match_charset
))
5846 if (NILP (lpef
->pattern
)
5847 || w32_font_match (buf
, SDATA (lpef
->pattern
)))
5849 /* Check if we already listed this font. This may happen if
5850 w32_enable_synthesized_fonts is non-nil, and there are real
5851 bold and italic versions of the font. */
5852 Lisp_Object font_name
= build_string (buf
);
5853 if (NILP (Fmember (font_name
, lpef
->list
)))
5855 Lisp_Object entry
= Fcons (font_name
, width
);
5856 lpef
->list
= Fcons (entry
, lpef
->list
);
5864 enum_font_cb1 (lplf
, lptm
, FontType
, lpef
)
5866 NEWTEXTMETRIC
* lptm
;
5870 return EnumFontFamilies (lpef
->hdc
,
5871 lplf
->elfLogFont
.lfFaceName
,
5872 (FONTENUMPROC
) enum_font_cb2
,
5878 enum_fontex_cb2 (lplf
, lptm
, font_type
, lpef
)
5879 ENUMLOGFONTEX
* lplf
;
5880 NEWTEXTMETRICEX
* lptm
;
5884 /* We are not interested in the extra info we get back from the 'Ex
5885 version - only the fact that we get character set variations
5886 enumerated seperately. */
5887 return enum_font_cb2 ((ENUMLOGFONT
*) lplf
, (NEWTEXTMETRIC
*) lptm
,
5892 enum_fontex_cb1 (lplf
, lptm
, font_type
, lpef
)
5893 ENUMLOGFONTEX
* lplf
;
5894 NEWTEXTMETRICEX
* lptm
;
5898 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
5899 FARPROC enum_font_families_ex
5900 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
5901 /* We don't really expect EnumFontFamiliesEx to disappear once we
5902 get here, so don't bother handling it gracefully. */
5903 if (enum_font_families_ex
== NULL
)
5904 error ("gdi32.dll has disappeared!");
5905 return enum_font_families_ex (lpef
->hdc
,
5907 (FONTENUMPROC
) enum_fontex_cb2
,
5911 /* Interface to fontset handler. (adapted from mw32font.c in Meadow
5912 and xterm.c in Emacs 20.3) */
5914 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
)
5916 char *fontname
, *ptnstr
;
5917 Lisp_Object list
, tem
, newlist
= Qnil
;
5920 list
= Vw32_bdf_filename_alist
;
5921 ptnstr
= SDATA (pattern
);
5923 for ( ; CONSP (list
); list
= XCDR (list
))
5927 fontname
= SDATA (XCAR (tem
));
5928 else if (STRINGP (tem
))
5929 fontname
= SDATA (tem
);
5933 if (w32_font_match (fontname
, ptnstr
))
5935 newlist
= Fcons (XCAR (tem
), newlist
);
5937 if (max_names
>= 0 && n_fonts
>= max_names
)
5946 /* Return a list of names of available fonts matching PATTERN on frame
5947 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
5948 to be listed. Frame F NULL means we have not yet created any
5949 frame, which means we can't get proper size info, as we don't have
5950 a device context to use for GetTextMetrics.
5951 MAXNAMES sets a limit on how many fonts to match. If MAXNAMES is
5952 negative, then all matching fonts are returned. */
5955 w32_list_fonts (f
, pattern
, size
, maxnames
)
5957 Lisp_Object pattern
;
5961 Lisp_Object patterns
, key
= Qnil
, tem
, tpat
;
5962 Lisp_Object list
= Qnil
, newlist
= Qnil
, second_best
= Qnil
;
5963 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
5966 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
5967 if (NILP (patterns
))
5968 patterns
= Fcons (pattern
, Qnil
);
5970 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
5975 tpat
= XCAR (patterns
);
5977 if (!STRINGP (tpat
))
5980 /* Avoid expensive EnumFontFamilies functions if we are not
5981 going to be able to output one of these anyway. */
5982 codepage
= w32_codepage_for_font (SDATA (tpat
));
5983 if (codepage
!= CP_8BIT
&& codepage
!= CP_UNICODE
5984 && codepage
!= CP_DEFAULT
&& codepage
!= CP_UNKNOWN
5985 && !IsValidCodePage(codepage
))
5988 /* See if we cached the result for this particular query.
5989 The cache is an alist of the form:
5990 ((PATTERN (FONTNAME . WIDTH) ...) ...)
5992 if (tem
= XCDR (dpyinfo
->name_list_element
),
5993 !NILP (list
= Fassoc (tpat
, tem
)))
5995 list
= Fcdr_safe (list
);
5996 /* We have a cached list. Don't have to get the list again. */
6001 /* At first, put PATTERN in the cache. */
6006 /* Use EnumFontFamiliesEx where it is available, as it knows
6007 about character sets. Fall back to EnumFontFamilies for
6008 older versions of NT that don't support the 'Ex function. */
6009 x_to_w32_font (SDATA (tpat
), &ef
.logfont
);
6011 LOGFONT font_match_pattern
;
6012 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6013 FARPROC enum_font_families_ex
6014 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6016 /* We do our own pattern matching so we can handle wildcards. */
6017 font_match_pattern
.lfFaceName
[0] = 0;
6018 font_match_pattern
.lfPitchAndFamily
= 0;
6019 /* We can use the charset, because if it is a wildcard it will
6020 be DEFAULT_CHARSET anyway. */
6021 font_match_pattern
.lfCharSet
= ef
.logfont
.lfCharSet
;
6023 ef
.hdc
= GetDC (dpyinfo
->root_window
);
6025 if (enum_font_families_ex
)
6026 enum_font_families_ex (ef
.hdc
,
6027 &font_match_pattern
,
6028 (FONTENUMPROC
) enum_fontex_cb1
,
6031 EnumFontFamilies (ef
.hdc
, NULL
, (FONTENUMPROC
) enum_font_cb1
,
6034 ReleaseDC (dpyinfo
->root_window
, ef
.hdc
);
6040 /* Make a list of the fonts we got back.
6041 Store that in the font cache for the display. */
6042 XSETCDR (dpyinfo
->name_list_element
,
6043 Fcons (Fcons (tpat
, list
),
6044 XCDR (dpyinfo
->name_list_element
)));
6047 if (NILP (list
)) continue; /* Try the remaining alternatives. */
6049 newlist
= second_best
= Qnil
;
6051 /* Make a list of the fonts that have the right width. */
6052 for (; CONSP (list
); list
= XCDR (list
))
6059 if (NILP (XCAR (tem
)))
6063 newlist
= Fcons (XCAR (tem
), newlist
);
6065 if (maxnames
>= 0 && n_fonts
>= maxnames
)
6070 if (!INTEGERP (XCDR (tem
)))
6072 /* Since we don't yet know the size of the font, we must
6073 load it and try GetTextMetrics. */
6074 W32FontStruct thisinfo
;
6079 if (!x_to_w32_font (SDATA (XCAR (tem
)), &lf
))
6083 thisinfo
.bdf
= NULL
;
6084 thisinfo
.hfont
= CreateFontIndirect (&lf
);
6085 if (thisinfo
.hfont
== NULL
)
6088 hdc
= GetDC (dpyinfo
->root_window
);
6089 oldobj
= SelectObject (hdc
, thisinfo
.hfont
);
6090 if (GetTextMetrics (hdc
, &thisinfo
.tm
))
6091 XSETCDR (tem
, make_number (FONT_WIDTH (&thisinfo
)));
6093 XSETCDR (tem
, make_number (0));
6094 SelectObject (hdc
, oldobj
);
6095 ReleaseDC (dpyinfo
->root_window
, hdc
);
6096 DeleteObject(thisinfo
.hfont
);
6099 found_size
= XINT (XCDR (tem
));
6100 if (found_size
== size
)
6102 newlist
= Fcons (XCAR (tem
), newlist
);
6104 if (maxnames
>= 0 && n_fonts
>= maxnames
)
6107 /* keep track of the closest matching size in case
6108 no exact match is found. */
6109 else if (found_size
> 0)
6111 if (NILP (second_best
))
6114 else if (found_size
< size
)
6116 if (XINT (XCDR (second_best
)) > size
6117 || XINT (XCDR (second_best
)) < found_size
)
6122 if (XINT (XCDR (second_best
)) > size
6123 && XINT (XCDR (second_best
)) >
6130 if (!NILP (newlist
))
6132 else if (!NILP (second_best
))
6134 newlist
= Fcons (XCAR (second_best
), Qnil
);
6139 /* Include any bdf fonts. */
6140 if (n_fonts
< maxnames
|| maxnames
< 0)
6142 Lisp_Object combined
[2];
6143 combined
[0] = w32_list_bdf_fonts (pattern
, maxnames
- n_fonts
);
6144 combined
[1] = newlist
;
6145 newlist
= Fnconc(2, combined
);
6152 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
6154 w32_get_font_info (f
, font_idx
)
6158 return (FRAME_W32_FONT_TABLE (f
) + font_idx
);
6163 w32_query_font (struct frame
*f
, char *fontname
)
6166 struct font_info
*pfi
;
6168 pfi
= FRAME_W32_FONT_TABLE (f
);
6170 for (i
= 0; i
< one_w32_display_info
.n_fonts
;i
++, pfi
++)
6172 if (strcmp(pfi
->name
, fontname
) == 0) return pfi
;
6178 /* Find a CCL program for a font specified by FONTP, and set the member
6179 `encoder' of the structure. */
6182 w32_find_ccl_program (fontp
)
6183 struct font_info
*fontp
;
6185 Lisp_Object list
, elt
;
6187 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
6191 && STRINGP (XCAR (elt
))
6192 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
6198 struct ccl_program
*ccl
6199 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
6201 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
6204 fontp
->font_encoder
= ccl
;
6209 /* Find BDF files in a specified directory. (use GCPRO when calling,
6210 as this calls lisp to get a directory listing). */
6212 w32_find_bdf_fonts_in_dir (Lisp_Object directory
)
6214 Lisp_Object filelist
, list
= Qnil
;
6217 if (!STRINGP(directory
))
6220 filelist
= Fdirectory_files (directory
, Qt
,
6221 build_string (".*\\.[bB][dD][fF]"), Qt
);
6223 for ( ; CONSP(filelist
); filelist
= XCDR (filelist
))
6225 Lisp_Object filename
= XCAR (filelist
);
6226 if (w32_BDF_to_x_font (SDATA (filename
), fontname
, 100))
6227 store_in_alist (&list
, build_string (fontname
), filename
);
6232 DEFUN ("w32-find-bdf-fonts", Fw32_find_bdf_fonts
, Sw32_find_bdf_fonts
,
6234 doc
: /* Return a list of BDF fonts in DIR.
6235 The list is suitable for appending to w32-bdf-filename-alist. Fonts
6236 which do not contain an xlfd description will not be included in the
6237 list. DIR may be a list of directories. */)
6239 Lisp_Object directory
;
6241 Lisp_Object list
= Qnil
;
6242 struct gcpro gcpro1
, gcpro2
;
6244 if (!CONSP (directory
))
6245 return w32_find_bdf_fonts_in_dir (directory
);
6247 for ( ; CONSP (directory
); directory
= XCDR (directory
))
6249 Lisp_Object pair
[2];
6252 GCPRO2 (directory
, list
);
6253 pair
[1] = w32_find_bdf_fonts_in_dir( XCAR (directory
) );
6254 list
= Fnconc( 2, pair
);
6261 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
6262 doc
: /* Internal function called by `color-defined-p', which see. */)
6264 Lisp_Object color
, frame
;
6267 FRAME_PTR f
= check_x_frame (frame
);
6269 CHECK_STRING (color
);
6271 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
6277 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
6278 doc
: /* Internal function called by `color-values', which see. */)
6280 Lisp_Object color
, frame
;
6283 FRAME_PTR f
= check_x_frame (frame
);
6285 CHECK_STRING (color
);
6287 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
6291 rgb
[0] = make_number ((GetRValue (foo
.pixel
) << 8)
6292 | GetRValue (foo
.pixel
));
6293 rgb
[1] = make_number ((GetGValue (foo
.pixel
) << 8)
6294 | GetGValue (foo
.pixel
));
6295 rgb
[2] = make_number ((GetBValue (foo
.pixel
) << 8)
6296 | GetBValue (foo
.pixel
));
6297 return Flist (3, rgb
);
6303 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
6304 doc
: /* Internal function called by `display-color-p', which see. */)
6306 Lisp_Object display
;
6308 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6310 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
6316 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
,
6317 Sx_display_grayscale_p
, 0, 1, 0,
6318 doc
: /* Return t if the X display supports shades of gray.
6319 Note that color displays do support shades of gray.
6320 The optional argument DISPLAY specifies which display to ask about.
6321 DISPLAY should be either a frame or a display name (a string).
6322 If omitted or nil, that stands for the selected frame's display. */)
6324 Lisp_Object display
;
6326 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6328 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
6334 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
,
6335 Sx_display_pixel_width
, 0, 1, 0,
6336 doc
: /* Returns the width in pixels of DISPLAY.
6337 The optional argument DISPLAY specifies which display to ask about.
6338 DISPLAY should be either a frame or a display name (a string).
6339 If omitted or nil, that stands for the selected frame's display. */)
6341 Lisp_Object display
;
6343 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6345 return make_number (dpyinfo
->width
);
6348 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
6349 Sx_display_pixel_height
, 0, 1, 0,
6350 doc
: /* Returns the height in pixels of DISPLAY.
6351 The optional argument DISPLAY specifies which display to ask about.
6352 DISPLAY should be either a frame or a display name (a string).
6353 If omitted or nil, that stands for the selected frame's display. */)
6355 Lisp_Object display
;
6357 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6359 return make_number (dpyinfo
->height
);
6362 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
6364 doc
: /* Returns the number of bitplanes of DISPLAY.
6365 The optional argument DISPLAY specifies which display to ask about.
6366 DISPLAY should be either a frame or a display name (a string).
6367 If omitted or nil, that stands for the selected frame's display. */)
6369 Lisp_Object display
;
6371 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6373 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
6376 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
6378 doc
: /* Returns the number of color cells of DISPLAY.
6379 The optional argument DISPLAY specifies which display to ask about.
6380 DISPLAY should be either a frame or a display name (a string).
6381 If omitted or nil, that stands for the selected frame's display. */)
6383 Lisp_Object display
;
6385 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6389 hdc
= GetDC (dpyinfo
->root_window
);
6390 if (dpyinfo
->has_palette
)
6391 cap
= GetDeviceCaps (hdc
,SIZEPALETTE
);
6393 cap
= GetDeviceCaps (hdc
,NUMCOLORS
);
6395 /* We force 24+ bit depths to 24-bit, both to prevent an overflow
6396 and because probably is more meaningful on Windows anyway */
6398 cap
= 1 << min(dpyinfo
->n_planes
* dpyinfo
->n_cbits
, 24);
6400 ReleaseDC (dpyinfo
->root_window
, hdc
);
6402 return make_number (cap
);
6405 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
6406 Sx_server_max_request_size
,
6408 doc
: /* Returns the maximum request size of the server of DISPLAY.
6409 The optional argument DISPLAY specifies which display to ask about.
6410 DISPLAY should be either a frame or a display name (a string).
6411 If omitted or nil, that stands for the selected frame's display. */)
6413 Lisp_Object display
;
6415 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6417 return make_number (1);
6420 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
6421 doc
: /* Returns the vendor ID string of the W32 system (Microsoft).
6422 The optional argument DISPLAY specifies which display to ask about.
6423 DISPLAY should be either a frame or a display name (a string).
6424 If omitted or nil, that stands for the selected frame's display. */)
6426 Lisp_Object display
;
6428 return build_string ("Microsoft Corp.");
6431 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
6432 doc
: /* Returns the version numbers of the server of DISPLAY.
6433 The value is a list of three integers: the major and minor
6434 version numbers, and the vendor-specific release
6435 number. See also the function `x-server-vendor'.
6437 The optional argument DISPLAY specifies which display to ask about.
6438 DISPLAY should be either a frame or a display name (a string).
6439 If omitted or nil, that stands for the selected frame's display. */)
6441 Lisp_Object display
;
6443 return Fcons (make_number (w32_major_version
),
6444 Fcons (make_number (w32_minor_version
),
6445 Fcons (make_number (w32_build_number
), Qnil
)));
6448 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
6449 doc
: /* Returns the number of screens on the server of DISPLAY.
6450 The optional argument DISPLAY specifies which display to ask about.
6451 DISPLAY should be either a frame or a display name (a string).
6452 If omitted or nil, that stands for the selected frame's display. */)
6454 Lisp_Object display
;
6456 return make_number (1);
6459 DEFUN ("x-display-mm-height", Fx_display_mm_height
,
6460 Sx_display_mm_height
, 0, 1, 0,
6461 doc
: /* Returns the height in millimeters of DISPLAY.
6462 The optional argument DISPLAY specifies which display to ask about.
6463 DISPLAY should be either a frame or a display name (a string).
6464 If omitted or nil, that stands for the selected frame's display. */)
6466 Lisp_Object display
;
6468 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6472 hdc
= GetDC (dpyinfo
->root_window
);
6474 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
6476 ReleaseDC (dpyinfo
->root_window
, hdc
);
6478 return make_number (cap
);
6481 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
6482 doc
: /* Returns the width in millimeters of DISPLAY.
6483 The optional argument DISPLAY specifies which display to ask about.
6484 DISPLAY should be either a frame or a display name (a string).
6485 If omitted or nil, that stands for the selected frame's display. */)
6487 Lisp_Object display
;
6489 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6494 hdc
= GetDC (dpyinfo
->root_window
);
6496 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
6498 ReleaseDC (dpyinfo
->root_window
, hdc
);
6500 return make_number (cap
);
6503 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
6504 Sx_display_backing_store
, 0, 1, 0,
6505 doc
: /* Returns an indication of whether DISPLAY does backing store.
6506 The value may be `always', `when-mapped', or `not-useful'.
6507 The optional argument DISPLAY specifies which display to ask about.
6508 DISPLAY should be either a frame or a display name (a string).
6509 If omitted or nil, that stands for the selected frame's display. */)
6511 Lisp_Object display
;
6513 return intern ("not-useful");
6516 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
6517 Sx_display_visual_class
, 0, 1, 0,
6518 doc
: /* Returns the visual class of DISPLAY.
6519 The value is one of the symbols `static-gray', `gray-scale',
6520 `static-color', `pseudo-color', `true-color', or `direct-color'.
6522 The optional argument DISPLAY specifies which display to ask about.
6523 DISPLAY should be either a frame or a display name (a string).
6524 If omitted or nil, that stands for the selected frame's display. */)
6526 Lisp_Object display
;
6528 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6529 Lisp_Object result
= Qnil
;
6531 if (dpyinfo
->has_palette
)
6532 result
= intern ("pseudo-color");
6533 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
6534 result
= intern ("static-grey");
6535 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
6536 result
= intern ("static-color");
6537 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
6538 result
= intern ("true-color");
6543 DEFUN ("x-display-save-under", Fx_display_save_under
,
6544 Sx_display_save_under
, 0, 1, 0,
6545 doc
: /* Returns t if DISPLAY supports the save-under feature.
6546 The optional argument DISPLAY specifies which display to ask about.
6547 DISPLAY should be either a frame or a display name (a string).
6548 If omitted or nil, that stands for the selected frame's display. */)
6550 Lisp_Object display
;
6557 register struct frame
*f
;
6559 return FRAME_PIXEL_WIDTH (f
);
6564 register struct frame
*f
;
6566 return FRAME_PIXEL_HEIGHT (f
);
6571 register struct frame
*f
;
6573 return FRAME_COLUMN_WIDTH (f
);
6578 register struct frame
*f
;
6580 return FRAME_LINE_HEIGHT (f
);
6585 register struct frame
*f
;
6587 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
6590 /* Return the display structure for the display named NAME.
6591 Open a new connection if necessary. */
6593 struct w32_display_info
*
6594 x_display_info_for_name (name
)
6598 struct w32_display_info
*dpyinfo
;
6600 CHECK_STRING (name
);
6602 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
6604 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
6607 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
6612 /* Use this general default value to start with. */
6613 Vx_resource_name
= Vinvocation_name
;
6615 validate_x_resource_name ();
6617 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
6618 (char *) SDATA (Vx_resource_name
));
6621 error ("Cannot connect to server %s", SDATA (name
));
6624 XSETFASTINT (Vwindow_system_version
, 3);
6629 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
6630 1, 3, 0, doc
: /* Open a connection to a server.
6631 DISPLAY is the name of the display to connect to.
6632 Optional second arg XRM-STRING is a string of resources in xrdb format.
6633 If the optional third arg MUST-SUCCEED is non-nil,
6634 terminate Emacs if we can't open the connection. */)
6635 (display
, xrm_string
, must_succeed
)
6636 Lisp_Object display
, xrm_string
, must_succeed
;
6638 unsigned char *xrm_option
;
6639 struct w32_display_info
*dpyinfo
;
6641 /* If initialization has already been done, return now to avoid
6642 overwriting critical parts of one_w32_display_info. */
6646 CHECK_STRING (display
);
6647 if (! NILP (xrm_string
))
6648 CHECK_STRING (xrm_string
);
6650 if (! EQ (Vwindow_system
, intern ("w32")))
6651 error ("Not using Microsoft Windows");
6653 /* Allow color mapping to be defined externally; first look in user's
6654 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
6656 Lisp_Object color_file
;
6657 struct gcpro gcpro1
;
6659 color_file
= build_string("~/rgb.txt");
6661 GCPRO1 (color_file
);
6663 if (NILP (Ffile_readable_p (color_file
)))
6665 Fexpand_file_name (build_string ("rgb.txt"),
6666 Fsymbol_value (intern ("data-directory")));
6668 Vw32_color_map
= Fw32_load_color_file (color_file
);
6672 if (NILP (Vw32_color_map
))
6673 Vw32_color_map
= Fw32_default_color_map ();
6675 /* Merge in system logical colors. */
6676 add_system_logical_colors_to_map (&Vw32_color_map
);
6678 if (! NILP (xrm_string
))
6679 xrm_option
= (unsigned char *) SDATA (xrm_string
);
6681 xrm_option
= (unsigned char *) 0;
6683 /* Use this general default value to start with. */
6684 /* First remove .exe suffix from invocation-name - it looks ugly. */
6686 char basename
[ MAX_PATH
], *str
;
6688 strcpy (basename
, SDATA (Vinvocation_name
));
6689 str
= strrchr (basename
, '.');
6691 Vinvocation_name
= build_string (basename
);
6693 Vx_resource_name
= Vinvocation_name
;
6695 validate_x_resource_name ();
6697 /* This is what opens the connection and sets x_current_display.
6698 This also initializes many symbols, such as those used for input. */
6699 dpyinfo
= w32_term_init (display
, xrm_option
,
6700 (char *) SDATA (Vx_resource_name
));
6704 if (!NILP (must_succeed
))
6705 fatal ("Cannot connect to server %s.\n",
6708 error ("Cannot connect to server %s", SDATA (display
));
6713 XSETFASTINT (Vwindow_system_version
, 3);
6717 DEFUN ("x-close-connection", Fx_close_connection
,
6718 Sx_close_connection
, 1, 1, 0,
6719 doc
: /* Close the connection to DISPLAY's server.
6720 For DISPLAY, specify either a frame or a display name (a string).
6721 If DISPLAY is nil, that stands for the selected frame's display. */)
6723 Lisp_Object display
;
6725 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6728 if (dpyinfo
->reference_count
> 0)
6729 error ("Display still has frames on it");
6732 /* Free the fonts in the font table. */
6733 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
6734 if (dpyinfo
->font_table
[i
].name
)
6736 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
6737 xfree (dpyinfo
->font_table
[i
].full_name
);
6738 xfree (dpyinfo
->font_table
[i
].name
);
6739 w32_unload_font (dpyinfo
, dpyinfo
->font_table
[i
].font
);
6741 x_destroy_all_bitmaps (dpyinfo
);
6743 x_delete_display (dpyinfo
);
6749 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
6750 doc
: /* Return the list of display names that Emacs has connections to. */)
6753 Lisp_Object tail
, result
;
6756 for (tail
= w32_display_name_list
; ! NILP (tail
); tail
= XCDR (tail
))
6757 result
= Fcons (XCAR (XCAR (tail
)), result
);
6762 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
6763 doc
: /* This is a noop on W32 systems. */)
6765 Lisp_Object display
, on
;
6772 /***********************************************************************
6774 ***********************************************************************/
6776 DEFUN ("x-change-window-property", Fx_change_window_property
,
6777 Sx_change_window_property
, 2, 6, 0,
6778 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
6779 VALUE may be a string or a list of conses, numbers and/or strings.
6780 If an element in the list is a string, it is converted to
6781 an Atom and the value of the Atom is used. If an element is a cons,
6782 it is converted to a 32 bit number where the car is the 16 top bits and the
6783 cdr is the lower 16 bits.
6784 FRAME nil or omitted means use the selected frame.
6785 If TYPE is given and non-nil, it is the name of the type of VALUE.
6786 If TYPE is not given or nil, the type is STRING.
6787 FORMAT gives the size in bits of each element if VALUE is a list.
6788 It must be one of 8, 16 or 32.
6789 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
6790 If OUTER_P is non-nil, the property is changed for the outer X window of
6791 FRAME. Default is to change on the edit X window.
6794 (prop
, value
, frame
, type
, format
, outer_p
)
6795 Lisp_Object prop
, value
, frame
, type
, format
, outer_p
;
6797 #if 0 /* TODO : port window properties to W32 */
6798 struct frame
*f
= check_x_frame (frame
);
6801 CHECK_STRING (prop
);
6802 CHECK_STRING (value
);
6805 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
6806 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
6807 prop_atom
, XA_STRING
, 8, PropModeReplace
,
6808 SDATA (value
), SCHARS (value
));
6810 /* Make sure the property is set when we return. */
6811 XFlush (FRAME_W32_DISPLAY (f
));
6820 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
6821 Sx_delete_window_property
, 1, 2, 0,
6822 doc
: /* Remove window property PROP from X window of FRAME.
6823 FRAME nil or omitted means use the selected frame. Value is PROP. */)
6825 Lisp_Object prop
, frame
;
6827 #if 0 /* TODO : port window properties to W32 */
6829 struct frame
*f
= check_x_frame (frame
);
6832 CHECK_STRING (prop
);
6834 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
6835 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
6837 /* Make sure the property is removed when we return. */
6838 XFlush (FRAME_W32_DISPLAY (f
));
6846 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
6848 doc
: /* Value is the value of window property PROP on FRAME.
6849 If FRAME is nil or omitted, use the selected frame. Value is nil
6850 if FRAME hasn't a property with name PROP or if PROP has no string
6853 Lisp_Object prop
, frame
;
6855 #if 0 /* TODO : port window properties to W32 */
6857 struct frame
*f
= check_x_frame (frame
);
6860 Lisp_Object prop_value
= Qnil
;
6861 char *tmp_data
= NULL
;
6864 unsigned long actual_size
, bytes_remaining
;
6866 CHECK_STRING (prop
);
6868 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
6869 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
6870 prop_atom
, 0, 0, False
, XA_STRING
,
6871 &actual_type
, &actual_format
, &actual_size
,
6872 &bytes_remaining
, (unsigned char **) &tmp_data
);
6875 int size
= bytes_remaining
;
6880 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
6881 prop_atom
, 0, bytes_remaining
,
6883 &actual_type
, &actual_format
,
6884 &actual_size
, &bytes_remaining
,
6885 (unsigned char **) &tmp_data
);
6887 prop_value
= make_string (tmp_data
, size
);
6902 /***********************************************************************
6904 ***********************************************************************/
6906 /* If non-null, an asynchronous timer that, when it expires, displays
6907 an hourglass cursor on all frames. */
6909 static struct atimer
*hourglass_atimer
;
6911 /* Non-zero means an hourglass cursor is currently shown. */
6913 static int hourglass_shown_p
;
6915 /* Number of seconds to wait before displaying an hourglass cursor. */
6917 static Lisp_Object Vhourglass_delay
;
6919 /* Default number of seconds to wait before displaying an hourglass
6922 #define DEFAULT_HOURGLASS_DELAY 1
6924 /* Function prototypes. */
6926 static void show_hourglass
P_ ((struct atimer
*));
6927 static void hide_hourglass
P_ ((void));
6930 /* Cancel a currently active hourglass timer, and start a new one. */
6935 #if 0 /* TODO: cursor shape changes. */
6937 int secs
, usecs
= 0;
6939 cancel_hourglass ();
6941 if (INTEGERP (Vhourglass_delay
)
6942 && XINT (Vhourglass_delay
) > 0)
6943 secs
= XFASTINT (Vhourglass_delay
);
6944 else if (FLOATP (Vhourglass_delay
)
6945 && XFLOAT_DATA (Vhourglass_delay
) > 0)
6948 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
6949 secs
= XFASTINT (tem
);
6950 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
6953 secs
= DEFAULT_HOURGLASS_DELAY
;
6955 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
6956 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
6957 show_hourglass
, NULL
);
6962 /* Cancel the hourglass cursor timer if active, hide an hourglass
6968 if (hourglass_atimer
)
6970 cancel_atimer (hourglass_atimer
);
6971 hourglass_atimer
= NULL
;
6974 if (hourglass_shown_p
)
6979 /* Timer function of hourglass_atimer. TIMER is equal to
6982 Display an hourglass cursor on all frames by mapping the frames'
6983 hourglass_window. Set the hourglass_p flag in the frames'
6984 output_data.x structure to indicate that an hourglass cursor is
6985 shown on the frames. */
6988 show_hourglass (timer
)
6989 struct atimer
*timer
;
6991 #if 0 /* TODO: cursor shape changes. */
6992 /* The timer implementation will cancel this timer automatically
6993 after this function has run. Set hourglass_atimer to null
6994 so that we know the timer doesn't have to be canceled. */
6995 hourglass_atimer
= NULL
;
6997 if (!hourglass_shown_p
)
6999 Lisp_Object rest
, frame
;
7003 FOR_EACH_FRAME (rest
, frame
)
7004 if (FRAME_W32_P (XFRAME (frame
)))
7006 struct frame
*f
= XFRAME (frame
);
7008 f
->output_data
.w32
->hourglass_p
= 1;
7010 if (!f
->output_data
.w32
->hourglass_window
)
7012 unsigned long mask
= CWCursor
;
7013 XSetWindowAttributes attrs
;
7015 attrs
.cursor
= f
->output_data
.w32
->hourglass_cursor
;
7017 f
->output_data
.w32
->hourglass_window
7018 = XCreateWindow (FRAME_X_DISPLAY (f
),
7019 FRAME_OUTER_WINDOW (f
),
7020 0, 0, 32000, 32000, 0, 0,
7026 XMapRaised (FRAME_X_DISPLAY (f
),
7027 f
->output_data
.w32
->hourglass_window
);
7028 XFlush (FRAME_X_DISPLAY (f
));
7031 hourglass_shown_p
= 1;
7038 /* Hide the hourglass cursor on all frames, if it is currently shown. */
7043 #if 0 /* TODO: cursor shape changes. */
7044 if (hourglass_shown_p
)
7046 Lisp_Object rest
, frame
;
7049 FOR_EACH_FRAME (rest
, frame
)
7051 struct frame
*f
= XFRAME (frame
);
7054 /* Watch out for newly created frames. */
7055 && f
->output_data
.x
->hourglass_window
)
7057 XUnmapWindow (FRAME_X_DISPLAY (f
),
7058 f
->output_data
.x
->hourglass_window
);
7059 /* Sync here because XTread_socket looks at the
7060 hourglass_p flag that is reset to zero below. */
7061 XSync (FRAME_X_DISPLAY (f
), False
);
7062 f
->output_data
.x
->hourglass_p
= 0;
7066 hourglass_shown_p
= 0;
7074 /***********************************************************************
7076 ***********************************************************************/
7078 static Lisp_Object x_create_tip_frame
P_ ((struct w32_display_info
*,
7079 Lisp_Object
, Lisp_Object
));
7080 static void compute_tip_xy
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
7081 Lisp_Object
, int, int, int *, int *));
7083 /* The frame of a currently visible tooltip. */
7085 Lisp_Object tip_frame
;
7087 /* If non-nil, a timer started that hides the last tooltip when it
7090 Lisp_Object tip_timer
;
7093 /* If non-nil, a vector of 3 elements containing the last args
7094 with which x-show-tip was called. See there. */
7096 Lisp_Object last_show_tip_args
;
7098 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
7100 Lisp_Object Vx_max_tooltip_size
;
7104 unwind_create_tip_frame (frame
)
7107 Lisp_Object deleted
;
7109 deleted
= unwind_create_frame (frame
);
7110 if (EQ (deleted
, Qt
))
7120 /* Create a frame for a tooltip on the display described by DPYINFO.
7121 PARMS is a list of frame parameters. TEXT is the string to
7122 display in the tip frame. Value is the frame.
7124 Note that functions called here, esp. x_default_parameter can
7125 signal errors, for instance when a specified color name is
7126 undefined. We have to make sure that we're in a consistent state
7127 when this happens. */
7130 x_create_tip_frame (dpyinfo
, parms
, text
)
7131 struct w32_display_info
*dpyinfo
;
7132 Lisp_Object parms
, text
;
7135 Lisp_Object frame
, tem
;
7137 long window_prompting
= 0;
7139 int count
= SPECPDL_INDEX ();
7140 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7142 int face_change_count_before
= face_change_count
;
7144 struct buffer
*old_buffer
;
7148 /* Use this general default value to start with until we know if
7149 this frame has a specified name. */
7150 Vx_resource_name
= Vinvocation_name
;
7153 kb
= dpyinfo
->kboard
;
7155 kb
= &the_only_kboard
;
7158 /* Get the name of the frame to use for resource lookup. */
7159 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
7161 && !EQ (name
, Qunbound
)
7163 error ("Invalid frame name--not a string or nil");
7164 Vx_resource_name
= name
;
7167 GCPRO3 (parms
, name
, frame
);
7168 /* Make a frame without minibuffer nor mode-line. */
7170 f
->wants_modeline
= 0;
7171 XSETFRAME (frame
, f
);
7173 buffer
= Fget_buffer_create (build_string (" *tip*"));
7174 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, Qnil
);
7175 old_buffer
= current_buffer
;
7176 set_buffer_internal_1 (XBUFFER (buffer
));
7177 current_buffer
->truncate_lines
= Qnil
;
7180 set_buffer_internal_1 (old_buffer
);
7182 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
7183 record_unwind_protect (unwind_create_tip_frame
, frame
);
7185 /* By setting the output method, we're essentially saying that
7186 the frame is live, as per FRAME_LIVE_P. If we get a signal
7187 from this point on, x_destroy_window might screw up reference
7189 f
->output_method
= output_w32
;
7190 f
->output_data
.w32
=
7191 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
7192 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
7194 FRAME_FONTSET (f
) = -1;
7195 f
->icon_name
= Qnil
;
7197 #if 0 /* GLYPH_DEBUG TODO: image support. */
7198 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
7199 dpyinfo_refcount
= dpyinfo
->reference_count
;
7200 #endif /* GLYPH_DEBUG */
7202 FRAME_KBOARD (f
) = kb
;
7204 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
7205 f
->output_data
.w32
->explicit_parent
= 0;
7207 /* Set the name; the functions to which we pass f expect the name to
7209 if (EQ (name
, Qunbound
) || NILP (name
))
7211 f
->name
= build_string (dpyinfo
->w32_id_name
);
7212 f
->explicit_name
= 0;
7217 f
->explicit_name
= 1;
7218 /* use the frame's title when getting resources for this frame. */
7219 specbind (Qx_resource_name
, name
);
7222 /* Extract the window parameters from the supplied values
7223 that are needed to determine window geometry. */
7227 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
7230 /* First, try whatever font the caller has specified. */
7233 tem
= Fquery_fontset (font
, Qnil
);
7235 font
= x_new_fontset (f
, tem
);
7237 font
= x_new_font (f
, SDATA (font
));
7240 /* Try out a font which we hope has bold and italic variations. */
7241 if (!STRINGP (font
))
7242 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
7243 if (! STRINGP (font
))
7244 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
7245 /* If those didn't work, look for something which will at least work. */
7246 if (! STRINGP (font
))
7247 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
7249 if (! STRINGP (font
))
7250 font
= build_string ("Fixedsys");
7252 x_default_parameter (f
, parms
, Qfont
, font
,
7253 "font", "Font", RES_TYPE_STRING
);
7256 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
7257 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
7258 /* This defaults to 2 in order to match xterm. We recognize either
7259 internalBorderWidth or internalBorder (which is what xterm calls
7261 if (NILP (Fassq (Qinternal_border_width
, parms
)))
7265 value
= w32_get_arg (parms
, Qinternal_border_width
,
7266 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
7267 if (! EQ (value
, Qunbound
))
7268 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
7271 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
7272 "internalBorderWidth", "internalBorderWidth",
7275 /* Also do the stuff which must be set before the window exists. */
7276 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
7277 "foreground", "Foreground", RES_TYPE_STRING
);
7278 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
7279 "background", "Background", RES_TYPE_STRING
);
7280 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
7281 "pointerColor", "Foreground", RES_TYPE_STRING
);
7282 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
7283 "cursorColor", "Foreground", RES_TYPE_STRING
);
7284 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
7285 "borderColor", "BorderColor", RES_TYPE_STRING
);
7287 /* Init faces before x_default_parameter is called for scroll-bar
7288 parameters because that function calls x_set_scroll_bar_width,
7289 which calls change_frame_size, which calls Fset_window_buffer,
7290 which runs hooks, which call Fvertical_motion. At the end, we
7291 end up in init_iterator with a null face cache, which should not
7293 init_frame_faces (f
);
7295 f
->output_data
.w32
->dwStyle
= WS_BORDER
| WS_POPUP
| WS_DISABLED
;
7296 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
7298 window_prompting
= x_figure_window_size (f
, parms
, 0);
7300 /* No fringes on tip frame. */
7302 f
->left_fringe_width
= 0;
7303 f
->right_fringe_width
= 0;
7306 my_create_tip_window (f
);
7311 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
7312 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
7313 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
7314 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
7315 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
7316 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
7318 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
7319 Change will not be effected unless different from the current
7321 width
= FRAME_COLS (f
);
7322 height
= FRAME_LINES (f
);
7323 FRAME_LINES (f
) = 0;
7324 SET_FRAME_COLS (f
, 0);
7325 change_frame_size (f
, height
, width
, 1, 0, 0);
7327 /* Add `tooltip' frame parameter's default value. */
7328 if (NILP (Fframe_parameter (frame
, intern ("tooltip"))))
7329 Fmodify_frame_parameters (frame
, Fcons (Fcons (intern ("tooltip"), Qt
),
7332 /* Set up faces after all frame parameters are known. This call
7333 also merges in face attributes specified for new frames.
7335 Frame parameters may be changed if .Xdefaults contains
7336 specifications for the default font. For example, if there is an
7337 `Emacs.default.attributeBackground: pink', the `background-color'
7338 attribute of the frame get's set, which let's the internal border
7339 of the tooltip frame appear in pink. Prevent this. */
7341 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
7343 /* Set tip_frame here, so that */
7345 call1 (Qface_set_after_frame_default
, frame
);
7347 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
7348 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qbackground_color
, bg
),
7356 /* It is now ok to make the frame official even if we get an error
7357 below. And the frame needs to be on Vframe_list or making it
7358 visible won't work. */
7359 Vframe_list
= Fcons (frame
, Vframe_list
);
7361 /* Now that the frame is official, it counts as a reference to
7363 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
7365 /* Setting attributes of faces of the tooltip frame from resources
7366 and similar will increment face_change_count, which leads to the
7367 clearing of all current matrices. Since this isn't necessary
7368 here, avoid it by resetting face_change_count to the value it
7369 had before we created the tip frame. */
7370 face_change_count
= face_change_count_before
;
7372 /* Discard the unwind_protect. */
7373 return unbind_to (count
, frame
);
7377 /* Compute where to display tip frame F. PARMS is the list of frame
7378 parameters for F. DX and DY are specified offsets from the current
7379 location of the mouse. WIDTH and HEIGHT are the width and height
7380 of the tooltip. Return coordinates relative to the root window of
7381 the display in *ROOT_X, and *ROOT_Y. */
7384 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, root_x
, root_y
)
7386 Lisp_Object parms
, dx
, dy
;
7388 int *root_x
, *root_y
;
7390 Lisp_Object left
, top
;
7392 /* User-specified position? */
7393 left
= Fcdr (Fassq (Qleft
, parms
));
7394 top
= Fcdr (Fassq (Qtop
, parms
));
7396 /* Move the tooltip window where the mouse pointer is. Resize and
7398 if (!INTEGERP (left
) || !INTEGERP (top
))
7410 *root_y
= XINT (top
);
7411 else if (*root_y
+ XINT (dy
) - height
< 0)
7412 *root_y
-= XINT (dy
);
7416 *root_y
+= XINT (dy
);
7419 if (INTEGERP (left
))
7420 *root_x
= XINT (left
);
7421 else if (*root_x
+ XINT (dx
) + width
<= FRAME_W32_DISPLAY_INFO (f
)->width
)
7422 /* It fits to the right of the pointer. */
7423 *root_x
+= XINT (dx
);
7424 else if (width
+ XINT (dx
) <= *root_x
)
7425 /* It fits to the left of the pointer. */
7426 *root_x
-= width
+ XINT (dx
);
7428 /* Put it left justified on the screen -- it ought to fit that way. */
7433 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
7434 doc
: /* Show STRING in a \"tooltip\" window on frame FRAME.
7435 A tooltip window is a small window displaying a string.
7437 FRAME nil or omitted means use the selected frame.
7439 PARMS is an optional list of frame parameters which can be
7440 used to change the tooltip's appearance.
7442 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
7443 means use the default timeout of 5 seconds.
7445 If the list of frame parameters PARAMS contains a `left' parameter,
7446 the tooltip is displayed at that x-position. Otherwise it is
7447 displayed at the mouse position, with offset DX added (default is 5 if
7448 DX isn't specified). Likewise for the y-position; if a `top' frame
7449 parameter is specified, it determines the y-position of the tooltip
7450 window, otherwise it is displayed at the mouse position, with offset
7451 DY added (default is -10).
7453 A tooltip's maximum size is specified by `x-max-tooltip-size'.
7454 Text larger than the specified size is clipped. */)
7455 (string
, frame
, parms
, timeout
, dx
, dy
)
7456 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
7461 struct buffer
*old_buffer
;
7462 struct text_pos pos
;
7463 int i
, width
, height
;
7464 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7465 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7466 int count
= SPECPDL_INDEX ();
7468 specbind (Qinhibit_redisplay
, Qt
);
7470 GCPRO4 (string
, parms
, frame
, timeout
);
7472 CHECK_STRING (string
);
7473 f
= check_x_frame (frame
);
7475 timeout
= make_number (5);
7477 CHECK_NATNUM (timeout
);
7480 dx
= make_number (5);
7485 dy
= make_number (-10);
7489 if (NILP (last_show_tip_args
))
7490 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
7492 if (!NILP (tip_frame
))
7494 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
7495 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
7496 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
7498 if (EQ (frame
, last_frame
)
7499 && !NILP (Fequal (last_string
, string
))
7500 && !NILP (Fequal (last_parms
, parms
)))
7502 struct frame
*f
= XFRAME (tip_frame
);
7504 /* Only DX and DY have changed. */
7505 if (!NILP (tip_timer
))
7507 Lisp_Object timer
= tip_timer
;
7509 call1 (Qcancel_timer
, timer
);
7513 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
7514 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
7516 /* Put tooltip in topmost group and in position. */
7517 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
7518 root_x
, root_y
, 0, 0,
7519 SWP_NOSIZE
| SWP_NOACTIVATE
);
7521 /* Ensure tooltip is on top of other topmost windows (eg menus). */
7522 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
7524 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
7531 /* Hide a previous tip, if any. */
7534 ASET (last_show_tip_args
, 0, string
);
7535 ASET (last_show_tip_args
, 1, frame
);
7536 ASET (last_show_tip_args
, 2, parms
);
7538 /* Add default values to frame parameters. */
7539 if (NILP (Fassq (Qname
, parms
)))
7540 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
7541 if (NILP (Fassq (Qinternal_border_width
, parms
)))
7542 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
7543 if (NILP (Fassq (Qborder_width
, parms
)))
7544 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
7545 if (NILP (Fassq (Qborder_color
, parms
)))
7546 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
7547 if (NILP (Fassq (Qbackground_color
, parms
)))
7548 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
7551 /* Block input until the tip has been fully drawn, to avoid crashes
7552 when drawing tips in menus. */
7555 /* Create a frame for the tooltip, and record it in the global
7556 variable tip_frame. */
7557 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
, string
);
7560 /* Set up the frame's root window. */
7561 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7562 w
->left_col
= w
->top_line
= make_number (0);
7564 if (CONSP (Vx_max_tooltip_size
)
7565 && INTEGERP (XCAR (Vx_max_tooltip_size
))
7566 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
7567 && INTEGERP (XCDR (Vx_max_tooltip_size
))
7568 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
7570 w
->total_cols
= XCAR (Vx_max_tooltip_size
);
7571 w
->total_lines
= XCDR (Vx_max_tooltip_size
);
7575 w
->total_cols
= make_number (80);
7576 w
->total_lines
= make_number (40);
7579 FRAME_TOTAL_COLS (f
) = XINT (w
->total_cols
);
7581 w
->pseudo_window_p
= 1;
7583 /* Display the tooltip text in a temporary buffer. */
7584 old_buffer
= current_buffer
;
7585 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
7586 current_buffer
->truncate_lines
= Qnil
;
7587 clear_glyph_matrix (w
->desired_matrix
);
7588 clear_glyph_matrix (w
->current_matrix
);
7589 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
7590 try_window (FRAME_ROOT_WINDOW (f
), pos
);
7592 /* Compute width and height of the tooltip. */
7594 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
7596 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
7600 /* Stop at the first empty row at the end. */
7601 if (!row
->enabled_p
|| !row
->displays_text_p
)
7604 /* Let the row go over the full width of the frame. */
7605 row
->full_width_p
= 1;
7607 #ifdef TODO /* Investigate why some fonts need more width than is
7608 calculated for some tooltips. */
7609 /* There's a glyph at the end of rows that is use to place
7610 the cursor there. Don't include the width of this glyph. */
7611 if (row
->used
[TEXT_AREA
])
7613 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
7614 row_width
= row
->pixel_width
- last
->pixel_width
;
7618 row_width
= row
->pixel_width
;
7620 /* TODO: find why tips do not draw along baseline as instructed. */
7621 height
+= row
->height
;
7622 width
= max (width
, row_width
);
7625 /* Add the frame's internal border to the width and height the X
7626 window should have. */
7627 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
7628 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
7630 /* Move the tooltip window where the mouse pointer is. Resize and
7632 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
7635 /* Adjust Window size to take border into account. */
7637 rect
.left
= rect
.top
= 0;
7639 rect
.bottom
= height
;
7640 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
7641 FRAME_EXTERNAL_MENU_BAR (f
));
7643 /* Position and size tooltip, and put it in the topmost group. */
7644 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
7645 root_x
, root_y
, rect
.right
- rect
.left
,
7646 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
);
7648 /* Ensure tooltip is on top of other topmost windows (eg menus). */
7649 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
7651 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
7653 /* Let redisplay know that we have made the frame visible already. */
7654 f
->async_visible
= 1;
7656 ShowWindow (FRAME_W32_WINDOW (f
), SW_SHOWNOACTIVATE
);
7659 /* Draw into the window. */
7660 w
->must_be_updated_p
= 1;
7661 update_single_window (w
, 1);
7665 /* Restore original current buffer. */
7666 set_buffer_internal_1 (old_buffer
);
7667 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7670 /* Let the tip disappear after timeout seconds. */
7671 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
7672 intern ("x-hide-tip"));
7675 return unbind_to (count
, Qnil
);
7679 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
7680 doc
: /* Hide the current tooltip window, if there is any.
7681 Value is t if tooltip was open, nil otherwise. */)
7685 Lisp_Object deleted
, frame
, timer
;
7686 struct gcpro gcpro1
, gcpro2
;
7688 /* Return quickly if nothing to do. */
7689 if (NILP (tip_timer
) && NILP (tip_frame
))
7694 GCPRO2 (frame
, timer
);
7695 tip_frame
= tip_timer
= deleted
= Qnil
;
7697 count
= SPECPDL_INDEX ();
7698 specbind (Qinhibit_redisplay
, Qt
);
7699 specbind (Qinhibit_quit
, Qt
);
7702 call1 (Qcancel_timer
, timer
);
7706 Fdelete_frame (frame
, Qnil
);
7711 return unbind_to (count
, deleted
);
7716 /***********************************************************************
7717 File selection dialog
7718 ***********************************************************************/
7719 extern Lisp_Object Qfile_name_history
;
7721 /* Callback for altering the behaviour of the Open File dialog.
7722 Makes the Filename text field contain "Current Directory" and be
7723 read-only when "Directories" is selected in the filter. This
7724 allows us to work around the fact that the standard Open File
7725 dialog does not support directories. */
7727 file_dialog_callback (hwnd
, msg
, wParam
, lParam
)
7733 if (msg
== WM_NOTIFY
)
7735 OFNOTIFY
* notify
= (OFNOTIFY
*)lParam
;
7736 /* Detect when the Filter dropdown is changed. */
7737 if (notify
->hdr
.code
== CDN_TYPECHANGE
)
7739 HWND dialog
= GetParent (hwnd
);
7740 HWND edit_control
= GetDlgItem (dialog
, FILE_NAME_TEXT_FIELD
);
7742 /* Directories is in index 2. */
7743 if (notify
->lpOFN
->nFilterIndex
== 2)
7745 CommDlg_OpenSave_SetControlText (dialog
, FILE_NAME_TEXT_FIELD
,
7746 "Current Directory");
7747 EnableWindow (edit_control
, FALSE
);
7751 CommDlg_OpenSave_SetControlText (dialog
, FILE_NAME_TEXT_FIELD
,
7753 EnableWindow (edit_control
, TRUE
);
7760 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 4, 0,
7761 doc
: /* Read file name, prompting with PROMPT in directory DIR.
7762 Use a file selection dialog.
7763 Select DEFAULT-FILENAME in the dialog's file selection box, if
7764 specified. Ensure that file exists if MUSTMATCH is non-nil. */)
7765 (prompt
, dir
, default_filename
, mustmatch
)
7766 Lisp_Object prompt
, dir
, default_filename
, mustmatch
;
7768 struct frame
*f
= SELECTED_FRAME ();
7769 Lisp_Object file
= Qnil
;
7770 int count
= SPECPDL_INDEX ();
7771 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
7772 char filename
[MAX_PATH
+ 1];
7773 char init_dir
[MAX_PATH
+ 1];
7775 GCPRO5 (prompt
, dir
, default_filename
, mustmatch
, file
);
7776 CHECK_STRING (prompt
);
7779 /* Create the dialog with PROMPT as title, using DIR as initial
7780 directory and using "*" as pattern. */
7781 dir
= Fexpand_file_name (dir
, Qnil
);
7782 strncpy (init_dir
, SDATA (dir
), MAX_PATH
);
7783 init_dir
[MAX_PATH
] = '\0';
7784 unixtodos_filename (init_dir
);
7786 if (STRINGP (default_filename
))
7788 char *file_name_only
;
7789 char *full_path_name
= SDATA (default_filename
);
7791 unixtodos_filename (full_path_name
);
7793 file_name_only
= strrchr (full_path_name
, '\\');
7794 if (!file_name_only
)
7795 file_name_only
= full_path_name
;
7801 strncpy (filename
, file_name_only
, MAX_PATH
);
7802 filename
[MAX_PATH
] = '\0';
7808 OPENFILENAME file_details
;
7810 /* Prevent redisplay. */
7811 specbind (Qinhibit_redisplay
, Qt
);
7814 bzero (&file_details
, sizeof (file_details
));
7815 file_details
.lStructSize
= sizeof (file_details
);
7816 file_details
.hwndOwner
= FRAME_W32_WINDOW (f
);
7817 /* Undocumented Bug in Common File Dialog:
7818 If a filter is not specified, shell links are not resolved. */
7819 file_details
.lpstrFilter
= "All Files (*.*)\0*.*\0Directories\0*|*\0\0";
7820 file_details
.lpstrFile
= filename
;
7821 file_details
.nMaxFile
= sizeof (filename
);
7822 file_details
.lpstrInitialDir
= init_dir
;
7823 file_details
.lpstrTitle
= SDATA (prompt
);
7824 file_details
.Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
7825 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
7826 if (!NILP (mustmatch
))
7827 file_details
.Flags
|= OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
;
7829 file_details
.lpfnHook
= (LPOFNHOOKPROC
) file_dialog_callback
;
7831 if (GetOpenFileName (&file_details
))
7833 dostounix_filename (filename
);
7834 if (file_details
.nFilterIndex
== 2)
7836 /* "Folder Only" selected - strip dummy file name. */
7837 char * last
= strrchr (filename
, '/');
7841 file
= DECODE_FILE(build_string (filename
));
7843 /* User cancelled the dialog without making a selection. */
7844 else if (!CommDlgExtendedError ())
7846 /* An error occurred, fallback on reading from the mini-buffer. */
7848 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
7849 dir
, mustmatch
, dir
, Qfile_name_history
,
7850 default_filename
, Qnil
);
7853 file
= unbind_to (count
, file
);
7858 /* Make "Cancel" equivalent to C-g. */
7860 Fsignal (Qquit
, Qnil
);
7862 return unbind_to (count
, file
);
7867 /***********************************************************************
7868 w32 specialized functions
7869 ***********************************************************************/
7871 DEFUN ("w32-select-font", Fw32_select_font
, Sw32_select_font
, 0, 2, 0,
7872 doc
: /* Select a font using the W32 font dialog.
7873 Returns an X font string corresponding to the selection. */)
7874 (frame
, include_proportional
)
7875 Lisp_Object frame
, include_proportional
;
7877 FRAME_PTR f
= check_x_frame (frame
);
7885 bzero (&cf
, sizeof (cf
));
7886 bzero (&lf
, sizeof (lf
));
7888 cf
.lStructSize
= sizeof (cf
);
7889 cf
.hwndOwner
= FRAME_W32_WINDOW (f
);
7890 cf
.Flags
= CF_FORCEFONTEXIST
| CF_SCREENFONTS
| CF_NOVERTFONTS
;
7892 /* Unless include_proportional is non-nil, limit the selection to
7893 monospaced fonts. */
7894 if (NILP (include_proportional
))
7895 cf
.Flags
|= CF_FIXEDPITCHONLY
;
7899 /* Initialize as much of the font details as we can from the current
7901 hdc
= GetDC (FRAME_W32_WINDOW (f
));
7902 oldobj
= SelectObject (hdc
, FRAME_FONT (f
)->hfont
);
7903 GetTextFace (hdc
, LF_FACESIZE
, lf
.lfFaceName
);
7904 if (GetTextMetrics (hdc
, &tm
))
7906 lf
.lfHeight
= tm
.tmInternalLeading
- tm
.tmHeight
;
7907 lf
.lfWeight
= tm
.tmWeight
;
7908 lf
.lfItalic
= tm
.tmItalic
;
7909 lf
.lfUnderline
= tm
.tmUnderlined
;
7910 lf
.lfStrikeOut
= tm
.tmStruckOut
;
7911 lf
.lfCharSet
= tm
.tmCharSet
;
7912 cf
.Flags
|= CF_INITTOLOGFONTSTRUCT
;
7914 SelectObject (hdc
, oldobj
);
7915 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
7917 if (!ChooseFont (&cf
) || !w32_to_x_font (&lf
, buf
, 100, NULL
))
7920 return build_string (buf
);
7923 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
,
7924 Sw32_send_sys_command
, 1, 2, 0,
7925 doc
: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND.
7926 Some useful values for command are #xf030 to maximise frame (#xf020
7927 to minimize), #xf120 to restore frame to original size, and #xf100
7928 to activate the menubar for keyboard access. #xf140 activates the
7929 screen saver if defined.
7931 If optional parameter FRAME is not specified, use selected frame. */)
7933 Lisp_Object command
, frame
;
7935 FRAME_PTR f
= check_x_frame (frame
);
7937 CHECK_NUMBER (command
);
7939 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
7944 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
7945 doc
: /* Get Windows to perform OPERATION on DOCUMENT.
7946 This is a wrapper around the ShellExecute system function, which
7947 invokes the application registered to handle OPERATION for DOCUMENT.
7948 OPERATION is typically \"open\", \"print\" or \"explore\" (but can be
7949 nil for the default action), and DOCUMENT is typically the name of a
7950 document file or URL, but can also be a program executable to run or
7951 a directory to open in the Windows Explorer.
7953 If DOCUMENT is a program executable, PARAMETERS can be a string
7954 containing command line parameters, but otherwise should be nil.
7956 SHOW-FLAG can be used to control whether the invoked application is hidden
7957 or minimized. If SHOW-FLAG is nil, the application is displayed normally,
7958 otherwise it is an integer representing a ShowWindow flag:
7963 6 - start minimized */)
7964 (operation
, document
, parameters
, show_flag
)
7965 Lisp_Object operation
, document
, parameters
, show_flag
;
7967 Lisp_Object current_dir
;
7969 CHECK_STRING (document
);
7971 /* Encode filename and current directory. */
7972 current_dir
= ENCODE_FILE (current_buffer
->directory
);
7973 document
= ENCODE_FILE (document
);
7974 if ((int) ShellExecute (NULL
,
7975 (STRINGP (operation
) ?
7976 SDATA (operation
) : NULL
),
7978 (STRINGP (parameters
) ?
7979 SDATA (parameters
) : NULL
),
7980 SDATA (current_dir
),
7981 (INTEGERP (show_flag
) ?
7982 XINT (show_flag
) : SW_SHOWDEFAULT
))
7985 error ("ShellExecute failed: %s", w32_strerror (0));
7988 /* Lookup virtual keycode from string representing the name of a
7989 non-ascii keystroke into the corresponding virtual key, using
7990 lispy_function_keys. */
7992 lookup_vk_code (char *key
)
7996 for (i
= 0; i
< 256; i
++)
7997 if (lispy_function_keys
[i
] != 0
7998 && strcmp (lispy_function_keys
[i
], key
) == 0)
8004 /* Convert a one-element vector style key sequence to a hot key
8007 w32_parse_hot_key (key
)
8010 /* Copied from Fdefine_key and store_in_keymap. */
8011 register Lisp_Object c
;
8015 struct gcpro gcpro1
;
8019 if (XFASTINT (Flength (key
)) != 1)
8024 c
= Faref (key
, make_number (0));
8026 if (CONSP (c
) && lucid_event_type_list_p (c
))
8027 c
= Fevent_convert_list (c
);
8031 if (! INTEGERP (c
) && ! SYMBOLP (c
))
8032 error ("Key definition is invalid");
8034 /* Work out the base key and the modifiers. */
8037 c
= parse_modifiers (c
);
8038 lisp_modifiers
= Fcar (Fcdr (c
));
8042 vk_code
= lookup_vk_code (SDATA (SYMBOL_NAME (c
)));
8044 else if (INTEGERP (c
))
8046 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
8047 /* Many ascii characters are their own virtual key code. */
8048 vk_code
= XINT (c
) & CHARACTERBITS
;
8051 if (vk_code
< 0 || vk_code
> 255)
8054 if ((lisp_modifiers
& meta_modifier
) != 0
8055 && !NILP (Vw32_alt_is_meta
))
8056 lisp_modifiers
|= alt_modifier
;
8058 /* Supply defs missing from mingw32. */
8060 #define MOD_ALT 0x0001
8061 #define MOD_CONTROL 0x0002
8062 #define MOD_SHIFT 0x0004
8063 #define MOD_WIN 0x0008
8066 /* Convert lisp modifiers to Windows hot-key form. */
8067 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
8068 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
8069 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
8070 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
8072 return HOTKEY (vk_code
, w32_modifiers
);
8075 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
,
8076 Sw32_register_hot_key
, 1, 1, 0,
8077 doc
: /* Register KEY as a hot-key combination.
8078 Certain key combinations like Alt-Tab are reserved for system use on
8079 Windows, and therefore are normally intercepted by the system. However,
8080 most of these key combinations can be received by registering them as
8081 hot-keys, overriding their special meaning.
8083 KEY must be a one element key definition in vector form that would be
8084 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta
8085 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper
8086 is always interpreted as the Windows modifier keys.
8088 The return value is the hotkey-id if registered, otherwise nil. */)
8092 key
= w32_parse_hot_key (key
);
8094 if (NILP (Fmemq (key
, w32_grabbed_keys
)))
8096 /* Reuse an empty slot if possible. */
8097 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
8099 /* Safe to add new key to list, even if we have focus. */
8101 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
8103 XSETCAR (item
, key
);
8105 /* Notify input thread about new hot-key definition, so that it
8106 takes effect without needing to switch focus. */
8107 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
8114 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
,
8115 Sw32_unregister_hot_key
, 1, 1, 0,
8116 doc
: /* Unregister HOTKEY as a hot-key combination. */)
8122 if (!INTEGERP (key
))
8123 key
= w32_parse_hot_key (key
);
8125 item
= Fmemq (key
, w32_grabbed_keys
);
8129 /* Notify input thread about hot-key definition being removed, so
8130 that it takes effect without needing focus switch. */
8131 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
8132 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
))
8135 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
8142 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
,
8143 Sw32_registered_hot_keys
, 0, 0, 0,
8144 doc
: /* Return list of registered hot-key IDs. */)
8147 return Fcopy_sequence (w32_grabbed_keys
);
8150 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
,
8151 Sw32_reconstruct_hot_key
, 1, 1, 0,
8152 doc
: /* Convert hot-key ID to a lisp key combination. */)
8154 Lisp_Object hotkeyid
;
8156 int vk_code
, w32_modifiers
;
8159 CHECK_NUMBER (hotkeyid
);
8161 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
8162 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
8164 if (lispy_function_keys
[vk_code
])
8165 key
= intern (lispy_function_keys
[vk_code
]);
8167 key
= make_number (vk_code
);
8169 key
= Fcons (key
, Qnil
);
8170 if (w32_modifiers
& MOD_SHIFT
)
8171 key
= Fcons (Qshift
, key
);
8172 if (w32_modifiers
& MOD_CONTROL
)
8173 key
= Fcons (Qctrl
, key
);
8174 if (w32_modifiers
& MOD_ALT
)
8175 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
8176 if (w32_modifiers
& MOD_WIN
)
8177 key
= Fcons (Qhyper
, key
);
8182 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
,
8183 Sw32_toggle_lock_key
, 1, 2, 0,
8184 doc
: /* Toggle the state of the lock key KEY.
8185 KEY can be `capslock', `kp-numlock', or `scroll'.
8186 If the optional parameter NEW-STATE is a number, then the state of KEY
8187 is set to off if the low bit of NEW-STATE is zero, otherwise on. */)
8189 Lisp_Object key
, new_state
;
8193 if (EQ (key
, intern ("capslock")))
8194 vk_code
= VK_CAPITAL
;
8195 else if (EQ (key
, intern ("kp-numlock")))
8196 vk_code
= VK_NUMLOCK
;
8197 else if (EQ (key
, intern ("scroll")))
8198 vk_code
= VK_SCROLL
;
8202 if (!dwWindowsThreadId
)
8203 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
8205 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
8206 (WPARAM
) vk_code
, (LPARAM
) new_state
))
8209 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
8210 return make_number (msg
.wParam
);
8215 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
8216 doc
: /* Return storage information about the file system FILENAME is on.
8217 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
8218 storage of the file system, FREE is the free storage, and AVAIL is the
8219 storage available to a non-superuser. All 3 numbers are in bytes.
8220 If the underlying system call fails, value is nil. */)
8222 Lisp_Object filename
;
8224 Lisp_Object encoded
, value
;
8226 CHECK_STRING (filename
);
8227 filename
= Fexpand_file_name (filename
, Qnil
);
8228 encoded
= ENCODE_FILE (filename
);
8232 /* Determining the required information on Windows turns out, sadly,
8233 to be more involved than one would hope. The original Win32 api
8234 call for this will return bogus information on some systems, but we
8235 must dynamically probe for the replacement api, since that was
8236 added rather late on. */
8238 HMODULE hKernel
= GetModuleHandle ("kernel32");
8239 BOOL (*pfn_GetDiskFreeSpaceEx
)
8240 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
8241 = (void *) GetProcAddress (hKernel
, "GetDiskFreeSpaceEx");
8243 /* On Windows, we may need to specify the root directory of the
8244 volume holding FILENAME. */
8245 char rootname
[MAX_PATH
];
8246 char *name
= SDATA (encoded
);
8248 /* find the root name of the volume if given */
8249 if (isalpha (name
[0]) && name
[1] == ':')
8251 rootname
[0] = name
[0];
8252 rootname
[1] = name
[1];
8256 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
8258 char *str
= rootname
;
8262 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
8272 if (pfn_GetDiskFreeSpaceEx
)
8274 /* Unsigned large integers cannot be cast to double, so
8275 use signed ones instead. */
8276 LARGE_INTEGER availbytes
;
8277 LARGE_INTEGER freebytes
;
8278 LARGE_INTEGER totalbytes
;
8280 if (pfn_GetDiskFreeSpaceEx(rootname
,
8281 (ULARGE_INTEGER
*)&availbytes
,
8282 (ULARGE_INTEGER
*)&totalbytes
,
8283 (ULARGE_INTEGER
*)&freebytes
))
8284 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
8285 make_float ((double) freebytes
.QuadPart
),
8286 make_float ((double) availbytes
.QuadPart
));
8290 DWORD sectors_per_cluster
;
8291 DWORD bytes_per_sector
;
8292 DWORD free_clusters
;
8293 DWORD total_clusters
;
8295 if (GetDiskFreeSpace(rootname
,
8296 §ors_per_cluster
,
8300 value
= list3 (make_float ((double) total_clusters
8301 * sectors_per_cluster
* bytes_per_sector
),
8302 make_float ((double) free_clusters
8303 * sectors_per_cluster
* bytes_per_sector
),
8304 make_float ((double) free_clusters
8305 * sectors_per_cluster
* bytes_per_sector
));
8312 DEFUN ("default-printer-name", Fdefault_printer_name
, Sdefault_printer_name
,
8313 0, 0, 0, doc
: /* Return the name of Windows default printer device. */)
8316 static char pname_buf
[256];
8319 PRINTER_INFO_2
*ppi2
= NULL
;
8320 DWORD dwNeeded
= 0, dwReturned
= 0;
8322 /* Retrieve the default string from Win.ini (the registry).
8323 * String will be in form "printername,drivername,portname".
8324 * This is the most portable way to get the default printer. */
8325 if (GetProfileString ("windows", "device", ",,", pname_buf
, sizeof (pname_buf
)) <= 0)
8327 /* printername precedes first "," character */
8328 strtok (pname_buf
, ",");
8329 /* We want to know more than the printer name */
8330 if (!OpenPrinter (pname_buf
, &hPrn
, NULL
))
8332 GetPrinter (hPrn
, 2, NULL
, 0, &dwNeeded
);
8335 ClosePrinter (hPrn
);
8338 /* Allocate memory for the PRINTER_INFO_2 struct */
8339 ppi2
= (PRINTER_INFO_2
*) xmalloc (dwNeeded
);
8342 ClosePrinter (hPrn
);
8345 /* Call GetPrinter() again with big enouth memory block */
8346 err
= GetPrinter (hPrn
, 2, (LPBYTE
)ppi2
, dwNeeded
, &dwReturned
);
8347 ClosePrinter (hPrn
);
8356 if (ppi2
->Attributes
& PRINTER_ATTRIBUTE_SHARED
&& ppi2
->pServerName
)
8358 /* a remote printer */
8359 if (*ppi2
->pServerName
== '\\')
8360 _snprintf(pname_buf
, sizeof (pname_buf
), "%s\\%s", ppi2
->pServerName
,
8363 _snprintf(pname_buf
, sizeof (pname_buf
), "\\\\%s\\%s", ppi2
->pServerName
,
8365 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
8369 /* a local printer */
8370 strncpy(pname_buf
, ppi2
->pPortName
, sizeof (pname_buf
));
8371 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
8372 /* `pPortName' can include several ports, delimited by ','.
8373 * we only use the first one. */
8374 strtok(pname_buf
, ",");
8379 return build_string (pname_buf
);
8382 /***********************************************************************
8384 ***********************************************************************/
8386 /* Keep this list in the same order as frame_parms in frame.c.
8387 Use 0 for unsupported frame parameters. */
8389 frame_parm_handler w32_frame_parm_handlers
[] =
8393 x_set_background_color
,
8399 x_set_foreground_color
,
8402 x_set_internal_border_width
,
8403 x_set_menu_bar_lines
,
8405 x_explicitly_set_name
,
8406 x_set_scroll_bar_width
,
8409 x_set_vertical_scroll_bars
,
8411 x_set_tool_bar_lines
,
8412 0, /* x_set_scroll_bar_foreground, */
8413 0, /* x_set_scroll_bar_background, */
8418 0, /* x_set_wait_for_wm, */
8425 globals_of_w32fns ();
8426 /* This is zero if not using MS-Windows. */
8428 track_mouse_window
= NULL
;
8430 w32_visible_system_caret_hwnd
= NULL
;
8432 Qnone
= intern ("none");
8434 Qsuppress_icon
= intern ("suppress-icon");
8435 staticpro (&Qsuppress_icon
);
8436 Qundefined_color
= intern ("undefined-color");
8437 staticpro (&Qundefined_color
);
8438 Qcancel_timer
= intern ("cancel-timer");
8439 staticpro (&Qcancel_timer
);
8441 Qhyper
= intern ("hyper");
8442 staticpro (&Qhyper
);
8443 Qsuper
= intern ("super");
8444 staticpro (&Qsuper
);
8445 Qmeta
= intern ("meta");
8447 Qalt
= intern ("alt");
8449 Qctrl
= intern ("ctrl");
8451 Qcontrol
= intern ("control");
8452 staticpro (&Qcontrol
);
8453 Qshift
= intern ("shift");
8454 staticpro (&Qshift
);
8455 /* This is the end of symbol initialization. */
8457 /* Text property `display' should be nonsticky by default. */
8458 Vtext_property_default_nonsticky
8459 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
8462 Fput (Qundefined_color
, Qerror_conditions
,
8463 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
8464 Fput (Qundefined_color
, Qerror_message
,
8465 build_string ("Undefined color"));
8467 staticpro (&w32_grabbed_keys
);
8468 w32_grabbed_keys
= Qnil
;
8470 DEFVAR_LISP ("w32-color-map", &Vw32_color_map
,
8471 doc
: /* An array of color name mappings for windows. */);
8472 Vw32_color_map
= Qnil
;
8474 DEFVAR_LISP ("w32-pass-alt-to-system", &Vw32_pass_alt_to_system
,
8475 doc
: /* Non-nil if alt key presses are passed on to Windows.
8476 When non-nil, for example, alt pressed and released and then space will
8477 open the System menu. When nil, Emacs silently swallows alt key events. */);
8478 Vw32_pass_alt_to_system
= Qnil
;
8480 DEFVAR_LISP ("w32-alt-is-meta", &Vw32_alt_is_meta
,
8481 doc
: /* Non-nil if the alt key is to be considered the same as the meta key.
8482 When nil, Emacs will translate the alt key to the Alt modifier, and not Meta. */);
8483 Vw32_alt_is_meta
= Qt
;
8485 DEFVAR_INT ("w32-quit-key", &Vw32_quit_key
,
8486 doc
: /* If non-zero, the virtual key code for an alternative quit key. */);
8487 XSETINT (Vw32_quit_key
, 0);
8489 DEFVAR_LISP ("w32-pass-lwindow-to-system",
8490 &Vw32_pass_lwindow_to_system
,
8491 doc
: /* Non-nil if the left \"Windows\" key is passed on to Windows.
8492 When non-nil, the Start menu is opened by tapping the key. */);
8493 Vw32_pass_lwindow_to_system
= Qt
;
8495 DEFVAR_LISP ("w32-pass-rwindow-to-system",
8496 &Vw32_pass_rwindow_to_system
,
8497 doc
: /* Non-nil if the right \"Windows\" key is passed on to Windows.
8498 When non-nil, the Start menu is opened by tapping the key. */);
8499 Vw32_pass_rwindow_to_system
= Qt
;
8501 DEFVAR_INT ("w32-phantom-key-code",
8502 &Vw32_phantom_key_code
,
8503 doc
: /* Virtual key code used to generate \"phantom\" key presses.
8504 Value is a number between 0 and 255.
8506 Phantom key presses are generated in order to stop the system from
8507 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or
8508 `w32-pass-rwindow-to-system' is nil. */);
8509 /* Although 255 is technically not a valid key code, it works and
8510 means that this hack won't interfere with any real key code. */
8511 Vw32_phantom_key_code
= 255;
8513 DEFVAR_LISP ("w32-enable-num-lock",
8514 &Vw32_enable_num_lock
,
8515 doc
: /* Non-nil if Num Lock should act normally.
8516 Set to nil to see Num Lock as the key `kp-numlock'. */);
8517 Vw32_enable_num_lock
= Qt
;
8519 DEFVAR_LISP ("w32-enable-caps-lock",
8520 &Vw32_enable_caps_lock
,
8521 doc
: /* Non-nil if Caps Lock should act normally.
8522 Set to nil to see Caps Lock as the key `capslock'. */);
8523 Vw32_enable_caps_lock
= Qt
;
8525 DEFVAR_LISP ("w32-scroll-lock-modifier",
8526 &Vw32_scroll_lock_modifier
,
8527 doc
: /* Modifier to use for the Scroll Lock on state.
8528 The value can be hyper, super, meta, alt, control or shift for the
8529 respective modifier, or nil to see Scroll Lock as the key `scroll'.
8530 Any other value will cause the key to be ignored. */);
8531 Vw32_scroll_lock_modifier
= Qt
;
8533 DEFVAR_LISP ("w32-lwindow-modifier",
8534 &Vw32_lwindow_modifier
,
8535 doc
: /* Modifier to use for the left \"Windows\" key.
8536 The value can be hyper, super, meta, alt, control or shift for the
8537 respective modifier, or nil to appear as the key `lwindow'.
8538 Any other value will cause the key to be ignored. */);
8539 Vw32_lwindow_modifier
= Qnil
;
8541 DEFVAR_LISP ("w32-rwindow-modifier",
8542 &Vw32_rwindow_modifier
,
8543 doc
: /* Modifier to use for the right \"Windows\" key.
8544 The value can be hyper, super, meta, alt, control or shift for the
8545 respective modifier, or nil to appear as the key `rwindow'.
8546 Any other value will cause the key to be ignored. */);
8547 Vw32_rwindow_modifier
= Qnil
;
8549 DEFVAR_LISP ("w32-apps-modifier",
8550 &Vw32_apps_modifier
,
8551 doc
: /* Modifier to use for the \"Apps\" key.
8552 The value can be hyper, super, meta, alt, control or shift for the
8553 respective modifier, or nil to appear as the key `apps'.
8554 Any other value will cause the key to be ignored. */);
8555 Vw32_apps_modifier
= Qnil
;
8557 DEFVAR_BOOL ("w32-enable-synthesized-fonts", &w32_enable_synthesized_fonts
,
8558 doc
: /* Non-nil enables selection of artificially italicized and bold fonts. */);
8559 w32_enable_synthesized_fonts
= 0;
8561 DEFVAR_LISP ("w32-enable-palette", &Vw32_enable_palette
,
8562 doc
: /* Non-nil enables Windows palette management to map colors exactly. */);
8563 Vw32_enable_palette
= Qt
;
8565 DEFVAR_INT ("w32-mouse-button-tolerance",
8566 &Vw32_mouse_button_tolerance
,
8567 doc
: /* Analogue of double click interval for faking middle mouse events.
8568 The value is the minimum time in milliseconds that must elapse between
8569 left/right button down events before they are considered distinct events.
8570 If both mouse buttons are depressed within this interval, a middle mouse
8571 button down event is generated instead. */);
8572 XSETINT (Vw32_mouse_button_tolerance
, GetDoubleClickTime () / 2);
8574 DEFVAR_INT ("w32-mouse-move-interval",
8575 &Vw32_mouse_move_interval
,
8576 doc
: /* Minimum interval between mouse move events.
8577 The value is the minimum time in milliseconds that must elapse between
8578 successive mouse move (or scroll bar drag) events before they are
8579 reported as lisp events. */);
8580 XSETINT (Vw32_mouse_move_interval
, 0);
8582 DEFVAR_BOOL ("w32-pass-extra-mouse-buttons-to-system",
8583 &w32_pass_extra_mouse_buttons_to_system
,
8584 doc
: /* Non-nil if the fourth and fifth mouse buttons are passed to Windows.
8585 Recent versions of Windows support mice with up to five buttons.
8586 Since most applications don't support these extra buttons, most mouse
8587 drivers will allow you to map them to functions at the system level.
8588 If this variable is non-nil, Emacs will pass them on, allowing the
8589 system to handle them. */);
8590 w32_pass_extra_mouse_buttons_to_system
= 0;
8592 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
8593 doc
: /* The shape of the pointer when over text.
8594 Changing the value does not affect existing frames
8595 unless you set the mouse color. */);
8596 Vx_pointer_shape
= Qnil
;
8598 Vx_nontext_pointer_shape
= Qnil
;
8600 Vx_mode_pointer_shape
= Qnil
;
8602 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
8603 doc
: /* The shape of the pointer when Emacs is busy.
8604 This variable takes effect when you create a new frame
8605 or when you set the mouse color. */);
8606 Vx_hourglass_pointer_shape
= Qnil
;
8608 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
8609 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
8610 display_hourglass_p
= 1;
8612 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
8613 doc
: /* *Seconds to wait before displaying an hourglass pointer.
8614 Value must be an integer or float. */);
8615 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
8617 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
8618 &Vx_sensitive_text_pointer_shape
,
8619 doc
: /* The shape of the pointer when over mouse-sensitive text.
8620 This variable takes effect when you create a new frame
8621 or when you set the mouse color. */);
8622 Vx_sensitive_text_pointer_shape
= Qnil
;
8624 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
8625 &Vx_window_horizontal_drag_shape
,
8626 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
8627 This variable takes effect when you create a new frame
8628 or when you set the mouse color. */);
8629 Vx_window_horizontal_drag_shape
= Qnil
;
8631 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
8632 doc
: /* A string indicating the foreground color of the cursor box. */);
8633 Vx_cursor_fore_pixel
= Qnil
;
8635 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size
,
8636 doc
: /* Maximum size for tooltips.
8637 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
8638 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
8640 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
8641 doc
: /* Non-nil if no window manager is in use.
8642 Emacs doesn't try to figure this out; this is always nil
8643 unless you set it to something else. */);
8644 /* We don't have any way to find this out, so set it to nil
8645 and maybe the user would like to set it to t. */
8646 Vx_no_window_manager
= Qnil
;
8648 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
8649 &Vx_pixel_size_width_font_regexp
,
8650 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
8652 Since Emacs gets width of a font matching with this regexp from
8653 PIXEL_SIZE field of the name, font finding mechanism gets faster for
8654 such a font. This is especially effective for such large fonts as
8655 Chinese, Japanese, and Korean. */);
8656 Vx_pixel_size_width_font_regexp
= Qnil
;
8658 DEFVAR_LISP ("w32-bdf-filename-alist",
8659 &Vw32_bdf_filename_alist
,
8660 doc
: /* List of bdf fonts and their corresponding filenames. */);
8661 Vw32_bdf_filename_alist
= Qnil
;
8663 DEFVAR_BOOL ("w32-strict-fontnames",
8664 &w32_strict_fontnames
,
8665 doc
: /* Non-nil means only use fonts that are exact matches for those requested.
8666 Default is nil, which allows old fontnames that are not XLFD compliant,
8667 and allows third-party CJK display to work by specifying false charset
8668 fields to trick Emacs into translating to Big5, SJIS etc.
8669 Setting this to t will prevent wrong fonts being selected when
8670 fontsets are automatically created. */);
8671 w32_strict_fontnames
= 0;
8673 DEFVAR_BOOL ("w32-strict-painting",
8674 &w32_strict_painting
,
8675 doc
: /* Non-nil means use strict rules for repainting frames.
8676 Set this to nil to get the old behaviour for repainting; this should
8677 only be necessary if the default setting causes problems. */);
8678 w32_strict_painting
= 1;
8680 DEFVAR_LISP ("w32-charset-info-alist",
8681 &Vw32_charset_info_alist
,
8682 doc
: /* Alist linking Emacs character sets to Windows fonts and codepages.
8683 Each entry should be of the form:
8685 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE))
8687 where CHARSET_NAME is a string used in font names to identify the charset,
8688 WINDOWS_CHARSET is a symbol that can be one of:
8689 w32-charset-ansi, w32-charset-default, w32-charset-symbol,
8690 w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312,
8691 w32-charset-chinesebig5,
8692 w32-charset-johab, w32-charset-hebrew,
8693 w32-charset-arabic, w32-charset-greek, w32-charset-turkish,
8694 w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope,
8695 w32-charset-russian, w32-charset-mac, w32-charset-baltic,
8696 w32-charset-unicode,
8698 CODEPAGE should be an integer specifying the codepage that should be used
8699 to display the character set, t to do no translation and output as Unicode,
8700 or nil to do no translation and output as 8 bit (or multibyte on far-east
8701 versions of Windows) characters. */);
8702 Vw32_charset_info_alist
= Qnil
;
8704 staticpro (&Qw32_charset_ansi
);
8705 Qw32_charset_ansi
= intern ("w32-charset-ansi");
8706 staticpro (&Qw32_charset_symbol
);
8707 Qw32_charset_symbol
= intern ("w32-charset-symbol");
8708 staticpro (&Qw32_charset_shiftjis
);
8709 Qw32_charset_shiftjis
= intern ("w32-charset-shiftjis");
8710 staticpro (&Qw32_charset_hangeul
);
8711 Qw32_charset_hangeul
= intern ("w32-charset-hangeul");
8712 staticpro (&Qw32_charset_chinesebig5
);
8713 Qw32_charset_chinesebig5
= intern ("w32-charset-chinesebig5");
8714 staticpro (&Qw32_charset_gb2312
);
8715 Qw32_charset_gb2312
= intern ("w32-charset-gb2312");
8716 staticpro (&Qw32_charset_oem
);
8717 Qw32_charset_oem
= intern ("w32-charset-oem");
8719 #ifdef JOHAB_CHARSET
8721 static int w32_extra_charsets_defined
= 1;
8722 DEFVAR_BOOL ("w32-extra-charsets-defined", &w32_extra_charsets_defined
,
8723 doc
: /* Internal variable. */);
8725 staticpro (&Qw32_charset_johab
);
8726 Qw32_charset_johab
= intern ("w32-charset-johab");
8727 staticpro (&Qw32_charset_easteurope
);
8728 Qw32_charset_easteurope
= intern ("w32-charset-easteurope");
8729 staticpro (&Qw32_charset_turkish
);
8730 Qw32_charset_turkish
= intern ("w32-charset-turkish");
8731 staticpro (&Qw32_charset_baltic
);
8732 Qw32_charset_baltic
= intern ("w32-charset-baltic");
8733 staticpro (&Qw32_charset_russian
);
8734 Qw32_charset_russian
= intern ("w32-charset-russian");
8735 staticpro (&Qw32_charset_arabic
);
8736 Qw32_charset_arabic
= intern ("w32-charset-arabic");
8737 staticpro (&Qw32_charset_greek
);
8738 Qw32_charset_greek
= intern ("w32-charset-greek");
8739 staticpro (&Qw32_charset_hebrew
);
8740 Qw32_charset_hebrew
= intern ("w32-charset-hebrew");
8741 staticpro (&Qw32_charset_vietnamese
);
8742 Qw32_charset_vietnamese
= intern ("w32-charset-vietnamese");
8743 staticpro (&Qw32_charset_thai
);
8744 Qw32_charset_thai
= intern ("w32-charset-thai");
8745 staticpro (&Qw32_charset_mac
);
8746 Qw32_charset_mac
= intern ("w32-charset-mac");
8750 #ifdef UNICODE_CHARSET
8752 static int w32_unicode_charset_defined
= 1;
8753 DEFVAR_BOOL ("w32-unicode-charset-defined",
8754 &w32_unicode_charset_defined
,
8755 doc
: /* Internal variable. */);
8757 staticpro (&Qw32_charset_unicode
);
8758 Qw32_charset_unicode
= intern ("w32-charset-unicode");
8761 #if 0 /* TODO: Port to W32 */
8762 defsubr (&Sx_change_window_property
);
8763 defsubr (&Sx_delete_window_property
);
8764 defsubr (&Sx_window_property
);
8766 defsubr (&Sxw_display_color_p
);
8767 defsubr (&Sx_display_grayscale_p
);
8768 defsubr (&Sxw_color_defined_p
);
8769 defsubr (&Sxw_color_values
);
8770 defsubr (&Sx_server_max_request_size
);
8771 defsubr (&Sx_server_vendor
);
8772 defsubr (&Sx_server_version
);
8773 defsubr (&Sx_display_pixel_width
);
8774 defsubr (&Sx_display_pixel_height
);
8775 defsubr (&Sx_display_mm_width
);
8776 defsubr (&Sx_display_mm_height
);
8777 defsubr (&Sx_display_screens
);
8778 defsubr (&Sx_display_planes
);
8779 defsubr (&Sx_display_color_cells
);
8780 defsubr (&Sx_display_visual_class
);
8781 defsubr (&Sx_display_backing_store
);
8782 defsubr (&Sx_display_save_under
);
8783 defsubr (&Sx_create_frame
);
8784 defsubr (&Sx_open_connection
);
8785 defsubr (&Sx_close_connection
);
8786 defsubr (&Sx_display_list
);
8787 defsubr (&Sx_synchronize
);
8789 /* W32 specific functions */
8791 defsubr (&Sw32_focus_frame
);
8792 defsubr (&Sw32_select_font
);
8793 defsubr (&Sw32_define_rgb_color
);
8794 defsubr (&Sw32_default_color_map
);
8795 defsubr (&Sw32_load_color_file
);
8796 defsubr (&Sw32_send_sys_command
);
8797 defsubr (&Sw32_shell_execute
);
8798 defsubr (&Sw32_register_hot_key
);
8799 defsubr (&Sw32_unregister_hot_key
);
8800 defsubr (&Sw32_registered_hot_keys
);
8801 defsubr (&Sw32_reconstruct_hot_key
);
8802 defsubr (&Sw32_toggle_lock_key
);
8803 defsubr (&Sw32_find_bdf_fonts
);
8805 defsubr (&Sfile_system_info
);
8806 defsubr (&Sdefault_printer_name
);
8808 /* Setting callback functions for fontset handler. */
8809 get_font_info_func
= w32_get_font_info
;
8811 #if 0 /* This function pointer doesn't seem to be used anywhere.
8812 And the pointer assigned has the wrong type, anyway. */
8813 list_fonts_func
= w32_list_fonts
;
8816 load_font_func
= w32_load_font
;
8817 find_ccl_program_func
= w32_find_ccl_program
;
8818 query_font_func
= w32_query_font
;
8819 set_frame_fontset_func
= x_set_font
;
8820 get_font_repertory_func
= x_get_font_repertory
;
8821 check_window_system_func
= check_w32
;
8824 hourglass_atimer
= NULL
;
8825 hourglass_shown_p
= 0;
8826 defsubr (&Sx_show_tip
);
8827 defsubr (&Sx_hide_tip
);
8829 staticpro (&tip_timer
);
8831 staticpro (&tip_frame
);
8833 last_show_tip_args
= Qnil
;
8834 staticpro (&last_show_tip_args
);
8836 defsubr (&Sx_file_dialog
);
8841 globals_of_w32fns is used to initialize those global variables that
8842 must always be initialized on startup even when the global variable
8843 initialized is non zero (see the function main in emacs.c).
8844 globals_of_w32fns is called from syms_of_w32fns when the global
8845 variable initialized is 0 and directly from main when initialized
8848 void globals_of_w32fns ()
8850 HMODULE user32_lib
= GetModuleHandle ("user32.dll");
8852 TrackMouseEvent not available in all versions of Windows, so must load
8853 it dynamically. Do it once, here, instead of every time it is used.
8855 track_mouse_event_fn
= (TrackMouseEvent_Proc
)
8856 GetProcAddress (user32_lib
, "TrackMouseEvent");
8857 /* ditto for GetClipboardSequenceNumber. */
8858 clipboard_sequence_fn
= (ClipboardSequence_Proc
)
8859 GetProcAddress (user32_lib
, "GetClipboardSequenceNumber");
8868 button
= MessageBox (NULL
,
8869 "A fatal error has occurred!\n\n"
8870 "Select Abort to exit, Retry to debug, Ignore to continue",
8871 "Emacs Abort Dialog",
8872 MB_ICONEXCLAMATION
| MB_TASKMODAL
8873 | MB_SETFOREGROUND
| MB_ABORTRETRYIGNORE
);
8888 /* For convenience when debugging. */
8892 return GetLastError ();
8895 /* arch-tag: 707589ab-b9be-4638-8cdd-74629cc9b446
8896 (do not change this comment) */