[comp.windows.x.motif] Accelerators

curtz@skat.usc.edu (Curtz Lam) (10/24/90)

	I am trying to use accelerators to activate some push bottons
from anywhere within my application.  I installed the accelarators with
XtInstallAccelerators and specfied them as resources for the
particular push button widgets, but nothing seems to happen.  Is there
anyone successful in using accelerators or is there a way to get
around it?  Please help.

							Curtz

argv@turnpike.Eng.Sun.COM (Dan Heller) (10/26/90)

In article <27685@usc.edu> curtz@skat.usc.edu (Curtz Lam) writes:
> 	I am trying to use accelerators to activate some push bottons
> from anywhere within my application.  I installed the accelarators with
> XtInstallAccelerators and specfied them as resources for the
> particular push button widgets, but nothing seems to happen.

As I understand it, you cannot use the default Xt accelerator stuff
in Motif applications because it completely takes over that area in
its effort to process keyboard terversal, menus, and its own accelerators.
I haven't tried real hard, but the basic stuff didn't work for me
either.  I simply just "gave in" and used the Motif accelerator
machanism.  I'm not saying it's impossible --just that it's not
straightforward.  I can't say anything definitive--someone from OSF
should do that.
--
dan
----------------------------------------------------
O'Reilly && Associates   argv@sun.com / argv@ora.com
Opinions expressed reflect those of the author only.

jerry@slhisc.uucp (Jerry Liebelson) (10/26/90)

*SEND REPLIES TO: uunet!slcpi!slhisc!jerry
Organization: Shearson Lehman Brothers, Inc.
------------------------------------------------------------------------------
>	I am trying to use accelerators to activate some push bottons
>from anywhere within my application.  I installed the accelarators with
>XtInstallAccelerators and specfied them as resources for the
>particular push button widgets, but nothing seems to happen.  Is there
>anyone successful in using accelerators or is there a way to get
>around it?  Please help.

I have been somewhat successful in getting the accelerators in Motif to
work. I recommend reading Volume 4 of O'Reilly pp. 205-211.

Basically, the technique that I used was to set an accelerator table for
the widget that does the action.  Then, call XtInstallAllAccelerators()
for all widgets that get input focus, specifying the focus widget and the
topLevel widget.

For example, say you have a window containing a QUIT button, and a few text
fields. Say you want the button to be activated by a F12 from anywhere
within the window:

1. Define the accelerator string:

     static String AcceleratorArray[]=
     {
       "#override <KeyPress>F12: ArmAndActivate()",	/* QUIT_BUTTON */
     };

2. Parse the accelerator string into table-form and use it to set the
   XmNaccelerators resource for the QUIT button widget.

	i=0;
	XtSetArg (argList[i], XmNaccelerators,
		XtParseAcceleratorTable(AcceleratorArray[0])); i++;
	XtSetValues (quitButtonWidget, argList, i);

3.  Then call InstallAllAccelerators for all widgets that might get
    keyboard focus (even other buttons):  
  
     XtInstallAllAccelerators(nameTextWidget, TopLevel);
     XtInstallAllAccelerators(addressTextWidget, TopLevel);
     XtInstallAllAccelerators(updateButtonWidget, TopLevel);
     
    What XtInstallAllAccelerators() does is to descend down the widget
hierarchy of the second argument (TopLevel), finding all widgets that
have accelerator resources and making these accelerators active whenever the
first argument widget has keyboard focus.

Yes, it's rather tedious and if there's a better way I'd like to know.
But this does work.
--
         Jerry Liebelson                   uunet!slcpi!slhisc!jerry   
    Distributed Infrastructure             (212) 341-3166  FAX: (212) 528-0101
   Shearson Lehman Brothers, Inc.         
--
         Jerry Liebelson                   uunet!slcpi!slhisc!jerry   
    Distributed Infrastructure             (212) 341-3166  FAX: (212) 528-0101
   Shearson Lehman Brothers, Inc.