1 /* NetHack 3.6 gnyesno.c $NHDT-Date: 1432512807 2015/05/25 00:13:27 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */
2 /* Copyright (C) 1998 by Erik Andersen <andersee@debian.org> */
3 /* NetHack may be freely redistributed. See license for details. */
9 ghack_yes_no_dialog(const char *question
, const char *choices
, int def
)
12 gchar button_name
[BUFSZ
];
14 GtkWidget
*mainWnd
= NULL
;
16 box
= gnome_message_box_new(question
, GNOME_MESSAGE_BOX_QUESTION
, NULL
);
17 /* add buttons for each choice */
18 if (!strcmp(GNOME_STOCK_BUTTON_OK
, choices
)) {
19 gnome_dialog_append_button(GNOME_DIALOG(box
), GNOME_STOCK_BUTTON_OK
);
20 gnome_dialog_set_default(GNOME_DIALOG(box
), 0);
21 gnome_dialog_set_accelerator(GNOME_DIALOG(box
), 0, 'o', 0);
23 g_print("Setting accelerator '%c' for button %d\n", 'o', 0);
26 for (; choices
[i
] != '\0'; i
++) {
27 if (choices
[i
] == 'y') {
28 sprintf(button_name
, GNOME_STOCK_BUTTON_YES
);
29 } else if (choices
[i
] == 'n') {
30 sprintf(button_name
, GNOME_STOCK_BUTTON_NO
);
31 } else if (choices
[i
] == 'q') {
32 sprintf(button_name
, "Quit");
34 sprintf(button_name
, "%c", choices
[i
]);
36 if (def
== choices
[i
])
37 gnome_dialog_set_default(GNOME_DIALOG(box
), i
);
38 gnome_dialog_append_button(GNOME_DIALOG(box
), button_name
);
39 gnome_dialog_set_accelerator(GNOME_DIALOG(box
), i
, choices
[i
], 0);
41 g_print("Setting accelerator '%c' for button %d\n", choices
[i
], i
);
46 /* Perhaps add in a quit game button, like this... */
47 gnome_dialog_append_button ( GNOME_DIALOG(box
), GNOME_STOCK_BUTTON_CLOSE
);
48 gnome_dialog_set_accelerator( GNOME_DIALOG(box
), i
, choices
[i
], 0);
49 g_print("Setting accelerator '%c' for button %d\n", 'Q', i
);
52 gnome_dialog_set_close(GNOME_DIALOG(box
), TRUE
);
53 mainWnd
= ghack_get_main_window();
54 gtk_window_set_modal(GTK_WINDOW(box
), TRUE
);
55 gtk_window_set_title(GTK_WINDOW(box
), "GnomeHack");
56 if (mainWnd
!= NULL
) {
57 gnome_dialog_set_parent(GNOME_DIALOG(box
), GTK_WINDOW(mainWnd
));
60 ret
= gnome_dialog_run_and_close(GNOME_DIALOG(box
));
63 g_print("You selected button %d\n", ret
);
69 return (choices
[ret
]);