Loading ...
Sorry, an error occurred while loading the content.

[PATCH] resizing works again in non-fu mode

Expand Messages
  • Nicolas Weber
    ... src/MacVim/MMVimView.h | 9 +-- src/MacVim/MMVimView.m | 44 ++++++++++------ src/MacVim/MMWindowController.m | 104
    Message 1 of 3 , Oct 30, 2007
    View Source
    • 0 Attachment
      ---
      src/MacVim/MMVimView.h | 9 +--
      src/MacVim/MMVimView.m | 44 ++++++++++------
      src/MacVim/MMWindowController.m | 104 +++++++++++++++++++--------------------
      3 files changed, 81 insertions(+), 76 deletions(-)

      diff --git a/src/MacVim/MMVimView.h b/src/MacVim/MMVimView.h
      index ec5e542..d247ba1 100644
      --- a/src/MacVim/MMVimView.h
      +++ b/src/MacVim/MMVimView.h
      @@ -29,7 +29,7 @@
      MMTextStorage *textStorage;
      NSMutableArray *scrollbars;

      - NSSize actualSize; // will become bounds or frame (?)
      + NSSize actualSize; // will become bounds or frame (?) XXX
      NSSize desiredSize;

      // This is temporary to make the refactoring easier
      @@ -47,11 +47,11 @@
      // XXX: name/comment methods in a sane way
      - (NSSize)actualSize;
      - (NSSize)desiredSize;
      -- (void)getDesiredRows:(int *)r columns:(int *)c forSize:(NSSize)size;
      +- (NSSize)getDesiredRows:(int *)r columns:(int *)c forSize:(NSSize)size;
      - (void)getActualRows:(int *)r columns:(int *)c;
      +- (void)setActualRows:(int)r columns:(int)c;

      - (PSMTabBarControl *)tabBarControl;
      -- (NSTabView *)tabView;
      - (IBAction)addNewTab:(id)sender;
      - (void)updateTabsWithData:(NSData *)data;
      - (void)selectTabWithIndex:(int)idx;
      @@ -70,7 +70,4 @@
      - (NSRect)textViewRectForContentSize:(NSSize)contentSize;
      - (void)setShouldUpdateWindowSize:(BOOL)b;

      -
      -- (NSSize)contentSizeForTextStorageSize:(NSSize)textViewSize;
      -- (NSSize)textStorageSizeForTextViewSize:(NSSize)textViewSize;
      @end
      diff --git a/src/MacVim/MMVimView.m b/src/MacVim/MMVimView.m
      index 61e51d3..5510509 100644
      --- a/src/MacVim/MMVimView.m
      +++ b/src/MacVim/MMVimView.m
      @@ -53,6 +53,9 @@ enum {
      - (void)placeScrollbars;
      - (int)representedIndexOfTabViewItem:(NSTabViewItem *)tvi;
      - (MMScroller *)scrollbarForIdentifier:(long)ident index:(unsigned *)idx;
      +- (NSSize)contentSizeForTextStorageSize:(NSSize)textViewSize;
      +- (NSSize)textStorageSizeForTextViewSize:(NSSize)textViewSize;
      +- (NSTabView *)tabView;
      @end


      @@ -61,6 +64,7 @@ enum {
      - (NSRect)tabBarFrameForFrame:(NSRect)frame
      {
      NSRect tabFrame = frame;
      +// tabFrame.origin.x = 0;
      tabFrame.origin.y = NSMaxY(tabFrame) - 22;
      tabFrame.size.height = 22;
      return tabFrame;
      @@ -237,18 +241,23 @@ enum {
      return [self contentSizeForTextStorageSize:[[self textStorage] size]];
      }

      -- (void)getDesiredRows:(int *)r columns:(int *)c forSize:(NSSize)size
      +- (NSSize)getDesiredRows:(int *)r columns:(int *)c forSize:(NSSize)size
      {
      NSSize textViewSize = [self textViewRectForContentSize:size].size;
      NSSize textStorageSize = [self textStorageSizeForTextViewSize:textViewSize];
      - [textStorage fitToSize:textStorageSize rows:r columns:c];
      + NSSize newSize = [textStorage fitToSize:textStorageSize rows:r columns:c];
      + return [self contentSizeForTextStorageSize:newSize];
      }

      - (void)getActualRows:(int *)r columns:(int *)c
      {
      - [textStorage getMaxRows:r columns:c];
      + [textStorage getMaxRows:r columns:c];
      }

      +- (void)setActualRows:(int)r columns:(int)c
      +{
      + [textStorage setMaxRows:r columns:c];
      +}

      - (IBAction)addNewTab:(id)sender
      {
      @@ -627,15 +636,11 @@ enum {
      NSRect textViewRect = [self textViewRectForContentSize:[self frame].size];

      // Give all superfluous space to the text view. It might be smaller or
      - // larger than it wants to, but this is needed during life resizing
      -// textViewRect.origin = [self textViewOrigin];
      -// textViewRect.size = [[self textStorage] size];
      + // larger than it wants to be, but this is needed during life resizing
      [[self textView] setFrame:textViewRect];

      - // for some reason, autoresizing doesn't work...
      + // for some reason, autoresizing doesn't work...set tab size manually
      [tabBarControl setFrame:[self tabBarFrameForFrame:[self frame]]];
      - //[tabBarControl update];
      -

      [self placeScrollbars];
      }
      @@ -670,6 +675,14 @@ enum {
      if ([self rightScrollbarVisible])
      size.width += [NSScroller scrollerWidth];

      +
      + NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
      + int right = [ud integerForKey:MMTextInsetRightKey];
      + int bot = [ud integerForKey:MMTextInsetBottomKey];
      +
      + size.width += [[self textView] textContainerOrigin].x + right;
      + size.height += [[self textView] textContainerOrigin].y + bot;
      +
      return size;
      }

      @@ -698,15 +711,12 @@ enum {
      {
      NSSize size = textViewSize;

      -// This screws stuff up of we want to calculate the rows/columns fitting in a
      -// rect, but it seems to be required when fitting the window to rows/columns?
      + NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
      + int right = [ud integerForKey:MMTextInsetRightKey];
      + int bot = [ud integerForKey:MMTextInsetBottomKey];

      -// NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
      -// int right = [ud integerForKey:MMTextInsetRightKey];
      -// int bot = [ud integerForKey:MMTextInsetBottomKey];
      -//
      -// size.width -= [[self textView] textContainerOrigin].x + right;
      -// size.height -= [[self textView] textContainerOrigin].y + bot;
      + size.width -= [[self textView] textContainerOrigin].x + right;
      + size.height -= [[self textView] textContainerOrigin].y + bot;

      return size;
      }
      diff --git a/src/MacVim/MMWindowController.m b/src/MacVim/MMWindowController.m
      index 766be82..c5c797e 100644
      --- a/src/MacVim/MMWindowController.m
      +++ b/src/MacVim/MMWindowController.m
      @@ -23,9 +23,8 @@

      @interface MMWindowController (Private)
      - (NSSize)contentSize;
      -- (NSSize)contentSizeForTextStorageSize:(NSSize)textViewSize;
      -- (NSRect)textViewRectForContentSize:(NSSize)contentSize;
      -- (NSSize)textStorageSizeForTextViewSize:(NSSize)textViewSize;
      +- (NSRect)contentRectForFrameRect:(NSRect)frame;
      +- (NSRect)frameRectForContentRect:(NSRect)contentRect;
      - (void)resizeWindowToFit:(id)sender;
      - (NSRect)fitWindowToFrame:(NSRect)frame;
      - (void)updateResizeIncrements;
      @@ -33,6 +32,7 @@
      - (IBAction)vimMenuItemAction:(id)sender;
      - (BOOL)askBackendForStarRegister:(NSPasteboard *)pb;
      - (void)checkWindowNeedsResizing;
      +- (NSSize)resizeVimViewToFitSize:(NSSize)size;
      @end


      @@ -210,7 +210,7 @@ NSMutableArray *buildMenuAddress(NSMenu *menu)
      {
      //NSLog(@"setTextDimensionsWithRows:%d columns:%d", rows, cols);

      - [[vimView textStorage] setMaxRows:rows columns:cols];
      + [vimView setActualRows:rows columns:cols];

      if (setupDone && ![vimView inLiveResize])
      shouldUpdateWindowSize = YES;
      @@ -263,6 +263,8 @@ NSMutableArray *buildMenuAddress(NSMenu *menu)

      - (void)processCommandQueueDidFinish
      {
      + // XXX: if not in live resize and vimviews desired size differs from actual
      + // size, resize ourselves
      if (shouldUpdateWindowSize) {
      shouldUpdateWindowSize = NO;
      [vimView setShouldUpdateWindowSize:NO];
      @@ -366,8 +368,6 @@ NSMutableArray *buildMenuAddress(NSMenu *menu)

      - (void)liveResizeDidEnd
      {
      - // TODO: Don't duplicate code from placeViews.
      -
      if (!setupDone) return;

      // XXX: clean this up
      @@ -426,7 +426,8 @@ NSMutableArray *buildMenuAddress(NSMenu *menu)

      NSRect vimViewRect;
      vimViewRect.origin = NSMakePoint(0, 0);
      - vimViewRect.size = [vimView desiredSize];
      + vimViewRect.size = [vimView getDesiredRows:NULL columns:NULL
      + forSize:[self contentSize]];
      [vimView setFrame:vimViewRect];
      }

      @@ -498,15 +499,6 @@ NSMutableArray *buildMenuAddress(NSMenu *menu)
      }
      }

      -- (NSSize)contentSize
      -{
      - NSWindow *win = [self window];
      - NSSize size = [win contentRectForFrameRect:[win frame]].size;
      - if (![tablineSeparator isHidden])
      - size.height -= 1;
      - return size;
      -}
      -
      - (void)windowDidResize:(id)sender
      {
      if (!setupDone) return;
      @@ -521,22 +513,7 @@ NSMutableArray *buildMenuAddress(NSMenu *menu)
      // resized text area.

      NSSize contentSize = [self contentSize];
      -
      - int desiredSize[2];
      - [vimView getDesiredRows:&desiredSize[0]
      - columns:&desiredSize[1]
      - forSize:contentSize];
      -
      - int rows, columns;
      - [vimView getActualRows:&rows columns:&columns];
      -
      - if (desiredSize[0] != rows || desiredSize[1] != columns) {
      - // NSLog(@"Notify Vim that text storage dimensions changed to %dx%d",
      - // desiredSize[0], desiredSize[1]);
      - NSData *data = [NSData dataWithBytes:desiredSize length:2*sizeof(int)];
      -
      - [vimController sendMessage:SetTextDimensionsMsgID data:data];
      - }
      + [self resizeVimViewToFitSize:contentSize];

      NSRect frame;
      frame.origin = NSMakePoint(0, 0);
      @@ -608,30 +585,32 @@ NSMutableArray *buildMenuAddress(NSMenu *menu)

      @implementation MMWindowController (Private)

      -- (NSSize)contentSizeForTextStorageSize:(NSSize)textViewSize
      +- (NSRect)contentRectForFrameRect:(NSRect)frame
      {
      - NSSize size = [vimView contentSizeForTextStorageSize:textViewSize];
      + NSRect result = [[self window] contentRectForFrameRect:frame];
      if (![tablineSeparator isHidden])
      - ++size.height;
      - return size;
      + --result.size.height;
      + return result;
      }

      -- (NSRect)textViewRectForContentSize:(NSSize)contentSize
      +- (NSRect)frameRectForContentRect:(NSRect)contentRect
      {
      - NSSize size = { contentSize.width, contentSize.height };
      if (![tablineSeparator isHidden])
      - --size.height;
      -
      - return [vimView textViewRectForContentSize:size];
      + ++contentRect.size.height;
      + return [[self window] frameRectForContentRect:contentRect];
      }

      -- (NSSize)textStorageSizeForTextViewSize:(NSSize)textViewSize
      +- (NSSize)contentSize
      {
      - return [vimView textStorageSizeForTextViewSize:textViewSize];
      + return [self contentRectForFrameRect:[[self window] frame]].size;
      }

      - (void)resizeWindowToFit:(id)sender
      {
      + // Makes the window large enough to contain the vim view, called after the
      + // vim view's size was changed. If the window had to become to big, the
      + // vim view is made smaller.
      +
      // 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.
      @@ -644,14 +623,14 @@ NSMutableArray *buildMenuAddress(NSMenu *menu)
      // Get size of text view, adapt window size to it
      NSWindow *win = [self window];
      NSRect frame = [win frame];
      - NSRect contentRect = [win contentRectForFrameRect:frame];
      + NSRect contentRect = [self contentRectForFrameRect:frame];
      NSSize newSize = [vimView desiredSize];

      // 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];
      + frame = [self frameRectForContentRect:contentRect];
      NSRect maxFrame = [win constrainFrameRect:frame toScreen:[win screen]];

      // HACK! Assuming the window frame cannot already be placed too high,
      @@ -668,9 +647,10 @@ NSMutableArray *buildMenuAddress(NSMenu *menu)
      // 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];
      + [self resizeVimViewToFitSize:frame.size];
      }

      - //NSLog(@"%s %@", _cmd, NSStringFromRect(frame));
      + // 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
      @@ -687,18 +667,15 @@ NSMutableArray *buildMenuAddress(NSMenu *menu)
      {
      if (!setupDone) return frame;

      - NSWindow *win = [self window];
      - NSRect contentRect = [win contentRectForFrameRect:frame];
      - NSSize size = [self textViewRectForContentSize:contentRect.size].size;
      - size = [self textStorageSizeForTextViewSize:size];
      - size = [[vimView textStorage] fitToSize:size];
      - size = [self contentSizeForTextStorageSize:size];
      + NSRect contentRect = [self contentRectForFrameRect:frame];
      + NSSize size = [vimView getDesiredRows:NULL columns:NULL
      + forSize:contentRect.size];

      // Keep top-left corner of 'frame' fixed.
      contentRect.origin.y -= size.height - contentRect.size.height;
      contentRect.size = size;

      - return [win frameRectForContentRect:contentRect];
      + return [self frameRectForContentRect:contentRect];
      }

      - (void)updateResizeIncrements
      @@ -747,4 +724,25 @@ NSMutableArray *buildMenuAddress(NSMenu *menu)
      shouldUpdateWindowSize || [vimView shouldUpdateWindowSize];
      }

      +- (NSSize)resizeVimViewToFitSize:(NSSize)size
      +{
      + int desired[2];
      + NSSize newSize = [vimView getDesiredRows:&desired[0] columns:&desired[1]
      + forSize:size];
      +
      + int rows, columns;
      + [vimView getActualRows:&rows columns:&columns];
      +
      + if (desired[0] != rows || desired[1] != columns) {
      + // NSLog(@"Notify Vim that text storage dimensions changed to %dx%d",
      + // desired[0], desired[1]);
      + NSData *data = [NSData dataWithBytes:desired length:2*sizeof(int)];
      +
      + [vimController sendMessage:SetTextDimensionsMsgID data:data];
      + }
      +
      + return newSize;
      +}
      +
      +
      @end // MMWindowController (Private)
      --
      1.5.3.4


      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_mac" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    Your message has been successfully submitted and would be delivered to recipients shortly.