private void AddExpose (Hwnd hwnd, bool client, int x, int y, int width, int height) {
// Don't waste time
if ((hwnd == null) || (x > hwnd.Width) || (y > hwnd.Height) || ((x + width) < 0) || ((y + height) < 0)) {
return;
}
// Keep the invalid area as small as needed
if ((x + width) > hwnd.width) {
width = hwnd.width - x;
}
if ((y + height) > hwnd.height) {
height = hwnd.height - y;
}
if (client) {
hwnd.AddInvalidArea(x, y, width, height);
if (!hwnd.expose_pending && hwnd.visible) {
MSG msg = new MSG ();
msg.message = Msg.WM_PAINT;
msg.hwnd = hwnd.Handle;
EnqueueMessage (msg);
hwnd.expose_pending = true;
}
} else {
hwnd.AddNcInvalidArea (x, y, width, height);
if (!hwnd.nc_expose_pending && hwnd.visible) {
MSG msg = new MSG ();
Region rgn = new Region (hwnd.Invalid);
IntPtr hrgn = rgn.GetHrgn (null); // Graphics object isn't needed
msg.message = Msg.WM_NCPAINT;
msg.wParam = hrgn == IntPtr.Zero ? (IntPtr)1 : hrgn;
msg.refobject = rgn;
msg.hwnd = hwnd.Handle;
EnqueueMessage (msg);
hwnd.nc_expose_pending = true;
}
}
}
#endregion