1 /* Graphical user interface functions for the Microsoft W32 API.
2 Copyright (C) 1989, 1992, 93, 94, 95, 96, 97, 98, 99, 2000, 01, 04
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* Added by Kevin Gallo */
33 #include "dispextern.h"
40 #include "intervals.h"
41 #include "blockinput.h"
44 #include "termhooks.h"
49 #include "bitmaps/gray.xbm"
57 #define FILE_NAME_TEXT_FIELD edt1
59 void syms_of_w32fns ();
60 void globals_of_w32fns ();
62 extern void free_frame_menubar ();
63 extern double atof ();
64 extern int w32_console_toggle_lock_key
P_ ((int, Lisp_Object
));
65 extern void w32_menu_display_help
P_ ((HWND
, HMENU
, UINT
, UINT
));
66 extern void w32_free_menu_strings
P_ ((HWND
));
70 extern char *lispy_function_keys
[];
72 /* The gray bitmap `bitmaps/gray'. This is done because w32term.c uses
73 it, and including `bitmaps/gray' more than once is a problem when
74 config.h defines `static' as an empty replacement string. */
76 int gray_bitmap_width
= gray_width
;
77 int gray_bitmap_height
= gray_height
;
78 unsigned char *gray_bitmap_bits
= gray_bits
;
80 /* The colormap for converting color names to RGB values */
81 Lisp_Object Vw32_color_map
;
83 /* Non nil if alt key presses are passed on to Windows. */
84 Lisp_Object Vw32_pass_alt_to_system
;
86 /* Non nil if alt key is translated to meta_modifier, nil if it is translated
88 Lisp_Object Vw32_alt_is_meta
;
90 /* If non-zero, the windows virtual key code for an alternative quit key. */
93 /* Non nil if left window key events are passed on to Windows (this only
94 affects whether "tapping" the key opens the Start menu). */
95 Lisp_Object Vw32_pass_lwindow_to_system
;
97 /* Non nil if right window key events are passed on to Windows (this
98 only affects whether "tapping" the key opens the Start menu). */
99 Lisp_Object Vw32_pass_rwindow_to_system
;
101 /* Virtual key code used to generate "phantom" key presses in order
102 to stop system from acting on Windows key events. */
103 Lisp_Object Vw32_phantom_key_code
;
105 /* Modifier associated with the left "Windows" key, or nil to act as a
107 Lisp_Object Vw32_lwindow_modifier
;
109 /* Modifier associated with the right "Windows" key, or nil to act as a
111 Lisp_Object Vw32_rwindow_modifier
;
113 /* Modifier associated with the "Apps" key, or nil to act as a normal
115 Lisp_Object Vw32_apps_modifier
;
117 /* Value is nil if Num Lock acts as a function key. */
118 Lisp_Object Vw32_enable_num_lock
;
120 /* Value is nil if Caps Lock acts as a function key. */
121 Lisp_Object Vw32_enable_caps_lock
;
123 /* Modifier associated with Scroll Lock, or nil to act as a normal key. */
124 Lisp_Object Vw32_scroll_lock_modifier
;
126 /* Switch to control whether we inhibit requests for synthesized bold
127 and italic versions of fonts. */
128 int w32_enable_synthesized_fonts
;
130 /* Enable palette management. */
131 Lisp_Object Vw32_enable_palette
;
133 /* Control how close left/right button down events must be to
134 be converted to a middle button down event. */
135 int w32_mouse_button_tolerance
;
137 /* Minimum interval between mouse movement (and scroll bar drag)
138 events that are passed on to the event loop. */
139 int w32_mouse_move_interval
;
141 /* Flag to indicate if XBUTTON events should be passed on to Windows. */
142 int w32_pass_extra_mouse_buttons_to_system
;
144 /* Non nil if no window manager is in use. */
145 Lisp_Object Vx_no_window_manager
;
147 /* Non-zero means we're allowed to display a hourglass pointer. */
149 int display_hourglass_p
;
151 /* The background and shape of the mouse pointer, and shape when not
152 over text or in the modeline. */
154 Lisp_Object Vx_pointer_shape
, Vx_nontext_pointer_shape
, Vx_mode_pointer_shape
;
155 Lisp_Object Vx_hourglass_pointer_shape
, Vx_window_horizontal_drag_shape
, Vx_hand_shape
;
157 /* The shape when over mouse-sensitive text. */
159 Lisp_Object Vx_sensitive_text_pointer_shape
;
162 #define IDC_HAND MAKEINTRESOURCE(32649)
165 /* Color of chars displayed in cursor box. */
167 Lisp_Object Vx_cursor_fore_pixel
;
169 /* Nonzero if using Windows. */
171 static int w32_in_use
;
173 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
175 Lisp_Object Vx_pixel_size_width_font_regexp
;
177 /* Alist of bdf fonts and the files that define them. */
178 Lisp_Object Vw32_bdf_filename_alist
;
180 /* A flag to control whether fonts are matched strictly or not. */
181 int w32_strict_fontnames
;
183 /* A flag to control whether we should only repaint if GetUpdateRect
184 indicates there is an update region. */
185 int w32_strict_painting
;
187 /* Associative list linking character set strings to Windows codepages. */
188 Lisp_Object Vw32_charset_info_alist
;
190 /* VIETNAMESE_CHARSET is not defined in some versions of MSVC. */
191 #ifndef VIETNAMESE_CHARSET
192 #define VIETNAMESE_CHARSET 163
196 Lisp_Object Qsuppress_icon
;
197 Lisp_Object Qundefined_color
;
198 Lisp_Object Qcancel_timer
;
204 Lisp_Object Qcontrol
;
207 Lisp_Object Qw32_charset_ansi
;
208 Lisp_Object Qw32_charset_default
;
209 Lisp_Object Qw32_charset_symbol
;
210 Lisp_Object Qw32_charset_shiftjis
;
211 Lisp_Object Qw32_charset_hangeul
;
212 Lisp_Object Qw32_charset_gb2312
;
213 Lisp_Object Qw32_charset_chinesebig5
;
214 Lisp_Object Qw32_charset_oem
;
216 #ifndef JOHAB_CHARSET
217 #define JOHAB_CHARSET 130
220 Lisp_Object Qw32_charset_easteurope
;
221 Lisp_Object Qw32_charset_turkish
;
222 Lisp_Object Qw32_charset_baltic
;
223 Lisp_Object Qw32_charset_russian
;
224 Lisp_Object Qw32_charset_arabic
;
225 Lisp_Object Qw32_charset_greek
;
226 Lisp_Object Qw32_charset_hebrew
;
227 Lisp_Object Qw32_charset_vietnamese
;
228 Lisp_Object Qw32_charset_thai
;
229 Lisp_Object Qw32_charset_johab
;
230 Lisp_Object Qw32_charset_mac
;
233 #ifdef UNICODE_CHARSET
234 Lisp_Object Qw32_charset_unicode
;
237 /* The ANSI codepage. */
238 int w32_ansi_code_page
;
240 /* Prefix for system colors. */
241 #define SYSTEM_COLOR_PREFIX "System"
242 #define SYSTEM_COLOR_PREFIX_LEN (sizeof (SYSTEM_COLOR_PREFIX) - 1)
244 /* State variables for emulating a three button mouse. */
249 static int button_state
= 0;
250 static W32Msg saved_mouse_button_msg
;
251 static unsigned mouse_button_timer
= 0; /* non-zero when timer is active */
252 static W32Msg saved_mouse_move_msg
;
253 static unsigned mouse_move_timer
= 0;
255 /* Window that is tracking the mouse. */
256 static HWND track_mouse_window
;
258 typedef BOOL (WINAPI
* TrackMouseEvent_Proc
)
259 (IN OUT LPTRACKMOUSEEVENT lpEventTrack
);
261 TrackMouseEvent_Proc track_mouse_event_fn
= NULL
;
262 ClipboardSequence_Proc clipboard_sequence_fn
= NULL
;
263 extern AppendMenuW_Proc unicode_append_menu
;
265 /* W95 mousewheel handler */
266 unsigned int msh_mousewheel
= 0;
269 #define MOUSE_BUTTON_ID 1
270 #define MOUSE_MOVE_ID 2
271 #define MENU_FREE_ID 3
272 /* The delay (milliseconds) before a menu is freed after WM_EXITMENULOOP
274 #define MENU_FREE_DELAY 1000
275 static unsigned menu_free_timer
= 0;
277 /* The below are defined in frame.c. */
279 extern Lisp_Object Vwindow_system_version
;
282 int image_cache_refcount
, dpyinfo_refcount
;
286 /* From w32term.c. */
287 extern int w32_num_mouse_buttons
;
288 extern Lisp_Object Vw32_recognize_altgr
;
290 extern HWND w32_system_caret_hwnd
;
292 extern int w32_system_caret_height
;
293 extern int w32_system_caret_x
;
294 extern int w32_system_caret_y
;
295 extern int w32_use_visible_system_caret
;
297 static HWND w32_visible_system_caret_hwnd
;
300 /* Error if we are not connected to MS-Windows. */
305 error ("MS-Windows not in use or not initialized");
308 /* Nonzero if we can use mouse menus.
309 You should not call this unless HAVE_MENUS is defined. */
317 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
318 and checking validity for W32. */
321 check_x_frame (frame
)
327 frame
= selected_frame
;
328 CHECK_LIVE_FRAME (frame
);
330 if (! FRAME_W32_P (f
))
331 error ("non-w32 frame used");
335 /* Let the user specify a display with a frame.
336 nil stands for the selected frame--or, if that is not a w32 frame,
337 the first display on the list. */
339 struct w32_display_info
*
340 check_x_display_info (frame
)
345 struct frame
*sf
= XFRAME (selected_frame
);
347 if (FRAME_W32_P (sf
) && FRAME_LIVE_P (sf
))
348 return FRAME_W32_DISPLAY_INFO (sf
);
350 return &one_w32_display_info
;
352 else if (STRINGP (frame
))
353 return x_display_info_for_name (frame
);
358 CHECK_LIVE_FRAME (frame
);
360 if (! FRAME_W32_P (f
))
361 error ("non-w32 frame used");
362 return FRAME_W32_DISPLAY_INFO (f
);
366 /* Return the Emacs frame-object corresponding to an w32 window.
367 It could be the frame's main window or an icon window. */
369 /* This function can be called during GC, so use GC_xxx type test macros. */
372 x_window_to_frame (dpyinfo
, wdesc
)
373 struct w32_display_info
*dpyinfo
;
376 Lisp_Object tail
, frame
;
379 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
382 if (!GC_FRAMEP (frame
))
385 if (!FRAME_W32_P (f
) || FRAME_W32_DISPLAY_INFO (f
) != dpyinfo
)
387 if (f
->output_data
.w32
->hourglass_window
== wdesc
)
390 if (FRAME_W32_WINDOW (f
) == wdesc
)
397 BOOL my_show_window
P_ ((struct frame
*, HWND
, int));
398 void my_set_window_pos
P_ ((HWND
, HWND
, int, int, int, int, UINT
));
399 static Lisp_Object unwind_create_frame
P_ ((Lisp_Object
));
400 static Lisp_Object unwind_create_tip_frame
P_ ((Lisp_Object
));
402 /* TODO: Native Input Method support; see x_create_im. */
403 void x_set_foreground_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
404 void x_set_background_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
405 void x_set_mouse_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
406 void x_set_cursor_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
407 void x_set_border_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
408 void x_set_cursor_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
409 void x_set_icon_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
410 void x_set_icon_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
411 void x_explicitly_set_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
412 void x_set_menu_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
413 void x_set_title
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
414 void x_set_tool_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
415 static void x_edge_detection
P_ ((struct frame
*, struct image
*, Lisp_Object
,
421 /* Store the screen positions of frame F into XPTR and YPTR.
422 These are the positions of the containing window manager window,
423 not Emacs's own window. */
426 x_real_positions (f
, xptr
, yptr
)
433 GetClientRect(FRAME_W32_WINDOW(f
), &rect
);
434 AdjustWindowRect(&rect
, f
->output_data
.w32
->dwStyle
, FRAME_EXTERNAL_MENU_BAR(f
));
439 ClientToScreen (FRAME_W32_WINDOW(f
), &pt
);
441 /* Remember x_pixels_diff and y_pixels_diff. */
442 f
->x_pixels_diff
= pt
.x
- rect
.left
;
443 f
->y_pixels_diff
= pt
.y
- rect
.top
;
451 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
,
452 Sw32_define_rgb_color
, 4, 4, 0,
453 doc
: /* Convert RGB numbers to a windows color reference and associate with NAME.
454 This adds or updates a named color to w32-color-map, making it
455 available for use. The original entry's RGB ref is returned, or nil
456 if the entry is new. */)
457 (red
, green
, blue
, name
)
458 Lisp_Object red
, green
, blue
, name
;
461 Lisp_Object oldrgb
= Qnil
;
465 CHECK_NUMBER (green
);
469 XSETINT (rgb
, RGB(XUINT (red
), XUINT (green
), XUINT (blue
)));
473 /* replace existing entry in w32-color-map or add new entry. */
474 entry
= Fassoc (name
, Vw32_color_map
);
477 entry
= Fcons (name
, rgb
);
478 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
482 oldrgb
= Fcdr (entry
);
483 Fsetcdr (entry
, rgb
);
491 DEFUN ("w32-load-color-file", Fw32_load_color_file
,
492 Sw32_load_color_file
, 1, 1, 0,
493 doc
: /* Create an alist of color entries from an external file.
494 Assign this value to w32-color-map to replace the existing color map.
496 The file should define one named RGB color per line like so:
498 where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
500 Lisp_Object filename
;
503 Lisp_Object cmap
= Qnil
;
506 CHECK_STRING (filename
);
507 abspath
= Fexpand_file_name (filename
, Qnil
);
509 fp
= fopen (SDATA (filename
), "rt");
513 int red
, green
, blue
;
518 while (fgets (buf
, sizeof (buf
), fp
) != NULL
) {
519 if (sscanf (buf
, "%u %u %u %n", &red
, &green
, &blue
, &num
) == 3)
521 char *name
= buf
+ num
;
522 num
= strlen (name
) - 1;
523 if (name
[num
] == '\n')
525 cmap
= Fcons (Fcons (build_string (name
),
526 make_number (RGB (red
, green
, blue
))),
538 /* The default colors for the w32 color map */
539 typedef struct colormap_t
545 colormap_t w32_color_map
[] =
547 {"snow" , PALETTERGB (255,250,250)},
548 {"ghost white" , PALETTERGB (248,248,255)},
549 {"GhostWhite" , PALETTERGB (248,248,255)},
550 {"white smoke" , PALETTERGB (245,245,245)},
551 {"WhiteSmoke" , PALETTERGB (245,245,245)},
552 {"gainsboro" , PALETTERGB (220,220,220)},
553 {"floral white" , PALETTERGB (255,250,240)},
554 {"FloralWhite" , PALETTERGB (255,250,240)},
555 {"old lace" , PALETTERGB (253,245,230)},
556 {"OldLace" , PALETTERGB (253,245,230)},
557 {"linen" , PALETTERGB (250,240,230)},
558 {"antique white" , PALETTERGB (250,235,215)},
559 {"AntiqueWhite" , PALETTERGB (250,235,215)},
560 {"papaya whip" , PALETTERGB (255,239,213)},
561 {"PapayaWhip" , PALETTERGB (255,239,213)},
562 {"blanched almond" , PALETTERGB (255,235,205)},
563 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
564 {"bisque" , PALETTERGB (255,228,196)},
565 {"peach puff" , PALETTERGB (255,218,185)},
566 {"PeachPuff" , PALETTERGB (255,218,185)},
567 {"navajo white" , PALETTERGB (255,222,173)},
568 {"NavajoWhite" , PALETTERGB (255,222,173)},
569 {"moccasin" , PALETTERGB (255,228,181)},
570 {"cornsilk" , PALETTERGB (255,248,220)},
571 {"ivory" , PALETTERGB (255,255,240)},
572 {"lemon chiffon" , PALETTERGB (255,250,205)},
573 {"LemonChiffon" , PALETTERGB (255,250,205)},
574 {"seashell" , PALETTERGB (255,245,238)},
575 {"honeydew" , PALETTERGB (240,255,240)},
576 {"mint cream" , PALETTERGB (245,255,250)},
577 {"MintCream" , PALETTERGB (245,255,250)},
578 {"azure" , PALETTERGB (240,255,255)},
579 {"alice blue" , PALETTERGB (240,248,255)},
580 {"AliceBlue" , PALETTERGB (240,248,255)},
581 {"lavender" , PALETTERGB (230,230,250)},
582 {"lavender blush" , PALETTERGB (255,240,245)},
583 {"LavenderBlush" , PALETTERGB (255,240,245)},
584 {"misty rose" , PALETTERGB (255,228,225)},
585 {"MistyRose" , PALETTERGB (255,228,225)},
586 {"white" , PALETTERGB (255,255,255)},
587 {"black" , PALETTERGB ( 0, 0, 0)},
588 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
589 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
590 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
591 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
592 {"dim gray" , PALETTERGB (105,105,105)},
593 {"DimGray" , PALETTERGB (105,105,105)},
594 {"dim grey" , PALETTERGB (105,105,105)},
595 {"DimGrey" , PALETTERGB (105,105,105)},
596 {"slate gray" , PALETTERGB (112,128,144)},
597 {"SlateGray" , PALETTERGB (112,128,144)},
598 {"slate grey" , PALETTERGB (112,128,144)},
599 {"SlateGrey" , PALETTERGB (112,128,144)},
600 {"light slate gray" , PALETTERGB (119,136,153)},
601 {"LightSlateGray" , PALETTERGB (119,136,153)},
602 {"light slate grey" , PALETTERGB (119,136,153)},
603 {"LightSlateGrey" , PALETTERGB (119,136,153)},
604 {"gray" , PALETTERGB (190,190,190)},
605 {"grey" , PALETTERGB (190,190,190)},
606 {"light grey" , PALETTERGB (211,211,211)},
607 {"LightGrey" , PALETTERGB (211,211,211)},
608 {"light gray" , PALETTERGB (211,211,211)},
609 {"LightGray" , PALETTERGB (211,211,211)},
610 {"midnight blue" , PALETTERGB ( 25, 25,112)},
611 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
612 {"navy" , PALETTERGB ( 0, 0,128)},
613 {"navy blue" , PALETTERGB ( 0, 0,128)},
614 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
615 {"cornflower blue" , PALETTERGB (100,149,237)},
616 {"CornflowerBlue" , PALETTERGB (100,149,237)},
617 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
618 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
619 {"slate blue" , PALETTERGB (106, 90,205)},
620 {"SlateBlue" , PALETTERGB (106, 90,205)},
621 {"medium slate blue" , PALETTERGB (123,104,238)},
622 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
623 {"light slate blue" , PALETTERGB (132,112,255)},
624 {"LightSlateBlue" , PALETTERGB (132,112,255)},
625 {"medium blue" , PALETTERGB ( 0, 0,205)},
626 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
627 {"royal blue" , PALETTERGB ( 65,105,225)},
628 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
629 {"blue" , PALETTERGB ( 0, 0,255)},
630 {"dodger blue" , PALETTERGB ( 30,144,255)},
631 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
632 {"deep sky blue" , PALETTERGB ( 0,191,255)},
633 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
634 {"sky blue" , PALETTERGB (135,206,235)},
635 {"SkyBlue" , PALETTERGB (135,206,235)},
636 {"light sky blue" , PALETTERGB (135,206,250)},
637 {"LightSkyBlue" , PALETTERGB (135,206,250)},
638 {"steel blue" , PALETTERGB ( 70,130,180)},
639 {"SteelBlue" , PALETTERGB ( 70,130,180)},
640 {"light steel blue" , PALETTERGB (176,196,222)},
641 {"LightSteelBlue" , PALETTERGB (176,196,222)},
642 {"light blue" , PALETTERGB (173,216,230)},
643 {"LightBlue" , PALETTERGB (173,216,230)},
644 {"powder blue" , PALETTERGB (176,224,230)},
645 {"PowderBlue" , PALETTERGB (176,224,230)},
646 {"pale turquoise" , PALETTERGB (175,238,238)},
647 {"PaleTurquoise" , PALETTERGB (175,238,238)},
648 {"dark turquoise" , PALETTERGB ( 0,206,209)},
649 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
650 {"medium turquoise" , PALETTERGB ( 72,209,204)},
651 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
652 {"turquoise" , PALETTERGB ( 64,224,208)},
653 {"cyan" , PALETTERGB ( 0,255,255)},
654 {"light cyan" , PALETTERGB (224,255,255)},
655 {"LightCyan" , PALETTERGB (224,255,255)},
656 {"cadet blue" , PALETTERGB ( 95,158,160)},
657 {"CadetBlue" , PALETTERGB ( 95,158,160)},
658 {"medium aquamarine" , PALETTERGB (102,205,170)},
659 {"MediumAquamarine" , PALETTERGB (102,205,170)},
660 {"aquamarine" , PALETTERGB (127,255,212)},
661 {"dark green" , PALETTERGB ( 0,100, 0)},
662 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
663 {"dark olive green" , PALETTERGB ( 85,107, 47)},
664 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
665 {"dark sea green" , PALETTERGB (143,188,143)},
666 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
667 {"sea green" , PALETTERGB ( 46,139, 87)},
668 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
669 {"medium sea green" , PALETTERGB ( 60,179,113)},
670 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
671 {"light sea green" , PALETTERGB ( 32,178,170)},
672 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
673 {"pale green" , PALETTERGB (152,251,152)},
674 {"PaleGreen" , PALETTERGB (152,251,152)},
675 {"spring green" , PALETTERGB ( 0,255,127)},
676 {"SpringGreen" , PALETTERGB ( 0,255,127)},
677 {"lawn green" , PALETTERGB (124,252, 0)},
678 {"LawnGreen" , PALETTERGB (124,252, 0)},
679 {"green" , PALETTERGB ( 0,255, 0)},
680 {"chartreuse" , PALETTERGB (127,255, 0)},
681 {"medium spring green" , PALETTERGB ( 0,250,154)},
682 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
683 {"green yellow" , PALETTERGB (173,255, 47)},
684 {"GreenYellow" , PALETTERGB (173,255, 47)},
685 {"lime green" , PALETTERGB ( 50,205, 50)},
686 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
687 {"yellow green" , PALETTERGB (154,205, 50)},
688 {"YellowGreen" , PALETTERGB (154,205, 50)},
689 {"forest green" , PALETTERGB ( 34,139, 34)},
690 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
691 {"olive drab" , PALETTERGB (107,142, 35)},
692 {"OliveDrab" , PALETTERGB (107,142, 35)},
693 {"dark khaki" , PALETTERGB (189,183,107)},
694 {"DarkKhaki" , PALETTERGB (189,183,107)},
695 {"khaki" , PALETTERGB (240,230,140)},
696 {"pale goldenrod" , PALETTERGB (238,232,170)},
697 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
698 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
699 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
700 {"light yellow" , PALETTERGB (255,255,224)},
701 {"LightYellow" , PALETTERGB (255,255,224)},
702 {"yellow" , PALETTERGB (255,255, 0)},
703 {"gold" , PALETTERGB (255,215, 0)},
704 {"light goldenrod" , PALETTERGB (238,221,130)},
705 {"LightGoldenrod" , PALETTERGB (238,221,130)},
706 {"goldenrod" , PALETTERGB (218,165, 32)},
707 {"dark goldenrod" , PALETTERGB (184,134, 11)},
708 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
709 {"rosy brown" , PALETTERGB (188,143,143)},
710 {"RosyBrown" , PALETTERGB (188,143,143)},
711 {"indian red" , PALETTERGB (205, 92, 92)},
712 {"IndianRed" , PALETTERGB (205, 92, 92)},
713 {"saddle brown" , PALETTERGB (139, 69, 19)},
714 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
715 {"sienna" , PALETTERGB (160, 82, 45)},
716 {"peru" , PALETTERGB (205,133, 63)},
717 {"burlywood" , PALETTERGB (222,184,135)},
718 {"beige" , PALETTERGB (245,245,220)},
719 {"wheat" , PALETTERGB (245,222,179)},
720 {"sandy brown" , PALETTERGB (244,164, 96)},
721 {"SandyBrown" , PALETTERGB (244,164, 96)},
722 {"tan" , PALETTERGB (210,180,140)},
723 {"chocolate" , PALETTERGB (210,105, 30)},
724 {"firebrick" , PALETTERGB (178,34, 34)},
725 {"brown" , PALETTERGB (165,42, 42)},
726 {"dark salmon" , PALETTERGB (233,150,122)},
727 {"DarkSalmon" , PALETTERGB (233,150,122)},
728 {"salmon" , PALETTERGB (250,128,114)},
729 {"light salmon" , PALETTERGB (255,160,122)},
730 {"LightSalmon" , PALETTERGB (255,160,122)},
731 {"orange" , PALETTERGB (255,165, 0)},
732 {"dark orange" , PALETTERGB (255,140, 0)},
733 {"DarkOrange" , PALETTERGB (255,140, 0)},
734 {"coral" , PALETTERGB (255,127, 80)},
735 {"light coral" , PALETTERGB (240,128,128)},
736 {"LightCoral" , PALETTERGB (240,128,128)},
737 {"tomato" , PALETTERGB (255, 99, 71)},
738 {"orange red" , PALETTERGB (255, 69, 0)},
739 {"OrangeRed" , PALETTERGB (255, 69, 0)},
740 {"red" , PALETTERGB (255, 0, 0)},
741 {"hot pink" , PALETTERGB (255,105,180)},
742 {"HotPink" , PALETTERGB (255,105,180)},
743 {"deep pink" , PALETTERGB (255, 20,147)},
744 {"DeepPink" , PALETTERGB (255, 20,147)},
745 {"pink" , PALETTERGB (255,192,203)},
746 {"light pink" , PALETTERGB (255,182,193)},
747 {"LightPink" , PALETTERGB (255,182,193)},
748 {"pale violet red" , PALETTERGB (219,112,147)},
749 {"PaleVioletRed" , PALETTERGB (219,112,147)},
750 {"maroon" , PALETTERGB (176, 48, 96)},
751 {"medium violet red" , PALETTERGB (199, 21,133)},
752 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
753 {"violet red" , PALETTERGB (208, 32,144)},
754 {"VioletRed" , PALETTERGB (208, 32,144)},
755 {"magenta" , PALETTERGB (255, 0,255)},
756 {"violet" , PALETTERGB (238,130,238)},
757 {"plum" , PALETTERGB (221,160,221)},
758 {"orchid" , PALETTERGB (218,112,214)},
759 {"medium orchid" , PALETTERGB (186, 85,211)},
760 {"MediumOrchid" , PALETTERGB (186, 85,211)},
761 {"dark orchid" , PALETTERGB (153, 50,204)},
762 {"DarkOrchid" , PALETTERGB (153, 50,204)},
763 {"dark violet" , PALETTERGB (148, 0,211)},
764 {"DarkViolet" , PALETTERGB (148, 0,211)},
765 {"blue violet" , PALETTERGB (138, 43,226)},
766 {"BlueViolet" , PALETTERGB (138, 43,226)},
767 {"purple" , PALETTERGB (160, 32,240)},
768 {"medium purple" , PALETTERGB (147,112,219)},
769 {"MediumPurple" , PALETTERGB (147,112,219)},
770 {"thistle" , PALETTERGB (216,191,216)},
771 {"gray0" , PALETTERGB ( 0, 0, 0)},
772 {"grey0" , PALETTERGB ( 0, 0, 0)},
773 {"dark grey" , PALETTERGB (169,169,169)},
774 {"DarkGrey" , PALETTERGB (169,169,169)},
775 {"dark gray" , PALETTERGB (169,169,169)},
776 {"DarkGray" , PALETTERGB (169,169,169)},
777 {"dark blue" , PALETTERGB ( 0, 0,139)},
778 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
779 {"dark cyan" , PALETTERGB ( 0,139,139)},
780 {"DarkCyan" , PALETTERGB ( 0,139,139)},
781 {"dark magenta" , PALETTERGB (139, 0,139)},
782 {"DarkMagenta" , PALETTERGB (139, 0,139)},
783 {"dark red" , PALETTERGB (139, 0, 0)},
784 {"DarkRed" , PALETTERGB (139, 0, 0)},
785 {"light green" , PALETTERGB (144,238,144)},
786 {"LightGreen" , PALETTERGB (144,238,144)},
789 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
790 0, 0, 0, doc
: /* Return the default color map. */)
794 colormap_t
*pc
= w32_color_map
;
801 for (i
= 0; i
< sizeof (w32_color_map
) / sizeof (w32_color_map
[0]);
803 cmap
= Fcons (Fcons (build_string (pc
->name
),
804 make_number (pc
->colorref
)),
822 color
= Frassq (rgb
, Vw32_color_map
);
827 return (Fcar (color
));
833 w32_color_map_lookup (colorname
)
836 Lisp_Object tail
, ret
= Qnil
;
840 for (tail
= Vw32_color_map
; !NILP (tail
); tail
= Fcdr (tail
))
842 register Lisp_Object elt
, tem
;
845 if (!CONSP (elt
)) continue;
849 if (lstrcmpi (SDATA (tem
), colorname
) == 0)
866 add_system_logical_colors_to_map (system_colors
)
867 Lisp_Object
*system_colors
;
871 /* Other registry operations are done with input blocked. */
874 /* Look for "Control Panel/Colors" under User and Machine registry
876 if (RegOpenKeyEx (HKEY_CURRENT_USER
, "Control Panel\\Colors", 0,
877 KEY_READ
, &colors_key
) == ERROR_SUCCESS
878 || RegOpenKeyEx (HKEY_LOCAL_MACHINE
, "Control Panel\\Colors", 0,
879 KEY_READ
, &colors_key
) == ERROR_SUCCESS
)
882 char color_buffer
[64];
883 char full_name_buffer
[MAX_PATH
+ SYSTEM_COLOR_PREFIX_LEN
];
885 DWORD name_size
, color_size
;
886 char *name_buffer
= full_name_buffer
+ SYSTEM_COLOR_PREFIX_LEN
;
888 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
889 color_size
= sizeof (color_buffer
);
891 strcpy (full_name_buffer
, SYSTEM_COLOR_PREFIX
);
893 while (RegEnumValueA (colors_key
, index
, name_buffer
, &name_size
,
894 NULL
, NULL
, color_buffer
, &color_size
)
898 if (sscanf (color_buffer
, " %u %u %u", &r
, &g
, &b
) == 3)
899 *system_colors
= Fcons (Fcons (build_string (full_name_buffer
),
900 make_number (RGB (r
, g
, b
))),
903 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
904 color_size
= sizeof (color_buffer
);
907 RegCloseKey (colors_key
);
915 x_to_w32_color (colorname
)
918 register Lisp_Object ret
= Qnil
;
922 if (colorname
[0] == '#')
924 /* Could be an old-style RGB Device specification. */
927 color
= colorname
+ 1;
929 size
= strlen(color
);
930 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
938 for (i
= 0; i
< 3; i
++)
944 /* The check for 'x' in the following conditional takes into
945 account the fact that strtol allows a "0x" in front of
946 our numbers, and we don't. */
947 if (!isxdigit(color
[0]) || color
[1] == 'x')
951 value
= strtoul(color
, &end
, 16);
953 if (errno
== ERANGE
|| end
- color
!= size
)
958 value
= value
* 0x10;
969 colorval
|= (value
<< pos
);
974 XSETINT (ret
, colorval
);
981 else if (strnicmp(colorname
, "rgb:", 4) == 0)
989 color
= colorname
+ 4;
990 for (i
= 0; i
< 3; i
++)
995 /* The check for 'x' in the following conditional takes into
996 account the fact that strtol allows a "0x" in front of
997 our numbers, and we don't. */
998 if (!isxdigit(color
[0]) || color
[1] == 'x')
1000 value
= strtoul(color
, &end
, 16);
1001 if (errno
== ERANGE
)
1003 switch (end
- color
)
1006 value
= value
* 0x10 + value
;
1019 if (value
== ULONG_MAX
)
1021 colorval
|= (value
<< pos
);
1028 XSETINT (ret
, colorval
);
1036 else if (strnicmp(colorname
, "rgbi:", 5) == 0)
1038 /* This is an RGB Intensity specification. */
1045 color
= colorname
+ 5;
1046 for (i
= 0; i
< 3; i
++)
1052 value
= strtod(color
, &end
);
1053 if (errno
== ERANGE
)
1055 if (value
< 0.0 || value
> 1.0)
1057 val
= (UINT
)(0x100 * value
);
1058 /* We used 0x100 instead of 0xFF to give a continuous
1059 range between 0.0 and 1.0 inclusive. The next statement
1060 fixes the 1.0 case. */
1063 colorval
|= (val
<< pos
);
1070 XSETINT (ret
, colorval
);
1078 /* I am not going to attempt to handle any of the CIE color schemes
1079 or TekHVC, since I don't know the algorithms for conversion to
1082 /* If we fail to lookup the color name in w32_color_map, then check the
1083 colorname to see if it can be crudely approximated: If the X color
1084 ends in a number (e.g., "darkseagreen2"), strip the number and
1085 return the result of looking up the base color name. */
1086 ret
= w32_color_map_lookup (colorname
);
1089 int len
= strlen (colorname
);
1091 if (isdigit (colorname
[len
- 1]))
1093 char *ptr
, *approx
= alloca (len
+ 1);
1095 strcpy (approx
, colorname
);
1096 ptr
= &approx
[len
- 1];
1097 while (ptr
> approx
&& isdigit (*ptr
))
1100 ret
= w32_color_map_lookup (approx
);
1109 w32_regenerate_palette (FRAME_PTR f
)
1111 struct w32_palette_entry
* list
;
1112 LOGPALETTE
* log_palette
;
1113 HPALETTE new_palette
;
1116 /* don't bother trying to create palette if not supported */
1117 if (! FRAME_W32_DISPLAY_INFO (f
)->has_palette
)
1120 log_palette
= (LOGPALETTE
*)
1121 alloca (sizeof (LOGPALETTE
) +
1122 FRAME_W32_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
1123 log_palette
->palVersion
= 0x300;
1124 log_palette
->palNumEntries
= FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1126 list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1128 i
< FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1129 i
++, list
= list
->next
)
1130 log_palette
->palPalEntry
[i
] = list
->entry
;
1132 new_palette
= CreatePalette (log_palette
);
1136 if (FRAME_W32_DISPLAY_INFO (f
)->palette
)
1137 DeleteObject (FRAME_W32_DISPLAY_INFO (f
)->palette
);
1138 FRAME_W32_DISPLAY_INFO (f
)->palette
= new_palette
;
1140 /* Realize display palette and garbage all frames. */
1141 release_frame_dc (f
, get_frame_dc (f
));
1146 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
1147 #define SET_W32_COLOR(pe, color) \
1150 pe.peRed = GetRValue (color); \
1151 pe.peGreen = GetGValue (color); \
1152 pe.peBlue = GetBValue (color); \
1157 /* Keep these around in case we ever want to track color usage. */
1159 w32_map_color (FRAME_PTR f
, COLORREF color
)
1161 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1163 if (NILP (Vw32_enable_palette
))
1166 /* check if color is already mapped */
1169 if (W32_COLOR (list
->entry
) == color
)
1177 /* not already mapped, so add to list and recreate Windows palette */
1178 list
= (struct w32_palette_entry
*)
1179 xmalloc (sizeof (struct w32_palette_entry
));
1180 SET_W32_COLOR (list
->entry
, color
);
1182 list
->next
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1183 FRAME_W32_DISPLAY_INFO (f
)->color_list
= list
;
1184 FRAME_W32_DISPLAY_INFO (f
)->num_colors
++;
1186 /* set flag that palette must be regenerated */
1187 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1191 w32_unmap_color (FRAME_PTR f
, COLORREF color
)
1193 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1194 struct w32_palette_entry
**prev
= &FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1196 if (NILP (Vw32_enable_palette
))
1199 /* check if color is already mapped */
1202 if (W32_COLOR (list
->entry
) == color
)
1204 if (--list
->refcount
== 0)
1208 FRAME_W32_DISPLAY_INFO (f
)->num_colors
--;
1218 /* set flag that palette must be regenerated */
1219 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1224 /* Gamma-correct COLOR on frame F. */
1227 gamma_correct (f
, color
)
1233 *color
= PALETTERGB (
1234 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1235 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1236 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1241 /* Decide if color named COLOR is valid for the display associated with
1242 the selected frame; if so, return the rgb values in COLOR_DEF.
1243 If ALLOC is nonzero, allocate a new colormap cell. */
1246 w32_defined_color (f
, color
, color_def
, alloc
)
1252 register Lisp_Object tem
;
1253 COLORREF w32_color_ref
;
1255 tem
= x_to_w32_color (color
);
1261 /* Apply gamma correction. */
1262 w32_color_ref
= XUINT (tem
);
1263 gamma_correct (f
, &w32_color_ref
);
1264 XSETINT (tem
, w32_color_ref
);
1267 /* Map this color to the palette if it is enabled. */
1268 if (!NILP (Vw32_enable_palette
))
1270 struct w32_palette_entry
* entry
=
1271 one_w32_display_info
.color_list
;
1272 struct w32_palette_entry
** prev
=
1273 &one_w32_display_info
.color_list
;
1275 /* check if color is already mapped */
1278 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1280 prev
= &entry
->next
;
1281 entry
= entry
->next
;
1284 if (entry
== NULL
&& alloc
)
1286 /* not already mapped, so add to list */
1287 entry
= (struct w32_palette_entry
*)
1288 xmalloc (sizeof (struct w32_palette_entry
));
1289 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1292 one_w32_display_info
.num_colors
++;
1294 /* set flag that palette must be regenerated */
1295 one_w32_display_info
.regen_palette
= TRUE
;
1298 /* Ensure COLORREF value is snapped to nearest color in (default)
1299 palette by simulating the PALETTERGB macro. This works whether
1300 or not the display device has a palette. */
1301 w32_color_ref
= XUINT (tem
) | 0x2000000;
1303 color_def
->pixel
= w32_color_ref
;
1304 color_def
->red
= GetRValue (w32_color_ref
) * 256;
1305 color_def
->green
= GetGValue (w32_color_ref
) * 256;
1306 color_def
->blue
= GetBValue (w32_color_ref
) * 256;
1316 /* Given a string ARG naming a color, compute a pixel value from it
1317 suitable for screen F.
1318 If F is not a color screen, return DEF (default) regardless of what
1322 x_decode_color (f
, arg
, def
)
1331 if (strcmp (SDATA (arg
), "black") == 0)
1332 return BLACK_PIX_DEFAULT (f
);
1333 else if (strcmp (SDATA (arg
), "white") == 0)
1334 return WHITE_PIX_DEFAULT (f
);
1336 if ((FRAME_W32_DISPLAY_INFO (f
)->n_planes
* FRAME_W32_DISPLAY_INFO (f
)->n_cbits
) == 1)
1339 /* w32_defined_color is responsible for coping with failures
1340 by looking for a near-miss. */
1341 if (w32_defined_color (f
, SDATA (arg
), &cdef
, 1))
1344 /* defined_color failed; return an ultimate default. */
1350 /* Functions called only from `x_set_frame_param'
1351 to set individual parameters.
1353 If FRAME_W32_WINDOW (f) is 0,
1354 the frame is being created and its window does not exist yet.
1355 In that case, just record the parameter's new value
1356 in the standard place; do not attempt to change the window. */
1359 x_set_foreground_color (f
, arg
, oldval
)
1361 Lisp_Object arg
, oldval
;
1363 struct w32_output
*x
= f
->output_data
.w32
;
1364 PIX_TYPE fg
, old_fg
;
1366 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1367 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
1368 FRAME_FOREGROUND_PIXEL (f
) = fg
;
1370 if (FRAME_W32_WINDOW (f
) != 0)
1372 if (x
->cursor_pixel
== old_fg
)
1373 x
->cursor_pixel
= fg
;
1375 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
1376 if (FRAME_VISIBLE_P (f
))
1382 x_set_background_color (f
, arg
, oldval
)
1384 Lisp_Object arg
, oldval
;
1386 FRAME_BACKGROUND_PIXEL (f
)
1387 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
1389 if (FRAME_W32_WINDOW (f
) != 0)
1391 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
1392 FRAME_BACKGROUND_PIXEL (f
));
1394 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
1396 if (FRAME_VISIBLE_P (f
))
1402 x_set_mouse_color (f
, arg
, oldval
)
1404 Lisp_Object arg
, oldval
;
1406 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
1410 if (!EQ (Qnil
, arg
))
1411 f
->output_data
.w32
->mouse_pixel
1412 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1413 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
1415 /* Don't let pointers be invisible. */
1416 if (mask_color
== f
->output_data
.w32
->mouse_pixel
1417 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
1418 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
1420 #if 0 /* TODO : cursor changes */
1423 /* It's not okay to crash if the user selects a screwy cursor. */
1424 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
1426 if (!EQ (Qnil
, Vx_pointer_shape
))
1428 CHECK_NUMBER (Vx_pointer_shape
);
1429 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
1432 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1433 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
1435 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
1437 CHECK_NUMBER (Vx_nontext_pointer_shape
);
1438 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1439 XINT (Vx_nontext_pointer_shape
));
1442 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
1443 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1445 if (!EQ (Qnil
, Vx_hourglass_pointer_shape
))
1447 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
1448 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1449 XINT (Vx_hourglass_pointer_shape
));
1452 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
1453 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
1455 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1456 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
1458 CHECK_NUMBER (Vx_mode_pointer_shape
);
1459 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1460 XINT (Vx_mode_pointer_shape
));
1463 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1464 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
1466 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
1468 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
1470 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1471 XINT (Vx_sensitive_text_pointer_shape
));
1474 hand_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
1476 if (!NILP (Vx_window_horizontal_drag_shape
))
1478 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
1479 horizontal_drag_cursor
1480 = XCreateFontCursor (FRAME_X_DISPLAY (f
),
1481 XINT (Vx_window_horizontal_drag_shape
));
1484 horizontal_drag_cursor
1485 = XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_sb_h_double_arrow
);
1487 /* Check and report errors with the above calls. */
1488 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
1489 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
1492 XColor fore_color
, back_color
;
1494 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
1495 back_color
.pixel
= mask_color
;
1496 XQueryColor (FRAME_W32_DISPLAY (f
),
1497 DefaultColormap (FRAME_W32_DISPLAY (f
),
1498 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1500 XQueryColor (FRAME_W32_DISPLAY (f
),
1501 DefaultColormap (FRAME_W32_DISPLAY (f
),
1502 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1504 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
1505 &fore_color
, &back_color
);
1506 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
1507 &fore_color
, &back_color
);
1508 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
1509 &fore_color
, &back_color
);
1510 XRecolorCursor (FRAME_W32_DISPLAY (f
), hand_cursor
,
1511 &fore_color
, &back_color
);
1512 XRecolorCursor (FRAME_W32_DISPLAY (f
), hourglass_cursor
,
1513 &fore_color
, &back_color
);
1516 if (FRAME_W32_WINDOW (f
) != 0)
1517 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
1519 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
1520 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
1521 f
->output_data
.w32
->text_cursor
= cursor
;
1523 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
1524 && f
->output_data
.w32
->nontext_cursor
!= 0)
1525 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
1526 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
1528 if (hourglass_cursor
!= f
->output_data
.w32
->hourglass_cursor
1529 && f
->output_data
.w32
->hourglass_cursor
!= 0)
1530 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hourglass_cursor
);
1531 f
->output_data
.w32
->hourglass_cursor
= hourglass_cursor
;
1533 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
1534 && f
->output_data
.w32
->modeline_cursor
!= 0)
1535 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
1536 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
1538 if (hand_cursor
!= f
->output_data
.w32
->hand_cursor
1539 && f
->output_data
.w32
->hand_cursor
!= 0)
1540 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hand_cursor
);
1541 f
->output_data
.w32
->hand_cursor
= hand_cursor
;
1543 XFlush (FRAME_W32_DISPLAY (f
));
1546 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1550 /* Defined in w32term.c. */
1552 x_set_cursor_color (f
, arg
, oldval
)
1554 Lisp_Object arg
, oldval
;
1556 unsigned long fore_pixel
, pixel
;
1558 if (!NILP (Vx_cursor_fore_pixel
))
1559 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1560 WHITE_PIX_DEFAULT (f
));
1562 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1564 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1566 /* Make sure that the cursor color differs from the background color. */
1567 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
1569 pixel
= f
->output_data
.w32
->mouse_pixel
;
1570 if (pixel
== fore_pixel
)
1571 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1574 f
->output_data
.w32
->cursor_foreground_pixel
= fore_pixel
;
1575 f
->output_data
.w32
->cursor_pixel
= pixel
;
1577 if (FRAME_W32_WINDOW (f
) != 0)
1580 /* Update frame's cursor_gc. */
1581 f
->output_data
.w32
->cursor_gc
->foreground
= fore_pixel
;
1582 f
->output_data
.w32
->cursor_gc
->background
= pixel
;
1586 if (FRAME_VISIBLE_P (f
))
1588 x_update_cursor (f
, 0);
1589 x_update_cursor (f
, 1);
1593 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1596 /* Set the border-color of frame F to pixel value PIX.
1597 Note that this does not fully take effect if done before
1601 x_set_border_pixel (f
, pix
)
1606 f
->output_data
.w32
->border_pixel
= pix
;
1608 if (FRAME_W32_WINDOW (f
) != 0 && f
->border_width
> 0)
1610 if (FRAME_VISIBLE_P (f
))
1615 /* Set the border-color of frame F to value described by ARG.
1616 ARG can be a string naming a color.
1617 The border-color is used for the border that is drawn by the server.
1618 Note that this does not fully take effect if done before
1619 F has a window; it must be redone when the window is created. */
1622 x_set_border_color (f
, arg
, oldval
)
1624 Lisp_Object arg
, oldval
;
1629 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1630 x_set_border_pixel (f
, pix
);
1631 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1636 x_set_cursor_type (f
, arg
, oldval
)
1638 Lisp_Object arg
, oldval
;
1640 set_frame_cursor_types (f
, arg
);
1642 /* Make sure the cursor gets redrawn. */
1643 cursor_type_changed
= 1;
1647 x_set_icon_type (f
, arg
, oldval
)
1649 Lisp_Object arg
, oldval
;
1653 if (NILP (arg
) && NILP (oldval
))
1656 if (STRINGP (arg
) && STRINGP (oldval
)
1657 && EQ (Fstring_equal (oldval
, arg
), Qt
))
1660 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
1665 result
= x_bitmap_icon (f
, arg
);
1669 error ("No icon window available");
1676 x_set_icon_name (f
, arg
, oldval
)
1678 Lisp_Object arg
, oldval
;
1682 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1685 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
1691 if (f
->output_data
.w32
->icon_bitmap
!= 0)
1696 result
= x_text_icon (f
,
1697 (char *) SDATA ((!NILP (f
->icon_name
)
1706 error ("No icon window available");
1709 /* If the window was unmapped (and its icon was mapped),
1710 the new icon is not mapped, so map the window in its stead. */
1711 if (FRAME_VISIBLE_P (f
))
1713 #ifdef USE_X_TOOLKIT
1714 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
1716 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
1719 XFlush (FRAME_W32_DISPLAY (f
));
1726 x_set_menu_bar_lines (f
, value
, oldval
)
1728 Lisp_Object value
, oldval
;
1731 int olines
= FRAME_MENU_BAR_LINES (f
);
1733 /* Right now, menu bars don't work properly in minibuf-only frames;
1734 most of the commands try to apply themselves to the minibuffer
1735 frame itself, and get an error because you can't switch buffers
1736 in or split the minibuffer window. */
1737 if (FRAME_MINIBUF_ONLY_P (f
))
1740 if (INTEGERP (value
))
1741 nlines
= XINT (value
);
1745 FRAME_MENU_BAR_LINES (f
) = 0;
1747 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1750 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1751 free_frame_menubar (f
);
1752 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1754 /* Adjust the frame size so that the client (text) dimensions
1755 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
1757 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
1758 do_pending_window_change (0);
1764 /* Set the number of lines used for the tool bar of frame F to VALUE.
1765 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1766 is the old number of tool bar lines. This function changes the
1767 height of all windows on frame F to match the new tool bar height.
1768 The frame's height doesn't change. */
1771 x_set_tool_bar_lines (f
, value
, oldval
)
1773 Lisp_Object value
, oldval
;
1775 int delta
, nlines
, root_height
;
1776 Lisp_Object root_window
;
1778 /* Treat tool bars like menu bars. */
1779 if (FRAME_MINIBUF_ONLY_P (f
))
1782 /* Use VALUE only if an integer >= 0. */
1783 if (INTEGERP (value
) && XINT (value
) >= 0)
1784 nlines
= XFASTINT (value
);
1788 /* Make sure we redisplay all windows in this frame. */
1789 ++windows_or_buffers_changed
;
1791 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
1793 /* Don't resize the tool-bar to more than we have room for. */
1794 root_window
= FRAME_ROOT_WINDOW (f
);
1795 root_height
= WINDOW_TOTAL_LINES (XWINDOW (root_window
));
1796 if (root_height
- delta
< 1)
1798 delta
= root_height
- 1;
1799 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
1802 FRAME_TOOL_BAR_LINES (f
) = nlines
;
1803 change_window_heights (root_window
, delta
);
1806 /* We also have to make sure that the internal border at the top of
1807 the frame, below the menu bar or tool bar, is redrawn when the
1808 tool bar disappears. This is so because the internal border is
1809 below the tool bar if one is displayed, but is below the menu bar
1810 if there isn't a tool bar. The tool bar draws into the area
1811 below the menu bar. */
1812 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
1816 clear_current_matrices (f
);
1817 updating_frame
= NULL
;
1820 /* If the tool bar gets smaller, the internal border below it
1821 has to be cleared. It was formerly part of the display
1822 of the larger tool bar, and updating windows won't clear it. */
1825 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1826 int width
= FRAME_PIXEL_WIDTH (f
);
1827 int y
= nlines
* FRAME_LINE_HEIGHT (f
);
1831 HDC hdc
= get_frame_dc (f
);
1832 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
1833 release_frame_dc (f
, hdc
);
1837 if (WINDOWP (f
->tool_bar_window
))
1838 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1843 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1846 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1847 name; if NAME is a string, set F's name to NAME and set
1848 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1850 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1851 suggesting a new name, which lisp code should override; if
1852 F->explicit_name is set, ignore the new name; otherwise, set it. */
1855 x_set_name (f
, name
, explicit)
1860 /* Make sure that requests from lisp code override requests from
1861 Emacs redisplay code. */
1864 /* If we're switching from explicit to implicit, we had better
1865 update the mode lines and thereby update the title. */
1866 if (f
->explicit_name
&& NILP (name
))
1867 update_mode_lines
= 1;
1869 f
->explicit_name
= ! NILP (name
);
1871 else if (f
->explicit_name
)
1874 /* If NAME is nil, set the name to the w32_id_name. */
1877 /* Check for no change needed in this very common case
1878 before we do any consing. */
1879 if (!strcmp (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
,
1882 name
= build_string (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
);
1885 CHECK_STRING (name
);
1887 /* Don't change the name if it's already NAME. */
1888 if (! NILP (Fstring_equal (name
, f
->name
)))
1893 /* For setting the frame title, the title parameter should override
1894 the name parameter. */
1895 if (! NILP (f
->title
))
1898 if (FRAME_W32_WINDOW (f
))
1900 if (STRING_MULTIBYTE (name
))
1901 name
= ENCODE_SYSTEM (name
);
1904 SetWindowText(FRAME_W32_WINDOW (f
), SDATA (name
));
1909 /* This function should be called when the user's lisp code has
1910 specified a name for the frame; the name will override any set by the
1913 x_explicitly_set_name (f
, arg
, oldval
)
1915 Lisp_Object arg
, oldval
;
1917 x_set_name (f
, arg
, 1);
1920 /* This function should be called by Emacs redisplay code to set the
1921 name; names set this way will never override names set by the user's
1924 x_implicitly_set_name (f
, arg
, oldval
)
1926 Lisp_Object arg
, oldval
;
1928 x_set_name (f
, arg
, 0);
1931 /* Change the title of frame F to NAME.
1932 If NAME is nil, use the frame name as the title.
1934 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1935 name; if NAME is a string, set F's name to NAME and set
1936 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1938 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1939 suggesting a new name, which lisp code should override; if
1940 F->explicit_name is set, ignore the new name; otherwise, set it. */
1943 x_set_title (f
, name
, old_name
)
1945 Lisp_Object name
, old_name
;
1947 /* Don't change the title if it's already NAME. */
1948 if (EQ (name
, f
->title
))
1951 update_mode_lines
= 1;
1958 if (FRAME_W32_WINDOW (f
))
1960 if (STRING_MULTIBYTE (name
))
1961 name
= ENCODE_SYSTEM (name
);
1964 SetWindowText(FRAME_W32_WINDOW (f
), SDATA (name
));
1970 void x_set_scroll_bar_default_width (f
)
1973 int wid
= FRAME_COLUMN_WIDTH (f
);
1975 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
1976 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) +
1981 /* Subroutines of creating a frame. */
1984 /* Return the value of parameter PARAM.
1986 First search ALIST, then Vdefault_frame_alist, then the X defaults
1987 database, using ATTRIBUTE as the attribute name and CLASS as its class.
1989 Convert the resource to the type specified by desired_type.
1991 If no default is specified, return Qunbound. If you call
1992 w32_get_arg, make sure you deal with Qunbound in a reasonable way,
1993 and don't let it get stored in any Lisp-visible variables! */
1996 w32_get_arg (alist
, param
, attribute
, class, type
)
1997 Lisp_Object alist
, param
;
2000 enum resource_types type
;
2002 return x_get_arg (check_x_display_info (Qnil
),
2003 alist
, param
, attribute
, class, type
);
2008 w32_load_cursor (LPCTSTR name
)
2010 /* Try first to load cursor from application resource. */
2011 Cursor cursor
= LoadImage ((HINSTANCE
) GetModuleHandle(NULL
),
2012 name
, IMAGE_CURSOR
, 0, 0,
2013 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
2016 /* Then try to load a shared predefined cursor. */
2017 cursor
= LoadImage (NULL
, name
, IMAGE_CURSOR
, 0, 0,
2018 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
2023 extern LRESULT CALLBACK
w32_wnd_proc ();
2026 w32_init_class (hinst
)
2031 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
2032 wc
.lpfnWndProc
= (WNDPROC
) w32_wnd_proc
;
2034 wc
.cbWndExtra
= WND_EXTRA_BYTES
;
2035 wc
.hInstance
= hinst
;
2036 wc
.hIcon
= LoadIcon (hinst
, EMACS_CLASS
);
2037 wc
.hCursor
= w32_load_cursor (IDC_ARROW
);
2038 wc
.hbrBackground
= NULL
; /* GetStockObject (WHITE_BRUSH); */
2039 wc
.lpszMenuName
= NULL
;
2040 wc
.lpszClassName
= EMACS_CLASS
;
2042 return (RegisterClass (&wc
));
2046 w32_createscrollbar (f
, bar
)
2048 struct scroll_bar
* bar
;
2050 return (CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
2051 /* Position and size of scroll bar. */
2052 XINT(bar
->left
) + VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
2054 XINT(bar
->width
) - VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
2056 FRAME_W32_WINDOW (f
),
2063 w32_createwindow (f
)
2069 rect
.left
= rect
.top
= 0;
2070 rect
.right
= FRAME_PIXEL_WIDTH (f
);
2071 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
2073 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
2074 FRAME_EXTERNAL_MENU_BAR (f
));
2076 /* Do first time app init */
2080 w32_init_class (hinst
);
2083 FRAME_W32_WINDOW (f
) = hwnd
2084 = CreateWindow (EMACS_CLASS
,
2086 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
2089 rect
.right
- rect
.left
,
2090 rect
.bottom
- rect
.top
,
2098 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
2099 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
2100 SetWindowLong (hwnd
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
2101 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->scroll_bar_actual_width
);
2102 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
2104 /* Enable drag-n-drop. */
2105 DragAcceptFiles (hwnd
, TRUE
);
2107 /* Do this to discard the default setting specified by our parent. */
2108 ShowWindow (hwnd
, SW_HIDE
);
2113 my_post_msg (wmsg
, hwnd
, msg
, wParam
, lParam
)
2120 wmsg
->msg
.hwnd
= hwnd
;
2121 wmsg
->msg
.message
= msg
;
2122 wmsg
->msg
.wParam
= wParam
;
2123 wmsg
->msg
.lParam
= lParam
;
2124 wmsg
->msg
.time
= GetMessageTime ();
2129 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
2130 between left and right keys as advertised. We test for this
2131 support dynamically, and set a flag when the support is absent. If
2132 absent, we keep track of the left and right control and alt keys
2133 ourselves. This is particularly necessary on keyboards that rely
2134 upon the AltGr key, which is represented as having the left control
2135 and right alt keys pressed. For these keyboards, we need to know
2136 when the left alt key has been pressed in addition to the AltGr key
2137 so that we can properly support M-AltGr-key sequences (such as M-@
2138 on Swedish keyboards). */
2140 #define EMACS_LCONTROL 0
2141 #define EMACS_RCONTROL 1
2142 #define EMACS_LMENU 2
2143 #define EMACS_RMENU 3
2145 static int modifiers
[4];
2146 static int modifiers_recorded
;
2147 static int modifier_key_support_tested
;
2150 test_modifier_support (unsigned int wparam
)
2154 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
2156 if (wparam
== VK_CONTROL
)
2166 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
2167 modifiers_recorded
= 1;
2169 modifiers_recorded
= 0;
2170 modifier_key_support_tested
= 1;
2174 record_keydown (unsigned int wparam
, unsigned int lparam
)
2178 if (!modifier_key_support_tested
)
2179 test_modifier_support (wparam
);
2181 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2184 if (wparam
== VK_CONTROL
)
2185 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2187 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2193 record_keyup (unsigned int wparam
, unsigned int lparam
)
2197 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2200 if (wparam
== VK_CONTROL
)
2201 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2203 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2208 /* Emacs can lose focus while a modifier key has been pressed. When
2209 it regains focus, be conservative and clear all modifiers since
2210 we cannot reconstruct the left and right modifier state. */
2216 if (GetFocus () == NULL
)
2217 /* Emacs doesn't have keyboard focus. Do nothing. */
2220 ctrl
= GetAsyncKeyState (VK_CONTROL
);
2221 alt
= GetAsyncKeyState (VK_MENU
);
2223 if (!(ctrl
& 0x08000))
2224 /* Clear any recorded control modifier state. */
2225 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2227 if (!(alt
& 0x08000))
2228 /* Clear any recorded alt modifier state. */
2229 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2231 /* Update the state of all modifier keys, because modifiers used in
2232 hot-key combinations can get stuck on if Emacs loses focus as a
2233 result of a hot-key being pressed. */
2237 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
2239 GetKeyboardState (keystate
);
2240 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
2241 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
2242 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
2243 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
2244 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
2245 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
2246 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
2247 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
2248 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
2249 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
2250 SetKeyboardState (keystate
);
2254 /* Synchronize modifier state with what is reported with the current
2255 keystroke. Even if we cannot distinguish between left and right
2256 modifier keys, we know that, if no modifiers are set, then neither
2257 the left or right modifier should be set. */
2261 if (!modifiers_recorded
)
2264 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
2265 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2267 if (!(GetKeyState (VK_MENU
) & 0x8000))
2268 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2272 modifier_set (int vkey
)
2274 if (vkey
== VK_CAPITAL
|| vkey
== VK_SCROLL
)
2275 return (GetKeyState (vkey
) & 0x1);
2276 if (!modifiers_recorded
)
2277 return (GetKeyState (vkey
) & 0x8000);
2282 return modifiers
[EMACS_LCONTROL
];
2284 return modifiers
[EMACS_RCONTROL
];
2286 return modifiers
[EMACS_LMENU
];
2288 return modifiers
[EMACS_RMENU
];
2290 return (GetKeyState (vkey
) & 0x8000);
2293 /* Convert between the modifier bits W32 uses and the modifier bits
2297 w32_key_to_modifier (int key
)
2299 Lisp_Object key_mapping
;
2304 key_mapping
= Vw32_lwindow_modifier
;
2307 key_mapping
= Vw32_rwindow_modifier
;
2310 key_mapping
= Vw32_apps_modifier
;
2313 key_mapping
= Vw32_scroll_lock_modifier
;
2319 /* NB. This code runs in the input thread, asychronously to the lisp
2320 thread, so we must be careful to ensure access to lisp data is
2321 thread-safe. The following code is safe because the modifier
2322 variable values are updated atomically from lisp and symbols are
2323 not relocated by GC. Also, we don't have to worry about seeing GC
2325 if (EQ (key_mapping
, Qhyper
))
2326 return hyper_modifier
;
2327 if (EQ (key_mapping
, Qsuper
))
2328 return super_modifier
;
2329 if (EQ (key_mapping
, Qmeta
))
2330 return meta_modifier
;
2331 if (EQ (key_mapping
, Qalt
))
2332 return alt_modifier
;
2333 if (EQ (key_mapping
, Qctrl
))
2334 return ctrl_modifier
;
2335 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
2336 return ctrl_modifier
;
2337 if (EQ (key_mapping
, Qshift
))
2338 return shift_modifier
;
2340 /* Don't generate any modifier if not explicitly requested. */
2345 w32_get_modifiers ()
2347 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
2348 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
2349 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
2350 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
2351 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
2352 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
2353 (modifier_set (VK_MENU
) ?
2354 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
2357 /* We map the VK_* modifiers into console modifier constants
2358 so that we can use the same routines to handle both console
2359 and window input. */
2362 construct_console_modifiers ()
2367 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
2368 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
2369 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
2370 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
2371 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
2372 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
2373 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
2374 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
2375 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
2376 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
2377 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
2383 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
2387 /* Convert to emacs modifiers. */
2388 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
2394 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
2396 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
2399 if (virt_key
== VK_RETURN
)
2400 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
2402 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
2403 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
2405 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
2406 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
2408 if (virt_key
== VK_CLEAR
)
2409 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
2414 /* List of special key combinations which w32 would normally capture,
2415 but emacs should grab instead. Not directly visible to lisp, to
2416 simplify synchronization. Each item is an integer encoding a virtual
2417 key code and modifier combination to capture. */
2418 Lisp_Object w32_grabbed_keys
;
2420 #define HOTKEY(vk,mods) make_number (((vk) & 255) | ((mods) << 8))
2421 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
2422 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
2423 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
2425 #define RAW_HOTKEY_ID(k) ((k) & 0xbfff)
2426 #define RAW_HOTKEY_VK_CODE(k) ((k) & 255)
2427 #define RAW_HOTKEY_MODIFIERS(k) ((k) >> 8)
2429 /* Register hot-keys for reserved key combinations when Emacs has
2430 keyboard focus, since this is the only way Emacs can receive key
2431 combinations like Alt-Tab which are used by the system. */
2434 register_hot_keys (hwnd
)
2437 Lisp_Object keylist
;
2439 /* Use GC_CONSP, since we are called asynchronously. */
2440 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
2442 Lisp_Object key
= XCAR (keylist
);
2444 /* Deleted entries get set to nil. */
2445 if (!INTEGERP (key
))
2448 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
2449 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
2454 unregister_hot_keys (hwnd
)
2457 Lisp_Object keylist
;
2459 /* Use GC_CONSP, since we are called asynchronously. */
2460 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
2462 Lisp_Object key
= XCAR (keylist
);
2464 if (!INTEGERP (key
))
2467 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
2471 /* Main message dispatch loop. */
2474 w32_msg_pump (deferred_msg
* msg_buf
)
2480 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
2482 while (GetMessage (&msg
, NULL
, 0, 0))
2484 if (msg
.hwnd
== NULL
)
2486 switch (msg
.message
)
2489 /* Produced by complete_deferred_msg; just ignore. */
2491 case WM_EMACS_CREATEWINDOW
:
2492 w32_createwindow ((struct frame
*) msg
.wParam
);
2493 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2496 case WM_EMACS_SETLOCALE
:
2497 SetThreadLocale (msg
.wParam
);
2498 /* Reply is not expected. */
2500 case WM_EMACS_SETKEYBOARDLAYOUT
:
2501 result
= (int) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
2502 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2506 case WM_EMACS_REGISTER_HOT_KEY
:
2507 focus_window
= GetFocus ();
2508 if (focus_window
!= NULL
)
2509 RegisterHotKey (focus_window
,
2510 RAW_HOTKEY_ID (msg
.wParam
),
2511 RAW_HOTKEY_MODIFIERS (msg
.wParam
),
2512 RAW_HOTKEY_VK_CODE (msg
.wParam
));
2513 /* Reply is not expected. */
2515 case WM_EMACS_UNREGISTER_HOT_KEY
:
2516 focus_window
= GetFocus ();
2517 if (focus_window
!= NULL
)
2518 UnregisterHotKey (focus_window
, RAW_HOTKEY_ID (msg
.wParam
));
2519 /* Mark item as erased. NB: this code must be
2520 thread-safe. The next line is okay because the cons
2521 cell is never made into garbage and is not relocated by
2523 XSETCAR ((Lisp_Object
) ((EMACS_INT
) msg
.lParam
), Qnil
);
2524 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2527 case WM_EMACS_TOGGLE_LOCK_KEY
:
2529 int vk_code
= (int) msg
.wParam
;
2530 int cur_state
= (GetKeyState (vk_code
) & 1);
2531 Lisp_Object new_state
= (Lisp_Object
) ((EMACS_INT
) msg
.lParam
);
2533 /* NB: This code must be thread-safe. It is safe to
2534 call NILP because symbols are not relocated by GC,
2535 and pointer here is not touched by GC (so the markbit
2536 can't be set). Numbers are safe because they are
2537 immediate values. */
2538 if (NILP (new_state
)
2539 || (NUMBERP (new_state
)
2540 && ((XUINT (new_state
)) & 1) != cur_state
))
2542 one_w32_display_info
.faked_key
= vk_code
;
2544 keybd_event ((BYTE
) vk_code
,
2545 (BYTE
) MapVirtualKey (vk_code
, 0),
2546 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2547 keybd_event ((BYTE
) vk_code
,
2548 (BYTE
) MapVirtualKey (vk_code
, 0),
2549 KEYEVENTF_EXTENDEDKEY
| 0, 0);
2550 keybd_event ((BYTE
) vk_code
,
2551 (BYTE
) MapVirtualKey (vk_code
, 0),
2552 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2553 cur_state
= !cur_state
;
2555 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2561 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
2566 DispatchMessage (&msg
);
2569 /* Exit nested loop when our deferred message has completed. */
2570 if (msg_buf
->completed
)
2575 deferred_msg
* deferred_msg_head
;
2577 static deferred_msg
*
2578 find_deferred_msg (HWND hwnd
, UINT msg
)
2580 deferred_msg
* item
;
2582 /* Don't actually need synchronization for read access, since
2583 modification of single pointer is always atomic. */
2584 /* enter_crit (); */
2586 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2587 if (item
->w32msg
.msg
.hwnd
== hwnd
2588 && item
->w32msg
.msg
.message
== msg
)
2591 /* leave_crit (); */
2597 send_deferred_msg (deferred_msg
* msg_buf
,
2603 /* Only input thread can send deferred messages. */
2604 if (GetCurrentThreadId () != dwWindowsThreadId
)
2607 /* It is an error to send a message that is already deferred. */
2608 if (find_deferred_msg (hwnd
, msg
) != NULL
)
2611 /* Enforced synchronization is not needed because this is the only
2612 function that alters deferred_msg_head, and the following critical
2613 section is guaranteed to only be serially reentered (since only the
2614 input thread can call us). */
2616 /* enter_crit (); */
2618 msg_buf
->completed
= 0;
2619 msg_buf
->next
= deferred_msg_head
;
2620 deferred_msg_head
= msg_buf
;
2621 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
2623 /* leave_crit (); */
2625 /* Start a new nested message loop to process other messages until
2626 this one is completed. */
2627 w32_msg_pump (msg_buf
);
2629 deferred_msg_head
= msg_buf
->next
;
2631 return msg_buf
->result
;
2635 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
2637 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
2639 if (msg_buf
== NULL
)
2640 /* Message may have been cancelled, so don't abort(). */
2643 msg_buf
->result
= result
;
2644 msg_buf
->completed
= 1;
2646 /* Ensure input thread is woken so it notices the completion. */
2647 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2651 cancel_all_deferred_msgs ()
2653 deferred_msg
* item
;
2655 /* Don't actually need synchronization for read access, since
2656 modification of single pointer is always atomic. */
2657 /* enter_crit (); */
2659 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2662 item
->completed
= 1;
2665 /* leave_crit (); */
2667 /* Ensure input thread is woken so it notices the completion. */
2668 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2676 deferred_msg dummy_buf
;
2678 /* Ensure our message queue is created */
2680 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
2682 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2685 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
2686 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
2687 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
2689 /* This is the inital message loop which should only exit when the
2690 application quits. */
2691 w32_msg_pump (&dummy_buf
);
2697 post_character_message (hwnd
, msg
, wParam
, lParam
, modifiers
)
2707 wmsg
.dwModifiers
= modifiers
;
2709 /* Detect quit_char and set quit-flag directly. Note that we
2710 still need to post a message to ensure the main thread will be
2711 woken up if blocked in sys_select(), but we do NOT want to post
2712 the quit_char message itself (because it will usually be as if
2713 the user had typed quit_char twice). Instead, we post a dummy
2714 message that has no particular effect. */
2717 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
2718 c
= make_ctrl_char (c
) & 0377;
2720 || (wmsg
.dwModifiers
== 0 &&
2721 w32_quit_key
&& wParam
== w32_quit_key
))
2725 /* The choice of message is somewhat arbitrary, as long as
2726 the main thread handler just ignores it. */
2729 /* Interrupt any blocking system calls. */
2732 /* As a safety precaution, forcibly complete any deferred
2733 messages. This is a kludge, but I don't see any particularly
2734 clean way to handle the situation where a deferred message is
2735 "dropped" in the lisp thread, and will thus never be
2736 completed, eg. by the user trying to activate the menubar
2737 when the lisp thread is busy, and then typing C-g when the
2738 menubar doesn't open promptly (with the result that the
2739 menubar never responds at all because the deferred
2740 WM_INITMENU message is never completed). Another problem
2741 situation is when the lisp thread calls SendMessage (to send
2742 a window manager command) when a message has been deferred;
2743 the lisp thread gets blocked indefinitely waiting for the
2744 deferred message to be completed, which itself is waiting for
2745 the lisp thread to respond.
2747 Note that we don't want to block the input thread waiting for
2748 a reponse from the lisp thread (although that would at least
2749 solve the deadlock problem above), because we want to be able
2750 to receive C-g to interrupt the lisp thread. */
2751 cancel_all_deferred_msgs ();
2755 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2758 /* Main window procedure */
2761 w32_wnd_proc (hwnd
, msg
, wParam
, lParam
)
2768 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
2770 int windows_translate
;
2773 /* Note that it is okay to call x_window_to_frame, even though we are
2774 not running in the main lisp thread, because frame deletion
2775 requires the lisp thread to synchronize with this thread. Thus, if
2776 a frame struct is returned, it can be used without concern that the
2777 lisp thread might make it disappear while we are using it.
2779 NB. Walking the frame list in this thread is safe (as long as
2780 writes of Lisp_Object slots are atomic, which they are on Windows).
2781 Although delete-frame can destructively modify the frame list while
2782 we are walking it, a garbage collection cannot occur until after
2783 delete-frame has synchronized with this thread.
2785 It is also safe to use functions that make GDI calls, such as
2786 w32_clear_rect, because these functions must obtain a DC handle
2787 from the frame struct using get_frame_dc which is thread-aware. */
2792 f
= x_window_to_frame (dpyinfo
, hwnd
);
2795 HDC hdc
= get_frame_dc (f
);
2796 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
2797 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
2798 release_frame_dc (f
, hdc
);
2800 #if defined (W32_DEBUG_DISPLAY)
2801 DebPrint (("WM_ERASEBKGND (frame %p): erasing %d,%d-%d,%d\n",
2803 wmsg
.rect
.left
, wmsg
.rect
.top
,
2804 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2805 #endif /* W32_DEBUG_DISPLAY */
2808 case WM_PALETTECHANGED
:
2809 /* ignore our own changes */
2810 if ((HWND
)wParam
!= hwnd
)
2812 f
= x_window_to_frame (dpyinfo
, hwnd
);
2814 /* get_frame_dc will realize our palette and force all
2815 frames to be redrawn if needed. */
2816 release_frame_dc (f
, get_frame_dc (f
));
2821 PAINTSTRUCT paintStruct
;
2823 bzero (&update_rect
, sizeof (update_rect
));
2825 f
= x_window_to_frame (dpyinfo
, hwnd
);
2828 DebPrint (("WM_PAINT received for unknown window %p\n", hwnd
));
2832 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
2833 fails. Apparently this can happen under some
2835 if (GetUpdateRect (hwnd
, &update_rect
, FALSE
) || !w32_strict_painting
)
2838 BeginPaint (hwnd
, &paintStruct
);
2840 /* The rectangles returned by GetUpdateRect and BeginPaint
2841 do not always match. Play it safe by assuming both areas
2843 UnionRect (&(wmsg
.rect
), &update_rect
, &(paintStruct
.rcPaint
));
2845 #if defined (W32_DEBUG_DISPLAY)
2846 DebPrint (("WM_PAINT (frame %p): painting %d,%d-%d,%d\n",
2848 wmsg
.rect
.left
, wmsg
.rect
.top
,
2849 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2850 DebPrint ((" [update region is %d,%d-%d,%d]\n",
2851 update_rect
.left
, update_rect
.top
,
2852 update_rect
.right
, update_rect
.bottom
));
2854 EndPaint (hwnd
, &paintStruct
);
2857 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2862 /* If GetUpdateRect returns 0 (meaning there is no update
2863 region), assume the whole window needs to be repainted. */
2864 GetClientRect(hwnd
, &wmsg
.rect
);
2865 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2869 case WM_INPUTLANGCHANGE
:
2870 /* Inform lisp thread of keyboard layout changes. */
2871 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2873 /* Clear dead keys in the keyboard state; for simplicity only
2874 preserve modifier key states. */
2879 GetKeyboardState (keystate
);
2880 for (i
= 0; i
< 256; i
++)
2897 SetKeyboardState (keystate
);
2902 /* Synchronize hot keys with normal input. */
2903 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
2908 record_keyup (wParam
, lParam
);
2913 /* Ignore keystrokes we fake ourself; see below. */
2914 if (dpyinfo
->faked_key
== wParam
)
2916 dpyinfo
->faked_key
= 0;
2917 /* Make sure TranslateMessage sees them though (as long as
2918 they don't produce WM_CHAR messages). This ensures that
2919 indicator lights are toggled promptly on Windows 9x, for
2921 if (lispy_function_keys
[wParam
] != 0)
2923 windows_translate
= 1;
2929 /* Synchronize modifiers with current keystroke. */
2931 record_keydown (wParam
, lParam
);
2932 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
2934 windows_translate
= 0;
2939 if (NILP (Vw32_pass_lwindow_to_system
))
2941 /* Prevent system from acting on keyup (which opens the
2942 Start menu if no other key was pressed) by simulating a
2943 press of Space which we will ignore. */
2944 if (GetAsyncKeyState (wParam
) & 1)
2946 if (NUMBERP (Vw32_phantom_key_code
))
2947 key
= XUINT (Vw32_phantom_key_code
) & 255;
2950 dpyinfo
->faked_key
= key
;
2951 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
2954 if (!NILP (Vw32_lwindow_modifier
))
2958 if (NILP (Vw32_pass_rwindow_to_system
))
2960 if (GetAsyncKeyState (wParam
) & 1)
2962 if (NUMBERP (Vw32_phantom_key_code
))
2963 key
= XUINT (Vw32_phantom_key_code
) & 255;
2966 dpyinfo
->faked_key
= key
;
2967 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
2970 if (!NILP (Vw32_rwindow_modifier
))
2974 if (!NILP (Vw32_apps_modifier
))
2978 if (NILP (Vw32_pass_alt_to_system
))
2979 /* Prevent DefWindowProc from activating the menu bar if an
2980 Alt key is pressed and released by itself. */
2982 windows_translate
= 1;
2985 /* Decide whether to treat as modifier or function key. */
2986 if (NILP (Vw32_enable_caps_lock
))
2987 goto disable_lock_key
;
2988 windows_translate
= 1;
2991 /* Decide whether to treat as modifier or function key. */
2992 if (NILP (Vw32_enable_num_lock
))
2993 goto disable_lock_key
;
2994 windows_translate
= 1;
2997 /* Decide whether to treat as modifier or function key. */
2998 if (NILP (Vw32_scroll_lock_modifier
))
2999 goto disable_lock_key
;
3000 windows_translate
= 1;
3003 /* Ensure the appropriate lock key state (and indicator light)
3004 remains in the same state. We do this by faking another
3005 press of the relevant key. Apparently, this really is the
3006 only way to toggle the state of the indicator lights. */
3007 dpyinfo
->faked_key
= wParam
;
3008 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3009 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3010 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3011 KEYEVENTF_EXTENDEDKEY
| 0, 0);
3012 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3013 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3014 /* Ensure indicator lights are updated promptly on Windows 9x
3015 (TranslateMessage apparently does this), after forwarding
3017 post_character_message (hwnd
, msg
, wParam
, lParam
,
3018 w32_get_key_modifiers (wParam
, lParam
));
3019 windows_translate
= 1;
3023 case VK_PROCESSKEY
: /* Generated by IME. */
3024 windows_translate
= 1;
3027 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
3028 which is confusing for purposes of key binding; convert
3029 VK_CANCEL events into VK_PAUSE events. */
3033 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
3034 for purposes of key binding; convert these back into
3035 VK_NUMLOCK events, at least when we want to see NumLock key
3036 presses. (Note that there is never any possibility that
3037 VK_PAUSE with Ctrl really is C-Pause as per above.) */
3038 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
3039 wParam
= VK_NUMLOCK
;
3042 /* If not defined as a function key, change it to a WM_CHAR message. */
3043 if (lispy_function_keys
[wParam
] == 0)
3045 DWORD modifiers
= construct_console_modifiers ();
3047 if (!NILP (Vw32_recognize_altgr
)
3048 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
3050 /* Always let TranslateMessage handle AltGr key chords;
3051 for some reason, ToAscii doesn't always process AltGr
3052 chords correctly. */
3053 windows_translate
= 1;
3055 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
3057 /* Handle key chords including any modifiers other
3058 than shift directly, in order to preserve as much
3059 modifier information as possible. */
3060 if ('A' <= wParam
&& wParam
<= 'Z')
3062 /* Don't translate modified alphabetic keystrokes,
3063 so the user doesn't need to constantly switch
3064 layout to type control or meta keystrokes when
3065 the normal layout translates alphabetic
3066 characters to non-ascii characters. */
3067 if (!modifier_set (VK_SHIFT
))
3068 wParam
+= ('a' - 'A');
3073 /* Try to handle other keystrokes by determining the
3074 base character (ie. translating the base key plus
3078 KEY_EVENT_RECORD key
;
3080 key
.bKeyDown
= TRUE
;
3081 key
.wRepeatCount
= 1;
3082 key
.wVirtualKeyCode
= wParam
;
3083 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
3084 key
.uChar
.AsciiChar
= 0;
3085 key
.dwControlKeyState
= modifiers
;
3087 add
= w32_kbd_patch_key (&key
);
3088 /* 0 means an unrecognised keycode, negative means
3089 dead key. Ignore both. */
3092 /* Forward asciified character sequence. */
3093 post_character_message
3094 (hwnd
, WM_CHAR
, key
.uChar
.AsciiChar
, lParam
,
3095 w32_get_key_modifiers (wParam
, lParam
));
3096 w32_kbd_patch_key (&key
);
3103 /* Let TranslateMessage handle everything else. */
3104 windows_translate
= 1;
3110 if (windows_translate
)
3112 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
3114 windows_msg
.time
= GetMessageTime ();
3115 TranslateMessage (&windows_msg
);
3123 post_character_message (hwnd
, msg
, wParam
, lParam
,
3124 w32_get_key_modifiers (wParam
, lParam
));
3127 /* Simulate middle mouse button events when left and right buttons
3128 are used together, but only if user has two button mouse. */
3129 case WM_LBUTTONDOWN
:
3130 case WM_RBUTTONDOWN
:
3131 if (w32_num_mouse_buttons
> 2)
3132 goto handle_plain_button
;
3135 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
3136 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
3138 if (button_state
& this)
3141 if (button_state
== 0)
3144 button_state
|= this;
3146 if (button_state
& other
)
3148 if (mouse_button_timer
)
3150 KillTimer (hwnd
, mouse_button_timer
);
3151 mouse_button_timer
= 0;
3153 /* Generate middle mouse event instead. */
3154 msg
= WM_MBUTTONDOWN
;
3155 button_state
|= MMOUSE
;
3157 else if (button_state
& MMOUSE
)
3159 /* Ignore button event if we've already generated a
3160 middle mouse down event. This happens if the
3161 user releases and press one of the two buttons
3162 after we've faked a middle mouse event. */
3167 /* Flush out saved message. */
3168 post_msg (&saved_mouse_button_msg
);
3170 wmsg
.dwModifiers
= w32_get_modifiers ();
3171 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3173 /* Clear message buffer. */
3174 saved_mouse_button_msg
.msg
.hwnd
= 0;
3178 /* Hold onto message for now. */
3179 mouse_button_timer
=
3180 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
3181 w32_mouse_button_tolerance
, NULL
);
3182 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
3183 saved_mouse_button_msg
.msg
.message
= msg
;
3184 saved_mouse_button_msg
.msg
.wParam
= wParam
;
3185 saved_mouse_button_msg
.msg
.lParam
= lParam
;
3186 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
3187 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
3194 if (w32_num_mouse_buttons
> 2)
3195 goto handle_plain_button
;
3198 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
3199 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
3201 if ((button_state
& this) == 0)
3204 button_state
&= ~this;
3206 if (button_state
& MMOUSE
)
3208 /* Only generate event when second button is released. */
3209 if ((button_state
& other
) == 0)
3212 button_state
&= ~MMOUSE
;
3214 if (button_state
) abort ();
3221 /* Flush out saved message if necessary. */
3222 if (saved_mouse_button_msg
.msg
.hwnd
)
3224 post_msg (&saved_mouse_button_msg
);
3227 wmsg
.dwModifiers
= w32_get_modifiers ();
3228 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3230 /* Always clear message buffer and cancel timer. */
3231 saved_mouse_button_msg
.msg
.hwnd
= 0;
3232 KillTimer (hwnd
, mouse_button_timer
);
3233 mouse_button_timer
= 0;
3235 if (button_state
== 0)
3240 case WM_XBUTTONDOWN
:
3242 if (w32_pass_extra_mouse_buttons_to_system
)
3244 /* else fall through and process them. */
3245 case WM_MBUTTONDOWN
:
3247 handle_plain_button
:
3252 if (parse_button (msg
, HIWORD (wParam
), &button
, &up
))
3254 if (up
) ReleaseCapture ();
3255 else SetCapture (hwnd
);
3256 button
= (button
== 0) ? LMOUSE
:
3257 ((button
== 1) ? MMOUSE
: RMOUSE
);
3259 button_state
&= ~button
;
3261 button_state
|= button
;
3265 wmsg
.dwModifiers
= w32_get_modifiers ();
3266 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3268 /* Need to return true for XBUTTON messages, false for others,
3269 to indicate that we processed the message. */
3270 return (msg
== WM_XBUTTONDOWN
|| msg
== WM_XBUTTONUP
);
3273 /* If the mouse has just moved into the frame, start tracking
3274 it, so we will be notified when it leaves the frame. Mouse
3275 tracking only works under W98 and NT4 and later. On earlier
3276 versions, there is no way of telling when the mouse leaves the
3277 frame, so we just have to put up with help-echo and mouse
3278 highlighting remaining while the frame is not active. */
3279 if (track_mouse_event_fn
&& !track_mouse_window
)
3281 TRACKMOUSEEVENT tme
;
3282 tme
.cbSize
= sizeof (tme
);
3283 tme
.dwFlags
= TME_LEAVE
;
3284 tme
.hwndTrack
= hwnd
;
3286 track_mouse_event_fn (&tme
);
3287 track_mouse_window
= hwnd
;
3290 if (w32_mouse_move_interval
<= 0
3291 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
3293 wmsg
.dwModifiers
= w32_get_modifiers ();
3294 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3298 /* Hang onto mouse move and scroll messages for a bit, to avoid
3299 sending such events to Emacs faster than it can process them.
3300 If we get more events before the timer from the first message
3301 expires, we just replace the first message. */
3303 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
3305 SetTimer (hwnd
, MOUSE_MOVE_ID
,
3306 w32_mouse_move_interval
, NULL
);
3308 /* Hold onto message for now. */
3309 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
3310 saved_mouse_move_msg
.msg
.message
= msg
;
3311 saved_mouse_move_msg
.msg
.wParam
= wParam
;
3312 saved_mouse_move_msg
.msg
.lParam
= lParam
;
3313 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
3314 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
3319 wmsg
.dwModifiers
= w32_get_modifiers ();
3320 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3324 wmsg
.dwModifiers
= w32_get_modifiers ();
3325 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3329 /* Flush out saved messages if necessary. */
3330 if (wParam
== mouse_button_timer
)
3332 if (saved_mouse_button_msg
.msg
.hwnd
)
3334 post_msg (&saved_mouse_button_msg
);
3335 saved_mouse_button_msg
.msg
.hwnd
= 0;
3337 KillTimer (hwnd
, mouse_button_timer
);
3338 mouse_button_timer
= 0;
3340 else if (wParam
== mouse_move_timer
)
3342 if (saved_mouse_move_msg
.msg
.hwnd
)
3344 post_msg (&saved_mouse_move_msg
);
3345 saved_mouse_move_msg
.msg
.hwnd
= 0;
3347 KillTimer (hwnd
, mouse_move_timer
);
3348 mouse_move_timer
= 0;
3350 else if (wParam
== menu_free_timer
)
3352 KillTimer (hwnd
, menu_free_timer
);
3353 menu_free_timer
= 0;
3354 f
= x_window_to_frame (dpyinfo
, hwnd
);
3355 if (!f
->output_data
.w32
->menu_command_in_progress
)
3357 /* Free memory used by owner-drawn and help-echo strings. */
3358 w32_free_menu_strings (hwnd
);
3359 f
->output_data
.w32
->menubar_active
= 0;
3365 /* Windows doesn't send us focus messages when putting up and
3366 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
3367 The only indication we get that something happened is receiving
3368 this message afterwards. So this is a good time to reset our
3369 keyboard modifiers' state. */
3376 /* We must ensure menu bar is fully constructed and up to date
3377 before allowing user interaction with it. To achieve this
3378 we send this message to the lisp thread and wait for a
3379 reply (whose value is not actually needed) to indicate that
3380 the menu bar is now ready for use, so we can now return.
3382 To remain responsive in the meantime, we enter a nested message
3383 loop that can process all other messages.
3385 However, we skip all this if the message results from calling
3386 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
3387 thread a message because it is blocked on us at this point. We
3388 set menubar_active before calling TrackPopupMenu to indicate
3389 this (there is no possibility of confusion with real menubar
3392 f
= x_window_to_frame (dpyinfo
, hwnd
);
3394 && (f
->output_data
.w32
->menubar_active
3395 /* We can receive this message even in the absence of a
3396 menubar (ie. when the system menu is activated) - in this
3397 case we do NOT want to forward the message, otherwise it
3398 will cause the menubar to suddenly appear when the user
3399 had requested it to be turned off! */
3400 || f
->output_data
.w32
->menubar_widget
== NULL
))
3404 deferred_msg msg_buf
;
3406 /* Detect if message has already been deferred; in this case
3407 we cannot return any sensible value to ignore this. */
3408 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3411 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
3414 case WM_EXITMENULOOP
:
3415 f
= x_window_to_frame (dpyinfo
, hwnd
);
3417 /* If a menu command is not already in progress, check again
3418 after a short delay, since Windows often (always?) sends the
3419 WM_EXITMENULOOP before the corresponding WM_COMMAND message. */
3420 if (f
&& !f
->output_data
.w32
->menu_command_in_progress
)
3421 menu_free_timer
= SetTimer (hwnd
, MENU_FREE_ID
, MENU_FREE_DELAY
, NULL
);
3425 /* Direct handling of help_echo in menus. Should be safe now
3426 that we generate the help_echo by placing a help event in the
3429 HMENU menu
= (HMENU
) lParam
;
3430 UINT menu_item
= (UINT
) LOWORD (wParam
);
3431 UINT flags
= (UINT
) HIWORD (wParam
);
3433 w32_menu_display_help (hwnd
, menu
, menu_item
, flags
);
3437 case WM_MEASUREITEM
:
3438 f
= x_window_to_frame (dpyinfo
, hwnd
);
3441 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
3443 if (pMis
->CtlType
== ODT_MENU
)
3445 /* Work out dimensions for popup menu titles. */
3446 char * title
= (char *) pMis
->itemData
;
3447 HDC hdc
= GetDC (hwnd
);
3448 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3449 LOGFONT menu_logfont
;
3453 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3454 menu_logfont
.lfWeight
= FW_BOLD
;
3455 menu_font
= CreateFontIndirect (&menu_logfont
);
3456 old_font
= SelectObject (hdc
, menu_font
);
3458 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
3461 if (unicode_append_menu
)
3462 GetTextExtentPoint32W (hdc
, (WCHAR
*) title
,
3463 wcslen ((WCHAR
*) title
),
3466 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
3468 pMis
->itemWidth
= size
.cx
;
3469 if (pMis
->itemHeight
< size
.cy
)
3470 pMis
->itemHeight
= size
.cy
;
3473 pMis
->itemWidth
= 0;
3475 SelectObject (hdc
, old_font
);
3476 DeleteObject (menu_font
);
3477 ReleaseDC (hwnd
, hdc
);
3484 f
= x_window_to_frame (dpyinfo
, hwnd
);
3487 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
3489 if (pDis
->CtlType
== ODT_MENU
)
3491 /* Draw popup menu title. */
3492 char * title
= (char *) pDis
->itemData
;
3495 HDC hdc
= pDis
->hDC
;
3496 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3497 LOGFONT menu_logfont
;
3500 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3501 menu_logfont
.lfWeight
= FW_BOLD
;
3502 menu_font
= CreateFontIndirect (&menu_logfont
);
3503 old_font
= SelectObject (hdc
, menu_font
);
3505 /* Always draw title as if not selected. */
3506 if (unicode_append_menu
)
3509 + GetSystemMetrics (SM_CXMENUCHECK
),
3511 ETO_OPAQUE
, &pDis
->rcItem
,
3513 wcslen ((WCHAR
*) title
), NULL
);
3517 + GetSystemMetrics (SM_CXMENUCHECK
),
3519 ETO_OPAQUE
, &pDis
->rcItem
,
3520 title
, strlen (title
), NULL
);
3522 SelectObject (hdc
, old_font
);
3523 DeleteObject (menu_font
);
3531 /* Still not right - can't distinguish between clicks in the
3532 client area of the frame from clicks forwarded from the scroll
3533 bars - may have to hook WM_NCHITTEST to remember the mouse
3534 position and then check if it is in the client area ourselves. */
3535 case WM_MOUSEACTIVATE
:
3536 /* Discard the mouse click that activates a frame, allowing the
3537 user to click anywhere without changing point (or worse!).
3538 Don't eat mouse clicks on scrollbars though!! */
3539 if (LOWORD (lParam
) == HTCLIENT
)
3540 return MA_ACTIVATEANDEAT
;
3545 /* No longer tracking mouse. */
3546 track_mouse_window
= NULL
;
3548 case WM_ACTIVATEAPP
:
3550 case WM_WINDOWPOSCHANGED
:
3552 /* Inform lisp thread that a frame might have just been obscured
3553 or exposed, so should recheck visibility of all frames. */
3554 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3558 dpyinfo
->faked_key
= 0;
3560 register_hot_keys (hwnd
);
3563 unregister_hot_keys (hwnd
);
3566 /* Relinquish the system caret. */
3567 if (w32_system_caret_hwnd
)
3569 w32_visible_system_caret_hwnd
= NULL
;
3570 w32_system_caret_hwnd
= NULL
;
3575 f
= x_window_to_frame (dpyinfo
, hwnd
);
3576 if (f
&& HIWORD (wParam
) == 0)
3578 f
->output_data
.w32
->menu_command_in_progress
= 1;
3579 if (menu_free_timer
)
3581 KillTimer (hwnd
, menu_free_timer
);
3582 menu_free_timer
= 0;
3588 wmsg
.dwModifiers
= w32_get_modifiers ();
3589 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3593 wmsg
.dwModifiers
= w32_get_modifiers ();
3594 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3597 case WM_WINDOWPOSCHANGING
:
3598 /* Don't restrict the sizing of tip frames. */
3599 if (hwnd
== tip_window
)
3603 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
3605 wp
.length
= sizeof (WINDOWPLACEMENT
);
3606 GetWindowPlacement (hwnd
, &wp
);
3608 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
3615 DWORD internal_border
;
3616 DWORD scrollbar_extra
;
3619 wp
.length
= sizeof(wp
);
3620 GetWindowRect (hwnd
, &wr
);
3624 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
3625 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
3626 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
3627 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
3631 memset (&rect
, 0, sizeof (rect
));
3632 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
3633 GetMenu (hwnd
) != NULL
);
3635 /* Force width and height of client area to be exact
3636 multiples of the character cell dimensions. */
3637 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
3638 - 2 * internal_border
- scrollbar_extra
)
3640 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
3641 - 2 * internal_border
)
3646 /* For right/bottom sizing we can just fix the sizes.
3647 However for top/left sizing we will need to fix the X
3648 and Y positions as well. */
3653 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
3654 && (lppos
->flags
& SWP_NOMOVE
) == 0)
3656 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
3663 lppos
->flags
|= SWP_NOMOVE
;
3674 case WM_GETMINMAXINFO
:
3675 /* Hack to correct bug that allows Emacs frames to be resized
3676 below the Minimum Tracking Size. */
3677 ((LPMINMAXINFO
) lParam
)->ptMinTrackSize
.y
++;
3678 /* Hack to allow resizing the Emacs frame above the screen size.
3679 Note that Windows 9x limits coordinates to 16-bits. */
3680 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.x
= 32767;
3681 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.y
= 32767;
3685 if (LOWORD (lParam
) == HTCLIENT
)
3690 case WM_EMACS_SETCURSOR
:
3692 Cursor cursor
= (Cursor
) wParam
;
3698 case WM_EMACS_CREATESCROLLBAR
:
3699 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
3700 (struct scroll_bar
*) lParam
);
3702 case WM_EMACS_SHOWWINDOW
:
3703 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
3705 case WM_EMACS_SETFOREGROUND
:
3707 HWND foreground_window
;
3708 DWORD foreground_thread
, retval
;
3710 /* On NT 5.0, and apparently Windows 98, it is necessary to
3711 attach to the thread that currently has focus in order to
3712 pull the focus away from it. */
3713 foreground_window
= GetForegroundWindow ();
3714 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
3715 if (!foreground_window
3716 || foreground_thread
== GetCurrentThreadId ()
3717 || !AttachThreadInput (GetCurrentThreadId (),
3718 foreground_thread
, TRUE
))
3719 foreground_thread
= 0;
3721 retval
= SetForegroundWindow ((HWND
) wParam
);
3723 /* Detach from the previous foreground thread. */
3724 if (foreground_thread
)
3725 AttachThreadInput (GetCurrentThreadId (),
3726 foreground_thread
, FALSE
);
3731 case WM_EMACS_SETWINDOWPOS
:
3733 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
3734 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
3735 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
3738 case WM_EMACS_DESTROYWINDOW
:
3739 DragAcceptFiles ((HWND
) wParam
, FALSE
);
3740 return DestroyWindow ((HWND
) wParam
);
3742 case WM_EMACS_HIDE_CARET
:
3743 return HideCaret (hwnd
);
3745 case WM_EMACS_SHOW_CARET
:
3746 return ShowCaret (hwnd
);
3748 case WM_EMACS_DESTROY_CARET
:
3749 w32_system_caret_hwnd
= NULL
;
3750 w32_visible_system_caret_hwnd
= NULL
;
3751 return DestroyCaret ();
3753 case WM_EMACS_TRACK_CARET
:
3754 /* If there is currently no system caret, create one. */
3755 if (w32_system_caret_hwnd
== NULL
)
3757 /* Use the default caret width, and avoid changing it
3758 unneccesarily, as it confuses screen reader software. */
3759 w32_system_caret_hwnd
= hwnd
;
3760 CreateCaret (hwnd
, NULL
, 0,
3761 w32_system_caret_height
);
3764 if (!SetCaretPos (w32_system_caret_x
, w32_system_caret_y
))
3766 /* Ensure visible caret gets turned on when requested. */
3767 else if (w32_use_visible_system_caret
3768 && w32_visible_system_caret_hwnd
!= hwnd
)
3770 w32_visible_system_caret_hwnd
= hwnd
;
3771 return ShowCaret (hwnd
);
3773 /* Ensure visible caret gets turned off when requested. */
3774 else if (!w32_use_visible_system_caret
3775 && w32_visible_system_caret_hwnd
)
3777 w32_visible_system_caret_hwnd
= NULL
;
3778 return HideCaret (hwnd
);
3783 case WM_EMACS_TRACKPOPUPMENU
:
3788 pos
= (POINT
*)lParam
;
3789 flags
= TPM_CENTERALIGN
;
3790 if (button_state
& LMOUSE
)
3791 flags
|= TPM_LEFTBUTTON
;
3792 else if (button_state
& RMOUSE
)
3793 flags
|= TPM_RIGHTBUTTON
;
3795 /* Remember we did a SetCapture on the initial mouse down event,
3796 so for safety, we make sure the capture is cancelled now. */
3800 /* Use menubar_active to indicate that WM_INITMENU is from
3801 TrackPopupMenu below, and should be ignored. */
3802 f
= x_window_to_frame (dpyinfo
, hwnd
);
3804 f
->output_data
.w32
->menubar_active
= 1;
3806 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
3810 /* Eat any mouse messages during popupmenu */
3811 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
3813 /* Get the menu selection, if any */
3814 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
3816 retval
= LOWORD (amsg
.wParam
);
3832 /* Check for messages registered at runtime. */
3833 if (msg
== msh_mousewheel
)
3835 wmsg
.dwModifiers
= w32_get_modifiers ();
3836 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3841 return DefWindowProc (hwnd
, msg
, wParam
, lParam
);
3845 /* The most common default return code for handled messages is 0. */
3850 my_create_window (f
)
3855 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
3857 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
3861 /* Create a tooltip window. Unlike my_create_window, we do not do this
3862 indirectly via the Window thread, as we do not need to process Window
3863 messages for the tooltip. Creating tooltips indirectly also creates
3864 deadlocks when tooltips are created for menu items. */
3866 my_create_tip_window (f
)
3871 rect
.left
= rect
.top
= 0;
3872 rect
.right
= FRAME_PIXEL_WIDTH (f
);
3873 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
3875 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
3876 FRAME_EXTERNAL_MENU_BAR (f
));
3878 tip_window
= FRAME_W32_WINDOW (f
)
3879 = CreateWindow (EMACS_CLASS
,
3881 f
->output_data
.w32
->dwStyle
,
3884 rect
.right
- rect
.left
,
3885 rect
.bottom
- rect
.top
,
3886 FRAME_W32_WINDOW (SELECTED_FRAME ()), /* owner */
3893 SetWindowLong (tip_window
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
3894 SetWindowLong (tip_window
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
3895 SetWindowLong (tip_window
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
3896 SetWindowLong (tip_window
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
3898 /* Tip frames have no scrollbars. */
3899 SetWindowLong (tip_window
, WND_SCROLLBAR_INDEX
, 0);
3901 /* Do this to discard the default setting specified by our parent. */
3902 ShowWindow (tip_window
, SW_HIDE
);
3907 /* Create and set up the w32 window for frame F. */
3910 w32_window (f
, window_prompting
, minibuffer_only
)
3912 long window_prompting
;
3913 int minibuffer_only
;
3917 /* Use the resource name as the top-level window name
3918 for looking up resources. Make a non-Lisp copy
3919 for the window manager, so GC relocation won't bother it.
3921 Elsewhere we specify the window name for the window manager. */
3924 char *str
= (char *) SDATA (Vx_resource_name
);
3925 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
3926 strcpy (f
->namebuf
, str
);
3929 my_create_window (f
);
3931 validate_x_resource_name ();
3933 /* x_set_name normally ignores requests to set the name if the
3934 requested name is the same as the current name. This is the one
3935 place where that assumption isn't correct; f->name is set, but
3936 the server hasn't been told. */
3939 int explicit = f
->explicit_name
;
3941 f
->explicit_name
= 0;
3944 x_set_name (f
, name
, explicit);
3949 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
3950 initialize_frame_menubar (f
);
3952 if (FRAME_W32_WINDOW (f
) == 0)
3953 error ("Unable to create window");
3956 /* Handle the icon stuff for this window. Perhaps later we might
3957 want an x_set_icon_position which can be called interactively as
3965 Lisp_Object icon_x
, icon_y
;
3967 /* Set the position of the icon. Note that Windows 95 groups all
3968 icons in the tray. */
3969 icon_x
= w32_get_arg (parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
3970 icon_y
= w32_get_arg (parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
3971 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
3973 CHECK_NUMBER (icon_x
);
3974 CHECK_NUMBER (icon_y
);
3976 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
3977 error ("Both left and top icon corners of icon must be specified");
3981 if (! EQ (icon_x
, Qunbound
))
3982 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
3985 /* Start up iconic or window? */
3986 x_wm_set_window_state
3987 (f
, (EQ (w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
3991 x_text_icon (f
, (char *) SDATA ((!NILP (f
->icon_name
)
4004 XGCValues gc_values
;
4008 /* Create the GC's of this frame.
4009 Note that many default values are used. */
4012 gc_values
.font
= FRAME_FONT (f
);
4014 /* Cursor has cursor-color background, background-color foreground. */
4015 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
4016 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
4017 f
->output_data
.w32
->cursor_gc
4018 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
4019 (GCFont
| GCForeground
| GCBackground
),
4023 f
->output_data
.w32
->white_relief
.gc
= 0;
4024 f
->output_data
.w32
->black_relief
.gc
= 0;
4030 /* Handler for signals raised during x_create_frame and
4031 x_create_top_frame. FRAME is the frame which is partially
4035 unwind_create_frame (frame
)
4038 struct frame
*f
= XFRAME (frame
);
4040 /* If frame is ``official'', nothing to do. */
4041 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
4044 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4047 x_free_frame_resources (f
);
4049 /* Check that reference counts are indeed correct. */
4050 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
4051 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
4060 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
4062 doc
: /* Make a new window, which is called a \"frame\" in Emacs terms.
4063 Returns an Emacs frame object.
4064 PARAMETERS is an alist of frame parameters.
4065 If the parameters specify that the frame should not have a minibuffer,
4066 and do not specify a specific minibuffer window to use,
4067 then `default-minibuffer-frame' must be a frame whose minibuffer can
4068 be shared by the new frame.
4070 This function is an internal primitive--use `make-frame' instead. */)
4072 Lisp_Object parameters
;
4075 Lisp_Object frame
, tem
;
4077 int minibuffer_only
= 0;
4078 long window_prompting
= 0;
4080 int count
= SPECPDL_INDEX ();
4081 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4082 Lisp_Object display
;
4083 struct w32_display_info
*dpyinfo
= NULL
;
4089 /* Use this general default value to start with
4090 until we know if this frame has a specified name. */
4091 Vx_resource_name
= Vinvocation_name
;
4093 display
= w32_get_arg (parameters
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
4094 if (EQ (display
, Qunbound
))
4096 dpyinfo
= check_x_display_info (display
);
4098 kb
= dpyinfo
->kboard
;
4100 kb
= &the_only_kboard
;
4103 name
= w32_get_arg (parameters
, Qname
, "name", "Name", RES_TYPE_STRING
);
4105 && ! EQ (name
, Qunbound
)
4107 error ("Invalid frame name--not a string or nil");
4110 Vx_resource_name
= name
;
4112 /* See if parent window is specified. */
4113 parent
= w32_get_arg (parameters
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
4114 if (EQ (parent
, Qunbound
))
4116 if (! NILP (parent
))
4117 CHECK_NUMBER (parent
);
4119 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
4120 /* No need to protect DISPLAY because that's not used after passing
4121 it to make_frame_without_minibuffer. */
4123 GCPRO4 (parameters
, parent
, name
, frame
);
4124 tem
= w32_get_arg (parameters
, Qminibuffer
, "minibuffer", "Minibuffer",
4126 if (EQ (tem
, Qnone
) || NILP (tem
))
4127 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
4128 else if (EQ (tem
, Qonly
))
4130 f
= make_minibuffer_frame ();
4131 minibuffer_only
= 1;
4133 else if (WINDOWP (tem
))
4134 f
= make_frame_without_minibuffer (tem
, kb
, display
);
4138 XSETFRAME (frame
, f
);
4140 /* Note that Windows does support scroll bars. */
4141 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
4143 /* By default, make scrollbars the system standard width. */
4144 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
4146 f
->output_method
= output_w32
;
4147 f
->output_data
.w32
=
4148 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
4149 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
4150 FRAME_FONTSET (f
) = -1;
4151 record_unwind_protect (unwind_create_frame
, frame
);
4154 = w32_get_arg (parameters
, Qicon_name
, "iconName", "Title", RES_TYPE_STRING
);
4155 if (! STRINGP (f
->icon_name
))
4156 f
->icon_name
= Qnil
;
4158 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
4160 FRAME_KBOARD (f
) = kb
;
4163 /* Specify the parent under which to make this window. */
4167 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
4168 f
->output_data
.w32
->explicit_parent
= 1;
4172 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4173 f
->output_data
.w32
->explicit_parent
= 0;
4176 /* Set the name; the functions to which we pass f expect the name to
4178 if (EQ (name
, Qunbound
) || NILP (name
))
4180 f
->name
= build_string (dpyinfo
->w32_id_name
);
4181 f
->explicit_name
= 0;
4186 f
->explicit_name
= 1;
4187 /* use the frame's title when getting resources for this frame. */
4188 specbind (Qx_resource_name
, name
);
4191 /* Extract the window parameters from the supplied values
4192 that are needed to determine window geometry. */
4196 font
= w32_get_arg (parameters
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4199 /* First, try whatever font the caller has specified. */
4202 tem
= Fquery_fontset (font
, Qnil
);
4204 font
= x_new_fontset (f
, SDATA (tem
));
4206 font
= x_new_font (f
, SDATA (font
));
4208 /* Try out a font which we hope has bold and italic variations. */
4209 if (!STRINGP (font
))
4210 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
4211 if (! STRINGP (font
))
4212 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
4213 /* If those didn't work, look for something which will at least work. */
4214 if (! STRINGP (font
))
4215 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
4217 if (! STRINGP (font
))
4218 font
= build_string ("Fixedsys");
4220 x_default_parameter (f
, parameters
, Qfont
, font
,
4221 "font", "Font", RES_TYPE_STRING
);
4224 x_default_parameter (f
, parameters
, Qborder_width
, make_number (2),
4225 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4226 /* This defaults to 2 in order to match xterm. We recognize either
4227 internalBorderWidth or internalBorder (which is what xterm calls
4229 if (NILP (Fassq (Qinternal_border_width
, parameters
)))
4233 value
= w32_get_arg (parameters
, Qinternal_border_width
,
4234 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
4235 if (! EQ (value
, Qunbound
))
4236 parameters
= Fcons (Fcons (Qinternal_border_width
, value
),
4239 /* Default internalBorderWidth to 0 on Windows to match other programs. */
4240 x_default_parameter (f
, parameters
, Qinternal_border_width
, make_number (0),
4241 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
4242 x_default_parameter (f
, parameters
, Qvertical_scroll_bars
, Qright
,
4243 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
4245 /* Also do the stuff which must be set before the window exists. */
4246 x_default_parameter (f
, parameters
, Qforeground_color
, build_string ("black"),
4247 "foreground", "Foreground", RES_TYPE_STRING
);
4248 x_default_parameter (f
, parameters
, Qbackground_color
, build_string ("white"),
4249 "background", "Background", RES_TYPE_STRING
);
4250 x_default_parameter (f
, parameters
, Qmouse_color
, build_string ("black"),
4251 "pointerColor", "Foreground", RES_TYPE_STRING
);
4252 x_default_parameter (f
, parameters
, Qcursor_color
, build_string ("black"),
4253 "cursorColor", "Foreground", RES_TYPE_STRING
);
4254 x_default_parameter (f
, parameters
, Qborder_color
, build_string ("black"),
4255 "borderColor", "BorderColor", RES_TYPE_STRING
);
4256 x_default_parameter (f
, parameters
, Qscreen_gamma
, Qnil
,
4257 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
4258 x_default_parameter (f
, parameters
, Qline_spacing
, Qnil
,
4259 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
4260 x_default_parameter (f
, parameters
, Qleft_fringe
, Qnil
,
4261 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
4262 x_default_parameter (f
, parameters
, Qright_fringe
, Qnil
,
4263 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
4266 /* Init faces before x_default_parameter is called for scroll-bar
4267 parameters because that function calls x_set_scroll_bar_width,
4268 which calls change_frame_size, which calls Fset_window_buffer,
4269 which runs hooks, which call Fvertical_motion. At the end, we
4270 end up in init_iterator with a null face cache, which should not
4272 init_frame_faces (f
);
4274 x_default_parameter (f
, parameters
, Qmenu_bar_lines
, make_number (1),
4275 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
4276 x_default_parameter (f
, parameters
, Qtool_bar_lines
, make_number (1),
4277 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
4279 x_default_parameter (f
, parameters
, Qbuffer_predicate
, Qnil
,
4280 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
4281 x_default_parameter (f
, parameters
, Qtitle
, Qnil
,
4282 "title", "Title", RES_TYPE_STRING
);
4283 x_default_parameter (f
, parameters
, Qfullscreen
, Qnil
,
4284 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
4286 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
4287 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
4289 f
->output_data
.w32
->text_cursor
= w32_load_cursor (IDC_IBEAM
);
4290 f
->output_data
.w32
->nontext_cursor
= w32_load_cursor (IDC_ARROW
);
4291 f
->output_data
.w32
->modeline_cursor
= w32_load_cursor (IDC_ARROW
);
4292 f
->output_data
.w32
->hand_cursor
= w32_load_cursor (IDC_HAND
);
4293 f
->output_data
.w32
->hourglass_cursor
= w32_load_cursor (IDC_WAIT
);
4294 f
->output_data
.w32
->horizontal_drag_cursor
= w32_load_cursor (IDC_SIZEWE
);
4296 window_prompting
= x_figure_window_size (f
, parameters
, 1);
4298 tem
= w32_get_arg (parameters
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
4299 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
4301 w32_window (f
, window_prompting
, minibuffer_only
);
4302 x_icon (f
, parameters
);
4306 /* Now consider the frame official. */
4307 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
4308 Vframe_list
= Fcons (frame
, Vframe_list
);
4310 /* We need to do this after creating the window, so that the
4311 icon-creation functions can say whose icon they're describing. */
4312 x_default_parameter (f
, parameters
, Qicon_type
, Qnil
,
4313 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
4315 x_default_parameter (f
, parameters
, Qauto_raise
, Qnil
,
4316 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4317 x_default_parameter (f
, parameters
, Qauto_lower
, Qnil
,
4318 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4319 x_default_parameter (f
, parameters
, Qcursor_type
, Qbox
,
4320 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4321 x_default_parameter (f
, parameters
, Qscroll_bar_width
, Qnil
,
4322 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
4324 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4325 Change will not be effected unless different from the current
4327 width
= FRAME_COLS (f
);
4328 height
= FRAME_LINES (f
);
4330 FRAME_LINES (f
) = 0;
4331 SET_FRAME_COLS (f
, 0);
4332 change_frame_size (f
, height
, width
, 1, 0, 0);
4334 /* Tell the server what size and position, etc, we want, and how
4335 badly we want them. This should be done after we have the menu
4336 bar so that its size can be taken into account. */
4338 x_wm_set_size_hint (f
, window_prompting
, 0);
4341 /* Avoid a bug that causes the new frame to never become visible if
4342 an echo area message is displayed during the following call1. */
4343 specbind(Qredisplay_dont_pause
, Qt
);
4345 /* Set up faces after all frame parameters are known. This call
4346 also merges in face attributes specified for new frames. If we
4347 don't do this, the `menu' face for instance won't have the right
4348 colors, and the menu bar won't appear in the specified colors for
4350 call1 (Qface_set_after_frame_default
, frame
);
4352 /* Make the window appear on the frame and enable display, unless
4353 the caller says not to. However, with explicit parent, Emacs
4354 cannot control visibility, so don't try. */
4355 if (! f
->output_data
.w32
->explicit_parent
)
4357 Lisp_Object visibility
;
4359 visibility
= w32_get_arg (parameters
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
4360 if (EQ (visibility
, Qunbound
))
4363 if (EQ (visibility
, Qicon
))
4364 x_iconify_frame (f
);
4365 else if (! NILP (visibility
))
4366 x_make_frame_visible (f
);
4368 /* Must have been Qnil. */
4373 /* Make sure windows on this frame appear in calls to next-window
4374 and similar functions. */
4375 Vwindow_list
= Qnil
;
4377 return unbind_to (count
, frame
);
4380 /* FRAME is used only to get a handle on the X display. We don't pass the
4381 display info directly because we're called from frame.c, which doesn't
4382 know about that structure. */
4384 x_get_focus_frame (frame
)
4385 struct frame
*frame
;
4387 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
4389 if (! dpyinfo
->w32_focus_frame
)
4392 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
4396 DEFUN ("w32-focus-frame", Fw32_focus_frame
, Sw32_focus_frame
, 1, 1, 0,
4397 doc
: /* Give FRAME input focus, raising to foreground if necessary. */)
4401 x_focus_on_frame (check_x_frame (frame
));
4406 /* Return the charset portion of a font name. */
4407 char * xlfd_charset_of_font (char * fontname
)
4409 char *charset
, *encoding
;
4411 encoding
= strrchr(fontname
, '-');
4412 if (!encoding
|| encoding
== fontname
)
4415 for (charset
= encoding
- 1; charset
>= fontname
; charset
--)
4416 if (*charset
== '-')
4419 if (charset
== fontname
|| strcmp(charset
, "-*-*") == 0)
4425 struct font_info
*w32_load_bdf_font (struct frame
*f
, char *fontname
,
4426 int size
, char* filename
);
4427 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
);
4428 static BOOL
w32_to_x_font (LOGFONT
* lplf
, char * lpxstr
, int len
,
4430 static BOOL
x_to_w32_font (char *lpxstr
, LOGFONT
*lplogfont
);
4432 static struct font_info
*
4433 w32_load_system_font (f
,fontname
,size
)
4438 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4439 Lisp_Object font_names
;
4441 /* Get a list of all the fonts that match this name. Once we
4442 have a list of matching fonts, we compare them against the fonts
4443 we already have loaded by comparing names. */
4444 font_names
= w32_list_fonts (f
, build_string (fontname
), size
, 100);
4446 if (!NILP (font_names
))
4451 /* First check if any are already loaded, as that is cheaper
4452 than loading another one. */
4453 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
4454 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
4455 if (dpyinfo
->font_table
[i
].name
4456 && (!strcmp (dpyinfo
->font_table
[i
].name
,
4457 SDATA (XCAR (tail
)))
4458 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
4459 SDATA (XCAR (tail
)))))
4460 return (dpyinfo
->font_table
+ i
);
4462 fontname
= (char *) SDATA (XCAR (font_names
));
4464 else if (w32_strict_fontnames
)
4466 /* If EnumFontFamiliesEx was available, we got a full list of
4467 fonts back so stop now to avoid the possibility of loading a
4468 random font. If we had to fall back to EnumFontFamilies, the
4469 list is incomplete, so continue whether the font we want was
4471 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
4472 FARPROC enum_font_families_ex
4473 = GetProcAddress (gdi32
, "EnumFontFamiliesExA");
4474 if (enum_font_families_ex
)
4478 /* Load the font and add it to the table. */
4480 char *full_name
, *encoding
, *charset
;
4482 struct font_info
*fontp
;
4488 if (!fontname
|| !x_to_w32_font (fontname
, &lf
))
4491 if (!*lf
.lfFaceName
)
4492 /* If no name was specified for the font, we get a random font
4493 from CreateFontIndirect - this is not particularly
4494 desirable, especially since CreateFontIndirect does not
4495 fill out the missing name in lf, so we never know what we
4499 lf
.lfQuality
= DEFAULT_QUALITY
;
4501 font
= (XFontStruct
*) xmalloc (sizeof (XFontStruct
));
4502 bzero (font
, sizeof (*font
));
4504 /* Set bdf to NULL to indicate that this is a Windows font. */
4509 font
->hfont
= CreateFontIndirect (&lf
);
4511 if (font
->hfont
== NULL
)
4520 codepage
= w32_codepage_for_font (fontname
);
4522 hdc
= GetDC (dpyinfo
->root_window
);
4523 oldobj
= SelectObject (hdc
, font
->hfont
);
4525 ok
= GetTextMetrics (hdc
, &font
->tm
);
4526 if (codepage
== CP_UNICODE
)
4527 font
->double_byte_p
= 1;
4530 /* Unfortunately, some fonts (eg. MingLiU, a big5 ttf font)
4531 don't report themselves as double byte fonts, when
4532 patently they are. So instead of trusting
4533 GetFontLanguageInfo, we check the properties of the
4534 codepage directly, since that is ultimately what we are
4535 working from anyway. */
4536 /* font->double_byte_p = GetFontLanguageInfo(hdc) & GCP_DBCS; */
4538 GetCPInfo (codepage
, &cpi
);
4539 font
->double_byte_p
= cpi
.MaxCharSize
> 1;
4542 SelectObject (hdc
, oldobj
);
4543 ReleaseDC (dpyinfo
->root_window
, hdc
);
4544 /* Fill out details in lf according to the font that was
4546 lf
.lfHeight
= font
->tm
.tmInternalLeading
- font
->tm
.tmHeight
;
4547 lf
.lfWidth
= font
->tm
.tmAveCharWidth
;
4548 lf
.lfWeight
= font
->tm
.tmWeight
;
4549 lf
.lfItalic
= font
->tm
.tmItalic
;
4550 lf
.lfCharSet
= font
->tm
.tmCharSet
;
4551 lf
.lfPitchAndFamily
= ((font
->tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
)
4552 ? VARIABLE_PITCH
: FIXED_PITCH
);
4553 lf
.lfOutPrecision
= ((font
->tm
.tmPitchAndFamily
& TMPF_VECTOR
)
4554 ? OUT_STROKE_PRECIS
: OUT_STRING_PRECIS
);
4556 w32_cache_char_metrics (font
);
4563 w32_unload_font (dpyinfo
, font
);
4567 /* Find a free slot in the font table. */
4568 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
4569 if (dpyinfo
->font_table
[i
].name
== NULL
)
4572 /* If no free slot found, maybe enlarge the font table. */
4573 if (i
== dpyinfo
->n_fonts
4574 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
4577 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
4578 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
4580 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
4583 fontp
= dpyinfo
->font_table
+ i
;
4584 if (i
== dpyinfo
->n_fonts
)
4587 /* Now fill in the slots of *FONTP. */
4589 bzero (fontp
, sizeof (*fontp
));
4591 fontp
->font_idx
= i
;
4592 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
4593 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
4595 charset
= xlfd_charset_of_font (fontname
);
4597 /* Cache the W32 codepage for a font. This makes w32_encode_char
4598 (called for every glyph during redisplay) much faster. */
4599 fontp
->codepage
= codepage
;
4601 /* Work out the font's full name. */
4602 full_name
= (char *)xmalloc (100);
4603 if (full_name
&& w32_to_x_font (&lf
, full_name
, 100, charset
))
4604 fontp
->full_name
= full_name
;
4607 /* If all else fails - just use the name we used to load it. */
4609 fontp
->full_name
= fontp
->name
;
4612 fontp
->size
= FONT_WIDTH (font
);
4613 fontp
->height
= FONT_HEIGHT (font
);
4615 /* The slot `encoding' specifies how to map a character
4616 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
4617 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
4618 (0:0x20..0x7F, 1:0xA0..0xFF,
4619 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
4620 2:0xA020..0xFF7F). For the moment, we don't know which charset
4621 uses this font. So, we set information in fontp->encoding[1]
4622 which is never used by any charset. If mapping can't be
4623 decided, set FONT_ENCODING_NOT_DECIDED. */
4625 /* SJIS fonts need to be set to type 4, all others seem to work as
4626 type FONT_ENCODING_NOT_DECIDED. */
4627 encoding
= strrchr (fontp
->name
, '-');
4628 if (encoding
&& strnicmp (encoding
+1, "sjis", 4) == 0)
4629 fontp
->encoding
[1] = 4;
4631 fontp
->encoding
[1] = FONT_ENCODING_NOT_DECIDED
;
4633 /* The following three values are set to 0 under W32, which is
4634 what they get set to if XGetFontProperty fails under X. */
4635 fontp
->baseline_offset
= 0;
4636 fontp
->relative_compose
= 0;
4637 fontp
->default_ascent
= 0;
4639 /* Set global flag fonts_changed_p to non-zero if the font loaded
4640 has a character with a smaller width than any other character
4641 before, or if the font loaded has a smaller height than any
4642 other font loaded before. If this happens, it will make a
4643 glyph matrix reallocation necessary. */
4644 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
4650 /* Load font named FONTNAME of size SIZE for frame F, and return a
4651 pointer to the structure font_info while allocating it dynamically.
4652 If loading fails, return NULL. */
4654 w32_load_font (f
,fontname
,size
)
4659 Lisp_Object bdf_fonts
;
4660 struct font_info
*retval
= NULL
;
4661 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
4663 bdf_fonts
= w32_list_bdf_fonts (build_string (fontname
), 1);
4665 while (!retval
&& CONSP (bdf_fonts
))
4667 char *bdf_name
, *bdf_file
;
4668 Lisp_Object bdf_pair
;
4671 bdf_name
= SDATA (XCAR (bdf_fonts
));
4672 bdf_pair
= Fassoc (XCAR (bdf_fonts
), Vw32_bdf_filename_alist
);
4673 bdf_file
= SDATA (XCDR (bdf_pair
));
4675 // If the font is already loaded, do not load it again.
4676 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
4678 if ((dpyinfo
->font_table
[i
].name
4679 && !strcmp (dpyinfo
->font_table
[i
].name
, bdf_name
))
4680 || (dpyinfo
->font_table
[i
].full_name
4681 && !strcmp (dpyinfo
->font_table
[i
].full_name
, bdf_name
)))
4682 return dpyinfo
->font_table
+ i
;
4685 retval
= w32_load_bdf_font (f
, bdf_name
, size
, bdf_file
);
4687 bdf_fonts
= XCDR (bdf_fonts
);
4693 return w32_load_system_font(f
, fontname
, size
);
4698 w32_unload_font (dpyinfo
, font
)
4699 struct w32_display_info
*dpyinfo
;
4704 if (font
->per_char
) xfree (font
->per_char
);
4705 if (font
->bdf
) w32_free_bdf_font (font
->bdf
);
4707 if (font
->hfont
) DeleteObject(font
->hfont
);
4712 /* The font conversion stuff between x and w32 */
4714 /* X font string is as follows (from faces.el)
4718 * (weight "\\(bold\\|demibold\\|medium\\)") ; 1
4719 * (weight\? "\\([^-]*\\)") ; 1
4720 * (slant "\\([ior]\\)") ; 2
4721 * (slant\? "\\([^-]?\\)") ; 2
4722 * (swidth "\\([^-]*\\)") ; 3
4723 * (adstyle "[^-]*") ; 4
4724 * (pixelsize "[0-9]+")
4725 * (pointsize "[0-9][0-9]+")
4726 * (resx "[0-9][0-9]+")
4727 * (resy "[0-9][0-9]+")
4728 * (spacing "[cmp?*]")
4729 * (avgwidth "[0-9]+")
4730 * (registry "[^-]+")
4731 * (encoding "[^-]+")
4736 x_to_w32_weight (lpw
)
4739 if (!lpw
) return (FW_DONTCARE
);
4741 if (stricmp (lpw
,"heavy") == 0) return FW_HEAVY
;
4742 else if (stricmp (lpw
,"extrabold") == 0) return FW_EXTRABOLD
;
4743 else if (stricmp (lpw
,"bold") == 0) return FW_BOLD
;
4744 else if (stricmp (lpw
,"demibold") == 0) return FW_SEMIBOLD
;
4745 else if (stricmp (lpw
,"semibold") == 0) return FW_SEMIBOLD
;
4746 else if (stricmp (lpw
,"medium") == 0) return FW_MEDIUM
;
4747 else if (stricmp (lpw
,"normal") == 0) return FW_NORMAL
;
4748 else if (stricmp (lpw
,"light") == 0) return FW_LIGHT
;
4749 else if (stricmp (lpw
,"extralight") == 0) return FW_EXTRALIGHT
;
4750 else if (stricmp (lpw
,"thin") == 0) return FW_THIN
;
4757 w32_to_x_weight (fnweight
)
4760 if (fnweight
>= FW_HEAVY
) return "heavy";
4761 if (fnweight
>= FW_EXTRABOLD
) return "extrabold";
4762 if (fnweight
>= FW_BOLD
) return "bold";
4763 if (fnweight
>= FW_SEMIBOLD
) return "demibold";
4764 if (fnweight
>= FW_MEDIUM
) return "medium";
4765 if (fnweight
>= FW_NORMAL
) return "normal";
4766 if (fnweight
>= FW_LIGHT
) return "light";
4767 if (fnweight
>= FW_EXTRALIGHT
) return "extralight";
4768 if (fnweight
>= FW_THIN
) return "thin";
4774 x_to_w32_charset (lpcs
)
4777 Lisp_Object this_entry
, w32_charset
;
4779 int len
= strlen (lpcs
);
4781 /* Support "*-#nnn" format for unknown charsets. */
4782 if (strncmp (lpcs
, "*-#", 3) == 0)
4783 return atoi (lpcs
+ 3);
4785 /* Handle wildcards by ignoring them; eg. treat "big5*-*" as "big5". */
4786 charset
= alloca (len
+ 1);
4787 strcpy (charset
, lpcs
);
4788 lpcs
= strchr (charset
, '*');
4792 /* Look through w32-charset-info-alist for the character set.
4793 Format of each entry is
4794 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
4796 this_entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
4798 if (NILP(this_entry
))
4800 /* At startup, we want iso8859-1 fonts to come up properly. */
4801 if (stricmp(charset
, "iso8859-1") == 0)
4802 return ANSI_CHARSET
;
4804 return DEFAULT_CHARSET
;
4807 w32_charset
= Fcar (Fcdr (this_entry
));
4809 /* Translate Lisp symbol to number. */
4810 if (EQ (w32_charset
, Qw32_charset_ansi
))
4811 return ANSI_CHARSET
;
4812 if (EQ (w32_charset
, Qw32_charset_symbol
))
4813 return SYMBOL_CHARSET
;
4814 if (EQ (w32_charset
, Qw32_charset_shiftjis
))
4815 return SHIFTJIS_CHARSET
;
4816 if (EQ (w32_charset
, Qw32_charset_hangeul
))
4817 return HANGEUL_CHARSET
;
4818 if (EQ (w32_charset
, Qw32_charset_chinesebig5
))
4819 return CHINESEBIG5_CHARSET
;
4820 if (EQ (w32_charset
, Qw32_charset_gb2312
))
4821 return GB2312_CHARSET
;
4822 if (EQ (w32_charset
, Qw32_charset_oem
))
4824 #ifdef JOHAB_CHARSET
4825 if (EQ (w32_charset
, Qw32_charset_johab
))
4826 return JOHAB_CHARSET
;
4827 if (EQ (w32_charset
, Qw32_charset_easteurope
))
4828 return EASTEUROPE_CHARSET
;
4829 if (EQ (w32_charset
, Qw32_charset_turkish
))
4830 return TURKISH_CHARSET
;
4831 if (EQ (w32_charset
, Qw32_charset_baltic
))
4832 return BALTIC_CHARSET
;
4833 if (EQ (w32_charset
, Qw32_charset_russian
))
4834 return RUSSIAN_CHARSET
;
4835 if (EQ (w32_charset
, Qw32_charset_arabic
))
4836 return ARABIC_CHARSET
;
4837 if (EQ (w32_charset
, Qw32_charset_greek
))
4838 return GREEK_CHARSET
;
4839 if (EQ (w32_charset
, Qw32_charset_hebrew
))
4840 return HEBREW_CHARSET
;
4841 if (EQ (w32_charset
, Qw32_charset_vietnamese
))
4842 return VIETNAMESE_CHARSET
;
4843 if (EQ (w32_charset
, Qw32_charset_thai
))
4844 return THAI_CHARSET
;
4845 if (EQ (w32_charset
, Qw32_charset_mac
))
4847 #endif /* JOHAB_CHARSET */
4848 #ifdef UNICODE_CHARSET
4849 if (EQ (w32_charset
, Qw32_charset_unicode
))
4850 return UNICODE_CHARSET
;
4853 return DEFAULT_CHARSET
;
4858 w32_to_x_charset (fncharset
)
4861 static char buf
[32];
4862 Lisp_Object charset_type
;
4867 /* Handle startup case of w32-charset-info-alist not
4868 being set up yet. */
4869 if (NILP(Vw32_charset_info_alist
))
4871 charset_type
= Qw32_charset_ansi
;
4873 case DEFAULT_CHARSET
:
4874 charset_type
= Qw32_charset_default
;
4876 case SYMBOL_CHARSET
:
4877 charset_type
= Qw32_charset_symbol
;
4879 case SHIFTJIS_CHARSET
:
4880 charset_type
= Qw32_charset_shiftjis
;
4882 case HANGEUL_CHARSET
:
4883 charset_type
= Qw32_charset_hangeul
;
4885 case GB2312_CHARSET
:
4886 charset_type
= Qw32_charset_gb2312
;
4888 case CHINESEBIG5_CHARSET
:
4889 charset_type
= Qw32_charset_chinesebig5
;
4892 charset_type
= Qw32_charset_oem
;
4895 /* More recent versions of Windows (95 and NT4.0) define more
4897 #ifdef EASTEUROPE_CHARSET
4898 case EASTEUROPE_CHARSET
:
4899 charset_type
= Qw32_charset_easteurope
;
4901 case TURKISH_CHARSET
:
4902 charset_type
= Qw32_charset_turkish
;
4904 case BALTIC_CHARSET
:
4905 charset_type
= Qw32_charset_baltic
;
4907 case RUSSIAN_CHARSET
:
4908 charset_type
= Qw32_charset_russian
;
4910 case ARABIC_CHARSET
:
4911 charset_type
= Qw32_charset_arabic
;
4914 charset_type
= Qw32_charset_greek
;
4916 case HEBREW_CHARSET
:
4917 charset_type
= Qw32_charset_hebrew
;
4919 case VIETNAMESE_CHARSET
:
4920 charset_type
= Qw32_charset_vietnamese
;
4923 charset_type
= Qw32_charset_thai
;
4926 charset_type
= Qw32_charset_mac
;
4929 charset_type
= Qw32_charset_johab
;
4933 #ifdef UNICODE_CHARSET
4934 case UNICODE_CHARSET
:
4935 charset_type
= Qw32_charset_unicode
;
4939 /* Encode numerical value of unknown charset. */
4940 sprintf (buf
, "*-#%u", fncharset
);
4946 char * best_match
= NULL
;
4948 /* Look through w32-charset-info-alist for the character set.
4949 Prefer ISO codepages, and prefer lower numbers in the ISO
4950 range. Only return charsets for codepages which are installed.
4952 Format of each entry is
4953 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
4955 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
4958 Lisp_Object w32_charset
;
4959 Lisp_Object codepage
;
4961 Lisp_Object this_entry
= XCAR (rest
);
4963 /* Skip invalid entries in alist. */
4964 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
4965 || !CONSP (XCDR (this_entry
))
4966 || !SYMBOLP (XCAR (XCDR (this_entry
))))
4969 x_charset
= SDATA (XCAR (this_entry
));
4970 w32_charset
= XCAR (XCDR (this_entry
));
4971 codepage
= XCDR (XCDR (this_entry
));
4973 /* Look for Same charset and a valid codepage (or non-int
4974 which means ignore). */
4975 if (EQ (w32_charset
, charset_type
)
4976 && (!INTEGERP (codepage
) || XINT (codepage
) == CP_DEFAULT
4977 || IsValidCodePage (XINT (codepage
))))
4979 /* If we don't have a match already, then this is the
4982 best_match
= x_charset
;
4983 /* If this is an ISO codepage, and the best so far isn't,
4984 then this is better. */
4985 else if (strnicmp (best_match
, "iso", 3) != 0
4986 && strnicmp (x_charset
, "iso", 3) == 0)
4987 best_match
= x_charset
;
4988 /* If both are ISO8859 codepages, choose the one with the
4989 lowest number in the encoding field. */
4990 else if (strnicmp (best_match
, "iso8859-", 8) == 0
4991 && strnicmp (x_charset
, "iso8859-", 8) == 0)
4993 int best_enc
= atoi (best_match
+ 8);
4994 int this_enc
= atoi (x_charset
+ 8);
4995 if (this_enc
> 0 && this_enc
< best_enc
)
4996 best_match
= x_charset
;
5001 /* If no match, encode the numeric value. */
5004 sprintf (buf
, "*-#%u", fncharset
);
5008 strncpy(buf
, best_match
, 31);
5015 /* Return all the X charsets that map to a font. */
5017 w32_to_all_x_charsets (fncharset
)
5020 static char buf
[32];
5021 Lisp_Object charset_type
;
5022 Lisp_Object retval
= Qnil
;
5027 /* Handle startup case of w32-charset-info-alist not
5028 being set up yet. */
5029 if (NILP(Vw32_charset_info_alist
))
5030 return Fcons (build_string ("iso8859-1"), Qnil
);
5032 charset_type
= Qw32_charset_ansi
;
5034 case DEFAULT_CHARSET
:
5035 charset_type
= Qw32_charset_default
;
5037 case SYMBOL_CHARSET
:
5038 charset_type
= Qw32_charset_symbol
;
5040 case SHIFTJIS_CHARSET
:
5041 charset_type
= Qw32_charset_shiftjis
;
5043 case HANGEUL_CHARSET
:
5044 charset_type
= Qw32_charset_hangeul
;
5046 case GB2312_CHARSET
:
5047 charset_type
= Qw32_charset_gb2312
;
5049 case CHINESEBIG5_CHARSET
:
5050 charset_type
= Qw32_charset_chinesebig5
;
5053 charset_type
= Qw32_charset_oem
;
5056 /* More recent versions of Windows (95 and NT4.0) define more
5058 #ifdef EASTEUROPE_CHARSET
5059 case EASTEUROPE_CHARSET
:
5060 charset_type
= Qw32_charset_easteurope
;
5062 case TURKISH_CHARSET
:
5063 charset_type
= Qw32_charset_turkish
;
5065 case BALTIC_CHARSET
:
5066 charset_type
= Qw32_charset_baltic
;
5068 case RUSSIAN_CHARSET
:
5069 charset_type
= Qw32_charset_russian
;
5071 case ARABIC_CHARSET
:
5072 charset_type
= Qw32_charset_arabic
;
5075 charset_type
= Qw32_charset_greek
;
5077 case HEBREW_CHARSET
:
5078 charset_type
= Qw32_charset_hebrew
;
5080 case VIETNAMESE_CHARSET
:
5081 charset_type
= Qw32_charset_vietnamese
;
5084 charset_type
= Qw32_charset_thai
;
5087 charset_type
= Qw32_charset_mac
;
5090 charset_type
= Qw32_charset_johab
;
5094 #ifdef UNICODE_CHARSET
5095 case UNICODE_CHARSET
:
5096 charset_type
= Qw32_charset_unicode
;
5100 /* Encode numerical value of unknown charset. */
5101 sprintf (buf
, "*-#%u", fncharset
);
5102 return Fcons (build_string (buf
), Qnil
);
5107 /* Look through w32-charset-info-alist for the character set.
5108 Only return charsets for codepages which are installed.
5110 Format of each entry in Vw32_charset_info_alist is
5111 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5113 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
5115 Lisp_Object x_charset
;
5116 Lisp_Object w32_charset
;
5117 Lisp_Object codepage
;
5119 Lisp_Object this_entry
= XCAR (rest
);
5121 /* Skip invalid entries in alist. */
5122 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
5123 || !CONSP (XCDR (this_entry
))
5124 || !SYMBOLP (XCAR (XCDR (this_entry
))))
5127 x_charset
= XCAR (this_entry
);
5128 w32_charset
= XCAR (XCDR (this_entry
));
5129 codepage
= XCDR (XCDR (this_entry
));
5131 /* Look for Same charset and a valid codepage (or non-int
5132 which means ignore). */
5133 if (EQ (w32_charset
, charset_type
)
5134 && (!INTEGERP (codepage
) || XINT (codepage
) == CP_DEFAULT
5135 || IsValidCodePage (XINT (codepage
))))
5137 retval
= Fcons (x_charset
, retval
);
5141 /* If no match, encode the numeric value. */
5144 sprintf (buf
, "*-#%u", fncharset
);
5145 return Fcons (build_string (buf
), Qnil
);
5152 /* Get the Windows codepage corresponding to the specified font. The
5153 charset info in the font name is used to look up
5154 w32-charset-to-codepage-alist. */
5156 w32_codepage_for_font (char *fontname
)
5158 Lisp_Object codepage
, entry
;
5159 char *charset_str
, *charset
, *end
;
5161 if (NILP (Vw32_charset_info_alist
))
5164 /* Extract charset part of font string. */
5165 charset
= xlfd_charset_of_font (fontname
);
5170 charset_str
= (char *) alloca (strlen (charset
) + 1);
5171 strcpy (charset_str
, charset
);
5174 /* Remove leading "*-". */
5175 if (strncmp ("*-", charset_str
, 2) == 0)
5176 charset
= charset_str
+ 2;
5179 charset
= charset_str
;
5181 /* Stop match at wildcard (including preceding '-'). */
5182 if (end
= strchr (charset
, '*'))
5184 if (end
> charset
&& *(end
-1) == '-')
5189 entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
5193 codepage
= Fcdr (Fcdr (entry
));
5195 if (NILP (codepage
))
5197 else if (XFASTINT (codepage
) == XFASTINT (Qt
))
5199 else if (INTEGERP (codepage
))
5200 return XINT (codepage
);
5207 w32_to_x_font (lplogfont
, lpxstr
, len
, specific_charset
)
5208 LOGFONT
* lplogfont
;
5211 char * specific_charset
;
5215 char height_pixels
[8];
5217 char width_pixels
[8];
5218 char *fontname_dash
;
5219 int display_resy
= (int) one_w32_display_info
.resy
;
5220 int display_resx
= (int) one_w32_display_info
.resx
;
5222 struct coding_system coding
;
5224 if (!lpxstr
) abort ();
5229 if (lplogfont
->lfOutPrecision
== OUT_STRING_PRECIS
)
5230 fonttype
= "raster";
5231 else if (lplogfont
->lfOutPrecision
== OUT_STROKE_PRECIS
)
5232 fonttype
= "outline";
5234 fonttype
= "unknown";
5236 setup_coding_system (Fcheck_coding_system (Vlocale_coding_system
),
5238 coding
.src_multibyte
= 0;
5239 coding
.dst_multibyte
= 1;
5240 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
5241 /* We explicitely disable composition handling because selection
5242 data should not contain any composition sequence. */
5243 coding
.composing
= COMPOSITION_DISABLED
;
5244 bufsz
= decoding_buffer_size (&coding
, LF_FACESIZE
);
5246 fontname
= alloca(sizeof(*fontname
) * bufsz
);
5247 decode_coding (&coding
, lplogfont
->lfFaceName
, fontname
,
5248 strlen(lplogfont
->lfFaceName
), bufsz
- 1);
5249 *(fontname
+ coding
.produced
) = '\0';
5251 /* Replace dashes with underscores so the dashes are not
5253 fontname_dash
= fontname
;
5254 while (fontname_dash
= strchr (fontname_dash
, '-'))
5255 *fontname_dash
= '_';
5257 if (lplogfont
->lfHeight
)
5259 sprintf (height_pixels
, "%u", abs (lplogfont
->lfHeight
));
5260 sprintf (height_dpi
, "%u",
5261 abs (lplogfont
->lfHeight
) * 720 / display_resy
);
5265 strcpy (height_pixels
, "*");
5266 strcpy (height_dpi
, "*");
5268 if (lplogfont
->lfWidth
)
5269 sprintf (width_pixels
, "%u", lplogfont
->lfWidth
* 10);
5271 strcpy (width_pixels
, "*");
5273 _snprintf (lpxstr
, len
- 1,
5274 "-%s-%s-%s-%c-normal-normal-%s-%s-%d-%d-%c-%s-%s",
5275 fonttype
, /* foundry */
5276 fontname
, /* family */
5277 w32_to_x_weight (lplogfont
->lfWeight
), /* weight */
5278 lplogfont
->lfItalic
?'i':'r', /* slant */
5280 /* add style name */
5281 height_pixels
, /* pixel size */
5282 height_dpi
, /* point size */
5283 display_resx
, /* resx */
5284 display_resy
, /* resy */
5285 ((lplogfont
->lfPitchAndFamily
& 0x3) == VARIABLE_PITCH
)
5286 ? 'p' : 'c', /* spacing */
5287 width_pixels
, /* avg width */
5288 specific_charset
? specific_charset
5289 : w32_to_x_charset (lplogfont
->lfCharSet
)
5290 /* charset registry and encoding */
5293 lpxstr
[len
- 1] = 0; /* just to be sure */
5298 x_to_w32_font (lpxstr
, lplogfont
)
5300 LOGFONT
* lplogfont
;
5302 struct coding_system coding
;
5304 if (!lplogfont
) return (FALSE
);
5306 memset (lplogfont
, 0, sizeof (*lplogfont
));
5308 /* Set default value for each field. */
5310 lplogfont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
5311 lplogfont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
5312 lplogfont
->lfQuality
= DEFAULT_QUALITY
;
5314 /* go for maximum quality */
5315 lplogfont
->lfOutPrecision
= OUT_STROKE_PRECIS
;
5316 lplogfont
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
5317 lplogfont
->lfQuality
= PROOF_QUALITY
;
5320 lplogfont
->lfCharSet
= DEFAULT_CHARSET
;
5321 lplogfont
->lfWeight
= FW_DONTCARE
;
5322 lplogfont
->lfPitchAndFamily
= DEFAULT_PITCH
| FF_DONTCARE
;
5327 /* Provide a simple escape mechanism for specifying Windows font names
5328 * directly -- if font spec does not beginning with '-', assume this
5330 * "<font name>[:height in pixels[:width in pixels[:weight]]]"
5336 char name
[50], weight
[20], slant
, pitch
, pixels
[10], height
[10],
5337 width
[10], resy
[10], remainder
[50];
5339 int dpi
= (int) one_w32_display_info
.resy
;
5341 fields
= sscanf (lpxstr
,
5342 "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%49s",
5343 name
, weight
, &slant
, pixels
, height
, resy
, &pitch
, width
, remainder
);
5347 /* In the general case when wildcards cover more than one field,
5348 we don't know which field is which, so don't fill any in.
5349 However, we need to cope with this particular form, which is
5350 generated by font_list_1 (invoked by try_font_list):
5351 "-raster-6x10-*-gb2312*-*"
5352 and make sure to correctly parse the charset field. */
5355 fields
= sscanf (lpxstr
,
5356 "-%*[^-]-%49[^-]-*-%49s",
5359 else if (fields
< 9)
5365 if (fields
> 0 && name
[0] != '*')
5371 (Fcheck_coding_system (Vlocale_coding_system
), &coding
);
5372 coding
.src_multibyte
= 1;
5373 coding
.dst_multibyte
= 0;
5374 /* Need to set COMPOSITION_DISABLED, otherwise Emacs crashes in
5375 encode_coding_iso2022 trying to dereference a null pointer. */
5376 coding
.composing
= COMPOSITION_DISABLED
;
5377 if (coding
.type
== coding_type_iso2022
)
5378 coding
.flags
|= CODING_FLAG_ISO_SAFE
;
5379 bufsize
= encoding_buffer_size (&coding
, strlen (name
));
5380 buf
= (unsigned char *) alloca (bufsize
);
5381 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
5382 encode_coding (&coding
, name
, buf
, strlen (name
), bufsize
);
5383 if (coding
.produced
>= LF_FACESIZE
)
5384 coding
.produced
= LF_FACESIZE
- 1;
5385 buf
[coding
.produced
] = 0;
5386 strcpy (lplogfont
->lfFaceName
, buf
);
5390 lplogfont
->lfFaceName
[0] = '\0';
5395 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
5399 lplogfont
->lfItalic
= (fields
> 0 && slant
== 'i');
5403 if (fields
> 0 && pixels
[0] != '*')
5404 lplogfont
->lfHeight
= atoi (pixels
);
5408 if (fields
> 0 && resy
[0] != '*')
5411 if (tem
> 0) dpi
= tem
;
5414 if (fields
> -1 && lplogfont
->lfHeight
== 0 && height
[0] != '*')
5415 lplogfont
->lfHeight
= atoi (height
) * dpi
/ 720;
5418 lplogfont
->lfPitchAndFamily
=
5419 (fields
> 0 && pitch
== 'p') ? VARIABLE_PITCH
: FIXED_PITCH
;
5423 if (fields
> 0 && width
[0] != '*')
5424 lplogfont
->lfWidth
= atoi (width
) / 10;
5428 /* Strip the trailing '-' if present. (it shouldn't be, as it
5429 fails the test against xlfd-tight-regexp in fontset.el). */
5431 int len
= strlen (remainder
);
5432 if (len
> 0 && remainder
[len
-1] == '-')
5433 remainder
[len
-1] = 0;
5435 encoding
= remainder
;
5437 if (strncmp (encoding
, "*-", 2) == 0)
5440 lplogfont
->lfCharSet
= x_to_w32_charset (encoding
);
5445 char name
[100], height
[10], width
[10], weight
[20];
5447 fields
= sscanf (lpxstr
,
5448 "%99[^:]:%9[^:]:%9[^:]:%19s",
5449 name
, height
, width
, weight
);
5451 if (fields
== EOF
) return (FALSE
);
5455 strncpy (lplogfont
->lfFaceName
,name
, LF_FACESIZE
);
5456 lplogfont
->lfFaceName
[LF_FACESIZE
-1] = 0;
5460 lplogfont
->lfFaceName
[0] = 0;
5466 lplogfont
->lfHeight
= atoi (height
);
5471 lplogfont
->lfWidth
= atoi (width
);
5475 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
5478 /* This makes TrueType fonts work better. */
5479 lplogfont
->lfHeight
= - abs (lplogfont
->lfHeight
);
5484 /* Strip the pixel height and point height from the given xlfd, and
5485 return the pixel height. If no pixel height is specified, calculate
5486 one from the point height, or if that isn't defined either, return
5487 0 (which usually signifies a scalable font).
5490 xlfd_strip_height (char *fontname
)
5492 int pixel_height
, field_number
;
5493 char *read_from
, *write_to
;
5497 pixel_height
= field_number
= 0;
5500 /* Look for height fields. */
5501 for (read_from
= fontname
; *read_from
; read_from
++)
5503 if (*read_from
== '-')
5506 if (field_number
== 7) /* Pixel height. */
5509 write_to
= read_from
;
5511 /* Find end of field. */
5512 for (;*read_from
&& *read_from
!= '-'; read_from
++)
5515 /* Split the fontname at end of field. */
5521 pixel_height
= atoi (write_to
);
5522 /* Blank out field. */
5523 if (read_from
> write_to
)
5528 /* If the pixel height field is at the end (partial xlfd),
5531 return pixel_height
;
5533 /* If we got a pixel height, the point height can be
5534 ignored. Just blank it out and break now. */
5537 /* Find end of point size field. */
5538 for (; *read_from
&& *read_from
!= '-'; read_from
++)
5544 /* Blank out the point size field. */
5545 if (read_from
> write_to
)
5551 return pixel_height
;
5555 /* If the point height is already blank, break now. */
5556 if (*read_from
== '-')
5562 else if (field_number
== 8)
5564 /* If we didn't get a pixel height, try to get the point
5565 height and convert that. */
5567 char *point_size_start
= read_from
++;
5569 /* Find end of field. */
5570 for (; *read_from
&& *read_from
!= '-'; read_from
++)
5579 point_size
= atoi (point_size_start
);
5581 /* Convert to pixel height. */
5582 pixel_height
= point_size
5583 * one_w32_display_info
.height_in
/ 720;
5585 /* Blank out this field and break. */
5593 /* Shift the rest of the font spec into place. */
5594 if (write_to
&& read_from
> write_to
)
5596 for (; *read_from
; read_from
++, write_to
++)
5597 *write_to
= *read_from
;
5601 return pixel_height
;
5604 /* Assume parameter 1 is fully qualified, no wildcards. */
5606 w32_font_match (fontname
, pattern
)
5611 char *font_name_copy
;
5612 char *regex
= alloca (strlen (pattern
) * 2 + 3);
5614 font_name_copy
= alloca (strlen (fontname
) + 1);
5615 strcpy (font_name_copy
, fontname
);
5620 /* Turn pattern into a regexp and do a regexp match. */
5621 for (; *pattern
; pattern
++)
5623 if (*pattern
== '?')
5625 else if (*pattern
== '*')
5636 /* Strip out font heights and compare them seperately, since
5637 rounding error can cause mismatches. This also allows a
5638 comparison between a font that declares only a pixel height and a
5639 pattern that declares the point height.
5642 int font_height
, pattern_height
;
5644 font_height
= xlfd_strip_height (font_name_copy
);
5645 pattern_height
= xlfd_strip_height (regex
);
5647 /* Compare now, and don't bother doing expensive regexp matching
5648 if the heights differ. */
5649 if (font_height
&& pattern_height
&& (font_height
!= pattern_height
))
5653 return (fast_string_match_ignore_case (build_string (regex
),
5654 build_string(font_name_copy
)) >= 0);
5657 /* Callback functions, and a structure holding info they need, for
5658 listing system fonts on W32. We need one set of functions to do the
5659 job properly, but these don't work on NT 3.51 and earlier, so we
5660 have a second set which don't handle character sets properly to
5663 In both cases, there are two passes made. The first pass gets one
5664 font from each family, the second pass lists all the fonts from
5667 typedef struct enumfont_t
5672 XFontStruct
*size_ref
;
5673 Lisp_Object pattern
;
5679 enum_font_maybe_add_to_list (enumfont_t
*, LOGFONT
*, char *, Lisp_Object
);
5683 enum_font_cb2 (lplf
, lptm
, FontType
, lpef
)
5685 NEWTEXTMETRIC
* lptm
;
5689 /* Ignore struck out and underlined versions of fonts. */
5690 if (lplf
->elfLogFont
.lfStrikeOut
|| lplf
->elfLogFont
.lfUnderline
)
5693 /* Only return fonts with names starting with @ if they were
5694 explicitly specified, since Microsoft uses an initial @ to
5695 denote fonts for vertical writing, without providing a more
5696 convenient way of identifying them. */
5697 if (lplf
->elfLogFont
.lfFaceName
[0] == '@'
5698 && lpef
->logfont
.lfFaceName
[0] != '@')
5701 /* Check that the character set matches if it was specified */
5702 if (lpef
->logfont
.lfCharSet
!= DEFAULT_CHARSET
&&
5703 lplf
->elfLogFont
.lfCharSet
!= lpef
->logfont
.lfCharSet
)
5706 if (FontType
== RASTER_FONTTYPE
)
5708 /* DBCS raster fonts have problems displaying, so skip them. */
5709 int charset
= lplf
->elfLogFont
.lfCharSet
;
5710 if (charset
== SHIFTJIS_CHARSET
5711 || charset
== HANGEUL_CHARSET
5712 || charset
== CHINESEBIG5_CHARSET
5713 || charset
== GB2312_CHARSET
5714 #ifdef JOHAB_CHARSET
5715 || charset
== JOHAB_CHARSET
5723 Lisp_Object width
= Qnil
;
5724 Lisp_Object charset_list
= Qnil
;
5725 char *charset
= NULL
;
5727 /* Truetype fonts do not report their true metrics until loaded */
5728 if (FontType
!= RASTER_FONTTYPE
)
5730 if (!NILP (lpef
->pattern
))
5732 /* Scalable fonts are as big as you want them to be. */
5733 lplf
->elfLogFont
.lfHeight
= lpef
->logfont
.lfHeight
;
5734 lplf
->elfLogFont
.lfWidth
= lpef
->logfont
.lfWidth
;
5735 width
= make_number (lpef
->logfont
.lfWidth
);
5739 lplf
->elfLogFont
.lfHeight
= 0;
5740 lplf
->elfLogFont
.lfWidth
= 0;
5744 /* Make sure the height used here is the same as everywhere
5745 else (ie character height, not cell height). */
5746 if (lplf
->elfLogFont
.lfHeight
> 0)
5748 /* lptm can be trusted for RASTER fonts, but not scalable ones. */
5749 if (FontType
== RASTER_FONTTYPE
)
5750 lplf
->elfLogFont
.lfHeight
= lptm
->tmInternalLeading
- lptm
->tmHeight
;
5752 lplf
->elfLogFont
.lfHeight
= -lplf
->elfLogFont
.lfHeight
;
5755 if (!NILP (lpef
->pattern
))
5757 charset
= xlfd_charset_of_font (SDATA (lpef
->pattern
));
5759 /* We already checked charsets above, but DEFAULT_CHARSET
5760 slipped through. So only allow exact matches for DEFAULT_CHARSET. */
5762 && strncmp (charset
, "*-*", 3) != 0
5763 && lpef
->logfont
.lfCharSet
== DEFAULT_CHARSET
5764 && strcmp (charset
, w32_to_x_charset (DEFAULT_CHARSET
)) != 0)
5769 charset_list
= Fcons (build_string (charset
), Qnil
);
5771 charset_list
= w32_to_all_x_charsets (lplf
->elfLogFont
.lfCharSet
);
5773 /* Loop through the charsets. */
5774 for ( ; CONSP (charset_list
); charset_list
= Fcdr (charset_list
))
5776 Lisp_Object this_charset
= Fcar (charset_list
);
5777 charset
= SDATA (this_charset
);
5779 /* List bold and italic variations if w32-enable-synthesized-fonts
5780 is non-nil and this is a plain font. */
5781 if (w32_enable_synthesized_fonts
5782 && lplf
->elfLogFont
.lfWeight
== FW_NORMAL
5783 && lplf
->elfLogFont
.lfItalic
== FALSE
)
5785 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5788 lplf
->elfLogFont
.lfWeight
= FW_BOLD
;
5789 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5792 lplf
->elfLogFont
.lfItalic
= TRUE
;
5793 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5796 lplf
->elfLogFont
.lfWeight
= FW_NORMAL
;
5797 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5801 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
5810 enum_font_maybe_add_to_list (lpef
, logfont
, match_charset
, width
)
5813 char * match_charset
;
5818 if (!w32_to_x_font (logfont
, buf
, 100, match_charset
))
5821 if (NILP (lpef
->pattern
)
5822 || w32_font_match (buf
, SDATA (lpef
->pattern
)))
5824 /* Check if we already listed this font. This may happen if
5825 w32_enable_synthesized_fonts is non-nil, and there are real
5826 bold and italic versions of the font. */
5827 Lisp_Object font_name
= build_string (buf
);
5828 if (NILP (Fmember (font_name
, lpef
->list
)))
5830 Lisp_Object entry
= Fcons (font_name
, width
);
5831 lpef
->list
= Fcons (entry
, lpef
->list
);
5839 enum_font_cb1 (lplf
, lptm
, FontType
, lpef
)
5841 NEWTEXTMETRIC
* lptm
;
5845 return EnumFontFamilies (lpef
->hdc
,
5846 lplf
->elfLogFont
.lfFaceName
,
5847 (FONTENUMPROC
) enum_font_cb2
,
5853 enum_fontex_cb2 (lplf
, lptm
, font_type
, lpef
)
5854 ENUMLOGFONTEX
* lplf
;
5855 NEWTEXTMETRICEX
* lptm
;
5859 /* We are not interested in the extra info we get back from the 'Ex
5860 version - only the fact that we get character set variations
5861 enumerated seperately. */
5862 return enum_font_cb2 ((ENUMLOGFONT
*) lplf
, (NEWTEXTMETRIC
*) lptm
,
5867 enum_fontex_cb1 (lplf
, lptm
, font_type
, lpef
)
5868 ENUMLOGFONTEX
* lplf
;
5869 NEWTEXTMETRICEX
* lptm
;
5873 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
5874 FARPROC enum_font_families_ex
5875 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
5876 /* We don't really expect EnumFontFamiliesEx to disappear once we
5877 get here, so don't bother handling it gracefully. */
5878 if (enum_font_families_ex
== NULL
)
5879 error ("gdi32.dll has disappeared!");
5880 return enum_font_families_ex (lpef
->hdc
,
5882 (FONTENUMPROC
) enum_fontex_cb2
,
5886 /* Interface to fontset handler. (adapted from mw32font.c in Meadow
5887 and xterm.c in Emacs 20.3) */
5889 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
)
5891 char *fontname
, *ptnstr
;
5892 Lisp_Object list
, tem
, newlist
= Qnil
;
5895 list
= Vw32_bdf_filename_alist
;
5896 ptnstr
= SDATA (pattern
);
5898 for ( ; CONSP (list
); list
= XCDR (list
))
5902 fontname
= SDATA (XCAR (tem
));
5903 else if (STRINGP (tem
))
5904 fontname
= SDATA (tem
);
5908 if (w32_font_match (fontname
, ptnstr
))
5910 newlist
= Fcons (XCAR (tem
), newlist
);
5912 if (max_names
>= 0 && n_fonts
>= max_names
)
5921 /* Return a list of names of available fonts matching PATTERN on frame
5922 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
5923 to be listed. Frame F NULL means we have not yet created any
5924 frame, which means we can't get proper size info, as we don't have
5925 a device context to use for GetTextMetrics.
5926 MAXNAMES sets a limit on how many fonts to match. If MAXNAMES is
5927 negative, then all matching fonts are returned. */
5930 w32_list_fonts (f
, pattern
, size
, maxnames
)
5932 Lisp_Object pattern
;
5936 Lisp_Object patterns
, key
= Qnil
, tem
, tpat
;
5937 Lisp_Object list
= Qnil
, newlist
= Qnil
, second_best
= Qnil
;
5938 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
5941 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
5942 if (NILP (patterns
))
5943 patterns
= Fcons (pattern
, Qnil
);
5945 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
5950 tpat
= XCAR (patterns
);
5952 if (!STRINGP (tpat
))
5955 /* Avoid expensive EnumFontFamilies functions if we are not
5956 going to be able to output one of these anyway. */
5957 codepage
= w32_codepage_for_font (SDATA (tpat
));
5958 if (codepage
!= CP_8BIT
&& codepage
!= CP_UNICODE
5959 && codepage
!= CP_DEFAULT
&& codepage
!= CP_UNKNOWN
5960 && !IsValidCodePage(codepage
))
5963 /* See if we cached the result for this particular query.
5964 The cache is an alist of the form:
5965 ((PATTERN (FONTNAME . WIDTH) ...) ...)
5967 if (tem
= XCDR (dpyinfo
->name_list_element
),
5968 !NILP (list
= Fassoc (tpat
, tem
)))
5970 list
= Fcdr_safe (list
);
5971 /* We have a cached list. Don't have to get the list again. */
5976 /* At first, put PATTERN in the cache. */
5981 /* Use EnumFontFamiliesEx where it is available, as it knows
5982 about character sets. Fall back to EnumFontFamilies for
5983 older versions of NT that don't support the 'Ex function. */
5984 x_to_w32_font (SDATA (tpat
), &ef
.logfont
);
5986 LOGFONT font_match_pattern
;
5987 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
5988 FARPROC enum_font_families_ex
5989 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
5991 /* We do our own pattern matching so we can handle wildcards. */
5992 font_match_pattern
.lfFaceName
[0] = 0;
5993 font_match_pattern
.lfPitchAndFamily
= 0;
5994 /* We can use the charset, because if it is a wildcard it will
5995 be DEFAULT_CHARSET anyway. */
5996 font_match_pattern
.lfCharSet
= ef
.logfont
.lfCharSet
;
5998 ef
.hdc
= GetDC (dpyinfo
->root_window
);
6000 if (enum_font_families_ex
)
6001 enum_font_families_ex (ef
.hdc
,
6002 &font_match_pattern
,
6003 (FONTENUMPROC
) enum_fontex_cb1
,
6006 EnumFontFamilies (ef
.hdc
, NULL
, (FONTENUMPROC
) enum_font_cb1
,
6009 ReleaseDC (dpyinfo
->root_window
, ef
.hdc
);
6015 /* Make a list of the fonts we got back.
6016 Store that in the font cache for the display. */
6017 XSETCDR (dpyinfo
->name_list_element
,
6018 Fcons (Fcons (tpat
, list
),
6019 XCDR (dpyinfo
->name_list_element
)));
6022 if (NILP (list
)) continue; /* Try the remaining alternatives. */
6024 newlist
= second_best
= Qnil
;
6026 /* Make a list of the fonts that have the right width. */
6027 for (; CONSP (list
); list
= XCDR (list
))
6034 if (NILP (XCAR (tem
)))
6038 newlist
= Fcons (XCAR (tem
), newlist
);
6040 if (maxnames
>= 0 && n_fonts
>= maxnames
)
6045 if (!INTEGERP (XCDR (tem
)))
6047 /* Since we don't yet know the size of the font, we must
6048 load it and try GetTextMetrics. */
6049 W32FontStruct thisinfo
;
6054 if (!x_to_w32_font (SDATA (XCAR (tem
)), &lf
))
6058 thisinfo
.bdf
= NULL
;
6059 thisinfo
.hfont
= CreateFontIndirect (&lf
);
6060 if (thisinfo
.hfont
== NULL
)
6063 hdc
= GetDC (dpyinfo
->root_window
);
6064 oldobj
= SelectObject (hdc
, thisinfo
.hfont
);
6065 if (GetTextMetrics (hdc
, &thisinfo
.tm
))
6066 XSETCDR (tem
, make_number (FONT_WIDTH (&thisinfo
)));
6068 XSETCDR (tem
, make_number (0));
6069 SelectObject (hdc
, oldobj
);
6070 ReleaseDC (dpyinfo
->root_window
, hdc
);
6071 DeleteObject(thisinfo
.hfont
);
6074 found_size
= XINT (XCDR (tem
));
6075 if (found_size
== size
)
6077 newlist
= Fcons (XCAR (tem
), newlist
);
6079 if (maxnames
>= 0 && n_fonts
>= maxnames
)
6082 /* keep track of the closest matching size in case
6083 no exact match is found. */
6084 else if (found_size
> 0)
6086 if (NILP (second_best
))
6089 else if (found_size
< size
)
6091 if (XINT (XCDR (second_best
)) > size
6092 || XINT (XCDR (second_best
)) < found_size
)
6097 if (XINT (XCDR (second_best
)) > size
6098 && XINT (XCDR (second_best
)) >
6105 if (!NILP (newlist
))
6107 else if (!NILP (second_best
))
6109 newlist
= Fcons (XCAR (second_best
), Qnil
);
6114 /* Include any bdf fonts. */
6115 if (n_fonts
< maxnames
|| maxnames
< 0)
6117 Lisp_Object combined
[2];
6118 combined
[0] = w32_list_bdf_fonts (pattern
, maxnames
- n_fonts
);
6119 combined
[1] = newlist
;
6120 newlist
= Fnconc(2, combined
);
6127 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
6129 w32_get_font_info (f
, font_idx
)
6133 return (FRAME_W32_FONT_TABLE (f
) + font_idx
);
6138 w32_query_font (struct frame
*f
, char *fontname
)
6141 struct font_info
*pfi
;
6143 pfi
= FRAME_W32_FONT_TABLE (f
);
6145 for (i
= 0; i
< one_w32_display_info
.n_fonts
;i
++, pfi
++)
6147 if (strcmp(pfi
->name
, fontname
) == 0) return pfi
;
6153 /* Find a CCL program for a font specified by FONTP, and set the member
6154 `encoder' of the structure. */
6157 w32_find_ccl_program (fontp
)
6158 struct font_info
*fontp
;
6160 Lisp_Object list
, elt
;
6162 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
6166 && STRINGP (XCAR (elt
))
6167 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
6173 struct ccl_program
*ccl
6174 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
6176 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
6179 fontp
->font_encoder
= ccl
;
6183 /* directory-files from dired.c. */
6184 Lisp_Object Fdirectory_files
P_((Lisp_Object
, Lisp_Object
, Lisp_Object
, Lisp_Object
));
6187 /* Find BDF files in a specified directory. (use GCPRO when calling,
6188 as this calls lisp to get a directory listing). */
6190 w32_find_bdf_fonts_in_dir (Lisp_Object directory
)
6192 Lisp_Object filelist
, list
= Qnil
;
6195 if (!STRINGP(directory
))
6198 filelist
= Fdirectory_files (directory
, Qt
,
6199 build_string (".*\\.[bB][dD][fF]"), Qt
);
6201 for ( ; CONSP(filelist
); filelist
= XCDR (filelist
))
6203 Lisp_Object filename
= XCAR (filelist
);
6204 if (w32_BDF_to_x_font (SDATA (filename
), fontname
, 100))
6205 store_in_alist (&list
, build_string (fontname
), filename
);
6210 DEFUN ("w32-find-bdf-fonts", Fw32_find_bdf_fonts
, Sw32_find_bdf_fonts
,
6212 doc
: /* Return a list of BDF fonts in DIRECTORY.
6213 The list is suitable for appending to `w32-bdf-filename-alist'.
6214 Fonts which do not contain an xlfd description will not be included
6215 in the list. DIRECTORY may be a list of directories. */)
6217 Lisp_Object directory
;
6219 Lisp_Object list
= Qnil
;
6220 struct gcpro gcpro1
, gcpro2
;
6222 if (!CONSP (directory
))
6223 return w32_find_bdf_fonts_in_dir (directory
);
6225 for ( ; CONSP (directory
); directory
= XCDR (directory
))
6227 Lisp_Object pair
[2];
6230 GCPRO2 (directory
, list
);
6231 pair
[1] = w32_find_bdf_fonts_in_dir( XCAR (directory
) );
6232 list
= Fnconc( 2, pair
);
6239 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
6240 doc
: /* Internal function called by `color-defined-p', which see. */)
6242 Lisp_Object color
, frame
;
6245 FRAME_PTR f
= check_x_frame (frame
);
6247 CHECK_STRING (color
);
6249 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
6255 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
6256 doc
: /* Internal function called by `color-values', which see. */)
6258 Lisp_Object color
, frame
;
6261 FRAME_PTR f
= check_x_frame (frame
);
6263 CHECK_STRING (color
);
6265 if (w32_defined_color (f
, SDATA (color
), &foo
, 0))
6269 rgb
[0] = make_number ((GetRValue (foo
.pixel
) << 8)
6270 | GetRValue (foo
.pixel
));
6271 rgb
[1] = make_number ((GetGValue (foo
.pixel
) << 8)
6272 | GetGValue (foo
.pixel
));
6273 rgb
[2] = make_number ((GetBValue (foo
.pixel
) << 8)
6274 | GetBValue (foo
.pixel
));
6275 return Flist (3, rgb
);
6281 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
6282 doc
: /* Internal function called by `display-color-p', which see. */)
6284 Lisp_Object display
;
6286 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6288 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
6294 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
,
6295 Sx_display_grayscale_p
, 0, 1, 0,
6296 doc
: /* Return t if DISPLAY supports shades of gray.
6297 Note that color displays do support shades of gray.
6298 The optional argument DISPLAY specifies which display to ask about.
6299 DISPLAY should be either a frame or a display name (a string).
6300 If omitted or nil, that stands for the selected frame's display. */)
6302 Lisp_Object display
;
6304 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6306 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
6312 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
,
6313 Sx_display_pixel_width
, 0, 1, 0,
6314 doc
: /* Returns the width in pixels of DISPLAY.
6315 The optional argument DISPLAY specifies which display to ask about.
6316 DISPLAY should be either a frame or a display name (a string).
6317 If omitted or nil, that stands for the selected frame's display. */)
6319 Lisp_Object display
;
6321 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6323 return make_number (dpyinfo
->width
);
6326 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
6327 Sx_display_pixel_height
, 0, 1, 0,
6328 doc
: /* Returns the height in pixels of DISPLAY.
6329 The optional argument DISPLAY specifies which display to ask about.
6330 DISPLAY should be either a frame or a display name (a string).
6331 If omitted or nil, that stands for the selected frame's display. */)
6333 Lisp_Object display
;
6335 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6337 return make_number (dpyinfo
->height
);
6340 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
6342 doc
: /* Returns the number of bitplanes of DISPLAY.
6343 The optional argument DISPLAY specifies which display to ask about.
6344 DISPLAY should be either a frame or a display name (a string).
6345 If omitted or nil, that stands for the selected frame's display. */)
6347 Lisp_Object display
;
6349 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6351 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
6354 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
6356 doc
: /* Returns the number of color cells of DISPLAY.
6357 The optional argument DISPLAY specifies which display to ask about.
6358 DISPLAY should be either a frame or a display name (a string).
6359 If omitted or nil, that stands for the selected frame's display. */)
6361 Lisp_Object display
;
6363 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6367 hdc
= GetDC (dpyinfo
->root_window
);
6368 if (dpyinfo
->has_palette
)
6369 cap
= GetDeviceCaps (hdc
, SIZEPALETTE
);
6371 cap
= GetDeviceCaps (hdc
, NUMCOLORS
);
6373 /* We force 24+ bit depths to 24-bit, both to prevent an overflow
6374 and because probably is more meaningful on Windows anyway */
6376 cap
= 1 << min(dpyinfo
->n_planes
* dpyinfo
->n_cbits
, 24);
6378 ReleaseDC (dpyinfo
->root_window
, hdc
);
6380 return make_number (cap
);
6383 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
6384 Sx_server_max_request_size
,
6386 doc
: /* Returns the maximum request size of the server of DISPLAY.
6387 The optional argument DISPLAY specifies which display to ask about.
6388 DISPLAY should be either a frame or a display name (a string).
6389 If omitted or nil, that stands for the selected frame's display. */)
6391 Lisp_Object display
;
6393 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6395 return make_number (1);
6398 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
6399 doc
: /* Returns the "vendor ID" string of the W32 system (Microsoft).
6400 The optional argument DISPLAY specifies which display to ask about.
6401 DISPLAY should be either a frame or a display name (a string).
6402 If omitted or nil, that stands for the selected frame's display. */)
6404 Lisp_Object display
;
6406 return build_string ("Microsoft Corp.");
6409 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
6410 doc
: /* Returns the version numbers of the server of DISPLAY.
6411 The value is a list of three integers: the major and minor
6412 version numbers of the X Protocol in use, and the distributor-specific release
6413 number. See also the function `x-server-vendor'.
6415 The optional argument DISPLAY specifies which display to ask about.
6416 DISPLAY should be either a frame or a display name (a string).
6417 If omitted or nil, that stands for the selected frame's display. */)
6419 Lisp_Object display
;
6421 return Fcons (make_number (w32_major_version
),
6422 Fcons (make_number (w32_minor_version
),
6423 Fcons (make_number (w32_build_number
), Qnil
)));
6426 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
6427 doc
: /* Returns the number of screens on the server of DISPLAY.
6428 The optional argument DISPLAY specifies which display to ask about.
6429 DISPLAY should be either a frame or a display name (a string).
6430 If omitted or nil, that stands for the selected frame's display. */)
6432 Lisp_Object display
;
6434 return make_number (1);
6437 DEFUN ("x-display-mm-height", Fx_display_mm_height
,
6438 Sx_display_mm_height
, 0, 1, 0,
6439 doc
: /* Returns the height in millimeters of DISPLAY.
6440 The optional argument DISPLAY specifies which display to ask about.
6441 DISPLAY should be either a frame or a display name (a string).
6442 If omitted or nil, that stands for the selected frame's display. */)
6444 Lisp_Object display
;
6446 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6450 hdc
= GetDC (dpyinfo
->root_window
);
6452 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
6454 ReleaseDC (dpyinfo
->root_window
, hdc
);
6456 return make_number (cap
);
6459 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
6460 doc
: /* Returns the width in millimeters of DISPLAY.
6461 The optional argument DISPLAY specifies which display to ask about.
6462 DISPLAY should be either a frame or a display name (a string).
6463 If omitted or nil, that stands for the selected frame's display. */)
6465 Lisp_Object display
;
6467 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6472 hdc
= GetDC (dpyinfo
->root_window
);
6474 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
6476 ReleaseDC (dpyinfo
->root_window
, hdc
);
6478 return make_number (cap
);
6481 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
6482 Sx_display_backing_store
, 0, 1, 0,
6483 doc
: /* Returns an indication of whether DISPLAY does backing store.
6484 The value may be `always', `when-mapped', or `not-useful'.
6485 The optional argument DISPLAY specifies which display to ask about.
6486 DISPLAY should be either a frame or a display name (a string).
6487 If omitted or nil, that stands for the selected frame's display. */)
6489 Lisp_Object display
;
6491 return intern ("not-useful");
6494 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
6495 Sx_display_visual_class
, 0, 1, 0,
6496 doc
: /* Returns the visual class of DISPLAY.
6497 The value is one of the symbols `static-gray', `gray-scale',
6498 `static-color', `pseudo-color', `true-color', or `direct-color'.
6500 The optional argument DISPLAY specifies which display to ask about.
6501 DISPLAY should be either a frame or a display name (a string).
6502 If omitted or nil, that stands for the selected frame's display. */)
6504 Lisp_Object display
;
6506 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6507 Lisp_Object result
= Qnil
;
6509 if (dpyinfo
->has_palette
)
6510 result
= intern ("pseudo-color");
6511 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
6512 result
= intern ("static-grey");
6513 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
6514 result
= intern ("static-color");
6515 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
6516 result
= intern ("true-color");
6521 DEFUN ("x-display-save-under", Fx_display_save_under
,
6522 Sx_display_save_under
, 0, 1, 0,
6523 doc
: /* Returns t if DISPLAY supports the save-under feature.
6524 The optional argument DISPLAY specifies which display to ask about.
6525 DISPLAY should be either a frame or a display name (a string).
6526 If omitted or nil, that stands for the selected frame's display. */)
6528 Lisp_Object display
;
6535 register struct frame
*f
;
6537 return FRAME_PIXEL_WIDTH (f
);
6542 register struct frame
*f
;
6544 return FRAME_PIXEL_HEIGHT (f
);
6549 register struct frame
*f
;
6551 return FRAME_COLUMN_WIDTH (f
);
6556 register struct frame
*f
;
6558 return FRAME_LINE_HEIGHT (f
);
6563 register struct frame
*f
;
6565 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
6568 /* Return the display structure for the display named NAME.
6569 Open a new connection if necessary. */
6571 struct w32_display_info
*
6572 x_display_info_for_name (name
)
6576 struct w32_display_info
*dpyinfo
;
6578 CHECK_STRING (name
);
6580 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
6582 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
6585 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
6590 /* Use this general default value to start with. */
6591 Vx_resource_name
= Vinvocation_name
;
6593 validate_x_resource_name ();
6595 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
6596 (char *) SDATA (Vx_resource_name
));
6599 error ("Cannot connect to server %s", SDATA (name
));
6602 XSETFASTINT (Vwindow_system_version
, 3);
6607 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
6608 1, 3, 0, doc
: /* Open a connection to a server.
6609 DISPLAY is the name of the display to connect to.
6610 Optional second arg XRM-STRING is a string of resources in xrdb format.
6611 If the optional third arg MUST-SUCCEED is non-nil,
6612 terminate Emacs if we can't open the connection. */)
6613 (display
, xrm_string
, must_succeed
)
6614 Lisp_Object display
, xrm_string
, must_succeed
;
6616 unsigned char *xrm_option
;
6617 struct w32_display_info
*dpyinfo
;
6619 /* If initialization has already been done, return now to avoid
6620 overwriting critical parts of one_w32_display_info. */
6624 CHECK_STRING (display
);
6625 if (! NILP (xrm_string
))
6626 CHECK_STRING (xrm_string
);
6628 if (! EQ (Vwindow_system
, intern ("w32")))
6629 error ("Not using Microsoft Windows");
6631 /* Allow color mapping to be defined externally; first look in user's
6632 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
6634 Lisp_Object color_file
;
6635 struct gcpro gcpro1
;
6637 color_file
= build_string("~/rgb.txt");
6639 GCPRO1 (color_file
);
6641 if (NILP (Ffile_readable_p (color_file
)))
6643 Fexpand_file_name (build_string ("rgb.txt"),
6644 Fsymbol_value (intern ("data-directory")));
6646 Vw32_color_map
= Fw32_load_color_file (color_file
);
6650 if (NILP (Vw32_color_map
))
6651 Vw32_color_map
= Fw32_default_color_map ();
6653 /* Merge in system logical colors. */
6654 add_system_logical_colors_to_map (&Vw32_color_map
);
6656 if (! NILP (xrm_string
))
6657 xrm_option
= (unsigned char *) SDATA (xrm_string
);
6659 xrm_option
= (unsigned char *) 0;
6661 /* Use this general default value to start with. */
6662 /* First remove .exe suffix from invocation-name - it looks ugly. */
6664 char basename
[ MAX_PATH
], *str
;
6666 strcpy (basename
, SDATA (Vinvocation_name
));
6667 str
= strrchr (basename
, '.');
6669 Vinvocation_name
= build_string (basename
);
6671 Vx_resource_name
= Vinvocation_name
;
6673 validate_x_resource_name ();
6675 /* This is what opens the connection and sets x_current_display.
6676 This also initializes many symbols, such as those used for input. */
6677 dpyinfo
= w32_term_init (display
, xrm_option
,
6678 (char *) SDATA (Vx_resource_name
));
6682 if (!NILP (must_succeed
))
6683 fatal ("Cannot connect to server %s.\n",
6686 error ("Cannot connect to server %s", SDATA (display
));
6691 XSETFASTINT (Vwindow_system_version
, 3);
6695 DEFUN ("x-close-connection", Fx_close_connection
,
6696 Sx_close_connection
, 1, 1, 0,
6697 doc
: /* Close the connection to DISPLAY's server.
6698 For DISPLAY, specify either a frame or a display name (a string).
6699 If DISPLAY is nil, that stands for the selected frame's display. */)
6701 Lisp_Object display
;
6703 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6706 if (dpyinfo
->reference_count
> 0)
6707 error ("Display still has frames on it");
6710 /* Free the fonts in the font table. */
6711 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
6712 if (dpyinfo
->font_table
[i
].name
)
6714 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
6715 xfree (dpyinfo
->font_table
[i
].full_name
);
6716 xfree (dpyinfo
->font_table
[i
].name
);
6717 w32_unload_font (dpyinfo
, dpyinfo
->font_table
[i
].font
);
6719 x_destroy_all_bitmaps (dpyinfo
);
6721 x_delete_display (dpyinfo
);
6727 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
6728 doc
: /* Return the list of display names that Emacs has connections to. */)
6731 Lisp_Object tail
, result
;
6734 for (tail
= w32_display_name_list
; ! NILP (tail
); tail
= XCDR (tail
))
6735 result
= Fcons (XCAR (XCAR (tail
)), result
);
6740 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
6741 doc
: /* This is a noop on W32 systems. */)
6743 Lisp_Object display
, on
;
6750 /***********************************************************************
6752 ***********************************************************************/
6754 DEFUN ("x-change-window-property", Fx_change_window_property
,
6755 Sx_change_window_property
, 2, 6, 0,
6756 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
6757 VALUE may be a string or a list of conses, numbers and/or strings.
6758 If an element in the list is a string, it is converted to
6759 an Atom and the value of the Atom is used. If an element is a cons,
6760 it is converted to a 32 bit number where the car is the 16 top bits and the
6761 cdr is the lower 16 bits.
6762 FRAME nil or omitted means use the selected frame.
6763 If TYPE is given and non-nil, it is the name of the type of VALUE.
6764 If TYPE is not given or nil, the type is STRING.
6765 FORMAT gives the size in bits of each element if VALUE is a list.
6766 It must be one of 8, 16 or 32.
6767 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
6768 If OUTER_P is non-nil, the property is changed for the outer X window of
6769 FRAME. Default is to change on the edit X window.
6772 (prop
, value
, frame
, type
, format
, outer_p
)
6773 Lisp_Object prop
, value
, frame
, type
, format
, outer_p
;
6775 #if 0 /* TODO : port window properties to W32 */
6776 struct frame
*f
= check_x_frame (frame
);
6779 CHECK_STRING (prop
);
6780 CHECK_STRING (value
);
6783 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
6784 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
6785 prop_atom
, XA_STRING
, 8, PropModeReplace
,
6786 SDATA (value
), SCHARS (value
));
6788 /* Make sure the property is set when we return. */
6789 XFlush (FRAME_W32_DISPLAY (f
));
6798 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
6799 Sx_delete_window_property
, 1, 2, 0,
6800 doc
: /* Remove window property PROP from X window of FRAME.
6801 FRAME nil or omitted means use the selected frame. Value is PROP. */)
6803 Lisp_Object prop
, frame
;
6805 #if 0 /* TODO : port window properties to W32 */
6807 struct frame
*f
= check_x_frame (frame
);
6810 CHECK_STRING (prop
);
6812 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
6813 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
6815 /* Make sure the property is removed when we return. */
6816 XFlush (FRAME_W32_DISPLAY (f
));
6824 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
6826 doc
: /* Value is the value of window property PROP on FRAME.
6827 If FRAME is nil or omitted, use the selected frame. Value is nil
6828 if FRAME hasn't a property with name PROP or if PROP has no string
6831 Lisp_Object prop
, frame
;
6833 #if 0 /* TODO : port window properties to W32 */
6835 struct frame
*f
= check_x_frame (frame
);
6838 Lisp_Object prop_value
= Qnil
;
6839 char *tmp_data
= NULL
;
6842 unsigned long actual_size
, bytes_remaining
;
6844 CHECK_STRING (prop
);
6846 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
6847 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
6848 prop_atom
, 0, 0, False
, XA_STRING
,
6849 &actual_type
, &actual_format
, &actual_size
,
6850 &bytes_remaining
, (unsigned char **) &tmp_data
);
6853 int size
= bytes_remaining
;
6858 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
6859 prop_atom
, 0, bytes_remaining
,
6861 &actual_type
, &actual_format
,
6862 &actual_size
, &bytes_remaining
,
6863 (unsigned char **) &tmp_data
);
6865 prop_value
= make_string (tmp_data
, size
);
6880 /***********************************************************************
6882 ***********************************************************************/
6884 /* If non-null, an asynchronous timer that, when it expires, displays
6885 an hourglass cursor on all frames. */
6887 static struct atimer
*hourglass_atimer
;
6889 /* Non-zero means an hourglass cursor is currently shown. */
6891 static int hourglass_shown_p
;
6893 /* Number of seconds to wait before displaying an hourglass cursor. */
6895 static Lisp_Object Vhourglass_delay
;
6897 /* Default number of seconds to wait before displaying an hourglass
6900 #define DEFAULT_HOURGLASS_DELAY 1
6902 /* Function prototypes. */
6904 static void show_hourglass
P_ ((struct atimer
*));
6905 static void hide_hourglass
P_ ((void));
6908 /* Cancel a currently active hourglass timer, and start a new one. */
6913 #if 0 /* TODO: cursor shape changes. */
6915 int secs
, usecs
= 0;
6917 cancel_hourglass ();
6919 if (INTEGERP (Vhourglass_delay
)
6920 && XINT (Vhourglass_delay
) > 0)
6921 secs
= XFASTINT (Vhourglass_delay
);
6922 else if (FLOATP (Vhourglass_delay
)
6923 && XFLOAT_DATA (Vhourglass_delay
) > 0)
6926 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
6927 secs
= XFASTINT (tem
);
6928 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
6931 secs
= DEFAULT_HOURGLASS_DELAY
;
6933 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
6934 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
6935 show_hourglass
, NULL
);
6940 /* Cancel the hourglass cursor timer if active, hide an hourglass
6946 if (hourglass_atimer
)
6948 cancel_atimer (hourglass_atimer
);
6949 hourglass_atimer
= NULL
;
6952 if (hourglass_shown_p
)
6957 /* Timer function of hourglass_atimer. TIMER is equal to
6960 Display an hourglass cursor on all frames by mapping the frames'
6961 hourglass_window. Set the hourglass_p flag in the frames'
6962 output_data.x structure to indicate that an hourglass cursor is
6963 shown on the frames. */
6966 show_hourglass (timer
)
6967 struct atimer
*timer
;
6969 #if 0 /* TODO: cursor shape changes. */
6970 /* The timer implementation will cancel this timer automatically
6971 after this function has run. Set hourglass_atimer to null
6972 so that we know the timer doesn't have to be canceled. */
6973 hourglass_atimer
= NULL
;
6975 if (!hourglass_shown_p
)
6977 Lisp_Object rest
, frame
;
6981 FOR_EACH_FRAME (rest
, frame
)
6982 if (FRAME_W32_P (XFRAME (frame
)))
6984 struct frame
*f
= XFRAME (frame
);
6986 f
->output_data
.w32
->hourglass_p
= 1;
6988 if (!f
->output_data
.w32
->hourglass_window
)
6990 unsigned long mask
= CWCursor
;
6991 XSetWindowAttributes attrs
;
6993 attrs
.cursor
= f
->output_data
.w32
->hourglass_cursor
;
6995 f
->output_data
.w32
->hourglass_window
6996 = XCreateWindow (FRAME_X_DISPLAY (f
),
6997 FRAME_OUTER_WINDOW (f
),
6998 0, 0, 32000, 32000, 0, 0,
7004 XMapRaised (FRAME_X_DISPLAY (f
),
7005 f
->output_data
.w32
->hourglass_window
);
7006 XFlush (FRAME_X_DISPLAY (f
));
7009 hourglass_shown_p
= 1;
7016 /* Hide the hourglass cursor on all frames, if it is currently shown. */
7021 #if 0 /* TODO: cursor shape changes. */
7022 if (hourglass_shown_p
)
7024 Lisp_Object rest
, frame
;
7027 FOR_EACH_FRAME (rest
, frame
)
7029 struct frame
*f
= XFRAME (frame
);
7032 /* Watch out for newly created frames. */
7033 && f
->output_data
.x
->hourglass_window
)
7035 XUnmapWindow (FRAME_X_DISPLAY (f
),
7036 f
->output_data
.x
->hourglass_window
);
7037 /* Sync here because XTread_socket looks at the
7038 hourglass_p flag that is reset to zero below. */
7039 XSync (FRAME_X_DISPLAY (f
), False
);
7040 f
->output_data
.x
->hourglass_p
= 0;
7044 hourglass_shown_p
= 0;
7052 /***********************************************************************
7054 ***********************************************************************/
7056 static Lisp_Object x_create_tip_frame
P_ ((struct w32_display_info
*,
7057 Lisp_Object
, Lisp_Object
));
7058 static void compute_tip_xy
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
7059 Lisp_Object
, int, int, int *, int *));
7061 /* The frame of a currently visible tooltip. */
7063 Lisp_Object tip_frame
;
7065 /* If non-nil, a timer started that hides the last tooltip when it
7068 Lisp_Object tip_timer
;
7071 /* If non-nil, a vector of 3 elements containing the last args
7072 with which x-show-tip was called. See there. */
7074 Lisp_Object last_show_tip_args
;
7076 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
7078 Lisp_Object Vx_max_tooltip_size
;
7082 unwind_create_tip_frame (frame
)
7085 Lisp_Object deleted
;
7087 deleted
= unwind_create_frame (frame
);
7088 if (EQ (deleted
, Qt
))
7098 /* Create a frame for a tooltip on the display described by DPYINFO.
7099 PARMS is a list of frame parameters. TEXT is the string to
7100 display in the tip frame. Value is the frame.
7102 Note that functions called here, esp. x_default_parameter can
7103 signal errors, for instance when a specified color name is
7104 undefined. We have to make sure that we're in a consistent state
7105 when this happens. */
7108 x_create_tip_frame (dpyinfo
, parms
, text
)
7109 struct w32_display_info
*dpyinfo
;
7110 Lisp_Object parms
, text
;
7113 Lisp_Object frame
, tem
;
7115 long window_prompting
= 0;
7117 int count
= SPECPDL_INDEX ();
7118 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7120 int face_change_count_before
= face_change_count
;
7122 struct buffer
*old_buffer
;
7126 /* Use this general default value to start with until we know if
7127 this frame has a specified name. */
7128 Vx_resource_name
= Vinvocation_name
;
7131 kb
= dpyinfo
->kboard
;
7133 kb
= &the_only_kboard
;
7136 /* Get the name of the frame to use for resource lookup. */
7137 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
7139 && !EQ (name
, Qunbound
)
7141 error ("Invalid frame name--not a string or nil");
7142 Vx_resource_name
= name
;
7145 GCPRO3 (parms
, name
, frame
);
7146 /* Make a frame without minibuffer nor mode-line. */
7148 f
->wants_modeline
= 0;
7149 XSETFRAME (frame
, f
);
7151 buffer
= Fget_buffer_create (build_string (" *tip*"));
7152 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, Qnil
);
7153 old_buffer
= current_buffer
;
7154 set_buffer_internal_1 (XBUFFER (buffer
));
7155 current_buffer
->truncate_lines
= Qnil
;
7156 specbind (Qinhibit_read_only
, Qt
);
7157 specbind (Qinhibit_modification_hooks
, Qt
);
7160 set_buffer_internal_1 (old_buffer
);
7162 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
7163 record_unwind_protect (unwind_create_tip_frame
, frame
);
7165 /* By setting the output method, we're essentially saying that
7166 the frame is live, as per FRAME_LIVE_P. If we get a signal
7167 from this point on, x_destroy_window might screw up reference
7169 f
->output_method
= output_w32
;
7170 f
->output_data
.w32
=
7171 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
7172 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
7174 FRAME_FONTSET (f
) = -1;
7175 f
->icon_name
= Qnil
;
7177 #if 0 /* GLYPH_DEBUG TODO: image support. */
7178 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
7179 dpyinfo_refcount
= dpyinfo
->reference_count
;
7180 #endif /* GLYPH_DEBUG */
7182 FRAME_KBOARD (f
) = kb
;
7184 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
7185 f
->output_data
.w32
->explicit_parent
= 0;
7187 /* Set the name; the functions to which we pass f expect the name to
7189 if (EQ (name
, Qunbound
) || NILP (name
))
7191 f
->name
= build_string (dpyinfo
->w32_id_name
);
7192 f
->explicit_name
= 0;
7197 f
->explicit_name
= 1;
7198 /* use the frame's title when getting resources for this frame. */
7199 specbind (Qx_resource_name
, name
);
7202 /* Extract the window parameters from the supplied values
7203 that are needed to determine window geometry. */
7207 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
7210 /* First, try whatever font the caller has specified. */
7213 tem
= Fquery_fontset (font
, Qnil
);
7215 font
= x_new_fontset (f
, SDATA (tem
));
7217 font
= x_new_font (f
, SDATA (font
));
7220 /* Try out a font which we hope has bold and italic variations. */
7221 if (!STRINGP (font
))
7222 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
7223 if (! STRINGP (font
))
7224 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
7225 /* If those didn't work, look for something which will at least work. */
7226 if (! STRINGP (font
))
7227 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
7229 if (! STRINGP (font
))
7230 font
= build_string ("Fixedsys");
7232 x_default_parameter (f
, parms
, Qfont
, font
,
7233 "font", "Font", RES_TYPE_STRING
);
7236 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
7237 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
7238 /* This defaults to 2 in order to match xterm. We recognize either
7239 internalBorderWidth or internalBorder (which is what xterm calls
7241 if (NILP (Fassq (Qinternal_border_width
, parms
)))
7245 value
= w32_get_arg (parms
, Qinternal_border_width
,
7246 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
7247 if (! EQ (value
, Qunbound
))
7248 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
7251 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
7252 "internalBorderWidth", "internalBorderWidth",
7255 /* Also do the stuff which must be set before the window exists. */
7256 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
7257 "foreground", "Foreground", RES_TYPE_STRING
);
7258 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
7259 "background", "Background", RES_TYPE_STRING
);
7260 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
7261 "pointerColor", "Foreground", RES_TYPE_STRING
);
7262 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
7263 "cursorColor", "Foreground", RES_TYPE_STRING
);
7264 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
7265 "borderColor", "BorderColor", RES_TYPE_STRING
);
7267 /* Init faces before x_default_parameter is called for scroll-bar
7268 parameters because that function calls x_set_scroll_bar_width,
7269 which calls change_frame_size, which calls Fset_window_buffer,
7270 which runs hooks, which call Fvertical_motion. At the end, we
7271 end up in init_iterator with a null face cache, which should not
7273 init_frame_faces (f
);
7275 f
->output_data
.w32
->dwStyle
= WS_BORDER
| WS_POPUP
| WS_DISABLED
;
7276 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
7278 window_prompting
= x_figure_window_size (f
, parms
, 0);
7280 /* No fringes on tip frame. */
7282 f
->left_fringe_width
= 0;
7283 f
->right_fringe_width
= 0;
7286 my_create_tip_window (f
);
7291 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
7292 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
7293 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
7294 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
7295 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
7296 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
7298 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
7299 Change will not be effected unless different from the current
7301 width
= FRAME_COLS (f
);
7302 height
= FRAME_LINES (f
);
7303 FRAME_LINES (f
) = 0;
7304 SET_FRAME_COLS (f
, 0);
7305 change_frame_size (f
, height
, width
, 1, 0, 0);
7307 /* Add `tooltip' frame parameter's default value. */
7308 if (NILP (Fframe_parameter (frame
, intern ("tooltip"))))
7309 Fmodify_frame_parameters (frame
, Fcons (Fcons (intern ("tooltip"), Qt
),
7312 /* Set up faces after all frame parameters are known. This call
7313 also merges in face attributes specified for new frames.
7315 Frame parameters may be changed if .Xdefaults contains
7316 specifications for the default font. For example, if there is an
7317 `Emacs.default.attributeBackground: pink', the `background-color'
7318 attribute of the frame get's set, which let's the internal border
7319 of the tooltip frame appear in pink. Prevent this. */
7321 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
7323 /* Set tip_frame here, so that */
7325 call1 (Qface_set_after_frame_default
, frame
);
7327 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
7328 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qbackground_color
, bg
),
7336 /* It is now ok to make the frame official even if we get an error
7337 below. And the frame needs to be on Vframe_list or making it
7338 visible won't work. */
7339 Vframe_list
= Fcons (frame
, Vframe_list
);
7341 /* Now that the frame is official, it counts as a reference to
7343 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
7345 /* Setting attributes of faces of the tooltip frame from resources
7346 and similar will increment face_change_count, which leads to the
7347 clearing of all current matrices. Since this isn't necessary
7348 here, avoid it by resetting face_change_count to the value it
7349 had before we created the tip frame. */
7350 face_change_count
= face_change_count_before
;
7352 /* Discard the unwind_protect. */
7353 return unbind_to (count
, frame
);
7357 /* Compute where to display tip frame F. PARMS is the list of frame
7358 parameters for F. DX and DY are specified offsets from the current
7359 location of the mouse. WIDTH and HEIGHT are the width and height
7360 of the tooltip. Return coordinates relative to the root window of
7361 the display in *ROOT_X, and *ROOT_Y. */
7364 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, root_x
, root_y
)
7366 Lisp_Object parms
, dx
, dy
;
7368 int *root_x
, *root_y
;
7370 Lisp_Object left
, top
;
7372 /* User-specified position? */
7373 left
= Fcdr (Fassq (Qleft
, parms
));
7374 top
= Fcdr (Fassq (Qtop
, parms
));
7376 /* Move the tooltip window where the mouse pointer is. Resize and
7378 if (!INTEGERP (left
) || !INTEGERP (top
))
7390 *root_y
= XINT (top
);
7391 else if (*root_y
+ XINT (dy
) - height
< 0)
7392 *root_y
-= XINT (dy
);
7396 *root_y
+= XINT (dy
);
7399 if (INTEGERP (left
))
7400 *root_x
= XINT (left
);
7401 else if (*root_x
+ XINT (dx
) + width
<= FRAME_W32_DISPLAY_INFO (f
)->width
)
7402 /* It fits to the right of the pointer. */
7403 *root_x
+= XINT (dx
);
7404 else if (width
+ XINT (dx
) <= *root_x
)
7405 /* It fits to the left of the pointer. */
7406 *root_x
-= width
+ XINT (dx
);
7408 /* Put it left justified on the screen -- it ought to fit that way. */
7413 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
7414 doc
: /* Show STRING in a \"tooltip\" window on frame FRAME.
7415 A tooltip window is a small window displaying a string.
7417 FRAME nil or omitted means use the selected frame.
7419 PARMS is an optional list of frame parameters which can be
7420 used to change the tooltip's appearance.
7422 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
7423 means use the default timeout of 5 seconds.
7425 If the list of frame parameters PARMS contains a `left' parameter,
7426 the tooltip is displayed at that x-position. Otherwise it is
7427 displayed at the mouse position, with offset DX added (default is 5 if
7428 DX isn't specified). Likewise for the y-position; if a `top' frame
7429 parameter is specified, it determines the y-position of the tooltip
7430 window, otherwise it is displayed at the mouse position, with offset
7431 DY added (default is -10).
7433 A tooltip's maximum size is specified by `x-max-tooltip-size'.
7434 Text larger than the specified size is clipped. */)
7435 (string
, frame
, parms
, timeout
, dx
, dy
)
7436 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
7441 struct buffer
*old_buffer
;
7442 struct text_pos pos
;
7443 int i
, width
, height
;
7444 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7445 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7446 int count
= SPECPDL_INDEX ();
7448 specbind (Qinhibit_redisplay
, Qt
);
7450 GCPRO4 (string
, parms
, frame
, timeout
);
7452 CHECK_STRING (string
);
7453 f
= check_x_frame (frame
);
7455 timeout
= make_number (5);
7457 CHECK_NATNUM (timeout
);
7460 dx
= make_number (5);
7465 dy
= make_number (-10);
7469 if (NILP (last_show_tip_args
))
7470 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
7472 if (!NILP (tip_frame
))
7474 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
7475 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
7476 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
7478 if (EQ (frame
, last_frame
)
7479 && !NILP (Fequal (last_string
, string
))
7480 && !NILP (Fequal (last_parms
, parms
)))
7482 struct frame
*f
= XFRAME (tip_frame
);
7484 /* Only DX and DY have changed. */
7485 if (!NILP (tip_timer
))
7487 Lisp_Object timer
= tip_timer
;
7489 call1 (Qcancel_timer
, timer
);
7493 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
7494 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
7496 /* Put tooltip in topmost group and in position. */
7497 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
7498 root_x
, root_y
, 0, 0,
7499 SWP_NOSIZE
| SWP_NOACTIVATE
);
7501 /* Ensure tooltip is on top of other topmost windows (eg menus). */
7502 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
7504 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
7511 /* Hide a previous tip, if any. */
7514 ASET (last_show_tip_args
, 0, string
);
7515 ASET (last_show_tip_args
, 1, frame
);
7516 ASET (last_show_tip_args
, 2, parms
);
7518 /* Add default values to frame parameters. */
7519 if (NILP (Fassq (Qname
, parms
)))
7520 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
7521 if (NILP (Fassq (Qinternal_border_width
, parms
)))
7522 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
7523 if (NILP (Fassq (Qborder_width
, parms
)))
7524 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
7525 if (NILP (Fassq (Qborder_color
, parms
)))
7526 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
7527 if (NILP (Fassq (Qbackground_color
, parms
)))
7528 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
7531 /* Block input until the tip has been fully drawn, to avoid crashes
7532 when drawing tips in menus. */
7535 /* Create a frame for the tooltip, and record it in the global
7536 variable tip_frame. */
7537 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
, string
);
7540 /* Set up the frame's root window. */
7541 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7542 w
->left_col
= w
->top_line
= make_number (0);
7544 if (CONSP (Vx_max_tooltip_size
)
7545 && INTEGERP (XCAR (Vx_max_tooltip_size
))
7546 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
7547 && INTEGERP (XCDR (Vx_max_tooltip_size
))
7548 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
7550 w
->total_cols
= XCAR (Vx_max_tooltip_size
);
7551 w
->total_lines
= XCDR (Vx_max_tooltip_size
);
7555 w
->total_cols
= make_number (80);
7556 w
->total_lines
= make_number (40);
7559 FRAME_TOTAL_COLS (f
) = XINT (w
->total_cols
);
7561 w
->pseudo_window_p
= 1;
7563 /* Display the tooltip text in a temporary buffer. */
7564 old_buffer
= current_buffer
;
7565 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
7566 current_buffer
->truncate_lines
= Qnil
;
7567 clear_glyph_matrix (w
->desired_matrix
);
7568 clear_glyph_matrix (w
->current_matrix
);
7569 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
7570 try_window (FRAME_ROOT_WINDOW (f
), pos
);
7572 /* Compute width and height of the tooltip. */
7574 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
7576 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
7580 /* Stop at the first empty row at the end. */
7581 if (!row
->enabled_p
|| !row
->displays_text_p
)
7584 /* Let the row go over the full width of the frame. */
7585 row
->full_width_p
= 1;
7587 #ifdef TODO /* Investigate why some fonts need more width than is
7588 calculated for some tooltips. */
7589 /* There's a glyph at the end of rows that is use to place
7590 the cursor there. Don't include the width of this glyph. */
7591 if (row
->used
[TEXT_AREA
])
7593 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
7594 row_width
= row
->pixel_width
- last
->pixel_width
;
7598 row_width
= row
->pixel_width
;
7600 /* TODO: find why tips do not draw along baseline as instructed. */
7601 height
+= row
->height
;
7602 width
= max (width
, row_width
);
7605 /* Add the frame's internal border to the width and height the X
7606 window should have. */
7607 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
7608 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
7610 /* Move the tooltip window where the mouse pointer is. Resize and
7612 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
7615 /* Adjust Window size to take border into account. */
7617 rect
.left
= rect
.top
= 0;
7619 rect
.bottom
= height
;
7620 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
7621 FRAME_EXTERNAL_MENU_BAR (f
));
7623 /* Position and size tooltip, and put it in the topmost group. */
7624 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
7625 root_x
, root_y
, rect
.right
- rect
.left
,
7626 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
);
7628 /* Ensure tooltip is on top of other topmost windows (eg menus). */
7629 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
7631 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
7633 /* Let redisplay know that we have made the frame visible already. */
7634 f
->async_visible
= 1;
7636 ShowWindow (FRAME_W32_WINDOW (f
), SW_SHOWNOACTIVATE
);
7639 /* Draw into the window. */
7640 w
->must_be_updated_p
= 1;
7641 update_single_window (w
, 1);
7645 /* Restore original current buffer. */
7646 set_buffer_internal_1 (old_buffer
);
7647 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7650 /* Let the tip disappear after timeout seconds. */
7651 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
7652 intern ("x-hide-tip"));
7655 return unbind_to (count
, Qnil
);
7659 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
7660 doc
: /* Hide the current tooltip window, if there is any.
7661 Value is t if tooltip was open, nil otherwise. */)
7665 Lisp_Object deleted
, frame
, timer
;
7666 struct gcpro gcpro1
, gcpro2
;
7668 /* Return quickly if nothing to do. */
7669 if (NILP (tip_timer
) && NILP (tip_frame
))
7674 GCPRO2 (frame
, timer
);
7675 tip_frame
= tip_timer
= deleted
= Qnil
;
7677 count
= SPECPDL_INDEX ();
7678 specbind (Qinhibit_redisplay
, Qt
);
7679 specbind (Qinhibit_quit
, Qt
);
7682 call1 (Qcancel_timer
, timer
);
7686 Fdelete_frame (frame
, Qnil
);
7691 return unbind_to (count
, deleted
);
7696 /***********************************************************************
7697 File selection dialog
7698 ***********************************************************************/
7699 extern Lisp_Object Qfile_name_history
;
7701 /* Callback for altering the behaviour of the Open File dialog.
7702 Makes the Filename text field contain "Current Directory" and be
7703 read-only when "Directories" is selected in the filter. This
7704 allows us to work around the fact that the standard Open File
7705 dialog does not support directories. */
7707 file_dialog_callback (hwnd
, msg
, wParam
, lParam
)
7713 if (msg
== WM_NOTIFY
)
7715 OFNOTIFY
* notify
= (OFNOTIFY
*)lParam
;
7716 /* Detect when the Filter dropdown is changed. */
7717 if (notify
->hdr
.code
== CDN_TYPECHANGE
7718 || notify
->hdr
.code
== CDN_INITDONE
)
7720 HWND dialog
= GetParent (hwnd
);
7721 HWND edit_control
= GetDlgItem (dialog
, FILE_NAME_TEXT_FIELD
);
7723 /* Directories is in index 2. */
7724 if (notify
->lpOFN
->nFilterIndex
== 2)
7726 CommDlg_OpenSave_SetControlText (dialog
, FILE_NAME_TEXT_FIELD
,
7727 "Current Directory");
7728 EnableWindow (edit_control
, FALSE
);
7732 /* Don't override default filename on init done. */
7733 if (notify
->hdr
.code
== CDN_TYPECHANGE
)
7734 CommDlg_OpenSave_SetControlText (dialog
,
7735 FILE_NAME_TEXT_FIELD
, "");
7736 EnableWindow (edit_control
, TRUE
);
7743 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
7744 doc
: /* Read file name, prompting with PROMPT in directory DIR.
7745 Use a file selection dialog.
7746 Select DEFAULT-FILENAME in the dialog's file selection box, if
7747 specified. Ensure that file exists if MUSTMATCH is non-nil.
7748 If ONLY-DIR-P is non-nil, the user can only select directories. */)
7749 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
)
7750 Lisp_Object prompt
, dir
, default_filename
, mustmatch
, only_dir_p
;
7752 struct frame
*f
= SELECTED_FRAME ();
7753 Lisp_Object file
= Qnil
;
7754 int count
= SPECPDL_INDEX ();
7755 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
7756 char filename
[MAX_PATH
+ 1];
7757 char init_dir
[MAX_PATH
+ 1];
7758 int default_filter_index
= 1; /* 1: All Files, 2: Directories only */
7760 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
7761 CHECK_STRING (prompt
);
7764 /* Create the dialog with PROMPT as title, using DIR as initial
7765 directory and using "*" as pattern. */
7766 dir
= Fexpand_file_name (dir
, Qnil
);
7767 strncpy (init_dir
, SDATA (ENCODE_FILE (dir
)), MAX_PATH
);
7768 init_dir
[MAX_PATH
] = '\0';
7769 unixtodos_filename (init_dir
);
7771 if (STRINGP (default_filename
))
7773 char *file_name_only
;
7774 char *full_path_name
= SDATA (ENCODE_FILE (default_filename
));
7776 unixtodos_filename (full_path_name
);
7778 file_name_only
= strrchr (full_path_name
, '\\');
7779 if (!file_name_only
)
7780 file_name_only
= full_path_name
;
7784 strncpy (filename
, file_name_only
, MAX_PATH
);
7785 filename
[MAX_PATH
] = '\0';
7791 OPENFILENAME file_details
;
7793 /* Prevent redisplay. */
7794 specbind (Qinhibit_redisplay
, Qt
);
7797 bzero (&file_details
, sizeof (file_details
));
7798 file_details
.lStructSize
= sizeof (file_details
);
7799 file_details
.hwndOwner
= FRAME_W32_WINDOW (f
);
7800 /* Undocumented Bug in Common File Dialog:
7801 If a filter is not specified, shell links are not resolved. */
7802 file_details
.lpstrFilter
= "All Files (*.*)\0*.*\0Directories\0*|*\0\0";
7803 file_details
.lpstrFile
= filename
;
7804 file_details
.nMaxFile
= sizeof (filename
);
7805 file_details
.lpstrInitialDir
= init_dir
;
7806 file_details
.lpstrTitle
= SDATA (prompt
);
7808 if (! NILP (only_dir_p
))
7809 default_filter_index
= 2;
7811 file_details
.nFilterIndex
= default_filter_index
;
7813 file_details
.Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
7814 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
7815 if (!NILP (mustmatch
))
7816 file_details
.Flags
|= OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
;
7818 file_details
.lpfnHook
= (LPOFNHOOKPROC
) file_dialog_callback
;
7820 if (GetOpenFileName (&file_details
))
7822 dostounix_filename (filename
);
7823 if (file_details
.nFilterIndex
== 2)
7825 /* "Directories" selected - strip dummy file name. */
7826 char * last
= strrchr (filename
, '/');
7830 file
= DECODE_FILE(build_string (filename
));
7832 /* User cancelled the dialog without making a selection. */
7833 else if (!CommDlgExtendedError ())
7835 /* An error occurred, fallback on reading from the mini-buffer. */
7837 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
7838 dir
, mustmatch
, dir
, Qfile_name_history
,
7839 default_filename
, Qnil
);
7842 file
= unbind_to (count
, file
);
7847 /* Make "Cancel" equivalent to C-g. */
7849 Fsignal (Qquit
, Qnil
);
7851 return unbind_to (count
, file
);
7856 /***********************************************************************
7857 w32 specialized functions
7858 ***********************************************************************/
7860 DEFUN ("w32-select-font", Fw32_select_font
, Sw32_select_font
, 0, 2, 0,
7861 doc
: /* Select a font using the W32 font dialog.
7862 Returns an X font string corresponding to the selection. */)
7863 (frame
, include_proportional
)
7864 Lisp_Object frame
, include_proportional
;
7866 FRAME_PTR f
= check_x_frame (frame
);
7874 bzero (&cf
, sizeof (cf
));
7875 bzero (&lf
, sizeof (lf
));
7877 cf
.lStructSize
= sizeof (cf
);
7878 cf
.hwndOwner
= FRAME_W32_WINDOW (f
);
7879 cf
.Flags
= CF_FORCEFONTEXIST
| CF_SCREENFONTS
| CF_NOVERTFONTS
;
7881 /* Unless include_proportional is non-nil, limit the selection to
7882 monospaced fonts. */
7883 if (NILP (include_proportional
))
7884 cf
.Flags
|= CF_FIXEDPITCHONLY
;
7888 /* Initialize as much of the font details as we can from the current
7890 hdc
= GetDC (FRAME_W32_WINDOW (f
));
7891 oldobj
= SelectObject (hdc
, FRAME_FONT (f
)->hfont
);
7892 GetTextFace (hdc
, LF_FACESIZE
, lf
.lfFaceName
);
7893 if (GetTextMetrics (hdc
, &tm
))
7895 lf
.lfHeight
= tm
.tmInternalLeading
- tm
.tmHeight
;
7896 lf
.lfWeight
= tm
.tmWeight
;
7897 lf
.lfItalic
= tm
.tmItalic
;
7898 lf
.lfUnderline
= tm
.tmUnderlined
;
7899 lf
.lfStrikeOut
= tm
.tmStruckOut
;
7900 lf
.lfCharSet
= tm
.tmCharSet
;
7901 cf
.Flags
|= CF_INITTOLOGFONTSTRUCT
;
7903 SelectObject (hdc
, oldobj
);
7904 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
7906 if (!ChooseFont (&cf
) || !w32_to_x_font (&lf
, buf
, 100, NULL
))
7909 return build_string (buf
);
7912 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
,
7913 Sw32_send_sys_command
, 1, 2, 0,
7914 doc
: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND.
7915 Some useful values for COMMAND are #xf030 to maximize frame (#xf020
7916 to minimize), #xf120 to restore frame to original size, and #xf100
7917 to activate the menubar for keyboard access. #xf140 activates the
7918 screen saver if defined.
7920 If optional parameter FRAME is not specified, use selected frame. */)
7922 Lisp_Object command
, frame
;
7924 FRAME_PTR f
= check_x_frame (frame
);
7926 CHECK_NUMBER (command
);
7928 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
7933 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
7934 doc
: /* Get Windows to perform OPERATION on DOCUMENT.
7935 This is a wrapper around the ShellExecute system function, which
7936 invokes the application registered to handle OPERATION for DOCUMENT.
7937 OPERATION is typically \"open\", \"print\" or \"explore\" (but can be
7938 nil for the default action), and DOCUMENT is typically the name of a
7939 document file or URL, but can also be a program executable to run or
7940 a directory to open in the Windows Explorer.
7942 If DOCUMENT is a program executable, PARAMETERS can be a string
7943 containing command line parameters, but otherwise should be nil.
7945 SHOW-FLAG can be used to control whether the invoked application is hidden
7946 or minimized. If SHOW-FLAG is nil, the application is displayed normally,
7947 otherwise it is an integer representing a ShowWindow flag:
7952 6 - start minimized */)
7953 (operation
, document
, parameters
, show_flag
)
7954 Lisp_Object operation
, document
, parameters
, show_flag
;
7956 Lisp_Object current_dir
;
7958 CHECK_STRING (document
);
7960 /* Encode filename and current directory. */
7961 current_dir
= ENCODE_FILE (current_buffer
->directory
);
7962 document
= ENCODE_FILE (document
);
7963 if ((int) ShellExecute (NULL
,
7964 (STRINGP (operation
) ?
7965 SDATA (operation
) : NULL
),
7967 (STRINGP (parameters
) ?
7968 SDATA (parameters
) : NULL
),
7969 SDATA (current_dir
),
7970 (INTEGERP (show_flag
) ?
7971 XINT (show_flag
) : SW_SHOWDEFAULT
))
7974 error ("ShellExecute failed: %s", w32_strerror (0));
7977 /* Lookup virtual keycode from string representing the name of a
7978 non-ascii keystroke into the corresponding virtual key, using
7979 lispy_function_keys. */
7981 lookup_vk_code (char *key
)
7985 for (i
= 0; i
< 256; i
++)
7986 if (lispy_function_keys
[i
] != 0
7987 && strcmp (lispy_function_keys
[i
], key
) == 0)
7993 /* Convert a one-element vector style key sequence to a hot key
7996 w32_parse_hot_key (key
)
7999 /* Copied from Fdefine_key and store_in_keymap. */
8000 register Lisp_Object c
;
8004 struct gcpro gcpro1
;
8008 if (XFASTINT (Flength (key
)) != 1)
8013 c
= Faref (key
, make_number (0));
8015 if (CONSP (c
) && lucid_event_type_list_p (c
))
8016 c
= Fevent_convert_list (c
);
8020 if (! INTEGERP (c
) && ! SYMBOLP (c
))
8021 error ("Key definition is invalid");
8023 /* Work out the base key and the modifiers. */
8026 c
= parse_modifiers (c
);
8027 lisp_modifiers
= XINT (Fcar (Fcdr (c
)));
8031 vk_code
= lookup_vk_code (SDATA (SYMBOL_NAME (c
)));
8033 else if (INTEGERP (c
))
8035 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
8036 /* Many ascii characters are their own virtual key code. */
8037 vk_code
= XINT (c
) & CHARACTERBITS
;
8040 if (vk_code
< 0 || vk_code
> 255)
8043 if ((lisp_modifiers
& meta_modifier
) != 0
8044 && !NILP (Vw32_alt_is_meta
))
8045 lisp_modifiers
|= alt_modifier
;
8047 /* Supply defs missing from mingw32. */
8049 #define MOD_ALT 0x0001
8050 #define MOD_CONTROL 0x0002
8051 #define MOD_SHIFT 0x0004
8052 #define MOD_WIN 0x0008
8055 /* Convert lisp modifiers to Windows hot-key form. */
8056 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
8057 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
8058 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
8059 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
8061 return HOTKEY (vk_code
, w32_modifiers
);
8064 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
,
8065 Sw32_register_hot_key
, 1, 1, 0,
8066 doc
: /* Register KEY as a hot-key combination.
8067 Certain key combinations like Alt-Tab are reserved for system use on
8068 Windows, and therefore are normally intercepted by the system. However,
8069 most of these key combinations can be received by registering them as
8070 hot-keys, overriding their special meaning.
8072 KEY must be a one element key definition in vector form that would be
8073 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta
8074 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper
8075 is always interpreted as the Windows modifier keys.
8077 The return value is the hotkey-id if registered, otherwise nil. */)
8081 key
= w32_parse_hot_key (key
);
8083 if (NILP (Fmemq (key
, w32_grabbed_keys
)))
8085 /* Reuse an empty slot if possible. */
8086 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
8088 /* Safe to add new key to list, even if we have focus. */
8090 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
8092 XSETCAR (item
, key
);
8094 /* Notify input thread about new hot-key definition, so that it
8095 takes effect without needing to switch focus. */
8096 #ifdef USE_LISP_UNION_TYPE
8097 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
8100 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
8108 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
,
8109 Sw32_unregister_hot_key
, 1, 1, 0,
8110 doc
: /* Unregister KEY as a hot-key combination. */)
8116 if (!INTEGERP (key
))
8117 key
= w32_parse_hot_key (key
);
8119 item
= Fmemq (key
, w32_grabbed_keys
);
8123 /* Notify input thread about hot-key definition being removed, so
8124 that it takes effect without needing focus switch. */
8125 #ifdef USE_LISP_UNION_TYPE
8126 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
8127 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
.i
))
8129 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
8130 (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.
8153 usage: (w32-reconstruct-hot-key ID) */)
8155 Lisp_Object hotkeyid
;
8157 int vk_code
, w32_modifiers
;
8160 CHECK_NUMBER (hotkeyid
);
8162 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
8163 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
8165 if (lispy_function_keys
[vk_code
])
8166 key
= intern (lispy_function_keys
[vk_code
]);
8168 key
= make_number (vk_code
);
8170 key
= Fcons (key
, Qnil
);
8171 if (w32_modifiers
& MOD_SHIFT
)
8172 key
= Fcons (Qshift
, key
);
8173 if (w32_modifiers
& MOD_CONTROL
)
8174 key
= Fcons (Qctrl
, key
);
8175 if (w32_modifiers
& MOD_ALT
)
8176 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
8177 if (w32_modifiers
& MOD_WIN
)
8178 key
= Fcons (Qhyper
, key
);
8183 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
,
8184 Sw32_toggle_lock_key
, 1, 2, 0,
8185 doc
: /* Toggle the state of the lock key KEY.
8186 KEY can be `capslock', `kp-numlock', or `scroll'.
8187 If the optional parameter NEW-STATE is a number, then the state of KEY
8188 is set to off if the low bit of NEW-STATE is zero, otherwise on. */)
8190 Lisp_Object key
, new_state
;
8194 if (EQ (key
, intern ("capslock")))
8195 vk_code
= VK_CAPITAL
;
8196 else if (EQ (key
, intern ("kp-numlock")))
8197 vk_code
= VK_NUMLOCK
;
8198 else if (EQ (key
, intern ("scroll")))
8199 vk_code
= VK_SCROLL
;
8203 if (!dwWindowsThreadId
)
8204 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
8206 #ifdef USE_LISP_UNION_TYPE
8207 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
8208 (WPARAM
) vk_code
, (LPARAM
) new_state
.i
))
8210 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
8211 (WPARAM
) vk_code
, (LPARAM
) new_state
))
8215 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
8216 return make_number (msg
.wParam
);
8221 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
8222 doc
: /* Return storage information about the file system FILENAME is on.
8223 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
8224 storage of the file system, FREE is the free storage, and AVAIL is the
8225 storage available to a non-superuser. All 3 numbers are in bytes.
8226 If the underlying system call fails, value is nil. */)
8228 Lisp_Object filename
;
8230 Lisp_Object encoded
, value
;
8232 CHECK_STRING (filename
);
8233 filename
= Fexpand_file_name (filename
, Qnil
);
8234 encoded
= ENCODE_FILE (filename
);
8238 /* Determining the required information on Windows turns out, sadly,
8239 to be more involved than one would hope. The original Win32 api
8240 call for this will return bogus information on some systems, but we
8241 must dynamically probe for the replacement api, since that was
8242 added rather late on. */
8244 HMODULE hKernel
= GetModuleHandle ("kernel32");
8245 BOOL (*pfn_GetDiskFreeSpaceEx
)
8246 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
8247 = (void *) GetProcAddress (hKernel
, "GetDiskFreeSpaceEx");
8249 /* On Windows, we may need to specify the root directory of the
8250 volume holding FILENAME. */
8251 char rootname
[MAX_PATH
];
8252 char *name
= SDATA (encoded
);
8254 /* find the root name of the volume if given */
8255 if (isalpha (name
[0]) && name
[1] == ':')
8257 rootname
[0] = name
[0];
8258 rootname
[1] = name
[1];
8262 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
8264 char *str
= rootname
;
8268 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
8278 if (pfn_GetDiskFreeSpaceEx
)
8280 /* Unsigned large integers cannot be cast to double, so
8281 use signed ones instead. */
8282 LARGE_INTEGER availbytes
;
8283 LARGE_INTEGER freebytes
;
8284 LARGE_INTEGER totalbytes
;
8286 if (pfn_GetDiskFreeSpaceEx(rootname
,
8287 (ULARGE_INTEGER
*)&availbytes
,
8288 (ULARGE_INTEGER
*)&totalbytes
,
8289 (ULARGE_INTEGER
*)&freebytes
))
8290 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
8291 make_float ((double) freebytes
.QuadPart
),
8292 make_float ((double) availbytes
.QuadPart
));
8296 DWORD sectors_per_cluster
;
8297 DWORD bytes_per_sector
;
8298 DWORD free_clusters
;
8299 DWORD total_clusters
;
8301 if (GetDiskFreeSpace(rootname
,
8302 §ors_per_cluster
,
8306 value
= list3 (make_float ((double) total_clusters
8307 * sectors_per_cluster
* bytes_per_sector
),
8308 make_float ((double) free_clusters
8309 * sectors_per_cluster
* bytes_per_sector
),
8310 make_float ((double) free_clusters
8311 * sectors_per_cluster
* bytes_per_sector
));
8318 DEFUN ("default-printer-name", Fdefault_printer_name
, Sdefault_printer_name
,
8319 0, 0, 0, doc
: /* Return the name of Windows default printer device. */)
8322 static char pname_buf
[256];
8325 PRINTER_INFO_2
*ppi2
= NULL
;
8326 DWORD dwNeeded
= 0, dwReturned
= 0;
8328 /* Retrieve the default string from Win.ini (the registry).
8329 * String will be in form "printername,drivername,portname".
8330 * This is the most portable way to get the default printer. */
8331 if (GetProfileString ("windows", "device", ",,", pname_buf
, sizeof (pname_buf
)) <= 0)
8333 /* printername precedes first "," character */
8334 strtok (pname_buf
, ",");
8335 /* We want to know more than the printer name */
8336 if (!OpenPrinter (pname_buf
, &hPrn
, NULL
))
8338 GetPrinter (hPrn
, 2, NULL
, 0, &dwNeeded
);
8341 ClosePrinter (hPrn
);
8344 /* Allocate memory for the PRINTER_INFO_2 struct */
8345 ppi2
= (PRINTER_INFO_2
*) xmalloc (dwNeeded
);
8348 ClosePrinter (hPrn
);
8351 /* Call GetPrinter() again with big enouth memory block */
8352 err
= GetPrinter (hPrn
, 2, (LPBYTE
)ppi2
, dwNeeded
, &dwReturned
);
8353 ClosePrinter (hPrn
);
8362 if (ppi2
->Attributes
& PRINTER_ATTRIBUTE_SHARED
&& ppi2
->pServerName
)
8364 /* a remote printer */
8365 if (*ppi2
->pServerName
== '\\')
8366 _snprintf(pname_buf
, sizeof (pname_buf
), "%s\\%s", ppi2
->pServerName
,
8369 _snprintf(pname_buf
, sizeof (pname_buf
), "\\\\%s\\%s", ppi2
->pServerName
,
8371 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
8375 /* a local printer */
8376 strncpy(pname_buf
, ppi2
->pPortName
, sizeof (pname_buf
));
8377 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
8378 /* `pPortName' can include several ports, delimited by ','.
8379 * we only use the first one. */
8380 strtok(pname_buf
, ",");
8385 return build_string (pname_buf
);
8388 /***********************************************************************
8390 ***********************************************************************/
8392 /* Keep this list in the same order as frame_parms in frame.c.
8393 Use 0 for unsupported frame parameters. */
8395 frame_parm_handler w32_frame_parm_handlers
[] =
8399 x_set_background_color
,
8405 x_set_foreground_color
,
8408 x_set_internal_border_width
,
8409 x_set_menu_bar_lines
,
8411 x_explicitly_set_name
,
8412 x_set_scroll_bar_width
,
8415 x_set_vertical_scroll_bars
,
8417 x_set_tool_bar_lines
,
8418 0, /* x_set_scroll_bar_foreground, */
8419 0, /* x_set_scroll_bar_background, */
8424 0, /* x_set_wait_for_wm, */
8431 globals_of_w32fns ();
8432 /* This is zero if not using MS-Windows. */
8434 track_mouse_window
= NULL
;
8436 w32_visible_system_caret_hwnd
= NULL
;
8438 Qnone
= intern ("none");
8440 Qsuppress_icon
= intern ("suppress-icon");
8441 staticpro (&Qsuppress_icon
);
8442 Qundefined_color
= intern ("undefined-color");
8443 staticpro (&Qundefined_color
);
8444 Qcancel_timer
= intern ("cancel-timer");
8445 staticpro (&Qcancel_timer
);
8447 Qhyper
= intern ("hyper");
8448 staticpro (&Qhyper
);
8449 Qsuper
= intern ("super");
8450 staticpro (&Qsuper
);
8451 Qmeta
= intern ("meta");
8453 Qalt
= intern ("alt");
8455 Qctrl
= intern ("ctrl");
8457 Qcontrol
= intern ("control");
8458 staticpro (&Qcontrol
);
8459 Qshift
= intern ("shift");
8460 staticpro (&Qshift
);
8461 /* This is the end of symbol initialization. */
8463 /* Text property `display' should be nonsticky by default. */
8464 Vtext_property_default_nonsticky
8465 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
8468 Fput (Qundefined_color
, Qerror_conditions
,
8469 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
8470 Fput (Qundefined_color
, Qerror_message
,
8471 build_string ("Undefined color"));
8473 staticpro (&w32_grabbed_keys
);
8474 w32_grabbed_keys
= Qnil
;
8476 DEFVAR_LISP ("w32-color-map", &Vw32_color_map
,
8477 doc
: /* An array of color name mappings for Windows. */);
8478 Vw32_color_map
= Qnil
;
8480 DEFVAR_LISP ("w32-pass-alt-to-system", &Vw32_pass_alt_to_system
,
8481 doc
: /* Non-nil if alt key presses are passed on to Windows.
8482 When non-nil, for example, alt pressed and released and then space will
8483 open the System menu. When nil, Emacs silently swallows alt key events. */);
8484 Vw32_pass_alt_to_system
= Qnil
;
8486 DEFVAR_LISP ("w32-alt-is-meta", &Vw32_alt_is_meta
,
8487 doc
: /* Non-nil if the alt key is to be considered the same as the meta key.
8488 When nil, Emacs will translate the alt key to the Alt modifier, and not Meta. */);
8489 Vw32_alt_is_meta
= Qt
;
8491 DEFVAR_INT ("w32-quit-key", &w32_quit_key
,
8492 doc
: /* If non-zero, the virtual key code for an alternative quit key. */);
8495 DEFVAR_LISP ("w32-pass-lwindow-to-system",
8496 &Vw32_pass_lwindow_to_system
,
8497 doc
: /* Non-nil if the left \"Windows\" key is passed on to Windows.
8498 When non-nil, the Start menu is opened by tapping the key. */);
8499 Vw32_pass_lwindow_to_system
= Qt
;
8501 DEFVAR_LISP ("w32-pass-rwindow-to-system",
8502 &Vw32_pass_rwindow_to_system
,
8503 doc
: /* Non-nil if the right \"Windows\" key is passed on to Windows.
8504 When non-nil, the Start menu is opened by tapping the key. */);
8505 Vw32_pass_rwindow_to_system
= Qt
;
8507 DEFVAR_LISP ("w32-phantom-key-code",
8508 &Vw32_phantom_key_code
,
8509 doc
: /* Virtual key code used to generate \"phantom\" key presses.
8510 Value is a number between 0 and 255.
8512 Phantom key presses are generated in order to stop the system from
8513 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or
8514 `w32-pass-rwindow-to-system' is nil. */);
8515 /* Although 255 is technically not a valid key code, it works and
8516 means that this hack won't interfere with any real key code. */
8517 XSETINT (Vw32_phantom_key_code
, 255);
8519 DEFVAR_LISP ("w32-enable-num-lock",
8520 &Vw32_enable_num_lock
,
8521 doc
: /* Non-nil if Num Lock should act normally.
8522 Set to nil to see Num Lock as the key `kp-numlock'. */);
8523 Vw32_enable_num_lock
= Qt
;
8525 DEFVAR_LISP ("w32-enable-caps-lock",
8526 &Vw32_enable_caps_lock
,
8527 doc
: /* Non-nil if Caps Lock should act normally.
8528 Set to nil to see Caps Lock as the key `capslock'. */);
8529 Vw32_enable_caps_lock
= Qt
;
8531 DEFVAR_LISP ("w32-scroll-lock-modifier",
8532 &Vw32_scroll_lock_modifier
,
8533 doc
: /* Modifier to use for the Scroll Lock on state.
8534 The value can be hyper, super, meta, alt, control or shift for the
8535 respective modifier, or nil to see Scroll Lock as the key `scroll'.
8536 Any other value will cause the key to be ignored. */);
8537 Vw32_scroll_lock_modifier
= Qt
;
8539 DEFVAR_LISP ("w32-lwindow-modifier",
8540 &Vw32_lwindow_modifier
,
8541 doc
: /* Modifier to use for the left \"Windows\" key.
8542 The value can be hyper, super, meta, alt, control or shift for the
8543 respective modifier, or nil to appear as the key `lwindow'.
8544 Any other value will cause the key to be ignored. */);
8545 Vw32_lwindow_modifier
= Qnil
;
8547 DEFVAR_LISP ("w32-rwindow-modifier",
8548 &Vw32_rwindow_modifier
,
8549 doc
: /* Modifier to use for the right \"Windows\" key.
8550 The value can be hyper, super, meta, alt, control or shift for the
8551 respective modifier, or nil to appear as the key `rwindow'.
8552 Any other value will cause the key to be ignored. */);
8553 Vw32_rwindow_modifier
= Qnil
;
8555 DEFVAR_LISP ("w32-apps-modifier",
8556 &Vw32_apps_modifier
,
8557 doc
: /* Modifier to use for the \"Apps\" key.
8558 The value can be hyper, super, meta, alt, control or shift for the
8559 respective modifier, or nil to appear as the key `apps'.
8560 Any other value will cause the key to be ignored. */);
8561 Vw32_apps_modifier
= Qnil
;
8563 DEFVAR_BOOL ("w32-enable-synthesized-fonts", &w32_enable_synthesized_fonts
,
8564 doc
: /* Non-nil enables selection of artificially italicized and bold fonts. */);
8565 w32_enable_synthesized_fonts
= 0;
8567 DEFVAR_LISP ("w32-enable-palette", &Vw32_enable_palette
,
8568 doc
: /* Non-nil enables Windows palette management to map colors exactly. */);
8569 Vw32_enable_palette
= Qt
;
8571 DEFVAR_INT ("w32-mouse-button-tolerance",
8572 &w32_mouse_button_tolerance
,
8573 doc
: /* Analogue of double click interval for faking middle mouse events.
8574 The value is the minimum time in milliseconds that must elapse between
8575 left/right button down events before they are considered distinct events.
8576 If both mouse buttons are depressed within this interval, a middle mouse
8577 button down event is generated instead. */);
8578 w32_mouse_button_tolerance
= GetDoubleClickTime () / 2;
8580 DEFVAR_INT ("w32-mouse-move-interval",
8581 &w32_mouse_move_interval
,
8582 doc
: /* Minimum interval between mouse move events.
8583 The value is the minimum time in milliseconds that must elapse between
8584 successive mouse move (or scroll bar drag) events before they are
8585 reported as lisp events. */);
8586 w32_mouse_move_interval
= 0;
8588 DEFVAR_BOOL ("w32-pass-extra-mouse-buttons-to-system",
8589 &w32_pass_extra_mouse_buttons_to_system
,
8590 doc
: /* Non-nil if the fourth and fifth mouse buttons are passed to Windows.
8591 Recent versions of Windows support mice with up to five buttons.
8592 Since most applications don't support these extra buttons, most mouse
8593 drivers will allow you to map them to functions at the system level.
8594 If this variable is non-nil, Emacs will pass them on, allowing the
8595 system to handle them. */);
8596 w32_pass_extra_mouse_buttons_to_system
= 0;
8598 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
8599 doc
: /* The shape of the pointer when over text.
8600 Changing the value does not affect existing frames
8601 unless you set the mouse color. */);
8602 Vx_pointer_shape
= Qnil
;
8604 Vx_nontext_pointer_shape
= Qnil
;
8606 Vx_mode_pointer_shape
= Qnil
;
8608 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
8609 doc
: /* The shape of the pointer when Emacs is busy.
8610 This variable takes effect when you create a new frame
8611 or when you set the mouse color. */);
8612 Vx_hourglass_pointer_shape
= Qnil
;
8614 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
8615 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
8616 display_hourglass_p
= 1;
8618 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
8619 doc
: /* *Seconds to wait before displaying an hourglass pointer.
8620 Value must be an integer or float. */);
8621 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
8623 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
8624 &Vx_sensitive_text_pointer_shape
,
8625 doc
: /* The shape of the pointer when over mouse-sensitive text.
8626 This variable takes effect when you create a new frame
8627 or when you set the mouse color. */);
8628 Vx_sensitive_text_pointer_shape
= Qnil
;
8630 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
8631 &Vx_window_horizontal_drag_shape
,
8632 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
8633 This variable takes effect when you create a new frame
8634 or when you set the mouse color. */);
8635 Vx_window_horizontal_drag_shape
= Qnil
;
8637 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
8638 doc
: /* A string indicating the foreground color of the cursor box. */);
8639 Vx_cursor_fore_pixel
= Qnil
;
8641 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size
,
8642 doc
: /* Maximum size for tooltips.
8643 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
8644 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
8646 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
8647 doc
: /* Non-nil if no window manager is in use.
8648 Emacs doesn't try to figure this out; this is always nil
8649 unless you set it to something else. */);
8650 /* We don't have any way to find this out, so set it to nil
8651 and maybe the user would like to set it to t. */
8652 Vx_no_window_manager
= Qnil
;
8654 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
8655 &Vx_pixel_size_width_font_regexp
,
8656 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
8658 Since Emacs gets width of a font matching with this regexp from
8659 PIXEL_SIZE field of the name, font finding mechanism gets faster for
8660 such a font. This is especially effective for such large fonts as
8661 Chinese, Japanese, and Korean. */);
8662 Vx_pixel_size_width_font_regexp
= Qnil
;
8664 DEFVAR_LISP ("w32-bdf-filename-alist",
8665 &Vw32_bdf_filename_alist
,
8666 doc
: /* List of bdf fonts and their corresponding filenames. */);
8667 Vw32_bdf_filename_alist
= Qnil
;
8669 DEFVAR_BOOL ("w32-strict-fontnames",
8670 &w32_strict_fontnames
,
8671 doc
: /* Non-nil means only use fonts that are exact matches for those requested.
8672 Default is nil, which allows old fontnames that are not XLFD compliant,
8673 and allows third-party CJK display to work by specifying false charset
8674 fields to trick Emacs into translating to Big5, SJIS etc.
8675 Setting this to t will prevent wrong fonts being selected when
8676 fontsets are automatically created. */);
8677 w32_strict_fontnames
= 0;
8679 DEFVAR_BOOL ("w32-strict-painting",
8680 &w32_strict_painting
,
8681 doc
: /* Non-nil means use strict rules for repainting frames.
8682 Set this to nil to get the old behaviour for repainting; this should
8683 only be necessary if the default setting causes problems. */);
8684 w32_strict_painting
= 1;
8686 DEFVAR_LISP ("w32-charset-info-alist",
8687 &Vw32_charset_info_alist
,
8688 doc
: /* Alist linking Emacs character sets to Windows fonts and codepages.
8689 Each entry should be of the form:
8691 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE))
8693 where CHARSET_NAME is a string used in font names to identify the charset,
8694 WINDOWS_CHARSET is a symbol that can be one of:
8695 w32-charset-ansi, w32-charset-default, w32-charset-symbol,
8696 w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312,
8697 w32-charset-chinesebig5,
8698 w32-charset-johab, w32-charset-hebrew,
8699 w32-charset-arabic, w32-charset-greek, w32-charset-turkish,
8700 w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope,
8701 w32-charset-russian, w32-charset-mac, w32-charset-baltic,
8702 w32-charset-unicode,
8704 CODEPAGE should be an integer specifying the codepage that should be used
8705 to display the character set, t to do no translation and output as Unicode,
8706 or nil to do no translation and output as 8 bit (or multibyte on far-east
8707 versions of Windows) characters. */);
8708 Vw32_charset_info_alist
= Qnil
;
8710 staticpro (&Qw32_charset_ansi
);
8711 Qw32_charset_ansi
= intern ("w32-charset-ansi");
8712 staticpro (&Qw32_charset_symbol
);
8713 Qw32_charset_symbol
= intern ("w32-charset-symbol");
8714 staticpro (&Qw32_charset_shiftjis
);
8715 Qw32_charset_shiftjis
= intern ("w32-charset-shiftjis");
8716 staticpro (&Qw32_charset_hangeul
);
8717 Qw32_charset_hangeul
= intern ("w32-charset-hangeul");
8718 staticpro (&Qw32_charset_chinesebig5
);
8719 Qw32_charset_chinesebig5
= intern ("w32-charset-chinesebig5");
8720 staticpro (&Qw32_charset_gb2312
);
8721 Qw32_charset_gb2312
= intern ("w32-charset-gb2312");
8722 staticpro (&Qw32_charset_oem
);
8723 Qw32_charset_oem
= intern ("w32-charset-oem");
8725 #ifdef JOHAB_CHARSET
8727 static int w32_extra_charsets_defined
= 1;
8728 DEFVAR_BOOL ("w32-extra-charsets-defined", &w32_extra_charsets_defined
,
8729 doc
: /* Internal variable. */);
8731 staticpro (&Qw32_charset_johab
);
8732 Qw32_charset_johab
= intern ("w32-charset-johab");
8733 staticpro (&Qw32_charset_easteurope
);
8734 Qw32_charset_easteurope
= intern ("w32-charset-easteurope");
8735 staticpro (&Qw32_charset_turkish
);
8736 Qw32_charset_turkish
= intern ("w32-charset-turkish");
8737 staticpro (&Qw32_charset_baltic
);
8738 Qw32_charset_baltic
= intern ("w32-charset-baltic");
8739 staticpro (&Qw32_charset_russian
);
8740 Qw32_charset_russian
= intern ("w32-charset-russian");
8741 staticpro (&Qw32_charset_arabic
);
8742 Qw32_charset_arabic
= intern ("w32-charset-arabic");
8743 staticpro (&Qw32_charset_greek
);
8744 Qw32_charset_greek
= intern ("w32-charset-greek");
8745 staticpro (&Qw32_charset_hebrew
);
8746 Qw32_charset_hebrew
= intern ("w32-charset-hebrew");
8747 staticpro (&Qw32_charset_vietnamese
);
8748 Qw32_charset_vietnamese
= intern ("w32-charset-vietnamese");
8749 staticpro (&Qw32_charset_thai
);
8750 Qw32_charset_thai
= intern ("w32-charset-thai");
8751 staticpro (&Qw32_charset_mac
);
8752 Qw32_charset_mac
= intern ("w32-charset-mac");
8756 #ifdef UNICODE_CHARSET
8758 static int w32_unicode_charset_defined
= 1;
8759 DEFVAR_BOOL ("w32-unicode-charset-defined",
8760 &w32_unicode_charset_defined
,
8761 doc
: /* Internal variable. */);
8763 staticpro (&Qw32_charset_unicode
);
8764 Qw32_charset_unicode
= intern ("w32-charset-unicode");
8767 #if 0 /* TODO: Port to W32 */
8768 defsubr (&Sx_change_window_property
);
8769 defsubr (&Sx_delete_window_property
);
8770 defsubr (&Sx_window_property
);
8772 defsubr (&Sxw_display_color_p
);
8773 defsubr (&Sx_display_grayscale_p
);
8774 defsubr (&Sxw_color_defined_p
);
8775 defsubr (&Sxw_color_values
);
8776 defsubr (&Sx_server_max_request_size
);
8777 defsubr (&Sx_server_vendor
);
8778 defsubr (&Sx_server_version
);
8779 defsubr (&Sx_display_pixel_width
);
8780 defsubr (&Sx_display_pixel_height
);
8781 defsubr (&Sx_display_mm_width
);
8782 defsubr (&Sx_display_mm_height
);
8783 defsubr (&Sx_display_screens
);
8784 defsubr (&Sx_display_planes
);
8785 defsubr (&Sx_display_color_cells
);
8786 defsubr (&Sx_display_visual_class
);
8787 defsubr (&Sx_display_backing_store
);
8788 defsubr (&Sx_display_save_under
);
8789 defsubr (&Sx_create_frame
);
8790 defsubr (&Sx_open_connection
);
8791 defsubr (&Sx_close_connection
);
8792 defsubr (&Sx_display_list
);
8793 defsubr (&Sx_synchronize
);
8795 /* W32 specific functions */
8797 defsubr (&Sw32_focus_frame
);
8798 defsubr (&Sw32_select_font
);
8799 defsubr (&Sw32_define_rgb_color
);
8800 defsubr (&Sw32_default_color_map
);
8801 defsubr (&Sw32_load_color_file
);
8802 defsubr (&Sw32_send_sys_command
);
8803 defsubr (&Sw32_shell_execute
);
8804 defsubr (&Sw32_register_hot_key
);
8805 defsubr (&Sw32_unregister_hot_key
);
8806 defsubr (&Sw32_registered_hot_keys
);
8807 defsubr (&Sw32_reconstruct_hot_key
);
8808 defsubr (&Sw32_toggle_lock_key
);
8809 defsubr (&Sw32_find_bdf_fonts
);
8811 defsubr (&Sfile_system_info
);
8812 defsubr (&Sdefault_printer_name
);
8814 /* Setting callback functions for fontset handler. */
8815 get_font_info_func
= w32_get_font_info
;
8817 #if 0 /* This function pointer doesn't seem to be used anywhere.
8818 And the pointer assigned has the wrong type, anyway. */
8819 list_fonts_func
= w32_list_fonts
;
8822 load_font_func
= w32_load_font
;
8823 find_ccl_program_func
= w32_find_ccl_program
;
8824 query_font_func
= w32_query_font
;
8825 set_frame_fontset_func
= x_set_font
;
8826 check_window_system_func
= check_w32
;
8829 hourglass_atimer
= NULL
;
8830 hourglass_shown_p
= 0;
8831 defsubr (&Sx_show_tip
);
8832 defsubr (&Sx_hide_tip
);
8834 staticpro (&tip_timer
);
8836 staticpro (&tip_frame
);
8838 last_show_tip_args
= Qnil
;
8839 staticpro (&last_show_tip_args
);
8841 defsubr (&Sx_file_dialog
);
8846 globals_of_w32fns is used to initialize those global variables that
8847 must always be initialized on startup even when the global variable
8848 initialized is non zero (see the function main in emacs.c).
8849 globals_of_w32fns is called from syms_of_w32fns when the global
8850 variable initialized is 0 and directly from main when initialized
8853 void globals_of_w32fns ()
8855 HMODULE user32_lib
= GetModuleHandle ("user32.dll");
8857 TrackMouseEvent not available in all versions of Windows, so must load
8858 it dynamically. Do it once, here, instead of every time it is used.
8860 track_mouse_event_fn
= (TrackMouseEvent_Proc
)
8861 GetProcAddress (user32_lib
, "TrackMouseEvent");
8862 /* ditto for GetClipboardSequenceNumber. */
8863 clipboard_sequence_fn
= (ClipboardSequence_Proc
)
8864 GetProcAddress (user32_lib
, "GetClipboardSequenceNumber");
8866 DEFVAR_INT ("w32-ansi-code-page",
8867 &w32_ansi_code_page
,
8868 doc
: /* The ANSI code page used by the system. */);
8869 w32_ansi_code_page
= GetACP ();
8878 button
= MessageBox (NULL
,
8879 "A fatal error has occurred!\n\n"
8880 "Select Abort to exit, Retry to debug, Ignore to continue",
8881 "Emacs Abort Dialog",
8882 MB_ICONEXCLAMATION
| MB_TASKMODAL
8883 | MB_SETFOREGROUND
| MB_ABORTRETRYIGNORE
);
8898 /* For convenience when debugging. */
8902 return GetLastError ();
8905 /* arch-tag: 707589ab-b9be-4638-8cdd-74629cc9b446
8906 (do not change this comment) */