OSDN Git Service

guarantee an alter on oracle
[nethackexpress/trunk.git] / win / gnome / gnaskstr.c
1 /*      SCCS Id: @(#)gnaskstr.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 "gnaskstr.h"
6 #include "gnmain.h"
7 #include <gnome.h>
8
9
10 static
11 void ghack_ask_string_callback(gchar * string, gpointer data)
12 {
13   char **user_text = (char **) data;
14
15   g_assert(user_text != NULL);
16
17   *user_text = string; /* note - value must be g_free'd */
18 }
19
20
21 int ghack_ask_string_dialog(const char *szMessageStr, 
22         const char *szDefaultStr, const char *szTitleStr, 
23         char *buffer)
24 {
25     int i;
26     GtkWidget* dialog;
27     gchar   *user_text = NULL;
28
29     dialog = gnome_request_dialog(FALSE, szMessageStr,
30                                   szDefaultStr, 0,
31                                   ghack_ask_string_callback,
32                                   &user_text, NULL);
33     g_assert(dialog != NULL);
34
35     gtk_window_set_title(GTK_WINDOW(dialog), szTitleStr);
36
37     gnome_dialog_set_default( GNOME_DIALOG(dialog), 0);
38     gtk_window_set_modal( GTK_WINDOW(dialog), TRUE);
39     gnome_dialog_set_parent (GNOME_DIALOG (dialog), 
40             GTK_WINDOW (ghack_get_main_window ()) );
41
42     i = gnome_dialog_run_and_close (GNOME_DIALOG (dialog));
43     
44     /* Quit */
45     if ( i != 0 || user_text == NULL ) {
46         if (user_text)
47           g_free(user_text);
48         return -1;
49     }
50
51     if ( *user_text == 0 ) {
52       g_free(user_text);
53       return -1;
54     }
55
56     g_assert(strlen(user_text) > 0);
57     strcpy (buffer, user_text);
58     g_free(user_text);
59     return 0;
60 }
61