if (gPreviousMenuHandleStack.Count()) { nsIMenu * menu = (nsIMenu *) gPreviousMenuStack[gPreviousMenuStack.Count() - 1]; MenuHandle menuHandle = (MenuHandle) gPreviousMenuHandleStack[gPreviousMenuHandleStack.Count() - 1];
if (gPreviousMenuHandleStack.Count()) { nsCOMPtr<nsIMenu> menu; gPreviousMenuStack.GetMenuAt(gPreviousMenuStack.Count() - 1, getter_AddRefs(menu));  MenuHandle menuHandle = (MenuHandle) gPreviousMenuHandleStack[gPreviousMenuHandleStack.Count() - 1];
pascal void nsDynamicMDEFMain(  short message,  MenuHandle theMenu,   Rect * menuRect,   Point hitPt,   short * whichItem) {		  switch (message) {    case kMenuDrawMsg:       //printf("  Draw passed in menu is = %d \n", *theMenu);      //printf("  t= %d l= %d b= %d r= %d\n", (*menuRect).top, (*menuRect).left, (*menuRect).bottom, (*menuRect).right);      //printf("  Point.v = %d  Point.h = %d\n", hitPt.v, hitPt.h);      //printf("  whichItem = %d \n", *whichItem);      //printf("  theMenu.menuID = %d \n", (**theMenu).menuID);            nsCheckDestroy(theMenu, whichItem);      break;    case kMenuChooseMsg:       // Keep track of currently chosen item      nsDynamicChooseItem(theMenu, menuRect, hitPt, whichItem);      return; // Yes, intentional return as CallSystemMDEF has happened already      break;          case kMenuSizeMsg:      //printf("Size passed in menu is = %d \n", *theMenu);       //printf("  t= %d l= %d b= %d r= %d \n", (*menuRect).top, (*menuRect).left, (*menuRect).bottom ,(*menuRect).right);      //printf("  Point.v = %d  Point.h = %d \n", hitPt.v, hitPt.h);      //printf("  whichItem = %d \n", *whichItem);      //printf("  theMenu.menuID = %d \n", (**theMenu).menuID);            nsCheckDestroy(theMenu, whichItem);            // Need to make sure that we rebuild the menu every time...if (gPreviousMenuHandleStack.Count()) {    nsIMenu * menu = (nsIMenu *) gPreviousMenuStack[gPreviousMenuStack.Count() - 1];    MenuHandle menuHandle = (MenuHandle) gPreviousMenuHandleStack[gPreviousMenuHandleStack.Count() - 1];        //printf("  gPreviousMenuStack.Count() = %d \n", gPreviousMenuStack.Count());    //printf("  gPreviousMenuHandleStack.Count() = %d \n", gPreviousMenuHandleStack.Count());               if( menu && menuHandle ) {            if( menuHandle == theMenu ) {           	      nsCOMPtr<nsIMenuListener> listener(do_QueryInterface(menu));		  if(listener) {		    //printf("MenuPop \n");		    		    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) nsnull;		    		    // UNDO		    listener->MenuDeselected(mevent);		    		    gPreviousMenuStack.RemoveElementAt(gPreviousMenuStack.Count() - 1);		    NS_IF_RELEASE(menu);		    	        //printf("%d items now on gPreviousMenuStack \n", gPreviousMenuStack.Count());	        gPreviousMenuHandleStack.RemoveElementAt(gPreviousMenuHandleStack.Count() - 1);	      		  }	  }	}  }             nsDynamicSizeTheMenu(theMenu);      break;  }  nsCallSystemMDEF(message, theMenu, menuRect, hitPt, whichItem);    // Force a size message next time we draw this menu  if(message == kMenuDrawMsg) {    SInt8 state = ::HGetState((Handle)theMenu);    HLock((Handle)theMenu);    (**theMenu).menuWidth = -1;	(**theMenu).menuHeight = -1;    HSetState((Handle)theMenu, state);    }}  