Remove spurious semicolons.
[bpt/emacs.git] / src / xmenu.c
index ca0bcdf..6767c1b 100644 (file)
@@ -1,6 +1,6 @@
 /* X Communication module for terminals which understand the X protocol.
    Copyright (C) 1986, 1988, 1993, 1994, 1996, 1999, 2000, 2001, 2002, 2003,
-                 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+                 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -146,6 +146,7 @@ static int popup_activated_flag;
 
 static int next_menubar_widget_id;
 
+/* For NS and NTGUI, these prototypes are defined in keyboard.h.  */
 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
 extern widget_value *xmalloc_widget_value P_ ((void));
 extern widget_value *digest_single_submenu P_ ((int, int, int));
@@ -359,6 +360,13 @@ no quit occurs and `x-popup-menu' returns nil.  */)
          Lisp_Object bar_window;
          enum scroll_bar_part part;
          unsigned long time;
+         void (*mouse_position_hook) P_ ((struct frame **, int,
+                                          Lisp_Object *,
+                                          enum scroll_bar_part *,
+                                          Lisp_Object *,
+                                          Lisp_Object *,
+                                          unsigned long *)) =
+           new_f->terminal->mouse_position_hook;
 
          if (mouse_position_hook)
            (*mouse_position_hook) (&new_f, 1, &bar_window,
@@ -402,8 +410,8 @@ no quit occurs and `x-popup-menu' returns nil.  */)
       xpos += XINT (x);
       ypos += XINT (y);
 
-      if (! FRAME_X_P (f))
-        error ("Can not put X menu on non-X terminal");
+      if (! FRAME_X_P (f) && ! FRAME_MSDOS_P (f))
+        error ("Can not put X menu on this terminal");
 
       XSETFRAME (Vmenu_updating_frame, f);
     }
@@ -593,8 +601,8 @@ for instance using the window manager, then this produces a quit and
        but I don't want to make one now.  */
     CHECK_WINDOW (window);
 
-  if (! FRAME_X_P (f))
-    error ("Can not put X dialog on non-X terminal");
+  if (! FRAME_X_P (f) && ! FRAME_MSDOS_P (f))
+    error ("Can not put X dialog on this terminal");
 
 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
   /* Display a menu with these alternatives
@@ -884,11 +892,12 @@ If FRAME is nil or not given, use the selected frame.  */)
       /* Activate the first menu.  */
       GList *children = gtk_container_get_children (GTK_CONTAINER (menubar));
 
-      gtk_menu_shell_select_item (GTK_MENU_SHELL (menubar),
-                                  GTK_WIDGET (children->data));
-
-      popup_activated_flag = 1;
-      g_list_free (children);
+      if (children)
+        {
+          g_signal_emit_by_name (children->data, "activate_item");
+          popup_activated_flag = 1;
+          g_list_free (children);
+        }
     }
   UNBLOCK_INPUT;
 
@@ -1687,8 +1696,9 @@ menu_position_func (menu, x, y, push_in, user_data)
 {
   struct next_popup_x_y* data = (struct next_popup_x_y*)user_data;
   GtkRequisition req;
-  int disp_width = FRAME_X_DISPLAY_INFO (data->f)->width;
-  int disp_height = FRAME_X_DISPLAY_INFO (data->f)->height;
+  struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (data->f);
+  int disp_width = x_display_pixel_width (dpyinfo);
+  int disp_height = x_display_pixel_height (dpyinfo);
 
   *x = data->x;
   *y = data->y;
@@ -2603,7 +2613,7 @@ xmenu_show (f, x, y, for_click, keymaps, title, error)
   unsigned int dummy_uint;
   int specpdl_count = SPECPDL_INDEX ();
 
-  if (! FRAME_X_P (f))
+  if (! FRAME_X_P (f) && ! FRAME_MSDOS_P (f))
     abort ();
 
   *error = 0;
@@ -2766,6 +2776,23 @@ xmenu_show (f, x, y, for_click, keymaps, title, error)
       y -= (uly + height) - dispheight;
       uly = dispheight - height;
     }
+#ifndef HAVE_X_WINDOWS
+  if (FRAME_HAS_MINIBUF_P (f) && uly+height > dispheight - 1)
+    {
+      /* Move the menu away of the echo area, to avoid overwriting the
+        menu with help echo messages or vice versa.  */
+      if (BUFFERP (echo_area_buffer[0]) && WINDOWP (echo_area_window))
+       {
+         y -= WINDOW_TOTAL_LINES (XWINDOW (echo_area_window));
+         uly -= WINDOW_TOTAL_LINES (XWINDOW (echo_area_window));
+       }
+      else
+       {
+         y--;
+         uly--;
+       }
+    }
+#endif
   if (ulx < 0) x -= ulx;
   if (uly < 0) y -= uly;