From d77c1a9e206dd4deb255b82d7691c55dd0d4aa11 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Thu, 5 Feb 2009 20:26:05 -0500 Subject: [PATCH] Implement preferences window resizing * Source/PreferencesController.h: Add blankView ivar * Source/PreferencesController.m: Create private interface for resizing (init): Create the blankView (dealloc): New method (awakeFromNib): New method (showGeneral:): Call the resize method (showPaths:): ditto (resizeWindowToSize:): New private method --- Source/PreferencesController.h | 2 ++ Source/PreferencesController.m | 55 ++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/Source/PreferencesController.h b/Source/PreferencesController.h index bcb318c..989a011 100644 --- a/Source/PreferencesController.h +++ b/Source/PreferencesController.h @@ -21,6 +21,8 @@ { IBOutlet NSToolbar *toolbar; + NSView *blankView; + IBOutlet NSView *generalPreferencesView; IBOutlet NSToolbarItem *generalPreferencesItem; diff --git a/Source/PreferencesController.m b/Source/PreferencesController.m index 56b18af..0234ab4 100644 --- a/Source/PreferencesController.m +++ b/Source/PreferencesController.m @@ -16,6 +16,13 @@ #import "PreferencesController.h" +NSSize generalSize; +NSSize pathsSize; + +@interface PreferencesController (Private) +- (void)resizeWindowToSize:(NSSize)size; +@end + @implementation PreferencesController @@ -26,10 +33,29 @@ { if (self = [super initWithWindowNibName:@"Preferences"]) { + blankView = [[NSView alloc] init]; } return self; } +/** + * Destructor + */ +- (void)dealloc +{ + [blankView release]; + [super dealloc]; +} + +/** + * Awake from nib + */ +- (void)awakeFromNib +{ + generalSize = [generalPreferencesView frame].size; + pathsSize = [pathsPreferencesView frame].size; +} + /** * Shows the preferences controller window */ @@ -49,6 +75,8 @@ if ([[self window] contentView] == generalPreferencesView) return; + [self resizeWindowToSize:generalSize]; + [[self window] setContentView:generalPreferencesView]; [toolbar setSelectedItemIdentifier:[generalPreferencesItem itemIdentifier]]; } @@ -61,6 +89,8 @@ if ([[self window] contentView] == pathsPreferencesView) return; + [self resizeWindowToSize:pathsSize]; + [[self window] setContentView:pathsPreferencesView]; [toolbar setSelectedItemIdentifier:[pathsPreferencesItem itemIdentifier]]; } @@ -79,4 +109,29 @@ ]; } +#pragma mark Private + +/** + * Resizes the preferences window to be the size of the given preferences panel + */ +- (void)resizeWindowToSize:(NSSize)size +{ + [[self window] setContentView:blankView]; // don't want weird redraw artifacts + + NSRect newFrame; + + newFrame = [NSWindow contentRectForFrameRect:[[self window] frame] styleMask:[[self window] styleMask]]; + + float height = size.height + 50; + + newFrame.origin.y += newFrame.size.height; + newFrame.origin.y -= height; + newFrame.size.height = height; + newFrame.size.width = size.width; + + newFrame = [NSWindow frameRectForContentRect:newFrame styleMask:[[self window] styleMask]]; + + [[self window] setFrame:newFrame display:YES animate:YES]; +} + @end -- 2.43.5