void set_frame_menubar P_ ((FRAME_PTR, int, int));
-static void push_menu_item P_ ((Lisp_Object, Lisp_Object, Lisp_Object,
- Lisp_Object, Lisp_Object, Lisp_Object,
- Lisp_Object, Lisp_Object));
#ifdef HAVE_DIALOGS
static Lisp_Object w32_dialog_show P_ ((FRAME_PTR, int, Lisp_Object, char**));
#else
void w32_free_menu_strings P_((HWND));
\f
-static int next_menubar_widget_id;
-
-extern widget_value *xmalloc_widget_value P_ ((void));
/* This is set nonzero after the user activates the menu bar, and set
to zero again after the menu bars are redisplayed by prepare_menu_bar.
}
\f
-/* Set up data i menu_items for a menu bar item
- whose event type is ITEM_KEY (with string ITEM_NAME)
- and whose contents come from the list of keymaps MAPS. */
-
-static int
-parse_single_submenu (item_key, item_name, maps)
- Lisp_Object item_key, item_name, maps;
-{
- Lisp_Object length;
- int len;
- Lisp_Object *mapvec;
- int i;
- int top_level_items = 0;
-
- length = Flength (maps);
- len = XINT (length);
-
- /* Convert the list MAPS into a vector MAPVEC. */
- mapvec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object));
- for (i = 0; i < len; i++)
- {
- mapvec[i] = Fcar (maps);
- maps = Fcdr (maps);
- }
-
- /* Loop over the given keymaps, making a pane for each map.
- But don't make a pane that is empty--ignore that map instead. */
- for (i = 0; i < len; i++)
- {
- if (SYMBOLP (mapvec[i])
- || (CONSP (mapvec[i]) && !KEYMAPP (mapvec[i])))
- {
- /* Here we have a command at top level in the menu bar
- as opposed to a submenu. */
- top_level_items = 1;
- push_menu_pane (Qnil, Qnil);
- push_menu_item (item_name, Qt, item_key, mapvec[i],
- Qnil, Qnil, Qnil, Qnil);
- }
- else
- {
- Lisp_Object prompt;
- prompt = Fkeymap_prompt (mapvec[i]);
- single_keymap_panes (mapvec[i],
- !NILP (prompt) ? prompt : item_name,
- item_key, 0, 10);
- }
- }
-
- return top_level_items;
-}
-
-
-/* Create a tree of widget_value objects
- representing the panes and items
- in menu_items starting at index START, up to index END. */
-
-static widget_value *
-digest_single_submenu (start, end, top_level_items)
- int start, end, top_level_items;
-{
- widget_value *wv, *prev_wv, *save_wv, *first_wv;
- int i;
- int submenu_depth = 0;
- widget_value **submenu_stack;
-
- submenu_stack
- = (widget_value **) alloca (menu_items_used * sizeof (widget_value *));
- wv = xmalloc_widget_value ();
- wv->name = "menu";
- wv->value = 0;
- wv->enabled = 1;
- wv->button_type = BUTTON_TYPE_NONE;
- wv->help = Qnil;
- first_wv = wv;
- save_wv = 0;
- prev_wv = 0;
-
- /* Loop over all panes and items made by the preceding call
- to parse_single_submenu and construct a tree of widget_value objects.
- Ignore the panes and items used by previous calls to
- digest_single_submenu, even though those are also in menu_items. */
- i = start;
- while (i < end)
- {
- if (EQ (AREF (menu_items, i), Qnil))
- {
- submenu_stack[submenu_depth++] = save_wv;
- save_wv = prev_wv;
- prev_wv = 0;
- i++;
- }
- else if (EQ (AREF (menu_items, i), Qlambda))
- {
- prev_wv = save_wv;
- save_wv = submenu_stack[--submenu_depth];
- i++;
- }
- else if (EQ (AREF (menu_items, i), Qt)
- && submenu_depth != 0)
- i += MENU_ITEMS_PANE_LENGTH;
- /* Ignore a nil in the item list.
- It's meaningful only for dialog boxes. */
- else if (EQ (AREF (menu_items, i), Qquote))
- i += 1;
- else if (EQ (AREF (menu_items, i), Qt))
- {
- /* Create a new pane. */
- Lisp_Object pane_name, prefix;
- char *pane_string;
-
- pane_name = AREF (menu_items, i + MENU_ITEMS_PANE_NAME);
- prefix = AREF (menu_items, i + MENU_ITEMS_PANE_PREFIX);
-
- if (STRINGP (pane_name))
- {
- if (unicode_append_menu)
- /* Encode as UTF-8 for now. */
- pane_name = ENCODE_UTF_8 (pane_name);
- else if (STRING_MULTIBYTE (pane_name))
- pane_name = ENCODE_SYSTEM (pane_name);
-
- ASET (menu_items, i + MENU_ITEMS_PANE_NAME, pane_name);
- }
-
- pane_string = (NILP (pane_name)
- ? "" : (char *) SDATA (pane_name));
- /* If there is just one top-level pane, put all its items directly
- under the top-level menu. */
- if (menu_items_n_panes == 1)
- pane_string = "";
-
- /* If the pane has a meaningful name,
- make the pane a top-level menu item
- with its items as a submenu beneath it. */
- if (strcmp (pane_string, ""))
- {
- wv = xmalloc_widget_value ();
- if (save_wv)
- save_wv->next = wv;
- else
- first_wv->contents = wv;
- wv->lname = pane_name;
- /* Set value to 1 so update_submenu_strings can handle '@' */
- wv->value = (char *) 1;
- wv->enabled = 1;
- wv->button_type = BUTTON_TYPE_NONE;
- wv->help = Qnil;
- }
- save_wv = wv;
- prev_wv = 0;
- i += MENU_ITEMS_PANE_LENGTH;
- }
- else
- {
- /* Create a new item within current pane. */
- Lisp_Object item_name, enable, descrip, def, type, selected;
- Lisp_Object help;
-
- item_name = AREF (menu_items, i + MENU_ITEMS_ITEM_NAME);
- enable = AREF (menu_items, i + MENU_ITEMS_ITEM_ENABLE);
- descrip = AREF (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY);
- def = AREF (menu_items, i + MENU_ITEMS_ITEM_DEFINITION);
- type = AREF (menu_items, i + MENU_ITEMS_ITEM_TYPE);
- selected = AREF (menu_items, i + MENU_ITEMS_ITEM_SELECTED);
- help = AREF (menu_items, i + MENU_ITEMS_ITEM_HELP);
-
- if (STRINGP (item_name))
- {
- if (unicode_append_menu)
- item_name = ENCODE_UTF_8 (item_name);
- else if (STRING_MULTIBYTE (item_name))
- item_name = ENCODE_SYSTEM (item_name);
-
- ASET (menu_items, i + MENU_ITEMS_ITEM_NAME, item_name);
- }
-
- if (STRINGP (descrip) && STRING_MULTIBYTE (descrip))
- {
- descrip = ENCODE_SYSTEM (descrip);
- ASET (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY, descrip);
- }
-
- wv = xmalloc_widget_value ();
- if (prev_wv)
- prev_wv->next = wv;
- else
- save_wv->contents = wv;
-
- wv->lname = item_name;
- if (!NILP (descrip))
- wv->lkey = descrip;
- wv->value = 0;
- /* The EMACS_INT cast avoids a warning. There's no problem
- as long as pointers have enough bits to hold small integers. */
- wv->call_data = (!NILP (def) ? (void *) (EMACS_INT) i : 0);
- wv->enabled = !NILP (enable);
-
- if (NILP (type))
- wv->button_type = BUTTON_TYPE_NONE;
- else if (EQ (type, QCradio))
- wv->button_type = BUTTON_TYPE_RADIO;
- else if (EQ (type, QCtoggle))
- wv->button_type = BUTTON_TYPE_TOGGLE;
- else
- abort ();
-
- wv->selected = !NILP (selected);
- if (!STRINGP (help))
- help = Qnil;
-
- wv->help = help;
-
- prev_wv = wv;
-
- i += MENU_ITEMS_ITEM_LENGTH;
- }
- }
-
- /* If we have just one "menu item"
- that was originally a button, return it by itself. */
- if (top_level_items && first_wv->contents && first_wv->contents->next == 0)
- {
- wv = first_wv->contents;
- free_widget_value (first_wv);
- return wv;
- }
-
- return first_wv;
-}
-
-
-\f
/* Set the contents of the menubar widgets of frame F.
The argument FIRST_TIME is currently ignored;
it is set the first time this is called, from initialize_frame_menubar. */
/* Fill in menu_items with the current menu bar contents.
This can evaluate Lisp code. */
+ save_menu_items ();
+
menu_items = f->menu_bar_vector;
menu_items_allocated = VECTORP (menu_items) ? ASIZE (menu_items) : 0;
submenu_start = (int *) alloca (XVECTOR (items)->size * sizeof (int *));
}
set_buffer_internal_1 (prev);
- unbind_to (specpdl_count, Qnil);
/* If there has been no change in the Lisp-level contents
of the menu bar, skip redisplaying it. Just exit. */
if (i == menu_items_used && i == previous_menu_items_used && i != 0)
{
free_menubar_widget_value_tree (first_wv);
- menu_items = Qnil;
-
+ discard_menu_items ();
+ unbind_to (specpdl_count, Qnil);
return;
}
+ f->menu_bar_vector = menu_items;
+ f->menu_bar_items_used = menu_items_used;
+
+ /* This undoes save_menu_items. */
+ unbind_to (specpdl_count, Qnil);
+
/* Now GC cannot happen during the lifetime of the widget_value,
so it's safe to store data from a Lisp_String, as long as
local copies are made when the actual menu is created.
update_submenu_strings (wv->contents);
wv = wv->next;
}
-
- f->menu_bar_vector = menu_items;
- f->menu_bar_items_used = menu_items_used;
- menu_items = Qnil;
}
else
{
*error = NULL;
+ if (menu_items_n_panes == 0)
+ return Qnil;
+
if (menu_items_used <= MENU_ITEMS_PANE_LENGTH)
{
*error = "Empty menu";
abort ();
wv->selected = !NILP (selected);
+
if (!STRINGP (help))
help = Qnil;
first_wv->contents = wv_title;
}
+ /* No selection has been chosen yet. */
+ menu_item_selection = 0;
+
/* Actually create the menu. */
current_popup_menu = menu = CreatePopupMenu ();
fill_in_menu (menu, first_wv->contents);
pos.y = y;
ClientToScreen (FRAME_W32_WINDOW (f), &pos);
- /* No selection has been chosen yet. */
- menu_item_selection = 0;
-
/* Display the menu. */
menu_item_selection = SendMessage (FRAME_W32_WINDOW (f),
WM_EMACS_TRACKPOPUPMENU,
complicated than simple yes/no type questions for which we can use
the MessageBox function.
*/
-
+
static char * button_names [] = {
"button1", "button2", "button3", "button4", "button5",
"button6", "button7", "button8", "button9", "button10" };
void syms_of_w32menu ()
{
globals_of_w32menu ();
- staticpro (&menu_items);
- menu_items = Qnil;
current_popup_menu = NULL;