Don't have previous and next buffers deal with internal windows.
[bpt/emacs.git] / src / xmenu.c
index f5bbca1..b4338c1 100644 (file)
@@ -240,7 +240,7 @@ for instance using the window manager, then this produces a quit and
       FRAME_PTR new_f = SELECTED_FRAME ();
       Lisp_Object bar_window;
       enum scroll_bar_part part;
-      unsigned long time;
+      Time time;
       Lisp_Object x, y;
 
       (*mouse_position_hook) (&new_f, 1, &bar_window, &part, &x, &y, &time);
@@ -347,6 +347,8 @@ for instance using the window manager, then this produces a quit and
 
 #ifndef MSDOS
 
+#if defined USE_GTK || defined USE_MOTIF
+
 /* Set menu_items_inuse so no other popup menu or dialog is created.  */
 
 void
@@ -360,6 +362,8 @@ x_menu_set_in_use (int in_use)
 #endif
 }
 
+#endif
+
 /* Wait for an X event to arrive or for a timer to expire.  */
 
 #ifndef USE_MOTIF
@@ -736,10 +740,13 @@ menu_highlight_callback (GtkWidget *widget, gpointer call_data)
   help = call_data ? cb_data->help : Qnil;
 
   /* If popup_activated_flag is greater than 1 we are in a popup menu.
-     Don't show help for them, they won't appear before the
-     popup is popped down.  */
-  if (popup_activated_flag <= 1)
-    show_help_event (cb_data->cl_data->f, widget, help);
+     Don't pass the frame to show_help_event for those.
+     Passing frame creates an Emacs event.  As we are looping in
+     popup_widget_loop, it won't be handeled.  Passing NULL shows the tip
+     directly without using an Emacs event.  This is what the Lucid code
+     does below.  */
+  show_help_event (popup_activated_flag <= 1 ? cb_data->cl_data->f : NULL,
+                   widget, help);
 }
 #else
 static void
@@ -922,7 +929,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p)
 #endif
   Lisp_Object items;
   widget_value *wv, *first_wv, *prev_wv = 0;
-  EMACS_UINT i, last_i = 0;
+  int i;
   int *submenu_start, *submenu_end;
   int *submenu_top_level_items, *submenu_n_panes;
 
@@ -966,7 +973,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p)
       Lisp_Object *previous_items
        = (Lisp_Object *) alloca (previous_menu_items_used
                                  * sizeof (Lisp_Object));
-      EMACS_UINT subitems;
+      int subitems;
 
       /* If we are making a new widget, its contents are empty,
         do always reinitialize them.  */
@@ -1011,18 +1018,16 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p)
 
       menu_items = f->menu_bar_vector;
       menu_items_allocated = VECTORP (menu_items) ? ASIZE (menu_items) : 0;
-      subitems = XVECTOR (items)->size / 4;
-      submenu_start = (int *) alloca (subitems * sizeof (int *));
-      submenu_end = (int *) alloca (subitems * sizeof (int *));
+      subitems = ASIZE (items) / 4;
+      submenu_start = (int *) alloca ((subitems + 1) * sizeof (int));
+      submenu_end = (int *) alloca (subitems * sizeof (int));
       submenu_n_panes = (int *) alloca (subitems * sizeof (int));
-      submenu_top_level_items = (int *) alloca (subitems * sizeof (int *));
+      submenu_top_level_items = (int *) alloca (subitems * sizeof (int));
       init_menu_items ();
       for (i = 0; i < subitems; i++)
        {
          Lisp_Object key, string, maps;
 
-         last_i = i;
-
          key = XVECTOR (items)->contents[4 * i];
          string = XVECTOR (items)->contents[4 * i + 1];
          maps = XVECTOR (items)->contents[4 * i + 2];
@@ -1039,6 +1044,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p)
          submenu_end[i] = menu_items_used;
        }
 
+      submenu_start[i] = -1;
       finish_menu_items ();
 
       /* Convert menu_items into widget_value trees
@@ -1052,7 +1058,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p)
       wv->help = Qnil;
       first_wv = wv;
 
-      for (i = 0; i < last_i; i++)
+      for (i = 0; 0 <= submenu_start[i]; i++)
        {
          menu_items_n_panes = submenu_n_panes[i];
          wv = digest_single_submenu (submenu_start[i], submenu_end[i],
@@ -1097,7 +1103,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p)
       /* Now GC cannot happen during the lifetime of the widget_value,
         so it's safe to store data from a Lisp_String.  */
       wv = first_wv->contents;
-      for (i = 0; i < XVECTOR (items)->size; i += 4)
+      for (i = 0; i < ASIZE (items); i += 4)
        {
          Lisp_Object string;
          string = XVECTOR (items)->contents[i + 1];
@@ -1123,7 +1129,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p)
       first_wv = wv;
 
       items = FRAME_MENU_BAR_ITEMS (f);
-      for (i = 0; i < XVECTOR (items)->size; i += 4)
+      for (i = 0; i < ASIZE (items); i += 4)
        {
          Lisp_Object string;
 
@@ -1139,9 +1145,9 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p)
          wv->help = Qnil;
          /* This prevents lwlib from assuming this
             menu item is really supposed to be empty.  */
-         /* The EMACS_INT cast avoids a warning.
+         /* The intptr_t cast avoids a warning.
             This value just has to be different from small integers.  */
-         wv->call_data = (void *) (EMACS_INT) (-1);
+         wv->call_data = (void *) (intptr_t) (-1);
 
          if (prev_wv)
            prev_wv->next = wv;
@@ -1421,7 +1427,8 @@ pop_down_menu (Lisp_Object arg)
    menu pops down.
    menu_item_selection will be set to the selection.  */
 static void
-create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv, int x, int y, int for_click, EMACS_UINT timestamp)
+create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv, int x, int y,
+                           int for_click, Time timestamp)
 {
   int i;
   GtkWidget *menu;
@@ -1465,7 +1472,7 @@ create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv, int x, int y, i
   gtk_widget_show_all (menu);
 
   gtk_menu_popup (GTK_MENU (menu), 0, 0, pos_func, &popup_x_y, i,
-                 timestamp > 0 ? timestamp : gtk_get_current_event_time());
+                 timestamp ? timestamp : gtk_get_current_event_time ());
 
   record_unwind_protect (pop_down_menu, make_save_value (menu, 0));
 
@@ -1525,7 +1532,7 @@ pop_down_menu (Lisp_Object arg)
    menu_item_selection will be set to the selection.  */
 static void
 create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv,
-                           int x, int y, int for_click, EMACS_UINT timestamp)
+                           int x, int y, int for_click, Time timestamp)
 {
   int i;
   Arg av[2];
@@ -1599,7 +1606,7 @@ create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv,
 
 Lisp_Object
 xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps,
-           Lisp_Object title, const char **error_name, EMACS_UINT timestamp)
+           Lisp_Object title, const char **error_name, Time timestamp)
 {
   int i;
   widget_value *wv, *save_wv = 0, *first_wv = 0, *prev_wv = 0;
@@ -1876,9 +1883,9 @@ xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps,
 static void
 dialog_selection_callback (GtkWidget *widget, gpointer client_data)
 {
-  /* The EMACS_INT cast avoids a warning.  There's no problem
+  /* Treat the pointer as an integer.  There's no problem
      as long as pointers have enough bits to hold small integers.  */
-  if ((int) (EMACS_INT) client_data != -1)
+  if ((intptr_t) client_data != -1)
     menu_item_selection = (Lisp_Object *) client_data;
 
   popup_activated_flag = 0;
@@ -1919,9 +1926,9 @@ create_and_show_dialog (FRAME_PTR f, widget_value *first_wv)
 static void
 dialog_selection_callback (Widget widget, LWLIB_ID id, XtPointer client_data)
 {
-  /* The EMACS_INT cast avoids a warning.  There's no problem
+  /* Treat the pointer as an integer.  There's no problem
      as long as pointers have enough bits to hold small integers.  */
-  if ((int) (EMACS_INT) client_data != -1)
+  if ((intptr_t) client_data != -1)
     menu_item_selection = (Lisp_Object *) client_data;
 
   BLOCK_INPUT;
@@ -2242,7 +2249,7 @@ pop_down_menu (Lisp_Object arg)
 
 Lisp_Object
 xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps,
-           Lisp_Object title, const char **error_name, EMACS_UINT timestamp)
+           Lisp_Object title, const char **error_name, Time timestamp)
 {
   Window root;
   XMenu *menu;
@@ -2299,7 +2306,8 @@ xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps,
   y += f->top_pos;
 
   /* Create all the necessary panes and their items.  */
-  maxlines = lines = i = 0;
+  maxwidth = maxlines = lines = i = 0;
+  lpane = XM_FAILURE;
   while (i < menu_items_used)
     {
       if (EQ (XVECTOR (menu_items)->contents[i], Qt))
@@ -2327,7 +2335,6 @@ xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps,
          i += MENU_ITEMS_PANE_LENGTH;
 
          /* Find the width of the widest item in this pane.  */
-         maxwidth = 0;
          j = i;
          while (j < menu_items_used)
            {
@@ -2379,10 +2386,11 @@ xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps,
          else
            item_data = SSDATA (item_name);
 
-         if (XMenuAddSelection (FRAME_X_DISPLAY (f),
-                                menu, lpane, 0, item_data,
-                                !NILP (enable), help_string)
-             == XM_FAILURE)
+         if (lpane == XM_FAILURE
+             || (XMenuAddSelection (FRAME_X_DISPLAY (f),
+                                    menu, lpane, 0, item_data,
+                                    !NILP (enable), help_string)
+                 == XM_FAILURE))
            {
              XMenuDestroy (FRAME_X_DISPLAY (f), menu);
              *error_name = "Can't add selection to menu";
@@ -2462,6 +2470,7 @@ xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps,
   status = XMenuActivate (FRAME_X_DISPLAY (f), menu, &pane, &selidx,
                           x, y, ButtonReleaseMask, &datap,
                           menu_help_callback);
+  entry = pane_prefix = Qnil;
 
   switch (status)
     {
@@ -2508,14 +2517,12 @@ xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps,
     case XM_FAILURE:
       *error_name = "Can't activate menu";
     case XM_IA_SELECT:
-      entry = Qnil;
       break;
     case XM_NO_SELECT:
       /* Make "Cancel" equivalent to C-g unless FOR_CLICK (which means
         the menu was invoked with a mouse event as POSITION).  */
       if (! for_click)
         Fsignal (Qquit, Qnil);
-      entry = Qnil;
       break;
     }
 
@@ -2555,8 +2562,7 @@ DEFUN ("menu-or-popup-active-p", Fmenu_or_popup_active_p, Smenu_or_popup_active_
 void
 syms_of_xmenu (void)
 {
-  Qdebug_on_next_call = intern_c_string ("debug-on-next-call");
-  staticpro (&Qdebug_on_next_call);
+  DEFSYM (Qdebug_on_next_call, "debug-on-next-call");
 
 #ifdef USE_X_TOOLKIT
   widget_id_tick = (1<<16);