[comp.windows.x.motif] Need help with accelerator

gjf00@duts.ccc.amdahl.com (Gordon Freedman) (03/28/91)

I am trying to use accelerators in my Motif application and cannot get them
to work at all. I'm running ICS-motif version 1.1 on a Sun Sparc with MIT
X11R4. 

I am trying to define accelerators for the function keys on the Sun keyboard.
I have successfully installed translations for them within a specific widget
from the resource file:

*memAddrLogical*translations:   #override\n\
    <Key>Return:        memAddrReturn()\n\
    <Key>osfRight:      memAddrRight()\n\
    <Key>osfLeft:       memAddrLeft()\n\
    <Key>osfBackSpace:  memAddrLeft()\n\
    <Key>F1:memAddrInit(00000000)\
            memAddrDisp()\n\
    <Key>F3:memAddrInit(0000f000)\
            memAddrStack(00000020)\
    <Key>:  memAddrKey()\n\
    <Btn3Down>,<Btn3Up>:extend-adjust()\n\
    <Btn2Down>,<Btn2Up>:memAddrPaste()

This works as advertised, although the user has to have the mouse pointer in
the memAddrLogical widget for the F1 and F3 keys to take effect. I want to
set things up so the user can enter these keys from anywhere in the window.
The Motif programmer's reference indicates that widgets with translations
in them will not propogate accelerators, so I took all of the translations
out of my widgets, and put them into an accelerator resource for the text
widget. I seem to remember hearing somewhere that acclerators only work for
buttons, so I also tried setting the accelerator resource for a button which
was not managed. Neither of these worked at all, I was not getting into the
action routines, and it appeared that the acclerator events were being ignored.
I even tried managing the button, to no avail.

I am doing an XtInstallAllAccelerators (memBigForm, memBigForm), where
memBigForm is near the top of the widget heierarchy, and both the unmanaged
button and the text widget are descendants of memBigForm.  I then put the
following in my resource file (and removed memAddrLogical*translations):

*memAddrLogical*accelerators:   #override\n\
    <Key>Return:        memAddrReturn()\n\
    <Key>osfRight:      memAddrRight()\n\
    <Key>osfLeft:       memAddrLeft()\n\
    <Key>osfBackSpace:  memAddrLeft()\n\
    <Key>F1:memAddrInit(00000000)\
            memAddrDisp()\n\
    <Key>F3:memAddrInit(0000f000)\
            memAddrStack(00000020)\
    <Key>:  memAddrKey()\n\
    <Btn3Down>,<Btn3Up>:extend-adjust()\n\
    <Btn2Down>,<Btn2Up>:memAddrPaste()

This doesn't work, nor does specifying the same thing for the accelerators
resource for the button. 

I have been able to successfully use the accelerator (no s) resource for
pushbuttons, so it looks like the XtInstallAllAccelerators works. I've also
gotten accelerators to work in an Xt application once before, so I'm
reasonably sure I'm doing it right. Any help would be much appreciated.


--
Gordon Freedman: gjf00@duts.ccc.amdahl.com
Disclaimer: My opinions! Not my employers!

nazgul@alfalfa.com (Kee Hinckley) (03/28/91)

> The Motif programmer's reference indicates that widgets with translations
> in them will not propogate accelerators, so I took all of the translations
That could explain alot, given that Motif installs translations on most
everything to do keyboard traversal.

Anyway.  Try recursing the widget tree and installing the accelerator on
every single widget.  That seems to work some of the time.  Otherwise
there's not much hope, although someone has posted a patch to Motif which
may help some.


Alfalfa Software, Inc.          |       Poste:  The EMail for Unix
nazgul@alfalfa.com              |       Send Anything... Anywhere
617/646-7703 (voice/fax)        |       info@alfalfa.com

I'm not sure which upsets me more: that people are so unwilling to accept
responsibility for their own actions, or that they are so eager to regulate
everyone else's.