Freeciv-3.1: /fast/freeciv/nightly/S3_1/client/gui-gtk-4.0/inputdlg.c Source File

Freeciv-3.1

Loading...
Searching...
No Matches
inputdlg.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <stdio.h>
19
20#include <gtk/gtk.h>
21
22/* utility */
23#include "fcintl.h"
24#include "log.h"
25#include "mem.h"
26
27/* client/gui-gtk-4.0 */
28#include "gui_main.h"
29#include "gui_stuff.h"
30
31#include "inputdlg.h"
32
33struct input_dialog_data {
34 input_dialog_callback_t response_callback;
35 gpointer response_cli_data;
36};
37
38/**********************************************************************/
41 static void input_dialog_response(GtkDialog *shell, gint response,
42 gpointer data)
43{
44 GtkWidget *winput = g_object_get_data(G_OBJECT(shell), "iinput");
45 struct input_dialog_data *cb = data;
46
47 cb->response_callback(cb->response_cli_data,
48 response,
49 gtk_entry_buffer_get_text(gtk_entry_get_buffer(GTK_ENTRY(winput))));
50
51 /* Any response is final */
52 gtk_window_destroy(GTK_WINDOW(shell));
53 FC_FREE(cb);
54}
55
56/**********************************************************************/
59 static void input_dialog_close(GtkDialog *shell, gpointer data)
60{
61 input_dialog_response(shell, GTK_RESPONSE_CANCEL, data);
62}
63
64/**********************************************************************/
67GtkWidget *input_dialog_create(GtkWindow *parent, const char *dialogname,
68 const char *text, const char *postinputtest,
69 input_dialog_callback_t response_callback,
70 gpointer response_cli_data)
71{
72 GtkWidget *shell, *label, *input;
73 struct input_dialog_data *cb = fc_malloc(sizeof(struct input_dialog_data));
74
75 cb->response_callback = response_callback;
76 cb->response_cli_data = response_cli_data;
77
78 shell = gtk_dialog_new_with_buttons(dialogname,
79 parent,
80 GTK_DIALOG_DESTROY_WITH_PARENT,
81 _("_Cancel"), GTK_RESPONSE_CANCEL,
82 _("_OK"), GTK_RESPONSE_OK,
83 NULL);
84 gtk_dialog_set_default_response(GTK_DIALOG(shell), GTK_RESPONSE_OK);
85 setup_dialog(shell, GTK_WIDGET(parent));
86 g_signal_connect(shell, "response", G_CALLBACK(input_dialog_response), cb);
87 g_signal_connect(shell, "close", G_CALLBACK(input_dialog_close), cb);
88
89 label = gtk_frame_new(text);
90 gtk_box_insert_child_after(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(shell))),
91 label, NULL);
92
93 input = gtk_entry_new();
94 gtk_frame_set_child(GTK_FRAME(label), input);
95 gtk_entry_buffer_set_text(gtk_entry_get_buffer(GTK_ENTRY(input)), postinputtest, -1);
96 gtk_entry_set_activates_default(GTK_ENTRY(input), TRUE);
97 g_object_set_data(G_OBJECT(shell), "iinput", input);
98
99 gtk_widget_show(GTK_WIDGET(shell));
100 gtk_window_present(GTK_WINDOW(shell));
101
102 return shell;
103}
fcintl.h
_
#define _(String)
Definition fcintl.h:67
setup_dialog
void setup_dialog(GtkWidget *shell, GtkWidget *parent)
Definition gui_stuff.c:281
input_dialog_close
static void input_dialog_close(GtkDialog *shell, gpointer data)
Definition inputdlg.c:58
input_dialog_create
GtkWidget * input_dialog_create(GtkWindow *parent, const char *dialogname, const char *text, const char *postinputtest, input_dialog_callback_t response_callback, gpointer response_cli_data)
Definition inputdlg.c:66
input_dialog_response
static void input_dialog_response(GtkDialog *shell, gint response, gpointer data)
Definition inputdlg.c:41
input_dialog_callback_t
void(* input_dialog_callback_t)(gpointer response_cli_data, gint response, const char *input)
Definition inputdlg.h:18
shell
static struct gui_dialog * shell
Definition messagedlg.c:39
gui_stuff.h
inputdlg.h
gui_main.h
log.h
mem.h
FC_FREE
#define FC_FREE(ptr)
Definition mem.h:41
fc_malloc
#define fc_malloc(sz)
Definition mem.h:34
input_dialog_data
Definition inputdlg.c:33
input_dialog_data::response_callback
input_dialog_callback_t response_callback
Definition inputdlg.c:34
input_dialog_data::response_cli_data
gpointer response_cli_data
Definition inputdlg.c:35
TRUE
#define TRUE
Definition support.h:46