32 var CPWindowSaveImage = nil,
34 CPWindowResizeTime = 0.2,
35 CPWindowResizeStyleGlobalChangeNotification =
@"CPWindowResizeStyleGlobalChangeNotification",
37 CPWindowMinVisibleHorizontalMargin = 40,
38 CPWindowMinVisibleVerticalMargin = 2;
43 var CPWindowActionMessageKeys = [
120 BOOL _hasBeenOrderedIn;
121 BOOL _isMiniaturized;
124 BOOL _isMovableByWindowBackground;
126 BOOL _constrainsToUsableScreen;
127 unsigned _shadowStyle;
128 BOOL _showsResizeIndicator;
130 int _positioningMask;
131 CGRect _positioningScreenRect;
133 BOOL _isDocumentEdited;
134 BOOL _isDocumentSaving;
142 CPArray _mouseEnteredStack;
143 CPView _leftMouseDownView;
144 CPView _rightMouseDownView;
149 BOOL _hasBecomeKeyWindow;
154 BOOL _acceptsMouseMovedEvents;
155 BOOL _ignoresMouseEvents;
163 CPURL _representedURL;
165 CPSet _registeredDraggedTypes;
166 CPArray _registeredDraggedTypesArray;
170 BOOL _defaultButtonEnabled;
172 BOOL _autorecalculatesKeyViewLoop;
173 BOOL _keyViewLoopIsDirty;
175 BOOL _sharesChromeWithPlatformWindow;
179 DOMElement _DOMElement;
182 unsigned _autoresizingMask;
184 BOOL _delegateRespondsToWindowWillReturnUndoManagerSelector;
186 BOOL _isFullPlatformWindow;
187 _CPWindowFullPlatformWindowSession _fullPlatformWindowSession;
190 CPArray _childWindows;
191 CPWindowOrderingMode _childOrdering;
196 _CPWindowFrameAnimation _frameAnimation;
199 + (Class)_binderClassForBinding:(
CPString)aBinding
201 if ([aBinding hasPrefix:CPDisplayPatternTitleBinding])
204 return [
super _binderClassForBinding:aBinding];
209 return [
self initWithContentRect:CGRectMakeZero() styleMask:CPTitledWindowMask];
227 - (id)initWithContentRect:(CGRect)aContentRect styleMask:(
unsigned)aStyleMask
233 var windowViewClass = [[
self class] _windowViewClassForStyleMask:aStyleMask];
235 _frame = [windowViewClass frameRectForContentRect:aContentRect];
236 _constrainsToUsableScreen = YES;
247 var visibleFrame = [[[
CPScreen alloc] init] visibleFrame];
248 _frame.size.height = MIN(768.0, visibleFrame.size.height);
249 _frame.size.width = MIN(1024.0, visibleFrame.size.width);
250 _frame.origin.x = (visibleFrame.size.width - _frame.size.
width) / 2;
251 _frame.origin.y = (visibleFrame.size.height - _frame.size.height) / 2;
254 [
self setPlatformWindow:[[
CPPlatformWindow alloc] initWithContentRect:_frame]];
255 [
self platformWindow]._only =
self;
258 _isFullPlatformWindow = NO;
259 _registeredDraggedTypes = [CPSet set];
260 _registeredDraggedTypesArray = [];
261 _acceptsMouseMovedEvents = YES;
263 _hasBeenOrderedIn = NO;
274 _windowNumber = [CPApp._windows count];
275 CPApp._windows[_windowNumber] =
self;
277 _styleMask = aStyleMask;
279 [
self setLevel:CPNormalWindowLevel];
282 _windowView = [[windowViewClass alloc] initWithFrame:CGRectMake(0.0, 0.0, CGRectGetWidth(_frame), CGRectGetHeight(_frame)) styleMask:aStyleMask];
284 [_windowView _setWindow:self];
285 [_windowView setNextResponder:self];
288 _minSize = [
self _calculateMinSizeForProposedSize:CGSizeMake(0.0, 0.0)];
289 _maxSize = CGSizeMake(1000000.0, 1000000.0);
291 [
self setMovableByWindowBackground:aStyleMask & CPHUDBackgroundWindowMask];
294 [
self setContentView:[[
CPView alloc] initWithFrame:CGRectMakeZero()]];
296 _firstResponder =
self;
299 _DOMElement = document.createElement(
"div");
301 _DOMElement.style.position =
"absolute";
302 _DOMElement.style.visibility =
"visible";
303 _DOMElement.style.zIndex = 0;
305 if (![
self _sharesChromeWithPlatformWindow])
307 CPDOMDisplayServerSetStyleLeftTop(_DOMElement, NULL, CGRectGetMinX(_frame), CGRectGetMinY(_frame));
310 CPDOMDisplayServerSetStyleSize(_DOMElement, 1, 1);
311 CPDOMDisplayServerAppendChild(_DOMElement, _windowView._DOMElement);
314 [
self setNextResponder:CPApp];
316 [
self setHasShadow:aStyleMask !== CPBorderlessWindowMask];
319 [
self setFullPlatformWindow:YES];
321 _autorecalculatesKeyViewLoop = NO;
322 _defaultButtonEnabled = YES;
323 _keyViewLoopIsDirty = NO;
324 _hasBecomeKeyWindow = NO;
326 [
self setShowsResizeIndicator:_styleMask & CPResizableWindowMask];
330 name:CPWindowResizeStyleGlobalChangeNotification
339 return _platformWindow;
349 var wasVisible = [
self isVisible];
355 _platformWindow = aPlatformWindow;
356 [_platformWindow _setTitle:_title window:self];
359 [
self orderFront:self];
366 + (Class)_windowViewClassForStyleMask:(
unsigned)aStyleMask
369 return _CPHUDWindowView;
372 return _CPBorderlessWindowView;
375 return _CPDocModalWindowView;
377 else if (aStyleMask & _CPModalWindowMask)
378 return _CPModalWindowView;
380 return _CPStandardWindowView;
383 + (Class)_windowViewClassForFullPlatformWindowStyleMask:(
unsigned)aStyleMask
385 return _CPBorderlessBridgeWindowView;
392 if (_positioningScreenRect)
394 var actualScreenRect = [
CPPlatform isBrowser] ? [_platformWindow contentBounds] : [[
self screen] visibleFrame],
395 frame = [
self frame],
396 origin =
frame.origin;
398 if (actualScreenRect)
403 origin.x *= (actualScreenRect.size.width / _positioningScreenRect.size.width);
405 else if (_positioningMask & CPWindowPositionFlexibleLeft)
408 origin.x += actualScreenRect.size.
width - _positioningScreenRect.size.
width;
410 else if (_positioningMask & CPWindowPositionFlexibleRight)
418 origin.y *= (actualScreenRect.size.height / _positioningScreenRect.size.height);
420 else if (_positioningMask & CPWindowPositionFlexibleTop)
423 origin.y += actualScreenRect.size.height - _positioningScreenRect.size.height;
430 [
self setFrameOrigin:origin];
437 if ([
self _hasKeyViewLoop:[_contentView subviews]])
439 var views = [
self _viewsSortedByPosition],
440 count = [views count];
444 for (var i = 1; i < count; ++i)
448 if ([view nextKeyView])
450 [_contentView setNextKeyView:view];
459 [
self _doRecalculateKeyViewLoop];
463 - (void)_setWindowView:(
CPView)aWindowView
465 if (_windowView === aWindowView)
468 var oldWindowView = _windowView;
470 _windowView = aWindowView;
474 [oldWindowView _setWindow:nil];
475 [oldWindowView noteToolbarChanged];
478 CPDOMDisplayServerRemoveChild(_DOMElement, oldWindowView._DOMElement);
485 CPDOMDisplayServerAppendChild(_DOMElement, _windowView._DOMElement);
488 var contentRect = [_contentView convertRect:[_contentView bounds] toView:nil];
490 contentRect.origin = [
self convertBaseToGlobal:contentRect.origin];
492 [_windowView _setWindow:self];
493 [_windowView setNextResponder:self];
494 [_windowView addSubview:_contentView];
495 [_windowView setTitle:_title];
496 [_windowView noteToolbarChanged];
497 [_windowView setShowsResizeIndicator:[
self showsResizeIndicator]];
499 [
self setFrame:[
self frameRectForContentRect:contentRect]];
509 - (void)setFullPlatformWindow:(BOOL)shouldBeFullPlatformWindow
511 if (![_platformWindow supportsFullPlatformWindows])
514 shouldBeFullPlatformWindow = !!shouldBeFullPlatformWindow;
516 if (_isFullPlatformWindow === shouldBeFullPlatformWindow)
519 _isFullPlatformWindow = shouldBeFullPlatformWindow;
521 if (_isFullPlatformWindow)
523 _fullPlatformWindowSession = _CPWindowFullPlatformWindowSessionMake(_windowView, [
self contentRectForFrameRect:[
self frame]], [
self hasShadow], [
self level]);
525 var fullPlatformWindowViewClass = [[
self class] _windowViewClassForFullPlatformWindowStyleMask:_styleMask],
526 windowView = [[fullPlatformWindowViewClass alloc] initWithFrame:CGRectMakeZero() styleMask:_styleMask];
528 [
self _setWindowView:windowView];
530 [
self setLevel:CPBackgroundWindowLevel];
531 [
self setHasShadow:NO];
532 [
self setAutoresizingMask:CPWindowWidthSizable | CPWindowHeightSizable];
533 [
self setFrame:[_platformWindow visibleFrame]];
537 var windowView = _fullPlatformWindowSession.windowView;
539 [
self _setWindowView:windowView];
541 [
self setLevel:_fullPlatformWindowSession.level];
542 [
self setHasShadow:_fullPlatformWindowSession.hasShadow];
543 [
self setAutoresizingMask:CPWindowNotSizable];
545 [
self setFrame:[windowView frameRectForContentRect:_fullPlatformWindowSession.contentRect]];
552 - (BOOL)isFullPlatformWindow
554 return _isFullPlatformWindow;
560 - (unsigned)styleMask
583 + (CGRect)frameRectForContentRect:(CGRect)aContentRect styleMask:(
unsigned)aStyleMask
585 return [[[
self class] _windowViewClassForStyleMask:aStyleMask] frameRectForContentRect:aContentRect];
592 - (CGRect)contentRectForFrameRect:(CGRect)aFrame
594 return [_windowView contentRectForFrameRect:aFrame];
602 - (CGRect)frameRectForContentRect:(CGRect)aContentRect
604 return [_windowView frameRectForContentRect:aContentRect];
612 return CGRectMakeCopy(_frame);
622 - (void)setFrame:(CGRect)aFrame display:(BOOL)shouldDisplay animate:(BOOL)shouldAnimate
624 [
self _setFrame:aFrame display:shouldDisplay animate:shouldAnimate constrainWidth:NO constrainHeight:YES];
627 - (void)_setFrame:(CGRect)aFrame display:(BOOL)shouldDisplay animate:(BOOL)shouldAnimate constrainWidth:(BOOL)shouldConstrainWidth constrainHeight:(BOOL)shouldConstrainHeight
629 var
frame = CGRectMakeCopy(aFrame),
630 value = frame.origin.x,
631 delta = value - FLOOR(value);
634 frame.origin.x = value > 0.879 ? CEIL(value) : FLOOR(value);
636 value = frame.origin.y;
637 delta = value - FLOOR(value);
640 frame.origin.y = value > 0.879 ? CEIL(value) : FLOOR(value);
642 value = frame.size.width;
643 delta = value - FLOOR(value);
646 frame.size.width = value > 0.15 ? CEIL(value) : FLOOR(value);
648 value = frame.size.height;
649 delta = value - FLOOR(value);
652 frame.size.height = value > 0.15 ? CEIL(value) : FLOOR(value);
654 frame = [
self _constrainFrame:frame toUsableScreenWidth:shouldConstrainWidth andHeight:shouldConstrainHeight];
658 [_frameAnimation stopAnimation];
659 _frameAnimation = [[_CPWindowFrameAnimation alloc] initWithWindow:self targetFrame:frame];
661 [_frameAnimation startAnimation];
665 var origin = _frame.origin,
666 newOrigin = frame.origin,
667 originMoved = !CGPointEqualToPoint(origin, newOrigin);
671 delta = CGPointMake(newOrigin.x - origin.x, newOrigin.y - origin.y);
672 origin.x = newOrigin.x;
673 origin.y = newOrigin.y;
676 if (![
self _sharesChromeWithPlatformWindow])
678 CPDOMDisplayServerSetStyleLeftTop(_DOMElement, NULL, origin.x, origin.y);
683 if ([
self attachedSheet])
684 [
self _setAttachedSheetFrameOrigin];
689 var size = _frame.size,
690 newSize = frame.size;
692 if (!CGSizeEqualToSize(size, newSize))
694 size.width = newSize.width;
695 size.height = newSize.height;
697 [_windowView setFrameSize:size];
700 [_shadowView setNeedsLayout];
706 if ([
self _sharesChromeWithPlatformWindow])
707 [_platformWindow setContentRect:_frame];
710 [
self _moveChildWindows:delta];
718 - (CGRect)_constrainFrame:(CGRect)aFrame toUsableScreenWidth:(BOOL)constrainWidth andHeight:(BOOL)constrainHeight
720 var frame = CGRectMakeCopy(aFrame);
722 if (!_constrainsToUsableScreen || !_isVisible)
725 var usableRect = [_platformWindow usableContentFrame];
730 frame.origin.x = MAX(frame.origin.x, usableRect.origin.x);
733 var maxX = MIN(CGRectGetMaxX(frame), CGRectGetMaxX(usableRect));
734 frame.origin.x = maxX - frame.size.
width;
737 var usableWidth = CGRectGetWidth(usableRect);
739 if (CGRectGetWidth(frame) > usableWidth)
741 frame.origin.x = CGRectGetMinX(usableRect);
742 frame.size.width = MAX(usableWidth, _minSize.width);
749 frame.origin.y = MAX(frame.origin.y, usableRect.origin.y);
752 var maxY = MIN(CGRectGetMaxY(frame), CGRectGetMaxY(usableRect));
753 frame.origin.y = maxY - frame.size.height;
756 var usableHeight = CGRectGetHeight(usableRect);
758 if (CGRectGetHeight(frame) > usableHeight)
760 frame.origin.y = CGRectGetMinY(usableRect);
761 frame.size.height = MAX(usableHeight, _minSize.height);
775 - (CGRect)_constrainOriginOfFrame:(CGRect)aFrame
777 var frame = CGRectMakeCopy(aFrame);
779 if (!_constrainsToUsableScreen || !_isVisible)
782 var usableRect = [_platformWindow usableContentFrame],
783 minimumSize = [_windowView _minimumResizeSize];
786 frame.origin.x = MAX(frame.origin.x, CGRectGetMinX(usableRect) + minimumSize.width - CGRectGetWidth(frame));
789 frame.origin.x = MIN(frame.origin.x, CGRectGetMaxX(usableRect) - minimumSize.width);
792 frame.origin.y = MAX(frame.origin.y, CGRectGetMinY(usableRect));
795 frame.origin.y = MIN(frame.origin.y, CGRectGetMaxY(usableRect) - CGRectGetMinY([_contentView frame]) - CPWindowMinVisibleVerticalMargin);
800 - (void)_moveChildWindows:(CGPoint)delta
802 [_childWindows enumerateObjectsUsingBlock:function(childWindow)
804 var origin = [childWindow frame].origin;
806 [childWindow setFrameOrigin:CGPointMake(origin.x + delta.x, origin.y + delta.y)];
816 - (void)setFrame:(CGRect)aFrame display:(BOOL)shouldDisplay
818 [
self setFrame:aFrame display:shouldDisplay animate:NO];
825 - (void)setFrame:(CGRect)aFrame
827 [
self setFrame:aFrame display:YES animate:NO];
834 - (void)setFrameOrigin:(CGPoint)anOrigin
836 var frame = [
self _constrainOriginOfFrame:CGRectMake(anOrigin.x, anOrigin.y, _frame.size.width, _frame.size.height)];
837 [
self _setFrame:frame display:YES animate:NO constrainWidth:NO constrainHeight:NO];
844 - (void)setFrameSize:(CGSize)aSize
846 [
self setFrame:CGRectMake(CGRectGetMinX(_frame), CGRectGetMinY(_frame), aSize.width, aSize.height) display:YES animate:NO];
853 - (void)orderFront:(
id)aSender
855 [
self orderWindow:CPWindowAbove relativeTo:0];
863 [_parentView orderFront:self];
866 [
self _setFrame:_frame display:YES animate:NO constrainWidth:YES constrainHeight:YES];
868 [_platformWindow orderFront:self];
869 [_platformWindow order:CPWindowAbove window:self relativeTo:nil];
872 if (!
CPApp._keyWindow)
873 [
self makeKeyWindow];
875 if ([
self isKeyWindow] && (_firstResponder ===
self || !_firstResponder))
876 [
self makeFirstResponder:_initialFirstResponder];
878 if (!
CPApp._mainWindow)
879 [
self makeMainWindow];
886 - (void)_parentDidOrderInChild
895 - (void)orderBack:(
id)aSender
897 [
self orderWindow:CPWindowBelow relativeTo:0];
909 - (void)orderOut:(
id)aSender
911 [
self orderWindow:CPWindowOut relativeTo:0];
914 - (void)_orderOutRecursively:(BOOL)recursive
922 [
self._parentView _detachSheetWindow];
927 [_childWindows makeObjectsPerformSelector:@selector(_orderOutRecursively:) withObject:recursive];
930 if ([
self _sharesChromeWithPlatformWindow])
931 [_platformWindow orderOut:self];
933 [_platformWindow order:CPWindowOut window:self relativeTo:nil];
936 [
self _updateMainAndKeyWindows];
944 - (void)orderWindow:(CPWindowOrderingMode)orderingMode relativeTo:(
int)otherWindowNumber
949 [_parentWindow removeChildWindow:self];
952 [
self _orderOutRecursively:!_parentWindow];
954 else if (orderingMode ===
CPWindowAbove && otherWindowNumber === 0)
956 else if (orderingMode ===
CPWindowBelow && otherWindowNumber === 0)
960 [_platformWindow order:orderingMode window:self relativeTo:CPApp._windows[otherWindowNumber]];
968 - (void)setLevel:(
int)aLevel
970 if (aLevel === _level)
973 [_platformWindow moveWindow:self fromLevel:_level toLevel:aLevel];
976 [_childWindows makeObjectsPerformSelector:@selector(setLevel:) withObject:_level];
978 if ([
self _sharesChromeWithPlatformWindow])
979 [_platformWindow setLevel:aLevel];
1003 + (void)setGlobalResizeStyle:(
int)aStyle
1016 + (void)setConstrainWindowsToUsableScreen:(BOOL)shouldConstrain
1024 + (BOOL)constrainWindowsToUsableScreen
1029 - (void)_didReceiveResizeStyleChange:(
CPNotification)aNotification
1031 [_windowView setShowsResizeIndicator:_styleMask & CPResizableWindowMask];
1037 + (int)globalResizeStyle
1045 - (BOOL)showsResizeIndicator
1047 return _showsResizeIndicator;
1054 - (void)setShowsResizeIndicator:(BOOL)shouldShowResizeIndicator
1056 shouldShowResizeIndicator = !!shouldShowResizeIndicator;
1058 if (_showsResizeIndicator === shouldShowResizeIndicator)
1061 _showsResizeIndicator = shouldShowResizeIndicator;
1062 [_windowView setShowsResizeIndicator:[
self showsResizeIndicator]];
1068 - (CGSize)resizeIndicatorOffset
1070 return [_windowView resizeIndicatorOffset];
1077 - (void)setResizeIndicatorOffset:(CGSize)anOffset
1079 [_windowView setResizeIndicatorOffset:anOffset];
1087 - (void)setContentView:(
CPView)aView
1090 [_contentView removeFromSuperview];
1092 var bounds = CGRectMake(0.0, 0.0, CGRectGetWidth(_frame), CGRectGetHeight(_frame));
1094 _contentView = aView;
1095 [_contentView setFrame:[
self contentRectForFrameRect:bounds]];
1097 [_contentView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
1098 [_windowView addSubview:_contentView];
1104 if (_initialFirstResponder && _initialFirstResponder !==
self)
1105 _initialFirstResponder =
self;
1113 return _contentView;
1120 - (void)setAlphaValue:(
float)aValue
1122 [_windowView setAlphaValue:aValue];
1130 return [_windowView alphaValue];
1137 - (void)setBackgroundColor:(
CPColor)aColor
1139 [_windowView setBackgroundColor:aColor];
1147 return [_windowView backgroundColor];
1157 - (void)setMinSize:(CGSize)aSize
1159 if (CGSizeEqualToSize(_minSize, aSize))
1162 _minSize = [
self _calculateMinSizeForProposedSize:aSize];
1164 var size = CGSizeMakeCopy([
self frame].size),
1165 needsFrameChange = NO;
1167 if (size.width < _minSize.width)
1169 size.width = _minSize.width;
1170 needsFrameChange = YES;
1173 if (size.height < _minSize.height)
1175 size.height = _minSize.height;
1176 needsFrameChange = YES;
1179 if (needsFrameChange)
1180 [
self setFrameSize:size];
1192 - (CGSize)_calculateMinSizeForProposedSize:(CGSize)proposedSize
1194 var contentFrame = [
self contentRectForFrameRect:_frame],
1195 minHeight = CGRectGetHeight(_frame) - CGRectGetHeight(contentFrame);
1197 return CGSizeMake(MAX(proposedSize.width, 0), MAX(proposedSize.height, minHeight));
1206 - (void)setMaxSize:(CGSize)aSize
1208 if (CGSizeEqualToSize(_maxSize, aSize))
1211 _maxSize = CGSizeMakeCopy(aSize);
1213 var size = CGSizeMakeCopy([
self frame].size),
1214 needsFrameChange = NO;
1216 if (size.width > _maxSize.width)
1218 size.width = _maxSize.width;
1219 needsFrameChange = YES;
1222 if (size.height > _maxSize.height)
1224 size.height = _maxSize.height;
1225 needsFrameChange = YES;
1228 if (needsFrameChange)
1229 [
self setFrameSize:size];
1248 - (void)_updateShadow
1250 if ([
self _sharesChromeWithPlatformWindow])
1255 CPDOMDisplayServerRemoveChild(_DOMElement, _shadowView._DOMElement);
1260 [_platformWindow setHasShadow:_hasShadow];
1265 if (_hasShadow && !_shadowView)
1267 _shadowView = [[_CPShadowWindowView alloc] initWithFrame:CGRectMakeZero()];
1269 [_shadowView setWindowView:_windowView];
1270 [_shadowView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
1271 [_shadowView setNeedsLayout];
1274 CPDOMDisplayServerInsertBefore(_DOMElement, _shadowView._DOMElement, _windowView._DOMElement);
1277 else if (!_hasShadow && _shadowView)
1280 CPDOMDisplayServerRemoveChild(_DOMElement, _shadowView._DOMElement);
1290 - (void)setHasShadow:(BOOL)shouldHaveShadow
1292 if (_hasShadow === shouldHaveShadow)
1295 _hasShadow = shouldHaveShadow;
1297 [
self _updateShadow];
1311 - (void)setShadowStyle:(
unsigned)aStyle
1313 _shadowStyle = aStyle;
1315 [[
self platformWindow] setShadowStyle:_shadowStyle];
1322 - (void)setDelegate:(
id)aDelegate
1326 [defaultCenter removeObserver:_delegate name:CPWindowDidResignKeyNotification object:self];
1327 [defaultCenter removeObserver:_delegate name:CPWindowDidBecomeKeyNotification object:self];
1328 [defaultCenter removeObserver:_delegate name:CPWindowDidBecomeMainNotification object:self];
1329 [defaultCenter removeObserver:_delegate name:CPWindowDidResignMainNotification object:self];
1330 [defaultCenter removeObserver:_delegate name:CPWindowDidMoveNotification object:self];
1331 [defaultCenter removeObserver:_delegate name:CPWindowDidResizeNotification object:self];
1332 [defaultCenter removeObserver:_delegate name:CPWindowWillBeginSheetNotification object:self];
1333 [defaultCenter removeObserver:_delegate name:CPWindowDidEndSheetNotification object:self];
1335 _delegate = aDelegate;
1336 _delegateRespondsToWindowWillReturnUndoManagerSelector = [_delegate respondsToSelector:@selector(windowWillReturnUndoManager:)];
1338 if ([_delegate respondsToSelector:
@selector(windowDidResignKey:)])
1340 addObserver:_delegate
1341 selector:@selector(windowDidResignKey:)
1342 name:CPWindowDidResignKeyNotification
1345 if ([_delegate respondsToSelector:
@selector(windowDidBecomeKey:)])
1347 addObserver:_delegate
1348 selector:@selector(windowDidBecomeKey:)
1349 name:CPWindowDidBecomeKeyNotification
1352 if ([_delegate respondsToSelector:
@selector(windowDidBecomeMain:)])
1354 addObserver:_delegate
1355 selector:@selector(windowDidBecomeMain:)
1356 name:CPWindowDidBecomeMainNotification
1359 if ([_delegate respondsToSelector:
@selector(windowDidResignMain:)])
1361 addObserver:_delegate
1362 selector:@selector(windowDidResignMain:)
1363 name:CPWindowDidResignMainNotification
1366 if ([_delegate respondsToSelector:
@selector(windowDidMove:)])
1368 addObserver:_delegate
1369 selector:@selector(windowDidMove:)
1370 name:CPWindowDidMoveNotification
1373 if ([_delegate respondsToSelector:
@selector(windowDidResize:)])
1375 addObserver:_delegate
1376 selector:@selector(windowDidResize:)
1377 name:CPWindowDidResizeNotification
1380 if ([_delegate respondsToSelector:
@selector(windowWillBeginSheet:)])
1382 addObserver:_delegate
1383 selector:@selector(windowWillBeginSheet:)
1384 name:CPWindowWillBeginSheetNotification
1387 if ([_delegate respondsToSelector:
@selector(windowDidEndSheet:)])
1389 addObserver:_delegate
1390 selector:@selector(windowDidEndSheet:)
1391 name:CPWindowDidEndSheetNotification
1409 _windowController = aWindowController;
1417 return _windowController;
1420 - (void)doCommandBySelector:(
SEL)aSelector
1422 if ([_delegate respondsToSelector:aSelector])
1423 [_delegate performSelector:aSelector];
1425 [
super doCommandBySelector:aSelector];
1428 - (BOOL)acceptsFirstResponder
1433 - (
CPView)initialFirstResponder
1435 return _initialFirstResponder;
1438 - (void)setInitialFirstResponder:(
CPView)aView
1440 _initialFirstResponder = aView;
1443 - (void)_setupFirstResponder
1448 if (!_hasBecomeKeyWindow)
1450 if (_firstResponder ===
self)
1452 if (_initialFirstResponder)
1453 [
self makeFirstResponder:_initialFirstResponder];
1457 var view = [_contentView nextValidKeyView];
1460 [
self makeFirstResponder:view];
1467 if (_firstResponder)
1468 [
self makeFirstResponder:_firstResponder];
1478 - (BOOL)makeFirstResponder:(
CPResponder)aResponder
1480 if (_firstResponder === aResponder)
1483 if (![_firstResponder resignFirstResponder])
1486 if (!aResponder || ![aResponder acceptsFirstResponder] || ![aResponder becomeFirstResponder])
1488 _firstResponder =
self;
1493 _firstResponder = aResponder;
1505 return _firstResponder;
1508 - (BOOL)acceptsMouseMovedEvents
1510 return _acceptsMouseMovedEvents;
1513 - (void)setAcceptsMouseMovedEvents:(BOOL)shouldAcceptMouseMovedEvents
1515 _acceptsMouseMovedEvents = shouldAcceptMouseMovedEvents;
1518 - (BOOL)ignoresMouseEvents
1520 return _ignoresMouseEvents;
1523 - (void)setIgnoresMouseEvents:(BOOL)shouldIgnoreMouseEvents
1525 _ignoresMouseEvents = shouldIgnoreMouseEvents;
1528 - (void)_mouseExitedResizeRect
1550 [_windowView setTitle:aTitle];
1551 [_platformWindow _setTitle:_title window:self];
1557 - (void)setTitleWithRepresentedFilename:(
CPString)aFilePath
1559 [
self setRepresentedFilename:aFilePath];
1560 [
self setTitle:[aFilePath lastPathComponent]];
1566 - (void)setRepresentedFilename:(
CPString)aFilePath
1577 return [_representedURL absoluteString];
1583 - (void)setRepresentedURL:(
CPURL)aURL
1585 _representedURL = aURL;
1591 - (
CPURL)representedURL
1593 return _representedURL;
1607 - (void)setMovableByWindowBackground:(BOOL)shouldBeMovableByWindowBackground
1609 _isMovableByWindowBackground = shouldBeMovableByWindowBackground;
1615 - (BOOL)isMovableByWindowBackground
1617 return _isMovableByWindowBackground;
1624 - (void)setMovable:(BOOL)shouldBeMovable
1626 _isMovable = shouldBeMovable;
1642 if (_isFullPlatformWindow)
1645 var size = [
self frame].size,
1646 containerSize = [
CPPlatform isBrowser] ? [_platformWindow contentBounds].size : [[
self screen] visibleFrame].size;
1648 var origin = CGPointMake((containerSize.width - size.width) / 2.0, (containerSize.height - size.height) / 2.0);
1656 [
self setFrameOrigin:origin];
1663 - (void)sendEvent:(
CPEvent)anEvent
1665 var type = [anEvent type],
1666 sheet = [
self attachedSheet];
1683 [_windowView mouseDown:anEvent];
1687 [sheet makeKeyAndOrderFront:self];
1701 var point = [anEvent locationInWindow];
1706 return [[
self firstResponder] flagsChanged:anEvent];
1709 return [[
self firstResponder] keyUp:anEvent];
1715 [
self selectPreviousKeyView:self];
1717 [
self selectNextKeyView:self];
1722 [[[anEvent window] platformWindow] _propagateCurrentDOMEvent:NO]
1728 var didTabBack = [
self selectPreviousKeyView:self];
1736 [[[anEvent window] platformWindow] _propagateCurrentDOMEvent:NO]
1743 [[
self firstResponder] keyDown:anEvent];
1747 if (![
self disableKeyEquivalentForDefaultButton])
1749 var defaultButton = [
self defaultButton],
1750 keyEquivalent = [defaultButton keyEquivalent],
1751 modifierMask = [defaultButton keyEquivalentModifierMask];
1753 if ([anEvent _triggersKeyEquivalent:keyEquivalent withModifierMask:modifierMask])
1754 [[
self defaultButton] performClick:self];
1760 return [[_windowView hitTest:point] scrollWheel:anEvent];
1764 var hitTestedView = _leftMouseDownView,
1765 selector = type ==
CPRightMouseUp ?
@selector(rightMouseUp:) :
@selector(mouseUp:);
1768 hitTestedView = [_windowView hitTest:point];
1770 [hitTestedView performSelector:selector withObject:anEvent];
1772 _leftMouseDownView = nil;
1779 _leftMouseDownView = [_windowView hitTest:point];
1781 if (_leftMouseDownView !== _firstResponder && [_leftMouseDownView acceptsFirstResponder])
1782 [
self makeFirstResponder:_leftMouseDownView];
1784 [CPApp activateIgnoringOtherApps:YES];
1786 var theWindow = [anEvent window],
1787 selector = type ==
CPRightMouseDown ?
@selector(rightMouseDown:) :
@selector(mouseDown:);
1789 if ([theWindow isKeyWindow] || ([theWindow becomesKeyOnlyIfNeeded] && ![_leftMouseDownView needsPanelToBecomeKey]))
1790 return [_leftMouseDownView performSelector:selector withObject:anEvent];
1794 [
self makeKeyAndOrderFront:self];
1796 if ([_leftMouseDownView acceptsFirstMouse:anEvent])
1797 return [_leftMouseDownView performSelector:selector withObject:anEvent];
1803 if (!_leftMouseDownView)
1804 return [[_windowView hitTest:point] mouseDragged:anEvent];
1810 selector =
@selector(rightMouseDragged:)
1811 if (![_leftMouseDownView respondsToSelector:selector])
1816 selector =
@selector(mouseDragged:)
1818 return [_leftMouseDownView performSelector:selector withObject:anEvent];
1821 [_windowView setCursorForLocation:point resizing:NO];
1824 if (!_acceptsMouseMovedEvents || sheet)
1827 if (!_mouseEnteredStack)
1828 _mouseEnteredStack = [];
1830 var hitTestView = [_windowView hitTest:point];
1832 if ([_mouseEnteredStack count] && [_mouseEnteredStack lastObject] === hitTestView)
1833 return [hitTestView mouseMoved:anEvent];
1835 var view = hitTestView,
1836 mouseEnteredStack = [];
1840 mouseEnteredStack.unshift(view);
1842 view = [view superview];
1845 var deviation = MIN(_mouseEnteredStack.length, mouseEnteredStack.length);
1848 if (_mouseEnteredStack[deviation] === mouseEnteredStack[deviation])
1851 var index = deviation + 1,
1852 count = _mouseEnteredStack.length;
1856 var
event = [
CPEvent mouseEventWithType:CPMouseExited location:point modifierFlags:[anEvent modifierFlags] timestamp:[anEvent timestamp] windowNumber:_windowNumber context:nil eventNumber:-1 clickCount:1 pressure:0];
1858 for (; index < count; ++index)
1859 [_mouseEnteredStack[index] mouseExited:event];
1862 index = deviation + 1;
1863 count = mouseEnteredStack.length;
1867 var
event = [
CPEvent mouseEventWithType:CPMouseEntered location:point modifierFlags:[anEvent modifierFlags] timestamp:[anEvent timestamp] windowNumber:_windowNumber context:nil eventNumber:-1 clickCount:1 pressure:0];
1869 for (; index < count; ++index)
1870 [mouseEnteredStack[index] mouseEntered:event];
1873 _mouseEnteredStack = mouseEnteredStack;
1875 [hitTestView mouseMoved:anEvent];
1884 return _windowNumber;
1892 - (void)becomeKeyWindow
1894 CPApp._keyWindow =
self;
1896 if (_firstResponder !==
self && [_firstResponder respondsToSelector:
@selector(becomeKeyWindow)])
1897 [_firstResponder becomeKeyWindow];
1899 if (!_hasBecomeKeyWindow)
1903 if (![
self _hasKeyViewLoop:[_contentView subviews]])
1904 [
self recalculateKeyViewLoop];
1907 [
self _setupFirstResponder];
1908 _hasBecomeKeyWindow = YES;
1910 [_windowView noteKeyWindowStateChanged];
1921 - (BOOL)canBecomeKeyWindow
1940 return [CPApp keyWindow] ==
self;
1947 - (void)makeKeyAndOrderFront:(
id)aSender
1949 [
self orderFront:self];
1951 [
self makeKeyWindow];
1952 [
self makeMainWindow];
1958 - (void)makeKeyWindow
1960 if ([
CPApp keyWindow] ===
self || ![
self canBecomeKeyWindow])
1963 [[CPApp keyWindow] resignKeyWindow];
1964 [
self becomeKeyWindow];
1970 - (void)resignKeyWindow
1972 if (_firstResponder !==
self && [_firstResponder respondsToSelector:
@selector(resignKeyWindow)])
1973 [_firstResponder resignKeyWindow];
1975 if (
CPApp._keyWindow ===
self)
1976 CPApp._keyWindow = nil;
1978 [_windowView noteKeyWindowStateChanged];
1995 - (void)dragImage:(
CPImage)anImage at:(CGPoint)imageLocation offset:(CGSize)mouseOffset event:(
CPEvent)anEvent pasteboard:(
CPPasteboard)aPasteboard source:(
id)aSourceObject slideBack:(BOOL)slideBack
1997 [[
CPDragServer sharedDragServer] dragImage:anImage fromWindow:self at:[
self convertBaseToGlobal:imageLocation] offset:mouseOffset event:anEvent pasteboard:aPasteboard source:aSourceObject slideBack:slideBack];
2000 - (void)_noteRegisteredDraggedTypes:(CPSet)pasteboardTypes
2002 if (!pasteboardTypes)
2005 if (!_inclusiveRegisteredDraggedTypes)
2008 [_inclusiveRegisteredDraggedTypes unionSet:pasteboardTypes];
2011 - (void)_noteUnregisteredDraggedTypes:(CPSet)pasteboardTypes
2013 if (!pasteboardTypes)
2016 [_inclusiveRegisteredDraggedTypes minusSet:pasteboardTypes];
2018 if ([_inclusiveRegisteredDraggedTypes count] === 0)
2019 _inclusiveRegisteredDraggedTypes = nil;
2032 - (void)dragView:(
CPView)aView at:(CGPoint)viewLocation offset:(CGSize)mouseOffset event:(
CPEvent)anEvent pasteboard:(
CPPasteboard)aPasteboard source:(
id)aSourceObject slideBack:(BOOL)slideBack
2034 [[
CPDragServer sharedDragServer] dragView:aView fromWindow:self at:[
self convertBaseToGlobal:viewLocation] offset:mouseOffset event:anEvent pasteboard:aPasteboard source:aSourceObject slideBack:slideBack];
2041 - (void)registerForDraggedTypes:(CPArray)pasteboardTypes
2043 if (!pasteboardTypes)
2046 [
self _noteUnregisteredDraggedTypes:_registeredDraggedTypes];
2047 [_registeredDraggedTypes addObjectsFromArray:pasteboardTypes];
2048 [
self _noteRegisteredDraggedTypes:_registeredDraggedTypes];
2050 _registeredDraggedTypesArray = nil;
2057 - (CPArray)registeredDraggedTypes
2059 if (!_registeredDraggedTypesArray)
2060 _registeredDraggedTypesArray = [_registeredDraggedTypes allObjects];
2062 return _registeredDraggedTypesArray;
2068 - (void)unregisterDraggedTypes
2070 [
self _noteUnregisteredDraggedTypes:_registeredDraggedTypes];
2072 _registeredDraggedTypes = [CPSet set];
2073 _registeredDraggedTypesArray = [];
2082 - (void)setDocumentEdited:(BOOL)isDocumentEdited
2084 if (_isDocumentEdited == isDocumentEdited)
2087 _isDocumentEdited = isDocumentEdited;
2089 [
CPMenu _setMenuBarIconImageAlphaValue:_isDocumentEdited ? 0.5 : 1.0];
2091 [_windowView setDocumentEdited:isDocumentEdited];
2097 - (BOOL)isDocumentEdited
2099 return _isDocumentEdited;
2102 - (void)setDocumentSaving:(BOOL)isDocumentSaving
2104 if (_isDocumentSaving == isDocumentSaving)
2107 _isDocumentSaving = isDocumentSaving;
2109 [
self _synchronizeSaveMenuWithDocumentSaving];
2111 [_windowView windowDidChangeDocumentSaving];
2114 - (BOOL)isDocumentSaving
2116 return _isDocumentSaving;
2120 - (void)_synchronizeSaveMenuWithDocumentSaving
2122 if (![
self isMainWindow])
2125 var mainMenu = [CPApp mainMenu],
2126 index = [mainMenu indexOfItemWithTitle:_isDocumentSaving ? @"Save" : @"Saving..."];
2131 var item = [mainMenu itemAtIndex:index];
2133 if (_isDocumentSaving)
2135 CPWindowSaveImage = [item image];
2137 [item setTitle:@"Saving..."];
2138 [item setImage:[[
CPTheme defaultTheme] valueForAttributeWithName:@"spinning-regular-gif" forClass:CPProgressIndicator]];
2139 [item setEnabled:NO];
2143 [item setTitle:@"Save"];
2144 [item setImage:CPWindowSaveImage];
2145 [item setEnabled:YES];
2155 - (void)performMiniaturize:(
id)aSender
2158 [
self miniaturize:aSender];
2165 - (void)miniaturize:(
id)sender
2169 [[
self platformWindow] miniaturize:sender];
2171 [
self _updateMainAndKeyWindows];
2175 _isMiniaturized = YES;
2181 - (void)deminiaturize:(
id)sender
2183 [[
self platformWindow] deminiaturize:sender];
2187 _isMiniaturized = NO;
2193 - (void)isMiniaturized
2195 return _isMiniaturized;
2204 - (void)performClose:(
id)aSender
2209 if ([
self isFullPlatformWindow])
2211 var
event = [CPApp currentEvent];
2215 [[
self platformWindow] _propagateCurrentDOMEvent:YES];
2222 if ([_delegate respondsToSelector:
@selector(windowShouldClose:)])
2224 if (![_delegate windowShouldClose:
self])
2227 else if ([
self respondsToSelector:
@selector(windowShouldClose:)])
2229 if (![
self windowShouldClose:
self])
2233 var documents = [_windowController documents];
2235 if ([documents count])
2237 var index = [documents indexOfObject:[_windowController document]];
2239 [documents[index] shouldCloseWindowController:_windowController
2241 shouldCloseSelector:@selector(_windowControllerContainingDocument:shouldClose:contextInfo:)
2242 contextInfo:{documents:[documents copy], visited:0, index:index}];
2248 - (void)_windowControllerContainingDocument:(
CPDocument)document shouldClose:(BOOL)shouldClose contextInfo:(Object)context
2252 var windowController = [
self windowController],
2253 documents = context.documents,
2254 count = [documents count],
2255 visited = ++context.visited,
2256 index = ++context.index % count;
2258 [document removeWindowController:windowController];
2260 if (visited < count)
2262 [windowController setDocument:documents[index]];
2264 [documents[index] shouldCloseWindowController:_windowController
2266 shouldCloseSelector:@selector(_windowControllerContainingDocument:shouldClose:contextInfo:)
2267 contextInfo:context];
2280 if ([_delegate respondsToSelector:
@selector(windowWillClose:)])
2281 [_delegate windowWillClose:
self];
2285 [_parentWindow removeChildWindow:self];
2286 [
self _orderOutRecursively:NO];
2287 [
self _detachFromChildrenClosing:!_parentWindow];
2290 - (void)_detachFromChildrenClosing:(BOOL)shouldCloseChildren
2293 [_childWindows enumerateObjectsUsingBlock:function(child)
2295 [child setParentWindow:nil];
2299 if (shouldCloseChildren)
2301 [_childWindows enumerateObjectsUsingBlock:function(child)
2305 [child _orderOutRecursively:NO];
2306 [child _detachFromChildrenClosing:![child parentWindow]];
2318 - (BOOL)isMainWindow
2320 return [CPApp mainWindow] ===
self;
2326 - (BOOL)canBecomeMainWindow
2333 return ([
self isVisible] && ((_styleMask &
CPTitledWindowMask) || _isFullPlatformWindow));
2339 - (void)makeMainWindow
2344 [_parentView makeMainWindow];
2348 if ([
CPApp mainWindow] ===
self || ![
self canBecomeMainWindow])
2351 [[CPApp mainWindow] resignMainWindow];
2352 [
self becomeMainWindow];
2358 - (void)becomeMainWindow
2360 CPApp._mainWindow =
self;
2362 [
self _synchronizeSaveMenuWithDocumentSaving];
2364 [_windowView noteMainWindowStateChanged];
2374 - (void)resignMainWindow
2380 if (
CPApp._mainWindow ===
self)
2381 CPApp._mainWindow = nil;
2383 [_windowView noteMainWindowStateChanged];
2386 - (void)_updateMainAndKeyWindows
2388 var allWindows = [CPApp orderedWindows],
2389 windowCount = [allWindows count];
2391 if ([
self isKeyWindow])
2393 var keyWindow = [CPApp keyWindow];
2394 [
self resignKeyWindow];
2396 if (keyWindow && keyWindow !==
self && [keyWindow canBecomeKeyWindow])
2397 [keyWindow makeKeyWindow];
2400 var mainMenu = [CPApp mainMenu],
2401 menuBarClass = objj_getClass(
"_CPMenuBarWindow"),
2404 for (var i = 0; i < windowCount; i++)
2406 var currentWindow = allWindows[i];
2408 if ([currentWindow isKindOfClass:menuBarClass])
2409 menuWindow = currentWindow;
2411 if (currentWindow ===
self || currentWindow === menuWindow)
2414 if ([currentWindow isVisible] && [currentWindow canBecomeKeyWindow])
2416 [currentWindow makeKeyWindow];
2421 if (![
CPApp keyWindow])
2422 [menuWindow makeKeyWindow];
2426 if ([
self isMainWindow])
2428 var mainWindow = [CPApp mainWindow];
2429 [
self resignMainWindow];
2431 if (mainWindow && mainWindow !==
self && [mainWindow canBecomeMainWindow])
2432 [mainWindow makeMainWindow];
2435 var mainMenu = [CPApp mainMenu],
2436 menuBarClass = objj_getClass(
"_CPMenuBarWindow"),
2439 for (var i = 0; i < windowCount; i++)
2441 var currentWindow = allWindows[i];
2443 if ([currentWindow isKindOfClass:menuBarClass])
2444 menuWindow = currentWindow;
2446 if (currentWindow ===
self || currentWindow === menuWindow)
2449 if ([currentWindow isVisible] && [currentWindow canBecomeMainWindow])
2451 [currentWindow makeMainWindow];
2474 if (_toolbar === aToolbar)
2478 [[aToolbar _window] setToolbar:nil];
2481 [_toolbar _setWindow:nil];
2483 _toolbar = aToolbar;
2486 [_toolbar _setWindow:self];
2488 [
self _noteToolbarChanged];
2491 - (void)toggleToolbarShown:(
id)aSender
2493 var toolbar = [
self toolbar];
2495 [toolbar setVisible:![toolbar isVisible]];
2498 - (void)_noteToolbarChanged
2500 var frame = CGRectMakeCopy([
self frame]),
2503 [_windowView noteToolbarChanged];
2505 if (_isFullPlatformWindow)
2506 newFrame = [_platformWindow visibleFrame];
2509 newFrame = CGRectMakeCopy([
self frame]);
2511 newFrame.origin = frame.origin;
2514 [
self setFrame:newFrame];
2526 - (CPArray)childWindows
2528 return _childWindows;
2531 - (void)addChildWindow:(
CPWindow)childWindow ordered:(CPWindowOrderingMode)orderingMode
2534 if ([_childWindows indexOfObject:childWindow] >= 0)
2538 [_childWindows addObject:childWindow];
2541 reason:_cmd + @" unrecognized ordering mode " + orderingMode];
2543 [childWindow setParentWindow:self];
2544 [childWindow _setChildOrdering:orderingMode];
2545 [childWindow setLevel:[
self level]];
2547 if ([
self isVisible] && ![childWindow isVisible])
2548 [childWindow orderWindow:orderingMode relativeTo:_windowNumber];
2551 - (void)removeChildWindow:(
CPWindow)childWindow
2553 var index = [_childWindows indexOfObject:childWindow];
2558 [_childWindows removeObjectAtIndex:index];
2559 [childWindow setParentWindow:nil];
2564 return _parentWindow;
2572 - (BOOL)_hasAncestorWindow:(
CPWindow)anAncestor
2574 if (!_parentWindow || !anAncestor)
2577 if (anAncestor === _parentWindow)
2580 return [_parentWindow _hasAncestorWindow:anAncestor];
2585 _parentWindow = parentWindow;
2588 - (void)_setFrame:(CGRect)aFrame delegate:(
id)delegate duration:(
int)duration curve:(CPAnimationCurve)curve
2590 [_frameAnimation stopAnimation];
2591 _frameAnimation = [[_CPWindowFrameAnimation alloc] initWithWindow:self targetFrame:aFrame];
2592 [_frameAnimation setDelegate:delegate];
2593 [_frameAnimation setAnimationCurve:curve];
2594 [_frameAnimation setDuration:duration];
2595 [_frameAnimation startAnimation];
2598 - (CPTimeInterval)animationResizeTime:(CGRect)newWindowFrame
2600 return CPWindowResizeTime;
2603 - (void)_setAttachedSheetFrameOrigin
2606 var attachedSheet = [
self attachedSheet],
2607 contentRect = [_contentView frame],
2608 sheetFrame = CGRectMakeCopy([attachedSheet frame]);
2610 sheetFrame.origin.y = CGRectGetMinY(_frame) + CGRectGetMinY(contentRect);
2611 sheetFrame.origin.x = CGRectGetMinX(_frame) + FLOOR((CGRectGetWidth(_frame) - CGRectGetWidth(sheetFrame)) / 2.0);
2613 [attachedSheet setFrame:sheetFrame display:YES animate:NO];
2619 - (void)_attachSheet:(
CPWindow)aSheet modalDelegate:(
id)aModalDelegate
2620 didEndSelector:(
SEL)didEndSelector contextInfo:(
id)contextInfo
2625 reason:@"The target window of beginSheet: already has a sheet, did you forget orderOut: ?"];
2631 "modalDelegate": aModalDelegate,
2632 "endSelector": didEndSelector,
2633 "contextInfo": contextInfo,
2637 "savedConstrains": aSheet._constrainsToUsableScreen
2641 aSheet._constrainsToUsableScreen = NO;
2657 var delegate = _sheetContext["modalDelegate"],
2658 endSelector = _sheetContext["endSelector"];
2662 if (delegate && endSelector)
2664 if (_sheetContext[
"isAttached"])
2665 objj_msgSend(delegate, endSelector, _sheetContext[
"sheet"], _sheetContext[
"returnCode"],
2666 _sheetContext[
"contextInfo"]);
2668 _sheetContext["deferDidEndSelector"] = YES;
2676 - (void)_detachSheetWindow
2678 _sheetContext["isAttached"] = NO;
2692 - (void)_cleanupSheetWindow
2694 var sheet = _sheetContext["sheet"],
2695 deferDidEnd = _sheetContext["deferDidEndSelector"];
2701 [
self _removeClipForSheet:sheet];
2704 sheet._isSheet = NO;
2705 [sheet._windowView _enableSheet:NO inWindow:self];
2706 sheet._constrainsToUsableScreen = _sheetContext["savedConstrains"];
2709 [sheet orderOut:self];
2715 var delegate = _sheetContext["modalDelegate"],
2716 selector = _sheetContext["endSelector"],
2717 returnCode = _sheetContext["returnCode"],
2718 contextInfo = _sheetContext["contextInfo"];
2721 _sheetContext = nil;
2722 sheet._parentView = nil;
2724 objj_msgSend(delegate, selector, sheet, returnCode, contextInfo);
2728 _sheetContext = nil;
2729 sheet._parentView = nil;
2734 - (void)animationDidEnd:(
id)anim
2736 var sheet = _sheetContext["sheet"];
2738 if (anim._window != sheet)
2748 - (void)_sheetShouldAnimateIn:(
CPTimer)timer
2751 if (_sheetContext[
"isOpening"] || _sheetContext[
"isClosing"])
2754 var sheet = _sheetContext["sheet"];
2755 sheet._isSheet = YES;
2756 sheet._parentView =
self;
2762 sheet._isModal = NO;
2764 if ([
CPApp modalWindow] ===
self)
2766 [CPApp runModalForWindow:sheet];
2767 sheet._isModal = YES;
2772 var sheetFrame = [sheet frame],
2773 sheetShadowFrame = sheet._hasShadow ? [sheet._shadowView frame] : sheetFrame,
2774 frame = [
self frame],
2775 originX = frame.origin.x + FLOOR((frame.size.
width - sheetFrame.size.
width) / 2),
2776 startFrame = CGRectMake(originX, -sheetShadowFrame.size.height, sheetFrame.size.
width, sheetFrame.size.height),
2777 endY = -1 + [_windowView bodyOffset] - [[self contentView] frame].origin.y,
2778 endFrame = CGRectMake(originX, endY, sheetFrame.size.
width, sheetFrame.size.height);
2780 if (_toolbar && [_windowView showsToolbar] && [
self isFullPlatformWindow])
2782 endY += [[_toolbar _toolbarView] frameSize].height;
2783 endFrame = CGRectMake(originX, endY, sheetFrame.size.width, sheetFrame.size.height);
2787 [sheet setFrameOrigin:CGPointMake(0, -13000)];
2790 [sheet orderFront:self];
2791 [
self _clipSheet:sheet];
2793 [sheet setFrame:startFrame display:YES animate:NO];
2795 _sheetContext["opened"] = YES;
2796 _sheetContext["shouldClose"] = NO;
2797 _sheetContext["isOpening"] = YES;
2799 [sheet _setFrame:endFrame delegate:self duration:[
self animationResizeTime:endFrame] curve:CPAnimationEaseOut];
2802 - (void)_sheetShouldAnimateOut:(
CPTimer)timer
2804 if (_sheetContext[
"isOpening"])
2807 _sheetContext["shouldClose"] = YES;
2811 if (_sheetContext[
"isClosing"])
2814 _sheetContext["opened"] = NO;
2815 _sheetContext["isClosing"] = YES;
2818 if ([
self isVisible])
2820 var sheet = _sheetContext["sheet"],
2821 sheetFrame = [sheet frame],
2822 fullHeight = sheet._hasShadow ? [sheet._shadowView frame].size.height : sheetFrame.size.height,
2823 endFrame = CGRectMakeCopy(sheetFrame),
2824 contentOrigin = [
self convertBaseToGlobal:[[
self contentView] frame].origin];
2827 sheet._constrainsToUsableScreen = NO;
2829 [sheet setFrameOrigin:CGPointMake(sheetFrame.origin.x, sheetFrame.origin.y - contentOrigin.y)];
2830 [
self _clipSheet:sheet];
2832 endFrame.origin.y = -fullHeight;
2833 [sheet _setFrame:endFrame delegate:self duration:[
self animationResizeTime:endFrame] curve:CPAnimationEaseIn];
2837 [
self _sheetAnimationDidEnd:nil];
2841 - (void)_sheetAnimationDidEnd:(
CPTimer)timer
2843 var sheet = _sheetContext["sheet"];
2845 _sheetContext["isOpening"] = NO;
2846 _sheetContext["isClosing"] = NO;
2848 if (_sheetContext[
"opened"] === YES)
2850 var sheetFrame = [sheet frame],
2851 sheetOrigin = CGPointMakeCopy(sheetFrame.origin);
2853 [
self _removeClipForSheet:sheet];
2854 [sheet setFrameOrigin:CGPointMake(sheetOrigin.x, [sheet frame].origin.y + sheetOrigin.y)];
2857 if (_sheetContext[
"shouldClose"] === YES)
2858 [
self _detachSheetWindow];
2860 [sheet makeKeyWindow];
2865 [
self _cleanupSheetWindow];
2869 - (void)_clipSheet:(
CPWindow)aSheet
2871 var clipRect = [_platformWindow contentBounds];
2872 clipRect.origin.y = [
self frame].origin.y + [[self contentView] frame].origin.y;
2874 [[_platformWindow layerAtLevel:_level create:NO] clipWindow:aSheet toRect:clipRect];
2877 - (void)_removeClipForSheet:(
CPWindow)aSheet
2879 [[_platformWindow layerAtLevel:_level create:NO] removeClipForWindow:aSheet];
2887 if (_sheetContext === nil)
2890 return _sheetContext["sheet"];
2906 - (BOOL)becomesKeyOnlyIfNeeded
2915 - (BOOL)worksWhenModal
2920 - (BOOL)performKeyEquivalent:(
CPEvent)anEvent
2924 return [_contentView performKeyEquivalent:anEvent];
2927 - (void)keyDown:(
CPEvent)anEvent
2931 if ([anEvent _couldBeKeyEquivalent] && [
self performKeyEquivalent:anEvent])
2939 if (![
self _processKeyboardUIKey:anEvent])
2940 [
super keyDown:anEvent];
2951 - (BOOL)_processKeyboardUIKey:(
CPEvent)anEvent
2953 var character = [anEvent charactersIgnoringModifiers];
2955 if (![CPWindowActionMessageKeys containsObject:character])
2960 if ([selectors count] <= 0)
2965 var selector = [selectors objectAtIndex:0];
2966 return [[
self firstResponder] tryToPerform:selector with:self];
2973 [[
self firstResponder] doCommandBySelector:@selector(complete:)];
2979 - (void)_dirtyKeyViewLoop
2981 if (_autorecalculatesKeyViewLoop)
2982 _keyViewLoopIsDirty = YES;
2990 - (BOOL)_hasKeyViewLoop:(CPArray)theViews
2993 count = [theViews count];
2995 for (i = 0; i < count; ++i)
2997 var view = theViews[i];
2999 if ([view nextKeyView] || [view previousKeyView])
3003 for (i = 0; i < count; ++i)
3005 var subviews = [theViews[i] subviews];
3007 if ([subviews count] && [
self _hasKeyViewLoop:subviews])
3021 - (void)recalculateKeyViewLoop
3023 [
self _doRecalculateKeyViewLoop];
3026 - (CPArray)_viewsSortedByPosition
3028 var views = [CPArray arrayWithObject:_contentView];
3030 views = views.concat([
self _subviewsSortedByPosition:[_contentView subviews]]);
3035 - (CPArray)_subviewsSortedByPosition:(CPArray)theSubviews
3043 theSubviews = [theSubviews copy];
3044 [theSubviews sortUsingFunction:keyViewComparator context:nil];
3046 var sortedViews = [];
3048 for (var i = 0, count = [theSubviews count]; i < count; ++i)
3050 var view = theSubviews[i],
3051 subviews = [view subviews];
3053 sortedViews.push(view);
3055 if ([subviews count])
3056 sortedViews = sortedViews.concat([
self _subviewsSortedByPosition:subviews]);
3062 - (void)_doRecalculateKeyViewLoop
3064 var views = [
self _viewsSortedByPosition];
3066 for (var index = 0, count = [views count]; index < count; ++index)
3067 [views[index] setNextKeyView:views[(index + 1) % count]];
3069 _keyViewLoopIsDirty = NO;
3072 - (void)setAutorecalculatesKeyViewLoop:(BOOL)shouldRecalculate
3074 if (_autorecalculatesKeyViewLoop === shouldRecalculate)
3077 _autorecalculatesKeyViewLoop = shouldRecalculate;
3080 - (BOOL)autorecalculatesKeyViewLoop
3082 return _autorecalculatesKeyViewLoop;
3085 - (void)selectNextKeyView:(
id)sender
3087 if (_keyViewLoopIsDirty)
3088 [
self _doRecalculateKeyViewLoop];
3090 var nextValidKeyView = nil;
3092 if ([_firstResponder isKindOfClass:[
CPView class]])
3093 nextValidKeyView = [_firstResponder nextValidKeyView];
3095 if (!nextValidKeyView)
3097 if ([_initialFirstResponder acceptsFirstResponder])
3098 nextValidKeyView = _initialFirstResponder;
3100 nextValidKeyView = [_initialFirstResponder nextValidKeyView];
3103 if (nextValidKeyView)
3104 [
self makeFirstResponder:nextValidKeyView];
3107 - (void)selectPreviousKeyView:(
id)sender
3109 if (_keyViewLoopIsDirty)
3110 [
self _doRecalculateKeyViewLoop];
3112 var previousValidKeyView = nil;
3114 if ([_firstResponder isKindOfClass:[CPView
class]])
3115 previousValidKeyView = [_firstResponder previousValidKeyView];
3117 if (!previousValidKeyView)
3119 if ([_initialFirstResponder acceptsFirstResponder])
3120 previousValidKeyView = _initialFirstResponder;
3122 previousValidKeyView = [_initialFirstResponder previousValidKeyView];
3125 if (previousValidKeyView)
3126 [
self makeFirstResponder:previousValidKeyView];
3129 - (void)selectKeyViewFollowingView:(CPView)aView
3131 if (_keyViewLoopIsDirty)
3132 [
self _doRecalculateKeyViewLoop];
3134 var nextValidKeyView = [aView nextValidKeyView];
3136 if ([nextValidKeyView isKindOfClass:[CPView
class]])
3137 [
self makeFirstResponder:nextValidKeyView];
3140 - (void)selectKeyViewPrecedingView:(CPView)aView
3142 if (_keyViewLoopIsDirty)
3143 [
self _doRecalculateKeyViewLoop];
3145 var previousValidKeyView = [aView previousValidKeyView];
3147 if ([previousValidKeyView isKindOfClass:[CPView
class]])
3148 [
self makeFirstResponder:previousValidKeyView];
3156 - (void)setDefaultButtonCell:(
CPButton)aButton
3158 [
self setDefaultButton:aButton];
3167 return [
self defaultButton];
3176 - (void)setDefaultButton:(
CPButton)aButton
3178 if (_defaultButton === aButton)
3182 [_defaultButton setKeyEquivalent:nil];
3184 _defaultButton = aButton;
3195 return _defaultButton;
3201 - (void)enableKeyEquivalentForDefaultButton
3203 _defaultButtonEnabled = YES;
3210 - (void)enableKeyEquivalentForDefaultButtonCell
3212 [
self enableKeyEquivalentForDefaultButton];
3218 - (void)disableKeyEquivalentForDefaultButton
3220 _defaultButtonEnabled = NO;
3227 - (void)disableKeyEquivalentForDefaultButtonCell
3229 [
self disableKeyEquivalentForDefaultButton];
3232 - (void)setValue:(
id)aValue forKey:(
CPString)aKey
3234 if (aKey === CPDisplayPatternTitleBinding)
3235 [
self setTitle:aValue ||
@""];
3237 [
super setValue:aValue forKey:aKey];
3242 var keyViewComparator =
function(lhs, rhs, context)
3244 var lhsBounds = [lhs convertRect:[lhs bounds] toView:nil],
3245 rhsBounds = [rhs convertRect:[rhs bounds] toView:nil],
3246 lhsY = CGRectGetMinY(lhsBounds),
3247 rhsY = CGRectGetMinY(rhsBounds),
3248 lhsX = CGRectGetMinX(lhsBounds),
3249 rhsX = CGRectGetMinX(rhsBounds),
3250 intersectsVertically = MIN(CGRectGetMaxY(lhsBounds), CGRectGetMaxY(rhsBounds)) - MAX(lhsY, rhsY);
3253 if (intersectsVertically > 0)
3273 @implementation CPWindow (BridgeSupport)
3278 - (void)resizeWithOldPlatformWindowSize:(CGSize)aSize
3280 if ([
self isFullPlatformWindow])
3281 return [
self setFrame:[_platformWindow visibleFrame]];
3287 var frame = [_platformWindow contentBounds],
3288 newFrame = CGRectMakeCopy(_frame),
3289 dX = (CGRectGetWidth(frame) - aSize.
width) /
3291 dY = (CGRectGetHeight(frame) - aSize.height) /
3295 newFrame.origin.x += dX;
3298 newFrame.size.width += dX;
3301 newFrame.origin.y += dY;
3304 newFrame.size.height += dY;
3306 [
self _setFrame:newFrame display:YES animate:NO constrainWidth:YES constrainHeight:YES];
3312 - (void)setAutoresizingMask:(
unsigned)anAutoresizingMask
3314 _autoresizingMask = anAutoresizingMask;
3320 - (unsigned)autoresizingMask
3322 return _autoresizingMask;
3328 - (CGPoint)convertBaseToGlobal:(CGPoint)aPoint
3330 return [
CPPlatform isBrowser] ? [
self convertBaseToPlatformWindow:aPoint] : [
self convertBaseToScreen:aPoint];
3336 - (CGPoint)convertGlobalToBase:(CGPoint)aPoint
3338 return [
CPPlatform isBrowser] ? [
self convertPlatformWindowToBase:aPoint] : [
self convertScreenToBase:aPoint];
3344 - (CGPoint)convertBaseToPlatformWindow:(CGPoint)aPoint
3346 if ([
self _sharesChromeWithPlatformWindow])
3347 return CGPointMakeCopy(aPoint);
3349 var origin = [
self frame].origin;
3351 return CGPointMake(aPoint.x + origin.x, aPoint.y + origin.y);
3357 - (CGPoint)convertPlatformWindowToBase:(CGPoint)aPoint
3359 if ([
self _sharesChromeWithPlatformWindow])
3360 return CGPointMakeCopy(aPoint);
3362 var origin = [
self frame].origin;
3364 return CGPointMake(aPoint.x - origin.x, aPoint.y - origin.y);
3367 - (CGPoint)convertScreenToBase:(CGPoint)aPoint
3369 return [
self convertPlatformWindowToBase:[_platformWindow convertScreenToBase:aPoint]];
3372 - (CGPoint)convertBaseToScreen:(CGPoint)aPoint
3374 return [_platformWindow convertBaseToScreen:[
self convertBaseToPlatformWindow:aPoint]];
3377 - (void)_setSharesChromeWithPlatformWindow:(BOOL)shouldShareFrameWithPlatformWindow
3380 if (shouldShareFrameWithPlatformWindow && [
CPPlatform isBrowser])
3383 _sharesChromeWithPlatformWindow = shouldShareFrameWithPlatformWindow;
3385 [
self _updateShadow];
3388 - (BOOL)_sharesChromeWithPlatformWindow
3390 return _sharesChromeWithPlatformWindow;
3401 return _undoManager;
3404 var documentUndoManager = [[_windowController document] undoManager];
3406 if (documentUndoManager)
3407 return documentUndoManager;
3410 if (_delegateRespondsToWindowWillReturnUndoManagerSelector)
3411 return [_delegate windowWillReturnUndoManager:self];
3417 return _undoManager;
3424 - (void)undo:(
id)aSender
3426 [[
self undoManager] undo];
3433 - (void)redo:(
id)aSender
3435 [[
self undoManager] redo];
3438 - (BOOL)containsPoint:(CGPoint)aPoint
3440 return CGRectContainsPoint(_frame, aPoint);
3444 - (BOOL)_isValidMousePoint:(CGPoint)aPoint
3450 return CGRectContainsPoint(mouseFrame, aPoint);
3455 @implementation CPWindow (Deprecated)
3460 - (void)setFullBridge:(BOOL)shouldBeFullBridge
3462 _CPReportLenientDeprecation([
self class], _cmd,
@selector(setFullPlatformWindow:));
3464 [
self setFullPlatformWindow:shouldBeFullBridge];
3471 - (BOOL)isFullBridge
3473 return [
self isFullPlatformWindow];
3479 - (CGPoint)convertBaseToBridge:(CGPoint)aPoint
3481 return [
self convertBaseToPlatformWindow:aPoint];
3487 - (CGPoint)convertBridgeToBase:(CGPoint)aPoint
3489 return [
self convertPlatformWindowToBase:aPoint];
3494 var interpolate =
function(fromValue, toValue, progress)
3496 return fromValue + (toValue - fromValue) * progress;
3500 @implementation _CPWindowFrameAnimation :
CPAnimation
3505 CGRect _targetFrame;
3508 - (id)initWithWindow:(
CPWindow)aWindow targetFrame:(CGRect)aTargetFrame
3510 self = [
super initWithDuration:[aWindow animationResizeTime:aTargetFrame] animationCurve:CPAnimationLinear];
3516 _targetFrame = CGRectMakeCopy(aTargetFrame);
3517 _startFrame = CGRectMakeCopy([_window frame]);
3523 - (void)startAnimation
3525 [
super startAnimation];
3527 _window._isAnimating = YES;
3530 - (void)setCurrentProgress:(
float)aProgress
3532 [
super setCurrentProgress:aProgress];
3534 var value = [
self currentValue];
3537 _window._isAnimating = NO;
3539 var newFrame = CGRectMake(
3540 interpolate(CGRectGetMinX(_startFrame), CGRectGetMinX(_targetFrame), value),
3541 interpolate(CGRectGetMinY(_startFrame), CGRectGetMinY(_targetFrame), value),
3542 interpolate(CGRectGetWidth(_startFrame), CGRectGetWidth(_targetFrame), value),
3543 interpolate(CGRectGetHeight(_startFrame), CGRectGetHeight(_targetFrame), value));
3545 [_window setFrame:newFrame display:YES animate:NO];
3551 @implementation CPWindow (CPDraggingAdditions)
3554 - (id)_dragHitTest:(CGPoint)aPoint pasteboard:(
CPPasteboard)aPasteboard
3557 if (!_inclusiveRegisteredDraggedTypes)
3566 var adjustedPoint = [
self convertPlatformWindowToBase:aPoint],
3567 hitView = [_windowView hitTest:adjustedPoint];
3569 while (hitView && ![aPasteboard availableTypeFromArray:[hitView registeredDraggedTypes]])
3570 hitView = [hitView superview];
3575 if ([aPasteboard availableTypeFromArray:[
self registeredDraggedTypes]])
3583 function _CPWindowFullPlatformWindowSessionMake(aWindowView, aContentRect, hasShadow, aLevel)
3585 return { windowView:aWindowView, contentRect:aContentRect, hasShadow:hasShadow, level:aLevel };
3588 @implementation CPWindow (CPSynthesizedAccessors)
3593 - (void)_setChildOrdering:(CPWindowOrderingMode)aValue
3595 _childOrdering = aValue;