TweetFollow Us on Twitter

Window Menus
Volume Number:4
Issue Number:11
Column Tag:Programmer's Workshop

Menus In Windows

By James Matthews, Hanover, NH

[Jim Matthews is a software developer at Dartmouth, working on network applications. He has done maintenance work on DarTerminal, an AppleTalk terminal emulator, and has worked on developing a Macintosh mail system. He started programming in high school on an IBM 360 with core memory but slowly moved to smaller, newer machines. In college, he helped develop MacFunction, a three-dimensional graphing program that is currently marketed by True Basic, Inc.]

Menus in Windows

by Jim Matthews, Dartmouth College

One of the critical elements of the Macintosh user interface is the menu bar. It relieves the user of the need for memorizing command names and gives easy access to a large number of operations in a small amount of space. Nonetheless, the limitations of the standard Macintosh menu bar have become increasingly evident. Large screens make the fixed position of the menu bar less convenient, and large programs present users with an overwhelming number of available commands. Desk accessories have never been able to use the menu bar fully, limiting their potential. Both Apple and third parties have developed workarounds to the limitations of the menu bar. Hierarchical and pop-up menus, implemented in System 4.1, provide alternate ways of structuring menu commands. The tear-off palettes used in HyperCard and MacPaint 2.0 add a new dimension to menus, as do the tear-off menus provided with Radius displays.

Still, I recently felt the need to extend the menu bar concept by another step. While developing a program with a large number of commands, I decided that what I wanted was a different menu bar for each window. It would have been possible to change the menu bar depending on which window was in front, but the commands needed by each window were so different that the user would never know what to expect when he pulled down a menu. Furthermore, I wanted to leave open the possibility of turning the program into a desk accessory, and I could not fit all my commands into one menu. So I re-implemented part of the Menu Manager to provide for window-specific menu bars. The code itself is not very complicated -- I was fortunate to be preceded by Mike Schuster, whose December, 1985 article on pop-up menus provided a wealth of useful information. The routines I produced met my needs admirably, but like any extension to the standard interface they also raised some tricky issues.

Figure 1. Edit Menu

The wMenu Manager Routines

Because I wanted to produce menu bars that function exactly like the one at the top of the screen, I implemented the window menus by imitating eight standard Menu Manager routines. They all operate on a wMenuBar data structure which is roughly comparable to a MenuList.

type 
wMenuRec = record
 mh : MenuHandle;
 titleRect : Rect;
   end;
wMenuBar = record
 numMenus : integer;
 hilited : integer;
 gp : GrafPtr;
 wMenus : array [0..0] of wMenuRec;
   end;

The wMenuBar stores the number of menus in a menu bar, which one is hilited (if any), and the GrafPort in which the menu bar is drawn. In addition, it stores a menu handle and a rectangle for each menu that has been inserted. The rectangle specifies the coordinates of the menu title; i.e. the area that is inverted when a menu is selected. This is a bit wasteful, since two of the rectangle’s coordinates are always the same, but it makes the code simpler. The wMenuBar record is created by a call to wInitMenus, which allocates the storage and returns a wMenuBarHandle. The rest of the routines accept the same arguments as their Menu Manager equivalents, with the addition of a wMenuBarHandle to specify the menu bar being altered. The routines are wInsertMenu and wDeleteMenu, to add and remove menus from the menu bar; wClearMenuBar to delete all the menus; wDrawMenuBar to redraw the menu bar; wMenuSelect and wMenuKey to respond to mouse and key events, respectively; and finally, wHiliteMenu to highlight a menu’s title.

Implementation Issues

There are a few subtle points in the implementation of the wMenu Manager. The System 4.2 menu definition procedure has a bug that is fixed by initializing the low memory global TopMenuItem in wInitMenus. Calls to the menu definition procedure are implemented using inline machine code, since Pascal doesn’t provide a standard way to call a routine based on its address. WMenuKey walks down a menu’s data looking for a certain command key equivalent, and the dynamic nature of the data structure requires some ugly code. GetNextEvent and SystemTask are called in the inner loop of the menu selection code: this means that keyDown events are swallowed while the user is holding down a menu, but it provides the ability to produce screen dumps and keeps desk accessories updated. With the standard menu bar it is impossible for the user to drag the mouse above the top of the menus, but with window menus it was necessary to deal with this case. I decided to have the displayed menu disappear when the user moved the mouse above a window’s content region, but that could easily be changed.

The wMenu routines can be substituted for Menu Manager ones with a few exceptions. Unlike InitMenus, wInitMenus must not be called until there is a window to put the menu bar in. wDrawMenuBar should be called in response to update events, since the Window Manager considers the menu bar part of a window’s content region. This also means that wMenuSelect should be called in response to mouseDown events in a window’s content region. A program should continue call MenuSelect and MenuKey at appropriate times to give the user access to desk accessory menus.

The wMenu routines make it fairly easy to implement a number of different menu bars in one program, but that can lead to an explosion of possible commands. The nested case statements that typically handle menu commands can become unwieldy when the number of menu bars exceeds two or three.

Interface Issues

Menus in windows have the significant disadvantage of being a departure from the standard way of doing things. Users do not expect to find a menu bar inside a window, and can be confused by one. If there is more than one menu bar visible the user may wonder which to use, and if the user types a command key equivalent it may not be clear which menu bar is handling it. This problem becomes especially difficult when some commands are available from the regular menu bar and others only from window menus. I have tried to use window menus for commands that only affect that particular window, and the regular menu bar for program-wide operations. This introduces a degree of modality into a program, but not much more than is present in any multiple-window application.

Figure 2. Scrolling Menus

Compatibility Issues

The wMenu routines were written to be compatible with all post Mac 512 models. The 128k ROM calls HSetState and HGetState are used in a few places; but if they were changed, I imagine the code would work on older Macs also. Given Apple’s emphasis on the sanctity of the Window Manager’s GrafPort, care was taken to make sure that menus are only drawn inside an application window’s content region if they overlap they either scroll or are cropped. There are a couple of things that could cause future compatibility problems, though. First, the program modifies TopMenuItem, and although the fix was made on the advice of Mac DTS, it could break on future systems. Secondly, Apple is now asking programmers not to rely on the internal structure of menu records. The wMenuKey routine could not be written without doing this, so it is vulnerable to future changes. The code emulates the pre-Mac SE Menu Manager in that color and hierarchical menus are not supported. The code has been tested on machines from the 512KE to the Mac II without mishap.

Figure 3. Project Window

wSample

I have included a wMenu version of the sample program found in Inside Macintosh Vol. I. This example illustrates how the wMenu routines are called and demonstrates how the menus appear to the user. It is not, however, a case where window menus add much to the program. Window menus are much more appropriate when there are multiple windows, each with significantly different functionality. I originally implemented them as part a mail program that had separate windows for composing letters, reading mail, and organizing a mailbox. In that case, window menus let me compartmentalize the program’s interface and use a large number of commands without overwhelming the standard menu bar.

{ wMenu Manager }
{ by Jim Matthews }

UNIT wMenu;

INTERFACE

 USES
 ROM85; { uses HGetState and HSetState }

 CONST
 mBarHeight = 20;
 betweenTitles = 15; 
{ # of pixels between adjacent menu titles }
 invertOverlap = 10; 
{ # of pixels to invert on each side of a menu title }
 noneHilited = -1; 
{ value to store in wMenuBar.hilited if nothing hilited }
 menuTitleBit = 31;
{ mac-style bit offset for menu title bit in enableFlags }

 TYPE
 wMenuRec = RECORD
 mh : MenuHandle;
 titleRect : Rect;
 END;
 wMenuBar = RECORD
 numMenus : integer;
 hilited : integer;
 gp : GrafPtr;
 wMenus : ARRAY[0..0] OF wMenuRec;
 END;
 wMenuBarPtr = ^wMenuBar;
 wMenuBarHandle = ^wMenuBarPtr;

 FUNCTION wInitMenus (gp : GrafPtr) : wMenuBarHandle;
 PROCEDURE wInsertMenu (theMenuBar : wMenuBarHandle;
 theMenu : MenuHandle;
 beforeID : integer);
 PROCEDURE wDrawMenuBar (theMenuBar : wMenuBarHandle);
 PROCEDURE wDeleteMenu (theMenuBar : wMenuBarHandle;
 menuID : integer);
 PROCEDURE wClearMenuBar (theMenuBar : wMenuBarHandle);

 FUNCTION wMenuSelect (theMenuBar : wMenuBarHandle;
 startPt : Point) : longint;
 FUNCTION wMenuKey (theMenuBar : wMenuBarHandle;
 ch : char) : longint;
 PROCEDURE wHiliteMenu (theMenuBar : wMenuBarHandle;
 menuID : integer);

IMPLEMENTATION

{wInitMenus -- create a wMenuBar and associate it with a grafport}
 FUNCTION wInitMenus;     { (gp : GrafPtr) : wMenuBarHandle; }
 TYPE
 intptr = ^Integer;
 VAR
 mbar : wMenuBarHandle;
 TopMenuItemP : intptr;
 BEGIN
 { Set low-mem global to fix menu display bug }
 TopMenuItemP := intptr($A0A);
 TopMenuItemP^ := mBarHeight;

 mbar := wMenuBarHandle(NewHandle(sizeof(wMenuBar)));
 mbar^^.numMenus := 0;
 mbar^^.hilited := noneHilited;
 mbar^^.gp := gp;
 wInitMenus := mbar;
 END; { wInitMenus }

{wInsertMenu -- insert a menu into a defined wMenuBar,}
{ analogous to InsertMenu }
 PROCEDURE wInsertMenu;   { (theMenuBar : wMenuBarHandle; }
 { theMenu : MenuHandle; }
 { beforeID : integer); }
 VAR
 newSize : Size;
 r : Rect;
 i, j : integer;
 titleWidth, oldSize, oldFont : integer;
 BEGIN
 newSize := sizeof(wMenuBar) + theMenuBar^^.numMenus * sizeof(wMenuRec);
 IF newSize > GetHandleSize(handle(theMenuBar)) THEN
 SetHandleSize(handle(theMenuBar), newSize);
 IF MemError = noErr THEN
 BEGIN
 oldSize := thePort^.txSize;
 oldFont := thePort^.txFont;
 TextSize(12);
 TextFont(systemFont);
 titleWidth := StringWidth(theMenu^^.menuData);
 TextSize(oldSize);
 TextFont(oldFont);
 i := 0;
 IF beforeID > 0 THEN
 { Insert the menu before a particular one? }
 BEGIN
 i := 0;
 WHILE (theMenuBar^^.wMenus[i].mh^^.menuID <> beforeID) AND (i < theMenuBar^^.numMenus) 
DO
 i := i + 1;
 IF i <> theMenuBar^^.numMenus THEN
 BEGIN
 FOR j := theMenuBar^^.numMenus DOWNTO i + 1 DO
 BEGIN
 theMenuBar^^.wMenus[j].mh := theMenuBar^^.wMenus[j - 1].mh;
 theMenuBar^^.wMenus[j].titleRect := theMenuBar^^.wMenus[j - 1].titleRect;
 OffsetRect(theMenuBar^^.wMenus[j].titleRect, titleWidth + betweenTitles, 
0);
 END; { for loop -- copying menus back }
 END; { if there’s a menu id = beforeID }
 END { if beforeID <> 0 }
 ELSE   { if beforeID <= 0, put it after the rest }
 i := theMenuBar^^.numMenus;
 WITH theMenuBar^^.wMenus[i] DO
 BEGIN
 titleRect.top := 1;
 titleRect.bottom := mBarHeight - 1;
 IF i = 0 THEN
 titleRect.left := betweenTItles - invertOverlap
 ELSE
 titleRect.left := theMenuBar^^.wMenus[i - 1].titleRect.right + betweenTitles 
- 2 * invertOverlap;
 titleRect.right := titleRect.left + titleWidth + 2 * invertOverlap;
 mh := theMenu;
 END; { with theMenuBar^^.wMenus[i] }
 theMenuBar^^.numMenus := theMenuBar^^.numMenus + 1;
 END; { no MemError }
 END; { wInsertMenu }

{ wDrawMenuBar -- draw the wMenuBar, with appropriate}
{ highlighting }
 PROCEDURE wDrawMenuBar;  { (theMenuBar : wMenuBarHandle); }
 VAR
 i : integer;
 r : Rect;
 oldPort : GrafPtr;
 oldSize, oldFont, oldMode : integer;
 oldStyle : Style;
 bmap, oldMap : BitMap;
 BEGIN
 GetPort(oldPort);
 SetPort(theMenuBar^^.gp);
 oldSize := thePort^.txSize;
 oldFont := thePort^.txFont;
 oldMode := thePort^.txMode;
 oldStyle := thePort^.txFace;
 TextSize(12);
 TextFont(systemFont);
 TextMode(srcOr);
 TextFace([]);

 SetRect(r, 0, 0, 10000, mBarHeight);
 EraseRect(r);
 MoveTo(0, mBarHeight - 1);
 Line(10000, 0);

 FOR i := 0 TO theMenuBar^^.numMenus - 1 DO
 BEGIN
 MoveTo(theMenuBar^^.wMenus[i].titleRect.left + invertOverlap, mBarHeight 
- 5);
 DrawString(theMenuBar^^.wMenus[i].mh^^.menuData);

 { gray-out disabled menu titles }
 IF NOT BitTst(@theMenuBar^^.wMenus[i].mh^^.enableFlags, menuTitleBit) 
THEN
 BEGIN
 r := theMenuBar^^.wMenus[i].titleRect;
 r.left := r.left + invertOverlap;
 r.right := r.right - invertOverlap;
 bmap.bounds := r;
 OffsetRect(bmap.bounds, -r.left, -r.top);
 IF (bmap.bounds.right MOD 16) <> 0 THEN
 bmap.rowBytes := 2 * ((bmap.bounds.right DIV 16) + 1)
 ELSE
 bmap.rowBytes := 2 * (bmap.bounds.right DIV 16);
 bmap.baseAddr := NewPtr(bmap.rowBytes * mBarHeight);
 oldMap := thePort^.portBits;
 SetPortBits(bmap);
 FillRect(bmap.bounds, gray);
 SetPortBits(oldMap);
 HLock(handle(theMenuBar));
 CopyBits(bmap, thePort^.portBits, bmap.bounds, r, notSrcBic, NIL);
 HUnlock(handle(theMenuBar));
 DisposPtr(bmap.baseAddr);
 END; { if title disabled }
 END; { for each menu }
 IF theMenuBar^^.hilited <> noneHilited THEN
 InvertRect(theMenuBar^^.wMenus[theMenuBar^^.hilited].titleRect);

 TextSize(oldSize);
 TextFont(oldFont);
 TextMode(oldMode);
 TextFace(oldStyle);
 SetPort(oldPort);
 END; { wDrawMenuBar }

{wDeleteMenu -- delete a menu from a wMenuBar}
 PROCEDURE wDeleteMenu;   { (theMenuBar : wMenuBarHandle; }
 { menuID : integer); }
 VAR
 i, j, oldSize, oldFont : integer;
 oldStyle : Style;
 titleWidth : integer;
 BEGIN
 oldSize := thePort^.txSize;
 { reset the font/size/style to compute menu title widths }
 oldFont := thePort^.txFont;
 oldStyle := thePort^.txFace;
 TextSize(12);
 TextFont(systemFont);
 TextFace([]);

 i := 0;
 WHILE (theMenuBar^^.wMenus[i].mh^^.menuID <> menuID)          
 AND (i < theMenuBar^^.numMenus) DO
 i := i + 1;
 IF i <> theMenuBar^^.numMenus THEN
 BEGIN
 titleWidth := StringWidth(theMenuBar^^.wMenus[i].mh^^.menuData);
 FOR j := i TO theMenuBar^^.numMenus - 1 DO
 BEGIN
 theMenuBar^^.wMenus[j].mh := theMenuBar^^.wMenus[j + 1].mh;
 theMenuBar^^.wMenus[j].titleRect := theMenuBar^^.wMenus[j + 1].titleRect;
 OffsetRect(theMenuBar^^.wMenus[j].titleRect, -(titleWidth + betweenTitles), 
0);
 END; { for loop -- copying menus back }
 theMenuBar^^.numMenus := theMenuBar^^.numMenus - 1;
 END; { if there’s a menu id = menuID }

 TextSize(oldSize);
 TextFont(oldFont);
 TextFace(oldStyle);
 END; { wDeleteMenu }

{wClearMenuBar -- delete all the menus in a menu bar}
 PROCEDURE wClearMenuBar; { (theMenuBar : wMenuBarHandle); }
 BEGIN
 theMenuBar^^.numMenus := 0; { take the easy way out.... }
 END; { wClearMenuBar }

{MenuDefProc -- inline call to the menu definition procedure}
{Pop the address of the proc off the stack and jsr to it}
 PROCEDURE MenuDefProc (message : integer;
 theMenu : MenuHandle;
 VAR menuRect : Rect;
 hitPt : Point;
 VAR whichItem : integer;
 theProc : ProcPtr);
 INLINE
 $205F, $4E90; { pop.l A0 , jsr (A0) }

{MenuDefGlue -- dereference menu handle to find the add. of}
{the definition proc and call it using MenuDefProc, above}
 PROCEDURE MenuDefGlue (message : integer;
 theMenu : MenuHandle;
 VAR menuRect : Rect;
 hitPt : Point;
 VAR whichItem : integer);
 BEGIN
 MenuDefProc(message, theMenu, menuRect, hitPt, whichItem, theMenu^^.menuProc^);
 END;

{wMenuSelect -- pull down the menus and let the user select an item}
 FUNCTION wMenuSelect;    { (theMenuBar : wMenuBarHandle; }
 { startPt : Point) : longint; }
 CONST
 flashDelay = 3; { # of ticks between calls to invert selected item }
 menuFrame = 2;  { width of menu frame }
 MenuFlashAddr = $A24;  
{ address of lo-mem global: # of times to flash menu }
 TYPE
 intPtr = ^integer;
 VAR
 bmap : BitMap;
 menuRect : Rect;
 oldClip : RgnHandle;
 nilPt : Point;
 blink, whichItem : integer;
 oldPort, wMgrPort : GrafPtr;
 i : integer;
 hstate, mprocState : SignedByte;
 ticks : longint;
 menuFlashP : intPtr;
 oldSize, oldFont, oldMode : integer;
 pnState : PenState;
 strayed : boolean;
 dummyEvt : EventRecord;
 BEGIN
 hState := HGetState(handle(theMenuBar));
 HLock(handle(theMenuBar));
 GetPort(oldPort);
 SetPort(theMenuBar^^.gp);
 oldSize := thePort^.txSize;
 oldFont := thePort^.txFont;
 oldMode := thePort^.txMode;
 TextSize(12);
 TextFont(systemFont);
 TextMode(srcOr);
 menuFlashP := intPtr(MenuFlashAddr);
 whichItem := 0;
 WHILE WaitMouseUp DO{ loop while the mouse is down }
 BEGIN
 { find menu title that user is clicking on }
 i := theMenuBar^^.numMenus - 1;
 WHILE (i >= 0) AND NOT PtInRect(startPt, theMenuBar^^.wMenus[i].titleRect) 
DO
 i := i - 1;

{ if user is clicking menu title, have the menu “drop down” }
 IF i >= 0 THEN
 WITH theMenuBar^^.wMenus[i] DO 
{ note: theMenuBar is locked }
 BEGIN
 wHiliteMenu(theMenuBar, mh^^.menuID); 
{ hilite title }
 CalcMenuSize(mh);   
{ calculate menu size, it may have changed }
 SetRect(menuRect, titleRect.left + 1, mBarHeight, titleRect.left + mh^^.menuWidth 
+ 1, mBarHeight + mh^^.menuHeight);
 InsetRect(menuRect, -menuFrame, -menuFrame);

 
{ if the menu overlaps the edges of the window, trim it }
 IF menuRect.bottom > thePort^.portRect.bottom THEN
 menuRect.bottom := thePort^.portRect.bottom;
 IF menuRect.right > thePort^.portRect.right THEN
 OffsetRect(menuRect, thePort^.portRect.right - menuRect.right - 2, 0);
 IF menuRect.left < 0 THEN
 OffsetRect(menuRect, -menuRect.left, 0);
 bmap.rowBytes := ((menuRect.right - menuRect.left + 15) DIV 16) * 2;
 bmap.bounds := menuRect;
 bmap.baseAddr := NewPtr(bmap.rowBytes * (menuRect.bottom - menuRect.top));
 IF bmap.baseAddr <> NIL THEN  
 { proceed if there is memory }
 BEGIN
 CopyBits(thePort^.portBits, bmap, bmap.bounds, bmap.bounds, srcCopy, 
NIL);
 oldClip := NewRgn;
 GetClip(oldClip);
 ClipRect(menuRect);

 
{ draw the menu -- thanks to Mike Schuster, MacTutor 12/85 }
 IF mh^^.menuHeight > 0 THEN
 BEGIN
      InsetRect(menuRect, menuFrame, menuFrame);
      EraseRect(menuRect);
      InsetRect(menuRect, -1, -1);
      FrameRect(menuRect);
      InsetRect(menuRect, 1, 1);

      GetPenState(pnState);
      PenNormal;
      MoveTo(menuRect.left + 1, menuRect.bottom + 1);
      Line((menuRect.right - menuRect.left), 0);
      Line(0, -(menuRect.bottom - menuRect.top));
      SetPenState(pnState);
 END; { if there’re any menu items }

 LoadResource(mh^^.menuProc);
 mprocState := HGetState(handle(mh^^.menuProc));
 HLock(mh^^.menuProc);
 whichItem := 0;
 MenuDefGlue(mDrawMsg, mh, menuRect, startPt, whichItem);

{ send the mChooseMsg while the user is still in this menu }
 strayed := false;
 WHILE WaitMouseUp AND NOT strayed DO
 BEGIN
      MenuDefGlue(mChooseMsg, mh, menuRect, startPt, whichItem);
      GetMouse(startPt);
      strayed := (startPt.v < mBarHeight - 1) AND (startPt.v > 0) AND 
(NOT PtInRect(startPt, titleRect));
   IF i < theMenuBar^^.numMenus - 1 THEN
 strayed := strayed OR ((startPt.v < mBarHeight - 1) AND (startPt.v > 
0) AND PtInRect(startPt, theMenuBar^^.wMenus[i + 1].titleRect));

{ Enable FKeys (i.e. screen dump) and DA updating }
      IF EventAvail(everyEvent, dummyEvt) THEN
           ;
      SystemTask;
 END; { while WaitMouseUp &not strayed }

 { flash the menu if an item was selected }
 IF (whichItem <> 0) AND NOT strayed THEN
 FOR blink := 1 TO menuFlashP^ DO
      BEGIN
           SetPt(nilPt, 0, 0);
           MenuDefGlue(mChooseMsg, mh, menuRect, nilPt, whichItem);
           Delay(flashDelay, ticks);
           MenuDefGlue(mChooseMsg, mh, menuRect, startPt, whichItem);
           Delay(flashDelay, ticks);
      END; { whichItem <> 0 }
 HSetState(mh^^.menuProc, mprocState);
 SetClip(oldClip);
 DisposeRgn(oldClip);
 CopyBits(bmap, thePort^.portBits, bmap.bounds, bmap.bounds, srcCopy, 
NIL);
 DisposPtr(bmap.baseAddr);
 END; { memory for bitmap }
 END { i >= 0: found the hit menu title }
 ELSE
 BEGIN  
{ user isn’t over a menu, so unhilite the last one hilited }
 IF theMenuBar^^.hilited <> noneHilited THEN
 wHiliteMenu(theMenuBar, 0);
 GetMouse(startPt);     
{ need a new startPt -- mouse may have moved }
 END;{ no menu currently selected }
 END; { while WaitMouseUp -- looking for a hit menu title}

 { user let up on the mouse -- return the appropriate value }
 IF whichItem = 0 THEN
 wMenuSelect := 0
 ELSE
 wMenuSelect := BitShift(theMenuBar^^.wMenus[i].mh^^.menuID, 16) + whichItem;
 TextSize(oldSize);
 TextFont(oldFont);
 TextMode(oldMode);
 SetPort(oldPort);
 HSetState(handle(theMenuBar), hState);
 END; { wMenuSelect }

{wMenuKey -- return the menu id and item no. with ch as it’s}
{ cmd-key equivalent }
{Caution: this assumes knowledge of the internal structure}
{ of  MenuInfo.menuData }
 FUNCTION wMenuKey;{ (theMenuBar : wMenuBarHandle; }
 { ch : char) : longint; }
 CONST
 flashDelay = 3;
 TYPE
 SignedBytePtr = ^SignedByte;
 CharPtr = ^char;
 VAR
 hState : SignedByte;
 bp, keyEquivP : SignedBytePtr;
 i, j, whichMenu, whichItem : integer;
 done, enabled : boolean;
 ticks : longint;

 { compare alphabetic characters w/o case sensitivity }
 FUNCTION equalChars (c1, c2 : char) : boolean;
 BEGIN
 IF c1 IN [‘a’..’z’] THEN
 c1 := char(ord(c1) + ord(‘A’) - ord(‘a’));
 IF c2 IN [‘a’..’z’] THEN
 c2 := char(ord(c2) + ord(‘A’) - ord(‘a’));
 equalChars := c1 = c2;
 END;

 BEGIN
 i := 0;
 done := false;
 WHILE (NOT done) AND (i < theMenuBar^^.numMenus) DO
 BEGIN
 hState := HGetState(handle(theMenuBar^^.wMenus[i].mh));
 HLock(handle(theMenuBar^^.wMenus[i].mh));

{ run down a menu, looking for an item w/ ch as its key}
{ equivalent }
 j := 1;
 bp := SignedBytePtr(@theMenuBar^^.wMenus[i].mh^^.menuData);
 bp := SignedBytePtr(ord4(bp) + bp^ + 1);
 WHILE (NOT done) AND (bp^ <> 0) DO
 BEGIN
 keyEquivP := SignedBytePtr(ord4(bp) + bp^ + 2);
 IF equalChars(ch, char(keyEquivP^)) THEN
 BEGIN
 whichMenu := theMenuBar^^.wMenus[i].mh^^.menuID;
 whichItem := j;
 done := true;
 END
 ELSE
 BEGIN
 j := j + 1;
 bp := SignedBytePtr(ord4(keyEquivP) + 3);
 END;
 END; { looking through this menu }

 HSetState(handle(theMenuBar^^.wMenus[i].mh), hState);
 i := i + 1;
 END; { while loop -- looking for key equiv }
 {the item is enabled if both it and its menu title are}
 enabled := BitTst(@theMenuBar^^.wMenus[i - 1].mh^^.enableFlags, menuTitleBit);
 enabled := enabled AND (j < 32) AND (BitTst(@theMenuBar^^.wMenus[i - 
1].mh^^.enableFlags, menuTitleBit - j));
 IF done AND enabled THEN
 BEGIN
 wHiliteMenu(theMenuBar, whichMenu);
 wMenuKey := BitShift(whichMenu, 16) + whichItem;
 END { done }
 ELSE
 wMenuKey := 0;
 END; { wMenuKey }

{wHiliteMenu -- unhilite the currently hilited menu title, and}
{ hilite a new one }
{if menuID <> 0 }
 PROCEDURE wHiliteMenu;   { (theMenuBar : wMenuBarHandle; }
 { menuID : integer); }
 VAR
 i : integer;
 oldPort : GrafPtr;
 BEGIN
 GetPort(oldPort);
 SetPort(theMenuBar^^.gp);
 IF (theMenuBar^^.hilited <> noneHilited) THEN
 InvertRect(theMenuBar^^.wMenus[theMenuBar^^.hilited].titleRect);
 theMenuBar^^.hilited := noneHilited;
 IF menuID <> 0 THEN
 BEGIN
 i := 0;
 WHILE (theMenuBar^^.wMenus[i].mh^^.menuID <> menuID) AND (i < theMenuBar^^.numMenus) 
DO
 i := i + 1;
 IF i <> theMenuBar^^.numMenus THEN
 BEGIN
 InvertRect(theMenuBar^^.wMenus[i].titleRect);
 theMenuBar^^.hilited := i;
 END; { found menuID }
 END;  { menuID <> 0 }
 SetPort(oldPort);
 END; { wHiliteMenu }

END.

{wSample -- the Mac User Education prog, adapted to use wMenus}
{ by Jim Matthews }
PROGRAM wSample;
{$I-}
 USES
 wMenu;
 CONST
 appleID = 128;
 fileID = 129;
 editID = 130;

 appleM = 1;
 fileM = 2;
 editM = 3;

 menuCount = 3;

 windowID = 128;

 undoCommand = 1;
 cutCommand = 3;
 copyCommand = 4;
 pasteCommand = 5;
 clearCommand = 6;

 VAR
 myMenus : ARRAY[1..menuCount] OF MenuHandle;
 dragRect, txRect : Rect;
 textH : TEHandle;
 theChar : char;
 extended, doneFlag : boolean;
 myEvent : EventRecord;
 wRecord : WindowRecord;
 myWindow : WindowPtr;
 whichWindow : WindowPtr;
 myMenuBar : wMenuBarHandle;

{SetUpWMenus -- read in menu templates and set up wMenuBar}
 PROCEDURE SetUpWMenus;
 VAR
 i : integer;
 BEGIN
 myMenuBar := wInitMenus(myWindow);
 myMenus[appleM] := GetMenu(appleID);
 AddResMenu(myMenus[appleM], ‘DRVR’);
 myMenus[fileM] := GetMenu(fileID);
 myMenus[editM] := GetMenu(editID);

 FOR i := 1 TO menuCount DO
 wInsertMenu(myMenuBar, myMenus[i], 0);
 END; {SetUpWMenus}

{DoCommand -- handle menu commands}
 PROCEDURE DoCommand (mResult : longint);
 VAR
 theItem, theMenu : integer;
 name : Str255;
 temp : integer;
 BEGIN
 theItem := LoWord(mResult);
 theMenu := HiWord(mResult);

 CASE theMenu OF
 appleID : 
 BEGIN
 GetItem(myMenus[appleM], theItem, name);
 temp := OpenDeskAcc(name);
 SetPort(myWindow);
 END; { appleID }
 fileID : 
 doneflag := true;
 editID : 
 BEGIN
 IF NOT SystemEdit(theItem - 1) THEN
 CASE theItem OF
 cutCommand : 
 TECut(textH);
 copyCommand : 
 TECopy(textH);
 pasteCommand : 
 TEPaste(textH);
 clearCommand : 
 TEDelete(textH);
 END; { case theItem of }
 END; { editID}
 OTHERWISE
 ;
 END; { case theMenu of }
 wHiliteMenu(myMenuBar, 0);
 END; { DoCommand }

{main program}
BEGIN
 InitGraf(@thePort);
 InitFonts;
 FlushEvents(everyEvent, 0);
 InitWindows;
 InitMenus;
 TEInit;
 InitDialogs(NIL);
 InitCursor;

 WITH screenBits.bounds DO
 SetRect(dragRect, 4, 24, right - 4, bottom - 4);
 doneFlag := false;
 myWindow := GetNewWindow(windowID, @wRecord, WindowPtr(-1));
 SetPort(myWindow);
 SetUpWMenus;
 txRect := thePort^.portRect;
 txRect.top := mBarHeight;
 InsetRect(txRect, 3, 3);
 textH := TENew(txRect, txRect);

 {main event loop}
 REPEAT
 SystemTask;
 TEIdle(textH);

 IF GetNextEvent(everyEvent, myEvent) THEN
 CASE myEvent.what OF
 mouseDown : 
 CASE FindWindow(myEvent.where, whichWindow) OF
 inSysWindow : 
 SystemClick(myEvent, whichWindow);
 inMenuBar : 
 IF MenuSelect(myEvent.where) <> 0 THEN
 ; 
{ handle da menus in the “real” menu bar }
 inDrag : 
 DragWindow(whichWindow, myEvent.where, dragRect);
 inContent : 
 BEGIN
 GlobalToLocal(myEvent.where);
 IF myEvent.where.v < mBarHeight THEN
 BEGIN
 IF whichWindow <> FrontWindow THEN
      SelectWindow(whichWindow);
 DoCommand(wMenuSelect(myMenuBar, myEvent.where));
 END
 ELSE
 BEGIN
 IF whichWindow <> FrontWindow THEN
      SelectWindow(whichWindow)
 ELSE
      BEGIN
           extended := BitAnd(myEvent.modifiers, shiftKey) <> 0;
           TEClick(myEvent.where, extended, textH);
      END; { whichWindow = FrontWindow}
 END; { click below menu bar }
 END; { inContent }
 OTHERWISE
 ;
 END; { mouseDown }
 keyDown, autoKey : 
 BEGIN
 theChar := char(BitAnd(myEvent.message, charCodeMask));
 IF BitAnd(myEvent.modifiers, cmdKey) <> 0 THEN
 DoCommand(wMenuKey(myMenuBar, theChar))
 ELSE
 TEKey(theChar, textH);
 END; { keyDown, autoKey }
 activateEvt : 
 BEGIN
 IF BitAnd(myEvent.modifiers, activeFlag) <> 0 THEN
 BEGIN
 TEActivate(textH);
 DisableItem(myMenus[editM], undoCommand);
 END
 ELSE
 BEGIN
 TEDeactivate(textH);
 EnableItem(myMenus[editM], undoCommand);
 END; { activate/deactivate }
 END; {activateEvt }
 updateEvt : 
 BEGIN
 BeginUpdate(WindowPtr(myEvent.message));
 EraseRect(thePort^.portRect);
 wDrawMenuBar(myMenuBar);
 TEUpdate(thePort^.portRect, textH);
 EndUpdate(WindowPtr(myEvent.message));
 END; { updateEvt }
 OTHERWISE
 ;
 END; { case event.what of }
 UNTIL doneFlag;
END.

* Rmaker source for wSample.rsrc

wSample.rsrc
????????

TYPE WIND
 ,128
wSample
40 50 300 450
Visible NoGoAway
0
0

TYPE MENU
 ,128
\14


TYPE MENU
 ,129
File
 Quit/Q

TYPE MENU
 ,130
Edit
 (Undo/Z
 (-
 Cut/X
 Copy/C
 Paste/V
 Clear
 
AAPL
$116.47
Apple Inc.
+0.16
MSFT
$47.98
Microsoft Corpora
-0.72
GOOG
$537.50
Google Inc.
+2.67

MacTech Search:
Community Search:

Software Updates via MacUpdate

Cobook 3.0.7 - Intelligent address book....
Cobook Contacts is an intuitive, engaging address book. Solve the problem of contact management with Cobook Contacts and its simple interface and powerful syncing and integration possibilities.... Read more
StatsBar 1.9 - Monitor system processes...
StatsBar gives you a comprehensive and detailed analysis of the following areas of your Mac: CPU usage Memory usage Disk usage Network and bandwidth usage Battery power and health (MacBooks only)... Read more
Cyberduck 4.6 - FTP and SFTP browser. (F...
Cyberduck is a robust FTP/FTP-TLS/SFTP browser for the Mac whose lack of visual clutter and cleverly intuitive features make it easy to use. Support for external editors and system technologies such... Read more
Maya 2015 - Professional 3D modeling and...
Maya is an award-winning software and powerful, integrated 3D modeling, animation, visual effects, and rendering solution. Because Maya is based on an open architecture, all your work can be scripted... Read more
Evernote 6.0.1 - Create searchable notes...
Evernote allows you to easily capture information in any environment using whatever device or platform you find most convenient, and makes this information accessible and searchable at anytime, from... Read more
calibre 2.11 - Complete e-library manage...
Calibre is a complete e-book library manager. Organize your collection, convert your books to multiple formats, and sync with all of your devices. Let Calibre be your multi-tasking digital... Read more
Herald 5.0.1 - Notification plugin for M...
Note: Versions 2.1.3 (for OS X 10.7), 3.0.6 (for OS X 10.8), and 4.0.8 (for OS X 10.9) are no longer supported by the developer. Herald is a notification plugin for Mail.app, Apple's Mac OS X email... Read more
Firetask 3.7 - Innovative task managemen...
Firetask uniquely combines the advantages of classical priority-and-due-date-based task management with GTD. Stay focused and on top of your commitments - Firetask's "Today" view shows all relevant... Read more
TechTool Pro 7.0.6 - Hard drive and syst...
TechTool Pro is now 7, and this is the most advanced version of the acclaimed Macintosh troubleshooting utility created in its 20-year history. Micromat has redeveloped TechTool Pro 7 to be fully 64... Read more
PhotoDesk 3.0.1 - Instagram client for p...
PhotoDesk lets you view, like, comment, and download Instagram pictures/videos! (NO Uploads! / Image Posting! Instagram forbids that! AND you *need* an *existing* Instagram account). But you can do... Read more

Latest Forum Discussions

See All

Ubisoft Gives Everyone Two New Ways to E...
Ubisoft Gives Everyone Two New Ways to Earn In-Game Stuff for Far Cry 4 Posted by Jessica Fisher on November 21st, 2014 [ permalink ] | Read more »
Golfinity – Tips, Tricks, Strategies, an...
Dig this: Would you like to know what we thought of being an infinite golfer? Check out our Golfinity review! Golfinity offers unlimited ways to test your skills at golf. Here are a few ways to make sure your score doesn’t get too high and your... | Read more »
Dark Hearts, The Sequel to Haunting Meli...
Dark Hearts, The Sequel to Haunting Melissa, is Available Now Posted by Jessica Fisher on November 21st, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Meowza! Toyze Brings Talking Tom to Life...
Meowza! | Read more »
Square Enix Announces New Tactical RPG f...
Square Enix Announces New Tactical RPG for Mobile, Heavenstrike Rivals. Posted by Jessica Fisher on November 21st, 2014 [ permalink ] With their epic stories and gorgeous graphics, | Read more »
Quest for Revenge (Games)
Quest for Revenge 1.0.0 Device: iOS Universal Category: Games Price: $4.99, Version: 1.0.0 (iTunes) Description: The great Kingdom of the west has fallen. The gods ignore the prayers of the desperate. A dark warlord has extinguished... | Read more »
Threadz is a New Writing Adventure for Y...
Threadz is a New Writing Adventure for You and Your Friends Posted by Jessica Fisher on November 21st, 2014 [ permalink ] In the tradition of round-robin storytelling, | Read more »
SteelSeries Stratus XL Hardware Review
Made by: SteelSeries Price: $59.99 Hardware/iOS Integration Rating: 4 out of 5 stars Usability Rating: 4.5 out of 5 stars Reuse Value Rating: 4.25 out of 5 stars Build Quality Rating: 4.5 out of 5 stars Overall Rating: 4.31 out of 5 stars | Read more »
ACDSee (Photography)
ACDSee 1.0.0 Device: iOS iPhone Category: Photography Price: $1.99, Version: 1.0.0 (iTunes) Description: Capture, perfect, and share your photos with ACDSee. The ACDSee iPhone app combines an innovative camera, a powerful photo... | Read more »
ProTube for YouTube (Entertainment)
ProTube for YouTube 2.0.2 Device: iOS Universal Category: Entertainment Price: $1.99, Version: 2.0.2 (iTunes) Description: ProTube is the ultimate, fully featured YouTube app. With it's highly polished design, ProTube offers ad-free... | Read more »

Price Scanner via MacPrices.net

15″ 2.2GHz Retina MacBook Pro on sale for $17...
 B&H Photo has the 2014 15″ 2.2GHz Retina MacBook Pro on sale today for $1749. Shipping is free, and B&H charges NY sales tax only. B&H will also include free copies of Parallels Desktop... Read more
27-inch 3.5GHz 5K iMac in stock today and on...
 B&H Photo has the new 27″ 3.5GHz 5K iMac in stock today and on sale for $2299 including free shipping plus NY sales tax only. Their price is $200 off MSRP, and it’s the lowest price available... Read more
21-inch 1.4GHz iMac on sale for $979, save $1...
B&H Photo has the new 21″ 1.4GHz iMac on sale for $979.99 including free shipping plus NY sales tax only. Their price is $120 off MSRP. B&H will also include free copies of Parallels Desktop... Read more
13-inch 1.4GHz/256GB MacBook Air on sale for...
B&H Photo has lowered their price on the 13″ 1.4GHz/256GB MacBook Air to $1059.99 including free shipping plus NY sales tax only. Their price is $140 off MSRP, and it’s the lowest price for this... Read more
Save up to $400 with Apple refurbished 2014 1...
The Apple Store has restocked Apple Certified Refurbished 2014 15″ Retina MacBook Pros for up to $400 off the cost of new models. An Apple one-year warranty is included with each model, and shipping... Read more
New 13-inch 1.4GHz MacBook Air on sale for $8...
 Adorama has the 2014 13″ 1.4GHz/128GB MacBook Air on sale for $899.99 including free shipping plus NY & NJ tax only. Their price is $100 off MSRP. B&H Photo has the 13″ 1.4GHz/128GB MacBook... Read more
Apple Expected to Reverse Nine-Month Tablet S...
Apple and Samsung combined accounted for 62 percent of the nearly 36 million branded tablets shipped in 3Q 2014, according to early vendor shipment share estimates from market intelligence firm ABI... Read more
Stratos: 30 Percent of US Smartphone Owners t...
Stratos, Inc., creator of the Bluetooth Connected Card Platform, has announced results from its 2014 Holiday Mobile Payments Survey. The consumer survey found that nearly one out of three (30 percent... Read more
2014 1.4GHz Mac mini on sale for $449, save $...
 B&H Photo has lowered their price on the new 1.4GHz Mac mini to $449.99 including free shipping plus NY tax only. Their price is $50 off MSRP, and it’s the lowest price available for this new... Read more
Check Apple prices on any device with the iTr...
MacPrices is proud to offer readers a free iOS app (iPhones, iPads, & iPod touch) and Android app (Google Play and Amazon App Store) called iTracx, which allows you to glance at today’s lowest... Read more

Jobs Board

*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
*Apple* Solutions Consultant (ASC)- Retail S...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
Project Manager, *Apple* Financial Services...
**Job Summary** Apple Financial Services (AFS) offers consumers, businesses and educational institutions ways to finance Apple purchases. We work with national and Read more
*Apple* Store Leader Program - College Gradu...
Job Description: Job Summary As an Apple Store Leader Program agent, you can continue your education as you major in the art of leadership at the Apple Store. You'll Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.