Newsgroup: comp.windows.x

 Re: REPOST: Accelerators/Translations
Keywords: Accelerator, case
Organization: Alsys Group, San Diego, CA, USA
Lines: 75

In <>  writes:

>I posted this a while ago and didn't receive one reply, and now we
>have another bug report on the same subject. Can anybody help me out?

The problem is that Motif uses XGrabKey to implement menu accelerators,
and these grabs are specific about which modifiers apply.  Unfortunately,
the specification for XGrabKey doesn't allow AnyModifier to be combined
with other modifiers, which is exactly what would be desired in this case:
"Ctrl Any<Key>q".

>In ORA Vol. 6, in the section on accelerators it says "For information
>on how to specify translation tables see Vol. 4...", this is so you
>know what to put for the XmNaccelerator resource.  If you go to
>Vol. 4 it says, "Likewise, if a modifier is specified, there is
>nothing to prohibit other modifiers from being present as well. For
>example, the translation:
>	Shift<Key>q:	quit
>will take effect even if the Ctrl key is held down at the same time as
>the Shift key .

This is true for accelerators and mnemonics, which are implemented using
event handlers instead of grabs; it's not true for menu accelerators.  If
you're a Motif implementor, I'd suggest lobbying to get the Xlib semantics
changed to support the feature I described above.  Otherwise, change the
documentation for menu accelerators to properly set the user's
expectations, because menu accelerators are NOT the same thing as
translations.

>Is it possible to supply > 1 accelerator for a menu entry?

If you mean "menu accelerator", no it's not possible.  That's according to
the definition of the XmNaccelerator resource in the XmLabel manual page.

>Keep in mind when answering this question that when using Motif you
>can't use XtInstallAccelerators.

I can't think of a reason why not.

>How can you ensure that accelerators work the same independent of
>case?  What I want is Ctrl+O and Ctrl+o to both be accelerators on one
>menu entry.

There is a workaround for Motif users.  In addition to the normal menu
accelerator you install on the XmPushButton[Gadget], set an XtNaccelerators
resource on the shell .  Install the shell's
accelerators on itself and all of its descendants with
XtInstallAllAccelerators .

For example,

  applicationShell - mainWindow - menuBar - fileCascade
					  -- filePulldown - openPushbutton
							  - exitPushbutton

  *openPushbutton.accelerator = Ctrl<Key>O
  *openPushbutton.acceleratorText = Ctrl+O
  *exitPushbutton.accelerator = Ctrl<Key>Q
  *exitPushbutton.acceleratorText = Ctrl+Q

  *applicationShell.accelerators = #override\n\
    Ctrl<Key>O: PerformAction\n\
    Ctrl<Key>Q: PerformAction

You have to write and add the application action PerformAction, which you
can implement by using XtNameToWidget on the first argument and then
XtCallActionProc with the rest of the arguments.

I tested out something similar to this.  To shorten development time, I
used TeleUSE's TuNinstallAccelerators resource to install the accelerators
on the shell, and I directly invoked the Open and Quit D actions instead
of asking the pushbuttons to do it for me, but the more general approach I
described above should work.

-- Trevor Bourget