NHDT->ANH, nethack->anethack, nhdat->anhdat
[aNetHack.git] / win / gnome / gnyesno.c
blob3cbf65c475afc5a3f86cbacab7c76be1b2f470e9
1 /* aNetHack 0.0.1 gnyesno.c $ANH-Date: 1432512807 2015/05/25 00:13:27 $ $ANH-Branch: master $:$ANH-Revision: 1.8 $ */
2 /* Copyright (C) 1998 by Erik Andersen <andersee@debian.org> */
3 /* aNetHack may be freely redistributed. See license for details. */
5 #include "gnbind.h"
6 #include "gnyesno.h"
8 int
9 ghack_yes_no_dialog(const char *question, const char *choices, int def)
11 int i = 0, ret;
12 gchar button_name[BUFSZ];
13 GtkWidget *box;
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);
22 #if 0
23 g_print("Setting accelerator '%c' for button %d\n", 'o', 0);
24 #endif
25 } else {
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");
33 } else {
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);
40 #if 0
41 g_print("Setting accelerator '%c' for button %d\n", choices[i], i);
42 #endif
45 #if 0
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);
50 #endif
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));
62 #if 0
63 g_print("You selected button %d\n", ret);
64 #endif
66 if (ret == -1)
67 return ('\033');
68 else
69 return (choices[ret]);