+ for (index = 0; index < lenof(scs.sc); index++) {
+ scs.sc[index].action = SHORTCUT_EMPTY;
+ }
+
+ ctrlbox = ctrl_new_box();
+
+ /*
+ * Preliminary pass over the va_list, to count up the number of
+ * buttons and find out what kinds there are.
+ */
+ ncols = 0;
+ va_start(ap, minwid);
+ min_type = +1;
+ while (va_arg(ap, char *) != NULL) {
+ int type;
+
+ (void) va_arg(ap, int); /* shortcut */
+ type = va_arg(ap, int); /* normal/default/cancel */
+ (void) va_arg(ap, int); /* end value */
+
+ ncols++;
+ if (min_type > type)
+ min_type = type;
+ }
+ va_end(ap);
+
+ s0 = ctrl_getset(ctrlbox, "", "", "");
+ c = ctrl_columns(s0, 2, 50, 50);
+ c->columns.ncols = s0->ncolumns = ncols;
+ c->columns.percentages = sresize(c->columns.percentages, ncols, int);
+ for (index = 0; index < ncols; index++)
+ c->columns.percentages[index] = (index+1)*100/ncols - index*100/ncols;
+ va_start(ap, minwid);
+ index = 0;
+ while (1) {
+ char *title = va_arg(ap, char *);
+ int shortcut, type, value;
+ if (title == NULL)
+ break;
+ shortcut = va_arg(ap, int);
+ type = va_arg(ap, int);
+ value = va_arg(ap, int);
+ c = ctrl_pushbutton(s0, title, shortcut, HELPCTX(no_help),
+ messagebox_handler, I(value));
+ c->generic.column = index++;
+ if (type > 0)
+ c->button.isdefault = TRUE;
+
+ /* We always arrange that _some_ button is labelled as
+ * 'iscancel', so that pressing Escape will always cause
+ * win_key_press to do something. The button we choose is
+ * whichever has the smallest type value: this means that real
+ * cancel buttons (labelled -1) will be picked if one is
+ * there, or in cases where the options are yes/no (1,0) then
+ * no will be picked, and if there's only one option (a box
+ * that really is just showing a _message_ and not even asking
+ * a question) then that will be picked. */
+ if (type == min_type)
+ c->button.iscancel = TRUE;
+ }
+ va_end(ap);
+
+ s1 = ctrl_getset(ctrlbox, "x", "", "");
+ ctrl_text(s1, msg, HELPCTX(no_help));
+
+ window = our_dialog_new();
+ gtk_window_set_title(GTK_WINDOW(window), title);
+ w0 = layout_ctrls(&dp, &scs, s0, GTK_WINDOW(window));
+ our_dialog_set_action_area(GTK_WINDOW(window), w0);
+ gtk_widget_show(w0);
+ w1 = layout_ctrls(&dp, &scs, s1, GTK_WINDOW(window));
+ gtk_container_set_border_width(GTK_CONTAINER(w1), 10);
+ gtk_widget_set_size_request(w1, minwid+20, -1);
+ our_dialog_add_to_content_area(GTK_WINDOW(window), w1, TRUE, TRUE, 0);
+ gtk_widget_show(w1);
+
+ dp.shortcuts = &scs;
+ dp.lastfocus = NULL;
+ dp.retval = 0;
+ dp.window = window;
+
+ gtk_window_set_modal(GTK_WINDOW(window), TRUE);
+ if (parentwin) {
+ set_transient_window_pos(parentwin, window);
+ gtk_window_set_transient_for(GTK_WINDOW(window),
+ GTK_WINDOW(parentwin));
+ } else
+ gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
+ gtk_widget_show(window);
+
+ g_signal_connect(G_OBJECT(window), "destroy",
+ G_CALLBACK(window_destroy), NULL);
+ g_signal_connect(G_OBJECT(window), "key_press_event",
+ G_CALLBACK(win_key_press), &dp);