int clipRgn= OS.NewRgn(); MacUtil.getVisibleRegion(parent.handle, clipRgn, true);  Rect bounds= new Rect(); MacUtil.getControlBounds(parent.handle, bounds); int left = x+bounds.left; int top = y+bounds.top; OS.SetRect(bounds, (short)left, (short)top, (short)(left+nWidth), (short)(top+nHeight));  int caretRgn= OS.NewRgn(); OS.RectRgn(caretRgn, bounds); OS.SectRgn(caretRgn, clipRgn, caretRgn);  if (!OS.EmptyRgn(caretRgn)) { int[] port= new int[1]; OS.GetPort(port); OS.SetPortWindowPort(OS.GetControlOwner(handle)); OS.InvertRgn(caretRgn); OS.SetPort(port[0]); }  OS.DisposeRgn(clipRgn); OS.DisposeRgn(caretRgn);
GC gc= new GC(parent); gc.setXORMode(true); gc.fillRectangle(x, y, nWidth, nHeight); gc.dispose();
boolean drawCaret () {	if (parent == null) return false;	if (parent.isDisposed ()) return false;	int handle = parent.handle;	int nWidth = width, nHeight = height;	if (image != null) {		Rectangle rect = image.getBounds ();		nWidth = rect.width;		nHeight = rect.height;	}	if (nWidth <= 0) nWidth = 2;		int clipRgn= OS.NewRgn();	MacUtil.getVisibleRegion(parent.handle, clipRgn, true);	Rect bounds= new Rect();	MacUtil.getControlBounds(parent.handle, bounds);	int left = x+bounds.left;	int top = y+bounds.top;	OS.SetRect(bounds, (short)left, (short)top, (short)(left+nWidth), (short)(top+nHeight));		int caretRgn= OS.NewRgn();	OS.RectRgn(caretRgn, bounds);	OS.SectRgn(caretRgn, clipRgn, caretRgn);		if (!OS.EmptyRgn(caretRgn)) {		int[] port= new int[1];		OS.GetPort(port);		OS.SetPortWindowPort(OS.GetControlOwner(handle));			OS.InvertRgn(caretRgn);		OS.SetPort(port[0]);	}		OS.DisposeRgn(clipRgn);	OS.DisposeRgn(caretRgn);	return true;}