[comp.windows.x.motif] XmText and arbitrary text additions

lampshir@airgun.wg.waii.com (gregory b. lampshire) (07/11/90)

Howdy Motif lovers (or disenchanted users)!

I need to append an arbitrary amount of text
to the XmText widget (MOTIF).  What my ultimate
goal is this.  I would like to make
the XmText widget into a sort of transcript 
region.  I need to collect application 
messages and other user info. into a text
area so that they can scroll through it and
review the output of the application (of which
the transcript is a part of).  

The xterm window has capability that I like,
that is, it can collect output from programs
that write to stdout and stderr etc....  I would
like the same type of running transcript capability
in my application for application specific
messages.  I am really a Smalltalk-80 programmer
and liked the transcript idea that Smalltalk
uses.

Any help?  I would appreciate some postings.
 
-- 
Gregory B. Lampshire     |    DOMAIN lampshir@airgun.wg.waii.com
Western Geophysical      |    UUNET  uunet!airgun!lampshir

carl@quad1.quad.com (Carl Priddy) (07/12/90)

It is the programmers responsibilty to maintain a copy of the text which
he initially sets as the XmNvalue resource of the text widget. The text
widget makes a copy of it which it then uses for it's own editing. The
text widget callback routines can be used to fetch a copy of the (possibly)
modified text. If you wish to edit the text yourself (you being programmer),
then do so with your internal version, and use XtSetValues to redefine the
XmNvalue resource of your text widget.
Hope this helps. FYI, I have just finished writing an X/Motif word processor,
and ended up using the DrawingArea widget and doing my own scrolling, etc.
becuase the Text widget apparently carries with it a LOT of overhead.

carl priddy QSI (Quadratron Systems, Inc)

meeks@osf.org (W. Scott Meeks) (07/12/90)

Al's solution was good, but it completely clears the log when MAX_LOG_SIZE
is reached.  To have something more like what xterm does, you need to just
dump the oldest material in the log that doesn't fit anymore.  Here's some
example code:

#define MAX_LOG_SIZE 4000

static log_size = 0;

void add_to_log(str)
    char *str;
{
    int len = strlen(str);

    if (log_size+len < MAX_LOG_SIZE) {
        XmTextReplace (log, log_size, log_size, str);
        log_size += len;
    }
    else 
      {
	diff = (log_size + len) - MAX_LOG_SIZE;
	XmTextReplace (log, 0, diff, "");
	XmTextReplace (log, MAX_LOG_SIZE - len, MAX_LOG_SIZE - len, str);
        log_size=MAX_LOG_SIZE;
    }
}


W. Scott Meeks
Open Software Foundation
meeks@osf.org
(617) 621-7229