Submitted by Anonymous on Mon, 08/04/2003 - 13:40.
I have a scrolled window with a scrolled text as a child. After I write to the scrolled text I attempt to scroll the last message into view with a call to XmTextShowPosition, passing it the last text position returned from XmTextGetLastPosition. The value I get from XmTextGetLastPosition appears to be reasonable, but the position never scrolls into view. Is there some resource that the text or scrolled window must be set to in order to make this call work? The O`Reilly Motif Reference Manual does not make reference to any.
Code is shown below
<br />
// Create the scrolled window & text</p>
<p> Widget w = XtVaCreateManagedWidget("scrolled", xmScrolledWindowWidgetClass, form,<br />
XmNtopAttachment, XmATTACH_WIDGET,<br />
XmNtopWidget, w,<br />
XmNtopOffset, 10,<br />
XmNleftAttachment, XmATTACH_FORM,<br />
XmNleftOffset, 10,<br />
XmNrightAttachment, XmATTACH_FORM,<br />
XmNrightOffset, 10,<br />
XmNwidth, 200,<br />
XmNheight, 250,<br />
XmNscrollingPolicy, XmAUTOMATIC,<br />
NULL);</p>
<p> Widget y = XtVaCreateManagedWidget("text", xmTextWidgetClass,<br />
bitm->biw.sw,<br />
XmNeditMode, XmMULTI_LINE_EDIT,<br />
XmNeditable, False,<br />
XmNwordWrap, True,<br />
XmNcursorPositionVisible, False,<br />
XmNcolumns, 74,<br />
XmNrows, 20,<br />
NULL);</p>
<p>.<br />
.<br />
.<br />
WriteResultMsg(<br />
Widget w, /* in widget */<br />
const char *msg, /* in msg to write */<br />
bool timeStamp<br />
)<br />
{<br />
XmTextPosition pos;<br />
time_t now;<br />
char timeBuf[40];</p>
<p> // If requested, write the date/time first<br />
if (timeStamp)<br />
{<br />
now = time(NULL);<br />
strftime(timeBuf, sizeof(timeBuf),<br />
"%d %b %Y %H%M%S - ", localtime(&now));</p>
<p> pos = XmTextGetLastPosition(w);<br />
XmTextInsert (w, pos, timeBuf);<br />
}</p>
<p> // Write the message<br />
pos = XmTextGetLastPosition(w);<br />
XmTextInsert (w, pos, (char *)msg);</p>
<p> // Write a trailing <CR><br />
pos = XmTextGetLastPosition(w);<br />
XmTextInsert (w, pos, "<br />
");</p>
<p> // This call should scroll the newly inserted text into view,<br />
// but doesn`t<br />
// printf("Position ->%d<br />
", pos);<br />
XmTextShowPosition(w, pos);<br />
}<br />
Tue, 08/05/2003 - 11:55#1
Anonymous
XmTextShowPosition
You should set XmNscrollingPolicy of your scrolled window to XmAPPLICATION_DEFINED, because XmText handles scrolling.
BTW, why don`t you use XmCreateScrolledText?
-- Yuriy Syrota
Tue, 08/05/2003 - 15:33#2
Anonymous
XmTextShowPosition
Thank you, that worked. Is there any way to get rid of the horizontal scroll bar? It is not needed. I tried setting the XmNscrollBarDisplayPolicy to XmAS_NEEDED, but that didn`t work.
Thanks,
Bob
Tue, 08/05/2003 - 17:02#3
Anonymous
XmTextShowPosition
Thank you, that worked. Is there any way to get rid of the horizontal scroll bar? It is not needed. I tried setting the XmNscrollBarDisplayPolicy to XmAS_NEEDED, but that didn`t work.
Thanks,
Bob
Tue, 08/05/2003 - 18:27#4
Anonymous
XmTextShowPosition
When you create the scrolled text, set XmNscrollHorizontal to False.
Note that this cannot be done after the widget is created.