29 @global _CPPlatformWindowWillCloseNotification
31 @
typedef _CPWindowFullPlatformWindowSession
37 - (BOOL)windowShouldClose:(
CPWindow)aWindow;
38 - (CGSize)windowWillResize:(
CPWindow)sender toSize:(CGSize)aSize;
51 - (void)windowWillClose:(
CPWindow)aWindow;
73 CPLeftArrowFunctionKey,
74 CPRightArrowFunctionKey,
76 CPDownArrowFunctionKey,
78 CPPageDownFunctionKey,
148 BOOL _hasBeenOrderedIn;
149 BOOL _isMiniaturized;
152 BOOL _isMovableByWindowBackground;
154 BOOL _constrainsToUsableScreen;
155 unsigned _shadowStyle;
156 BOOL _showsResizeIndicator;
158 int _positioningMask;
159 CGRect _positioningScreenRect;
161 BOOL _isDocumentEdited;
162 BOOL _isDocumentSaving;
170 BOOL _handlingTrackingAreaEvent;
171 BOOL _restartHandlingTrackingAreaEvent;
172 CPArray _previousMouseEnteredStack;
173 CPArray _previousCursorUpdateStack;
174 CPArray _mouseEnteredStack;
175 CPArray _cursorUpdateStack;
176 CPArray _queuedEvents;
177 CPArray _trackingAreaViews;
178 id _activeCursorTrackingArea;
179 CPArray _queuedTrackingEvents;
180 CPView _leftMouseDownView;
181 CPView _rightMouseDownView;
186 BOOL _hasBecomeKeyWindow;
187 id <CPWindowDelegate> _delegate;
188 unsigned _implementedDelegateMethods;
192 BOOL _acceptsMouseMovedEvents;
193 BOOL _ignoresMouseEvents;
201 CPURL _representedURL;
203 CPSet _registeredDraggedTypes;
204 CPArray _registeredDraggedTypesArray;
208 BOOL _defaultButtonEnabled;
209 BOOL _defaultButtonDisabledTemporarily;
211 BOOL _autorecalculatesKeyViewLoop;
212 BOOL _keyViewLoopIsDirty;
214 BOOL _sharesChromeWithPlatformWindow;
218 DOMElement _DOMElement;
221 unsigned _autoresizingMask;
223 BOOL _isFullPlatformWindow;
224 _CPWindowFullPlatformWindowSession _fullPlatformWindowSession;
227 CPArray _childWindows;
228 CPWindowOrderingMode _childOrdering;
233 _CPWindowFrameAnimation _frameAnimation;
234 _CPWindowFrameAnimationDelegate _frameAnimationDelegate;
237 + (Class)_binderClassForBinding:(
CPString)aBinding
239 if ([aBinding hasPrefix:CPDisplayPatternTitleBinding])
242 return [
super _binderClassForBinding:aBinding];
265 - (id)initWithContentRect:(CGRect)aContentRect styleMask:(
unsigned)aStyleMask
271 var windowViewClass = [[
self class] _windowViewClassForStyleMask:aStyleMask];
273 _frame = [windowViewClass frameRectForContentRect:aContentRect];
274 _constrainsToUsableScreen = YES;
286 _frame.size.height = MIN(768.0, visibleFrame.size.height);
287 _frame.size.width = MIN(1024.0, visibleFrame.size.width);
288 _frame.origin.x = (visibleFrame.size.width - _frame.size.width) / 2;
289 _frame.origin.y = (visibleFrame.size.height - _frame.size.height) / 2;
296 _isFullPlatformWindow = NO;
297 _registeredDraggedTypes = [CPSet set];
298 _registeredDraggedTypesArray = [];
299 _acceptsMouseMovedEvents = YES;
301 _hasBeenOrderedIn = NO;
310 _frameAnimation = nil;
311 _frameAnimationDelegate = nil;
314 _windowNumber = [CPApp._windows count];
315 CPApp._windows[_windowNumber] =
self;
317 _styleMask = aStyleMask;
319 [
self setLevel:CPNormalWindowLevel];
321 _handlingTrackingAreaEvent = NO;
322 _restartHandlingTrackingAreaEvent = NO;
323 _trackingAreaViews = [];
324 _previousMouseEnteredStack = [];
325 _previousCursorUpdateStack = [];
326 _mouseEnteredStack = [];
327 _cursorUpdateStack = [];
329 _queuedTrackingEvents = [];
330 _activeCursorTrackingArea = nil;
333 _windowView = [[windowViewClass alloc] initWithFrame:CGRectMake(0.0, 0.0, CGRectGetWidth(_frame), CGRectGetHeight(_frame)) styleMask:aStyleMask];
335 [_windowView _setWindow:self];
336 [_windowView setNextResponder:self];
339 _minSize = [
self _calculateMinSizeForProposedSize:CGSizeMake(0.0, 0.0)];
340 _maxSize = CGSizeMake(1000000.0, 1000000.0);
347 _firstResponder =
self;
350 _DOMElement = document.createElement(
"div");
352 _DOMElement.style.position =
"absolute";
353 _DOMElement.style.visibility =
"visible";
354 _DOMElement.style.zIndex = 0;
356 if (![
self _sharesChromeWithPlatformWindow])
358 CPDOMDisplayServerSetStyleLeftTop(_DOMElement, NULL, CGRectGetMinX(_frame), CGRectGetMinY(_frame));
361 CPDOMDisplayServerSetStyleSize(_DOMElement, 1, 1);
362 CPDOMDisplayServerAppendChild(_DOMElement, _windowView._DOMElement);
367 [
self setHasShadow:aStyleMask !== CPBorderlessWindowMask];
372 _autorecalculatesKeyViewLoop = NO;
373 _defaultButtonEnabled = YES;
374 _defaultButtonDisabledTemporarily = NO;
375 _keyViewLoopIsDirty = NO;
376 _hasBecomeKeyWindow = NO;
382 name:CPWindowResizeStyleGlobalChangeNotification
391 return _platformWindow;
407 _platformWindow = aPlatformWindow;
408 [_platformWindow _setTitle:_title window:self];
418 + (Class)_windowViewClassForStyleMask:(
unsigned)aStyleMask
421 return _CPHUDWindowView;
424 return _CPBorderlessWindowView;
427 return _CPDocModalWindowView;
429 else if (aStyleMask & _CPModalWindowMask)
430 return _CPModalWindowView;
432 return _CPStandardWindowView;
435 + (Class)_windowViewClassForFullPlatformWindowStyleMask:(
unsigned)aStyleMask
437 return _CPBorderlessBridgeWindowView;
444 if (_positioningScreenRect)
448 origin =
frame.origin;
450 if (actualScreenRect)
455 origin.x *= (actualScreenRect.size.width / _positioningScreenRect.size.width);
460 origin.x += actualScreenRect.size.width - _positioningScreenRect.size.width;
470 origin.y *= (actualScreenRect.size.height / _positioningScreenRect.size.height);
475 origin.y += actualScreenRect.size.height - _positioningScreenRect.size.height;
489 if ([
self _hasKeyViewLoop:[_contentView subviews]])
491 var views = [
self _viewsSortedByPosition],
492 count = [views count];
496 for (var i = 1; i < count; ++i)
500 if ([view nextKeyView])
502 [_contentView setNextKeyView:view];
511 [
self _doRecalculateKeyViewLoop];
515 - (void)_setWindowView:(
CPView)aWindowView
517 if (_windowView === aWindowView)
520 var oldWindowView = _windowView;
522 _windowView = aWindowView;
526 [oldWindowView _setWindow:nil];
527 [oldWindowView noteToolbarChanged];
530 CPDOMDisplayServerRemoveChild(_DOMElement, oldWindowView._DOMElement);
537 CPDOMDisplayServerAppendChild(_DOMElement, _windowView._DOMElement);
540 var contentRect = [_contentView convertRect:[_contentView bounds] toView:nil];
542 contentRect.origin = [
self convertBaseToGlobal:contentRect.origin];
544 [_windowView _setWindow:self];
545 [_windowView setNextResponder:self];
546 [_windowView addSubview:_contentView];
547 [_windowView setTitle:_title];
548 [_windowView noteToolbarChanged];
549 [_windowView setShowsResizeIndicator:[
self showsResizeIndicator]];
551 [
self setFrame:[
self frameRectForContentRect:contentRect]];
566 - (void)setFullPlatformWindow:(BOOL)shouldBeFullPlatformWindow
568 if (![_platformWindow supportsFullPlatformWindows])
571 shouldBeFullPlatformWindow = !!shouldBeFullPlatformWindow;
573 if (_isFullPlatformWindow === shouldBeFullPlatformWindow)
576 _isFullPlatformWindow = shouldBeFullPlatformWindow;
578 if (_isFullPlatformWindow)
580 _fullPlatformWindowSession = _CPWindowFullPlatformWindowSessionMake(_windowView, [
self contentRectForFrameRect:[
self frame]], [
self hasShadow], [
self level]);
582 var fullPlatformWindowViewClass = [[
self class] _windowViewClassForFullPlatformWindowStyleMask:_styleMask],
583 windowView = [[fullPlatformWindowViewClass alloc] initWithFrame:CGRectMakeZero() styleMask:_styleMask];
585 if (_platformWindow != [
CPPlatformWindow primaryPlatformWindow] && [_platformWindow _hasInitializeInstanceWithWindow])
586 [_platformWindow setContentRect:[
self frame]];
588 [
self _setWindowView:windowView];
590 [
self setLevel:CPBackgroundWindowLevel];
593 [
self setFrame:[_platformWindow visibleFrame]];
597 var windowView = _fullPlatformWindowSession.windowView;
599 [
self _setWindowView:windowView];
601 [
self setLevel:_fullPlatformWindowSession.level];
602 [
self setHasShadow:_fullPlatformWindowSession.hasShadow];
605 [
self setFrame:[windowView frameRectForContentRect:_fullPlatformWindowSession.contentRect]];
612 - (BOOL)isFullPlatformWindow
614 return _isFullPlatformWindow;
620 - (unsigned)styleMask
642 + (CGRect)frameRectForContentRect:(CGRect)aContentRect styleMask:(
unsigned)aStyleMask
644 return [[[
self class] _windowViewClassForStyleMask:aStyleMask] frameRectForContentRect:aContentRect];
651 - (CGRect)contentRectForFrameRect:(CGRect)aFrame
653 return [_windowView contentRectForFrameRect:aFrame];
661 - (CGRect)frameRectForContentRect:(CGRect)aContentRect
663 return [_windowView frameRectForContentRect:aContentRect];
671 return CGRectMakeCopy(_frame);
681 - (void)setFrame:(CGRect)aFrame display:(BOOL)shouldDisplay animate:(BOOL)shouldAnimate
683 [
self _setFrame:aFrame display:shouldDisplay animate:shouldAnimate constrainWidth:NO constrainHeight:YES];
686 - (void)_setFrame:(CGRect)aFrame display:(BOOL)shouldDisplay animate:(BOOL)shouldAnimate constrainWidth:(BOOL)shouldConstrainWidth constrainHeight:(BOOL)shouldConstrainHeight
688 var
frame = CGRectMakeCopy(aFrame),
689 value =
frame.origin.x,
690 delta = value - FLOOR(value);
693 frame.origin.x = value > 0.879 ? CEIL(value) : FLOOR(value);
695 value =
frame.origin.y;
696 delta = value - FLOOR(value);
699 frame.origin.y = value > 0.879 ? CEIL(value) : FLOOR(value);
701 value =
frame.size.width;
702 delta = value - FLOOR(value);
705 frame.size.width = value > 0.15 ? CEIL(value) : FLOOR(value);
707 value =
frame.size.height;
708 delta = value - FLOOR(value);
711 frame.size.height = value > 0.15 ? CEIL(value) : FLOOR(value);
713 frame = [
self _constrainFrame:frame toUsableScreenWidth:shouldConstrainWidth andHeight:shouldConstrainHeight];
717 [_frameAnimation stopAnimation];
718 _frameAnimation = [[_CPWindowFrameAnimation alloc] initWithWindow:self targetFrame:frame];
719 [_frameAnimation setDelegate:[
self _frameAnimationDelegate]];
720 [_frameAnimation startAnimation];
724 var origin = _frame.origin,
725 newOrigin =
frame.origin,
726 originMoved = !CGPointEqualToPoint(origin, newOrigin);
730 delta = CGPointMake(newOrigin.x - origin.x, newOrigin.y - origin.y);
731 origin.x = newOrigin.x;
732 origin.y = newOrigin.y;
735 if (![
self _sharesChromeWithPlatformWindow])
737 CPDOMDisplayServerSetStyleLeftTop(_DOMElement, NULL, origin.x, origin.y);
742 if ([
self attachedSheet])
743 [
self _setAttachedSheetFrameOrigin];
748 var size = _frame.size,
749 newSize =
frame.size;
751 if (!CGSizeEqualToSize(size, newSize))
753 size.width = newSize.width;
754 size.height = newSize.height;
757 size = [
self _sendDelegateWindowWillResizeToSize:size];
759 [_windowView setFrameSize:size];
762 [_shadowView setNeedsLayout];
768 if ([
self _sharesChromeWithPlatformWindow])
769 [_platformWindow setContentRect:_frame];
772 [
self _moveChildWindows:delta];
775 if ([_platformWindow _canUpdateContentRect] && _isFullPlatformWindow && _platformWindow != [
CPPlatformWindow primaryPlatformWindow])
776 [_platformWindow setContentRect:aFrame];
779 - (id)_frameAnimationDelegate
781 if (_frameAnimationDelegate == nil)
782 _frameAnimationDelegate = [[_CPWindowFrameAnimationDelegate alloc] initWithWindow:self];
784 return _frameAnimationDelegate;
790 - (CGRect)_constrainFrame:(CGRect)aFrame toUsableScreenWidth:(BOOL)constrainWidth andHeight:(BOOL)constrainHeight
792 var
frame = CGRectMakeCopy(aFrame);
794 if (!_constrainsToUsableScreen || !_isVisible)
797 var usableRect = [_platformWindow usableContentFrame];
802 frame.origin.x = MAX(
frame.origin.x, usableRect.origin.x);
805 var maxX = MIN(CGRectGetMaxX(
frame), CGRectGetMaxX(usableRect));
809 var usableWidth = CGRectGetWidth(usableRect);
811 if (CGRectGetWidth(
frame) > usableWidth)
813 frame.origin.x = CGRectGetMinX(usableRect);
814 frame.size.width = MAX(usableWidth, _minSize.width);
821 frame.origin.y = MAX(
frame.origin.y, usableRect.origin.y);
824 var maxY = MIN(CGRectGetMaxY(
frame), CGRectGetMaxY(usableRect));
828 var usableHeight = CGRectGetHeight(usableRect);
830 if (CGRectGetHeight(
frame) > usableHeight)
832 frame.origin.y = CGRectGetMinY(usableRect);
833 frame.size.height = MAX(usableHeight, _minSize.height);
847 - (CGRect)_constrainOriginOfFrame:(CGRect)aFrame
849 var
frame = CGRectMakeCopy(aFrame);
851 if (!_constrainsToUsableScreen || !_isVisible)
854 var usableRect = [_platformWindow usableContentFrame],
855 minimumSize = [_windowView _minimumResizeSize];
858 frame.origin.x = MAX(
frame.origin.x, CGRectGetMinX(usableRect) + minimumSize.width - CGRectGetWidth(
frame));
861 frame.origin.x = MIN(
frame.origin.x, CGRectGetMaxX(usableRect) - minimumSize.width);
864 frame.origin.y = MAX(
frame.origin.y, CGRectGetMinY(usableRect));
872 - (void)_moveChildWindows:(CGPoint)delta
874 [_childWindows enumerateObjectsUsingBlock:function(childWindow)
876 var origin = [childWindow frame].origin;
878 [childWindow setFrameOrigin:CGPointMake(origin.x + delta.x, origin.y + delta.y)];
888 - (void)setFrame:(CGRect)aFrame display:(BOOL)shouldDisplay
897 - (void)setFrame:(CGRect)aFrame
906 - (void)setFrameOrigin:(CGPoint)anOrigin
908 var
frame = [
self _constrainOriginOfFrame:CGRectMake(anOrigin.x, anOrigin.y, _frame.size.width, _frame.size.height)];
909 [
self _setFrame:frame display:YES animate:NO constrainWidth:NO constrainHeight:NO];
916 - (void)setFrameSize:(CGSize)aSize
918 [
self setFrame:CGRectMake(CGRectGetMinX(_frame), CGRectGetMinY(_frame), aSize.width, aSize.height)
display:YES
animate:NO];
925 - (void)orderFront:(
id)aSender
936 [_platformWindow _setShouldUpdateContentRect:NO];
940 [_parentView orderFront:self];
943 var wasVisible = _isVisible;
945 [_platformWindow orderFront:self];
946 [_platformWindow order:CPWindowAbove window:self relativeTo:nil];
950 [
self _setFrame:_frame display:YES animate:NO constrainWidth:YES constrainHeight:YES];
953 if (!
CPApp._keyWindow)
954 [
self makeKeyWindow];
956 if ([
self isKeyWindow] && (_firstResponder ===
self || !_firstResponder))
957 [
self makeFirstResponder:_initialFirstResponder];
959 if (!
CPApp._mainWindow)
960 [
self makeMainWindow];
962 [_platformWindow _setShouldUpdateContentRect:YES];
964 if ([
self attachedSheet])
965 [_platformWindow order:CPWindowAbove window:[
self attachedSheet] relativeTo:nil];
972 - (void)_parentDidOrderInChild
979 - (void)_windowWillBeAddedToTheDOM
983 name:_CPPlatformWindowWillCloseNotification
986 [[
self contentView] _addObservers];
992 - (void)_windowWillBeRemovedFromTheDOM
996 [[
self contentView] _removeObservers];
997 _hasBecomeKeyWindow = NO;
1006 - (void)orderBack:(
id)aSender
1020 - (void)orderOut:(
id)aSender
1025 - (void)_orderOutRecursively:(BOOL)recursive
1033 [
self._parentView _detachSheetWindow];
1038 [_childWindows makeObjectsPerformSelector:@selector(_orderOutRecursively:) withObject:recursive];
1041 if ([
self _sharesChromeWithPlatformWindow])
1042 [_platformWindow orderOut:self];
1044 if (_isFullPlatformWindow && _platformWindow != [
CPPlatformWindow primaryPlatformWindow])
1045 [_platformWindow orderOut:self];
1047 [_platformWindow order:CPWindowOut window:self relativeTo:nil];
1050 [
self makeFirstResponder:nil];
1051 [
self _updateMainAndKeyWindows];
1059 - (void)orderWindow:(CPWindowOrderingMode)orderingMode relativeTo:(
int)otherWindowNumber
1064 [_parentWindow removeChildWindow:self];
1067 [
self _orderOutRecursively:!_parentWindow];
1069 else if (orderingMode ===
CPWindowAbove && otherWindowNumber === 0)
1071 else if (orderingMode ===
CPWindowBelow && otherWindowNumber === 0)
1075 [_platformWindow order:orderingMode window:self relativeTo:CPApp._windows[otherWindowNumber]];
1083 - (void)setLevel:(
int)aLevel
1085 if (aLevel === _level)
1088 [_platformWindow moveWindow:self fromLevel:_level toLevel:aLevel];
1091 [_childWindows makeObjectsPerformSelector:@selector(setLevel:) withObject:_level];
1093 if ([
self _sharesChromeWithPlatformWindow])
1094 [_platformWindow setLevel:aLevel];
1118 + (void)setGlobalResizeStyle:(
int)aStyle
1131 + (void)setConstrainWindowsToUsableScreen:(BOOL)shouldConstrain
1139 + (BOOL)constrainWindowsToUsableScreen
1144 - (void)_didReceiveResizeStyleChange:(
CPNotification)aNotification
1146 [_windowView setShowsResizeIndicator:_styleMask & CPResizableWindowMask];
1152 + (int)globalResizeStyle
1160 - (BOOL)showsResizeIndicator
1162 return _showsResizeIndicator;
1169 - (void)setShowsResizeIndicator:(BOOL)shouldShowResizeIndicator
1171 shouldShowResizeIndicator = !!shouldShowResizeIndicator;
1173 if (_showsResizeIndicator === shouldShowResizeIndicator)
1176 _showsResizeIndicator = shouldShowResizeIndicator;
1183 - (CGSize)resizeIndicatorOffset
1185 return [_windowView resizeIndicatorOffset];
1192 - (void)setResizeIndicatorOffset:(CGSize)anOffset
1194 [_windowView setResizeIndicatorOffset:anOffset];
1204 if (_contentView && _contentView !== aView)
1205 [_contentView removeFromSuperview];
1207 var
bounds = CGRectMake(0.0, 0.0, CGRectGetWidth(_frame), CGRectGetHeight(_frame));
1209 _contentView = aView;
1212 [_contentView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
1213 [_windowView addSubview:_contentView];
1219 if (_initialFirstResponder && _initialFirstResponder !==
self)
1220 _initialFirstResponder =
self;
1228 return _contentView;
1235 - (void)setAlphaValue:(
float)aValue
1237 [_windowView setAlphaValue:aValue];
1245 return [_windowView alphaValue];
1254 [_windowView setBackgroundColor:aColor];
1262 return [_windowView backgroundColor];
1272 - (void)setMinSize:(CGSize)aSize
1274 if (CGSizeEqualToSize(_minSize, aSize))
1277 _minSize = [
self _calculateMinSizeForProposedSize:aSize];
1279 var size = CGSizeMakeCopy([
self frame].size),
1280 needsFrameChange = NO;
1282 if (size.width < _minSize.width)
1284 size.width = _minSize.width;
1285 needsFrameChange = YES;
1288 if (size.height < _minSize.height)
1290 size.height = _minSize.height;
1291 needsFrameChange = YES;
1294 if (needsFrameChange)
1307 - (CGSize)_calculateMinSizeForProposedSize:(CGSize)proposedSize
1309 var contentFrame = [
self contentRectForFrameRect:_frame],
1310 minHeight = CGRectGetHeight(_frame) - CGRectGetHeight(contentFrame);
1312 return CGSizeMake(MAX(proposedSize.width, 0), MAX(proposedSize.height, minHeight));
1321 - (void)setMaxSize:(CGSize)aSize
1323 if (CGSizeEqualToSize(_maxSize, aSize))
1326 _maxSize = CGSizeMakeCopy(aSize);
1328 var size = CGSizeMakeCopy([
self frame].size),
1329 needsFrameChange = NO;
1331 if (size.width > _maxSize.width)
1333 size.width = _maxSize.width;
1334 needsFrameChange = YES;
1337 if (size.height > _maxSize.height)
1339 size.height = _maxSize.height;
1340 needsFrameChange = YES;
1343 if (needsFrameChange)
1363 - (void)_updateShadow
1365 if ([
self _sharesChromeWithPlatformWindow])
1370 CPDOMDisplayServerRemoveChild(_DOMElement, _shadowView._DOMElement);
1375 [_platformWindow setHasShadow:_hasShadow];
1380 if (_hasShadow && !_shadowView)
1382 _shadowView = [[_CPShadowWindowView alloc] initWithFrame:CGRectMakeZero()];
1384 [_shadowView setWindowView:_windowView];
1385 [_shadowView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
1386 [_shadowView setNeedsLayout];
1389 CPDOMDisplayServerInsertBefore(_DOMElement, _shadowView._DOMElement, _windowView._DOMElement);
1392 else if (!_hasShadow && _shadowView)
1395 CPDOMDisplayServerRemoveChild(_DOMElement, _shadowView._DOMElement);
1405 - (void)setHasShadow:(BOOL)shouldHaveShadow
1407 if (_hasShadow === shouldHaveShadow)
1410 _hasShadow = shouldHaveShadow;
1412 [
self _updateShadow];
1426 - (void)setShadowStyle:(
unsigned)aStyle
1428 _shadowStyle = aStyle;
1437 - (void)setDelegate:(
id <CPWindowDelegate>)aDelegate
1439 if (_delegate === aDelegate)
1444 [defaultCenter removeObserver:_delegate name:CPWindowDidResignKeyNotification object:self];
1445 [defaultCenter removeObserver:_delegate name:CPWindowDidBecomeKeyNotification object:self];
1446 [defaultCenter removeObserver:_delegate name:CPWindowDidBecomeMainNotification object:self];
1447 [defaultCenter removeObserver:_delegate name:CPWindowDidResignMainNotification object:self];
1448 [defaultCenter removeObserver:_delegate name:CPWindowDidMoveNotification object:self];
1449 [defaultCenter removeObserver:_delegate name:CPWindowDidResizeNotification object:self];
1450 [defaultCenter removeObserver:_delegate name:CPWindowWillBeginSheetNotification object:self];
1451 [defaultCenter removeObserver:_delegate name:CPWindowDidEndSheetNotification object:self];
1452 [defaultCenter removeObserver:_delegate name:CPWindowDidMiniaturizeNotification object:self];
1453 [defaultCenter removeObserver:_delegate name:CPWindowDidDeminiaturizeNotification object:self];
1454 [defaultCenter removeObserver:_delegate name:CPWindowWillMiniaturizeNotification object:self];
1456 _delegate = aDelegate;
1457 _implementedDelegateMethods = 0;
1459 if ([_delegate respondsToSelector:
@selector(windowShouldClose:)])
1462 if ([_delegate respondsToSelector:
@selector(windowWillReturnUndoManager:)])
1465 if ([_delegate respondsToSelector:
@selector(windowWillClose:)])
1468 if ([_delegate respondsToSelector:
@selector(windowWillResize:toSize:)])
1471 if ([_delegate respondsToSelector:
@selector(windowDidResignKey:)])
1473 addObserver:_delegate
1474 selector:@selector(windowDidResignKey:)
1475 name:CPWindowDidResignKeyNotification
1478 if ([_delegate respondsToSelector:
@selector(windowDidBecomeKey:)])
1480 addObserver:_delegate
1481 selector:@selector(windowDidBecomeKey:)
1482 name:CPWindowDidBecomeKeyNotification
1485 if ([_delegate respondsToSelector:
@selector(windowDidBecomeMain:)])
1487 addObserver:_delegate
1488 selector:@selector(windowDidBecomeMain:)
1489 name:CPWindowDidBecomeMainNotification
1492 if ([_delegate respondsToSelector:
@selector(windowDidResignMain:)])
1494 addObserver:_delegate
1495 selector:@selector(windowDidResignMain:)
1496 name:CPWindowDidResignMainNotification
1499 if ([_delegate respondsToSelector:
@selector(windowDidMove:)])
1501 addObserver:_delegate
1502 selector:@selector(windowDidMove:)
1503 name:CPWindowDidMoveNotification
1506 if ([_delegate respondsToSelector:
@selector(windowDidResize:)])
1508 addObserver:_delegate
1509 selector:@selector(windowDidResize:)
1510 name:CPWindowDidResizeNotification
1513 if ([_delegate respondsToSelector:
@selector(windowWillBeginSheet:)])
1515 addObserver:_delegate
1516 selector:@selector(windowWillBeginSheet:)
1517 name:CPWindowWillBeginSheetNotification
1520 if ([_delegate respondsToSelector:
@selector(windowDidEndSheet:)])
1522 addObserver:_delegate
1523 selector:@selector(windowDidEndSheet:)
1524 name:CPWindowDidEndSheetNotification
1527 if ([_delegate respondsToSelector:
@selector(windowDidMiniaturize:)])
1529 addObserver:_delegate
1530 selector:@selector(windowDidMiniaturize:)
1531 name:CPWindowDidMiniaturizeNotification
1534 if ([_delegate respondsToSelector:
@selector(windowWillMiniaturize:)])
1536 addObserver:_delegate
1537 selector:@selector(windowWillMiniaturize:)
1538 name:CPWindowWillMiniaturizeNotification
1541 if ([_delegate respondsToSelector:
@selector(windowDidDeminiaturize:)])
1543 addObserver:_delegate
1544 selector:@selector(windowDidDeminiaturize:)
1545 name:CPWindowDidDeminiaturizeNotification
1563 _windowController = aWindowController;
1571 return _windowController;
1574 - (void)doCommandBySelector:(
SEL)aSelector
1576 if ([_delegate respondsToSelector:aSelector])
1577 [_delegate performSelector:aSelector];
1582 - (BOOL)acceptsFirstResponder
1589 return _initialFirstResponder;
1592 - (void)setInitialFirstResponder:(
CPView)aView
1594 _initialFirstResponder = aView;
1597 - (void)_setupFirstResponder
1602 if (!_hasBecomeKeyWindow)
1604 if (_firstResponder ===
self)
1606 if (_initialFirstResponder)
1607 [
self makeFirstResponder:_initialFirstResponder];
1611 var view = [_contentView nextValidKeyView];
1614 [
self makeFirstResponder:view];
1621 if (_firstResponder)
1622 [
self makeFirstResponder:_firstResponder];
1634 if (_firstResponder === aResponder)
1637 if (![_firstResponder resignFirstResponder])
1640 if (!aResponder || ![aResponder acceptsFirstResponder] || ![aResponder becomeFirstResponder])
1642 _firstResponder =
self;
1647 _firstResponder = aResponder;
1659 return _firstResponder;
1662 - (BOOL)acceptsMouseMovedEvents
1664 return _acceptsMouseMovedEvents;
1667 - (void)setAcceptsMouseMovedEvents:(BOOL)shouldAcceptMouseMovedEvents
1669 _acceptsMouseMovedEvents = shouldAcceptMouseMovedEvents;
1672 - (BOOL)ignoresMouseEvents
1674 return _ignoresMouseEvents;
1677 - (void)setIgnoresMouseEvents:(BOOL)shouldIgnoreMouseEvents
1679 _ignoresMouseEvents = shouldIgnoreMouseEvents;
1682 - (void)_mouseExitedResizeRect
1704 [_windowView setTitle:aTitle];
1705 [_platformWindow _setTitle:_title window:self];
1711 - (void)setTitleWithRepresentedFilename:(
CPString)aFilePath
1731 return [_representedURL absoluteString];
1739 _representedURL = aURL;
1747 return _representedURL;
1761 - (void)setMovableByWindowBackground:(BOOL)shouldBeMovableByWindowBackground
1763 _isMovableByWindowBackground = shouldBeMovableByWindowBackground;
1769 - (BOOL)isMovableByWindowBackground
1771 return _isMovableByWindowBackground;
1778 - (void)setMovable:(BOOL)shouldBeMovable
1780 _isMovable = shouldBeMovable;
1796 if (_isFullPlatformWindow)
1799 var size = [
self frame].size,
1802 var origin = CGPointMake((containerSize.width - size.width) / 2.0, (containerSize.height - size.height) / 2.0);
1819 var type = [anEvent
type],
1827 if (sheet && _sheetContext[
"isAttached"])
1833 [_windowView mouseDown:anEvent];
1837 [sheet makeKeyAndOrderFront:self];
1856 return [CPApp activateIgnoringOtherApps:YES];
1895 else if ([anEvent charactersIgnoringModifiers] ==
CPEscapeFunctionKey && [
self _processKeyboardUIKey:anEvent])
1903 if (_defaultButtonEnabled && !_defaultButtonDisabledTemporarily)
1906 keyEquivalent = [defaultButton keyEquivalent],
1907 modifierMask = [defaultButton keyEquivalentModifierMask];
1909 if ([anEvent _triggersKeyEquivalent:keyEquivalent withModifierMask:modifierMask])
1913 _defaultButtonDisabledTemporarily = NO;
1918 return [[_windowView hitTest:point] scrollWheel:anEvent];
1922 var hitTestedView = _leftMouseDownView,
1923 selector = type ==
CPRightMouseUp ?
@selector(rightMouseUp:) :
@selector(mouseUp:);
1926 hitTestedView = [_windowView hitTest:point];
1928 [hitTestedView performSelector:selector withObject:anEvent];
1930 _leftMouseDownView = nil;
1933 [
self _flushTrackingEventQueueForMouseAt:point];
1940 _leftMouseDownView = [_windowView hitTest:point];
1942 if (_leftMouseDownView !== _firstResponder && [_leftMouseDownView acceptsFirstResponder])
1945 var keyWindow = [CPApp keyWindow];
1948 if ([keyWindow platformWindow] != [
self platformWindow])
1951 [CPApp activateIgnoringOtherApps:YES];
1953 var theWindow = [anEvent window],
1954 selector = type ==
CPRightMouseDown ?
@selector(rightMouseDown:) :
@selector(mouseDown:);
1956 if (([theWindow _isFrontmostWindow] && [theWindow isKeyWindow]) || ([theWindow becomesKeyOnlyIfNeeded] && ![_leftMouseDownView needsPanelToBecomeKey]))
1957 return [_leftMouseDownView performSelector:selector withObject:anEvent];
1963 if ([_leftMouseDownView acceptsFirstMouse:anEvent])
1964 return [_leftMouseDownView performSelector:selector withObject:anEvent];
1972 [
self _handleTrackingAreaEvent:anEvent];
1975 if (!_leftMouseDownView)
1976 return [[_windowView hitTest:point] mouseDragged:anEvent];
1982 selector =
@selector(rightMouseDragged:);
1983 if (![_leftMouseDownView respondsToSelector:selector])
1988 selector =
@selector(mouseDragged:);
1990 return [_leftMouseDownView performSelector:selector withObject:anEvent];
1995 if (!_acceptsMouseMovedEvents || sheet)
1998 [
self _handleTrackingAreaEvent:anEvent];
2002 - (void)_startLiveResize
2009 - (void)_endLiveResize
2016 - (BOOL)_inLiveResize
2018 return [_windowView _isTracking];
2026 return _windowNumber;
2034 - (void)becomeKeyWindow
2036 CPApp._keyWindow =
self;
2038 if (_firstResponder !==
self && [_firstResponder respondsToSelector:
@selector(becomeKeyWindow)])
2039 [_firstResponder becomeKeyWindow];
2041 if (!_hasBecomeKeyWindow)
2045 if (![
self _hasKeyViewLoop:[_contentView subviews]])
2049 [
self _setupFirstResponder];
2050 _hasBecomeKeyWindow = YES;
2051 _platformWindow._currentKeyWindow =
self;
2053 [_windowView noteKeyWindowStateChanged];
2054 [_contentView _notifyWindowDidBecomeKey];
2065 - (BOOL)canBecomeKeyWindow
2080 - (BOOL)_isFrontmostWindow
2082 if ([
self isFullBridge])
2085 var orderedWindows = [CPApp orderedWindows];
2087 if ([orderedWindows count] == 0)
2090 if ([orderedWindows objectAtIndex:0] ===
self)
2095 [orderedWindows count] > 1 && [orderedWindows objectAtIndex:1] ===
self)
2106 return [CPApp keyWindow] ==
self;
2113 - (void)makeKeyAndOrderFront:(
id)aSender
2124 - (void)makeKeyWindow
2126 if ([
CPApp keyWindow] ===
self || ![
self canBecomeKeyWindow])
2129 [[CPApp keyWindow] resignKeyWindow];
2136 - (void)resignKeyWindow
2138 if (_firstResponder !==
self && [_firstResponder respondsToSelector:
@selector(resignKeyWindow)])
2139 [_firstResponder resignKeyWindow];
2141 if (
CPApp._keyWindow ===
self)
2142 CPApp._keyWindow = nil;
2144 _platformWindow._currentKeyWindow = nil;
2145 [_windowView noteKeyWindowStateChanged];
2146 [_contentView _notifyWindowDidResignKey];
2163 - (void)dragImage:(
CPImage)anImage at:(CGPoint)imageLocation offset:(CGSize)mouseOffset event:(
CPEvent)anEvent pasteboard:(
CPPasteboard)aPasteboard source:(
id)aSourceObject slideBack:(BOOL)slideBack
2168 - (void)_noteRegisteredDraggedTypes:(CPSet)pasteboardTypes
2170 if (!pasteboardTypes)
2173 if (!_inclusiveRegisteredDraggedTypes)
2176 [_inclusiveRegisteredDraggedTypes unionSet:pasteboardTypes];
2179 - (void)_noteUnregisteredDraggedTypes:(CPSet)pasteboardTypes
2181 if (!pasteboardTypes)
2184 [_inclusiveRegisteredDraggedTypes minusSet:pasteboardTypes];
2186 if ([_inclusiveRegisteredDraggedTypes count] === 0)
2187 _inclusiveRegisteredDraggedTypes = nil;
2200 - (void)dragView:(
CPView)aView at:(CGPoint)viewLocation offset:(CGSize)mouseOffset event:(
CPEvent)anEvent pasteboard:(
CPPasteboard)aPasteboard source:(
id)aSourceObject slideBack:(BOOL)slideBack
2209 - (void)registerForDraggedTypes:(CPArray)pasteboardTypes
2211 if (!pasteboardTypes)
2214 [
self _noteUnregisteredDraggedTypes:_registeredDraggedTypes];
2215 [_registeredDraggedTypes addObjectsFromArray:pasteboardTypes];
2216 [
self _noteRegisteredDraggedTypes:_registeredDraggedTypes];
2218 _registeredDraggedTypesArray = nil;
2225 - (CPArray)registeredDraggedTypes
2227 if (!_registeredDraggedTypesArray)
2228 _registeredDraggedTypesArray = [_registeredDraggedTypes allObjects];
2230 return _registeredDraggedTypesArray;
2236 - (void)unregisterDraggedTypes
2238 [
self _noteUnregisteredDraggedTypes:_registeredDraggedTypes];
2240 _registeredDraggedTypes = [CPSet set];
2241 _registeredDraggedTypesArray = [];
2250 - (void)setDocumentEdited:(BOOL)isDocumentEdited
2252 if (_isDocumentEdited == isDocumentEdited)
2255 _isDocumentEdited = isDocumentEdited;
2257 [
CPMenu _setMenuBarIconImageAlphaValue:_isDocumentEdited ? 0.5 : 1.0];
2259 [_windowView setDocumentEdited:isDocumentEdited];
2265 - (BOOL)isDocumentEdited
2267 return _isDocumentEdited;
2270 - (void)setDocumentSaving:(BOOL)isDocumentSaving
2272 if (_isDocumentSaving == isDocumentSaving)
2275 _isDocumentSaving = isDocumentSaving;
2277 [
self _synchronizeSaveMenuWithDocumentSaving];
2279 [_windowView windowDidChangeDocumentSaving];
2282 - (BOOL)isDocumentSaving
2284 return _isDocumentSaving;
2288 - (void)_synchronizeSaveMenuWithDocumentSaving
2290 if (![
self isMainWindow])
2293 var mainMenu = [CPApp mainMenu],
2294 index = [mainMenu indexOfItemWithTitle:_isDocumentSaving ? @"Save" : @"Saving..."];
2299 var item = [mainMenu itemAtIndex:index];
2301 if (_isDocumentSaving)
2305 [item setTitle:@"Saving..."];
2307 [item setEnabled:NO];
2311 [item setTitle:@"Save"];
2312 [item setImage:CPWindowSaveImage];
2313 [item setEnabled:YES];
2323 - (void)performMiniaturize:(
id)aSender
2333 - (void)miniaturize:(
id)sender
2339 [
self _updateMainAndKeyWindows];
2343 _isMiniaturized = YES;
2349 - (void)deminiaturize:(
id)sender
2355 _isMiniaturized = NO;
2361 - (void)isMiniaturized
2363 return _isMiniaturized;
2372 - (void)performClose:(
id)aSender
2377 if ([
self isFullPlatformWindow])
2379 var
event = [CPApp currentEvent];
2390 if ([
self _delegateRespondsToWindowShouldClose])
2392 if (![
self _sendDelegateWindowShouldClose])
2395 else if ([
self respondsToSelector:
@selector(windowShouldClose:)])
2397 if (![
self windowShouldClose:
self])
2401 var documents = [_windowController documents];
2403 if ([documents count])
2405 var index = [documents indexOfObject:[_windowController document]];
2407 [documents[index] shouldCloseWindowController:_windowController
2409 shouldCloseSelector:@selector(_windowControllerContainingDocument:shouldClose:contextInfo:)
2410 contextInfo:{documents:[documents copy], visited:0, index:index}];
2416 - (void)_windowControllerContainingDocument:(
CPDocument)document shouldClose:(BOOL)shouldClose contextInfo:(Object)context
2420 var windowController = [
self windowController],
2421 documents = context.documents,
2422 count = [documents count],
2423 visited = ++context.visited,
2424 index = ++context.index % count;
2428 if (visited < count)
2430 [windowController setDocument:documents[index]];
2432 [documents[index] shouldCloseWindowController:_windowController
2434 shouldCloseSelector:@selector(_windowControllerContainingDocument:shouldClose:contextInfo:)
2435 contextInfo:context];
2448 [
self _sendDelegateWindowWillClose];
2452 [_parentWindow removeChildWindow:self];
2453 [
self _orderOutRecursively:NO];
2454 [
self _detachFromChildrenClosing:!_parentWindow];
2457 - (void)_detachFromChildrenClosing:(BOOL)shouldCloseChildren
2460 [_childWindows enumerateObjectsUsingBlock:function(child)
2462 [child setParentWindow:nil];
2466 if (shouldCloseChildren)
2468 [_childWindows enumerateObjectsUsingBlock:function(child)
2472 [child _orderOutRecursively:NO];
2473 [child _detachFromChildrenClosing:![child parentWindow]];
2485 - (BOOL)isMainWindow
2487 return [CPApp mainWindow] ===
self;
2493 - (BOOL)canBecomeMainWindow
2500 return ([
self isVisible] && ((_styleMask &
CPTitledWindowMask) || _isFullPlatformWindow));
2506 - (void)makeMainWindow
2511 [_parentView makeMainWindow];
2515 if ([
CPApp mainWindow] ===
self || ![
self canBecomeMainWindow])
2518 [[CPApp mainWindow] resignMainWindow];
2525 - (void)becomeMainWindow
2527 CPApp._mainWindow =
self;
2528 _platformWindow._currentMainWindow =
self;
2530 [
self _synchronizeSaveMenuWithDocumentSaving];
2532 [_windowView noteMainWindowStateChanged];
2542 - (void)resignMainWindow
2548 if (
CPApp._mainWindow ===
self)
2549 CPApp._mainWindow = nil;
2551 _platformWindow._currentMainWindow = nil;
2552 [_windowView noteMainWindowStateChanged];
2555 - (void)_updateMainAndKeyWindows
2557 var allWindows = [CPApp orderedWindows],
2558 windowCount = [allWindows count];
2560 if ([
self isKeyWindow])
2562 var keyWindow = [CPApp keyWindow];
2563 [
self resignKeyWindow];
2565 if (keyWindow && keyWindow !==
self && [keyWindow canBecomeKeyWindow])
2566 [keyWindow makeKeyWindow];
2569 var mainMenu = [CPApp mainMenu],
2570 menuBarClass = objj_getClass(
"_CPMenuBarWindow"),
2573 for (var i = 0; i < windowCount; i++)
2575 var currentWindow = allWindows[i];
2577 if ([currentWindow isKindOfClass:menuBarClass])
2578 menuWindow = currentWindow;
2580 if (currentWindow ===
self || currentWindow === menuWindow)
2583 if ([currentWindow isVisible] && [currentWindow canBecomeKeyWindow] && [currentWindow platformWindow] == [keyWindow platformWindow])
2585 [currentWindow makeKeyWindow];
2590 if (![
CPApp keyWindow])
2591 [menuWindow makeKeyWindow];
2595 if ([
self isMainWindow])
2597 var mainWindow = [CPApp mainWindow];
2598 [
self resignMainWindow];
2600 if (mainWindow && mainWindow !==
self && [mainWindow canBecomeMainWindow])
2601 [mainWindow makeMainWindow];
2604 var mainMenu = [CPApp mainMenu],
2605 menuBarClass = objj_getClass(
"_CPMenuBarWindow"),
2608 for (var i = 0; i < windowCount; i++)
2610 var currentWindow = allWindows[i];
2612 if ([currentWindow isKindOfClass:menuBarClass])
2613 menuWindow = currentWindow;
2615 if (currentWindow ===
self || currentWindow === menuWindow)
2618 if ([currentWindow isVisible] && [currentWindow canBecomeMainWindow])
2620 [currentWindow makeMainWindow];
2643 if (_toolbar === aToolbar)
2647 [[aToolbar _window] setToolbar:nil];
2650 [_toolbar _setWindow:nil];
2652 _toolbar = aToolbar;
2655 [_toolbar _setWindow:self];
2657 [
self _noteToolbarChanged];
2660 - (void)toggleToolbarShown:(
id)aSender
2664 [toolbar setVisible:![toolbar isVisible]];
2667 - (void)_noteToolbarChanged
2672 [_windowView noteToolbarChanged];
2674 if (_isFullPlatformWindow)
2675 newFrame = [_platformWindow visibleFrame];
2678 newFrame = CGRectMakeCopy([
self frame]);
2680 newFrame.origin =
frame.origin;
2683 [
self setFrame:newFrame];
2695 - (CPArray)childWindows
2697 return _childWindows;
2700 - (void)addChildWindow:(
CPWindow)childWindow ordered:(CPWindowOrderingMode)orderingMode
2703 if ([_childWindows indexOfObject:childWindow] >= 0)
2707 [_childWindows addObject:childWindow];
2710 reason:_cmd + @" unrecognized ordering mode " + orderingMode];
2713 [childWindow _setChildOrdering:orderingMode];
2716 if ([
self isVisible] && ![childWindow isVisible])
2722 var index = [_childWindows indexOfObject:childWindow];
2727 [_childWindows removeObjectAtIndex:index];
2733 return _parentWindow;
2741 - (BOOL)_hasAncestorWindow:(
CPWindow)anAncestor
2743 if (!_parentWindow || !anAncestor)
2746 if (anAncestor === _parentWindow)
2749 return [_parentWindow _hasAncestorWindow:anAncestor];
2754 _parentWindow = parentWindow;
2757 - (void)_setFrame:(CGRect)aFrame delegate:(
id)delegate duration:(
int)duration curve:(CPAnimationCurve)curve
2759 [_frameAnimation stopAnimation];
2760 _frameAnimation = [[_CPWindowFrameAnimation alloc] initWithWindow:self targetFrame:aFrame];
2761 [_frameAnimation setDelegate:delegate];
2762 [_frameAnimation setAnimationCurve:curve];
2763 [_frameAnimation setDuration:duration];
2764 [_frameAnimation startAnimation];
2767 - (CPTimeInterval)animationResizeTime:(CGRect)newWindowFrame
2772 - (void)_setAttachedSheetFrameOrigin
2775 var attachedSheet = [
self attachedSheet],
2776 contentRect = [_contentView frame],
2777 sheetFrame = CGRectMakeCopy([attachedSheet
frame]);
2779 sheetFrame.origin.y = CGRectGetMinY(_frame) + CGRectGetMinY(contentRect);
2780 sheetFrame.origin.x = CGRectGetMinX(_frame) + FLOOR((CGRectGetWidth(_frame) - CGRectGetWidth(sheetFrame)) / 2.0);
2782 [attachedSheet setFrame:sheetFrame display:YES animate:NO];
2785 - (void)_previousSheetIsClosedNotification:(
CPNotification)aNotification
2789 var sheet = _sheetContext[@"nextSheet"],
2790 modalDelegate = _sheetContext[@"nextModalDelegate"],
2791 endSelector = _sheetContext[@"nextEndSelector"],
2792 contextInfo = _sheetContext[@"nextContextInfo"];
2795 setTimeout(
function()
2797 [sheet._windowView _enableSheet:YES inWindow:self];
2798 [
self _attachSheet:sheet modalDelegate:modalDelegate didEndSelector:endSelector contextInfo:contextInfo];
2805 - (void)_attachSheet:(
CPWindow)aSheet modalDelegate:(
id)aModalDelegate
2806 didEndSelector:(
SEL)didEndSelector contextInfo:(
id)contextInfo
2811 if (_sheetContext[
@"isClosing"])
2814 _sheetContext[@"nextSheet"] = aSheet;
2815 _sheetContext[@"nextModalDelegate"] = aModalDelegate;
2816 _sheetContext[@"nextEndSelector"] = didEndSelector;
2817 _sheetContext[@"nextContextInfo"] = contextInfo;
2825 reason:@"The target window of beginSheet: already has a sheet, did you forget orderOut: ?"];
2832 "modalDelegate": aModalDelegate,
2833 "endSelector": didEndSelector,
2834 "contextInfo": contextInfo,
2838 "savedConstrains": aSheet._constrainsToUsableScreen
2842 aSheet._constrainsToUsableScreen = NO;
2858 var
delegate = _sheetContext["modalDelegate"],
2859 endSelector = _sheetContext["endSelector"];
2865 if (_sheetContext[
"isAttached"])
2866 delegate.isa.objj_msgSend3(
delegate, endSelector, _sheetContext[
"sheet"], _sheetContext[
"returnCode"],
2867 _sheetContext[
"contextInfo"]);
2869 _sheetContext["deferDidEndSelector"] = YES;
2877 - (void)_detachSheetWindow
2879 if (_sheetContext[
"isClosing"])
2882 _sheetContext["isAttached"] = NO;
2883 _sheetContext["isClosing"] = YES;
2884 _sheetContext["opened"] = NO;
2898 - (void)_cleanupSheetWindow
2900 var sheet = _sheetContext["sheet"],
2901 deferDidEnd = _sheetContext["deferDidEndSelector"];
2907 [
self _removeClipForSheet:sheet];
2910 sheet._isSheet = NO;
2911 [sheet._windowView _enableSheet:NO inWindow:self];
2912 sheet._constrainsToUsableScreen = _sheetContext["savedConstrains"];
2915 [sheet orderOut:self];
2921 var
delegate = _sheetContext["modalDelegate"],
2922 selector = _sheetContext["endSelector"],
2923 returnCode = _sheetContext["returnCode"],
2924 contextInfo = _sheetContext["contextInfo"];
2927 _sheetContext = nil;
2928 sheet._parentView = nil;
2931 delegate.isa.objj_msgSend3(
delegate, selector, sheet, returnCode, contextInfo);
2935 _sheetContext = nil;
2936 sheet._parentView = nil;
2941 - (void)animationDidEnd:(
id)anim
2943 var sheet = _sheetContext["sheet"];
2945 if (anim._window != sheet)
2955 - (void)_sheetShouldAnimateIn:(
CPTimer)timer
2958 if (_sheetContext[
"isOpening"] || _sheetContext[
"isClosing"])
2961 var sheet = _sheetContext["sheet"];
2962 sheet._isSheet = YES;
2963 sheet._parentView =
self;
2969 sheet._isModal = NO;
2971 if ([
CPApp modalWindow] ===
self)
2973 [CPApp runModalForWindow:sheet];
2974 sheet._isModal = YES;
2979 var sheetFrame = [sheet frame],
2980 sheetShadowFrame = sheet._hasShadow ? [sheet._shadowView frame] : sheetFrame,
2981 frame = [
self frame],
2983 startFrame = CGRectMake(originX, -sheetShadowFrame.size.height, sheetFrame.size.
width, sheetFrame.size.height),
2984 endY = -1 + [_windowView bodyOffset] - [[self contentView]
frame].origin.y,
2985 endFrame = CGRectMake(originX, endY, sheetFrame.size.
width, sheetFrame.size.height);
2987 if (_toolbar && [_windowView showsToolbar] && [
self isFullPlatformWindow])
2989 endY += [[_toolbar _toolbarView] frameSize].height;
2990 endFrame = CGRectMake(originX, endY, sheetFrame.size.width, sheetFrame.size.height);
2994 [sheet setFrameOrigin:CGPointMake(0, -13000)];
2997 [sheet orderFront:self];
2998 [
self _clipSheet:sheet];
3000 [sheet setFrame:startFrame display:YES animate:NO];
3002 _sheetContext["opened"] = YES;
3003 _sheetContext["shouldClose"] = NO;
3004 _sheetContext["isOpening"] = YES;
3006 [sheet _setFrame:endFrame delegate:self duration:[
self animationResizeTime:endFrame] curve:CPAnimationEaseOut];
3009 - (void)_sheetShouldAnimateOut:(
CPTimer)timer
3011 if (_sheetContext[
"isOpening"])
3014 _sheetContext["shouldClose"] = YES;
3019 if ([
self isVisible])
3021 var sheet = _sheetContext["sheet"],
3022 sheetFrame = [sheet frame],
3023 fullHeight = sheet._hasShadow ? [sheet._shadowView frame].size.height : sheetFrame.size.height,
3024 endFrame = CGRectMakeCopy(sheetFrame),
3025 contentOrigin = [
self convertBaseToGlobal:[[
self contentView] frame].origin];
3028 sheet._constrainsToUsableScreen = NO;
3030 [sheet setFrameOrigin:CGPointMake(sheetFrame.origin.x, sheetFrame.origin.y - contentOrigin.y)];
3031 [
self _clipSheet:sheet];
3033 endFrame.origin.y = -fullHeight;
3034 [sheet _setFrame:endFrame delegate:self duration:[
self animationResizeTime:endFrame] curve:CPAnimationEaseIn];
3038 [
self _sheetAnimationDidEnd:nil];
3042 - (void)_sheetAnimationDidEnd:(
CPTimer)timer
3044 var sheet = _sheetContext["sheet"];
3046 _sheetContext["isOpening"] = NO;
3047 _sheetContext["isClosing"] = NO;
3049 if (_sheetContext[
"opened"] === YES)
3051 var sheetFrame = [sheet frame],
3052 sheetOrigin = CGPointMakeCopy(sheetFrame.origin);
3054 [
self _removeClipForSheet:sheet];
3055 [sheet setFrameOrigin:CGPointMake(sheetOrigin.x, [sheet frame].origin.y + sheetOrigin.y)];
3058 if (_sheetContext[
"shouldClose"] === YES)
3059 [
self _detachSheetWindow];
3061 [sheet makeKeyWindow];
3066 [
self _cleanupSheetWindow];
3070 - (void)_clipSheet:(
CPWindow)aSheet
3072 var clipRect = [_platformWindow contentBounds];
3073 clipRect.origin.y = [
self frame].origin.y + [[self contentView]
frame].origin.y;
3075 [[_platformWindow layerAtLevel:_level create:NO] clipWindow:aSheet toRect:clipRect];
3078 - (void)_removeClipForSheet:(
CPWindow)aSheet
3080 [[_platformWindow layerAtLevel:_level create:NO] removeClipForWindow:aSheet];
3088 if (_sheetContext === nil)
3091 return _sheetContext["sheet"];
3107 - (BOOL)becomesKeyOnlyIfNeeded
3116 - (BOOL)worksWhenModal
3125 return [_contentView performKeyEquivalent:anEvent];
3132 if ([anEvent _couldBeKeyEquivalent] && [
self performKeyEquivalent:anEvent])
3140 if (![
self _processKeyboardUIKey:anEvent])
3152 - (BOOL)_processKeyboardUIKey:(
CPEvent)anEvent
3161 if ([selectors count] <= 0)
3164 var selector = [selectors objectAtIndex:0];
3166 return [[
self firstResponder] tryToPerform:selector with:self];
3169 - (void)_dirtyKeyViewLoop
3171 if (_autorecalculatesKeyViewLoop)
3172 _keyViewLoopIsDirty = YES;
3180 - (BOOL)_hasKeyViewLoop:(CPArray)theViews
3183 count = [theViews count];
3185 for (i = 0; i < count; ++i)
3187 var view = theViews[i];
3189 if ([view nextKeyView] || [view previousKeyView])
3193 for (i = 0; i < count; ++i)
3195 var subviews = [theViews[i] subviews];
3197 if ([subviews count] && [
self _hasKeyViewLoop:subviews])
3211 - (void)recalculateKeyViewLoop
3213 [
self _doRecalculateKeyViewLoop];
3216 - (CPArray)_viewsSortedByPosition
3218 var views = [CPArray arrayWithObject:_contentView];
3220 views = views.concat([
self _subviewsSortedByPosition:[_contentView subviews]]);
3225 - (CPArray)_subviewsSortedByPosition:(CPArray)theSubviews
3233 theSubviews = [theSubviews copy];
3234 [theSubviews sortUsingFunction:keyViewComparator context:nil];
3236 var sortedViews = [];
3238 for (var i = 0, count = [theSubviews count]; i < count; ++i)
3240 var view = theSubviews[i],
3241 subviews = [view subviews];
3243 sortedViews.push(view);
3245 if ([subviews count])
3246 sortedViews = sortedViews.concat([
self _subviewsSortedByPosition:subviews]);
3252 - (void)_doRecalculateKeyViewLoop
3254 var views = [
self _viewsSortedByPosition];
3256 for (var index = 0, count = [views count]; index < count; ++index)
3257 [views[index] setNextKeyView:views[(index + 1) % count]];
3259 _keyViewLoopIsDirty = NO;
3262 - (void)setAutorecalculatesKeyViewLoop:(BOOL)shouldRecalculate
3264 if (_autorecalculatesKeyViewLoop === shouldRecalculate)
3267 _autorecalculatesKeyViewLoop = shouldRecalculate;
3270 - (BOOL)autorecalculatesKeyViewLoop
3272 return _autorecalculatesKeyViewLoop;
3275 - (void)selectNextKeyView:(
id)sender
3277 if (_keyViewLoopIsDirty)
3278 [
self _doRecalculateKeyViewLoop];
3280 var nextValidKeyView = nil;
3282 if ([_firstResponder isKindOfClass:[
CPView class]])
3283 nextValidKeyView = [_firstResponder nextValidKeyView];
3285 if (!nextValidKeyView)
3287 if ([_initialFirstResponder acceptsFirstResponder])
3288 nextValidKeyView = _initialFirstResponder;
3290 nextValidKeyView = [_initialFirstResponder nextValidKeyView];
3293 if (nextValidKeyView)
3294 [
self makeFirstResponder:nextValidKeyView];
3297 - (void)selectPreviousKeyView:(
id)sender
3299 if (_keyViewLoopIsDirty)
3300 [
self _doRecalculateKeyViewLoop];
3302 var previousValidKeyView = nil;
3304 if ([_firstResponder isKindOfClass:[
CPView class]])
3305 previousValidKeyView = [_firstResponder previousValidKeyView];
3307 if (!previousValidKeyView)
3309 if ([_initialFirstResponder acceptsFirstResponder])
3310 previousValidKeyView = _initialFirstResponder;
3312 previousValidKeyView = [_initialFirstResponder previousValidKeyView];
3315 if (previousValidKeyView)
3316 [
self makeFirstResponder:previousValidKeyView];
3319 - (void)selectKeyViewFollowingView:(
CPView)aView
3321 if (_keyViewLoopIsDirty)
3322 [
self _doRecalculateKeyViewLoop];
3326 if ([nextValidKeyView isKindOfClass:[
CPView class]])
3327 [
self makeFirstResponder:nextValidKeyView];
3330 - (void)selectKeyViewPrecedingView:(
CPView)aView
3332 if (_keyViewLoopIsDirty)
3333 [
self _doRecalculateKeyViewLoop];
3337 if ([previousValidKeyView isKindOfClass:[
CPView class]])
3338 [
self makeFirstResponder:previousValidKeyView];
3368 if (_defaultButton === aButton)
3372 [_defaultButton setKeyEquivalent:nil];
3374 _defaultButton = aButton;
3385 return _defaultButton;
3391 - (void)enableKeyEquivalentForDefaultButton
3393 _defaultButtonEnabled = YES;
3400 - (void)enableKeyEquivalentForDefaultButtonCell
3408 - (void)disableKeyEquivalentForDefaultButton
3410 _defaultButtonEnabled = NO;
3413 - (void)_temporarilyDisableKeyEquivalentForDefaultButton
3415 _defaultButtonDisabledTemporarily = YES;
3422 - (void)disableKeyEquivalentForDefaultButtonCell
3429 if (aKey === CPDisplayPatternTitleBinding)
3430 [
self setTitle:aValue ||
@""];
3435 - (void)_didReceivePlatformWindowWillCloseNotification:(
CPNotification)aNotification
3437 if ([aNotification
object] != _platformWindow)
3447 var lhsBounds = [lhs convertRect:[lhs bounds] toView:nil],
3448 rhsBounds = [rhs convertRect:[rhs bounds] toView:nil],
3449 lhsY = CGRectGetMinY(lhsBounds),
3450 rhsY = CGRectGetMinY(rhsBounds),
3451 lhsX = CGRectGetMinX(lhsBounds),
3452 rhsX = CGRectGetMinX(rhsBounds),
3453 intersectsVertically = MIN(CGRectGetMaxY(lhsBounds), CGRectGetMaxY(rhsBounds)) - MAX(lhsY, rhsY);
3456 if (intersectsVertically > 0)
3483 - (BOOL)_delegateRespondsToWindowWillUndoManager
3492 - (BOOL)_delegateRespondsToWindowShouldClose
3501 - (BOOL)_sendDelegateWindowShouldClose
3506 return [_delegate windowShouldClose:self];
3513 - (BOOL)_sendDelegateWindowWillReturnUndoManager
3518 return [_delegate windowWillReturnUndoManager:self];
3525 - (void)_sendDelegateWindowWillClose
3530 [_delegate windowWillClose:self];
3537 - (CGSize)_sendDelegateWindowWillResizeToSize:(CGSize)aSize
3542 return [_delegate windowWillResize:self toSize:aSize];
3553 - (void)resizeWithOldPlatformWindowSize:(CGSize)aSize
3555 if ([
self isFullPlatformWindow])
3556 return [
self setFrame:[_platformWindow visibleFrame]];
3562 var
frame = [_platformWindow contentBounds],
3563 newFrame = CGRectMakeCopy(_frame),
3564 dX = (CGRectGetWidth(
frame) - aSize.width) /
3566 dY = (CGRectGetHeight(
frame) - aSize.height) /
3570 newFrame.origin.x += dX;
3573 newFrame.size.width += dX;
3576 newFrame.origin.y += dY;
3579 newFrame.size.height += dY;
3581 [
self _setFrame:newFrame display:YES animate:NO constrainWidth:YES constrainHeight:YES];
3587 - (void)setAutoresizingMask:(
unsigned)anAutoresizingMask
3589 _autoresizingMask = anAutoresizingMask;
3595 - (unsigned)autoresizingMask
3597 return _autoresizingMask;
3603 - (CGPoint)convertBaseToGlobal:(CGPoint)aPoint
3612 - (CGPoint)_nativeScrollOffset
3615 return CGPointMake(_windowView._DOMElement.scrollLeft, _windowView._DOMElement.scrollTop);
3625 - (CGPoint)convertGlobalToBase:(CGPoint)aPoint
3633 - (CGPoint)convertBaseToPlatformWindow:(CGPoint)aPoint
3635 if ([
self _sharesChromeWithPlatformWindow])
3636 return CGPointMakeCopy(aPoint);
3638 var origin = [
self frame].origin,
3639 scrollOffset = [
self _nativeScrollOffset];
3641 return CGPointMake(aPoint.x + origin.x - scrollOffset.x, aPoint.y + origin.y - scrollOffset.y);
3647 - (CGPoint)convertPlatformWindowToBase:(CGPoint)aPoint
3649 if ([
self _sharesChromeWithPlatformWindow])
3650 return CGPointMakeCopy(aPoint);
3652 var origin = [
self frame].origin,
3653 scrollOffset = [
self _nativeScrollOffset];
3655 return CGPointMake(aPoint.x - origin.x + scrollOffset.x, aPoint.y - origin.y + scrollOffset.y);
3658 - (CGPoint)convertScreenToBase:(CGPoint)aPoint
3663 - (CGPoint)convertBaseToScreen:(CGPoint)aPoint
3668 - (void)_setSharesChromeWithPlatformWindow:(BOOL)shouldShareFrameWithPlatformWindow
3671 if (shouldShareFrameWithPlatformWindow && [
CPPlatform isBrowser])
3674 _sharesChromeWithPlatformWindow = shouldShareFrameWithPlatformWindow;
3676 [
self _updateShadow];
3679 - (BOOL)_sharesChromeWithPlatformWindow
3681 return _sharesChromeWithPlatformWindow;
3692 return _undoManager;
3695 var documentUndoManager = [[_windowController document] undoManager];
3697 if (documentUndoManager)
3698 return documentUndoManager;
3701 if ([
self _delegateRespondsToWindowWillUndoManager])
3702 return [
self _sendDelegateWindowWillReturnUndoManager];
3708 return _undoManager;
3715 - (void)undo:(
id)aSender
3724 - (void)redo:(
id)aSender
3729 - (BOOL)containsPoint:(CGPoint)aPoint
3731 return CGRectContainsPoint(_frame, aPoint);
3735 - (BOOL)_isValidMousePoint:(CGPoint)aPoint
3741 return CGRectContainsPoint(mouseFrame, aPoint);
3751 - (void)setFullBridge:(BOOL)shouldBeFullBridge
3753 _CPReportLenientDeprecation([
self class], _cmd,
@selector(setFullPlatformWindow:));
3762 - (BOOL)isFullBridge
3770 - (CGPoint)convertBaseToBridge:(CGPoint)aPoint
3778 - (CGPoint)convertBridgeToBase:(CGPoint)aPoint
3787 return fromValue + (toValue - fromValue) * progress;
3791 @implementation _CPWindowFrameAnimation :
CPAnimation 3796 CGRect _targetFrame;
3799 - (id)initWithWindow:(
CPWindow)aWindow targetFrame:(CGRect)aTargetFrame
3801 self = [
super initWithDuration:[aWindow
animationResizeTime:aTargetFrame] animationCurve:CPAnimationLinear];
3807 _targetFrame = CGRectMakeCopy(aTargetFrame);
3808 _startFrame = CGRectMakeCopy([_window
frame]);
3814 - (void)setCurrentProgress:(
float)aProgress
3816 [
super setCurrentProgress:aProgress];
3818 var value = [
self currentValue];
3821 [_window _setAnimating:NO];
3823 var newFrame = CGRectMake(
3824 interpolate(CGRectGetMinX(_startFrame), CGRectGetMinX(_targetFrame), value),
3825 interpolate(CGRectGetMinY(_startFrame), CGRectGetMinY(_targetFrame), value),
3826 interpolate(CGRectGetWidth(_startFrame), CGRectGetWidth(_targetFrame), value),
3827 interpolate(CGRectGetHeight(_startFrame), CGRectGetHeight(_targetFrame), value));
3829 [_window setFrame:newFrame display:YES animate:NO];
3834 @implementation _CPWindowFrameAnimationDelegate :
CPObject 3839 - (id)initWithWindow:(
CPWindow)aWindow
3841 self = [
super init];
3848 - (BOOL)animationShouldStart:(
CPAnimation)animation
3850 [_window _setAnimating:YES];
3851 [_window _startLiveResize];
3858 [_window _setAnimating:NO];
3859 [_window _endLiveResize];
3864 [_window _setAnimating:NO];
3865 [_window _endLiveResize];
3873 - (id)_dragHitTest:(CGPoint)aPoint pasteboard:(
CPPasteboard)aPasteboard
3876 if (!_inclusiveRegisteredDraggedTypes)
3886 hitView = [_windowView hitTest:adjustedPoint];
3888 while (hitView && ![aPasteboard availableTypeFromArray:[hitView registeredDraggedTypes]])
3889 hitView = [hitView superview];
3894 if ([aPasteboard availableTypeFromArray:[
self registeredDraggedTypes]])
3904 - (void)_addTrackingAreaView:(
CPView)aView
3906 var trackingAreas = [aView trackingAreas];
3908 for (var i = 0; i < trackingAreas.length; i++)
3909 [
self _addTrackingArea:trackingAreas[i]];
3912 - (void)_removeTrackingAreaView:(
CPView)aView
3914 var trackingAreas = [aView trackingAreas];
3916 for (var i = 0; i < trackingAreas.length; i++)
3917 [self _removeTrackingArea:trackingAreas[i]];
3922 var trackingAreaView = [trackingArea
view];
3924 if (![_trackingAreaViews containsObjectIdenticalTo:trackingAreaView])
3925 [_trackingAreaViews addObject:trackingAreaView];
3930 [
self _insertTrackingArea:trackingArea assumeInside:([trackingArea
options] & CPTrackingAssumeInside)];
3937 [
self _purgeTrackingArea:trackingArea];
3939 var trackingAreaView = [trackingArea
view];
3941 [_trackingAreaViews removeObjectIdenticalTo:trackingAreaView];
3944 - (void)_insertTrackingArea:(
CPTrackingArea)trackingArea assumeInside:(BOOL)assumeInside
3946 if (_handlingTrackingAreaEvent)
3947 _restartHandlingTrackingAreaEvent = YES;
3951 if (_handlingTrackingAreaEvent)
3952 [_mouseEnteredStack addObject:trackingArea];
3954 [_previousMouseEnteredStack addObject:trackingArea];
3960 if (_handlingTrackingAreaEvent)
3962 [_mouseEnteredStack removeObjectIdenticalTo:trackingArea];
3964 var i = _queuedEvents.length;
3967 if ([_queuedEvents[i] trackingArea] === trackingArea)
3968 [_queuedEvents removeObjectAtIndex:i];
3970 _cursorUpdateStack = [];
3971 _activeCursorTrackingArea = nil;
3975 [_previousMouseEnteredStack removeObjectIdenticalTo:trackingArea];
3976 [_previousCursorUpdateStack removeObjectIdenticalTo:trackingArea];
3980 - (void)_handleTrackingAreaEvent:(
CPEvent)anEvent
3982 _handlingTrackingAreaEvent = YES;
3990 _restartHandlingTrackingAreaEvent = NO;
3992 _mouseEnteredStack = [];
3993 _cursorUpdateStack = [];
4001 [
self _handleMouseMovedAndEnteredEventsForEvent:anEvent atPoint:point dragging:dragging];
4005 [
self _handleMouseExitedEventsForEvent:anEvent atPoint:point dragging:dragging];
4009 if (_cursorUpdateStack.length > 0)
4011 [
self _handleCursorUpdateEventsForEvent:anEvent atPoint:point dragging:dragging];
4017 [_windowView setCursorForLocation:point resizing:NO];
4018 _activeCursorTrackingArea = nil;
4024 while (_queuedEvents.length > 0)
4026 var queuedEvent = _queuedEvents[0],
4027 trackingArea = [queuedEvent trackingArea],
4028 trackingOwner = [trackingArea owner];
4030 switch ([queuedEvent type])
4033 [trackingOwner mouseEntered:queuedEvent];
4037 [trackingOwner mouseExited:queuedEvent];
4041 [trackingOwner cursorUpdate:queuedEvent];
4045 if (queuedEvent === _queuedEvents[0])
4046 [_queuedEvents removeObjectAtIndex:0];
4051 _previousMouseEnteredStack = _mouseEnteredStack;
4052 _previousCursorUpdateStack = _cursorUpdateStack;
4054 while (_restartHandlingTrackingAreaEvent)
4056 _handlingTrackingAreaEvent = NO;
4059 - (void)_handleMouseMovedAndEnteredEventsForEvent:(
CPEvent)anEvent atPoint:(CGPoint)point dragging:(BOOL)dragging
4061 var isKeyWindow = [
self isKeyWindow];
4063 for (var i = 0; i < _trackingAreaViews.length; i++)
4065 var aView = _trackingAreaViews[i],
4066 trackingAreas = [aView trackingAreas];
4071 for (var j = 0; j < trackingAreas.length; j++)
4073 var aTrackingArea = trackingAreas[j],
4074 trackingOptions = [aTrackingArea options],
4075 trackingImplementedMethods = [aTrackingArea implementedOwnerMethods];
4081 (CGRectContainsPoint([aTrackingArea windowRect], point))))
4086 [_mouseEnteredStack addObject:aTrackingArea];
4088 if ([_previousMouseEnteredStack containsObjectIdenticalTo:aTrackingArea])
4093 [[aTrackingArea owner] mouseMoved:anEvent];
4107 [
self _queueTrackingEvent:mouseEnteredEvent];
4109 [_queuedEvents addObject:mouseEnteredEvent];
4113 [_cursorUpdateStack addObject:aTrackingArea];
4118 - (void)_handleMouseExitedEventsForEvent:(
CPEvent)anEvent atPoint:(CGPoint)point dragging:(BOOL)dragging
4122 for (var i = 0; i < _previousMouseEnteredStack.length; i++)
4124 var aTrackingArea = _previousMouseEnteredStack[i],
4125 trackingOptions = [aTrackingArea options];
4127 if ([_mouseEnteredStack containsObjectIdenticalTo:aTrackingArea])
4134 var theView = [aTrackingArea owner],
4145 [
self _queueTrackingEvent:mouseExitedEvent];
4147 [_queuedEvents addObject:mouseExitedEvent];
4152 if (aTrackingArea === _activeCursorTrackingArea)
4154 _previousCursorUpdateStack = [];
4155 _activeCursorTrackingArea = nil;
4160 - (void)_handleCursorUpdateEventsForEvent:(
CPEvent)anEvent atPoint:(CGPoint)point dragging:(BOOL)dragging
4162 var overlappingTrackingAreas = [];
4164 for (var i = 0; i < _cursorUpdateStack.length; i++)
4166 var aTrackingArea = _cursorUpdateStack[i];
4168 if ((![_previousCursorUpdateStack containsObjectIdenticalTo:aTrackingArea]) || (aTrackingArea === _activeCursorTrackingArea))
4169 [overlappingTrackingAreas addObject:aTrackingArea];
4172 if (overlappingTrackingAreas.length === 0)
4175 var frontmostTrackingArea = overlappingTrackingAreas[0],
4176 frontmostView = [frontmostTrackingArea view];
4178 for (var i = 1; i < overlappingTrackingAreas.length; i++)
4180 var aTrackingArea = overlappingTrackingAreas[i],
4181 aView = [aTrackingArea view];
4186 if (aView === _windowView)
4191 if (frontmostView === _windowView)
4193 frontmostTrackingArea = aTrackingArea;
4194 frontmostView = aView;
4202 var searchingView = aView;
4204 while ((searchingView !== _contentView) && ([searchingView superview] !== frontmostView))
4205 searchingView = [searchingView superview];
4207 if (searchingView !== _contentView)
4209 frontmostTrackingArea = aTrackingArea;
4210 frontmostView = aView;
4219 var firstView = frontmostView,
4220 firstSuperview = [firstView superview];
4222 while (firstView !== _contentView)
4224 var secondView = aView,
4225 secondSuperview = [secondView superview];
4227 while ((secondSuperview !== _contentView) && (firstSuperview !== secondSuperview))
4229 secondView = secondSuperview;
4230 secondSuperview = [secondView superview];
4233 if (firstSuperview === secondSuperview)
4236 firstView = firstSuperview;
4237 firstSuperview = [firstView superview];
4240 if (firstSuperview !== secondSuperview)
4243 var firstSuperviewSubviews = [firstSuperview subviews],
4244 firstViewIndex = [firstSuperviewSubviews indexOfObject:firstView],
4245 secondViewIndex = [firstSuperviewSubviews indexOfObject:secondView];
4247 if (secondViewIndex > firstViewIndex)
4249 frontmostTrackingArea = aTrackingArea;
4250 frontmostView = aView;
4254 if (frontmostTrackingArea !== _activeCursorTrackingArea)
4266 [
self _queueTrackingEvent:cursorUpdateEvent];
4268 [_queuedEvents addObject:cursorUpdateEvent];
4270 _activeCursorTrackingArea = frontmostTrackingArea;
4274 - (void)_queueTrackingEvent:(
CPEvent)anEvent
4284 var eventType = [anEvent
type],
4287 switch ([anEvent type])
4290 for (var i = 0; i < _queuedTrackingEvents.length; i++)
4292 var queuedEvent = _queuedTrackingEvents[i];
4294 if (([queuedEvent trackingArea] === trackingArea) && ([queuedEvent type] ===
CPMouseExited))
4296 [_queuedTrackingEvents removeObjectAtIndex:i];
4301 [_queuedTrackingEvents addObject:anEvent];
4305 for (var i = 0; i < _queuedTrackingEvents.length; i++)
4307 var queuedEvent = _queuedTrackingEvents[i];
4309 if (([queuedEvent trackingArea] === trackingArea) && ([queuedEvent type] ===
CPMouseEntered))
4311 [_queuedTrackingEvents removeObjectAtIndex:i];
4316 [_queuedTrackingEvents addObject:anEvent];
4320 [_queuedTrackingEvents addObject:anEvent];
4325 - (void)_flushTrackingEventQueueForMouseAt:(CGPoint)point
4327 for (var i = 0; i < _queuedTrackingEvents.length; i++)
4329 var queuedEvent = _queuedTrackingEvents[i],
4330 trackingArea = [queuedEvent trackingArea],
4331 trackingOwner = [trackingArea owner];
4333 switch ([queuedEvent type])
4336 [trackingOwner mouseEntered:queuedEvent];
4340 [trackingOwner mouseExited:queuedEvent];
4344 [trackingOwner updateTrackingAreas];
4346 if (CGRectContainsPoint([trackingArea windowRect], point))
4347 [trackingOwner cursorUpdate:queuedEvent];
4353 _queuedTrackingEvents = [];
4358 function _CPWindowFullPlatformWindowSessionMake(aWindowView, aContentRect, hasShadow, aLevel)
4360 return { windowView:aWindowView, contentRect:aContentRect, hasShadow:hasShadow, level:aLevel };
4368 - (void)_setAnimating:(BOOL)aValue
4370 _isAnimating = aValue;
4376 - (void)_setChildOrdering:(CPWindowOrderingMode)aValue
4378 _childOrdering = aValue;
void setHasShadow:(BOOL shouldHaveShadow)
Used to implement exception handling (creating & raising).
BOOL makeFirstResponder:(CPResponder aResponder)
void setFrame:(CGRect aFrame)
CPWindow setParentWindow:(CPWindow parentWindow)
CPView previousValidKeyView()
CGPoint convertBaseToPlatformWindow:(CGPoint aPoint)
var CPWindowDelegate_windowShouldClose_
CPWindowPositionFlexibleTop
void removeWindowController:(CPWindowController aWindowController)
CPTrackingOwnerImplementsCursorUpdate
CPWindowResizeStyleModern
CPWindowPositionFlexibleRight
void setRepresentedFilename:(CPString aFilePath)
void setShowsResizeIndicator:(BOOL shouldShowResizeIndicator)
CGPoint convertBaseToScreen:(CGPoint aPoint)
void addObserver:selector:name:object:(id anObserver, [selector] SEL aSelector, [name] CPString aNotificationName, [object] id anObject)
void setTitle:(CPString aTitle)
CPResponder firstResponder()
CGPoint locationInWindow()
var CPWindowActionMessageKeys
CPTrackingAreaOptions options()
void setPlatformWindow:(CPPlatformWindow aPlatformWindow)
var CPWindowResizeStyleGlobalChangeNotification
void postNotificationName:object:(CPString aNotificationName, [object] id anObject)
void raise:reason:(CPString aName, [reason] CPString aReason)
CPBorderlessBridgeWindowMask
CPString charactersIgnoringModifiers()
var CPWindowMinVisibleHorizontalMargin
CPArray selectorsForKey:modifierFlags:(CPString aKey, [modifierFlags] unsigned aFlag)
CPTrackingActiveInKeyWindow
void keyDown:(CPEvent anEvent)
BOOL isFullPlatformWindow()
CPTrackingActiveInActiveApp
CPNotificationCenter defaultCenter()
A mutable key-value pair collection.
void dragImage:fromWindow:at:offset:event:pasteboard:source:slideBack:(CPImage anImage, [fromWindow] CPWindow aWindow, [at] CGPoint imageLocation, [offset] CGSize mouseOffset, [event] CPEvent anEvent, [pasteboard] CPPasteboard aPasteboard, [source] id aSourceObject, [slideBack] BOOL slideBack)
CPTrackingActiveWhenFirstResponder
void setFrameSize:(CGSize aSize)
void setFrame:display:animate:(CGRect aFrame, [display] BOOL shouldDisplay, [animate] BOOL shouldAnimate)
id initWithContentRect:styleMask:(CGRect aContentRect, [styleMask] unsigned aStyleMask)
void orderFront:(id aSender)
CPWindowPositionFlexibleLeft
void flagsChanged:(CPEvent anEvent)
An immutable string (collection of characters).
CPUndoManager undoManager()
CGPoint convertBaseToGlobal:(CGPoint aPoint)
CPView nextValidKeyView()
void selectNextKeyView:(id sender)
CPWindowConstrainToScreen
CPTrackingOwnerImplementsMouseMoved
void miniaturize:(id sender)
CGPoint convertPlatformWindowToBase:(CGPoint aPoint)
CPDragServer sharedDragServer()
void doCommandBySelector:(SEL aSelector)
void makeKeyAndOrderFront:(id aSender)
void disableKeyEquivalentForDefaultButton()
CPTrackingOwnerImplementsMouseExited
CPColor backgroundColor()
void dragView:fromWindow:at:offset:event:pasteboard:source:slideBack:(CPView aView, [fromWindow] CPWindow aWindow, [at] CGPoint viewLocation, [offset] CGSize mouseOffset, [event] CPEvent mouseDownEvent, [pasteboard] CPPasteboard aPasteboard, [source] id aSourceObject, [slideBack] BOOL slideBack)
A notification that can be posted to a CPNotificationCenter.
CPTimer scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:(CPTimeInterval seconds, [target] id aTarget, [selector] SEL aSelector, [userInfo] id userInfo, [repeats] BOOL shouldRepeat)
void setDefaultButton:(CPButton aButton)
void recalculateKeyViewLoop()
void setAutoresizingMask:(unsigned anAutoresizingMask)
CPInternalInconsistencyException
CPTimeInterval timestamp()
An mutable collection which may contain a specific object numerous times.
id enterExitEventWithType:location:modifierFlags:timestamp:windowNumber:context:eventNumber:trackingArea:(CPEventType anEventType, [location] CGPoint aPoint, [modifierFlags] unsigned modifierFlags, [timestamp] CPTimeInterval aTimestamp, [windowNumber] int aWindowNumber, [context] CPGraphicsContext aGraphicsContext, [eventNumber] int anEventNumber, [trackingArea] CPTrackingArea aTrackingArea)
void setFrameOrigin:(CGPoint anOrigin)
A general mechanism for user action "undo".
CPString lastPathComponent()
A timer object that can send a message after the given time interval.
void enableKeyEquivalentForDefaultButton()
void setLevel:(int aLevel)
void keyUp:(CPEvent anEvent)
void setMovableByWindowBackground:(BOOL shouldBeMovableByWindowBackground)
void setValue:forKey:(id aValue, [forKey] CPString aKey)
CPTrackingAreaOptions CPTrackingMouseEnteredAndExited
Sends messages (CPNotification) between objects.
void selectPreviousKeyView:(id sender)
var CPWindowMinVisibleVerticalMargin
void setFullPlatformWindow:(BOOL shouldBeFullPlatformWindow)
var CPWindowDelegate_windowWillClose_
void setNextResponder:(CPResponder aResponder)
CPCarriageReturnCharacter
void removeObserver:name:object:(id anObserver, [name] CPString aNotificationName, [object] id anObject)
CPTrackingEnabledDuringMouseDrag
void orderWindow:relativeTo:(CPWindowOrderingMode orderingMode, [relativeTo] int otherWindowNumber)
CGRect contentRectForFrameRect:(CGRect aFrame)
CPPlatformWindow platformWindow()
id URLWithString:(CPString URLString)
id valueForAttributeWithName:forClass:(CPString aName, [forClass] id aClass)
void setRepresentedURL:(CPURL aURL)
CGPoint convertScreenToBase:(CGPoint aPoint)
CPTrackingOwnerImplementsMouseEntered
CPWindowOrderingMode CPWindowAbove
CPTrackingArea trackingArea()
BOOL showsResizeIndicator()
var CPWindowDelegate_windowWillResize_toSize_
CPWindowPositionFlexibleBottom
void setContentView:(CPView aView)
CPTimeInterval animationResizeTime:(CGRect newWindowFrame)
var CPWindowDelegate_windowWillReturnUndoManager_
CPHUDBackgroundWindowMask