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-4.0 */
45#include "colors.h"
46#include "gui_main.h"
47#include "gui_stuff.h"
48#include "menu.h"
49#include "pages.h"
50
51#include "chatline.h"
52
53#define MAX_CHATLINE_HISTORY 20
54
55static struct genlist *history_list = NULL;
56static int history_pos = -1;
57
58static struct inputline_toolkit {
65} toolkit; /* Singleton. */
66
68
69/**********************************************************************/
73{
74 return gtk_widget_has_focus(toolkit.entry);
75}
76
77/**********************************************************************/
84
85/**********************************************************************/
89{
90 return gtk_widget_get_mapped(toolkit.entry);
91}
92
93/**********************************************************************/
103
104/**********************************************************************/
114
115/**********************************************************************/
120static bool is_plain_public_message(const char *s)
121{
122 const char *p;
123
124 /* If it is a server command or an explicit ally
125 * message, then it is not a public message. */
126 if (s[0] == SERVER_COMMAND_PREFIX || s[0] == CHAT_ALLIES_PREFIX) {
127 return FALSE;
128 }
129
130 /* It might be a private message of the form
131 * 'player name with spaces':the message
132 * or with ". So skip past the player name part. */
133 if (s[0] == '\'' || s[0] == '"') {
134 p = strchr(s + 1, s[0]);
135 } else {
136 p = s;
137 }
138
139 /* Now we just need to check that it is not a private
140 * message. If we encounter a space then the preceding
141 * text could not have been a user/player name (the
142 * quote check above eliminated names with spaces) so
143 * it must be a public message. Otherwise if we encounter
144 * the message prefix : then the text parsed up until now
145 * was a player/user name and the line is intended as
146 * a private message (or explicit public message if the
147 * first character is :). */
148 while (p != NULL && *p != '\0') {
149 if (fc_isspace(*p)) {
150 return TRUE;
151 } else if (*p == CHAT_DIRECT_PREFIX) {
152 return FALSE;
153 }
154 p++;
155 }
156 return TRUE;
157}
158
159
160/**********************************************************************/
163static void inputline_return(GtkEntry *w, gpointer data)
164{
165 const char *theinput;
167
169
170 if (*theinput) {
174 char buf[MAX_LEN_MSG];
175
176 fc_snprintf(buf, sizeof(buf), ". %s", theinput);
177 send_chat(buf);
178 } else {
180 }
181
183 void *history_data;
184
188 }
189
191 history_pos = -1;
192 }
193
194 gtk_entry_buffer_set_text(buffer, "", -1);
195}
196
197/**********************************************************************/
200static const char *get_player_or_user_name(int id)
201{
203
204 if (id < size) {
205 return conn_list_get(game.all_connections, id)->username;
206 } else {
207 struct player *pplayer = player_by_number(id - size);
208 if (pplayer) {
209 return pplayer->name;
210 } else {
211 /* Empty slot. Relies on being used with comparison function
212 * which can cope with NULL. */
213 return NULL;
214 }
215 }
216}
217
218/**********************************************************************/
227static int check_player_or_user_name(const char *prefix,
228 const char **matches,
229 const int max_matches)
230{
231 int matches_id[max_matches * 2], ind, num;
232
237 prefix, &ind, matches_id,
238 max_matches * 2, &num)) {
239 case M_PRE_EXACT:
240 case M_PRE_ONLY:
242 return 1;
243 case M_PRE_AMBIGUOUS:
244 {
245 /* Remove duplications playername/username. */
246 const char *name;
247 int i, j, c = 0;
248
249 for (i = 0; i < num && c < max_matches; i++) {
251 for (j = 0; j < c; j++) {
252 if (0 == fc_strncasecmp(name, matches[j], MAX_LEN_NAME)) {
253 break;
254 }
255 }
256 if (j >= c) {
257 matches[c++] = name;
258 }
259 }
260 return c;
261 }
262 case M_PRE_EMPTY:
263 case M_PRE_LONG:
264 case M_PRE_FAIL:
265 case M_PRE_LAST:
266 break;
267 }
268
269 return 0;
270}
271
272/**********************************************************************/
282static size_t get_common_prefix(const char *const *prefixes,
283 size_t num_prefixes,
284 char *buf, size_t buf_len)
285{
286 const char *p;
287 char *q;
288 size_t i;
289
291 for (i = 1; i < num_prefixes; i++) {
292 for (p = prefixes[i], q = buf; *p != '\0' && *q != '\0';
296 *q = '\0';
297 break;
298 }
299 }
300 }
301
302 return g_utf8_strlen(buf, -1);
303}
304
305/**********************************************************************/
310{
311#define MAX_MATCHES 10
312 const char *name[MAX_MATCHES];
314 gint pos;
315 gchar *chars, *p, *prev;
316 int num, i;
317 size_t prefix_len;
318
319 /* Part 1: get the string to complete. */
322
323 p = chars + strlen(chars);
324 while ((prev = g_utf8_find_prev_char(chars, p))) {
326 break;
327 }
328 p = prev;
329 }
330 /* p points to the start of the last word, or the start of the string. */
331
332 prefix_len = g_utf8_strlen(p, -1);
333 if (0 == prefix_len) {
334 /* Empty: nothing to complete, propagate the event. */
335 g_free(chars);
336 return FALSE;
337 }
338
339 /* Part 2: compare with player and user names. */
341 if (1 == num) {
343 pos -= prefix_len;
346 g_free(chars);
347 return TRUE;
348 } else if (num > 1) {
349 if (get_common_prefix(name, num, buf, sizeof(buf)) > prefix_len) {
351 pos -= prefix_len;
354 }
355 sz_strlcpy(buf, name[0]);
356 for (i = 1; i < num; i++) {
357 cat_snprintf(buf, sizeof(buf), ", %s", name[i]);
358 }
359 /* TRANS: comma-separated list of player/user names for completion */
360 output_window_printf(ftc_client, _("Suggestions: %s."), buf);
361 }
362
363 g_free(chars);
364 return TRUE;
365}
366
367/**********************************************************************/
373 GdkModifierType state,
374 gpointer data)
375{
377
378 if ((state & GDK_CONTROL_MASK)) {
379 /* Chatline featured text support. */
380
381 switch (keyval) {
382 case GDK_KEY_b:
384 return TRUE;
385
386 case GDK_KEY_c:
388 return TRUE;
389
390 case GDK_KEY_i:
392 return TRUE;
393
394 case GDK_KEY_s:
396 return TRUE;
397
398 case GDK_KEY_u:
400 return TRUE;
401
402 default:
403 break;
404 }
405
406 } else {
407 /* Chatline history controls. */
409
410 switch (keyval) {
411 case GDK_KEY_Up:
415 -1);
417 }
418 return TRUE;
419
420 case GDK_KEY_Down:
421 if (history_pos >= 0) {
422 history_pos--;
423 }
424
425 if (history_pos >= 0) {
428 -1);
429 } else {
430 gtk_entry_buffer_set_text(buffer, "", -1);
431 }
433 return TRUE;
434
435 case GDK_KEY_Tab:
438 }
439 return FALSE;
440
441 default:
442 break;
443 }
444 }
445
446 return FALSE;
447}
448
449/**********************************************************************/
453{
454 char buf[MAX_LEN_MSG];
457 gchar *selection;
459
461 /* Let's say the selection starts and ends at the current position. */
463 }
464
466
467 if (type == TTT_COLOR) {
468 /* Get the color arguments. */
471
472 if (!fg_color && !bg_color) {
473 goto CLEAN_UP;
474 }
475
476 if (fg_color) {
478 }
479 if (bg_color) {
481 }
482
483 if (0 == featured_text_apply_tag(selection, buf, sizeof(buf),
486 bg_color_text))) {
487 goto CLEAN_UP;
488 }
489 } else if (0 == featured_text_apply_tag(selection, buf, sizeof(buf),
490 type, 0, FT_OFFSET_UNSET)) {
491 goto CLEAN_UP;
492 }
493
494 /* Replace the selection. */
499
501 g_free(selection);
504}
505
506/**********************************************************************/
510void inputline_make_chat_link(struct tile *ptile, bool unit)
511{
512 char buf[MAX_LEN_MSG];
513 GtkWidget *entry = toolkit.entry;
516 gchar *chars;
517 struct unit *punit;
518
519 /* Get the target. */
520 if (unit) {
521 punit = find_visible_unit(ptile);
522 if (!punit) {
523 output_window_append(ftc_client, _("No visible unit on this tile."));
524 return;
525 }
526 } else {
527 punit = NULL;
528 }
529
531 /* There is a selection, make it clickable. */
532 gpointer target;
533 enum text_link_type type;
534
536 if (punit) {
537 type = TLT_UNIT;
538 target = punit;
539 } else if (tile_city(ptile)) {
540 type = TLT_CITY;
541 target = tile_city(ptile);
542 } else {
543 type = TLT_TILE;
544 target = ptile;
545 }
546
547 if (0 != featured_text_apply_tag(chars, buf, sizeof(buf), TTT_LINK,
548 0, FT_OFFSET_UNSET, type, target)) {
549 /* Replace the selection. */
555 }
556 } else {
557 /* Just insert the link at the current position. */
561 start_pos + 1);
562 if (punit) {
564 } else if (tile_city(ptile)) {
566 } else {
567 sz_strlcpy(buf, tile_link(ptile));
568 }
569
570 if (start_pos > 0 && strlen(chars) > 0 && chars[0] != ' ') {
571 /* Maybe insert an extra space. */
573 }
575 if (chars[start_pos > 0 ? 1 : 0] != '\0'
576 && chars[start_pos > 0 ? 1 : 0] != ' ') {
577 /* Maybe insert an extra space. */
579 }
582 }
583
584 g_free(chars);
585}
586
587/**********************************************************************/
616
617/**********************************************************************/
621 double x, double y, gpointer data)
622{
624 GtkTextIter start, end, iter;
625 GtkTextBuffer *buffer;
626 GSList *tags, *tagp;
627 gint bx, by;
628 struct tile *ptile = NULL;
629
631
632 /* We shouldn't follow a link if the user has selected something. */
633 gtk_text_buffer_get_selection_bounds(buffer, &start, &end);
635 return FALSE;
636 }
637
640 x, y, &bx, &by);
641
643
644 if ((tags = gtk_text_iter_get_tags(&iter))) {
645 for (tagp = tags; tagp; tagp = tagp->next) {
646 GtkTextTag *tag = tagp->data;
647 enum text_link_type type =
649
650 if (type != 0) {
651 /* This is a link. */
652 int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(tag), "id"));
653 ptile = NULL;
654
655 /* Real type is type - 1.
656 * See comment in apply_text_tag() for g_object_set_data(). */
657 type--;
658
659 switch (type) {
660 case TLT_CITY:
661 {
662 struct city *pcity = game_city_by_number(id);
663
664 if (pcity) {
665 ptile = client_city_tile(pcity);
666 } else {
667 output_window_append(ftc_client, _("This city isn't known!"));
668 }
669 }
670 break;
671 case TLT_TILE:
672 ptile = index_to_tile(&(wld.map), id);
673
674 if (!ptile) {
676 _("This tile doesn't exist in this game!"));
677 }
678 break;
679 case TLT_UNIT:
680 {
681 struct unit *punit = game_unit_by_number(id);
682
683 if (punit) {
684 ptile = unit_tile(punit);
685 } else {
686 output_window_append(ftc_client, _("This unit isn't known!"));
687 }
688 }
689 break;
690 }
691
692 if (ptile) {
696 }
697 }
698 }
699 g_slist_free(tags);
700 }
701
702 return FALSE;
703}
704
705/**********************************************************************/
709{
711 static GdkCursor *hand_cursor = NULL;
712 static GdkCursor *regular_cursor = NULL;
713 GSList *tags, *tagp;
716
717 /* Initialize the cursors. */
718 if (!hand_cursor) {
720 }
721 if (!regular_cursor) {
723 }
724
726
728 for (tagp = tags; tagp; tagp = tagp->next) {
729 enum text_link_type type =
731
732 if (type != 0) {
733 hovering = TRUE;
734 break;
735 }
736 }
737
740
741 if (hovering_over_link) {
743 } else {
745 }
746 }
747
748 if (tags) {
749 g_slist_free(tags);
750 }
751}
752
753/**********************************************************************/
770
771/**********************************************************************/
790
791/**********************************************************************/
795 ft_offset_t text_start_offset, const char *text)
796{
797 static bool initialized = FALSE;
798 GtkTextIter start, stop;
799
800 if (!initialized) {
802 "weight", PANGO_WEIGHT_BOLD, NULL);
804 "style", PANGO_STYLE_ITALIC, NULL);
806 "strikethrough", TRUE, NULL);
807 gtk_text_buffer_create_tag(buf, "underline",
808 "underline", PANGO_UNDERLINE_SINGLE, NULL);
810 }
811
812 /* Get the position. */
813 /*
814 * N.B.: text_tag_*_offset() value is in bytes, so we need to convert it
815 * to utf8 character offset.
816 */
819 text + text_tag_start_offset(ptag)));
822 } else {
825 text + text_tag_stop_offset(ptag)));
826 }
827
828 switch (text_tag_type(ptag)) {
829 case TTT_BOLD:
830 gtk_text_buffer_apply_tag_by_name(buf, "bold", &start, &stop);
831 break;
832 case TTT_ITALIC:
833 gtk_text_buffer_apply_tag_by_name(buf, "italic", &start, &stop);
834 break;
835 case TTT_STRIKE:
836 gtk_text_buffer_apply_tag_by_name(buf, "strike", &start, &stop);
837 break;
838 case TTT_UNDERLINE:
839 gtk_text_buffer_apply_tag_by_name(buf, "underline", &start, &stop);
840 break;
841 case TTT_COLOR:
842 {
843 /* We have to make a new tag every time. */
844 GtkTextTag *tag = NULL;
845 const char *foreground = text_tag_color_foreground(ptag);
846 const char *background = text_tag_color_background(ptag);
847
848 if (foreground && foreground[0]) {
849 if (background && background[0]) {
851 "foreground", foreground,
852 "background", background,
853 NULL);
854 } else {
856 "foreground", foreground,
857 NULL);
858 }
859 } else if (background && background[0]) {
861 "background", background,
862 NULL);
863 }
864
865 if (!tag) {
866 break; /* No color. */
867 }
868 gtk_text_buffer_apply_tag(buf, tag, &start, &stop);
869 }
870 break;
871 case TTT_LINK:
872 {
873 struct color *pcolor = NULL;
874 GtkTextTag *tag;
875
876 switch (text_tag_link_type(ptag)) {
877 case TLT_CITY:
879 break;
880 case TLT_TILE:
882 break;
883 case TLT_UNIT:
885 break;
886 }
887
888 if (!pcolor) {
889 break; /* Not a valid link type case. */
890 }
891
893 "foreground-rgba", &pcolor->color,
894 "underline", PANGO_UNDERLINE_SINGLE,
895 NULL);
896
897 /* Type 0 is reserved for non-link tags. So, add 1 to the
898 * type value. */
899 g_object_set_data(G_OBJECT(tag), "type",
901 g_object_set_data(G_OBJECT(tag), "id",
903 gtk_text_buffer_apply_tag(buf, tag, &start, &stop);
904 break;
905 }
906 }
907}
908
909/**********************************************************************/
914 const struct text_tag_list *tags,
915 int conn_id)
916{
921
923
924 if (buf == NULL) {
925 log_error("Output when no message buffer: %s", astring);
926
927 return;
928 }
929
931 gtk_text_buffer_insert(buf, &iter, "\n", -1);
933
935 char timebuf[64];
936 time_t now;
937 struct tm now_tm;
938
939 now = time(NULL);
941 strftime(timebuf, sizeof(timebuf), "[%H:%M:%S] ", &now_tm);
943 }
944
950
951 if (main_message_area) {
953 }
954 if (start_message_area) {
956 }
958
960}
961
962/**********************************************************************/
968{
969 GtkTextIter start, end;
970 gchar *txt;
971
974
976 g_free(txt);
977}
978
979/**********************************************************************/
983{
984 set_output_window_text(_("Cleared output window."));
985}
986
987/**********************************************************************/
990void set_output_window_text(const char *text)
991{
993}
994
995/**********************************************************************/
999{
1000 GtkWidget *sw, *w;
1002 gdouble val, max, upper, page_size;
1003
1004 if (get_client_page() == PAGE_GAME) {
1006 } else {
1008 }
1009
1010 if (w == NULL) {
1011 return TRUE;
1012 }
1013
1014 sw = gtk_widget_get_parent(w);
1017 g_object_get(G_OBJECT(vadj), "upper", &upper,
1018 "page-size", &page_size, NULL);
1019 max = upper - page_size;
1020
1021 /* Approximation. */
1022 return max - val < 0.00000001;
1023}
1024
1025/**********************************************************************/
1034{
1035 chatline_scroll_to_bottom(FALSE); /* Not delayed this time! */
1036
1037 *((guint *) data) = 0;
1038 return FALSE; /* Remove this idle function. */
1039}
1040
1041/**********************************************************************/
1046{
1047 static guint callback_id = 0;
1048
1049 if (delayed) {
1050 if (callback_id == 0) {
1052 }
1053 } else if (message_buffer) {
1054 GtkTextIter end;
1055
1057
1058 if (main_message_area) {
1060 &end, 0.0, TRUE, 1.0, 0.0);
1061 }
1062 if (start_message_area) {
1064 &end, 0.0, TRUE, 1.0, 0.0);
1065 }
1066 }
1067}
1068
1069/**********************************************************************/
1072static void make_tag_callback(GtkButton *button, gpointer data)
1073{
1076 "text_tag_type")));
1077}
1078
1079/**********************************************************************/
1082static void color_set(GObject *object, const gchar *color_target,
1083 GdkRGBA *color, GtkButton *button)
1084{
1086
1087 if (NULL == color) {
1088 /* Clears the current color. */
1089 if (NULL != current_color) {
1092 if (NULL != button) {
1093 gtk_button_set_child(button, NULL);
1094 }
1095 }
1096 } else {
1097 /* Apply the new color. */
1098 if (NULL != current_color) {
1099 /* We already have a GdkRGBA pointer. */
1100 *current_color = *color;
1101 } else {
1102 /* We need to make a GdkRGBA pointer. */
1105 }
1106
1107 if (NULL != button) {
1108 /* Update the button. */
1111
1112 gtk_button_set_child(button, NULL);
1113
1114 {
1116 CAIRO_FORMAT_RGB24, 16, 16);
1117 cairo_t *cr = cairo_create(surface);
1118
1120 cairo_paint(cr);
1121 cairo_destroy(cr);
1122 pixbuf = gdk_pixbuf_get_from_surface(surface, 0, 0, 16, 16);
1123 cairo_surface_destroy(surface);
1124 }
1126 gtk_button_set_child(button, image);
1129 }
1130 }
1131}
1132
1133/**********************************************************************/
1136static void color_selected(GtkDialog *dialog, gint res, gpointer data)
1137{
1138 const gchar *color_target =
1139 g_object_get_data(G_OBJECT(data), "color_target");
1140 GObject *entry = g_object_get_data(G_OBJECT(data), "entry");
1141
1142 if (res == GTK_RESPONSE_REJECT) {
1143 /* Clears the current color. */
1145 } else if (res == GTK_RESPONSE_OK) {
1146 /* Apply the new color. */
1148 GTK_COLOR_CHOOSER(g_object_get_data(G_OBJECT(dialog), "chooser"));
1150
1153 }
1154
1156}
1157
1158/**********************************************************************/
1161static void select_color_callback(GtkButton *button, gpointer data)
1162{
1163 GtkWidget *dialog, *chooser;
1164 /* "fg_color" or "bg_color". */
1166 "color_target");
1168
1169 /* TRANS: "text" or "background". */
1170 gchar *buf = g_strdup_printf(_("Select the %s color"),
1171 (const char *) g_object_get_data(G_OBJECT(button),
1172 "color_info"));
1174 _("_Cancel"), GTK_RESPONSE_CANCEL,
1175 _("C_lear"), GTK_RESPONSE_REJECT,
1176 _("_OK"), GTK_RESPONSE_OK, NULL);
1177 setup_dialog(dialog, toplevel);
1178 g_object_set_data(G_OBJECT(button), "entry", data);
1179 g_signal_connect(dialog, "response", G_CALLBACK(color_selected), button);
1180
1183 chooser, NULL);
1184 g_object_set_data(G_OBJECT(dialog), "chooser", chooser);
1185
1186 if (current_color != NULL) {
1188 }
1189
1191 g_free(buf);
1192}
1193
1194/**********************************************************************/
1198{
1199 struct inputline_toolkit *ptoolkit = (struct inputline_toolkit *) data;
1202 "button_box"));
1203 GtkWidget *iter;
1204
1205 if (parent) {
1206 if (parent == toolkit_view) {
1207 return FALSE; /* Already owned. */
1208 }
1209
1210 /* N.B.: We need to hide/show the toolbar to reset the sensitivity
1211 * of the tool buttons. */
1212 if (ptoolkit->toolbar_displayed) {
1214 }
1215 g_object_ref(ptoolkit->main_widget); /* Make sure reference count stays above 0
1216 * during the transition to new parent. */
1217 gtk_box_remove(GTK_BOX(parent), ptoolkit->main_widget);
1219 g_object_unref(ptoolkit->main_widget);
1220 if (ptoolkit->toolbar_displayed) {
1222 }
1223
1225 /* Attach to the toolkit button_box. */
1227 }
1229 if (!ptoolkit->toolbar_displayed) {
1231 }
1232
1233 /* Hide all other buttons boxes. */
1235 iter != NULL;
1237 if (iter != button_box) {
1239 }
1240 }
1241
1242 } else {
1243 /* First time attached to a parent. */
1246 gtk_widget_set_visible(ptoolkit->main_widget, TRUE);
1247 }
1248
1249 return FALSE;
1250}
1251
1252/**********************************************************************/
1256{
1257 struct inputline_toolkit *ptoolkit = (struct inputline_toolkit *) data;
1258 GtkToggleButton *button = GTK_TOGGLE_BUTTON(toolkit.toggle_button);
1259
1260 if (ptoolkit->toolbar_displayed) {
1261 if (!gtk_toggle_button_get_active(button)) {
1262 /* button_toggled() will be called and the toolbar shown. */
1264 } else {
1265 /* Ensure the widget is visible. */
1267 }
1268 } else {
1269 if (gtk_toggle_button_get_active(button)) {
1270 /* button_toggled() will be called and the toolbar hidden. */
1272 } else {
1273 /* Ensure the widget is not visible. */
1275 }
1276 }
1277
1278 return FALSE;
1279}
1280
1281/**********************************************************************/
1284static void button_toggled(GtkToggleButton *button, gpointer data)
1285{
1286 struct inputline_toolkit *ptoolkit = (struct inputline_toolkit *) data;
1287
1288 if (gtk_toggle_button_get_active(button)) {
1290 ptoolkit->toolbar_displayed = TRUE;
1292 /* Make sure to be still at the end. */
1294 }
1295 } else {
1297 ptoolkit->toolbar_displayed = FALSE;
1298 }
1299}
1300
1301/**********************************************************************/
1309{
1311
1312 /* Main widget. */
1316
1317 /* Button box. */
1320
1321 return toolkit_view;
1322}
1323
1324/**********************************************************************/
1333
1334/**********************************************************************/
1338{
1339 GtkWidget *vbox, *hgrid, *entry, *bbox;
1340 GtkWidget *button;
1342 GtkWidget *item;
1343 GdkRGBA color;
1344 int grid_col = 0;
1347
1348 /* Chatline history. */
1349 if (!history_list) {
1351 history_pos = -1;
1352 }
1353
1354 /* Inputline toolkit. */
1355 memset(&toolkit, 0, sizeof(toolkit));
1356
1358
1359 toolkit.main_widget = vbox;
1360 g_signal_connect_after(vbox, "map",
1362
1363 entry = gtk_entry_new();
1375 toolkit.entry = entry;
1376
1377 hgrid = gtk_grid_new();
1379
1380 /* First line: toolbar */
1383 toolkit.toolbar = toolbar;
1384
1385 /* Bold button. */
1386 item = gtk_button_new_from_icon_name("format-text-bold");
1387
1388 /* _("Bold")); */
1389
1391 g_object_set_data(G_OBJECT(item), "text_tag_type",
1394 gtk_widget_set_tooltip_text(GTK_WIDGET(item), _("Bold (Ctrl-B)"));
1395
1396 /* Italic button. */
1397 item = gtk_button_new_from_icon_name("format-text-italic");
1398
1399 /* _("Italic")); */
1400
1402 g_object_set_data(G_OBJECT(item), "text_tag_type",
1405 gtk_widget_set_tooltip_text(GTK_WIDGET(item), _("Italic (Ctrl-I)"));
1406
1407 /* Strike button. */
1408 item = gtk_button_new_from_icon_name("format-text-strikethrough");
1409
1410 /* _("Strikethrough")); */
1412 g_object_set_data(G_OBJECT(item), "text_tag_type",
1415 gtk_widget_set_tooltip_text(GTK_WIDGET(item), _("Strikethrough (Ctrl-S)"));
1416
1417 /* Underline button. */
1418 item = gtk_button_new_from_icon_name("format-text-underline");
1419
1420 /* _("Underline")); */
1422 g_object_set_data(G_OBJECT(item), "text_tag_type",
1425 gtk_widget_set_tooltip_text(GTK_WIDGET(item), _("Underline (Ctrl-U)"));
1426
1428
1429 /* Color button. */
1430 item = gtk_button_new_with_label(_("Color"));
1431
1433 g_object_set_data(G_OBJECT(item), "text_tag_type",
1436 gtk_widget_set_tooltip_text(GTK_WIDGET(item), _("Color (Ctrl-C)"));
1437
1439
1440 /* Foreground selector. */
1441 item = gtk_button_new();
1443 g_object_set_data(G_OBJECT(item), "color_target", fc_strdup("fg_color"));
1444 g_object_set_data(G_OBJECT(item), "color_info",
1445 fc_strdup(_("foreground")));
1446 g_signal_connect(item, "clicked",
1448 gtk_widget_set_tooltip_text(GTK_WIDGET(item), _("Select the text color"));
1449 if (gdk_rgba_parse(&color, "#000000")) {
1450 /* Set default foreground color. */
1451 color_set(G_OBJECT(entry), "fg_color", &color, GTK_BUTTON(item));
1452 } else {
1453 log_error("Failed to set the default foreground color.");
1454 }
1455
1456 /* Background selector. */
1457 item = gtk_button_new();
1459 g_object_set_data(G_OBJECT(item), "color_target", fc_strdup("bg_color"));
1460 g_object_set_data(G_OBJECT(item), "color_info",
1461 fc_strdup(_("background")));
1462 g_signal_connect(item, "clicked",
1465 _("Select the background color"));
1466 if (gdk_rgba_parse(&color, "#ffffff")) {
1467 /* Set default background color. */
1468 color_set(G_OBJECT(entry), "bg_color", &color, GTK_BUTTON(item));
1469 } else {
1470 log_error("Failed to set the default background color.");
1471 }
1472
1474
1475 /* Return button. */
1478 g_signal_connect_swapped(item, "clicked",
1481 /* TRANS: "Return" means the return key. */
1482 _("Send the chat (Return)"));
1483
1484 /* Second line */
1486
1487 /* Toggle button. */
1488 button = gtk_toggle_button_new();
1490 gtk_widget_set_margin_end(button, 2);
1491 gtk_widget_set_margin_start(button, 2);
1492 gtk_widget_set_margin_top(button, 2);
1493 gtk_grid_attach(GTK_GRID(hgrid), button, grid_col++, 0, 1, 1);
1494 gtk_button_set_icon_name(GTK_BUTTON(button), "insert-link");
1495 g_signal_connect(button, "toggled", G_CALLBACK(button_toggled), &toolkit);
1496 gtk_widget_set_tooltip_text(GTK_WIDGET(button), _("Chat tools"));
1497 toolkit.toggle_button = button;
1498
1499 /* Entry. */
1502
1504 g_signal_connect(chat_controller, "key-pressed",
1507
1508 /* Button box. */
1511 toolkit.button_box = bbox;
1512}
1513
1514/**********************************************************************/
1518{
1519 char *vertext = (char *)user_data;
1520
1522
1524
1525 return G_SOURCE_REMOVE;
1526}
1527
1528/**********************************************************************/
1531void version_message(const char *vertext)
1532{
1533 int len = strlen(vertext) + 1;
1534 char *persistent = fc_malloc(len);
1535
1537
1539}
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: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
#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 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 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:96
static gboolean chat_pointer_motion(GtkEventControllerMotion *controller, gdouble e_x, gdouble e_y, gpointer data)
Definition chatline.c:756
static gboolean il_gained_focus(GtkEventControllerFocus *controller, gpointer data)
Definition chatline.c:107
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: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