changeset 48937:3cabed8b65b7

* macmenu.c (MIN_POPUP_SUBMENU_ID): Added (mac_menu_show): Added support for hierarchical popup menus (add_menu_item): Removed indentation support (fill_submenu, fill_menu): Now creates hierarchical menus instead of using indentation
author Steven Tamm <steventamm@mac.com>
date Sun, 22 Dec 2002 23:14:52 +0000
parents 34c0bb0d7b38
children 05f00479612c
files src/ChangeLog src/macmenu.c
diffstat 2 files changed, 56 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Sun Dec 22 22:06:38 2002 +0000
+++ b/src/ChangeLog	Sun Dec 22 23:14:52 2002 +0000
@@ -1,3 +1,11 @@
+2002-12-22  Steven Tamm  <steventamm@mac.com>
+
+	* macmenu.c (MIN_POPUP_SUBMENU_ID): Added 
+	(mac_menu_show): Added support for hierarchical popup menus
+	(add_menu_item): Removed indentation support
+	(fill_submenu, fill_menu): Now creates hierarchical menus
+	instead of using indentation
+
 2002-12-22  Richard M. Stallman  <rms@gnu.org>
 
 	* xdisp.c (try_cursor_movement): Don't call try_window here.
--- a/src/macmenu.c	Sun Dec 22 22:06:38 2002 +0000
+++ b/src/macmenu.c	Sun Dec 22 23:14:52 2002 +0000
@@ -89,6 +89,7 @@
 #include "dispextern.h"
 
 #define POPUP_SUBMENU_ID 235
+#define MIN_POPUP_SUBMENU_ID 512
 #define MIN_MENU_ID 256
 #define MIN_SUBMENU_ID 1
 
@@ -173,7 +174,7 @@
 #define TRUE 1
 #define FALSE 0
 #endif /* no TRUE */
-
+  
 Lisp_Object Vmenu_updating_frame;
 
 Lisp_Object Qdebug_on_next_call;
@@ -205,7 +206,7 @@
 static void list_of_panes ();
 static void list_of_items ();
 
-static void fill_submenu (MenuHandle, widget_value *, int);
+static void fill_submenu (MenuHandle, widget_value *);
 static void fill_menubar (widget_value *);
 
 
@@ -267,6 +268,9 @@
    Xt on behalf of one of the widget sets.  */
 static int popup_activated_flag;
 
+/* Index of the next submenu */
+static int submenu_id;
+
 static int next_menubar_widget_id;
 
 /* This is set nonzero after the user activates the menu bar, and set
@@ -1605,6 +1609,8 @@
      char **error;
 {
   int i;
+  UInt32 refcon;
+  int menu_item_choice;
   int menu_item_selection;
   MenuHandle menu;
   Point pos;
@@ -1798,7 +1804,8 @@
 
   /* Actually create the menu.  */
   menu = NewMenu (POPUP_SUBMENU_ID, "\p");
-  fill_submenu (menu, first_wv->contents, 0);
+  submenu_id = MIN_POPUP_SUBMENU_ID;
+  fill_submenu (menu, first_wv->contents);
 
   /* Adjust coordinates to be root-window-relative.  */
   pos.h = x;
@@ -1813,14 +1820,23 @@
   LocalToGlobal (&pos);
 
   /* No selection has been chosen yet.  */
+  menu_item_choice = 0;
   menu_item_selection = 0;
 
   InsertMenu (menu, -1);
 
   /* Display the menu.  */
-  menu_item_selection = LoWord (PopUpMenuSelect (menu, pos.v, pos.h, 0));
+  menu_item_choice = PopUpMenuSelect (menu, pos.v, pos.h, 0);
+  menu_item_selection = LoWord (menu_item_choice);
 
-  DeleteMenu (POPUP_SUBMENU_ID);
+  /* Get the refcon to find the correct item*/
+  if (menu_item_selection) 
+    {
+      menu = GetMenuHandle (HiWord (menu_item_choice));
+      if (menu) {
+	GetMenuItemRefCon (menu, menu_item_selection, &refcon);
+      }
+    }
   
 #if 0
   /* Clean up extraneous mouse events which might have been generated
@@ -1832,6 +1848,19 @@
      contents.  */
   free_menubar_widget_value_tree (first_wv);
 
+  /* delete all menus */
+  {
+    int i = MIN_POPUP_SUBMENU_ID;
+    MenuHandle submenu = GetMenuHandle (i);
+    while (menu != NULL)
+      {
+	DeleteMenu (i);
+	DisposeMenu (menu);
+	menu = GetMenuHandle (++i);
+      }
+  }
+
+  DeleteMenu (POPUP_SUBMENU_ID);
   DisposeMenu (menu);
 
   /* Find the selected item, and its pane, to return
@@ -1839,7 +1868,6 @@
   if (menu_item_selection != 0)
     {
       Lisp_Object prefix, entry;
-      int j = 1;
 
       prefix = entry = Qnil;
       i = 0;
@@ -1861,7 +1889,6 @@
 	      prefix
 		= XVECTOR (menu_items)->contents[i + MENU_ITEMS_PANE_PREFIX];
 	      i += MENU_ITEMS_PANE_LENGTH;
-	      j += 2;
 	    }
 	  /* Ignore a nil in the item list.
 	     It's meaningful only for dialog boxes.  */
@@ -1871,7 +1898,7 @@
 	    {
 	      entry
 		= XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_VALUE];
-	      if (menu_item_selection == j)
+	      if ((int) (EMACS_INT) refcon == i)
 		{
 		  if (keymaps != 0)
 		    {
@@ -1887,7 +1914,6 @@
 		  return entry;
 		}
 	      i += MENU_ITEMS_ITEM_LENGTH;
-	      j++;
 	    }
 	}
     }
@@ -2206,7 +2232,7 @@
 }
 
 static void
-add_menu_item (MenuHandle menu, widget_value *wv, int submenu, int indent,
+add_menu_item (MenuHandle menu, widget_value *wv, int submenu,
 	       int force_disable)
 {
   Str255 item_name;
@@ -2225,8 +2251,6 @@
 #endif
 
       strcpy (item_name, "");
-      for (i = 0; i < indent; i++)
-	strncat (item_name, "    ", 255);
       strncat (item_name, wv->name, 255);
       if (wv->key != NULL)
 	{
@@ -2266,22 +2290,22 @@
     SetMenuItemHierarchicalID (menu, pos, submenu);
 }
 
-static int submenu_id;
-  
 /* Construct native Mac OS menubar based on widget_value tree.  */
 
 static void
-fill_submenu (MenuHandle menu, widget_value *wv, int indent)
+fill_submenu (MenuHandle menu, widget_value *wv)
 {
   for ( ; wv != NULL; wv = wv->next)
     if (wv->contents)
       {
-        add_menu_item (menu, wv, NULL, indent, 1);
-        
-        fill_submenu (menu, wv->contents, indent + 1);
+	int cur_submenu = submenu_id++;
+        MenuHandle submenu = NewMenu (cur_submenu, "\pX");
+        fill_submenu (submenu, wv->contents);
+        InsertMenu (submenu, -1);
+        add_menu_item (menu, wv, cur_submenu, 0);
       }
     else
-      add_menu_item (menu, wv, NULL, indent, 0);
+      add_menu_item (menu, wv, NULL, 0);
 }
 
 
@@ -2293,14 +2317,14 @@
   for ( ; wv != NULL; wv = wv->next)
     if (wv->contents)
       {
-        MenuHandle submenu = NewMenu (submenu_id, "\pX");
-        fill_submenu (submenu, wv->contents, 0);
+	int cur_submenu = submenu_id++;
+        MenuHandle submenu = NewMenu (cur_submenu, "\pX");
+        fill_submenu (submenu, wv->contents);
         InsertMenu (submenu, -1);
-        add_menu_item (menu, wv, submenu_id, 0, 0);
-        submenu_id++;
+        add_menu_item (menu, wv, cur_submenu, 0);
       }
     else
-      add_menu_item (menu, wv, NULL, 0, 0);
+      add_menu_item (menu, wv, NULL, 0);
 }
 
 /* Construct native Mac OS menubar based on widget_value tree.  */