30 @
typedef _CPWindowFullPlatformWindowSession
36 - (BOOL)windowShouldClose:(
CPWindow)aWindow;
46 - (void)windowWillClose:(
CPWindow)aWindow;
51 CPWindowDelegate_windowWillReturnUndoManager_ = 1 << 2,
66 CPLeftArrowFunctionKey,
67 CPRightArrowFunctionKey,
69 CPDownArrowFunctionKey,
71 CPPageDownFunctionKey,
141 BOOL _hasBeenOrderedIn;
142 BOOL _isMiniaturized;
145 BOOL _isMovableByWindowBackground;
147 BOOL _constrainsToUsableScreen;
148 unsigned _shadowStyle;
149 BOOL _showsResizeIndicator;
151 int _positioningMask;
152 CGRect _positioningScreenRect;
154 BOOL _isDocumentEdited;
155 BOOL _isDocumentSaving;
163 CPArray _mouseEnteredStack;
164 CPView _leftMouseDownView;
165 CPView _rightMouseDownView;
170 BOOL _hasBecomeKeyWindow;
171 id <CPWindowDelegate> _delegate;
172 unsigned _implementedDelegateMethods;
176 BOOL _acceptsMouseMovedEvents;
177 BOOL _ignoresMouseEvents;
185 CPURL _representedURL;
187 CPSet _registeredDraggedTypes;
188 CPArray _registeredDraggedTypesArray;
192 BOOL _defaultButtonEnabled;
194 BOOL _autorecalculatesKeyViewLoop;
195 BOOL _keyViewLoopIsDirty;
197 BOOL _sharesChromeWithPlatformWindow;
201 DOMElement _DOMElement;
204 unsigned _autoresizingMask;
206 BOOL _isFullPlatformWindow;
207 _CPWindowFullPlatformWindowSession _fullPlatformWindowSession;
210 CPArray _childWindows;
211 CPWindowOrderingMode _childOrdering;
216 _CPWindowFrameAnimation _frameAnimation;
219 + (Class)_binderClassForBinding:(
CPString)aBinding
224 return [
super _binderClassForBinding:aBinding];
247 - (id)initWithContentRect:(CGRect)aContentRect styleMask:(
unsigned)aStyleMask
253 var windowViewClass = [[
self class] _windowViewClassForStyleMask:aStyleMask];
255 _frame = [windowViewClass frameRectForContentRect:aContentRect];
256 _constrainsToUsableScreen = YES;
268 _frame.size.height = MIN(768.0, visibleFrame.size.height);
269 _frame.size.width = MIN(1024.0, visibleFrame.size.width);
270 _frame.origin.x = (visibleFrame.size.width - _frame.size.width) / 2;
271 _frame.origin.y = (visibleFrame.size.height - _frame.size.height) / 2;
278 _isFullPlatformWindow = NO;
279 _registeredDraggedTypes = [CPSet set];
280 _registeredDraggedTypesArray = [];
281 _acceptsMouseMovedEvents = YES;
283 _hasBeenOrderedIn = NO;
294 _windowNumber = [CPApp._windows count];
295 CPApp._windows[_windowNumber] =
self;
297 _styleMask = aStyleMask;
299 [
self setLevel:CPNormalWindowLevel];
302 _windowView = [[windowViewClass alloc] initWithFrame:CGRectMake(0.0, 0.0, CGRectGetWidth(_frame), CGRectGetHeight(_frame)) styleMask:aStyleMask];
304 [_windowView _setWindow:self];
305 [_windowView setNextResponder:self];
308 _minSize = [
self _calculateMinSizeForProposedSize:CGSizeMake(0.0, 0.0)];
309 _maxSize = CGSizeMake(1000000.0, 1000000.0);
316 _firstResponder =
self;
319 _DOMElement = document.createElement(
"div");
321 _DOMElement.style.position =
"absolute";
322 _DOMElement.style.visibility =
"visible";
323 _DOMElement.style.zIndex = 0;
325 if (![
self _sharesChromeWithPlatformWindow])
327 CPDOMDisplayServerSetStyleLeftTop(_DOMElement, NULL, CGRectGetMinX(_frame), CGRectGetMinY(_frame));
330 CPDOMDisplayServerSetStyleSize(_DOMElement, 1, 1);
331 CPDOMDisplayServerAppendChild(_DOMElement, _windowView._DOMElement);
336 [
self setHasShadow:aStyleMask !== CPBorderlessWindowMask];
341 _autorecalculatesKeyViewLoop = NO;
342 _defaultButtonEnabled = YES;
343 _keyViewLoopIsDirty = NO;
344 _hasBecomeKeyWindow = NO;
350 name:CPWindowResizeStyleGlobalChangeNotification
359 return _platformWindow;
375 _platformWindow = aPlatformWindow;
376 [_platformWindow _setTitle:_title window:self];
386 + (Class)_windowViewClassForStyleMask:(
unsigned)aStyleMask
389 return _CPHUDWindowView;
392 return _CPBorderlessWindowView;
395 return _CPDocModalWindowView;
397 else if (aStyleMask & _CPModalWindowMask)
398 return _CPModalWindowView;
400 return _CPStandardWindowView;
403 + (Class)_windowViewClassForFullPlatformWindowStyleMask:(
unsigned)aStyleMask
405 return _CPBorderlessBridgeWindowView;
412 if (_positioningScreenRect)
416 origin =
frame.origin;
418 if (actualScreenRect)
423 origin.x *= (actualScreenRect.size.width / _positioningScreenRect.size.width);
425 else if (_positioningMask & CPWindowPositionFlexibleLeft)
428 origin.x += actualScreenRect.size.width - _positioningScreenRect.size.width;
430 else if (_positioningMask & CPWindowPositionFlexibleRight)
438 origin.y *= (actualScreenRect.size.height / _positioningScreenRect.size.height);
440 else if (_positioningMask & CPWindowPositionFlexibleTop)
443 origin.y += actualScreenRect.size.height - _positioningScreenRect.size.height;
457 if ([
self _hasKeyViewLoop:[_contentView subviews]])
459 var views = [
self _viewsSortedByPosition],
460 count = [views count];
464 for (var i = 1; i < count; ++i)
468 if ([view nextKeyView])
470 [_contentView setNextKeyView:view];
479 [
self _doRecalculateKeyViewLoop];
483 - (void)_setWindowView:(
CPView)aWindowView
485 if (_windowView === aWindowView)
488 var oldWindowView = _windowView;
490 _windowView = aWindowView;
494 [oldWindowView _setWindow:nil];
495 [oldWindowView noteToolbarChanged];
498 CPDOMDisplayServerRemoveChild(_DOMElement, oldWindowView._DOMElement);
505 CPDOMDisplayServerAppendChild(_DOMElement, _windowView._DOMElement);
508 var contentRect = [_contentView convertRect:[_contentView bounds] toView:nil];
510 contentRect.origin = [
self convertBaseToGlobal:contentRect.origin];
512 [_windowView _setWindow:self];
513 [_windowView setNextResponder:self];
514 [_windowView addSubview:_contentView];
515 [_windowView setTitle:_title];
516 [_windowView noteToolbarChanged];
517 [_windowView setShowsResizeIndicator:[
self showsResizeIndicator]];
519 [
self setFrame:[
self frameRectForContentRect:contentRect]];
529 - (void)setFullPlatformWindow:(BOOL)shouldBeFullPlatformWindow
531 if (![_platformWindow supportsFullPlatformWindows])
534 shouldBeFullPlatformWindow = !!shouldBeFullPlatformWindow;
536 if (_isFullPlatformWindow === shouldBeFullPlatformWindow)
539 _isFullPlatformWindow = shouldBeFullPlatformWindow;
541 if (_isFullPlatformWindow)
543 _fullPlatformWindowSession = _CPWindowFullPlatformWindowSessionMake(_windowView, [
self contentRectForFrameRect:[
self frame]], [
self hasShadow], [
self level]);
545 var fullPlatformWindowViewClass = [[
self class] _windowViewClassForFullPlatformWindowStyleMask:_styleMask],
546 windowView = [[fullPlatformWindowViewClass alloc] initWithFrame:CGRectMakeZero() styleMask:_styleMask];
548 if (_platformWindow != [
CPPlatformWindow primaryPlatformWindow] && [_platformWindow _hasInitializeInstanceWithWindow])
549 [_platformWindow setContentRect:[
self frame]];
551 [
self _setWindowView:windowView];
553 [
self setLevel:CPBackgroundWindowLevel];
556 [
self setFrame:[_platformWindow visibleFrame]];
560 var windowView = _fullPlatformWindowSession.windowView;
562 [
self _setWindowView:windowView];
564 [
self setLevel:_fullPlatformWindowSession.level];
565 [
self setHasShadow:_fullPlatformWindowSession.hasShadow];
568 [
self setFrame:[windowView frameRectForContentRect:_fullPlatformWindowSession.contentRect]];
575 - (BOOL)isFullPlatformWindow
577 return _isFullPlatformWindow;
583 - (unsigned)styleMask
606 + (CGRect)frameRectForContentRect:(CGRect)aContentRect styleMask:(
unsigned)aStyleMask
608 return [[[
self class] _windowViewClassForStyleMask:aStyleMask] frameRectForContentRect:aContentRect];
615 - (CGRect)contentRectForFrameRect:(CGRect)aFrame
617 return [_windowView contentRectForFrameRect:aFrame];
625 - (CGRect)frameRectForContentRect:(CGRect)aContentRect
627 return [_windowView frameRectForContentRect:aContentRect];
635 return CGRectMakeCopy(_frame);
645 - (void)setFrame:(CGRect)aFrame display:(BOOL)shouldDisplay animate:(BOOL)shouldAnimate
647 [
self _setFrame:aFrame display:shouldDisplay animate:shouldAnimate constrainWidth:NO constrainHeight:YES];
650 - (void)_setFrame:(CGRect)aFrame display:(BOOL)shouldDisplay animate:(BOOL)shouldAnimate constrainWidth:(BOOL)shouldConstrainWidth constrainHeight:(BOOL)shouldConstrainHeight
652 var
frame = CGRectMakeCopy(aFrame),
653 value =
frame.origin.x,
654 delta = value - FLOOR(value);
657 frame.origin.x = value > 0.879 ? CEIL(value) : FLOOR(value);
659 value =
frame.origin.y;
660 delta = value - FLOOR(value);
663 frame.origin.y = value > 0.879 ? CEIL(value) : FLOOR(value);
665 value =
frame.size.width;
666 delta = value - FLOOR(value);
669 frame.size.width = value > 0.15 ? CEIL(value) : FLOOR(value);
671 value =
frame.size.height;
672 delta = value - FLOOR(value);
675 frame.size.height = value > 0.15 ? CEIL(value) : FLOOR(value);
677 frame = [
self _constrainFrame:frame toUsableScreenWidth:shouldConstrainWidth andHeight:shouldConstrainHeight];
681 [_frameAnimation stopAnimation];
682 _frameAnimation = [[_CPWindowFrameAnimation alloc] initWithWindow:self targetFrame:frame];
684 [_frameAnimation startAnimation];
688 var origin = _frame.origin,
689 newOrigin =
frame.origin,
690 originMoved = !CGPointEqualToPoint(origin, newOrigin);
694 delta = CGPointMake(newOrigin.x - origin.x, newOrigin.y - origin.y);
695 origin.x = newOrigin.x;
696 origin.y = newOrigin.y;
699 if (![
self _sharesChromeWithPlatformWindow])
701 CPDOMDisplayServerSetStyleLeftTop(_DOMElement, NULL, origin.x, origin.y);
706 if ([
self attachedSheet])
707 [
self _setAttachedSheetFrameOrigin];
712 var size = _frame.size,
713 newSize =
frame.size;
715 if (!CGSizeEqualToSize(size, newSize))
717 size.width = newSize.width;
718 size.height = newSize.height;
720 [_windowView setFrameSize:size];
723 [_shadowView setNeedsLayout];
729 if ([
self _sharesChromeWithPlatformWindow])
730 [_platformWindow setContentRect:_frame];
733 [
self _moveChildWindows:delta];
736 if ([_platformWindow _canUpdateContentRect] && _isFullPlatformWindow && _platformWindow != [
CPPlatformWindow primaryPlatformWindow])
737 [_platformWindow setContentRect:aFrame];
744 - (CGRect)_constrainFrame:(CGRect)aFrame toUsableScreenWidth:(BOOL)constrainWidth andHeight:(BOOL)constrainHeight
746 var
frame = CGRectMakeCopy(aFrame);
748 if (!_constrainsToUsableScreen || !_isVisible)
751 var usableRect = [_platformWindow usableContentFrame];
756 frame.origin.x = MAX(frame.origin.x, usableRect.origin.x);
759 var maxX = MIN(CGRectGetMaxX(frame), CGRectGetMaxX(usableRect));
760 frame.origin.x = maxX - frame.size.
width;
763 var usableWidth = CGRectGetWidth(usableRect);
765 if (CGRectGetWidth(frame) > usableWidth)
767 frame.origin.x = CGRectGetMinX(usableRect);
768 frame.size.width = MAX(usableWidth, _minSize.width);
775 frame.origin.y = MAX(frame.origin.y, usableRect.origin.y);
778 var maxY = MIN(CGRectGetMaxY(frame), CGRectGetMaxY(usableRect));
779 frame.origin.y = maxY - frame.size.height;
782 var usableHeight = CGRectGetHeight(usableRect);
784 if (CGRectGetHeight(frame) > usableHeight)
786 frame.origin.y = CGRectGetMinY(usableRect);
787 frame.size.height = MAX(usableHeight, _minSize.height);
801 - (CGRect)_constrainOriginOfFrame:(CGRect)aFrame
803 var frame = CGRectMakeCopy(aFrame);
805 if (!_constrainsToUsableScreen || !_isVisible)
808 var usableRect = [_platformWindow usableContentFrame],
809 minimumSize = [_windowView _minimumResizeSize];
812 frame.origin.x = MAX(frame.origin.x, CGRectGetMinX(usableRect) + minimumSize.width - CGRectGetWidth(frame));
815 frame.origin.x = MIN(frame.origin.x, CGRectGetMaxX(usableRect) - minimumSize.width);
818 frame.origin.y = MAX(frame.origin.y, CGRectGetMinY(usableRect));
826 - (void)_moveChildWindows:(CGPoint)delta
828 [_childWindows enumerateObjectsUsingBlock:function(childWindow)
830 var origin = [childWindow frame].origin;
832 [childWindow setFrameOrigin:CGPointMake(origin.x + delta.x, origin.y + delta.y)];
842 - (void)setFrame:(CGRect)aFrame display:(BOOL)shouldDisplay
851 - (void)setFrame:(CGRect)aFrame
860 - (void)setFrameOrigin:(CGPoint)anOrigin
862 var frame = [
self _constrainOriginOfFrame:CGRectMake(anOrigin.x, anOrigin.y, _frame.size.width, _frame.size.height)];
863 [
self _setFrame:frame display:YES animate:NO constrainWidth:NO constrainHeight:NO];
870 - (void)setFrameSize:(CGSize)aSize
872 [
self setFrame:CGRectMake(CGRectGetMinX(_frame), CGRectGetMinY(_frame), aSize.width, aSize.height)
display:YES
animate:NO];
879 - (void)orderFront:(
id)aSender
890 [_platformWindow _setShouldUpdateContentRect:NO];
894 [_parentView orderFront:self];
897 var wasVisible = _isVisible;
899 [_platformWindow orderFront:self];
900 [_platformWindow order:CPWindowAbove window:self relativeTo:nil];
904 [
self _setFrame:_frame display:YES animate:NO constrainWidth:YES constrainHeight:YES];
907 if (!
CPApp._keyWindow)
908 [
self makeKeyWindow];
910 if ([
self isKeyWindow] && (_firstResponder ===
self || !_firstResponder))
911 [
self makeFirstResponder:_initialFirstResponder];
913 if (!
CPApp._mainWindow)
914 [
self makeMainWindow];
916 [_platformWindow _setShouldUpdateContentRect:YES];
923 - (void)_parentDidOrderInChild
930 - (void)_windowWillBeAddedToTheDOM
934 name:_CPPlatformWindowWillCloseNotification
937 [[
self contentView] _addObservers];
943 - (void)_windowWillBeRemovedFromTheDOM
947 [[
self contentView] _removeObservers];
956 - (void)orderBack:(
id)aSender
970 - (void)orderOut:(
id)aSender
975 - (void)_orderOutRecursively:(BOOL)recursive
983 [
self._parentView _detachSheetWindow];
988 [_childWindows makeObjectsPerformSelector:@selector(_orderOutRecursively:) withObject:recursive];
991 if ([
self _sharesChromeWithPlatformWindow])
992 [_platformWindow orderOut:self];
994 if (_isFullPlatformWindow && _platformWindow != [
CPPlatformWindow primaryPlatformWindow])
995 [_platformWindow orderOut:self];
997 [_platformWindow order:CPWindowOut window:self relativeTo:nil];
1000 [
self makeFirstResponder:nil];
1001 [
self _updateMainAndKeyWindows];
1009 - (void)orderWindow:(CPWindowOrderingMode)orderingMode relativeTo:(
int)otherWindowNumber
1014 [_parentWindow removeChildWindow:self];
1017 [
self _orderOutRecursively:!_parentWindow];
1019 else if (orderingMode ===
CPWindowAbove && otherWindowNumber === 0)
1021 else if (orderingMode ===
CPWindowBelow && otherWindowNumber === 0)
1025 [_platformWindow order:orderingMode window:self relativeTo:CPApp._windows[otherWindowNumber]];
1033 - (void)setLevel:(
int)aLevel
1035 if (aLevel === _level)
1038 [_platformWindow moveWindow:self fromLevel:_level toLevel:aLevel];
1041 [_childWindows makeObjectsPerformSelector:@selector(setLevel:) withObject:_level];
1043 if ([
self _sharesChromeWithPlatformWindow])
1044 [_platformWindow setLevel:aLevel];
1068 + (void)setGlobalResizeStyle:(
int)aStyle
1081 + (void)setConstrainWindowsToUsableScreen:(BOOL)shouldConstrain
1089 + (BOOL)constrainWindowsToUsableScreen
1094 - (void)_didReceiveResizeStyleChange:(
CPNotification)aNotification
1096 [_windowView setShowsResizeIndicator:_styleMask & CPResizableWindowMask];
1102 + (int)globalResizeStyle
1110 - (BOOL)showsResizeIndicator
1112 return _showsResizeIndicator;
1119 - (void)setShowsResizeIndicator:(BOOL)shouldShowResizeIndicator
1121 shouldShowResizeIndicator = !!shouldShowResizeIndicator;
1123 if (_showsResizeIndicator === shouldShowResizeIndicator)
1126 _showsResizeIndicator = shouldShowResizeIndicator;
1133 - (CGSize)resizeIndicatorOffset
1135 return [_windowView resizeIndicatorOffset];
1142 - (void)setResizeIndicatorOffset:(CGSize)anOffset
1144 [_windowView setResizeIndicatorOffset:anOffset];
1154 if (_contentView && _contentView !== aView)
1155 [_contentView removeFromSuperview];
1157 var
bounds = CGRectMake(0.0, 0.0, CGRectGetWidth(_frame), CGRectGetHeight(_frame));
1159 _contentView = aView;
1162 [_contentView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
1163 [_windowView addSubview:_contentView];
1169 if (_initialFirstResponder && _initialFirstResponder !==
self)
1170 _initialFirstResponder =
self;
1178 return _contentView;
1185 - (void)setAlphaValue:(
float)aValue
1187 [_windowView setAlphaValue:aValue];
1195 return [_windowView alphaValue];
1204 [_windowView setBackgroundColor:aColor];
1212 return [_windowView backgroundColor];
1222 - (void)setMinSize:(CGSize)aSize
1224 if (CGSizeEqualToSize(_minSize, aSize))
1227 _minSize = [
self _calculateMinSizeForProposedSize:aSize];
1229 var size = CGSizeMakeCopy([
self frame].size),
1230 needsFrameChange = NO;
1232 if (size.width < _minSize.width)
1234 size.width = _minSize.width;
1235 needsFrameChange = YES;
1238 if (size.height < _minSize.height)
1240 size.height = _minSize.height;
1241 needsFrameChange = YES;
1244 if (needsFrameChange)
1257 - (CGSize)_calculateMinSizeForProposedSize:(CGSize)proposedSize
1259 var contentFrame = [
self contentRectForFrameRect:_frame],
1260 minHeight = CGRectGetHeight(_frame) - CGRectGetHeight(contentFrame);
1262 return CGSizeMake(MAX(proposedSize.width, 0), MAX(proposedSize.height, minHeight));
1271 - (void)setMaxSize:(CGSize)aSize
1273 if (CGSizeEqualToSize(_maxSize, aSize))
1276 _maxSize = CGSizeMakeCopy(aSize);
1278 var size = CGSizeMakeCopy([
self frame].size),
1279 needsFrameChange = NO;
1281 if (size.width > _maxSize.width)
1283 size.width = _maxSize.width;
1284 needsFrameChange = YES;
1287 if (size.height > _maxSize.height)
1289 size.height = _maxSize.height;
1290 needsFrameChange = YES;
1293 if (needsFrameChange)
1313 - (void)_updateShadow
1315 if ([
self _sharesChromeWithPlatformWindow])
1320 CPDOMDisplayServerRemoveChild(_DOMElement, _shadowView._DOMElement);
1325 [_platformWindow setHasShadow:_hasShadow];
1330 if (_hasShadow && !_shadowView)
1332 _shadowView = [[_CPShadowWindowView alloc] initWithFrame:CGRectMakeZero()];
1334 [_shadowView setWindowView:_windowView];
1335 [_shadowView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
1336 [_shadowView setNeedsLayout];
1339 CPDOMDisplayServerInsertBefore(_DOMElement, _shadowView._DOMElement, _windowView._DOMElement);
1342 else if (!_hasShadow && _shadowView)
1345 CPDOMDisplayServerRemoveChild(_DOMElement, _shadowView._DOMElement);
1355 - (void)setHasShadow:(BOOL)shouldHaveShadow
1357 if (_hasShadow === shouldHaveShadow)
1360 _hasShadow = shouldHaveShadow;
1362 [
self _updateShadow];
1376 - (void)setShadowStyle:(
unsigned)aStyle
1378 _shadowStyle = aStyle;
1389 if (_delegate === aDelegate)
1394 [defaultCenter removeObserver:_delegate name:CPWindowDidResignKeyNotification object:self];
1395 [defaultCenter removeObserver:_delegate name:CPWindowDidBecomeKeyNotification object:self];
1396 [defaultCenter removeObserver:_delegate name:CPWindowDidBecomeMainNotification object:self];
1397 [defaultCenter removeObserver:_delegate name:CPWindowDidResignMainNotification object:self];
1398 [defaultCenter removeObserver:_delegate name:CPWindowDidMoveNotification object:self];
1399 [defaultCenter removeObserver:_delegate name:CPWindowDidResizeNotification object:self];
1400 [defaultCenter removeObserver:_delegate name:CPWindowWillBeginSheetNotification object:self];
1401 [defaultCenter removeObserver:_delegate name:CPWindowDidEndSheetNotification object:self];
1403 _delegate = aDelegate;
1404 _implementedDelegateMethods = 0;
1406 if ([_delegate respondsToSelector:
@selector(windowShouldClose:)])
1409 if ([_delegate respondsToSelector:
@selector(windowWillReturnUndoManager:)])
1410 _implementedDelegateMethods |= CPWindowDelegate_windowWillReturnUndoManager_;
1412 if ([_delegate respondsToSelector:
@selector(windowWillClose:)])
1415 if ([_delegate respondsToSelector:
@selector(windowDidResignKey:)])
1417 addObserver:_delegate
1418 selector:@selector(windowDidResignKey:)
1419 name:CPWindowDidResignKeyNotification
1422 if ([_delegate respondsToSelector:
@selector(windowDidBecomeKey:)])
1424 addObserver:_delegate
1425 selector:@selector(windowDidBecomeKey:)
1426 name:CPWindowDidBecomeKeyNotification
1429 if ([_delegate respondsToSelector:
@selector(windowDidBecomeMain:)])
1431 addObserver:_delegate
1432 selector:@selector(windowDidBecomeMain:)
1433 name:CPWindowDidBecomeMainNotification
1436 if ([_delegate respondsToSelector:
@selector(windowDidResignMain:)])
1438 addObserver:_delegate
1439 selector:@selector(windowDidResignMain:)
1440 name:CPWindowDidResignMainNotification
1443 if ([_delegate respondsToSelector:
@selector(windowDidMove:)])
1445 addObserver:_delegate
1446 selector:@selector(windowDidMove:)
1447 name:CPWindowDidMoveNotification
1450 if ([_delegate respondsToSelector:
@selector(windowDidResize:)])
1452 addObserver:_delegate
1453 selector:@selector(windowDidResize:)
1454 name:CPWindowDidResizeNotification
1457 if ([_delegate respondsToSelector:
@selector(windowWillBeginSheet:)])
1459 addObserver:_delegate
1460 selector:@selector(windowWillBeginSheet:)
1461 name:CPWindowWillBeginSheetNotification
1464 if ([_delegate respondsToSelector:
@selector(windowDidEndSheet:)])
1466 addObserver:_delegate
1467 selector:@selector(windowDidEndSheet:)
1468 name:CPWindowDidEndSheetNotification
1486 _windowController = aWindowController;
1494 return _windowController;
1497 - (void)doCommandBySelector:(
SEL)aSelector
1499 if ([_delegate respondsToSelector:aSelector])
1500 [_delegate performSelector:aSelector];
1505 - (BOOL)acceptsFirstResponder
1512 return _initialFirstResponder;
1515 - (void)setInitialFirstResponder:(
CPView)aView
1517 _initialFirstResponder = aView;
1520 - (void)_setupFirstResponder
1525 if (!_hasBecomeKeyWindow)
1527 if (_firstResponder ===
self)
1529 if (_initialFirstResponder)
1530 [
self makeFirstResponder:_initialFirstResponder];
1534 var view = [_contentView nextValidKeyView];
1537 [
self makeFirstResponder:view];
1544 if (_firstResponder)
1545 [
self makeFirstResponder:_firstResponder];
1557 if (_firstResponder === aResponder)
1560 if (![_firstResponder resignFirstResponder])
1563 if (!aResponder || ![aResponder acceptsFirstResponder] || ![aResponder becomeFirstResponder])
1565 _firstResponder =
self;
1570 _firstResponder = aResponder;
1582 return _firstResponder;
1585 - (BOOL)acceptsMouseMovedEvents
1587 return _acceptsMouseMovedEvents;
1590 - (void)setAcceptsMouseMovedEvents:(BOOL)shouldAcceptMouseMovedEvents
1592 _acceptsMouseMovedEvents = shouldAcceptMouseMovedEvents;
1595 - (BOOL)ignoresMouseEvents
1597 return _ignoresMouseEvents;
1600 - (void)setIgnoresMouseEvents:(BOOL)shouldIgnoreMouseEvents
1602 _ignoresMouseEvents = shouldIgnoreMouseEvents;
1605 - (void)_mouseExitedResizeRect
1627 [_windowView setTitle:aTitle];
1628 [_platformWindow _setTitle:_title window:self];
1634 - (void)setTitleWithRepresentedFilename:(
CPString)aFilePath
1654 return [_representedURL absoluteString];
1662 _representedURL = aURL;
1670 return _representedURL;
1684 - (void)setMovableByWindowBackground:(BOOL)shouldBeMovableByWindowBackground
1686 _isMovableByWindowBackground = shouldBeMovableByWindowBackground;
1692 - (BOOL)isMovableByWindowBackground
1694 return _isMovableByWindowBackground;
1701 - (void)setMovable:(BOOL)shouldBeMovable
1703 _isMovable = shouldBeMovable;
1719 if (_isFullPlatformWindow)
1722 var size = [
self frame].size,
1725 var origin = CGPointMake((containerSize.width - size.width) / 2.0, (containerSize.height - size.height) / 2.0);
1742 var type = [anEvent
type],
1760 [_windowView mouseDown:anEvent];
1764 [sheet makeKeyAndOrderFront:self];
1819 else if ([anEvent charactersIgnoringModifiers] ==
CPEscapeFunctionKey && [
self _processKeyboardUIKey:anEvent])
1828 if (![
self disableKeyEquivalentForDefaultButton])
1831 keyEquivalent = [defaultButton keyEquivalent],
1832 modifierMask = [defaultButton keyEquivalentModifierMask];
1834 if ([anEvent _triggersKeyEquivalent:keyEquivalent withModifierMask:modifierMask])
1841 return [[_windowView hitTest:point] scrollWheel:anEvent];
1845 var hitTestedView = _leftMouseDownView,
1846 selector = type ==
CPRightMouseUp ?
@selector(rightMouseUp:) :
@selector(mouseUp:);
1849 hitTestedView = [_windowView hitTest:point];
1851 [hitTestedView performSelector:selector withObject:anEvent];
1853 _leftMouseDownView = nil;
1860 _leftMouseDownView = [_windowView hitTest:point];
1862 if (_leftMouseDownView !== _firstResponder && [_leftMouseDownView acceptsFirstResponder])
1865 var keyWindow = [CPApp keyWindow];
1868 if ([keyWindow platformWindow] != [
self platformWindow])
1871 [CPApp activateIgnoringOtherApps:YES];
1873 var theWindow = [anEvent window],
1874 selector = type ==
CPRightMouseDown ?
@selector(rightMouseDown:) :
@selector(mouseDown:);
1876 if ([theWindow isKeyWindow] || ([theWindow becomesKeyOnlyIfNeeded] && ![_leftMouseDownView needsPanelToBecomeKey]))
1877 return [_leftMouseDownView performSelector:selector withObject:anEvent];
1883 if ([_leftMouseDownView acceptsFirstMouse:anEvent])
1884 return [_leftMouseDownView performSelector:selector withObject:anEvent];
1890 if (!_leftMouseDownView)
1891 return [[_windowView hitTest:point] mouseDragged:anEvent];
1897 selector =
@selector(rightMouseDragged:)
1898 if (![_leftMouseDownView respondsToSelector:selector])
1903 selector =
@selector(mouseDragged:)
1905 return [_leftMouseDownView performSelector:selector withObject:anEvent];
1908 [_windowView setCursorForLocation:point resizing:NO];
1911 if (!_acceptsMouseMovedEvents || sheet)
1914 if (!_mouseEnteredStack)
1915 _mouseEnteredStack = [];
1917 var hitTestView = [_windowView hitTest:point];
1919 if ([_mouseEnteredStack count] && [_mouseEnteredStack lastObject] === hitTestView)
1920 return [hitTestView mouseMoved:anEvent];
1922 var view = hitTestView,
1923 mouseEnteredStack = [];
1927 mouseEnteredStack.unshift(view);
1929 view = [view superview];
1932 var deviation = MIN(_mouseEnteredStack.length, mouseEnteredStack.length);
1935 if (_mouseEnteredStack[deviation] === mouseEnteredStack[deviation])
1938 var index = deviation + 1,
1939 count = _mouseEnteredStack.length;
1945 for (; index < count; ++index)
1946 [_mouseEnteredStack[index] mouseExited:event];
1949 index = deviation + 1;
1950 count = mouseEnteredStack.length;
1956 for (; index < count; ++index)
1957 [mouseEnteredStack[index] mouseEntered:event];
1960 _mouseEnteredStack = mouseEnteredStack;
1962 [hitTestView mouseMoved:anEvent];
1971 return _windowNumber;
1979 - (void)becomeKeyWindow
1981 CPApp._keyWindow =
self;
1983 if (_firstResponder !==
self && [_firstResponder respondsToSelector:
@selector(becomeKeyWindow)])
1984 [_firstResponder becomeKeyWindow];
1986 if (!_hasBecomeKeyWindow)
1990 if (![
self _hasKeyViewLoop:[_contentView subviews]])
1994 [
self _setupFirstResponder];
1995 _hasBecomeKeyWindow = YES;
1997 [_windowView noteKeyWindowStateChanged];
1998 [_contentView _notifyWindowDidBecomeKey];
2009 - (BOOL)canBecomeKeyWindow
2028 return [CPApp keyWindow] ==
self;
2035 - (void)makeKeyAndOrderFront:(
id)aSender
2046 - (void)makeKeyWindow
2048 if ([
CPApp keyWindow] ===
self || ![
self canBecomeKeyWindow])
2051 [[CPApp keyWindow] resignKeyWindow];
2058 - (void)resignKeyWindow
2060 if (_firstResponder !==
self && [_firstResponder respondsToSelector:
@selector(resignKeyWindow)])
2061 [_firstResponder resignKeyWindow];
2063 if (
CPApp._keyWindow ===
self)
2064 CPApp._keyWindow = nil;
2066 [_windowView noteKeyWindowStateChanged];
2067 [_contentView _notifyWindowDidResignKey];
2084 - (void)dragImage:(
CPImage)anImage at:(CGPoint)imageLocation offset:(CGSize)mouseOffset event:(
CPEvent)anEvent pasteboard:(
CPPasteboard)aPasteboard source:(
id)aSourceObject slideBack:(BOOL)slideBack
2089 - (void)_noteRegisteredDraggedTypes:(CPSet)pasteboardTypes
2091 if (!pasteboardTypes)
2094 if (!_inclusiveRegisteredDraggedTypes)
2097 [_inclusiveRegisteredDraggedTypes unionSet:pasteboardTypes];
2100 - (void)_noteUnregisteredDraggedTypes:(CPSet)pasteboardTypes
2102 if (!pasteboardTypes)
2105 [_inclusiveRegisteredDraggedTypes minusSet:pasteboardTypes];
2107 if ([_inclusiveRegisteredDraggedTypes count] === 0)
2108 _inclusiveRegisteredDraggedTypes = nil;
2121 - (void)dragView:(
CPView)aView at:(CGPoint)viewLocation offset:(CGSize)mouseOffset event:(
CPEvent)anEvent pasteboard:(
CPPasteboard)aPasteboard source:(
id)aSourceObject slideBack:(BOOL)slideBack
2130 - (void)registerForDraggedTypes:(CPArray)pasteboardTypes
2132 if (!pasteboardTypes)
2135 [
self _noteUnregisteredDraggedTypes:_registeredDraggedTypes];
2136 [_registeredDraggedTypes addObjectsFromArray:pasteboardTypes];
2137 [
self _noteRegisteredDraggedTypes:_registeredDraggedTypes];
2139 _registeredDraggedTypesArray = nil;
2146 - (CPArray)registeredDraggedTypes
2148 if (!_registeredDraggedTypesArray)
2149 _registeredDraggedTypesArray = [_registeredDraggedTypes allObjects];
2151 return _registeredDraggedTypesArray;
2157 - (void)unregisterDraggedTypes
2159 [
self _noteUnregisteredDraggedTypes:_registeredDraggedTypes];
2161 _registeredDraggedTypes = [CPSet set];
2162 _registeredDraggedTypesArray = [];
2171 - (void)setDocumentEdited:(BOOL)isDocumentEdited
2173 if (_isDocumentEdited == isDocumentEdited)
2176 _isDocumentEdited = isDocumentEdited;
2178 [
CPMenu _setMenuBarIconImageAlphaValue:_isDocumentEdited ? 0.5 : 1.0];
2180 [_windowView setDocumentEdited:isDocumentEdited];
2186 - (BOOL)isDocumentEdited
2188 return _isDocumentEdited;
2191 - (void)setDocumentSaving:(BOOL)isDocumentSaving
2193 if (_isDocumentSaving == isDocumentSaving)
2196 _isDocumentSaving = isDocumentSaving;
2198 [
self _synchronizeSaveMenuWithDocumentSaving];
2200 [_windowView windowDidChangeDocumentSaving];
2203 - (BOOL)isDocumentSaving
2205 return _isDocumentSaving;
2209 - (void)_synchronizeSaveMenuWithDocumentSaving
2211 if (![
self isMainWindow])
2214 var mainMenu = [CPApp mainMenu],
2215 index = [mainMenu indexOfItemWithTitle:_isDocumentSaving ? @"Save" : @"Saving..."];
2220 var item = [mainMenu itemAtIndex:index];
2222 if (_isDocumentSaving)
2226 [item setTitle:@"Saving..."];
2228 [item setEnabled:NO];
2232 [item setTitle:@"Save"];
2233 [item setImage:CPWindowSaveImage];
2234 [item setEnabled:YES];
2244 - (void)performMiniaturize:(
id)aSender
2254 - (void)miniaturize:(
id)sender
2260 [
self _updateMainAndKeyWindows];
2264 _isMiniaturized = YES;
2270 - (void)deminiaturize:(
id)sender
2276 _isMiniaturized = NO;
2282 - (void)isMiniaturized
2284 return _isMiniaturized;
2293 - (void)performClose:(
id)aSender
2298 if ([
self isFullPlatformWindow])
2300 var
event = [CPApp currentEvent];
2311 if ([
self _delegateRespondsToWindowShouldClose])
2313 if (![
self _sendDelegateWindowShouldClose])
2316 else if ([
self respondsToSelector:
@selector(windowShouldClose:)])
2318 if (![
self windowShouldClose:
self])
2322 var documents = [_windowController documents];
2324 if ([documents count])
2326 var index = [documents indexOfObject:[_windowController document]];
2328 [documents[index] shouldCloseWindowController:_windowController
2330 shouldCloseSelector:@selector(_windowControllerContainingDocument:shouldClose:contextInfo:)
2331 contextInfo:{documents:[documents copy], visited:0, index:index}];
2337 - (void)_windowControllerContainingDocument:(
CPDocument)document shouldClose:(BOOL)shouldClose contextInfo:(Object)context
2341 var windowController = [
self windowController],
2342 documents = context.documents,
2343 count = [documents count],
2344 visited = ++context.visited,
2345 index = ++context.index % count;
2349 if (visited < count)
2351 [windowController setDocument:documents[index]];
2353 [documents[index] shouldCloseWindowController:_windowController
2355 shouldCloseSelector:@selector(_windowControllerContainingDocument:shouldClose:contextInfo:)
2356 contextInfo:context];
2369 [
self _sendDelegateWindowWillClose];
2373 [_parentWindow removeChildWindow:self];
2374 [
self _orderOutRecursively:NO];
2375 [
self _detachFromChildrenClosing:!_parentWindow];
2378 - (void)_detachFromChildrenClosing:(BOOL)shouldCloseChildren
2381 [_childWindows enumerateObjectsUsingBlock:function(child)
2383 [child setParentWindow:nil];
2387 if (shouldCloseChildren)
2389 [_childWindows enumerateObjectsUsingBlock:function(child)
2393 [child _orderOutRecursively:NO];
2394 [child _detachFromChildrenClosing:![child parentWindow]];
2406 - (BOOL)isMainWindow
2408 return [CPApp mainWindow] ===
self;
2414 - (BOOL)canBecomeMainWindow
2421 return ([
self isVisible] && ((_styleMask &
CPTitledWindowMask) || _isFullPlatformWindow));
2427 - (void)makeMainWindow
2432 [_parentView makeMainWindow];
2436 if ([
CPApp mainWindow] ===
self || ![
self canBecomeMainWindow])
2439 [[CPApp mainWindow] resignMainWindow];
2446 - (void)becomeMainWindow
2448 CPApp._mainWindow =
self;
2450 [
self _synchronizeSaveMenuWithDocumentSaving];
2452 [_windowView noteMainWindowStateChanged];
2462 - (void)resignMainWindow
2468 if (
CPApp._mainWindow ===
self)
2469 CPApp._mainWindow = nil;
2471 [_windowView noteMainWindowStateChanged];
2474 - (void)_updateMainAndKeyWindows
2476 var allWindows = [CPApp orderedWindows],
2477 windowCount = [allWindows count];
2479 if ([
self isKeyWindow])
2481 var keyWindow = [CPApp keyWindow];
2482 [
self resignKeyWindow];
2484 if (keyWindow && keyWindow !==
self && [keyWindow canBecomeKeyWindow])
2485 [keyWindow makeKeyWindow];
2488 var mainMenu = [CPApp mainMenu],
2489 menuBarClass = objj_getClass(
"_CPMenuBarWindow"),
2492 for (var i = 0; i < windowCount; i++)
2494 var currentWindow = allWindows[i];
2496 if ([currentWindow isKindOfClass:menuBarClass])
2497 menuWindow = currentWindow;
2499 if (currentWindow ===
self || currentWindow === menuWindow)
2502 if ([currentWindow isVisible] && [currentWindow canBecomeKeyWindow] && [currentWindow platformWindow] == [keyWindow platformWindow])
2504 [currentWindow makeKeyWindow];
2509 if (![
CPApp keyWindow])
2510 [menuWindow makeKeyWindow];
2514 if ([
self isMainWindow])
2516 var mainWindow = [CPApp mainWindow];
2517 [
self resignMainWindow];
2519 if (mainWindow && mainWindow !==
self && [mainWindow canBecomeMainWindow])
2520 [mainWindow makeMainWindow];
2523 var mainMenu = [CPApp mainMenu],
2524 menuBarClass = objj_getClass(
"_CPMenuBarWindow"),
2527 for (var i = 0; i < windowCount; i++)
2529 var currentWindow = allWindows[i];
2531 if ([currentWindow isKindOfClass:menuBarClass])
2532 menuWindow = currentWindow;
2534 if (currentWindow ===
self || currentWindow === menuWindow)
2537 if ([currentWindow isVisible] && [currentWindow canBecomeMainWindow])
2539 [currentWindow makeMainWindow];
2562 if (_toolbar === aToolbar)
2566 [[aToolbar _window] setToolbar:nil];
2569 [_toolbar _setWindow:nil];
2571 _toolbar = aToolbar;
2574 [_toolbar _setWindow:self];
2576 [
self _noteToolbarChanged];
2579 - (void)toggleToolbarShown:(
id)aSender
2583 [toolbar setVisible:![toolbar isVisible]];
2586 - (void)_noteToolbarChanged
2588 var
frame = CGRectMakeCopy([
self frame]),
2591 [_windowView noteToolbarChanged];
2593 if (_isFullPlatformWindow)
2594 newFrame = [_platformWindow visibleFrame];
2597 newFrame = CGRectMakeCopy([
self frame]);
2599 newFrame.origin = frame.origin;
2602 [
self setFrame:newFrame];
2614 - (CPArray)childWindows
2616 return _childWindows;
2619 - (void)addChildWindow:(
CPWindow)childWindow ordered:(CPWindowOrderingMode)orderingMode
2622 if ([_childWindows indexOfObject:childWindow] >= 0)
2626 [_childWindows addObject:childWindow];
2629 reason:_cmd + @" unrecognized ordering mode " + orderingMode];
2632 [childWindow _setChildOrdering:orderingMode];
2635 if ([
self isVisible] && ![childWindow isVisible])
2641 var index = [_childWindows indexOfObject:childWindow];
2646 [_childWindows removeObjectAtIndex:index];
2652 return _parentWindow;
2660 - (BOOL)_hasAncestorWindow:(
CPWindow)anAncestor
2662 if (!_parentWindow || !anAncestor)
2665 if (anAncestor === _parentWindow)
2668 return [_parentWindow _hasAncestorWindow:anAncestor];
2673 _parentWindow = parentWindow;
2676 - (void)_setFrame:(CGRect)aFrame delegate:(
id)delegate duration:(
int)duration curve:(CPAnimationCurve)curve
2678 [_frameAnimation stopAnimation];
2679 _frameAnimation = [[_CPWindowFrameAnimation alloc] initWithWindow:self targetFrame:aFrame];
2680 [_frameAnimation setDelegate:delegate];
2681 [_frameAnimation setAnimationCurve:curve];
2682 [_frameAnimation setDuration:duration];
2683 [_frameAnimation startAnimation];
2686 - (CPTimeInterval)animationResizeTime:(CGRect)newWindowFrame
2691 - (void)_setAttachedSheetFrameOrigin
2694 var attachedSheet = [
self attachedSheet],
2695 contentRect = [_contentView frame],
2696 sheetFrame = CGRectMakeCopy([attachedSheet
frame]);
2698 sheetFrame.origin.y = CGRectGetMinY(_frame) + CGRectGetMinY(contentRect);
2699 sheetFrame.origin.x = CGRectGetMinX(_frame) + FLOOR((CGRectGetWidth(_frame) - CGRectGetWidth(sheetFrame)) / 2.0);
2701 [attachedSheet setFrame:sheetFrame display:YES animate:NO];
2704 - (void)_previousSheetIsClosedNotification:(
CPNotification)aNotification
2708 var sheet = _sheetContext[@"nextSheet"],
2709 modalDelegate =_sheetContext[@"nextModalDelegate"],
2710 endSelector = _sheetContext[@"nextEndSelector"],
2711 contextInfo = _sheetContext[@"nextContextInfo"];
2714 setTimeout(
function()
2716 [sheet._windowView _enableSheet:YES inWindow:self];
2717 [
self _attachSheet:sheet modalDelegate:modalDelegate didEndSelector:endSelector contextInfo:contextInfo];
2724 - (
void)_attachSheet:(
CPWindow)aSheet modalDelegate:(
id)aModalDelegate
2725 didEndSelector:(
SEL)didEndSelector contextInfo:(
id)contextInfo
2730 if (_sheetContext[
@"isClosing"])
2733 _sheetContext[@"nextSheet"] = aSheet;
2734 _sheetContext[@"nextModalDelegate"] = aModalDelegate;
2735 _sheetContext[@"nextEndSelector"] = didEndSelector;
2736 _sheetContext[@"nextContextInfo"] = contextInfo;
2744 reason:@"The target window of beginSheet: already has a sheet, did you forget orderOut: ?"];
2751 "modalDelegate": aModalDelegate,
2752 "endSelector": didEndSelector,
2753 "contextInfo": contextInfo,
2757 "savedConstrains": aSheet._constrainsToUsableScreen
2761 aSheet._constrainsToUsableScreen = NO;
2777 var
delegate = _sheetContext["modalDelegate"],
2778 endSelector = _sheetContext["endSelector"];
2782 if (delegate && endSelector)
2784 if (_sheetContext[
"isAttached"])
2785 objj_msgSend(delegate, endSelector, _sheetContext[
"sheet"], _sheetContext[
"returnCode"],
2786 _sheetContext[
"contextInfo"]);
2788 _sheetContext["deferDidEndSelector"] = YES;
2796 - (void)_detachSheetWindow
2798 if (_sheetContext[
"isClosing"])
2801 _sheetContext["isAttached"] = NO;
2802 _sheetContext["isClosing"] = YES;
2803 _sheetContext["opened"] = NO;
2817 - (void)_cleanupSheetWindow
2819 var sheet = _sheetContext["sheet"],
2820 deferDidEnd = _sheetContext["deferDidEndSelector"];
2826 [
self _removeClipForSheet:sheet];
2829 sheet._isSheet = NO;
2830 [sheet._windowView _enableSheet:NO inWindow:self];
2831 sheet._constrainsToUsableScreen = _sheetContext["savedConstrains"];
2834 [sheet orderOut:self];
2840 var delegate = _sheetContext["modalDelegate"],
2841 selector = _sheetContext["endSelector"],
2842 returnCode = _sheetContext["returnCode"],
2843 contextInfo = _sheetContext["contextInfo"];
2846 _sheetContext = nil;
2847 sheet._parentView = nil;
2849 objj_msgSend(delegate, selector, sheet, returnCode, contextInfo);
2853 _sheetContext = nil;
2854 sheet._parentView = nil;
2859 - (void)animationDidEnd:(
id)anim
2861 var sheet = _sheetContext["sheet"];
2863 if (anim._window != sheet)
2873 - (void)_sheetShouldAnimateIn:(
CPTimer)timer
2876 if (_sheetContext[
"isOpening"] || _sheetContext[
"isClosing"])
2879 var sheet = _sheetContext["sheet"];
2880 sheet._isSheet = YES;
2881 sheet._parentView =
self;
2887 sheet._isModal = NO;
2889 if ([
CPApp modalWindow] ===
self)
2891 [CPApp runModalForWindow:sheet];
2892 sheet._isModal = YES;
2897 var sheetFrame = [sheet frame],
2898 sheetShadowFrame = sheet._hasShadow ? [sheet._shadowView frame] : sheetFrame,
2899 frame = [
self frame],
2900 originX = frame.origin.x + FLOOR((frame.size.
width - sheetFrame.size.
width) / 2),
2901 startFrame = CGRectMake(originX, -sheetShadowFrame.size.height, sheetFrame.size.
width, sheetFrame.size.height),
2902 endY = -1 + [_windowView bodyOffset] - [[self contentView] frame].origin.y,
2903 endFrame = CGRectMake(originX, endY, sheetFrame.size.
width, sheetFrame.size.height);
2905 if (_toolbar && [_windowView showsToolbar] && [
self isFullPlatformWindow])
2907 endY += [[_toolbar _toolbarView] frameSize].height;
2908 endFrame = CGRectMake(originX, endY, sheetFrame.size.width, sheetFrame.size.height);
2912 [sheet setFrameOrigin:CGPointMake(0, -13000)];
2915 [sheet orderFront:self];
2916 [
self _clipSheet:sheet];
2918 [sheet setFrame:startFrame display:YES animate:NO];
2920 _sheetContext["opened"] = YES;
2921 _sheetContext["shouldClose"] = NO;
2922 _sheetContext["isOpening"] = YES;
2924 [sheet _setFrame:endFrame delegate:self duration:[
self animationResizeTime:endFrame] curve:CPAnimationEaseOut];
2927 - (void)_sheetShouldAnimateOut:(
CPTimer)timer
2929 if (_sheetContext[
"isOpening"])
2932 _sheetContext["shouldClose"] = YES;
2937 if ([
self isVisible])
2939 var sheet = _sheetContext["sheet"],
2940 sheetFrame = [sheet frame],
2941 fullHeight = sheet._hasShadow ? [sheet._shadowView frame].size.height : sheetFrame.size.height,
2942 endFrame = CGRectMakeCopy(sheetFrame),
2943 contentOrigin = [
self convertBaseToGlobal:[[
self contentView] frame].origin];
2946 sheet._constrainsToUsableScreen = NO;
2948 [sheet setFrameOrigin:CGPointMake(sheetFrame.origin.x, sheetFrame.origin.y - contentOrigin.y)];
2949 [
self _clipSheet:sheet];
2951 endFrame.origin.y = -fullHeight;
2952 [sheet _setFrame:endFrame delegate:self duration:[
self animationResizeTime:endFrame] curve:CPAnimationEaseIn];
2956 [
self _sheetAnimationDidEnd:nil];
2960 - (void)_sheetAnimationDidEnd:(
CPTimer)timer
2962 var sheet = _sheetContext["sheet"];
2964 _sheetContext["isOpening"] = NO;
2965 _sheetContext["isClosing"] = NO;
2967 if (_sheetContext[
"opened"] === YES)
2969 var sheetFrame = [sheet frame],
2970 sheetOrigin = CGPointMakeCopy(sheetFrame.origin);
2972 [
self _removeClipForSheet:sheet];
2973 [sheet setFrameOrigin:CGPointMake(sheetOrigin.x, [sheet frame].origin.y + sheetOrigin.y)];
2976 if (_sheetContext[
"shouldClose"] === YES)
2977 [
self _detachSheetWindow];
2979 [sheet makeKeyWindow];
2984 [
self _cleanupSheetWindow];
2988 - (void)_clipSheet:(
CPWindow)aSheet
2990 var clipRect = [_platformWindow contentBounds];
2991 clipRect.origin.y = [
self frame].origin.y + [[self contentView] frame].origin.y;
2993 [[_platformWindow layerAtLevel:_level create:NO] clipWindow:aSheet toRect:clipRect];
2996 - (void)_removeClipForSheet:(
CPWindow)aSheet
2998 [[_platformWindow layerAtLevel:_level create:NO] removeClipForWindow:aSheet];
3006 if (_sheetContext === nil)
3009 return _sheetContext["sheet"];
3025 - (BOOL)becomesKeyOnlyIfNeeded
3034 - (BOOL)worksWhenModal
3043 return [_contentView performKeyEquivalent:anEvent];
3050 if ([anEvent _couldBeKeyEquivalent] && [
self performKeyEquivalent:anEvent])
3058 if (![
self _processKeyboardUIKey:anEvent])
3070 - (BOOL)_processKeyboardUIKey:(
CPEvent)anEvent
3079 if ([selectors count] <= 0)
3082 var selector = [selectors objectAtIndex:0];
3084 return [[
self firstResponder] tryToPerform:selector with:self];
3087 - (void)_dirtyKeyViewLoop
3089 if (_autorecalculatesKeyViewLoop)
3090 _keyViewLoopIsDirty = YES;
3098 - (BOOL)_hasKeyViewLoop:(CPArray)theViews
3101 count = [theViews count];
3103 for (i = 0; i < count; ++i)
3105 var view = theViews[i];
3107 if ([view nextKeyView] || [view previousKeyView])
3111 for (i = 0; i < count; ++i)
3113 var subviews = [theViews[i] subviews];
3115 if ([subviews count] && [
self _hasKeyViewLoop:subviews])
3129 - (void)recalculateKeyViewLoop
3131 [
self _doRecalculateKeyViewLoop];
3134 - (CPArray)_viewsSortedByPosition
3136 var views = [CPArray arrayWithObject:_contentView];
3138 views = views.concat([
self _subviewsSortedByPosition:[_contentView subviews]]);
3143 - (CPArray)_subviewsSortedByPosition:(CPArray)theSubviews
3151 theSubviews = [theSubviews copy];
3152 [theSubviews sortUsingFunction:keyViewComparator context:nil];
3154 var sortedViews = [];
3156 for (var i = 0, count = [theSubviews count]; i < count; ++i)
3158 var view = theSubviews[i],
3159 subviews = [view subviews];
3161 sortedViews.push(view);
3163 if ([subviews count])
3164 sortedViews = sortedViews.concat([
self _subviewsSortedByPosition:subviews]);
3170 - (void)_doRecalculateKeyViewLoop
3172 var views = [
self _viewsSortedByPosition];
3174 for (var index = 0, count = [views count]; index < count; ++index)
3175 [views[index] setNextKeyView:views[(index + 1) % count]];
3177 _keyViewLoopIsDirty = NO;
3180 - (void)setAutorecalculatesKeyViewLoop:(BOOL)shouldRecalculate
3182 if (_autorecalculatesKeyViewLoop === shouldRecalculate)
3185 _autorecalculatesKeyViewLoop = shouldRecalculate;
3188 - (BOOL)autorecalculatesKeyViewLoop
3190 return _autorecalculatesKeyViewLoop;
3193 - (void)selectNextKeyView:(
id)sender
3195 if (_keyViewLoopIsDirty)
3196 [
self _doRecalculateKeyViewLoop];
3198 var nextValidKeyView = nil;
3200 if ([_firstResponder isKindOfClass:[
CPView class]])
3201 nextValidKeyView = [_firstResponder nextValidKeyView];
3203 if (!nextValidKeyView)
3205 if ([_initialFirstResponder acceptsFirstResponder])
3206 nextValidKeyView = _initialFirstResponder;
3208 nextValidKeyView = [_initialFirstResponder nextValidKeyView];
3211 if (nextValidKeyView)
3212 [
self makeFirstResponder:nextValidKeyView];
3215 - (void)selectPreviousKeyView:(
id)sender
3217 if (_keyViewLoopIsDirty)
3218 [
self _doRecalculateKeyViewLoop];
3220 var previousValidKeyView = nil;
3222 if ([_firstResponder isKindOfClass:[
CPView class]])
3223 previousValidKeyView = [_firstResponder previousValidKeyView];
3225 if (!previousValidKeyView)
3227 if ([_initialFirstResponder acceptsFirstResponder])
3228 previousValidKeyView = _initialFirstResponder;
3230 previousValidKeyView = [_initialFirstResponder previousValidKeyView];
3233 if (previousValidKeyView)
3234 [
self makeFirstResponder:previousValidKeyView];
3237 - (void)selectKeyViewFollowingView:(
CPView)aView
3239 if (_keyViewLoopIsDirty)
3240 [
self _doRecalculateKeyViewLoop];
3244 if ([nextValidKeyView isKindOfClass:[
CPView class]])
3245 [
self makeFirstResponder:nextValidKeyView];
3248 - (void)selectKeyViewPrecedingView:(
CPView)aView
3250 if (_keyViewLoopIsDirty)
3251 [
self _doRecalculateKeyViewLoop];
3255 if ([previousValidKeyView isKindOfClass:[
CPView class]])
3256 [
self makeFirstResponder:previousValidKeyView];
3286 if (_defaultButton === aButton)
3290 [_defaultButton setKeyEquivalent:nil];
3292 _defaultButton = aButton;
3303 return _defaultButton;
3309 - (void)enableKeyEquivalentForDefaultButton
3311 _defaultButtonEnabled = YES;
3318 - (void)enableKeyEquivalentForDefaultButtonCell
3326 - (void)disableKeyEquivalentForDefaultButton
3328 _defaultButtonEnabled = NO;
3335 - (void)disableKeyEquivalentForDefaultButtonCell
3343 [
self setTitle:aValue ||
@""];
3348 - (void)_didReceivePlatformWindowWillCloseNotification:(
CPNotification)aNotification
3350 if ([aNotification
object] != _platformWindow)
3360 var lhsBounds = [lhs convertRect:[lhs bounds] toView:nil],
3361 rhsBounds = [rhs convertRect:[rhs bounds] toView:nil],
3362 lhsY = CGRectGetMinY(lhsBounds),
3363 rhsY = CGRectGetMinY(rhsBounds),
3364 lhsX = CGRectGetMinX(lhsBounds),
3365 rhsX = CGRectGetMinX(rhsBounds),
3366 intersectsVertically = MIN(CGRectGetMaxY(lhsBounds), CGRectGetMaxY(rhsBounds)) - MAX(lhsY, rhsY);
3369 if (intersectsVertically > 0)
3396 - (BOOL)_delegateRespondsToWindowWillUndoManager
3398 return _implementedDelegateMethods & CPWindowDelegate_windowWillReturnUndoManager_;
3405 - (BOOL)_delegateRespondsToWindowShouldClose
3414 - (BOOL)_sendDelegateWindowShouldClose
3419 return [_delegate windowShouldClose:self];
3426 - (BOOL)_sendDelegateWindowWillReturnUndoManager
3428 if (!(_implementedDelegateMethods & CPWindowDelegate_windowWillReturnUndoManager_))
3431 return [_delegate windowWillReturnUndoManager:self];
3438 - (void)_sendDelegateWindowWillClose
3443 [_delegate windowWillClose:self];
3454 - (void)resizeWithOldPlatformWindowSize:(CGSize)aSize
3456 if ([
self isFullPlatformWindow])
3457 return [
self setFrame:[_platformWindow visibleFrame]];
3463 var
frame = [_platformWindow contentBounds],
3464 newFrame = CGRectMakeCopy(_frame),
3465 dX = (CGRectGetWidth(frame) - aSize.width) /
3467 dY = (CGRectGetHeight(frame) - aSize.height) /
3470 if (_autoresizingMask & CPWindowMinXMargin)
3471 newFrame.origin.x += dX;
3474 newFrame.size.width += dX;
3476 if (_autoresizingMask & CPWindowMinYMargin)
3477 newFrame.origin.y += dY;
3480 newFrame.size.height += dY;
3482 [
self _setFrame:newFrame display:YES animate:NO constrainWidth:YES constrainHeight:YES];
3488 - (void)setAutoresizingMask:(
unsigned)anAutoresizingMask
3490 _autoresizingMask = anAutoresizingMask;
3496 - (unsigned)autoresizingMask
3498 return _autoresizingMask;
3504 - (CGPoint)convertBaseToGlobal:(CGPoint)aPoint
3512 - (CGPoint)convertGlobalToBase:(CGPoint)aPoint
3520 - (CGPoint)convertBaseToPlatformWindow:(CGPoint)aPoint
3522 if ([
self _sharesChromeWithPlatformWindow])
3523 return CGPointMakeCopy(aPoint);
3525 var origin = [
self frame].origin;
3527 return CGPointMake(aPoint.x + origin.x, aPoint.y + origin.y);
3533 - (CGPoint)convertPlatformWindowToBase:(CGPoint)aPoint
3535 if ([
self _sharesChromeWithPlatformWindow])
3536 return CGPointMakeCopy(aPoint);
3538 var origin = [
self frame].origin;
3540 return CGPointMake(aPoint.x - origin.x, aPoint.y - origin.y);
3543 - (CGPoint)convertScreenToBase:(CGPoint)aPoint
3548 - (CGPoint)convertBaseToScreen:(CGPoint)aPoint
3553 - (void)_setSharesChromeWithPlatformWindow:(BOOL)shouldShareFrameWithPlatformWindow
3556 if (shouldShareFrameWithPlatformWindow && [
CPPlatform isBrowser])
3559 _sharesChromeWithPlatformWindow = shouldShareFrameWithPlatformWindow;
3561 [
self _updateShadow];
3564 - (BOOL)_sharesChromeWithPlatformWindow
3566 return _sharesChromeWithPlatformWindow;
3577 return _undoManager;
3580 var documentUndoManager = [[_windowController document] undoManager];
3582 if (documentUndoManager)
3583 return documentUndoManager;
3586 if ([
self _delegateRespondsToWindowWillUndoManager])
3587 return [
self _sendDelegateWindowWillReturnUndoManager];
3593 return _undoManager;
3600 - (void)undo:(
id)aSender
3609 - (void)redo:(
id)aSender
3614 - (BOOL)containsPoint:(CGPoint)aPoint
3616 return CGRectContainsPoint(_frame, aPoint);
3620 - (BOOL)_isValidMousePoint:(CGPoint)aPoint
3626 return CGRectContainsPoint(mouseFrame, aPoint);
3636 - (void)setFullBridge:(BOOL)shouldBeFullBridge
3638 _CPReportLenientDeprecation([
self class], _cmd,
@selector(setFullPlatformWindow:));
3647 - (BOOL)isFullBridge
3655 - (CGPoint)convertBaseToBridge:(CGPoint)aPoint
3663 - (CGPoint)convertBridgeToBase:(CGPoint)aPoint
3672 return fromValue + (toValue - fromValue) * progress;
3676 @implementation _CPWindowFrameAnimation :
CPAnimation
3681 CGRect _targetFrame;
3684 - (id)initWithWindow:(
CPWindow)aWindow targetFrame:(CGRect)aTargetFrame
3686 self = [
super initWithDuration:[aWindow
animationResizeTime:aTargetFrame] animationCurve:CPAnimationLinear];
3692 _targetFrame = CGRectMakeCopy(aTargetFrame);
3693 _startFrame = CGRectMakeCopy([_window
frame]);
3699 - (void)startAnimation
3701 [
super startAnimation];
3703 _window._isAnimating = YES;
3706 - (void)setCurrentProgress:(
float)aProgress
3708 [
super setCurrentProgress:aProgress];
3710 var value = [
self currentValue];
3713 _window._isAnimating = NO;
3715 var newFrame = CGRectMake(
3716 interpolate(CGRectGetMinX(_startFrame), CGRectGetMinX(_targetFrame), value),
3717 interpolate(CGRectGetMinY(_startFrame), CGRectGetMinY(_targetFrame), value),
3718 interpolate(CGRectGetWidth(_startFrame), CGRectGetWidth(_targetFrame), value),
3719 interpolate(CGRectGetHeight(_startFrame), CGRectGetHeight(_targetFrame), value));
3721 [_window setFrame:newFrame display:YES animate:NO];
3730 - (id)_dragHitTest:(CGPoint)aPoint pasteboard:(
CPPasteboard)aPasteboard
3733 if (!_inclusiveRegisteredDraggedTypes)
3743 hitView = [_windowView hitTest:adjustedPoint];
3745 while (hitView && ![aPasteboard availableTypeFromArray:[hitView registeredDraggedTypes]])
3746 hitView = [hitView superview];
3751 if ([aPasteboard availableTypeFromArray:[
self registeredDraggedTypes]])
3759 function _CPWindowFullPlatformWindowSessionMake(aWindowView, aContentRect, hasShadow, aLevel)
3761 return { windowView:aWindowView, contentRect:aContentRect, hasShadow:hasShadow, level:aLevel };
3769 - (void)_setChildOrdering:(CPWindowOrderingMode)aValue
3771 _childOrdering = aValue;