From 1e6f0090dade9d18c01ff4065a39d77967fcd027 Mon Sep 17 00:00:00 2001 From: Darrell Walisser Date: Sun, 6 May 2012 12:06:23 -0400 Subject: [PATCH] -allow any window to become a sheet --- AppKit/CPWindow/CPWindow.j | 4 +- AppKit/CPWindow/_CPDocModalWindowView.j | 5 +++ AppKit/CPWindow/_CPHUDWindowView.j | 34 +++++++++++++++- AppKit/CPWindow/_CPStandardWindowView.j | 54 +++++++++++++++++++++---- AppKit/CPWindow/_CPWindowView.j | 19 +++++++++ 5 files changed, 106 insertions(+), 10 deletions(-) diff --git a/AppKit/CPWindow/CPWindow.j b/AppKit/CPWindow/CPWindow.j index fff020616..fb2b182e8 100644 --- a/AppKit/CPWindow/CPWindow.j +++ b/AppKit/CPWindow/CPWindow.j @@ -2395,7 +2395,7 @@ CPTexturedBackgroundWindowMask - (void)_endSheet { CPLog("%@ %@", [self class], _cmd); - + var sheet = _sheetContext["sheet"], delegate = _sheetContext["modalDelegate"], endSelector = _sheetContext["endSelector"]; @@ -2445,6 +2445,8 @@ CPTexturedBackgroundWindowMask [sheet orderOut:self]; + [sheet._windowView _enableSheet:NO]; + [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowDidEndSheetNotification object:self]; if (_nextSheetContext) diff --git a/AppKit/CPWindow/_CPDocModalWindowView.j b/AppKit/CPWindow/_CPDocModalWindowView.j index ae691300d..3758527e3 100644 --- a/AppKit/CPWindow/_CPDocModalWindowView.j +++ b/AppKit/CPWindow/_CPDocModalWindowView.j @@ -54,4 +54,9 @@ var _CPStandardWindowViewBodyBackgroundColor = nil; return aContentRect; } +- (void)_enableSheet:(BOOL)enable +{ + // do nothing, already a sheet +} + @end \ No newline at end of file diff --git a/AppKit/CPWindow/_CPHUDWindowView.j b/AppKit/CPWindow/_CPHUDWindowView.j index d84ad6e60..abb1385e5 100644 --- a/AppKit/CPWindow/_CPHUDWindowView.j +++ b/AppKit/CPWindow/_CPHUDWindowView.j @@ -208,8 +208,40 @@ var HUD_TITLEBAR_HEIGHT = 26.0; [_titleField setFrame:CGRectMake(20.0, 3.0, width - 40.0, CGRectGetHeight([_titleField frame]))]; var maxY = [self toolbarMaxY]; + if ([_titleField isHidden]) + maxY -= ([self toolbarOffset]).height; - [[theWindow contentView] setFrameOrigin:CGPointMake(0.0, maxY, width, CGRectGetHeight(bounds) - maxY)]; + //[[theWindow contentView] setFrameOrigin:CGPointMake(0.0, maxY, width, CGRectGetHeight(bounds) - maxY)]; + + var contentRect = CGRectMake(0.0, maxY, width, CGRectGetHeight(bounds) - maxY); + + [[theWindow contentView] setFrame:contentRect]; +} + +- (void)_enableSheet:(BOOL)enable +{ + [super _enableSheet:enable]; + + // convert window to "sheet mode" and back again + [_closeButton setHidden:enable]; + [_titleField setHidden:enable]; + + // resize the window + var window = [self window], + frame = [window frame]; + + var dy = ([self toolbarOffset]).height; + if (enable) + dy = -dy; + + var newHeight = CGRectGetMaxY(frame) + dy; + var newWidth = CGRectGetMaxX(frame); + frame.size.height += dy; + + [self setFrameSize:CGSizeMake(newWidth, newHeight)]; + [self tile]; + [window setFrame:frame display:NO animate:NO]; + [window setMovableByWindowBackground:!enable]; } @end diff --git a/AppKit/CPWindow/_CPStandardWindowView.j b/AppKit/CPWindow/_CPStandardWindowView.j index abd7e389d..91e81abd7 100644 --- a/AppKit/CPWindow/_CPStandardWindowView.j +++ b/AppKit/CPWindow/_CPStandardWindowView.j @@ -147,8 +147,11 @@ var STANDARD_GRADIENT_HEIGHT = 41.0, return _CPStandardWindowViewTitleBackgroundColor; } + + (CGRect)contentRectForFrameRect:(CGRect)aFrameRect { + CPLog("%@ %@: static", [self class], _cmd); + var contentRect = CGRectMakeCopy(aFrameRect), titleBarHeight = [self titleBarHeight] + 1.0; @@ -160,6 +163,8 @@ var STANDARD_GRADIENT_HEIGHT = 41.0, + (CGRect)frameRectForContentRect:(CGRect)aContentRect { + CPLog("%@ %@: static", [self class], _cmd); + var frameRect = CGRectMakeCopy(aContentRect), titleBarHeight = [self titleBarHeight] + 1.0; @@ -181,7 +186,7 @@ var STANDARD_GRADIENT_HEIGHT = 41.0, if ([theToolbar isVisible]) { - toolbarHeight = CGRectGetHeight([[theToolbar _toolbarView] frame]); + var toolbarHeight = CGRectGetHeight([[theToolbar _toolbarView] frame]); contentRect.origin.y += toolbarHeight; contentRect.size.height -= toolbarHeight; @@ -330,11 +335,13 @@ var STANDARD_GRADIENT_HEIGHT = 41.0, [_headView setFrameSize:CGSizeMake(width, [self toolbarMaxY])]; [_dividerView setFrame:CGRectMake(0.0, CGRectGetMaxY([_headView frame]), width, 1.0)]; - - var dividerMaxY = CGRectGetMaxY([_dividerView frame]); - + + var dividerMaxY = 0; + if (![_dividerView isHidden]) + dividerMaxY = CGRectGetMaxY([_dividerView frame]); + [_bodyView setFrame:CGRectMake(0.0, dividerMaxY, width, CGRectGetHeight(bounds) - dividerMaxY)]; - + var leftOffset = 8; if (_closeButton) @@ -344,7 +351,9 @@ var STANDARD_GRADIENT_HEIGHT = 41.0, [_titleField setFrame:CGRectMake(leftOffset, 5.0, width - leftOffset * 2.0, CGRectGetHeight([_titleField frame]))]; - [[theWindow contentView] setFrameOrigin:CGPointMake(0.0, CGRectGetMaxY([_dividerView frame]))]; + var contentRect = CGRectMake(0.0, dividerMaxY, width, CGRectGetHeight([_bodyView frame])); + + [[theWindow contentView] setFrame:contentRect]; } /* - (void)setAnimatingToolbar:(BOOL)isAnimatingToolbar @@ -401,10 +410,39 @@ var STANDARD_GRADIENT_HEIGHT = 41.0, - (void)mouseDown:(CPEvent)anEvent { - if (CGRectContainsPoint([_headView frame], [self convertPoint:[anEvent locationInWindow] fromView:nil])) - return [self trackMoveWithEvent:anEvent]; + if (![_headView isHidden]) + if (CGRectContainsPoint([_headView frame], [self convertPoint:[anEvent locationInWindow] fromView:nil])) + return [self trackMoveWithEvent:anEvent]; [super mouseDown:anEvent]; } +- (void)_enableSheet:(BOOL)enable +{ + [super _enableSheet:enable]; + + // convert window to "sheet mode" and back again + [_headView setHidden:enable]; + [_dividerView setHidden:enable]; + [_closeButton setHidden:enable]; + [_minimizeButton setHidden:enable]; + [_titleField setHidden:enable]; + + // resize the window + var window = [self window], + frame = [window frame]; + + var dy = CGRectGetHeight([_headView frame]) + CGRectGetHeight([_dividerView frame]); + if (enable) + dy = -dy; + + var newHeight = CGRectGetMaxY(frame) + dy; + var newWidth = CGRectGetMaxX(frame); + frame.size.height += dy; + + [self setFrameSize:CGSizeMake(newWidth, newHeight)]; + [self tile]; + [window setFrame:frame display:NO animate:NO]; +} + @end diff --git a/AppKit/CPWindow/_CPWindowView.j b/AppKit/CPWindow/_CPWindowView.j index fcf290d78..eaf52f12e 100644 --- a/AppKit/CPWindow/_CPWindowView.j +++ b/AppKit/CPWindow/_CPWindowView.j @@ -41,6 +41,8 @@ var _CPWindowViewResizeIndicatorImage = nil; CGPoint _mouseDraggedPoint; CGRect _cachedScreenFrame; + + CPView _sheetShadowView; } + (void)initialize @@ -380,4 +382,21 @@ var _CPWindowViewResizeIndicatorImage = nil; [self addSubview:_resizeIndicator]; } +- (void)_enableSheet:(BOOL)enable +{ + if (enable) + { + var bundle = [CPBundle bundleForClass:[CPWindow class]]; + _sheetShadowView = [[CPView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth([self bounds]), 8)]; + [_sheetShadowView setAutoresizingMask:CPViewWidthSizable]; + [_sheetShadowView setBackgroundColor:[CPColor colorWithPatternImage:[[CPImage alloc] + initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowAttachedSheetShadow.png"] size:CGSizeMake(9,8)]]]; + [self addSubview:_sheetShadowView]; + } + else + { + [_sheetShadowView removeFromSuperview]; + } +} + @end