* lisp.h: (XVECTOR_SIZE): Remove. All uses replaced with ASIZE.
[bpt/emacs.git] / src / w32menu.c
index fb54caf..c8c6a31 100644 (file)
@@ -1,6 +1,5 @@
 /* Menu support for GNU Emacs on the Microsoft W32 API.
-   Copyright (C) 1986, 1988, 1993, 1994, 1996, 1998, 1999, 2001, 2002,
-                 2003, 2004, 2005, 2006, 2007, 2008
+   Copyright (C) 1986, 1988, 1993-1994, 1996, 1998-1999, 2001-2011
                  Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
@@ -23,6 +22,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <signal.h>
 #include <stdio.h>
 #include <mbstring.h>
+#include <setjmp.h>
 
 #include "lisp.h"
 #include "keyboard.h"
@@ -35,6 +35,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "charset.h"
 #include "character.h"
 #include "coding.h"
+#include "menu.h"
 
 /* This may include sys/types.h, and that somehow loses
    if this is not done before the other system files.  */
@@ -57,8 +58,8 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 HMENU current_popup_menu;
 
-void syms_of_w32menu ();
-void globals_of_w32menu ();
+void syms_of_w32menu (void);
+void globals_of_w32menu (void);
 
 typedef BOOL (WINAPI * GetMenuItemInfoA_Proc) (
     IN HMENU,
@@ -70,38 +71,32 @@ typedef BOOL (WINAPI * SetMenuItemInfoA_Proc) (
     IN UINT,
     IN BOOL,
     IN LPCMENUITEMINFOA);
+typedef int (WINAPI * MessageBoxW_Proc) (
+    IN HWND window,
+    IN WCHAR *text,
+    IN WCHAR *caption,
+    IN UINT type);
 
 GetMenuItemInfoA_Proc get_menu_item_info = NULL;
 SetMenuItemInfoA_Proc set_menu_item_info = NULL;
 AppendMenuW_Proc unicode_append_menu = NULL;
+MessageBoxW_Proc unicode_message_box = NULL;
 
 Lisp_Object Qdebug_on_next_call;
 
-extern Lisp_Object Vmenu_updating_frame;
-
-extern Lisp_Object Qmenu_bar;
-
-extern Lisp_Object QCtoggle, QCradio;
-
-extern Lisp_Object Voverriding_local_map;
-extern Lisp_Object Voverriding_local_map_menu_flag;
-
-extern Lisp_Object Qoverriding_local_map, Qoverriding_terminal_local_map;
-
-extern Lisp_Object Qmenu_bar_update_hook;
-
-void set_frame_menubar P_ ((FRAME_PTR, int, int));
+void set_frame_menubar (FRAME_PTR, int, int);
 
 #ifdef HAVE_DIALOGS
-static Lisp_Object w32_dialog_show P_ ((FRAME_PTR, int, Lisp_Object, char**));
+static Lisp_Object w32_dialog_show (FRAME_PTR, int, Lisp_Object, char**);
 #else
-static int is_simple_dialog P_ ((Lisp_Object));
-static Lisp_Object simple_dialog_show P_ ((FRAME_PTR, Lisp_Object, Lisp_Object));
+static int is_simple_dialog (Lisp_Object);
+static Lisp_Object simple_dialog_show (FRAME_PTR, Lisp_Object, Lisp_Object);
 #endif
-static Lisp_Object w32_menu_show P_ ((FRAME_PTR, int, int, int, int,
-                                     Lisp_Object, char **));
 
-void w32_free_menu_strings P_((HWND));
+static void utf8to16 (unsigned char *, int, WCHAR *);
+static int fill_in_menu (HMENU, widget_value *);
+
+void w32_free_menu_strings (HWND);
 \f
 
 /* This is set nonzero after the user activates the menu bar, and set
@@ -113,269 +108,6 @@ void w32_free_menu_strings P_((HWND));
 
 int pending_menu_activation;
 \f
-
-/* Return the frame whose ->output_data.w32->menubar_widget equals
-   ID, or 0 if none.  */
-
-static struct frame *
-menubar_id_to_frame (id)
-     HMENU id;
-{
-  Lisp_Object tail, frame;
-  FRAME_PTR f;
-
-  for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
-    {
-      frame = XCAR (tail);
-      if (!FRAMEP (frame))
-        continue;
-      f = XFRAME (frame);
-      if (!FRAME_WINDOW_P (f))
-       continue;
-      if (f->output_data.w32->menubar_widget == id)
-       return f;
-    }
-  return 0;
-}
-\f
-DEFUN ("x-popup-menu", Fx_popup_menu, Sx_popup_menu, 2, 2, 0,
-       doc: /* Pop up a deck-of-cards menu and return user's selection.
-POSITION is a position specification.  This is either a mouse button
-event or a list ((XOFFSET YOFFSET) WINDOW) where XOFFSET and YOFFSET
-are positions in pixels from the top left corner of WINDOW's frame
-\(WINDOW may be a frame object instead of a window).  This controls the
-position of the center of the first line in the first pane of the
-menu, not the top left of the menu as a whole.  If POSITION is t, it
-means to use the current mouse position.
-
-MENU is a specifier for a menu.  For the simplest case, MENU is a keymap.
-The menu items come from key bindings that have a menu string as well as
-a definition; actually, the \"definition\" in such a key binding looks like
-\(STRING . REAL-DEFINITION).  To give the menu a title, put a string into
-the keymap as a top-level element.
-
-If REAL-DEFINITION is nil, that puts a nonselectable string in the menu.
-Otherwise, REAL-DEFINITION should be a valid key binding definition.
-
-You can also use a list of keymaps as MENU.  Then each keymap makes a
-separate pane.  When MENU is a keymap or a list of keymaps, the return
-value is a list of events.
-
-Alternatively, you can specify a menu of multiple panes with a list of
-the form (TITLE PANE1 PANE2...), where each pane is a list of
-form (TITLE ITEM1 ITEM2...).
-Each ITEM is normally a cons cell (STRING . VALUE); but a string can
-appear as an item--that makes a nonselectable line in the menu.
-With this form of menu, the return value is VALUE from the chosen item.
-
-If POSITION is nil, don't display the menu at all, just precalculate the
-cached information about equivalent key sequences.  */)
-  (position, menu)
-     Lisp_Object position, menu;
-{
-  Lisp_Object keymap, tem;
-  int xpos = 0, ypos = 0;
-  Lisp_Object title;
-  char *error_name;
-  Lisp_Object selection;
-  FRAME_PTR f = NULL;
-  Lisp_Object x, y, window;
-  int keymaps = 0;
-  int for_click = 0;
-  int specpdl_count = SPECPDL_INDEX ();
-  struct gcpro gcpro1;
-
-#ifdef HAVE_MENUS
-  if (! NILP (position))
-    {
-      check_w32 ();
-
-      /* Decode the first argument: find the window and the coordinates.  */
-      if (EQ (position, Qt)
-         || (CONSP (position) && (EQ (XCAR (position), Qmenu_bar)
-                                   || EQ (XCAR (position), Qtool_bar))))
-       {
-         /* Use the mouse's current position.  */
-         FRAME_PTR new_f = SELECTED_FRAME ();
-         Lisp_Object bar_window;
-         enum scroll_bar_part part;
-         unsigned long time;
-
-         if (FRAME_TERMINAL (new_f)->mouse_position_hook)
-           (*FRAME_TERMINAL (new_f)->mouse_position_hook) (&new_f, 1, &bar_window,
-                                   &part, &x, &y, &time);
-         if (new_f != 0)
-           XSETFRAME (window, new_f);
-         else
-           {
-             window = selected_window;
-             XSETFASTINT (x, 0);
-             XSETFASTINT (y, 0);
-           }
-       }
-      else
-       {
-         tem = Fcar (position);
-         if (CONSP (tem))
-           {
-             window = Fcar (Fcdr (position));
-             x = Fcar (tem);
-             y = Fcar (Fcdr (tem));
-           }
-         else
-           {
-             for_click = 1;
-             tem = Fcar (Fcdr (position));  /* EVENT_START (position) */
-             window = Fcar (tem);           /* POSN_WINDOW (tem) */
-             tem = Fcar (Fcdr (Fcdr (tem))); /* POSN_WINDOW_POSN (tem) */
-             x = Fcar (tem);
-             y = Fcdr (tem);
-           }
-       }
-
-      CHECK_NUMBER (x);
-      CHECK_NUMBER (y);
-
-      /* Decode where to put the menu.  */
-
-      if (FRAMEP (window))
-       {
-         f = XFRAME (window);
-         xpos = 0;
-         ypos = 0;
-       }
-      else if (WINDOWP (window))
-       {
-         CHECK_LIVE_WINDOW (window);
-         f = XFRAME (WINDOW_FRAME (XWINDOW (window)));
-
-         xpos = WINDOW_LEFT_EDGE_X (XWINDOW (window));
-         ypos = WINDOW_TOP_EDGE_Y (XWINDOW (window));
-       }
-      else
-       /* ??? Not really clean; should be CHECK_WINDOW_OR_FRAME,
-          but I don't want to make one now.  */
-       CHECK_WINDOW (window);
-
-      xpos += XINT (x);
-      ypos += XINT (y);
-
-      XSETFRAME (Vmenu_updating_frame, f);
-    }
-  else
-    Vmenu_updating_frame = Qnil;
-#endif /* HAVE_MENUS */
-
-  record_unwind_protect (unuse_menu_items, Qnil);
-
-  title = Qnil;
-  GCPRO1 (title);
-
-  /* Decode the menu items from what was specified.  */
-
-  keymap = get_keymap (menu, 0, 0);
-  if (CONSP (keymap))
-    {
-      /* We were given a keymap.  Extract menu info from the keymap.  */
-      Lisp_Object prompt;
-
-      /* Extract the detailed info to make one pane.  */
-      keymap_panes (&menu, 1, NILP (position));
-
-      /* Search for a string appearing directly as an element of the keymap.
-        That string is the title of the menu.  */
-      prompt = Fkeymap_prompt (keymap);
-      if (NILP (title) && !NILP (prompt))
-       title = prompt;
-
-      /* Make that be the pane title of the first pane.  */
-      if (!NILP (prompt) && menu_items_n_panes >= 0)
-       ASET (menu_items, MENU_ITEMS_PANE_NAME, prompt);
-
-      keymaps = 1;
-    }
-  else if (CONSP (menu) && KEYMAPP (XCAR (menu)))
-    {
-      /* We were given a list of keymaps.  */
-      int nmaps = XFASTINT (Flength (menu));
-      Lisp_Object *maps
-       = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object));
-      int i;
-
-      title = Qnil;
-
-      /* The first keymap that has a prompt string
-        supplies the menu title.  */
-      for (tem = menu, i = 0; CONSP (tem); tem = Fcdr (tem))
-       {
-         Lisp_Object prompt;
-
-         maps[i++] = keymap = get_keymap (Fcar (tem), 1, 0);
-
-         prompt = Fkeymap_prompt (keymap);
-         if (NILP (title) && !NILP (prompt))
-           title = prompt;
-       }
-
-      /* Extract the detailed info to make one pane.  */
-      keymap_panes (maps, nmaps, NILP (position));
-
-      /* Make the title be the pane title of the first pane.  */
-      if (!NILP (title) && menu_items_n_panes >= 0)
-       ASET (menu_items, MENU_ITEMS_PANE_NAME, title);
-
-      keymaps = 1;
-    }
-  else
-    {
-      /* We were given an old-fashioned menu.  */
-      title = Fcar (menu);
-      CHECK_STRING (title);
-
-      list_of_panes (Fcdr (menu));
-
-      keymaps = 0;
-    }
-
-  unbind_to (specpdl_count, Qnil);
-
-  if (NILP (position))
-    {
-      discard_menu_items ();
-      UNGCPRO;
-      return Qnil;
-    }
-
-#ifdef HAVE_MENUS
-  /* If resources from a previous popup menu still exist, does nothing
-     until the `menu_free_timer' has freed them (see w32fns.c). This
-     can occur if you press ESC or click outside a menu without selecting
-     a menu item.
-  */
-  if (current_popup_menu)
-    {
-      discard_menu_items ();
-      UNGCPRO;
-      return Qnil;
-    }
-
-  /* Display them in a menu.  */
-  BLOCK_INPUT;
-
-  selection = w32_menu_show (f, xpos, ypos, for_click,
-                            keymaps, title, &error_name);
-  UNBLOCK_INPUT;
-
-  discard_menu_items ();
-
-#endif /* HAVE_MENUS */
-
-  UNGCPRO;
-
-  if (error_name) error (error_name);
-  return selection;
-}
-
 #ifdef HAVE_MENUS
 
 DEFUN ("x-popup-dialog", Fx_popup_dialog, Sx_popup_dialog, 2, 3, 0,
@@ -397,8 +129,7 @@ on the left of the dialog box and all following items on the right.
 
 If HEADER is non-nil, the frame title for the box is "Information",
 otherwise it is "Question". */)
-  (position, contents, header)
-     Lisp_Object position, contents, header;
+  (Lisp_Object position, Lisp_Object contents, Lisp_Object header)
 {
   FRAME_PTR f = NULL;
   Lisp_Object window;
@@ -495,6 +226,7 @@ otherwise it is "Question". */)
     UNBLOCK_INPUT;
 
     discard_menu_items ();
+    FRAME_X_DISPLAY_INFO (f)->grabbed = 0;
 
     if (error_name) error (error_name);
     return selection;
@@ -515,8 +247,7 @@ otherwise it is "Question". */)
    This way we can safely execute Lisp code.  */
 
 void
-x_activate_menubar (f)
-     FRAME_PTR f;
+x_activate_menubar (FRAME_PTR f)
 {
   set_frame_menubar (f, 0, 1);
 
@@ -625,10 +356,7 @@ menubar_selection_callback (FRAME_PTR f, void * client_data)
    it is set the first time this is called, from initialize_frame_menubar.  */
 
 void
-set_frame_menubar (f, first_time, deep_p)
-     FRAME_PTR f;
-     int first_time;
-     int deep_p;
+set_frame_menubar (FRAME_PTR f, int first_time, int deep_p)
 {
   HMENU menubar_widget = f->output_data.w32->menubar_widget;
   Lisp_Object items;
@@ -681,12 +409,8 @@ set_frame_menubar (f, first_time, deep_p)
 
       set_buffer_internal_1 (XBUFFER (buffer));
 
-      /* Run the Lucid hook.  */
+      /* Run the hooks.  */
       safe_run_hooks (Qactivate_menubar_hook);
-      /* If it has changed current-menubar from previous value,
-        really recompute the menubar from the value.  */
-      if (! NILP (Vlucid_menu_bar_dirty_flag))
-       call0 (Qrecompute_lucid_menubar);
       safe_run_hooks (Qmenu_bar_update_hook);
       FRAME_MENU_BAR_ITEMS (f) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f));
 
@@ -694,8 +418,8 @@ set_frame_menubar (f, first_time, deep_p)
 
       /* Save the frame's previous menu bar contents data.  */
       if (previous_menu_items_used)
-       bcopy (XVECTOR (f->menu_bar_vector)->contents, previous_items,
-              previous_menu_items_used * sizeof (Lisp_Object));
+       memcpy (previous_items, XVECTOR (f->menu_bar_vector)->contents,
+               previous_menu_items_used * sizeof (Lisp_Object));
 
       /* Fill in menu_items with the current menu bar contents.
         This can evaluate Lisp code.  */
@@ -703,11 +427,11 @@ set_frame_menubar (f, first_time, deep_p)
 
       menu_items = f->menu_bar_vector;
       menu_items_allocated = VECTORP (menu_items) ? ASIZE (menu_items) : 0;
-      submenu_start = (int *) alloca (XVECTOR (items)->size * sizeof (int *));
-      submenu_end = (int *) alloca (XVECTOR (items)->size * sizeof (int *));
-      submenu_n_panes = (int *) alloca (XVECTOR (items)->size * sizeof (int));
+      submenu_start = (int *) alloca (ASIZE (items) * sizeof (int *));
+      submenu_end = (int *) alloca (ASIZE (items) * sizeof (int *));
+      submenu_n_panes = (int *) alloca (ASIZE (items) * sizeof (int));
       submenu_top_level_items
-       = (int *) alloca (XVECTOR (items)->size * sizeof (int *));
+       = (int *) alloca (ASIZE (items) * sizeof (int *));
       init_menu_items ();
       for (i = 0; i < ASIZE (items); i += 4)
        {
@@ -794,7 +518,7 @@ set_frame_menubar (f, first_time, deep_p)
          string = AREF (items, i + 1);
          if (NILP (string))
            break;
-         wv->name = (char *) SDATA (string);
+         wv->name = SSDATA (string);
          update_submenu_strings (wv->contents);
          wv = wv->next;
        }
@@ -822,7 +546,7 @@ set_frame_menubar (f, first_time, deep_p)
            break;
 
          wv = xmalloc_widget_value ();
-         wv->name = (char *) SDATA (string);
+         wv->name = SSDATA (string);
          wv->value = 0;
          wv->enabled = 1;
          wv->button_type = BUTTON_TYPE_NONE;
@@ -887,8 +611,7 @@ set_frame_menubar (f, first_time, deep_p)
    is visible.  */
 
 void
-initialize_frame_menubar (f)
-     FRAME_PTR f;
+initialize_frame_menubar (FRAME_PTR f)
 {
   /* This function is called before the first chance to redisplay
      the frame.  It has to be, so the frame will have the right size.  */
@@ -900,8 +623,7 @@ initialize_frame_menubar (f)
    This is used when deleting a frame, and when turning off the menu bar.  */
 
 void
-free_frame_menubar (f)
-     FRAME_PTR f;
+free_frame_menubar (FRAME_PTR f)
 {
   BLOCK_INPUT;
 
@@ -931,15 +653,9 @@ free_frame_menubar (f)
    ERROR is a place to store an error message string in case of failure.
    (We return nil on failure, but the value doesn't actually matter.)  */
 
-static Lisp_Object
-w32_menu_show (f, x, y, for_click, keymaps, title, error)
-     FRAME_PTR f;
-     int x;
-     int y;
-     int for_click;
-     int keymaps;
-     Lisp_Object title;
-     char **error;
+Lisp_Object
+w32_menu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps,
+              Lisp_Object title, const char **error)
 {
   int i;
   int menu_item_selection;
@@ -1020,7 +736,7 @@ w32_menu_show (f, x, y, for_click, keymaps, title, error)
            }
 
          pane_string = (NILP (pane_name)
-                        ? "" : (char *) SDATA (pane_name));
+                        ? "" : SSDATA (pane_name));
          /* If there is just one top-level pane, put all its items directly
             under the top-level menu.  */
          if (menu_items_n_panes == 1)
@@ -1088,9 +804,9 @@ w32_menu_show (f, x, y, for_click, keymaps, title, error)
            prev_wv->next = wv;
          else
            save_wv->contents = wv;
-         wv->name = (char *) SDATA (item_name);
+         wv->name = SSDATA (item_name);
          if (!NILP (descrip))
-           wv->key = (char *) SDATA (descrip);
+           wv->key = SSDATA (descrip);
          wv->value = 0;
          /* Use the contents index as call_data, since we are
              restricted to 16-bits.  */
@@ -1136,7 +852,7 @@ w32_menu_show (f, x, y, for_click, keymaps, title, error)
       else if (STRING_MULTIBYTE (title))
        title = ENCODE_SYSTEM (title);
 
-      wv_title->name = (char *) SDATA (title);
+      wv_title->name = SSDATA (title);
       wv_title->enabled = TRUE;
       wv_title->title = TRUE;
       wv_title->button_type = BUTTON_TYPE_NONE;
@@ -1165,6 +881,7 @@ w32_menu_show (f, x, y, for_click, keymaps, title, error)
   /* Clean up extraneous mouse events which might have been generated
      during the call. */
   discard_mouse_events ();
+  FRAME_X_DISPLAY_INFO (f)->grabbed = 0;
 
   /* Free the widget_value objects we used to specify the contents.  */
   free_menubar_widget_value_tree (first_wv);
@@ -1264,13 +981,11 @@ static char * button_names [] = {
   "button6", "button7", "button8", "button9", "button10" };
 
 static Lisp_Object
-w32_dialog_show (f, keymaps, title, header, error)
-     FRAME_PTR f;
-     int keymaps;
-     Lisp_Object title, header;
-     char **error;
+w32_dialog_show (FRAME_PTR f, int keymaps,
+                Lisp_Object title, Lisp_Object header,
+                char **error)
 {
-  int i, nb_buttons=0;
+  int i, nb_buttons = 0;
   char dialog_name[6];
   int menu_item_selection;
 
@@ -1297,7 +1012,7 @@ w32_dialog_show (f, keymaps, title, header, error)
     pane_name = AREF (menu_items, MENU_ITEMS_PANE_NAME);
     prefix = AREF (menu_items, MENU_ITEMS_PANE_PREFIX);
     pane_string = (NILP (pane_name)
-                  ? "" : (char *) SDATA (pane_name));
+                  ? "" : SSDATA (pane_name));
     prev_wv = xmalloc_widget_value ();
     prev_wv->value = pane_string;
     if (keymaps && !NILP (prefix))
@@ -1345,8 +1060,8 @@ w32_dialog_show (f, keymaps, title, header, error)
        prev_wv->next = wv;
        wv->name = (char *) button_names[nb_buttons];
        if (!NILP (descrip))
-         wv->key = (char *) SDATA (descrip);
-       wv->value = (char *) SDATA (item_name);
+         wv->key = SSDATA (descrip);
+       wv->value = SSDATA (item_name);
        wv->call_data = (void *) &AREF (menu_items, i);
        wv->enabled = !NILP (enable);
        wv->help = Qnil;
@@ -1371,7 +1086,7 @@ w32_dialog_show (f, keymaps, title, header, error)
     /*  Frame title: 'Q' = Question, 'I' = Information.
         Can also have 'E' = Error if, one day, we want
         a popup for errors. */
-    if (NILP(header))
+    if (NILP (header))
       dialog_name[0] = 'Q';
     else
       dialog_name[0] = 'I';
@@ -1457,8 +1172,8 @@ w32_dialog_show (f, keymaps, title, header, error)
    anywhere in Emacs that uses the other specific dialog choices that
    MessageBox provides.  */
 
-static int is_simple_dialog (contents)
-  Lisp_Object contents;
+static int
+is_simple_dialog (Lisp_Object contents)
 {
   Lisp_Object options = XCDR (contents);
   Lisp_Object name, yes, no, other;
@@ -1493,36 +1208,78 @@ static int is_simple_dialog (contents)
   return !(CONSP (options));
 }
 
-static Lisp_Object simple_dialog_show (f, contents, header)
-     FRAME_PTR f;
-     Lisp_Object contents, header;
+static Lisp_Object
+simple_dialog_show (FRAME_PTR f, Lisp_Object contents, Lisp_Object header)
 {
   int answer;
   UINT type;
-  char *text, *title;
   Lisp_Object lispy_answer = Qnil, temp = XCAR (contents);
 
-  if (STRINGP (temp))
-    text = SDATA (temp);
-  else
-    text = "";
+  type = MB_YESNO;
+
+  /* Since we only handle Yes/No dialogs, and we already checked
+     is_simple_dialog, we don't need to worry about checking contents
+     to see what type of dialog to use.  */
 
-  if (NILP (header))
+  /* Use unicode if possible, so any language can be displayed.  */
+  if (unicode_message_box)
     {
-      title = "Question";
-      type = MB_ICONQUESTION;
+      WCHAR *text, *title;
+
+      if (STRINGP (temp))
+       {
+         char *utf8_text = SDATA (ENCODE_UTF_8 (temp));
+         /* Be pessimistic about the number of characters needed.
+            Remember characters outside the BMP will take more than
+            one utf16 word, so we cannot simply use the character
+            length of temp.  */
+         int utf8_len = strlen (utf8_text);
+         text = alloca ((utf8_len + 1) * sizeof (WCHAR));
+         utf8to16 (utf8_text, utf8_len, text);
+       }
+      else
+       {
+         text = L"";
+       }
+
+      if (NILP (header))
+       {
+         title = L"Question";
+         type |= MB_ICONQUESTION;
+       }
+      else
+       {
+         title = L"Information";
+         type |= MB_ICONINFORMATION;
+       }
+
+      answer = unicode_message_box (FRAME_W32_WINDOW (f), text, title, type);
     }
   else
     {
-      title = "Information";
-      type = MB_ICONINFORMATION;
-    }
-  type |= MB_YESNO;
+      char *text, *title;
 
-  /* Since we only handle Yes/No dialogs, and we already checked
-     is_simple_dialog, we don't need to worry about checking contents
-     to see what type of dialog to use.  */
-  answer = MessageBox (FRAME_W32_WINDOW (f), text, title, type);
+      /* Fall back on ANSI message box, but at least use system
+        encoding so questions representable by the system codepage
+        are encoded properly.  */
+      if (STRINGP (temp))
+       text = SDATA (ENCODE_SYSTEM (temp));
+      else
+       text = "";
+
+      if (NILP (header))
+       {
+         title = "Question";
+         type |= MB_ICONQUESTION;
+       }
+      else
+       {
+         title = "Information";
+         type |= MB_ICONINFORMATION;
+       }
+
+      answer = MessageBox (FRAME_W32_WINDOW (f), text, title, type);
+    }
 
   if (answer == IDYES)
     lispy_answer = build_string ("Yes");
@@ -1557,36 +1314,12 @@ static Lisp_Object simple_dialog_show (f, contents, header)
 #endif  /* !HAVE_DIALOGS  */
 \f
 
-/* Is this item a separator? */
-static int
-name_is_separator (name)
-     char *name;
-{
-  char *start = name;
-
-  /* Check if name string consists of only dashes ('-').  */
-  while (*name == '-') name++;
-  /* Separators can also be of the form "--:TripleSuperMegaEtched"
-     or "--deep-shadow".  We don't implement them yet, se we just treat
-     them like normal separators.  */
-  return (*name == '\0' || start + 2 == name);
-}
-
-
-/* Indicate boundary between left and right.  */
-static int
-add_left_right_boundary (HMENU menu)
-{
-  return AppendMenu (menu, MF_MENUBARBREAK, 0, NULL);
-}
-
 /* UTF8: 0xxxxxxx, 110xxxxx 10xxxxxx, 1110xxxx, 10xxxxxx, 10xxxxxx */
 static void
 utf8to16 (unsigned char * src, int len, WCHAR * dest)
 {
   while (len > 0)
     {
-      int utf16;
       if (*src < 0x80)
        {
          *dest = (WCHAR) *src;
@@ -1628,7 +1361,7 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item)
   int return_value;
   size_t nlen, orig_len;
 
-  if (name_is_separator (wv->name))
+  if (menu_separator_name_p (wv->name))
     {
       fuFlags = MF_SEPARATOR;
       out_string = NULL;
@@ -1648,7 +1381,7 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item)
          strcat (out_string, wv->key);
        }
       else
-       out_string = wv->name;
+       out_string = (char *)wv->name;
 
       /* Quote any special characters within the menu item's text and
         key binding.  */
@@ -1777,7 +1510,7 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item)
       if (set_menu_item_info)
        {
          MENUITEMINFO info;
-         bzero (&info, sizeof (info));
+         memset (&info, 0, sizeof (info));
          info.cbSize = sizeof (info);
          info.fMask = MIIM_DATA;
 
@@ -1809,11 +1542,9 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item)
 }
 
 /* Construct native Windows menu(bar) based on widget_value tree.  */
-int
+static int
 fill_in_menu (HMENU menu, widget_value *wv)
 {
-  int items_added = 0;
-
   for ( ; wv != NULL; wv = wv->next)
     {
       if (wv->contents)
@@ -1860,7 +1591,7 @@ w32_menu_display_help (HWND owner, HMENU menu, UINT item, UINT flags)
        {
          MENUITEMINFO info;
 
-         bzero (&info, sizeof (info));
+         memset (&info, 0, sizeof (info));
          info.cbSize = sizeof (info);
          info.fMask = MIIM_DATA;
          get_menu_item_info (menu, item, FALSE, &info);
@@ -1885,20 +1616,19 @@ w32_menu_display_help (HWND owner, HMENU menu, UINT item, UINT flags)
       else
        /* X version has a loop through frames here, which doesn't
           appear to do anything, unless it has some side effect.  */
-       show_help_echo (help, Qnil, Qnil, Qnil, 1);
+       show_help_echo (help, Qnil, Qnil, Qnil);
     }
 }
 
 /* Free memory used by owner-drawn strings.  */
 static void
-w32_free_submenu_strings (menu)
-     HMENU menu;
+w32_free_submenu_strings (HMENU menu)
 {
   int i, num = GetMenuItemCount (menu);
   for (i = 0; i < num; i++)
     {
       MENUITEMINFO info;
-      bzero (&info, sizeof (info));
+      memset (&info, 0, sizeof (info));
       info.cbSize = sizeof (info);
       info.fMask = MIIM_DATA | MIIM_TYPE | MIIM_SUBMENU;
 
@@ -1920,8 +1650,7 @@ w32_free_submenu_strings (menu)
 }
 
 void
-w32_free_menu_strings (hwnd)
-     HWND hwnd;
+w32_free_menu_strings (HWND hwnd)
 {
   HMENU menu = current_popup_menu;
 
@@ -1945,7 +1674,7 @@ w32_free_menu_strings (hwnd)
 
 DEFUN ("menu-or-popup-active-p", Fmenu_or_popup_active_p, Smenu_or_popup_active_p, 0, 0, 0,
        doc: /* Return t if a menu or popup dialog is active on selected frame.  */)
-     ()
+  (void)
 {
 #ifdef HAVE_MENUS
   FRAME_PTR f;
@@ -1956,7 +1685,8 @@ DEFUN ("menu-or-popup-active-p", Fmenu_or_popup_active_p, Smenu_or_popup_active_
 #endif /* HAVE_MENUS */
 }
 
-void syms_of_w32menu ()
+void
+syms_of_w32menu (void)
 {
   globals_of_w32menu ();
 
@@ -1964,7 +1694,6 @@ void syms_of_w32menu ()
 
   DEFSYM (Qdebug_on_next_call, "debug-on-next-call");
 
-  defsubr (&Sx_popup_menu);
   defsubr (&Smenu_or_popup_active_p);
 #ifdef HAVE_MENUS
   defsubr (&Sx_popup_dialog);
@@ -1979,14 +1708,13 @@ void syms_of_w32menu ()
        variable initialized is 0 and directly from main when initialized
        is non zero.
  */
-void globals_of_w32menu ()
+void
+globals_of_w32menu (void)
 {
-       /* See if Get/SetMenuItemInfo functions are available.  */
+  /* See if Get/SetMenuItemInfo functions are available.  */
   HMODULE user32 = GetModuleHandle ("user32.dll");
   get_menu_item_info = (GetMenuItemInfoA_Proc) GetProcAddress (user32, "GetMenuItemInfoA");
   set_menu_item_info = (SetMenuItemInfoA_Proc) GetProcAddress (user32, "SetMenuItemInfoA");
   unicode_append_menu = (AppendMenuW_Proc) GetProcAddress (user32, "AppendMenuW");
+  unicode_message_box = (MessageBoxW_Proc) GetProcAddress (user32, "MessageBoxW");
 }
-
-/* arch-tag: 0eaed431-bb4e-4aac-a527-95a1b4f1fed0
-   (do not change this comment) */