ssroy@phoenix.Princeton.EDU (Steve Scot Roy) (02/17/89)
I have a question about text widgets that should be easy. If I create a text widget without an initial string it creates its own buffer and handles it itself. How do I get at the text in the buffer? I tried XtGetValues for XtNstring but I got a null pointer back. Is this a bug? Am I overlooking a routine in the manual for this? If it is a bug, how do you work around it and when will it be fixed? Sorry if this has been answered before, but I need this and I'm stumped. Steve Roy ssr@courant.princeton.edu
meo@stiatl.UUCP (Miles O'Neal) (02/17/89)
In article <6444@phoenix.Princeton.EDU> ssroy@phoenix.Princeton.EDU (Steve Scot Roy) writes: >If I create a text widget without an initial string it creates its own >buffer and handles it itself. How do I get at the text in the buffer? I >tried XtGetValues for XtNstring but I got a null pointer back. Is this >a bug? Am I overlooking a routine in the manual for this? If it is a >bug, how do you work around it and when will it be fixed? Sorry if this >has been answered before, but I need this and I'm stumped. Steve, We had the same problem. The following was what we came up with to fix the problem. Unfortunately, only the GetText part worked, we could never successfully replace the text in anything approaching a rational manner, which is why we wrote our own replacement (that and we really wanted something slightly different anyway). #include <X11/Xatom.h> #include <X11/IntrinsicP.h> #include <X11/StringDefs.h> #include <X11/TextP.h> #include <X11/AsciiText.h> int PutTextOnScreen (w, s) Widget w; char *s; { static XtTextBlock tb; int ret; tb.ptr = s; tb.firstPos = 0; tb.length = strlen (tb.ptr); ret = XtTextReplace(w, (XtTextPosition)0, (XtTextPosition)sizeof(bs)-1, &tb); return ret; } char *GetTextFromScreen (w) Widget w; { static XtTextBlock tb; TextWidget ww = (TextWidget) w; (*ww->text.source->Read) (ww->text.source, 0l, &tb, 2000); return tb.ptr; } I would love to know why the PutText part never worked (it would reliably put the 1st 2 characters of the buffer on the screen!), but it's somewhat moot right now. Anyway, the trick is to get down in the guts of the TextWidget, as seen here. -Miles