nsISupports * supports = nsnull;  if(gCurrentMenuItem) { if(gPreviousMenuStack.Count() > 0) { nsIMenu * prevMenu = (nsIMenu *) gPreviousMenuStack[gPreviousMenuStack.Count() - 1];
if (gCurrentMenuItem){ if (gPreviousMenuStack.Count() > 0) { nsCOMPtr<nsIMenu> prevMenu; gPreviousMenuStack.GetMenuAt(gPreviousMenuStack.Count() - 1, getter_AddRefs(prevMenu));
void nsBuildMenu(MenuHandle theMenu, PRBool isChild){  // printf("enter BuildMenu \n");  nsIMenuBar * menubar = gMacMenubar; // Global for current menubar     if(!menubar || !theMenu) {    return;  }     nsMenuEvent mevent;  mevent.message = NS_MENU_SELECTED;  mevent.eventStructType = NS_MENU_EVENT;  mevent.point.x = 0;  mevent.point.y = 0;  mevent.widget = nsnull;  mevent.time = PR_IntervalNow();  mevent.mCommand = (PRUint32) theMenu;          // If toplevel  if( gCurrentMenuDepth < 2 ) {	  PRUint32 numMenus = 0;	  menubar->GetMenuCount(numMenus);	  numMenus--;	  for(PRInt32 i = numMenus; i >= 0; i--) {	    nsCOMPtr<nsIMenu> menu;	    menubar->GetMenuAt(i, *getter_AddRefs(menu));	    if(menu) {	        nsCOMPtr<nsIMenuListener> listener(do_QueryInterface(menu));	        if(listener) {	          // Reset menu depth count	          gMenuDepth = 0;	          nsEventStatus status = listener->MenuSelected(mevent);	          if(status != nsEventStatus_eIgnore) {	                          nsPostBuild(menu, theMenu, isChild);	            gPreviousTopLevelMenuHandle = theMenu;	            gPreviousTopLevelMenu = menu;              gPreviousMenuBar = menubar;	  	            //printf("exit BuildMenu \n");	            return;   	          }	        }	    } 	  }  } else {      // Not top level, so we can't use recursive MenuSelect <sigh>      // We must use the previously chosen menu item in combination      // with the current menu to determine what menu needs to be constructed        nsISupports * supports = nsnull;        //printf("gCurrentMenuItem = %d \n", gCurrentMenuItem);        if(gCurrentMenuItem) {        	if(gPreviousMenuStack.Count() > 0) {	            nsIMenu * prevMenu = (nsIMenu *) gPreviousMenuStack[gPreviousMenuStack.Count() - 1];	            //printf("gPreviousMenuStack.Count() = %d \n", gPreviousMenuStack.Count() );	            	            if(prevMenu) {			        prevMenu->GetItemAt(gCurrentMenuItem - 1, supports);			        nsCOMPtr<nsIMenu> menu(do_QueryInterface(supports));			        if(menu) {			          nsCOMPtr<nsIMenuListener> menulistener(do_QueryInterface(supports));			          menulistener->MenuSelected(mevent);			          nsPostBuild(menu, theMenu, isChild);			        }		        } 			}	    }  }  //printf("exit BuildMenu \n");}