if (REVERSE) { for (int i= 0; i < pos; i++) { if (OS.GetIndexedSubControl(parentControlHandle, (short)(n-pos+1), outControl) == 0) if (OS.EmbedControl(outControl[0], parentControlHandle) != OS.kNoErr) System.out.println("MacUtil.embedControl: couldn't move control to end"); }  } else { int count= n-pos; for (int i= 0; i < count; i++) { if (OS.GetIndexedSubControl(parentControlHandle, (short)(pos+1), outControl) == 0) if (OS.EmbedControl(outControl[0], parentControlHandle) != OS.kNoErr) System.out.println("MacUtil.embedControl: couldn't move control to end"); }
for (int i= 0; i < pos; i++) { if (OS.GetIndexedSubControl(parentControlHandle, (short)(n-pos+1), outControl) == 0) if (OSEmbedControl(outControl[0], parentControlHandle) != OS.kNoErr) System.out.println("MacUtil.embedControl: couldn't move control to end");
	public static void embedControl(int controlHandle, int parentControlHandle, int pos) {				// add at end		if (OS.EmbedControl(controlHandle, parentControlHandle) != OS.kNoErr)			System.out.println("MacUtil.embedControl: could not embed control in parent");					int n= countSubControls(parentControlHandle)-1;				if (pos < 0 || pos > n)			pos= n;				int[] outControl= new int[1];		if (REVERSE) {			for (int i= 0; i < pos; i++) {				if (OS.GetIndexedSubControl(parentControlHandle, (short)(n-pos+1), outControl) == 0)					if (OS.EmbedControl(outControl[0], parentControlHandle) != OS.kNoErr)						System.out.println("MacUtil.embedControl: couldn't move control to end");			}					} else {			int count= n-pos;			for (int i= 0; i < count; i++) {				if (OS.GetIndexedSubControl(parentControlHandle, (short)(pos+1), outControl) == 0)					if (OS.EmbedControl(outControl[0], parentControlHandle) != OS.kNoErr)						System.out.println("MacUtil.embedControl: couldn't move control to end");			}		}				// verify correct position		n++;		for (int i= 0; i < n; i++) {			int index= REVERSE ? (n-i) : (i+1);			int[] outHandle= new int[1];			if (OS.GetIndexedSubControl(parentControlHandle, (short)index, outHandle) == 0) {	// indices are 1 based				if (outHandle[0] == controlHandle) {					if (i != pos)						System.out.println("MacUtil.embedControl: creation at position nyi (is: "+i+" should: "+ pos+")");					return;				}			}		}		System.out.println("MacUtil.embedControl: new child not found");	}