Created
January 12, 2010 23:09
-
-
Save oleganza/275729 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void) updateToolOptionsView | |
{ | |
ToolOptionsViewController* optionsController = tool.optionsViewController; | |
// Stretch view frame according to autoresizing rules | |
// If the view is not stretched, there will be autosurprising | |
NSView* optionsView = [optionsController view]; | |
NSSize optionsSize = [optionsView frame].size; | |
NSSize targetSize = [[self.scrollView contentView] frame].size; | |
NSSize newOptionsSize = optionsSize; | |
NSUInteger autoresizingMask = [optionsView autoresizingMask]; | |
if (autoresizingMask & NSViewWidthSizable) | |
{ | |
newOptionsSize.width = targetSize.width; | |
} | |
if (autoresizingMask & NSViewHeightSizable) | |
{ | |
newOptionsSize.height = targetSize.height; | |
} | |
[optionsView setFrameSize:newOptionsSize]; | |
// Wrap the options view into a flipped view so that NSScrollView | |
// renders view from top to bottom as expected. | |
[self patchViewControllerWithFlippedViewIfNeeded:optionsController]; | |
[self.scrollView setDocumentView:[optionsController view]]; | |
} | |
- (void) patchViewControllerWithFlippedViewIfNeeded:(NSViewController*) controller | |
{ | |
NSView* myView = [controller view]; | |
// The view is already good or was already patched - do nothing. | |
if ([myView isFlipped]) return; | |
// MyViewFlipped is a subclass of NSView with a single method isFlipped returning YES | |
NSView* flippedWrapper = [[[MyViewFlipped alloc] initWithFrame:[myView frame]] autorelease]; | |
// Clone the existing autoresizingMask | |
[flippedWrapper setAutoresizingMask:[myView autoresizingMask]]; | |
[flippedWrapper setAutoresizesSubviews:YES]; | |
// And autoresize myView inside the wrapper | |
[myView setAutoresizingMask: | |
NSViewWidthSizable | | |
NSViewHeightSizable | | |
NSViewMinXMargin | | |
NSViewMaxXMargin | | |
NSViewMinYMargin | | |
NSViewMaxYMargin ]; | |
[myView setFrameOrigin:NSZeroPoint]; | |
// Replace the view | |
[flippedWrapper addSubview:myView]; | |
[controller setView:flippedWrapper]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment