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

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