if (data.controlHandle != 0) { if (fClipCache == 0) { fClipCache= OS.NewRgn(); MacUtil.getVisibleRegion(data.controlHandle, fClipCache, true); OS.OffsetRgn(fClipCache, (short)-fRect.getX(), (short)-fRect.getY()); } if (data.clipRgn != 0) { int rgn= OS.NewRgn(); OS.SectRgn(fClipCache, data.clipRgn, rgn); OS.SetClip(rgn); OS.DisposeRgn(rgn); } else OS.SetClip(fClipCache);  OS.DisposeRgn(fClipCache); fClipCache= 0;
if (data.clipRgn != 0) { OS.SectRgn(result, data.clipRgn, result); }  OS.SetClip(result); if (bounds != null) OS.GetRegionBounds(result, bounds.getData()); OS.DisposeRgn(result);  } else {  if (data.clipRgn != 0) { OS.SetClip(data.clipRgn); if (bounds != null) OS.GetRegionBounds(data.clipRgn, bounds.getData());
	private void focus(boolean clip) {			// save global state		OS.GetGWorld(fSavePort, fSaveGWorld);				OS.SetGWorld(handle, fSaveGWorld[0]);				fOffsetX= 0;		fOffsetY= 0;				if (fIsFocused)			return;		if (clip) {			// set origin of port using drawable bounds			if (data.controlHandle != 0) {				OS.GetControlBounds(data.controlHandle, fRect.getData());				fOffsetX= (short)fRect.getX();				fOffsetY= (short)fRect.getY();				OS.SetOrigin((short)-fOffsetX, (short)-fOffsetY);			}			// save clip region 			OS.GetClip(fSaveClip);						// calculate new clip based on the controls bound and GC clipping region			if (data.controlHandle != 0) {				if (fClipCache == 0) {					fClipCache= OS.NewRgn();					MacUtil.getVisibleRegion(data.controlHandle, fClipCache, true);					OS.OffsetRgn(fClipCache, (short)-fRect.getX(), (short)-fRect.getY());				}				if (data.clipRgn != 0) {					int rgn= OS.NewRgn();					OS.SectRgn(fClipCache, data.clipRgn, rgn);					OS.SetClip(rgn);					OS.DisposeRgn(rgn);				} else 					OS.SetClip(fClipCache);				// caching doesn't work yet				OS.DisposeRgn(fClipCache);				fClipCache= 0;			} else {				if (data.clipRgn != 0)					OS.SetClip(data.clipRgn);			}		}	}