[comp.windows.x] text widget bug?

Rick.Kazman@SEI.CMU.EDU (06/13/89)

A while ago, I posted, asking information about text strings in the Athena
text widgets, and I was told that they are just like ordinary strings in C:
they terminate with a '\0' character.  I was also told that the text widget
uses strlen() to determine the length of the string.  However, it appears to
me that once the text widget thinks it knows the length of the string that
you're displaying, it doesn't check the string again to determine its
length.  I have enclosed a test program which demonstrates this.  

This program has a command widget and a text widget, enclosed in a form
widget.  When the user presses the command button, he gets prompted to enter
the text to be displayed in the text widget.  When the text is redisplayed,
only the number of characters in the original text are displayed--larger
strings get truncated and shorter ones have the end of the old string tacked
onto them.  

So, my question is, how do I get the text widget to look at the string
again, to determine its new length?

Thanks.  rick

p.s. I'm running a Sun 3/60 with X11/R3 and the Athena widget set.
______________________________________________________________________

#include <stdio.h>
#include <X11/Intrinsic.h>
#include <X11/Command.h>
#include <X11/Form.h>
#include <X11/AsciiText.h>
#include <X11/Text.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>

char temp_body[100] = "bungfig" ;

XtCallbackProc Activate(w, client_data, call_data)
    Widget w;
    caddr_t client_data ;
    caddr_t call_data ;
{
    printf("Gimme one: ");
    scanf("%s", temp_body) ;
}


void main(argc, argv)
    unsigned int argc;
    char **argv;
{
    int n ;
    Widget toplevel, command_widget1, form_widget, text_widget1 ;
    Arg args[25] ;

    static XtCallbackRec callbacks[] = {
      { Activate, (caddr_t) NULL },
      { NULL, NULL },
    };

    toplevel = XtInitialize ("test1", "Test1", NULL, 0, &argc, argv);

    form_widget = XtCreateManagedWidget( "form", formWidgetClass, 
			toplevel, args, XtNumber(args) );

    n = 0 ;
    XtSetArg(args[n], XtNhorizDistance, (XtArgVal) 150) ; n++;
    XtSetArg(args[n], XtNvertDistance, (XtArgVal) 175) ; n++; 
    XtSetArg(args[n], XtNwidth, (XtArgVal) 200) ; n++;
    XtSetArg(args[n], XtNheight, (XtArgVal) 50) ; n++;
    XtSetArg(args[n], XtNeditType, (XtArgVal) XttextEdit) ; n++;
    XtSetArg(args[n], XtNtextOptions, (XtArgVal) editable) ; n++;
    XtSetArg(args[n], XtNlength, (XtArgVal) 100) ; n++;
    XtSetArg(args[n], XtNstring, temp_body);
    text_widget1 = XtCreateManagedWidget("", asciiStringWidgetClass, 
			form_widget, args, XtNumber(args) );

    n = 0 ;
    XtSetArg(args[n], XtNcallback, (XtArgVal) callbacks) ; n++;
    XtSetArg(args[n], XtNlabel, "Scudda hoo") ; n++;
    XtSetArg(args[n], XtNhorizDistance, (XtArgVal) 10) ; n++;
    XtSetArg(args[n], XtNvertDistance, (XtArgVal) 10) ; n++; 
    XtSetArg(args[n], XtNwidth, (XtArgVal) 100) ; n++;
    XtSetArg(args[n], XtNheight, (XtArgVal) 50) ; n++;
    command_widget1 = XtCreateManagedWidget( "command", commandWidgetClass, 
			form_widget, args, XtNumber(args) );

    XtRealizeWidget(toplevel);

    XtMainLoop() ;
}

swick@ATHENA.MIT.EDU (Ralph R. Swick) (06/13/89)

> So, my question is, how do I get the text widget to look at the string
> again, to determine its new length?

You're not supposed to directly modify the string once you pass it
to the Text widget; at this point, the widget owns it until you
destroy the widget.  Use XtTextReplace() instead.

janson@ATHENA.MIT.EDU (06/21/89)

> > So, my question is, how do I get the text widget to look at the string
> > again, to determine its new length?
>
> You're not supposed to directly modify the string once you pass it
> to the Text widget; at this point, the widget owns it until you
> destroy the widget.  Use XtTextReplace() instead.

what is one supposed to do in order to change the actual size and
location  of the text buffer?

kit@EXPO.LCS.MIT.EDU (Chris D. Peterson) (06/21/89)

> what is one supposed to do in order to change the actual size and
> location  of the text buffer?

In this case you need to destroy the current text source, and create another
one for the text widget.  Use the functions XtStringSourceDestroy() and
XtStringSourceCreate().  This will allow you to change the size of the 
string that is currently displayed.

						Chris D. Peterson     
						MIT X Consortium 

Net:	 kit@expo.lcs.mit.edu
Phone:   (617) 253 - 9608	
Address: MIT - Room NE43-213