aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii2012-10-08 15:06:31 +0200
committerEli Zaretskii2012-10-08 15:06:31 +0200
commit7014794467aac02be3a935a093e1bfb8ad410c12 (patch)
tree0aa27b30dcdc8fc4e63c8d88d9b878d0b3ff9765 /src
parentd6de17607045c1d33826a12983e33deb73426457 (diff)
parentc54ebba4e076caeb6105c6bb682252b139a169fa (diff)
downloademacs-7014794467aac02be3a935a093e1bfb8ad410c12.tar.gz
emacs-7014794467aac02be3a935a093e1bfb8ad410c12.zip
Merge from trunk after cygw32 commit, and resolve conflicts.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog183
-rw-r--r--src/Makefile.in30
-rw-r--r--src/conf_post.h14
-rw-r--r--src/cygw32.c169
-rw-r--r--src/cygw32.h58
-rw-r--r--src/dispextern.h4
-rw-r--r--src/emacs.c66
-rw-r--r--src/font.c4
-rw-r--r--src/font.h5
-rw-r--r--src/fontset.c2
-rw-r--r--src/frame.c4
-rw-r--r--src/frame.h5
-rw-r--r--src/image.c81
-rw-r--r--src/keyboard.c17
-rw-r--r--src/keyboard.h2
-rw-r--r--src/makefile.w32-in8
-rw-r--r--src/menu.c4
-rw-r--r--src/process.c1
-rw-r--r--src/ralloc.c5
-rw-r--r--src/termhooks.h6
-rw-r--r--src/unexw32.c2
-rw-r--r--src/w32.c19
-rw-r--r--src/w32.h17
-rw-r--r--src/w32console.c49
-rw-r--r--src/w32fns.c786
-rw-r--r--src/w32font.c4
-rw-r--r--src/w32heap.c41
-rw-r--r--src/w32inevt.c172
-rw-r--r--src/w32menu.c27
-rw-r--r--src/w32proc.c14
-rw-r--r--src/w32select.c5
-rw-r--r--src/w32select.h30
-rw-r--r--src/w32term.c53
-rw-r--r--src/w32term.h61
-rw-r--r--src/w32xfns.c32
-rw-r--r--src/window.c2
-rw-r--r--src/xdisp.c2
-rw-r--r--src/xfaces.c18
38 files changed, 1444 insertions, 558 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index cb2aab2166c..30db50fbcc8 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,170 @@
12012-10-08 Eli Zaretskii <eliz@gnu.org>
2
3 * makefile.w32-in (FONT_H): Add $(FRAME_H).
4 (W32TERM_H): Add $(ATIMER_H) and $(FRAME_H).
5 ($(BLD)/emacs.$(O), $(BLD)/w32console.$(O)): Update dependencies.
6 (GLOBAL_SOURCES): Add cygw32.c.
7
8 * w32fns.c (w32_color_map_lookup, x_to_w32_color): Argument is now
9 'const char *'.
10 (x_to_w32_color): Don't modify the argument, modify a copy instead.
11
122012-10-08 Daniel Colascione <dancol@dancol.org>
13
14 * image.c: Permanent fix for JPEG compilation issue --- limit
15 jpeglib `boolean' redefinition to Cygwin builds.
16
172012-10-08 Eli Zaretskii <eliz@gnu.org>
18
19 * image.c (CHECK_LIB_AVAILABLE): Remove, no longer used.
20
21 * emacs.c (DAEMON_MUST_EXEC) [HAVE_NTGUI]: Define this only on
22 Cygwin.
23
242012-10-08 Daniel Colascione <dancol@dancol.org>
25
26 * xfaces.c, xdisp.c, window.c, w32xfns.c, w32term.h, w32term.c,
27 w32select.h w32select.c, w32proc.c, w32menu.c, w32inevt.c,
28 w32help.c, w32font.c, w32font.c, w32fns.c, w32console.c, w32.h,
29 w32.c, unexw32.c, termhooks.h, process.c, menu.c, keyboard.h,
30 keyboard.c, image.c, frame.h, frame.c, fontset.c, font.h, font.c,
31 emacs.c, dispextern.h, cygw32.h, cygw32.c, conf_post.h,
32 Makefile.in: use HAVE_NTGUI for W32 GUI and WINDOWSNT for the
33 operating system. defined(HAVE_NTGUI) && !defined(WINDOWSNT) is
34 now a supported configuration.
35
36 * Makefile.in: consolidate image variables into LIBIMAGE; add
37 W32_OBJ and W32_LIBS. Compile new files.
38
39 * conf_post.h:
40 (_DebPrint) declare tracing facility for W32 debugging. We need
41 to unify tracing later.
42
43 (NTGUI_UNICODE) Define when compiling for Cygwin to allow the
44 unconditional use of W32 Unicode functions. Cygwin runs only on
45 100% Unicode operating systems.
46
47 * cygw32.c: New file. Define Cygwin-specific facilities.
48 (Fcygwin_convert_path_to_windows)
49 (Fcygwin_convert_path_from_windows): New user functions for
50 accessing Cygwin path-munging routines.
51
52 * cygw32.h: New file.
53 (WCSDATA, to_unicode, from_unicode): Define facilities for storing
54 UTF-16LE strings temporarily inside non-Lisp-visible string
55 objects.
56
57 (w32_strerror): Just what it says on the tin.
58
59 * emacs.c: Make the NS fork-then-exec code for daemon-launching
60 also run for Cygwin; both systems have the same problem with using
61 GUI facilities in a forked child. Also call syms_of_cygw32,
62 syms_of_w32select in correct places.
63
64 (DAEMON_MUST_EXEC): new macro defined to signal that a platform
65 needs fork-then-exec for daemon launching.
66
67 * font.h: Include frame.h.
68
69 * image.c: Use the image library cache machinery only when we're
70 compiling for native WINDOWSNT; Cygwin can use shared libraries
71 like any other Unixlike system.
72
73 * keyboard.c: Clarify a comment regarding the input loop.
74
75 * menu.c: When NTGUI_UNICODE is defined, use Unicode menu
76 functions directly instead of trying to detect at runtime that our
77 host operating system supports them. We make this change for two
78 reasons: Cygwin lacks support for the multibyte character
79 conversion functions used by the legacy menu code, and Cygwin
80 never needs to rely on non-Unicode APIs.
81
82 * unexw32.c (hinst): Declare extern.
83
84 * w32.c: Change header order;
85 (w32_strerror): Move to w32fns.c because we need it for
86 non-WINDOWSNT builds.
87
88 * w32.h: Add #error macro to make sure we don't include w32.h for
89 Cygwin builds. Remove w32select declarations.
90
91 * w32console.c (w32_sys_ring_bell, Fset_message_beep): Move to
92 w32fns.c. w32console.c is WINDOWSNT-only.
93
94 * w32fns.c: Include cygw32.h or w32.h depending on CYGWIN; more
95 NTGUI_UNICODE tweaks. (See above.) Change _snprintf to the more
96 POSIXy alternative.
97 (faked_key, sysinfo_cache, osinfo_cahce, syspage_mask)
98 (w32_major_version, w32_minor_version, w32_build_number)
99 (os_subtype, sound_type): Define here
100 (w32_defined_color): Make color parameter const for consistency
101 with other _defined_color functions.
102 (w32_createwindow): Unconditionally call w32_init_class instead of
103 doing so only when hprevinst is non-NULL. Plumbing hprevinst
104 through the code is complex and unnecessary because class
105 registration is practically free.
106 (w32_name_of_message): New EMACSDEBUG-only function.
107 (Fset_message_beep): Move here
108 (Fx_open_connection): Require that the display name for Windows be
109 "w32" for consistency, emacsclient disambiguation, and maybe, one
110 day, multi-window-system support.
111 (file_dialog_callback): NTGUI_UNICODE changes; encode and decode
112 Cygwin files for W32 GUI facilities, since these clearly don't
113 expect Cygwin names.
114 (_DebPrint): Define.
115 (w32_strerror, w32_console_toggle_lock_key, w32_kbd_mods_to_emacs)
116 (w32_kbd_patch_key, w32_sys_ring_bell): Move here.
117 (Ssystem_move_file_to_trash): Define only for native WINDOWSNT.
118 (w32_last_error): Remove.
119
120 * w32font.c: Define _strlwr to strlwr for non-WINDOWSNT builds.
121
122 * w32heap.c (syspage_mask): Declare here.
123 (cache_system_info): Remove.
124
125 * w32inevt.c (faked_key): Define globally, not statically.
126 (w32_kbd_mods_to_emacs, w32_kbd_patch_key, faked_key)
127 (w32_console_toggle_lock_key): Move to w32fns.c.
128
129 * w32menu.c: Include setjmp.h. NTGUI_UNICODE changes throughout.
130
131 * w32proc.c (_DebPrint): Move to w32fns.c.
132 * w32select.c: Include string.h, stdio.h for Cygwin.
133 * w32select.h: New File.
134
135 * w32term.c: Include io.h for non-CYGWIN builds; needed for
136 get_osfhandle.
137 (w32_message_fd): New variable. Under Cygwin, holds the file
138 descriptor the system used to tell us about pending thread
139 messages.
140
141 (w32_init_term): Remove incorrect calls to fcntl and init_sigio
142 that prevented compilation under non-WINDOWSNT systems.
143
144 (w32_initialize): Open /dev/windows and assign it to
145 w32_message_fd. Provide w32 feature.
146
147 * w32term.h: Include frame.h, atimer.h. Declare various frame functions.
148 (WM_EMACS_INPUT_READY): add.
149 (prepend_msg, w32_message_fd): Declare globally.
150
151 * w32xfns.c:
152 (keyboard_handle): Use only when WINDOWSNT.
153 (notify_msg_ready): New function. Posts a message to the main
154 thread's message queue under CYGWIN, which wakes up the main
155 thread from select(2) by making the /dev/windows file descriptor
156 ready. Under WINDOWSNT, it sets an event the same way the old
157 code did.
158
159 (post, prepend_msg): Actually call notify_msg_ready instead of
160 setting the input event directly.
161
1622012-10-07 Eli Zaretskii <eliz@gnu.org>
163
164 * ralloc.c (relinquish): If a heap is ready to be relinquished,
165 but it still has blocs in it, don't return it to the system,
166 instead of aborting. (Bug#12402)
167
12012-10-07 Eli Zaretskii <eliz@gnu.org> 1682012-10-07 Eli Zaretskii <eliz@gnu.org>
2 169
3 * w32term.h (WM_EMACS_FILENOTIFY): New custom message. 170 * w32term.h (WM_EMACS_FILENOTIFY): New custom message.
@@ -34,11 +201,12 @@
34 201
352012-10-07 Jan Djärv <jan.h.d@swipnet.se> 2022012-10-07 Jan Djärv <jan.h.d@swipnet.se>
36 203
37 * nsterm.m (ns_dumpglyphs_image): Only draw slize of image (Bug#12506). 204 * nsterm.m (ns_dumpglyphs_image): Only draw slice of image (Bug#12506).
38 205
39 * nsterm.m (ns_update_auto_hide_menu_bar): Remove defintion of 206 * nsterm.m (ns_update_auto_hide_menu_bar): Remove defintion of
40 MAC_OS_X_VERSION_10_6. 207 MAC_OS_X_VERSION_10_6.
41 (syms_of_nsterm): Remove comment about Panther and above for ns-antialias-text. 208 (syms_of_nsterm): Remove comment about Panther and above for
209 ns-antialias-text.
42 * nsterm.h (MAC_OS_X_VERSION_10_3, onTiger): Remove. 210 * nsterm.h (MAC_OS_X_VERSION_10_3, onTiger): Remove.
43 (EmacsApp): Remove check for >= MAC_OS_X_VERSION_10_4. 211 (EmacsApp): Remove check for >= MAC_OS_X_VERSION_10_4.
44 (struct nsfont_info): Remove check for >= MAC_OS_X_VERSION_10_3. 212 (struct nsfont_info): Remove check for >= MAC_OS_X_VERSION_10_3.
@@ -46,7 +214,8 @@
46 * nsselect.m (ns_string_from_pasteboard): Remove check for >= 214 * nsselect.m (ns_string_from_pasteboard): Remove check for >=
47 MAC_OS_X_VERSION_10_4. 215 MAC_OS_X_VERSION_10_4.
48 216
49 * nsmenu.m (fillWithWidgetValue:): Remove code for < MAC_OS_X_VERSION_10_2. 217 * nsmenu.m (fillWithWidgetValue:): Remove code for <
218 MAC_OS_X_VERSION_10_2.
50 219
51 * nsimage.m (setPixmapData, getPixelAtX, setAlphaAtX): Remove onTiger. 220 * nsimage.m (setPixmapData, getPixelAtX, setAlphaAtX): Remove onTiger.
52 221
@@ -55,13 +224,13 @@
55 224
56 * nsterm.m (ns_in_resize): Remove (Bug#12479). 225 * nsterm.m (ns_in_resize): Remove (Bug#12479).
57 (ns_resize_handle_rect, mouseDown, mouseUp, mouseDragged): Remove. 226 (ns_resize_handle_rect, mouseDown, mouseUp, mouseDragged): Remove.
58 (ns_clear_frame, sendEvent, windowDidResize, drawRect:): Remove ns_in_resize 227 (ns_clear_frame, sendEvent, windowDidResize, drawRect:): Remove
59 check. 228 ns_in_resize check.
60 (ns_clear_frame_area): Remove resize handle code. 229 (ns_clear_frame_area): Remove resize handle code.
61 230
62 * nsfns.m (ns_in_resize): Remove. 231 * nsfns.m (ns_in_resize): Remove.
63 (x_set_icon_name, ns_set_name, ns_set_name_as_filename): Remove ns_in_resize 232 (x_set_icon_name, ns_set_name, ns_set_name_as_filename): Remove
64 check. 233 ns_in_resize check.
65 234
662012-10-07 Paul Eggert <eggert@cs.ucla.edu> 2352012-10-07 Paul Eggert <eggert@cs.ucla.edu>
67 236
diff --git a/src/Makefile.in b/src/Makefile.in
index f8da0091711..e704f2f5c0c 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -135,13 +135,10 @@ LIB_MATH=@LIB_MATH@
135## -lpthreads, or empty. 135## -lpthreads, or empty.
136LIB_PTHREAD=@LIB_PTHREAD@ 136LIB_PTHREAD=@LIB_PTHREAD@
137 137
138LIBTIFF=@LIBTIFF@ 138LIBIMAGE=@LIBTIFF@ @LIBJPEG@ @LIBPNG@ @LIBGIF@ @LIBXPM@
139LIBJPEG=@LIBJPEG@ 139
140LIBPNG=@LIBPNG@
141LIBGIF=@LIBGIF@
142LIBXPM=@LIBXPM@
143XFT_LIBS=@XFT_LIBS@ 140XFT_LIBS=@XFT_LIBS@
144LIBX_EXTRA=$(LIBTIFF) $(LIBJPEG) $(LIBPNG) $(LIBGIF) $(LIBXPM) -lX11 $(XFT_LIBS) 141LIBX_EXTRA=-lX11 $(XFT_LIBS)
145 142
146FONTCONFIG_CFLAGS = @FONTCONFIG_CFLAGS@ 143FONTCONFIG_CFLAGS = @FONTCONFIG_CFLAGS@
147FONTCONFIG_LIBS = @FONTCONFIG_LIBS@ 144FONTCONFIG_LIBS = @FONTCONFIG_LIBS@
@@ -261,6 +258,13 @@ NS_OBJ=@NS_OBJ@
261NS_OBJC_OBJ=@NS_OBJC_OBJ@ 258NS_OBJC_OBJ=@NS_OBJC_OBJ@
262## Only set if NS_IMPL_GNUSTEP. 259## Only set if NS_IMPL_GNUSTEP.
263GNU_OBJC_CFLAGS=@GNU_OBJC_CFLAGS@ 260GNU_OBJC_CFLAGS=@GNU_OBJC_CFLAGS@
261## w32fns.o w32menu.c w32reg.o fringe.o fontset.o w32font.o w32term.o
262## w32xfns.o w32select.o image.o w32uniscribe.o if HAVE_W32, else
263## empty.
264W32_OBJ=@W32_OBJ@
265## -lkernel32 -luser32 -lgdi32 -lole32 -lcomdlg32 lusp10 -lcomctl32
266## --lwinspool if HAVE_W32, else empty.
267W32_LIBS=@W32_LIBS@
264 268
265## Empty if !HAVE_X_WINDOWS 269## Empty if !HAVE_X_WINDOWS
266## xfont.o ftfont.o xftfont.o ftxfont.o if HAVE_XFT 270## xfont.o ftfont.o xftfont.o ftxfont.o if HAVE_XFT
@@ -342,7 +346,7 @@ base_obj = dispnew.o frame.o scroll.o xdisp.o menu.o $(XMENU_OBJ) window.o \
342 doprnt.o intervals.o textprop.o composite.o xml.o \ 346 doprnt.o intervals.o textprop.o composite.o xml.o \
343 profiler.o \ 347 profiler.o \
344 $(MSDOS_OBJ) $(MSDOS_X_OBJ) $(NS_OBJ) $(CYGWIN_OBJ) $(FONT_OBJ) \ 348 $(MSDOS_OBJ) $(MSDOS_X_OBJ) $(NS_OBJ) $(CYGWIN_OBJ) $(FONT_OBJ) \
345 $(WINDOW_SYSTEM_OBJ) 349 $(W32_OBJ) $(WINDOW_SYSTEM_OBJ)
346obj = $(base_obj) $(NS_OBJC_OBJ) 350obj = $(base_obj) $(NS_OBJC_OBJ)
347 351
348## Object files used on some machine or other. 352## Object files used on some machine or other.
@@ -351,9 +355,9 @@ obj = $(base_obj) $(NS_OBJC_OBJ)
351## in the list, in case they ever add any such entries. 355## in the list, in case they ever add any such entries.
352SOME_MACHINE_OBJECTS = dosfns.o msdos.o \ 356SOME_MACHINE_OBJECTS = dosfns.o msdos.o \
353 xterm.o xfns.o xmenu.o xselect.o xrdb.o xsmfns.o fringe.o image.o \ 357 xterm.o xfns.o xmenu.o xselect.o xrdb.o xsmfns.o fringe.o image.o \
354 fontset.o dbusbind.o \ 358 fontset.o dbusbind.o cygw32.o \
355 nsterm.o nsfns.o nsmenu.o nsselect.o nsimage.o nsfont.o \ 359 nsterm.o nsfns.o nsmenu.o nsselect.o nsimage.o nsfont.o \
356 w32.o w32console.o w32fns.o w32heap.o w32inevt.o \ 360 w32.o w32console.o w32fns.o w32heap.o \
357 w32menu.o w32proc.o w32reg.o w32select.o w32term.o w32xfns.o \ 361 w32menu.o w32proc.o w32reg.o w32select.o w32term.o w32xfns.o \
358 w16select.o widget.o xfont.o ftfont.o xftfont.o ftxfont.o gtkutil.o \ 362 w16select.o widget.o xfont.o ftfont.o xftfont.o ftxfont.o gtkutil.o \
359 xsettings.o xgselect.o termcap.o 363 xsettings.o xgselect.o termcap.o
@@ -385,9 +389,11 @@ otherobj= $(TERMCAP_OBJ) $(PRE_ALLOC_OBJ) $(GMALLOC_OBJ) $(RALLOC_OBJ) \
385## Note that SunOS needs -lm to come before -lc; otherwise, you get 389## Note that SunOS needs -lm to come before -lc; otherwise, you get
386## duplicated symbols. If the standard libraries were compiled 390## duplicated symbols. If the standard libraries were compiled
387## with GCC, we might need LIB_GCC again after them. 391## with GCC, we might need LIB_GCC again after them.
388LIBES = $(LIBS) $(LIBX_BASE) $(LIBX_OTHER) $(LIBSOUND) \ 392LIBES = $(LIBS) $(W32_LIBS) $(LIBX_BASE) $(LIBIMAGE) \
389 $(RSVG_LIBS) $(IMAGEMAGICK_LIBS) $(LIB_CLOCK_GETTIME) $(LIB_TIMER_TIME) \ 393 $(LIBX_OTHER) $(LIBSOUND) \
390 $(DBUS_LIBS) $(LIB_EXECINFO) \ 394 $(RSVG_LIBS) $(IMAGEMAGICK_LIBS) $(LIB_CLOCK_GETTIME) \
395 $(LIB_TIMER_TIME) $(DBUS_LIBS) \
396 $(LIB_EXECINFO) \
391 $(LIBXML2_LIBS) $(LIBGPM) $(LIBRESOLV) $(LIBS_SYSTEM) \ 397 $(LIBXML2_LIBS) $(LIBGPM) $(LIBRESOLV) $(LIBS_SYSTEM) \
392 $(LIBS_TERMCAP) $(GETLOADAVG_LIBS) $(SETTINGS_LIBS) $(LIBSELINUX_LIBS) \ 398 $(LIBS_TERMCAP) $(GETLOADAVG_LIBS) $(SETTINGS_LIBS) $(LIBSELINUX_LIBS) \
393 $(FREETYPE_LIBS) $(FONTCONFIG_LIBS) $(LIBOTF_LIBS) $(M17N_FLT_LIBS) \ 399 $(FREETYPE_LIBS) $(FONTCONFIG_LIBS) $(LIBOTF_LIBS) $(M17N_FLT_LIBS) \
diff --git a/src/conf_post.h b/src/conf_post.h
index 0c4d029bc5d..53fc941f464 100644
--- a/src/conf_post.h
+++ b/src/conf_post.h
@@ -142,6 +142,20 @@ You lose; /* Emacs for DOS must be compiled with DJGPP */
142#endif 142#endif
143#endif 143#endif
144 144
145#if defined(HAVE_NTGUI) && !defined(DebPrint)
146# if defined(EMACSDEBUG)
147extern void _DebPrint (const char *fmt, ...);
148# define DebPrint(stuff) _DebPrint stuff
149# else
150# define DebPrint(stuff)
151# endif /* EMACSDEBUG */
152#endif /* DebPrint */
153
154#if defined(CYGWIN) && defined(HAVE_NTGUI)
155#define NTGUI_UNICODE /* Cygwin runs only on UNICODE-supporting systems */
156#define _WIN32_WINNT 0x500 /* Win2k */
157#endif /* CYGWIN && HAVE_NTGUI */
158
145#ifdef emacs /* Don't do this for lib-src. */ 159#ifdef emacs /* Don't do this for lib-src. */
146/* Tell regex.c to use a type compatible with Emacs. */ 160/* Tell regex.c to use a type compatible with Emacs. */
147#define RE_TRANSLATE_TYPE Lisp_Object 161#define RE_TRANSLATE_TYPE Lisp_Object
diff --git a/src/cygw32.c b/src/cygw32.c
new file mode 100644
index 00000000000..ab7ee91a138
--- /dev/null
+++ b/src/cygw32.c
@@ -0,0 +1,169 @@
1/* Cygwin support routines.
2 Copyright (C) 2011-2012 Free Software Foundation, Inc.
3
4This file is part of GNU Emacs.
5
6GNU Emacs is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
18
19
20#include "cygw32.h"
21#include "character.h"
22#include "buffer.h"
23#include <unistd.h>
24#include <fcntl.h>
25static Lisp_Object Qutf_16_le;
26
27static Lisp_Object
28fchdir_unwind (Lisp_Object dir_fd)
29{
30 (void) fchdir (XFASTINT (dir_fd));
31 (void) close (XFASTINT (dir_fd));
32 return Qnil;
33}
34
35static void
36chdir_to_default_directory ()
37{
38 Lisp_Object new_cwd;
39 int old_cwd_fd = open (".", O_RDONLY | O_DIRECTORY);
40
41 if (old_cwd_fd == -1)
42 error ("could not open current directory: %s", strerror (errno));
43
44 record_unwind_protect (fchdir_unwind, make_number (old_cwd_fd));
45
46 new_cwd = Funhandled_file_name_directory (
47 Fexpand_file_name (build_string ("."), Qnil));
48 if (!STRINGP (new_cwd))
49 new_cwd = build_string ("/");
50
51 if (chdir (SDATA (ENCODE_FILE (new_cwd))))
52 error ("could not chdir: %s", strerror (errno));
53}
54
55static Lisp_Object
56conv_filename_to_w32_unicode (Lisp_Object in, int absolute_p)
57{
58 ssize_t converted_len;
59 Lisp_Object converted;
60 unsigned flags;
61 int count = SPECPDL_INDEX ();
62
63 chdir_to_default_directory ();
64
65 flags = CCP_POSIX_TO_WIN_W;
66 if (!absolute_p) {
67 flags |= CCP_RELATIVE;
68 }
69
70 in = ENCODE_FILE (in);
71
72 converted_len = cygwin_conv_path (flags, SDATA (in), NULL, 0);
73 if (converted_len < 2)
74 error ("cygwin_conv_path: %s", strerror (errno));
75
76 converted = make_uninit_string (converted_len - 1);
77 if (cygwin_conv_path (flags, SDATA (in),
78 SDATA (converted), converted_len))
79 error ("cygwin_conv_path: %s", strerror (errno));
80
81 return unbind_to (count, converted);
82}
83
84static Lisp_Object
85conv_filename_from_w32_unicode (const wchar_t* in, int absolute_p)
86{
87 ssize_t converted_len;
88 Lisp_Object converted;
89 unsigned flags;
90 int count = SPECPDL_INDEX ();
91
92 chdir_to_default_directory ();
93
94 flags = CCP_WIN_W_TO_POSIX;
95 if (!absolute_p) {
96 flags |= CCP_RELATIVE;
97 }
98
99 converted_len = cygwin_conv_path (flags, in, NULL, 0);
100 if (converted_len < 1)
101 error ("cygwin_conv_path: %s", strerror (errno));
102
103 converted = make_uninit_string (converted_len - 1 /*subtract terminator*/);
104 if (cygwin_conv_path (flags, in, SDATA (converted), converted_len))
105 error ("cygwin_conv_path: %s", strerror (errno));
106
107 return unbind_to (count, DECODE_FILE (converted));
108}
109
110Lisp_Object
111from_unicode (Lisp_Object str)
112{
113 CHECK_STRING (str);
114 if (!STRING_MULTIBYTE (str) &&
115 SBYTES (str) & 1)
116 {
117 str = Fsubstring (str, make_number (0), make_number (-1));
118 }
119
120 return code_convert_string_norecord (str, Qutf_16_le, 0);
121}
122
123wchar_t *
124to_unicode (Lisp_Object str, Lisp_Object *buf)
125{
126 *buf = code_convert_string_norecord (str, Qutf_16_le, 1);
127 /* We need to make a another copy (in addition to the one made by
128 code_convert_string_norecord) to ensure that the final string is
129 _doubly_ zero terminated --- that is, that the string is
130 terminated by two zero bytes and one utf-16le null character.
131 Because strings are already terminated with a single zero byte,
132 we just add one additional zero. */
133 str = make_uninit_string (SBYTES (*buf) + 1);
134 memcpy (SDATA (str), SDATA (*buf), SBYTES (*buf));
135 SDATA (str) [SBYTES (*buf)] = '\0';
136 *buf = str;
137 return WCSDATA (*buf);
138}
139
140DEFUN ("cygwin-convert-path-to-windows",
141 Fcygwin_convert_path_to_windows, Scygwin_convert_path_to_windows,
142 1, 2, 0,
143 doc: /* Convert PATH to a Windows path. If ABSOLUTE-P if
144 non-nil, return an absolute path.*/)
145 (Lisp_Object path, Lisp_Object absolute_p)
146{
147 return from_unicode (
148 conv_filename_to_w32_unicode (path, absolute_p == Qnil ? 0 : 1));
149}
150
151DEFUN ("cygwin-convert-path-from-windows",
152 Fcygwin_convert_path_from_windows, Scygwin_convert_path_from_windows,
153 1, 2, 0,
154 doc: /* Convert a Windows path to a Cygwin path. If ABSOLUTE-P
155 if non-nil, return an absolute path.*/)
156 (Lisp_Object path, Lisp_Object absolute_p)
157{
158 return conv_filename_from_w32_unicode (to_unicode (path, &path),
159 absolute_p == Qnil ? 0 : 1);
160}
161
162void
163syms_of_cygw32 (void)
164{
165 /* No, not utf-16-le: that one has a BOM. */
166 DEFSYM (Qutf_16_le, "utf-16le");
167 defsubr (&Scygwin_convert_path_from_windows);
168 defsubr (&Scygwin_convert_path_to_windows);
169}
diff --git a/src/cygw32.h b/src/cygw32.h
new file mode 100644
index 00000000000..22b6f5692da
--- /dev/null
+++ b/src/cygw32.h
@@ -0,0 +1,58 @@
1/* Header for Cygwin support routines.
2 Copyright (C) 2011-2012 Free Software Foundation, Inc.
3
4This file is part of GNU Emacs.
5
6GNU Emacs is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
18
19#ifndef CYGW32_H
20#define CYGW32_H
21#include <config.h>
22#include <windef.h>
23#include <sys/cygwin.h>
24#include <wchar.h>
25
26#include <signal.h>
27#include <stdio.h>
28#include <limits.h>
29#include <errno.h>
30#include <math.h>
31#include <setjmp.h>
32
33#include "lisp.h"
34#include "coding.h"
35
36/* *** Character conversion *** */
37
38/* Access the wide-character string stored in a Lisp string object. */
39#define WCSDATA(x) ((wchar_t *) SDATA (x))
40
41/* Convert the multi-byte string in STR to UTF-16LE encoded unibyte
42 string, and store it in *BUF. BUF may safely point to STR on entry. */
43extern wchar_t *to_unicode (Lisp_Object str, Lisp_Object *buf);
44
45/* Convert STR, a UTF-16LE encoded string embedded in a unibyte string
46 object, to a multi-byte Emacs string, and return it. */
47extern Lisp_Object from_unicode (Lisp_Object str);
48
49/* *** Path conversion. *** */
50
51EXFUN (Fcygwin_convert_path_to_windows, 2);
52EXFUN (Fcygwin_convert_path_from_windows, 2);
53
54/* *** Misc *** */
55extern void syms_of_cygw32 (void);
56extern char * w32_strerror (int error_no);
57
58#endif /* CYGW32_H */
diff --git a/src/dispextern.h b/src/dispextern.h
index f1ea8e97ee8..c5ebb808b05 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -3144,7 +3144,7 @@ int draw_window_fringes (struct window *, int);
3144int update_window_fringes (struct window *, int); 3144int update_window_fringes (struct window *, int);
3145void compute_fringe_widths (struct frame *, int); 3145void compute_fringe_widths (struct frame *, int);
3146 3146
3147#ifdef WINDOWSNT 3147#ifdef HAVE_NTGUI
3148void w32_init_fringe (struct redisplay_interface *); 3148void w32_init_fringe (struct redisplay_interface *);
3149void w32_reset_fringes (void); 3149void w32_reset_fringes (void);
3150#endif 3150#endif
@@ -3247,7 +3247,7 @@ extern char unspecified_fg[], unspecified_bg[];
3247#ifdef HAVE_X_WINDOWS 3247#ifdef HAVE_X_WINDOWS
3248void gamma_correct (struct frame *, XColor *); 3248void gamma_correct (struct frame *, XColor *);
3249#endif 3249#endif
3250#ifdef WINDOWSNT 3250#ifdef HAVE_NTGUI
3251void gamma_correct (struct frame *, COLORREF *); 3251void gamma_correct (struct frame *, COLORREF *);
3252#endif 3252#endif
3253 3253
diff --git a/src/emacs.c b/src/emacs.c
index 65ee11fb261..2e3c880fb53 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -33,9 +33,20 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
33 33
34#ifdef WINDOWSNT 34#ifdef WINDOWSNT
35#include <fcntl.h> 35#include <fcntl.h>
36#include <windows.h> /* just for w32.h */
37#include "w32.h" 36#include "w32.h"
38#include "w32heap.h" /* for prototype of sbrk */ 37#endif
38
39#if defined (WINDOWSNT)
40#include "w32heap.h"
41#endif
42
43#if defined (WINDOWSNT) || defined (HAVE_NTGUI)
44#include "w32select.h"
45#include "w32font.h"
46#endif
47
48#if defined (HAVE_NTGUI) && defined (CYGWIN)
49#include "cygw32.h"
39#endif 50#endif
40 51
41#ifdef HAVE_WINDOW_SYSTEM 52#ifdef HAVE_WINDOW_SYSTEM
@@ -156,6 +167,22 @@ static void *my_heap_start;
156static uprintmax_t heap_bss_diff; 167static uprintmax_t heap_bss_diff;
157#endif 168#endif
158 169
170/* To run as a daemon under Cocoa or Windows, we must do a fork+exec,
171 not a simple fork.
172
173 On Cocoa, CoreFoundation lib fails in forked process:
174 http://developer.apple.com/ReleaseNotes/
175 CoreFoundation/CoreFoundation.html)
176
177 On Windows, a Cygwin fork child cannot access the USER subsystem.
178
179 We mark being in the exec'd process by a daemon name argument of
180 form "--daemon=\nFD0,FD1\nNAME" where FD are the pipe file descriptors,
181 NAME is the original daemon name, if any. */
182#if defined (NS_IMPL_COCOA) || (defined (HAVE_NTGUI) && defined (CYGWIN))
183# define DAEMON_MUST_EXEC
184#endif
185
159/* True means running Emacs without interactive terminal. */ 186/* True means running Emacs without interactive terminal. */
160bool noninteractive; 187bool noninteractive;
161 188
@@ -669,9 +696,9 @@ main (int argc, char **argv)
669 bool no_loadup = 0; 696 bool no_loadup = 0;
670 char *junk = 0; 697 char *junk = 0;
671 char *dname_arg = 0; 698 char *dname_arg = 0;
672#ifdef NS_IMPL_COCOA 699#ifdef DAEMON_MUST_EXEC
673 char dname_arg2[80]; 700 char dname_arg2[80];
674#endif 701#endif /* DAEMON_MUST_EXEC */
675 char *ch_to_dir; 702 char *ch_to_dir;
676 703
677#if GC_MARK_STACK 704#if GC_MARK_STACK
@@ -964,25 +991,19 @@ main (int argc, char **argv)
964 exit (1); 991 exit (1);
965 } 992 }
966 993
967#ifndef NS_IMPL_COCOA 994#ifndef DAEMON_MUST_EXEC
968#ifdef USE_GTK 995#ifdef USE_GTK
969 fprintf (stderr, "\nWarning: due to a long standing Gtk+ bug\nhttp://bugzilla.gnome.org/show_bug.cgi?id=85715\n\ 996 fprintf (stderr, "\nWarning: due to a long standing Gtk+ bug\nhttp://bugzilla.gnome.org/show_bug.cgi?id=85715\n\
970Emacs might crash when run in daemon mode and the X11 connection is unexpectedly lost.\n\ 997Emacs might crash when run in daemon mode and the X11 connection is unexpectedly lost.\n\
971Using an Emacs configured with --with-x-toolkit=lucid does not have this problem.\n"); 998Using an Emacs configured with --with-x-toolkit=lucid does not have this problem.\n");
972#endif 999#endif /* USE_GTK */
973 f = fork (); 1000 f = fork ();
974#else /* NS_IMPL_COCOA */ 1001#else /* DAEMON_MUST_EXEC */
975 /* Under Cocoa we must do fork+exec as CoreFoundation lib fails in
976 forked process: http://developer.apple.com/ReleaseNotes/
977 CoreFoundation/CoreFoundation.html)
978 We mark being in the exec'd process by a daemon name argument of
979 form "--daemon=\nFD0,FD1\nNAME" where FD are the pipe file descriptors,
980 NAME is the original daemon name, if any. */
981 if (!dname_arg || !strchr (dname_arg, '\n')) 1002 if (!dname_arg || !strchr (dname_arg, '\n'))
982 f = fork (); /* in orig */ 1003 f = fork (); /* in orig */
983 else 1004 else
984 f = 0; /* in exec'd */ 1005 f = 0; /* in exec'd */
985#endif /* NS_IMPL_COCOA */ 1006#endif /* !DAEMON_MUST_EXEC */
986 if (f > 0) 1007 if (f > 0)
987 { 1008 {
988 int retval; 1009 int retval;
@@ -1018,7 +1039,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1018 exit (1); 1039 exit (1);
1019 } 1040 }
1020 1041
1021#ifdef NS_IMPL_COCOA 1042#ifdef DAEMON_MUST_EXEC
1022 { 1043 {
1023 /* In orig process, forked as child, OR in exec'd. */ 1044 /* In orig process, forked as child, OR in exec'd. */
1024 if (!dname_arg || !strchr (dname_arg, '\n')) 1045 if (!dname_arg || !strchr (dname_arg, '\n'))
@@ -1054,7 +1075,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1054 dname_arg2); 1075 dname_arg2);
1055 dname_arg = *dname_arg2 ? dname_arg2 : NULL; 1076 dname_arg = *dname_arg2 ? dname_arg2 : NULL;
1056 } 1077 }
1057#endif /* NS_IMPL_COCOA */ 1078#endif /* DAEMON_MUST_EXEC */
1058 1079
1059 if (dname_arg) 1080 if (dname_arg)
1060 daemon_name = xstrdup (dname_arg); 1081 daemon_name = xstrdup (dname_arg);
@@ -1357,6 +1378,9 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1357#ifdef WINDOWSNT 1378#ifdef WINDOWSNT
1358 syms_of_ntproc (); 1379 syms_of_ntproc ();
1359#endif /* WINDOWSNT */ 1380#endif /* WINDOWSNT */
1381#if defined (CYGWIN) && defined (HAVE_NTGUI)
1382 syms_of_cygw32 ();
1383#endif /* defined(CYGWIN) && defined (HAVE_NTGUI) */
1360 syms_of_window (); 1384 syms_of_window ();
1361 syms_of_xdisp (); 1385 syms_of_xdisp ();
1362 syms_of_font (); 1386 syms_of_font ();
@@ -1387,11 +1411,14 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1387#ifdef HAVE_NTGUI 1411#ifdef HAVE_NTGUI
1388 syms_of_w32term (); 1412 syms_of_w32term ();
1389 syms_of_w32fns (); 1413 syms_of_w32fns ();
1390 syms_of_w32select ();
1391 syms_of_w32menu (); 1414 syms_of_w32menu ();
1392 syms_of_fontset (); 1415 syms_of_fontset ();
1393#endif /* HAVE_NTGUI */ 1416#endif /* HAVE_NTGUI */
1394 1417
1418#ifdef HAVE_W32SELECT
1419 syms_of_w32select ();
1420#endif /* HAVE_W32SELECT */
1421
1395#ifdef MSDOS 1422#ifdef MSDOS
1396 syms_of_xmenu (); 1423 syms_of_xmenu ();
1397 syms_of_dosfns (); 1424 syms_of_dosfns ();
@@ -1437,8 +1464,11 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1437 globals_of_w32font (); 1464 globals_of_w32font ();
1438 globals_of_w32fns (); 1465 globals_of_w32fns ();
1439 globals_of_w32menu (); 1466 globals_of_w32menu ();
1440 globals_of_w32select ();
1441#endif /* HAVE_NTGUI */ 1467#endif /* HAVE_NTGUI */
1468
1469#ifdef HAVE_W32SELECT
1470 globals_of_w32select ();
1471#endif /* HAVE_W32SELECT */
1442 } 1472 }
1443 1473
1444 init_charset (); 1474 init_charset ();
diff --git a/src/font.c b/src/font.c
index 1f22fee88ee..629e8bb977a 100644
--- a/src/font.c
+++ b/src/font.c
@@ -5208,9 +5208,9 @@ EMACS_FONT_LOG is set. Otherwise, it is set to t. */);
5208#ifdef HAVE_BDFFONT 5208#ifdef HAVE_BDFFONT
5209 syms_of_bdffont (); 5209 syms_of_bdffont ();
5210#endif /* HAVE_BDFFONT */ 5210#endif /* HAVE_BDFFONT */
5211#ifdef WINDOWSNT 5211#ifdef HAVE_NTGUI
5212 syms_of_w32font (); 5212 syms_of_w32font ();
5213#endif /* WINDOWSNT */ 5213#endif /* HAVE_NTGUI */
5214#ifdef HAVE_NS 5214#ifdef HAVE_NS
5215 syms_of_nsfont (); 5215 syms_of_nsfont ();
5216#endif /* HAVE_NS */ 5216#endif /* HAVE_NS */
diff --git a/src/font.h b/src/font.h
index 0475eb665dd..3035a909efc 100644
--- a/src/font.h
+++ b/src/font.h
@@ -23,6 +23,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
23#define EMACS_FONT_H 23#define EMACS_FONT_H
24 24
25#include "ccl.h" 25#include "ccl.h"
26#include "frame.h"
26 27
27/* We have three types of Lisp objects related to font. 28/* We have three types of Lisp objects related to font.
28 29
@@ -818,11 +819,11 @@ extern struct font_driver ftxfont_driver;
818extern void syms_of_bdffont (void); 819extern void syms_of_bdffont (void);
819#endif /* HAVE_BDFFONT */ 820#endif /* HAVE_BDFFONT */
820#endif /* HAVE_X_WINDOWS */ 821#endif /* HAVE_X_WINDOWS */
821#ifdef WINDOWSNT 822#ifdef HAVE_NTGUI
822extern struct font_driver w32font_driver; 823extern struct font_driver w32font_driver;
823extern struct font_driver uniscribe_font_driver; 824extern struct font_driver uniscribe_font_driver;
824extern void syms_of_w32font (void); 825extern void syms_of_w32font (void);
825#endif /* WINDOWSNT */ 826#endif /* HAVE_NTGUI */
826#ifdef HAVE_NS 827#ifdef HAVE_NS
827extern Lisp_Object Qfontsize; 828extern Lisp_Object Qfontsize;
828extern struct font_driver nsfont_driver; 829extern struct font_driver nsfont_driver;
diff --git a/src/fontset.c b/src/fontset.c
index 7b051cbe1f3..da745b31ca1 100644
--- a/src/fontset.c
+++ b/src/fontset.c
@@ -42,7 +42,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
42#ifdef HAVE_X_WINDOWS 42#ifdef HAVE_X_WINDOWS
43#include "xterm.h" 43#include "xterm.h"
44#endif 44#endif
45#ifdef WINDOWSNT 45#ifdef HAVE_NTGUI
46#include "w32term.h" 46#include "w32term.h"
47#endif 47#endif
48#ifdef HAVE_NS 48#ifdef HAVE_NS
diff --git a/src/frame.c b/src/frame.c
index 2fcf7275f9c..599d8879169 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -2697,7 +2697,7 @@ static const struct frame_parm_table frame_parms[] =
2697 {"tool-bar-position", &Qtool_bar_position}, 2697 {"tool-bar-position", &Qtool_bar_position},
2698}; 2698};
2699 2699
2700#ifdef WINDOWSNT 2700#ifdef HAVE_NTGUI
2701 2701
2702/* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the 2702/* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
2703 wanted positions of the WM window (not Emacs window). 2703 wanted positions of the WM window (not Emacs window).
@@ -2741,7 +2741,7 @@ x_fullscreen_adjust (struct frame *f, int *width, int *height, int *top_pos, int
2741 *height = newheight; 2741 *height = newheight;
2742} 2742}
2743 2743
2744#endif /* WINDOWSNT */ 2744#endif /* HAVE_NTGUI */
2745 2745
2746#ifdef HAVE_WINDOW_SYSTEM 2746#ifdef HAVE_WINDOW_SYSTEM
2747 2747
diff --git a/src/frame.h b/src/frame.h
index 26235cc036e..7bf76c21c56 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -618,7 +618,7 @@ typedef struct frame *FRAME_PTR;
618#define FRAME_INITIAL_P(f) ((f)->output_method == output_initial) 618#define FRAME_INITIAL_P(f) ((f)->output_method == output_initial)
619#define FRAME_TERMCAP_P(f) ((f)->output_method == output_termcap) 619#define FRAME_TERMCAP_P(f) ((f)->output_method == output_termcap)
620#define FRAME_X_P(f) ((f)->output_method == output_x_window) 620#define FRAME_X_P(f) ((f)->output_method == output_x_window)
621#ifndef WINDOWSNT 621#ifndef HAVE_NTGUI
622#define FRAME_W32_P(f) (0) 622#define FRAME_W32_P(f) (0)
623#else 623#else
624#define FRAME_W32_P(f) ((f)->output_method == output_w32) 624#define FRAME_W32_P(f) ((f)->output_method == output_w32)
@@ -1210,7 +1210,7 @@ extern Lisp_Object x_new_font (struct frame *, Lisp_Object, int);
1210 1210
1211extern Lisp_Object Qface_set_after_frame_default; 1211extern Lisp_Object Qface_set_after_frame_default;
1212 1212
1213#ifdef WINDOWSNT 1213#ifdef HAVE_NTGUI
1214extern void x_fullscreen_adjust (struct frame *f, int *, int *, 1214extern void x_fullscreen_adjust (struct frame *f, int *, int *,
1215 int *, int *); 1215 int *, int *);
1216#endif 1216#endif
@@ -1282,6 +1282,7 @@ extern char *x_get_resource_string (const char *, const char *);
1282#endif 1282#endif
1283 1283
1284extern void x_query_colors (struct frame *f, XColor *, int); 1284extern void x_query_colors (struct frame *f, XColor *, int);
1285extern void x_query_color (struct frame *f, XColor *);
1285 1286
1286#endif /* HAVE_WINDOW_SYSTEM */ 1287#endif /* HAVE_WINDOW_SYSTEM */
1287 1288
diff --git a/src/image.c b/src/image.c
index 91eeb91920c..6058bdf444c 100644
--- a/src/image.c
+++ b/src/image.c
@@ -75,7 +75,11 @@ typedef struct x_bitmap_record Bitmap_Record;
75#endif /* HAVE_X_WINDOWS */ 75#endif /* HAVE_X_WINDOWS */
76 76
77#ifdef HAVE_NTGUI 77#ifdef HAVE_NTGUI
78#include "w32.h" 78# ifdef WINDOWSNT
79/* We only need (or want) w32.h when we're _not_
80 * compiling for Cygwin */
81# include "w32.h"
82# endif /* WINDOWSNT */
79/* W32_TODO : Color tables on W32. */ 83/* W32_TODO : Color tables on W32. */
80#undef COLOR_TABLE_SUPPORT 84#undef COLOR_TABLE_SUPPORT
81 85
@@ -560,13 +564,14 @@ static struct image_type *lookup_image_type (Lisp_Object);
560static void x_laplace (struct frame *, struct image *); 564static void x_laplace (struct frame *, struct image *);
561static void x_emboss (struct frame *, struct image *); 565static void x_emboss (struct frame *, struct image *);
562static void x_build_heuristic_mask (struct frame *, struct image *, 566static void x_build_heuristic_mask (struct frame *, struct image *,
563 Lisp_Object); 567 Lisp_Object);
564#ifdef HAVE_NTGUI 568#ifdef WINDOWSNT
569extern Lisp_Object Vlibrary_cache;
565#define CACHE_IMAGE_TYPE(type, status) \ 570#define CACHE_IMAGE_TYPE(type, status) \
566 do { Vlibrary_cache = Fcons (Fcons (type, status), Vlibrary_cache); } while (0) 571 do { Vlibrary_cache = Fcons (Fcons (type, status), Vlibrary_cache); } while (0)
567#else 572#else
568#define CACHE_IMAGE_TYPE(type, status) 573#define CACHE_IMAGE_TYPE(type, status)
569#endif 574#endif /* WINDOWSNT */
570 575
571#define ADD_IMAGE_TYPE(type) \ 576#define ADD_IMAGE_TYPE(type) \
572 do { Vimage_types = Fcons (type, Vimage_types); } while (0) 577 do { Vimage_types = Fcons (type, Vimage_types); } while (0)
@@ -589,7 +594,7 @@ define_image_type (struct image_type *type)
589 594
590 if (type->init) 595 if (type->init)
591 { 596 {
592#ifdef HAVE_NTGUI 597#if defined (HAVE_NTGUI) && defined (WINDOWSNT)
593 /* If we failed to load the library before, don't try again. */ 598 /* If we failed to load the library before, don't try again. */
594 Lisp_Object tested = Fassq (target_type, Vlibrary_cache); 599 Lisp_Object tested = Fassq (target_type, Vlibrary_cache);
595 if (CONSP (tested) && NILP (XCDR (tested))) 600 if (CONSP (tested) && NILP (XCDR (tested)))
@@ -1834,7 +1839,7 @@ mark_image_cache (struct image_cache *c)
1834 X / NS / W32 support code 1839 X / NS / W32 support code
1835 ***********************************************************************/ 1840 ***********************************************************************/
1836 1841
1837#ifdef HAVE_NTGUI 1842#ifdef WINDOWSNT
1838 1843
1839/* Macro for defining functions that will be loaded from image DLLs. */ 1844/* Macro for defining functions that will be loaded from image DLLs. */
1840#define DEF_IMGLIB_FN(rettype,func,args) static rettype (FAR CDECL *fn_##func)args 1845#define DEF_IMGLIB_FN(rettype,func,args) static rettype (FAR CDECL *fn_##func)args
@@ -1845,7 +1850,7 @@ mark_image_cache (struct image_cache *c)
1845 if (!fn_##func) return 0; \ 1850 if (!fn_##func) return 0; \
1846 } 1851 }
1847 1852
1848#endif /* HAVE_NTGUI */ 1853#endif /* WINDOWSNT */
1849 1854
1850/* Return true if XIMG's size WIDTH x HEIGHT doesn't break the 1855/* Return true if XIMG's size WIDTH x HEIGHT doesn't break the
1851 windowing system. 1856 windowing system.
@@ -2897,7 +2902,7 @@ xbm_load (struct frame *f, struct image *img)
2897 else 2902 else
2898 bits = (char *) XBOOL_VECTOR (data)->data; 2903 bits = (char *) XBOOL_VECTOR (data)->data;
2899 2904
2900#ifdef WINDOWSNT 2905#ifdef HAVE_NTGUI
2901 { 2906 {
2902 char *invertedBits; 2907 char *invertedBits;
2903 int nbytes, i; 2908 int nbytes, i;
@@ -3008,7 +3013,7 @@ static const struct image_keyword xpm_format[XPM_LAST] =
3008 {":background", IMAGE_STRING_OR_NIL_VALUE, 0} 3013 {":background", IMAGE_STRING_OR_NIL_VALUE, 0}
3009}; 3014};
3010 3015
3011#ifdef HAVE_NTGUI 3016#if defined(HAVE_NTGUI) && defined(WINDOWSNT)
3012static bool init_xpm_functions (void); 3017static bool init_xpm_functions (void);
3013#else 3018#else
3014#define init_xpm_functions NULL 3019#define init_xpm_functions NULL
@@ -3207,7 +3212,7 @@ xpm_free_colors (Display *dpy, Colormap cmap, Pixel *pixels, int npixels, void *
3207#endif /* ALLOC_XPM_COLORS */ 3212#endif /* ALLOC_XPM_COLORS */
3208 3213
3209 3214
3210#ifdef HAVE_NTGUI 3215#ifdef WINDOWSNT
3211 3216
3212/* XPM library details. */ 3217/* XPM library details. */
3213 3218
@@ -3233,8 +3238,15 @@ init_xpm_functions (void)
3233 return 1; 3238 return 1;
3234} 3239}
3235 3240
3236#endif /* HAVE_NTGUI */ 3241#endif /* WINDOWSNT */
3237 3242
3243#if defined (HAVE_NTGUI) && !defined (WINDOWSNT)
3244/* Glue for code below */
3245#define fn_XpmReadFileToImage XpmReadFileToImage
3246#define fn_XpmCreateImageFromBuffer XpmCreateImageFromBuffer
3247#define fn_XImageFree XImageFree
3248#define fn_XpmFreeAttributes XpmFreeAttributes
3249#endif /* HAVE_NTGUI && !WINDOWSNT */
3238 3250
3239/* Value is true if COLOR_SYMBOLS is a valid color symbols list 3251/* Value is true if COLOR_SYMBOLS is a valid color symbols list
3240 for XPM images. Such a list must consist of conses whose car and 3252 for XPM images. Such a list must consist of conses whose car and
@@ -5340,7 +5352,7 @@ static const struct image_keyword png_format[PNG_LAST] =
5340 {":background", IMAGE_STRING_OR_NIL_VALUE, 0} 5352 {":background", IMAGE_STRING_OR_NIL_VALUE, 0}
5341}; 5353};
5342 5354
5343#ifdef HAVE_NTGUI 5355#if defined(HAVE_NTGUI) && defined (WINDOWSNT)
5344static bool init_png_functions (void); 5356static bool init_png_functions (void);
5345#else 5357#else
5346#define init_png_functions NULL 5358#define init_png_functions NULL
@@ -5378,7 +5390,7 @@ png_image_p (Lisp_Object object)
5378 5390
5379#ifdef HAVE_PNG 5391#ifdef HAVE_PNG
5380 5392
5381#ifdef HAVE_NTGUI 5393#ifdef WINDOWSNT
5382/* PNG library details. */ 5394/* PNG library details. */
5383 5395
5384DEF_IMGLIB_FN (png_voidp, png_get_io_ptr, (png_structp)); 5396DEF_IMGLIB_FN (png_voidp, png_get_io_ptr, (png_structp));
@@ -5478,7 +5490,7 @@ init_png_functions (void)
5478#define fn_png_set_longjmp_fn png_set_longjmp_fn 5490#define fn_png_set_longjmp_fn png_set_longjmp_fn
5479#endif /* libpng version >= 1.5 */ 5491#endif /* libpng version >= 1.5 */
5480 5492
5481#endif /* HAVE_NTGUI */ 5493#endif /* WINDOWSNT */
5482 5494
5483/* Possibly inefficient/inexact substitutes for _setjmp and _longjmp. 5495/* Possibly inefficient/inexact substitutes for _setjmp and _longjmp.
5484 Do not use sys_setjmp, as PNG supports only jmp_buf. The _longjmp 5496 Do not use sys_setjmp, as PNG supports only jmp_buf. The _longjmp
@@ -5999,7 +6011,7 @@ static const struct image_keyword jpeg_format[JPEG_LAST] =
5999 {":background", IMAGE_STRING_OR_NIL_VALUE, 0} 6011 {":background", IMAGE_STRING_OR_NIL_VALUE, 0}
6000}; 6012};
6001 6013
6002#ifdef HAVE_NTGUI 6014#if defined(HAVE_NTGUI) && defined(WINDOWSNT)
6003static bool init_jpeg_functions (void); 6015static bool init_jpeg_functions (void);
6004#else 6016#else
6005#define init_jpeg_functions NULL 6017#define init_jpeg_functions NULL
@@ -6049,14 +6061,27 @@ jpeg_image_p (Lisp_Object object)
6049#define __WIN32__ 1 6061#define __WIN32__ 1
6050#endif 6062#endif
6051 6063
6064/* rpcndr.h (via windows.h) and jpeglib.h both define boolean types.
6065 Some versions of jpeglib try to detect whether rpcndr.h is loaded,
6066 using the Windows boolean type instead of the jpeglib boolean type
6067 if so. Cygwin jpeglib, however, doesn't try to detect whether its
6068 headers are included along with windows.h, so under Cygwin, jpeglib
6069 attempts to define a conflicting boolean type. Worse, forcing
6070 Cygwin jpeglib headers to use the Windows boolean type doesn't work
6071 because it created an ABI incompatibility between the
6072 already-compiled jpeg library and the header interface definition.
6073
6074 The best we can do is to define jpeglib's boolean type to a
6075 different name. This name, jpeg_boolean, remains in effect through
6076 the rest of image.c.
6077*/
6078#if defined (CYGWIN) && defined (HAVE_NTGUI)
6079#define boolean jpeg_boolean
6080#endif
6052#include <jpeglib.h> 6081#include <jpeglib.h>
6053#include <jerror.h> 6082#include <jerror.h>
6054 6083
6055#ifdef HAVE_STLIB_H_1 6084#ifdef WINDOWSNT
6056#define HAVE_STDLIB_H 1
6057#endif
6058
6059#ifdef HAVE_NTGUI
6060 6085
6061/* JPEG library details. */ 6086/* JPEG library details. */
6062DEF_IMGLIB_FN (void, jpeg_CreateDecompress, (j_decompress_ptr, int, size_t)); 6087DEF_IMGLIB_FN (void, jpeg_CreateDecompress, (j_decompress_ptr, int, size_t));
@@ -6106,7 +6131,7 @@ jpeg_resync_to_restart_wrapper (j_decompress_ptr cinfo, int desired)
6106#define fn_jpeg_std_error jpeg_std_error 6131#define fn_jpeg_std_error jpeg_std_error
6107#define jpeg_resync_to_restart_wrapper jpeg_resync_to_restart 6132#define jpeg_resync_to_restart_wrapper jpeg_resync_to_restart
6108 6133
6109#endif /* HAVE_NTGUI */ 6134#endif /* WINDOWSNT */
6110 6135
6111struct my_jpeg_error_mgr 6136struct my_jpeg_error_mgr
6112{ 6137{
@@ -6630,7 +6655,7 @@ tiff_image_p (Lisp_Object object)
6630 6655
6631#include <tiffio.h> 6656#include <tiffio.h>
6632 6657
6633#ifdef HAVE_NTGUI 6658#ifdef WINDOWSNT
6634 6659
6635/* TIFF library details. */ 6660/* TIFF library details. */
6636DEF_IMGLIB_FN (TIFFErrorHandler, TIFFSetErrorHandler, (TIFFErrorHandler)); 6661DEF_IMGLIB_FN (TIFFErrorHandler, TIFFSetErrorHandler, (TIFFErrorHandler));
@@ -6674,7 +6699,7 @@ init_tiff_functions (void)
6674#define fn_TIFFReadRGBAImage TIFFReadRGBAImage 6699#define fn_TIFFReadRGBAImage TIFFReadRGBAImage
6675#define fn_TIFFClose TIFFClose 6700#define fn_TIFFClose TIFFClose
6676#define fn_TIFFSetDirectory TIFFSetDirectory 6701#define fn_TIFFSetDirectory TIFFSetDirectory
6677#endif /* HAVE_NTGUI */ 6702#endif /* WINDOWSNT */
6678 6703
6679 6704
6680/* Reading from a memory buffer for TIFF images Based on the PNG 6705/* Reading from a memory buffer for TIFF images Based on the PNG
@@ -7046,7 +7071,7 @@ static const struct image_keyword gif_format[GIF_LAST] =
7046 {":background", IMAGE_STRING_OR_NIL_VALUE, 0} 7071 {":background", IMAGE_STRING_OR_NIL_VALUE, 0}
7047}; 7072};
7048 7073
7049#ifdef HAVE_NTGUI 7074#if defined(HAVE_NTGUI) && defined(WINDOWSNT)
7050static bool init_gif_functions (void); 7075static bool init_gif_functions (void);
7051#else 7076#else
7052#define init_gif_functions NULL 7077#define init_gif_functions NULL
@@ -7110,7 +7135,7 @@ gif_image_p (Lisp_Object object)
7110#endif /* HAVE_NTGUI */ 7135#endif /* HAVE_NTGUI */
7111 7136
7112 7137
7113#ifdef HAVE_NTGUI 7138#ifdef WINDOWSNT
7114 7139
7115/* GIF library details. */ 7140/* GIF library details. */
7116DEF_IMGLIB_FN (int, DGifCloseFile, (GifFileType *)); 7141DEF_IMGLIB_FN (int, DGifCloseFile, (GifFileType *));
@@ -7140,7 +7165,7 @@ init_gif_functions (void)
7140#define fn_DGifOpen DGifOpen 7165#define fn_DGifOpen DGifOpen
7141#define fn_DGifOpenFileName DGifOpenFileName 7166#define fn_DGifOpenFileName DGifOpenFileName
7142 7167
7143#endif /* HAVE_NTGUI */ 7168#endif /* WINDOWSNT */
7144 7169
7145/* Reading a GIF image from memory 7170/* Reading a GIF image from memory
7146 Based on the PNG memory stuff to a certain extent. */ 7171 Based on the PNG memory stuff to a certain extent. */
@@ -8137,7 +8162,7 @@ svg_image_p (Lisp_Object object)
8137 8162
8138#include <librsvg/rsvg.h> 8163#include <librsvg/rsvg.h>
8139 8164
8140#ifdef HAVE_NTGUI 8165#ifdef WINDOWSNT
8141 8166
8142/* SVG library functions. */ 8167/* SVG library functions. */
8143DEF_IMGLIB_FN (RsvgHandle *, rsvg_handle_new); 8168DEF_IMGLIB_FN (RsvgHandle *, rsvg_handle_new);
@@ -8215,7 +8240,7 @@ init_svg_functions (void)
8215#define fn_g_type_init g_type_init 8240#define fn_g_type_init g_type_init
8216#define fn_g_object_unref g_object_unref 8241#define fn_g_object_unref g_object_unref
8217#define fn_g_error_free g_error_free 8242#define fn_g_error_free g_error_free
8218#endif /* !HAVE_NTGUI */ 8243#endif /* !WINDOWSNT */
8219 8244
8220/* Load SVG image IMG for use on frame F. Value is true if 8245/* Load SVG image IMG for use on frame F. Value is true if
8221 successful. */ 8246 successful. */
diff --git a/src/keyboard.c b/src/keyboard.c
index ad0c5db0fc3..8316223cd28 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -313,8 +313,11 @@ static Lisp_Object Qmouse_fixup_help_message;
313/* Symbols to denote kinds of events. */ 313/* Symbols to denote kinds of events. */
314static Lisp_Object Qfunction_key; 314static Lisp_Object Qfunction_key;
315Lisp_Object Qmouse_click; 315Lisp_Object Qmouse_click;
316#if defined (WINDOWSNT) 316#if defined (HAVE_NTGUI)
317Lisp_Object Qlanguage_change, Qfile_notify; 317Lisp_Object Qlanguage_change;
318#ifdef WINDOWSNT
319Lisp_Object Qfile_notify;
320#endif
318#endif 321#endif
319static Lisp_Object Qdrag_n_drop; 322static Lisp_Object Qdrag_n_drop;
320static Lisp_Object Qsave_session; 323static Lisp_Object Qsave_session;
@@ -3766,8 +3769,8 @@ kbd_buffer_get_event (KBOARD **kbp,
3766#ifdef subprocesses 3769#ifdef subprocesses
3767 if (kbd_on_hold_p () && kbd_buffer_nr_stored () < KBD_BUFFER_SIZE/4) 3770 if (kbd_on_hold_p () && kbd_buffer_nr_stored () < KBD_BUFFER_SIZE/4)
3768 { 3771 {
3769 /* Start reading input again, we have processed enough so we can 3772 /* Start reading input again because we have processed enough to
3770 accept new events again. */ 3773 be able to accept new events again. */
3771 unhold_keyboard_input (); 3774 unhold_keyboard_input ();
3772 start_polling (); 3775 start_polling ();
3773 } 3776 }
@@ -3947,7 +3950,7 @@ kbd_buffer_get_event (KBOARD **kbp,
3947 x_activate_menubar (XFRAME (event->frame_or_window)); 3950 x_activate_menubar (XFRAME (event->frame_or_window));
3948 } 3951 }
3949#endif 3952#endif
3950#if defined (WINDOWSNT) 3953#if defined (HAVE_NTGUI)
3951 else if (event->kind == LANGUAGE_CHANGE_EVENT) 3954 else if (event->kind == LANGUAGE_CHANGE_EVENT)
3952 { 3955 {
3953 /* Make an event (language-change (FRAME CODEPAGE LANGUAGE-ID)). */ 3956 /* Make an event (language-change (FRAME CODEPAGE LANGUAGE-ID)). */
@@ -5427,7 +5430,7 @@ make_lispy_event (struct input_event *event)
5427 (sizeof (lispy_function_keys) 5430 (sizeof (lispy_function_keys)
5428 / sizeof (lispy_function_keys[0]))); 5431 / sizeof (lispy_function_keys[0])));
5429 5432
5430#ifdef WINDOWSNT 5433#ifdef HAVE_NTGUI
5431 case MULTIMEDIA_KEY_EVENT: 5434 case MULTIMEDIA_KEY_EVENT:
5432 if (event->code < (sizeof (lispy_multimedia_keys) 5435 if (event->code < (sizeof (lispy_multimedia_keys)
5433 / sizeof (lispy_multimedia_keys[0])) 5436 / sizeof (lispy_multimedia_keys[0]))
@@ -11404,7 +11407,7 @@ syms_of_keyboard (void)
11404 DEFSYM (Qconfig_changed_event, "config-changed-event"); 11407 DEFSYM (Qconfig_changed_event, "config-changed-event");
11405 DEFSYM (Qmenu_enable, "menu-enable"); 11408 DEFSYM (Qmenu_enable, "menu-enable");
11406 11409
11407#if defined (WINDOWSNT) 11410#if defined (HAVE_NTGUI)
11408 DEFSYM (Qlanguage_change, "language-change"); 11411 DEFSYM (Qlanguage_change, "language-change");
11409 DEFSYM (Qfile_notify, "file-notify"); 11412 DEFSYM (Qfile_notify, "file-notify");
11410#endif 11413#endif
diff --git a/src/keyboard.h b/src/keyboard.h
index bc35bba4ecc..d78c27fbf9b 100644
--- a/src/keyboard.h
+++ b/src/keyboard.h
@@ -551,7 +551,7 @@ extern int tty_read_avail_input (struct terminal *, struct input_event *);
551extern EMACS_TIME timer_check (void); 551extern EMACS_TIME timer_check (void);
552extern void mark_kboards (void); 552extern void mark_kboards (void);
553 553
554#ifdef WINDOWSNT 554#ifdef HAVE_NTGUI
555extern const char *const lispy_function_keys[]; 555extern const char *const lispy_function_keys[];
556#endif 556#endif
557 557
diff --git a/src/makefile.w32-in b/src/makefile.w32-in
index f051ed6a8a9..5fc5b6ece46 100644
--- a/src/makefile.w32-in
+++ b/src/makefile.w32-in
@@ -208,7 +208,7 @@ make-buildobj-SH:
208GLOBAL_SOURCES = dosfns.c msdos.c \ 208GLOBAL_SOURCES = dosfns.c msdos.c \
209 xterm.c xfns.c xmenu.c xselect.c xrdb.c xsmfns.c fringe.c image.c \ 209 xterm.c xfns.c xmenu.c xselect.c xrdb.c xsmfns.c fringe.c image.c \
210 fontset.c menu.c dbusbind.c \ 210 fontset.c menu.c dbusbind.c \
211 w32.c w32console.c w32fns.c w32heap.c w32inevt.c \ 211 w32.c w32console.c w32fns.c w32heap.c w32inevt.c cygw32.c \
212 w32menu.c w32proc.c w32reg.c w32select.c w32term.c w32xfns.c \ 212 w32menu.c w32proc.c w32reg.c w32select.c w32term.c w32xfns.c \
213 font.c w32font.c w32uniscribe.c w32notify.c \ 213 font.c w32font.c w32uniscribe.c w32notify.c \
214 dispnew.c frame.c scroll.c xdisp.c window.c bidi.c \ 214 dispnew.c frame.c scroll.c xdisp.c window.c bidi.c \
@@ -425,6 +425,7 @@ DISPEXTERN_H = $(SRC)/dispextern.h \
425FILEMODE_H = $(GNU_LIB)/filemode.h \ 425FILEMODE_H = $(GNU_LIB)/filemode.h \
426 $(NT_INC)/sys/stat.h 426 $(NT_INC)/sys/stat.h
427FONT_H = $(SRC)/font.h \ 427FONT_H = $(SRC)/font.h \
428 $(FRAME_H) \
428 $(CCL_H) 429 $(CCL_H)
429FRAME_H = $(SRC)/frame.h \ 430FRAME_H = $(SRC)/frame.h \
430 $(DISPEXTERN_H) 431 $(DISPEXTERN_H)
@@ -477,6 +478,8 @@ TERMHOOKS_H = $(SRC)/termhooks.h \
477W32FONT_H = $(SRC)/w32font.h \ 478W32FONT_H = $(SRC)/w32font.h \
478 $(FONT_H) 479 $(FONT_H)
479W32TERM_H = $(SRC)/w32term.h \ 480W32TERM_H = $(SRC)/w32term.h \
481 $(ATIMER_H) \
482 $(FRAME_H) \
480 $(W32GUI_H) 483 $(W32GUI_H)
481WINDOW_H = $(SRC)/window.h \ 484WINDOW_H = $(SRC)/window.h \
482 $(DISPEXTERN_H) 485 $(DISPEXTERN_H)
@@ -797,6 +800,8 @@ $(BLD)/emacs.$(O) : \
797 $(SRC)/unexec.h \ 800 $(SRC)/unexec.h \
798 $(SRC)/w32.h \ 801 $(SRC)/w32.h \
799 $(SRC)/w32heap.h \ 802 $(SRC)/w32heap.h \
803 $(SRC)/w32select.h \
804 $(SRC)/w32font.h \
800 $(NT_INC)/sys/file.h \ 805 $(NT_INC)/sys/file.h \
801 $(NT_INC)/unistd.h \ 806 $(NT_INC)/unistd.h \
802 $(GNU_LIB)/ignore-value.h \ 807 $(GNU_LIB)/ignore-value.h \
@@ -1234,6 +1239,7 @@ $(BLD)/w32console.$(O) : \
1234 $(FRAME_H) \ 1239 $(FRAME_H) \
1235 $(LISP_H) \ 1240 $(LISP_H) \
1236 $(TERMHOOKS_H) \ 1241 $(TERMHOOKS_H) \
1242 $(W32TERM_H) \
1237 $(WINDOW_H) 1243 $(WINDOW_H)
1238 1244
1239$(BLD)/print.$(O) : \ 1245$(BLD)/print.$(O) : \
diff --git a/src/menu.c b/src/menu.c
index 5374aa9157a..835267b2f0c 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -40,7 +40,11 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
40#endif /* HAVE_WINDOW_SYSTEM */ 40#endif /* HAVE_WINDOW_SYSTEM */
41 41
42#ifdef HAVE_NTGUI 42#ifdef HAVE_NTGUI
43# ifdef NTGUI_UNICODE
44# define unicode_append_menu AppendMenuW
45# else /* !NTGUI_UNICODE */
43extern AppendMenuW_Proc unicode_append_menu; 46extern AppendMenuW_Proc unicode_append_menu;
47# endif /* NTGUI_UNICODE */
44extern HMENU current_popup_menu; 48extern HMENU current_popup_menu;
45#endif /* HAVE_NTGUI */ 49#endif /* HAVE_NTGUI */
46 50
diff --git a/src/process.c b/src/process.c
index 92bea0d3a27..c941a196539 100644
--- a/src/process.c
+++ b/src/process.c
@@ -4646,6 +4646,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4646 process_output_skip = 0; 4646 process_output_skip = 0;
4647 } 4647 }
4648#endif 4648#endif
4649
4649#if defined (USE_GTK) || defined (HAVE_GCONF) || defined (HAVE_GSETTINGS) 4650#if defined (USE_GTK) || defined (HAVE_GCONF) || defined (HAVE_GSETTINGS)
4650 nfds = xg_select 4651 nfds = xg_select
4651#elif defined (HAVE_NS) 4652#elif defined (HAVE_NS)
diff --git a/src/ralloc.c b/src/ralloc.c
index e4a8fe9c6da..11897411930 100644
--- a/src/ralloc.c
+++ b/src/ralloc.c
@@ -327,10 +327,11 @@ relinquish (void)
327 327
328 if ((char *)last_heap->end - (char *)last_heap->bloc_start <= excess) 328 if ((char *)last_heap->end - (char *)last_heap->bloc_start <= excess)
329 { 329 {
330 /* This heap should have no blocs in it. */ 330 /* This heap should have no blocs in it. If it does, we
331 cannot return it to the system. */
331 if (last_heap->first_bloc != NIL_BLOC 332 if (last_heap->first_bloc != NIL_BLOC
332 || last_heap->last_bloc != NIL_BLOC) 333 || last_heap->last_bloc != NIL_BLOC)
333 emacs_abort (); 334 return;
334 335
335 /* Return the last heap, with its header, to the system. */ 336 /* Return the last heap, with its header, to the system. */
336 excess = (char *)last_heap->end - (char *)last_heap->start; 337 excess = (char *)last_heap->end - (char *)last_heap->start;
diff --git a/src/termhooks.h b/src/termhooks.h
index 0afd7d97e7b..285a1824ecb 100644
--- a/src/termhooks.h
+++ b/src/termhooks.h
@@ -107,9 +107,9 @@ enum event_kind
107 HORIZ_WHEEL_EVENT, /* A wheel event generated by a second 107 HORIZ_WHEEL_EVENT, /* A wheel event generated by a second
108 horizontal wheel that is present on some 108 horizontal wheel that is present on some
109 mice. See WHEEL_EVENT. */ 109 mice. See WHEEL_EVENT. */
110#if defined (WINDOWSNT) 110#if defined (HAVE_NTGUI)
111 LANGUAGE_CHANGE_EVENT, /* A LANGUAGE_CHANGE_EVENT is 111 LANGUAGE_CHANGE_EVENT, /* A LANGUAGE_CHANGE_EVENT is
112 generated on WINDOWSNT or Mac OS 112 generated when HAVE_NTGUI or on Mac OS
113 when the keyboard layout or input 113 when the keyboard layout or input
114 language is changed by the 114 language is changed by the
115 user. */ 115 user. */
@@ -188,7 +188,7 @@ enum event_kind
188 188
189 , CONFIG_CHANGED_EVENT 189 , CONFIG_CHANGED_EVENT
190 190
191#ifdef WINDOWSNT 191#ifdef HAVE_NTGUI
192 /* Generated when an APPCOMMAND event is received, in response to 192 /* Generated when an APPCOMMAND event is received, in response to
193 Multimedia or Internet buttons on some keyboards. 193 Multimedia or Internet buttons on some keyboards.
194 Such keys are available as normal function keys on X through the 194 Such keys are available as normal function keys on X through the
diff --git a/src/unexw32.c b/src/unexw32.c
index 3eefc9ce058..d57378b2421 100644
--- a/src/unexw32.c
+++ b/src/unexw32.c
@@ -83,7 +83,7 @@ DWORD_PTR extra_bss_size_static = 0;
83PIMAGE_SECTION_HEADER heap_section; 83PIMAGE_SECTION_HEADER heap_section;
84 84
85#ifdef HAVE_NTGUI 85#ifdef HAVE_NTGUI
86HINSTANCE hinst = NULL; 86extern HINSTANCE hinst;
87HINSTANCE hprevinst = NULL; 87HINSTANCE hprevinst = NULL;
88LPSTR lpCmdLine = ""; 88LPSTR lpCmdLine = "";
89int nCmdShow = 0; 89int nCmdShow = 0;
diff --git a/src/w32.c b/src/w32.c
index f17c06ea807..85210cb8e4c 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -31,13 +31,13 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
31#include <sys/file.h> 31#include <sys/file.h>
32#include <sys/time.h> 32#include <sys/time.h>
33#include <sys/utime.h> 33#include <sys/utime.h>
34#include <mbstring.h> /* for _mbspbrk */
35#include <math.h> 34#include <math.h>
36#include <time.h> 35#include <time.h>
37 36
38/* must include CRT headers *before* config.h */ 37/* must include CRT headers *before* config.h */
39 38
40#include <config.h> 39#include <config.h>
40#include <mbstring.h> /* for _mbspbrk */
41 41
42#undef access 42#undef access
43#undef chdir 43#undef chdir
@@ -866,23 +866,6 @@ create_symbolic_link (LPTSTR lpSymlinkFilename,
866 return retval; 866 return retval;
867} 867}
868 868
869/* Equivalent of strerror for W32 error codes. */
870char *
871w32_strerror (int error_no)
872{
873 static char buf[500];
874
875 if (error_no == 0)
876 error_no = GetLastError ();
877
878 buf[0] = '\0';
879 if (!FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL,
880 error_no,
881 0, /* choose most suitable language */
882 buf, sizeof (buf), NULL))
883 sprintf (buf, "w32 error %u", error_no);
884 return buf;
885}
886 869
887/* Return 1 if P is a valid pointer to an object of size SIZE. Return 870/* Return 1 if P is a valid pointer to an object of size SIZE. Return
888 0 if P is NOT a valid pointer. Return -1 if we cannot validate P. 871 0 if P is NOT a valid pointer. Return -1 if we cannot validate P.
diff --git a/src/w32.h b/src/w32.h
index 2e2315e245d..c4cfdf5fedd 100644
--- a/src/w32.h
+++ b/src/w32.h
@@ -19,6 +19,12 @@ GNU General Public License for more details.
19You should have received a copy of the GNU General Public License 19You should have received a copy of the GNU General Public License
20along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ 20along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 21
22#ifdef CYGWIN
23#error "w32.h is not compatible with Cygwin"
24#endif
25
26#include <windows.h>
27
22 28
23/* File descriptor set emulation. */ 29/* File descriptor set emulation. */
24 30
@@ -130,17 +136,6 @@ extern LPBYTE w32_get_resource (char * key, LPDWORD type);
130extern void init_ntproc (int); 136extern void init_ntproc (int);
131extern void term_ntproc (int); 137extern void term_ntproc (int);
132extern void globals_of_w32 (void); 138extern void globals_of_w32 (void);
133extern void syms_of_w32term (void);
134extern void syms_of_w32fns (void);
135extern void globals_of_w32fns (void);
136extern void syms_of_w32select (void);
137extern void globals_of_w32select (void);
138extern void term_w32select (void);
139extern void syms_of_w32menu (void);
140extern void globals_of_w32menu (void);
141extern void syms_of_fontset (void);
142extern void syms_of_w32font (void);
143extern void check_windows_init_file (void);
144 139
145extern void term_timers (void); 140extern void term_timers (void);
146extern void init_timers (void); 141extern void init_timers (void);
diff --git a/src/w32console.c b/src/w32console.c
index b22b09af2f2..5a44d3748a2 100644
--- a/src/w32console.c
+++ b/src/w32console.c
@@ -36,6 +36,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
36#include "termhooks.h" 36#include "termhooks.h"
37#include "termchar.h" 37#include "termchar.h"
38#include "dispextern.h" 38#include "dispextern.h"
39#include "w32term.h"
39#include "w32heap.h" /* for os_subtype */ 40#include "w32heap.h" /* for os_subtype */
40#include "w32inevt.h" 41#include "w32inevt.h"
41 42
@@ -430,53 +431,6 @@ w32con_delete_glyphs (struct frame *f, int n)
430 scroll_line (f, n, LEFT); 431 scroll_line (f, n, LEFT);
431} 432}
432 433
433static unsigned int sound_type = 0xFFFFFFFF;
434#define MB_EMACS_SILENT (0xFFFFFFFF - 1)
435
436void
437w32_sys_ring_bell (struct frame *f)
438{
439 if (sound_type == 0xFFFFFFFF)
440 {
441 Beep (666, 100);
442 }
443 else if (sound_type == MB_EMACS_SILENT)
444 {
445 /* Do nothing. */
446 }
447 else
448 MessageBeep (sound_type);
449}
450
451DEFUN ("set-message-beep", Fset_message_beep, Sset_message_beep, 1, 1, 0,
452 doc: /* Set the sound generated when the bell is rung.
453SOUND is 'asterisk, 'exclamation, 'hand, 'question, 'ok, or 'silent
454to use the corresponding system sound for the bell. The 'silent sound
455prevents Emacs from making any sound at all.
456SOUND is nil to use the normal beep. */)
457 (Lisp_Object sound)
458{
459 CHECK_SYMBOL (sound);
460
461 if (NILP (sound))
462 sound_type = 0xFFFFFFFF;
463 else if (EQ (sound, intern ("asterisk")))
464 sound_type = MB_ICONASTERISK;
465 else if (EQ (sound, intern ("exclamation")))
466 sound_type = MB_ICONEXCLAMATION;
467 else if (EQ (sound, intern ("hand")))
468 sound_type = MB_ICONHAND;
469 else if (EQ (sound, intern ("question")))
470 sound_type = MB_ICONQUESTION;
471 else if (EQ (sound, intern ("ok")))
472 sound_type = MB_OK;
473 else if (EQ (sound, intern ("silent")))
474 sound_type = MB_EMACS_SILENT;
475 else
476 sound_type = 0xFFFFFFFF;
477
478 return sound;
479}
480 434
481static void 435static void
482w32con_reset_terminal_modes (struct terminal *t) 436w32con_reset_terminal_modes (struct terminal *t)
@@ -850,5 +804,4 @@ scroll-back buffer. */);
850 defsubr (&Sset_screen_color); 804 defsubr (&Sset_screen_color);
851 defsubr (&Sget_screen_color); 805 defsubr (&Sget_screen_color);
852 defsubr (&Sset_cursor_size); 806 defsubr (&Sset_cursor_size);
853 defsubr (&Sset_message_beep);
854} 807}
diff --git a/src/w32fns.c b/src/w32fns.c
index fac6030b9b5..5833a59497d 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -44,8 +44,14 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
44#include "fontset.h" 44#include "fontset.h"
45#include "systime.h" 45#include "systime.h"
46#include "termhooks.h" 46#include "termhooks.h"
47
47#include "w32heap.h" 48#include "w32heap.h"
49
50#if CYGWIN
51#include "cygw32.h"
52#else
48#include "w32.h" 53#include "w32.h"
54#endif
49 55
50#include "bitmaps/gray.xbm" 56#include "bitmaps/gray.xbm"
51 57
@@ -58,9 +64,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
58 64
59#include <dlgs.h> 65#include <dlgs.h>
60#include <imm.h> 66#include <imm.h>
61#define FILE_NAME_TEXT_FIELD edt1
62#define FILE_NAME_COMBO_BOX cmb13
63#define FILE_NAME_LIST lst1
64 67
65#include "font.h" 68#include "font.h"
66#include "w32font.h" 69#include "w32font.h"
@@ -78,6 +81,7 @@ extern int w32_console_toggle_lock_key (int, Lisp_Object);
78extern void w32_menu_display_help (HWND, HMENU, UINT, UINT); 81extern void w32_menu_display_help (HWND, HMENU, UINT, UINT);
79extern void w32_free_menu_strings (HWND); 82extern void w32_free_menu_strings (HWND);
80extern const char *map_w32_filename (const char *, const char **); 83extern const char *map_w32_filename (const char *, const char **);
84extern char * w32_strerror (int error_no);
81 85
82/* If non-NULL, a handle to a frame where to display the hourglass cursor. */ 86/* If non-NULL, a handle to a frame where to display the hourglass cursor. */
83static HWND hourglass_hwnd = NULL; 87static HWND hourglass_hwnd = NULL;
@@ -161,7 +165,11 @@ ImmSetCompositionWindow_Proc set_ime_composition_window_fn = NULL;
161MonitorFromPoint_Proc monitor_from_point_fn = NULL; 165MonitorFromPoint_Proc monitor_from_point_fn = NULL;
162GetMonitorInfo_Proc get_monitor_info_fn = NULL; 166GetMonitorInfo_Proc get_monitor_info_fn = NULL;
163 167
168#ifdef NTGUI_UNICODE
169#define unicode_append_menu AppendMenuW
170#else /* !NTGUI_UNICODE */
164extern AppendMenuW_Proc unicode_append_menu; 171extern AppendMenuW_Proc unicode_append_menu;
172#endif /* NTGUI_UNICODE */
165 173
166/* Flag to selectively ignore WM_IME_CHAR messages. */ 174/* Flag to selectively ignore WM_IME_CHAR messages. */
167static int ignore_ime_char = 0; 175static int ignore_ime_char = 0;
@@ -198,6 +206,33 @@ extern int uniscribe_available;
198static void w32_show_hourglass (struct frame *); 206static void w32_show_hourglass (struct frame *);
199static void w32_hide_hourglass (void); 207static void w32_hide_hourglass (void);
200 208
209#ifdef WINDOWSNT
210/* From w32inevet.c */
211extern int faked_key;
212#endif /* WINDOWSNT */
213
214/* This gives us the page size and the size of the allocation unit on NT. */
215SYSTEM_INFO sysinfo_cache;
216
217/* This gives us version, build, and platform identification. */
218OSVERSIONINFO osinfo_cache;
219
220unsigned long syspage_mask = 0;
221
222/* The major and minor versions of NT. */
223int w32_major_version;
224int w32_minor_version;
225int w32_build_number;
226
227/* Distinguish between Windows NT and Windows 95. */
228int os_subtype;
229
230#ifdef HAVE_NTGUI
231HINSTANCE hinst = NULL;
232#endif
233
234static unsigned int sound_type = 0xFFFFFFFF;
235#define MB_EMACS_SILENT (0xFFFFFFFF - 1)
201 236
202 237
203/* Error if we are not connected to MS-Windows. */ 238/* Error if we are not connected to MS-Windows. */
@@ -662,7 +697,7 @@ DEFUN ("w32-default-color-map", Fw32_default_color_map, Sw32_default_color_map,
662} 697}
663 698
664static Lisp_Object 699static Lisp_Object
665w32_color_map_lookup (char *colorname) 700w32_color_map_lookup (const char *colorname)
666{ 701{
667 Lisp_Object tail, ret = Qnil; 702 Lisp_Object tail, ret = Qnil;
668 703
@@ -741,7 +776,7 @@ add_system_logical_colors_to_map (Lisp_Object *system_colors)
741 776
742 777
743static Lisp_Object 778static Lisp_Object
744x_to_w32_color (char * colorname) 779x_to_w32_color (const char * colorname)
745{ 780{
746 register Lisp_Object ret = Qnil; 781 register Lisp_Object ret = Qnil;
747 782
@@ -750,11 +785,10 @@ x_to_w32_color (char * colorname)
750 if (colorname[0] == '#') 785 if (colorname[0] == '#')
751 { 786 {
752 /* Could be an old-style RGB Device specification. */ 787 /* Could be an old-style RGB Device specification. */
753 char *color; 788 int size = strlen (colorname + 1);
754 int size; 789 char *color = alloca (size + 1);
755 color = colorname + 1;
756 790
757 size = strlen (color); 791 strcpy (color, colorname + 1);
758 if (size == 3 || size == 6 || size == 9 || size == 12) 792 if (size == 3 || size == 6 || size == 9 || size == 12)
759 { 793 {
760 UINT colorval; 794 UINT colorval;
@@ -808,7 +842,7 @@ x_to_w32_color (char * colorname)
808 } 842 }
809 else if (strnicmp (colorname, "rgb:", 4) == 0) 843 else if (strnicmp (colorname, "rgb:", 4) == 0)
810 { 844 {
811 char *color; 845 const char *color;
812 UINT colorval; 846 UINT colorval;
813 int i, pos; 847 int i, pos;
814 pos = 0; 848 pos = 0;
@@ -864,7 +898,7 @@ x_to_w32_color (char * colorname)
864 else if (strnicmp (colorname, "rgbi:", 5) == 0) 898 else if (strnicmp (colorname, "rgbi:", 5) == 0)
865 { 899 {
866 /* This is an RGB Intensity specification. */ 900 /* This is an RGB Intensity specification. */
867 char *color; 901 const char *color;
868 UINT colorval; 902 UINT colorval;
869 int i, pos; 903 int i, pos;
870 pos = 0; 904 pos = 0;
@@ -1068,7 +1102,7 @@ gamma_correct (struct frame *f, COLORREF *color)
1068 If ALLOC is nonzero, allocate a new colormap cell. */ 1102 If ALLOC is nonzero, allocate a new colormap cell. */
1069 1103
1070int 1104int
1071w32_defined_color (FRAME_PTR f, char *color, XColor *color_def, int alloc) 1105w32_defined_color (FRAME_PTR f, const char *color, XColor *color_def, int alloc)
1072{ 1106{
1073 register Lisp_Object tem; 1107 register Lisp_Object tem;
1074 COLORREF w32_color_ref; 1108 COLORREF w32_color_ref;
@@ -1843,10 +1877,7 @@ w32_createwindow (struct frame *f)
1843 1877
1844 /* Do first time app init */ 1878 /* Do first time app init */
1845 1879
1846 if (!hprevinst) 1880 w32_init_class (hinst);
1847 {
1848 w32_init_class (hinst);
1849 }
1850 1881
1851 if (f->size_hint_flags & USPosition || f->size_hint_flags & PPosition) 1882 if (f->size_hint_flags & USPosition || f->size_hint_flags & PPosition)
1852 { 1883 {
@@ -2246,6 +2277,84 @@ unregister_hot_keys (HWND hwnd)
2246 } 2277 }
2247} 2278}
2248 2279
2280#if EMACSDEBUG
2281const char*
2282w32_name_of_message (UINT msg)
2283{
2284 unsigned i;
2285 static char buf[64];
2286 static const struct {
2287 UINT msg;
2288 const char* name;
2289 } msgnames[] = {
2290#define M(msg) { msg, # msg }
2291 M (WM_PAINT),
2292 M (WM_TIMER),
2293 M (WM_USER),
2294 M (WM_MOUSEMOVE),
2295 M (WM_LBUTTONUP),
2296 M (WM_KEYDOWN),
2297 M (WM_EMACS_KILL),
2298 M (WM_EMACS_CREATEWINDOW),
2299 M (WM_EMACS_DONE),
2300 M (WM_EMACS_CREATESCROLLBAR),
2301 M (WM_EMACS_SHOWWINDOW),
2302 M (WM_EMACS_SETWINDOWPOS),
2303 M (WM_EMACS_DESTROYWINDOW),
2304 M (WM_EMACS_TRACKPOPUPMENU),
2305 M (WM_EMACS_SETFOCUS),
2306 M (WM_EMACS_SETFOREGROUND),
2307 M (WM_EMACS_SETLOCALE),
2308 M (WM_EMACS_SETKEYBOARDLAYOUT),
2309 M (WM_EMACS_REGISTER_HOT_KEY),
2310 M (WM_EMACS_UNREGISTER_HOT_KEY),
2311 M (WM_EMACS_TOGGLE_LOCK_KEY),
2312 M (WM_EMACS_TRACK_CARET),
2313 M (WM_EMACS_DESTROY_CARET),
2314 M (WM_EMACS_SHOW_CARET),
2315 M (WM_EMACS_HIDE_CARET),
2316 M (WM_EMACS_SETCURSOR),
2317 M (WM_EMACS_PAINT),
2318 M (WM_CHAR),
2319#undef M
2320 { 0, 0 }
2321 };
2322
2323 for (i = 0; msgnames[i].name; ++i)
2324 if (msgnames[i].msg == msg)
2325 return msgnames[i].name;
2326
2327 sprintf (buf, "message 0x%04x", (unsigned)msg);
2328 return buf;
2329}
2330#endif /* EMACSDEBUG */
2331
2332/* Here's an overview of how Emacs input works on MS-Windows.
2333
2334 System messages are read and processed by w32_msg_pump below. This
2335 function runs in a separate thread. It handles a small number of
2336 custom WM_EMACS_* messages (posted by the main thread, look for
2337 PostMessage calls), and dispatches the rest to w32_wnd_proc, which
2338 is the main window procedure for the entire Emacs application.
2339
2340 w32_wnd_proc also runs in the same separate input thread. It
2341 handles some messages, mostly those that need GDI calls, by itself.
2342 For the others, it calls my_post_msg, which inserts the messages
2343 into the input queue serviced by w32_read_socket.
2344
2345 w32_read_socket runs in the main (a.k.a. "Lisp") thread, and is
2346 called synchronously from keyboard.c when it is known or suspected
2347 that some input is available. w32_read_socket either handles
2348 messages immediately, or converts them into Emacs input events and
2349 stuffs them into kbd_buffer, where kbd_buffer_get_event can get at
2350 them and process them when read_char and its callers require
2351 input.
2352
2353 Under Cygwin with the W32 toolkit, the use of /dev/windows with
2354 select(2) takes the place of w32_read_socket.
2355
2356 */
2357
2249/* Main message dispatch loop. */ 2358/* Main message dispatch loop. */
2250 2359
2251static void 2360static void
@@ -2259,6 +2368,10 @@ w32_msg_pump (deferred_msg * msg_buf)
2259 2368
2260 while ((w32_unicode_gui ? GetMessageW : GetMessageA) (&msg, NULL, 0, 0)) 2369 while ((w32_unicode_gui ? GetMessageW : GetMessageA) (&msg, NULL, 0, 0))
2261 { 2370 {
2371
2372 /* DebPrint (("w32_msg_pump: %s time:%u\n", */
2373 /* w32_name_of_message (msg.message), msg.time)); */
2374
2262 if (msg.hwnd == NULL) 2375 if (msg.hwnd == NULL)
2263 { 2376 {
2264 switch (msg.message) 2377 switch (msg.message)
@@ -2346,7 +2459,7 @@ w32_msg_pump (deferred_msg * msg_buf)
2346 /* Broadcast messages make it here, so you need to be looking 2459 /* Broadcast messages make it here, so you need to be looking
2347 for something in particular for this to be useful. */ 2460 for something in particular for this to be useful. */
2348 default: 2461 default:
2349 DebPrint (("msg %x not expected by w32_msg_pump\n", msg.message)); 2462 DebPrint (("msg %x not expected by w32_msg_pump\n", msg.message));
2350#endif 2463#endif
2351 } 2464 }
2352 } 2465 }
@@ -4685,6 +4798,37 @@ If omitted or nil, that stands for the selected frame's display. */)
4685{ 4798{
4686 return Qnil; 4799 return Qnil;
4687} 4800}
4801
4802DEFUN ("set-message-beep", Fset_message_beep, Sset_message_beep, 1, 1, 0,
4803 doc: /* Set the sound generated when the bell is rung.
4804SOUND is 'asterisk, 'exclamation, 'hand, 'question, 'ok, or 'silent
4805to use the corresponding system sound for the bell. The 'silent sound
4806prevents Emacs from making any sound at all.
4807SOUND is nil to use the normal beep. */)
4808 (Lisp_Object sound)
4809{
4810 CHECK_SYMBOL (sound);
4811
4812 if (NILP (sound))
4813 sound_type = 0xFFFFFFFF;
4814 else if (EQ (sound, intern ("asterisk")))
4815 sound_type = MB_ICONASTERISK;
4816 else if (EQ (sound, intern ("exclamation")))
4817 sound_type = MB_ICONEXCLAMATION;
4818 else if (EQ (sound, intern ("hand")))
4819 sound_type = MB_ICONHAND;
4820 else if (EQ (sound, intern ("question")))
4821 sound_type = MB_ICONQUESTION;
4822 else if (EQ (sound, intern ("ok")))
4823 sound_type = MB_OK;
4824 else if (EQ (sound, intern ("silent")))
4825 sound_type = MB_EMACS_SILENT;
4826 else
4827 sound_type = 0xFFFFFFFF;
4828
4829 return sound;
4830}
4831
4688 4832
4689int 4833int
4690x_pixel_width (register struct frame *f) 4834x_pixel_width (register struct frame *f)
@@ -4766,12 +4910,21 @@ terminate Emacs if we can't open the connection.
4766 unsigned char *xrm_option; 4910 unsigned char *xrm_option;
4767 struct w32_display_info *dpyinfo; 4911 struct w32_display_info *dpyinfo;
4768 4912
4913 CHECK_STRING (display);
4914
4915 /* Signal an error in order to encourage correct use from callers.
4916 * If we ever support multiple window systems in the same Emacs,
4917 * we'll need callers to be precise about what window system they
4918 * want. */
4919
4920 if (strcmp (SSDATA (display), "w32") != 0)
4921 error ("The name of the display in this Emacs must be \"w32\"");
4922
4769 /* If initialization has already been done, return now to avoid 4923 /* If initialization has already been done, return now to avoid
4770 overwriting critical parts of one_w32_display_info. */ 4924 overwriting critical parts of one_w32_display_info. */
4771 if (w32_in_use) 4925 if (w32_in_use)
4772 return Qnil; 4926 return Qnil;
4773 4927
4774 CHECK_STRING (display);
4775 if (! NILP (xrm_string)) 4928 if (! NILP (xrm_string))
4776 CHECK_STRING (xrm_string); 4929 CHECK_STRING (xrm_string);
4777 4930
@@ -5842,6 +5995,18 @@ Value is t if tooltip was open, nil otherwise. */)
5842 File selection dialog 5995 File selection dialog
5843 ***********************************************************************/ 5996 ***********************************************************************/
5844 5997
5998#define FILE_NAME_TEXT_FIELD edt1
5999#define FILE_NAME_COMBO_BOX cmb13
6000#define FILE_NAME_LIST lst1
6001
6002#ifdef NTGUI_UNICODE
6003#define GUISTR(x) (L ## x)
6004typedef wchar_t guichar_t;
6005#else /* !NTGUI_UNICODE */
6006#define GUISTR(x) x
6007typedef char guichar_t;
6008#endif /* NTGUI_UNICODE */
6009
5845/* Callback for altering the behavior of the Open File dialog. 6010/* Callback for altering the behavior of the Open File dialog.
5846 Makes the Filename text field contain "Current Directory" and be 6011 Makes the Filename text field contain "Current Directory" and be
5847 read-only when "Directories" is selected in the filter. This 6012 read-only when "Directories" is selected in the filter. This
@@ -5852,7 +6017,11 @@ file_dialog_callback (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5852{ 6017{
5853 if (msg == WM_NOTIFY) 6018 if (msg == WM_NOTIFY)
5854 { 6019 {
5855 OFNOTIFY * notify = (OFNOTIFY *)lParam; 6020#ifdef NTGUI_UNICODE
6021 OFNOTIFYW * notify = (OFNOTIFYW *)lParam;
6022#else /* !NTGUI_UNICODE */
6023 OFNOTIFYA * notify = (OFNOTIFYA *)lParam;
6024#endif /* NTGUI_UNICODE */
5856 /* Detect when the Filter dropdown is changed. */ 6025 /* Detect when the Filter dropdown is changed. */
5857 if (notify->hdr.code == CDN_TYPECHANGE 6026 if (notify->hdr.code == CDN_TYPECHANGE
5858 || notify->hdr.code == CDN_INITDONE) 6027 || notify->hdr.code == CDN_INITDONE)
@@ -5880,7 +6049,7 @@ file_dialog_callback (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5880 if (notify->lpOFN->nFilterIndex == 2) 6049 if (notify->lpOFN->nFilterIndex == 2)
5881 { 6050 {
5882 CommDlg_OpenSave_SetControlText (dialog, FILE_NAME_TEXT_FIELD, 6051 CommDlg_OpenSave_SetControlText (dialog, FILE_NAME_TEXT_FIELD,
5883 "Current Directory"); 6052 GUISTR ("Current Directory"));
5884 EnableWindow (edit_control, FALSE); 6053 EnableWindow (edit_control, FALSE);
5885 /* Note that at least on Windows 7, the above call to EnableWindow 6054 /* Note that at least on Windows 7, the above call to EnableWindow
5886 disables the window that would ordinarily have focus. If we 6055 disables the window that would ordinarily have focus. If we
@@ -5896,7 +6065,8 @@ file_dialog_callback (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5896 /* Don't override default filename on init done. */ 6065 /* Don't override default filename on init done. */
5897 if (notify->hdr.code == CDN_TYPECHANGE) 6066 if (notify->hdr.code == CDN_TYPECHANGE)
5898 CommDlg_OpenSave_SetControlText (dialog, 6067 CommDlg_OpenSave_SetControlText (dialog,
5899 FILE_NAME_TEXT_FIELD, ""); 6068 FILE_NAME_TEXT_FIELD,
6069 GUISTR (""));
5900 EnableWindow (edit_control, TRUE); 6070 EnableWindow (edit_control, TRUE);
5901 } 6071 }
5902 } 6072 }
@@ -5904,19 +6074,6 @@ file_dialog_callback (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5904 return 0; 6074 return 0;
5905} 6075}
5906 6076
5907/* Since we compile with _WIN32_WINNT set to 0x0400 (for NT4 compatibility)
5908 we end up with the old file dialogs. Define a big enough struct for the
5909 new dialog to trick GetOpenFileName into giving us the new dialogs on
5910 Windows 2000 and XP. */
5911typedef struct
5912{
5913 OPENFILENAME real_details;
5914 void * pReserved;
5915 DWORD dwReserved;
5916 DWORD FlagsEx;
5917} NEWOPENFILENAME;
5918
5919
5920DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 5, 0, 6077DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 5, 0,
5921 doc: /* Read file name, prompting with PROMPT in directory DIR. 6078 doc: /* Read file name, prompting with PROMPT in directory DIR.
5922Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file 6079Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
@@ -5928,134 +6085,204 @@ Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
5928Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */) 6085Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
5929 (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object only_dir_p) 6086 (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object only_dir_p)
5930{ 6087{
6088 /* Filter index: 1: All Files, 2: Directories only */
6089 static const guichar_t filter[] =
6090 GUISTR ("All Files (*.*)\0*.*\0Directories\0*|*\0");
6091
6092 Lisp_Object filename = default_filename;
5931 struct frame *f = SELECTED_FRAME (); 6093 struct frame *f = SELECTED_FRAME ();
5932 Lisp_Object file = Qnil; 6094 BOOL file_opened = FALSE;
5933 ptrdiff_t count = SPECPDL_INDEX (); 6095 Lisp_Object orig_dir = dir;
6096 Lisp_Object orig_prompt = prompt;
6097
6098 /* If we compile with _WIN32_WINNT set to 0x0400 (for NT4
6099 compatibility) we end up with the old file dialogs. Define a big
6100 enough struct for the new dialog to trick GetOpenFileName into
6101 giving us the new dialogs on newer versions of Windows. */
6102 struct {
6103#ifdef NTGUI_UNICODE
6104 OPENFILENAMEW details;
6105#else /* !NTGUI_UNICODE */
6106 OPENFILENAMEA details;
6107#endif /* NTGUI_UNICODE */
6108
6109#if _WIN32_WINNT < 0x500 /* < win2k */
6110 PVOID pvReserved;
6111 DWORD dwReserved;
6112 DWORD FlagsEx;
6113#endif /* < win2k */
6114 } new_file_details;
6115
6116#ifdef NTGUI_UNICODE
6117 wchar_t filename_buf[MAX_PATH + 1];
6118 OPENFILENAMEW * file_details = &new_file_details.details;
6119#else /* not NTGUI_UNICODE */
6120 char filename_buf[MAX_PATH + 1];
6121 OPENFILENAMEA * file_details = &new_file_details.details;
6122#endif /* NTGUI_UNICODE */
6123
5934 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6; 6124 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
5935 char filename[MAX_PATH + 1]; 6125 GCPRO6 (prompt, dir, default_filename, mustmatch, only_dir_p, filename);
5936 char init_dir[MAX_PATH + 1];
5937 int default_filter_index = 1; /* 1: All Files, 2: Directories only */
5938
5939 GCPRO6 (prompt, dir, default_filename, mustmatch, only_dir_p, file);
5940 CHECK_STRING (prompt);
5941 CHECK_STRING (dir);
5942
5943 /* Create the dialog with PROMPT as title, using DIR as initial
5944 directory and using "*" as pattern. */
5945 dir = Fexpand_file_name (dir, Qnil);
5946 strncpy (init_dir, SDATA (ENCODE_FILE (dir)), MAX_PATH);
5947 init_dir[MAX_PATH] = '\0';
5948 unixtodos_filename (init_dir);
5949
5950 if (STRINGP (default_filename))
5951 {
5952 char *file_name_only;
5953 char *full_path_name = SDATA (ENCODE_FILE (default_filename));
5954 6126
5955 unixtodos_filename (full_path_name); 6127 {
6128 struct gcpro gcpro1, gcpro2;
6129 GCPRO2 (orig_dir, orig_prompt); /* There is no GCPRON, N>6. */
5956 6130
5957 file_name_only = strrchr (full_path_name, '\\'); 6131 /* Note: under NTGUI_UNICODE, we do _NOT_ use ENCODE_FILE: the
5958 if (!file_name_only) 6132 system file encoding expected by the platform APIs (e.g. Cygwin's
5959 file_name_only = full_path_name; 6133 POSIX implementation) may not be the same as the encoding expected
5960 else 6134 by the Windows "ANSI" APIs! */
5961 file_name_only++;
5962 6135
5963 strncpy (filename, file_name_only, MAX_PATH); 6136 CHECK_STRING (prompt);
5964 filename[MAX_PATH] = '\0'; 6137 CHECK_STRING (dir);
5965 }
5966 else
5967 filename[0] = '\0';
5968 6138
5969 /* The code in file_dialog_callback that attempts to set the text 6139 dir = Fexpand_file_name (dir, Qnil);
5970 of the file name edit window when handling the CDN_INITDONE
5971 WM_NOTIFY message does not work. Setting filename to "Current
5972 Directory" in the only_dir_p case here does work however. */
5973 if (filename[0] == 0 && ! NILP (only_dir_p))
5974 strcpy (filename, "Current Directory");
5975 6140
5976 { 6141 if (STRINGP (filename))
5977 NEWOPENFILENAME new_file_details; 6142 filename = Ffile_name_nondirectory (filename);
5978 BOOL file_opened = FALSE; 6143 else
5979 OPENFILENAME * file_details = &new_file_details.real_details; 6144 filename = empty_unibyte_string;
5980 6145
5981 /* Prevent redisplay. */ 6146#ifdef CYGWIN
5982 specbind (Qinhibit_redisplay, Qt); 6147 dir = Fcygwin_convert_path_to_windows (dir, Qt);
5983 block_input (); 6148 if (SCHARS (filename) > 0)
6149 filename = Fcygwin_convert_path_to_windows (filename, Qnil);
6150#endif
5984 6151
6152 CHECK_STRING (dir);
6153 CHECK_STRING (filename);
6154
6155 /* The code in file_dialog_callback that attempts to set the text
6156 of the file name edit window when handling the CDN_INITDONE
6157 WM_NOTIFY message does not work. Setting filename to "Current
6158 Directory" in the only_dir_p case here does work however. */
6159 if (SCHARS (filename) == 0 && ! NILP (only_dir_p))
6160 filename = build_string ("Current Directory");
6161
6162 /* Convert the values we've computed so far to system form. */
6163#ifdef NTGUI_UNICODE
6164 to_unicode (prompt, &prompt);
6165 to_unicode (dir, &dir);
6166 to_unicode (filename, &filename);
6167#else /* !NTGUI_UNICODE */
6168 prompt = ENCODE_FILE (prompt);
6169 dir = ENCODE_FILE (dir);
6170 filename = ENCODE_FILE (filename);
6171
6172 /* We modify these in-place, so make copies for safety. */
6173 dir = Fcopy_sequence (dir);
6174 unixtodos_filename (SDATA (dir));
6175 filename = Fcopy_sequence (filename);
6176 unixtodos_filename (SDATA (filename));
6177#endif /* NTGUI_UNICODE */
6178
6179 /* Fill in the structure for the call to GetOpenFileName below. For
6180 NTGUI_UNICODE builds (which run only on NT), we just use the
6181 actual size of the structure. For non-NTGUI_UNICODE builds, we
6182 tell the OS we're using an old version of the structure if it's not
6183 new enough to support the newer version. */
5985 memset (&new_file_details, 0, sizeof (new_file_details)); 6184 memset (&new_file_details, 0, sizeof (new_file_details));
5986 /* Apparently NT4 crashes if you give it an unexpected size. 6185
5987 I'm not sure about Windows 9x, so play it safe. */
5988 if (w32_major_version > 4 && w32_major_version < 95) 6186 if (w32_major_version > 4 && w32_major_version < 95)
5989 file_details->lStructSize = sizeof (NEWOPENFILENAME); 6187 file_details->lStructSize = sizeof (new_file_details);
5990 else 6188 else
5991 file_details->lStructSize = sizeof (OPENFILENAME); 6189 file_details->lStructSize = sizeof (*file_details);
6190
6191 /* Set up the inout parameter for the selected file name. */
6192 if (SBYTES (filename) + 1 > sizeof (filename_buf))
6193 error ("filename too long");
6194
6195 memcpy (filename_buf, SDATA (filename), SBYTES (filename) + 1);
6196 file_details->lpstrFile = filename_buf;
6197 file_details->nMaxFile = sizeof (filename_buf) / sizeof (*filename_buf);
5992 6198
5993 file_details->hwndOwner = FRAME_W32_WINDOW (f); 6199 file_details->hwndOwner = FRAME_W32_WINDOW (f);
5994 /* Undocumented Bug in Common File Dialog: 6200 /* Undocumented Bug in Common File Dialog:
5995 If a filter is not specified, shell links are not resolved. */ 6201 If a filter is not specified, shell links are not resolved. */
5996 file_details->lpstrFilter = "All Files (*.*)\0*.*\0Directories\0*|*\0\0"; 6202 file_details->lpstrFilter = filter;
5997 file_details->lpstrFile = filename; 6203 file_details->lpstrInitialDir = (guichar_t*) SDATA (dir);
5998 file_details->nMaxFile = sizeof (filename); 6204 file_details->lpstrTitle = (guichar_t*) SDATA (prompt);
5999 file_details->lpstrInitialDir = init_dir; 6205 file_details->nFilterIndex = NILP (only_dir_p) ? 1 : 2;
6000 file_details->lpstrTitle = SDATA (prompt);
6001
6002 if (! NILP (only_dir_p))
6003 default_filter_index = 2;
6004
6005 file_details->nFilterIndex = default_filter_index;
6006
6007 file_details->Flags = (OFN_HIDEREADONLY | OFN_NOCHANGEDIR 6206 file_details->Flags = (OFN_HIDEREADONLY | OFN_NOCHANGEDIR
6008 | OFN_EXPLORER | OFN_ENABLEHOOK); 6207 | OFN_EXPLORER | OFN_ENABLEHOOK);
6208
6009 if (!NILP (mustmatch)) 6209 if (!NILP (mustmatch))
6010 { 6210 {
6011 /* Require that the path to the parent directory exists. */ 6211 /* Require that the path to the parent directory exists. */
6012 file_details->Flags |= OFN_PATHMUSTEXIST; 6212 file_details->Flags |= OFN_PATHMUSTEXIST;
6013 /* If we are looking for a file, require that it exists. */ 6213 /* If we are looking for a file, require that it exists. */
6014 if (NILP (only_dir_p)) 6214 if (NILP (only_dir_p))
6015 file_details->Flags |= OFN_FILEMUSTEXIST; 6215 file_details->Flags |= OFN_FILEMUSTEXIST;
6016 } 6216 }
6017 6217
6018 file_details->lpfnHook = (LPOFNHOOKPROC) file_dialog_callback; 6218 {
6019 6219 int count = SPECPDL_INDEX ();
6020 file_opened = GetOpenFileName (file_details); 6220 /* Prevent redisplay. */
6221 specbind (Qinhibit_redisplay, Qt);
6222 block_input ();
6223 file_details->lpfnHook = file_dialog_callback;
6021 6224
6022 unblock_input (); 6225#ifdef NTGUI_UNICODE
6226 file_opened = GetOpenFileNameW (file_details);
6227#else /* !NTGUI_UNICODE */
6228 file_opened = GetOpenFileNameA (file_details);
6229#endif /* NTGUI_UNICODE */
6230 unblock_input ();
6231 unbind_to (count, Qnil);
6232 }
6023 6233
6024 if (file_opened) 6234 if (file_opened)
6025 { 6235 {
6026 dostounix_filename (filename); 6236 /* Get an Emacs string from the value Windows gave us. */
6027 6237#ifdef NTGUI_UNICODE
6028 if (file_details->nFilterIndex == 2) 6238 filename = from_unicode (
6029 { 6239 make_unibyte_string (
6030 /* "Directories" selected - strip dummy file name. */ 6240 (char*) filename_buf,
6031 char * last = strrchr (filename, '/'); 6241 /* we get one of the two final 0 bytes for free. */
6032 *last = '\0'; 6242 1 + sizeof (wchar_t) * wcslen (filename_buf)));
6033 } 6243#else /* !NTGUI_UNICODE */
6034 6244 dostounix_filename (filename_buf);
6035 file = DECODE_FILE (build_string (filename)); 6245 filename = DECODE_FILE (build_string (filename_buf));
6246#endif /* NTGUI_UNICODE */
6247
6248#ifdef CYGWIN
6249 filename = Fcygwin_convert_path_from_windows (filename, Qt);
6250#endif /* CYGWIN */
6251
6252 /* Strip the dummy filename off the end of the string if we
6253 added it to select a directory. */
6254 if (file_details->nFilterIndex == 2)
6255 {
6256 filename = Ffile_name_directory (filename);
6257 }
6036 } 6258 }
6037 /* User canceled the dialog without making a selection. */ 6259 /* User canceled the dialog without making a selection. */
6038 else if (!CommDlgExtendedError ()) 6260 else if (!CommDlgExtendedError ())
6039 file = Qnil; 6261 filename = Qnil;
6040 /* An error occurred, fallback on reading from the mini-buffer. */ 6262 /* An error occurred, fallback on reading from the mini-buffer. */
6041 else 6263 else
6042 file = Fcompleting_read (prompt, intern ("read-file-name-internal"), 6264 filename = Fcompleting_read (
6043 dir, mustmatch, dir, Qfile_name_history, 6265 orig_prompt,
6044 default_filename, Qnil); 6266 intern ("read-file-name-internal"),
6267 orig_dir,
6268 mustmatch,
6269 orig_dir,
6270 Qfile_name_history,
6271 default_filename,
6272 Qnil);
6045 6273
6046 file = unbind_to (count, file); 6274 UNGCPRO;
6047 } 6275 }
6048 6276
6049 UNGCPRO;
6050
6051 /* Make "Cancel" equivalent to C-g. */ 6277 /* Make "Cancel" equivalent to C-g. */
6052 if (NILP (file)) 6278 if (NILP (filename))
6053 Fsignal (Qquit, Qnil); 6279 Fsignal (Qquit, Qnil);
6054 6280
6055 return unbind_to (count, file); 6281 RETURN_UNGCPRO (filename);
6056} 6282}
6057 6283
6058 6284
6285#ifdef WINDOWSNT
6059/* Moving files to the system recycle bin. 6286/* Moving files to the system recycle bin.
6060 Used by `move-file-to-trash' instead of the default moving to ~/.Trash */ 6287 Used by `move-file-to-trash' instead of the default moving to ~/.Trash */
6061DEFUN ("system-move-file-to-trash", Fsystem_move_file_to_trash, 6288DEFUN ("system-move-file-to-trash", Fsystem_move_file_to_trash,
@@ -6109,6 +6336,8 @@ DEFUN ("system-move-file-to-trash", Fsystem_move_file_to_trash,
6109 return Qnil; 6336 return Qnil;
6110} 6337}
6111 6338
6339#endif /* WINDOWSNT */
6340
6112 6341
6113/*********************************************************************** 6342/***********************************************************************
6114 w32 specialized functions 6343 w32 specialized functions
@@ -6526,7 +6755,7 @@ The following %-sequences are provided:
6526 else 6755 else
6527 { 6756 {
6528 char buffer[16]; 6757 char buffer[16];
6529 _snprintf (buffer, 16, "%d", system_status.BatteryLifePercent); 6758 snprintf (buffer, 16, "%d", system_status.BatteryLifePercent);
6530 load_percentage = build_string (buffer); 6759 load_percentage = build_string (buffer);
6531 } 6760 }
6532 6761
@@ -6537,18 +6766,18 @@ The following %-sequences are provided:
6537 long m; 6766 long m;
6538 float h; 6767 float h;
6539 char buffer[16]; 6768 char buffer[16];
6540 _snprintf (buffer, 16, "%ld", seconds_left); 6769 snprintf (buffer, 16, "%ld", seconds_left);
6541 seconds = build_string (buffer); 6770 seconds = build_string (buffer);
6542 6771
6543 m = seconds_left / 60; 6772 m = seconds_left / 60;
6544 _snprintf (buffer, 16, "%ld", m); 6773 snprintf (buffer, 16, "%ld", m);
6545 minutes = build_string (buffer); 6774 minutes = build_string (buffer);
6546 6775
6547 h = seconds_left / 3600.0; 6776 h = seconds_left / 3600.0;
6548 _snprintf (buffer, 16, "%3.1f", h); 6777 snprintf (buffer, 16, "%3.1f", h);
6549 hours = build_string (buffer); 6778 hours = build_string (buffer);
6550 6779
6551 _snprintf (buffer, 16, "%ld:%02ld", m / 60, m % 60); 6780 snprintf (buffer, 16, "%ld:%02ld", m / 60, m % 60);
6552 remain = build_string (buffer); 6781 remain = build_string (buffer);
6553 } 6782 }
6554 6783
@@ -6710,10 +6939,10 @@ DEFUN ("default-printer-name", Fdefault_printer_name, Sdefault_printer_name,
6710 { 6939 {
6711 /* a remote printer */ 6940 /* a remote printer */
6712 if (*ppi2->pServerName == '\\') 6941 if (*ppi2->pServerName == '\\')
6713 _snprintf (pname_buf, sizeof (pname_buf), "%s\\%s", ppi2->pServerName, 6942 snprintf (pname_buf, sizeof (pname_buf), "%s\\%s", ppi2->pServerName,
6714 ppi2->pShareName); 6943 ppi2->pShareName);
6715 else 6944 else
6716 _snprintf (pname_buf, sizeof (pname_buf), "\\\\%s\\%s", ppi2->pServerName, 6945 snprintf (pname_buf, sizeof (pname_buf), "\\\\%s\\%s", ppi2->pServerName,
6717 ppi2->pShareName); 6946 ppi2->pShareName);
6718 pname_buf[sizeof (pname_buf) - 1] = '\0'; 6947 pname_buf[sizeof (pname_buf) - 1] = '\0';
6719 } 6948 }
@@ -6732,6 +6961,292 @@ DEFUN ("default-printer-name", Fdefault_printer_name, Sdefault_printer_name,
6732 return build_string (pname_buf); 6961 return build_string (pname_buf);
6733} 6962}
6734 6963
6964
6965/* Equivalent of strerror for W32 error codes. */
6966char *
6967w32_strerror (int error_no)
6968{
6969 static char buf[500];
6970 DWORD ret;
6971
6972 if (error_no == 0)
6973 error_no = GetLastError ();
6974
6975 ret = FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM |
6976 FORMAT_MESSAGE_IGNORE_INSERTS,
6977 NULL,
6978 error_no,
6979 0, /* choose most suitable language */
6980 buf, sizeof (buf), NULL);
6981
6982 while (ret > 0 && (buf[ret - 1] == '\n' ||
6983 buf[ret - 1] == '\r' ))
6984 --ret;
6985 buf[ret] = '\0';
6986 if (!ret)
6987 sprintf (buf, "w32 error %u", error_no);
6988
6989 return buf;
6990}
6991
6992/* For convenience when debugging. */
6993int
6994w32_last_error (void)
6995{
6996 return GetLastError ();
6997}
6998
6999/* Cache information describing the NT system for later use. */
7000void
7001cache_system_info (void)
7002{
7003 union
7004 {
7005 struct info
7006 {
7007 char major;
7008 char minor;
7009 short platform;
7010 } info;
7011 DWORD data;
7012 } version;
7013
7014 /* Cache the version of the operating system. */
7015 version.data = GetVersion ();
7016 w32_major_version = version.info.major;
7017 w32_minor_version = version.info.minor;
7018
7019 if (version.info.platform & 0x8000)
7020 os_subtype = OS_9X;
7021 else
7022 os_subtype = OS_NT;
7023
7024 /* Cache page size, allocation unit, processor type, etc. */
7025 GetSystemInfo (&sysinfo_cache);
7026 syspage_mask = sysinfo_cache.dwPageSize - 1;
7027
7028 /* Cache os info. */
7029 osinfo_cache.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
7030 GetVersionEx (&osinfo_cache);
7031
7032 w32_build_number = osinfo_cache.dwBuildNumber;
7033 if (os_subtype == OS_9X)
7034 w32_build_number &= 0xffff;
7035
7036 w32_num_mouse_buttons = GetSystemMetrics (SM_CMOUSEBUTTONS);
7037}
7038
7039#ifdef EMACSDEBUG
7040void
7041_DebPrint (const char *fmt, ...)
7042{
7043 char buf[1024];
7044 va_list args;
7045
7046 va_start (args, fmt);
7047 vsprintf (buf, fmt, args);
7048 va_end (args);
7049#if CYGWIN
7050 fprintf (stderr, "%s", buf);
7051#endif
7052 OutputDebugString (buf);
7053}
7054#endif
7055
7056int
7057w32_console_toggle_lock_key (int vk_code, Lisp_Object new_state)
7058{
7059 int cur_state = (GetKeyState (vk_code) & 1);
7060
7061 if (NILP (new_state)
7062 || (NUMBERP (new_state)
7063 && ((XUINT (new_state)) & 1) != cur_state))
7064 {
7065#ifdef WINDOWSNT
7066 faked_key = vk_code;
7067#endif /* WINDOWSNT */
7068
7069 keybd_event ((BYTE) vk_code,
7070 (BYTE) MapVirtualKey (vk_code, 0),
7071 KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
7072 keybd_event ((BYTE) vk_code,
7073 (BYTE) MapVirtualKey (vk_code, 0),
7074 KEYEVENTF_EXTENDEDKEY | 0, 0);
7075 keybd_event ((BYTE) vk_code,
7076 (BYTE) MapVirtualKey (vk_code, 0),
7077 KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
7078 cur_state = !cur_state;
7079 }
7080
7081 return cur_state;
7082}
7083
7084/* Translate console modifiers to emacs modifiers.
7085 German keyboard support (Kai Morgan Zeise 2/18/95). */
7086int
7087w32_kbd_mods_to_emacs (DWORD mods, WORD key)
7088{
7089 int retval = 0;
7090
7091 /* If we recognize right-alt and left-ctrl as AltGr, and it has been
7092 pressed, first remove those modifiers. */
7093 if (!NILP (Vw32_recognize_altgr)
7094 && (mods & (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED))
7095 == (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED))
7096 mods &= ~ (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED);
7097
7098 if (mods & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED))
7099 retval = ((NILP (Vw32_alt_is_meta)) ? alt_modifier : meta_modifier);
7100
7101 if (mods & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED))
7102 {
7103 retval |= ctrl_modifier;
7104 if ((mods & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED))
7105 == (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED))
7106 retval |= meta_modifier;
7107 }
7108
7109 if (mods & LEFT_WIN_PRESSED)
7110 retval |= w32_key_to_modifier (VK_LWIN);
7111 if (mods & RIGHT_WIN_PRESSED)
7112 retval |= w32_key_to_modifier (VK_RWIN);
7113 if (mods & APPS_PRESSED)
7114 retval |= w32_key_to_modifier (VK_APPS);
7115 if (mods & SCROLLLOCK_ON)
7116 retval |= w32_key_to_modifier (VK_SCROLL);
7117
7118 /* Just in case someone wanted the original behavior, make it
7119 optional by setting w32-capslock-is-shiftlock to t. */
7120 if (NILP (Vw32_capslock_is_shiftlock)
7121 /* Keys that should _not_ be affected by CapsLock. */
7122 && ( (key == VK_BACK)
7123 || (key == VK_TAB)
7124 || (key == VK_CLEAR)
7125 || (key == VK_RETURN)
7126 || (key == VK_ESCAPE)
7127 || ((key >= VK_SPACE) && (key <= VK_HELP))
7128 || ((key >= VK_NUMPAD0) && (key <= VK_F24))
7129 || ((key >= VK_NUMPAD_CLEAR) && (key <= VK_NUMPAD_DELETE))
7130 ))
7131 {
7132 /* Only consider shift state. */
7133 if ((mods & SHIFT_PRESSED) != 0)
7134 retval |= shift_modifier;
7135 }
7136 else
7137 {
7138 /* Ignore CapsLock state if not enabled. */
7139 if (NILP (Vw32_enable_caps_lock))
7140 mods &= ~CAPSLOCK_ON;
7141 if ((mods & (SHIFT_PRESSED | CAPSLOCK_ON)) != 0)
7142 retval |= shift_modifier;
7143 }
7144
7145 return retval;
7146}
7147
7148/* The return code indicates key code size. cpID is the codepage to
7149 use for translation to Unicode; -1 means use the current console
7150 input codepage. */
7151int
7152w32_kbd_patch_key (KEY_EVENT_RECORD *event, int cpId)
7153{
7154 unsigned int key_code = event->wVirtualKeyCode;
7155 unsigned int mods = event->dwControlKeyState;
7156 BYTE keystate[256];
7157 static BYTE ansi_code[4];
7158 static int isdead = 0;
7159
7160 if (isdead == 2)
7161 {
7162 event->uChar.AsciiChar = ansi_code[2];
7163 isdead = 0;
7164 return 1;
7165 }
7166 if (event->uChar.AsciiChar != 0)
7167 return 1;
7168
7169 memset (keystate, 0, sizeof (keystate));
7170 keystate[key_code] = 0x80;
7171 if (mods & SHIFT_PRESSED)
7172 keystate[VK_SHIFT] = 0x80;
7173 if (mods & CAPSLOCK_ON)
7174 keystate[VK_CAPITAL] = 1;
7175 /* If we recognize right-alt and left-ctrl as AltGr, set the key
7176 states accordingly before invoking ToAscii. */
7177 if (!NILP (Vw32_recognize_altgr)
7178 && (mods & LEFT_CTRL_PRESSED) && (mods & RIGHT_ALT_PRESSED))
7179 {
7180 keystate[VK_CONTROL] = 0x80;
7181 keystate[VK_LCONTROL] = 0x80;
7182 keystate[VK_MENU] = 0x80;
7183 keystate[VK_RMENU] = 0x80;
7184 }
7185
7186#if 0
7187 /* Because of an OS bug, ToAscii corrupts the stack when called to
7188 convert a dead key in console mode on NT4. Unfortunately, trying
7189 to check for dead keys using MapVirtualKey doesn't work either -
7190 these functions apparently use internal information about keyboard
7191 layout which doesn't get properly updated in console programs when
7192 changing layout (though apparently it gets partly updated,
7193 otherwise ToAscii wouldn't crash). */
7194 if (is_dead_key (event->wVirtualKeyCode))
7195 return 0;
7196#endif
7197
7198 /* On NT, call ToUnicode instead and then convert to the current
7199 console input codepage. */
7200 if (os_subtype == OS_NT)
7201 {
7202 WCHAR buf[128];
7203
7204 isdead = ToUnicode (event->wVirtualKeyCode, event->wVirtualScanCode,
7205 keystate, buf, 128, 0);
7206 if (isdead > 0)
7207 {
7208 /* When we are called from the GUI message processing code,
7209 we are passed the current keyboard codepage, a positive
7210 number, to use below. */
7211 if (cpId == -1)
7212 cpId = GetConsoleCP ();
7213
7214 event->uChar.UnicodeChar = buf[isdead - 1];
7215 isdead = WideCharToMultiByte (cpId, 0, buf, isdead,
7216 ansi_code, 4, NULL, NULL);
7217 }
7218 else
7219 isdead = 0;
7220 }
7221 else
7222 {
7223 isdead = ToAscii (event->wVirtualKeyCode, event->wVirtualScanCode,
7224 keystate, (LPWORD) ansi_code, 0);
7225 }
7226
7227 if (isdead == 0)
7228 return 0;
7229 event->uChar.AsciiChar = ansi_code[0];
7230 return isdead;
7231}
7232
7233
7234void
7235w32_sys_ring_bell (struct frame *f)
7236{
7237 if (sound_type == 0xFFFFFFFF)
7238 {
7239 Beep (666, 100);
7240 }
7241 else if (sound_type == MB_EMACS_SILENT)
7242 {
7243 /* Do nothing. */
7244 }
7245 else
7246 MessageBeep (sound_type);
7247}
7248
7249
6735/*********************************************************************** 7250/***********************************************************************
6736 Initialization 7251 Initialization
6737 ***********************************************************************/ 7252 ***********************************************************************/
@@ -7098,6 +7613,7 @@ only be necessary if the default setting causes problems. */);
7098 7613
7099 defsubr (&Sfile_system_info); 7614 defsubr (&Sfile_system_info);
7100 defsubr (&Sdefault_printer_name); 7615 defsubr (&Sdefault_printer_name);
7616 defsubr (&Sset_message_beep);
7101 7617
7102 check_window_system_func = check_w32; 7618 check_window_system_func = check_w32;
7103 7619
@@ -7114,7 +7630,9 @@ only be necessary if the default setting causes problems. */);
7114 staticpro (&last_show_tip_args); 7630 staticpro (&last_show_tip_args);
7115 7631
7116 defsubr (&Sx_file_dialog); 7632 defsubr (&Sx_file_dialog);
7633#ifdef WINDOWSNT
7117 defsubr (&Ssystem_move_file_to_trash); 7634 defsubr (&Ssystem_move_file_to_trash);
7635#endif
7118} 7636}
7119 7637
7120 7638
@@ -7196,9 +7714,3 @@ emacs_abort (void)
7196 } 7714 }
7197} 7715}
7198 7716
7199/* For convenience when debugging. */
7200int
7201w32_last_error (void)
7202{
7203 return GetLastError ();
7204}
diff --git a/src/w32font.c b/src/w32font.c
index 833b7cdfb25..d7d25d89939 100644
--- a/src/w32font.c
+++ b/src/w32font.c
@@ -18,6 +18,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
18 18
19#include <config.h> 19#include <config.h>
20#include <windows.h> 20#include <windows.h>
21#include <stdio.h>
21#include <math.h> 22#include <math.h>
22#include <ctype.h> 23#include <ctype.h>
23#include <commdlg.h> 24#include <commdlg.h>
@@ -1434,6 +1435,9 @@ w32font_coverage_ok (FONTSIGNATURE * coverage, BYTE charset)
1434 return 1; 1435 return 1;
1435} 1436}
1436 1437
1438#ifndef WINDOWSNT
1439#define _strlwr strlwr
1440#endif /* !WINDOWSNT */
1437 1441
1438static int 1442static int
1439check_face_name (LOGFONT *font, char *full_name) 1443check_face_name (LOGFONT *font, char *full_name)
diff --git a/src/w32heap.c b/src/w32heap.c
index 8b9b19ea35d..0ff473fb0a8 100644
--- a/src/w32heap.c
+++ b/src/w32heap.c
@@ -32,10 +32,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
32SYSTEM_INFO sysinfo_cache; 32SYSTEM_INFO sysinfo_cache;
33 33
34/* This gives us version, build, and platform identification. */ 34/* This gives us version, build, and platform identification. */
35extern unsigned long syspage_mask;
35OSVERSIONINFO osinfo_cache; 36OSVERSIONINFO osinfo_cache;
36 37
37size_t syspage_mask = 0;
38
39/* The major and minor versions of NT. */ 38/* The major and minor versions of NT. */
40int w32_major_version; 39int w32_major_version;
41int w32_minor_version; 40int w32_minor_version;
@@ -44,44 +43,6 @@ int w32_build_number;
44/* Distinguish between Windows NT and Windows 95. */ 43/* Distinguish between Windows NT and Windows 95. */
45int os_subtype; 44int os_subtype;
46 45
47/* Cache information describing the NT system for later use. */
48void
49cache_system_info (void)
50{
51 union
52 {
53 struct info
54 {
55 char major;
56 char minor;
57 short platform;
58 } info;
59 DWORD data;
60 } version;
61
62 /* Cache the version of the operating system. */
63 version.data = GetVersion ();
64 w32_major_version = version.info.major;
65 w32_minor_version = version.info.minor;
66
67 if (version.info.platform & 0x8000)
68 os_subtype = OS_9X;
69 else
70 os_subtype = OS_NT;
71
72 /* Cache page size, allocation unit, processor type, etc. */
73 GetSystemInfo (&sysinfo_cache);
74 syspage_mask = sysinfo_cache.dwPageSize - 1;
75
76 /* Cache os info. */
77 osinfo_cache.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
78 GetVersionEx (&osinfo_cache);
79
80 w32_build_number = osinfo_cache.dwBuildNumber;
81 if (os_subtype == OS_9X)
82 w32_build_number &= 0xffff;
83}
84
85/* Emulate getpagesize. */ 46/* Emulate getpagesize. */
86int 47int
87getpagesize (void) 48getpagesize (void)
diff --git a/src/w32inevt.c b/src/w32inevt.c
index ebb95dcace5..c322d3a0b44 100644
--- a/src/w32inevt.c
+++ b/src/w32inevt.c
@@ -70,6 +70,9 @@ w32_read_console_input (HANDLE h, INPUT_RECORD *rec, DWORD recsize,
70 : ReadConsoleInputA (h, rec, recsize, waiting)); 70 : ReadConsoleInputA (h, rec, recsize, waiting));
71} 71}
72 72
73/* Set by w32_console_toggle_lock_key. */
74int faked_key;
75
73static int 76static int
74fill_queue (BOOL block) 77fill_queue (BOOL block)
75{ 78{
@@ -110,67 +113,7 @@ get_frame (void)
110 113
111/* Translate console modifiers to emacs modifiers. 114/* Translate console modifiers to emacs modifiers.
112 German keyboard support (Kai Morgan Zeise 2/18/95). */ 115 German keyboard support (Kai Morgan Zeise 2/18/95). */
113int
114w32_kbd_mods_to_emacs (DWORD mods, WORD key)
115{
116 int retval = 0;
117
118 /* If we recognize right-alt and left-ctrl as AltGr, and it has been
119 pressed, first remove those modifiers. */
120 if (!NILP (Vw32_recognize_altgr)
121 && (mods & (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED))
122 == (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED))
123 mods &= ~ (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED);
124 116
125 if (mods & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED))
126 retval = ((NILP (Vw32_alt_is_meta)) ? alt_modifier : meta_modifier);
127
128 if (mods & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED))
129 {
130 retval |= ctrl_modifier;
131 if ((mods & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED))
132 == (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED))
133 retval |= meta_modifier;
134 }
135
136 if (mods & LEFT_WIN_PRESSED)
137 retval |= w32_key_to_modifier (VK_LWIN);
138 if (mods & RIGHT_WIN_PRESSED)
139 retval |= w32_key_to_modifier (VK_RWIN);
140 if (mods & APPS_PRESSED)
141 retval |= w32_key_to_modifier (VK_APPS);
142 if (mods & SCROLLLOCK_ON)
143 retval |= w32_key_to_modifier (VK_SCROLL);
144
145 /* Just in case someone wanted the original behavior, make it
146 optional by setting w32-capslock-is-shiftlock to t. */
147 if (NILP (Vw32_capslock_is_shiftlock)
148 /* Keys that should _not_ be affected by CapsLock. */
149 && ( (key == VK_BACK)
150 || (key == VK_TAB)
151 || (key == VK_CLEAR)
152 || (key == VK_RETURN)
153 || (key == VK_ESCAPE)
154 || ((key >= VK_SPACE) && (key <= VK_HELP))
155 || ((key >= VK_NUMPAD0) && (key <= VK_F24))
156 || ((key >= VK_NUMPAD_CLEAR) && (key <= VK_NUMPAD_DELETE))
157 ))
158 {
159 /* Only consider shift state. */
160 if ((mods & SHIFT_PRESSED) != 0)
161 retval |= shift_modifier;
162 }
163 else
164 {
165 /* Ignore CapsLock state if not enabled. */
166 if (NILP (Vw32_enable_caps_lock))
167 mods &= ~CAPSLOCK_ON;
168 if ((mods & (SHIFT_PRESSED | CAPSLOCK_ON)) != 0)
169 retval |= shift_modifier;
170 }
171
172 return retval;
173}
174 117
175#if 0 118#if 0
176/* Return nonzero if the virtual key is a dead key. */ 119/* Return nonzero if the virtual key is a dead key. */
@@ -187,90 +130,7 @@ is_dead_key (int wparam)
187/* The return code indicates key code size. cpID is the codepage to 130/* The return code indicates key code size. cpID is the codepage to
188 use for translation to Unicode; -1 means use the current console 131 use for translation to Unicode; -1 means use the current console
189 input codepage. */ 132 input codepage. */
190int
191w32_kbd_patch_key (KEY_EVENT_RECORD *event, int cpId)
192{
193 unsigned int key_code = event->wVirtualKeyCode;
194 unsigned int mods = event->dwControlKeyState;
195 BYTE keystate[256];
196 static BYTE ansi_code[4];
197 static int isdead = 0;
198 133
199 if (isdead == 2)
200 {
201 event->uChar.AsciiChar = ansi_code[2];
202 isdead = 0;
203 return 1;
204 }
205 if (event->uChar.AsciiChar != 0)
206 return 1;
207
208 memset (keystate, 0, sizeof (keystate));
209 keystate[key_code] = 0x80;
210 if (mods & SHIFT_PRESSED)
211 keystate[VK_SHIFT] = 0x80;
212 if (mods & CAPSLOCK_ON)
213 keystate[VK_CAPITAL] = 1;
214 /* If we recognize right-alt and left-ctrl as AltGr, set the key
215 states accordingly before invoking ToAscii. */
216 if (!NILP (Vw32_recognize_altgr)
217 && (mods & LEFT_CTRL_PRESSED) && (mods & RIGHT_ALT_PRESSED))
218 {
219 keystate[VK_CONTROL] = 0x80;
220 keystate[VK_LCONTROL] = 0x80;
221 keystate[VK_MENU] = 0x80;
222 keystate[VK_RMENU] = 0x80;
223 }
224
225#if 0
226 /* Because of an OS bug, ToAscii corrupts the stack when called to
227 convert a dead key in console mode on NT4. Unfortunately, trying
228 to check for dead keys using MapVirtualKey doesn't work either -
229 these functions apparently use internal information about keyboard
230 layout which doesn't get properly updated in console programs when
231 changing layout (though apparently it gets partly updated,
232 otherwise ToAscii wouldn't crash). */
233 if (is_dead_key (event->wVirtualKeyCode))
234 return 0;
235#endif
236
237 /* On NT, call ToUnicode instead and then convert to the current
238 console input codepage. */
239 if (os_subtype == OS_NT)
240 {
241 WCHAR buf[128];
242
243 isdead = ToUnicode (event->wVirtualKeyCode, event->wVirtualScanCode,
244 keystate, buf, 128, 0);
245 if (isdead > 0)
246 {
247 /* When we are called from the GUI message processing code,
248 we are passed the current keyboard codepage, a positive
249 number, to use below. */
250 if (cpId == -1)
251 cpId = GetConsoleCP ();
252
253 event->uChar.UnicodeChar = buf[isdead - 1];
254 isdead = WideCharToMultiByte (cpId, 0, buf, isdead,
255 ansi_code, 4, NULL, NULL);
256 }
257 else
258 isdead = 0;
259 }
260 else
261 {
262 isdead = ToAscii (event->wVirtualKeyCode, event->wVirtualScanCode,
263 keystate, (LPWORD) ansi_code, 0);
264 }
265
266 if (isdead == 0)
267 return 0;
268 event->uChar.AsciiChar = ansi_code[0];
269 return isdead;
270}
271
272
273static int faked_key = 0;
274 134
275/* return code -1 means that event_queue_ptr won't be incremented. 135/* return code -1 means that event_queue_ptr won't be incremented.
276 In other word, this event makes two key codes. (by himi) */ 136 In other word, this event makes two key codes. (by himi) */
@@ -531,32 +391,6 @@ key_event (KEY_EVENT_RECORD *event, struct input_event *emacs_ev, int *isdead)
531 return 1; 391 return 1;
532} 392}
533 393
534int
535w32_console_toggle_lock_key (int vk_code, Lisp_Object new_state)
536{
537 int cur_state = (GetKeyState (vk_code) & 1);
538
539 if (NILP (new_state)
540 || (NUMBERP (new_state)
541 && ((XUINT (new_state)) & 1) != cur_state))
542 {
543 faked_key = vk_code;
544
545 keybd_event ((BYTE) vk_code,
546 (BYTE) MapVirtualKey (vk_code, 0),
547 KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
548 keybd_event ((BYTE) vk_code,
549 (BYTE) MapVirtualKey (vk_code, 0),
550 KEYEVENTF_EXTENDEDKEY | 0, 0);
551 keybd_event ((BYTE) vk_code,
552 (BYTE) MapVirtualKey (vk_code, 0),
553 KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
554 cur_state = !cur_state;
555 }
556
557 return cur_state;
558}
559
560/* Mouse position hook. */ 394/* Mouse position hook. */
561void 395void
562w32_console_mouse_position (FRAME_PTR *f, 396w32_console_mouse_position (FRAME_PTR *f,
diff --git a/src/w32menu.c b/src/w32menu.c
index 0a10f1f0893..40ee82d42d5 100644
--- a/src/w32menu.c
+++ b/src/w32menu.c
@@ -21,7 +21,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 21
22#include <signal.h> 22#include <signal.h>
23#include <stdio.h> 23#include <stdio.h>
24#include <mbstring.h> 24#include <setjmp.h>
25 25
26#include "lisp.h" 26#include "lisp.h"
27#include "keyboard.h" 27#include "keyboard.h"
@@ -40,6 +40,14 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
40 if this is not done before the other system files. */ 40 if this is not done before the other system files. */
41#include "w32term.h" 41#include "w32term.h"
42 42
43/* Cygwin does not support the multibyte string functions declared in
44 * mbstring.h below --- but that's okay: because Cygwin is
45 * UNICODE-only, we don't need to use these functions anyway. */
46
47#ifndef NTGUI_UNICODE
48#include <mbstring.h>
49#endif /* !NTGUI_UNICODE */
50
43/* Load sys/types.h if not already loaded. 51/* Load sys/types.h if not already loaded.
44 In some systems loading it twice is suicidal. */ 52 In some systems loading it twice is suicidal. */
45#ifndef makedev 53#ifndef makedev
@@ -78,10 +86,17 @@ typedef int (WINAPI * MessageBoxW_Proc) (
78 IN WCHAR *caption, 86 IN WCHAR *caption,
79 IN UINT type); 87 IN UINT type);
80 88
89#ifdef NTGUI_UNICODE
90#define get_menu_item_info GetMenuItemInfoA
91#define set_menu_item_info SetMenuItemInfoA
92#define unicode_append_menu AppendMenuW
93#define unicode_message_box MessageBoxW
94#else /* !NTGUI_UNICODE */
81GetMenuItemInfoA_Proc get_menu_item_info = NULL; 95GetMenuItemInfoA_Proc get_menu_item_info = NULL;
82SetMenuItemInfoA_Proc set_menu_item_info = NULL; 96SetMenuItemInfoA_Proc set_menu_item_info = NULL;
83AppendMenuW_Proc unicode_append_menu = NULL; 97AppendMenuW_Proc unicode_append_menu = NULL;
84MessageBoxW_Proc unicode_message_box = NULL; 98MessageBoxW_Proc unicode_message_box = NULL;
99#endif /* NTGUI_UNICODE */
85 100
86Lisp_Object Qdebug_on_next_call; 101Lisp_Object Qdebug_on_next_call;
87 102
@@ -98,6 +113,7 @@ static void utf8to16 (unsigned char *, int, WCHAR *);
98static int fill_in_menu (HMENU, widget_value *); 113static int fill_in_menu (HMENU, widget_value *);
99 114
100void w32_free_menu_strings (HWND); 115void w32_free_menu_strings (HWND);
116
101 117
102 118
103/* This is set nonzero after the user activates the menu bar, and set 119/* This is set nonzero after the user activates the menu bar, and set
@@ -1405,6 +1421,7 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item)
1405 nlen++; 1421 nlen++;
1406 } 1422 }
1407 } 1423 }
1424#ifndef NTGUI_UNICODE
1408 else 1425 else
1409 { 1426 {
1410 /* If encoded with the system codepage, use multibyte string 1427 /* If encoded with the system codepage, use multibyte string
@@ -1415,6 +1432,7 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item)
1415 nlen++; 1432 nlen++;
1416 } 1433 }
1417 } 1434 }
1435#endif /* !NTGUI_UNICODE */
1418 1436
1419 if (nlen > orig_len) 1437 if (nlen > orig_len)
1420 { 1438 {
@@ -1429,6 +1447,7 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item)
1429 *q++ = *p; 1447 *q++ = *p;
1430 *q++ = *p++; 1448 *q++ = *p++;
1431 } 1449 }
1450#ifndef NTGUI_UNICODE
1432 else 1451 else
1433 { 1452 {
1434 if (_mbsnextc (p) == '&') 1453 if (_mbsnextc (p) == '&')
@@ -1440,6 +1459,7 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item)
1440 p = _mbsinc (p); 1459 p = _mbsinc (p);
1441 q = _mbsinc (q); 1460 q = _mbsinc (q);
1442 } 1461 }
1462#endif /* !NTGUI_UNICODE */
1443 } 1463 }
1444 *q = '\0'; 1464 *q = '\0';
1445 } 1465 }
@@ -1486,6 +1506,8 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item)
1486 item != NULL ? (UINT_PTR) item 1506 item != NULL ? (UINT_PTR) item
1487 : (UINT_PTR) wv->call_data, 1507 : (UINT_PTR) wv->call_data,
1488 utf16_string); 1508 utf16_string);
1509
1510#ifndef NTGUI_UNICODE /* Fallback does not apply when always UNICODE */
1489 if (!return_value) 1511 if (!return_value)
1490 { 1512 {
1491 /* On W9x/ME, Unicode menus are not supported, though AppendMenuW 1513 /* On W9x/ME, Unicode menus are not supported, though AppendMenuW
@@ -1504,6 +1526,7 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item)
1504 if (osinfo_cache.dwPlatformId != VER_PLATFORM_WIN32_NT) 1526 if (osinfo_cache.dwPlatformId != VER_PLATFORM_WIN32_NT)
1505 unicode_append_menu = NULL; 1527 unicode_append_menu = NULL;
1506 } 1528 }
1529#endif /* NTGUI_UNICODE */
1507 1530
1508 if (unicode_append_menu && (fuFlags & MF_OWNERDRAW)) 1531 if (unicode_append_menu && (fuFlags & MF_OWNERDRAW))
1509 local_free (out_string); 1532 local_free (out_string);
@@ -1723,10 +1746,12 @@ syms_of_w32menu (void)
1723void 1746void
1724globals_of_w32menu (void) 1747globals_of_w32menu (void)
1725{ 1748{
1749#ifndef NTGUI_UNICODE
1726 /* See if Get/SetMenuItemInfo functions are available. */ 1750 /* See if Get/SetMenuItemInfo functions are available. */
1727 HMODULE user32 = GetModuleHandle ("user32.dll"); 1751 HMODULE user32 = GetModuleHandle ("user32.dll");
1728 get_menu_item_info = (GetMenuItemInfoA_Proc) GetProcAddress (user32, "GetMenuItemInfoA"); 1752 get_menu_item_info = (GetMenuItemInfoA_Proc) GetProcAddress (user32, "GetMenuItemInfoA");
1729 set_menu_item_info = (SetMenuItemInfoA_Proc) GetProcAddress (user32, "SetMenuItemInfoA"); 1753 set_menu_item_info = (SetMenuItemInfoA_Proc) GetProcAddress (user32, "SetMenuItemInfoA");
1730 unicode_append_menu = (AppendMenuW_Proc) GetProcAddress (user32, "AppendMenuW"); 1754 unicode_append_menu = (AppendMenuW_Proc) GetProcAddress (user32, "AppendMenuW");
1731 unicode_message_box = (MessageBoxW_Proc) GetProcAddress (user32, "MessageBoxW"); 1755 unicode_message_box = (MessageBoxW_Proc) GetProcAddress (user32, "MessageBoxW");
1756#endif /* !NTGUI_UNICODE */
1732} 1757}
diff --git a/src/w32proc.c b/src/w32proc.c
index d032b21c59e..7d0039d0d5e 100644
--- a/src/w32proc.c
+++ b/src/w32proc.c
@@ -67,20 +67,6 @@ extern BOOL WINAPI IsValidLocale (LCID, DWORD);
67 67
68Lisp_Object Qhigh, Qlow; 68Lisp_Object Qhigh, Qlow;
69 69
70#ifdef EMACSDEBUG
71void
72_DebPrint (const char *fmt, ...)
73{
74 char buf[1024];
75 va_list args;
76
77 va_start (args, fmt);
78 vsprintf (buf, fmt, args);
79 va_end (args);
80 OutputDebugString (buf);
81}
82#endif
83
84typedef void (_CALLBACK_ *signal_handler) (int); 70typedef void (_CALLBACK_ *signal_handler) (int);
85 71
86/* Signal handlers...SIG_DFL == 0 so this is initialized correctly. */ 72/* Signal handlers...SIG_DFL == 0 so this is initialized correctly. */
diff --git a/src/w32select.c b/src/w32select.c
index 66f9f7ab041..1690c3b7824 100644
--- a/src/w32select.c
+++ b/src/w32select.c
@@ -81,6 +81,11 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
81#include "coding.h" 81#include "coding.h"
82#include "composite.h" 82#include "composite.h"
83 83
84#ifdef CYGWIN
85#include <string.h>
86#include <stdio.h>
87#define _memccpy memccpy
88#endif
84 89
85static HGLOBAL convert_to_handle_as_ascii (void); 90static HGLOBAL convert_to_handle_as_ascii (void);
86static HGLOBAL convert_to_handle_as_coded (Lisp_Object coding_system); 91static HGLOBAL convert_to_handle_as_coded (Lisp_Object coding_system);
diff --git a/src/w32select.h b/src/w32select.h
new file mode 100644
index 00000000000..6924d4d51ae
--- /dev/null
+++ b/src/w32select.h
@@ -0,0 +1,30 @@
1/* Selection processing for Emacs on the Microsoft W32 API.
2
3Copyright (C) 1993-1994, 2001-2011 Free Software Foundation, Inc.
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 3 of the License, or
10(at your option) any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19
20#ifndef W32SELECT_H
21#define W32SELECT_H
22#include <windows.h>
23
24#define HAVE_W32SELECT 1
25
26extern void syms_of_w32select (void);
27extern void globals_of_w32select (void);
28extern void term_w32select (void);
29
30#endif
diff --git a/src/w32term.c b/src/w32term.c
index 71e6c7235a1..b18d07135ed 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -51,7 +51,14 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
51#include "atimer.h" 51#include "atimer.h"
52#include "keymap.h" 52#include "keymap.h"
53 53
54#ifdef WINDOWSNT
54#include "w32heap.h" 55#include "w32heap.h"
56#endif
57
58#ifndef WINDOWSNT
59#include <io.h> /* for get_osfhandle */
60#endif
61
55#include <shellapi.h> 62#include <shellapi.h>
56 63
57#include "font.h" 64#include "font.h"
@@ -121,7 +128,7 @@ typedef struct tagGLYPHSET
121 WCRANGE ranges[1]; 128 WCRANGE ranges[1];
122} GLYPHSET; 129} GLYPHSET;
123 130
124#endif 131#endif /* compiling for pre-Win2k */
125 132
126/* Dynamic linking to SetLayeredWindowAttribute (only since 2000). */ 133/* Dynamic linking to SetLayeredWindowAttribute (only since 2000). */
127BOOL (WINAPI *pfnSetLayeredWindowAttributes) (HWND, COLORREF, BYTE, DWORD); 134BOOL (WINAPI *pfnSetLayeredWindowAttributes) (HWND, COLORREF, BYTE, DWORD);
@@ -190,6 +197,13 @@ static int volatile input_signal_count;
190static int input_signal_count; 197static int input_signal_count;
191#endif 198#endif
192 199
200#ifdef CYGWIN
201int w32_message_fd = -1;
202#endif /* CYGWIN */
203
204/* Keyboard code page - may be changed by language-change events. */
205static int keyboard_codepage;
206
193static void x_update_window_end (struct window *, int, int); 207static void x_update_window_end (struct window *, int, int);
194static void w32_handle_tool_bar_click (struct frame *, 208static void w32_handle_tool_bar_click (struct frame *,
195 struct input_event *); 209 struct input_event *);
@@ -4256,6 +4270,9 @@ static char dbcs_lead = 0;
4256 This routine is called by the SIGIO handler. 4270 This routine is called by the SIGIO handler.
4257 We return as soon as there are no more events to be read. 4271 We return as soon as there are no more events to be read.
4258 4272
4273 For an overview of how Emacs input works on MS-Windows, see the
4274 commentary before w32_msg_pump in w32fns.c.
4275
4259 We return the number of characters stored into the buffer, 4276 We return the number of characters stored into the buffer,
4260 thus pretending to be `read'. 4277 thus pretending to be `read'.
4261 4278
@@ -4278,18 +4295,26 @@ w32_read_socket (struct terminal *terminal,
4278 struct frame *f; 4295 struct frame *f;
4279 struct w32_display_info *dpyinfo = &one_w32_display_info; 4296 struct w32_display_info *dpyinfo = &one_w32_display_info;
4280 Mouse_HLInfo *hlinfo = &dpyinfo->mouse_highlight; 4297 Mouse_HLInfo *hlinfo = &dpyinfo->mouse_highlight;
4298 static char buf[1];
4281 4299
4282 block_input (); 4300 block_input ();
4283 4301
4284 /* So people can tell when we have read the available input. */ 4302 /* So people can tell when we have read the available input. */
4285 input_signal_count++; 4303 input_signal_count++;
4286 4304
4305 /* Process any incoming thread messages. */
4306 drain_message_queue ();
4307
4287 /* TODO: ghostscript integration. */ 4308 /* TODO: ghostscript integration. */
4288 while (get_next_msg (&msg, FALSE)) 4309 while (get_next_msg (&msg, FALSE))
4289 { 4310 {
4290 struct input_event inev; 4311 struct input_event inev;
4291 int do_help = 0; 4312 int do_help = 0;
4292 4313
4314 /* DebPrint (("w32_read_socket: %s time:%u\n", */
4315 /* w32_name_of_message (msg.msg.message), */
4316 /* msg.msg.time)); */
4317
4293 EVENT_INIT (inev); 4318 EVENT_INIT (inev);
4294 inev.kind = NO_EVENT; 4319 inev.kind = NO_EVENT;
4295 inev.arg = Qnil; 4320 inev.arg = Qnil;
@@ -6428,8 +6453,15 @@ w32_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
6428 w32_defined_color (0, "black", &color, 1); 6453 w32_defined_color (0, "black", &color, 1);
6429 } 6454 }
6430 6455
6431 /* Add the default keyboard. */ 6456#ifdef WINDOWSNT
6457 /* Add the default keyboard. When !WINDOWSNT, we're using the
6458 standard Emacs console handling machinery and don't need an
6459 explicit FD here. */
6432 add_keyboard_wait_descriptor (0); 6460 add_keyboard_wait_descriptor (0);
6461#elif CYGWIN
6462 /* /dev/windows wakes us up when we have a thread message pending. */
6463 add_keyboard_wait_descriptor (w32_message_fd);
6464#endif
6433 6465
6434 /* Create Fringe Bitmaps and store them for later use. 6466 /* Create Fringe Bitmaps and store them for later use.
6435 6467
@@ -6440,15 +6472,6 @@ w32_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
6440 the bitmaps. */ 6472 the bitmaps. */
6441 w32_init_fringe (terminal->rif); 6473 w32_init_fringe (terminal->rif);
6442 6474
6443#ifdef F_SETOWN
6444 fcntl (connection, F_SETOWN, getpid ());
6445#endif /* ! defined (F_SETOWN) */
6446
6447#ifdef SIGIO
6448 if (interrupt_input)
6449 init_sigio (connection);
6450#endif /* ! defined (SIGIO) */
6451
6452 unblock_input (); 6475 unblock_input ();
6453 6476
6454 return dpyinfo; 6477 return dpyinfo;
@@ -6498,6 +6521,7 @@ x_delete_display (struct w32_display_info *dpyinfo)
6498 6521
6499 w32_reset_fringes (); 6522 w32_reset_fringes ();
6500} 6523}
6524
6501 6525
6502/* Set up use of W32. */ 6526/* Set up use of W32. */
6503 6527
@@ -6535,6 +6559,11 @@ w32_initialize (void)
6535 set_user_model (L"GNU.Emacs"); 6559 set_user_model (L"GNU.Emacs");
6536 } 6560 }
6537 6561
6562#ifdef CYGWIN
6563 if ((w32_message_fd = open ("/dev/windows", O_RDWR | O_CLOEXEC)) == -1)
6564 fatal ("opening /dev/windows: %s", strerror (errno));
6565#endif /* CYGWIN */
6566
6538 /* Initialize w32_use_visible_system_caret based on whether a screen 6567 /* Initialize w32_use_visible_system_caret based on whether a screen
6539 reader is in use. */ 6568 reader is in use. */
6540 if (!SystemParametersInfo (SPI_GETSCREENREADER, 0, 6569 if (!SystemParametersInfo (SPI_GETSCREENREADER, 0,
@@ -6701,4 +6730,6 @@ With MS Windows or Nextstep, the value is t. */);
6701 6730
6702 staticpro (&last_mouse_motion_frame); 6731 staticpro (&last_mouse_motion_frame);
6703 last_mouse_motion_frame = Qnil; 6732 last_mouse_motion_frame = Qnil;
6733
6734 Fprovide (intern_c_string ("w32"), Qnil);
6704} 6735}
diff --git a/src/w32term.h b/src/w32term.h
index 75537458981..6e4f8594d67 100644
--- a/src/w32term.h
+++ b/src/w32term.h
@@ -19,6 +19,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19/* Added by Kevin Gallo */ 19/* Added by Kevin Gallo */
20 20
21#include "w32gui.h" 21#include "w32gui.h"
22#include "frame.h"
23#include "atimer.h"
22 24
23 25
24#define BLACK_PIX_DEFAULT(f) PALETTERGB(0,0,0) 26#define BLACK_PIX_DEFAULT(f) PALETTERGB(0,0,0)
@@ -195,11 +197,45 @@ Lisp_Object display_x_get_resource (struct w32_display_info *,
195 Lisp_Object, Lisp_Object, 197 Lisp_Object, Lisp_Object,
196 Lisp_Object, Lisp_Object); 198 Lisp_Object, Lisp_Object);
197 199
200extern void x_focus_on_frame (struct frame *f);
201
202/* also defined in xterm.h XXX: factor out to common header */
203
198extern struct w32_display_info *w32_term_init (Lisp_Object, 204extern struct w32_display_info *w32_term_init (Lisp_Object,
199 char *, char *); 205 char *, char *);
200 206extern void check_w32 (void);
207extern int w32_defined_color (FRAME_PTR f, const char *color,
208 XColor *color_def, int alloc);
209extern void x_set_window_size (struct frame *f, int change_grav,
210 int cols, int rows);
201extern int x_display_pixel_height (struct w32_display_info *); 211extern int x_display_pixel_height (struct w32_display_info *);
202extern int x_display_pixel_width (struct w32_display_info *); 212extern int x_display_pixel_width (struct w32_display_info *);
213extern void x_sync (struct frame *);
214extern Lisp_Object x_get_focus_frame (struct frame *);
215extern void x_set_mouse_position (struct frame *f, int h, int v);
216extern void x_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y);
217extern void x_make_frame_visible (struct frame *f);
218extern void x_make_frame_invisible (struct frame *f);
219extern void x_iconify_frame (struct frame *f);
220extern int x_char_width (struct frame *f);
221extern int x_char_height (struct frame *f);
222extern int x_pixel_width (struct frame *f);
223extern int x_pixel_height (struct frame *f);
224extern void x_set_frame_alpha (struct frame *f);
225extern void x_set_menu_bar_lines (struct frame *, Lisp_Object, Lisp_Object);
226extern void x_set_tool_bar_lines (struct frame *f,
227 Lisp_Object value,
228 Lisp_Object oldval);
229extern void x_activate_menubar (struct frame *);
230extern int x_bitmap_icon (struct frame *, Lisp_Object);
231extern void initialize_frame_menubar (struct frame *);
232extern void x_free_frame_resources (struct frame *);
233extern void x_real_positions (struct frame *, int *, int *);
234
235/* w32inevt.c */
236extern int w32_kbd_patch_key (KEY_EVENT_RECORD *event, int cpId);
237extern int w32_kbd_mods_to_emacs (DWORD mods, WORD key);
238
203 239
204extern Lisp_Object x_get_focus_frame (struct frame *); 240extern Lisp_Object x_get_focus_frame (struct frame *);
205 241
@@ -584,8 +620,9 @@ do { \
584#define WM_EMACS_SETCURSOR (WM_EMACS_START + 19) 620#define WM_EMACS_SETCURSOR (WM_EMACS_START + 19)
585#define WM_EMACS_PAINT (WM_EMACS_START + 20) 621#define WM_EMACS_PAINT (WM_EMACS_START + 20)
586#define WM_EMACS_BRINGTOTOP (WM_EMACS_START + 21) 622#define WM_EMACS_BRINGTOTOP (WM_EMACS_START + 21)
587#define WM_EMACS_FILENOTIFY (WM_EMACS_START + 22) 623#define WM_EMACS_INPUT_READY (WM_EMACS_START + 22)
588#define WM_EMACS_END (WM_EMACS_START + 23) 624#define WM_EMACS_FILENOTIFY (WM_EMACS_START + 23)
625#define WM_EMACS_END (WM_EMACS_START + 24)
589 626
590#define WND_FONTWIDTH_INDEX (0) 627#define WND_FONTWIDTH_INDEX (0)
591#define WND_LINEHEIGHT_INDEX (4) 628#define WND_LINEHEIGHT_INDEX (4)
@@ -607,6 +644,8 @@ typedef struct W32Msg {
607 RECT rect; 644 RECT rect;
608} W32Msg; 645} W32Msg;
609 646
647extern BOOL prepend_msg (W32Msg *lpmsg);
648
610/* Structure for recording message when input thread must return a 649/* Structure for recording message when input thread must return a
611 result that depends on lisp thread to compute. Lisp thread can 650 result that depends on lisp thread to compute. Lisp thread can
612 complete deferred messages out of order. */ 651 complete deferred messages out of order. */
@@ -715,3 +754,19 @@ extern HWND w32_system_caret_hwnd;
715extern int w32_system_caret_height; 754extern int w32_system_caret_height;
716extern int w32_system_caret_x; 755extern int w32_system_caret_x;
717extern int w32_system_caret_y; 756extern int w32_system_caret_y;
757
758#if EMACSDEBUG
759extern const char*
760w32_name_of_message (UINT msg);
761#endif /* EMACSDEBUG */
762
763extern void syms_of_w32term (void);
764extern void syms_of_w32menu (void);
765extern void syms_of_w32fns (void);
766
767extern void globals_of_w32menu (void);
768extern void globals_of_w32fns (void);
769
770#ifdef CYGWIN
771extern int w32_message_fd;
772#endif /* CYGWIN */
diff --git a/src/w32xfns.c b/src/w32xfns.c
index 018dd14cb80..cb452571665 100644
--- a/src/w32xfns.c
+++ b/src/w32xfns.c
@@ -19,6 +19,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19#include <config.h> 19#include <config.h>
20#include <signal.h> 20#include <signal.h>
21#include <stdio.h> 21#include <stdio.h>
22
22#include "lisp.h" 23#include "lisp.h"
23#include "keyboard.h" 24#include "keyboard.h"
24#include "frame.h" 25#include "frame.h"
@@ -32,7 +33,11 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
32#define myfree(lp) GlobalFreePtr (lp) 33#define myfree(lp) GlobalFreePtr (lp)
33 34
34CRITICAL_SECTION critsect; 35CRITICAL_SECTION critsect;
36
37#ifdef WINDOWSNT
35extern HANDLE keyboard_handle; 38extern HANDLE keyboard_handle;
39#endif /* WINDOWSNT */
40
36HANDLE input_available = NULL; 41HANDLE input_available = NULL;
37HANDLE interrupt_handle = NULL; 42HANDLE interrupt_handle = NULL;
38 43
@@ -43,7 +48,11 @@ init_crit (void)
43 48
44 /* For safety, input_available should only be reset by get_next_msg 49 /* For safety, input_available should only be reset by get_next_msg
45 when the input queue is empty, so make it a manual reset event. */ 50 when the input queue is empty, so make it a manual reset event. */
46 keyboard_handle = input_available = CreateEvent (NULL, TRUE, FALSE, NULL); 51 input_available = CreateEvent (NULL, TRUE, FALSE, NULL);
52
53#ifdef WINDOWSNT
54 keyboard_handle = input_available;
55#endif /* WINDOWSNT */
47 56
48 /* interrupt_handle is signaled when quit (C-g) is detected, so that 57 /* interrupt_handle is signaled when quit (C-g) is detected, so that
49 blocking system calls can be interrupted. We make it a manual 58 blocking system calls can be interrupted. We make it a manual
@@ -240,6 +249,22 @@ get_next_msg (W32Msg * lpmsg, BOOL bWait)
240 return (bRet); 249 return (bRet);
241} 250}
242 251
252extern char * w32_strerror (int error_no);
253
254/* Tell the main thread that we have input available; if the main
255 thread is blocked in select(), we wake it up here. */
256static void
257notify_msg_ready (void)
258{
259 SetEvent (input_available);
260
261#ifdef CYGWIN
262 /* Wakes up the main thread, which is blocked select()ing for /dev/windows,
263 among other files. */
264 (void) PostThreadMessage (dwMainThreadId, WM_EMACS_INPUT_READY, 0, 0);
265#endif /* CYGWIN */
266}
267
243BOOL 268BOOL
244post_msg (W32Msg * lpmsg) 269post_msg (W32Msg * lpmsg)
245{ 270{
@@ -263,8 +288,7 @@ post_msg (W32Msg * lpmsg)
263 } 288 }
264 289
265 lpTail = lpNew; 290 lpTail = lpNew;
266 SetEvent (input_available); 291 notify_msg_ready ();
267
268 leave_crit (); 292 leave_crit ();
269 293
270 return (TRUE); 294 return (TRUE);
@@ -285,7 +309,7 @@ prepend_msg (W32Msg *lpmsg)
285 nQueue++; 309 nQueue++;
286 lpNew->lpNext = lpHead; 310 lpNew->lpNext = lpHead;
287 lpHead = lpNew; 311 lpHead = lpNew;
288 312 notify_msg_ready ();
289 leave_crit (); 313 leave_crit ();
290 314
291 return (TRUE); 315 return (TRUE);
diff --git a/src/window.c b/src/window.c
index 3b974616e38..61d2a8b073f 100644
--- a/src/window.c
+++ b/src/window.c
@@ -43,7 +43,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
43#ifdef HAVE_X_WINDOWS 43#ifdef HAVE_X_WINDOWS
44#include "xterm.h" 44#include "xterm.h"
45#endif /* HAVE_X_WINDOWS */ 45#endif /* HAVE_X_WINDOWS */
46#ifdef WINDOWSNT 46#ifdef HAVE_NTGUI
47#include "w32term.h" 47#include "w32term.h"
48#endif 48#endif
49#ifdef MSDOS 49#ifdef MSDOS
diff --git a/src/xdisp.c b/src/xdisp.c
index 635e7ecd0b2..2047c0e78c1 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -302,7 +302,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
302#ifdef HAVE_X_WINDOWS 302#ifdef HAVE_X_WINDOWS
303#include "xterm.h" 303#include "xterm.h"
304#endif 304#endif
305#ifdef WINDOWSNT 305#ifdef HAVE_NTGUI
306#include "w32term.h" 306#include "w32term.h"
307#endif 307#endif
308#ifdef HAVE_NS 308#ifdef HAVE_NS
diff --git a/src/xfaces.c b/src/xfaces.c
index f861dde2d15..3e6e9dc8ec0 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -227,13 +227,13 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
227#ifdef HAVE_WINDOW_SYSTEM 227#ifdef HAVE_WINDOW_SYSTEM
228#include TERM_HEADER 228#include TERM_HEADER
229#include "fontset.h" 229#include "fontset.h"
230#ifdef WINDOWSNT 230#ifdef HAVE_NTGUI
231#undef FRAME_X_DISPLAY_INFO 231#undef FRAME_X_DISPLAY_INFO
232#define FRAME_X_DISPLAY_INFO FRAME_W32_DISPLAY_INFO 232#define FRAME_X_DISPLAY_INFO FRAME_W32_DISPLAY_INFO
233#define x_display_info w32_display_info 233#define x_display_info w32_display_info
234#define check_x check_w32 234#define check_x check_w32
235#define GCGraphicsExposures 0 235#define GCGraphicsExposures 0
236#endif /* WINDOWSNT */ 236#endif /* HAVE_NTGUI */
237 237
238#ifdef HAVE_NS 238#ifdef HAVE_NS
239#undef FRAME_X_DISPLAY_INFO 239#undef FRAME_X_DISPLAY_INFO
@@ -625,7 +625,7 @@ x_free_gc (struct frame *f, GC gc)
625 625
626#endif /* HAVE_X_WINDOWS */ 626#endif /* HAVE_X_WINDOWS */
627 627
628#ifdef WINDOWSNT 628#ifdef HAVE_NTGUI
629/* W32 emulation of GCs */ 629/* W32 emulation of GCs */
630 630
631static GC 631static GC
@@ -649,7 +649,7 @@ x_free_gc (struct frame *f, GC gc)
649 xfree (gc); 649 xfree (gc);
650} 650}
651 651
652#endif /* WINDOWSNT */ 652#endif /* HAVE_NTGUI */
653 653
654#ifdef HAVE_NS 654#ifdef HAVE_NS
655/* NS emulation of GCs */ 655/* NS emulation of GCs */
@@ -719,7 +719,7 @@ init_frame_faces (struct frame *f)
719#ifdef HAVE_X_WINDOWS 719#ifdef HAVE_X_WINDOWS
720 if (!FRAME_X_P (f) || FRAME_X_WINDOW (f)) 720 if (!FRAME_X_P (f) || FRAME_X_WINDOW (f))
721#endif 721#endif
722#ifdef WINDOWSNT 722#ifdef HAVE_NTGUI
723 if (!FRAME_WINDOW_P (f) || FRAME_W32_WINDOW (f)) 723 if (!FRAME_WINDOW_P (f) || FRAME_W32_WINDOW (f))
724#endif 724#endif
725#ifdef HAVE_NS 725#ifdef HAVE_NS
@@ -1098,7 +1098,7 @@ defined_color (struct frame *f, const char *color_name, XColor *color_def,
1098 else if (FRAME_X_P (f)) 1098 else if (FRAME_X_P (f))
1099 return x_defined_color (f, color_name, color_def, alloc); 1099 return x_defined_color (f, color_name, color_def, alloc);
1100#endif 1100#endif
1101#ifdef WINDOWSNT 1101#ifdef HAVE_NTGUI
1102 else if (FRAME_W32_P (f)) 1102 else if (FRAME_W32_P (f))
1103 return w32_defined_color (f, color_name, color_def, alloc); 1103 return w32_defined_color (f, color_name, color_def, alloc);
1104#endif 1104#endif
@@ -3245,7 +3245,7 @@ FRAME 0 means change the face on all frames, and change the default
3245 param = Qbackground_color; 3245 param = Qbackground_color;
3246 } 3246 }
3247#ifdef HAVE_WINDOW_SYSTEM 3247#ifdef HAVE_WINDOW_SYSTEM
3248#ifndef WINDOWSNT 3248#ifndef HAVE_NTGUI
3249 else if (EQ (face, Qscroll_bar)) 3249 else if (EQ (face, Qscroll_bar))
3250 { 3250 {
3251 /* Changing the colors of `scroll-bar' sets frame parameters 3251 /* Changing the colors of `scroll-bar' sets frame parameters
@@ -3255,7 +3255,7 @@ FRAME 0 means change the face on all frames, and change the default
3255 else if (EQ (attr, QCbackground)) 3255 else if (EQ (attr, QCbackground))
3256 param = Qscroll_bar_background; 3256 param = Qscroll_bar_background;
3257 } 3257 }
3258#endif /* not WINDOWSNT */ 3258#endif /* not HAVE_NTGUI */
3259 else if (EQ (face, Qborder)) 3259 else if (EQ (face, Qborder))
3260 { 3260 {
3261 /* Changing background color of `border' sets frame parameter 3261 /* Changing background color of `border' sets frame parameter
@@ -6362,7 +6362,7 @@ where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
6362 if (num >= 0 && name[num] == '\n') 6362 if (num >= 0 && name[num] == '\n')
6363 name[num] = 0; 6363 name[num] = 0;
6364 cmap = Fcons (Fcons (build_string (name), 6364 cmap = Fcons (Fcons (build_string (name),
6365#ifdef WINDOWSNT 6365#ifdef HAVE_NTGUI
6366 make_number (RGB (red, green, blue))), 6366 make_number (RGB (red, green, blue))),
6367#else 6367#else
6368 make_number ((red << 16) | (green << 8) | blue)), 6368 make_number ((red << 16) | (green << 8) | blue)),