1
/**********************************************************************
2
Freeciv - Copyright (C) 1996-2005 - Freeciv Development Team
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)
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
***********************************************************************/
24
#include "gui_stuff.h"
26
#include "choice_dialog.h"
28
/****************************************************************
29
Choice dialog: A dialog with a label and a list of buttons
31
****************************************************************/
33
/****************************************************************
35
*****************************************************************/
36
static GtkWidget* choice_dialog_get_nth_button(GtkWidget *cd,
39
char button_name[512];
42
my_snprintf(button_name, sizeof(button_name), "button%d", button);
44
b = g_object_get_data(G_OBJECT(cd), button_name);
49
/****************************************************************
51
*****************************************************************/
52
void choice_dialog_button_set_sensitive(GtkWidget *cd, int button,
55
gtk_widget_set_sensitive(choice_dialog_get_nth_button(cd, button), state);
58
/****************************************************************
60
*****************************************************************/
61
void choice_dialog_button_set_label(GtkWidget *cd, int number,
64
GtkWidget* button = choice_dialog_get_nth_button(cd, number);
65
gtk_button_set_label(GTK_BUTTON(button), label);
68
/****************************************************************
70
*****************************************************************/
71
GtkWidget *choice_dialog_start(GtkWindow *parent, const gchar *name,
74
GtkWidget *dshell, *dlabel, *vbox, *bbox;
76
dshell = gtk_window_new(GTK_WINDOW_TOPLEVEL);
77
setup_dialog(dshell, toplevel);
78
gtk_window_set_position (GTK_WINDOW(dshell), GTK_WIN_POS_MOUSE);
80
gtk_window_set_title(GTK_WINDOW(dshell), name);
82
gtk_window_set_transient_for(GTK_WINDOW(dshell), parent);
83
gtk_window_set_destroy_with_parent(GTK_WINDOW(dshell), TRUE);
85
vbox = gtk_vbox_new(FALSE, 5);
86
gtk_container_add(GTK_CONTAINER(dshell),vbox);
88
gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
90
dlabel = gtk_label_new(text);
91
gtk_container_add(GTK_CONTAINER(vbox), dlabel);
93
bbox = gtk_vbutton_box_new();
94
gtk_box_set_spacing(GTK_BOX(bbox), 2);
95
gtk_container_add(GTK_CONTAINER(vbox), bbox);
97
g_object_set_data(G_OBJECT(dshell), "bbox", bbox);
98
g_object_set_data(G_OBJECT(dshell), "nbuttons", GINT_TO_POINTER(0));
99
g_object_set_data(G_OBJECT(dshell), "hide", GINT_TO_POINTER(FALSE));
101
gtk_widget_show(vbox);
102
gtk_widget_show(dlabel);
107
/****************************************************************
109
*****************************************************************/
110
static void choice_dialog_clicked(GtkWidget *w, gpointer data)
112
if (g_object_get_data(G_OBJECT(data), "hide")) {
113
gtk_widget_hide(GTK_WIDGET(data));
115
gtk_widget_destroy(GTK_WIDGET(data));
119
/****************************************************************
121
*****************************************************************/
122
void choice_dialog_add(GtkWidget *dshell, const gchar *label,
123
GCallback handler, gpointer data)
125
GtkWidget *button, *bbox;
129
bbox = g_object_get_data(G_OBJECT(dshell), "bbox");
130
nbuttons = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(dshell), "nbuttons"));
131
g_object_set_data(G_OBJECT(dshell), "nbuttons", GINT_TO_POINTER(nbuttons+1));
133
my_snprintf(name, sizeof(name), "button%d", nbuttons);
135
button = gtk_button_new_from_stock(label);
136
gtk_container_add(GTK_CONTAINER(bbox), button);
137
g_object_set_data(G_OBJECT(dshell), name, button);
140
g_signal_connect(button, "clicked", handler, data);
143
g_signal_connect_after(button, "clicked",
144
G_CALLBACK(choice_dialog_clicked), dshell);
147
/****************************************************************
149
*****************************************************************/
150
void choice_dialog_end(GtkWidget *dshell)
154
bbox = g_object_get_data(G_OBJECT(dshell), "bbox");
156
gtk_widget_show_all(bbox);
157
gtk_widget_show(dshell);
160
/****************************************************************
162
*****************************************************************/
163
void choice_dialog_set_hide(GtkWidget *dshell, gboolean setting)
165
g_object_set_data(G_OBJECT(dshell), "hide", GINT_TO_POINTER(setting));
168
/****************************************************************
170
*****************************************************************/
171
GtkWidget *popup_choice_dialog(GtkWindow *parent, const gchar *dialogname,
172
const gchar *text, ...)
179
dshell = choice_dialog_start(parent, dialogname, text);
182
va_start(args, text);
184
while ((name = va_arg(args, gchar *))) {
188
handler = va_arg(args, GCallback);
189
data = va_arg(args, gpointer);
191
choice_dialog_add(dshell, name, handler, data);
196
choice_dialog_end(dshell);