Make preferences window resizable.

This is only done when the content view has either a resizable width or height.

The minimum and maximum sizes are hardcoded. I think leaving the maximum size as CGFLOAT_MAX × CGFLOAT_MAX is fine, but minimum size should probably be the initial frame size of the content view (until we require Lion and can leverage the new constraint based layout engine).
This commit is contained in:
Allan Odgaard 2011-10-06 14:28:28 +02:00
Родитель 6948116d82
Коммит 3fa4fd3ebc
2 изменённых файлов: 13 добавлений и 13 удалений

Просмотреть файл

@ -38,7 +38,7 @@
<string key="NSClassName">NSApplication</string>
</object>
<object class="NSWindowTemplate" id="1005">
<int key="NSWindowStyleMask">3</int>
<int key="NSWindowStyleMask">11</int>
<int key="NSWindowBacking">2</int>
<string key="NSWindowRect">{{540, 400}, {360, 270}}</string>
<int key="NSWTFlags">1618478080</int>

Просмотреть файл

@ -195,25 +195,25 @@ NSString *const kMASPreferencesWindowControllerDidChangeViewNotification = @"MAS
// Retrieve the view to place into window
NSView *controllerView = controller.view;
// Calculate changes for window size and position
NSSize controllerViewSize = controllerView.bounds.size;
NSView *contentView = self.window.contentView;
NSSize contentSize = contentView.bounds.size;
CGFloat widthChange = contentSize.width - controllerViewSize.width;
CGFloat heightChange = contentSize.height - controllerViewSize.height;
// Calculate new window size and position
NSRect windowFrame = self.window.frame;
windowFrame.size.width -= widthChange;
windowFrame.size.height -= heightChange;
windowFrame.origin.y += heightChange;
NSRect oldFrame = [self.window frame];
NSRect newFrame = [self.window frameRectForContentRect:controllerView.bounds];
newFrame = NSOffsetRect(newFrame, NSMinX(oldFrame), NSMaxY(oldFrame) - NSMaxY(newFrame));
// Setup min/max sizes and show/hide resize indicator
BOOL sizableWidth = [controllerView autoresizingMask] & NSViewWidthSizable;
BOOL sizableHeight = [controllerView autoresizingMask] & NSViewHeightSizable;
[self.window setContentMinSize:NSMakeSize(sizableWidth ? 200 : NSWidth(controllerView.bounds), sizableHeight ? 200 : NSHeight(controllerView.bounds))];
[self.window setContentMaxSize:NSMakeSize(sizableWidth ? CGFLOAT_MAX : NSWidth(controllerView.bounds), sizableHeight ? CGFLOAT_MAX : NSHeight(controllerView.bounds))];
[self.window setShowsResizeIndicator:sizableWidth || sizableHeight];
// Place the view into window and perform reposition
NSView *contentView = self.window.contentView;
NSArray *subviews = [contentView.subviews retain];
for (NSView *subview in contentView.subviews)
[subview removeFromSuperviewWithoutNeedingDisplay];
[subviews release];
[self.window setFrame:windowFrame display:YES animate:animate];
[self.window setFrame:newFrame display:YES animate:animate];
if ([_lastSelectedController respondsToSelector:@selector(viewDidDisappear)])
[_lastSelectedController viewDidDisappear];