changeset 11237:7c968b691ff0

(frame_vector): New static variable. (syms_of_xmenu): staticpro it. (frame_vector_add_frame): New function. (set_frame_menubar): Use frame_vector; use index as the widget id. (free_frame_menubar): Likewise. Remove the frame from frame_vector. (menubar_selection_callback): Use frame_vector to turn id into frame.
author Richard M. Stallman <rms@gnu.org>
date Fri, 07 Apr 1995 03:39:07 +0000
parents abd63066ddf0
children 747eeabdbbcb
files src/xmenu.c
diffstat 1 files changed, 51 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/xmenu.c	Fri Apr 07 02:59:03 1995 +0000
+++ b/src/xmenu.c	Fri Apr 07 03:39:07 1995 +0000
@@ -151,6 +151,47 @@
    Xt on behalf of one of the widget sets.  */
 static int popup_activated_flag;
 
+/* This holds a Lisp vector
+   which contains frames that have menu bars.
+   Each frame that has a menu bar is found at some index in this vector
+   and the menu bar widget refers to the frame through that index.  */
+static Lisp_Object frame_vector;
+
+/* Return the index of FRAME in frame_vector.
+   If FRAME isn't in frame_vector yet, put it in,
+   lengthening the vector if necessary.  */
+
+static int
+frame_vector_add_frame (f)
+     FRAME_PTR *f;
+{
+  int length = XVECTOR (frame_vector)->size;
+  int i, empty = -1;
+  Lisp_Object new, frame;
+
+  XSETFRAME (frame, f);
+
+  for (i = 0; i < length; i++)
+    {
+      if (EQ (frame, XVECTOR (frame_vector)->contents[i]))
+	return i;
+      if (NILP (XVECTOR (frame_vector)->contents[i]))
+	empty = i;
+    }
+
+  if (empty >= 0)
+    {
+      XVECTOR (frame_vector)->contents[empty] = frame;
+      return empty;
+    }
+
+  new = Fmake_vector (make_number (length * 2), Qnil);
+  bcopy (XVECTOR (frame_vector)->contents,
+	 XVECTOR (new)->contents, sizeof (Lisp_Object) * length);
+  
+  XVECTOR (frame_vector)->contents[length] = frame;
+  return length;
+}
 
 /* Initialize the menu_items structure if we haven't already done so.
    Also mark it as currently empty.  */
@@ -1060,7 +1101,7 @@
      XtPointer client_data;
 {
   Lisp_Object prefix;
-  FRAME_PTR f = (FRAME_PTR) id;
+  FRAME_PTR f = XFRAME (XVECTOR (frame_vector)->contents[id]);
   Lisp_Object vector;
   Lisp_Object *subprefix_stack;
   int submenu_depth = 0;
@@ -1378,10 +1419,12 @@
      int first_time;
 {
   Widget menubar_widget = f->display.x->menubar_widget;
-  int id = (int) f;
-  Lisp_Object tail, items;
+  Lisp_Object tail, items, frame;
   widget_value *wv, *first_wv, *prev_wv = 0;
   int i;
+  int id;
+
+  id = frame_vector_add_frame (f);
 
   BLOCK_INPUT;
 
@@ -1493,12 +1536,13 @@
   int id;
 
   menubar_widget = f->display.x->menubar_widget;
-  id = (int) f;
   
   if (menubar_widget)
     {
+      id = frame_vector_add_frame (f);
       BLOCK_INPUT;
       lw_destroy_all_widgets (id);
+      XVECTOR (frame_vector)->contents[id] = Qnil;
       UNBLOCK_INPUT;
     }
 }
@@ -2352,6 +2396,9 @@
   widget_id_tick = (1<<16);	
 #endif
 
+  staticpro (&frame_vector);
+  frame_vector = Fmake_vector (make_number (10), Qnil);
+
   defsubr (&Sx_popup_menu);
   defsubr (&Sx_popup_dialog);
 }