Freeciv-3.2
Loading...
Searching...
No Matches
chatline.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#include <time.h>
22
23#include <gdk/gdkkeysyms.h>
24
25/* utility */
26#include "fcintl.h"
27#include "genlist.h"
28#include "log.h"
29#include "mem.h"
30#include "support.h"
31
32/* common */
33#include "chat.h"
34#include "featured_text.h"
35#include "game.h"
36#include "packets.h"
37
38/* client */
39#include "client_main.h"
40#include "climap.h"
41#include "control.h"
42#include "mapview_common.h"
43
44/* client/gui-gtk-3.22 */
45#include "colors.h"
46#include "gui_main.h"
47#include "gui_stuff.h"
48#include "pages.h"
49
50#include "chatline.h"
51
52#define MAX_CHATLINE_HISTORY 20
53
54static struct genlist *history_list = NULL;
55static int history_pos = -1;
56
65
67
68/**********************************************************************/
72{
73 return gtk_widget_has_focus(toolkit.entry);
74}
75
76/**********************************************************************/
83
84/**********************************************************************/
88{
89 return gtk_widget_get_mapped(toolkit.entry);
90}
91
92/**********************************************************************/
97static bool is_plain_public_message(const char *s)
98{
99 const char *p;
100
101 /* If it is a server command or an explicit ally
102 * message, then it is not a public message. */
103 if (s[0] == SERVER_COMMAND_PREFIX || s[0] == CHAT_ALLIES_PREFIX) {
104 return FALSE;
105 }
106
107 /* It might be a private message of the form
108 * 'player name with spaces':the message
109 * or with ". So skip past the player name part. */
110 if (s[0] == '\'' || s[0] == '"') {
111 p = strchr(s + 1, s[0]);
112 } else {
113 p = s;
114 }
115
116 /* Now we just need to check that it is not a private
117 * message. If we encounter a space then the preceding
118 * text could not have been a user/player name (the
119 * quote check above eliminated names with spaces) so
120 * it must be a public message. Otherwise if we encounter
121 * the message prefix : then the text parsed up until now
122 * was a player/user name and the line is intended as
123 * a private message (or explicit public message if the
124 * first character is :). */
125 while (p != NULL && *p != '\0') {
126 if (fc_isspace(*p)) {
127 return TRUE;
128 } else if (*p == CHAT_DIRECT_PREFIX) {
129 return FALSE;
130 }
131 p++;
132 }
133 return TRUE;
134}
135
136/**********************************************************************/
139static void inputline_return(GtkEntry *w, gpointer data)
140{
141 const char *theinput;
142
144
145 if (*theinput) {
149 char buf[MAX_LEN_MSG];
150
151 fc_snprintf(buf, sizeof(buf), ". %s", theinput);
152 send_chat(buf);
153 } else {
155 }
156
158 void *history_data;
159
163 }
164
166 history_pos = -1;
167 }
168
169 gtk_entry_set_text(w, "");
170}
171
172/**********************************************************************/
175static const char *get_player_or_user_name(int id)
176{
178
179 if (id < size) {
180 return conn_list_get(game.all_connections, id)->username;
181 } else {
182 struct player *pplayer = player_by_number(id - size);
183 if (pplayer) {
184 return pplayer->name;
185 } else {
186 /* Empty slot. Relies on being used with comparison function
187 * which can cope with NULL. */
188 return NULL;
189 }
190 }
191}
192
193/**********************************************************************/
202static int check_player_or_user_name(const char *prefix,
203 const char **matches,
204 const int max_matches)
205{
206 int matches_id[max_matches * 2], ind, num;
207
212 prefix, &ind, matches_id,
213 max_matches * 2, &num)) {
214 case M_PRE_EXACT:
215 case M_PRE_ONLY:
217 return 1;
218 case M_PRE_AMBIGUOUS:
219 {
220 /* Remove duplications playername/username. */
221 const char *name;
222 int i, j, c = 0;
223
224 for (i = 0; i < num && c < max_matches; i++) {
226 for (j = 0; j < c; j++) {
227 if (0 == fc_strncasecmp(name, matches[j], MAX_LEN_NAME)) {
228 break;
229 }
230 }
231 if (j >= c) {
232 matches[c++] = name;
233 }
234 }
235 return c;
236 }
237 case M_PRE_EMPTY:
238 case M_PRE_LONG:
239 case M_PRE_FAIL:
240 case M_PRE_LAST:
241 break;
242 }
243
244 return 0;
245}
246
247/**********************************************************************/
257static size_t get_common_prefix(const char *const *prefixes,
258 size_t num_prefixes,
259 char *buf, size_t buf_len)
260{
261 const char *p;
262 char *q;
263 size_t i;
264
266 for (i = 1; i < num_prefixes; i++) {
267 for (p = prefixes[i], q = buf; *p != '\0' && *q != '\0';
271 *q = '\0';
272 break;
273 }
274 }
275 }
276
277 return g_utf8_strlen(buf, -1);
278}
279
280/**********************************************************************/
285{
286#define MAX_MATCHES 10
287 const char *name[MAX_MATCHES];
289 gint pos;
290 gchar *chars, *p, *prev;
291 int num, i;
292 size_t prefix_len;
293
294 /* Part 1: get the string to complete. */
297
298 p = chars + strlen(chars);
299 while ((prev = g_utf8_find_prev_char(chars, p))) {
301 break;
302 }
303 p = prev;
304 }
305 /* p points to the start of the last word, or the start of the string. */
306
307 prefix_len = g_utf8_strlen(p, -1);
308 if (0 == prefix_len) {
309 /* Empty: nothing to complete, propagate the event. */
310 g_free(chars);
311 return FALSE;
312 }
313
314 /* Part 2: compare with player and user names. */
316 if (1 == num) {
318 pos -= prefix_len;
321 g_free(chars);
322 return TRUE;
323 } else if (num > 1) {
324 if (get_common_prefix(name, num, buf, sizeof(buf)) > prefix_len) {
326 pos -= prefix_len;
329 }
330 sz_strlcpy(buf, name[0]);
331 for (i = 1; i < num; i++) {
332 cat_snprintf(buf, sizeof(buf), ", %s", name[i]);
333 }
334 /* TRANS: comma-separated list of player/user names for completion */
335 output_window_printf(ftc_client, _("Suggestions: %s."), buf);
336 }
337
338 g_free(chars);
339 return TRUE;
340}
341
342/**********************************************************************/
346{
347 if ((ev->state & GDK_CONTROL_MASK)) {
348 /* Chatline featured text support. */
349 switch (ev->keyval) {
350 case GDK_KEY_b:
352 return TRUE;
353
354 case GDK_KEY_c:
356 return TRUE;
357
358 case GDK_KEY_i:
360 return TRUE;
361
362 case GDK_KEY_s:
364 return TRUE;
365
366 case GDK_KEY_u:
368 return TRUE;
369
370 default:
371 break;
372 }
373
374 } else {
375 /* Chatline history controls. */
376 switch (ev->keyval) {
377 case GDK_KEY_Up:
382 }
383 return TRUE;
384
385 case GDK_KEY_Down:
386 if (history_pos >= 0) {
387 history_pos--;
388 }
389
390 if (history_pos >= 0) {
393 } else {
395 }
397 return TRUE;
398
399 case GDK_KEY_Tab:
402 }
403 return FALSE;
404
405 default:
406 break;
407 }
408 }
409
410 return FALSE;
411}
412
413/**********************************************************************/
417{
418 char buf[MAX_LEN_MSG];
421 gchar *selection;
423
425 /* Let's say the selection starts and ends at the current position. */
427 }
428
430
431 if (type == TTT_COLOR) {
432 /* Get the color arguments. */
435
436 if (!fg_color && !bg_color) {
437 goto CLEAN_UP;
438 }
439
440 if (fg_color) {
442 }
443 if (bg_color) {
445 }
446
447 if (0 == featured_text_apply_tag(selection, buf, sizeof(buf),
450 bg_color_text))) {
451 goto CLEAN_UP;
452 }
453 } else if (0 == featured_text_apply_tag(selection, buf, sizeof(buf),
454 type, 0, FT_OFFSET_UNSET)) {
455 goto CLEAN_UP;
456 }
457
458 /* Replace the selection. */
463
465 g_free(selection);
468}
469
470/**********************************************************************/
474void inputline_make_chat_link(struct tile *ptile, bool unit)
475{
476 char buf[MAX_LEN_MSG];
477 GtkWidget *entry = toolkit.entry;
480 gchar *chars;
481 struct unit *punit;
482
483 /* Get the target. */
484 if (unit) {
485 punit = find_visible_unit(ptile);
486 if (!punit) {
487 output_window_append(ftc_client, _("No visible unit on this tile."));
488 return;
489 }
490 } else {
491 punit = NULL;
492 }
493
495 /* There is a selection, make it clickable. */
496 gpointer target;
497 enum text_link_type type;
498
500 if (punit) {
501 type = TLT_UNIT;
502 target = punit;
503 } else if (tile_city(ptile)) {
504 type = TLT_CITY;
505 target = tile_city(ptile);
506 } else {
507 type = TLT_TILE;
508 target = ptile;
509 }
510
511 if (0 != featured_text_apply_tag(chars, buf, sizeof(buf), TTT_LINK,
512 0, FT_OFFSET_UNSET, type, target)) {
513 /* Replace the selection. */
519 }
520 } else {
521 /* Just insert the link at the current position. */
525 start_pos + 1);
526 if (punit) {
528 } else if (tile_city(ptile)) {
530 } else {
531 sz_strlcpy(buf, tile_link(ptile));
532 }
533
534 if (start_pos > 0 && strlen(chars) > 0 && chars[0] != ' ') {
535 /* Maybe insert an extra space. */
537 }
539 if (chars[start_pos > 0 ? 1 : 0] != '\0'
540 && chars[start_pos > 0 ? 1 : 0] != ' ') {
541 /* Maybe insert an extra space. */
543 }
546 }
547
548 g_free(chars);
549}
550
551/**********************************************************************/
580
581/**********************************************************************/
585{
586 GtkTextIter start, end, iter;
587 GtkTextBuffer *buffer;
588 GSList *tags, *tagp;
589 gint x, y;
590 struct tile *ptile = NULL;
591
592 if (event->type != GDK_BUTTON_RELEASE || event->button != 1) {
593 return FALSE;
594 }
595
597
598 /* We shouldn't follow a link if the user has selected something. */
599 gtk_text_buffer_get_selection_bounds(buffer, &start, &end);
601 return FALSE;
602 }
603
606 event->x, event->y, &x, &y);
607
609
610 if ((tags = gtk_text_iter_get_tags(&iter))) {
611 for (tagp = tags; tagp; tagp = tagp->next) {
612 GtkTextTag *tag = tagp->data;
613 enum text_link_type type =
615
616 if (type != 0) {
617 /* This is a link. */
618 int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(tag), "id"));
619 ptile = NULL;
620
621 /* Real type is type - 1.
622 * See comment in apply_text_tag() for g_object_set_data(). */
623 type--;
624
625 switch (type) {
626 case TLT_CITY:
627 {
628 struct city *pcity = game_city_by_number(id);
629
630 if (pcity) {
631 ptile = client_city_tile(pcity);
632 } else {
633 output_window_append(ftc_client, _("This city isn't known!"));
634 }
635 }
636 break;
637 case TLT_TILE:
638 ptile = index_to_tile(&(wld.map), id);
639
640 if (!ptile) {
642 _("This tile doesn't exist in this game!"));
643 }
644 break;
645 case TLT_UNIT:
646 {
647 struct unit *punit = game_unit_by_number(id);
648
649 if (punit) {
650 ptile = unit_tile(punit);
651 } else {
652 output_window_append(ftc_client, _("This unit isn't known!"));
653 }
654 }
655 break;
656 }
657
658 if (ptile) {
662 }
663 }
664 }
665 g_slist_free(tags);
666 }
667
668 return FALSE;
669}
670
671/**********************************************************************/
675{
677 static GdkCursor *hand_cursor = NULL;
678 static GdkCursor *regular_cursor = NULL;
679 GSList *tags, *tagp;
682
683 /* Initialize the cursors. */
684 if (!hand_cursor) {
687 }
688 if (!regular_cursor) {
691 }
692
694
696 for (tagp = tags; tagp; tagp = tagp->next) {
697 enum text_link_type type =
699
700 if (type != 0) {
701 hovering = TRUE;
702 break;
703 }
704 }
705
708
709 if (hovering_over_link) {
713 } else {
717 }
718 }
719
720 if (tags) {
721 g_slist_free(tags);
722 }
723}
724
725/**********************************************************************/
740
741/**********************************************************************/
751
752/**********************************************************************/
756 ft_offset_t text_start_offset, const char *text)
757{
758 static bool initialized = FALSE;
759 GtkTextIter start, stop;
760
761 if (!initialized) {
763 "weight", PANGO_WEIGHT_BOLD, NULL);
765 "style", PANGO_STYLE_ITALIC, NULL);
767 "strikethrough", TRUE, NULL);
768 gtk_text_buffer_create_tag(buf, "underline",
769 "underline", PANGO_UNDERLINE_SINGLE, NULL);
771 }
772
773 /* Get the position. */
774 /*
775 * N.B.: text_tag_*_offset() value is in bytes, so we need to convert it
776 * to utf8 character offset.
777 */
780 text + text_tag_start_offset(ptag)));
783 } else {
786 text + text_tag_stop_offset(ptag)));
787 }
788
789 switch (text_tag_type(ptag)) {
790 case TTT_BOLD:
791 gtk_text_buffer_apply_tag_by_name(buf, "bold", &start, &stop);
792 break;
793 case TTT_ITALIC:
794 gtk_text_buffer_apply_tag_by_name(buf, "italic", &start, &stop);
795 break;
796 case TTT_STRIKE:
797 gtk_text_buffer_apply_tag_by_name(buf, "strike", &start, &stop);
798 break;
799 case TTT_UNDERLINE:
800 gtk_text_buffer_apply_tag_by_name(buf, "underline", &start, &stop);
801 break;
802 case TTT_COLOR:
803 {
804 /* We have to make a new tag every time. */
805 GtkTextTag *tag = NULL;
806 const char *foreground = text_tag_color_foreground(ptag);
807 const char *background = text_tag_color_background(ptag);
808
809 if (foreground && foreground[0]) {
810 if (background && background[0]) {
812 "foreground", foreground,
813 "background", background,
814 NULL);
815 } else {
817 "foreground", foreground,
818 NULL);
819 }
820 } else if (background && background[0]) {
822 "background", background,
823 NULL);
824 }
825
826 if (!tag) {
827 break; /* No color. */
828 }
829 gtk_text_buffer_apply_tag(buf, tag, &start, &stop);
830 }
831 break;
832 case TTT_LINK:
833 {
834 struct color *pcolor = NULL;
835 GtkTextTag *tag;
836
837 switch (text_tag_link_type(ptag)) {
838 case TLT_CITY:
840 break;
841 case TLT_TILE:
843 break;
844 case TLT_UNIT:
846 break;
847 }
848
849 if (!pcolor) {
850 break; /* Not a valid link type case. */
851 }
852
854 "foreground-rgba", &pcolor->color,
855 "underline", PANGO_UNDERLINE_SINGLE,
856 NULL);
857
858 /* Type 0 is reserved for non-link tags. So, add 1 to the
859 * type value. */
860 g_object_set_data(G_OBJECT(tag), "type",
862 g_object_set_data(G_OBJECT(tag), "id",
864 gtk_text_buffer_apply_tag(buf, tag, &start, &stop);
865 break;
866 }
867 }
868}
869
870/**********************************************************************/
875 const struct text_tag_list *tags,
876 int conn_id)
877{
882
884
885 if (buf == NULL) {
886 log_error("Output when no message buffer: %s", astring);
887
888 return;
889 }
890
892 gtk_text_buffer_insert(buf, &iter, "\n", -1);
894
896 char timebuf[64];
897 time_t now;
898 struct tm now_tm;
899
900 now = time(NULL);
902 strftime(timebuf, sizeof(timebuf), "[%H:%M:%S] ", &now_tm);
904 }
905
911
912 if (main_message_area) {
914 }
915 if (start_message_area) {
917 }
919
921}
922
923/**********************************************************************/
929{
930 GtkTextIter start, end;
931 gchar *txt;
932
935
937 g_free(txt);
938}
939
940/**********************************************************************/
944{
945 set_output_window_text(_("Cleared output window."));
946}
947
948/**********************************************************************/
951void set_output_window_text(const char *text)
952{
954}
955
956/**********************************************************************/
960{
961 GtkWidget *sw, *w;
963 gdouble val, max, upper, page_size;
964
965 if (get_client_page() == PAGE_GAME) {
967 } else {
969 }
970
971 if (w == NULL) {
972 return TRUE;
973 }
974
975 sw = gtk_widget_get_parent(w);
978 g_object_get(G_OBJECT(vadj), "upper", &upper,
979 "page-size", &page_size, NULL);
980 max = upper - page_size;
981
982 /* Approximation. */
983 return max - val < 0.00000001;
984}
985
986/**********************************************************************/
995{
996 chatline_scroll_to_bottom(FALSE); /* Not delayed this time! */
997
998 *((guint *) data) = 0;
999 return FALSE; /* Remove this idle function. */
1000}
1001
1002/**********************************************************************/
1007{
1008 static guint callback_id = 0;
1009
1010 if (delayed) {
1011 if (callback_id == 0) {
1013 }
1014 } else if (message_buffer) {
1015 GtkTextIter end;
1016
1018
1019 if (main_message_area) {
1021 &end, 0.0, TRUE, 1.0, 0.0);
1022 }
1023 if (start_message_area) {
1025 &end, 0.0, TRUE, 1.0, 0.0);
1026 }
1027 }
1028}
1029
1030/**********************************************************************/
1033static void make_tag_callback(GtkToolButton *button, gpointer data)
1034{
1037 "text_tag_type")));
1038}
1039
1040/**********************************************************************/
1043static void color_set(GObject *object, const gchar *color_target,
1044 GdkRGBA *color, GtkToolButton *button)
1045{
1047
1048 if (NULL == color) {
1049 /* Clears the current color. */
1050 if (NULL != current_color) {
1053 if (NULL != button) {
1055 }
1056 }
1057 } else {
1058 /* Apply the new color. */
1059 if (NULL != current_color) {
1060 /* We already have a GdkRGBA pointer. */
1061 *current_color = *color;
1062 } else {
1063 /* We need to make a GdkRGBA pointer. */
1066 }
1067
1068 if (NULL != button) {
1069 /* Update the button. */
1072
1073 {
1075 CAIRO_FORMAT_RGB24, 16, 16);
1076 cairo_t *cr = cairo_create(surface);
1078 cairo_paint(cr);
1079 cairo_destroy(cr);
1080 pixbuf = gdk_pixbuf_get_from_surface(surface, 0, 0, 16, 16);
1081 cairo_surface_destroy(surface);
1082 }
1087 }
1088 }
1089}
1090
1091/**********************************************************************/
1094static void color_selected(GtkDialog *dialog, gint res, gpointer data)
1095{
1096 GtkToolButton *button =
1097 GTK_TOOL_BUTTON(g_object_get_data(G_OBJECT(dialog), "button"));
1098 const gchar *color_target =
1099 g_object_get_data(G_OBJECT(button), "color_target");
1100
1101 if (res == GTK_RESPONSE_REJECT) {
1102 /* Clears the current color. */
1103 color_set(G_OBJECT(data), color_target, NULL, button);
1104 } else if (res == GTK_RESPONSE_OK) {
1105 /* Apply the new color. */
1107 GTK_COLOR_CHOOSER(g_object_get_data(G_OBJECT(dialog), "chooser"));
1109
1111 color_set(G_OBJECT(data), color_target, &new_color, button);
1112 }
1113
1115}
1116
1117/**********************************************************************/
1121{
1122 GtkWidget *dialog, *chooser;
1123 /* "fg_color" or "bg_color". */
1125 "color_target");
1127
1128 /* TRANS: "text" or "background". */
1129 gchar *buf = g_strdup_printf(_("Select the %s color"),
1130 (const char *) g_object_get_data(G_OBJECT(button),
1131 "color_info"));
1133 _("_Cancel"), GTK_RESPONSE_CANCEL,
1134 _("C_lear"), GTK_RESPONSE_REJECT,
1135 _("_OK"), GTK_RESPONSE_OK, NULL);
1136 setup_dialog(dialog, toplevel);
1137 g_object_set_data(G_OBJECT(dialog), "button", button);
1138 g_signal_connect(dialog, "response", G_CALLBACK(color_selected), data);
1139
1142 chooser, FALSE, FALSE, 0);
1143 g_object_set_data(G_OBJECT(dialog), "chooser", chooser);
1144 if (current_color) {
1146 }
1147
1148 gtk_widget_show_all(dialog);
1149 g_free(buf);
1150}
1151
1152/**********************************************************************/
1156 gpointer data)
1157{
1158 struct inputline_toolkit *ptoolkit = (struct inputline_toolkit *) data;
1161 "button_box"));
1162 GList *list, *iter;
1163
1164 if (parent) {
1165 if (parent == toolkit_view) {
1166 return FALSE; /* Already owned. */
1167 }
1168
1169 /* N.B.: We need to hide/show the toolbar to reset the sensitivity
1170 * of the tool buttons. */
1171 if (ptoolkit->toolbar_displayed) {
1172 gtk_widget_hide(ptoolkit->toolbar);
1173 }
1174 g_object_ref(ptoolkit->main_widget); /* Make sure reference count stays above 0
1175 * during the transition to new parent. */
1178 g_object_unref(ptoolkit->main_widget);
1179 if (ptoolkit->toolbar_displayed) {
1180 gtk_widget_show(ptoolkit->toolbar);
1181 }
1182
1184 /* Attach to the toolkit button_box. */
1186 }
1187 gtk_widget_show_all(ptoolkit->main_widget);
1188 if (!ptoolkit->toolbar_displayed) {
1189 gtk_widget_hide(ptoolkit->toolbar);
1190 }
1191
1192 /* Hide all other buttons boxes. */
1194 for (iter = list; iter != NULL; iter = g_list_next(iter)) {
1195 GtkWidget *widget = GTK_WIDGET(iter->data);
1196
1197 if (widget != button_box) {
1199 }
1200 }
1202
1203 } else {
1204 /* First time attached to a parent. */
1207 gtk_widget_show_all(ptoolkit->main_widget);
1208 }
1209
1210 return FALSE;
1211}
1212
1213/**********************************************************************/
1217 gpointer data)
1218{
1219 struct inputline_toolkit *ptoolkit = (struct inputline_toolkit *) data;
1220 GtkToggleButton *button = GTK_TOGGLE_BUTTON(toolkit.toggle_button);
1221
1222 if (ptoolkit->toolbar_displayed) {
1223 if (!gtk_toggle_button_get_active(button)) {
1224 /* button_toggled() will be called and the toolbar shown. */
1226 } else {
1227 /* Ensure the widget is visible. */
1228 gtk_widget_show(ptoolkit->toolbar);
1229 }
1230 } else {
1231 if (gtk_toggle_button_get_active(button)) {
1232 /* button_toggled() will be called and the toolbar hidden. */
1234 } else {
1235 /* Ensure the widget is not visible. */
1236 gtk_widget_hide(ptoolkit->toolbar);
1237 }
1238 }
1239
1240 return FALSE;
1241}
1242
1243/**********************************************************************/
1246static void button_toggled(GtkToggleButton *button, gpointer data)
1247{
1248 struct inputline_toolkit *ptoolkit = (struct inputline_toolkit *) data;
1249
1250 if (gtk_toggle_button_get_active(button)) {
1251 gtk_widget_show(ptoolkit->toolbar);
1252 ptoolkit->toolbar_displayed = TRUE;
1254 /* Make sure to be still at the end. */
1256 }
1257 } else {
1258 gtk_widget_hide(ptoolkit->toolbar);
1259 ptoolkit->toolbar_displayed = FALSE;
1260 }
1261}
1262
1263/**********************************************************************/
1288
1289/**********************************************************************/
1298
1299/**********************************************************************/
1303{
1304 GtkWidget *vbox, *toolbar, *hbox, *button, *entry, *bbox;
1306 GdkRGBA color;
1307
1308 /* Chatline history. */
1309 if (!history_list) {
1311 history_pos = -1;
1312 }
1313
1314 /* Inputline toolkit. */
1315 memset(&toolkit, 0, sizeof(toolkit));
1316
1317 vbox = gtk_grid_new();
1321 toolkit.main_widget = vbox;
1322 g_signal_connect_after(vbox, "map",
1324
1325 entry = gtk_entry_new();
1326 g_object_set(entry, "margin", 2, NULL);
1328 toolkit.entry = entry;
1329
1330 /* First line: toolbar */
1338 toolkit.toolbar = toolbar;
1339
1340 /* Bold button. */
1341 item = gtk_tool_button_new(gtk_image_new_from_icon_name("format-text-bold", 0),
1342 _("Bold"));
1343
1345 g_object_set_data(G_OBJECT(item), "text_tag_type",
1348 gtk_widget_set_tooltip_text(GTK_WIDGET(item), _("Bold (Ctrl-B)"));
1349
1350 /* Italic button. */
1351 item = gtk_tool_button_new(gtk_image_new_from_icon_name("format-text-italic", 0),
1352 _("Italic"));
1354 g_object_set_data(G_OBJECT(item), "text_tag_type",
1357 gtk_widget_set_tooltip_text(GTK_WIDGET(item), _("Italic (Ctrl-I)"));
1358
1359 /* Strike button. */
1360 item = gtk_tool_button_new(gtk_image_new_from_icon_name("format-text-strikethrough", 0),
1361 _("Strikethrough"));
1363 g_object_set_data(G_OBJECT(item), "text_tag_type",
1366 gtk_widget_set_tooltip_text(GTK_WIDGET(item), _("Strikethrough (Ctrl-S)"));
1367
1368 /* Underline button. */
1369 item = gtk_tool_button_new(gtk_image_new_from_icon_name("format-text-underline", 0),
1370 _("Underline"));
1372 g_object_set_data(G_OBJECT(item), "text_tag_type",
1375 gtk_widget_set_tooltip_text(GTK_WIDGET(item), _("Underline (Ctrl-U)"));
1376
1377 /* Color button. */
1378 item = gtk_tool_button_new(NULL, _("Color"));
1380 g_object_set_data(G_OBJECT(item), "text_tag_type",
1383 gtk_widget_set_tooltip_text(GTK_WIDGET(item), _("Color (Ctrl-C)"));
1384
1387
1388 /* Foreground selector. */
1391 g_object_set_data(G_OBJECT(item), "color_target", fc_strdup("fg_color"));
1392 g_object_set_data(G_OBJECT(item), "color_info",
1393 fc_strdup(_("foreground")));
1394 g_signal_connect(item, "clicked",
1396 gtk_widget_set_tooltip_text(GTK_WIDGET(item), _("Select the text color"));
1397 if (gdk_rgba_parse(&color, "#000000")) {
1398 /* Set default foreground color. */
1400 } else {
1401 log_error("Failed to set the default foreground color.");
1402 }
1403
1404 /* Background selector. */
1407 g_object_set_data(G_OBJECT(item), "color_target", fc_strdup("bg_color"));
1408 g_object_set_data(G_OBJECT(item), "color_info",
1409 fc_strdup(_("background")));
1410 g_signal_connect(item, "clicked",
1413 _("Select the background color"));
1414 if (gdk_rgba_parse(&color, "#ffffff")) {
1415 /* Set default background color. */
1417 } else {
1418 log_error("Failed to set the default background color.");
1419 }
1420
1423
1424 /* Return button. */
1425 item = gtk_tool_button_new(NULL, _("OK"));
1427 g_signal_connect_swapped(item, "clicked",
1430 /* TRANS: "Return" means the return key. */
1431 _("Send the chat (Return)"));
1432
1433 /* Second line */
1434 hbox = gtk_grid_new();
1437
1438 /* Toggle button. */
1439 button = gtk_toggle_button_new();
1440 g_object_set(button, "margin", 2, NULL);
1443 gtk_image_new_from_icon_name("gtk-edit", 0));
1444 g_signal_connect(button, "toggled", G_CALLBACK(button_toggled), &toolkit);
1445 gtk_widget_set_tooltip_text(GTK_WIDGET(button), _("Chat tools"));
1446 toolkit.toggle_button = button;
1447
1448 /* Entry. */
1451 g_signal_connect(entry, "key_press_event",
1453
1454 /* Button box. */
1455 bbox = gtk_grid_new();
1457 toolkit.button_box = bbox;
1458}
1459
1460/**********************************************************************/
1464{
1465 char *vertext = (char *)user_data;
1466
1468
1470
1471 return G_SOURCE_REMOVE;
1472}
1473
1474/**********************************************************************/
1477void version_message(const char *vertext)
1478{
1479 int len = strlen(vertext) + 1;
1480 char *persistent = fc_malloc(len);
1481
1483
1485}
struct canvas int int int int struct sprite *sprite struct canvas struct color * pcolor
Definition canvas_g.h:56
#define CHAT_DIRECT_PREFIX
Definition chat.h:31
#define CHAT_ALLIES_PREFIX
Definition chat.h:30
#define SERVER_COMMAND_PREFIX
Definition chat.h:28
int send_chat(const char *message)
void output_window_append(const struct ft_color color, const char *featured_text)
void write_chatline_content(const char *txt)
void output_window_printf(const struct ft_color color, const char *format,...)
enum client_states client_state(void)
@ C_S_RUNNING
Definition client_main.h:47
struct tile * client_city_tile(const struct city *pcity)
Definition climap.c:87
static struct fc_sockaddr_list * list
Definition clinet.c:102
struct color * get_color(const struct tileset *t, enum color_std stdcolor)
char * incite_cost
Definition comments.c:75
#define MAX_LEN_MSG
Definition conn_types.h:37
struct unit * find_visible_unit(struct tile *ptile)
Definition control.c:822
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
static bool initialized
Definition effects.c:42
enum event_type event
Definition events.c:81
#define MAX_LEN_NAME
Definition fc_types.h:66
#define _(String)
Definition fcintl.h:67
size_t featured_text_apply_tag(const char *text_source, char *featured_text, size_t featured_text_len, enum text_tag_type tag_type, ft_offset_t start_offset, ft_offset_t stop_offset,...)
enum text_link_type text_tag_link_type(const struct text_tag *ptag)
const char * tile_link(const struct tile *ptile)
ft_offset_t text_tag_stop_offset(const struct text_tag *ptag)
const char * text_tag_color_foreground(const struct text_tag *ptag)
const struct ft_color ftc_client
const char * city_link(const struct city *pcity)
int text_tag_link_id(const struct text_tag *ptag)
ft_offset_t text_tag_start_offset(const struct text_tag *ptag)
const char * unit_link(const struct unit *punit)
const char * text_tag_color_background(const struct text_tag *ptag)
#define text_tag_list_iterate_end
#define text_tag_list_iterate(tags, ptag)
#define FT_OFFSET_UNSET
int ft_offset_t
text_link_type
@ TLT_TILE
@ TLT_UNIT
@ TLT_CITY
text_tag_type
@ TTT_LINK
@ TTT_BOLD
@ TTT_ITALIC
@ TTT_STRIKE
@ TTT_COLOR
@ TTT_UNDERLINE
static struct ft_color ft_color_construct(const char *foreground, const char *background)
struct civ_game game
Definition game.c:62
struct world wld
Definition game.c:63
struct unit * game_unit_by_number(int id)
Definition game.c:116
struct city * game_city_by_number(int id)
Definition game.c:107
bool genlist_remove(struct genlist *pgenlist, const void *punlink)
Definition genlist.c:329
struct genlist * genlist_new(void)
Definition genlist.c:31
void * genlist_get(const struct genlist *pgenlist, int idx)
Definition genlist.c:224
void genlist_prepend(struct genlist *pgenlist, void *data)
Definition genlist.c:526
int genlist_size(const struct genlist *pgenlist)
Definition genlist.c:192
bool inputline_has_focus(void)
Definition chatline.c:71
static void set_cursor_if_appropriate(GtkTextView *text_view, gint x, gint y)
Definition chatline.c:674
static size_t get_common_prefix(const char *const *prefixes, size_t num_prefixes, char *buf, size_t buf_len)
Definition chatline.c:257
static int history_pos
Definition chatline.c:55
#define MAX_CHATLINE_HISTORY
Definition chatline.c:52
static gboolean version_message_main_thread(gpointer user_data)
Definition chatline.c:1463
void inputline_toolkit_view_append_button(GtkWidget *toolkit_view, GtkWidget *button)
Definition chatline.c:1292
void version_message(const char *vertext)
Definition chatline.c:1477
static const char * get_player_or_user_name(int id)
Definition chatline.c:175
GtkWidget * inputline_toolkit_view_new(void)
Definition chatline.c:1270
void log_output_window(void)
Definition chatline.c:928
static gboolean chatline_scroll_callback(gpointer data)
Definition chatline.c:994
void set_message_buffer_view_link_handlers(GtkWidget *view)
Definition chatline.c:744
static gboolean motion_notify_event(GtkWidget *text_view, GdkEventMotion *event)
Definition chatline.c:728
static void button_toggled(GtkToggleButton *button, gpointer data)
Definition chatline.c:1246
static void select_color_callback(GtkToolButton *button, gpointer data)
Definition chatline.c:1120
void scroll_if_necessary(GtkTextView *textview, GtkTextMark *scroll_target)
Definition chatline.c:557
bool inputline_is_visible(void)
Definition chatline.c:87
static void color_selected(GtkDialog *dialog, gint res, gpointer data)
Definition chatline.c:1094
static bool is_plain_public_message(const char *s)
Definition chatline.c:97
static bool chatline_autocomplete(GtkEditable *editable)
Definition chatline.c:284
static struct genlist * history_list
Definition chatline.c:54
void clear_output_window(void)
Definition chatline.c:943
void apply_text_tag(const struct text_tag *ptag, GtkTextBuffer *buf, ft_offset_t text_start_offset, const char *text)
Definition chatline.c:755
void chatline_init(void)
Definition chatline.c:1302
static void make_tag_callback(GtkToolButton *button, gpointer data)
Definition chatline.c:1033
static int check_player_or_user_name(const char *prefix, const char **matches, const int max_matches)
Definition chatline.c:202
static struct inputline_toolkit toolkit
void inputline_make_chat_link(struct tile *ptile, bool unit)
Definition chatline.c:474
bool chatline_is_scrolled_to_bottom(void)
Definition chatline.c:959
static gboolean event_after(GtkWidget *text_view, GdkEventButton *event)
Definition chatline.c:584
void real_output_window_append(const char *astring, const struct text_tag_list *tags, int conn_id)
Definition chatline.c:874
static gboolean set_toolbar_visibility(GtkWidget *w, gpointer data)
Definition chatline.c:1216
static gboolean inputline_handler(GtkWidget *w, GdkEventKey *ev)
Definition chatline.c:345
static void inputline_return(GtkEntry *w, gpointer data)
Definition chatline.c:139
void inputline_grab_focus(void)
Definition chatline.c:79
void chatline_scroll_to_bottom(bool delayed)
Definition chatline.c:1006
#define MAX_MATCHES
static gboolean move_toolkit(GtkWidget *toolkit_view, gpointer data)
Definition chatline.c:1155
static void inputline_make_tag(GtkEntry *entry, enum text_tag_type type)
Definition chatline.c:416
static struct tile * pos
Definition finddlg.c:53
GtkTextBuffer * message_buffer
Definition gui_main.c:178
GtkWidget * toplevel
Definition gui_main.c:125
GtkWidget * map_canvas
Definition gui_main.c:107
GtkTextView * main_message_area
Definition gui_main.c:177
#define GUI_GTK_OPTION(optname)
Definition gui_main.h:25
void setup_dialog(GtkWidget *shell, GtkWidget *parent)
Definition gui_stuff.c:287
void append_network_statusbar(const char *text, bool force)
Definition pages.c:894
GtkWidget * start_message_area
Definition pages.c:1457
static GtkWidget * persistent
GType type
Definition repodlgs.c:1313
#define set_output_window_text(_pstr_)
Definition chatline.h:31
const char * name
Definition inputfile.c:127
#define fc_assert_ret(condition)
Definition log.h:191
#define log_error(message,...)
Definition log.h:103
struct tile * index_to_tile(const struct civ_map *imap, int mindex)
Definition map.c:456
void link_mark_restore(enum text_link_type type, int id)
void center_tile_mapcanvas(const struct tile *ptile)
#define FC_FREE(ptr)
Definition mem.h:41
#define fc_strdup(str)
Definition mem.h:43
#define fc_malloc(sz)
Definition mem.h:34
#define color_set(color_tgt, color)
int len
Definition packhand.c:127
enum client_pages get_client_page(void)
struct player * player_by_number(const int player_id)
Definition player.c:849
int player_slot_count(void)
Definition player.c:418
enum m_pre_result match_prefix_full(m_pre_accessor_fn_t accessor_fn, size_t n_names, size_t max_len_name, m_pre_strncmp_fn_t cmp_fn, m_strlen_fn_t len_fn, const char *prefix, int *ind_result, int *matches, int max_matches, int *pnum_matches)
Definition shared.c:1613
#define MAX(x, y)
Definition shared.h:54
@ M_PRE_EXACT
Definition shared.h:208
@ M_PRE_ONLY
Definition shared.h:209
@ M_PRE_LAST
Definition shared.h:214
@ M_PRE_LONG
Definition shared.h:212
@ M_PRE_AMBIGUOUS
Definition shared.h:210
@ M_PRE_EMPTY
Definition shared.h:211
@ M_PRE_FAIL
Definition shared.h:213
size_t size
Definition specvec.h:72
struct sprite int int y
Definition sprite_g.h:31
struct sprite int x
Definition sprite_g.h:31
Definition city.h:320
struct conn_list * all_connections
Definition game.h:96
Definition colors.h:21
GtkWidget * main_widget
Definition chatline.c:58
GtkWidget * toggle_button
Definition chatline.c:62
GtkWidget * button_box
Definition chatline.c:60
GtkWidget * entry
Definition chatline.c:59
GtkWidget * toolbar
Definition chatline.c:61
bool toolbar_displayed
Definition chatline.c:63
Definition climisc.h:82
char name[MAX_LEN_NAME]
Definition player.h:249
Definition tile.h:50
Definition unit.h:138
struct civ_map map
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:974
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:791
bool fc_isspace(char c)
Definition support.c:1254
struct tm * fc_localtime(const time_t *timep, struct tm *result)
Definition support.c:1315
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:1000
int fc_strncasecmp(const char *str0, const char *str1, size_t n)
Definition support.c:238
#define sz_strlcpy(dest, src)
Definition support.h:195
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define unit_tile(_pu)
Definition unit.h:397