int ww= OS.GetControlOwner(fTrackedControl); int[] w= new int[1]; int rc= OS.GetEventParameter(eRefHandle, OS.kEventParamWindowRef, OS.typeWindowRef, null, 4, null, w); if (rc == OS.noErr) whichWindow= w[0]; if (whichWindow != ww) System.out.println("Display.handleMouseEvent:  oops");
whichWindow= OS.GetControlOwner(fTrackedControl);
	private int handleMouseCallback(int nextHandler, int eRefHandle, int whichWindow) {				int eventClass= OS.GetEventClass(eRefHandle);		if (eventClass != OS.kEventClassMouse) {			System.out.println("handleMouseCallback: unexpected event class: " + MacUtil.toString(eventClass));			return OS.eventNotHandledErr;		}						int eventKind= OS.GetEventKind(eRefHandle);		if (eventKind == OS.kEventMouseDown) {			fTrackedControl= 0;		}				MacEvent me= new MacEvent(eRefHandle);		org.eclipse.swt.internal.carbon.Point where= me.getWhere();				// retrieve window and window part from event		if (whichWindow == 0) {			if (fTrackedControl != 0) {				// in tracking mode: get window from control				int ww= OS.GetControlOwner(fTrackedControl);				int[] w= new int[1];				int rc= OS.GetEventParameter(eRefHandle, OS.kEventParamWindowRef, OS.typeWindowRef, null, 4, null, w);				if (rc == OS.noErr)					whichWindow= w[0];				if (whichWindow != ww)					System.out.println("Display.handleMouseEvent:  oops");			} else {				int[] w= new int[1];				OS.FindWindow(where, w);				whichWindow= w[0];				if (whichWindow == 0) {					// try to retrieve window from event					int rc= OS.GetEventParameter(eRefHandle, OS.kEventParamWindowRef, OS.typeWindowRef, null, 4, null, w);					if (rc == OS.noErr)						whichWindow= w[0];					else {						// the event is a MouseMoved event:					}				}			}		}						if (whichWindow == 0) {			// give up			return OS.eventNotHandledErr;		}					MacEvent.trackStateMask(eRefHandle, eventKind);						// determine control under mouse		short[] cpart= new short[1];				int whichControl= MacUtil.findControlUnderMouse(whichWindow, me, cpart);						Widget widget= WidgetTable.get(whichControl);				MacMouseEvent mme= new MacMouseEvent(me);				switch (eventKind) {				case OS.kEventMouseDown:									Shell shell= null;			Widget w= findWidget(whichWindow);			if (w instanceof Shell)				shell= (Shell) w;							// first click in window -> activation			if (!OS.IsWindowActive(whichWindow)) {				if (shell != null && (shell.getStyle() & SWT.ON_TOP) == 0) {					// let the default handler activate the window					break;				}			}						// whatever we do, we hide the tooltip			hideToolTip();			// focus handling			if (shell != null && (shell.getStyle() & SWT.ON_TOP) == 0)				setMacFocusHandle(whichWindow, whichControl);												if (whichControl != 0) {							// deal with the context menu				if (widget instanceof Control) {					Menu cm= ((Control)widget).getMenu();	// is a context menu installed?					if (cm != null && me.isShowContextualMenuClick()) {						try {							fInContextMenu= true;							// AW: not ready for primetime							// OS.ContextualMenuSelect(cm.handle, globalPos.getData(), new short[1], new short[1]);							org.eclipse.swt.internal.carbon.Point pos= me.getWhere();							OS.PopUpMenuSelect(cm.handle, pos.v, pos.h, (short)1);						} finally {							fInContextMenu= false;						}						return OS.noErr;					}				}								if (cpart[0] == 111) { 	// a user pane					if (!(widget instanceof Text)) 						fTrackedControl= whichControl;	// starts mouse tracking					windowProc(whichControl, SWT.MouseDown, mme);					return OS.noErr;				} else {					windowProc(whichControl, SWT.MouseDown, mme);				}			}			break;				case OS.kEventMouseDragged:			if (fTrackedControl != 0) {				windowProc(fTrackedControl, SWT.MouseMove, mme);				return OS.noErr;			}			break;		case OS.kEventMouseUp:			if (fTrackedControl != 0) {				windowProc(fTrackedControl, SWT.MouseUp, mme);				fTrackedControl= 0;				return OS.noErr;			}				break;					case OS.kEventMouseMoved:					fTrackedControl= 0;											if (fCurrentControl != whichControl) {							if (fCurrentControl != 0) {					fLastHoverHandle= 0;					windowProc(fCurrentControl, SWT.MouseExit, mme);				}								fCurrentControl= whichControl;								if (widget instanceof Control) {					Control c= (Control) widget;					if (c.cursor != null)						c.cursor.install(this);						else						setCursor(0);						} else					setCursor(0);								windowProc(fCurrentControl, SWT.MouseMove, mme);								if (fCurrentControl != 0) {					windowProc(fCurrentControl, SWT.MouseEnter, mme);				}				return OS.noErr;							} else {				if (fCurrentControl != 0) {					windowProc(fCurrentControl, SWT.MouseMove, mme);					return OS.noErr;				}			}			break;					case OS.kEventMouseWheelMoved:			if (widget instanceof Composite) {				ScrollBar sb= ((Composite) widget).getVerticalBar();				if (sb != null)					return sb.processWheel(eRefHandle);			}			break;		}							return OS.eventNotHandledErr;	}