if (!closing) { closing = true; close (); }
if (!closing) close ();
int commandProc (int nextHandler, int theEvent, int userData) {	int eventKind = OS.GetEventKind (theEvent);	HICommand command = new HICommand ();	OS.GetEventParameter (theEvent, OS.kEventParamDirectObject, OS.typeHICommand, null, HICommand.sizeof, null, command);	switch (eventKind) {		case OS.kEventProcessCommand: {			if (command.commandID == OS.kAEQuitApplication) {				if (!closing) {					closing = true;					close ();				}				return OS.noErr;			}			if ((command.attributes & OS.kHICommandFromMenu) != 0) {				if (userData != 0) {					Widget widget = getWidget (userData);					if (widget != null) return widget.commandProc (nextHandler, theEvent, userData);				} else {					int menuRef = command.menu_menuRef;					short menuID = OS.GetMenuID (menuRef);					Menu menu = getMenu (menuID);					if (menu != null) {						/*						* Feature in the Macintosh.  When a menu item is selected by the						* user, the Macintosh sends kEventMenuOpening, remembers the index						* of the item the user selected, sends kEventMenuClosed and then						* sends kEventProcessCommand.  If application code modifies the menu						* inside of kEventMenuClosed by adding or removing items, the index						* of the item that the user selected is invalid.  The fix is to detect						* that a menu has been modified during kEventMenuClosed and use the						* last target item remembered kEventMenuTargetItem.						*/						MenuItem item = null;						if (menu.closed && menu.modified) {							item = menu.lastTarget;						} else {							item = menu.getItem (command.menu_menuItemIndex - 1);						}						if (item != null) {							return item.kEventProcessCommand (nextHandler, theEvent, userData);						}					}					OS.HiliteMenu ((short) 0);				}			}		}	}	return OS.eventNotHandledErr;}