int setBounds (int control, int x, int y, int width, int height, boolean move, boolean resize, boolean events) {
boolean sameOrigin = true, sameExtent = true;
if (OS.HIVIEW) {
CGRect oldBounds = new CGRect ();
OS.HIViewGetFrame (control, oldBounds);
Rect inset = getInset ();
oldBounds.x -= inset.left;
oldBounds.y -= inset.top;
oldBounds.width += inset.left + inset.right;
oldBounds.height += inset.top + inset.bottom;
if (!move) {
x = (int) oldBounds.x;
y = (int) oldBounds.y;
}
if (!resize) {
width = (int) oldBounds.width;
height = (int) oldBounds.height;
}
CGRect newBounds = new CGRect ();
newBounds.x = x + inset.left;
newBounds.y = y + inset.top;
newBounds.width = width - inset.right - inset.left;
newBounds.height = height - inset.bottom - inset.top;
sameOrigin = newBounds.x == oldBounds.x && newBounds.y == oldBounds.y;
sameExtent = newBounds.width == oldBounds.width && newBounds.height == oldBounds.height;
if (sameOrigin && sameExtent) return 0;
OS.HIViewSetFrame (control, newBounds);
invalidateVisibleRegion (control);
} else {
/* Compute the old bounds */
Rect oldBounds = new Rect ();
OS.GetControlBounds (control, oldBounds);
int [] theRoot = new int [1];
int window = OS.GetControlOwner (control);
OS.GetRootControl (window, theRoot);
int [] parentHandle = new int [1];
OS.GetSuperControl (control, parentHandle);
Rect parentRect = new Rect ();
if (parentHandle [0] != theRoot [0]) {
OS.GetControlBounds (parentHandle [0], parentRect);
OS.OffsetRect (oldBounds, (short) -parentRect.left, (short) -parentRect.top);
}
Rect inset = getInset ();
oldBounds.left -= inset.left;
oldBounds.top -= inset.top;
oldBounds.right += inset.right;
oldBounds.bottom += inset.bottom;
/* Compute the new bounds */
if (!move) {
x = oldBounds.left;
y = oldBounds.top;
}
if (!resize) {
width = oldBounds.right - oldBounds.left;
height = oldBounds.bottom - oldBounds.top;
}
Rect newBounds = new Rect ();
newBounds.left = (short) (parentRect.left + x + inset.left);
newBounds.top = (short) (parentRect.top + y + inset.top);
newBounds.right = (short) (newBounds.left + width - inset.right - inset.left);
newBounds.bottom = (short) (newBounds.top + height - inset.bottom - inset.top);
if (newBounds.bottom < newBounds.top) newBounds.bottom = newBounds.top;