Freeciv-3.3
Loading...
Searching...
No Matches
messagewin.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#include <stdlib.h>
20#include <string.h>
21
22#include <gtk/gtk.h>
23
24/* utility */
25#include "fcintl.h"
26#include "log.h"
27
28/* common */
29#include "events.h"
30#include "game.h"
31#include "map.h"
32#include "player.h"
33
34/* client */
35#include "options.h"
36
37/* client/gui-gtk-3.22 */
38#include "chatline.h"
39#include "citydlg.h"
40#include "gui_main.h"
41#include "gui_stuff.h"
42#include "mapview.h"
43
44#include "messagewin.h"
45
46
51
52/* Those values must match meswin_dialog_store_new(). */
64
69
70static struct meswin_dialog meswin = { NULL, };
71
72/************************************************************************/
76{
78 GDK_TYPE_PIXBUF, /* MESWIN_COL_ICON */
79 G_TYPE_STRING, /* MESWIN_COL_MESSAGE */
80 G_TYPE_INT, /* MESWIN_COL_WEIGHT */
81 G_TYPE_INT, /* MESWIN_COL_STYLE */
82 G_TYPE_INT); /* MESWIN_COL_ID */
83}
84
85/************************************************************************/
88static void meswin_dialog_visited_get_attr(bool visited, gint *weight,
89 gint *style)
90{
91 if (NULL != weight) {
92 *weight = (visited ? PANGO_WEIGHT_NORMAL : PANGO_WEIGHT_BOLD);
93 }
94 if (NULL != style) {
95 *style = (visited ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL);
96 }
97}
98
99/************************************************************************/
103 GtkTreeIter *iter, bool visited)
104{
105 gint row, weight, style;
106
108 meswin_dialog_visited_get_attr(visited, &weight, &style);
110 MESWIN_COL_WEIGHT, weight,
111 MESWIN_COL_STYLE, style,
112 -1);
114}
115
116/************************************************************************/
119static void meswin_dialog_refresh(struct meswin_dialog *pdialog)
120{
121 GtkTreeSelection *selection;
122 GtkTreeModel *model;
123 GtkListStore *store;
125 const struct message *pmsg;
126 gint weight, style;
127 int selected, i, num;
128 bool need_alert = FALSE;
129
130 fc_assert_ret(NULL != pdialog);
131
132 /* Save the selection. */
133 selection = gtk_tree_view_get_selection(pdialog->tree_view);
134 if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
135 gtk_tree_model_get(model, &iter, MESWIN_COL_ID, &selected, -1);
136 } else {
137 selected = -1;
138 }
139
140 model = gtk_tree_view_get_model(pdialog->tree_view);
141 store = GTK_LIST_STORE(model);
143
145 for (i = 0; i < num; i++) {
146 GdkPixbuf *pb;
147 struct sprite *icon;
148 int x0, y0, x1, y1, w, h;
150
152
155 } else {
157 }
158
159 icon = get_event_sprite(tileset, pmsg->event);
160 sprite_get_bounding_box(icon, &x0, &y0, &x1, &y1);
161 w = (x1 - x0) + 1;
162 h = (y1 - y0) + 1;
166 pb, 0, 0);
168
169 meswin_dialog_visited_get_attr(pmsg->visited, &weight, &style);
170 gtk_list_store_set(store, &iter,
172 MESWIN_COL_MESSAGE, pmsg->descr,
173 MESWIN_COL_WEIGHT, weight,
174 MESWIN_COL_STYLE, style,
176 -1);
178 if (i == selected) {
179 /* Restore the selection. */
181 }
182
183 if (!pmsg->visited) {
185 }
186 }
187
188 if (need_alert) {
189 gui_dialog_alert(pdialog->shell);
190 }
191}
192
193/************************************************************************/
197 gpointer data)
198{
199 struct meswin_dialog *pdialog = data;
200 const struct message *pmsg;
201 GtkTreeModel *model;
203 gint row;
204
205 if (!gtk_tree_selection_get_selected(selection, &model, &iter)) {
206 return;
207 }
208
211
213 NULL != pmsg && pmsg->location_ok);
215 NULL != pmsg && pmsg->city_ok);
216}
217
218/************************************************************************/
222 GtkTreePath *path,
224 gpointer data)
225{
228 gint row;
229
230 if (!gtk_tree_model_get_iter(model, &iter, path)) {
231 return;
232 }
233
235
236 if (NULL != meswin_get_message(row)) {
239 }
240}
241
242/************************************************************************/
249 gpointer data)
250{
251 GtkTreePath *path = NULL;
252 GtkTreeModel *model;
254 gint row;
255
257
258 if (GDK_BUTTON_PRESS != ev->type || 3 != ev->button) {
259 return FALSE;
260 }
261
263 &path, NULL, NULL, NULL)) {
264 return TRUE;
265 }
266
268 if (gtk_tree_model_get_iter(model, &iter, path)) {
271 }
272 gtk_tree_path_free(path);
273
274 return TRUE;
275}
276
277/************************************************************************/
281 int response, gpointer data)
282{
283 struct meswin_dialog *pdialog = data;
284 GtkTreeSelection *selection;
285 GtkTreeModel *model;
287 gint row;
288
289 switch (response) {
290 case MESWIN_RES_GOTO:
292 break;
293 default:
295 return;
296 }
297
298 selection = gtk_tree_view_get_selection(pdialog->tree_view);
299 if (!gtk_tree_selection_get_selected(selection, &model, &iter)) {
300 return;
301 }
302
304
305 switch (response) {
306 case MESWIN_RES_GOTO:
308 break;
311 break;
312 }
314}
315
316/************************************************************************/
319static void meswin_dialog_init(struct meswin_dialog *pdialog)
320{
321 GtkWidget *view, *sw, *cmd, *notebook;
322 GtkContainer *vbox;
323 GtkListStore *store;
324 GtkTreeSelection *selection;
325 GtkCellRenderer *renderer;
327
328 fc_assert_ret(NULL != pdialog);
329
331 notebook = right_notebook;
332 } else {
333 notebook = bottom_notebook;
334 }
335
336 gui_dialog_new(&pdialog->shell, GTK_NOTEBOOK(notebook), pdialog, TRUE);
337 gui_dialog_set_title(pdialog->shell, _("Messages"));
338 vbox = GTK_CONTAINER(pdialog->shell->vbox);
339
345 gtk_container_add(vbox, sw);
346
347 store = meswin_dialog_store_new();
351 g_object_unref(store);
354 g_signal_connect(view, "row_activated",
356 g_signal_connect(view, "button-press-event",
358 pdialog->tree_view = GTK_TREE_VIEW(view);
359
360 renderer = gtk_cell_renderer_pixbuf_new();
362 "pixbuf", MESWIN_COL_ICON, NULL);
365
366 renderer = gtk_cell_renderer_text_new();
368 "text", MESWIN_COL_MESSAGE,
369 "weight", MESWIN_COL_WEIGHT,
370 "style", MESWIN_COL_STYLE,
371 NULL);
374
376 g_signal_connect(selection, "changed",
378
379 gui_dialog_add_button(pdialog->shell, "window-close", _("_Close"),
381
383 cmd = gui_dialog_add_button(pdialog->shell, "zoom-in",
384 _("I_nspect City"),
387
388 cmd = gui_dialog_add_button(pdialog->shell, "go-jump",
389 _("Goto _Location"), MESWIN_RES_GOTO);
391 }
392
395 gui_dialog_set_default_size(pdialog->shell, 520, 300);
396
397 meswin_dialog_refresh(pdialog);
398 gui_dialog_show_all(pdialog->shell);
399}
400
401/************************************************************************/
404static void meswin_dialog_free(struct meswin_dialog *pdialog)
405{
406 fc_assert_ret(NULL != pdialog);
407
408 gui_dialog_destroy(pdialog->shell);
409 fc_assert(NULL == pdialog->shell);
410
411 memset(pdialog, 0, sizeof(*pdialog));
412}
413
414/************************************************************************/
418{
419 if (NULL == meswin.shell) {
421 }
422
424 if (raise) {
426 }
427}
428
429/************************************************************************/
433{
434 if (NULL != meswin.shell) {
437 }
438}
439
440/************************************************************************/
444{
445 return (NULL != meswin.shell);
446}
447
448/************************************************************************/
452{
453 if (NULL != meswin.shell) {
455 }
456}
char * incite_cost
Definition comments.c:76
#define _(String)
Definition fcintl.h:67
GtkWidget * bottom_notebook
Definition gui_main.c:130
GtkWidget * right_notebook
Definition gui_main.c:130
#define GUI_GTK_OPTION(optname)
Definition gui_main.h:25
void gui_dialog_destroy(struct gui_dialog *dlg)
Definition gui_stuff.c:954
void gui_dialog_present(struct gui_dialog *dlg)
Definition gui_stuff.c:835
void gui_dialog_raise(struct gui_dialog *dlg)
Definition gui_stuff.c:865
void gui_dialog_new(struct gui_dialog **pdlg, GtkNotebook *notebook, gpointer user_data, bool check_top)
Definition gui_stuff.c:517
void gui_dialog_response_set_callback(struct gui_dialog *dlg, GUI_DIALOG_RESPONSE_FUN fun)
Definition gui_stuff.c:988
void gui_dialog_show_all(struct gui_dialog *dlg)
Definition gui_stuff.c:795
void gui_dialog_set_title(struct gui_dialog *dlg, const char *title)
Definition gui_stuff.c:935
void gui_dialog_set_default_size(struct gui_dialog *dlg, int width, int height)
Definition gui_stuff.c:919
void gui_dialog_alert(struct gui_dialog *dlg)
Definition gui_stuff.c:888
GtkWidget * gui_dialog_add_button(struct gui_dialog *dlg, const char *icon_name, const char *text, int response)
Definition gui_stuff.c:706
void gui_dialog_set_response_sensitive(struct gui_dialog *dlg, int response, bool setting)
Definition gui_stuff.c:760
static void meswin_dialog_init(struct meswin_dialog *pdialog)
Definition messagewin.c:319
static gboolean meswin_dialog_button_press_callback(GtkWidget *widget, GdkEventButton *ev, gpointer data)
Definition messagewin.c:247
void meswin_dialog_popdown(void)
Definition messagewin.c:432
static void meswin_dialog_visited_get_attr(bool visited, gint *weight, gint *style)
Definition messagewin.c:88
static void meswin_dialog_row_activated_callback(GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data)
Definition messagewin.c:221
static void meswin_dialog_set_visited(GtkTreeModel *model, GtkTreeIter *iter, bool visited)
Definition messagewin.c:102
static struct meswin_dialog meswin
Definition messagewin.c:70
static GtkListStore * meswin_dialog_store_new(void)
Definition messagewin.c:75
static void meswin_dialog_response_callback(struct gui_dialog *pgui_dialog, int response, gpointer data)
Definition messagewin.c:280
void meswin_dialog_popup(bool raise)
Definition messagewin.c:417
static void meswin_dialog_refresh(struct meswin_dialog *pdialog)
Definition messagewin.c:119
meswin_columns
Definition messagewin.c:53
@ MESWIN_COL_NUM
Definition messagewin.c:62
@ MESWIN_COL_MESSAGE
Definition messagewin.c:55
@ MESWIN_COL_STYLE
Definition messagewin.c:59
@ MESWIN_COL_ID
Definition messagewin.c:60
@ MESWIN_COL_ICON
Definition messagewin.c:54
@ MESWIN_COL_WEIGHT
Definition messagewin.c:58
meswin_responses
Definition messagewin.c:65
@ MESWIN_RES_GOTO
Definition messagewin.c:66
@ MESWIN_RES_POPUP_CITY
Definition messagewin.c:67
static void meswin_dialog_free(struct meswin_dialog *pdialog)
Definition messagewin.c:404
static void meswin_dialog_selection_callback(GtkTreeSelection *selection, gpointer data)
Definition messagewin.c:196
void real_meswin_dialog_update(void *unused)
Definition messagewin.c:451
bool meswin_dialog_is_open(void)
Definition messagewin.c:443
GdkPixbuf * sprite_get_pixbuf(struct sprite *sprite)
Definition sprite.c:402
void sprite_get_bounding_box(struct sprite *sprite, int *start_x, int *start_y, int *end_x, int *end_y)
Definition sprite.c:321
#define fc_assert_ret(condition)
Definition log.h:192
#define fc_assert(condition)
Definition log.h:177
#define fc_assert_ret_val(condition, val)
Definition log.h:195
void meswin_popup_city(int message_index)
void meswin_goto(int message_index)
int meswin_get_num_messages(void)
const struct message * meswin_get_message(int message_index)
void meswin_double_click(int message_index)
void meswin_set_visited_state(int message_index, bool state)
@ GUI_GTK_MSGCHAT_SPLIT
Definition options.h:67
GtkWidget * vbox
Definition gui_stuff.h:72
GtkTreeView * tree_view
Definition messagewin.c:49
struct gui_dialog * shell
Definition messagewin.c:48
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
struct sprite * get_event_sprite(const struct tileset *t, enum event_type event)
Definition tilespec.c:7124