Path: utzoo!attcan!uunet!cs.utexas.edu!sun-barr!olivea!samsung!zaphod.mps.ohio-state.edu!wuarchive!udel!haven!adm!cmcl2!phri!marob!slhisc!sky!jerry From: jerry@slhisc.uucp (Jerry Liebelson) Newsgroups: comp.windows.x.motif Subject: Re: Accelerators Message-ID: Date: 26 Oct 90 14:50:29 GMT References: <27685@usc.edu> Sender: jerry@slhisc.uucp (Jerry Liebelson) Organization: Shearson Lehman Brothers, Inc. (ISC) Lines: 59 In-Reply-To: curtz@skat.usc.edu's message of 24 Oct 90 09:15:05 GMT *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 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.