From 605acbb7085e1c95e29d6eeb0136502c5dcab488 Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Tue, 18 Sep 2007 14:32:31 +0000 Subject: [PATCH] - Disabled MM_RESEND_LAST_FAILURE as it doesn't seem to work - Call resizeWindowToFit: when live resize ends, in case SetTextDimensions DO message was lost during live resize. git-svn-id: http://macvim.googlecode.com/svn/trunk@241 96c4425d-ca35-0410-94e5-3396d5c13a8f --- MMTextView.m | 11 +++++ MMVimController.h | 2 +- MMWindowController.h | 2 + MMWindowController.m | 98 +++++++++++++++++++++++--------------------- 4 files changed, 66 insertions(+), 47 deletions(-) diff --git a/MMTextView.m b/MMTextView.m index 6c2ff70113..f429eaedba 100644 --- a/MMTextView.m +++ b/MMTextView.m @@ -740,6 +740,17 @@ static NSString *MMKeypadEnterString = @"KA"; // The font panel is updated whenever the font is set. } +- (void)viewDidEndLiveResize +{ + // HACK! If a SetTextDimensionsMsgID message is lost while dragging to + // resize the window, then the text view and window sizes may become out of + // sync. To avoid this problem, resize the window when live resizes ends. + // This sometimes makes the window size 'jump' unpleasantly, but that is + // better than the alternative. + id windowController = [[self window] windowController]; + [windowController resizeWindowToFit:self]; +} + @end // MMTextView diff --git a/MMVimController.h b/MMVimController.h index ec6c543e33..6bf7bb8f9e 100644 --- a/MMVimController.h +++ b/MMVimController.h @@ -13,7 +13,7 @@ // If sendMessage: fails, store the message and resend after a delay. -#define MM_RESEND_LAST_FAILURE 1 +#define MM_RESEND_LAST_FAILURE 0 @class MMWindowController; diff --git a/MMWindowController.h b/MMWindowController.h index 84a46b407d..e172317745 100644 --- a/MMWindowController.h +++ b/MMWindowController.h @@ -62,6 +62,8 @@ - (IBAction)addNewTab:(id)sender; - (IBAction)toggleToolbar:(id)sender; +- (void)resizeWindowToFit:(id)sender; + @end // vim: set ft=objc: diff --git a/MMWindowController.m b/MMWindowController.m index a691ff9ac3..85143b9ef4 100644 --- a/MMWindowController.m +++ b/MMWindowController.m @@ -50,7 +50,6 @@ enum { - (NSSize)contentSizeForTextStorageSize:(NSSize)textViewSize; - (NSRect)textViewRectForContentSize:(NSSize)contentSize; - (NSSize)textStorageSizeForTextViewSize:(NSSize)textViewSize; -- (void)resizeWindowToFit:(id)sender; - (NSRect)fitWindowToFrame:(NSRect)frame; - (void)updateResizeIncrements; - (NSTabViewItem *)addNewTabViewItem; @@ -720,6 +719,58 @@ NSMutableArray *buildMenuAddress(NSMenu *menu) return [self askBackendForStarRegister:pboard]; } +- (void)resizeWindowToFit:(id)sender +{ + // NOTE: Be very careful when you call this method! Do not call while + // processing command queue, instead set 'shouldUpdateWindowSize' to YES. + // The only other place it is currently called is when live resize ends. + // This is done to ensure that the text view and window sizes match up + // (they may become out of sync if a SetTextDimensionsMsgID message to the + // backend is dropped). + + if (!setupDone) return; + + NSWindow *win = [self window]; + NSRect frame = [win frame]; + NSRect contentRect = [win contentRectForFrameRect:frame]; + NSSize newSize = [self contentSizeForTextStorageSize:[textStorage size]]; + + // Keep top-left corner of the window fixed when resizing. + contentRect.origin.y -= newSize.height - contentRect.size.height; + contentRect.size = newSize; + + frame = [win frameRectForContentRect:contentRect]; + NSRect maxFrame = [win constrainFrameRect:frame toScreen:[win screen]]; + + // HACK! Assuming the window frame cannot already be placed too high, + // adjust 'maxFrame' so that it at least as high up as the current frame. + // The reason for doing this is that constrainFrameRect:toScreen: does not + // always seem to utilize as much area as possible. + if (NSMaxY(frame) > NSMaxY(maxFrame)) { + maxFrame.size.height = frame.origin.y - maxFrame.origin.y + + frame.size.height; + } + + if (!NSEqualRects(maxFrame, frame)) { + // The new window frame is too big to fit on the screen, so fit the + // text storage to the biggest frame which will fit on the screen. + //NSLog(@"Proposed window frame does not fit on the screen!"); + frame = [self fitWindowToFrame:maxFrame]; + } + + //NSLog(@"%s %@", _cmd, NSStringFromRect(frame)); + + // HACK! If the window does resize, then windowDidResize is called which in + // turn calls placeViews. In case the computed new size of the window is + // no different from the current size, then we need to call placeViews + // manually. + if (NSEqualRects(frame, [win frame])) { + [self placeViews]; + } else { + [win setFrame:frame display:YES]; + } +} + @end // MMWindowController @@ -789,51 +840,6 @@ NSMutableArray *buildMenuAddress(NSMenu *menu) return size; } -- (void)resizeWindowToFit:(id)sender -{ - if (!setupDone) return; - - NSWindow *win = [self window]; - NSRect frame = [win frame]; - NSRect contentRect = [win contentRectForFrameRect:frame]; - NSSize newSize = [self contentSizeForTextStorageSize:[textStorage size]]; - - // Keep top-left corner of the window fixed when resizing. - contentRect.origin.y -= newSize.height - contentRect.size.height; - contentRect.size = newSize; - - frame = [win frameRectForContentRect:contentRect]; - NSRect maxFrame = [win constrainFrameRect:frame toScreen:[win screen]]; - - // HACK! Assuming the window frame cannot already be placed too high, - // adjust 'maxFrame' so that it at least as high up as the current frame. - // The reason for doing this is that constrainFrameRect:toScreen: does not - // always seem to utilize as much area as possible. - if (NSMaxY(frame) > NSMaxY(maxFrame)) { - maxFrame.size.height = frame.origin.y - maxFrame.origin.y - + frame.size.height; - } - - if (!NSEqualRects(maxFrame, frame)) { - // The new window frame is too big to fit on the screen, so fit the - // text storage to the biggest frame which will fit on the screen. - //NSLog(@"Proposed window frame does not fit on the screen!"); - frame = [self fitWindowToFrame:maxFrame]; - } - - //NSLog(@"%s %@", _cmd, NSStringFromRect(frame)); - - // HACK! If the window does resize, then windowDidResize is called which in - // turn calls placeViews. In case the computed new size of the window is - // no different from the current size, then we need to call placeViews - // manually. - if (NSEqualRects(frame, [win frame])) { - [self placeViews]; - } else { - [win setFrame:frame display:YES]; - } -} - - (NSRect)fitWindowToFrame:(NSRect)frame { if (!setupDone) return frame;