Freeciv-3.1
Loading...
Searching...
No Matches
messagedlg.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 <gtk/gtk.h>
19
20/* utility */
21#include "fcintl.h"
22
23/* common */
24#include "events.h"
25
26/* client */
27#include "options.h"
28
29/* client/gui-gtk-4.0 */
30#include "colors.h"
31#include "gui_main.h"
32#include "gui_stuff.h"
33
34#include "messagedlg.h"
35
36#define NUM_LISTS 1
37
38/*************************************************************************/
39static struct gui_dialog *shell;
40static GtkListStore *models[NUM_LISTS];
41
42static void create_messageopt_dialog(void);
43static void messageopt_response(struct gui_dialog *dlg, int response,
44 gpointer data);
45static void item_toggled(GtkCellRendererToggle *cell,
46 gchar *spath, gpointer data);
47
48/**********************************************************************/
52{
53 if (!shell) {
55 }
56
58}
59
60/**********************************************************************/
63static void create_messageopt_dialog(void)
64{
65 GtkWidget *form, *explanation;
66 int n, i = 0, j;
67 int form_col = 0;
68
69 gui_dialog_new(&shell, GTK_NOTEBOOK(top_notebook), NULL, TRUE);
70 gui_dialog_set_title(shell, _("Message Options"));
71
73
74 gui_dialog_add_button(shell, NULL, _("_OK"), GTK_RESPONSE_OK);
75 gui_dialog_add_button(shell, NULL, _("_Cancel"), GTK_RESPONSE_CANCEL);
76
77 explanation = gtk_label_new(NULL);
78 gtk_widget_set_margin_bottom(explanation, 4);
79 gtk_widget_set_margin_end(explanation, 4);
80 gtk_widget_set_margin_start(explanation, 4);
81 gtk_widget_set_margin_top(explanation, 4);
82 gtk_label_set_markup(GTK_LABEL(explanation),
83 _("Where to display messages?\n"
84 "<b>Out</b>put window ; "
85 "<b>Mes</b>sages window ; "
86 "<b>Pop</b>up individual window"));
87 gtk_widget_set_name(explanation, "comment_label");
89 gtk_widget_show(explanation);
90
91 form = gtk_grid_new();
93
94 for (n = 0; n < NUM_LISTS; n++) {
95 models[n] = gtk_list_store_new(5, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN,
96 G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_INT);
97 }
98
100 GtkTreeIter it;
101 GValue value = { 0, };
102
103 n = (i++ % NUM_LISTS);
104
105 gtk_list_store_append(models[n], &it);
106
107 g_value_init(&value, G_TYPE_STRING);
108 g_value_set_static_string(&value, get_event_message_text(ev));
109 gtk_list_store_set_value(models[n], &it, 3, &value);
110 g_value_unset(&value);
111
112 gtk_list_store_set(models[n], &it, 4, ev, -1);
113
114 for (j = 0; j < NUM_MW; j++) {
115 gtk_list_store_set(models[n], &it, j, messages_where[ev] & (1<<j), -1);
116 }
118
119 for (n = 0; n < NUM_LISTS; n++) {
120 GtkWidget *view, *sw;
121 GtkCellRenderer *renderer;
122 GtkTreeViewColumn *column;
123
124 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(models[n]));
125 gtk_widget_set_hexpand(view, TRUE);
126 gtk_widget_set_vexpand(view, TRUE);
127 g_object_unref(models[n]);
128
129 renderer = gtk_cell_renderer_text_new();
130 column = gtk_tree_view_column_new_with_attributes(_("Event"),
131 renderer, "text", 3, NULL);
132 gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
133 gtk_tree_view_column_set_expand(column, TRUE);
134
135 renderer = gtk_cell_renderer_toggle_new();
136 g_object_set_data(G_OBJECT(renderer), "column", GINT_TO_POINTER(0));
137 g_signal_connect(renderer, "toggled", G_CALLBACK(item_toggled), models[n]);
138
139 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
140 -1, _("Out"), renderer,
141 "active", 0, NULL);
142
143 renderer = gtk_cell_renderer_toggle_new();
144 g_object_set_data(G_OBJECT(renderer), "column", GINT_TO_POINTER(1));
145 g_signal_connect(renderer, "toggled", G_CALLBACK(item_toggled), models[n]);
146
147 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
148 -1, _("Mes"), renderer,
149 "active", 1, NULL);
150
151 renderer = gtk_cell_renderer_toggle_new();
152 g_object_set_data(G_OBJECT(renderer), "column", GINT_TO_POINTER(2));
153 g_signal_connect(renderer, "toggled", G_CALLBACK(item_toggled), models[n]);
154
155 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
156 -1, _("Pop"), renderer,
157 "active", 2, NULL);
158
159 sw = gtk_scrolled_window_new();
160 gtk_scrolled_window_set_has_frame(GTK_SCROLLED_WINDOW(sw), TRUE);
161 gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(sw), view);
162
163 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
164 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
165 gtk_grid_attach(GTK_GRID(form), sw, form_col++, 0, 1, 1);
166
167 gtk_tree_view_focus(GTK_TREE_VIEW(view));
168 }
169
172}
173
174/**********************************************************************/
177static void messageopt_response(struct gui_dialog *dlg, int response,
178 gpointer data)
179{
180 if (response == GTK_RESPONSE_OK) {
181 ITree it;
182 gint n, j, i;
183 gboolean toggle;
184
185 for (i = 0; i <= event_type_max(); i++) {
186 /* Include possible undefined messages. */
187 messages_where[i] = 0;
188 }
189
190 for (n = 0; n < NUM_LISTS; n++) {
191 GtkTreeModel *pmodel = GTK_TREE_MODEL(models[n]);
192
193 for (itree_begin(pmodel, &it); !itree_end(&it); itree_next(&it)) {
194 for (j = 0; j < NUM_MW; j++) {
195 itree_get(&it, j, &toggle, 4, &i, -1);
196
197 if (toggle)
198 messages_where[i] |= (1<<j);
199 }
200 }
201 }
202 }
204}
205
206/**********************************************************************/
209static void item_toggled(GtkCellRendererToggle *cell,
210 gchar *spath, gpointer data)
211{
212 GtkTreeModel *model = GTK_TREE_MODEL(data);
213 GtkTreePath *path;
214 GtkTreeIter it;
215 gboolean toggle;
216 gint column;
217
218 path = gtk_tree_path_new_from_string(spath);
219
220 column = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cell), "column"));
221
222 gtk_tree_model_get_iter(model, &it, path);
223 gtk_tree_model_get(model, &it, column, &toggle, -1);
224 toggle ^= 1;
225 gtk_list_store_set(GTK_LIST_STORE(model), &it, column, toggle, -1);
226
227 gtk_tree_path_free(path);
228}
#define n
Definition astring.c:77
const char * get_event_message_text(enum event_type event)
Definition events.c:245
#define sorted_event_iterate_end
Definition events.h:211
#define sorted_event_iterate(event)
Definition events.h:201
#define _(String)
Definition fcintl.h:67
GtkWidget * top_notebook
Definition gui_main.c:128
void gtk_tree_view_focus(GtkTreeView *view)
Definition gui_stuff.c:230
void gui_dialog_destroy(struct gui_dialog *dlg)
Definition gui_stuff.c:951
void itree_get(ITree *it,...)
Definition gui_stuff.c:158
void gui_dialog_raise(struct gui_dialog *dlg)
Definition gui_stuff.c:864
void gui_dialog_new(struct gui_dialog **pdlg, GtkNotebook *notebook, gpointer user_data, bool check_top)
Definition gui_stuff.c:504
void gui_dialog_response_set_callback(struct gui_dialog *dlg, GUI_DIALOG_RESPONSE_FUN fun)
Definition gui_stuff.c:985
void itree_begin(GtkTreeModel *model, ITree *it)
Definition gui_stuff.c:121
GtkWidget * gui_dialog_add_button(struct gui_dialog *dlg, const char *text, int response)
Definition gui_stuff.c:706
void gui_dialog_show_all(struct gui_dialog *dlg)
Definition gui_stuff.c:794
void gui_dialog_set_title(struct gui_dialog *dlg, const char *title)
Definition gui_stuff.c:932
void gui_dialog_set_default_size(struct gui_dialog *dlg, int width, int height)
Definition gui_stuff.c:916
void itree_next(ITree *it)
Definition gui_stuff.c:138
gboolean itree_end(ITree *it)
Definition gui_stuff.c:130
static void item_toggled(GtkCellRendererToggle *cell, gchar *spath, gpointer data)
Definition messagedlg.c:205
static GtkListStore * models[NUM_LISTS]
Definition messagedlg.c:40
void popup_messageopt_dialog(void)
Definition messagedlg.c:51
#define NUM_LISTS
Definition messagedlg.c:36
static void create_messageopt_dialog(void)
Definition messagedlg.c:62
static void messageopt_response(struct gui_dialog *dlg, int response, gpointer data)
Definition messagedlg.c:173
static struct gui_dialog * shell
Definition messagedlg.c:39
void gui_dialog_add_content_widget(struct gui_dialog *dlg, GtkWidget *wdg)
Definition gui_stuff.c:1095
int messages_where[E_COUNT]
Definition options.c:5028
#define NUM_MW
Definition options.h:553
#define TRUE
Definition support.h:46