(xlfd_charset_of_font): Fix last change.
[bpt/emacs.git] / src / w32fns.c
index 45ea7b1..b65be25 100644 (file)
@@ -30,12 +30,12 @@ Boston, MA 02111-1307, USA.  */
 
 #include "lisp.h"
 #include "charset.h"
-#include "fontset.h"
+#include "dispextern.h"
 #include "w32term.h"
 #include "frame.h"
 #include "window.h"
 #include "buffer.h"
-#include "dispextern.h"
+#include "fontset.h"
 #include "intervals.h"
 #include "keyboard.h"
 #include "blockinput.h"
@@ -52,9 +52,10 @@ Boston, MA 02111-1307, USA.  */
 #include <shellapi.h>
 #include <ctype.h>
 
+#define max(a, b) ((a) > (b) ? (a) : (b))
+
 extern void free_frame_menubar ();
 extern double atof ();
-extern struct scroll_bar *x_window_to_scroll_bar ();
 extern int w32_console_toggle_lock_key (int vk_code, Lisp_Object new_state);
 extern int quit_char;
 
@@ -146,26 +147,33 @@ Lisp_Object Vx_resource_name;
 Lisp_Object Vx_no_window_manager;
 
 /* Non-zero means we're allowed to display a busy cursor.  */
+
 int display_busy_cursor_p;
 
 /* The background and shape of the mouse pointer, and shape when not
    over text or in the modeline.  */
+
 Lisp_Object Vx_pointer_shape, Vx_nontext_pointer_shape, Vx_mode_pointer_shape;
-Lisp_Object Vx_busy_pointer_shape;
+Lisp_Object Vx_busy_pointer_shape, Vx_window_horizontal_drag_shape;
 
 /* The shape when over mouse-sensitive text.  */
+
 Lisp_Object Vx_sensitive_text_pointer_shape;
 
 /* Color of chars displayed in cursor box.  */
+
 Lisp_Object Vx_cursor_fore_pixel;
 
 /* Nonzero if using Windows.  */
+
 static int w32_in_use;
 
 /* Search path for bitmap files.  */
+
 Lisp_Object Vx_bitmap_file_path;
 
 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.  */
+
 Lisp_Object Vx_pixel_size_width_font_regexp;
 
 /* Alist of bdf fonts and the files that define them.  */
@@ -180,6 +188,15 @@ int w32_strict_fontnames;
    indicates there is an update region.  */
 int w32_strict_painting;
 
+/* Associative list linking character set strings to Windows codepages. */
+Lisp_Object Vw32_charset_info_alist;
+
+/* VIETNAMESE_CHARSET is not defined in some versions of MSVC.  */
+#ifndef VIETNAMESE_CHARSET
+#define VIETNAMESE_CHARSET 163
+#endif
+
+
 /* Evaluate this expression to rebuild the section of syms_of_w32fns
    that initializes and staticpros the symbols declared below.  Note
    that Emacs 18 has a bug that keeps C-x C-e from being able to
@@ -245,6 +262,8 @@ Lisp_Object Qx_resource_name;
 Lisp_Object Quser_position;
 Lisp_Object Quser_size;
 Lisp_Object Qscreen_gamma;
+Lisp_Object Qline_spacing;
+Lisp_Object Qcenter;
 Lisp_Object Qhyper;
 Lisp_Object Qsuper;
 Lisp_Object Qmeta;
@@ -253,6 +272,36 @@ Lisp_Object Qctrl;
 Lisp_Object Qcontrol;
 Lisp_Object Qshift;
 
+Lisp_Object Qw32_charset_ansi;
+Lisp_Object Qw32_charset_default;
+Lisp_Object Qw32_charset_symbol;
+Lisp_Object Qw32_charset_shiftjis;
+Lisp_Object Qw32_charset_hangeul;
+Lisp_Object Qw32_charset_gb2312;
+Lisp_Object Qw32_charset_chinesebig5;
+Lisp_Object Qw32_charset_oem;
+
+#ifndef JOHAB_CHARSET
+#define JOHAB_CHARSET 130
+#endif
+#ifdef JOHAB_CHARSET
+Lisp_Object Qw32_charset_easteurope;
+Lisp_Object Qw32_charset_turkish;
+Lisp_Object Qw32_charset_baltic;
+Lisp_Object Qw32_charset_russian;
+Lisp_Object Qw32_charset_arabic;
+Lisp_Object Qw32_charset_greek;
+Lisp_Object Qw32_charset_hebrew;
+Lisp_Object Qw32_charset_vietnamese;
+Lisp_Object Qw32_charset_thai;
+Lisp_Object Qw32_charset_johab;
+Lisp_Object Qw32_charset_mac;
+#endif
+
+#ifdef UNICODE_CHARSET
+Lisp_Object Qw32_charset_unicode;
+#endif
+
 extern Lisp_Object Qtop;
 extern Lisp_Object Qdisplay;
 extern Lisp_Object Qtool_bar_lines;
@@ -275,6 +324,7 @@ unsigned int msh_mousewheel = 0;
 #define MOUSE_MOVE_ID  2
 
 /* The below are defined in frame.c.  */
+
 extern Lisp_Object Qheight, Qminibuffer, Qname, Qonly, Qwidth;
 extern Lisp_Object Qunsplittable, Qmenu_bar_lines, Qbuffer_predicate, Qtitle;
 extern Lisp_Object Qtool_bar_lines;
@@ -283,9 +333,6 @@ extern Lisp_Object Vwindow_system_version;
 
 Lisp_Object Qface_set_after_frame_default;
 
-extern Lisp_Object last_mouse_scroll_bar;
-extern int last_mouse_scroll_bar_pos;
-
 /* From w32term.c. */
 extern Lisp_Object Vw32_num_mouse_buttons;
 extern Lisp_Object Vw32_recognize_altgr;
@@ -378,6 +425,10 @@ x_window_to_frame (dpyinfo, wdesc)
       f = XFRAME (frame);
       if (!FRAME_W32_P (f) || FRAME_W32_DISPLAY_INFO (f) != dpyinfo)
        continue;
+      if (f->output_data.w32->busy_window == wdesc)
+        return f;
+
+      /* TODO: Check tooltips when supported.  */
       if (FRAME_W32_WINDOW (f) == wdesc)
         return f;
     }
@@ -507,7 +558,7 @@ x_create_bitmap_from_file (f, file)
      Lisp_Object file;
 {
   return -1;
-#if 0 /* NTEMACS_TODO : bitmap support */
+#if 0 /* TODO : bitmap support */
   struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f);
   unsigned int width, height;
   HBITMAP bitmap;
@@ -533,9 +584,6 @@ x_create_bitmap_from_file (f, file)
   fd = openp (Vx_bitmap_file_path, file, "", &found, 0);
   if (fd < 0)
     return -1;
-  /* LoadLibraryEx won't handle special files handled by Emacs handler.  */
-  if (fd == 0)
-    return -1;
   emacs_close (fd);
 
   filename = (char *) XSTRING (found)->data;
@@ -561,7 +609,7 @@ x_create_bitmap_from_file (f, file)
   strcpy (dpyinfo->bitmaps[id - 1].file, XSTRING (file)->data);
 
   return id;
-#endif  /* NTEMACS_TODO */
+#endif  /* TODO */
 }
 
 /* Remove reference to bitmap with id number ID.  */
@@ -640,8 +688,9 @@ struct x_frame_parm_table
   void (*setter) P_ ((struct frame *, Lisp_Object, Lisp_Object));
 };
 
-/* NTEMACS_TODO: Native Input Method support; see x_create_im.  */
+/* TODO: Native Input Method support; see x_create_im.  */
 void x_set_foreground_color P_ ((struct frame *, Lisp_Object, Lisp_Object));
+static void x_set_line_spacing P_ ((struct frame *, Lisp_Object, Lisp_Object));
 void x_set_background_color P_ ((struct frame *, Lisp_Object, Lisp_Object));
 void x_set_mouse_color P_ ((struct frame *, Lisp_Object, Lisp_Object));
 void x_set_cursor_color P_ ((struct frame *, Lisp_Object, Lisp_Object));
@@ -689,12 +738,14 @@ static struct x_frame_parm_table x_frame_parms[] =
   "vertical-scroll-bars", x_set_vertical_scroll_bars,
   "visibility", x_set_visibility,
   "tool-bar-lines", x_set_tool_bar_lines,
-  "screen-gamma", x_set_screen_gamma
+  "screen-gamma", x_set_screen_gamma,
+  "line-spacing", x_set_line_spacing
 };
 
 /* Attach the `x-frame-parameter' properties to
    the Lisp symbol names of parameters relevant to W32.  */
 
+void
 init_x_parm_symbols ()
 {
   int i;
@@ -704,7 +755,7 @@ init_x_parm_symbols ()
          make_number (i));
 }
 \f
-/* Change the parameters of FRAME as specified by ALIST.
+/* Change the parameters of frame F as specified by ALIST.
    If a parameter is not specially recognized, do nothing;
    otherwise call the `x_set_...' function for that parameter.  */
 
@@ -754,7 +805,6 @@ x_set_frame_parameters (f, alist)
       values[i] = Fcdr (elt);
       i++;
     }
-
   /* TAIL and ALIST are not used again below here.  */
   alist = tail = Qnil;
 
@@ -768,8 +818,15 @@ x_set_frame_parameters (f, alist)
   icon_left = icon_top = Qunbound;
 
   /* Provide default values for HEIGHT and WIDTH.  */
-  width = FRAME_WIDTH (f);
-  height = FRAME_HEIGHT (f);
+  if (FRAME_NEW_WIDTH (f))
+    width = FRAME_NEW_WIDTH (f);
+  else
+    width = FRAME_WIDTH (f);
+
+  if (FRAME_NEW_HEIGHT (f))
+    height = FRAME_NEW_HEIGHT (f);
+  else
+    height = FRAME_HEIGHT (f);
 
   /* Process foreground_color and background_color before anything else.
      They are independent of other properties, but other properties (e.g.,
@@ -880,8 +937,9 @@ x_set_frame_parameters (f, alist)
 
     XSETFRAME (frame, f);
 
-    if (XINT (width) != FRAME_WIDTH (f)
-       || XINT (height) != FRAME_HEIGHT (f))
+    if (width != FRAME_WIDTH (f)
+       || height != FRAME_HEIGHT (f)
+       || FRAME_NEW_HEIGHT (f) || FRAME_NEW_WIDTH (f))
       Fset_frame_size (frame, make_number (width), make_number (height));
 
     if ((!NILP (left) || !NILP (top))
@@ -990,6 +1048,7 @@ x_real_positions (f, xptr, yptr)
    and whose values are not correctly recorded in the frame's
    param_alist need to be considered here.  */
 
+void
 x_report_frame_params (f, alistptr)
      struct frame *f;
      Lisp_Object *alistptr;
@@ -1870,6 +1929,26 @@ x_decode_color (f, arg, def)
   return def;
 }
 \f
+/* Change the `line-spacing' frame parameter of frame F.  OLD_VALUE is
+   the previous value of that parameter, NEW_VALUE is the new value.  */
+
+static void
+x_set_line_spacing (f, new_value, old_value)
+     struct frame *f;
+     Lisp_Object new_value, old_value;
+{
+  if (NILP (new_value))
+    f->extra_line_spacing = 0;
+  else if (NATNUMP (new_value))
+    f->extra_line_spacing = XFASTINT (new_value);
+  else
+    Fsignal (Qerror, Fcons (build_string ("Invalid line-spacing"),
+                           Fcons (new_value, Qnil)));
+  if (FRAME_VISIBLE_P (f))
+    redraw_frame (f);
+}
+
+
 /* Change the `screen-gamma' frame parameter of frame F.  OLD_VALUE is
    the previous value of that parameter, NEW_VALUE is the new value.  */
 
@@ -1884,7 +1963,7 @@ x_set_screen_gamma (f, new_value, old_value)
     /* The value 0.4545 is the normal viewing gamma.  */
     f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
   else
-    Fsignal (Qerror, Fcons (build_string ("Illegal screen-gamma"),
+    Fsignal (Qerror, Fcons (build_string ("Invalid screen-gamma"),
                            Fcons (new_value, Qnil)));
 
   clear_face_cache (0);
@@ -1940,7 +2019,6 @@ x_set_mouse_color (f, arg, oldval)
      struct frame *f;
      Lisp_Object arg, oldval;
 {
-
   Cursor cursor, nontext_cursor, mode_cursor, cross_cursor;
   int count;
   int mask_color;
@@ -1955,7 +2033,7 @@ x_set_mouse_color (f, arg, oldval)
        && mask_color == FRAME_BACKGROUND_PIXEL (f))
     f->output_data.w32->mouse_pixel = FRAME_FOREGROUND_PIXEL (f);
 
-#if 0 /* NTEMACS_TODO : cursor changes */
+#if 0 /* TODO : cursor changes */
   BLOCK_INPUT;
 
   /* It's not okay to crash if the user selects a screwy cursor.  */
@@ -2011,6 +2089,17 @@ x_set_mouse_color (f, arg, oldval)
   else
     cross_cursor = XCreateFontCursor (FRAME_W32_DISPLAY (f), XC_crosshair);
 
+  if (!NILP (Vx_window_horizontal_drag_shape))
+    {
+      CHECK_NUMBER (Vx_window_horizontal_drag_shape, 0);
+      horizontal_drag_cursor
+       = XCreateFontCursor (FRAME_X_DISPLAY (f),
+                            XINT (Vx_window_horizontal_drag_shape));
+    }
+  else
+    horizontal_drag_cursor
+      = XCreateFontCursor (FRAME_X_DISPLAY (f), XC_sb_h_double_arrow);
+
   /* Check and report errors with the above calls.  */
   x_check_errors (FRAME_W32_DISPLAY (f), "can't set cursor shape: %s");
   x_uncatch_errors (FRAME_W32_DISPLAY (f), count);
@@ -2071,38 +2160,44 @@ x_set_mouse_color (f, arg, oldval)
   UNBLOCK_INPUT;
 
   update_face_from_frame_parameter (f, Qmouse_color, arg);
-#endif /* NTEMACS_TODO */
+#endif /* TODO */
 }
 
+/* Defined in w32term.c. */
+void x_update_cursor (struct frame *f, int on_p);
+
 void
 x_set_cursor_color (f, arg, oldval)
      struct frame *f;
      Lisp_Object arg, oldval;
 {
-  unsigned long fore_pixel;
+  unsigned long fore_pixel, pixel;
 
-  if (!EQ (Vx_cursor_fore_pixel, Qnil))
+  if (!NILP (Vx_cursor_fore_pixel))
     fore_pixel = x_decode_color (f, Vx_cursor_fore_pixel,
-                                WHITE_PIX_DEFAULT (f));
+                                 WHITE_PIX_DEFAULT (f));
   else
     fore_pixel = FRAME_BACKGROUND_PIXEL (f);
-  f->output_data.w32->cursor_pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
+
+  pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
   
   /* Make sure that the cursor color differs from the background color.  */
-  if (f->output_data.w32->cursor_pixel == FRAME_BACKGROUND_PIXEL (f))
+  if (pixel == FRAME_BACKGROUND_PIXEL (f))
     {
-      f->output_data.w32->cursor_pixel = f->output_data.w32->mouse_pixel;
-      if (f->output_data.w32->cursor_pixel == fore_pixel)
+      pixel = f->output_data.w32->mouse_pixel;
+      if (pixel == fore_pixel)
        fore_pixel = FRAME_BACKGROUND_PIXEL (f);
     }
+
   FRAME_FOREGROUND_PIXEL (f) = fore_pixel;
+  f->output_data.w32->cursor_pixel = pixel;
 
   if (FRAME_W32_WINDOW (f) != 0)
     {
       if (FRAME_VISIBLE_P (f))
        {
-         x_display_cursor (f, 0);
-         x_display_cursor (f, 1);
+         x_update_cursor (f, 0);
+         x_update_cursor (f, 1);
        }
     }
 
@@ -2145,33 +2240,56 @@ x_set_border_color (f, arg, oldval)
   update_face_from_frame_parameter (f, Qborder_color, arg);
 }
 
-void
-x_set_cursor_type (f, arg, oldval)
-     FRAME_PTR f;
-     Lisp_Object arg, oldval;
+/* Value is the internal representation of the specified cursor type
+   ARG.  If type is BAR_CURSOR, return in *WIDTH the specified width
+   of the bar cursor.  */
+
+enum text_cursor_kinds
+x_specified_cursor_type (arg, width)
+     Lisp_Object arg;
+     int *width;
 {
+  enum text_cursor_kinds type;
+  
   if (EQ (arg, Qbar))
     {
-      FRAME_DESIRED_CURSOR (f) = BAR_CURSOR;
-      f->output_data.w32->cursor_width = 2;
+      type = BAR_CURSOR;
+      *width = 2;
     }
-  else if (CONSP (arg) && EQ (XCAR (arg), Qbar)
-          && INTEGERP (XCDR (arg)))
+  else if (CONSP (arg)
+          && EQ (XCAR (arg), Qbar)
+          && INTEGERP (XCDR (arg))
+          && XINT (XCDR (arg)) >= 0)
     {
-      FRAME_DESIRED_CURSOR (f) = BAR_CURSOR;
-      f->output_data.w32->cursor_width = XINT (XCDR (arg));
+      type = BAR_CURSOR;
+      *width = XINT (XCDR (arg));
     }
+  else if (NILP (arg))
+    type = NO_CURSOR;
   else
     /* Treat anything unknown as "box cursor".
        It was bad to signal an error; people have trouble fixing
        .Xdefaults with Emacs, when it has something bad in it.  */
-    FRAME_DESIRED_CURSOR (f) = FILLED_BOX_CURSOR;
+    type = FILLED_BOX_CURSOR;
+
+  return type;
+}
+
+void
+x_set_cursor_type (f, arg, oldval)
+     FRAME_PTR f;
+     Lisp_Object arg, oldval;
+{
+  int width;
+  
+  FRAME_DESIRED_CURSOR (f) = x_specified_cursor_type (arg, &width);
+  f->output_data.w32->cursor_width = width;
 
   /* Make sure the cursor gets redrawn.  This is overkill, but how
      often do people change cursor types?  */
   update_mode_lines++;
 }
-
+\f
 void
 x_set_icon_type (f, arg, oldval)
      struct frame *f;
@@ -2290,9 +2408,9 @@ x_set_font (f, arg, oldval)
   UNBLOCK_INPUT;
   
   if (EQ (result, Qnil))
-    error ("Font \"%s\" is not defined", XSTRING (arg)->data);
+    error ("Font `%s' is not defined", XSTRING (arg)->data);
   else if (EQ (result, Qt))
-    error ("the characters of the given font have varying widths");
+    error ("The characters of the given font have varying widths");
   else if (STRINGP (result))
     {
       store_frame_param (f, Qfont, result);
@@ -2370,6 +2488,36 @@ x_set_visibility (f, value, oldval)
     Fmake_frame_visible (frame);
 }
 
+\f
+/* Change window heights in windows rooted in WINDOW by N lines.  */
+
+static void
+x_change_window_heights (window, n)
+  Lisp_Object window;
+  int n;
+{
+  struct window *w = XWINDOW (window);
+
+  XSETFASTINT (w->top, XFASTINT (w->top) + n);
+  XSETFASTINT (w->height, XFASTINT (w->height) - n);
+
+  if (INTEGERP (w->orig_top))
+    XSETFASTINT (w->orig_top, XFASTINT (w->orig_top) + n);
+  if (INTEGERP (w->orig_height))
+    XSETFASTINT (w->orig_height, XFASTINT (w->orig_height) - n);
+
+  /* Handle just the top child in a vertical split.  */
+  if (!NILP (w->vchild))
+    x_change_window_heights (w->vchild, n);
+
+  /* Adjust all children in a horizontal split.  */
+  for (window = w->hchild; !NILP (window); window = w->next)
+    {
+      w = XWINDOW (window);
+      x_change_window_heights (window, n);
+    }
+}
+
 void
 x_set_menu_bar_lines (f, value, oldval)
      struct frame *f;
@@ -2420,7 +2568,8 @@ x_set_tool_bar_lines (f, value, oldval)
      struct frame *f;
      Lisp_Object value, oldval;
 {
-  int delta, nlines;
+  int delta, nlines, root_height;
+  Lisp_Object root_window;
 
   /* Use VALUE only if an integer >= 0.  */
   if (INTEGERP (value) && XINT (value) >= 0)
@@ -2432,10 +2581,51 @@ x_set_tool_bar_lines (f, value, oldval)
   ++windows_or_buffers_changed;
 
   delta = nlines - FRAME_TOOL_BAR_LINES (f);
+
+  /* Don't resize the tool-bar to more than we have room for.  */
+  root_window = FRAME_ROOT_WINDOW (f);
+  root_height = XINT (XWINDOW (root_window)->height);
+  if (root_height - delta < 1)
+    {
+      delta = root_height - 1;
+      nlines = FRAME_TOOL_BAR_LINES (f) + delta;
+    }
+
   FRAME_TOOL_BAR_LINES (f) = nlines;
-  x_set_window_size (f, 0, FRAME_WIDTH (f), FRAME_HEIGHT (f));
-  do_pending_window_change (0);
+  x_change_window_heights (root_window, delta);
   adjust_glyphs (f);
+
+  /* We also have to make sure that the internal border at the top of
+     the frame, below the menu bar or tool bar, is redrawn when the
+     tool bar disappears.  This is so because the internal border is
+     below the tool bar if one is displayed, but is below the menu bar
+     if there isn't a tool bar.  The tool bar draws into the area
+     below the menu bar.  */
+  if (FRAME_W32_WINDOW (f) && FRAME_TOOL_BAR_LINES (f) == 0)
+    {
+      updating_frame = f;
+      clear_frame ();
+      clear_current_matrices (f);
+      updating_frame = NULL;
+    }
+
+  /* If the tool bar gets smaller, the internal border below it
+     has to be cleared.  It was formerly part of the display
+     of the larger tool bar, and updating windows won't clear it.  */
+  if (delta < 0)
+    {
+      int height = FRAME_INTERNAL_BORDER_WIDTH (f);
+      int width = PIXEL_WIDTH (f);
+      int y = nlines * CANON_Y_UNIT (f);
+
+      BLOCK_INPUT;
+      {
+        HDC hdc = get_frame_dc (f);
+        w32_clear_area (f, hdc, 0, y, width, height);
+        release_frame_dc (f, hdc);
+      }
+      UNBLOCK_INPUT;
+    }
 }
 
 
@@ -2497,7 +2687,7 @@ x_set_name (f, name, explicit)
   if (FRAME_W32_WINDOW (f))
     {
       if (STRING_MULTIBYTE (name))
-       name = string_make_unibyte (name);
+       name = ENCODE_SYSTEM (name);
 
       BLOCK_INPUT;
       SetWindowText(FRAME_W32_WINDOW (f), XSTRING (name)->data);
@@ -2557,7 +2747,7 @@ x_set_title (f, name, old_name)
   if (FRAME_W32_WINDOW (f))
     {
       if (STRING_MULTIBYTE (name))
-       name = string_make_unibyte (name);
+       name = ENCODE_SYSTEM (name);
 
       BLOCK_INPUT;
       SetWindowText(FRAME_W32_WINDOW (f), XSTRING (name)->data);
@@ -2669,7 +2859,7 @@ validate_x_resource_name ()
       unsigned char *p = XSTRING (Vx_resource_name)->data;
       int i;
 
-      len = XSTRING (Vx_resource_name)->size;
+      len = STRING_BYTES (XSTRING (Vx_resource_name));
 
       /* Only letters, digits, - and _ are valid in resource names.
         Count the valid characters and count the invalid ones.  */
@@ -2751,16 +2941,16 @@ and the class is `Emacs.CLASS.SUBCLASS'.")
 
   /* Allocate space for the components, the dots which separate them,
      and the final '\0'.  Make them big enough for the worst case.  */
-  name_key = (char *) alloca (XSTRING (Vx_resource_name)->size
+  name_key = (char *) alloca (STRING_BYTES (XSTRING (Vx_resource_name))
                              + (STRINGP (component)
-                                ? XSTRING (component)->size : 0)
-                             + XSTRING (attribute)->size
+                                ? STRING_BYTES (XSTRING (component)) : 0)
+                             + STRING_BYTES (XSTRING (attribute))
                              + 3);
 
   class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1)
-                              + XSTRING (class)->size
+                              + STRING_BYTES (XSTRING (class))
                               + (STRINGP (subclass)
-                                 ? XSTRING (subclass)->size : 0)
+                                 ? STRING_BYTES (XSTRING (subclass)) : 0)
                               + 3);
 
   /* Start with emacs.FRAMENAME for the name (the specific one)
@@ -2804,7 +2994,7 @@ x_get_resource_string (attribute, class)
 
   /* Allocate space for the components, the dots which separate them,
      and the final '\0'.  */
-  name_key = (char *) alloca (XSTRING (Vinvocation_name)->size
+  name_key = (char *) alloca (STRING_BYTES (XSTRING (Vinvocation_name))
                              + strlen (attribute) + 2);
   class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1)
                               + strlen (class) + 2);
@@ -2908,8 +3098,8 @@ w32_get_arg (alist, param, attribute, class, type)
 }
 
 /* Record in frame F the specified or default value according to ALIST
-   of the parameter named PARAM (a Lisp symbol).
-   If no value is specified for PARAM, look for an X default for XPROP
+   of the parameter named PROP (a Lisp symbol).
+   If no value is specified for PROP, look for an X default for XPROP
    on the frame named NAME.
    If that is not found either, use the value DEFLT.  */
 
@@ -4467,6 +4657,11 @@ w32_wnd_proc (hwnd, msg, wParam, lParam)
        f->output_data.w32->menubar_active = 0;
       goto dflt;
 
+    case WM_MENUSELECT:
+      wmsg.dwModifiers = w32_get_modifiers ();
+      my_post_msg (&wmsg, hwnd, msg, wParam, lParam);
+      return 0;
+
     case WM_MEASUREITEM:
       f = x_window_to_frame (dpyinfo, hwnd);
       if (f)
@@ -4488,11 +4683,16 @@ w32_wnd_proc (hwnd, msg, wParam, lParam)
              menu_font = CreateFontIndirect (&menu_logfont);
              old_font = SelectObject (hdc, menu_font);
 
-             GetTextExtentPoint32 (hdc, title, strlen (title), &size);
-             pMis->itemWidth = size.cx;
-             pMis->itemHeight = GetSystemMetrics (SM_CYMENUSIZE);
-             if (pMis->itemHeight < size.cy)
-               pMis->itemHeight = size.cy;
+              pMis->itemHeight = GetSystemMetrics (SM_CYMENUSIZE);
+              if (title)
+                {
+                  GetTextExtentPoint32 (hdc, title, strlen (title), &size);
+                  pMis->itemWidth = size.cx;
+                  if (pMis->itemHeight < size.cy)
+                    pMis->itemHeight = size.cy;
+                }
+              else
+                pMis->itemWidth = 0;
 
              SelectObject (hdc, old_font);
              DeleteObject (menu_font);
@@ -4512,25 +4712,29 @@ w32_wnd_proc (hwnd, msg, wParam, lParam)
            {
              /* Draw popup menu title. */
              char * title = (char *) pDis->itemData;
-             HDC hdc = pDis->hDC;
-             HFONT menu_font = GetCurrentObject (hdc, OBJ_FONT);
-             LOGFONT menu_logfont;
-             HFONT old_font;
-
-             GetObject (menu_font, sizeof (menu_logfont), &menu_logfont);
-             menu_logfont.lfWeight = FW_BOLD;
-             menu_font = CreateFontIndirect (&menu_logfont);
-             old_font = SelectObject (hdc, menu_font);
-
-             /* Always draw title as if not selected.  */
-             ExtTextOut (hdc,
-                         pDis->rcItem.left + GetSystemMetrics (SM_CXMENUCHECK),
-                         pDis->rcItem.top,
-                         ETO_OPAQUE, &pDis->rcItem,
-                         title, strlen (title), NULL);
-
-             SelectObject (hdc, old_font);
-             DeleteObject (menu_font);
+              if (title)
+                {
+                  HDC hdc = pDis->hDC;
+                  HFONT menu_font = GetCurrentObject (hdc, OBJ_FONT);
+                  LOGFONT menu_logfont;
+                  HFONT old_font;
+
+                  GetObject (menu_font, sizeof (menu_logfont), &menu_logfont);
+                  menu_logfont.lfWeight = FW_BOLD;
+                  menu_font = CreateFontIndirect (&menu_logfont);
+                  old_font = SelectObject (hdc, menu_font);
+
+                  /* Always draw title as if not selected.  */
+                  ExtTextOut (hdc,
+                              pDis->rcItem.left
+                              + GetSystemMetrics (SM_CXMENUCHECK),
+                              pDis->rcItem.top,
+                              ETO_OPAQUE, &pDis->rcItem,
+                              title, strlen (title), NULL);
+
+                  SelectObject (hdc, old_font);
+                  DeleteObject (menu_font);
+                }
              return TRUE;
            }
        }
@@ -4969,7 +5173,8 @@ This function is an internal primitive--use `make-frame' instead.")
      it to make_frame_without_minibuffer.  */
   frame = Qnil;
   GCPRO4 (parms, parent, name, frame);
-  tem = w32_get_arg (parms, Qminibuffer, 0, 0, RES_TYPE_SYMBOL);
+  tem = w32_get_arg (parms, Qminibuffer, "minibuffer", "Minibuffer",
+                     RES_TYPE_SYMBOL);
   if (EQ (tem, Qnone) || NILP (tem))
     f = make_frame_without_minibuffer (Qnil, kb, display);
   else if (EQ (tem, Qonly))
@@ -5010,7 +5215,7 @@ This function is an internal primitive--use `make-frame' instead.")
 
   if (!NILP (parent))
     {
-      f->output_data.w32->parent_desc = (Window) parent;
+      f->output_data.w32->parent_desc = (Window) XFASTINT (parent);
       f->output_data.w32->explicit_parent = 1;
     }
   else
@@ -5034,10 +5239,6 @@ This function is an internal primitive--use `make-frame' instead.")
       specbind (Qx_resource_name, name);
     }
 
-  /* Create fontsets from `global_fontset_alist' before handling fonts.  */
-  for (tem = Vglobal_fontset_alist; CONSP (tem); tem = XCDR (tem))
-    fs_register_fontset (f, XCAR (tem));
-
   /* Extract the window parameters from the supplied values
      that are needed to determine window geometry.  */
   {
@@ -5057,7 +5258,7 @@ This function is an internal primitive--use `make-frame' instead.")
       }
     /* Try out a font which we hope has bold and italic variations.  */
     if (!STRINGP (font))
-      font = x_new_font (f, "-*-Courier New-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
+      font = x_new_font (f, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
     if (! STRINGP (font))
       font = x_new_font (f, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
     /* If those didn't work, look for something which will at least work.  */
@@ -5072,7 +5273,7 @@ This function is an internal primitive--use `make-frame' instead.")
   }
 
   x_default_parameter (f, parms, Qborder_width, make_number (2),
-                      "borderwidth", "BorderWidth", RES_TYPE_NUMBER);
+                      "borderWidth", "BorderWidth", RES_TYPE_NUMBER);
   /* This defaults to 2 in order to match xterm.  We recognize either
      internalBorderWidth or internalBorder (which is what xterm calls
      it).  */
@@ -5081,16 +5282,16 @@ This function is an internal primitive--use `make-frame' instead.")
       Lisp_Object value;
 
       value = w32_get_arg (parms, Qinternal_border_width,
-                        "internalBorder", "BorderWidth", RES_TYPE_NUMBER);
+                        "internalBorder", "InternalBorder", RES_TYPE_NUMBER);
       if (! EQ (value, Qunbound))
        parms = Fcons (Fcons (Qinternal_border_width, value),
                       parms);
     }
   /* Default internalBorderWidth to 0 on Windows to match other programs.  */
   x_default_parameter (f, parms, Qinternal_border_width, make_number (0),
-                      "internalBorderWidth", "BorderWidth", RES_TYPE_NUMBER);
-  x_default_parameter (f, parms, Qvertical_scroll_bars, Qt,
-                      "verticalScrollBars", "ScrollBars", RES_TYPE_BOOLEAN);
+                      "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER);
+  x_default_parameter (f, parms, Qvertical_scroll_bars, Qright,
+                      "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL);
 
   /* Also do the stuff which must be set before the window exists.  */
   x_default_parameter (f, parms, Qforeground_color, build_string ("black"),
@@ -5105,6 +5306,8 @@ This function is an internal primitive--use `make-frame' instead.")
                       "borderColor", "BorderColor", RES_TYPE_STRING);
   x_default_parameter (f, parms, Qscreen_gamma, Qnil,
                       "screenGamma", "ScreenGamma", RES_TYPE_FLOAT);
+  x_default_parameter (f, parms, Qline_spacing, Qnil,
+                      "lineSpacing", "LineSpacing", RES_TYPE_NUMBER);
 
 
   /* Init faces before x_default_parameter is called for scroll-bar
@@ -5187,9 +5390,6 @@ This function is an internal primitive--use `make-frame' instead.")
   SET_FRAME_WIDTH (f, 0);
   change_frame_size (f, height, width, 1, 0, 0);
 
-  /* Set up faces after all frame parameters are known.  */
-  call1 (Qface_set_after_frame_default, frame);
-
   /* Tell the server what size and position, etc, we want, and how
      badly we want them.  This should be done after we have the menu
      bar so that its size can be taken into account.  */
@@ -5197,6 +5397,13 @@ This function is an internal primitive--use `make-frame' instead.")
   x_wm_set_size_hint (f, window_prompting, 0);
   UNBLOCK_INPUT;
 
+  /* Set up faces after all frame parameters are known.  This call
+     also merges in face attributes specified for new frames.  If we
+     don't do this, the `menu' face for instance won't have the right
+     colors, and the menu bar won't appear in the specified colors for
+     new frames.  */
+  call1 (Qface_set_after_frame_default, frame);
+
   /* Make the window appear on the frame and enable display, unless
      the caller says not to.  However, with explicit parent, Emacs
      cannot control visibility, so don't try.  */
@@ -5246,8 +5453,28 @@ DEFUN ("w32-focus-frame", Fw32_focus_frame, Sw32_focus_frame, 1, 1, 0,
 }
 
 \f
+/* Return the charset portion of a font name.  */
+char * xlfd_charset_of_font (char * fontname)
+{
+  char *charset, *encoding;
+
+  encoding = strrchr(fontname, '-');
+  if (!encoding || encoding == fontname)
+    return NULL;
+
+  for (charset = encoding - 1; charset >= fontname; charset--)
+    if (*charset == '-')
+      break;
+
+  if (charset == fontname || strcmp(charset, "-*-*") == 0)
+    return NULL;
+
+  return charset + 1;
+}
+
 struct font_info *w32_load_bdf_font (struct frame *f, char *fontname,
                                      int size, char* filename);
+BOOL w32_to_x_font (LOGFONT * lplf, char * lpxstr, int len, char * charset);
 
 struct font_info *
 w32_load_system_font (f,fontname,size)
@@ -5297,7 +5524,7 @@ w32_load_system_font (f,fontname,size)
 
   /* Load the font and add it to the table. */
   {
-    char *full_name, *encoding;
+    char *full_name, *encoding, *charset;
     XFontStruct *font;
     struct font_info *fontp;
     LOGFONT lf;
@@ -5316,6 +5543,7 @@ w32_load_system_font (f,fontname,size)
       return NULL;
 
     font = (XFontStruct *) xmalloc (sizeof (XFontStruct));
+    bzero (font, sizeof (*font));
 
     /* Set bdf to NULL to indicate that this is a Windows font.  */
     font->bdf = NULL;
@@ -5332,10 +5560,17 @@ w32_load_system_font (f,fontname,size)
       {
        HDC hdc;
        HANDLE oldobj;
+        int codepage = w32_codepage_for_font (fontname);
 
        hdc = GetDC (dpyinfo->root_window);
        oldobj = SelectObject (hdc, font->hfont);
+
        ok = GetTextMetrics (hdc, &font->tm);
+        if (codepage == CP_UNICODE)
+          font->double_byte_p = 1;
+        else
+          font->double_byte_p = GetFontLanguageInfo(hdc) & GCP_DBCS;
+
        SelectObject (hdc, oldobj);
        ReleaseDC (dpyinfo->root_window, hdc);
         /* Fill out details in lf according to the font that was
@@ -5349,6 +5584,8 @@ w32_load_system_font (f,fontname,size)
                                ? VARIABLE_PITCH : FIXED_PITCH);
         lf.lfOutPrecision = ((font->tm.tmPitchAndFamily & TMPF_VECTOR)
                              ? OUT_STROKE_PRECIS : OUT_STRING_PRECIS);
+
+       w32_cache_char_metrics (font);
       }
 
     UNBLOCK_INPUT;
@@ -5386,9 +5623,11 @@ w32_load_system_font (f,fontname,size)
     fontp->name = (char *) xmalloc (strlen (fontname) + 1);
     bcopy (fontname, fontp->name, strlen (fontname) + 1);
 
+    charset = xlfd_charset_of_font (fontname);
+
     /* Work out the font's full name.  */
     full_name = (char *)xmalloc (100);
-    if (full_name && w32_to_x_font (&lf, full_name, 100))
+    if (full_name && w32_to_x_font (&lf, full_name, 100, charset))
         fontp->full_name = full_name;
     else
       {
@@ -5402,9 +5641,9 @@ w32_load_system_font (f,fontname,size)
 
     /* The slot `encoding' specifies how to map a character
        code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
-       the font code-points (0:0x20..0x7F, 1:0xA0..0xFF, 0:0x2020..0x7F7F,
-       the font code-points (0:0x20..0x7F, 1:0xA0..0xFF,
-       0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF, or
+       the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
+       (0:0x20..0x7F, 1:0xA0..0xFF,
+       (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
        2:0xA020..0xFF7F).  For the moment, we don't know which charset
        uses this font.  So, we set information in fontp->encoding[1]
        which is never used by any charset.  If mapping can't be
@@ -5477,6 +5716,7 @@ w32_unload_font (dpyinfo, font)
 {
   if (font) 
     {
+      if (font->per_char) xfree (font->per_char);
       if (font->bdf) w32_free_bdf_font (font->bdf);
 
       if (font->hfont) DeleteObject(font->hfont);
@@ -5505,58 +5745,7 @@ w32_unload_font (dpyinfo, font)
  *      (registry      "[^-]+")
  *      (encoding      "[^-]+")
  *      )
- *  (setq x-font-regexp
- *     (concat "\\`\\*?[-?*]"
- *             foundry - family - weight\? - slant\? - swidth - adstyle -
- *             pixelsize - pointsize - resx - resy - spacing - registry -
- *             encoding "[-?*]\\*?\\'"
- *             ))
- *  (setq x-font-regexp-head
- *     (concat "\\`[-?*]" foundry - family - weight\? - slant\?
- *             "\\([-*?]\\|\\'\\)"))
- *  (setq x-font-regexp-slant (concat - slant -))
- *  (setq x-font-regexp-weight (concat - weight -))
- * nil)            
  */
-    
-#define FONT_START       "[-?]"
-#define FONT_FOUNDRY     "[^-]+"
-#define FONT_FAMILY      "\\([^-]+\\)"                      /* 1 */
-#define FONT_WEIGHT      "\\(bold\\|demibold\\|medium\\)"   /* 2 */
-#define FONT_WEIGHT_Q    "\\([^-]*\\)"                      /* 2 */
-#define FONT_SLANT       "\\([ior]\\)"                      /* 3 */
-#define FONT_SLANT_Q     "\\([^-]?\\)"                      /* 3 */
-#define FONT_SWIDTH      "\\([^-]*\\)"                      /* 4 */
-#define FONT_ADSTYLE     "[^-]*"
-#define FONT_PIXELSIZE   "[^-]*"
-#define FONT_POINTSIZE   "\\([0-9][0-9]+\\|\\*\\)"          /* 5 */
-#define FONT_RESX        "[0-9][0-9]+"
-#define FONT_RESY        "[0-9][0-9]+"
-#define FONT_SPACING     "[cmp?*]"
-#define FONT_AVGWIDTH    "[0-9]+"
-#define FONT_REGISTRY    "[^-]+"
-#define FONT_ENCODING    "[^-]+"
-
-#define FONT_REGEXP      ("\\`\\*?[-?*]"     \
-                         FONT_FOUNDRY   "-" \
-                         FONT_FAMILY    "-" \
-                         FONT_WEIGHT_Q  "-" \
-                         FONT_SLANT_Q   "-" \
-                         FONT_SWIDTH    "-" \
-                         FONT_ADSTYLE   "-" \
-                         FONT_PIXELSIZE "-" \
-                         FONT_POINTSIZE "-" \
-                         "[-?*]\\|\\'")
-
-#define FONT_REGEXP_HEAD ("\\`[-?*]"        \
-                         FONT_FOUNDRY  "-" \
-                         FONT_FAMILY   "-" \
-                         FONT_WEIGHT_Q "-" \
-                         FONT_SLANT_Q      \
-                         "\\([-*?]\\|\\'\\)")
-
-#define FONT_REGEXP_SLANT  "-" FONT_SLANT  "-"
-#define FONT_REGEXP_WEIGHT "-" FONT_WEIGHT "-"
 
 LONG 
 x_to_w32_weight (lpw)
@@ -5600,111 +5789,289 @@ LONG
 x_to_w32_charset (lpcs)
     char * lpcs;
 {
-  if (!lpcs) return (0);
-
-  if (stricmp (lpcs,"ansi") == 0)                return ANSI_CHARSET;
-  else if (stricmp (lpcs,"iso8859-1") == 0)      return ANSI_CHARSET;
-  else if (stricmp (lpcs, "ms-symbol") == 0)     return SYMBOL_CHARSET;
-  /* Map all Japanese charsets to the Windows Shift-JIS charset.  */
-  else if (strnicmp (lpcs, "jis", 3) == 0)       return SHIFTJIS_CHARSET;
-  /* Map all GB charsets to the Windows GB2312 charset.  */
-  else if (strnicmp (lpcs, "gb2312", 6) == 0)    return GB2312_CHARSET;
-  /* Map all Big5 charsets to the Windows Big5 charset.  */
-  else if (strnicmp (lpcs, "big5", 4) == 0)      return CHINESEBIG5_CHARSET;
-  else if (stricmp (lpcs, "ksc5601.1987") == 0)  return HANGEUL_CHARSET;
-  else if (stricmp (lpcs, "ms-oem") == 0)       return OEM_CHARSET;
+  Lisp_Object this_entry, w32_charset;
 
-#ifdef EASTEUROPE_CHARSET
-  else if (stricmp (lpcs, "iso8859-2") == 0)     return EASTEUROPE_CHARSET;
-  else if (stricmp (lpcs, "iso8859-3") == 0)     return TURKISH_CHARSET;
-  else if (stricmp (lpcs, "iso8859-4") == 0)     return BALTIC_CHARSET;
-  else if (stricmp (lpcs, "iso8859-5") == 0)     return RUSSIAN_CHARSET;
-  else if (stricmp (lpcs, "koi8") == 0)          return RUSSIAN_CHARSET;
-  else if (stricmp (lpcs, "iso8859-6") == 0)     return ARABIC_CHARSET;
-  else if (stricmp (lpcs, "iso8859-7") == 0)     return GREEK_CHARSET;
-  else if (stricmp (lpcs, "iso8859-8") == 0)     return HEBREW_CHARSET;
-  else if (stricmp (lpcs, "iso8859-9") == 0)     return TURKISH_CHARSET;
-#ifndef VIETNAMESE_CHARSET
-#define VIETNAMESE_CHARSET 163
-#endif
-  /* Map all Viscii charsets to the Windows Vietnamese charset.  */
-  else if (strnicmp (lpcs, "viscii", 6) == 0)    return VIETNAMESE_CHARSET;
-  else if (strnicmp (lpcs, "vscii", 5) == 0)     return VIETNAMESE_CHARSET;
-  /* Map all TIS charsets to the Windows Thai charset.  */
-  else if (strnicmp (lpcs, "tis620", 6) == 0)    return THAI_CHARSET;
-  else if (stricmp (lpcs, "mac") == 0)           return MAC_CHARSET;
-  else if (stricmp (lpcs, "ksc5601.1992") == 0)  return JOHAB_CHARSET;
-  /* For backwards compatibility with previous 20.4 pretests, map
-     non-specific KSC charsets to the Windows Hangeul charset.  */
-  else if (strnicmp (lpcs, "ksc5601", 7) == 0)   return HANGEUL_CHARSET;
-  else if (stricmp (lpcs, "johab") == 0)         return JOHAB_CHARSET;
-#endif
+  /* Look through w32-charset-info-alist for the character set.
+     Format of each entry is
+       (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
+  */
+  this_entry = Fassoc (build_string(lpcs), Vw32_charset_info_alist);
 
+  if (NILP(this_entry))
+    {
+      /* At startup, we want iso8859-1 fonts to come up properly. */
+      if (stricmp(lpcs, "iso8859-1") == 0)
+        return ANSI_CHARSET;
+      else
+        return DEFAULT_CHARSET;
+    }
+
+  w32_charset = Fcar (Fcdr (this_entry));
+
+  // Translate Lisp symbol to number.
+  if (w32_charset == Qw32_charset_ansi)
+    return ANSI_CHARSET;
+  if (w32_charset == Qw32_charset_symbol)
+    return SYMBOL_CHARSET;
+  if (w32_charset == Qw32_charset_shiftjis)
+    return SHIFTJIS_CHARSET;
+  if (w32_charset == Qw32_charset_hangeul)
+    return HANGEUL_CHARSET;
+  if (w32_charset == Qw32_charset_chinesebig5)
+    return CHINESEBIG5_CHARSET;
+  if (w32_charset == Qw32_charset_gb2312)
+    return GB2312_CHARSET;
+  if (w32_charset == Qw32_charset_oem)
+    return OEM_CHARSET;
+#ifdef JOHAB_CHARSET
+  if (w32_charset == Qw32_charset_johab)
+    return JOHAB_CHARSET;
+  if (w32_charset == Qw32_charset_easteurope)
+    return EASTEUROPE_CHARSET;
+  if (w32_charset == Qw32_charset_turkish)
+    return TURKISH_CHARSET;
+  if (w32_charset == Qw32_charset_baltic)
+    return BALTIC_CHARSET;
+  if (w32_charset == Qw32_charset_russian)
+    return RUSSIAN_CHARSET;
+  if (w32_charset == Qw32_charset_arabic)
+    return ARABIC_CHARSET;
+  if (w32_charset == Qw32_charset_greek)
+    return GREEK_CHARSET;
+  if (w32_charset == Qw32_charset_hebrew)
+    return HEBREW_CHARSET;
+  if (w32_charset == Qw32_charset_vietnamese)
+    return VIETNAMESE_CHARSET;
+  if (w32_charset == Qw32_charset_thai)
+    return THAI_CHARSET;
+  if (w32_charset == Qw32_charset_mac)
+    return MAC_CHARSET;
+#endif /* JOHAB_CHARSET */
 #ifdef UNICODE_CHARSET
-  else if (stricmp (lpcs,"iso10646") == 0)       return UNICODE_CHARSET;
-  else if (stricmp (lpcs, "unicode") == 0)       return UNICODE_CHARSET;
+  if (w32_charset == Qw32_charset_unicode)
+    return UNICODE_CHARSET;
 #endif
-  else if (lpcs[0] == '#')                      return atoi (lpcs + 1);
-  else
-    return DEFAULT_CHARSET;
+
+  return DEFAULT_CHARSET;
 }
 
+
 char *
 w32_to_x_charset (fncharset)
     int fncharset;
 {
   static char buf[16];
+  Lisp_Object charset_type;
 
   switch (fncharset)
     {
-      /* ansi is considered iso8859-1, as most modern ansi fonts are.  */
-    case ANSI_CHARSET:        return "iso8859-1";
-    case DEFAULT_CHARSET:     return "ascii-*";
-    case SYMBOL_CHARSET:      return "ms-symbol";
-    case SHIFTJIS_CHARSET:    return "jisx0208-sjis";
-    case HANGEUL_CHARSET:     return "ksc5601.1987-*";
-    case GB2312_CHARSET:      return "gb2312-*";
-    case CHINESEBIG5_CHARSET: return "big5-*";
-    case OEM_CHARSET:         return "ms-oem";
+    case ANSI_CHARSET:
+      /* Handle startup case of w32-charset-info-alist not
+         being set up yet. */
+      if (NILP(Vw32_charset_info_alist))
+        return "iso8859-1";
+      charset_type = Qw32_charset_ansi;
+      break;
+    case DEFAULT_CHARSET:
+      charset_type = Qw32_charset_default;
+      break;
+    case SYMBOL_CHARSET:
+      charset_type = Qw32_charset_symbol;
+      break;
+    case SHIFTJIS_CHARSET:
+      charset_type = Qw32_charset_shiftjis;
+      break;
+    case HANGEUL_CHARSET:
+      charset_type = Qw32_charset_hangeul;
+      break;
+    case GB2312_CHARSET:
+      charset_type = Qw32_charset_gb2312;
+      break;
+    case CHINESEBIG5_CHARSET:
+      charset_type = Qw32_charset_chinesebig5;
+      break;
+    case OEM_CHARSET:
+      charset_type = Qw32_charset_oem;
+      break;
 
       /* More recent versions of Windows (95 and NT4.0) define more
          character sets.  */
 #ifdef EASTEUROPE_CHARSET
-    case EASTEUROPE_CHARSET: return "iso8859-2";
-    case TURKISH_CHARSET:    return "iso8859-9";
-    case BALTIC_CHARSET:     return "iso8859-4";
-
-      /* W95 with international support but not IE4 often has the
-         KOI8-R codepage but not ISO8859-5.  */
+    case EASTEUROPE_CHARSET:
+      charset_type = Qw32_charset_easteurope;
+      break;
+    case TURKISH_CHARSET:
+      charset_type = Qw32_charset_turkish;
+      break;
+    case BALTIC_CHARSET:
+      charset_type = Qw32_charset_baltic;
+      break;
     case RUSSIAN_CHARSET:
-      if (!IsValidCodePage(28595) && IsValidCodePage(20886))
-        return "koi8-r";
-      else
-        return "iso8859-5";
-    case ARABIC_CHARSET:     return "iso8859-6";
-    case GREEK_CHARSET:      return "iso8859-7";
-    case HEBREW_CHARSET:     return "iso8859-8";
-    case VIETNAMESE_CHARSET: return "viscii1.1-*";
-    case THAI_CHARSET:       return "tis620-*";
-    case MAC_CHARSET:        return "mac-*";
-    case JOHAB_CHARSET:      return "ksc5601.1992-*";
-
+      charset_type = Qw32_charset_russian;
+      break;
+    case ARABIC_CHARSET:
+      charset_type = Qw32_charset_arabic;
+      break;
+    case GREEK_CHARSET:
+      charset_type = Qw32_charset_greek;
+      break;
+    case HEBREW_CHARSET:
+      charset_type = Qw32_charset_hebrew;
+      break;
+    case VIETNAMESE_CHARSET:
+      charset_type = Qw32_charset_vietnamese;
+      break;
+    case THAI_CHARSET:
+      charset_type = Qw32_charset_thai;
+      break;
+    case MAC_CHARSET:
+      charset_type = Qw32_charset_mac;
+      break;
+    case JOHAB_CHARSET:
+      charset_type = Qw32_charset_johab;
+      break;
 #endif
 
 #ifdef UNICODE_CHARSET
-    case UNICODE_CHARSET:  return "iso10646-unicode";
+    case UNICODE_CHARSET:
+      charset_type = Qw32_charset_unicode;
+      break;
 #endif
+    default:
+      /* Encode numerical value of unknown charset.  */
+      sprintf (buf, "*-#%u", fncharset);
+      return buf;
     }
-  /* Encode numerical value of unknown charset.  */
-  sprintf (buf, "*-#%u", fncharset);
-  return buf;
+  
+  {
+    Lisp_Object rest;
+    char * best_match = NULL;
+
+    /* Look through w32-charset-info-alist for the character set.
+       Prefer ISO codepages, and prefer lower numbers in the ISO
+       range. Only return charsets for codepages which are installed.
+
+       Format of each entry is
+         (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
+    */
+    for (rest = Vw32_charset_info_alist; CONSP (rest); rest = XCDR (rest))
+      {
+        char * x_charset;
+        Lisp_Object w32_charset;
+        Lisp_Object codepage;
+
+        Lisp_Object this_entry = XCAR (rest);
+
+        /* Skip invalid entries in alist. */
+        if (!CONSP (this_entry) || !STRINGP (XCAR (this_entry))
+            || !CONSP (XCDR (this_entry))
+            || !SYMBOLP (XCAR (XCDR (this_entry))))
+          continue;
+
+        x_charset = XSTRING (XCAR (this_entry))->data;
+        w32_charset = XCAR (XCDR (this_entry));
+        codepage = XCDR (XCDR (this_entry));
+
+        /* Look for Same charset and a valid codepage (or non-int
+           which means ignore).  */
+        if (w32_charset == charset_type
+            && (!INTEGERP (codepage) || codepage == CP_DEFAULT
+                || IsValidCodePage (XINT (codepage))))
+          {
+            /* If we don't have a match already, then this is the
+               best.  */
+            if (!best_match)
+              best_match = x_charset;
+            /* If this is an ISO codepage, and the best so far isn't,
+               then this is better.  */
+            else if (stricmp (best_match, "iso") != 0
+                     && stricmp (x_charset, "iso") == 0)
+              best_match = x_charset;
+            /* If both are ISO8859 codepages, choose the one with the
+               lowest number in the encoding field.  */
+            else if (stricmp (best_match, "iso8859-") == 0
+                     && stricmp (x_charset, "iso8859-") == 0)
+              {
+                int best_enc = atoi (best_match + 8);
+                int this_enc = atoi (x_charset + 8);
+                if (this_enc > 0 && this_enc < best_enc)
+                  best_match = x_charset;
+              }                
+          }
+      }
+
+    /* If no match, encode the numeric value. */
+    if (!best_match)
+      {
+        sprintf (buf, "*-#%u", fncharset);
+        return buf;
+      }
+
+    strncpy(buf, best_match, 15);
+    buf[15] = '\0';
+    return buf;
+  }
 }
 
+
+/* Get the Windows codepage corresponding to the specified font.  The
+   charset info in the font name is used to look up
+   w32-charset-to-codepage-alist.  */
+int 
+w32_codepage_for_font (char *fontname)
+{
+  Lisp_Object codepage, entry;
+  char *charset_str, *charset, *end;
+
+  if (NILP (Vw32_charset_info_alist))
+    return CP_DEFAULT;
+
+  /* Extract charset part of font string.  */
+  charset = xlfd_charset_of_font (fontname);
+
+  if (!charset)
+    return CP_UNKNOWN;
+
+  charset_str = (char *) alloca (strlen (charset));
+  strcpy (charset_str, charset);
+
+  /* Remove leading "*-".  */
+  if (strncmp ("*-", charset_str, 2) == 0)
+    charset = charset_str + 2;
+  else
+    charset = charset_str;
+
+  /* Stop match at wildcard (including preceding '-'). */
+  if (end = strchr (charset, '*'))
+      {
+        if (end > charset && *(end-1) == '-')
+          end--;
+        *end = '\0';
+      }
+
+  entry = Fassoc (build_string(charset), Vw32_charset_info_alist);
+  if (NILP (entry))
+    return CP_UNKNOWN;
+
+  codepage = Fcdr (Fcdr (entry));
+
+  if (NILP (codepage))
+    return CP_8BIT;
+  else if (XFASTINT (codepage) == XFASTINT (Qt))
+    return CP_UNICODE;
+  else if (INTEGERP (codepage))
+    return XINT (codepage);
+  else
+    return CP_UNKNOWN;
+}
+
+
 BOOL 
-w32_to_x_font (lplogfont, lpxstr, len)
+w32_to_x_font (lplogfont, lpxstr, len, specific_charset)
      LOGFONT * lplogfont;
      char * lpxstr;
      int len;
+     char * specific_charset;
 {
   char* fonttype;
   char *fontname;
@@ -5731,6 +6098,8 @@ w32_to_x_font (lplogfont, lpxstr, len)
 
   setup_coding_system (Fcheck_coding_system (Vw32_system_coding_system),
                        &coding);
+  coding.src_multibyte = 0;
+  coding.dst_multibyte = 1;
   coding.mode |= CODING_MODE_LAST_BLOCK;
   bufsz = decoding_buffer_size (&coding, LF_FACESIZE);
 
@@ -5776,8 +6145,9 @@ w32_to_x_font (lplogfont, lpxstr, len)
             ((lplogfont->lfPitchAndFamily & 0x3) == VARIABLE_PITCH)
              ? 'p' : 'c',                            /* spacing */
             width_pixels,                           /* avg width */
-            w32_to_x_charset (lplogfont->lfCharSet) /* charset registry
-                                                        and encoding*/
+            specific_charset ? specific_charset
+             : w32_to_x_charset (lplogfont->lfCharSet) 
+             /* charset registry and encoding */
             );
 
   lpxstr[len - 1] = 0;         /* just to be sure */
@@ -5826,7 +6196,7 @@ x_to_w32_font (lpxstr, lplogfont)
       char name[50], weight[20], slant, pitch, pixels[10], height[10],
         width[10], resy[10], remainder[20];
       char * encoding;
-      int dpi = one_w32_display_info.height_in;
+      int dpi = one_w32_display_info.resy;
 
       fields = sscanf (lpxstr,
                       "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%19s",
@@ -5846,6 +6216,8 @@ x_to_w32_font (lpxstr, lplogfont)
 
           setup_coding_system
             (Fcheck_coding_system (Vw32_system_coding_system), &coding);
+         coding.src_multibyte = 1;
+         coding.dst_multibyte = 1;
          bufsize = encoding_buffer_size (&coding, strlen (name));
          buf = (unsigned char *) alloca (bufsize);
           coding.mode |= CODING_MODE_LAST_BLOCK;
@@ -5866,8 +6238,7 @@ x_to_w32_font (lpxstr, lplogfont)
 
       fields--;
 
-      if (!NILP (Vw32_enable_synthesized_fonts))
-       lplogfont->lfItalic = (fields > 0 && slant == 'i');
+      lplogfont->lfItalic = (fields > 0 && slant == 'i');
 
       fields--;
 
@@ -5993,7 +6364,7 @@ int xlfd_strip_height (char *fontname)
                   *write_to = '-';
                   write_to++;
                 }
-              /* If the pixel height field is at the end (partial xfld),
+              /* If the pixel height field is at the end (partial xlfd),
                  return now.  */
               else
                 return pixel_height;
@@ -6160,6 +6531,7 @@ enum_font_cb2 (lplf, lptm, FontType, lpef)
   {
     char buf[100];
     Lisp_Object width = Qnil;
+    char *charset = NULL;
 
     /* Truetype fonts do not report their true metrics until loaded */
     if (FontType != RASTER_FONTTYPE)
@@ -6189,7 +6561,18 @@ enum_font_cb2 (lplf, lptm, FontType, lpef)
           lplf->elfLogFont.lfHeight = -lplf->elfLogFont.lfHeight;
       }
 
-    if (!w32_to_x_font (&(lplf->elfLogFont), buf, 100))
+    if (!NILP (*(lpef->pattern)))
+      {
+        charset = xlfd_charset_of_font (XSTRING(*(lpef->pattern))->data);
+
+        /* Ensure that charset is valid for this font. */
+        if (charset
+            && (x_to_w32_charset (charset) != lplf->elfLogFont.lfCharSet))
+          charset = NULL;
+      }
+
+    /* TODO: List all relevant charsets if charset not specified. */
+    if (!w32_to_x_font (&(lplf->elfLogFont), buf, 100, charset))
       return (0);
 
     if (NILP (*(lpef->pattern))
@@ -6311,9 +6694,21 @@ w32_list_fonts (FRAME_PTR f, Lisp_Object pattern, int size, int maxnames )
   for (; CONSP (patterns); patterns = XCDR (patterns))
     {
       enumfont_t ef;
+      int codepage;
 
       tpat = XCAR (patterns);
 
+      if (!STRINGP (tpat))
+        continue;
+
+      /* Avoid expensive EnumFontFamilies functions if we are not
+         going to be able to output one of these anyway. */
+      codepage = w32_codepage_for_font (XSTRING (tpat)->data);
+      if (codepage != CP_8BIT && codepage != CP_UNICODE
+          && codepage != CP_DEFAULT && codepage != CP_UNKNOWN
+         && !IsValidCodePage(codepage))
+        continue;
+
       /* See if we cached the result for this particular query.
          The cache is an alist of the form:
            ((PATTERN (FONTNAME . WIDTH) ...) ...)
@@ -6336,8 +6731,7 @@ w32_list_fonts (FRAME_PTR f, Lisp_Object pattern, int size, int maxnames )
       /* Use EnumFontFamiliesEx where it is available, as it knows
          about character sets.  Fall back to EnumFontFamilies for
          older versions of NT that don't support the 'Ex function.  */
-      x_to_w32_font (STRINGP (tpat) ? XSTRING (tpat)->data :
-                     NULL, &ef.logfont);
+      x_to_w32_font (XSTRING (tpat)->data, &ef.logfont);
       {
         LOGFONT font_match_pattern;
         HMODULE gdi32 = GetModuleHandle ("gdi32.dll");
@@ -6598,7 +6992,7 @@ w32_find_ccl_program (fontp)
 DEFUN ("w32-find-bdf-fonts", Fw32_find_bdf_fonts, Sw32_find_bdf_fonts,
        1, 1, 0,
        "Return a list of BDF fonts in DIR, suitable for appending to\n\
-w32-bdf-filename-alist.  Fonts which do not contain an xfld description\n\
+w32-bdf-filename-alist.  Fonts which do not contain an xlfd description\n\
 will not be included in the list. DIR may be a list of directories.")
      (directory)
      Lisp_Object directory;
@@ -6646,8 +7040,7 @@ Lisp_Object w32_find_bdf_fonts_in_dir( Lisp_Object directory )
 
 \f
 DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0,
-       "Return non-nil if color COLOR is supported on frame FRAME.\n\
-If FRAME is omitted or nil, use the selected frame.")
+  "Internal function called by `color-defined-p', which see.")
   (color, frame)
      Lisp_Object color, frame;
 {
@@ -6663,11 +7056,7 @@ If FRAME is omitted or nil, use the selected frame.")
 }
 
 DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2, 0,
-  "Return a description of the color named COLOR on frame FRAME.\n\
-The value is a list of integer RGB values--(RED GREEN BLUE).\n\
-These values appear to range from 0 to 65280 or 65535, depending\n\
-on the system; white is (65280 65280 65280) or (65535 65535 65535).\n\
-If FRAME is omitted or nil, use the selected frame.")
+  "Internal function called by `color-values', which see.")
   (color, frame)
      Lisp_Object color, frame;
 {
@@ -6693,10 +7082,7 @@ If FRAME is omitted or nil, use the selected frame.")
 }
 
 DEFUN ("xw-display-color-p", Fxw_display_color_p, Sxw_display_color_p, 0, 1, 0,
-  "Return t if the X display supports color.\n\
-The optional argument DISPLAY specifies which display to ask about.\n\
-DISPLAY should be either a frame or a display name (a string).\n\
-If omitted or nil, that stands for the selected frame's display.")
+  "Internal function called by `display-color-p', which see.")
   (display)
      Lisp_Object display;
 {
@@ -6815,11 +7201,7 @@ If omitted or nil, that stands for the selected frame's display.")
   (display)
      Lisp_Object display;
 {
-  struct w32_display_info *dpyinfo = check_x_display_info (display);
-  char *vendor = "Microsoft Corp.";
-
-  if (! vendor) vendor = "";
-  return build_string (vendor);
+  return build_string ("Microsoft Corp.");
 }
 
 DEFUN ("x-server-version", Fx_server_version, Sx_server_version, 0, 1, 0,
@@ -6833,10 +7215,9 @@ If omitted or nil, that stands for the selected frame's display.")
   (display)
      Lisp_Object display;
 {
-  struct w32_display_info *dpyinfo = check_x_display_info (display);
-
   return Fcons (make_number (w32_major_version),
-               Fcons (make_number (w32_minor_version), Qnil));
+               Fcons (make_number (w32_minor_version),
+                      Fcons (make_number (w32_build_number), Qnil)));
 }
 
 DEFUN ("x-display-screens", Fx_display_screens, Sx_display_screens, 0, 1, 0,
@@ -6847,8 +7228,6 @@ If omitted or nil, that stands for the selected frame's display.")
   (display)
      Lisp_Object display;
 {
-  struct w32_display_info *dpyinfo = check_x_display_info (display);
-
   return make_number (1);
 }
 
@@ -6947,8 +7326,6 @@ If omitted or nil, that stands for the selected frame's display.")
   (display)
      Lisp_Object display;
 {
-  struct w32_display_info *dpyinfo = check_x_display_info (display);
-
   return Qnil;
 }
 \f
@@ -7125,9 +7502,9 @@ If DISPLAY is nil, that stands for the selected frame's display.")
   for (i = 0; i < dpyinfo->n_fonts; i++)
     if (dpyinfo->font_table[i].name)
       {
+        if (dpyinfo->font_table[i].name != dpyinfo->font_table[i].full_name)
+          xfree (dpyinfo->font_table[i].full_name);
         xfree (dpyinfo->font_table[i].name);
-        /* Don't free the full_name string;
-           it is always shared with something else.  */
         w32_unload_font (dpyinfo, dpyinfo->font_table[i].font);
       }
   x_destroy_all_bitmaps (dpyinfo);
@@ -7161,8 +7538,6 @@ If DISPLAY is omitted or nil, that stands for the selected frame's display.")
   (on, display)
     Lisp_Object display, on;
 {
-  struct w32_display_info *dpyinfo = check_x_display_info (display);
-
   return Qnil;
 }
 
@@ -7181,10 +7556,6 @@ If DISPLAY is omitted or nil, that stands for the selected frame's display.")
 
 static struct image_type *image_types;
 
-/* A list of symbols, one for each supported image type.  */
-
-Lisp_Object Vimage_types;
-
 /* The symbol `image' which is the car of the lists used to represent
    images in Lisp.  */
 
@@ -7196,10 +7567,11 @@ Lisp_Object Qxbm;
 
 /* Keywords.  */
 
-Lisp_Object QCtype, QCdata, QCascent, QCmargin, QCrelief;
 extern Lisp_Object QCwidth, QCheight, QCforeground, QCbackground, QCfile;
+extern Lisp_Object QCdata;
+Lisp_Object QCtype, QCascent, QCmargin, QCrelief;
 Lisp_Object QCalgorithm, QCcolor_symbols, QCheuristic_mask;
-extern Lisp_Object QCindex;
+Lisp_Object QCindex;
 
 /* Other symbols.  */
 
@@ -7219,6 +7591,7 @@ static void x_laplace P_ ((struct frame *, struct image *));
 static int x_build_heuristic_mask P_ ((struct frame *, struct image *,
                                       Lisp_Object));
 
+
 /* Define a new image type from TYPE.  This adds a copy of TYPE to
    image_types and adds the symbol *TYPE->type to Vimage_types.  */
 
@@ -7306,6 +7679,7 @@ enum image_value_type
   IMAGE_SYMBOL_VALUE,
   IMAGE_POSITIVE_INTEGER_VALUE,
   IMAGE_NON_NEGATIVE_INTEGER_VALUE,
+  IMAGE_ASCENT_VALUE,
   IMAGE_INTEGER_VALUE,
   IMAGE_FUNCTION_VALUE,
   IMAGE_NUMBER_VALUE,
@@ -7408,6 +7782,15 @@ parse_image_spec (spec, keywords, nkeywords, type)
            return 0;
          break;
 
+        case IMAGE_ASCENT_VALUE:
+         if (SYMBOLP (value) && EQ (value, Qcenter))
+           break;
+         else if (INTEGERP (value)
+                  && XINT (value) >= 0
+                  && XINT (value) <= 100)
+           break;
+         return 0;
+
        case IMAGE_NON_NEGATIVE_INTEGER_VALUE:
          if (!INTEGERP (value) || XINT (value) < 0)
            return 0;
@@ -7570,6 +7953,32 @@ prepare_image_for_display (f, img)
 }
      
 
+/* Value is the number of pixels for the ascent of image IMG when
+   drawn in face FACE.  */
+
+int
+image_ascent (img, face)
+     struct image *img;
+     struct face *face;
+{
+  int height = img->height + img->margin;
+  int ascent;
+
+  if (img->ascent == CENTERED_IMAGE_ASCENT)
+    {
+      if (face->font)
+       ascent = height / 2 - (FONT_DESCENT(face->font)
+                               - FONT_BASE(face->font)) / 2;
+      else
+       ascent = height / 2;
+    }
+  else
+    ascent = height * img->ascent / 100.0;
+
+  return ascent;
+}
+
+
 \f
 /***********************************************************************
                  Helper functions for X image types
@@ -7588,7 +7997,7 @@ x_clear_image (f, img)
      struct frame *f;
      struct image *img;
 {
-#if 0 /* NTEMACS_TODO: W32 image support  */
+#if 0 /* TODO: W32 image support  */
 
   if (img->pixmap)
     {
@@ -7636,7 +8045,7 @@ x_alloc_image_color (f, img, color_name, dflt)
      Lisp_Object color_name;
      unsigned long dflt;
 {
-#if 0 /* NTEMACS_TODO: allocing colors.  */
+#if 0 /* TODO: allocing colors.  */
   XColor color;
   unsigned long result;
 
@@ -7716,8 +8125,8 @@ free_image_cache (f)
 /* Clear image cache of frame F.  FORCE_P non-zero means free all
    images.  FORCE_P zero means clear only images that haven't been
    displayed for some time.  Should be called from time to time to
-   reduce the number of loaded images.  If image-cache-eveiction-delay
-   is non-nil, this frees images in the cache which weren't displayed for
+   reduce the number of loaded images.  If image-eviction-seconds is
+   non-nil, this frees images in the cache which weren't displayed for
    at least that many seconds.  */
 
 void
@@ -7846,7 +8255,9 @@ lookup_image (f, spec)
          ascent = image_spec_value (spec, QCascent, NULL);
          if (INTEGERP (ascent))
            img->ascent = XFASTINT (ascent);
-         
+         else if (EQ (ascent, Qcenter))
+            img->ascent = CENTERED_IMAGE_ASCENT;
+
          margin = image_spec_value (spec, QCmargin, NULL);
          if (INTEGERP (margin) && XINT (margin) >= 0)
            img->margin = XFASTINT (margin);
@@ -7947,7 +8358,7 @@ forall_images_in_image_cache (f, fn)
                            W32 support code
  ***********************************************************************/
 
-#if 0 /* NTEMACS_TODO: W32 specific image code.  */
+#if 0 /* TODO: W32 specific image code.  */
 
 static int x_create_x_image_and_pixmap P_ ((struct frame *, int, int, int,
                                             XImage **, Pixmap *));
@@ -7968,7 +8379,7 @@ x_create_x_image_and_pixmap (f, width, height, depth, ximg, pixmap)
      XImage **ximg;
      Pixmap *pixmap;
 {
-#if 0 /* NTEMACS_TODO: Image support for W32 */
+#if 0 /* TODO: Image support for W32 */
   Display *display = FRAME_W32_DISPLAY (f);
   Screen *screen = FRAME_X_SCREEN (f);
   Window window = FRAME_W32_WINDOW (f);
@@ -8064,7 +8475,7 @@ x_find_image_file (file)
   /* Try to find FILE in data-directory, then x-bitmap-file-path.  */
   fd = openp (search_path, file, "", &file_found, 0);
   
-  if (fd < 0)
+  if (fd == -1)
     file_found = Qnil;
   else
     close (fd);
@@ -8536,7 +8947,7 @@ xbm_load_image_from_file (f, img, specified_file)
       if (!NILP (value))
        background = x_alloc_image_color (f, img, value, background);
 
-#if 0 /* NTEMACS_TODO : Port image display to W32 */
+#if 0 /* TODO : Port image display to W32 */
       BLOCK_INPUT;
       img->pixmap
        = XCreatePixmapFromBitmapData (FRAME_W32_DISPLAY (f),
@@ -8639,7 +9050,7 @@ xbm_load (f, img)
       else
        bits = XBOOL_VECTOR (data)->data;
 
-#if 0 /* NTEMACS_TODO : W32 XPM code */
+#if 0 /* TODO : W32 XPM code */
       /* Create the pixmap.  */
       depth = DefaultDepthOfScreen (FRAME_X_SCREEN (f));
       img->pixmap
@@ -8649,7 +9060,7 @@ xbm_load (f, img)
                                       img->width, img->height,
                                       foreground, background,
                                       depth);
-#endif /* NTEMACS_TODO */
+#endif /* TODO */
 
       if (img->pixmap)
        success_p = 1;
@@ -8785,11 +9196,18 @@ xpm_load (f, img)
   /* Configure the XPM lib.  Use the visual of frame F.  Allocate
      close colors.  Return colors allocated.  */
   bzero (&attrs, sizeof attrs);
-  attrs.visual = FRAME_W32_DISPLAY_INFO (f)->visual;
+  attrs.visual = FRAME_X_VISUAL (f);
+  attrs.colormap = FRAME_X_COLORMAP (f);
   attrs.valuemask |= XpmVisual;
+  attrs.valuemask |= XpmColormap;
   attrs.valuemask |= XpmReturnAllocPixels;
+#ifdef XpmAllocCloseColors
   attrs.alloc_close_colors = 1;
   attrs.valuemask |= XpmAllocCloseColors;
+#else
+  attrs.closeness = 600;
+  attrs.valuemask |= XpmCloseness;
+#endif
 
   /* If image specification contains symbolic color definitions, add
      these to `attrs'.  */
@@ -8905,7 +9323,7 @@ xpm_load (f, img)
 #endif /* HAVE_XPM != 0 */
 
 \f
-#if 0 /* NTEMACS_TODO : Color tables on W32.  */
+#if 0 /* TODO : Color tables on W32.  */
 /***********************************************************************
                             Color table
  ***********************************************************************/
@@ -9097,14 +9515,14 @@ colors_in_color_table (n)
   return colors;
 }
 
-#endif /* NTEMACS_TODO */
+#endif /* TODO */
 
 \f
 /***********************************************************************
                              Algorithms
  ***********************************************************************/
 
-#if 0 /* NTEMACS_TODO : W32 versions of low level algorithms */
+#if 0 /* TODO : W32 versions of low level algorithms */
 static void x_laplace_write_row P_ ((struct frame *, long *,
                                     int, XImage *, int));
 static void x_laplace_read_row P_ ((struct frame *, Colormap,
@@ -9161,7 +9579,7 @@ x_laplace (f, img)
      struct frame *f;
      struct image *img;
 {
-#if 0 /* NTEMACS_TODO : W32 version */
+#if 0 /* TODO : W32 version */
   Colormap cmap = DefaultColormapOfScreen (FRAME_X_SCREEN (f));
   XImage *ximg, *oimg;
   XColor *in[3];
@@ -9239,7 +9657,7 @@ x_laplace (f, img)
   free_color_table ();
 
   UNBLOCK_INPUT;
-#endif /* NTEMACS_TODO */
+#endif /* TODO */
 }
 
 
@@ -9256,7 +9674,7 @@ x_build_heuristic_mask (f, img, how)
      struct image *img;
      Lisp_Object how;
 {
-#if 0 /* NTEMACS_TODO : W32 version */
+#if 0 /* TODO : W32 version */
   Display *dpy = FRAME_W32_DISPLAY (f);
   XImage *ximg, *mask_img;
   int x, y, rc, look_at_corners_p;
@@ -9348,7 +9766,7 @@ x_build_heuristic_mask (f, img, how)
   XDestroyImage (ximg);
   
   UNBLOCK_INPUT;
-#endif /* NTEMACS_TODO */
+#endif /* TODO */
 
   return 1;
 }
@@ -9564,14 +9982,6 @@ pbm_load (f, img)
       return 0;
     }
 
-  if (*magic != 'P')
-    {
-      fclose (fp);
-      image_error ("Not a PBM image file: %s", file, Qnil);
-      UNGCPRO;
-      return 0;
-    }
-
   switch (*p++)
     {
     case '1':
@@ -9677,7 +10087,7 @@ pbm_load (f, img)
            
            if (r < 0 || g < 0 || b < 0)
              {
-b              xfree (ximg->data);
+               xfree (ximg->data);
                ximg->data = NULL;
                XDestroyImage (ximg);
                UNBLOCK_INPUT;
@@ -9816,7 +10226,6 @@ my_png_warning (png_ptr, msg)
   image_error ("PNG warning: %s", build_string (msg), Qnil);
 }
 
-
 /* Memory source for PNG decoding.  */
 
 struct png_memory_storage
@@ -9847,7 +10256,6 @@ png_read_from_memory (png_ptr, data, length)
   tbr->index = tbr->index + length;
 }
 
-
 /* Load PNG image IMG for use on frame F.  Value is non-zero if
    successful.  */
 
@@ -9933,7 +10341,6 @@ png_load (f, img)
       tbr.bytes += sizeof (sig);
     }
 
-
   /* Initialize read and info structs for PNG lib.  */
   png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL,
                                    my_png_error, my_png_warning);
@@ -10297,7 +10704,6 @@ my_error_exit (cinfo)
   longjmp (mgr->setjmp_buffer, 1);
 }
 
-
 /* Init source method for JPEG data source manager.  Called by
    jpeg_read_header() before any data is actually read.  See
    libjpeg.doc from the JPEG lib distribution.  */
@@ -10421,7 +10827,6 @@ jpeg_load (f, img)
   file = Qnil;
   GCPRO1 (file);
 
-
   if (NILP (specified_data))
     {
       file = x_find_image_file (specified_file);
@@ -10756,7 +11161,6 @@ tiff_size_of_memory (data)
   return ((tiff_memory_source *) data)->len;
 }
 
-
 /* Load TIFF image IMG for use on frame F.  Value is non-zero if
    successful.  */
 
@@ -11023,11 +11427,11 @@ gif_load (f, img)
   specified_file = image_spec_value (img->spec, QCfile, NULL);
   specified_data = image_spec_value (img->spec, QCdata, NULL);
   file = Qnil;
+  GCPRO1 (file);
 
   if (NILP (specified_data))
     {
       file = x_find_image_file (specified_file);
-      GCPRO1 (file);
       if (!STRINGP (file))
         {
           image_error ("Cannot find image file `%s'", specified_file, Qnil);
@@ -11488,7 +11892,7 @@ selected frame.  Value is VALUE.")
   (prop, value, frame)
      Lisp_Object frame, prop, value;
 {
-#if 0 /* NTEMACS_TODO : port window properties to W32 */
+#if 0 /* TODO : port window properties to W32 */
   struct frame *f = check_x_frame (frame);
   Atom prop_atom;
 
@@ -11505,7 +11909,7 @@ selected frame.  Value is VALUE.")
   XFlush (FRAME_W32_DISPLAY (f));
   UNBLOCK_INPUT;
 
-#endif /* NTEMACS_TODO */
+#endif /* TODO */
 
   return value;
 }
@@ -11518,7 +11922,7 @@ FRAME nil or omitted means use the selected frame.  Value is PROP.")
   (prop, frame)
      Lisp_Object prop, frame;
 {
-#if 0 /* NTEMACS_TODO : port window properties to W32 */
+#if 0 /* TODO : port window properties to W32 */
 
   struct frame *f = check_x_frame (frame);
   Atom prop_atom;
@@ -11531,7 +11935,7 @@ FRAME nil or omitted means use the selected frame.  Value is PROP.")
   /* Make sure the property is removed when we return.  */
   XFlush (FRAME_W32_DISPLAY (f));
   UNBLOCK_INPUT;
-#endif  /* NTEMACS_TODO */
+#endif  /* TODO */
 
   return prop;
 }
@@ -11546,7 +11950,7 @@ value.")
   (prop, frame)
      Lisp_Object prop, frame;
 {
-#if 0 /* NTEMACS_TODO : port window properties to W32 */
+#if 0 /* TODO : port window properties to W32 */
 
   struct frame *f = check_x_frame (frame);
   Atom prop_atom;
@@ -11587,7 +11991,7 @@ value.")
 
   return prop_value;
 
-#endif /* NTEMACS_TODO */
+#endif /* TODO */
   return Qnil;
 }
 
@@ -11597,109 +12001,168 @@ value.")
                                Busy cursor
  ***********************************************************************/
 
-/* The implementation partly follows a patch from
-   F.Pierresteguy@frcl.bull.fr dated 1994.  */
+/* If non-null, an asynchronous timer that, when it expires, displays
+   a busy cursor on all frames.  */
 
-/* Setting inhibit_busy_cursor to 2 inhibits busy-cursor display until
-   the next X event is read and we enter XTread_socket again.  Setting
-   it to 1 inhibits busy-cursor display for direct commands.  */
+static struct atimer *busy_cursor_atimer;
 
-int inhibit_busy_cursor;
+/* Non-zero means a busy cursor is currently shown.  */
 
-/* Incremented with each call to x-display-busy-cursor.
-   Decremented in x-undisplay-busy-cursor.  */
+static int busy_cursor_shown_p;
 
-static int busy_count;
+/* Number of seconds to wait before displaying a busy cursor.  */
 
+static Lisp_Object Vbusy_cursor_delay;
 
-DEFUN ("x-show-busy-cursor", Fx_show_busy_cursor,
-       Sx_show_busy_cursor, 0, 0, 0,
-  "Show a busy cursor, if not already shown.\n\
-Each call to this function must be matched by a call to\n\
-x-undisplay-busy-cursor to make the busy pointer disappear again.")
-  ()
+/* Default number of seconds to wait before displaying a busy
+   cursor.  */
+
+#define DEFAULT_BUSY_CURSOR_DELAY 1
+
+/* Function prototypes.  */
+
+static void show_busy_cursor P_ ((struct atimer *));
+static void hide_busy_cursor P_ ((void));
+
+
+/* Cancel a currently active busy-cursor timer, and start a new one.  */
+
+void
+start_busy_cursor ()
 {
-  ++busy_count;
-  if (busy_count == 1)
+#if 0 /* TODO: cursor shape changes.  */
+  EMACS_TIME delay;
+  int secs, usecs = 0;
+  
+  cancel_busy_cursor ();
+
+  if (INTEGERP (Vbusy_cursor_delay)
+      && XINT (Vbusy_cursor_delay) > 0)
+    secs = XFASTINT (Vbusy_cursor_delay);
+  else if (FLOATP (Vbusy_cursor_delay)
+          && XFLOAT_DATA (Vbusy_cursor_delay) > 0)
     {
-      Lisp_Object rest, frame;
+      Lisp_Object tem;
+      tem = Ftruncate (Vbusy_cursor_delay, Qnil);
+      secs = XFASTINT (tem);
+      usecs = (XFLOAT_DATA (Vbusy_cursor_delay) - secs) * 1000000;
+    }
+  else
+    secs = DEFAULT_BUSY_CURSOR_DELAY;
+  
+  EMACS_SET_SECS_USECS (delay, secs, usecs);
+  busy_cursor_atimer = start_atimer (ATIMER_RELATIVE, delay,
+                                    show_busy_cursor, NULL);
+#endif
+}
+
+
+/* Cancel the busy cursor timer if active, hide a busy cursor if
+   shown.  */
+
+void
+cancel_busy_cursor ()
+{
+  if (busy_cursor_atimer)
+    {
+      cancel_atimer (busy_cursor_atimer);
+      busy_cursor_atimer = NULL;
+    }
+  
+  if (busy_cursor_shown_p)
+    hide_busy_cursor ();
+}
+
+
+/* Timer function of busy_cursor_atimer.  TIMER is equal to
+   busy_cursor_atimer.
+
+   Display a busy cursor on all frames by mapping the frames'
+   busy_window.  Set the busy_p flag in the frames' output_data.x
+   structure to indicate that a busy cursor is shown on the
+   frames.  */
 
+static void
+show_busy_cursor (timer)
+     struct atimer *timer;
+{
+#if 0  /* TODO: cursor shape changes.  */
+  /* The timer implementation will cancel this timer automatically
+     after this function has run.  Set busy_cursor_atimer to null
+     so that we know the timer doesn't have to be canceled.  */
+  busy_cursor_atimer = NULL;
+
+  if (!busy_cursor_shown_p)
+    {
+      Lisp_Object rest, frame;
+  
+      BLOCK_INPUT;
+  
       FOR_EACH_FRAME (rest, frame)
        if (FRAME_X_P (XFRAME (frame)))
          {
            struct frame *f = XFRAME (frame);
-#if 0 /* NTEMACS_TODO : busy cursor */
-           
-           BLOCK_INPUT;
+       
            f->output_data.w32->busy_p = 1;
-           
+       
            if (!f->output_data.w32->busy_window)
              {
                unsigned long mask = CWCursor;
                XSetWindowAttributes attrs;
-
+           
                attrs.cursor = f->output_data.w32->busy_cursor;
+           
                f->output_data.w32->busy_window
-                 = XCreateWindow (FRAME_W32_DISPLAY (f),
+                 = XCreateWindow (FRAME_X_DISPLAY (f),
                                   FRAME_OUTER_WINDOW (f),
                                   0, 0, 32000, 32000, 0, 0,
-                                  InputOnly, CopyFromParent,
+                                  InputOnly,
+                                  CopyFromParent,
                                   mask, &attrs);
              }
-
-           XMapRaised (FRAME_W32_DISPLAY (f), f->output_data.w32->busy_window);
-           UNBLOCK_INPUT;
-#endif
+       
+           XMapRaised (FRAME_X_DISPLAY (f), f->output_data.w32->busy_window);
+           XFlush (FRAME_X_DISPLAY (f));
          }
-    }
 
-  return Qnil;
+      busy_cursor_shown_p = 1;
+      UNBLOCK_INPUT;
+    }
+#endif
 }
 
 
-DEFUN ("x-hide-busy-cursor", Fx_hide_busy_cursor,
-       Sx_hide_busy_cursor, 0, 1, 0,
-  "Hide a busy-cursor.\n\
-A busy-cursor will actually be undisplayed when a matching\n\
-`x-undisplay-busy-cursor' is called for each `x-display-busy-cursor'\n\
-issued.  FORCE non-nil means undisplay the busy-cursor forcibly,\n\
-not counting calls.")
-  (force)
-     Lisp_Object force;
-{
-  Lisp_Object rest, frame;
-
-  if (busy_count == 0)
-    return Qnil;
-
-  if (!NILP (force) && busy_count != 0)
-    busy_count = 1;
+/* Hide the busy cursor on all frames, if it is currently shown.  */
 
-  --busy_count;
-  if (busy_count != 0)
-    return Qnil;
-
-  FOR_EACH_FRAME (rest, frame)
+static void
+hide_busy_cursor ()
+{
+#if 0 /* TODO: cursor shape changes.  */
+  if (busy_cursor_shown_p)
     {
-      struct frame *f = XFRAME (frame);
-      
-      if (FRAME_X_P (f)
-         /* Watch out for newly created frames.  */
-         && f->output_data.w32->busy_window)
+      Lisp_Object rest, frame;
+
+      BLOCK_INPUT;
+      FOR_EACH_FRAME (rest, frame)
        {
-#if 0 /* NTEMACS_TODO : busy cursor */   
-         BLOCK_INPUT;
-         XUnmapWindow (FRAME_W32_DISPLAY (f), f->output_data.w32->busy_window);
-         /* Sync here because XTread_socket looks at the busy_p flag
-            that is reset to zero below.  */
-         XSync (FRAME_W32_DISPLAY (f), False);
-         UNBLOCK_INPUT;
-         f->output_data.w32->busy_p = 0;
-#endif
+         struct frame *f = XFRAME (frame);
+      
+         if (FRAME_X_P (f)
+             /* Watch out for newly created frames.  */
+             && f->output_data.x->busy_window)
+           {
+             XUnmapWindow (FRAME_X_DISPLAY (f), f->output_data.x->busy_window);
+             /* Sync here because XTread_socket looks at the busy_p flag
+                that is reset to zero below.  */
+             XSync (FRAME_X_DISPLAY (f), False);
+             f->output_data.x->busy_p = 0;
+           }
        }
-    }
 
-  return Qnil;
+      busy_cursor_shown_p = 0;
+      UNBLOCK_INPUT;
+    }
+#endif
 }
 
 
@@ -11729,7 +12192,7 @@ x_create_tip_frame (dpyinfo, parms)
      struct w32_display_info *dpyinfo;
      Lisp_Object parms;
 {
-#if 0 /* NTEMACS_TODO : w32 version */
+#if 0 /* TODO : w32 version */
   struct frame *f;
   Lisp_Object frame, tem;
   Lisp_Object name;
@@ -11796,10 +12259,6 @@ x_create_tip_frame (dpyinfo, parms)
       specbind (Qx_resource_name, name);
     }
 
-  /* Create fontsets from `global_fontset_alist' before handling fonts.  */
-  for (tem = Vglobal_fontset_alist; CONSP (tem); tem = XCDR (tem))
-    fs_register_fontset (f, XCAR (tem));
-
   /* Extract the window parameters from the supplied values
      that are needed to determine window geometry.  */
   {
@@ -11820,7 +12279,7 @@ x_create_tip_frame (dpyinfo, parms)
     
     /* Try out a font which we hope has bold and italic variations.  */
     if (!STRINGP (font))
-      font = x_new_font (f, "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1");
+      font = x_new_font (f, "-*-courier new-normal-r-*-*-*-100-*-*-*-*-iso8859-1");
     if (!STRINGP (font))
       font = x_new_font (f, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
     if (! STRINGP (font))
@@ -11959,27 +12418,37 @@ x_create_tip_frame (dpyinfo, parms)
   FRAME_W32_DISPLAY_INFO (f)->reference_count++;
 
   return unbind_to (count, frame);
-#endif /* NTEMACS_TODO */
+#endif /* TODO */
   return Qnil;
 }
 
-
-DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 4, 0,
+#ifdef TODO /* Tooltip support not complete.  */
+DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0,
   "Show STRING in a \"tooltip\" window on frame FRAME.\n\
-A tooltip window is a small X window displaying STRING at\n\
-the current mouse position.\n\
+A tooltip window is a small X window displaying a string.\n\
+\n\
 FRAME nil or omitted means use the selected frame.\n\
+\n\
 PARMS is an optional list of frame parameters which can be\n\
 used to change the tooltip's appearance.\n\
+\n\
 Automatically hide the tooltip after TIMEOUT seconds.\n\
-TIMEOUT nil means use the default timeout of 5 seconds.")
-  (string, frame, parms, timeout)
-     Lisp_Object string, frame, parms, timeout;
+TIMEOUT nil means use the default timeout of 5 seconds.\n\
+\n\
+If the list of frame parameters PARAMS contains a `left' parameters,\n\
+the tooltip is displayed at that x-position.  Otherwise it is\n\
+displayed at the mouse position, with offset DX added (default is 5 if\n\
+DX isn't specified).  Likewise for the y-position; if a `top' frame\n\
+parameter is specified, it determines the y-position of the tooltip\n\
+window, otherwise it is displayed at the mouse position, with offset\n\
+DY added (default is -5).")
+  (string, frame, parms, timeout, dx, dy)
+     Lisp_Object string, frame, parms, timeout, dx, dy;
 {
   struct frame *f;
   struct window *w;
   Window root, child;
-  Lisp_Object buffer;
+  Lisp_Object buffer, top, left;
   struct buffer *old_buffer;
   struct text_pos pos;
   int i, width, height;
@@ -11991,7 +12460,7 @@ TIMEOUT nil means use the default timeout of 5 seconds.")
   
   specbind (Qinhibit_redisplay, Qt);
 
-  GCPRO3 (string, parms, frame, timeout);
+  GCPRO4 (string, parms, frame, timeout);
 
   CHECK_STRING (string, 0);
   f = check_x_frame (frame);
@@ -12000,6 +12469,16 @@ TIMEOUT nil means use the default timeout of 5 seconds.")
   else
     CHECK_NATNUM (timeout, 2);
 
+  if (NILP (dx))
+    dx = make_number (5);
+  else
+    CHECK_NUMBER (dx, 5);
+  
+  if (NILP (dy))
+    dy = make_number (-5);
+  else
+    CHECK_NUMBER (dy, 6);
+
   /* Hide a previous tip, if any.  */
   Fx_hide_tip ();
 
@@ -12077,17 +12556,32 @@ TIMEOUT nil means use the default timeout of 5 seconds.")
   height += 2 * FRAME_INTERNAL_BORDER_WIDTH (f);
   width += 2 * FRAME_INTERNAL_BORDER_WIDTH (f);
 
+  /* User-specified position?  */
+  left = Fcdr (Fassq (Qleft, parms));
+  top  = Fcdr (Fassq (Qtop, parms));
+  
   /* Move the tooltip window where the mouse pointer is.  Resize and
      show it.  */
-#if 0 /* NTEMACS_TODO : W32 specifics */
+#if 0 /* TODO : W32 specifics */
   BLOCK_INPUT;
-  XQueryPointer (FRAME_W32_DISPLAY (f), FRAME_W32_DISPLAY_INFO (f)->root_window,
+  XQueryPointer (FRAME_X_DISPLAY (f), FRAME_X_DISPLAY_INFO (f)->root_window,
                 &root, &child, &root_x, &root_y, &win_x, &win_y, &pmask);
-  XMoveResizeWindow (FRAME_W32_DISPLAY (f), FRAME_W32_WINDOW (f),
-                    root_x + 5, root_y - height - 5, width, height);
-  XMapRaised (FRAME_W32_DISPLAY (f), FRAME_W32_WINDOW (f));
   UNBLOCK_INPUT;
-#endif /* NTEMACS_TODO */
+
+  root_x += XINT (dx);
+  root_y += XINT (dy);
+  
+  if (INTEGERP (left))
+    root_x = XINT (left);
+  if (INTEGERP (top))
+    root_y = XINT (top);
+  
+  BLOCK_INPUT;
+  XMoveResizeWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
+                    root_x, root_y - height, width, height);
+  XMapRaised (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f));
+  UNBLOCK_INPUT;
+#endif /* TODO */
 
   /* Draw into the window.  */
   w->must_be_updated_p = 1;
@@ -12100,8 +12594,8 @@ TIMEOUT nil means use the default timeout of 5 seconds.")
   /* Let the tip disappear after timeout seconds.  */
   tip_timer = call3 (intern ("run-at-time"), timeout, Qnil,
                     intern ("x-hide-tip"));
-  UNGCPRO;
 
+  UNGCPRO;
   return unbind_to (count, Qnil);
 }
 
@@ -12134,6 +12628,7 @@ Value is t is tooltip was open, nil otherwise.")
 
   return unbind_to (count, deleted_p ? Qt : Qnil);
 }
+#endif
 
 
 \f
@@ -12243,7 +12738,7 @@ selection dialog's entry field, if MUSTMATCH is non-nil.")
   if (NILP (file))
     Fsignal (Qquit, Qnil);
 
-  return file;
+  return unbind_to (count, file);
 }
 
 
@@ -12323,7 +12818,7 @@ DEFUN ("w32-select-font", Fw32_select_font, Sw32_select_font, 0, 1, 0,
   SelectObject (hdc, oldobj);
   ReleaseDC (FRAME_W32_WINDOW (f), hdc);
 
-  if (!ChooseFont (&cf) || !w32_to_x_font (&lf, buf, 100))
+  if (!ChooseFont (&cf) || !w32_to_x_font (&lf, buf, 100, NULL))
       return Qnil;
 
   return build_string (buf);
@@ -12464,6 +12959,14 @@ w32_parse_hot_key (key)
       && !NILP (Vw32_alt_is_meta))
     lisp_modifiers |= alt_modifier;
 
+  /* Supply defs missing from mingw32.  */
+#ifndef MOD_ALT
+#define MOD_ALT         0x0001
+#define MOD_CONTROL     0x0002
+#define MOD_SHIFT       0x0004
+#define MOD_WIN         0x0008
+#endif
+
   /* Convert lisp modifiers to Windows hot-key form.  */
   w32_modifiers  = (lisp_modifiers & hyper_modifier)    ? MOD_WIN : 0;
   w32_modifiers |= (lisp_modifiers & alt_modifier)      ? MOD_ALT : 0;
@@ -12675,12 +13178,12 @@ syms_of_w32fns ()
   staticpro (&Quser_position);
   Quser_size = intern ("user-size");
   staticpro (&Quser_size);
-#if 0 /* Duplicate initialization in xdisp.c */
-  Qdisplay = intern ("display");
-  staticpro (&Qdisplay);
-#endif
   Qscreen_gamma = intern ("screen-gamma");
   staticpro (&Qscreen_gamma);
+  Qline_spacing = intern ("line-spacing");
+  staticpro (&Qline_spacing);
+  Qcenter = intern ("center");
+  staticpro (&Qcenter);
   /* This is the end of symbol initialization.  */
 
   Qhyper = intern ("hyper");
@@ -12804,7 +13307,7 @@ respective modifier, or nil to appear as the key `apps'.\n\
 Any other value will cause the key to be ignored.");
   Vw32_apps_modifier = Qnil;
 
-  DEFVAR_LISP ("w32-enable-synthesized_fonts", &Vw32_enable_synthesized_fonts,
+  DEFVAR_LISP ("w32-enable-synthesized-fonts", &Vw32_enable_synthesized_fonts,
     "Non-nil enables selection of artificially italicized and bold fonts.");
   Vw32_enable_synthesized_fonts = Qnil;
 
@@ -12864,6 +13367,11 @@ or when you set the mouse color.");
     "Non-zero means Emacs displays a busy cursor on window systems.");
   display_busy_cursor_p = 1;
   
+  DEFVAR_LISP ("busy-cursor-delay", &Vbusy_cursor_delay,
+     "*Seconds to wait before displaying a busy-cursor.\n\
+Value must be an integer or float.");
+  Vbusy_cursor_delay = make_number (DEFAULT_BUSY_CURSOR_DELAY);
+
   DEFVAR_LISP ("x-sensitive-text-pointer-shape",
              &Vx_sensitive_text_pointer_shape,
              "The shape of the pointer when over mouse-sensitive text.\n\
@@ -12871,6 +13379,13 @@ This variable takes effect when you create a new frame\n\
 or when you set the mouse color.");
   Vx_sensitive_text_pointer_shape = Qnil;
 
+  DEFVAR_LISP ("x-window-horizontal-drag-cursor",
+             &Vx_window_horizontal_drag_shape,
+  "Pointer shape to use for indicating a window can be dragged horizontally.\n\
+This variable takes effect when you create a new frame\n\
+or when you set the mouse color.");
+  Vx_window_horizontal_drag_shape = Qnil;
+
   DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel,
               "A string indicating the foreground color of the cursor box.");
   Vx_cursor_fore_pixel = Qnil;
@@ -12900,11 +13415,6 @@ from the image cache.  Value must be an integer or nil with nil\n\
 meaning don't clear the cache.");
   Vimage_cache_eviction_delay = make_number (30 * 60);
 
-  DEFVAR_LISP ("image-types", &Vimage_types,
-     "List of supported image types.\n\
-Each element of the list is a symbol for a supported image type.");
-  Vimage_types = Qnil;
-
   DEFVAR_LISP ("w32-bdf-filename-alist",
                &Vw32_bdf_filename_alist,
                "List of bdf fonts and their corresponding filenames.");
@@ -12932,8 +13442,91 @@ only be necessary if the default setting causes problems.");
   "Coding system used by Windows system functions, such as for font names.");
   Vw32_system_coding_system = Qnil;
 
+  DEFVAR_LISP ("w32-charset-info-alist",
+               &Vw32_charset_info_alist,
+               "Alist linking Emacs character sets to Windows fonts\n\
+and codepages. Each entry should be of the form:\n\
+\n\
+   (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE))\n\
+\n\
+where CHARSET_NAME is a string used in font names to identify the charset,\n\
+WINDOWS_CHARSET is a symbol that can be one of:\n\
+w32-charset-ansi, w32-charset-default, w32-charset-symbol,\n\
+w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312,\n\
+w32-charset-chinesebig5, "
+#ifdef JOHAB_CHARSET
+"w32-charset-johab, w32-charset-hebrew,\n\
+w32-charset-arabic, w32-charset-greek, w32-charset-turkish,\n\
+w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope,\n\
+w32-charset-russian, w32-charset-mac, w32-charset-baltic,\n"
+#endif
+#ifdef UNICODE_CHARSET
+"w32-charset-unicode, "
+#endif
+"or w32-charset-oem.\n\
+CODEPAGE should be an integer specifying the codepage that should be used\n\
+to display the character set, t to do no translation and output as Unicode,\n\
+or nil to do no translation and output as 8 bit (or multibyte on far-east\n\
+versions of Windows) characters.");
+    Vw32_charset_info_alist = Qnil;
+
+  staticpro (&Qw32_charset_ansi);
+  Qw32_charset_ansi = intern ("w32-charset-ansi");
+  staticpro (&Qw32_charset_symbol);
+  Qw32_charset_symbol = intern ("w32-charset-symbol");
+  staticpro (&Qw32_charset_shiftjis);
+  Qw32_charset_shiftjis = intern ("w32-charset-shiftjis");
+  staticpro (&Qw32_charset_hangeul);
+  Qw32_charset_hangeul = intern ("w32-charset-hangeul");
+  staticpro (&Qw32_charset_chinesebig5);
+  Qw32_charset_chinesebig5 = intern ("w32-charset-chinesebig5");
+  staticpro (&Qw32_charset_gb2312);
+  Qw32_charset_gb2312 = intern ("w32-charset-gb2312");
+  staticpro (&Qw32_charset_oem);
+  Qw32_charset_oem = intern ("w32-charset-oem");
+
+#ifdef JOHAB_CHARSET
+  {
+    static int w32_extra_charsets_defined = 1;
+    DEFVAR_BOOL ("w32-extra-charsets-defined", &w32_extra_charsets_defined, "");
+
+    staticpro (&Qw32_charset_johab);
+    Qw32_charset_johab = intern ("w32-charset-johab");
+    staticpro (&Qw32_charset_easteurope);
+    Qw32_charset_easteurope = intern ("w32-charset-easteurope");
+    staticpro (&Qw32_charset_turkish);
+    Qw32_charset_turkish = intern ("w32-charset-turkish");
+    staticpro (&Qw32_charset_baltic);
+    Qw32_charset_baltic = intern ("w32-charset-baltic");
+    staticpro (&Qw32_charset_russian);
+    Qw32_charset_russian = intern ("w32-charset-russian");
+    staticpro (&Qw32_charset_arabic);
+    Qw32_charset_arabic = intern ("w32-charset-arabic");
+    staticpro (&Qw32_charset_greek);
+    Qw32_charset_greek = intern ("w32-charset-greek");
+    staticpro (&Qw32_charset_hebrew);
+    Qw32_charset_hebrew = intern ("w32-charset-hebrew");
+    staticpro (&Qw32_charset_vietnamese);
+    Qw32_charset_vietnamese = intern ("w32-charset-vietnamese");
+    staticpro (&Qw32_charset_thai);
+    Qw32_charset_thai = intern ("w32-charset-thai");
+    staticpro (&Qw32_charset_mac);
+    Qw32_charset_mac = intern ("w32-charset-mac");
+  }
+#endif
+
+#ifdef UNICODE_CHARSET
+  {
+    static int w32_unicode_charset_defined = 1;
+    DEFVAR_BOOL ("w32-unicode-charset-defined",
+                 &w32_unicode_charset_defined, "");
+
+    staticpro (&Qw32_charset_unicode);
+    Qw32_charset_unicode = intern ("w32-charset-unicode");
+#endif
+
   defsubr (&Sx_get_resource);
-#if 0 /* NTEMACS_TODO: Port to W32 */
+#if 0 /* TODO: Port to W32 */
   defsubr (&Sx_change_window_property);
   defsubr (&Sx_delete_window_property);
   defsubr (&Sx_window_property);
@@ -12992,7 +13585,7 @@ only be necessary if the default setting causes problems.");
   set_frame_fontset_func = x_set_font;
   check_window_system_func = check_w32;
 
-#if 0 /* NTEMACS_TODO Image support for W32 */
+#if 0 /* TODO Image support for W32 */
   /* Images.  */
   Qxbm = intern ("xbm");
   staticpro (&Qxbm);
@@ -13004,8 +13597,6 @@ only be necessary if the default setting causes problems.");
   staticpro (&QCheuristic_mask);
   QCcolor_symbols = intern (":color-symbols");
   staticpro (&QCcolor_symbols);
-  QCdata = intern (":data");
-  staticpro (&QCdata);
   QCascent = intern (":ascent");
   staticpro (&QCascent);
   QCmargin = intern (":margin");
@@ -13058,16 +13649,14 @@ only be necessary if the default setting causes problems.");
   defsubr (&Simagep);
   defsubr (&Slookup_image);
 #endif
-#endif /* NTEMACS_TODO */
-
-  /* Busy-cursor.  */
-  defsubr (&Sx_show_busy_cursor);
-  defsubr (&Sx_hide_busy_cursor);
-  busy_count = 0;
-  inhibit_busy_cursor = 0;
+#endif /* TODO */
 
+  busy_cursor_atimer = NULL;
+  busy_cursor_shown_p = 0;
+#ifdef TODO /* Tooltip support not complete.  */
   defsubr (&Sx_show_tip);
   defsubr (&Sx_hide_tip);
+#endif
   staticpro (&tip_timer);
   tip_timer = Qnil;
 
@@ -13081,7 +13670,7 @@ init_xfns ()
   image_types = NULL;
   Vimage_types = Qnil;
 
-#if 0 /* NTEMACS_TODO : Image support for W32 */
+#if 0 /* TODO : Image support for W32 */
   define_image_type (&xbm_type);
   define_image_type (&gs_type);
   define_image_type (&pbm_type);
@@ -13105,7 +13694,7 @@ init_xfns ()
 #if HAVE_PNG
   define_image_type (&png_type);
 #endif
-#endif /* NTEMACS_TODO */
+#endif /* TODO */
 }
 
 #undef abort