OSDN Git Service

Initial Import
[nethackexpress/trunk.git] / win / gnome / gnyesno.c
1 /*      SCCS Id: @(#)gnyesno.c  3.4     2000/07/16      */
2 /* Copyright (C) 1998 by Erik Andersen <andersee@debian.org> */
3 /* NetHack may be freely redistributed.  See license for details. */
4
5 #include "gnbind.h"
6 #include "gnyesno.h"
7
8
9
10 int ghack_yes_no_dialog( const char *question, 
11                       const char *choices, int def)
12 {
13     int i=0, ret;
14     gchar button_name[BUFSZ];
15     GtkWidget *box;
16     GtkWidget* mainWnd=NULL;
17
18     box = gnome_message_box_new ( question, GNOME_MESSAGE_BOX_QUESTION, NULL);
19     /* add buttons for each choice */
20     if (!strcmp(GNOME_STOCK_BUTTON_OK, choices)) {
21         gnome_dialog_append_button ( GNOME_DIALOG(box), GNOME_STOCK_BUTTON_OK);
22         gnome_dialog_set_default( GNOME_DIALOG(box), 0);
23         gnome_dialog_set_accelerator( GNOME_DIALOG(box), 0, 'o', 0);
24 #if 0
25         g_print("Setting accelerator '%c' for button %d\n", 'o', 0);
26 #endif
27     }
28     else {
29         for( ; choices[i]!='\0'; i++) {
30             if (choices[i]=='y') {
31                 sprintf( button_name, GNOME_STOCK_BUTTON_YES);
32             }
33             else if (choices[i]=='n') {
34                 sprintf( button_name, GNOME_STOCK_BUTTON_NO);
35             }
36             else if (choices[i] == 'q') {
37                 sprintf( button_name, "Quit");
38             } else {
39                 sprintf( button_name, "%c", choices[i]);
40             }
41             if (def==choices[i])
42                 gnome_dialog_set_default( GNOME_DIALOG(box), i);
43             gnome_dialog_append_button ( GNOME_DIALOG(box), button_name);
44             gnome_dialog_set_accelerator( GNOME_DIALOG(box), i, choices[i], 0);
45 #if 0
46             g_print("Setting accelerator '%c' for button %d\n", choices[i], i);
47 #endif
48         }
49     }
50 #if 0
51     /* Perhaps add in a quit game button, like this... */
52     gnome_dialog_append_button ( GNOME_DIALOG(box), GNOME_STOCK_BUTTON_CLOSE);
53     gnome_dialog_set_accelerator( GNOME_DIALOG(box), i, choices[i], 0);
54     g_print("Setting accelerator '%c' for button %d\n", 'Q', i);
55 #endif
56
57     gnome_dialog_set_close(GNOME_DIALOG (box), TRUE);
58     mainWnd = ghack_get_main_window ();
59     gtk_window_set_modal( GTK_WINDOW(box), TRUE);
60     gtk_window_set_title( GTK_WINDOW(box), "GnomeHack");
61     if ( mainWnd != NULL ) {
62         gnome_dialog_set_parent (GNOME_DIALOG (box), 
63                 GTK_WINDOW ( mainWnd) );
64     }
65
66     ret=gnome_dialog_run_and_close ( GNOME_DIALOG (box));
67     
68 #if 0
69     g_print("You selected button %d\n", ret);
70 #endif
71     
72     if (ret==-1)
73         return( '\033');
74     else
75         return( choices[ret]);
76 }