diff --git a/dlls/winemac.drv/cocoa_window.m b/dlls/winemac.drv/cocoa_window.m index 9b3fa9d1b81..380469c58d2 100644 --- a/dlls/winemac.drv/cocoa_window.m +++ b/dlls/winemac.drv/cocoa_window.m @@ -1616,6 +1616,47 @@ - (void) windowWillStartLiveResize:(NSNotification *)notification forMode:NSRunLoopCommonModes]; } + - (NSRect) windowWillUseStandardFrame:(NSWindow*)window defaultFrame:(NSRect)proposedFrame + { + macdrv_query* query; + NSRect currentContentRect, proposedContentRect, newContentRect, screenRect; + NSSize maxSize; + + query = macdrv_create_query(); + query->type = QUERY_MIN_MAX_INFO; + query->window = (macdrv_window)[self retain]; + [self.queue query:query timeout:0.5]; + macdrv_release_query(query); + + currentContentRect = [self contentRectForFrameRect:[self frame]]; + proposedContentRect = [self contentRectForFrameRect:proposedFrame]; + + maxSize = [self contentMaxSize]; + newContentRect.size.width = MIN(NSWidth(proposedContentRect), maxSize.width); + newContentRect.size.height = MIN(NSHeight(proposedContentRect), maxSize.height); + + // Try to keep the top-left corner where it is. + newContentRect.origin.x = NSMinX(currentContentRect); + newContentRect.origin.y = NSMaxY(currentContentRect) - NSHeight(newContentRect); + + // If that pushes the bottom or right off the screen, pull it up and to the left. + screenRect = [self contentRectForFrameRect:[[self screen] visibleFrame]]; + if (NSMaxX(newContentRect) > NSMaxX(screenRect)) + newContentRect.origin.x = NSMaxX(screenRect) - NSWidth(newContentRect); + if (NSMinY(newContentRect) < NSMinY(screenRect)) + newContentRect.origin.y = NSMinY(screenRect); + + // If that pushes the top or left off the screen, push it down and the right + // again. Do this last because the top-left corner is more important than the + // bottom-right. + if (NSMinX(newContentRect) < NSMinX(screenRect)) + newContentRect.origin.x = NSMinX(screenRect); + if (NSMaxY(newContentRect) > NSMaxY(screenRect)) + newContentRect.origin.y = NSMaxY(screenRect) - NSHeight(newContentRect); + + return [self frameRectForContentRect:newContentRect]; + } + /* * ---------- NSPasteboardOwner methods ---------- diff --git a/dlls/winemac.drv/event.c b/dlls/winemac.drv/event.c index 515671eac55..b9b97785f96 100644 --- a/dlls/winemac.drv/event.c +++ b/dlls/winemac.drv/event.c @@ -158,6 +158,10 @@ static void macdrv_query_event(HWND hwnd, const macdrv_event *event) TRACE("QUERY_RESIZE_START\n"); success = query_resize_start(hwnd); break; + case QUERY_MIN_MAX_INFO: + TRACE("QUERY_MIN_MAX_INFO\n"); + success = query_min_max_info(hwnd); + break; default: FIXME("unrecognized query type %d\n", query->type); break; diff --git a/dlls/winemac.drv/macdrv.h b/dlls/winemac.drv/macdrv.h index e2a54cc6a00..4a7e25910a9 100644 --- a/dlls/winemac.drv/macdrv.h +++ b/dlls/winemac.drv/macdrv.h @@ -164,6 +164,7 @@ static inline RECT rect_from_cgrect(CGRect cgrect) extern void macdrv_window_did_unminimize(HWND hwnd) DECLSPEC_HIDDEN; extern BOOL query_resize_end(HWND hwnd) DECLSPEC_HIDDEN; extern BOOL query_resize_start(HWND hwnd) DECLSPEC_HIDDEN; +extern BOOL query_min_max_info(HWND hwnd) DECLSPEC_HIDDEN; extern void macdrv_mouse_button(HWND hwnd, const macdrv_event *event) DECLSPEC_HIDDEN; extern void macdrv_mouse_moved(HWND hwnd, const macdrv_event *event) DECLSPEC_HIDDEN; diff --git a/dlls/winemac.drv/macdrv_cocoa.h b/dlls/winemac.drv/macdrv_cocoa.h index 63f537e1be1..d99a5ec40cb 100644 --- a/dlls/winemac.drv/macdrv_cocoa.h +++ b/dlls/winemac.drv/macdrv_cocoa.h @@ -287,6 +287,7 @@ extern int macdrv_set_display_mode(const struct macdrv_display* display, QUERY_PASTEBOARD_DATA, QUERY_RESIZE_END, QUERY_RESIZE_START, + QUERY_MIN_MAX_INFO, NUM_QUERY_TYPES }; diff --git a/dlls/winemac.drv/window.c b/dlls/winemac.drv/window.c index efd63d1b07e..1afe2941f43 100644 --- a/dlls/winemac.drv/window.c +++ b/dlls/winemac.drv/window.c @@ -2048,3 +2048,16 @@ BOOL query_resize_end(HWND hwnd) SendMessageW(hwnd, WM_EXITSIZEMOVE, 0, 0); return TRUE; } + + +/*********************************************************************** + * query_min_max_info + * + * Handler for QUERY_MIN_MAX_INFO query. + */ +BOOL query_min_max_info(HWND hwnd) +{ + TRACE("hwnd %p\n", hwnd); + sync_window_min_max_info(hwnd); + return TRUE; +}