/* As above, but return the menu selection instead of storing in kb buffer. If KEYMAPS, return full prefixes to selection. */ Lisp_Object find_and_return_menu_selection (struct frame *f, bool keymaps, void *client_data) { Lisp_Object prefix, entry; int i; Lisp_Object *subprefix_stack; int submenu_depth = 0; prefix = entry = Qnil; i = 0; subprefix_stack = alloca (menu_items_used * word_size); while (i < menu_items_used) { if (EQ (AREF (menu_items, i), Qnil)) { subprefix_stack[submenu_depth++] = prefix; prefix = entry; i++; } else if (EQ (AREF (menu_items, i), Qlambda)) { prefix = subprefix_stack[--submenu_depth]; i++; } else if (EQ (AREF (menu_items, i), Qt)) { prefix = AREF (menu_items, i + MENU_ITEMS_PANE_PREFIX); 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 { entry = AREF (menu_items, i + MENU_ITEMS_ITEM_VALUE); if (aref_addr (menu_items, i) == client_data) { if (keymaps) { int j; entry = list1 (entry); if (!NILP (prefix)) entry = Fcons (prefix, entry); for (j = submenu_depth - 1; j >= 0; j--) if (!NILP (subprefix_stack[j])) entry = Fcons (subprefix_stack[j], entry); } return entry; } i += MENU_ITEMS_ITEM_LENGTH; } } return Qnil; }
static Lisp_Object w32_dialog_show (struct frame *f, Lisp_Object title, Lisp_Object header, char **error) { int i, nb_buttons = 0; char dialog_name[6]; int menu_item_selection; widget_value *wv, *first_wv = 0, *prev_wv = 0; /* Number of elements seen so far, before boundary. */ int left_count = 0; /* true means we've seen the boundary between left-hand elts and right-hand. */ bool boundary_seen = false; *error = NULL; if (menu_items_n_panes > 1) { *error = "Multiple panes in dialog box"; return Qnil; } /* Create a tree of widget_value objects representing the text label and buttons. */ { Lisp_Object pane_name; char *pane_string; pane_name = AREF (menu_items, MENU_ITEMS_PANE_NAME); pane_string = (NILP (pane_name) ? "" : SSDATA (pane_name)); prev_wv = make_widget_value ("message", pane_string, true, Qnil); first_wv = prev_wv; /* Loop over all panes and items, filling in the tree. */ i = MENU_ITEMS_PANE_LENGTH; while (i < menu_items_used) { /* Create a new item within current pane. */ Lisp_Object item_name, enable, descrip, 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); help = AREF (menu_items, i + MENU_ITEMS_ITEM_HELP); if (NILP (item_name)) { free_menubar_widget_value_tree (first_wv); *error = "Submenu in dialog items"; return Qnil; } if (EQ (item_name, Qquote)) { /* This is the boundary between left-side elts and right-side elts. Stop incrementing right_count. */ boundary_seen = true; i++; continue; } if (nb_buttons >= 9) { free_menubar_widget_value_tree (first_wv); *error = "Too many dialog items"; return Qnil; } wv = make_widget_value (button_names[nb_buttons], SSDATA (item_name), !NILP (enable), Qnil); prev_wv->next = wv; if (!NILP (descrip)) wv->key = SSDATA (descrip); wv->call_data = aref_addr (menu_items, i); prev_wv = wv; if (! boundary_seen) left_count++; nb_buttons++; i += MENU_ITEMS_ITEM_LENGTH; } /* If the boundary was not specified, by default put half on the left and half on the right. */ if (! boundary_seen) left_count = nb_buttons - nb_buttons / 2; wv = make_widget_value (dialog_name, NULL, false, Qnil); /* Frame title: 'Q' = Question, 'I' = Information. Can also have 'E' = Error if, one day, we want a popup for errors. */ if (NILP (header)) dialog_name[0] = 'Q'; else dialog_name[0] = 'I'; /* Dialog boxes use a really stupid name encoding which specifies how many buttons to use and how many buttons are on the right. */ dialog_name[1] = '0' + nb_buttons; dialog_name[2] = 'B'; dialog_name[3] = 'R'; /* Number of buttons to put on the right. */ dialog_name[4] = '0' + nb_buttons - left_count; dialog_name[5] = 0; wv->contents = first_wv; first_wv = wv; } /* Actually create the dialog. */ dialog_id = widget_id_tick++; menu = lw_create_widget (first_wv->name, "dialog", dialog_id, first_wv, f->output_data.w32->widget, true, 0, dialog_selection_callback, 0); lw_modify_all_widgets (dialog_id, first_wv->contents, TRUE); /* Free the widget_value objects we used to specify the contents. */ free_menubar_widget_value_tree (first_wv); /* No selection has been chosen yet. */ menu_item_selection = 0; /* Display the menu. */ lw_pop_up_all_widgets (dialog_id); /* Process events that apply to the menu. */ popup_get_selection ((XEvent *) 0, FRAME_DISPLAY_INFO (f), dialog_id); lw_destroy_all_widgets (dialog_id); /* Find the selected item, and its pane, to return the proper value. */ if (menu_item_selection != 0) { i = 0; while (i < menu_items_used) { Lisp_Object entry; if (EQ (AREF (menu_items, i), Qt)) i += MENU_ITEMS_PANE_LENGTH; else { entry = AREF (menu_items, i + MENU_ITEMS_ITEM_VALUE); if (menu_item_selection == i) return entry; i += MENU_ITEMS_ITEM_LENGTH; } } } else /* Make "Cancel" equivalent to C-g. */ Fsignal (Qquit, Qnil); return Qnil; }