175 _CPWindowDidChangeFirstResponderNotification =
@"_CPWindowDidChangeFirstResponderNotification";
192 _CPWindowShadowColor = nil;
280 BOOL _isMiniaturized;
283 BOOL _isMovableByWindowBackground;
285 unsigned _shadowStyle;
286 BOOL _showsResizeIndicator;
288 int _positioningMask;
289 CGRect _positioningScreenRect;
291 BOOL _isDocumentEdited;
292 BOOL _isDocumentSaving;
301 CPView _leftMouseDownView;
302 CPView _rightMouseDownView;
307 BOOL _hasBecomeKeyWindow;
312 BOOL _acceptsMouseMovedEvents;
313 BOOL _ignoresMouseEvents;
321 CPURL _representedURL;
323 CPSet _registeredDraggedTypes;
324 CPArray _registeredDraggedTypesArray;
328 BOOL _defaultButtonEnabled;
330 BOOL _autorecalculatesKeyViewLoop;
331 BOOL _keyViewLoopIsDirty;
333 BOOL _sharesChromeWithPlatformWindow;
337 DOMElement _DOMElement;
340 unsigned _autoresizingMask;
342 BOOL _delegateRespondsToWindowWillReturnUndoManagerSelector;
344 BOOL _isFullPlatformWindow;
345 _CPWindowFullPlatformWindowSession _fullPlatformWindowSession;
350 _CPWindowFrameAnimation _frameAnimation;
387 - (id)initWithContentRect:(CGRect)aContentRect styleMask:(
unsigned int)aStyleMask
393 var windowViewClass = [[
self class] _windowViewClassForStyleMask:aStyleMask];
395 _frame = [windowViewClass frameRectForContentRect:aContentRect];
407 _frame.size.height = MIN(768.0, visibleFrame.size.height);
408 _frame.size.width = MIN(1024.0, visibleFrame.size.width);
409 _frame.origin.x = (visibleFrame.size.width - _frame.size.width) / 2;
410 _frame.origin.y = (visibleFrame.size.height - _frame.size.height) / 2;
416 _isFullPlatformWindow = NO;
417 _registeredDraggedTypes = [
CPSet set];
418 _registeredDraggedTypesArray = [];
419 _acceptsMouseMovedEvents = YES;
427 _windowNumber = [CPApp._windows count];
428 CPApp._windows[_windowNumber] =
self;
430 _styleMask = aStyleMask;
432 [
self setLevel:CPNormalWindowLevel];
434 _minSize = _CGSizeMake(0.0, 0.0);
435 _maxSize = _CGSizeMake(1000000.0, 1000000.0);
438 _windowView = [[windowViewClass alloc] initWithFrame:_CGRectMake(0.0, 0.0, _CGRectGetWidth(_frame), _CGRectGetHeight(_frame)) styleMask:aStyleMask];
440 [_windowView _setWindow:self];
441 [_windowView setNextResponder:self];
448 _firstResponder =
self;
451 _DOMElement = document.createElement(
"div");
453 _DOMElement.style.position =
"absolute";
454 _DOMElement.style.visibility =
"visible";
455 _DOMElement.style.zIndex = 0;
457 if (![
self _sharesChromeWithPlatformWindow])
459 CPDOMDisplayServerSetStyleLeftTop(_DOMElement, NULL, _CGRectGetMinX(_frame), _CGRectGetMinY(_frame));
462 CPDOMDisplayServerSetStyleSize(_DOMElement, 1, 1);
463 CPDOMDisplayServerAppendChild(_DOMElement, _windowView._DOMElement);
468 [
self setHasShadow:aStyleMask !== CPBorderlessWindowMask];
473 _autorecalculatesKeyViewLoop = NO;
474 _defaultButtonEnabled = YES;
475 _keyViewLoopIsDirty = NO;
476 _hasBecomeKeyWindow = NO;
482 name:CPWindowResizeStyleGlobalChangeNotification
491 return _platformWindow;
507 _platformWindow = aPlatformWindow;
508 [_platformWindow _setTitle:_title window:self];
518 + (Class)_windowViewClassForStyleMask:(
unsigned)aStyleMask
521 return _CPHUDWindowView;
524 return _CPBorderlessWindowView;
527 return _CPDocModalWindowView;
529 return _CPStandardWindowView;
532 + (Class)_windowViewClassForFullPlatformWindowStyleMask:(
unsigned)aStyleMask
534 return _CPBorderlessBridgeWindowView;
541 if (_positioningScreenRect)
545 origin =
frame.origin;
547 if (actualScreenRect)
549 if ((_positioningMask & CPWindowPositionFlexibleLeft) && (_positioningMask & CPWindowPositionFlexibleRight))
552 origin.x *= (actualScreenRect.size.width / _positioningScreenRect.size.width);
554 else if (_positioningMask & CPWindowPositionFlexibleLeft)
557 origin.x += actualScreenRect.size.width - _positioningScreenRect.size.width;
559 else if (_positioningMask & CPWindowPositionFlexibleRight)
564 if ((_positioningMask & CPWindowPositionFlexibleTop) && (_positioningMask & CPWindowPositionFlexibleBottom))
567 origin.y *= (actualScreenRect.size.height / _positioningScreenRect.size.height);
569 else if (_positioningMask & CPWindowPositionFlexibleTop)
572 origin.y += actualScreenRect.size.height - _positioningScreenRect.size.height;
574 else if (_positioningMask & CPWindowPositionFlexibleBottom)
586 if ([
self _hasKeyViewLoop:[_contentView subviews]])
588 var views = [
self _viewsSortedByPosition],
589 count = [views count];
593 for (var i = 1; i < count; ++i)
597 if ([view nextKeyView])
599 [_contentView setNextKeyView:view];
608 [
self _doRecalculateKeyViewLoop];
612 - (void)_setWindowView:(
CPView)aWindowView
614 if (_windowView === aWindowView)
617 var oldWindowView = _windowView;
619 _windowView = aWindowView;
623 [oldWindowView _setWindow:nil];
624 [oldWindowView noteToolbarChanged];
627 CPDOMDisplayServerRemoveChild(_DOMElement, oldWindowView._DOMElement);
634 CPDOMDisplayServerAppendChild(_DOMElement, _windowView._DOMElement);
637 var contentRect = [_contentView convertRect:[_contentView bounds] toView:nil];
639 contentRect.origin = [
self convertBaseToGlobal:contentRect.origin];
641 [_windowView _setWindow:self];
642 [_windowView setNextResponder:self];
643 [_windowView addSubview:_contentView];
644 [_windowView setTitle:_title];
645 [_windowView noteToolbarChanged];
646 [_windowView setShowsResizeIndicator:[
self showsResizeIndicator]];
648 [
self setFrame:[
self frameRectForContentRect:contentRect]];
658 - (void)setFullPlatformWindow:(BOOL)shouldBeFullPlatformWindow
660 if (![_platformWindow supportsFullPlatformWindows])
663 shouldBeFullPlatformWindow = !!shouldBeFullPlatformWindow;
665 if (_isFullPlatformWindow === shouldBeFullPlatformWindow)
668 _isFullPlatformWindow = shouldBeFullPlatformWindow;
670 if (_isFullPlatformWindow)
672 _fullPlatformWindowSession = _CPWindowFullPlatformWindowSessionMake(_windowView, [
self contentRectForFrameRect:[
self frame]], [
self hasShadow], [
self level]);
674 var fullPlatformWindowViewClass = [[
self class] _windowViewClassForFullPlatformWindowStyleMask:_styleMask],
675 windowView = [[fullPlatformWindowViewClass alloc] initWithFrame:_CGRectMakeZero() styleMask:_styleMask];
677 [
self _setWindowView:windowView];
679 [
self setLevel:CPBackgroundWindowLevel];
682 [
self setFrame:[_platformWindow visibleFrame]];
686 var windowView = _fullPlatformWindowSession.windowView;
688 [
self _setWindowView:windowView];
690 [
self setLevel:_fullPlatformWindowSession.level];
691 [
self setHasShadow:_fullPlatformWindowSession.hasShadow];
694 [
self setFrame:[windowView frameRectForContentRect:_fullPlatformWindowSession.contentRect]];
701 - (BOOL)isFullPlatformWindow
703 return _isFullPlatformWindow;
709 - (unsigned)styleMask
732 + (CGRect)frameRectForContentRect:(CGRect)aContentRect styleMask:(
unsigned)aStyleMask
734 return [[[
self class] _windowViewClassForStyleMask:aStyleMask] frameRectForContentRect:aContentRect];
741 - (CGRect)contentRectForFrameRect:(CGRect)aFrame
743 return [_windowView contentRectForFrameRect:aFrame];
751 - (CGRect)frameRectForContentRect:(CGRect)aContentRect
753 return [_windowView frameRectForContentRect:aContentRect];
761 return _CGRectMakeCopy(_frame);
771 - (void)_setClippedFrame:(CGRect)aFrame display:(BOOL)shouldDisplay animate:(BOOL)shouldAnimate
773 aFrame.size.width = MIN(MAX(aFrame.size.width, _minSize.width), _maxSize.width)
774 aFrame.size.height = MIN(MAX(aFrame.size.height, _minSize.height), _maxSize.height);
775 [self setFrame:aFrame display:shouldDisplay animate:shouldAnimate];
785 - (
void)setFrame:(CGRect)aFrame display:(BOOL)shouldDisplay animate:(BOOL)shouldAnimate
787 aFrame = _CGRectMakeCopy(aFrame);
789 var value = aFrame.origin.x,
790 delta = value - FLOOR(value);
793 aFrame.origin.x = value > 0.879 ? CEIL(value) : FLOOR(value);
795 value = aFrame.origin.y;
796 delta = value - FLOOR(value);
799 aFrame.origin.y = value > 0.879 ? CEIL(value) : FLOOR(value);
801 value = aFrame.size.width;
802 delta = value - FLOOR(value);
805 aFrame.size.width = value > 0.15 ? CEIL(value) : FLOOR(value);
807 value = aFrame.size.height;
808 delta = value - FLOOR(value);
811 aFrame.size.height = value > 0.15 ? CEIL(value) : FLOOR(value);
815 [_frameAnimation stopAnimation];
816 _frameAnimation = [[_CPWindowFrameAnimation alloc] initWithWindow:self targetFrame:aFrame];
818 [_frameAnimation startAnimation];
822 var origin = _frame.origin,
823 newOrigin = aFrame.origin;
825 if (!_CGPointEqualToPoint(origin, newOrigin))
827 origin.x = newOrigin.x;
828 origin.y = newOrigin.y;
831 if (![
self _sharesChromeWithPlatformWindow])
833 CPDOMDisplayServerSetStyleLeftTop(_DOMElement, NULL, origin.x, origin.y);
840 var size = _frame.size,
841 newSize = aFrame.size;
843 if (!_CGSizeEqualToSize(size, newSize))
845 size.width = newSize.width;
846 size.height = newSize.height;
848 [_windowView setFrameSize:size];
856 var shadowSize = _CGSizeMake(size.width, size.height);
864 [_shadowView setFrameSize:shadowSize];
871 if ([
self _sharesChromeWithPlatformWindow])
872 [_platformWindow setContentRect:_frame];
881 - (void)setFrame:(CGRect)aFrame display:(BOOL)shouldDisplay
883 [
self _setClippedFrame:aFrame display:shouldDisplay animate:NO];
890 - (void)setFrame:(CGRect)aFrame
892 [
self _setClippedFrame:aFrame display:YES animate:NO];
899 - (void)setFrameOrigin:(CGPoint)anOrigin
901 [
self _setClippedFrame:_CGRectMake(anOrigin.x, anOrigin.y, _CGRectGetWidth(_frame), _CGRectGetHeight(_frame)) display:YES animate:NO];
904 if ([
self attachedSheet])
905 [
self _setAttachedSheetFrameOrigin];
912 - (void)setFrameSize:(CGSize)aSize
914 [
self _setClippedFrame:_CGRectMake(_CGRectGetMinX(_frame), _CGRectGetMinY(_frame), aSize.width, aSize.height) display:YES animate:NO];
921 - (void)orderFront:(
id)aSender
926 [_parentView orderFront:self];
928 [_platformWindow orderFront:self];
929 [_platformWindow order:CPWindowAbove window:self relativeTo:nil];
932 if (!
CPApp._keyWindow)
935 if ([
self isKeyWindow] && (_firstResponder ===
self || !_firstResponder))
938 if (!
CPApp._mainWindow)
947 - (void)orderBack:(
id)aSender
956 - (void)orderOut:(
id)aSender
961 [
self._parentView _detachSheetWindow];
966 if ([
self _sharesChromeWithPlatformWindow])
967 [_platformWindow orderOut:self];
970 if ([_delegate respondsToSelector:
@selector(windowWillClose:)])
971 [_delegate windowWillClose:self];
974 [_platformWindow order:CPWindowOut window:self relativeTo:nil];
977 [
self _updateMainAndKeyWindows];
985 - (void)orderWindow:(CPWindowOrderingMode)aPlace relativeTo:(
int)otherWindowNumber
988 [_platformWindow order:aPlace window:self relativeTo:CPApp._windows[otherWindowNumber]];
996 - (void)setLevel:(
int)aLevel
998 if (aLevel === _level)
1001 [_platformWindow moveWindow:self fromLevel:_level toLevel:aLevel];
1005 if ([
self _sharesChromeWithPlatformWindow])
1006 [_platformWindow setLevel:aLevel];
1030 + (void)setGlobalResizeStyle:(
int)aStyle
1039 - (void)_didReceiveResizeStyleChange:(
CPNotification)aNotification
1041 [_windowView setShowsResizeIndicator:_styleMask & CPResizableWindowMask];
1047 + (int)globalResizeStyle
1055 - (BOOL)showsResizeIndicator
1057 return _showsResizeIndicator;
1064 - (void)setShowsResizeIndicator:(BOOL)shouldShowResizeIndicator
1066 shouldShowResizeIndicator = !!shouldShowResizeIndicator;
1068 if (_showsResizeIndicator === shouldShowResizeIndicator)
1071 _showsResizeIndicator = shouldShowResizeIndicator;
1078 - (CGSize)resizeIndicatorOffset
1080 return [_windowView resizeIndicatorOffset];
1087 - (void)setResizeIndicatorOffset:(CGSize)anOffset
1089 [_windowView setResizeIndicatorOffset:anOffset];
1100 [_contentView removeFromSuperview];
1102 var bounds = _CGRectMake(0.0, 0.0, _CGRectGetWidth(_frame), _CGRectGetHeight(_frame));
1104 _contentView = aView;
1107 [_contentView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
1108 [_windowView addSubview:_contentView];
1114 if (_initialFirstResponder && _initialFirstResponder !==
self)
1115 _initialFirstResponder =
self;
1123 return _contentView;
1130 - (void)setAlphaValue:(
float)aValue
1132 [_windowView setAlphaValue:aValue];
1140 return [_windowView alphaValue];
1149 [_windowView setBackgroundColor:aColor];
1157 return [_windowView backgroundColor];
1165 - (void)setMinSize:(CGSize)aSize
1167 if (_CGSizeEqualToSize(_minSize, aSize))
1170 _minSize = _CGSizeMakeCopy(aSize);
1172 var size = _CGSizeMakeCopy([
self frame].size),
1173 needsFrameChange = NO;
1175 if (size.width < _minSize.width)
1177 size.width = _minSize.width;
1178 needsFrameChange = YES;
1181 if (size.height < _minSize.height)
1183 size.height = _minSize.height;
1184 needsFrameChange = YES;
1187 if (needsFrameChange)
1205 - (void)setMaxSize:(CGSize)aSize
1207 if (_CGSizeEqualToSize(_maxSize, aSize))
1210 _maxSize = _CGSizeMakeCopy(aSize);
1212 var size = _CGSizeMakeCopy([
self frame].size),
1213 needsFrameChange = NO;
1215 if (size.width > _maxSize.width)
1217 size.width = _maxSize.width;
1218 needsFrameChange = YES;
1221 if (size.height > _maxSize.height)
1223 size.height = _maxSize.height;
1224 needsFrameChange = YES;
1227 if (needsFrameChange)
1247 - (void)_updateShadow
1249 if ([
self _sharesChromeWithPlatformWindow])
1254 CPDOMDisplayServerRemoveChild(_DOMElement, _shadowView._DOMElement);
1259 [_platformWindow setHasShadow:_hasShadow];
1264 if (_hasShadow && !_shadowView)
1266 var bounds = [_windowView bounds];
1268 _shadowView = [[
CPView alloc] initWithFrame:_CGRectMake(-SHADOW_MARGIN_LEFT, -SHADOW_MARGIN_TOP + SHADOW_DISTANCE,
1269 SHADOW_MARGIN_LEFT + _CGRectGetWidth(bounds) + SHADOW_MARGIN_RIGHT, SHADOW_MARGIN_TOP + _CGRectGetHeight(bounds) + SHADOW_MARGIN_BOTTOM)];
1271 if (!_CPWindowShadowColor)
1291 [_shadowView setBackgroundColor:_CPWindowShadowColor];
1292 [_shadowView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
1295 CPDOMDisplayServerInsertBefore(_DOMElement, _shadowView._DOMElement, _windowView._DOMElement);
1298 else if (!_hasShadow && _shadowView)
1301 CPDOMDisplayServerRemoveChild(_DOMElement, _shadowView._DOMElement);
1311 - (void)setHasShadow:(BOOL)shouldHaveShadow
1313 if (_hasShadow === shouldHaveShadow)
1316 _hasShadow = shouldHaveShadow;
1318 [
self _updateShadow];
1332 - (void)setShadowStyle:(
unsigned)aStyle
1334 _shadowStyle = aStyle;
1343 - (void)setDelegate:(
id)aDelegate
1347 [defaultCenter removeObserver:_delegate name:CPWindowDidResignKeyNotification object:self];
1348 [defaultCenter removeObserver:_delegate name:CPWindowDidBecomeKeyNotification object:self];
1349 [defaultCenter removeObserver:_delegate name:CPWindowDidBecomeMainNotification object:self];
1350 [defaultCenter removeObserver:_delegate name:CPWindowDidResignMainNotification object:self];
1351 [defaultCenter removeObserver:_delegate name:CPWindowDidMoveNotification object:self];
1352 [defaultCenter removeObserver:_delegate name:CPWindowDidResizeNotification object:self];
1353 [defaultCenter removeObserver:_delegate name:CPWindowWillBeginSheetNotification object:self];
1354 [defaultCenter removeObserver:_delegate name:CPWindowDidEndSheetNotification object:self];
1356 _delegate = aDelegate;
1357 _delegateRespondsToWindowWillReturnUndoManagerSelector = [_delegate respondsToSelector:@selector(windowWillReturnUndoManager:)];
1359 if ([_delegate respondsToSelector:
@selector(windowDidResignKey:)])
1361 addObserver:_delegate
1362 selector:@selector(windowDidResignKey:)
1363 name:CPWindowDidResignKeyNotification
1366 if ([_delegate respondsToSelector:
@selector(windowDidBecomeKey:)])
1368 addObserver:_delegate
1369 selector:@selector(windowDidBecomeKey:)
1370 name:CPWindowDidBecomeKeyNotification
1373 if ([_delegate respondsToSelector:
@selector(windowDidBecomeMain:)])
1375 addObserver:_delegate
1376 selector:@selector(windowDidBecomeMain:)
1377 name:CPWindowDidBecomeMainNotification
1380 if ([_delegate respondsToSelector:
@selector(windowDidResignMain:)])
1382 addObserver:_delegate
1383 selector:@selector(windowDidResignMain:)
1384 name:CPWindowDidResignMainNotification
1387 if ([_delegate respondsToSelector:
@selector(windowDidMove:)])
1389 addObserver:_delegate
1390 selector:@selector(windowDidMove:)
1391 name:CPWindowDidMoveNotification
1394 if ([_delegate respondsToSelector:
@selector(windowDidResize:)])
1396 addObserver:_delegate
1397 selector:@selector(windowDidResize:)
1398 name:CPWindowDidResizeNotification
1401 if ([_delegate respondsToSelector:
@selector(windowWillBeginSheet:)])
1403 addObserver:_delegate
1404 selector:@selector(windowWillBeginSheet:)
1405 name:CPWindowWillBeginSheetNotification
1408 if ([_delegate respondsToSelector:
@selector(windowDidEndSheet:)])
1410 addObserver:_delegate
1411 selector:@selector(windowDidEndSheet:)
1412 name:CPWindowDidEndSheetNotification
1430 _windowController = aWindowController;
1438 return _windowController;
1441 - (void)doCommandBySelector:(
SEL)aSelector
1443 if ([_delegate respondsToSelector:aSelector])
1444 [_delegate performSelector:aSelector];
1449 - (BOOL)acceptsFirstResponder
1456 return _initialFirstResponder;
1459 - (void)setInitialFirstResponder:(
CPView)aView
1461 _initialFirstResponder = aView;
1464 - (void)_setupFirstResponder
1469 if (!_hasBecomeKeyWindow)
1471 if (_firstResponder ===
self)
1473 if (_initialFirstResponder)
1474 [
self makeFirstResponder:_initialFirstResponder];
1478 var view = [_contentView nextValidKeyView];
1481 [
self makeFirstResponder:view];
1488 if (_firstResponder)
1489 [
self makeFirstResponder:_firstResponder];
1501 if (_firstResponder === aResponder)
1504 if (![_firstResponder resignFirstResponder])
1507 if (!aResponder || ![aResponder acceptsFirstResponder] || ![aResponder becomeFirstResponder])
1509 _firstResponder =
self;
1514 _firstResponder = aResponder;
1526 return _firstResponder;
1529 - (BOOL)acceptsMouseMovedEvents
1531 return _acceptsMouseMovedEvents;
1534 - (void)setAcceptsMouseMovedEvents:(BOOL)shouldAcceptMouseMovedEvents
1536 _acceptsMouseMovedEvents = shouldAcceptMouseMovedEvents;
1539 - (BOOL)ignoresMouseEvents
1541 return _ignoresMouseEvents;
1544 - (void)setIgnoresMouseEvents:(BOOL)shouldIgnoreMouseEvents
1546 _ignoresMouseEvents = shouldIgnoreMouseEvents;
1549 - (void)_mouseExitedResizeRect
1571 [_windowView setTitle:aTitle];
1572 [_platformWindow _setTitle:_title window:self];
1574 [
self _synchronizeMenuBarTitleWithWindowTitle];
1580 - (void)setTitleWithRepresentedFilename:(
CPString)aFilePath
1600 return _representedURL;
1608 _representedURL = aURL;
1616 return _representedURL;
1630 - (void)setMovableByWindowBackground:(BOOL)shouldBeMovableByWindowBackground
1632 _isMovableByWindowBackground = shouldBeMovableByWindowBackground;
1638 - (BOOL)isMovableByWindowBackground
1640 return _isMovableByWindowBackground;
1647 - (void)setMovable:(BOOL)shouldBeMovable
1649 _isMovable = shouldBeMovable;
1665 if (_isFullPlatformWindow)
1668 var size = [
self frame].size,
1671 var origin = _CGPointMake((containerSize.width - size.width) / 2.0, (containerSize.height - size.height) / 2.0);
1688 var type = [anEvent
type],
1702 [_windowView mouseDown:anEvent];
1706 [sheet makeKeyAndOrderFront:self];
1709 [_windowView mouseMoved:anEvent];
1760 if (![
self disableKeyEquivalentForDefaultButton])
1763 keyEquivalent = [defaultButton keyEquivalent],
1764 modifierMask = [defaultButton keyEquivalentModifierMask];
1766 if ([anEvent _triggersKeyEquivalent:keyEquivalent withModifierMask:modifierMask])
1773 return [[_windowView hitTest:point] scrollWheel:anEvent];
1777 var hitTestedView = _leftMouseDownView,
1778 selector = type ==
CPRightMouseUp ?
@selector(rightMouseUp:) :
@selector(mouseUp:);
1781 hitTestedView = [_windowView hitTest:point];
1783 [hitTestedView performSelector:selector withObject:anEvent];
1785 _leftMouseDownView = nil;
1791 _leftMouseDownView = [_windowView hitTest:point];
1793 if (_leftMouseDownView != _firstResponder && [_leftMouseDownView acceptsFirstResponder])
1796 [CPApp activateIgnoringOtherApps:YES];
1798 var theWindow = [anEvent
window],
1799 selector = type ==
CPRightMouseDown ?
@selector(rightMouseDown:) :
@selector(mouseDown:);
1801 if ([theWindow isKeyWindow] || [theWindow becomesKeyOnlyIfNeeded] && ![_leftMouseDownView needsPanelToBecomeKey])
1802 return [_leftMouseDownView performSelector:selector withObject:anEvent];
1808 if ([_leftMouseDownView acceptsFirstMouse:anEvent])
1809 return [_leftMouseDownView performSelector:selector withObject:anEvent];
1815 if (!_leftMouseDownView)
1816 return [[_windowView hitTest:point] mouseDragged:anEvent];
1822 selector =
@selector(rightMouseDragged:)
1823 if (![_leftMouseDownView respondsToSelector:selector])
1828 selector =
@selector(mouseDragged:)
1830 return [_leftMouseDownView performSelector:selector withObject:anEvent];
1833 [_windowView setCursorForLocation:point resizing:NO];
1835 if (!_acceptsMouseMovedEvents)
1838 if (!_mouseEnteredStack)
1839 _mouseEnteredStack = [];
1841 var hitTestView = [_windowView hitTest:point];
1843 if ([_mouseEnteredStack count] && [_mouseEnteredStack lastObject] === hitTestView)
1844 return [hitTestView mouseMoved:anEvent];
1846 var view = hitTestView,
1847 mouseEnteredStack = [];
1851 mouseEnteredStack.unshift(view);
1853 view = [view superview];
1856 var deviation = MIN(_mouseEnteredStack.length, mouseEnteredStack.length);
1859 if (_mouseEnteredStack[deviation] === mouseEnteredStack[deviation])
1862 var index = deviation + 1,
1863 count = _mouseEnteredStack.length;
1869 for (; index < count; ++index)
1870 [_mouseEnteredStack[index] mouseExited:event];
1873 index = deviation + 1;
1874 count = mouseEnteredStack.length;
1880 for (; index < count; ++index)
1881 [mouseEnteredStack[index] mouseEntered:event];
1884 _mouseEnteredStack = mouseEnteredStack;
1886 [hitTestView mouseMoved:anEvent];
1895 return _windowNumber;
1903 - (void)becomeKeyWindow
1905 CPApp._keyWindow =
self;
1907 if (_firstResponder !==
self && [_firstResponder respondsToSelector:
@selector(becomeKeyWindow)])
1908 [_firstResponder becomeKeyWindow];
1910 if (!_hasBecomeKeyWindow)
1914 if (![
self _hasKeyViewLoop:[_contentView subviews]])
1918 [
self _setupFirstResponder];
1919 _hasBecomeKeyWindow = YES;
1921 [_windowView noteKeyWindowStateChanged];
1932 - (BOOL)canBecomeKeyWindow
1951 return [CPApp keyWindow] ==
self;
1958 - (void)makeKeyAndOrderFront:(
id)aSender
1969 - (void)makeKeyWindow
1971 if ([
CPApp keyWindow] ===
self || ![
self canBecomeKeyWindow])
1974 [[CPApp keyWindow] resignKeyWindow];
1981 - (void)resignKeyWindow
1983 if (_firstResponder !==
self && [_firstResponder respondsToSelector:
@selector(resignKeyWindow)])
1984 [_firstResponder resignKeyWindow];
1986 if (
CPApp._keyWindow ===
self)
1987 CPApp._keyWindow = nil;
1989 [_windowView noteKeyWindowStateChanged];
2006 - (void)dragImage:(
CPImage)anImage at:(CGPoint)imageLocation offset:(CGSize)mouseOffset event:(
CPEvent)anEvent pasteboard:(
CPPasteboard)aPasteboard source:(
id)aSourceObject slideBack:(BOOL)slideBack
2011 - (void)_noteRegisteredDraggedTypes:(
CPSet)pasteboardTypes
2013 if (!pasteboardTypes)
2016 if (!_inclusiveRegisteredDraggedTypes)
2019 [_inclusiveRegisteredDraggedTypes unionSet:pasteboardTypes];
2022 - (void)_noteUnregisteredDraggedTypes:(
CPSet)pasteboardTypes
2024 if (!pasteboardTypes)
2027 [_inclusiveRegisteredDraggedTypes minusSet:pasteboardTypes];
2029 if ([_inclusiveRegisteredDraggedTypes count] === 0)
2030 _inclusiveRegisteredDraggedTypes = nil;
2043 - (void)dragView:(
CPView)aView at:(CGPoint)viewLocation offset:(CGSize)mouseOffset event:(
CPEvent)anEvent pasteboard:(
CPPasteboard)aPasteboard source:(
id)aSourceObject slideBack:(BOOL)slideBack
2052 - (void)registerForDraggedTypes:(
CPArray)pasteboardTypes
2054 if (!pasteboardTypes)
2057 [
self _noteUnregisteredDraggedTypes:_registeredDraggedTypes];
2058 [_registeredDraggedTypes addObjectsFromArray:pasteboardTypes];
2059 [
self _noteRegisteredDraggedTypes:_registeredDraggedTypes];
2061 _registeredDraggedTypesArray = nil;
2070 if (!_registeredDraggedTypesArray)
2071 _registeredDraggedTypesArray = [_registeredDraggedTypes allObjects];
2073 return _registeredDraggedTypesArray;
2079 - (void)unregisterDraggedTypes
2081 [
self _noteUnregisteredDraggedTypes:_registeredDraggedTypes];
2083 _registeredDraggedTypes = [
CPSet set];
2084 _registeredDraggedTypesArray = [];
2093 - (void)setDocumentEdited:(BOOL)isDocumentEdited
2095 if (_isDocumentEdited == isDocumentEdited)
2098 _isDocumentEdited = isDocumentEdited;
2100 [
CPMenu _setMenuBarIconImageAlphaValue:_isDocumentEdited ? 0.5 : 1.0];
2102 [_windowView setDocumentEdited:isDocumentEdited];
2108 - (BOOL)isDocumentEdited
2110 return _isDocumentEdited;
2113 - (void)setDocumentSaving:(BOOL)isDocumentSaving
2115 if (_isDocumentSaving == isDocumentSaving)
2118 _isDocumentSaving = isDocumentSaving;
2120 [
self _synchronizeSaveMenuWithDocumentSaving];
2122 [_windowView windowDidChangeDocumentSaving];
2125 - (BOOL)isDocumentSaving
2127 return _isDocumentSaving;
2131 - (void)_synchronizeSaveMenuWithDocumentSaving
2133 if (![
self isMainWindow])
2136 var mainMenu = [CPApp mainMenu],
2137 index = [mainMenu indexOfItemWithTitle:_isDocumentSaving ? @"Save" : @"Saving..."];
2142 var item = [mainMenu itemAtIndex:index];
2144 if (_isDocumentSaving)
2148 [item setTitle:@"Saving..."];
2149 [item setImage:CPWindowSavingImage];
2150 [item setEnabled:NO];
2154 [item setTitle:@"Save"];
2155 [item setImage:CPWindowSaveImage];
2156 [item setEnabled:YES];
2166 - (void)performMiniaturize:(
id)aSender
2176 - (void)miniaturize:(
id)sender
2182 [
self _updateMainAndKeyWindows];
2186 _isMiniaturized = YES;
2192 - (void)deminiaturize:(
id)sender
2198 _isMiniaturized = NO;
2204 - (void)isMiniaturized
2206 return _isMiniaturized;
2215 - (void)performClose:(
id)aSender
2220 if ([
self isFullBridge])
2222 var
event = [CPApp currentEvent];
2232 if ([_delegate respondsToSelector:
@selector(windowShouldClose:)])
2234 if (![_delegate windowShouldClose:
self])
2239 else if ([
self respondsToSelector:
@selector(windowShouldClose:)] && ![
self windowShouldClose:
self])
2242 var documents = [_windowController documents];
2244 if ([documents count])
2246 var index = [documents indexOfObject:[_windowController document]];
2248 [documents[index] shouldCloseWindowController:_windowController
2250 shouldCloseSelector:@selector(_windowControllerContainingDocument:shouldClose:contextInfo:)
2251 contextInfo:{documents:[documents copy], visited:0, index:index}];
2257 - (void)_windowControllerContainingDocument:(
CPDocument)document shouldClose:(BOOL)shouldClose contextInfo:(Object)context
2261 var windowController = [
self windowController],
2262 documents = context.documents,
2263 count = [documents count],
2264 visited = ++context.visited,
2265 index = ++context.index % count;
2269 if (visited < count)
2271 [windowController setDocument:documents[index]];
2273 [documents[index] shouldCloseWindowController:_windowController
2275 shouldCloseSelector:@selector(_windowControllerContainingDocument:shouldClose:contextInfo:)
2276 contextInfo:context];
2298 - (BOOL)isMainWindow
2300 return [CPApp mainWindow] ===
self;
2306 - (BOOL)canBecomeMainWindow
2313 return ([
self isVisible] && ((_styleMask &
CPTitledWindowMask) || _isFullPlatformWindow));
2319 - (void)makeMainWindow
2321 if ([
CPApp mainWindow] ===
self || ![
self canBecomeMainWindow])
2324 [[CPApp mainWindow] resignMainWindow];
2331 - (void)becomeMainWindow
2333 CPApp._mainWindow =
self;
2335 [
self _synchronizeMenuBarTitleWithWindowTitle];
2336 [
self _synchronizeSaveMenuWithDocumentSaving];
2338 [_windowView noteMainWindowStateChanged];
2348 - (void)resignMainWindow
2354 if (
CPApp._mainWindow ===
self)
2355 CPApp._mainWindow = nil;
2357 [_windowView noteMainWindowStateChanged];
2360 - (void)_updateMainAndKeyWindows
2362 var allWindows = [CPApp orderedWindows],
2363 windowCount = [allWindows count];
2365 if ([
self isKeyWindow])
2367 var keyWindow = [CPApp keyWindow];
2368 [
self resignKeyWindow];
2370 if (keyWindow && keyWindow !==
self && [keyWindow canBecomeKeyWindow])
2371 [keyWindow makeKeyWindow];
2374 var mainMenu = [CPApp mainMenu],
2375 menuBarClass = objj_getClass(
"_CPMenuBarWindow"),
2378 for (var i = 0; i < windowCount; i++)
2380 var currentWindow = allWindows[i];
2382 if ([currentWindow isKindOfClass:menuBarClass])
2383 menuWindow = currentWindow;
2385 if (currentWindow ===
self || currentWindow === menuWindow)
2388 if ([currentWindow isVisible] && [currentWindow canBecomeKeyWindow])
2390 [currentWindow makeKeyWindow];
2395 if (![
CPApp keyWindow])
2396 [menuWindow makeKeyWindow];
2400 if ([
self isMainWindow])
2402 var mainWindow = [CPApp mainWindow];
2403 [
self resignMainWindow];
2405 if (mainWindow && mainWindow !==
self && [mainWindow canBecomeMainWindow])
2406 [mainWindow makeMainWindow];
2409 var mainMenu = [CPApp mainMenu],
2410 menuBarClass = objj_getClass(
"_CPMenuBarWindow"),
2413 for (var i = 0; i < windowCount; i++)
2415 var currentWindow = allWindows[i];
2417 if ([currentWindow isKindOfClass:menuBarClass])
2418 menuWindow = currentWindow;
2420 if (currentWindow ===
self || currentWindow === menuWindow)
2423 if ([currentWindow isVisible] && [currentWindow canBecomeMainWindow])
2425 [currentWindow makeMainWindow];
2448 if (_toolbar === aToolbar)
2452 [[aToolbar _window] setToolbar:nil];
2455 [_toolbar _setWindow:nil];
2457 _toolbar = aToolbar;
2460 [_toolbar _setWindow:self];
2462 [
self _noteToolbarChanged];
2465 - (void)toggleToolbarShown:(
id)aSender
2469 [toolbar setVisible:![toolbar isVisible]];
2472 - (void)_noteToolbarChanged
2474 var
frame = _CGRectMakeCopy([
self frame]),
2477 [_windowView noteToolbarChanged];
2479 if (_isFullPlatformWindow)
2480 newFrame = [_platformWindow visibleFrame];
2483 newFrame = _CGRectMakeCopy([
self frame]);
2485 newFrame.origin = frame.origin;
2488 [
self setFrame:newFrame];
2497 - (void)_setFrame:(CGRect)aFrame delegate:(
id)delegate duration:(
int)duration curve:(CPAnimationCurve)curve
2499 [_frameAnimation stopAnimation];
2500 _frameAnimation = [[_CPWindowFrameAnimation alloc] initWithWindow:self targetFrame:aFrame];
2501 [_frameAnimation setDelegate:delegate];
2502 [_frameAnimation setAnimationCurve:curve];
2503 [_frameAnimation setDuration:duration];
2504 [_frameAnimation startAnimation];
2507 - (CPTimeInterval)animationResizeTime:(CGRect)newWindowFrame
2513 - (void)_setAttachedSheetFrameOrigin
2516 var attachedSheet = [
self attachedSheet],
2517 contentRect = [_contentView frame],
2518 sheetFrame = _CGRectMakeCopy([attachedSheet
frame]);
2520 sheetFrame.origin.y = _CGRectGetMinY(_frame) + _CGRectGetMinY(contentRect);
2521 sheetFrame.origin.x = _CGRectGetMinX(_frame) + FLOOR((_CGRectGetWidth(_frame) - _CGRectGetWidth(sheetFrame)) / 2.0);
2523 [attachedSheet setFrame:sheetFrame display:YES animate:NO];
2529 - (void)_attachSheet:(
CPWindow)aSheet modalDelegate:(
id)aModalDelegate
2530 didEndSelector:(
SEL)aDidEndSelector contextInfo:(
id)aContextInfo
2535 reason:@"The target window of beginSheet: already has a sheet, did you forget orderOut: ?"];
2539 var sheetFrame = [aSheet
frame];
2541 _sheetContext = {
"sheet": aSheet,
"modalDelegate": aModalDelegate,
"endSelector": aDidEndSelector,
2542 "contextInfo": aContextInfo,
"frame": _CGRectMakeCopy(sheetFrame),
"returnCode": -1,
2545 [
self _attachSheetWindow];
2552 - (void)_attachSheetWindow
2554 _sheetContext["isAttached"] = YES;
2570 var delegate = _sheetContext["modalDelegate"],
2571 endSelector = _sheetContext["endSelector"];
2575 if (delegate && endSelector)
2577 if (_sheetContext[
"isAttached"])
2578 objj_msgSend(delegate, endSelector, _sheetContext[
"sheet"], _sheetContext[
"returnCode"],
2579 _sheetContext[
"contextInfo"]);
2581 _sheetContext["deferDidEndSelector"] = YES;
2589 - (void)_detachSheetWindow
2591 _sheetContext["isAttached"] = NO;
2604 - (void)_cleanupSheetWindow
2606 var sheet = _sheetContext["sheet"],
2607 lastFrame = _sheetContext["frame"],
2608 deferDidEnd = _sheetContext["deferDidEndSelector"];
2610 [sheet setFrame:lastFrame];
2611 [
self _restoreMasksForView:[sheet contentView]];
2618 [sheet._windowView _enableSheet:NO];
2621 sheet._isSheet = NO;
2622 [sheet orderOut:self];
2628 var delegate = _sheetContext["modalDelegate"],
2629 selector = _sheetContext["endSelector"],
2630 returnCode = _sheetContext["returnCode"],
2631 contextInfo = _sheetContext["contextInfo"];
2634 _sheetContext = nil;
2635 sheet._parentView = nil;
2637 objj_msgSend(delegate, selector, sheet, returnCode, contextInfo);
2641 _sheetContext = nil;
2642 sheet._parentView = nil;
2647 - (void)animationDidEnd:(
id)anim
2649 var sheet = _sheetContext["sheet"];
2651 if (anim._window != sheet)
2662 - (void)_sheetShouldAnimateIn:(
CPTimer)timer
2665 if (_sheetContext[
"isOpening"] ||
2666 _sheetContext[
"isClosing"])
2669 var sheet = _sheetContext["sheet"],
2670 sheetFrame = [sheet frame],
2671 frame = [
self frame];
2673 [
self _setUpMasksForView:[sheet contentView]];
2675 sheet._isSheet = YES;
2676 sheet._parentView =
self;
2679 originy =
frame.origin.y + [_contentView
frame].origin.y,
2680 startFrame = _CGRectMake(originx, originy, sheetFrame.size.
width, 0),
2681 endFrame = _CGRectMake(originx, originy, sheetFrame.size.
width, sheetFrame.size.height);
2687 sheet._isModal = NO;
2689 if ([
CPApp modalWindow] ===
self)
2691 [CPApp runModalForWindow:sheet];
2692 sheet._isModal = YES;
2695 [sheet orderFront:self];
2696 [sheet setFrame:startFrame display:YES animate:NO];
2698 _sheetContext["opened"] = YES;
2699 _sheetContext["shouldClose"] = NO;
2700 _sheetContext["isOpening"] = YES;
2702 [sheet _setFrame:endFrame delegate:self duration:[
self animationResizeTime:endFrame] curve:CPAnimationEaseOut];
2707 [sheet makeKeyWindow];
2711 - (void)_sheetShouldAnimateOut:(
CPTimer)timer
2713 var sheet = _sheetContext["sheet"],
2714 startFrame = [sheet frame],
2715 endFrame = _CGRectMakeCopy(startFrame);
2717 if (_sheetContext[
"isOpening"])
2720 _sheetContext["shouldClose"] = YES;
2724 if (_sheetContext[
"isClosing"])
2727 _sheetContext["opened"] = NO;
2728 _sheetContext["frame"] = startFrame;
2729 _sheetContext["isClosing"] = YES;
2732 if ([
self isVisible])
2734 endFrame.size.height = 0;
2735 [
self _setUpMasksForView:[sheet contentView]];
2736 [sheet _setFrame:endFrame delegate:self duration:[
self animationResizeTime:endFrame] curve:CPAnimationEaseIn];
2740 [
self _sheetAnimationDidEnd:nil];
2745 - (void)_sheetAnimationDidEnd:(
CPTimer)timer
2747 var sheet = _sheetContext["sheet"];
2749 _sheetContext["isOpening"] = NO;
2750 _sheetContext["isClosing"] = NO;
2752 if (_sheetContext[
"opened"] === YES)
2755 [
self _restoreMasksForView:[sheet contentView]];
2758 if (_sheetContext[
"shouldClose"] === YES)
2759 [
self _detachSheetWindow];
2764 [
self _cleanupSheetWindow];
2768 - (void)_setUpMasksForView:(
CPView)aView
2772 [views addObject:aView];
2774 for (var i = 0, count = [views count]; i < count; i++)
2776 var view = [views objectAtIndex:i],
2777 mask = [view autoresizingMask],
2780 [view setAutoresizingMask:(mask | maskToAdd)];
2784 - (void)_restoreMasksForView:(
CPView)aView
2788 [views addObject:aView];
2790 for (var i = 0, count = [views count]; i < count; i++)
2792 var view = [views objectAtIndex:i],
2793 mask = [view autoresizingMask],
2796 [view setAutoresizingMask:(mask & (~ maskToRemove))];
2805 if (_sheetContext === nil)
2808 return _sheetContext["sheet"];
2824 - (BOOL)becomesKeyOnlyIfNeeded
2833 - (BOOL)worksWhenModal
2842 return [_contentView performKeyEquivalent:anEvent];
2849 if ([anEvent _couldBeKeyEquivalent] && [
self performKeyEquivalent:anEvent])
2857 if (![
self _processKeyboardUIKey:anEvent])
2869 - (BOOL)_processKeyboardUIKey:(
CPEvent)anEvent
2878 if ([selectors count] <= 0)
2883 var selector = [selectors objectAtIndex:0];
2884 return [[
self firstResponder] tryToPerform:selector with:self];
2891 [[
self firstResponder] doCommandBySelector:@selector(complete:)];
2897 - (void)_dirtyKeyViewLoop
2899 if (_autorecalculatesKeyViewLoop)
2900 _keyViewLoopIsDirty = YES;
2908 - (BOOL)_hasKeyViewLoop:(
CPArray)theViews
2911 count = [theViews
count];
2913 for (i = 0; i < count; ++i)
2915 var view = theViews[i];
2917 if ([view nextKeyView] || [view previousKeyView])
2921 for (i = 0; i < count; ++i)
2923 var subviews = [theViews[i] subviews];
2925 if ([subviews count] && [
self _hasKeyViewLoop:subviews])
2939 - (void)recalculateKeyViewLoop
2941 [
self _doRecalculateKeyViewLoop];
2944 - (
CPArray)_viewsSortedByPosition
2948 views = views.concat([
self _subviewsSortedByPosition:[_contentView subviews]]);
2961 theSubviews = [theSubviews
copy];
2962 [theSubviews sortUsingFunction:keyViewComparator context:nil];
2964 var sortedViews = [];
2966 for (var i = 0, count = [theSubviews count]; i < count; ++i)
2968 var view = theSubviews[i],
2969 subviews = [view subviews];
2971 sortedViews.push(view);
2973 if ([subviews count])
2974 sortedViews = sortedViews.concat([
self _subviewsSortedByPosition:subviews]);
2980 - (void)_doRecalculateKeyViewLoop
2982 var views = [
self _viewsSortedByPosition];
2984 for (var index = 0, count = [views count]; index < count; ++index)
2985 [views[index] setNextKeyView:views[(index + 1) % count]];
2987 _keyViewLoopIsDirty = NO;
2990 - (void)setAutorecalculatesKeyViewLoop:(BOOL)shouldRecalculate
2992 if (_autorecalculatesKeyViewLoop === shouldRecalculate)
2995 _autorecalculatesKeyViewLoop = shouldRecalculate;
2998 - (BOOL)autorecalculatesKeyViewLoop
3000 return _autorecalculatesKeyViewLoop;
3003 - (void)selectNextKeyView:(
id)sender
3005 if (_keyViewLoopIsDirty)
3006 [
self _doRecalculateKeyViewLoop];
3008 var nextValidKeyView = nil;
3010 if ([_firstResponder isKindOfClass:[
CPView class]])
3011 nextValidKeyView = [_firstResponder nextValidKeyView];
3013 if (!nextValidKeyView)
3015 if ([_initialFirstResponder acceptsFirstResponder])
3016 nextValidKeyView = _initialFirstResponder;
3018 nextValidKeyView = [_initialFirstResponder nextValidKeyView];
3021 if (nextValidKeyView)
3022 [
self makeFirstResponder:nextValidKeyView];
3025 - (void)selectPreviousKeyView:(
id)sender
3027 if (_keyViewLoopIsDirty)
3028 [
self _doRecalculateKeyViewLoop];
3030 var previousValidKeyView = nil;
3032 if ([_firstResponder isKindOfClass:[
CPView class]])
3033 previousValidKeyView = [_firstResponder previousValidKeyView];
3035 if (!previousValidKeyView)
3037 if ([_initialFirstResponder acceptsFirstResponder])
3038 previousValidKeyView = _initialFirstResponder;
3040 previousValidKeyView = [_initialFirstResponder previousValidKeyView];
3043 if (previousValidKeyView)
3044 [
self makeFirstResponder:previousValidKeyView];
3047 - (void)selectKeyViewFollowingView:(
CPView)aView
3049 if (_keyViewLoopIsDirty)
3050 [
self _doRecalculateKeyViewLoop];
3054 if ([nextValidKeyView isKindOfClass:[
CPView class]])
3055 [
self makeFirstResponder:nextValidKeyView];
3058 - (void)selectKeyViewPrecedingView:(
CPView)aView
3060 if (_keyViewLoopIsDirty)
3061 [
self _doRecalculateKeyViewLoop];
3065 if ([previousValidKeyView isKindOfClass:[
CPView class]])
3066 [
self makeFirstResponder:previousValidKeyView];
3096 if (_defaultButton === aButton)
3100 [_defaultButton setKeyEquivalent:nil];
3102 _defaultButton = aButton;
3113 return _defaultButton;
3119 - (void)enableKeyEquivalentForDefaultButton
3121 _defaultButtonEnabled = YES;
3128 - (void)enableKeyEquivalentForDefaultButtonCell
3136 - (void)disableKeyEquivalentForDefaultButton
3138 _defaultButtonEnabled = NO;
3145 - (void)disableKeyEquivalentForDefaultButtonCell
3154 var lhsBounds = [lhs convertRect:[lhs bounds] toView:nil],
3155 rhsBounds = [rhs convertRect:[rhs bounds] toView:nil],
3156 lhsY = _CGRectGetMinY(lhsBounds),
3157 rhsY = _CGRectGetMinY(rhsBounds),
3158 lhsX = _CGRectGetMinX(lhsBounds),
3159 rhsX = _CGRectGetMinX(rhsBounds),
3160 intersectsVertically = MIN(_CGRectGetMaxY(lhsBounds), _CGRectGetMaxY(rhsBounds)) - MAX(lhsY, rhsY);
3163 if (intersectsVertically > 0)
3185 - (void)_synchronizeMenuBarTitleWithWindowTitle
3188 if (![_windowController document] || ![
self isMainWindow])
3201 - (void)resizeWithOldPlatformWindowSize:(CGSize)aSize
3203 if ([
self isFullPlatformWindow])
3204 return [
self setFrame:[_platformWindow visibleFrame]];
3209 var
frame = [_platformWindow contentBounds],
3210 newFrame = _CGRectMakeCopy(_frame),
3211 dX = (_CGRectGetWidth(
frame) - aSize.width) /
3213 dY = (_CGRectGetHeight(
frame) - aSize.height) /
3217 newFrame.origin.x += dX;
3219 newFrame.size.width += dX;
3222 newFrame.origin.y += dY;
3224 newFrame.size.height += dY;
3232 - (void)setAutoresizingMask:(
unsigned)anAutoresizingMask
3234 _autoresizingMask = anAutoresizingMask;
3240 - (unsigned)autoresizingMask
3242 return _autoresizingMask;
3248 - (CGPoint)convertBaseToGlobal:(CGPoint)aPoint
3256 - (CGPoint)convertGlobalToBase:(CGPoint)aPoint
3264 - (CGPoint)convertBaseToPlatformWindow:(CGPoint)aPoint
3266 if ([
self _sharesChromeWithPlatformWindow])
3267 return _CGPointMakeCopy(aPoint);
3269 var origin = [
self frame].origin;
3271 return _CGPointMake(aPoint.x + origin.x, aPoint.y + origin.y);
3277 - (CGPoint)convertPlatformWindowToBase:(CGPoint)aPoint
3279 if ([
self _sharesChromeWithPlatformWindow])
3280 return _CGPointMakeCopy(aPoint);
3282 var origin = [
self frame].origin;
3284 return _CGPointMake(aPoint.x - origin.x, aPoint.y - origin.y);
3287 - (CGPoint)convertScreenToBase:(CGPoint)aPoint
3292 - (CGPoint)convertBaseToScreen:(CGPoint)aPoint
3297 - (void)_setSharesChromeWithPlatformWindow:(BOOL)shouldShareFrameWithPlatformWindow
3300 if (shouldShareFrameWithPlatformWindow && [
CPPlatform isBrowser])
3303 _sharesChromeWithPlatformWindow = shouldShareFrameWithPlatformWindow;
3305 [
self _updateShadow];
3308 - (BOOL)_sharesChromeWithPlatformWindow
3310 return _sharesChromeWithPlatformWindow;
3321 return _undoManager;
3324 var documentUndoManager = [[_windowController document] undoManager];
3326 if (documentUndoManager)
3327 return documentUndoManager;
3330 if (_delegateRespondsToWindowWillReturnUndoManagerSelector)
3331 return [_delegate windowWillReturnUndoManager:self];
3337 return _undoManager;
3344 - (void)undo:(
id)aSender
3353 - (void)redo:(
id)aSender
3358 - (BOOL)containsPoint:(CGPoint)aPoint
3360 return _CGRectContainsPoint(_frame, aPoint);
3363 - (BOOL)_isValidMousePoint:(CGPoint)aPoint
3369 return _CGRectContainsPoint(mouseFrame, aPoint);
3379 - (void)setFullBridge:(BOOL)shouldBeFullBridge
3388 - (BOOL)isFullBridge
3396 - (CGPoint)convertBaseToBridge:(CGPoint)aPoint
3404 - (CGPoint)convertBridgeToBase:(CGPoint)aPoint
3413 return fromValue + (toValue - fromValue) * progress;
3417 @implementation _CPWindowFrameAnimation :
CPAnimation
3422 CGRect _targetFrame;
3425 - (id)initWithWindow:(
CPWindow)aWindow targetFrame:(CGRect)aTargetFrame
3427 self = [
super initWithDuration:[aWindow
animationResizeTime:aTargetFrame] animationCurve:CPAnimationLinear];
3433 _targetFrame = _CGRectMakeCopy(aTargetFrame);
3434 _startFrame = _CGRectMakeCopy([_window
frame]);
3440 - (void)startAnimation
3442 [
super startAnimation];
3444 _window._isAnimating = YES;
3447 - (void)setCurrentProgress:(
float)aProgress
3449 [
super setCurrentProgress:aProgress];
3451 var value = [
self currentValue];
3454 _window._isAnimating = NO;
3456 var newFrame = _CGRectMake(
3457 interpolate(_CGRectGetMinX(_startFrame), _CGRectGetMinX(_targetFrame), value),
3458 interpolate(_CGRectGetMinY(_startFrame), _CGRectGetMinY(_targetFrame), value),
3459 interpolate(_CGRectGetWidth(_startFrame), _CGRectGetWidth(_targetFrame), value),
3460 interpolate(_CGRectGetHeight(_startFrame), _CGRectGetHeight(_targetFrame), value));
3462 [_window setFrame:newFrame display:YES animate:NO];
3467 function _CPWindowFullPlatformWindowSessionMake(aWindowView, aContentRect, hasShadow, aLevel)
3469 return { windowView:aWindowView, contentRect:aContentRect, hasShadow:hasShadow, level:aLevel };