Freeciv-3.2
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-4.0 */
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
47struct meswin_dialog {
48 struct gui_dialog *shell;
50};
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/************************************************************************/
248 int n_press,
249 double x, double y)
250{
252 GtkTreePath *path = NULL;
253 GtkTreeModel *model;
255 gint row;
256
258
260 &path, NULL, NULL, NULL)) {
261 return TRUE;
262 }
263
265 if (gtk_tree_model_get_iter(model, &iter, path)) {
268 }
269
270 gtk_tree_path_free(path);
271
272 return TRUE;
273}
274
275/************************************************************************/
279 int response, gpointer data)
280{
281 struct meswin_dialog *pdialog = data;
282 GtkTreeSelection *selection;
283 GtkTreeModel *model;
285 gint row;
286
287 switch (response) {
288 case MESWIN_RES_GOTO:
290 break;
291 default:
293 return;
294 }
295
296 selection = gtk_tree_view_get_selection(pdialog->tree_view);
297 if (!gtk_tree_selection_get_selected(selection, &model, &iter)) {
298 return;
299 }
300
302
303 switch (response) {
304 case MESWIN_RES_GOTO:
306 break;
309 break;
310 }
312}
313
314/************************************************************************/
317static void meswin_dialog_init(struct meswin_dialog *pdialog)
318{
319 GtkWidget *view, *sw, *cmd, *notebook;
320 GtkListStore *store;
321 GtkTreeSelection *selection;
322 GtkCellRenderer *renderer;
326
327 fc_assert_ret(NULL != pdialog);
328
330 notebook = right_notebook;
331 } else {
332 notebook = bottom_notebook;
333 }
334
335 gui_dialog_new(&pdialog->shell, GTK_NOTEBOOK(notebook), pdialog, TRUE);
336 gui_dialog_set_title(pdialog->shell, _("Messages"));
337
343
344 store = meswin_dialog_store_new();
348 g_object_unref(store);
351 g_signal_connect(view, "row_activated",
353
357 g_signal_connect(controller, "pressed",
360
361 pdialog->tree_view = GTK_TREE_VIEW(view);
362
363 renderer = gtk_cell_renderer_pixbuf_new();
365 "pixbuf", MESWIN_COL_ICON, NULL);
368
369 renderer = gtk_cell_renderer_text_new();
371 "text", MESWIN_COL_MESSAGE,
372 "weight", MESWIN_COL_WEIGHT,
373 "style", MESWIN_COL_STYLE,
374 NULL);
377
379 g_signal_connect(selection, "changed",
381
382 gui_dialog_add_button(pdialog->shell, "window-close", _("_Close"),
384
386 cmd = gui_dialog_add_button(pdialog->shell, "zoom-in",
387 _("I_nspect City"),
390
391 cmd = gui_dialog_add_button(pdialog->shell, "go-jump",
392 _("Goto _Location"), MESWIN_RES_GOTO);
394 }
395
398 gui_dialog_set_default_size(pdialog->shell, 520, 300);
399
400 meswin_dialog_refresh(pdialog);
401 gui_dialog_show_all(pdialog->shell);
402}
403
404/************************************************************************/
407static void meswin_dialog_free(struct meswin_dialog *pdialog)
408{
409 fc_assert_ret(NULL != pdialog);
410
411 gui_dialog_destroy(pdialog->shell);
412 fc_assert(NULL == pdialog->shell);
413
414 memset(pdialog, 0, sizeof(*pdialog));
415}
416
417/************************************************************************/
421{
422 if (NULL == meswin.shell) {
424 }
425
427 if (raise) {
429 }
430}
431
432/************************************************************************/
436{
437 if (NULL != meswin.shell) {
440 }
441}
442
443/************************************************************************/
447{
448 return (NULL != meswin.shell);
449}
450
451/************************************************************************/
455{
456 if (NULL != meswin.shell) {
458 }
459}
char * incite_cost
Definition comments.c:75
#define _(String)
Definition fcintl.h:67
GtkWidget * bottom_notebook
Definition gui_main.c:129
GtkWidget * right_notebook
Definition gui_main.c:129
#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
void gui_dialog_add_content_widget(struct gui_dialog *dlg, GtkWidget *wdg)
Definition gui_stuff.c:1104
#define fc_assert_ret(condition)
Definition log.h:191
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_ret_val(condition, val)
Definition log.h:194
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
struct sprite int int y
Definition sprite_g.h:31
struct sprite int x
Definition sprite_g.h:31
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:6900