diff --git a/Headers/win32/WIN32Geometry.h b/Headers/win32/WIN32Geometry.h index 19a3395..f1b96ed 100644 --- a/Headers/win32/WIN32Geometry.h +++ b/Headers/win32/WIN32Geometry.h @@ -19,7 +19,8 @@ You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free - Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA. + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02111 USA. */ #ifndef _WIN32Geometry_h_INCLUDE @@ -29,70 +30,69 @@ #include -static inline -NSPoint MSWindowPointToGS(HWND hwnd, int x, int y) +@class WIN32Server; + +static inline NSPoint +MSWindowPointToGS(WIN32Server *svr, HWND hwnd, int x, int y) { + NSGraphicsContext *ctxt; + RECT rect; + float h, l, r, t, b; NSPoint p1; - RECT rect; - int h; + NSWindow *window; + ctxt = GSCurrentContext(); + window = GSWindowWithNumber((int)hwnd); GetClientRect(hwnd, &rect); h = rect.bottom - rect.top; + [svr styleoffsets: &l : &r : &t : &b : [window styleMask]]; - p1.x = x; - p1.y = h - y; + p1.x = x + l; + p1.y = h - y + b; return p1; } -static inline -POINT GSWindowPointToMS(HWND hwnd, NSPoint p) +static inline NSRect +MSWindowRectToGS(WIN32Server *svr, HWND hwnd, RECT r0) { - POINT p1; + NSGraphicsContext *ctxt; RECT rect; - int h; - - GetClientRect(hwnd, &rect); - h = rect.bottom - rect.top; - - p1.x = p.x; - p1.y = h -p.y; - - return p1; -} - -static inline -NSRect MSWindowRectToGS(HWND hwnd, RECT r) -{ + float h, l, r, t, b; NSRect r1; - RECT rect; - int h; + NSWindow *window; + ctxt = GSCurrentContext(); + window = GSWindowWithNumber((int)hwnd); GetClientRect(hwnd, &rect); h = rect.bottom - rect.top; + [svr styleoffsets: &l : &r : &t : &b : [window styleMask]]; - r1.origin.x = r.left; - r1.origin.y = h - r.bottom; - r1.size.width = r.right - r.left; - r1.size.height = r.bottom -r.top; - + r1.origin.x = r0.left + l; + r1.origin.y = h - r0.bottom + b; + r1.size.width = r0.right - r0.left; + r1.size.height = r0.bottom - r0.top; return r1; } -static inline -RECT GSWindowRectToMS(HWND hwnd, NSRect r) +static inline RECT +GSWindowRectToMS(WIN32Server *svr, HWND hwnd, NSRect r0) { - RECT r1; + NSGraphicsContext *ctxt; RECT rect; - int h; + float h, l, r, t, b; + RECT r1; + NSWindow *window; + ctxt = GSCurrentContext(); + window = GSWindowWithNumber((int)hwnd); GetClientRect(hwnd, &rect); h = rect.bottom - rect.top; + [svr styleoffsets: &l : &r : &t : &b : [window styleMask]]; - r1.left = r.origin.x; - r1.bottom = h - r.origin.y; - r1.right = r.origin.x + r.size.width; - r1.top = h - r.origin.y - r.size.height; - + r1.left = r0.origin.x - l; + r1.bottom = h - r0.origin.y + b; + r1.right = r1.left + r0.size.width; + r1.top = r1.bottom - r0.size.height; return r1; } @@ -145,20 +145,12 @@ NSRect MSScreenRectToGS(RECT r, unsigned int styleMask, WIN32Server *self) { NSRect r1; int screen_height = GetSystemMetrics(SM_CYSCREEN); - float t, b, l, rr; - - [self styleoffsets: &l : &rr : &t : &b : styleMask]; r1.origin.x = r.left; r1.origin.y = screen_height - r.bottom; r1.size.width = r.right - r.left; r1.size.height = r.bottom - r.top; - r1.origin.x += l; - r1.origin.y += b; - r1.size.width -= l + rr; - r1.size.height -= t + b; - return r1; } @@ -178,14 +170,6 @@ RECT GSScreenRectToMS(NSRect r, unsigned int styleMask, WIN32Server *self) { RECT r1; int screen_height = GetSystemMetrics(SM_CYSCREEN); - float t, b, l, rr; - - [self styleoffsets: &l : &rr : &t : &b : styleMask]; - - r.origin.x -= l; - r.origin.y -= b; - r.size.width += l + rr; - r.size.height += t + b; r1.left = r.origin.x; r1.bottom = screen_height - r.origin.y; diff --git a/Source/win32/GSDisplayServer_details.m b/Source/win32/GSDisplayServer_details.m index ad10da9..f611315 100644 --- a/Source/win32/GSDisplayServer_details.m +++ b/Source/win32/GSDisplayServer_details.m @@ -18,7 +18,8 @@ You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free - Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA. + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02111 USA. */ #include diff --git a/Source/win32/WIN32Server.m b/Source/win32/WIN32Server.m index c817547..7aa9abe 100644 --- a/Source/win32/WIN32Server.m +++ b/Source/win32/WIN32Server.m @@ -21,7 +21,8 @@ You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free - Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA. + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02111 USA. */ #include @@ -58,16 +59,16 @@ static NSString *NSMenuWillTearOff = @"MenuWillTearOff"; static NSString *NSMenuwillPopUP =@"MenuwillPopUP"; static NSString *NSWindowDidCreateWindow =@"WindowDidCreateWindow"; -static NSEvent *process_key_event(HWND hwnd, WPARAM wParam, LPARAM lParam, - NSEventType eventType); -static NSEvent *process_mouse_event(HWND hwnd, WPARAM wParam, LPARAM lParam, - NSEventType eventType); +static NSEvent *process_key_event(WIN32Server *svr, + HWND hwnd, WPARAM wParam, LPARAM lParam, NSEventType eventType); +static NSEvent *process_mouse_event(WIN32Server *svr, + HWND hwnd, WPARAM wParam, LPARAM lParam, NSEventType eventType); //static BOOL HAVE_MAIN_MENU = NO; static BOOL handlesWindowDecorations = NO; static void -validateWindow(HWND hwnd, RECT rect); +validateWindow(WIN32Server *svr, HWND hwnd, RECT rect); LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); @@ -1409,27 +1410,27 @@ printf("\n\n##############################################################\n"); break; case WM_MOUSEMOVE: //MOUSE NSDebugLLog(@"NSEvent", @"Got Message %s for %d", "MOUSEMOVE", hwnd); - ev = process_mouse_event(hwnd, wParam, lParam, NSMouseMoved); + ev = process_mouse_event(self, hwnd, wParam, lParam, NSMouseMoved); break; case WM_LBUTTONDOWN: //MOUSE NSDebugLLog(@"NSEvent", @"Got Message %s for %d", "LBUTTONDOWN", hwnd); //[self decodeWM_LBUTTONDOWNParams: (WPARAM)wParam : (LPARAM)lParam : (HWND)hwnd]; - ev = process_mouse_event(hwnd, wParam, lParam, NSLeftMouseDown); + ev = process_mouse_event(self, hwnd, wParam, lParam, NSLeftMouseDown); break; case WM_LBUTTONUP: //MOUSE NSDebugLLog(@"NSEvent", @"Got Message %s for %d", "LBUTTONUP", hwnd); - ev = process_mouse_event(hwnd, wParam, lParam, NSLeftMouseUp); + ev = process_mouse_event(self, hwnd, wParam, lParam, NSLeftMouseUp); break; case WM_LBUTTONDBLCLK: //MOUSE NSDebugLLog(@"NSEvent", @"Got Message %s for %d", "LBUTTONDBLCLK", hwnd); break; case WM_MBUTTONDOWN: //MOUSE NSDebugLLog(@"NSEvent", @"Got Message %s for %d", "MBUTTONDOWN", hwnd); - ev = process_mouse_event(hwnd, wParam, lParam, NSOtherMouseDown); + ev = process_mouse_event(self, hwnd, wParam, lParam, NSOtherMouseDown); break; case WM_MBUTTONUP: //MOUSE NSDebugLLog(@"NSEvent", @"Got Message %s for %d", "MBUTTONUP", hwnd); - ev = process_mouse_event(hwnd, wParam, lParam, NSOtherMouseUp); + ev = process_mouse_event(self, hwnd, wParam, lParam, NSOtherMouseUp); break; case WM_MBUTTONDBLCLK: //MOUSE NSDebugLLog(@"NSEvent", @"Got Message %s for %d", "MBUTTONDBLCLK", hwnd); @@ -1437,13 +1438,13 @@ printf("\n\n##############################################################\n"); case WM_RBUTTONDOWN: //MOUSE { NSDebugLLog(@"NSEvent", @"Got Message %s for %d", "RBUTTONDOWN", hwnd); - ev = process_mouse_event(hwnd, wParam, lParam, NSRightMouseDown); + ev = process_mouse_event(self, hwnd, wParam, lParam, NSRightMouseDown); } break; case WM_RBUTTONUP: //MOUSE NSDebugLLog(@"NSEvent", @"Got Message %s for %d", "RBUTTONUP", hwnd); { - ev = process_mouse_event(hwnd, wParam, lParam, NSRightMouseUp); + ev = process_mouse_event(self, hwnd, wParam, lParam, NSRightMouseUp); } break; case WM_RBUTTONDBLCLK: //MOUSE @@ -1451,16 +1452,16 @@ printf("\n\n##############################################################\n"); break; case WM_MOUSEWHEEL: //MOUSE NSDebugLLog(@"NSEvent", @"Got Message %s for %d", "MOUSEWHEEL", hwnd); - ev = process_mouse_event(hwnd, wParam, lParam, NSScrollWheel); + ev = process_mouse_event(self, hwnd, wParam, lParam, NSScrollWheel); break; case WM_KEYDOWN: //KEYBOARD NSDebugLLog(@"NSEvent", @"Got Message %s for %d", "KEYDOWN", hwnd); - ev = process_key_event(hwnd, wParam, lParam, NSKeyDown); + ev = process_key_event(self, hwnd, wParam, lParam, NSKeyDown); break; case WM_KEYUP: //KEYBOARD NSDebugLLog(@"NSEvent", @"Got Message %s for %d", "KEYUP", hwnd); - ev = process_key_event(hwnd, wParam, lParam, NSKeyUp); + ev = process_key_event(self, hwnd, wParam, lParam, NSKeyUp); break; case WM_POWERBROADCAST: //SYSTEM @@ -1708,10 +1709,17 @@ printf("\n\n##############################################################\n"); - (void) windowdevice: (int) winNum { NSGraphicsContext *ctxt; + RECT rect; + float h, l, r, t, b; + NSWindow *window; NSDebugLLog(@"WTrace", @"windowdevice: %d", winNum); ctxt = GSCurrentContext(); - GSSetDevice(ctxt, (void*)winNum, 0, 0); + window = GSWindowWithNumber(winNum); + GetClientRect((HWND)winNum, &rect); + h = rect.bottom - rect.top; + [self styleoffsets: &l : &r : &t : &b : [window styleMask]]; + GSSetDevice(ctxt, (void*)winNum, l, h + b); DPSinitmatrix(ctxt); DPSinitclip(ctxt); } @@ -1894,8 +1902,8 @@ printf("\n\n##############################################################\n"); /** Causes buffered graphics to be flushed to the screen */ - (void) flushwindowrect: (NSRect)rect : (int) winNum { - RECT r = GSWindowRectToMS((HWND)winNum, rect); - validateWindow((HWND)winNum, r); + RECT r = GSWindowRectToMS(self, (HWND)winNum, rect); + validateWindow(self, (HWND)winNum, r); } - (void) styleoffsets: (float *) l : (float *) r : (float *) t : (float *) b @@ -2137,7 +2145,7 @@ process_char(WPARAM wParam, unsigned *eventModifierFlags) } static NSEvent* -process_key_event(HWND hwnd, WPARAM wParam, LPARAM lParam, +process_key_event(WIN32Server *svr, HWND hwnd, WPARAM wParam, LPARAM lParam, NSEventType eventType) { NSEvent *event; @@ -2162,7 +2170,7 @@ process_key_event(HWND hwnd, WPARAM wParam, LPARAM lParam, pos = GetMessagePos(); eventLocation - = MSWindowPointToGS(hwnd, GET_X_LPARAM(pos), GET_Y_LPARAM(pos)); + = MSWindowPointToGS(svr, hwnd, GET_X_LPARAM(pos), GET_Y_LPARAM(pos)); ltime = GetMessageTime(); time = ltime / 1000; @@ -2255,7 +2263,7 @@ process_key_event(HWND hwnd, WPARAM wParam, LPARAM lParam, } static NSEvent* -process_mouse_event(HWND hwnd, WPARAM wParam, LPARAM lParam, +process_mouse_event(WIN32Server *svr, HWND hwnd, WPARAM wParam, LPARAM lParam, NSEventType eventType) { NSEvent *event; @@ -2270,7 +2278,7 @@ process_mouse_event(HWND hwnd, WPARAM wParam, LPARAM lParam, static LONG lastTime = 0; gcontext = GSCurrentContext(); - eventLocation = MSWindowPointToGS(hwnd, GET_X_LPARAM(lParam), + eventLocation = MSWindowPointToGS(svr, hwnd, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); ltime = GetMessageTime(); time = ltime / 1000; @@ -2355,7 +2363,7 @@ LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, static void -validateWindow(HWND hwnd, RECT rect) +validateWindow(WIN32Server *svr, HWND hwnd, RECT rect) { WIN_INTERN *win = (WIN_INTERN *)GetWindowLong((HWND)hwnd, GWL_USERDATA); @@ -2370,7 +2378,7 @@ validateWindow(HWND hwnd, RECT rect) if (!result) { NSLog(@"validated window %d %@", hwnd, - NSStringFromRect(MSWindowRectToGS((HWND)hwnd, rect))); + NSStringFromRect(MSWindowRectToGS(svr, (HWND)hwnd, rect))); NSLog(@"validateWindow failed %d", GetLastError()); } ReleaseDC((HWND)hwnd, hdc); diff --git a/Source/win32/w32_windowdisplay.m b/Source/win32/w32_windowdisplay.m index 2d444fb..97750fa 100644 --- a/Source/win32/w32_windowdisplay.m +++ b/Source/win32/w32_windowdisplay.m @@ -27,10 +27,10 @@ #include "w32_Events.h" -static void invalidateWindow(HWND hwnd, RECT rect); +static void invalidateWindow(WIN32Server *svr, HWND hwnd, RECT rect); static void -invalidateWindow(HWND hwnd, RECT rect) +invalidateWindow(WIN32Server *svr, HWND hwnd, RECT rect) { WIN_INTERN *win = (WIN_INTERN *)GetWindowLong((HWND)hwnd, GWL_USERDATA); @@ -44,8 +44,6 @@ invalidateWindow(HWND hwnd, RECT rect) win->hdc, rect.left, rect.top, SRCCOPY); if (!result) { - NSLog(@"validated window %d %@", hwnd, - NSStringFromRect(MSWindowRectToGS((HWND)hwnd, rect))); NSLog(@"validateWindow failed %d", GetLastError()); } ReleaseDC((HWND)hwnd, hdc); @@ -53,14 +51,14 @@ invalidateWindow(HWND hwnd, RECT rect) else { NSWindow *window = GSWindowWithNumber((int)hwnd); - NSRect r = MSWindowRectToGS((HWND)hwnd, rect); + NSRect r = MSWindowRectToGS(svr, (HWND)hwnd, rect); /* NSLog(@"Invalidated window %d %@ (%d, %d, %d, %d)", hwnd, NSStringFromRect(r), rect.left, rect.top, rect.right, rect.bottom); */ // Repaint the window's client area. - [[window contentView] setNeedsDisplayInRect: r]; + [[[window contentView] superview] setNeedsDisplayInRect: r]; } } @@ -242,7 +240,7 @@ invalidateWindow(HWND hwnd, RECT rect) { //InvalidateRect(hwnd,rect,YES); - invalidateWindow(hwnd, rect); + invalidateWindow(self, hwnd, rect); // validate the whole window, for in some cases an infinite series // of WM_PAINT is triggered ValidateRect(hwnd, NULL); diff --git a/Source/winlib/WIN32GState.m b/Source/winlib/WIN32GState.m index f9b69dd..7057e6c 100644 --- a/Source/winlib/WIN32GState.m +++ b/Source/winlib/WIN32GState.m @@ -82,14 +82,9 @@ static inline POINT GSWindowPointToMS(WIN32GState *s, NSPoint p) { POINT p1; - int h; - h = WindowHeight([s window]); - - p.x += s->offset.x; - p.y += s->offset.y; - p1.x = p.x; - p1.y = h - p.y; + p1.x = p.x - s->offset.x; + p1.y = s->offset.y - p.y; return p1; } @@ -98,17 +93,11 @@ static inline RECT GSWindowRectToMS(WIN32GState *s, NSRect r) { RECT r1; - int h; - h = WindowHeight([s window]); - - r.origin.x += s->offset.x; - r.origin.y += s->offset.y; - - r1.left = r.origin.x; - r1.right = r.origin.x + r.size.width; - r1.bottom = h - r.origin.y; - r1.top = h - r.origin.y - r.size.height; + r1.left = r.origin.x - s->offset.x; + r1.bottom = s->offset.y - r.origin.y; + r1.right = r1.left + r.size.width; + r1.top = r1.bottom - r.size.height; return r1; }