[comp.windows.x.motif] auto-traverse of text widgets

rroux@rigel.sdd.trw.com (04/10/91)

I'm stumped.  I have a bulletinboard widget that contains two single line
text widgets and a couple labels.  I want to be able to press <Return> 
in one of the text widgets and have the focus automatically shift to the
other text widget.

I tried using XtSetKeyboardFocus with limited success.  The focus _does_
change, but the text cursor in the first widget keeps blinking.  It seems
that there is confusion between the program and the window manager as to
which widget really has the focus.

Is there a better/another way?  By the way, I'm using Motif 1.0.3 and the
X11R3 libraries, but running X11R4.

Thanks,
  Ray Roux
    rroux@rigel.sdd.trw.com

rich@aftac1.llnl.gov (Rich Mayfield) (04/16/91)

I just got through with this same problem (i.e. my I-bars didn't go where
I set the keyboard focus) - instead of using the XtSetKeyboardFocus
call, the FAQ directs Motif 1.0 users to the undocumented _XmGrabTheFocus:

_XmGrabTheFocus(widget);   /* where widget is to get the keyboard focus */

If and when you go to Motif 1.1 as I just have, a new function is added
called XmProcessTraversal.  From what I here its had some problems but
its worked for me pretty well so far.

---------------------------------------+--------------------------------
Rich Mayfield                          | rich@aracsunny.llnl.gov
who works at but does not represent    |
Lawrence Livermore National Laboratory |

dvb@emisle.uucp (David Van Beveren) (04/20/91)

In article <2801F4F9.5C0D@deneva.sdd.trw.com> rroux@rigel.sdd.trw.com () writes:
>
>I'm stumped.  I have a bulletinboard widget that contains two single line
>text widgets and a couple labels.  I want to be able to press <Return> 
>in one of the text widgets and have the focus automatically shift to the
>other text widget.
>
>I tried using XtSetKeyboardFocus with limited success.  The focus _does_
>change, but the text cursor in the first widget keeps blinking.  It seems
>that there is confusion between the program and the window manager as to
>which widget really has the focus.

Motif and XtSetKeyboardFocus indeed do not cooperate. OSF tells you not to
use them together, and in X11R4 provides a set of routines to do what you 
need (XmProcessTraversal, XmAdd(Remove)TabGroup). This is one of the major
improvements of Motif 1.1 over Motif 1.0.

>
>Is there a better/another way?  By the way, I'm using Motif 1.0.3 and the
>X11R3 libraries, but running X11R4.
>

I assume this means you are running on an X11R4 server? My advice is to pursue
X11R4 and Motif 1.1 aggressively. It is really quite an improvement. Both in
features and bug fixes.

>Thanks,
>  Ray Roux
>    rroux@rigel.sdd.trw.com


-- 
David Van Beveren                           INTERNET: emisle!dvb@ism.isc.com
EIS ltd. Professional Software Services     UUCP:   ..uunet!emisle!dvb
voice: (818) 587-1247

pjp@sloth.mlb.semi.harris.com (Pat J. Pinchera) (05/07/91)

In article <2801F4F9.5C0D@deneva.sdd.trw.com> rroux@rigel.sdd.trw.com () writes:
>
>I'm stumped.  I have a bulletinboard widget that contains two single line
>text widgets and a couple labels.  I want to be able to press <Return> 
>in one of the text widgets and have the focus automatically shift to the
>other text widget.
>
>I tried using XtSetKeyboardFocus with limited success.  The focus _does_
>change, but the text cursor in the first widget keeps blinking.  It seems
>that there is confusion between the program and the window manager as to
>which widget really has the focus.
>
>Is there a better/another way?  By the way, I'm using Motif 1.0.3 and the
>X11R3 libraries, but running X11R4.
>


I had to add the widget(s) to a tab group so that a regular
<Tab> would make the cursor move between the text fields. Then I had to
make the <Return> look like a <Tab> to Motif; this is done with 
XtOverrideTranslations.

Here is a code excerpt:

        /*
	** make the text widgets part of a 'Tab Group' so that user
	** can tab between text fields. See PG9-3, PG1-6, PR1-163
	** PG = Motif Programmer's Guide, v1.0, 
	** PR = Motif Programmer's Reference, v1.0
	*/
	XmAddTabGroup ( widget );
						       
        /*
        ** make <Return>, Down-Arrow act like a Tab;
        ** make Up-Arrow act like a Shift-Tab (back tab)
        */
        XtOverrideTranslations(widget, XtParseTranslationTable
                                    ("<Key>Return:next-tab-group()\n\
                                      <Key>Down:next-tab-group()  \n\
                                      <Key>Up:prev-tab-group()"));

I had  heard of these two functions, XmAddTabGroup & XtOverrideTranslations,
but never thought of where/when they could be used, and if I did, I surely
didn't know exactly how to code them, i.e. syntax and such.
When I got these examples from someone on the net, it became obvious.
Now I wonder how many other 'amazing' feats can be accomplished with Motif!!!
-- 
---------------------------------------------------------------------
  Patrick J. Pinchera            |  Interface & Control Systems, Inc.
  pjp@sloth.mlb.semi.harris.com  |  Melbourne, Florida, USA
---------------------------------------------------------------------