NHDT->ANH, nethack->anethack, nhdat->anhdat
[aNetHack.git] / win / gnome / gnaskstr.c
blob8e7d0a9473310f83e85f912795e2d1052fec6c66
1 /* aNetHack 0.0.1 gnaskstr.c $ANH-Date: 1432512806 2015/05/25 00:13:26 $ $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 "gnaskstr.h"
6 #include "gnmain.h"
7 #include <gnome.h>
9 static void
10 ghack_ask_string_callback(gchar *string, gpointer data)
12 char **user_text = (char **) data;
14 g_assert(user_text != NULL);
16 *user_text = string; /* note - value must be g_free'd */
19 int
20 ghack_ask_string_dialog(const char *szMessageStr, const char *szDefaultStr,
21 const char *szTitleStr, char *buffer)
23 int i;
24 GtkWidget *dialog;
25 gchar *user_text = NULL;
27 dialog =
28 gnome_request_dialog(FALSE, szMessageStr, szDefaultStr, 0,
29 ghack_ask_string_callback, &user_text, NULL);
30 g_assert(dialog != NULL);
32 gtk_window_set_title(GTK_WINDOW(dialog), szTitleStr);
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()));
39 i = gnome_dialog_run_and_close(GNOME_DIALOG(dialog));
41 /* Quit */
42 if (i != 0 || user_text == NULL) {
43 if (user_text)
44 g_free(user_text);
45 return -1;
48 if (*user_text == 0) {
49 g_free(user_text);
50 return -1;
53 g_assert(strlen(user_text) > 0);
54 strcpy(buffer, user_text);
55 g_free(user_text);
56 return 0;