@begin(header)
author: ackerman=ag@.ics.uci.edu
show_author: ShowNone
author_organization: Harvard X Class
node_expert: ackerman=ag@ics.uci.edu 
expiration_date: 11/25/93
last_modifier: ackerman=ag@.ics.uci.edu
last_mod_date: 11/25/91
mod_num: 1
@end(header)
---------------------
The Motif Text Widget
---------------------

@begin(Q)
Why does  pressing  <return> in a text widget do nothing?  This
happens using Motif 1.0 when I have a text widget inside a
bulletin board (or form) inside a dialog shell.  (In Motif 1.1 it
is fixed for both text and list widgets.)
@end(Q)

@begin(A)
In single line mode, pressing the <return> key usually invokes
the activate() action, and in multi-line mode, the newline()
action.  However, whenever a widget is the child of a bulletin
board widget which is the child of a dialog shell, the bulletin
board forces all of its children to translate <return> to the
bulletin board action Return() which is usually associated with
the default button of the dialog.  To restore the text actions of
activate() or newline(), you need to overide the Return() action
of the bulletin board.


        /* declarations */
        /* for a single line widget */
        char newTrans[] = "<Key>Return : activate()";
        /* for a multi line widget */
        char newTrans[] = "<Key>Return : newline()";
        XtTranslations transTable;

        /* in executable section */

        transTable = XtParseTranslationTable(newTrans);

       /* after creating but before managing text widget */

      XtOverrideTranslations(textWidget, transTable);

				Motif FAQ 8/12/91
@end(A)

@begin(Q)
When I add text to a scrolling text widget how can I get the new
text to show?
@end(Q)

@begin(A)
Use the call undocumented in Motif 1.0

        void XmTextShowPosition(w, position)
        Widget w;
        XmTextPosition position;

where the position is the number of characters from the beginning
of the buffer of the text to be displayed. If you don't know how
many characters are in the buffer, use another call undocumented
in Motif 1.0

        position = XmTextGetLastPosition(w)

				Motif FAQ 8/12/91
@end(A)

@begin(Q)
Does the text widget support 16 bit character fonts?
@end(Q)

@begin(A)
Answer: R5 will have support for 16 bit character sets, and Motif 1.2 will use
that. You will have to wait until then.

				Motif FAQ 8/12/91
@end(A)

@begin(Q)
How can I stop the text widget from echoing characters typed?  I
need to turn off echo for password input.
@end(Q)

@begin(A)
Use the modifyVerifyCallback to tell when input is
received. Set the `doit' field in the XmTextVerifyCallbackStruct
to False to stop the echo. In Motif 1.0 this will cause a beep
per character: Live with it, because at 1.1 you can turn it off. 
Note that password hiding is inherently insecure in X - someone
may have an X grab on the keyboard and be reading all characters
typed in anyway.

Another solution often proposed is to set the foreground and
background colours to be the same, effectively hiding the text. 
This has a major flaw: someone may select the text (triple click
the mouse to get the line), and then paste the password into say
an xterm with *different* foreground and background colours. 
This immediately shows the password.

				Motif FAQ 8/12/91
@end(A)

@begin(Q)
How can I replace characters typed with say a `*'?  I want to
replace input for password entry.
@end(Q)

@begin(A)
In Motif 1.1 set text->ptr in the callback structure to '*'. 
This does not work under 1.0 because of an oversight in which
changes to this are ignored.  In Motif 1.0, what you can do is
set the doit flag to 'false' so the text is not displayed. Then
set a static boolean to True to prevent re-entrance.  Next call
XmTextReplace() to display your '*'.  then reset your re-entrance
flag to False.  XmTextReplace() will call the XmNmodifyVerify
callback.  To prevent getting into an infinite loop, you need the
re-entrance flag.

				Motif FAQ 8/12/91
@end(A)

@begin(Q)
How can I best add a large piece of text to a scrolled text
widget? It insists on adding the text one line at a time,
adjusting the scroll bar each time. It looks awful and is slow.
@end(Q)

@begin(A)
Unmanage the widget, add the text and then manage it again.

				Motif FAQ 8/12/91
@end(A)

@begin(Q)
How can I highlight text in the Text widget?
@end(Q)

@begin(A)
From: argv@zipcode.com (Dan Heller)

If you don't need font or color changes, you can do all this
using a Text widget very easily [in Motif 1.1, anyway].

        loop() {
            pos = offset_of_pattern_in_text_widget(pattern, text_w);
            search_len = strlen(pattern);
            XmTextSetHighlight(text_w, pos, pos+search_len,
                        XmHIGHLIGHT_SELECTED);
        }


There are two choices for highlighting: reverse video
(HIGHLIGHT_SELECTED) and underlined
(HIGHLIGHT_SECONDARY_SELECTED).  Be careful that your users won't
confuse your highlights with actual selections!

				Motif FAQ 8/12/91
@end(A)

@begin(Q)
How can I select all of the text in a widget programmatically? 
So that some initial text is displayed, but anything typed
replaces it.
@end(Q)

@begin(A)
XmTextSetSelection(Text1, 0, XmTextGetLastPosition(Text1), 
		  event->xbutton.time);

where Text1 is the widget in question (obviously) and event is
some event that triggered this call.

				Motif FAQ 8/12/91
@end(A)


@begin(Q)
How can I change colours of text in the Text widget?  I want some
of the text in one colour, some in another.
@end(Q)

@begin(A)
You can't.  Text stores an ordinary string, and points where
`highlights' of various types begin and end.  These highlights
are all the control you have over components of the text.  See
the previous question.

				Motif FAQ 8/12/91
@end(A)

@begin(Q)
How can I change the font of text in the Text widget?  I want some
of the text in one font, some in another.
@end(Q)

@begin(A)
You can't in Text (see the previous question).  If you wanted
readonly text, you could do it by using a label instead.  Label
uses XmStrings, which can contain multiple character sets in the
one string.

        Ctrl <Key>y:            unkill()\n\
        Ctrl <Key>k:            kill-to-end-of-line()\n\
        Alt <Key>Delete:        kill-to-start-of-line()\n\
        Meta <Key>Delete:       kill-to-start-of-line()\n\
        Ctrl <Key>o:            newline-and-backup()\n\
        Ctrl <Key>j:            newline-and-indent()\n\
        Ctrl <Key>n:            next-line()\n\
        Ctrl <Key>osfLeft:      page-left()\n\
        Ctrl <Key>osfRight:     page-right()\n\
        Ctrl <Key>p:            previous-line()\n\
        Ctrl <Key>g:            process-cancel()\n\
        Ctrl <Key>l:            redraw-display()\n\
        Ctrl <Key>osfDown:      next-page()\n\
        Ctrl <Key>osfUp:        previous-page()\n\
        Ctrl <Key>space:        set-anchor()\n

!       Shift Alt <Key>n:       forward-paragraph(extend)\n\
!       Shift Meta <Key>n:      forward-paragraph(extend)\n\
!       Shift Alt <Key>f:       forward-word(extend)\n\
!       Shift Meta <Key>f:      forward-word(extend)\n\
!       Alt <Key>d:             kill-next-word()\n\
!       Meta <Key>d:            kill-next-word()\n\
!       Alt <Key>h:             select-all()\n\
!       Meta <Key>h:            select-all()\n\

Similar sets of translations have been suggested by others.

				Motif FAQ 8/12/91
@end(A)

@begin(Q)
How can I use a file as the text source for a Text widget?
@end(Q)

@begin(A)
You can't do it directly like you can with the Athena Text
widget.  Instead, read the text from the file into a string (all
of it!) and then use XmTextSetString.  Alternatively, read blocks
of characters and add them at the end of the text using
XmTextInsertString.

				Motif FAQ 8/12/91
@end(A)


@begin(Q)
How can put Text in overstrike mode instead of insert?
@end(Q)

@begin(A)
There is no direct way. This was posted by Edmond Pitt
(ejp@bohra.cpg.oz) The correct answer to the question is to put
the following in a modifyVerify callback, where 'mvcb' is the
XmTextVerifyCallbackStruct, and 'overstriking' is defined by you:

    if (overstriking && mvcb->text->length == 1)
    {
        _XmTextDisableRedisplay(w,FALSE);
        XtCallActionProc(w,"delete-next-character",mvcb->event,0);
        _XmTextEnableRedisplay(w);
    }

_XmText{Dis,En}ableRedisplay() are XmText{Dis,En}ableRedisplay()
in 1.0, but X11R3 has no XtCallActionProc() anyway. For this
environment you need my 1.0.3 Text widget patches posted last
year & available on request.

				Motif FAQ 8/12/91
@end(A)

@begin(Q)
How can make the Delete key do a backspace?
@end(Q)

@begin(A)
Answer: Put this in your .Xdefaults

   *XmText.translations: #override <Key>osfDelete: delete-previous
@end(A)
