1 /***********************************************************************
2  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3    This program is free software; you can redistribute it and/or modify
4    it under the terms of the GNU General Public License as published by
5    the Free Software Foundation; either version 2, or (at your option)
6    any later version.
7 
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12 ***********************************************************************/
13 
14 #ifdef HAVE_CONFIG_H
15 #include <fc_config.h>
16 #endif
17 
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 
22 #include <X11/Intrinsic.h>
23 #include <X11/StringDefs.h>
24 #include <X11/Xaw/AsciiText.h>
25 
26 /* utility */
27 #include "fcintl.h"
28 #include "log.h"
29 #include "mem.h"
30 #include "shared.h"
31 #include "support.h"
32 
33 /* common */
34 #include "packets.h"
35 
36 /* client */
37 #include "climisc.h"
38 
39 /* client/gui-xaw */
40 #include "gui_main.h"
41 #include "gui_stuff.h"
42 
43 #include "chatline.h"
44 
45 /**************************************************************************
46 ...
47 **************************************************************************/
chatline_key_send(Widget w)48 void chatline_key_send(Widget w)
49 {
50   String theinput;
51   String empty="";
52 
53   XtVaGetValues(w, XtNstring, &theinput, NULL);
54 
55   if(*theinput) {
56     send_chat(theinput);
57   }
58 
59   XtVaSetValues(w, XtNstring, empty, NULL);
60 }
61 
62 /**************************************************************************
63   Appends the string to the chat output window.  The string should be
64   inserted on its own line, although it will have no newline.
65 **************************************************************************/
real_output_window_append(const char * astring,const struct text_tag_list * tags,int conn_id)66 void real_output_window_append(const char *astring,
67                                const struct text_tag_list *tags,
68                                int conn_id)
69 {
70   /* this is properly a bad way to append to a text widget. Using the
71    * "useStringInPlace" resource and doubling mem alloc'ing would be better.
72    * Nope - tried it and many other variations and it wasn't any better.
73    * I'll replace this widget with a widget supportting hyperlinks later, so
74    * leth's forget the problem.
75    *
76    * There seems to be an Xaw problem with doing both wrap and scroll:
77    * its supposed to automatically scroll to end when we change the insertion
78    * point, but if a line is wrapped the scroll lags behind a line, and
79    * stays behind on subsequent additions, until the too-long line scrolls
80    * off the top.  (I tried setting the insert position to the last char,
81    * instead of the start of line as below, but that didn't help.)  So we
82    * split the line ourselves.  I'm just using a fixed length split; should
83    * perhaps check and use width of output window (but font size?)  -dwp
84    *
85    * Now uses window's font size and width.  Assumes fixed-width font.  --jjm
86    */
87   String theoutput;
88   char *newout, *rmcr, *astring2 = fc_strdup(astring);
89 
90   XtVaGetValues(outputwindow_text, XtNstring, &theoutput, NULL);
91   newout=fc_malloc(strlen(astring2)+strlen(theoutput)+2);
92   sprintf(newout, "%s\n%s", theoutput, astring2);
93 
94   /* calc carret position - last line, first pos */
95   for(rmcr=newout+strlen(newout); rmcr>newout; rmcr--)
96     if(*rmcr=='\n')
97       break;
98 
99   /* shit happens when setting both values at the same time */
100   XawTextDisableRedisplay(outputwindow_text);
101   XtVaSetValues(outputwindow_text, XtNstring, newout, NULL);
102   XtVaSetValues(outputwindow_text, XtNinsertPosition, rmcr-newout+1, NULL);
103   XawTextEnableRedisplay(outputwindow_text);
104 
105   free(newout);
106   free(astring2);
107 }
108 
109 /**************************************************************************
110  I have no idea what module this belongs in -- Syela
111  I've decided to put output_window routines in chatline.c, because
112  the are somewhat related and append_output_window is already here.  --dwp
113 **************************************************************************/
log_output_window(void)114 void log_output_window(void)
115 {
116   String theoutput;
117 
118   XtVaGetValues(outputwindow_text, XtNstring, &theoutput, NULL);
119   write_chatline_content(theoutput);
120 }
121 
122 /**************************************************************************
123 ...
124 **************************************************************************/
clear_output_window(void)125 void clear_output_window(void)
126 {
127   XtVaSetValues(outputwindow_text, XtNstring, _("Cleared output window."), NULL);
128 }
129 
130 /**************************************************************************
131   Got version message from metaserver thread.
132 **************************************************************************/
version_message(const char * vertext)133 void version_message(const char *vertext)
134 {
135   output_window_append(ftc_client, vertext);
136 }
137