OS.RemoveEventLoopTimer (id [0]);
if (timer != 0) { OS.RemoveEventLoopTimer (timer); pollingTimer = 0; }
int mouseProc (int nextHandler, int theEvent, int userData) {	int eventKind = OS.GetEventKind (theEvent);	switch (eventKind) {		case OS.kEventMouseDown:			short [] buttonData = new short [1];			OS.GetEventParameter (theEvent, OS.kEventParamMouseButton, OS.typeMouseButton, null, 2, null, buttonData);			int [] clickCountData = new int [1];			OS.GetEventParameter (theEvent, OS.kEventParamClickCount, OS.typeUInt32, null, 4, null, clickCountData);			clickCount = clickCountButton == buttonData [0] ? clickCountData [0] : 1;			clickCountButton = buttonData [0];			break;		case OS.kEventMouseDragged:		case OS.kEventMouseMoved:			mouseMoved = true;	}	if (mouseUpControl != null && eventKind == OS.kEventMouseUp) {		if (!mouseUpControl.isDisposed ()) {			mouseUpControl.mouseProc (nextHandler, theEvent, userData);			mouseUpControl = null;			return OS.noErr;		}		mouseUpControl = null;	}	int sizeof = org.eclipse.swt.internal.carbon.Point.sizeof;	org.eclipse.swt.internal.carbon.Point where = new org.eclipse.swt.internal.carbon.Point ();	OS.GetEventParameter (theEvent, OS.kEventParamMouseLocation, OS.typeQDPoint, null, sizeof, null, where);	int [] theWindow = new int [1];	int part = OS.FindWindow (where, theWindow);	switch (part) {		case OS.inMenuBar: {			if (eventKind == OS.kEventMouseDown) {				clearMenuFlags ();				if (menuBar == null || menuBar.isEnabled ()) {					int [] id = new int [1];					int eventLoop = OS.GetCurrentEventLoop ();					OS.InstallEventLoopTimer (eventLoop, 10 / 1000.0, 10 / 1000.0, pollingProc, 0, id);					OS.MenuSelect (where);					OS.RemoveEventLoopTimer (id [0]);				}					 				clearMenuFlags ();				return OS.noErr;			}			break;		}		case OS.inContent: {			Rect windowRect = new Rect ();			OS.GetWindowBounds (theWindow [0], (short) OS.kWindowContentRgn, windowRect);			CGPoint inPoint = new CGPoint ();			inPoint.x = where.h - windowRect.left;			inPoint.y = where.v - windowRect.top;			if (OS.HIVIEW) {				int root = OS.HIViewGetRoot (theWindow [0]);				int [] buffer = new int [1];				OS.HIViewGetViewForMouseEvent (root, theEvent, buffer);				int view = buffer [0];				OS.HIViewFindByID (root, OS.kHIViewWindowContentID (), buffer);				int contentView = buffer [0]; 				while (view != 0 && view != contentView && !OS.IsControlEnabled (view)) {						view = OS.HIViewGetSuperview (view);				}				Widget widget = null;				boolean consume = false;				do {					widget = getWidget (view);					if (widget != null) {						if (widget.isEnabled ()) break;						consume = true;					}					view = OS.HIViewGetSuperview (view);				} while (view != 0 && view != contentView);				if (widget != null) {					if (widget.contains ((int) inPoint.x, (int) inPoint.y)) {						int result = userData != 0 ? widget.mouseProc (nextHandler, theEvent, userData) : OS.eventNotHandledErr;						return consume ? OS.noErr : result;					}				}			} else {				int [] theRoot = new int [1];				OS.GetRootControl (theWindow [0], theRoot);				int [] theControl = new int [1];				OS.HIViewGetSubviewHit (theRoot [0], inPoint, true, theControl);				while (theControl [0] != 0 && !OS.IsControlEnabled (theControl [0])) {									OS.GetSuperControl (theControl [0], theControl);				}				Widget widget = null;				boolean consume = false;				if (theControl [0] == 0) theControl [0] = theRoot [0];				do {					widget = getWidget (theControl [0]);					if (widget != null) {						if (widget.isEnabled ()) break;						consume = true;					}					OS.GetSuperControl (theControl [0], theControl);				} while (theControl [0] != 0);				if (theControl [0] == 0) widget = getWidget (theRoot [0]);				if (widget != null) {					if (widget.contains ((int) inPoint.x, (int) inPoint.y)) {						int result = userData != 0 ? widget.mouseProc (nextHandler, theEvent, userData) : OS.eventNotHandledErr;						return consume ? OS.noErr : result;					}				}			}			break;		}	}	switch (eventKind) {		case OS.kEventMouseDragged:		case OS.kEventMouseMoved:  OS.InitCursor ();	}	return OS.eventNotHandledErr;}