diff --git a/AppKit/CPApplication.j b/AppKit/CPApplication.j index f276ebd74..7e5b948f1 100644 --- a/AppKit/CPApplication.j +++ b/AppKit/CPApplication.j @@ -40,6 +40,10 @@ CPApp = nil; CPApplicationWillFinishLaunchingNotification = @"CPApplicationWillFinishLaunchingNotification"; CPApplicationDidFinishLaunchingNotification = @"CPApplicationDidFinishLaunchingNotification"; CPApplicationWillTerminateNotification = @"CPApplicationWillTerminateNotification"; +CPApplicationWillBecomeActiveNotification = @"CPApplicationWillBecomeActiveNotification"; +CPApplicationDidBecomeActiveNotification = @"CPApplicationDidBecomeActiveNotification"; +CPApplicationWillResignActiveNotification = @"CPApplicationWillResignActiveNotification"; +CPApplicationDidResignActiveNotification = @"CPApplicationDidResignActiveNotification"; CPTerminateNow = YES; CPTerminateCancel = NO; @@ -83,6 +87,8 @@ CPRunContinuesResponse = -1002; CPArray _windows; CPWindow _keyWindow; CPWindow _mainWindow; + CPWindow _previousKeyWindow; + CPWindow _previousMainWindow; CPMenu _mainMenu; CPDocumentController _documentController; @@ -92,6 +98,7 @@ CPRunContinuesResponse = -1002; // id _delegate; BOOL _finishedLaunching; + BOOL _isActive; CPDictionary _namedArgs; CPArray _args; @@ -219,6 +226,26 @@ CPRunContinuesResponse = -1002; removeObserver:_delegate name:CPApplicationDidFinishLaunchingNotification object:self]; + + [defaultCenter + removeObserver:_delegate + name:CPApplicationWillBecomeActiveNotification + object:self]; + + [defaultCenter + removeObserver:_delegate + name:CPApplicationDidBecomeActiveNotification + object:self]; + + [defaultCenter + removeObserver:_delegate + name:CPApplicationWillResignActiveNotification + object:self]; + + [defaultCenter + removeObserver:_delegate + name:CPApplicationDidResignActiveNotification + object:self]; } _delegate = aDelegate; @@ -236,6 +263,34 @@ CPRunContinuesResponse = -1002; selector:@selector(applicationDidFinishLaunching:) name:CPApplicationDidFinishLaunchingNotification object:self]; + + if ([_delegate respondsToSelector:@selector(applicationWillBecomeActive:)]) + [defaultCenter + addObserver:_delegate + selector:@selector(applicationWillBecomeActive:) + name:CPApplicationWillBecomeActiveNotification + object:self]; + + if ([_delegate respondsToSelector:@selector(applicationDidBecomeActive:)]) + [defaultCenter + addObserver:_delegate + selector:@selector(applicationDidBecomeActive:) + name:CPApplicationDidBecomeActiveNotification + object:self]; + + if ([_delegate respondsToSelector:@selector(applicationWillResignActive:)]) + [defaultCenter + addObserver:_delegate + selector:@selector(applicationWillResignActive:) + name:CPApplicationWillResignActiveNotification + object:self]; + + if ([_delegate respondsToSelector:@selector(applicationDidResignActive:)]) + [defaultCenter + addObserver:_delegate + selector:@selector(applicationDidResignActive:) + name:CPApplicationDidResignActiveNotification + object:self]; } /*! @@ -419,7 +474,27 @@ CPRunContinuesResponse = -1002; - (void)activateIgnoringOtherApps:(BOOL)shouldIgnoreOtherApps { + [self _willBecomeActive]; + [CPPlatform activateIgnoringOtherApps:shouldIgnoreOtherApps]; + _isActive = YES; + + [self _willResignActive]; +} + +- (void)deactivate +{ + [self _willResignActive]; + + [CPPlatform deactivate]; + _isActive = NO; + + [self _didResignActive]; +} + +- (void)isActive +{ + return _isActive; } - (void)hideOtherApplications:(id)aSender @@ -624,6 +699,14 @@ CPRunContinuesResponse = -1002; return _windows; } +/*! + Returns an array of visible CPWindow objects, ordered by their front to back order on the screen. +*/ +- (CPArray)orderedWindows +{ + return CPWindowObjectList(); +} + - (void)hide:(id)aSender { [CPPlatform hide:self]; @@ -953,10 +1036,65 @@ CPRunContinuesResponse = -1002; return !![_documentController openDocumentWithContentsOfURL:aURL display:YES error:NULL]; } +- (void)_willBecomeActive +{ + [[CPNotificationCenter defaultCenter] postNotificationName:CPApplicationWillBecomeActiveNotification + object:self + userInfo:nil]; +} + +- (void)_didBecomeActive +{ + if (![self keyWindow] && _previousKeyWindow && + [[self windows] indexOfObjectIdenticalTo:_previousKeyWindow] !== CPNotFound) + [_previousKeyWindow makeKeyWindow]; + + if (![self mainWindow] && _previousMainWindow && + [[self windows] indexOfObjectIdenticalTo:_previousMainWindow] !== CPNotFound) + [_previousMainWindow makeMainWindow]; + + if ([self keyWindow]) + [[self keyWindow] orderFront:self]; + else if ([self mainWindow]) + [[self mainWindow] makeKeyAndOrderFront:self]; + else + [[[self mainMenu] window] makeKeyWindow]; //FIXME this may not actually work + + _previousKeyWindow = nil; + _previousMainWindow = nil; + + [[CPNotificationCenter defaultCenter] postNotificationName:CPApplicationDidBecomeActiveNotification + object:self + userInfo:nil]; +} + +- (void)_willResignActive +{ + [[CPNotificationCenter defaultCenter] postNotificationName:CPApplicationWillResignActiveNotification + object:self + userInfo:nil]; +} + - (void)_didResignActive { if (self._activeMenu) [self._activeMenu cancelTracking]; + + if ([self keyWindow]) + { + _previousKeyWindow = [self keyWindow]; + [_previousKeyWindow resignKeyWindow]; + } + + if ([self mainWindow]) + { + _previousMainWindow = [self mainWindow]; + [_previousMainWindow resignMainWindow]; + } + + [[CPNotificationCenter defaultCenter] postNotificationName:CPApplicationDidResignActiveNotification + object:self + userInfo:nil]; } + (CPString)defaultThemeName diff --git a/AppKit/CPCursor.j b/AppKit/CPCursor.j index f5e67f692..95b1dc79a 100755 --- a/AppKit/CPCursor.j +++ b/AppKit/CPCursor.j @@ -230,8 +230,6 @@ var currentCursor = nil, + (void)_setCursorCSS:(CPString)aString { #if PLATFORM(DOM) - [CPPlatformWindow primaryPlatformWindow]._DOMBodyElement.style.cursor = aString; - var platformWindows = [[CPPlatformWindow visiblePlatformWindows] allObjects]; for (var i = 0, count = [platformWindows count]; i < count; i++) platformWindows[i]._DOMBodyElement.style.cursor = aString; diff --git a/AppKit/CPImageView.j b/AppKit/CPImageView.j index ed6eeea42..817ffbd0b 100644 --- a/AppKit/CPImageView.j +++ b/AppKit/CPImageView.j @@ -31,24 +31,10 @@ #include "CoreGraphics/CGGeometry.h" - -/* - @global - @group CPImageScaling -*/ CPScaleProportionally = 0; -/* - @global - @group CPImageScaling -*/ CPScaleToFit = 1; -/* - @global - @group CPImageScaling -*/ CPScaleNone = 2; - var CPImageViewShadowBackgroundColor = nil; var LEFT_SHADOW_INSET = 3.0, @@ -225,6 +211,11 @@ var LEFT_SHADOW_INSET = 3.0, [self setNeedsDisplay:YES]; } +- (unsigned)imageScaling +{ + return [self currentValueForThemeAttribute:@"image-scaling"]; +} + /*! Toggles the display of the image view. */ diff --git a/AppKit/CPMenuItem/_CPMenuItemMenuBarView.j b/AppKit/CPMenuItem/_CPMenuItemMenuBarView.j index 6e232fef8..6342ef99e 100644 --- a/AppKit/CPMenuItem/_CPMenuItemMenuBarView.j +++ b/AppKit/CPMenuItem/_CPMenuItemMenuBarView.j @@ -155,7 +155,7 @@ var SelectionColor = nil, { // FIXME: This should probably be even throw. if (![_menuItem isEnabled]) - return; + shouldHighlight = NO; if (shouldHighlight) { diff --git a/AppKit/CPTextField.j b/AppKit/CPTextField.j index bb883ac70..e70984296 100644 --- a/AppKit/CPTextField.j +++ b/AppKit/CPTextField.j @@ -483,6 +483,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder"); window.setTimeout(function() { element.focus(); + [self textDidFocus:[CPNotification notificationWithName:CPTextFieldDidFocusNotification object:self userInfo:nil]]; CPTextFieldInputOwner = self; }, 0.0); @@ -500,8 +501,6 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder"); [[self window] platformWindow]._DOMBodyElement.ondrag = function () {}; [[self window] platformWindow]._DOMBodyElement.onselectstart = function () {}; } - - [self textDidFocus:[CPNotification notificationWithName:CPTextFieldDidFocusNotification object:self userInfo:nil]]; #endif return YES; diff --git a/AppKit/CPTheme.j b/AppKit/CPTheme.j index 499aaa8f7..77bac886d 100644 --- a/AppKit/CPTheme.j +++ b/AppKit/CPTheme.j @@ -22,7 +22,7 @@ @import @import - +@import var CPThemesByName = { }, CPThemeDefaultTheme = nil; diff --git a/AppKit/CPWindow/CPWindow.j b/AppKit/CPWindow/CPWindow.j index 3f506889d..e68c33174 100644 --- a/AppKit/CPWindow/CPWindow.j +++ b/AppKit/CPWindow/CPWindow.j @@ -175,6 +175,8 @@ CPWindowBelow = 2; CPWindowWillCloseNotification = @"CPWindowWillCloseNotification"; CPWindowDidBecomeMainNotification = @"CPWindowDidBecomeMainNotification"; CPWindowDidResignMainNotification = @"CPWindowDidResignMainNotification"; +CPWindowDidBecomeKeyNotification = @"CPWindowDidBecomeKeyNotification"; +CPWindowDidResignKeyNotification = @"CPWindowDidResignKeyNotification"; CPWindowDidResizeNotification = @"CPWindowDidResizeNotification"; CPWindowDidMoveNotification = @"CPWindowDidMoveNotification"; CPWindowWillBeginSheetNotification = @"CPWindowWillBeginSheetNotification"; @@ -762,12 +764,7 @@ CPTexturedBackgroundWindowMask [_platformWindow order:CPWindowOut window:self relativeTo:nil]; - if ([CPApp keyWindow] == self) - { - [self resignKeyWindow]; - - CPApp._keyWindow = nil; - } + [self _updateMainAndKeyWindows]; } /*! @@ -1066,13 +1063,31 @@ CPTexturedBackgroundWindowMask */ - (void)setDelegate:(id)aDelegate { - // FIXME: Unregister for notifications! + var defaultCenter = [CPNotificationCenter defaultCenter]; + + [defaultCenter removeObserver:_delegate name:CPWindowDidResignKeyNotification object:self]; + [defaultCenter removeObserver:_delegate name:CPWindowDidBecomeKeyNotification object:self]; + [defaultCenter removeObserver:_delegate name:CPWindowDidBecomeMainNotification object:self]; + [defaultCenter removeObserver:_delegate name:CPWindowDidResignMainNotification object:self]; + [defaultCenter removeObserver:_delegate name:CPWindowDidMoveNotification object:self]; + [defaultCenter removeObserver:_delegate name:CPWindowDidResizeNotification object:self]; _delegate = aDelegate; - _delegateRespondsToWindowWillReturnUndoManagerSelector = [_delegate respondsToSelector:@selector(windowWillReturnUndoManager:)]; - var defaultCenter = [CPNotificationCenter defaultCenter]; + if ([_delegate respondsToSelector:@selector(windowDidResignKey:)]) + [defaultCenter + addObserver:_delegate + selector:@selector(windowDidResignKey:) + name:CPWindowDidResignKeyNotification + object:self]; + + if ([_delegate respondsToSelector:@selector(windowDidBecomeKey:)]) + [defaultCenter + addObserver:_delegate + selector:@selector(windowDidBecomeKey:) + name:CPWindowDidBecomeKeyNotification + object:self]; if ([_delegate respondsToSelector:@selector(windowDidBecomeMain:)]) [defaultCenter @@ -1418,8 +1433,14 @@ CPTexturedBackgroundWindowMask */ - (void)becomeKeyWindow { - if (_firstResponder != self && [_firstResponder respondsToSelector:@selector(becomeKeyWindow)]) + CPApp._keyWindow = self; + + if (_firstResponder !== self && [_firstResponder respondsToSelector:@selector(becomeKeyWindow)]) [_firstResponder becomeKeyWindow]; + + [[CPNotificationCenter defaultCenter] + postNotificationName:CPWindowDidBecomeKeyNotification + object:self]; } /*! @@ -1456,13 +1477,10 @@ CPTexturedBackgroundWindowMask */ - (void)makeKeyWindow { - if (![self canBecomeKeyWindow]) + if ([CPApp keyWindow] === self || ![self canBecomeKeyWindow]) return; - [CPApp._keyWindow resignKeyWindow]; - - CPApp._keyWindow = self; - + [[CPApp keyWindow] resignKeyWindow]; [self becomeKeyWindow]; } @@ -1473,9 +1491,12 @@ CPTexturedBackgroundWindowMask { if (_firstResponder != self && [_firstResponder respondsToSelector:@selector(resignKeyWindow)]) [_firstResponder resignKeyWindow]; - - if ([_delegate respondsToSelector:@selector(windowDidResignKey:)]) - [_delegate windowDidResignKey:self]; + + CPApp._keyWindow = nil; + + [[CPNotificationCenter defaultCenter] + postNotificationName:CPWindowDidResignKeyNotification + object:self]; } /*! @@ -1664,6 +1685,8 @@ CPTexturedBackgroundWindowMask [[self platformWindow] miniaturize:sender]; + [self _updateMainAndKeyWindows]; + [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowDidMiniaturizeNotification object:self]; _isMiniaturized = YES; @@ -1799,13 +1822,10 @@ CPTexturedBackgroundWindowMask */ - (void)makeMainWindow { - if (CPApp._mainWindow === self || ![self canBecomeMainWindow]) + if ([CPApp mainWindow] === self || ![self canBecomeMainWindow]) return; - [CPApp._mainWindow resignMainWindow]; - - CPApp._mainWindow = self; - + [[CPApp mainWindow] resignMainWindow]; [self becomeMainWindow]; } @@ -1814,9 +1834,11 @@ CPTexturedBackgroundWindowMask */ - (void)becomeMainWindow { + CPApp._mainWindow = self; + [self _synchronizeMenuBarTitleWithWindowTitle]; [self _synchronizeSaveMenuWithDocumentSaving]; - + [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowDidBecomeMainNotification object:self]; @@ -1830,6 +1852,71 @@ CPTexturedBackgroundWindowMask [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowDidResignMainNotification object:self]; + + CPApp._mainWindow = nil; +} + +- (void)_updateMainAndKeyWindows +{ + var allWindows = [CPApp orderedWindows], + windowCount = [allWindows count]; + + if (!windowCount) + return; + + if ([self isKeyWindow]) + { + var keyWindow = [CPApp keyWindow]; + [self resignKeyWindow]; + + if (keyWindow && keyWindow !== self && [keyWindow canBecomeKeyWindow]) + [keyWindow makeKeyWindow]; + else + { + var menuWindow = [CPApp mainMenu]._menuWindow; + for (var i = 0; i < windowCount; i++) + { + var currentWindow = allWindows[i]; + if (currentWindow === self || currentWindow === menuWindow) + continue; + + if ([currentWindow isVisible] && [currentWindow canBecomeKeyWindow]) + { + [currentWindow makeKeyWindow]; + break; + } + } + + if (![CPApp keyWindow]) + [keyWindow makeKeyWindow]; + } + } + + + if ([self isMainWindow]) + { + var mainWindow = [CPApp mainWindow]; + [self resignMainWindow]; + + if (mainWindow && mainWindow !== self && [mainWindow canBecomeMainWindow]) + [mainWindow makeMainWindow]; + else + { + var menuWindow = [CPApp mainMenu]._menuWindow; + for (var i = 0; i < windowCount; i++) + { + var currentWindow = allWindows[i]; + if (currentWindow === self || currentWindow === menuWindow) + continue; + + if ([currentWindow isVisible] && [currentWindow canBecomeMainWindow]) + { + [currentWindow makeMainWindow]; + break; + } + } + } + } } // Managing Toolbars diff --git a/AppKit/Platform/CPPlatform.j b/AppKit/Platform/CPPlatform.j index 8bf37856e..db2128810 100644 --- a/AppKit/Platform/CPPlatform.j +++ b/AppKit/Platform/CPPlatform.j @@ -58,6 +58,10 @@ { } ++ (void)deactivate +{ +} + + (void)hideOtherApplications:(id)aSender { } diff --git a/AppKit/Platform/DOM/CPPlatform.j b/AppKit/Platform/DOM/CPPlatform.j index 96c7a30bf..98d7ca02e 100644 --- a/AppKit/Platform/DOM/CPPlatform.j +++ b/AppKit/Platform/DOM/CPPlatform.j @@ -69,6 +69,12 @@ var screenNeedsInitialization = NO, window.cpActivateIgnoringOtherApps(!!shouldIgnoreOtherApps); } ++ (void)deactivate +{ + if (typeof window["cpDeactivate"] === "function") + window.cpDeactivate(); +} + + (void)hideOtherApplications:(id)aSender { if (typeof window["cpHideOtherApplications"] === "function") diff --git a/AppKit/Platform/DOM/CPPlatformWindow+DOM.j b/AppKit/Platform/DOM/CPPlatformWindow+DOM.j index e6cff4912..1e7f8d835 100644 --- a/AppKit/Platform/DOM/CPPlatformWindow+DOM.j +++ b/AppKit/Platform/DOM/CPPlatformWindow+DOM.j @@ -426,7 +426,14 @@ var supportsNativeDragAndDrop = [CPPlatform supportsDragAndDrop]; + (CPSet)visiblePlatformWindows { - return PlatformWindows; + if ([[CPPlatformWindow primaryPlatformWindow] isVisible]) + { + var set = [CPSet setWithSet:PlatformWindows]; + [set addObject:[CPPlatformWindow primaryPlatformWindow]]; + return set; + } + else + return PlatformWindows; } - (void)orderFront:(id)aSender @@ -1374,19 +1381,25 @@ var CPDOMEventStop = function(aDOMEvent, aPlatformWindow) function CPWindowObjectList() { - var platformWindow = [CPPlatformWindow primaryPlatformWindow], - levels = platformWindow._windowLevels, - layers = platformWindow._windowLayers, - levelCount = levels.length, + var platformWindows = [CPPlatformWindow visiblePlatformWindows], + platformWindowEnumerator = [platformWindows objectEnumerator], + platformWindow = nil, windowObjects = []; - while (levelCount--) + while (platformWindow = [platformWindowEnumerator nextObject]) { - var windows = [layers objectForKey:levels[levelCount]]._windows, - windowCount = windows.length; + var levels = platformWindow._windowLevels, + layers = platformWindow._windowLayers, + levelCount = levels.length; - while (windowCount--) - windowObjects.push(windows[windowCount]); + while (levelCount--) + { + var windows = [layers objectForKey:levels[levelCount]]._windows, + windowCount = windows.length; + + while (windowCount--) + windowObjects.push(windows[windowCount]); + } } return windowObjects; @@ -1394,20 +1407,11 @@ function CPWindowObjectList() function CPWindowList() { - var platformWindow = [CPPlatformWindow primaryPlatformWindow], - levels = platformWindow._windowLevels, - layers = platformWindow._windowLayers, - levelCount = levels.length, - windowNumbers = []; + var windowObjectList = CPWindowObjectList(), + windowList = []; - while (levelCount--) - { - var windows = [layers objectForKey:levels[levelCount]]._windows, - windowCount = windows.length; + for (var i = 0, count = [windowObjectList count]; i < count; i++) + windowList.push([windowObjectList[i] windowNumber]); - while (windowCount--) - windowNumbers.push([windows[windowCount] windowNumber]); - } - - return windowNumbers; + return windowList; } diff --git a/Objective-J/Preprocessor.js b/Objective-J/Preprocessor.js index e07ccf75a..51bcd4bae 100644 --- a/Objective-J/Preprocessor.js +++ b/Objective-J/Preprocessor.js @@ -855,7 +855,7 @@ Preprocessor.prototype.preprocess = function(tokens, /*StringBuffer*/ aStringBuf // If we get this far and we're parsing an objj_msgSend (or array), then we have a problem. if (tuple) - new SyntaxError(this.error_message("*** Expected ']' - Unterminated message send or array.")); + throw new SyntaxError(this.error_message("*** Expected ']' - Unterminated message send or array.")); if (!aStringBuffer) return buffer; diff --git a/Tools/nib2cib/NSImageView.j b/Tools/nib2cib/NSImageView.j index 62eb55fe0..2624c2582 100644 --- a/Tools/nib2cib/NSImageView.j +++ b/Tools/nib2cib/NSImageView.j @@ -33,7 +33,7 @@ { var cell = [aCoder decodeObjectForKey:@"NSCell"]; - _imageScaling = [cell imageScaling]; + [self setImageScaling:[cell imageScaling]]; _isEditable = [cell isEditable]; }