internal override void SetWindowPos(IntPtr handle, int x, int y, int width, int height) {
Hwnd hwnd;
hwnd = Hwnd.ObjectFromHandle(handle);
if (hwnd == null) {
return;
}
// Win32 automatically changes negative width/height to 0.
if (width < 0)
width = 0;
if (height < 0)
height = 0;
// X requires a sanity check for width & height; otherwise it dies
if (hwnd.zero_sized && width > 0 && height > 0) {
if (hwnd.visible) {
MapWindow(hwnd, WindowType.Whole);
}
hwnd.zero_sized = false;
}
if ((width < 1) || (height < 1)) {
hwnd.zero_sized = true;
UnmapWindow(hwnd, WindowType.Whole);
}
// Save a server roundtrip (and prevent a feedback loop)
if ((hwnd.x == x) && (hwnd.y == y) &&
(hwnd.width == width) && (hwnd.height == height)) {
return;
}
if (!hwnd.zero_sized) {
//Hack?
hwnd.x = x;
hwnd.y = y;
hwnd.width = width;
hwnd.height = height;
SendMessage(hwnd.client_window, Msg.WM_WINDOWPOSCHANGED, IntPtr.Zero, IntPtr.Zero);
if (hwnd.fixed_size) {
SetWindowMinMax(handle, Rectangle.Empty, new Size(width, height), new Size(width, height));
}
lock (XlibLock) {
Control ctrl = Control.FromHandle (handle);
Size TranslatedSize = TranslateWindowSizeToXWindowSize (ctrl.GetCreateParams (), new Size (width, height));
MoveResizeWindow (DisplayHandle, hwnd.whole_window, x, y, TranslatedSize.Width, TranslatedSize.Height);
PerformNCCalc(hwnd);
}
}
// Update our position/size immediately, so
// that future calls to SetWindowPos aren't
// kept from calling XMoveResizeWindow (by the
// "Save a server roundtrip" block above).
hwnd.x = x;
hwnd.y = y;
hwnd.width = width;
hwnd.height = height;
hwnd.ClientRect = Rectangle.Empty;
}