- 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
This commit is contained in:
Bjorn Winckler
2007-09-18 14:32:31 +00:00
parent f4f647e20e
commit 605acbb708
4 changed files with 66 additions and 47 deletions
+11
View File
@@ -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
+1 -1
View File
@@ -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;
+2
View File
@@ -62,6 +62,8 @@
- (IBAction)addNewTab:(id)sender;
- (IBAction)toggleToolbar:(id)sender;
- (void)resizeWindowToFit:(id)sender;
@end
// vim: set ft=objc:
+52 -46
View File
@@ -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;