diff --git a/AppKit/CPWindow/CPWindow.j b/AppKit/CPWindow/CPWindow.j index 0b0d1bee0..2c0c0693d 100644 --- a/AppKit/CPWindow/CPWindow.j +++ b/AppKit/CPWindow/CPWindow.j @@ -178,6 +178,9 @@ CPWindowDidResignMainNotification = @"CPWindowDidResignMainNotification"; CPWindowDidMoveNotification = @"CPWindowDidMoveNotification"; CPWindowWillBeginSheetNotification = @"CPWindowWillBeginSheetNotification"; CPWindowDidEndSheetNotification = @"CPWindowDidEndSheetNotification"; +CPWindowDidMiniaturizeNotification = @"CPWindowDidMiniaturizeNotification"; +CPWindowWillMiniaturizeNotification = @"CPWindowWillMiniaturizeNotification"; +CPWindowDidDeminiaturizeNotification = @"CPWindowDidDeminiaturizeNotification"; CPWindowShadowStyleStandard = 0; CPWindowShadowStyleMenu = 1; @@ -249,6 +252,7 @@ var CPWindowSaveImage = nil, CGRect _frame; int _level; BOOL _isVisible; + BOOL _isMiniaturized; BOOL _isAnimating; BOOL _hasShadow; BOOL _isMovableByWindowBackground; @@ -441,10 +445,10 @@ CPTexturedBackgroundWindowMask { if (aStyleMask & CPHUDBackgroundWindowMask) return _CPHUDWindowView; - + else if (aStyleMask === CPBorderlessWindowMask) return _CPBorderlessWindowView; - + else if (aStyleMask & CPDocModalWindowMask) return _CPDocModalWindowView; @@ -964,17 +968,17 @@ CPTexturedBackgroundWindowMask if (!_CPWindowShadowColor) { var bundle = [CPBundle bundleForClass:[CPWindow class]]; - + _CPWindowShadowColor = [CPColor colorWithPatternImage:[[CPNinePartImage alloc] initWithImageSlices: [ [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow0.png"] size:CGSizeMake(20.0, 19.0)], [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow1.png"] size:CGSizeMake(1.0, 19.0)], [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow2.png"] size:CGSizeMake(19.0, 19.0)], - + [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow3.png"] size:CGSizeMake(20.0, 1.0)], [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow4.png"] size:CGSizeMake(1.0, 1.0)], [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow5.png"] size:CGSizeMake(19.0, 1.0)], - + [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow6.png"] size:CGSizeMake(20.0, 18.0)], [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow7.png"] size:CGSizeMake(1.0, 18.0)], [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow8.png"] size:CGSizeMake(19.0, 18.0)] @@ -1249,33 +1253,33 @@ CPTexturedBackgroundWindowMask case CPLeftMouseUp: if (!_leftMouseDownView) return [[_windowView hitTest:point] mouseUp:anEvent]; - + [_leftMouseDownView mouseUp:anEvent] - + _leftMouseDownView = nil; - + return; case CPLeftMouseDown: _leftMouseDownView = [_windowView hitTest:point]; if (_leftMouseDownView != _firstResponder && [_leftMouseDownView acceptsFirstResponder]) [self makeFirstResponder:_leftMouseDownView]; - + var theWindow = [anEvent window]; - + if ([theWindow isKeyWindow] || [theWindow becomesKeyOnlyIfNeeded]) return [_leftMouseDownView mouseDown:anEvent]; else { // FIXME: delayed ordering? [self makeKeyAndOrderFront:self]; - + if ([_leftMouseDownView acceptsFirstMouse:anEvent]) return [_leftMouseDownView mouseDown:anEvent] } break; case CPLeftMouseDragged: if (!_leftMouseDownView) return [[_windowView hitTest:point] mouseDragged:anEvent]; - + return [_leftMouseDownView mouseDragged:anEvent]; case CPRightMouseUp: return [_rightMouseDownView mouseUp:anEvent]; @@ -1574,6 +1578,53 @@ CPTexturedBackgroundWindowMask } } +// Minimizing Windows + +/*! + Simulates the user minimizing the window, then minimizes the window. + @param aSender the object making this request +*/ +- (void)performMiniaturize:(id)aSender +{ + //FIXME show stuff + [self miniaturize:aSender]; +} + +/*! + Minimizes the window. Posts a \c CPWindowWillMiniaturizeNotification to the + notification center before minimizing the window. +*/ +- (void)miniaturize:(id)sender +{ + [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowWillMiniaturizeNotification object:self]; + + [[self platformWindow] miniaturize:sender]; + + [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowDidMiniaturizeNotification object:self]; + + _isMiniaturized = YES; +} + +/*! + Restores a mimized window to it's original size. +*/ +- (void)deminiaturize:(id)sender +{ + [[self platformWindow] deminiaturize:sender]; + + [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowDidDeminiaturizeNotification object:self]; + + _isMiniaturized = NO; +} + +/*! + Returns YES if the window is minimized. +*/ +- (void)isMiniaturized +{ + return _isMiniaturized; +} + // Closing Windows /*! @@ -1806,7 +1857,7 @@ CPTexturedBackgroundWindowMask var sheetContent = [sheet contentView]; [self _setUpMasksForView:sheetContent]; - + _sheetContext["opened"] = NO; [sheet _setFrame:endFrame delegate:self duration:0.2 curve:CPAnimationEaseIn]; } diff --git a/AppKit/CPWindow/_CPStandardWindowView.j b/AppKit/CPWindow/_CPStandardWindowView.j index c88da796b..5b100a2cc 100644 --- a/AppKit/CPWindow/_CPStandardWindowView.j +++ b/AppKit/CPWindow/_CPStandardWindowView.j @@ -98,7 +98,9 @@ var _CPStandardWindowViewBodyBackgroundColor = nil, _CPStandardWindowViewDividerBackgroundColor = nil, _CPStandardWindowViewTitleBackgroundColor = nil, _CPStandardWindowViewCloseButtonImage = nil, - _CPStandardWindowViewCloseButtonHighlightedImage = nil; + _CPStandardWindowViewCloseButtonHighlightedImage = nil, + _CPStandardWindowViewMinimizeButtonImage = nil, + _CPStandardWindowViewMinimizeButtonHighlightedImage = nil; var STANDARD_GRADIENT_HEIGHT = 41.0; STANDARD_TITLEBAR_HEIGHT = 25.0; @@ -112,6 +114,7 @@ var STANDARD_GRADIENT_HEIGHT = 41.0; CPTextField _titleField; CPButton _closeButton; + CPButton _minimizeButton; } + (CPColor)bodyBackgroundColor @@ -230,7 +233,7 @@ var STANDARD_GRADIENT_HEIGHT = 41.0; [_bodyView setHitTests:NO]; [self addSubview:_bodyView]; - + [self setResizeIndicatorOffset:CGSizeMake(2.0, 2.0)]; _titleField = [[CPTextField alloc] initWithFrame:CGRectMakeZero()]; @@ -256,24 +259,44 @@ var STANDARD_GRADIENT_HEIGHT = 41.0; if (!_CPStandardWindowViewCloseButtonImage) { var bundle = [CPBundle bundleForClass:[CPWindow class]]; - + _CPStandardWindowViewCloseButtonImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/Standard/CPWindowStandardCloseButton.png"] size:CGSizeMake(16.0, 16.0)]; _CPStandardWindowViewCloseButtonHighlightedImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/Standard/CPWindowStandardCloseButtonHighlighted.png"] size:CGSizeMake(16.0, 16.0)]; } - + _closeButton = [[CPButton alloc] initWithFrame:CGRectMake(8.0, 7.0, 16.0, 16.0)]; - + [_closeButton setBordered:NO]; - + [_closeButton setImage:_CPStandardWindowViewCloseButtonImage]; [_closeButton setAlternateImage:_CPStandardWindowViewCloseButtonHighlightedImage]; - + [self addSubview:_closeButton]; } - + + if (_styleMask & CPMiniaturizableWindowMask && ![CPPlatform isBrowser]) + { + if (!_CPStandardWindowViewMinimizeButtonImage) + { + var bundle = [CPBundle bundleForClass:[CPWindow class]]; + + _CPStandardWindowViewMinimizeButtonImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/Standard/CPWindowStandardMinimizeButton.png"] size:CGSizeMake(16.0, 16.0)]; + _CPStandardWindowViewMinimizeButtonHighlightedImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/Standard/CPWindowStandardMinimizeButtonHighlighted.png"] size:CGSizeMake(16.0, 16.0)]; + } + + _minimizeButton = [[CPButton alloc] initWithFrame:CGRectMake(27.0, 7.0, 16.0, 16.0)]; + + [_minimizeButton setBordered:NO]; + + [_minimizeButton setImage:_CPStandardWindowViewMinimizeButtonImage]; + [_minimizeButton setAlternateImage:_CPStandardWindowViewMinimizeButtonHighlightedImage]; + + [self addSubview:_minimizeButton]; + } + [self tile]; } - + return self; } @@ -281,6 +304,9 @@ var STANDARD_GRADIENT_HEIGHT = 41.0; { [_closeButton setTarget:[self window]]; [_closeButton setAction:@selector(performClose:)]; + + [_minimizeButton setTarget:[self window]]; + [_minimizeButton setAction:@selector(performMiniaturize:)]; } - (CGSize)toolbarOffset @@ -303,7 +329,14 @@ var STANDARD_GRADIENT_HEIGHT = 41.0; [_bodyView setFrame:CGRectMake(0.0, dividerMaxY, width, CGRectGetHeight(bounds) - dividerMaxY)]; - [_titleField setFrame:CGRectMake(10.0, 3.0, width - 20.0, CGRectGetHeight([_titleField frame]))]; + var leftOffset = 8; + + if (_closeButton) + leftOffset += 19.0; + if (_minimizeButton) + leftOffset += 19.0; + + [_titleField setFrame:CGRectMake(leftOffset, 5.0, width - leftOffset*2.0, CGRectGetHeight([_titleField frame]))]; [[theWindow contentView] setFrameOrigin:CGPointMake(0.0, CGRectGetMaxY([_dividerView frame]))]; } diff --git a/AppKit/Platform/CPPlatformWindow.j b/AppKit/Platform/CPPlatformWindow.j index c0194a7f9..5ad005aad 100644 --- a/AppKit/Platform/CPPlatformWindow.j +++ b/AppKit/Platform/CPPlatformWindow.j @@ -149,6 +149,22 @@ var PrimaryPlatformWindow = NULL; #endif } +- (void)deminiaturize:(id)sender +{ +#if PLATFORM(DOM) + if (_DOMWindow && typeof _DOMWindow["cpDeminiaturize"] === "function") + _DOMWindow.cpDeminiaturize(); +#endif +} + +- (void)miniaturize:(id)sender +{ +#if PLATFORM(DOM) + if (_DOMWindow && typeof _DOMWindow["cpMiniaturize"] === "function") + _DOMWindow.cpMiniaturize(); +#endif +} + - (void)setLevel:(CPInteger)aLevel { _level = aLevel; diff --git a/AppKit/Resources/CPWindow/Standard/CPWindowStandardCloseButtonUnsaved.png b/AppKit/Resources/CPWindow/Standard/CPWindowStandardCloseButtonUnsaved.png new file mode 100644 index 000000000..2cb0e4929 Binary files /dev/null and b/AppKit/Resources/CPWindow/Standard/CPWindowStandardCloseButtonUnsaved.png differ diff --git a/AppKit/Resources/CPWindow/Standard/CPWindowStandardCloseButtonUnsavedHighlighted.png b/AppKit/Resources/CPWindow/Standard/CPWindowStandardCloseButtonUnsavedHighlighted.png new file mode 100644 index 000000000..29e0bd19e Binary files /dev/null and b/AppKit/Resources/CPWindow/Standard/CPWindowStandardCloseButtonUnsavedHighlighted.png differ diff --git a/AppKit/Resources/CPWindow/Standard/CPWindowStandardMaximizeButton.png b/AppKit/Resources/CPWindow/Standard/CPWindowStandardMaximizeButton.png new file mode 100644 index 000000000..403ea85eb Binary files /dev/null and b/AppKit/Resources/CPWindow/Standard/CPWindowStandardMaximizeButton.png differ diff --git a/AppKit/Resources/CPWindow/Standard/CPWindowStandardMaximizeButtonHighlighted.png b/AppKit/Resources/CPWindow/Standard/CPWindowStandardMaximizeButtonHighlighted.png new file mode 100644 index 000000000..77f0a58ad Binary files /dev/null and b/AppKit/Resources/CPWindow/Standard/CPWindowStandardMaximizeButtonHighlighted.png differ diff --git a/AppKit/Resources/CPWindow/Standard/CPWindowStandardMinimizeButton.png b/AppKit/Resources/CPWindow/Standard/CPWindowStandardMinimizeButton.png new file mode 100644 index 000000000..9b462b25b Binary files /dev/null and b/AppKit/Resources/CPWindow/Standard/CPWindowStandardMinimizeButton.png differ diff --git a/AppKit/Resources/CPWindow/Standard/CPWindowStandardMinimizeButtonHighlighted.png b/AppKit/Resources/CPWindow/Standard/CPWindowStandardMinimizeButtonHighlighted.png new file mode 100644 index 000000000..d4136ec38 Binary files /dev/null and b/AppKit/Resources/CPWindow/Standard/CPWindowStandardMinimizeButtonHighlighted.png differ