OSDN Git Service

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