Freeciv-3.3
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#include "update_queue.h"
44
45/* client/gui-gtk-4.0 */
46#include "colors.h"
47#include "gui_main.h"
48#include "gui_stuff.h"
49#include "menu.h"
50#include "pages.h"
51
52#include "chatline.h"
53
54#define MAX_CHATLINE_HISTORY 20
55
56static struct genlist *history_list = NULL;
57static int history_pos = -1;
58
59static struct inputline_toolkit {
66} toolkit; /* Singleton. */
67
69
70/**********************************************************************/
74{
75 return gtk_widget_has_focus(toolkit.entry);
76}
77
78/**********************************************************************/
85
86/**********************************************************************/
90{
91 return gtk_widget_get_mapped(toolkit.entry);
92}
93
94/**********************************************************************/
104
105/**********************************************************************/
115
116/**********************************************************************/
121static bool is_plain_public_message(const char *s)
122{
123 const char *p;
124
125 /* If it is a server command or an explicit ally
126 * message, then it is not a public message. */
127 if (s[0] == SERVER_COMMAND_PREFIX || s[0] == CHAT_ALLIES_PREFIX) {
128 return FALSE;
129 }
130
131 /* It might be a private message of the form
132 * 'player name with spaces':the message
133 * or with ". So skip past the player name part. */
134 if (s[0] == '\'' || s[0] == '"') {
135 p = strchr(s + 1, s[0]);
136 } else {
137 p = s;
138 }
139
140 /* Now we just need to check that it is not a private
141 * message. If we encounter a space then the preceding
142 * text could not have been a user/player name (the
143 * quote check above eliminated names with spaces) so
144 * it must be a public message. Otherwise if we encounter
145 * the message prefix : then the text parsed up until now
146 * was a player/user name and the line is intended as
147 * a private message (or explicit public message if the
148 * first character is :). */
149 while (p != NULL && *p != '\0') {
150 if (fc_isspace(*p)) {
151 return TRUE;
152 } else if (*p == CHAT_DIRECT_PREFIX) {
153 return FALSE;
154 }
155 p++;
156 }
157 return TRUE;
158}
159
160
161/**********************************************************************/
164static void inputline_return(GtkEntry *w, gpointer data)
165{
166 const char *theinput;
168
170
171 if (*theinput) {
175 char buf[MAX_LEN_MSG];
176
177 fc_snprintf(buf, sizeof(buf), ". %s", theinput);
178 send_chat(buf);
179 } else {
181 }
182
184 void *history_data;
185
189 }
190
192 history_pos = -1;
193 }
194
195 gtk_entry_buffer_set_text(buffer, "", -1);
196}
197
198/**********************************************************************/
201static const char *get_player_or_user_name(int id)
202{
204
205 if (id < size) {
206 return conn_list_get(game.all_connections, id)->username;
207 } else {
208 struct player *pplayer = player_by_number(id - size);
209 if (pplayer) {
210 return pplayer->name;
211 } else {
212 /* Empty slot. Relies on being used with comparison function
213 * which can cope with NULL. */
214 return NULL;
215 }
216 }
217}
218
219/**********************************************************************/
228static int check_player_or_user_name(const char *prefix,
229 const char **matches,
230 const int max_matches)
231{
232 int matches_id[max_matches * 2], ind, num;
233
238 prefix, &ind, matches_id,
239 max_matches * 2, &num)) {
240 case M_PRE_EXACT:
241 case M_PRE_ONLY:
243 return 1;
244 case M_PRE_AMBIGUOUS:
245 {
246 /* Remove duplications playername/username. */
247 const char *name;
248 int i, j, c = 0;
249
250 for (i = 0; i < num && c < max_matches; i++) {
252 for (j = 0; j < c; j++) {
253 if (0 == fc_strncasecmp(name, matches[j], MAX_LEN_NAME)) {
254 break;
255 }
256 }
257 if (j >= c) {
258 matches[c++] = name;
259 }
260 }
261 return c;
262 }
263 case M_PRE_EMPTY:
264 case M_PRE_LONG:
265 case M_PRE_FAIL:
266 case M_PRE_LAST:
267 break;
268 }
269
270 return 0;
271}
272
273/**********************************************************************/
283static size_t get_common_prefix(const char *const *prefixes,
284 size_t num_prefixes,
285 char *buf, size_t buf_len)
286{
287 const char *p;
288 char *q;
289 size_t i;
290
292 for (i = 1; i < num_prefixes; i++) {
293 for (p = prefixes[i], q = buf; *p != '\0' && *q != '\0';
297 *q = '\0';
298 break;
299 }
300 }
301 }
302
303 return g_utf8_strlen(buf, -1);
304}
305
306/**********************************************************************/
311{
312#define MAX_MATCHES 10
313 const char *name[MAX_MATCHES];
315 gint pos;
316 gchar *chars, *p, *prev;
317 int num, i;
318 size_t prefix_len;
319
320 /* Part 1: get the string to complete. */
323
324 p = chars + strlen(chars);
325 while ((prev = g_utf8_find_prev_char(chars, p))) {
327 break;
328 }
329 p = prev;
330 }
331 /* p points to the start of the last word, or the start of the string. */
332
333 prefix_len = g_utf8_strlen(p, -1);
334 if (0 == prefix_len) {
335 /* Empty: nothing to complete, propagate the event. */
336 g_free(chars);
337 return FALSE;
338 }
339
340 /* Part 2: Compare with player and user names. */
342 if (1 == num) {
344 pos -= prefix_len;
347 g_free(chars);
348 return TRUE;
349 } else if (num > 1) {
350 if (get_common_prefix(name, num, buf, sizeof(buf)) > prefix_len) {
352 pos -= prefix_len;
355 }
356 sz_strlcpy(buf, name[0]);
357 for (i = 1; i < num; i++) {
358 cat_snprintf(buf, sizeof(buf), ", %s", name[i]);
359 }
360 /* TRANS: comma-separated list of player/user names for completion */
361 output_window_printf(ftc_client, _("Suggestions: %s."), buf);
362 }
363
364 g_free(chars);
365
366 return TRUE;
367}
368
369/**********************************************************************/
375 GdkModifierType state,
376 gpointer data)
377{
379
380 if ((state & GDK_CONTROL_MASK)) {
381 /* Chatline featured text support. */
382
383 switch (keyval) {
384 case GDK_KEY_b:
386 return TRUE;
387
388 case GDK_KEY_c:
390 return TRUE;
391
392 case GDK_KEY_i:
394 return TRUE;
395
396 case GDK_KEY_s:
398 return TRUE;
399
400 case GDK_KEY_u:
402 return TRUE;
403
404 default:
405 break;
406 }
407
408 } else {
409 /* Chatline history controls. */
411
412 switch (keyval) {
413 case GDK_KEY_Up:
417 -1);
419 }
420 return TRUE;
421
422 case GDK_KEY_Down:
423 if (history_pos >= 0) {
424 history_pos--;
425 }
426
427 if (history_pos >= 0) {
430 -1);
431 } else {
432 gtk_entry_buffer_set_text(buffer, "", -1);
433 }
435 return TRUE;
436
437 case GDK_KEY_Tab:
440 }
441 return FALSE;
442
443 default:
444 break;
445 }
446 }
447
448 return FALSE;
449}
450
451/**********************************************************************/
455{
456 char buf[MAX_LEN_MSG];
459 gchar *selection;
461
463 /* Let's say the selection starts and ends at the current position. */
465 }
466
468
469 if (type == TTT_COLOR) {
470 /* Get the color arguments. */
473
474 if (!fg_color && !bg_color) {
475 goto CLEAN_UP;
476 }
477
478 if (fg_color) {
480 }
481 if (bg_color) {
483 }
484
485 if (0 == featured_text_apply_tag(selection, buf, sizeof(buf),
488 bg_color_text))) {
489 goto CLEAN_UP;
490 }
491 } else if (0 == featured_text_apply_tag(selection, buf, sizeof(buf),
492 type, 0, FT_OFFSET_UNSET)) {
493 goto CLEAN_UP;
494 }
495
496 /* Replace the selection. */
501
503 g_free(selection);
506}
507
508/**********************************************************************/
512void inputline_make_chat_link(struct tile *ptile, bool unit)
513{
514 char buf[MAX_LEN_MSG];
515 GtkWidget *entry = toolkit.entry;
518 gchar *chars;
519 struct unit *punit;
520
521 /* Get the target. */
522 if (unit) {
523 punit = find_visible_unit(ptile);
524 if (!punit) {
525 output_window_append(ftc_client, _("No visible unit on this tile."));
526 return;
527 }
528 } else {
529 punit = NULL;
530 }
531
533 /* There is a selection, make it clickable. */
534 gpointer target;
535 enum text_link_type type;
536
538 if (punit) {
539 type = TLT_UNIT;
540 target = punit;
541 } else if (tile_city(ptile)) {
542 type = TLT_CITY;
543 target = tile_city(ptile);
544 } else {
545 type = TLT_TILE;
546 target = ptile;
547 }
548
549 if (0 != featured_text_apply_tag(chars, buf, sizeof(buf), TTT_LINK,
550 0, FT_OFFSET_UNSET, type, target)) {
551 /* Replace the selection. */
557 }
558 } else {
559 /* Just insert the link at the current position. */
563 start_pos + 1);
564 if (punit) {
566 } else if (tile_city(ptile)) {
568 } else {
569 sz_strlcpy(buf, tile_link(ptile));
570 }
571
572 if (start_pos > 0 && strlen(chars) > 0 && chars[0] != ' ') {
573 /* Maybe insert an extra space. */
575 }
577 if (chars[start_pos > 0 ? 1 : 0] != '\0'
578 && chars[start_pos > 0 ? 1 : 0] != ' ') {
579 /* Maybe insert an extra space. */
581 }
584 }
585
586 g_free(chars);
587}
588
589/**********************************************************************/
618
619/**********************************************************************/
623 double x, double y, gpointer data)
624{
626 GtkTextIter start, end, iter;
627 GtkTextBuffer *buffer;
628 GSList *tags, *tagp;
629 gint bx, by;
630 struct tile *ptile = NULL;
631
633
634 /* We shouldn't follow a link if the user has selected something. */
635 gtk_text_buffer_get_selection_bounds(buffer, &start, &end);
637 return FALSE;
638 }
639
642 x, y, &bx, &by);
643
645
646 if ((tags = gtk_text_iter_get_tags(&iter))) {
647 for (tagp = tags; tagp; tagp = tagp->next) {
648 GtkTextTag *tag = tagp->data;
649 enum text_link_type type =
651
652 if (type != 0) {
653 /* This is a link. */
654 int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(tag), "id"));
655 ptile = NULL;
656
657 /* Real type is type - 1.
658 * See comment in apply_text_tag() for g_object_set_data(). */
659 type--;
660
661 switch (type) {
662 case TLT_CITY:
663 {
664 struct city *pcity = game_city_by_number(id);
665
666 if (pcity) {
667 ptile = client_city_tile(pcity);
668 } else {
669 output_window_append(ftc_client, _("This city isn't known!"));
670 }
671 }
672 break;
673 case TLT_TILE:
674 ptile = index_to_tile(&(wld.map), id);
675
676 if (!ptile) {
678 _("This tile doesn't exist in this game!"));
679 }
680 break;
681 case TLT_UNIT:
682 {
683 struct unit *punit = game_unit_by_number(id);
684
685 if (punit) {
686 ptile = unit_tile(punit);
687 } else {
688 output_window_append(ftc_client, _("This unit isn't known!"));
689 }
690 }
691 break;
692 }
693
694 if (ptile) {
698 }
699 }
700 }
701 g_slist_free(tags);
702 }
703
704 return FALSE;
705}
706
707/**********************************************************************/
711{
713 static GdkCursor *hand_cursor = NULL;
714 static GdkCursor *regular_cursor = NULL;
715 GSList *tags, *tagp;
718
719 /* Initialize the cursors. */
720 if (!hand_cursor) {
722 }
723 if (!regular_cursor) {
725 }
726
728
730 for (tagp = tags; tagp; tagp = tagp->next) {
731 enum text_link_type type =
733
734 if (type != 0) {
735 hovering = TRUE;
736 break;
737 }
738 }
739
742
743 if (hovering_over_link) {
745 } else {
747 }
748 }
749
750 if (tags) {
751 g_slist_free(tags);
752 }
753}
754
755/**********************************************************************/
772
773/**********************************************************************/
792
793/**********************************************************************/
797 ft_offset_t text_start_offset, const char *text)
798{
799 static bool initialized = FALSE;
800 GtkTextIter start, stop;
801
802 if (!initialized) {
804 "weight", PANGO_WEIGHT_BOLD, NULL);
806 "style", PANGO_STYLE_ITALIC, NULL);
808 "strikethrough", TRUE, NULL);
809 gtk_text_buffer_create_tag(buf, "underline",
810 "underline", PANGO_UNDERLINE_SINGLE, NULL);
812 }
813
814 /* Get the position. */
815 /*
816 * N.B.: text_tag_*_offset() value is in bytes, so we need to convert it
817 * to utf8 character offset.
818 */
821 text + text_tag_start_offset(ptag)));
824 } else {
827 text + text_tag_stop_offset(ptag)));
828 }
829
830 switch (text_tag_type(ptag)) {
831 case TTT_BOLD:
832 gtk_text_buffer_apply_tag_by_name(buf, "bold", &start, &stop);
833 break;
834 case TTT_ITALIC:
835 gtk_text_buffer_apply_tag_by_name(buf, "italic", &start, &stop);
836 break;
837 case TTT_STRIKE:
838 gtk_text_buffer_apply_tag_by_name(buf, "strike", &start, &stop);
839 break;
840 case TTT_UNDERLINE:
841 gtk_text_buffer_apply_tag_by_name(buf, "underline", &start, &stop);
842 break;
843 case TTT_COLOR:
844 {
845 /* We have to make a new tag every time. */
846 GtkTextTag *tag = NULL;
847 const char *foreground = text_tag_color_foreground(ptag);
848 const char *background = text_tag_color_background(ptag);
849
850 if (foreground && foreground[0]) {
851 if (background && background[0]) {
853 "foreground", foreground,
854 "background", background,
855 NULL);
856 } else {
858 "foreground", foreground,
859 NULL);
860 }
861 } else if (background && background[0]) {
863 "background", background,
864 NULL);
865 }
866
867 if (!tag) {
868 break; /* No color. */
869 }
870 gtk_text_buffer_apply_tag(buf, tag, &start, &stop);
871 }
872 break;
873 case TTT_LINK:
874 {
875 struct color *pcolor = NULL;
876 GtkTextTag *tag;
877
878 switch (text_tag_link_type(ptag)) {
879 case TLT_CITY:
881 break;
882 case TLT_TILE:
884 break;
885 case TLT_UNIT:
887 break;
888 }
889
890 if (!pcolor) {
891 break; /* Not a valid link type case. */
892 }
893
895 "foreground-rgba", &pcolor->color,
896 "underline", PANGO_UNDERLINE_SINGLE,
897 NULL);
898
899 /* Type 0 is reserved for non-link tags. So, add 1 to the
900 * type value. */
901 g_object_set_data(G_OBJECT(tag), "type",
903 g_object_set_data(G_OBJECT(tag), "id",
905 gtk_text_buffer_apply_tag(buf, tag, &start, &stop);
906 break;
907 }
908 }
909}
910
911/**********************************************************************/
916 const struct text_tag_list *tags,
917 int conn_id)
918{
923
925
926 if (buf == NULL) {
927 log_error("Output when no message buffer: %s", astring);
928
929 return;
930 }
931
933 gtk_text_buffer_insert(buf, &iter, "\n", -1);
935
937 char timebuf[64];
938 time_t now;
939 struct tm now_tm;
940
941 now = time(NULL);
943 strftime(timebuf, sizeof(timebuf), "[%H:%M:%S] ", &now_tm);
945 }
946
952
953 if (main_message_area) {
955 }
956 if (start_message_area) {
958 }
960
962}
963
964/**********************************************************************/
970{
971 GtkTextIter start, end;
972 gchar *txt;
973
976
978 g_free(txt);
979}
980
981/**********************************************************************/
985{
986 set_output_window_text(_("Cleared output window."));
987}
988
989/**********************************************************************/
992void set_output_window_text(const char *text)
993{
995}
996
997/**********************************************************************/
1001{
1002 GtkWidget *sw, *w;
1004 gdouble val, max, upper, page_size;
1005
1006 if (get_client_page() == PAGE_GAME) {
1008 } else {
1010 }
1011
1012 if (w == NULL) {
1013 return TRUE;
1014 }
1015
1016 sw = gtk_widget_get_parent(w);
1019 g_object_get(G_OBJECT(vadj), "upper", &upper,
1020 "page-size", &page_size, NULL);
1021 max = upper - page_size;
1022
1023 /* Approximation. */
1024 return max - val < 0.00000001;
1025}
1026
1027/**********************************************************************/
1036{
1037 chatline_scroll_to_bottom(FALSE); /* Not delayed this time! */
1038
1039 *((guint *) data) = 0;
1040
1041 return FALSE; /* Remove this idle function. */
1042}
1043
1044/**********************************************************************/
1049{
1050 static guint callback_id = 0;
1051
1052 if (delayed) {
1053 if (callback_id == 0) {
1055 }
1056 } else if (message_buffer) {
1057 GtkTextIter end;
1058
1060
1061 if (main_message_area) {
1063 &end, 0.0, TRUE, 1.0, 0.0);
1064 }
1065 if (start_message_area) {
1067 &end, 0.0, TRUE, 1.0, 0.0);
1068 }
1069 }
1070}
1071
1072/**********************************************************************/
1075static void make_tag_callback(GtkButton *button, gpointer data)
1076{
1079 "text_tag_type")));
1080}
1081
1082/**********************************************************************/
1085static void color_set(GObject *object, const gchar *color_target,
1086 GdkRGBA *color, GtkButton *button)
1087{
1089
1090 if (NULL == color) {
1091 /* Clears the current color. */
1092 if (NULL != current_color) {
1095 if (NULL != button) {
1096 gtk_button_set_child(button, NULL);
1097 }
1098 }
1099 } else {
1100 /* Apply the new color. */
1101 if (NULL != current_color) {
1102 /* We already have a GdkRGBA pointer. */
1103 *current_color = *color;
1104 } else {
1105 /* We need to make a GdkRGBA pointer. */
1108 }
1109
1110 if (NULL != button) {
1111 /* Update the button. */
1114
1115 gtk_button_set_child(button, NULL);
1116
1117 {
1119 CAIRO_FORMAT_RGB24, 16, 16);
1120 cairo_t *cr = cairo_create(surface);
1121
1123 cairo_paint(cr);
1124 cairo_destroy(cr);
1125 pixbuf = gdk_pixbuf_get_from_surface(surface, 0, 0, 16, 16);
1126 cairo_surface_destroy(surface);
1127 }
1129 gtk_button_set_child(button, image);
1132 }
1133 }
1134}
1135
1136/**********************************************************************/
1139static void color_selected(GtkDialog *dialog, gint res, gpointer data)
1140{
1141 const gchar *color_target =
1142 g_object_get_data(G_OBJECT(data), "color_target");
1143 GObject *entry = g_object_get_data(G_OBJECT(data), "entry");
1144
1145 if (res == GTK_RESPONSE_REJECT) {
1146 /* Clears the current color. */
1148 } else if (res == GTK_RESPONSE_OK) {
1149 /* Apply the new color. */
1151 = GTK_COLOR_CHOOSER(g_object_get_data(G_OBJECT(dialog), "chooser"));
1153
1156 }
1157
1159}
1160
1161/**********************************************************************/
1164static void select_color_callback(GtkButton *button, gpointer data)
1165{
1166 GtkWidget *dialog, *chooser;
1167 /* "fg_color" or "bg_color". */
1169 "color_target");
1171
1172 /* TRANS: "text" or "background". */
1173 gchar *buf = g_strdup_printf(_("Select the %s color"),
1174 (const char *) g_object_get_data(G_OBJECT(button),
1175 "color_info"));
1177 _("_Cancel"), GTK_RESPONSE_CANCEL,
1178 _("C_lear"), GTK_RESPONSE_REJECT,
1179 _("_OK"), GTK_RESPONSE_OK, NULL);
1180 setup_dialog(dialog, toplevel);
1181 g_object_set_data(G_OBJECT(button), "entry", data);
1182 g_signal_connect(dialog, "response", G_CALLBACK(color_selected), button);
1183
1186 chooser, NULL);
1187 g_object_set_data(G_OBJECT(dialog), "chooser", chooser);
1188
1189 if (current_color != nullptr) {
1191 }
1192
1194 g_free(buf);
1195}
1196
1197/**********************************************************************/
1201{
1202 struct inputline_toolkit *ptoolkit = (struct inputline_toolkit *) data;
1205 "button_box"));
1206 GtkWidget *iter;
1207
1208 if (parent) {
1209 if (parent == toolkit_view) {
1210 return FALSE; /* Already owned. */
1211 }
1212
1213 /* N.B.: We need to hide/show the toolbar to reset the sensitivity
1214 * of the tool buttons. */
1215 if (ptoolkit->toolbar_displayed) {
1217 }
1218 g_object_ref(ptoolkit->main_widget); /* Make sure reference count stays above 0
1219 * during the transition to new parent. */
1220 gtk_box_remove(GTK_BOX(parent), ptoolkit->main_widget);
1222 g_object_unref(ptoolkit->main_widget);
1223 if (ptoolkit->toolbar_displayed) {
1225 }
1226
1228 /* Attach to the toolkit button_box. */
1230 }
1232 if (!ptoolkit->toolbar_displayed) {
1234 }
1235
1236 /* Hide all other buttons boxes. */
1238 iter != nullptr;
1240 if (iter != button_box) {
1242 }
1243 }
1244
1245 } else {
1246 /* First time attached to a parent. */
1249 gtk_widget_set_visible(ptoolkit->main_widget, TRUE);
1250 }
1251
1252 return FALSE;
1253}
1254
1255/**********************************************************************/
1259{
1260 struct inputline_toolkit *ptoolkit = (struct inputline_toolkit *) data;
1261 GtkToggleButton *button = GTK_TOGGLE_BUTTON(toolkit.toggle_button);
1262
1263 if (ptoolkit->toolbar_displayed) {
1264 if (!gtk_toggle_button_get_active(button)) {
1265 /* button_toggled() will be called and the toolbar shown. */
1267 } else {
1268 /* Ensure the widget is visible. */
1270 }
1271 } else {
1272 if (gtk_toggle_button_get_active(button)) {
1273 /* button_toggled() will be called and the toolbar hidden. */
1275 } else {
1276 /* Ensure the widget is not visible. */
1278 }
1279 }
1280
1281 return FALSE;
1282}
1283
1284/**********************************************************************/
1287static void button_toggled(GtkToggleButton *button, gpointer data)
1288{
1289 struct inputline_toolkit *ptoolkit = (struct inputline_toolkit *) data;
1290
1291 if (gtk_toggle_button_get_active(button)) {
1293 ptoolkit->toolbar_displayed = TRUE;
1295 /* Make sure to be still at the end. */
1297 }
1298 } else {
1300 ptoolkit->toolbar_displayed = FALSE;
1301 }
1302}
1303
1304/**********************************************************************/
1312{
1314
1315 /* Main widget. */
1319
1320 /* Button box. */
1323
1324 return toolkit_view;
1325}
1326
1327/**********************************************************************/
1336
1337/**********************************************************************/
1341{
1342 GtkWidget *vbox, *hgrid, *entry, *bbox;
1343 GtkWidget *button;
1345 GtkWidget *item;
1346 GdkRGBA color;
1347 int grid_col = 0;
1350
1351 /* Chatline history. */
1352 if (!history_list) {
1354 history_pos = -1;
1355 }
1356
1357 /* Inputline toolkit. */
1358 memset(&toolkit, 0, sizeof(toolkit));
1359
1361
1362 toolkit.main_widget = vbox;
1363 g_signal_connect_after(vbox, "map",
1365
1366 entry = gtk_entry_new();
1378 toolkit.entry = entry;
1379
1380 hgrid = gtk_grid_new();
1382
1383 /* First line: toolbar */
1386 toolkit.toolbar = toolbar;
1387
1388 /* Bold button. */
1389 item = gtk_button_new_from_icon_name("format-text-bold");
1390
1391 /* _("Bold")); */
1392
1394 g_object_set_data(G_OBJECT(item), "text_tag_type",
1397 gtk_widget_set_tooltip_text(GTK_WIDGET(item), _("Bold (Ctrl-B)"));
1398
1399 /* Italic button. */
1400 item = gtk_button_new_from_icon_name("format-text-italic");
1401
1402 /* _("Italic")); */
1403
1405 g_object_set_data(G_OBJECT(item), "text_tag_type",
1408 gtk_widget_set_tooltip_text(GTK_WIDGET(item), _("Italic (Ctrl-I)"));
1409
1410 /* Strike button. */
1411 item = gtk_button_new_from_icon_name("format-text-strikethrough");
1412
1413 /* _("Strikethrough")); */
1415 g_object_set_data(G_OBJECT(item), "text_tag_type",
1418 gtk_widget_set_tooltip_text(GTK_WIDGET(item), _("Strikethrough (Ctrl-S)"));
1419
1420 /* Underline button. */
1421 item = gtk_button_new_from_icon_name("format-text-underline");
1422
1423 /* _("Underline")); */
1425 g_object_set_data(G_OBJECT(item), "text_tag_type",
1428 gtk_widget_set_tooltip_text(GTK_WIDGET(item), _("Underline (Ctrl-U)"));
1429
1431
1432 /* Color button. */
1433 item = gtk_button_new_with_label(_("Color"));
1434
1436 g_object_set_data(G_OBJECT(item), "text_tag_type",
1439 gtk_widget_set_tooltip_text(GTK_WIDGET(item), _("Color (Ctrl-C)"));
1440
1442
1443 /* Foreground selector. */
1444 item = gtk_button_new();
1446 g_object_set_data(G_OBJECT(item), "color_target", fc_strdup("fg_color"));
1447 g_object_set_data(G_OBJECT(item), "color_info",
1448 fc_strdup(_("foreground")));
1449 g_signal_connect(item, "clicked",
1451 gtk_widget_set_tooltip_text(GTK_WIDGET(item), _("Select the text color"));
1452 if (gdk_rgba_parse(&color, "#000000")) {
1453 /* Set default foreground color. */
1454 color_set(G_OBJECT(entry), "fg_color", &color, GTK_BUTTON(item));
1455 } else {
1456 log_error("Failed to set the default foreground color.");
1457 }
1458
1459 /* Background selector. */
1460 item = gtk_button_new();
1462 g_object_set_data(G_OBJECT(item), "color_target", fc_strdup("bg_color"));
1463 g_object_set_data(G_OBJECT(item), "color_info",
1464 fc_strdup(_("background")));
1465 g_signal_connect(item, "clicked",
1468 _("Select the background color"));
1469 if (gdk_rgba_parse(&color, "#ffffff")) {
1470 /* Set default background color. */
1471 color_set(G_OBJECT(entry), "bg_color", &color, GTK_BUTTON(item));
1472 } else {
1473 log_error("Failed to set the default background color.");
1474 }
1475
1477
1478 /* Return button. */
1481 g_signal_connect_swapped(item, "clicked",
1484 /* TRANS: "Return" means the return key. */
1485 _("Send the chat (Return)"));
1486
1487 /* Second line */
1489
1490 /* Toggle button. */
1491 button = gtk_toggle_button_new();
1493 gtk_widget_set_margin_end(button, 2);
1494 gtk_widget_set_margin_start(button, 2);
1495 gtk_widget_set_margin_top(button, 2);
1496 gtk_grid_attach(GTK_GRID(hgrid), button, grid_col++, 0, 1, 1);
1497 gtk_button_set_icon_name(GTK_BUTTON(button), "insert-link");
1498 g_signal_connect(button, "toggled", G_CALLBACK(button_toggled), &toolkit);
1499 gtk_widget_set_tooltip_text(GTK_WIDGET(button), _("Chat tools"));
1500 toolkit.toggle_button = button;
1501
1502 /* Entry. */
1505
1507 g_signal_connect(chat_controller, "key-pressed",
1510
1511 /* Button box. */
1514 toolkit.button_box = bbox;
1515}
1516
1517/**********************************************************************/
1521{
1522 char *vertext = (char *)user_data;
1523
1525
1527
1528 return G_SOURCE_REMOVE;
1529}
1530
1531/**********************************************************************/
1534void version_message(const char *vertext)
1535{
1536 int len = strlen(vertext) + 1;
1537 char *persistent = fc_malloc(len);
1538
1540
1542}
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
struct color * get_color(const struct tileset *t, enum color_std stdcolor)
char * incite_cost
Definition comments.c:76
#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
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 int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
static bool initialized
Definition effects.c:42
#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:61
struct world wld
Definition game.c:62
struct unit * game_unit_by_number(int id)
Definition game.c:115
struct city * game_city_by_number(int id)
Definition game.c:106
bool genlist_remove(struct genlist *pgenlist, const void *punlink)
Definition genlist.c:322
struct genlist * genlist_new(void)
Definition genlist.c:31
void * genlist_get(const struct genlist *pgenlist, int idx)
Definition genlist.c:221
void genlist_prepend(struct genlist *pgenlist, void *data)
Definition genlist.c:500
int genlist_size(const struct genlist *pgenlist)
Definition genlist.c:192
bool inputline_has_focus(void)
Definition chatline.c:72
static void set_cursor_if_appropriate(GtkTextView *text_view, gint x, gint y)
Definition chatline.c:675
static size_t get_common_prefix(const char *const *prefixes, size_t num_prefixes, char *buf, size_t buf_len)
Definition chatline.c:258
static int history_pos
Definition chatline.c:56
#define MAX_CHATLINE_HISTORY
Definition chatline.c:53
static gboolean version_message_main_thread(gpointer user_data)
Definition chatline.c:1464
void inputline_toolkit_view_append_button(GtkWidget *toolkit_view, GtkWidget *button)
Definition chatline.c:1293
void version_message(const char *vertext)
Definition chatline.c:1478
static const char * get_player_or_user_name(int id)
Definition chatline.c:176
GtkWidget * inputline_toolkit_view_new(void)
Definition chatline.c:1271
void log_output_window(void)
Definition chatline.c:929
static gboolean chatline_scroll_callback(gpointer data)
Definition chatline.c:995
void set_message_buffer_view_link_handlers(GtkWidget *view)
Definition chatline.c:745
static void button_toggled(GtkToggleButton *button, gpointer data)
Definition chatline.c:1247
static void select_color_callback(GtkToolButton *button, gpointer data)
Definition chatline.c:1121
void scroll_if_necessary(GtkTextView *textview, GtkTextMark *scroll_target)
Definition chatline.c:558
bool inputline_is_visible(void)
Definition chatline.c:88
static void color_selected(GtkDialog *dialog, gint res, gpointer data)
Definition chatline.c:1095
static bool is_plain_public_message(const char *s)
Definition chatline.c:98
static bool chatline_autocomplete(GtkEditable *editable)
Definition chatline.c:285
static struct genlist * history_list
Definition chatline.c:55
void clear_output_window(void)
Definition chatline.c:944
void apply_text_tag(const struct text_tag *ptag, GtkTextBuffer *buf, ft_offset_t text_start_offset, const char *text)
Definition chatline.c:756
void chatline_init(void)
Definition chatline.c:1303
static void make_tag_callback(GtkToolButton *button, gpointer data)
Definition chatline.c:1034
static int check_player_or_user_name(const char *prefix, const char **matches, const int max_matches)
Definition chatline.c:203
static struct inputline_toolkit toolkit
void inputline_make_chat_link(struct tile *ptile, bool unit)
Definition chatline.c:475
bool chatline_is_scrolled_to_bottom(void)
Definition chatline.c:960
static gboolean event_after(GtkWidget *text_view, GdkEventButton *event)
Definition chatline.c:585
void real_output_window_append(const char *astring, const struct text_tag_list *tags, int conn_id)
Definition chatline.c:875
static gboolean set_toolbar_visibility(GtkWidget *w, gpointer data)
Definition chatline.c:1217
static gboolean inputline_handler(GtkWidget *w, GdkEventKey *ev)
Definition chatline.c:346
static void inputline_return(GtkEntry *w, gpointer data)
Definition chatline.c:140
void inputline_grab_focus(void)
Definition chatline.c:80
void chatline_scroll_to_bottom(bool delayed)
Definition chatline.c:1007
#define MAX_MATCHES
static gboolean move_toolkit(GtkWidget *toolkit_view, gpointer data)
Definition chatline.c:1156
static void inputline_make_tag(GtkEntry *entry, enum text_tag_type type)
Definition chatline.c:417
static struct tile * pos
Definition finddlg.c:53
GtkTextBuffer * message_buffer
Definition gui_main.c:179
GtkWidget * toplevel
Definition gui_main.c:126
GtkWidget * map_canvas
Definition gui_main.c:108
GtkTextView * main_message_area
Definition gui_main.c:178
#define GUI_GTK_OPTION(optname)
Definition gui_main.h:25
void setup_dialog(GtkWidget *shell, GtkWidget *parent)
Definition gui_stuff.c:287
void real_menus_update(void)
Definition menu.c:2353
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
static gboolean il_lost_focus(GtkEventControllerFocus *controller, gpointer data)
Definition chatline.c:97
static gboolean chat_pointer_motion(GtkEventControllerMotion *controller, gdouble e_x, gdouble e_y, gpointer data)
Definition chatline.c:758
static gboolean il_gained_focus(GtkEventControllerFocus *controller, gpointer data)
Definition chatline.c:108
void menus_disable_unit_commands(void)
Definition menu.c:4164
#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:192
#define log_error(message,...)
Definition log.h:104
struct tile * index_to_tile(const struct civ_map *imap, int mindex)
Definition map.c:471
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
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:1606
#define MAX(x, y)
Definition shared.h:54
@ M_PRE_EXACT
Definition shared.h:214
@ M_PRE_ONLY
Definition shared.h:215
@ M_PRE_LAST
Definition shared.h:220
@ M_PRE_LONG
Definition shared.h:218
@ M_PRE_AMBIGUOUS
Definition shared.h:216
@ M_PRE_EMPTY
Definition shared.h:217
@ M_PRE_FAIL
Definition shared.h:219
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:317
struct conn_list * all_connections
Definition game.h:96
Definition colors.h:21
GtkWidget * main_widget
Definition chatline.c:59
GtkWidget * toggle_button
Definition chatline.c:63
GtkWidget * button_box
Definition chatline.c:61
GtkWidget * entry
Definition chatline.c:60
GtkWidget * toolbar
Definition chatline.c:62
bool toolbar_displayed
Definition chatline.c:64
Definition climisc.h:82
char name[MAX_LEN_NAME]
Definition player.h:251
Definition tile.h:50
Definition unit.h:140
struct civ_map map
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:777
bool fc_isspace(char c)
Definition support.c:1240
struct tm * fc_localtime(const time_t *timep, struct tm *result)
Definition support.c:1301
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:986
int fc_strncasecmp(const char *str0, const char *str1, size_t n)
Definition support.c:235
#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:404
enum client_pages get_client_page(void)