Complete.Org: Mailing Lists: Archives: freeciv-dev: June 1999:
[Freeciv-Dev] Re: problem with the xaw output (PR#2)
Home

[Freeciv-Dev] Re: problem with the xaw output (PR#2)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Cc: bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: problem with the xaw output (PR#2)
From: dwp@xxxxxxxxxxxxxx
Date: Sun, 13 Jun 1999 06:16:50 -0700 (PDT)

This is a multi-part message in MIME format.

--_----------=_929279605232040
Content-Disposition: inline
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Nicolas Brunel wrote:

> This problem occurs with the xaw client. 
> When a lign is too long is entered, the whole lign is not shown in the output.
> The output will stay at least one lign late.

I looked into this, and it seems to me to be an Xaw bug.
See comments in patch attached.  I couldn't find a good Xaw
fix, so the patch attached manually inserts line breaks.

Its not ideal, since it doesn't adjust to the actual 
output window width, and even if it did it wouldn't be
able to handle well if the user adjusts the window size.
(Eg, including for previous lines.)

But at least it should stop messages disappearing off
the bottom of the output window for the most part.

-- David

--_----------=_929279605232040
Content-Disposition: inline; filename="wrap_output.diff"
Content-Type: text/plain; name="wrap_output.diff"
Content-Transfer-Encoding: 7bit

diff -u -r --exclude-from exclude freeciv-cvs/client/gui-xaw/chatline.c 
freeciv-mod/client/gui-xaw/chatline.c
--- freeciv-cvs/client/gui-xaw/chatline.c       Sat Jun 12 17:40:05 1999
+++ freeciv-mod/client/gui-xaw/chatline.c       Sun Jun 13 21:45:15 1999
@@ -20,6 +20,7 @@
 
 #include "mem.h"
 #include "packets.h"
+#include "shared.h"            /* wordwrap_string() */
 
 #include "clinet.h"
 #include "gui_stuff.h"
@@ -28,6 +29,8 @@
 
 extern Widget inputline_text, outputwindow_text;
 
+#define OUTPUT_MAXLEN 95
+
 /**************************************************************************
 ...
 **************************************************************************/
@@ -49,19 +52,32 @@
   XtVaSetValues(w, XtNstring, empty, NULL);
 }
 
-char *buf;
 /**************************************************************************
  this is properly a bad way to append to a text widget. Using the 
  "useStringInPlace" resource and doubling mem alloc'ing would be better.  
  Nope - tried it and many other variations and it wasn't any better. 
  I'll replace this widget with a widget supportting hyperlinks later, so
  leth's forget the problem.
- **************************************************************************/
+
+ There seems to be an Xaw problem with doing both wrap and scroll:
+ its supposed to automatically scroll to end when we change the insertion
+ point, but if a line is wrapped the scroll lags behind a line, and
+ stays behind on subsequent additions, until the too-long line scrolls
+ off the top.  (I tried setting the insert position to the last char,
+ instead of the start of line as below, but that didn't help.)  So we
+ split the line ourselves.  I'm just using a fixed length split; should
+ perhaps check and use width of output window (but font size?)  -dwp
+**************************************************************************/
 void append_output_window(char *astring)
 {
-
   String theoutput;
   char *newout, *rmcr;
+  char *input_string = astring;
+
+  if (strlen(astring) > OUTPUT_MAXLEN) {
+    astring = mystrdup(astring);
+    wordwrap_string(astring, OUTPUT_MAXLEN);
+  }
   
   XtVaGetValues(outputwindow_text, XtNstring, &theoutput, NULL);
   newout=fc_malloc(strlen(astring)+strlen(theoutput)+2);
@@ -81,6 +97,9 @@
   XawTextEnableRedisplay(outputwindow_text);
   
   free(newout);
+  if (astring != input_string) {
+    free(astring);
+  }
 }
 
 /**************************************************************************
diff -u -r --exclude-from exclude freeciv-cvs/common/shared.c 
freeciv-mod/common/shared.c
--- freeciv-cvs/common/shared.c Sat Jun 12 17:40:10 1999
+++ freeciv-mod/common/shared.c Sun Jun 13 21:30:46 1999
@@ -385,6 +385,52 @@
 }
 
 /***************************************************************************
+  Change spaces in s into newlines, so as to keep lines length len
+  or shorter.  That is, modifies s.
+  Returns number of lines in modified s.
+***************************************************************************/
+int wordwrap_string(char *s, int len)
+{
+  int num_lines = 0;
+  
+  /* At top of this loop, s points to the rest of string,
+   * either at start or after inserted newline: */
+ top:
+  if (s && *s && strlen(s) > len) {
+    char *c;
+
+    num_lines++;
+    
+    /* check if there is already a newline: */
+    for(c=s; c<s+len; c++) {
+      if (*c == '\n') {
+       s = c+1;
+       goto top;
+      }
+    }
+    
+    /* find space and break: */
+    for(c=s+len; c>s; c--) {
+      if (isspace(*c)) {
+       *c = '\n';
+       s = c+1;
+       goto top;
+      }
+    }
+
+    /* couldn't find a good break; settle for a bad one... */
+    for(c=s+len+1; *c; c++) {
+      if (isspace(*c)) {
+       *c = '\n';
+       s = c+1;
+       goto top;
+      }
+    }
+  }
+  return num_lines;
+}
+
+/***************************************************************************
   Returns string which gives users home dir, as specified by $HOME.
   Gets value once, and then caches result.
   If $HOME is not set, give a log message and returns NULL.
diff -u -r --exclude-from exclude freeciv-cvs/common/shared.h 
freeciv-mod/common/shared.h
--- freeciv-cvs/common/shared.h Thu Jun 10 22:20:18 1999
+++ freeciv-mod/common/shared.h Sun Jun 13 20:49:33 1999
@@ -78,6 +78,7 @@
 char *remove_leading_spaces(char *s);
 void remove_trailing_spaces(char *s);
 void remove_trailing_char(char *s, char trailing);
+int wordwrap_string(char *s, int len);
 
 char *user_home_dir(void);
 char *datafilename(char *filename);

--_----------=_929279605232040--



[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] Re: problem with the xaw output (PR#2), dwp <=