Index: lisp/menubar.el
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/lisp/menubar.el,v
retrieving revision 1.8.2.1
diff -u -r1.8.2.1 menubar.el
--- lisp/menubar.el	2001/07/25 07:44:29	1.8.2.1
+++ lisp/menubar.el	2001/12/12 06:27:40
@@ -671,6 +671,10 @@
 
 MENU-DESC and EVENT are as in the call to `popup-menu'."
   ;; partially stolen from w3
+
+  ;; This function is way gross and assumes to much about menu
+  ;; processing that is X specific. Under mswindows popup menus behave
+  ;; in reasonable ways that you can't obstruct.
   (let ((echo-keystrokes 0)
 	new-event)
     (popup-menu menu-desc event)
@@ -679,14 +683,22 @@
 	(setq new-event (next-command-event new-event))
 	(cond ((misc-user-event-p new-event)
 	       (throw 'popup-done new-event))
-	      ((not (popup-up-p))
-	       (setq unread-command-events (cons new-event
-						 unread-command-events))
-	       (throw 'popup-done nil))
 	      ((button-release-event-p new-event);; don't beep twice
 	       nil)
-	      ((event-matches-key-specifier-p (quit-char))
+	      ;; It shows how bogus this function is that the event
+	      ;; arg could be missing and no-one noticed ...
+	      ((event-matches-key-specifier-p new-event (quit-char))
 	       (signal 'quit nil))
+	      ;; mswindows has no pop-down processing (selection is
+	      ;; atomic) so doing anything more makes no sense. Since
+	      ;; popup-up-p is always false under mswindows, this
+	      ;; function has been ordered to do essentially X-specifc
+	      ;; processing after this check.
+	      ((not (popup-up-p))	
+	       (setq unread-command-events (cons new-event
+						 unread-command-events))
+	       (throw 'popup-done nil))
+	      ;; mswindows never gets here
 	      (t
 	       (beep)
 	       (message "please make a choice from the menu.")))))))
Index: src/dialog-msw.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/dialog-msw.c,v
retrieving revision 1.7.2.1.4.2
diff -u -r1.7.2.1.4.2 dialog-msw.c
--- src/dialog-msw.c	2001/11/22 02:39:08	1.7.2.1.4.2
+++ src/dialog-msw.c	2001/12/12 06:27:45
@@ -285,7 +285,14 @@
   return arg;
 }
 
+/* Unwind protection decrements dialog count */
+static Lisp_Object
+dialog_popped_down (Lisp_Object arg)
+{
+  popup_up_p--;
+}
 
+
 #define ALIGN_TEMPLATE					\
 {							\
   unsigned int slippage = Dynarr_length (template) & 3;	\
@@ -792,16 +799,21 @@
 mswindows_make_dialog_box_internal (struct frame* f, Lisp_Object type,
 				    Lisp_Object keys)
 {
+  int unbind_count = specpdl_depth ();
+  record_unwind_protect (dialog_popped_down, Qnil);
+  popup_up_p++;
+
   if (EQ (type, Qfile))
-    return handle_file_dialog_box (f, keys);
+    return unbind_to (unbind_count, handle_file_dialog_box (f, keys));
   else if (EQ (type, Qdirectory))
-    return handle_directory_dialog_box (f, keys);
+    return unbind_to (unbind_count, handle_directory_dialog_box (f, keys));
   else if (EQ (type, Qquestion))
-    return handle_question_dialog_box (f, keys);
+    return unbind_to (unbind_count, handle_question_dialog_box (f, keys));
   else if (EQ (type, Qprint))
-    return mswindows_handle_print_dialog_box (f, keys);
+    return unbind_to (unbind_count, mswindows_handle_print_dialog_box (f, keys));
   else if (EQ (type, Qpage_setup))
-    return mswindows_handle_page_setup_dialog_box (f, keys);
+    return unbind_to (unbind_count, 
+		      mswindows_handle_page_setup_dialog_box (f, keys));
   else
     signal_type_error (Qunimplemented, "Dialog box type", type);
   return Qnil;
Index: src/menubar-msw.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/menubar-msw.c,v
retrieving revision 1.21
diff -u -r1.21 menubar-msw.c
--- src/menubar-msw.c	2001/04/12 18:24:01	1.21
+++ src/menubar-msw.c	2001/12/12 06:27:49
@@ -737,7 +737,7 @@
 
   Lisp_Object path, desc;
   struct gcpro gcpro1;
-
+  
   /* Find which guy is going to explode */
   path = Fgethash (hmenu_to_lisp_object (menu), current_hash_table, Qunbound);
   assert (!UNBOUNDP (path));
@@ -821,8 +821,7 @@
      breaks customize because the misc_event gets eval'ed in some
      circumstances. Don't change it back unless you can fix the
      customize problem also.*/
-  enqueue_misc_user_event (frame, fn, arg);
-  mswindows_enqueue_magic_event (NULL, XM_BUMPQUEUE);
+  mswindows_enqueue_misc_user_event (frame, fn, arg);
 
   UNGCPRO; /* data */
   return Qt;
@@ -916,6 +915,8 @@
 	eev = NULL;
     }
 
+  popup_up_p++;
+
   /* Default is to put the menu at the point (10, 10) in frame */
   if (eev)
     {
@@ -931,6 +932,8 @@
   CHECK_CONS (menu_desc);
   CHECK_STRING (XCAR (menu_desc));
 
+  menu_cleanup (f);
+
   current_menudesc = menu_desc;
   current_hash_table =
     make_lisp_hash_table (10, HASH_TABLE_NON_WEAK, HASH_TABLE_EQUAL);
@@ -949,7 +952,15 @@
 
   DestroyMenu (menu);
 
-  /* Signal a signal if caught by Track...() modal loop */
+  /* A WM_COMMAND is not issued until TrackPopupMenu returns. This
+     makes setting popup_up_p fairly pointless since we cannot keep
+     the menu up and dispatch events. Furthermore, we seem to have
+     little control over what happens to the menu when we click. */
+  popup_up_p--;
+
+  /* Signal a signal if caught by Track...() modal loop. */
+  /* I think this is pointless, the code hasn't actually put us in a
+     modal loop at this time -- andyp. */
   mswindows_unmodalize_signal_maybe ();
 
   /* This is probably the only real reason for failure */
@@ -960,6 +971,8 @@
 			   menu_desc);
     }
   UNGCPRO;
+
+  return Qnil;
 }
 
 
