00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 @import <Foundation/CPCountedSet.j>
00024 @import <Foundation/CPNotificationCenter.j>
00025 @import <Foundation/CPUndoManager.j>
00026
00027 @import "CGGeometry.j"
00028 @import "CPAnimation.j"
00029 @import "CPResponder.j"
00030
00031 #include "../Platform/Platform.h"
00032 #include "../Platform/DOM/CPDOMDisplayServer.h"
00033
00034 #include "../CoreGraphics/CGGeometry.h"
00035
00036
00037
00038
00039
00040
00041
00042 CPBorderlessWindowMask = 0;
00043
00044
00045
00046
00047
00048 CPTitledWindowMask = 1 << 0;
00049
00050
00051
00052
00053
00054 CPClosableWindowMask = 1 << 1;
00055
00056
00057
00058
00059
00060 CPMiniaturizableWindowMask = 1 << 2;
00061
00062
00063
00064
00065
00066 CPResizableWindowMask = 1 << 3;
00067
00068
00069
00070
00071
00072 CPTexturedBackgroundWindowMask = 1 << 8;
00073
00074
00075
00076
00077 CPBorderlessBridgeWindowMask = 1 << 20;
00078
00079
00080
00081
00082 CPHUDBackgroundWindowMask = 1 << 21;
00083
00084 CPWindowNotSizable = 0;
00085 CPWindowMinXMargin = 1;
00086 CPWindowWidthSizable = 2;
00087 CPWindowMaxXMargin = 4;
00088 CPWindowMinYMargin = 8;
00089 CPWindowHeightSizable = 16;
00090 CPWindowMaxYMargin = 32;
00091
00092 CPBackgroundWindowLevel = -1;
00093
00094
00095
00096
00097
00098 CPNormalWindowLevel = 4;
00099
00100
00101
00102
00103
00104 CPFloatingWindowLevel = 5;
00105
00106
00107
00108
00109
00110 CPSubmenuWindowLevel = 6;
00111
00112
00113
00114
00115
00116 CPTornOffMenuWindowLevel = 6;
00117
00118
00119
00120
00121
00122 CPMainMenuWindowLevel = 8;
00123
00124
00125
00126
00127
00128 CPStatusWindowLevel = 9;
00129
00130
00131
00132
00133
00134 CPModalPanelWindowLevel = 10;
00135
00136
00137
00138
00139
00140 CPPopUpMenuWindowLevel = 11;
00141
00142
00143
00144
00145
00146 CPDraggingWindowLevel = 12;
00147
00148
00149
00150
00151
00152 CPScreenSaverWindowLevel = 13;
00153
00154
00155
00156
00157
00158
00159 CPWindowOut = 0;
00160
00161
00162
00163
00164
00165 CPWindowAbove = 1;
00166
00167
00168
00169
00170
00171 CPWindowBelow = 2;
00172
00173 CPWindowWillCloseNotification = @"CPWindowWillCloseNotification";
00174 CPWindowDidBecomeMainNotification = @"CPWindowDidBecomeMainNotification";
00175 CPWindowDidResignMainNotification = @"CPWindowDidResignMainNotification";
00176 CPWindowDidMoveNotification = @"CPWindowDidMoveNotification";
00177
00178
00179 var SHADOW_MARGIN_LEFT = 20.0,
00180 SHADOW_MARGIN_RIGHT = 19.0,
00181 SHADOW_MARGIN_TOP = 10.0,
00182 SHADOW_MARGIN_BOTTOM = 10.0,
00183 SHADOW_DISTANCE = 5.0,
00184
00185 _CPWindowShadowColor = nil;
00186
00187 var CPWindowSaveImage = nil,
00188 CPWindowSavingImage = nil;
00189
00236 @implementation CPWindow : CPResponder
00237 {
00238 int _windowNumber;
00239 unsigned _styleMask;
00240 CGRect _frame;
00241 int _level;
00242 BOOL _isVisible;
00243 BOOL _isAnimating;
00244 BOOL _hasShadow;
00245 BOOL _isMovableByWindowBackground;
00246
00247 BOOL _isDocumentEdited;
00248 BOOL _isDocumentSaving;
00249
00250 CPImageView _shadowView;
00251
00252 CPView _windowView;
00253 CPView _contentView;
00254 CPView _toolbarView;
00255
00256 CPView _mouseOverView;
00257 CPView _leftMouseDownView;
00258 CPView _rightMouseDownView;
00259
00260 CPToolbar _toolbar;
00261 CPResponder _firstResponder;
00262 CPResponder _initialFirstResponder;
00263 id _delegate;
00264
00265 CPString _title;
00266
00267 BOOL _acceptsMouseMovedEvents;
00268 BOOL _ignoresMouseEvents;
00269
00270 CPWindowController _windowController;
00271
00272 CGSize _minSize;
00273 CGSize _maxSize;
00274
00275 CPUndoManager _undoManager;
00276 CPURL _representedURL;
00277
00278 CPSet _registeredDraggedTypes;
00279 CPArray _registeredDraggedTypesArray;
00280 CPCountedSet _inclusiveRegisteredDraggedTypes;
00281
00282 CPButton _defaultButton;
00283 BOOL _defaultButtonEnabled;
00284
00285 BOOL _autorecalculatesKeyViewLoop;
00286 BOOL _keyViewLoopIsDirty;
00287
00288
00289 #if PLATFORM(DOM)
00290 DOMElement _DOMElement;
00291 #endif
00292 CPDOMWindowBridge _bridge;
00293 unsigned _autoresizingMask;
00294
00295 BOOL _delegateRespondsToWindowWillReturnUndoManagerSelector;
00296
00297 BOOL _isFullBridge;
00298 _CPWindowFullBridgeSession _fullBridgeSession;
00299 }
00300
00301
00302
00303
00304
00305 + (void)initialize
00306 {
00307 if (self != [CPWindow class])
00308 return;
00309
00310 var bundle = [CPBundle bundleForClass:[CPWindow class]];
00311
00312 CPWindowSavingImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPProgressIndicator/CPProgressIndicatorSpinningStyleRegular.gif"] size:CGSizeMake(16.0, 16.0)]
00313 }
00314
00330 - (id)initWithContentRect:(CGRect)aContentRect styleMask:(unsigned int)aStyleMask
00331 {
00332 #if PLATFORM(DOM)
00333 return [self initWithContentRect:aContentRect styleMask:aStyleMask bridge:[CPDOMWindowBridge sharedDOMWindowBridge]];
00334 #else
00335 return [self initWithContentRect:aContentRect styleMask:aStyleMask bridge:nil];
00336 #endif
00337 }
00338
00356 - (id)initWithContentRect:(CGRect)aContentRect styleMask:(unsigned int)aStyleMask bridge:(CPDOMWindowBridge)aBridge
00357 {
00358 self = [super init];
00359
00360 if (self)
00361 {
00362 _isFullBridge = NO;
00363 _registeredDraggedTypes = [CPSet set];
00364 _registeredDraggedTypesArray = [];
00365
00366
00367 _windowNumber = [CPApp._windows count];
00368 CPApp._windows[_windowNumber] = self;
00369
00370 _styleMask = aStyleMask;
00371 _level = CPNormalWindowLevel;
00372
00373 _minSize = CGSizeMake(0.0, 0.0);
00374 _maxSize = CGSizeMake(1000000.0, 1000000.0);
00375
00376
00377 var windowViewClass = [[self class] _windowViewClassForStyleMask:aStyleMask];
00378
00379 _frame = [windowViewClass frameRectForContentRect:aContentRect];
00380 _windowView = [[windowViewClass alloc] initWithFrame:CGRectMake(0.0, 0.0, CGRectGetWidth(_frame), CGRectGetHeight(_frame)) styleMask:aStyleMask];
00381
00382 [_windowView _setWindow:self];
00383 [_windowView setNextResponder:self];
00384
00385 [self setMovableByWindowBackground:aStyleMask & CPHUDBackgroundWindowMask];
00386
00387
00388 [self setContentView:[[CPView alloc] initWithFrame:CGRectMakeZero()]];
00389
00390 _firstResponder = self;
00391
00392 #if PLATFORM(DOM)
00393 _DOMElement = document.createElement("div");
00394
00395 _DOMElement.style.position = "absolute";
00396 _DOMElement.style.visibility = "visible";
00397 _DOMElement.style.zIndex = 0;
00398
00399 CPDOMDisplayServerSetStyleLeftTop(_DOMElement, NULL, _CGRectGetMinX(_frame), _CGRectGetMinY(_frame));
00400 CPDOMDisplayServerSetStyleSize(_DOMElement, 1, 1);
00401
00402 CPDOMDisplayServerAppendChild(_DOMElement, _windowView._DOMElement);
00403 #endif
00404
00405 [self setBridge:aBridge];
00406
00407 [self setNextResponder:CPApp];
00408
00409 [self setHasShadow:aStyleMask !== CPBorderlessWindowMask];
00410
00411 if (aStyleMask & CPBorderlessBridgeWindowMask)
00412 [self setFullBridge:YES];
00413
00414 _defaultButtonEnabled = YES;
00415 _keyViewLoopIsDirty = YES;
00416 }
00417
00418 return self;
00419 }
00420
00424 + (Class)_windowViewClassForStyleMask:(unsigned)aStyleMask
00425 {
00426 if (aStyleMask & CPHUDBackgroundWindowMask)
00427 return _CPHUDWindowView;
00428
00429 else if (aStyleMask === CPBorderlessWindowMask)
00430 return _CPBorderlessWindowView;
00431
00432 return _CPStandardWindowView;
00433 }
00434
00435 + (Class)_windowViewClassForFullBridgeStyleMask:(unsigned)aStyleMask
00436 {
00437 return _CPBorderlessBridgeWindowView;
00438 }
00439
00440 - (void)awakeFromCib
00441 {
00442 if (_initialFirstResponder)
00443 [self makeFirstResponder:_initialFirstResponder];
00444
00445 _keyViewLoopIsDirty = ![self _hasKeyViewLoop];
00446 }
00447
00448 - (void)_setWindowView:(CPView)aWindowView
00449 {
00450 if (_windowView === aWindowView)
00451 return;
00452
00453 var oldWindowView = _windowView;
00454
00455 _windowView = aWindowView;
00456
00457 #if PLATFORM(DOM)
00458 if (oldWindowView)
00459 {
00460 [oldWindowView _setWindow:nil];
00461 [oldWindowView noteToolbarChanged];
00462
00463 CPDOMDisplayServerRemoveChild(_DOMElement, oldWindowView._DOMElement);
00464 }
00465
00466 if (_windowView)
00467 {
00468 CPDOMDisplayServerAppendChild(_DOMElement, _windowView._DOMElement);
00469
00470 var contentRect = [_contentView convertRect:[_contentView bounds] toView:nil];
00471
00472 contentRect.origin = [self convertBaseToBridge:contentRect.origin];
00473
00474 [_windowView _setWindow:self];
00475 [_windowView setNextResponder:self];
00476 [_windowView addSubview:_contentView];
00477 [_windowView setTitle:_title];
00478 [_windowView noteToolbarChanged];
00479
00480 [self setFrame:[self frameRectForContentRect:contentRect]];
00481 }
00482 #endif
00483 }
00484
00485 - (void)setFullBridge:(BOOL)shouldBeFullBridge
00486 {
00487 shouldBeFullBridge = !!shouldBeFullBridge;
00488
00489 if (_isFullBridge === shouldBeFullBridge)
00490 return;
00491
00492 _isFullBridge = shouldBeFullBridge;
00493
00494 if (_isFullBridge)
00495 {
00496 _fullBridgeSession = _CPWindowFullBridgeSessionMake(_windowView, [self contentRectForFrameRect:[self frame]], [self hasShadow], [self level]);
00497
00498 var fullBridgeWindowViewClass = [[self class] _windowViewClassForFullBridgeStyleMask:_styleMask],
00499 windowView = [[fullBridgeWindowViewClass alloc] initWithFrame:CGRectMakeZero() styleMask:_styleMask];
00500
00501 [self _setWindowView:windowView];
00502
00503 [self setLevel:CPBackgroundWindowLevel];
00504 [self setHasShadow:NO];
00505 [self setAutoresizingMask:CPWindowWidthSizable | CPWindowHeightSizable];
00506 [self setFrame:[_bridge visibleFrame]];
00507 }
00508 else
00509 {
00510 var windowView = _fullBridgeSession.windowView;
00511
00512 [self _setWindowView:windowView];
00513
00514 [self setLevel:_fullBridgeSession.level];
00515 [self setHasShadow:_fullBridgeSession.hasShadow];
00516 [self setAutoresizingMask:CPWindowNotSizable];
00517
00518 [self setFrame:[windowView frameRectForContentRect:_fullBridgeSession.contentRect]];
00519 }
00520 }
00521
00522 - (BOOL)isFullBridge
00523 {
00524 return _isFullBridge;
00525 }
00526
00530 - (unsigned)styleMask
00531 {
00532 return _styleMask;
00533 }
00534
00541 + (CGRect)frameRectForContentRect:(CGRect)aContentRect styleMask:(unsigned)aStyleMask
00542 {
00543 return [[[self class] _windowViewClassForStyleMask:_styleMask] frameRectForContentRect:aContentRect];
00544 }
00545
00550 - (CGRect)contentRectForFrameRect:(CGRect)aFrame
00551 {
00552 return [_windowView contentRectForFrameRect:aFrame];
00553 }
00554
00560 - (CGRect)frameRectForContentRect:(CGRect)aContentRect
00561 {
00562 return [_windowView frameRectForContentRect:aContentRect];
00563 }
00564
00568 - (CGRect)frame
00569 {
00570 return _frame;
00571 }
00572
00580 - (void)setFrame:(CGRect)aFrame display:(BOOL)shouldDisplay animate:(BOOL)shouldAnimate
00581 {
00582 if (shouldAnimate)
00583 {
00584 var animation = [[_CPWindowFrameAnimation alloc] initWithWindow:self targetFrame:aFrame];
00585
00586 [animation startAnimation];
00587 }
00588 else
00589 {
00590 [self setFrameOrigin:aFrame.origin];
00591 [self setFrameSize:aFrame.size];
00592 }
00593 }
00594
00598 - (void)setFrame:(CGRect)aFrame
00599 {
00600 [self setFrame:aFrame display:YES animate:NO];
00601 }
00602
00607 - (void)setFrameOrigin:(CGPoint)anOrigin
00608 {
00609 var origin = _frame.origin;
00610
00611 if (_CGPointEqualToPoint(origin, anOrigin))
00612 return;
00613
00614 origin.x = anOrigin.x;
00615 origin.y = anOrigin.y;
00616
00617 #if PLATFORM(DOM)
00618 CPDOMDisplayServerSetStyleLeftTop(_DOMElement, NULL, origin.x, origin.y);
00619 #endif
00620
00621 [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowDidMoveNotification object:self];
00622 }
00623
00628 - (void)setFrameSize:(CGSize)aSize
00629 {
00630 aSize = _CGSizeMake(MIN(MAX(aSize.width, _minSize.width), _maxSize.width), MIN(MAX(aSize.height, _minSize.height), _maxSize.height));
00631
00632 if (_CGSizeEqualToSize(_frame.size, aSize))
00633 return;
00634
00635 _frame.size = aSize;
00636
00637 [_windowView setFrameSize:aSize];
00638
00639 if (_hasShadow)
00640 [_shadowView setFrameSize:_CGSizeMake(SHADOW_MARGIN_LEFT + aSize.width + SHADOW_MARGIN_RIGHT, SHADOW_MARGIN_BOTTOM + aSize.height + SHADOW_MARGIN_TOP + SHADOW_DISTANCE)];
00641
00642 if (!_isAnimating && [_delegate respondsToSelector:@selector(windowDidResize:)])
00643 [_delegate windowDidResize:self];
00644 }
00645
00650 - (void)orderFront:(id)aSender
00651 {
00652 [_bridge order:CPWindowAbove window:self relativeTo:nil];
00653 }
00654
00655
00656
00657
00658
00659
00660 - (void)orderBack:(id)aSender
00661 {
00662
00663 }
00664
00669 - (void)orderOut:(id)aSender
00670 {
00671 if ([_delegate respondsToSelector:@selector(windowWillClose:)])
00672 [_delegate windowWillClose:self];
00673
00674 [_bridge order:CPWindowOut window:self relativeTo:nil];
00675
00676 if ([CPApp keyWindow] == self)
00677 {
00678 [self resignKeyWindow];
00679
00680 CPApp._keyWindow = nil;
00681 }
00682 }
00683
00689 - (void)orderWindow:(CPWindowOrderingMode)aPlace relativeTo:(int)otherWindowNumber
00690 {
00691 [_bridge order:aPlace window:self relativeTo:CPApp._windows[otherWindowNumber]];
00692 }
00693
00698 - (void)setLevel:(int)aLevel
00699 {
00700 _level = aLevel;
00701 }
00702
00706 - (int)level
00707 {
00708 return _level;
00709 }
00710
00714 - (BOOL)isVisible
00715 {
00716 return _isVisible;
00717 }
00718
00722 - (BOOL)showsResizeIndicator
00723 {
00724 return [_windowView showsResizeIndicator];
00725 }
00726
00731 - (void)setShowsResizeIndicator:(BOOL)shouldShowResizeIndicator
00732 {
00733 [_windowView setShowsResizeIndicator:shouldShowResizeIndicator];
00734 }
00735
00739 - (CGSize)resizeIndicatorOffset
00740 {
00741 return [_windowView resizeIndicatorOffset];
00742 }
00743
00748 - (void)setResizeIndicatorOffset:(CGSize)anOffset
00749 {
00750 [_windowView setResizeIndicatorOffset:anOffset];
00751 }
00752
00758 - (void)setContentView:(CPView)aView
00759 {
00760 if (_contentView)
00761 [_contentView removeFromSuperview];
00762
00763 var bounds = CGRectMake(0.0, 0.0, CGRectGetWidth(_frame), CGRectGetHeight(_frame));
00764
00765 _contentView = aView;
00766 [_contentView setFrame:[self contentRectForFrameRect:bounds]];
00767
00768 [_contentView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
00769 [_windowView addSubview:_contentView];
00770 }
00771
00775 - (CPView)contentView
00776 {
00777 return _contentView;
00778 }
00779
00784 - (void)setBackgroundColor:(CPColor)aColor
00785 {
00786 [_windowView setBackgroundColor:aColor];
00787 }
00788
00792 - (CPColor)backgroundColor
00793 {
00794 return [_windowView backgroundColor];
00795 }
00796
00802 - (void)setMinSize:(CGSize)aSize
00803 {
00804 if (CGSizeEqualToSize(_minSize, aSize))
00805 return;
00806
00807 _minSize = CGSizeCreateCopy(aSize);
00808
00809 var size = CGSizeMakeCopy([self frame].size),
00810 needsFrameChange = NO;
00811
00812 if (size.width < _minSize.width)
00813 {
00814 size.width = _minSize.width;
00815 needsFrameChange = YES;
00816 }
00817
00818 if (size.height < _minSize.height)
00819 {
00820 size.height = _minSize.height;
00821 needsFrameChange = YES;
00822 }
00823
00824 if (needsFrameChange)
00825 [self setFrameSize:size];
00826 }
00827
00831 - (CGSize)minSize
00832 {
00833 return _minSize;
00834 }
00835
00842 - (void)setMaxSize:(CGSize)aSize
00843 {
00844 if (CGSizeEqualToSize(_maxSize, aSize))
00845 return;
00846
00847 _maxSize = CGSizeCreateCopy(aSize);
00848
00849 var size = CGSizeMakeCopy([self frame].size),
00850 needsFrameChange = NO;
00851
00852 if (size.width > _maxSize.width)
00853 {
00854 size.width = _maxSize.width;
00855 needsFrameChange = YES;
00856 }
00857
00858 if (size.height > _maxSize.height)
00859 {
00860 size.height = _maxSize.height;
00861 needsFrameChange = YES;
00862 }
00863
00864 if (needsFrameChange)
00865 [self setFrameSize:size];
00866 }
00867
00871 - (CGSize)maxSize
00872 {
00873 return _maxSize;
00874 }
00875
00879 - (BOOL)hasShadow
00880 {
00881 return _hasShadow;
00882 }
00883
00888 - (void)setHasShadow:(BOOL)shouldHaveShadow
00889 {
00890 if (_hasShadow === shouldHaveShadow)
00891 return;
00892
00893 _hasShadow = shouldHaveShadow;
00894
00895 if (_hasShadow)
00896 {
00897 var bounds = [_windowView bounds];
00898
00899 _shadowView = [[CPView alloc] initWithFrame:CGRectMake(-SHADOW_MARGIN_LEFT, -SHADOW_MARGIN_TOP + SHADOW_DISTANCE,
00900 SHADOW_MARGIN_LEFT + CGRectGetWidth(bounds) + SHADOW_MARGIN_RIGHT, SHADOW_MARGIN_TOP + CGRectGetHeight(bounds) + SHADOW_MARGIN_BOTTOM)];
00901
00902 if (!_CPWindowShadowColor)
00903 {
00904 var bundle = [CPBundle bundleForClass:[CPWindow class]];
00905
00906 _CPWindowShadowColor = [CPColor colorWithPatternImage:[[CPNinePartImage alloc] initWithImageSlices:
00907 [
00908 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow0.png"] size:CGSizeMake(20.0, 19.0)],
00909 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow1.png"] size:CGSizeMake(1.0, 19.0)],
00910 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow2.png"] size:CGSizeMake(19.0, 19.0)],
00911
00912 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow3.png"] size:CGSizeMake(20.0, 1.0)],
00913 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow4.png"] size:CGSizeMake(1.0, 1.0)],
00914 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow5.png"] size:CGSizeMake(19.0, 1.0)],
00915
00916 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow6.png"] size:CGSizeMake(20.0, 18.0)],
00917 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow7.png"] size:CGSizeMake(1.0, 18.0)],
00918 [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow8.png"] size:CGSizeMake(19.0, 18.0)]
00919 ]]];
00920 }
00921
00922 [_shadowView setBackgroundColor:_CPWindowShadowColor];
00923 [_shadowView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
00924
00925 #if PLATFORM(DOM)
00926 CPDOMDisplayServerInsertBefore(_DOMElement, _shadowView._DOMElement, _windowView._DOMElement);
00927 #endif
00928 }
00929 else if (_shadowView)
00930 {
00931 #if PLATFORM(DOM)
00932 CPDOMDisplayServerRemoveChild(_DOMElement, _shadowView._DOMElement);
00933 #endif
00934 _shadowView = nil;
00935 }
00936 }
00937
00942 - (void)setDelegate:(id)aDelegate
00943 {
00944
00945
00946 _delegate = aDelegate;
00947
00948 _delegateRespondsToWindowWillReturnUndoManagerSelector = [_delegate respondsToSelector:@selector(windowWillReturnUndoManager:)];
00949
00950 var defaultCenter = [CPNotificationCenter defaultCenter];
00951
00952 if ([_delegate respondsToSelector:@selector(windowDidBecomeMain:)])
00953 [defaultCenter
00954 addObserver:_delegate
00955 selector:@selector(windowDidBecomeMain:)
00956 name:CPWindowDidBecomeMainNotification
00957 object:self];
00958
00959 if ([_delegate respondsToSelector:@selector(windowDidResignMain:)])
00960 [defaultCenter
00961 addObserver:_delegate
00962 selector:@selector(windowDidResignMain:)
00963 name:CPWindowDidResignMainNotification
00964 object:self];
00965
00966 if ([_delegate respondsToSelector:@selector(windowDidMove:)])
00967 [defaultCenter
00968 addObserver:_delegate
00969 selector:@selector(windowDidMove:)
00970 name:CPWindowDidMoveNotification
00971 object:self];
00972 }
00973
00977 - (id)delegate
00978 {
00979 return _delegate;
00980 }
00981
00986 - (void)setWindowController:(CPWindowController)aWindowController
00987 {
00988 _windowController = aWindowController;
00989 }
00990
00994 - (CPWindowController)windowController
00995 {
00996 return _windowController;
00997 }
00998
00999 - (void)doCommandBySelector:(SEL)aSelector
01000 {
01001 if ([_delegate respondsToSelector:aSelector])
01002 [_delegate performSelector:aSelector];
01003 else
01004 [super doCommandBySelector:aSelector];
01005 }
01006
01007 - (BOOL)acceptsFirstResponder
01008 {
01009 return YES;
01010 }
01011
01019 - (void)makeFirstResponder:(CPResponder)aResponder
01020 {
01021 if (_firstResponder == aResponder)
01022 return YES;
01023
01024 if(![_firstResponder resignFirstResponder])
01025 return NO;
01026
01027 if(!aResponder || ![aResponder acceptsFirstResponder] || ![aResponder becomeFirstResponder])
01028 {
01029 _firstResponder = self;
01030
01031 return NO;
01032 }
01033
01034 _firstResponder = aResponder;
01035
01036 return YES;
01037 }
01038
01042 - (CPResponder)firstResponder
01043 {
01044 return _firstResponder;
01045 }
01046
01047 - (BOOL)acceptsMouseMovedEvents
01048 {
01049 return _acceptsMouseMovedEvents;
01050 }
01051
01052 - (void)setAcceptsMouseMovedEvents:(BOOL)shouldAcceptMouseMovedEvents
01053 {
01054 _acceptsMouseMovedEvents = shouldAcceptMouseMovedEvents;
01055 }
01056
01057 - (BOOL)ignoresMouseEvents
01058 {
01059 return _ignoresMouseEvents;
01060 }
01061
01062 - (void)setIgnoresMouseEvents:(BOOL)shouldIgnoreMouseEvents
01063 {
01064 _ignoresMouseEvents = shouldIgnoreMouseEvents;
01065 }
01066
01067
01068
01072 - (CPString)title
01073 {
01074 return _title;
01075 }
01076
01080 - (void)setTitle:(CPString)aTitle
01081 {
01082 _title = aTitle;
01083
01084 [_windowView setTitle:aTitle];
01085
01086 [self _synchronizeMenuBarTitleWithWindowTitle];
01087 }
01088
01092 - (void)setTitleWithRepresentedFilename:(CPString)aFilePath
01093 {
01094 [self setRepresentedFilename:aFilePath];
01095 [self setTitle:[aFilePath lastPathComponent]];
01096 }
01097
01101 - (void)setRepresentedFilename:(CPString)aFilePath
01102 {
01103
01104 [self setRepresentedURL:aFilePath];
01105 }
01106
01110 - (CPString)representedFilename
01111 {
01112 return _representedURL;
01113 }
01114
01118 - (void)setRepresentedURL:(CPURL)aURL
01119 {
01120 _representedURL = aURL;
01121 }
01122
01126 - (CPURL)representedURL
01127 {
01128 return _representedURL;
01129 }
01130
01131
01132
01137 - (void)setMovableByWindowBackground:(BOOL)shouldBeMovableByWindowBackground
01138 {
01139 _isMovableByWindowBackground = shouldBeMovableByWindowBackground;
01140 }
01141
01145 - (BOOL)isMovableByWindowBackground
01146 {
01147 return _isMovableByWindowBackground;
01148 }
01149
01153 - (void)center
01154 {
01155 var size = [self frame].size,
01156 bridgeSize = [_bridge contentBounds].size;
01157
01158 [self setFrameOrigin:CGPointMake((bridgeSize.width - size.width) / 2.0, (bridgeSize.height - size.height) / 2.0)];
01159 }
01160
01165 - (void)sendEvent:(CPEvent)anEvent
01166 {
01167 var type = [anEvent type],
01168 point = [anEvent locationInWindow];
01169
01170 switch (type)
01171 {
01172 case CPKeyUp: return [[self firstResponder] keyUp:anEvent];
01173 case CPKeyDown: return [[self firstResponder] keyDown:anEvent];
01174
01175 case CPScrollWheel: return [[_windowView hitTest:point] scrollWheel:anEvent];
01176
01177 case CPLeftMouseUp: if (!_leftMouseDownView)
01178 return [[_windowView hitTest:point] mouseUp:anEvent];
01179
01180 [_leftMouseDownView mouseUp:anEvent]
01181
01182 _leftMouseDownView = nil;
01183
01184 return;
01185 case CPLeftMouseDown: _leftMouseDownView = [_windowView hitTest:point];
01186
01187 if (_leftMouseDownView != _firstResponder && [_leftMouseDownView acceptsFirstResponder])
01188 [self makeFirstResponder:_leftMouseDownView];
01189
01190 var theWindow = [anEvent window];
01191
01192 if ([theWindow isKeyWindow] || [theWindow becomesKeyOnlyIfNeeded])
01193 return [_leftMouseDownView mouseDown:anEvent];
01194 else
01195 {
01196
01197 [self makeKeyAndOrderFront:self];
01198
01199 if ([_leftMouseDownView acceptsFirstMouse:anEvent])
01200 return [_leftMouseDownView mouseDown:anEvent]
01201 }
01202 break;
01203 case CPLeftMouseDragged: if (!_leftMouseDownView)
01204 return [[_windowView hitTest:point] mouseDragged:anEvent];
01205
01206 return [_leftMouseDownView mouseDragged:anEvent];
01207
01208 case CPRightMouseUp: return [_rightMouseDownView mouseUp:anEvent];
01209 case CPRightMouseDown: _rightMouseDownView = [_windowView hitTest:point];
01210 return [_rightMouseDownView mouseDown:anEvent];
01211 case CPRightMouseDragged: return [_rightMouseDownView mouseDragged:anEvent];
01212
01213 case CPMouseMoved: if (!_acceptsMouseMovedEvents)
01214 return;
01215
01216 var hitTestView = [_windowView hitTest:point];
01217
01218 if (hitTestView != _mouseOverView)
01219 {
01220 if (_mouseOverView)
01221 [_mouseOverView mouseExited:[CPEvent mouseEventWithType:CPMouseExited location:point
01222 modifierFlags:[anEvent modifierFlags] timestamp:[anEvent timestamp] windowNumber:_windowNumber context:nil eventNumber:-1 clickCount:1 pressure:0]];
01223
01224 if (hitTestView)
01225 [hitTestView mouseEntered:[CPEvent mouseEventWithType:CPMouseEntered location:point
01226 modifierFlags:[anEvent modifierFlags] timestamp:[anEvent timestamp] windowNumber:_windowNumber context:nil eventNumber:-1 clickCount:1 pressure:0]];
01227
01228 _mouseOverView = hitTestView;
01229 }
01230
01231 [_mouseOverView mouseMoved:anEvent];
01232 }
01233 }
01234
01238 - (int)windowNumber
01239 {
01240 return _windowNumber;
01241 }
01242
01247 - (void)becomeKeyWindow
01248 {
01249 if (_firstResponder != self && [_firstResponder respondsToSelector:@selector(becomeKeyWindow)])
01250 [_firstResponder becomeKeyWindow];
01251 }
01252
01257 - (BOOL)canBecomeKeyWindow
01258 {
01259 return YES;
01260 }
01261
01265 - (BOOL)isKeyWindow
01266 {
01267 return [CPApp keyWindow] == self;
01268 }
01269
01274 - (void)makeKeyAndOrderFront:(id)aSender
01275 {
01276 [self orderFront:self];
01277
01278 [self makeKeyWindow];
01279 [self makeMainWindow];
01280 }
01281
01285 - (void)makeKeyWindow
01286 {
01287 if (![self canBecomeKeyWindow])
01288 return;
01289
01290 [CPApp._keyWindow resignKeyWindow];
01291
01292 CPApp._keyWindow = self;
01293
01294 [self becomeKeyWindow];
01295 }
01296
01300 - (void)resignKeyWindow
01301 {
01302 if (_firstResponder != self && [_firstResponder respondsToSelector:@selector(resignKeyWindow)])
01303 [_firstResponder resignKeyWindow];
01304
01305 if ([_delegate respondsToSelector:@selector(windowDidResignKey:)])
01306 [_delegate windowDidResignKey:self];
01307 }
01308
01319 - (void)dragImage:(CPImage)anImage at:(CGPoint)imageLocation offset:(CGSize)mouseOffset event:(CPEvent)anEvent pasteboard:(CPPasteboard)aPasteboard source:(id)aSourceObject slideBack:(BOOL)slideBack
01320 {
01321 [[CPDragServer sharedDragServer] dragImage:anImage fromWindow:self at:[self convertBaseToBridge:imageLocation] offset:mouseOffset event:anEvent pasteboard:aPasteboard source:aSourceObject slideBack:slideBack];
01322 }
01323
01324 - (void)_noteRegisteredDraggedTypes:(CPSet)pasteboardTypes
01325 {
01326 if (!pasteboardTypes)
01327 return;
01328
01329 if (!_inclusiveRegisteredDraggedTypes)
01330 _inclusiveRegisteredDraggedTypes = [CPCountedSet set];
01331
01332 [_inclusiveRegisteredDraggedTypes unionSet:pasteboardTypes];
01333 }
01334
01335 - (void)_noteUnregisteredDraggedTypes:(CPArray)pasteboardTypes
01336 {
01337 if (!pasteboardTypes)
01338 return;
01339
01340 [_inclusiveRegisteredDraggedTypes minusSet:pasteboardTypes]
01341
01342 if ([_inclusiveRegisteredDraggedTypes count] === 0)
01343 _inclusiveRegisteredDraggedTypes = nil;
01344 }
01345
01356 - (void)dragView:(CPView)aView at:(CGPoint)imageLocation offset:(CGSize)mouseOffset event:(CPEvent)anEvent pasteboard:(CPPasteboard)aPasteboard source:(id)aSourceObject slideBack:(BOOL)slideBack
01357 {
01358 [[CPDragServer sharedDragServer] dragView:aView fromWindow:self at:[self convertBaseToBridge:imageLocation] offset:mouseOffset event:anEvent pasteboard:aPasteboard source:aSourceObject slideBack:slideBack];
01359 }
01360
01365 - (void)registerForDraggedTypes:(CPArray)pasteboardTypes
01366 {
01367 if (!pasteboardTypes)
01368 return;
01369
01370 [self _noteUnregisteredDraggedTypes:_registeredDraggedTypes];
01371 [_registeredDraggedTypes addObjectsFromArray:pasteboardTypes]
01372 [self _noteRegisteredDraggedTypes:_registeredDraggedTypes];
01373
01374 _registeredDraggedTypesArray = nil;
01375 }
01376
01381 - (CPArray)registeredDraggedTypes
01382 {
01383 if (!_registeredDraggedTypesArray)
01384 _registeredDraggedTypesArray = [_registeredDraggedTypes allObjects]
01385
01386 return _registeredDraggedTypesArray;
01387 }
01388
01392 - (void)unregisterDraggedTypes
01393 {
01394 [self _noteUnregisteredDraggedTypes:_registeredDraggedTypes];
01395
01396 _registeredDraggedTypes = [CPSet set];
01397 _registeredDraggedTypesArray = [];
01398 }
01399
01400
01401
01406 - (void)setDocumentEdited:(BOOL)isDocumentEdited
01407 {
01408 if (_isDocumentEdited == isDocumentEdited)
01409 return;
01410
01411 _isDocumentEdited = isDocumentEdited;
01412
01413 [CPMenu _setMenuBarIconImageAlphaValue:_isDocumentEdited ? 0.5 : 1.0];
01414 }
01415
01419 - (BOOL)isDocumentEdited
01420 {
01421 return _isDocumentEdited;
01422 }
01423
01424 - (void)setDocumentSaving:(BOOL)isDocumentSaving
01425 {
01426 if (_isDocumentSaving == isDocumentSaving)
01427 return;
01428
01429 _isDocumentSaving = isDocumentSaving;
01430
01431 [self _synchronizeSaveMenuWithDocumentSaving];
01432
01433 [_windowView windowDidChangeDocumentSaving];
01434 }
01435
01436 - (BOOL)isDocumentSaving
01437 {
01438 return _isDocumentSaving;
01439 }
01440
01441
01442 - (void)_synchronizeSaveMenuWithDocumentSaving
01443 {
01444 if (![self isMainWindow])
01445 return;
01446
01447 var mainMenu = [CPApp mainMenu],
01448 index = [mainMenu indexOfItemWithTitle:_isDocumentSaving ? @"Save" : @"Saving..."];
01449
01450 if (index == CPNotFound)
01451 return;
01452
01453 var item = [mainMenu itemAtIndex:index];
01454
01455 if (_isDocumentSaving)
01456 {
01457 CPWindowSaveImage = [item image];
01458
01459 [item setTitle:@"Saving..."];
01460 [item setImage:CPWindowSavingImage];
01461 [item setEnabled:NO];
01462 }
01463 else
01464 {
01465 [item setTitle:@"Save"];
01466 [item setImage:CPWindowSaveImage];
01467 [item setEnabled:YES];
01468 }
01469 }
01470
01471
01472
01477 - (void)performClose:(id)aSender
01478 {
01479
01480 if ([_delegate respondsToSelector:@selector(windowShouldClose:)])
01481 {
01482 if (![_delegate windowShouldClose:self])
01483 return;
01484 }
01485
01486
01487 else if ([self respondsToSelector:@selector(windowShouldClose:)] && ![self windowShouldClose:self])
01488 return;
01489
01490 [self close];
01491 }
01492
01497 - (void)close
01498 {
01499 [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowWillCloseNotification object:self];
01500
01501 [self orderOut:nil];
01502 }
01503
01504
01508 - (BOOL)isMainWindow
01509 {
01510 return [CPApp mainWindow] == self;
01511 }
01512
01516 - (BOOL)canBecomeMainWindow
01517 {
01518
01519 if ([self isVisible])
01520 return YES;
01521
01522 return NO;
01523 }
01524
01528 - (void)makeMainWindow
01529 {
01530 if (![self canBecomeMainWindow])
01531 return;
01532
01533 [CPApp._mainWindow resignMainWindow];
01534
01535 CPApp._mainWindow = self;
01536
01537 [self becomeMainWindow];
01538 }
01539
01543 - (void)becomeMainWindow
01544 {
01545 [self _synchronizeMenuBarTitleWithWindowTitle];
01546 [self _synchronizeSaveMenuWithDocumentSaving];
01547
01548 [[CPNotificationCenter defaultCenter]
01549 postNotificationName:CPWindowDidBecomeMainNotification
01550 object:self];
01551 }
01552
01556 - (void)resignMainWindow
01557 {
01558 [[CPNotificationCenter defaultCenter]
01559 postNotificationName:CPWindowDidResignMainNotification
01560 object:self];
01561 }
01562
01563
01567 - (CPToolbar)toolbar
01568 {
01569 return _toolbar;
01570 }
01571
01576 - (void)setToolbar:(CPToolbar)aToolbar
01577 {
01578 if (_toolbar === aToolbar)
01579 return;
01580
01581
01582 [[aToolbar _window] setToolbar:nil];
01583
01584
01585 [_toolbar _setWindow:nil];
01586
01587 _toolbar = aToolbar;
01588
01589
01590 [_toolbar _setWindow:self];
01591
01592 [self _noteToolbarChanged];
01593 }
01594
01595 - (void)toggleToolbarShown:(id)aSender
01596 {
01597 var toolbar = [self toolbar];
01598
01599 [toolbar setVisible:![toolbar isVisible]];
01600 }
01601
01602 - (void)_noteToolbarChanged
01603 {
01604 var frame = CGRectMakeCopy([self frame]),
01605 newFrame;
01606
01607 [_windowView noteToolbarChanged];
01608
01609 if (_isFullBridge)
01610 newFrame = [_bridge visibleFrame];
01611 else
01612 {
01613 newFrame = CGRectMakeCopy([self frame]);
01614
01615 newFrame.origin = frame.origin;
01616 }
01617
01618 [self setFrame:newFrame];
01619
01620
01621
01622
01623
01624
01625 }
01626
01627
01628 - (void)_setAttachedSheetFrameOrigin
01629 {
01630
01631 var contentRect = [[self contentView] frame],
01632 sheetFrame = CGRectMakeCopy([_attachedSheet frame]);
01633
01634 sheetFrame.origin.y = CGRectGetMinY(_frame) + CGRectGetMinY(contentRect);
01635 sheetFrame.origin.x = CGRectGetMinX(_frame) + FLOOR((CGRectGetWidth(_frame) - CGRectGetWidth(sheetFrame)) / 2.0);
01636
01637 [_attachedSheet setFrameOrigin:sheetFrame.origin];
01638 }
01639
01640
01641 - (void)_animateAttachedSheet
01642 {
01643
01644
01645
01646
01647
01648
01649
01650
01651
01652
01653
01654
01655
01656
01657
01658
01659
01660
01661
01662
01663 }
01664
01665
01666 - (void)_attachSheet:(CPWindow)aSheet modalDelegate:(id)aModalDelegate didEndSelector:(SEL)aDidEndSelector contextInfo:(id)aContextInfo
01667 {
01668
01669 _attachedSheet = aSheet;
01670
01671
01672 aSheet._isSheet = YES;
01673
01674 [self _setAttachedSheetFrameOrigin];
01675
01676
01677 [_bridge order:CPWindowAbove window:aSheet relativeTo:self];
01678 }
01679
01683 - (CPWindow)attachedSheet
01684 {
01685 return _attachedSheet;
01686 }
01687
01691 - (BOOL)isSheet
01692 {
01693 return _isSheet;
01694 }
01695
01696
01697
01698
01699
01700
01701 - (BOOL)becomesKeyOnlyIfNeeded
01702 {
01703 return NO;
01704 }
01705
01710 - (BOOL)worksWhenModal
01711 {
01712 return NO;
01713 }
01714
01715 - (void)keyDown:(CPEvent)event
01716 {
01717 if (![self performKeyEquivalent:event])
01718 [self interpretKeyEvents:[event]];
01719 }
01720
01721 - (void)insertNewline:(id)sender
01722 {
01723 if (_defaultButton && _defaultButtonEnabled)
01724 [_defaultButton performClick:nil];
01725 }
01726
01727 - (void)insertTab:(id)sender
01728 {
01729 [self selectNextKeyView:nil];
01730 }
01731
01732 - (void)_dirtyKeyViewLoop
01733 {
01734 if (_autorecalculatesKeyViewLoop)
01735 _keyViewLoopIsDirty = YES;
01736 }
01737
01738 - (BOOL)_hasKeyViewLoop
01739 {
01740 var subviews = [];
01741
01742 [self _appendSubviewsOf:_contentView toArray:subviews];
01743
01744 for (var i = 0, count = [subviews count]; i<count; i++)
01745 {
01746 if (subviews[i]._nextKeyView)
01747 return YES;
01748 }
01749
01750 return NO;
01751 }
01752
01753 - (void)recalculateKeyViewLoop
01754 {
01755 var subviews = [];
01756
01757 [self _appendSubviewsOf:_contentView toArray:subviews];
01758
01759 var keyViewOrder = [subviews sortedArrayUsingFunction:keyViewComparator context:_contentView],
01760 count = [keyViewOrder count];
01761
01762 for (var i=0; i<count; i++)
01763 [keyViewOrder[i] setNextKeyView:keyViewOrder[(i+1)%count]];
01764
01765 _keyViewLoopIsDirty = NO;
01766 }
01767
01768 - (void)_appendSubviewsOf:(CPView)aView toArray:(CPArray)anArray
01769 {
01770 var subviews = [aView subviews],
01771 count = [subviews count];
01772
01773 while (count--)
01774 [self _appendSubviewsOf:subviews[count] toArray:anArray];
01775
01776 [anArray addObject:aView];
01777 }
01778
01779 - (void)setAutorecalculatesKeyViewLoop:(BOOL)shouldRecalculate
01780 {
01781 if (_autorecalculatesKeyViewLoop === shouldRecalculate)
01782 return;
01783
01784 _autorecalculatesKeyViewLoop = shouldRecalculate;
01785
01786 [self _dirtyKeyViewLoop];
01787 }
01788
01789 - (BOOL)autorecalculatesKeyViewLoop
01790 {
01791 return _autorecalculatesKeyViewLoop;
01792 }
01793
01794 - (void)selectNextKeyView:(id)sender
01795 {
01796 if ([_firstResponder isKindOfClass:[CPView class]])
01797 [self selectKeyViewFollowingView:_firstResponder];
01798 }
01799
01800 - (void)selectPreviousKeyView:(id)sender
01801 {
01802 if ([_firstResponder isKindOfClass:[CPView class]])
01803 [self selectKeyViewPrecedingView:_firstResponder];
01804 }
01805
01806 - (void)selectKeyViewFollowingView:(CPView)aView
01807 {
01808 if (_keyViewLoopIsDirty)
01809 [self recalculateKeyViewLoop];
01810
01811 [self makeFirstResponder:[aView nextValidKeyView]];
01812 }
01813
01814 - (void)selectKeyViewPrecedingView:(CPView)aView
01815 {
01816 if (_keyViewLoopIsDirty)
01817 [self recalculateKeyViewLoop];
01818
01819 [self makeFirstResponder:[aView previousValidKeyView]];
01820 }
01821
01822 - (void)setDefaultButtonCell:(CPButton)aButton
01823 {
01824 [self setDefaultButton:aButton];
01825 }
01826
01827 - (CPButton)defaultButtonCell
01828 {
01829 return [self defaultButton];
01830 }
01831
01832 - (void)setDefaultButton:(CPButton)aButton
01833 {
01834 [_defaultButton setDefaultButton:NO];
01835
01836 _defaultButton = aButton;
01837
01838 [_defaultButton setDefaultButton:YES];
01839 }
01840
01841 - (CPButton)defaultButton
01842 {
01843 return _defaultButton;
01844 }
01845
01846 - (void)enableKeyEquivalentForDefaultButton
01847 {
01848 _defaultButtonEnabled = YES;
01849 }
01850
01851 - (void)enableKeyEquivalentForDefaultButtonCell
01852 {
01853 [self enableKeyEquivalentForDefaultButton];
01854 }
01855
01856 - (void)disableKeyEquivalentForDefaultButton
01857 {
01858 _defaultButtonEnabled = NO;
01859 }
01860
01861 - (void)disableKeyEquivalentForDefaultButtonCell
01862 {
01863 [self disableKeyEquivalentForDefaultButton];
01864 }
01865
01866 @end
01867
01868 var keyViewComparator = function(a, b, context)
01869 {
01870 var viewBounds = [a convertRect:[a bounds] toView:nil],
01871 otherBounds = [b convertRect:[b bounds] toView:nil];
01872
01873 if (CGRectGetMinY(viewBounds) < CGRectGetMinY(otherBounds))
01874 return -1;
01875 else if (CGRectGetMinY(viewBounds) == CGRectGetMinY(otherBounds) && CGRectGetMinX(viewBounds) < CGRectGetMinX(otherBounds))
01876 return -1;
01877 else if (CGRectGetMinX(viewBounds) == CGRectGetMinX(otherBounds) && CGRectGetMinX(viewBounds) == CGRectGetMinX(otherBounds))
01878 return 0;
01879 else
01880 return 1;
01881 }
01882
01883 @implementation CPWindow (MenuBar)
01884
01885 - (void)_synchronizeMenuBarTitleWithWindowTitle
01886 {
01887
01888 if (![_windowController document] || ![self isMainWindow])
01889 return;
01890
01891 [CPMenu setMenuBarTitle:_title];
01892 }
01893
01894 @end
01895
01896 @implementation CPWindow (BridgeSupport)
01897
01898
01899
01900
01901
01902 - (void)setBridge:(CPDOMWindowBridge)aBridge
01903 {
01904 if (_bridge == aBridge)
01905 return;
01906
01907 if (_bridge)
01908 {
01909 [self orderOut:self];
01910
01911 }
01912
01913 _bridge = aBridge;
01914
01915 if ([self isFullBridge])
01916 [self setFrame:[aBridge contentBounds]];
01917 }
01918
01919
01920
01921
01922 - (void)resizeWithOldBridgeSize:(CGSize)aSize
01923 {
01924 if ([self isFullBridge])
01925 return [self setFrame:[_bridge visibleFrame]];
01926
01927 if (_autoresizingMask == CPWindowNotSizable)
01928 return;
01929
01930 var frame = [_bridge contentBounds],
01931 newFrame = CGRectMakeCopy(_frame),
01932 dX = (CGRectGetWidth(frame) - aSize.width) /
01933 (((_autoresizingMask & CPWindowMinXMargin) ? 1 : 0) + (_autoresizingMask & CPWindowWidthSizable ? 1 : 0) + (_autoresizingMask & CPWindowMaxXMargin ? 1 : 0)),
01934 dY = (CGRectGetHeight(frame) - aSize.height) /
01935 ((_autoresizingMask & CPWindowMinYMargin ? 1 : 0) + (_autoresizingMask & CPWindowHeightSizable ? 1 : 0) + (_autoresizingMask & CPWindowMaxYMargin ? 1 : 0));
01936
01937 if (_autoresizingMask & CPWindowMinXMargin)
01938 newFrame.origin.x += dX;
01939 if (_autoresizingMask & CPWindowWidthSizable)
01940 newFrame.size.width += dX;
01941
01942 if (_autoresizingMask & CPWindowMinYMargin)
01943 newFrame.origin.y += dY;
01944 if (_autoresizingMask & CPWindowHeightSizable)
01945 newFrame.size.height += dY;
01946
01947 [self setFrame:newFrame];
01948 }
01949
01950
01951
01952
01953 - (void)setAutoresizingMask:(unsigned)anAutoresizingMask
01954 {
01955 _autoresizingMask = anAutoresizingMask;
01956 }
01957
01958
01959
01960
01961 - (unsigned)autoresizingMask
01962 {
01963 return _autoresizingMask;
01964 }
01965
01966
01967
01968
01969 - (CGPoint)convertBaseToBridge:(CGPoint)aPoint
01970 {
01971 var origin = [self frame].origin;
01972
01973 return CGPointMake(aPoint.x + origin.x, aPoint.y + origin.y);
01974 }
01975
01976
01977
01978
01979 - (CGPoint)convertBridgeToBase:(CGPoint)aPoint
01980 {
01981 var origin = [self frame].origin;
01982
01983 return CGPointMake(aPoint.x - origin.x, aPoint.y - origin.y);
01984 }
01985
01986
01990 - (CPUndoManager)undoManager
01991 {
01992 if (_delegateRespondsToWindowWillReturnUndoManagerSelector)
01993 return [_delegate windowWillReturnUndoManager:self];
01994
01995 if (!_undoManager)
01996 _undoManager = [[CPUndoManager alloc] init];
01997
01998 return _undoManager;
01999 }
02000
02005 - (void)undo:(id)aSender
02006 {
02007 [[self undoManager] undo];
02008 }
02009
02014 - (void)redo:(id)aSender
02015 {
02016 [[self undoManager] redo];
02017 }
02018
02019 - (BOOL)containsPoint:(CGPoint)aPoint
02020 {
02021 return CGRectContainsPoint(_frame, aPoint);
02022 }
02023
02024 @end
02025
02026 var interpolate = function(fromValue, toValue, progress)
02027 {
02028 return fromValue + (toValue - fromValue) * progress;
02029 }
02030
02031
02032 @implementation _CPWindowFrameAnimation : CPAnimation
02033 {
02034 CPWindow _window;
02035
02036 CGRect _startFrame;
02037 CGRect _targetFrame;
02038 }
02039
02040 - (id)initWithWindow:(CPWindow)aWindow targetFrame:(CGRect)aTargetFrame
02041 {
02042 self = [super initWithDuration:0.2 animationCurve:CPAnimationLinear];
02043
02044 if (self)
02045 {
02046 _window = aWindow;
02047
02048 _targetFrame = CGRectMakeCopy(aTargetFrame);
02049 _startFrame = CGRectMakeCopy([_window frame]);
02050 }
02051
02052 return self;
02053 }
02054
02055 - (void)startAnimation
02056 {
02057 [super startAnimation];
02058
02059 _window._isAnimating = YES;
02060 }
02061
02062 - (void)setCurrentProgress:(float)aProgress
02063 {
02064 [super setCurrentProgress:aProgress];
02065
02066 var value = [self currentValue];
02067
02068 if (value == 1.0)
02069 _window._isAnimating = NO;
02070
02071 [_window setFrameOrigin:CGPointMake(interpolate(CGRectGetMinX(_startFrame), CGRectGetMinX(_targetFrame), value), interpolate(CGRectGetMinY(_startFrame), CGRectGetMinY(_targetFrame), value))];
02072 [_window setFrameSize:CGSizeMake(interpolate(CGRectGetWidth(_startFrame), CGRectGetWidth(_targetFrame), value), interpolate(CGRectGetHeight(_startFrame), CGRectGetHeight(_targetFrame), value))];
02073 }
02074
02075 @end
02076
02077 function _CPWindowFullBridgeSessionMake(aWindowView, aContentRect, hasShadow, aLevel)
02078 {
02079 return { windowView:aWindowView, contentRect:aContentRect, hasShadow:hasShadow, level:aLevel };
02080 }
02081
02082 @import "_CPWindowView.j"
02083 @import "_CPStandardWindowView.j"
02084 @import "_CPHUDWindowView.j"
02085 @import "_CPBorderlessWindowView.j"
02086 @import "_CPBorderlessBridgeWindowView.j"
02087 @import "CPDragServer.j"
02088 @import "CPDOMWindowBridge.j"
02089 @import "CPView.j"