aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDaniel Colascione2012-09-17 03:55:02 -0800
committerDaniel Colascione2012-09-17 03:55:02 -0800
commit0fda9b750e337d876c9461db7d4426a3f0b81482 (patch)
tree1e1659bfa590cd8375c564c6fb5c3bafa65e06c0 /src
parent8b33967313f09a736a833816d32fd52e10640969 (diff)
downloademacs-0fda9b750e337d876c9461db7d4426a3f0b81482.tar.gz
emacs-0fda9b750e337d876c9461db7d4426a3f0b81482.zip
Implement cygw32
Here, we use the generic window-system configuration system we just implemented to support the w32 window-system in the mainline build under Cygwin. (Previously, the w32 window system could only be compiled as part of the NT-native Emacs build process.) The changes in this patch need to be applied atomically in order to avoid breaking Emacs. The changes include: - Changes throughout the Lisp and C code to not assume that NT Emacs and the w32 window system are synonymous. - Wiring up the regular select(2) event loop to Windows messages - Cleaning up the w32 drag-and-drop receiving code. - Exposing Cygwin path conversion functions to elisp. - Unicode file dialog support when compiling for Cygwin. - Splitting the w32 term lisp initialization code into code applicable to any w32 window-system and code specific to system-type windows-nt. - Integrating the old and new w32 code into the build system.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.in25
-rw-r--r--src/conf_post.h14
-rw-r--r--src/dispextern.h4
-rw-r--r--src/emacs.c28
-rw-r--r--src/font.c4
-rw-r--r--src/font.h4
-rw-r--r--src/fontset.c2
-rw-r--r--src/frame.c4
-rw-r--r--src/frame.h5
-rw-r--r--src/image.c62
-rw-r--r--src/keyboard.c12
-rw-r--r--src/keyboard.h2
-rw-r--r--src/menu.c4
-rw-r--r--src/process.c1
-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.c732
-rw-r--r--src/w32font.c4
-rw-r--r--src/w32heap.c41
-rw-r--r--src/w32inevt.c172
-rw-r--r--src/w32menu.c26
-rw-r--r--src/w32proc.c14
-rw-r--r--src/w32select.c5
-rw-r--r--src/w32term.c52
-rw-r--r--src/w32term.h63
-rw-r--r--src/w32xfns.c32
-rw-r--r--src/window.c2
-rw-r--r--src/xdisp.c6
-rw-r--r--src/xfaces.c18
-rw-r--r--src/xterm.h1
33 files changed, 912 insertions, 520 deletions
diff --git a/src/Makefile.in b/src/Makefile.in
index a809216f095..847a5e58fd7 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@
@@ -263,6 +260,13 @@ NS_OBJ=@NS_OBJ@
263NS_OBJC_OBJ=@NS_OBJC_OBJ@ 260NS_OBJC_OBJ=@NS_OBJC_OBJ@
264## Only set if NS_IMPL_GNUSTEP. 261## Only set if NS_IMPL_GNUSTEP.
265GNU_OBJC_CFLAGS=@GNU_OBJC_CFLAGS@ 262GNU_OBJC_CFLAGS=@GNU_OBJC_CFLAGS@
263## w32fns.o w32menu.c w32reg.o fringe.o fontset.o w32font.o w32term.o
264## w32xfns.o w32select.o image.o w32uniscribe.o if HAVE_W32, else
265## empty.
266W32_OBJ=@W32_OBJ@
267## -lkernel32 -luser32 -lgdi32 -lole32 -lcomdlg32 lusp10 -lcomctl32
268## --lwinspool if HAVE_W32, else empty.
269W32_LIBS=@W32_LIBS@
266 270
267## Empty if !HAVE_X_WINDOWS 271## Empty if !HAVE_X_WINDOWS
268## xfont.o ftfont.o xftfont.o ftxfont.o if HAVE_XFT 272## xfont.o ftfont.o xftfont.o ftxfont.o if HAVE_XFT
@@ -343,7 +347,7 @@ base_obj = dispnew.o frame.o scroll.o xdisp.o menu.o $(XMENU_OBJ) window.o \
343 region-cache.o sound.o atimer.o \ 347 region-cache.o sound.o atimer.o \
344 doprnt.o intervals.o textprop.o composite.o xml.o \ 348 doprnt.o intervals.o textprop.o composite.o xml.o \
345 $(MSDOS_OBJ) $(MSDOS_X_OBJ) $(NS_OBJ) $(CYGWIN_OBJ) $(FONT_OBJ) \ 349 $(MSDOS_OBJ) $(MSDOS_X_OBJ) $(NS_OBJ) $(CYGWIN_OBJ) $(FONT_OBJ) \
346 $(WINDOW_SYSTEM_OBJ) 350 $(W32_OBJ) $(WINDOW_SYSTEM_OBJ)
347obj = $(base_obj) $(NS_OBJC_OBJ) 351obj = $(base_obj) $(NS_OBJC_OBJ)
348 352
349## Object files used on some machine or other. 353## Object files used on some machine or other.
@@ -352,9 +356,9 @@ obj = $(base_obj) $(NS_OBJC_OBJ)
352## in the list, in case they ever add any such entries. 356## in the list, in case they ever add any such entries.
353SOME_MACHINE_OBJECTS = dosfns.o msdos.o \ 357SOME_MACHINE_OBJECTS = dosfns.o msdos.o \
354 xterm.o xfns.o xmenu.o xselect.o xrdb.o xsmfns.o fringe.o image.o \ 358 xterm.o xfns.o xmenu.o xselect.o xrdb.o xsmfns.o fringe.o image.o \
355 fontset.o dbusbind.o \ 359 fontset.o dbusbind.o cygw32.o \
356 nsterm.o nsfns.o nsmenu.o nsselect.o nsimage.o nsfont.o \ 360 nsterm.o nsfns.o nsmenu.o nsselect.o nsimage.o nsfont.o \
357 w32.o w32console.o w32fns.o w32heap.o w32inevt.o \ 361 w32.o w32console.o w32fns.o w32heap.o \
358 w32menu.o w32proc.o w32reg.o w32select.o w32term.o w32xfns.o \ 362 w32menu.o w32proc.o w32reg.o w32select.o w32term.o w32xfns.o \
359 w16select.o widget.o xfont.o ftfont.o xftfont.o ftxfont.o gtkutil.o \ 363 w16select.o widget.o xfont.o ftfont.o xftfont.o ftxfont.o gtkutil.o \
360 xsettings.o xgselect.o termcap.o 364 xsettings.o xgselect.o termcap.o
@@ -386,7 +390,8 @@ otherobj= $(TERMCAP_OBJ) $(PRE_ALLOC_OBJ) $(GMALLOC_OBJ) $(RALLOC_OBJ) \
386## Note that SunOS needs -lm to come before -lc; otherwise, you get 390## Note that SunOS needs -lm to come before -lc; otherwise, you get
387## duplicated symbols. If the standard libraries were compiled 391## duplicated symbols. If the standard libraries were compiled
388## with GCC, we might need LIB_GCC again after them. 392## with GCC, we might need LIB_GCC again after them.
389LIBES = $(LIBS) $(LIBX_BASE) $(LIBX_OTHER) $(LIBSOUND) \ 393LIBES = $(LIBS) $(W32_LIBS) $(LIBX_BASE) $(LIBIMAGE) \
394 $(LIBX_OTHER) $(LIBSOUND) \
390 $(RSVG_LIBS) $(IMAGEMAGICK_LIBS) $(LIB_CLOCK_GETTIME) $(DBUS_LIBS) \ 395 $(RSVG_LIBS) $(IMAGEMAGICK_LIBS) $(LIB_CLOCK_GETTIME) $(DBUS_LIBS) \
391 $(LIB_EXECINFO) \ 396 $(LIB_EXECINFO) \
392 $(LIBXML2_LIBS) $(LIBGPM) $(LIBRESOLV) $(LIBS_SYSTEM) \ 397 $(LIBXML2_LIBS) $(LIBGPM) $(LIBRESOLV) $(LIBS_SYSTEM) \
diff --git a/src/conf_post.h b/src/conf_post.h
index f90ef90fb83..8bd66be2c4d 100644
--- a/src/conf_post.h
+++ b/src/conf_post.h
@@ -164,6 +164,20 @@ You lose; /* Emacs for DOS must be compiled with DJGPP */
164#endif 164#endif
165#endif 165#endif
166 166
167#if defined(HAVE_NTGUI) && !defined(DebPrint)
168# if defined(EMACSDEBUG)
169extern void _DebPrint (const char *fmt, ...);
170# define DebPrint(stuff) _DebPrint stuff
171# else
172# define DebPrint(stuff)
173# endif /* EMACSDEBUG */
174#endif /* DebPrint */
175
176#if defined(CYGWIN) && defined(HAVE_NTGUI)
177#define NTGUI_UNICODE /* Cygwin runs only on UNICODE-supporting systems */
178#define _WIN32_WINNT 0x500 /* Win2k */
179#endif /* CYGWIN && HAVE_NTGUI */
180
167#ifdef emacs /* Don't do this for lib-src. */ 181#ifdef emacs /* Don't do this for lib-src. */
168/* Tell regex.c to use a type compatible with Emacs. */ 182/* Tell regex.c to use a type compatible with Emacs. */
169#define RE_TRANSLATE_TYPE Lisp_Object 183#define RE_TRANSLATE_TYPE Lisp_Object
diff --git a/src/dispextern.h b/src/dispextern.h
index 1140d98f8a7..1aff547f187 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -3139,7 +3139,7 @@ int draw_window_fringes (struct window *, int);
3139int update_window_fringes (struct window *, int); 3139int update_window_fringes (struct window *, int);
3140void compute_fringe_widths (struct frame *, int); 3140void compute_fringe_widths (struct frame *, int);
3141 3141
3142#ifdef WINDOWSNT 3142#ifdef HAVE_NTGUI
3143void w32_init_fringe (struct redisplay_interface *); 3143void w32_init_fringe (struct redisplay_interface *);
3144void w32_reset_fringes (void); 3144void w32_reset_fringes (void);
3145#endif 3145#endif
@@ -3241,7 +3241,7 @@ extern char unspecified_fg[], unspecified_bg[];
3241#ifdef HAVE_X_WINDOWS 3241#ifdef HAVE_X_WINDOWS
3242void gamma_correct (struct frame *, XColor *); 3242void gamma_correct (struct frame *, XColor *);
3243#endif 3243#endif
3244#ifdef WINDOWSNT 3244#ifdef HAVE_NTGUI
3245void gamma_correct (struct frame *, COLORREF *); 3245void gamma_correct (struct frame *, COLORREF *);
3246#endif 3246#endif
3247 3247
diff --git a/src/emacs.c b/src/emacs.c
index adfff6ff3ed..9a9309546ab 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -37,9 +37,20 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
37 37
38#ifdef WINDOWSNT 38#ifdef WINDOWSNT
39#include <fcntl.h> 39#include <fcntl.h>
40#include <windows.h> /* just for w32.h */
41#include "w32.h" 40#include "w32.h"
42#include "w32heap.h" /* for prototype of sbrk */ 41#endif
42
43#if defined (WINDOWSNT)
44#include "w32heap.h"
45#endif
46
47#if defined (WINDOWSNT) || defined (HAVE_NTGUI)
48#include "w32select.h"
49#include "w32font.h"
50#endif
51
52#if defined (HAVE_NTGUI) && defined (CYGWIN)
53#include "cygw32.h"
43#endif 54#endif
44 55
45#ifdef NS_IMPL_GNUSTEP 56#ifdef NS_IMPL_GNUSTEP
@@ -1484,6 +1495,9 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1484#ifdef WINDOWSNT 1495#ifdef WINDOWSNT
1485 syms_of_ntproc (); 1496 syms_of_ntproc ();
1486#endif /* WINDOWSNT */ 1497#endif /* WINDOWSNT */
1498#if defined (CYGWIN) && defined (HAVE_NTGUI)
1499 syms_of_cygw32 ();
1500#endif /* defined(CYGWIN) && defined (HAVE_NTGUI) */
1487 syms_of_window (); 1501 syms_of_window ();
1488 syms_of_xdisp (); 1502 syms_of_xdisp ();
1489 syms_of_font (); 1503 syms_of_font ();
@@ -1514,11 +1528,14 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1514#ifdef HAVE_NTGUI 1528#ifdef HAVE_NTGUI
1515 syms_of_w32term (); 1529 syms_of_w32term ();
1516 syms_of_w32fns (); 1530 syms_of_w32fns ();
1517 syms_of_w32select ();
1518 syms_of_w32menu (); 1531 syms_of_w32menu ();
1519 syms_of_fontset (); 1532 syms_of_fontset ();
1520#endif /* HAVE_NTGUI */ 1533#endif /* HAVE_NTGUI */
1521 1534
1535#ifdef HAVE_W32SELECT
1536 syms_of_w32select ();
1537#endif /* HAVE_W32SELECT */
1538
1522#ifdef MSDOS 1539#ifdef MSDOS
1523 syms_of_xmenu (); 1540 syms_of_xmenu ();
1524 syms_of_dosfns (); 1541 syms_of_dosfns ();
@@ -1561,8 +1578,11 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1561 globals_of_w32font (); 1578 globals_of_w32font ();
1562 globals_of_w32fns (); 1579 globals_of_w32fns ();
1563 globals_of_w32menu (); 1580 globals_of_w32menu ();
1564 globals_of_w32select ();
1565#endif /* HAVE_NTGUI */ 1581#endif /* HAVE_NTGUI */
1582
1583#ifdef HAVE_W32SELECT
1584 globals_of_w32select ();
1585#endif /* HAVE_W32SELECT */
1566 } 1586 }
1567 1587
1568 init_charset (); 1588 init_charset ();
diff --git a/src/font.c b/src/font.c
index cf9964f08f3..c775b56caa9 100644
--- a/src/font.c
+++ b/src/font.c
@@ -5207,9 +5207,9 @@ EMACS_FONT_LOG is set. Otherwise, it is set to t. */);
5207#ifdef HAVE_BDFFONT 5207#ifdef HAVE_BDFFONT
5208 syms_of_bdffont (); 5208 syms_of_bdffont ();
5209#endif /* HAVE_BDFFONT */ 5209#endif /* HAVE_BDFFONT */
5210#ifdef WINDOWSNT 5210#ifdef HAVE_NTGUI
5211 syms_of_w32font (); 5211 syms_of_w32font ();
5212#endif /* WINDOWSNT */ 5212#endif /* HAVE_NTGUI */
5213#ifdef HAVE_NS 5213#ifdef HAVE_NS
5214 syms_of_nsfont (); 5214 syms_of_nsfont ();
5215#endif /* HAVE_NS */ 5215#endif /* HAVE_NS */
diff --git a/src/font.h b/src/font.h
index 6e9387f7632..5ed9affa9ef 100644
--- a/src/font.h
+++ b/src/font.h
@@ -826,11 +826,11 @@ extern struct font_driver ftxfont_driver;
826extern void syms_of_bdffont (void); 826extern void syms_of_bdffont (void);
827#endif /* HAVE_BDFFONT */ 827#endif /* HAVE_BDFFONT */
828#endif /* HAVE_X_WINDOWS */ 828#endif /* HAVE_X_WINDOWS */
829#ifdef WINDOWSNT 829#ifdef HAVE_NTGUI
830extern struct font_driver w32font_driver; 830extern struct font_driver w32font_driver;
831extern struct font_driver uniscribe_font_driver; 831extern struct font_driver uniscribe_font_driver;
832extern void syms_of_w32font (void); 832extern void syms_of_w32font (void);
833#endif /* WINDOWSNT */ 833#endif /* HAVE_NTGUI */
834#ifdef HAVE_NS 834#ifdef HAVE_NS
835extern Lisp_Object Qfontsize; 835extern Lisp_Object Qfontsize;
836extern struct font_driver nsfont_driver; 836extern struct font_driver nsfont_driver;
diff --git a/src/fontset.c b/src/fontset.c
index 01e38fe45e5..783f99c210c 100644
--- a/src/fontset.c
+++ b/src/fontset.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 45#endif
46#ifdef WINDOWSNT 46#ifdef HAVE_NTGUI
47#include "w32term.h" 47#include "w32term.h"
48#endif 48#endif
49#ifdef HAVE_NS 49#ifdef HAVE_NS
diff --git a/src/frame.c b/src/frame.c
index 968cb4905a2..aa1508e6d28 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -2693,7 +2693,7 @@ static const struct frame_parm_table frame_parms[] =
2693 {"tool-bar-position", &Qtool_bar_position}, 2693 {"tool-bar-position", &Qtool_bar_position},
2694}; 2694};
2695 2695
2696#ifdef WINDOWSNT 2696#ifdef HAVE_NTGUI
2697 2697
2698/* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the 2698/* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
2699 wanted positions of the WM window (not Emacs window). 2699 wanted positions of the WM window (not Emacs window).
@@ -2737,7 +2737,7 @@ x_fullscreen_adjust (struct frame *f, int *width, int *height, int *top_pos, int
2737 *height = newheight; 2737 *height = newheight;
2738} 2738}
2739 2739
2740#endif /* WINDOWSNT */ 2740#endif /* HAVE_NTGUI */
2741 2741
2742#ifdef HAVE_WINDOW_SYSTEM 2742#ifdef HAVE_WINDOW_SYSTEM
2743 2743
diff --git a/src/frame.h b/src/frame.h
index 1fe3ebd9182..2e0bcee432c 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -621,7 +621,7 @@ typedef struct frame *FRAME_PTR;
621#define FRAME_INITIAL_P(f) ((f)->output_method == output_initial) 621#define FRAME_INITIAL_P(f) ((f)->output_method == output_initial)
622#define FRAME_TERMCAP_P(f) ((f)->output_method == output_termcap) 622#define FRAME_TERMCAP_P(f) ((f)->output_method == output_termcap)
623#define FRAME_X_P(f) ((f)->output_method == output_x_window) 623#define FRAME_X_P(f) ((f)->output_method == output_x_window)
624#ifndef WINDOWSNT 624#ifndef HAVE_NTGUI
625#define FRAME_W32_P(f) (0) 625#define FRAME_W32_P(f) (0)
626#else 626#else
627#define FRAME_W32_P(f) ((f)->output_method == output_w32) 627#define FRAME_W32_P(f) ((f)->output_method == output_w32)
@@ -1213,7 +1213,7 @@ extern Lisp_Object x_new_font (struct frame *, Lisp_Object, int);
1213 1213
1214extern Lisp_Object Qface_set_after_frame_default; 1214extern Lisp_Object Qface_set_after_frame_default;
1215 1215
1216#ifdef WINDOWSNT 1216#ifdef HAVE_NTGUI
1217extern void x_fullscreen_adjust (struct frame *f, int *, int *, 1217extern void x_fullscreen_adjust (struct frame *f, int *, int *,
1218 int *, int *); 1218 int *, int *);
1219#endif 1219#endif
@@ -1285,6 +1285,7 @@ extern char *x_get_resource_string (const char *, const char *);
1285#endif 1285#endif
1286 1286
1287extern void x_query_colors (struct frame *f, XColor *, int); 1287extern void x_query_colors (struct frame *f, XColor *, int);
1288extern void x_query_color (struct frame *f, XColor *);
1288 1289
1289/* In xmenu.c */ 1290/* In xmenu.c */
1290extern void set_frame_menubar (FRAME_PTR, int, int); 1291extern void set_frame_menubar (FRAME_PTR, int, int);
diff --git a/src/image.c b/src/image.c
index d4e78d41000..b5a2e0328eb 100644
--- a/src/image.c
+++ b/src/image.c
@@ -76,7 +76,11 @@ typedef struct x_bitmap_record Bitmap_Record;
76#endif /* HAVE_X_WINDOWS */ 76#endif /* HAVE_X_WINDOWS */
77 77
78#ifdef HAVE_NTGUI 78#ifdef HAVE_NTGUI
79#include "w32.h" 79# ifdef WINDOWSNT
80/* We only need (or want) w32.h when we're _not_
81 * compiling for Cygwin */
82# include "w32.h"
83# endif /* WINDOWSNT */
80/* W32_TODO : Color tables on W32. */ 84/* W32_TODO : Color tables on W32. */
81#undef COLOR_TABLE_SUPPORT 85#undef COLOR_TABLE_SUPPORT
82 86
@@ -569,13 +573,14 @@ static void x_laplace (struct frame *, struct image *);
569static void x_emboss (struct frame *, struct image *); 573static void x_emboss (struct frame *, struct image *);
570static int x_build_heuristic_mask (struct frame *, struct image *, 574static int x_build_heuristic_mask (struct frame *, struct image *,
571 Lisp_Object); 575 Lisp_Object);
572#ifdef HAVE_NTGUI 576#ifdef WINDOWSNT
573extern Lisp_Object Vlibrary_cache, QCloaded_from; 577extern Lisp_Object Vlibrary_cache;
578
574#define CACHE_IMAGE_TYPE(type, status) \ 579#define CACHE_IMAGE_TYPE(type, status) \
575 do { Vlibrary_cache = Fcons (Fcons (type, status), Vlibrary_cache); } while (0) 580 do { Vlibrary_cache = Fcons (Fcons (type, status), Vlibrary_cache); } while (0)
576#else 581#else
577#define CACHE_IMAGE_TYPE(type, status) 582#define CACHE_IMAGE_TYPE(type, status)
578#endif 583#endif /* WINDOWSNT */
579 584
580#define ADD_IMAGE_TYPE(type) \ 585#define ADD_IMAGE_TYPE(type) \
581 do { Vimage_types = Fcons (type, Vimage_types); } while (0) 586 do { Vimage_types = Fcons (type, Vimage_types); } while (0)
@@ -1861,7 +1866,7 @@ mark_image_cache (struct image_cache *c)
1861 X / NS / W32 support code 1866 X / NS / W32 support code
1862 ***********************************************************************/ 1867 ***********************************************************************/
1863 1868
1864#ifdef HAVE_NTGUI 1869#ifdef WINDOWSNT
1865 1870
1866/* Macro for defining functions that will be loaded from image DLLs. */ 1871/* Macro for defining functions that will be loaded from image DLLs. */
1867#define DEF_IMGLIB_FN(rettype,func,args) static rettype (FAR CDECL *fn_##func)args 1872#define DEF_IMGLIB_FN(rettype,func,args) static rettype (FAR CDECL *fn_##func)args
@@ -1872,7 +1877,7 @@ mark_image_cache (struct image_cache *c)
1872 if (!fn_##func) return 0; \ 1877 if (!fn_##func) return 0; \
1873 } 1878 }
1874 1879
1875#endif /* HAVE_NTGUI */ 1880#endif /* WINDOWSNT */
1876 1881
1877static int x_create_x_image_and_pixmap (struct frame *, int, int, int, 1882static int x_create_x_image_and_pixmap (struct frame *, int, int, int,
1878 XImagePtr *, Pixmap *); 1883 XImagePtr *, Pixmap *);
@@ -2935,7 +2940,7 @@ xbm_load (struct frame *f, struct image *img)
2935 else 2940 else
2936 bits = (char *) XBOOL_VECTOR (data)->data; 2941 bits = (char *) XBOOL_VECTOR (data)->data;
2937 2942
2938#ifdef WINDOWSNT 2943#ifdef HAVE_NTGUI
2939 { 2944 {
2940 char *invertedBits; 2945 char *invertedBits;
2941 int nbytes, i; 2946 int nbytes, i;
@@ -3243,7 +3248,7 @@ xpm_free_colors (Display *dpy, Colormap cmap, Pixel *pixels, int npixels, void *
3243#endif /* ALLOC_XPM_COLORS */ 3248#endif /* ALLOC_XPM_COLORS */
3244 3249
3245 3250
3246#ifdef HAVE_NTGUI 3251#ifdef WINDOWSNT
3247 3252
3248/* XPM library details. */ 3253/* XPM library details. */
3249 3254
@@ -3269,8 +3274,15 @@ init_xpm_functions (Lisp_Object libraries)
3269 return 1; 3274 return 1;
3270} 3275}
3271 3276
3272#endif /* HAVE_NTGUI */ 3277#endif /* WINDOWSNT */
3273 3278
3279#ifdef HAVE_NTGUI
3280/* Glue for code below */
3281#define fn_XpmReadFileToImage XpmReadFileToImage
3282#define fn_XpmCreateImageFromBuffer XpmCreateImageFromBuffer
3283#define fn_XImageFree XImageFree
3284#define fn_XpmFreeAttributes XpmFreeAttributes
3285#endif /* HAVE_NTGUI */
3274 3286
3275/* Value is non-zero if COLOR_SYMBOLS is a valid color symbols list 3287/* Value is non-zero if COLOR_SYMBOLS is a valid color symbols list
3276 for XPM images. Such a list must consist of conses whose car and 3288 for XPM images. Such a list must consist of conses whose car and
@@ -5414,7 +5426,7 @@ png_image_p (Lisp_Object object)
5414 5426
5415#ifdef HAVE_PNG 5427#ifdef HAVE_PNG
5416 5428
5417#ifdef HAVE_NTGUI 5429#ifdef WINDOWSNT
5418/* PNG library details. */ 5430/* PNG library details. */
5419 5431
5420DEF_IMGLIB_FN (png_voidp, png_get_io_ptr, (png_structp)); 5432DEF_IMGLIB_FN (png_voidp, png_get_io_ptr, (png_structp));
@@ -5514,7 +5526,7 @@ init_png_functions (Lisp_Object libraries)
5514#define fn_png_set_longjmp_fn png_set_longjmp_fn 5526#define fn_png_set_longjmp_fn png_set_longjmp_fn
5515#endif /* libpng version >= 1.5 */ 5527#endif /* libpng version >= 1.5 */
5516 5528
5517#endif /* HAVE_NTGUI */ 5529#endif /* WINDOWSNT */
5518 5530
5519 5531
5520#if (PNG_LIBPNG_VER < 10500) 5532#if (PNG_LIBPNG_VER < 10500)
@@ -6045,14 +6057,20 @@ jpeg_image_p (Lisp_Object object)
6045#define __WIN32__ 1 6057#define __WIN32__ 1
6046#endif 6058#endif
6047 6059
6060/* Work around conflict between jpeg boolean and rpcndr.h
6061 under Windows. */
6062#define boolean jpeg_boolean
6048#include <jpeglib.h> 6063#include <jpeglib.h>
6049#include <jerror.h> 6064#include <jerror.h>
6050 6065
6066/* Don't undefine boolean --- use the JPEG boolean
6067 through the rest of the file. */
6068
6051#ifdef HAVE_STLIB_H_1 6069#ifdef HAVE_STLIB_H_1
6052#define HAVE_STDLIB_H 1 6070#define HAVE_STDLIB_H 1
6053#endif 6071#endif
6054 6072
6055#ifdef HAVE_NTGUI 6073#ifdef WINDOWSNT
6056 6074
6057/* JPEG library details. */ 6075/* JPEG library details. */
6058DEF_IMGLIB_FN (void, jpeg_CreateDecompress, (j_decompress_ptr, int, size_t)); 6076DEF_IMGLIB_FN (void, jpeg_CreateDecompress, (j_decompress_ptr, int, size_t));
@@ -6102,7 +6120,7 @@ jpeg_resync_to_restart_wrapper (j_decompress_ptr cinfo, int desired)
6102#define fn_jpeg_std_error jpeg_std_error 6120#define fn_jpeg_std_error jpeg_std_error
6103#define jpeg_resync_to_restart_wrapper jpeg_resync_to_restart 6121#define jpeg_resync_to_restart_wrapper jpeg_resync_to_restart
6104 6122
6105#endif /* HAVE_NTGUI */ 6123#endif /* WINDOWSNT */
6106 6124
6107struct my_jpeg_error_mgr 6125struct my_jpeg_error_mgr
6108{ 6126{
@@ -6583,7 +6601,7 @@ tiff_image_p (Lisp_Object object)
6583 6601
6584#include <tiffio.h> 6602#include <tiffio.h>
6585 6603
6586#ifdef HAVE_NTGUI 6604#ifdef WINDOWSNT
6587 6605
6588/* TIFF library details. */ 6606/* TIFF library details. */
6589DEF_IMGLIB_FN (TIFFErrorHandler, TIFFSetErrorHandler, (TIFFErrorHandler)); 6607DEF_IMGLIB_FN (TIFFErrorHandler, TIFFSetErrorHandler, (TIFFErrorHandler));
@@ -6627,7 +6645,7 @@ init_tiff_functions (Lisp_Object libraries)
6627#define fn_TIFFReadRGBAImage TIFFReadRGBAImage 6645#define fn_TIFFReadRGBAImage TIFFReadRGBAImage
6628#define fn_TIFFClose TIFFClose 6646#define fn_TIFFClose TIFFClose
6629#define fn_TIFFSetDirectory TIFFSetDirectory 6647#define fn_TIFFSetDirectory TIFFSetDirectory
6630#endif /* HAVE_NTGUI */ 6648#endif /* WINDOWSNT */
6631 6649
6632 6650
6633/* Reading from a memory buffer for TIFF images Based on the PNG 6651/* Reading from a memory buffer for TIFF images Based on the PNG
@@ -7056,7 +7074,7 @@ gif_image_p (Lisp_Object object)
7056#endif /* HAVE_NTGUI */ 7074#endif /* HAVE_NTGUI */
7057 7075
7058 7076
7059#ifdef HAVE_NTGUI 7077#ifdef WINDOWSNT
7060 7078
7061/* GIF library details. */ 7079/* GIF library details. */
7062DEF_IMGLIB_FN (int, DGifCloseFile, (GifFileType *)); 7080DEF_IMGLIB_FN (int, DGifCloseFile, (GifFileType *));
@@ -7086,7 +7104,7 @@ init_gif_functions (Lisp_Object libraries)
7086#define fn_DGifOpen DGifOpen 7104#define fn_DGifOpen DGifOpen
7087#define fn_DGifOpenFileName DGifOpenFileName 7105#define fn_DGifOpenFileName DGifOpenFileName
7088 7106
7089#endif /* HAVE_NTGUI */ 7107#endif /* WINDOWSNT */
7090 7108
7091/* Reading a GIF image from memory 7109/* Reading a GIF image from memory
7092 Based on the PNG memory stuff to a certain extent. */ 7110 Based on the PNG memory stuff to a certain extent. */
@@ -8075,7 +8093,7 @@ svg_image_p (Lisp_Object object)
8075 8093
8076#include <librsvg/rsvg.h> 8094#include <librsvg/rsvg.h>
8077 8095
8078#ifdef HAVE_NTGUI 8096#ifdef WINDOWSNT
8079 8097
8080/* SVG library functions. */ 8098/* SVG library functions. */
8081DEF_IMGLIB_FN (RsvgHandle *, rsvg_handle_new); 8099DEF_IMGLIB_FN (RsvgHandle *, rsvg_handle_new);
@@ -8153,7 +8171,7 @@ init_svg_functions (Lisp_Object libraries)
8153#define fn_g_type_init g_type_init 8171#define fn_g_type_init g_type_init
8154#define fn_g_object_unref g_object_unref 8172#define fn_g_object_unref g_object_unref
8155#define fn_g_error_free g_error_free 8173#define fn_g_error_free g_error_free
8156#endif /* !HAVE_NTGUI */ 8174#endif /* !WINDOWSNT */
8157 8175
8158/* Load SVG image IMG for use on frame F. Value is non-zero if 8176/* Load SVG image IMG for use on frame F. Value is non-zero if
8159 successful. this function will go into the svg_type structure, and 8177 successful. this function will go into the svg_type structure, and
@@ -8701,7 +8719,7 @@ DEFUN ("lookup-image", Flookup_image, Slookup_image, 1, 1, 0, "")
8701 Initialization 8719 Initialization
8702 ***********************************************************************/ 8720 ***********************************************************************/
8703 8721
8704#ifdef HAVE_NTGUI 8722#ifdef WINDOWSNT
8705/* Image types that rely on external libraries are loaded dynamically 8723/* Image types that rely on external libraries are loaded dynamically
8706 if the library is available. */ 8724 if the library is available. */
8707#define CHECK_LIB_AVAILABLE(image_type, init_lib_fn, libraries) \ 8725#define CHECK_LIB_AVAILABLE(image_type, init_lib_fn, libraries) \
@@ -8709,7 +8727,7 @@ DEFUN ("lookup-image", Flookup_image, Slookup_image, 1, 1, 0, "")
8709#else 8727#else
8710#define CHECK_LIB_AVAILABLE(image_type, init_lib_fn, libraries) \ 8728#define CHECK_LIB_AVAILABLE(image_type, init_lib_fn, libraries) \
8711 define_image_type (image_type, 1) 8729 define_image_type (image_type, 1)
8712#endif /* HAVE_NTGUI */ 8730#endif /* WINDOWSNT */
8713 8731
8714DEFUN ("init-image-library", Finit_image_library, Sinit_image_library, 2, 2, 0, 8732DEFUN ("init-image-library", Finit_image_library, Sinit_image_library, 2, 2, 0,
8715 doc: /* Initialize image library implementing image type TYPE. 8733 doc: /* Initialize image library implementing image type TYPE.
@@ -8720,7 +8738,7 @@ Libraries to load are specified in alist LIBRARIES (usually, the value
8720of `dynamic-library-alist', which see). */) 8738of `dynamic-library-alist', which see). */)
8721 (Lisp_Object type, Lisp_Object libraries) 8739 (Lisp_Object type, Lisp_Object libraries)
8722{ 8740{
8723#ifdef HAVE_NTGUI 8741#ifdef WINDOWSNT
8724 /* Don't try to reload the library. */ 8742 /* Don't try to reload the library. */
8725 Lisp_Object tested = Fassq (type, Vlibrary_cache); 8743 Lisp_Object tested = Fassq (type, Vlibrary_cache);
8726 if (CONSP (tested)) 8744 if (CONSP (tested))
diff --git a/src/keyboard.c b/src/keyboard.c
index ff2b75e351c..992d1a97b3c 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -314,7 +314,7 @@ static Lisp_Object Qmouse_fixup_help_message;
314/* Symbols to denote kinds of events. */ 314/* Symbols to denote kinds of events. */
315static Lisp_Object Qfunction_key; 315static Lisp_Object Qfunction_key;
316Lisp_Object Qmouse_click; 316Lisp_Object Qmouse_click;
317#if defined (WINDOWSNT) 317#if defined (HAVE_NTGUI)
318Lisp_Object Qlanguage_change; 318Lisp_Object Qlanguage_change;
319#endif 319#endif
320static Lisp_Object Qdrag_n_drop; 320static Lisp_Object Qdrag_n_drop;
@@ -3828,8 +3828,8 @@ kbd_buffer_get_event (KBOARD **kbp,
3828#ifdef subprocesses 3828#ifdef subprocesses
3829 if (kbd_on_hold_p () && kbd_buffer_nr_stored () < KBD_BUFFER_SIZE/4) 3829 if (kbd_on_hold_p () && kbd_buffer_nr_stored () < KBD_BUFFER_SIZE/4)
3830 { 3830 {
3831 /* Start reading input again, we have processed enough so we can 3831 /* Start reading input again because we have processed enough to
3832 accept new events again. */ 3832 be able to accept new events again. */
3833 unhold_keyboard_input (); 3833 unhold_keyboard_input ();
3834#ifdef SIGIO 3834#ifdef SIGIO
3835 if (!noninteractive) 3835 if (!noninteractive)
@@ -4015,7 +4015,7 @@ kbd_buffer_get_event (KBOARD **kbp,
4015 x_activate_menubar (XFRAME (event->frame_or_window)); 4015 x_activate_menubar (XFRAME (event->frame_or_window));
4016 } 4016 }
4017#endif 4017#endif
4018#if defined (WINDOWSNT) 4018#if defined (HAVE_NTGUI)
4019 else if (event->kind == LANGUAGE_CHANGE_EVENT) 4019 else if (event->kind == LANGUAGE_CHANGE_EVENT)
4020 { 4020 {
4021 /* Make an event (language-change (FRAME CODEPAGE LANGUAGE-ID)). */ 4021 /* Make an event (language-change (FRAME CODEPAGE LANGUAGE-ID)). */
@@ -5470,7 +5470,7 @@ make_lispy_event (struct input_event *event)
5470 (sizeof (lispy_function_keys) 5470 (sizeof (lispy_function_keys)
5471 / sizeof (lispy_function_keys[0]))); 5471 / sizeof (lispy_function_keys[0])));
5472 5472
5473#ifdef WINDOWSNT 5473#ifdef HAVE_NTGUI
5474 case MULTIMEDIA_KEY_EVENT: 5474 case MULTIMEDIA_KEY_EVENT:
5475 if (event->code < (sizeof (lispy_multimedia_keys) 5475 if (event->code < (sizeof (lispy_multimedia_keys)
5476 / sizeof (lispy_multimedia_keys[0])) 5476 / sizeof (lispy_multimedia_keys[0]))
@@ -11499,7 +11499,7 @@ syms_of_keyboard (void)
11499 DEFSYM (Qconfig_changed_event, "config-changed-event"); 11499 DEFSYM (Qconfig_changed_event, "config-changed-event");
11500 DEFSYM (Qmenu_enable, "menu-enable"); 11500 DEFSYM (Qmenu_enable, "menu-enable");
11501 11501
11502#if defined (WINDOWSNT) 11502#if defined (HAVE_NTGUI)
11503 DEFSYM (Qlanguage_change, "language-change"); 11503 DEFSYM (Qlanguage_change, "language-change");
11504#endif 11504#endif
11505 11505
diff --git a/src/keyboard.h b/src/keyboard.h
index 98b1933f3f9..69fa533fd03 100644
--- a/src/keyboard.h
+++ b/src/keyboard.h
@@ -552,7 +552,7 @@ extern int tty_read_avail_input (struct terminal *, int,
552extern EMACS_TIME timer_check (void); 552extern EMACS_TIME timer_check (void);
553extern void mark_kboards (void); 553extern void mark_kboards (void);
554 554
555#ifdef WINDOWSNT 555#ifdef HAVE_NTGUI
556extern const char *const lispy_function_keys[]; 556extern const char *const lispy_function_keys[];
557#endif 557#endif
558 558
diff --git a/src/menu.c b/src/menu.c
index 20770537326..336e1a9e31d 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -41,7 +41,11 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
41#endif /* HAVE_WINDOW_SYSTEM */ 41#endif /* HAVE_WINDOW_SYSTEM */
42 42
43#ifdef HAVE_NTGUI 43#ifdef HAVE_NTGUI
44# ifdef NTGUI_UNICODE
45# define unicode_append_menu AppendMenuW
46# else /* !NTGUI_UNICODE */
44extern AppendMenuW_Proc unicode_append_menu; 47extern AppendMenuW_Proc unicode_append_menu;
48# endif /* NTGUI_UNICODE */
45extern HMENU current_popup_menu; 49extern HMENU current_popup_menu;
46#endif /* HAVE_NTGUI */ 50#endif /* HAVE_NTGUI */
47 51
diff --git a/src/process.c b/src/process.c
index bfac054c3c2..b45ba733636 100644
--- a/src/process.c
+++ b/src/process.c
@@ -4675,6 +4675,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4675 process_output_skip = 0; 4675 process_output_skip = 0;
4676 } 4676 }
4677#endif 4677#endif
4678
4678#if defined (USE_GTK) || defined (HAVE_GCONF) || defined (HAVE_GSETTINGS) 4679#if defined (USE_GTK) || defined (HAVE_GCONF) || defined (HAVE_GSETTINGS)
4679 nfds = xg_select 4680 nfds = xg_select
4680#elif defined (HAVE_NS) 4681#elif defined (HAVE_NS)
diff --git a/src/termhooks.h b/src/termhooks.h
index 46962a1217d..0864b80da84 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 52b2ec4bf2b..8061227d3a8 100644
--- a/src/unexw32.c
+++ b/src/unexw32.c
@@ -83,7 +83,7 @@ DWORD 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 84a46e522bb..d779d740724 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -31,7 +31,6 @@ 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 <setjmp.h> 35#include <setjmp.h>
37#include <time.h> 36#include <time.h>
@@ -39,6 +38,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
39/* must include CRT headers *before* config.h */ 38/* must include CRT headers *before* config.h */
40 39
41#include <config.h> 40#include <config.h>
41#include <mbstring.h> /* for _mbspbrk */
42 42
43#undef access 43#undef access
44#undef chdir 44#undef chdir
@@ -867,23 +867,6 @@ create_symbolic_link (LPTSTR lpSymlinkFilename,
867 return retval; 867 return retval;
868} 868}
869 869
870/* Equivalent of strerror for W32 error codes. */
871char *
872w32_strerror (int error_no)
873{
874 static char buf[500];
875
876 if (error_no == 0)
877 error_no = GetLastError ();
878
879 buf[0] = '\0';
880 if (!FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL,
881 error_no,
882 0, /* choose most suitable language */
883 buf, sizeof (buf), NULL))
884 sprintf (buf, "w32 error %u", error_no);
885 return buf;
886}
887 870
888/* Return 1 if P is a valid pointer to an object of size SIZE. Return 871/* Return 1 if P is a valid pointer to an object of size SIZE. Return
889 0 if P is NOT a valid pointer. Return -1 if we cannot validate P. 872 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 73d57a65a4a..b83b716b617 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 (void); 136extern void init_ntproc (void);
131extern void term_ntproc (void); 137extern void term_ntproc (void);
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 int _sys_read_ahead (int fd); 140extern int _sys_read_ahead (int fd);
146extern int _sys_wait_accept (int fd); 141extern int _sys_wait_accept (int fd);
diff --git a/src/w32console.c b/src/w32console.c
index 76585851e7f..76b7bb0b451 100644
--- a/src/w32console.c
+++ b/src/w32console.c
@@ -37,6 +37,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
37#include "termhooks.h" 37#include "termhooks.h"
38#include "termchar.h" 38#include "termchar.h"
39#include "dispextern.h" 39#include "dispextern.h"
40#include "w32term.h"
40#include "w32heap.h" /* for os_subtype */ 41#include "w32heap.h" /* for os_subtype */
41#include "w32inevt.h" 42#include "w32inevt.h"
42 43
@@ -431,53 +432,6 @@ w32con_delete_glyphs (struct frame *f, int n)
431 scroll_line (f, n, LEFT); 432 scroll_line (f, n, LEFT);
432} 433}
433 434
434static unsigned int sound_type = 0xFFFFFFFF;
435#define MB_EMACS_SILENT (0xFFFFFFFF - 1)
436
437void
438w32_sys_ring_bell (struct frame *f)
439{
440 if (sound_type == 0xFFFFFFFF)
441 {
442 Beep (666, 100);
443 }
444 else if (sound_type == MB_EMACS_SILENT)
445 {
446 /* Do nothing. */
447 }
448 else
449 MessageBeep (sound_type);
450}
451
452DEFUN ("set-message-beep", Fset_message_beep, Sset_message_beep, 1, 1, 0,
453 doc: /* Set the sound generated when the bell is rung.
454SOUND is 'asterisk, 'exclamation, 'hand, 'question, 'ok, or 'silent
455to use the corresponding system sound for the bell. The 'silent sound
456prevents Emacs from making any sound at all.
457SOUND is nil to use the normal beep. */)
458 (Lisp_Object sound)
459{
460 CHECK_SYMBOL (sound);
461
462 if (NILP (sound))
463 sound_type = 0xFFFFFFFF;
464 else if (EQ (sound, intern ("asterisk")))
465 sound_type = MB_ICONASTERISK;
466 else if (EQ (sound, intern ("exclamation")))
467 sound_type = MB_ICONEXCLAMATION;
468 else if (EQ (sound, intern ("hand")))
469 sound_type = MB_ICONHAND;
470 else if (EQ (sound, intern ("question")))
471 sound_type = MB_ICONQUESTION;
472 else if (EQ (sound, intern ("ok")))
473 sound_type = MB_OK;
474 else if (EQ (sound, intern ("silent")))
475 sound_type = MB_EMACS_SILENT;
476 else
477 sound_type = 0xFFFFFFFF;
478
479 return sound;
480}
481 435
482static void 436static void
483w32con_reset_terminal_modes (struct terminal *t) 437w32con_reset_terminal_modes (struct terminal *t)
@@ -851,5 +805,4 @@ scroll-back buffer. */);
851 defsubr (&Sset_screen_color); 805 defsubr (&Sset_screen_color);
852 defsubr (&Sget_screen_color); 806 defsubr (&Sget_screen_color);
853 defsubr (&Sset_cursor_size); 807 defsubr (&Sset_cursor_size);
854 defsubr (&Sset_message_beep);
855} 808}
diff --git a/src/w32fns.c b/src/w32fns.c
index 5a1b6dfabab..16a2fb4dfdd 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -45,8 +45,14 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
45#include "fontset.h" 45#include "fontset.h"
46#include "systime.h" 46#include "systime.h"
47#include "termhooks.h" 47#include "termhooks.h"
48
48#include "w32heap.h" 49#include "w32heap.h"
50
51#if CYGWIN
52#include "cygw32.h"
53#else
49#include "w32.h" 54#include "w32.h"
55#endif
50 56
51#include "bitmaps/gray.xbm" 57#include "bitmaps/gray.xbm"
52 58
@@ -59,9 +65,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
59 65
60#include <dlgs.h> 66#include <dlgs.h>
61#include <imm.h> 67#include <imm.h>
62#define FILE_NAME_TEXT_FIELD edt1
63#define FILE_NAME_COMBO_BOX cmb13
64#define FILE_NAME_LIST lst1
65 68
66#include "font.h" 69#include "font.h"
67#include "w32font.h" 70#include "w32font.h"
@@ -79,6 +82,7 @@ extern int w32_console_toggle_lock_key (int, Lisp_Object);
79extern void w32_menu_display_help (HWND, HMENU, UINT, UINT); 82extern void w32_menu_display_help (HWND, HMENU, UINT, UINT);
80extern void w32_free_menu_strings (HWND); 83extern void w32_free_menu_strings (HWND);
81extern const char *map_w32_filename (const char *, const char **); 84extern const char *map_w32_filename (const char *, const char **);
85extern char * w32_strerror (int error_no);
82 86
83/* If non-zero, a w32 timer that, when it expires, displays an 87/* If non-zero, a w32 timer that, when it expires, displays an
84 hourglass cursor on all frames. */ 88 hourglass cursor on all frames. */
@@ -164,7 +168,11 @@ ImmSetCompositionWindow_Proc set_ime_composition_window_fn = NULL;
164MonitorFromPoint_Proc monitor_from_point_fn = NULL; 168MonitorFromPoint_Proc monitor_from_point_fn = NULL;
165GetMonitorInfo_Proc get_monitor_info_fn = NULL; 169GetMonitorInfo_Proc get_monitor_info_fn = NULL;
166 170
171#ifdef NTGUI_UNICODE
172#define unicode_append_menu AppendMenuW
173#else /* !NTGUI_UNICODE */
167extern AppendMenuW_Proc unicode_append_menu; 174extern AppendMenuW_Proc unicode_append_menu;
175#endif /* NTGUI_UNICODE */
168 176
169/* Flag to selectively ignore WM_IME_CHAR messages. */ 177/* Flag to selectively ignore WM_IME_CHAR messages. */
170static int ignore_ime_char = 0; 178static int ignore_ime_char = 0;
@@ -202,6 +210,33 @@ extern int uniscribe_available;
202static void w32_show_hourglass (struct frame *); 210static void w32_show_hourglass (struct frame *);
203static void w32_hide_hourglass (void); 211static void w32_hide_hourglass (void);
204 212
213#ifdef WINDOWSNT
214/* From w32inevet.c */
215extern int faked_key;
216#endif /* WINDOWSNT */
217
218/* This gives us the page size and the size of the allocation unit on NT. */
219SYSTEM_INFO sysinfo_cache;
220
221/* This gives us version, build, and platform identification. */
222OSVERSIONINFO osinfo_cache;
223
224unsigned long syspage_mask = 0;
225
226/* The major and minor versions of NT. */
227int w32_major_version;
228int w32_minor_version;
229int w32_build_number;
230
231/* Distinguish between Windows NT and Windows 95. */
232int os_subtype;
233
234#ifdef HAVE_NTGUI
235HINSTANCE hinst = NULL;
236#endif
237
238static unsigned int sound_type = 0xFFFFFFFF;
239#define MB_EMACS_SILENT (0xFFFFFFFF - 1)
205 240
206 241
207/* Error if we are not connected to MS-Windows. */ 242/* Error if we are not connected to MS-Windows. */
@@ -1847,10 +1882,7 @@ w32_createwindow (struct frame *f)
1847 1882
1848 /* Do first time app init */ 1883 /* Do first time app init */
1849 1884
1850 if (!hprevinst) 1885 w32_init_class (hinst);
1851 {
1852 w32_init_class (hinst);
1853 }
1854 1886
1855 if (f->size_hint_flags & USPosition || f->size_hint_flags & PPosition) 1887 if (f->size_hint_flags & USPosition || f->size_hint_flags & PPosition)
1856 { 1888 {
@@ -2250,6 +2282,58 @@ unregister_hot_keys (HWND hwnd)
2250 } 2282 }
2251} 2283}
2252 2284
2285#if EMACSDEBUG
2286const char*
2287w32_name_of_message (UINT msg)
2288{
2289 unsigned i;
2290 static char buf[64];
2291 static const struct {
2292 UINT msg;
2293 const char* name;
2294 } msgnames[] = {
2295#define M(msg) { msg, # msg }
2296 M (WM_PAINT),
2297 M (WM_TIMER),
2298 M (WM_USER),
2299 M (WM_MOUSEMOVE),
2300 M (WM_LBUTTONUP),
2301 M (WM_KEYDOWN),
2302 M (WM_EMACS_KILL),
2303 M (WM_EMACS_CREATEWINDOW),
2304 M (WM_EMACS_DONE),
2305 M (WM_EMACS_CREATESCROLLBAR),
2306 M (WM_EMACS_SHOWWINDOW),
2307 M (WM_EMACS_SETWINDOWPOS),
2308 M (WM_EMACS_DESTROYWINDOW),
2309 M (WM_EMACS_TRACKPOPUPMENU),
2310 M (WM_EMACS_SETFOCUS),
2311 M (WM_EMACS_SETFOREGROUND),
2312 M (WM_EMACS_SETLOCALE),
2313 M (WM_EMACS_SETKEYBOARDLAYOUT),
2314 M (WM_EMACS_REGISTER_HOT_KEY),
2315 M (WM_EMACS_UNREGISTER_HOT_KEY),
2316 M (WM_EMACS_TOGGLE_LOCK_KEY),
2317 M (WM_EMACS_TRACK_CARET),
2318 M (WM_EMACS_DESTROY_CARET),
2319 M (WM_EMACS_SHOW_CARET),
2320 M (WM_EMACS_HIDE_CARET),
2321 M (WM_EMACS_SETCURSOR),
2322 M (WM_EMACS_PAINT),
2323 M (WM_CHAR),
2324#undef M
2325 { 0, 0 }
2326 };
2327
2328 for (i = 0; msgnames[i].name; ++i)
2329 if (msgnames[i].msg == msg)
2330 return msgnames[i].name;
2331
2332 sprintf (buf, "message 0x%04x", (unsigned)msg);
2333 return buf;
2334}
2335#endif /* EMACSDEBUG */
2336
2253/* Main message dispatch loop. */ 2337/* Main message dispatch loop. */
2254 2338
2255static void 2339static void
@@ -2263,6 +2347,10 @@ w32_msg_pump (deferred_msg * msg_buf)
2263 2347
2264 while ((w32_unicode_gui ? GetMessageW : GetMessageA) (&msg, NULL, 0, 0)) 2348 while ((w32_unicode_gui ? GetMessageW : GetMessageA) (&msg, NULL, 0, 0))
2265 { 2349 {
2350
2351 /* DebPrint (("w32_msg_pump: %s time:%u\n", */
2352 /* w32_name_of_message (msg.message), msg.time)); */
2353
2266 if (msg.hwnd == NULL) 2354 if (msg.hwnd == NULL)
2267 { 2355 {
2268 switch (msg.message) 2356 switch (msg.message)
@@ -2350,7 +2438,7 @@ w32_msg_pump (deferred_msg * msg_buf)
2350 /* Broadcast messages make it here, so you need to be looking 2438 /* Broadcast messages make it here, so you need to be looking
2351 for something in particular for this to be useful. */ 2439 for something in particular for this to be useful. */
2352 default: 2440 default:
2353 DebPrint (("msg %x not expected by w32_msg_pump\n", msg.message)); 2441 DebPrint (("msg %x not expected by w32_msg_pump\n", msg.message));
2354#endif 2442#endif
2355 } 2443 }
2356 } 2444 }
@@ -4692,6 +4780,37 @@ If omitted or nil, that stands for the selected frame's display. */)
4692{ 4780{
4693 return Qnil; 4781 return Qnil;
4694} 4782}
4783
4784DEFUN ("set-message-beep", Fset_message_beep, Sset_message_beep, 1, 1, 0,
4785 doc: /* Set the sound generated when the bell is rung.
4786SOUND is 'asterisk, 'exclamation, 'hand, 'question, 'ok, or 'silent
4787to use the corresponding system sound for the bell. The 'silent sound
4788prevents Emacs from making any sound at all.
4789SOUND is nil to use the normal beep. */)
4790 (Lisp_Object sound)
4791{
4792 CHECK_SYMBOL (sound);
4793
4794 if (NILP (sound))
4795 sound_type = 0xFFFFFFFF;
4796 else if (EQ (sound, intern ("asterisk")))
4797 sound_type = MB_ICONASTERISK;
4798 else if (EQ (sound, intern ("exclamation")))
4799 sound_type = MB_ICONEXCLAMATION;
4800 else if (EQ (sound, intern ("hand")))
4801 sound_type = MB_ICONHAND;
4802 else if (EQ (sound, intern ("question")))
4803 sound_type = MB_ICONQUESTION;
4804 else if (EQ (sound, intern ("ok")))
4805 sound_type = MB_OK;
4806 else if (EQ (sound, intern ("silent")))
4807 sound_type = MB_EMACS_SILENT;
4808 else
4809 sound_type = 0xFFFFFFFF;
4810
4811 return sound;
4812}
4813
4695 4814
4696int 4815int
4697x_pixel_width (register struct frame *f) 4816x_pixel_width (register struct frame *f)
@@ -5865,6 +5984,18 @@ Value is t if tooltip was open, nil otherwise. */)
5865 File selection dialog 5984 File selection dialog
5866 ***********************************************************************/ 5985 ***********************************************************************/
5867 5986
5987#define FILE_NAME_TEXT_FIELD edt1
5988#define FILE_NAME_COMBO_BOX cmb13
5989#define FILE_NAME_LIST lst1
5990
5991#ifdef NTGUI_UNICODE
5992#define GUISTR(x) (L ## x)
5993typedef wchar_t guichar_t;
5994#else /* !NTGUI_UNICODE */
5995#define GUISTR(x) x
5996typedef char guichar_t;
5997#endif /* NTGUI_UNICODE */
5998
5868/* Callback for altering the behavior of the Open File dialog. 5999/* Callback for altering the behavior of the Open File dialog.
5869 Makes the Filename text field contain "Current Directory" and be 6000 Makes the Filename text field contain "Current Directory" and be
5870 read-only when "Directories" is selected in the filter. This 6001 read-only when "Directories" is selected in the filter. This
@@ -5875,7 +6006,11 @@ file_dialog_callback (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5875{ 6006{
5876 if (msg == WM_NOTIFY) 6007 if (msg == WM_NOTIFY)
5877 { 6008 {
5878 OFNOTIFY * notify = (OFNOTIFY *)lParam; 6009#ifdef NTGUI_UNICODE
6010 OFNOTIFYW * notify = (OFNOTIFYW *)lParam;
6011#else /* !NTGUI_UNICODE */
6012 OFNOTIFYA * notify = (OFNOTIFYA *)lParam;
6013#endif /* NTGUI_UNICODE */
5879 /* Detect when the Filter dropdown is changed. */ 6014 /* Detect when the Filter dropdown is changed. */
5880 if (notify->hdr.code == CDN_TYPECHANGE 6015 if (notify->hdr.code == CDN_TYPECHANGE
5881 || notify->hdr.code == CDN_INITDONE) 6016 || notify->hdr.code == CDN_INITDONE)
@@ -5903,7 +6038,7 @@ file_dialog_callback (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5903 if (notify->lpOFN->nFilterIndex == 2) 6038 if (notify->lpOFN->nFilterIndex == 2)
5904 { 6039 {
5905 CommDlg_OpenSave_SetControlText (dialog, FILE_NAME_TEXT_FIELD, 6040 CommDlg_OpenSave_SetControlText (dialog, FILE_NAME_TEXT_FIELD,
5906 "Current Directory"); 6041 GUISTR ("Current Directory"));
5907 EnableWindow (edit_control, FALSE); 6042 EnableWindow (edit_control, FALSE);
5908 /* Note that at least on Windows 7, the above call to EnableWindow 6043 /* Note that at least on Windows 7, the above call to EnableWindow
5909 disables the window that would ordinarily have focus. If we 6044 disables the window that would ordinarily have focus. If we
@@ -5919,7 +6054,8 @@ file_dialog_callback (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5919 /* Don't override default filename on init done. */ 6054 /* Don't override default filename on init done. */
5920 if (notify->hdr.code == CDN_TYPECHANGE) 6055 if (notify->hdr.code == CDN_TYPECHANGE)
5921 CommDlg_OpenSave_SetControlText (dialog, 6056 CommDlg_OpenSave_SetControlText (dialog,
5922 FILE_NAME_TEXT_FIELD, ""); 6057 FILE_NAME_TEXT_FIELD,
6058 GUISTR (""));
5923 EnableWindow (edit_control, TRUE); 6059 EnableWindow (edit_control, TRUE);
5924 } 6060 }
5925 } 6061 }
@@ -5927,19 +6063,6 @@ file_dialog_callback (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5927 return 0; 6063 return 0;
5928} 6064}
5929 6065
5930/* Since we compile with _WIN32_WINNT set to 0x0400 (for NT4 compatibility)
5931 we end up with the old file dialogs. Define a big enough struct for the
5932 new dialog to trick GetOpenFileName into giving us the new dialogs on
5933 Windows 2000 and XP. */
5934typedef struct
5935{
5936 OPENFILENAME real_details;
5937 void * pReserved;
5938 DWORD dwReserved;
5939 DWORD FlagsEx;
5940} NEWOPENFILENAME;
5941
5942
5943DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 5, 0, 6066DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 5, 0,
5944 doc: /* Read file name, prompting with PROMPT in directory DIR. 6067 doc: /* Read file name, prompting with PROMPT in directory DIR.
5945Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file 6068Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
@@ -5951,134 +6074,203 @@ Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
5951Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */) 6074Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
5952 (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object only_dir_p) 6075 (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object only_dir_p)
5953{ 6076{
6077 /* Filter index: 1: All Files, 2: Directories only */
6078 static const guichar_t filter[] =
6079 GUISTR ("All Files (*.*)\0*.*\0Directories\0*|*\0");
6080
6081 Lisp_Object filename = default_filename;
5954 struct frame *f = SELECTED_FRAME (); 6082 struct frame *f = SELECTED_FRAME ();
5955 Lisp_Object file = Qnil; 6083 BOOL file_opened = FALSE;
5956 ptrdiff_t count = SPECPDL_INDEX (); 6084 Lisp_Object orig_dir = dir;
6085 Lisp_Object orig_prompt = prompt;
6086
6087 /* If we compile with _WIN32_WINNT set to 0x0400 (for NT4
6088 compatibility) we end up with the old file dialogs. Define a big
6089 enough struct for the new dialog to trick GetOpenFileName into
6090 giving us the new dialogs on newer versions of Windows. */
6091 struct {
6092#ifdef NTGUI_UNICODE
6093 OPENFILENAMEW details;
6094#else /* !NTGUI_UNICODE */
6095 OPENFILENAMEA details;
6096#endif /* NTGUI_UNICODE */
6097
6098#if _WIN32_WINNT < 0x500 /* < win2k */
6099 PVOID pvReserved;
6100 DWORD dwReserved;
6101 DWORD FlagsEx;
6102#endif /* < win2k */
6103 } new_file_details;
6104
6105#ifdef NTGUI_UNICODE
6106 wchar_t filename_buf[MAX_PATH + 1];
6107 OPENFILENAMEW * file_details = &new_file_details.details;
6108#else /* not NTGUI_UNICODE */
6109 char filename_buf[MAX_PATH + 1];
6110 OPENFILENAMEA * file_details = &new_file_details.details;
6111#endif /* NTGUI_UNICODE */
6112
5957 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6; 6113 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
5958 char filename[MAX_PATH + 1]; 6114 GCPRO6 (prompt, dir, default_filename, mustmatch, only_dir_p, filename);
5959 char init_dir[MAX_PATH + 1];
5960 int default_filter_index = 1; /* 1: All Files, 2: Directories only */
5961
5962 GCPRO6 (prompt, dir, default_filename, mustmatch, only_dir_p, file);
5963 CHECK_STRING (prompt);
5964 CHECK_STRING (dir);
5965
5966 /* Create the dialog with PROMPT as title, using DIR as initial
5967 directory and using "*" as pattern. */
5968 dir = Fexpand_file_name (dir, Qnil);
5969 strncpy (init_dir, SDATA (ENCODE_FILE (dir)), MAX_PATH);
5970 init_dir[MAX_PATH] = '\0';
5971 unixtodos_filename (init_dir);
5972
5973 if (STRINGP (default_filename))
5974 {
5975 char *file_name_only;
5976 char *full_path_name = SDATA (ENCODE_FILE (default_filename));
5977 6115
5978 unixtodos_filename (full_path_name); 6116 {
6117 struct gcpro gcpro1, gcpro2;
6118 GCPRO2 (orig_dir, orig_prompt); /* There is no GCPRON, N>6. */
5979 6119
5980 file_name_only = strrchr (full_path_name, '\\'); 6120 /* Note: under NTGUI_UNICODE, we do _NOT_ use ENCODE_FILE: the
5981 if (!file_name_only) 6121 system file encoding expected by the platform APIs (e.g. Cygwin's
5982 file_name_only = full_path_name; 6122 POSIX implementation) may not the same as the encoding expected
5983 else 6123 by the Windows API! */
5984 file_name_only++;
5985 6124
5986 strncpy (filename, file_name_only, MAX_PATH); 6125 CHECK_STRING (prompt);
5987 filename[MAX_PATH] = '\0'; 6126 CHECK_STRING (dir);
5988 }
5989 else
5990 filename[0] = '\0';
5991 6127
5992 /* The code in file_dialog_callback that attempts to set the text 6128 dir = Fexpand_file_name (dir, Qnil);
5993 of the file name edit window when handling the CDN_INITDONE
5994 WM_NOTIFY message does not work. Setting filename to "Current
5995 Directory" in the only_dir_p case here does work however. */
5996 if (filename[0] == 0 && ! NILP (only_dir_p))
5997 strcpy (filename, "Current Directory");
5998 6129
5999 { 6130 if (STRINGP (filename))
6000 NEWOPENFILENAME new_file_details; 6131 filename = Ffile_name_nondirectory (filename);
6001 BOOL file_opened = FALSE; 6132 else
6002 OPENFILENAME * file_details = &new_file_details.real_details; 6133 filename = empty_unibyte_string;
6003 6134
6004 /* Prevent redisplay. */ 6135#ifdef CYGWIN
6005 specbind (Qinhibit_redisplay, Qt); 6136 dir = Fcygwin_convert_path_to_windows (dir, Qt);
6006 BLOCK_INPUT; 6137 if (SCHARS (filename) > 0)
6138 filename = Fcygwin_convert_path_to_windows (filename, Qnil);
6139#endif
6007 6140
6141 CHECK_STRING (dir);
6142 CHECK_STRING (filename);
6143
6144 /* The code in file_dialog_callback that attempts to set the text
6145 of the file name edit window when handling the CDN_INITDONE
6146 WM_NOTIFY message does not work. Setting filename to "Current
6147 Directory" in the only_dir_p case here does work however. */
6148 if (SCHARS (filename) == 0 && ! NILP (only_dir_p))
6149 filename = build_string ("Current Directory");
6150
6151 /* Convert the values we've computed so far to system form. */
6152#ifdef NTGUI_UNICODE
6153 to_unicode (prompt, &prompt);
6154 to_unicode (dir, &dir);
6155 to_unicode (filename, &filename);
6156#else /* !NTGUI_UNICODE */
6157 prompt = ENCODE_FILE (prompt);
6158 dir = ENCODE_FILE (dir);
6159 filename = ENCODE_FILE (filename);
6160
6161 /* We modify these in-place, so make copies for safety. */
6162 dir = Fcopy_sequence (dir);
6163 unixtodos_filename (SDATA (dir));
6164 filename = Fcopy_sequence (filename);
6165 unixtodos_filename (SDATA (filename));
6166#endif /* NTGUI_UNICODE */
6167
6168 /* Fill in the structure for the call to GetOpenFileName below. For
6169 NTGUI_UNICODE builds (which run only on NT), we just use the
6170 actual size of the structure. For non-NTGUI_UNICODE builds, we
6171 tell the OS we're using an old version of the structure if it's not
6172 new enough to support the newer version. */
6008 memset (&new_file_details, 0, sizeof (new_file_details)); 6173 memset (&new_file_details, 0, sizeof (new_file_details));
6009 /* Apparently NT4 crashes if you give it an unexpected size. 6174
6010 I'm not sure about Windows 9x, so play it safe. */
6011 if (w32_major_version > 4 && w32_major_version < 95) 6175 if (w32_major_version > 4 && w32_major_version < 95)
6012 file_details->lStructSize = sizeof (NEWOPENFILENAME); 6176 file_details->lStructSize = sizeof (new_file_details);
6013 else 6177 else
6014 file_details->lStructSize = sizeof (OPENFILENAME); 6178 file_details->lStructSize = sizeof (*file_details);
6179
6180 /* Set up the inout parameter for the selected file name. */
6181 if (SBYTES (filename) + 1 > sizeof (filename_buf))
6182 error ("filename too long");
6183
6184 memcpy (filename_buf, SDATA (filename), SBYTES (filename) + 1);
6185 file_details->lpstrFile = filename_buf;
6186 file_details->nMaxFile = sizeof (filename_buf) / sizeof (*filename_buf);
6015 6187
6016 file_details->hwndOwner = FRAME_W32_WINDOW (f); 6188 file_details->hwndOwner = FRAME_W32_WINDOW (f);
6017 /* Undocumented Bug in Common File Dialog: 6189 /* Undocumented Bug in Common File Dialog:
6018 If a filter is not specified, shell links are not resolved. */ 6190 If a filter is not specified, shell links are not resolved. */
6019 file_details->lpstrFilter = "All Files (*.*)\0*.*\0Directories\0*|*\0\0"; 6191 file_details->lpstrFilter = filter;
6020 file_details->lpstrFile = filename; 6192 file_details->lpstrInitialDir = (guichar_t*) SDATA (dir);
6021 file_details->nMaxFile = sizeof (filename); 6193 file_details->lpstrTitle = (guichar_t*) SDATA (prompt);
6022 file_details->lpstrInitialDir = init_dir; 6194 file_details->nFilterIndex = NILP (only_dir_p) ? 1 : 2;
6023 file_details->lpstrTitle = SDATA (prompt);
6024
6025 if (! NILP (only_dir_p))
6026 default_filter_index = 2;
6027
6028 file_details->nFilterIndex = default_filter_index;
6029
6030 file_details->Flags = (OFN_HIDEREADONLY | OFN_NOCHANGEDIR 6195 file_details->Flags = (OFN_HIDEREADONLY | OFN_NOCHANGEDIR
6031 | OFN_EXPLORER | OFN_ENABLEHOOK); 6196 | OFN_EXPLORER | OFN_ENABLEHOOK);
6197
6032 if (!NILP (mustmatch)) 6198 if (!NILP (mustmatch))
6033 { 6199 {
6034 /* Require that the path to the parent directory exists. */ 6200 /* Require that the path to the parent directory exists. */
6035 file_details->Flags |= OFN_PATHMUSTEXIST; 6201 file_details->Flags |= OFN_PATHMUSTEXIST;
6036 /* If we are looking for a file, require that it exists. */ 6202 /* If we are looking for a file, require that it exists. */
6037 if (NILP (only_dir_p)) 6203 if (NILP (only_dir_p))
6038 file_details->Flags |= OFN_FILEMUSTEXIST; 6204 file_details->Flags |= OFN_FILEMUSTEXIST;
6039 } 6205 }
6040 6206
6041 file_details->lpfnHook = (LPOFNHOOKPROC) file_dialog_callback; 6207 {
6042 6208 int count = SPECPDL_INDEX ();
6043 file_opened = GetOpenFileName (file_details); 6209 specbind (Qinhibit_redisplay, Qt);
6210 BLOCK_INPUT;
6211 file_details->lpfnHook = file_dialog_callback;
6044 6212
6045 UNBLOCK_INPUT; 6213#ifdef NTGUI_UNICODE
6214 file_opened = GetOpenFileNameW (file_details);
6215#else /* !NTGUI_UNICODE */
6216 file_opened = GetOpenFileNameA (file_details);
6217#endif /* NTGUI_UNICODE */
6218 UNBLOCK_INPUT;
6219 unbind_to (count, Qnil);
6220 }
6046 6221
6047 if (file_opened) 6222 if (file_opened)
6048 { 6223 {
6049 dostounix_filename (filename); 6224 /* Get an Emacs string from the value Windows gave us. */
6050 6225#ifdef NTGUI_UNICODE
6051 if (file_details->nFilterIndex == 2) 6226 filename = from_unicode (
6052 { 6227 make_unibyte_string (
6053 /* "Directories" selected - strip dummy file name. */ 6228 (char*) filename_buf,
6054 char * last = strrchr (filename, '/'); 6229 /* we get one of the two final 0 bytes for free. */
6055 *last = '\0'; 6230 1 + sizeof (wchar_t) * wcslen (filename_buf)));
6056 } 6231#else /* !NTGUI_UNICODE */
6057 6232 dostounix_filename (filename_buf);
6058 file = DECODE_FILE (build_string (filename)); 6233 filename = DECODE_FILE (build_string (filename_buf));
6234#endif /* NTGUI_UNICODE */
6235
6236#ifdef CYGWIN
6237 filename = Fcygwin_convert_path_from_windows (filename, Qt);
6238#endif /* CYGWIN */
6239
6240 /* Strip the dummy filename off the end of the string if we
6241 added it to select a directory. */
6242 if (file_details->nFilterIndex == 2)
6243 {
6244 filename = Ffile_name_directory (filename);
6245 }
6059 } 6246 }
6060 /* User canceled the dialog without making a selection. */ 6247 /* User canceled the dialog without making a selection. */
6061 else if (!CommDlgExtendedError ()) 6248 else if (!CommDlgExtendedError ())
6062 file = Qnil; 6249 filename = Qnil;
6063 /* An error occurred, fallback on reading from the mini-buffer. */ 6250 /* An error occurred, fallback on reading from the mini-buffer. */
6064 else 6251 else
6065 file = Fcompleting_read (prompt, intern ("read-file-name-internal"), 6252 filename = Fcompleting_read (
6066 dir, mustmatch, dir, Qfile_name_history, 6253 orig_prompt,
6067 default_filename, Qnil); 6254 intern ("read-file-name-internal"),
6255 orig_dir,
6256 mustmatch,
6257 orig_dir,
6258 Qfile_name_history,
6259 default_filename,
6260 Qnil);
6068 6261
6069 file = unbind_to (count, file); 6262 UNGCPRO;
6070 } 6263 }
6071 6264
6072 UNGCPRO;
6073
6074 /* Make "Cancel" equivalent to C-g. */ 6265 /* Make "Cancel" equivalent to C-g. */
6075 if (NILP (file)) 6266 if (NILP (filename))
6076 Fsignal (Qquit, Qnil); 6267 Fsignal (Qquit, Qnil);
6077 6268
6078 return unbind_to (count, file); 6269 RETURN_UNGCPRO (filename);
6079} 6270}
6080 6271
6081 6272
6273#ifdef WINDOWSNT
6082/* Moving files to the system recycle bin. 6274/* Moving files to the system recycle bin.
6083 Used by `move-file-to-trash' instead of the default moving to ~/.Trash */ 6275 Used by `move-file-to-trash' instead of the default moving to ~/.Trash */
6084DEFUN ("system-move-file-to-trash", Fsystem_move_file_to_trash, 6276DEFUN ("system-move-file-to-trash", Fsystem_move_file_to_trash,
@@ -6132,6 +6324,8 @@ DEFUN ("system-move-file-to-trash", Fsystem_move_file_to_trash,
6132 return Qnil; 6324 return Qnil;
6133} 6325}
6134 6326
6327#endif /* WINDOWSNT */
6328
6135 6329
6136/*********************************************************************** 6330/***********************************************************************
6137 w32 specialized functions 6331 w32 specialized functions
@@ -6549,7 +6743,7 @@ The following %-sequences are provided:
6549 else 6743 else
6550 { 6744 {
6551 char buffer[16]; 6745 char buffer[16];
6552 _snprintf (buffer, 16, "%d", system_status.BatteryLifePercent); 6746 snprintf (buffer, 16, "%d", system_status.BatteryLifePercent);
6553 load_percentage = build_string (buffer); 6747 load_percentage = build_string (buffer);
6554 } 6748 }
6555 6749
@@ -6560,18 +6754,18 @@ The following %-sequences are provided:
6560 long m; 6754 long m;
6561 float h; 6755 float h;
6562 char buffer[16]; 6756 char buffer[16];
6563 _snprintf (buffer, 16, "%ld", seconds_left); 6757 snprintf (buffer, 16, "%ld", seconds_left);
6564 seconds = build_string (buffer); 6758 seconds = build_string (buffer);
6565 6759
6566 m = seconds_left / 60; 6760 m = seconds_left / 60;
6567 _snprintf (buffer, 16, "%ld", m); 6761 snprintf (buffer, 16, "%ld", m);
6568 minutes = build_string (buffer); 6762 minutes = build_string (buffer);
6569 6763
6570 h = seconds_left / 3600.0; 6764 h = seconds_left / 3600.0;
6571 _snprintf (buffer, 16, "%3.1f", h); 6765 snprintf (buffer, 16, "%3.1f", h);
6572 hours = build_string (buffer); 6766 hours = build_string (buffer);
6573 6767
6574 _snprintf (buffer, 16, "%ld:%02ld", m / 60, m % 60); 6768 snprintf (buffer, 16, "%ld:%02ld", m / 60, m % 60);
6575 remain = build_string (buffer); 6769 remain = build_string (buffer);
6576 } 6770 }
6577 6771
@@ -6733,10 +6927,10 @@ DEFUN ("default-printer-name", Fdefault_printer_name, Sdefault_printer_name,
6733 { 6927 {
6734 /* a remote printer */ 6928 /* a remote printer */
6735 if (*ppi2->pServerName == '\\') 6929 if (*ppi2->pServerName == '\\')
6736 _snprintf (pname_buf, sizeof (pname_buf), "%s\\%s", ppi2->pServerName, 6930 snprintf (pname_buf, sizeof (pname_buf), "%s\\%s", ppi2->pServerName,
6737 ppi2->pShareName); 6931 ppi2->pShareName);
6738 else 6932 else
6739 _snprintf (pname_buf, sizeof (pname_buf), "\\\\%s\\%s", ppi2->pServerName, 6933 snprintf (pname_buf, sizeof (pname_buf), "\\\\%s\\%s", ppi2->pServerName,
6740 ppi2->pShareName); 6934 ppi2->pShareName);
6741 pname_buf[sizeof (pname_buf) - 1] = '\0'; 6935 pname_buf[sizeof (pname_buf) - 1] = '\0';
6742 } 6936 }
@@ -6755,6 +6949,292 @@ DEFUN ("default-printer-name", Fdefault_printer_name, Sdefault_printer_name,
6755 return build_string (pname_buf); 6949 return build_string (pname_buf);
6756} 6950}
6757 6951
6952
6953/* Equivalent of strerror for W32 error codes. */
6954char *
6955w32_strerror (int error_no)
6956{
6957 static char buf[500];
6958 DWORD ret;
6959
6960 if (error_no == 0)
6961 error_no = GetLastError ();
6962
6963 ret = FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM |
6964 FORMAT_MESSAGE_IGNORE_INSERTS,
6965 NULL,
6966 error_no,
6967 0, /* choose most suitable language */
6968 buf, sizeof (buf), NULL);
6969
6970 while (ret > 0 && (buf[ret - 1] == '\n' ||
6971 buf[ret - 1] == '\r' ))
6972 --ret;
6973 buf[ret] = '\0';
6974 if (!ret)
6975 sprintf (buf, "w32 error %u", error_no);
6976
6977 return buf;
6978}
6979
6980/* For convenience when debugging. */
6981int
6982w32_last_error (void)
6983{
6984 return GetLastError ();
6985}
6986
6987/* Cache information describing the NT system for later use. */
6988void
6989cache_system_info (void)
6990{
6991 union
6992 {
6993 struct info
6994 {
6995 char major;
6996 char minor;
6997 short platform;
6998 } info;
6999 DWORD data;
7000 } version;
7001
7002 /* Cache the version of the operating system. */
7003 version.data = GetVersion ();
7004 w32_major_version = version.info.major;
7005 w32_minor_version = version.info.minor;
7006
7007 if (version.info.platform & 0x8000)
7008 os_subtype = OS_9X;
7009 else
7010 os_subtype = OS_NT;
7011
7012 /* Cache page size, allocation unit, processor type, etc. */
7013 GetSystemInfo (&sysinfo_cache);
7014 syspage_mask = sysinfo_cache.dwPageSize - 1;
7015
7016 /* Cache os info. */
7017 osinfo_cache.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
7018 GetVersionEx (&osinfo_cache);
7019
7020 w32_build_number = osinfo_cache.dwBuildNumber;
7021 if (os_subtype == OS_9X)
7022 w32_build_number &= 0xffff;
7023
7024 w32_num_mouse_buttons = GetSystemMetrics (SM_CMOUSEBUTTONS);
7025}
7026
7027#ifdef EMACSDEBUG
7028void
7029_DebPrint (const char *fmt, ...)
7030{
7031 char buf[1024];
7032 va_list args;
7033
7034 va_start (args, fmt);
7035 vsprintf (buf, fmt, args);
7036 va_end (args);
7037#if CYGWIN
7038 fprintf (stderr, "%s", buf);
7039#endif
7040 OutputDebugString (buf);
7041}
7042#endif
7043
7044int
7045w32_console_toggle_lock_key (int vk_code, Lisp_Object new_state)
7046{
7047 int cur_state = (GetKeyState (vk_code) & 1);
7048
7049 if (NILP (new_state)
7050 || (NUMBERP (new_state)
7051 && ((XUINT (new_state)) & 1) != cur_state))
7052 {
7053#ifdef WINDOWSNT
7054 faked_key = vk_code;
7055#endif /* WINDOWSNT */
7056
7057 keybd_event ((BYTE) vk_code,
7058 (BYTE) MapVirtualKey (vk_code, 0),
7059 KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
7060 keybd_event ((BYTE) vk_code,
7061 (BYTE) MapVirtualKey (vk_code, 0),
7062 KEYEVENTF_EXTENDEDKEY | 0, 0);
7063 keybd_event ((BYTE) vk_code,
7064 (BYTE) MapVirtualKey (vk_code, 0),
7065 KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
7066 cur_state = !cur_state;
7067 }
7068
7069 return cur_state;
7070}
7071
7072/* Translate console modifiers to emacs modifiers.
7073 German keyboard support (Kai Morgan Zeise 2/18/95). */
7074int
7075w32_kbd_mods_to_emacs (DWORD mods, WORD key)
7076{
7077 int retval = 0;
7078
7079 /* If we recognize right-alt and left-ctrl as AltGr, and it has been
7080 pressed, first remove those modifiers. */
7081 if (!NILP (Vw32_recognize_altgr)
7082 && (mods & (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED))
7083 == (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED))
7084 mods &= ~ (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED);
7085
7086 if (mods & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED))
7087 retval = ((NILP (Vw32_alt_is_meta)) ? alt_modifier : meta_modifier);
7088
7089 if (mods & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED))
7090 {
7091 retval |= ctrl_modifier;
7092 if ((mods & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED))
7093 == (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED))
7094 retval |= meta_modifier;
7095 }
7096
7097 if (mods & LEFT_WIN_PRESSED)
7098 retval |= w32_key_to_modifier (VK_LWIN);
7099 if (mods & RIGHT_WIN_PRESSED)
7100 retval |= w32_key_to_modifier (VK_RWIN);
7101 if (mods & APPS_PRESSED)
7102 retval |= w32_key_to_modifier (VK_APPS);
7103 if (mods & SCROLLLOCK_ON)
7104 retval |= w32_key_to_modifier (VK_SCROLL);
7105
7106 /* Just in case someone wanted the original behavior, make it
7107 optional by setting w32-capslock-is-shiftlock to t. */
7108 if (NILP (Vw32_capslock_is_shiftlock)
7109 /* Keys that should _not_ be affected by CapsLock. */
7110 && ( (key == VK_BACK)
7111 || (key == VK_TAB)
7112 || (key == VK_CLEAR)
7113 || (key == VK_RETURN)
7114 || (key == VK_ESCAPE)
7115 || ((key >= VK_SPACE) && (key <= VK_HELP))
7116 || ((key >= VK_NUMPAD0) && (key <= VK_F24))
7117 || ((key >= VK_NUMPAD_CLEAR) && (key <= VK_NUMPAD_DELETE))
7118 ))
7119 {
7120 /* Only consider shift state. */
7121 if ((mods & SHIFT_PRESSED) != 0)
7122 retval |= shift_modifier;
7123 }
7124 else
7125 {
7126 /* Ignore CapsLock state if not enabled. */
7127 if (NILP (Vw32_enable_caps_lock))
7128 mods &= ~CAPSLOCK_ON;
7129 if ((mods & (SHIFT_PRESSED | CAPSLOCK_ON)) != 0)
7130 retval |= shift_modifier;
7131 }
7132
7133 return retval;
7134}
7135
7136/* The return code indicates key code size. cpID is the codepage to
7137 use for translation to Unicode; -1 means use the current console
7138 input codepage. */
7139int
7140w32_kbd_patch_key (KEY_EVENT_RECORD *event, int cpId)
7141{
7142 unsigned int key_code = event->wVirtualKeyCode;
7143 unsigned int mods = event->dwControlKeyState;
7144 BYTE keystate[256];
7145 static BYTE ansi_code[4];
7146 static int isdead = 0;
7147
7148 if (isdead == 2)
7149 {
7150 event->uChar.AsciiChar = ansi_code[2];
7151 isdead = 0;
7152 return 1;
7153 }
7154 if (event->uChar.AsciiChar != 0)
7155 return 1;
7156
7157 memset (keystate, 0, sizeof (keystate));
7158 keystate[key_code] = 0x80;
7159 if (mods & SHIFT_PRESSED)
7160 keystate[VK_SHIFT] = 0x80;
7161 if (mods & CAPSLOCK_ON)
7162 keystate[VK_CAPITAL] = 1;
7163 /* If we recognize right-alt and left-ctrl as AltGr, set the key
7164 states accordingly before invoking ToAscii. */
7165 if (!NILP (Vw32_recognize_altgr)
7166 && (mods & LEFT_CTRL_PRESSED) && (mods & RIGHT_ALT_PRESSED))
7167 {
7168 keystate[VK_CONTROL] = 0x80;
7169 keystate[VK_LCONTROL] = 0x80;
7170 keystate[VK_MENU] = 0x80;
7171 keystate[VK_RMENU] = 0x80;
7172 }
7173
7174#if 0
7175 /* Because of an OS bug, ToAscii corrupts the stack when called to
7176 convert a dead key in console mode on NT4. Unfortunately, trying
7177 to check for dead keys using MapVirtualKey doesn't work either -
7178 these functions apparently use internal information about keyboard
7179 layout which doesn't get properly updated in console programs when
7180 changing layout (though apparently it gets partly updated,
7181 otherwise ToAscii wouldn't crash). */
7182 if (is_dead_key (event->wVirtualKeyCode))
7183 return 0;
7184#endif
7185
7186 /* On NT, call ToUnicode instead and then convert to the current
7187 console input codepage. */
7188 if (os_subtype == OS_NT)
7189 {
7190 WCHAR buf[128];
7191
7192 isdead = ToUnicode (event->wVirtualKeyCode, event->wVirtualScanCode,
7193 keystate, buf, 128, 0);
7194 if (isdead > 0)
7195 {
7196 /* When we are called from the GUI message processing code,
7197 we are passed the current keyboard codepage, a positive
7198 number, to use below. */
7199 if (cpId == -1)
7200 cpId = GetConsoleCP ();
7201
7202 event->uChar.UnicodeChar = buf[isdead - 1];
7203 isdead = WideCharToMultiByte (cpId, 0, buf, isdead,
7204 ansi_code, 4, NULL, NULL);
7205 }
7206 else
7207 isdead = 0;
7208 }
7209 else
7210 {
7211 isdead = ToAscii (event->wVirtualKeyCode, event->wVirtualScanCode,
7212 keystate, (LPWORD) ansi_code, 0);
7213 }
7214
7215 if (isdead == 0)
7216 return 0;
7217 event->uChar.AsciiChar = ansi_code[0];
7218 return isdead;
7219}
7220
7221
7222void
7223w32_sys_ring_bell (struct frame *f)
7224{
7225 if (sound_type == 0xFFFFFFFF)
7226 {
7227 Beep (666, 100);
7228 }
7229 else if (sound_type == MB_EMACS_SILENT)
7230 {
7231 /* Do nothing. */
7232 }
7233 else
7234 MessageBeep (sound_type);
7235}
7236
7237
6758/*********************************************************************** 7238/***********************************************************************
6759 Initialization 7239 Initialization
6760 ***********************************************************************/ 7240 ***********************************************************************/
@@ -7121,10 +7601,10 @@ only be necessary if the default setting causes problems. */);
7121 7601
7122 defsubr (&Sfile_system_info); 7602 defsubr (&Sfile_system_info);
7123 defsubr (&Sdefault_printer_name); 7603 defsubr (&Sdefault_printer_name);
7604 defsubr (&Sset_message_beep);
7124 7605
7125 check_window_system_func = check_w32; 7606 check_window_system_func = check_w32;
7126 7607
7127
7128 hourglass_timer = 0; 7608 hourglass_timer = 0;
7129 hourglass_hwnd = NULL; 7609 hourglass_hwnd = NULL;
7130 7610
@@ -7139,7 +7619,9 @@ only be necessary if the default setting causes problems. */);
7139 staticpro (&last_show_tip_args); 7619 staticpro (&last_show_tip_args);
7140 7620
7141 defsubr (&Sx_file_dialog); 7621 defsubr (&Sx_file_dialog);
7622#ifdef WINDOWSNT
7142 defsubr (&Ssystem_move_file_to_trash); 7623 defsubr (&Ssystem_move_file_to_trash);
7624#endif
7143} 7625}
7144 7626
7145 7627
@@ -7223,9 +7705,3 @@ w32_abort (void)
7223 } 7705 }
7224} 7706}
7225 7707
7226/* For convenience when debugging. */
7227int
7228w32_last_error (void)
7229{
7230 return GetLastError ();
7231}
diff --git a/src/w32font.c b/src/w32font.c
index cfd453282dd..c135d061e7d 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>
@@ -1436,6 +1437,9 @@ w32font_coverage_ok (FONTSIGNATURE * coverage, BYTE charset)
1436 return 1; 1437 return 1;
1437} 1438}
1438 1439
1440#ifndef WINDOWSNT
1441#define _strlwr strlwr
1442#endif /* !WINDOWSNT */
1439 1443
1440static int 1444static int
1441check_face_name (LOGFONT *font, char *full_name) 1445check_face_name (LOGFONT *font, char *full_name)
diff --git a/src/w32heap.c b/src/w32heap.c
index 26cc9aa0a0f..f0753404792 100644
--- a/src/w32heap.c
+++ b/src/w32heap.c
@@ -33,10 +33,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
33SYSTEM_INFO sysinfo_cache; 33SYSTEM_INFO sysinfo_cache;
34 34
35/* This gives us version, build, and platform identification. */ 35/* This gives us version, build, and platform identification. */
36extern unsigned long syspage_mask;
36OSVERSIONINFO osinfo_cache; 37OSVERSIONINFO osinfo_cache;
37 38
38unsigned long syspage_mask = 0;
39
40/* The major and minor versions of NT. */ 39/* The major and minor versions of NT. */
41int w32_major_version; 40int w32_major_version;
42int w32_minor_version; 41int w32_minor_version;
@@ -45,44 +44,6 @@ int w32_build_number;
45/* Distinguish between Windows NT and Windows 95. */ 44/* Distinguish between Windows NT and Windows 95. */
46int os_subtype; 45int os_subtype;
47 46
48/* Cache information describing the NT system for later use. */
49void
50cache_system_info (void)
51{
52 union
53 {
54 struct info
55 {
56 char major;
57 char minor;
58 short platform;
59 } info;
60 DWORD data;
61 } version;
62
63 /* Cache the version of the operating system. */
64 version.data = GetVersion ();
65 w32_major_version = version.info.major;
66 w32_minor_version = version.info.minor;
67
68 if (version.info.platform & 0x8000)
69 os_subtype = OS_9X;
70 else
71 os_subtype = OS_NT;
72
73 /* Cache page size, allocation unit, processor type, etc. */
74 GetSystemInfo (&sysinfo_cache);
75 syspage_mask = sysinfo_cache.dwPageSize - 1;
76
77 /* Cache os info. */
78 osinfo_cache.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
79 GetVersionEx (&osinfo_cache);
80
81 w32_build_number = osinfo_cache.dwBuildNumber;
82 if (os_subtype == OS_9X)
83 w32_build_number &= 0xffff;
84}
85
86/* Emulate getpagesize. */ 47/* Emulate getpagesize. */
87int 48int
88getpagesize (void) 49getpagesize (void)
diff --git a/src/w32inevt.c b/src/w32inevt.c
index 731dd6715dc..ca97fed1fe6 100644
--- a/src/w32inevt.c
+++ b/src/w32inevt.c
@@ -71,6 +71,9 @@ w32_read_console_input (HANDLE h, INPUT_RECORD *rec, DWORD recsize,
71 : ReadConsoleInputA (h, rec, recsize, waiting)); 71 : ReadConsoleInputA (h, rec, recsize, waiting));
72} 72}
73 73
74/* Set by w32_console_toggle_lock_key. */
75int faked_key;
76
74static int 77static int
75fill_queue (BOOL block) 78fill_queue (BOOL block)
76{ 79{
@@ -111,67 +114,7 @@ get_frame (void)
111 114
112/* Translate console modifiers to emacs modifiers. 115/* Translate console modifiers to emacs modifiers.
113 German keyboard support (Kai Morgan Zeise 2/18/95). */ 116 German keyboard support (Kai Morgan Zeise 2/18/95). */
114int
115w32_kbd_mods_to_emacs (DWORD mods, WORD key)
116{
117 int retval = 0;
118
119 /* If we recognize right-alt and left-ctrl as AltGr, and it has been
120 pressed, first remove those modifiers. */
121 if (!NILP (Vw32_recognize_altgr)
122 && (mods & (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED))
123 == (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED))
124 mods &= ~ (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED);
125 117
126 if (mods & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED))
127 retval = ((NILP (Vw32_alt_is_meta)) ? alt_modifier : meta_modifier);
128
129 if (mods & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED))
130 {
131 retval |= ctrl_modifier;
132 if ((mods & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED))
133 == (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED))
134 retval |= meta_modifier;
135 }
136
137 if (mods & LEFT_WIN_PRESSED)
138 retval |= w32_key_to_modifier (VK_LWIN);
139 if (mods & RIGHT_WIN_PRESSED)
140 retval |= w32_key_to_modifier (VK_RWIN);
141 if (mods & APPS_PRESSED)
142 retval |= w32_key_to_modifier (VK_APPS);
143 if (mods & SCROLLLOCK_ON)
144 retval |= w32_key_to_modifier (VK_SCROLL);
145
146 /* Just in case someone wanted the original behavior, make it
147 optional by setting w32-capslock-is-shiftlock to t. */
148 if (NILP (Vw32_capslock_is_shiftlock)
149 /* Keys that should _not_ be affected by CapsLock. */
150 && ( (key == VK_BACK)
151 || (key == VK_TAB)
152 || (key == VK_CLEAR)
153 || (key == VK_RETURN)
154 || (key == VK_ESCAPE)
155 || ((key >= VK_SPACE) && (key <= VK_HELP))
156 || ((key >= VK_NUMPAD0) && (key <= VK_F24))
157 || ((key >= VK_NUMPAD_CLEAR) && (key <= VK_NUMPAD_DELETE))
158 ))
159 {
160 /* Only consider shift state. */
161 if ((mods & SHIFT_PRESSED) != 0)
162 retval |= shift_modifier;
163 }
164 else
165 {
166 /* Ignore CapsLock state if not enabled. */
167 if (NILP (Vw32_enable_caps_lock))
168 mods &= ~CAPSLOCK_ON;
169 if ((mods & (SHIFT_PRESSED | CAPSLOCK_ON)) != 0)
170 retval |= shift_modifier;
171 }
172
173 return retval;
174}
175 118
176#if 0 119#if 0
177/* Return nonzero if the virtual key is a dead key. */ 120/* Return nonzero if the virtual key is a dead key. */
@@ -188,90 +131,7 @@ is_dead_key (int wparam)
188/* The return code indicates key code size. cpID is the codepage to 131/* The return code indicates key code size. cpID is the codepage to
189 use for translation to Unicode; -1 means use the current console 132 use for translation to Unicode; -1 means use the current console
190 input codepage. */ 133 input codepage. */
191int
192w32_kbd_patch_key (KEY_EVENT_RECORD *event, int cpId)
193{
194 unsigned int key_code = event->wVirtualKeyCode;
195 unsigned int mods = event->dwControlKeyState;
196 BYTE keystate[256];
197 static BYTE ansi_code[4];
198 static int isdead = 0;
199 134
200 if (isdead == 2)
201 {
202 event->uChar.AsciiChar = ansi_code[2];
203 isdead = 0;
204 return 1;
205 }
206 if (event->uChar.AsciiChar != 0)
207 return 1;
208
209 memset (keystate, 0, sizeof (keystate));
210 keystate[key_code] = 0x80;
211 if (mods & SHIFT_PRESSED)
212 keystate[VK_SHIFT] = 0x80;
213 if (mods & CAPSLOCK_ON)
214 keystate[VK_CAPITAL] = 1;
215 /* If we recognize right-alt and left-ctrl as AltGr, set the key
216 states accordingly before invoking ToAscii. */
217 if (!NILP (Vw32_recognize_altgr)
218 && (mods & LEFT_CTRL_PRESSED) && (mods & RIGHT_ALT_PRESSED))
219 {
220 keystate[VK_CONTROL] = 0x80;
221 keystate[VK_LCONTROL] = 0x80;
222 keystate[VK_MENU] = 0x80;
223 keystate[VK_RMENU] = 0x80;
224 }
225
226#if 0
227 /* Because of an OS bug, ToAscii corrupts the stack when called to
228 convert a dead key in console mode on NT4. Unfortunately, trying
229 to check for dead keys using MapVirtualKey doesn't work either -
230 these functions apparently use internal information about keyboard
231 layout which doesn't get properly updated in console programs when
232 changing layout (though apparently it gets partly updated,
233 otherwise ToAscii wouldn't crash). */
234 if (is_dead_key (event->wVirtualKeyCode))
235 return 0;
236#endif
237
238 /* On NT, call ToUnicode instead and then convert to the current
239 console input codepage. */
240 if (os_subtype == OS_NT)
241 {
242 WCHAR buf[128];
243
244 isdead = ToUnicode (event->wVirtualKeyCode, event->wVirtualScanCode,
245 keystate, buf, 128, 0);
246 if (isdead > 0)
247 {
248 /* When we are called from the GUI message processing code,
249 we are passed the current keyboard codepage, a positive
250 number, to use below. */
251 if (cpId == -1)
252 cpId = GetConsoleCP ();
253
254 event->uChar.UnicodeChar = buf[isdead - 1];
255 isdead = WideCharToMultiByte (cpId, 0, buf, isdead,
256 ansi_code, 4, NULL, NULL);
257 }
258 else
259 isdead = 0;
260 }
261 else
262 {
263 isdead = ToAscii (event->wVirtualKeyCode, event->wVirtualScanCode,
264 keystate, (LPWORD) ansi_code, 0);
265 }
266
267 if (isdead == 0)
268 return 0;
269 event->uChar.AsciiChar = ansi_code[0];
270 return isdead;
271}
272
273
274static int faked_key = 0;
275 135
276/* return code -1 means that event_queue_ptr won't be incremented. 136/* return code -1 means that event_queue_ptr won't be incremented.
277 In other word, this event makes two key codes. (by himi) */ 137 In other word, this event makes two key codes. (by himi) */
@@ -532,32 +392,6 @@ key_event (KEY_EVENT_RECORD *event, struct input_event *emacs_ev, int *isdead)
532 return 1; 392 return 1;
533} 393}
534 394
535int
536w32_console_toggle_lock_key (int vk_code, Lisp_Object new_state)
537{
538 int cur_state = (GetKeyState (vk_code) & 1);
539
540 if (NILP (new_state)
541 || (NUMBERP (new_state)
542 && ((XUINT (new_state)) & 1) != cur_state))
543 {
544 faked_key = vk_code;
545
546 keybd_event ((BYTE) vk_code,
547 (BYTE) MapVirtualKey (vk_code, 0),
548 KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
549 keybd_event ((BYTE) vk_code,
550 (BYTE) MapVirtualKey (vk_code, 0),
551 KEYEVENTF_EXTENDEDKEY | 0, 0);
552 keybd_event ((BYTE) vk_code,
553 (BYTE) MapVirtualKey (vk_code, 0),
554 KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
555 cur_state = !cur_state;
556 }
557
558 return cur_state;
559}
560
561/* Mouse position hook. */ 395/* Mouse position hook. */
562void 396void
563w32_console_mouse_position (FRAME_PTR *f, 397w32_console_mouse_position (FRAME_PTR *f,
diff --git a/src/w32menu.c b/src/w32menu.c
index 3aa4c8bc96d..886fd55bbe9 100644
--- a/src/w32menu.c
+++ b/src/w32menu.c
@@ -21,7 +21,6 @@ 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>
25#include <setjmp.h> 24#include <setjmp.h>
26 25
27#include "lisp.h" 26#include "lisp.h"
@@ -41,6 +40,14 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
41 if this is not done before the other system files. */ 40 if this is not done before the other system files. */
42#include "w32term.h" 41#include "w32term.h"
43 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
44/* Load sys/types.h if not already loaded. 51/* Load sys/types.h if not already loaded.
45 In some systems loading it twice is suicidal. */ 52 In some systems loading it twice is suicidal. */
46#ifndef makedev 53#ifndef makedev
@@ -79,10 +86,17 @@ typedef int (WINAPI * MessageBoxW_Proc) (
79 IN WCHAR *caption, 86 IN WCHAR *caption,
80 IN UINT type); 87 IN UINT type);
81 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 */
82GetMenuItemInfoA_Proc get_menu_item_info = NULL; 95GetMenuItemInfoA_Proc get_menu_item_info = NULL;
83SetMenuItemInfoA_Proc set_menu_item_info = NULL; 96SetMenuItemInfoA_Proc set_menu_item_info = NULL;
84AppendMenuW_Proc unicode_append_menu = NULL; 97AppendMenuW_Proc unicode_append_menu = NULL;
85MessageBoxW_Proc unicode_message_box = NULL; 98MessageBoxW_Proc unicode_message_box = NULL;
99#endif /* NTGUI_UNICODE */
86 100
87Lisp_Object Qdebug_on_next_call; 101Lisp_Object Qdebug_on_next_call;
88 102
@@ -99,6 +113,7 @@ static void utf8to16 (unsigned char *, int, WCHAR *);
99static int fill_in_menu (HMENU, widget_value *); 113static int fill_in_menu (HMENU, widget_value *);
100 114
101void w32_free_menu_strings (HWND); 115void w32_free_menu_strings (HWND);
116
102 117
103 118
104/* 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
@@ -1406,6 +1421,7 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item)
1406 nlen++; 1421 nlen++;
1407 } 1422 }
1408 } 1423 }
1424#ifndef NTGUI_UNICODE
1409 else 1425 else
1410 { 1426 {
1411 /* If encoded with the system codepage, use multibyte string 1427 /* If encoded with the system codepage, use multibyte string
@@ -1416,6 +1432,7 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item)
1416 nlen++; 1432 nlen++;
1417 } 1433 }
1418 } 1434 }
1435#endif /* !NTGUI_UNICODE */
1419 1436
1420 if (nlen > orig_len) 1437 if (nlen > orig_len)
1421 { 1438 {
@@ -1430,6 +1447,7 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item)
1430 *q++ = *p; 1447 *q++ = *p;
1431 *q++ = *p++; 1448 *q++ = *p++;
1432 } 1449 }
1450#ifndef NTGUI_UNICODE
1433 else 1451 else
1434 { 1452 {
1435 if (_mbsnextc (p) == '&') 1453 if (_mbsnextc (p) == '&')
@@ -1441,6 +1459,7 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item)
1441 p = _mbsinc (p); 1459 p = _mbsinc (p);
1442 q = _mbsinc (q); 1460 q = _mbsinc (q);
1443 } 1461 }
1462#endif /* !NTGUI_UNICODE */
1444 } 1463 }
1445 *q = '\0'; 1464 *q = '\0';
1446 } 1465 }
@@ -1487,6 +1506,8 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item)
1487 item != NULL ? (UINT) item 1506 item != NULL ? (UINT) item
1488 : (UINT) wv->call_data, 1507 : (UINT) wv->call_data,
1489 utf16_string); 1508 utf16_string);
1509
1510#ifndef NTGUI_UNICODE /* Fallback does not apply when always UNICODE */
1490 if (!return_value) 1511 if (!return_value)
1491 { 1512 {
1492 /* On W9x/ME, Unicode menus are not supported, though AppendMenuW 1513 /* On W9x/ME, Unicode menus are not supported, though AppendMenuW
@@ -1505,6 +1526,7 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item)
1505 if (osinfo_cache.dwPlatformId != VER_PLATFORM_WIN32_NT) 1526 if (osinfo_cache.dwPlatformId != VER_PLATFORM_WIN32_NT)
1506 unicode_append_menu = NULL; 1527 unicode_append_menu = NULL;
1507 } 1528 }
1529#endif /* NTGUI_UNICODE */
1508 1530
1509 if (unicode_append_menu && (fuFlags & MF_OWNERDRAW)) 1531 if (unicode_append_menu && (fuFlags & MF_OWNERDRAW))
1510 local_free (out_string); 1532 local_free (out_string);
@@ -1724,10 +1746,12 @@ syms_of_w32menu (void)
1724void 1746void
1725globals_of_w32menu (void) 1747globals_of_w32menu (void)
1726{ 1748{
1749#ifndef NTGUI_UNICODE
1727 /* See if Get/SetMenuItemInfo functions are available. */ 1750 /* See if Get/SetMenuItemInfo functions are available. */
1728 HMODULE user32 = GetModuleHandle ("user32.dll"); 1751 HMODULE user32 = GetModuleHandle ("user32.dll");
1729 get_menu_item_info = (GetMenuItemInfoA_Proc) GetProcAddress (user32, "GetMenuItemInfoA"); 1752 get_menu_item_info = (GetMenuItemInfoA_Proc) GetProcAddress (user32, "GetMenuItemInfoA");
1730 set_menu_item_info = (SetMenuItemInfoA_Proc) GetProcAddress (user32, "SetMenuItemInfoA"); 1753 set_menu_item_info = (SetMenuItemInfoA_Proc) GetProcAddress (user32, "SetMenuItemInfoA");
1731 unicode_append_menu = (AppendMenuW_Proc) GetProcAddress (user32, "AppendMenuW"); 1754 unicode_append_menu = (AppendMenuW_Proc) GetProcAddress (user32, "AppendMenuW");
1732 unicode_message_box = (MessageBoxW_Proc) GetProcAddress (user32, "MessageBoxW"); 1755 unicode_message_box = (MessageBoxW_Proc) GetProcAddress (user32, "MessageBoxW");
1756#endif /* !NTGUI_UNICODE */
1733} 1757}
diff --git a/src/w32proc.c b/src/w32proc.c
index 33aed5eb8e3..0cc62aebca0 100644
--- a/src/w32proc.c
+++ b/src/w32proc.c
@@ -68,20 +68,6 @@ extern BOOL WINAPI IsValidLocale (LCID, DWORD);
68 68
69Lisp_Object Qhigh, Qlow; 69Lisp_Object Qhigh, Qlow;
70 70
71#ifdef EMACSDEBUG
72void
73_DebPrint (const char *fmt, ...)
74{
75 char buf[1024];
76 va_list args;
77
78 va_start (args, fmt);
79 vsprintf (buf, fmt, args);
80 va_end (args);
81 OutputDebugString (buf);
82}
83#endif
84
85typedef void (_CALLBACK_ *signal_handler) (int); 71typedef void (_CALLBACK_ *signal_handler) (int);
86 72
87/* Signal handlers...SIG_DFL == 0 so this is initialized correctly. */ 73/* Signal handlers...SIG_DFL == 0 so this is initialized correctly. */
diff --git a/src/w32select.c b/src/w32select.c
index 59ff4405368..6b855b43a35 100644
--- a/src/w32select.c
+++ b/src/w32select.c
@@ -82,6 +82,11 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
82#include "coding.h" 82#include "coding.h"
83#include "composite.h" 83#include "composite.h"
84 84
85#ifdef CYGWIN
86#include <string.h>
87#include <stdio.h>
88#define _memccpy memccpy
89#endif
85 90
86static HGLOBAL convert_to_handle_as_ascii (void); 91static HGLOBAL convert_to_handle_as_ascii (void);
87static HGLOBAL convert_to_handle_as_coded (Lisp_Object coding_system); 92static HGLOBAL convert_to_handle_as_coded (Lisp_Object coding_system);
diff --git a/src/w32term.c b/src/w32term.c
index 6948a98998e..0dffcd0bf0a 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -52,7 +52,14 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
52#include "atimer.h" 52#include "atimer.h"
53#include "keymap.h" 53#include "keymap.h"
54 54
55#ifdef WINDOWSNT
55#include "w32heap.h" 56#include "w32heap.h"
57#endif
58
59#ifndef WINDOWSNT
60#include <io.h> /* for get_osfhandle */
61#endif
62
56#include <shellapi.h> 63#include <shellapi.h>
57 64
58#include "font.h" 65#include "font.h"
@@ -103,7 +110,7 @@ struct w32_display_info *x_display_list;
103Lisp_Object w32_display_name_list; 110Lisp_Object w32_display_name_list;
104 111
105 112
106#ifndef GLYPHSET 113#if !defined (GLYPHSET) && _WIN32_WINNT < 0x500
107/* Pre Windows 2000, this was not available, but define it here so 114/* Pre Windows 2000, this was not available, but define it here so
108 that Emacs compiled on such a platform will run on newer versions. */ 115 that Emacs compiled on such a platform will run on newer versions. */
109 116
@@ -122,7 +129,7 @@ typedef struct tagGLYPHSET
122 WCRANGE ranges[1]; 129 WCRANGE ranges[1];
123} GLYPHSET; 130} GLYPHSET;
124 131
125#endif 132#endif /* compiling for pre-Win2k */
126 133
127/* Dynamic linking to SetLayeredWindowAttribute (only since 2000). */ 134/* Dynamic linking to SetLayeredWindowAttribute (only since 2000). */
128BOOL (WINAPI *pfnSetLayeredWindowAttributes) (HWND, COLORREF, BYTE, DWORD); 135BOOL (WINAPI *pfnSetLayeredWindowAttributes) (HWND, COLORREF, BYTE, DWORD);
@@ -191,6 +198,13 @@ static int volatile input_signal_count;
191static int input_signal_count; 198static int input_signal_count;
192#endif 199#endif
193 200
201#ifdef CYGWIN
202int w32_message_fd = -1;
203#endif /* CYGWIN */
204
205/* Keyboard code page - may be changed by language-change events. */
206static int keyboard_codepage;
207
194static void x_update_window_end (struct window *, int, int); 208static void x_update_window_end (struct window *, int, int);
195static void w32_handle_tool_bar_click (struct frame *, 209static void w32_handle_tool_bar_click (struct frame *,
196 struct input_event *); 210 struct input_event *);
@@ -4158,6 +4172,7 @@ w32_read_socket (struct terminal *terminal, int expected,
4158 struct frame *f; 4172 struct frame *f;
4159 struct w32_display_info *dpyinfo = &one_w32_display_info; 4173 struct w32_display_info *dpyinfo = &one_w32_display_info;
4160 Mouse_HLInfo *hlinfo = &dpyinfo->mouse_highlight; 4174 Mouse_HLInfo *hlinfo = &dpyinfo->mouse_highlight;
4175 static char buf[1];
4161 4176
4162 if (interrupt_input_blocked) 4177 if (interrupt_input_blocked)
4163 { 4178 {
@@ -4171,12 +4186,19 @@ w32_read_socket (struct terminal *terminal, int expected,
4171 /* So people can tell when we have read the available input. */ 4186 /* So people can tell when we have read the available input. */
4172 input_signal_count++; 4187 input_signal_count++;
4173 4188
4189 /* Process any incoming thread messages. */
4190 drain_message_queue ();
4191
4174 /* TODO: ghostscript integration. */ 4192 /* TODO: ghostscript integration. */
4175 while (get_next_msg (&msg, FALSE)) 4193 while (get_next_msg (&msg, FALSE))
4176 { 4194 {
4177 struct input_event inev; 4195 struct input_event inev;
4178 int do_help = 0; 4196 int do_help = 0;
4179 4197
4198 /* DebPrint (("w32_read_socket: %s time:%u\n", */
4199 /* w32_name_of_message (msg.msg.message), */
4200 /* msg.msg.time)); */
4201
4180 EVENT_INIT (inev); 4202 EVENT_INIT (inev);
4181 inev.kind = NO_EVENT; 4203 inev.kind = NO_EVENT;
4182 inev.arg = Qnil; 4204 inev.arg = Qnil;
@@ -6309,8 +6331,15 @@ w32_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
6309 w32_defined_color (0, "black", &color, 1); 6331 w32_defined_color (0, "black", &color, 1);
6310 } 6332 }
6311 6333
6312 /* Add the default keyboard. */ 6334#ifdef WINDOWSNT
6335 /* Add the default keyboard. When !WINDOWSNT, we're using the
6336 standard Emacs console handling machinery and don't need an
6337 explicit FD here. */
6313 add_keyboard_wait_descriptor (0); 6338 add_keyboard_wait_descriptor (0);
6339#elif CYGWIN
6340 /* /dev/windows wakes us up when we have a thread message pending. */
6341 add_keyboard_wait_descriptor (w32_message_fd);
6342#endif
6314 6343
6315 /* Create Fringe Bitmaps and store them for later use. 6344 /* Create Fringe Bitmaps and store them for later use.
6316 6345
@@ -6321,15 +6350,6 @@ w32_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
6321 the bitmaps. */ 6350 the bitmaps. */
6322 w32_init_fringe (terminal->rif); 6351 w32_init_fringe (terminal->rif);
6323 6352
6324#ifdef F_SETOWN
6325 fcntl (connection, F_SETOWN, getpid ());
6326#endif /* ! defined (F_SETOWN) */
6327
6328#ifdef SIGIO
6329 if (interrupt_input)
6330 init_sigio (connection);
6331#endif /* ! defined (SIGIO) */
6332
6333 UNBLOCK_INPUT; 6353 UNBLOCK_INPUT;
6334 6354
6335 return dpyinfo; 6355 return dpyinfo;
@@ -6379,6 +6399,7 @@ x_delete_display (struct w32_display_info *dpyinfo)
6379 6399
6380 w32_reset_fringes (); 6400 w32_reset_fringes ();
6381} 6401}
6402
6382 6403
6383/* Set up use of W32. */ 6404/* Set up use of W32. */
6384 6405
@@ -6416,6 +6437,11 @@ w32_initialize (void)
6416 set_user_model (L"GNU.Emacs"); 6437 set_user_model (L"GNU.Emacs");
6417 } 6438 }
6418 6439
6440#ifdef CYGWIN
6441 if ((w32_message_fd = open ("/dev/windows", O_RDWR | O_CLOEXEC)) == -1)
6442 fatal ("opening /dev/windows: %s", strerror (errno));
6443#endif /* CYGWIN */
6444
6419 /* Initialize w32_use_visible_system_caret based on whether a screen 6445 /* Initialize w32_use_visible_system_caret based on whether a screen
6420 reader is in use. */ 6446 reader is in use. */
6421 if (!SystemParametersInfo (SPI_GETSCREENREADER, 0, 6447 if (!SystemParametersInfo (SPI_GETSCREENREADER, 0,
@@ -6576,4 +6602,6 @@ With MS Windows or Nextstep, the value is t. */);
6576 6602
6577 staticpro (&last_mouse_motion_frame); 6603 staticpro (&last_mouse_motion_frame);
6578 last_mouse_motion_frame = Qnil; 6604 last_mouse_motion_frame = Qnil;
6605
6606 Fprovide (intern_c_string ("w32"), Qnil);
6579} 6607}
diff --git a/src/w32term.h b/src/w32term.h
index 5d756f435e4..434eb92fdea 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,47 @@ 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, char *color,
208 XColor *color_def, int alloc);
209extern void set_frame_menubar (struct frame *f, int first_time, int deep_p);
210extern void x_set_window_size (struct frame *f, int change_grav,
211 int cols, int rows);
201extern int x_display_pixel_height (struct w32_display_info *); 212extern int x_display_pixel_height (struct w32_display_info *);
202extern int x_display_pixel_width (struct w32_display_info *); 213extern int x_display_pixel_width (struct w32_display_info *);
214extern void x_sync (struct frame *);
215extern Lisp_Object x_get_focus_frame (struct frame *);
216extern void x_set_mouse_position (struct frame *f, int h, int v);
217extern void x_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y);
218extern void x_make_frame_visible (struct frame *f);
219extern void x_make_frame_invisible (struct frame *f);
220extern void x_iconify_frame (struct frame *f);
221extern int x_char_width (struct frame *f);
222extern int x_char_height (struct frame *f);
223extern int x_pixel_width (struct frame *f);
224extern int x_pixel_height (struct frame *f);
225extern void x_set_frame_alpha (struct frame *f);
226extern void x_set_menu_bar_lines (struct frame *, Lisp_Object, Lisp_Object);
227extern void x_set_tool_bar_lines (struct frame *f,
228 Lisp_Object value,
229 Lisp_Object oldval);
230extern void x_activate_menubar (struct frame *);
231extern int x_bitmap_icon (struct frame *, Lisp_Object);
232extern void initialize_frame_menubar (struct frame *);
233extern void x_free_frame_resources (struct frame *);
234extern void x_wm_set_size_hint (struct frame *, long, int);
235extern void x_real_positions (struct frame *, int *, int *);
236
237/* w32inevt.c */
238extern int w32_kbd_patch_key (KEY_EVENT_RECORD *event, int cpId);
239extern int w32_kbd_mods_to_emacs (DWORD mods, WORD key);
240
203 241
204 242
205#define PIX_TYPE COLORREF 243#define PIX_TYPE COLORREF
@@ -573,8 +611,9 @@ do { \
573#define WM_EMACS_HIDE_CARET (WM_EMACS_START + 18) 611#define WM_EMACS_HIDE_CARET (WM_EMACS_START + 18)
574#define WM_EMACS_SETCURSOR (WM_EMACS_START + 19) 612#define WM_EMACS_SETCURSOR (WM_EMACS_START + 19)
575#define WM_EMACS_PAINT (WM_EMACS_START + 20) 613#define WM_EMACS_PAINT (WM_EMACS_START + 20)
576#define WM_EMACS_BRINGTOTOP (WM_EMACS_START + 21) 614#define WM_EMACS_BRINGTOTOP (WM_EMACS_START + 22)
577#define WM_EMACS_END (WM_EMACS_START + 22) 615#define WM_EMACS_INPUT_READY (WM_EMACS_START + 23)
616#define WM_EMACS_END (WM_EMACS_START + 24)
578 617
579#define WND_FONTWIDTH_INDEX (0) 618#define WND_FONTWIDTH_INDEX (0)
580#define WND_LINEHEIGHT_INDEX (4) 619#define WND_LINEHEIGHT_INDEX (4)
@@ -596,6 +635,8 @@ typedef struct W32Msg {
596 RECT rect; 635 RECT rect;
597} W32Msg; 636} W32Msg;
598 637
638extern BOOL prepend_msg (W32Msg *lpmsg);
639
599/* Structure for recording message when input thread must return a 640/* Structure for recording message when input thread must return a
600 result that depends on lisp thread to compute. Lisp thread can 641 result that depends on lisp thread to compute. Lisp thread can
601 complete deferred messages out of order. */ 642 complete deferred messages out of order. */
@@ -699,3 +740,19 @@ extern HWND w32_system_caret_hwnd;
699extern int w32_system_caret_height; 740extern int w32_system_caret_height;
700extern int w32_system_caret_x; 741extern int w32_system_caret_x;
701extern int w32_system_caret_y; 742extern int w32_system_caret_y;
743
744#if EMACSDEBUG
745extern const char*
746w32_name_of_message (UINT msg);
747#endif /* EMACSDEBUG */
748
749extern void syms_of_w32term (void);
750extern void syms_of_w32menu (void);
751extern void syms_of_w32fns (void);
752
753extern void globals_of_w32menu (void);
754extern void globals_of_w32fns (void);
755
756#ifdef CYGWIN
757extern int w32_message_fd;
758#endif /* CYGWIN */
diff --git a/src/w32xfns.c b/src/w32xfns.c
index 62e45dd987b..dfafb0ac742 100644
--- a/src/w32xfns.c
+++ b/src/w32xfns.c
@@ -20,6 +20,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20#include <signal.h> 20#include <signal.h>
21#include <stdio.h> 21#include <stdio.h>
22#include <setjmp.h> 22#include <setjmp.h>
23
23#include "lisp.h" 24#include "lisp.h"
24#include "keyboard.h" 25#include "keyboard.h"
25#include "frame.h" 26#include "frame.h"
@@ -33,7 +34,11 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
33#define myfree(lp) GlobalFreePtr (lp) 34#define myfree(lp) GlobalFreePtr (lp)
34 35
35CRITICAL_SECTION critsect; 36CRITICAL_SECTION critsect;
37
38#ifdef WINDOWSNT
36extern HANDLE keyboard_handle; 39extern HANDLE keyboard_handle;
40#endif /* WINDOWSNT */
41
37HANDLE input_available = NULL; 42HANDLE input_available = NULL;
38HANDLE interrupt_handle = NULL; 43HANDLE interrupt_handle = NULL;
39 44
@@ -44,7 +49,11 @@ init_crit (void)
44 49
45 /* For safety, input_available should only be reset by get_next_msg 50 /* For safety, input_available should only be reset by get_next_msg
46 when the input queue is empty, so make it a manual reset event. */ 51 when the input queue is empty, so make it a manual reset event. */
47 keyboard_handle = input_available = CreateEvent (NULL, TRUE, FALSE, NULL); 52 input_available = CreateEvent (NULL, TRUE, FALSE, NULL);
53
54#ifdef WINDOWSNT
55 keyboard_handle = input_available;
56#endif /* WINDOWSNT */
48 57
49 /* interrupt_handle is signaled when quit (C-g) is detected, so that 58 /* interrupt_handle is signaled when quit (C-g) is detected, so that
50 blocking system calls can be interrupted. We make it a manual 59 blocking system calls can be interrupted. We make it a manual
@@ -241,6 +250,22 @@ get_next_msg (W32Msg * lpmsg, BOOL bWait)
241 return (bRet); 250 return (bRet);
242} 251}
243 252
253extern char * w32_strerror (int error_no);
254
255/* Tell the main thread that we have input available; if the main
256 thread is blocked in select(), we wake it up here. */
257static void
258notify_msg_ready (void)
259{
260 SetEvent (input_available);
261
262#ifdef CYGWIN
263 /* Wakes up the main thread, which is blocked select()ing for /dev/windows,
264 among other files. */
265 (void) PostThreadMessage (dwMainThreadId, WM_EMACS_INPUT_READY, 0, 0);
266#endif /* CYGWIN */
267}
268
244BOOL 269BOOL
245post_msg (W32Msg * lpmsg) 270post_msg (W32Msg * lpmsg)
246{ 271{
@@ -264,8 +289,7 @@ post_msg (W32Msg * lpmsg)
264 } 289 }
265 290
266 lpTail = lpNew; 291 lpTail = lpNew;
267 SetEvent (input_available); 292 notify_msg_ready ();
268
269 leave_crit (); 293 leave_crit ();
270 294
271 return (TRUE); 295 return (TRUE);
@@ -286,7 +310,7 @@ prepend_msg (W32Msg *lpmsg)
286 nQueue++; 310 nQueue++;
287 lpNew->lpNext = lpHead; 311 lpNew->lpNext = lpHead;
288 lpHead = lpNew; 312 lpHead = lpNew;
289 313 notify_msg_ready ();
290 leave_crit (); 314 leave_crit ();
291 315
292 return (TRUE); 316 return (TRUE);
diff --git a/src/window.c b/src/window.c
index 38124cb13a9..117e86065e3 100644
--- a/src/window.c
+++ b/src/window.c
@@ -44,7 +44,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
44#ifdef HAVE_X_WINDOWS 44#ifdef HAVE_X_WINDOWS
45#include "xterm.h" 45#include "xterm.h"
46#endif /* HAVE_X_WINDOWS */ 46#endif /* HAVE_X_WINDOWS */
47#ifdef WINDOWSNT 47#ifdef HAVE_NTGUI
48#include "w32term.h" 48#include "w32term.h"
49#endif 49#endif
50#ifdef MSDOS 50#ifdef MSDOS
diff --git a/src/xdisp.c b/src/xdisp.c
index 13b03736bde..9b9b91a8905 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
@@ -29361,7 +29361,7 @@ init_xdisp (void)
29361 29361
29362/* Since w32 does not support atimers, it defines its own implementation of 29362/* Since w32 does not support atimers, it defines its own implementation of
29363 the following three functions in w32fns.c. */ 29363 the following three functions in w32fns.c. */
29364#ifndef WINDOWSNT 29364#ifndef HAVE_NTGUI
29365 29365
29366/* Platform-independent portion of hourglass implementation. */ 29366/* Platform-independent portion of hourglass implementation. */
29367 29367
@@ -29407,4 +29407,4 @@ cancel_hourglass (void)
29407 hide_hourglass (); 29407 hide_hourglass ();
29408#endif 29408#endif
29409} 29409}
29410#endif /* ! WINDOWSNT */ 29410#endif /* ! HAVE_NTGUI */
diff --git a/src/xfaces.c b/src/xfaces.c
index 5554c4aa705..67e9c2c37c6 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -228,13 +228,13 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
228#ifdef HAVE_WINDOW_SYSTEM 228#ifdef HAVE_WINDOW_SYSTEM
229#include TERM_HEADER 229#include TERM_HEADER
230#include "fontset.h" 230#include "fontset.h"
231#ifdef WINDOWSNT 231#ifdef HAVE_NTGUI
232#undef FRAME_X_DISPLAY_INFO 232#undef FRAME_X_DISPLAY_INFO
233#define FRAME_X_DISPLAY_INFO FRAME_W32_DISPLAY_INFO 233#define FRAME_X_DISPLAY_INFO FRAME_W32_DISPLAY_INFO
234#define x_display_info w32_display_info 234#define x_display_info w32_display_info
235#define check_x check_w32 235#define check_x check_w32
236#define GCGraphicsExposures 0 236#define GCGraphicsExposures 0
237#endif /* WINDOWSNT */ 237#endif /* HAVE_NTGUI */
238 238
239#ifdef HAVE_NS 239#ifdef HAVE_NS
240#undef FRAME_X_DISPLAY_INFO 240#undef FRAME_X_DISPLAY_INFO
@@ -663,7 +663,7 @@ x_free_gc (struct frame *f, GC gc)
663 663
664#endif /* HAVE_X_WINDOWS */ 664#endif /* HAVE_X_WINDOWS */
665 665
666#ifdef WINDOWSNT 666#ifdef HAVE_NTGUI
667/* W32 emulation of GCs */ 667/* W32 emulation of GCs */
668 668
669static inline GC 669static inline GC
@@ -687,7 +687,7 @@ x_free_gc (struct frame *f, GC gc)
687 xfree (gc); 687 xfree (gc);
688} 688}
689 689
690#endif /* WINDOWSNT */ 690#endif /* HAVE_NTGUI */
691 691
692#ifdef HAVE_NS 692#ifdef HAVE_NS
693/* NS emulation of GCs */ 693/* NS emulation of GCs */
@@ -757,7 +757,7 @@ init_frame_faces (struct frame *f)
757#ifdef HAVE_X_WINDOWS 757#ifdef HAVE_X_WINDOWS
758 if (!FRAME_X_P (f) || FRAME_X_WINDOW (f)) 758 if (!FRAME_X_P (f) || FRAME_X_WINDOW (f))
759#endif 759#endif
760#ifdef WINDOWSNT 760#ifdef HAVE_NTGUI
761 if (!FRAME_WINDOW_P (f) || FRAME_W32_WINDOW (f)) 761 if (!FRAME_WINDOW_P (f) || FRAME_W32_WINDOW (f))
762#endif 762#endif
763#ifdef HAVE_NS 763#ifdef HAVE_NS
@@ -1136,7 +1136,7 @@ defined_color (struct frame *f, const char *color_name, XColor *color_def,
1136 else if (FRAME_X_P (f)) 1136 else if (FRAME_X_P (f))
1137 return x_defined_color (f, color_name, color_def, alloc); 1137 return x_defined_color (f, color_name, color_def, alloc);
1138#endif 1138#endif
1139#ifdef WINDOWSNT 1139#ifdef HAVE_NTGUI
1140 else if (FRAME_W32_P (f)) 1140 else if (FRAME_W32_P (f))
1141 return w32_defined_color (f, color_name, color_def, alloc); 1141 return w32_defined_color (f, color_name, color_def, alloc);
1142#endif 1142#endif
@@ -3283,7 +3283,7 @@ FRAME 0 means change the face on all frames, and change the default
3283 param = Qbackground_color; 3283 param = Qbackground_color;
3284 } 3284 }
3285#ifdef HAVE_WINDOW_SYSTEM 3285#ifdef HAVE_WINDOW_SYSTEM
3286#ifndef WINDOWSNT 3286#ifndef HAVE_NTGUI
3287 else if (EQ (face, Qscroll_bar)) 3287 else if (EQ (face, Qscroll_bar))
3288 { 3288 {
3289 /* Changing the colors of `scroll-bar' sets frame parameters 3289 /* Changing the colors of `scroll-bar' sets frame parameters
@@ -3293,7 +3293,7 @@ FRAME 0 means change the face on all frames, and change the default
3293 else if (EQ (attr, QCbackground)) 3293 else if (EQ (attr, QCbackground))
3294 param = Qscroll_bar_background; 3294 param = Qscroll_bar_background;
3295 } 3295 }
3296#endif /* not WINDOWSNT */ 3296#endif /* not HAVE_NTGUI */
3297 else if (EQ (face, Qborder)) 3297 else if (EQ (face, Qborder))
3298 { 3298 {
3299 /* Changing background color of `border' sets frame parameter 3299 /* Changing background color of `border' sets frame parameter
@@ -6400,7 +6400,7 @@ where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
6400 if (num >= 0 && name[num] == '\n') 6400 if (num >= 0 && name[num] == '\n')
6401 name[num] = 0; 6401 name[num] = 0;
6402 cmap = Fcons (Fcons (build_string (name), 6402 cmap = Fcons (Fcons (build_string (name),
6403#ifdef WINDOWSNT 6403#ifdef HAVE_NTGUI
6404 make_number (RGB (red, green, blue))), 6404 make_number (RGB (red, green, blue))),
6405#else 6405#else
6406 make_number ((red << 16) | (green << 8) | blue)), 6406 make_number ((red << 16) | (green << 8) | blue)),
diff --git a/src/xterm.h b/src/xterm.h
index 2d718f49118..8b8ae2a12f5 100644
--- a/src/xterm.h
+++ b/src/xterm.h
@@ -967,7 +967,6 @@ extern int x_alloc_lighter_color_for_widget (Widget, Display *, Colormap,
967 double, int); 967 double, int);
968#endif 968#endif
969extern int x_alloc_nearest_color (struct frame *, Colormap, XColor *); 969extern int x_alloc_nearest_color (struct frame *, Colormap, XColor *);
970extern void x_query_color (struct frame *f, XColor *);
971extern void x_clear_area (Display *, Window, int, int, int, int, int); 970extern void x_clear_area (Display *, Window, int, int, int, int, int);
972#if defined HAVE_MENUS && !defined USE_X_TOOLKIT && !defined USE_GTK 971#if defined HAVE_MENUS && !defined USE_X_TOOLKIT && !defined USE_GTK
973extern void x_mouse_leave (struct x_display_info *); 972extern void x_mouse_leave (struct x_display_info *);