maner@bgsuvax.UUCP (Walter Maner) (04/01/89)
Two of my students would appreciate adivce on a problem they describe as follows: "We are working on a desk accessory that will speak the menu choice on a mouse event. I would like to know how to get the English text of the menu and the menu choice (whichever the cursor was over) on mouseDOWN. "Secondly, my DA does not have a window. Thus I would like to close the DA with the appropriate choice from the menu the DA creates. I've tried to call my Close(Device) routine, when that menu item was chosen, but that did not work. What will work?" Thanks for the help. WALT -- CSNet : maner@research1.bgsu.edu | 419/372-8719 InterNet: maner@research1.bgsu.edu (129.1.1.2) | BGSU CS Dept UUCP : ... !osu-cis!bgsuvax!maner | Bowling Green, OH 43403 BITNet : MANER@BGSUOPIE
ewing@tramp.Colorado.EDU (EWING DAVID JAMES) (04/01/89)
Walt, in your article you say: >"We are working on a desk accessory that will speak the menu choice on a >mouse event. I would like to know how to get the English text of the menu >and the menu choice (whichever the cursor was over) on mouseDOWN. Getting the text for a menu item is as simple as calling GetItem(). It looks like you have to get a menu's title directly from the MenuInfo record (yuck). See Inside Mac vol I chapter 11. If you actually want to speek the menu item that the mouse is over as it's being tracked through the choices, I'd say you actually have to write an MDEF for this (even yuckier). >"Secondly, my DA does not have a window. Thus I would like to close the DA >with the appropriate choice from the menu the DA creates. I've tried to call >my Close(Device) routine, when that menu item was chosen, but that did not >work. What will work?" You need to call CloseDeskAcc() from your quit routine. (Your close() routine will be called indirectly from this). See Inside Mac vol I, chapt. 14. -dave-
mnkonar@gorby.SRC.Honeywell.COM (Murat N. Konar) (04/01/89)
In article <7826@boulder.Colorado.EDU> ewing@tramp.Colorado.EDU (EWING DAVID JAMES) writes: >Walt, in your article you say: > >>"We are working on a desk accessory that will speak the menu choice on a >>mouse event. I would like to know how to get the English text of the menu >>and the menu choice (whichever the cursor was over) on mouseDOWN. > > >If you actually want to speek the menu item that the mouse is over as it's >being tracked through the choices, I'd say you actually have to write an >MDEF for this (even yuckier). Not true. Sorry for the following vagueness but I don't have my references with me. Here's how you can do it: There is a low memory global that holds a pointer to a routine that gets called whenever there is a menu down. It gets called repeatedly until the mouse is released. (Sorry I can't remember the name or location of this global. Check IM X-Ref) Point this at a routine that examines another low memory global (which I also can't remember the name of) that holds the menuID and item currently highlighted. Using the menu ID and item you can get the item text by calling GetMenuItem. I just remembered: the routine pointer is called MenuHook and I think the menuID and Item global is called MenuChoice. Look 'em up. Standard warnings about the use of lowmwmory globals apply. ____________________________________________________________________ Have a day. :^| Murat N. Konar Honeywell Systems & Research Center, Camden, MN mnkonar@SRC.honeywell.com (internet) {umn-cs,ems,bthpyd}!srcsip!mnkonar(UUCP)
borton@uva.UUCP (Chris Borton) (04/04/89)
In article <19742@srcsip.UUCP> mnkonar@gorby.UUCP (Murat N. Konar) writes: >There is a low memory global that holds a pointer to a routine that gets called >whenever there is a menu down. It gets called repeatedly until the mouse is >released. (Sorry I can't remember the name or location of this global. Check >IM X-Ref) Point this at a routine that examines another low memory global >(which I also can't remember the name of) that holds the menuID and item >currently highlighted. Using the menu ID and item you can get the item >text by calling GetMenuItem. > >I just remembered: the routine pointer is called MenuHook and I think the >menuID and Item global is called MenuChoice. Look 'em up. Standard >warnings about the use of lowmwmory globals apply. Im I-369: MBarHook is the low-mem global for a hook routine to be repeatedly called during a menu. [Note: this is how QuicKeys and others do a pseudo-menu bar via user-items & pop-up menus] TheMenu is the currently highlited menu (word). Note also that there are some changes in Inside Mac V, some of which only apply to the Mac II. For example, on a Mac II you can call MenuChoice() after returning from a MenuSelect() zero to get the *disabled* item the mouse was released over. On a Plus/SE this has to be done directly by looking at the global MenuDisable. I haven't tried it, but what would MenuChoice() do if called on a Plus/SE? Aren't these systems supposed to be compatible :-))) ? Hope this helps a bit... -cbb -- Chris Borton borton%uva@mcvax.{nl,bitnet,uucp} Rotary Scholar & Network Administrator, University of Amsterdam CS
leahy3@apple.com (Frank Leahy) (04/06/89)
In article <3937@bgsuvax.UUCP> maner@bgsuvax.UUCP (Walter Maner) writes: > "We are working on a desk accessory that will speak the menu choice on a > mouse event. I would like to know how to get the English text of the menu > and the menu choice (whichever the cursor was over) on mouseDOWN. There seems to be enough interest in this question that I thought I'd post my answer to the net. The global MenuDisable ($B54) along with a MenuHook does what you want. MenuDisable was originally designed to allow Help systems to determine which item the user had chosen, even if the item was disabled (hence the name). After MenuSelect returns 0,0, you can call MenuDisable to see if 1) the mouse was released outside of the menu and menu bar (MenuDisable=0) 2) the mouse was released in the menu bar (hi word of MenuDisable <> 0) 3) a disabled item had been chosen (both hi and lo words of MenuDisable <> 0) The standard MDEF (supplied by Apple) continuously sets MenuDisable while the menu is down. You can install a MenuHook (very easy to do) that looks at the value of MenuDisable, call GetMHandle(hi word of MenuDisable) to get the menu handle (if <> 0), then GetItem(lo word of MenuDisable) to get the item text (if <> 0). (You may also want to look at whether the item is disabled, and if so speak the item in a different voice). If you are doing this for your own program, and it has all text items, you're ok. Problems occur if you are trying to make this work with either custom MDEF's, e.g. a palette, or with hierarchical menus. Custom MDEF's may not set MenuDisable, and many do not have item text defined for each item in the palette. If the custom MDEF does set MenuDisable, you could use ResEdit to enter text for each item (e.g. white, gray, 50%, black, etc.). The problem with hierarchical menus is that MenuHook is not called while a hierarchical menu is down, because of an oversight on my part when I rewrote the Menu Manager for the MacII. Another way to get both time and information is to write an MDEF "wrapper" that gets called instead of the standard MDEF. (This will require **MANY** more tricks than writing a MenuHook. You should not do this unless you REALLY know what you are doing, including how to get at the correct MDEF's once yours has been called, as well as how to get yours called instead of any other MDEF. Kids don't try this at home!). When your MDEF is called, you will want to do your work during the "Choose Message". Once you do the work, or if it is not the choose message, you must call the real MDEF so that tracking continues properly. In summary, if it's your program, and you don't use hierarchical menus it's very easy. The hard part is trying to handle custom MDEF's, and hierarchical menus. Good luck, Frank Leahy <in a previous life "Mr. Menu Manager"> Apple Computer leahy3@apple.com AppleLink: LEAHY3