[comp.windows.x] TextWidget - getting text

meo@stiatl.UUCP (Miles O'Neal) (10/10/89)

Someone asked how to get text from a buffer in the TextWidget.

The following worked for us.

-------------------------------------------------------------------------------
/*
   Copyright 1988, Sales Technologies, Inc. We don't use this code,
   so feel free to use it however you wish!
*/
#include <X11/TextP.h>

...

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;
}
-------------------------------------------------------------------------------

Note that it accesses private widget data and requires the private
header file.

We tried using the corresponding text replacement routines to write
to the text widget, but only got the 1st 2 characters to show up;
the rest of the widget was blanked out.

This was under X11R2 - by  the time R3 was up, we had written a
replacement for the TextWidget (VERY limited functionality compared
to the TW - don't think I threw together a true replacement!), so
I don't know whether the text replacement would work under R3 or
not. We never got it to work.

We use the default buffer allocated by the TW.

-Miles O'Neal
{yr fave backbone here}!gatech!stiatl!meo

kit@EXPO.LCS.MIT.EDU (Chris D. Peterson) (10/11/89)

> The following worked for us.

> char *GetTextFromScreen (w)

[ code deleted. ]

Bleh !!!

Without being too annoying I would like to urge people not to use this function
unless absolutely necessary.  It is prone to dister.  If you want to retreive
all the text from a text widget then just make a GetValues call on the XtNstring
resource.  If you want to get some subset of the text then take a look at the
internal function _XtTextGetText().  This function is much more robust than the
one posted to xpert.  In any case using the internal text routines will be
INCOMPATABLE with the R4 text widget.  I have preseved the publicly documented
interface, but the internal one has gone through major changes.

BTW:  Things will be much easier to deal with in R$.  I have made many changes
      to the text widget, and I think the code makes it both easier to use,
      and more powerful.


						Chris D. Peterson     
						MIT X Consortium 

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