From b62e9875ea5f367494dd4d0bd7364c766800369e Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Sat, 18 Oct 2008 15:38:08 +0200 Subject: [PATCH] Fix "set lines=999" in .gvimrc Ensure that the window fits on screen when the window is resized to fit the content. This should fix a problem where the window would not be flush with the menu bar when "set lines=999" was added to .gvimrc. --- src/MacVim/MMWindowController.m | 45 +++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/src/MacVim/MMWindowController.m b/src/MacVim/MMWindowController.m index 0b821e12..36228284 100644 --- a/src/MacVim/MMWindowController.m +++ b/src/MacVim/MMWindowController.m @@ -74,6 +74,7 @@ - (NSSize)contentSize; - (void)resizeWindowToFitContentSize:(NSSize)contentSize; - (NSSize)constrainContentSizeToScreenSize:(NSSize)contentSize; +- (NSRect)constrainFrame:(NSRect)frame; - (void)updateResizeConstraints; - (NSTabViewItem *)addNewTabViewItem; - (BOOL)askBackendForStarRegister:(NSPasteboard *)pb; @@ -744,10 +745,7 @@ // change at any time (dock could move, resolution could change, window // could be moved to another screen, ...). - NSRect maxFrame = [[win screen] visibleFrame]; - NSRect rect = [win contentRectForFrameRect:maxFrame]; - rect.size = [vimView constrainRows:NULL columns:NULL toSize:rect.size]; - maxFrame = [win frameRectForContentRect:rect]; + NSRect maxFrame = [self constrainFrame:[[win screen] visibleFrame]]; if (proposedFrameSize.width > maxFrame.size.width) proposedFrameSize.width = maxFrame.size.width; @@ -786,15 +784,7 @@ // The "default frame" represents the maximal size of a zoomed window. // Constrain this frame so that the content fits an even number of rows and // columns. - NSRect contentRect = [decoratedWindow contentRectForFrameRect:frame]; - NSSize constrainedSize = [vimView constrainRows:NULL - columns:NULL - toSize:contentRect.size]; - - contentRect.origin.y += contentRect.size.height - constrainedSize.height; - contentRect.size = constrainedSize; - - frame = [decoratedWindow frameRectForContentRect:contentRect]; + frame = [self constrainFrame:frame]; if (!((zoomBoth && !cmdLeftClick) || (!zoomBoth && cmdLeftClick))) { // Zoom in horizontal direction only. @@ -855,6 +845,20 @@ contentRect.size = contentSize; frame = [decoratedWindow frameRectForContentRect:contentRect]; + + // Ensure that the window fits inside the visible part of the screen. + NSRect maxFrame = [[decoratedWindow screen] visibleFrame]; + maxFrame = [self constrainFrame:maxFrame]; + + if (frame.size.width > maxFrame.size.width) { + frame.size.width = maxFrame.size.width; + frame.origin.x = maxFrame.origin.x; + } + if (frame.size.height > maxFrame.size.height) { + frame.size.height = maxFrame.size.height; + frame.origin.y = maxFrame.origin.y; + } + [decoratedWindow setFrame:frame display:YES]; } @@ -871,6 +875,21 @@ return contentSize; } +- (NSRect)constrainFrame:(NSRect)frame +{ + // Constrain the given (window) frame so that it fits an even number of + // rows and columns. + NSRect contentRect = [decoratedWindow contentRectForFrameRect:frame]; + NSSize constrainedSize = [vimView constrainRows:NULL + columns:NULL + toSize:contentRect.size]; + + contentRect.origin.y += contentRect.size.height - constrainedSize.height; + contentRect.size = constrainedSize; + + return [decoratedWindow frameRectForContentRect:contentRect]; +} + - (void)updateResizeConstraints { if (!setupDone) return; -- 2.11.4.GIT