From 4841f209b368859a46b189ab24331b3e6c436d42 Mon Sep 17 00:00:00 2001 From: Antoine Mercadal Date: Wed, 2 Nov 2011 11:59:20 +0100 Subject: [PATCH 1/8] fix delegate methods not sent in transient mode when closing --- AppKit/CPPopover.j | 15 +++++++++++++++ AppKit/_CPAttachedWindow.j | 8 +++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/AppKit/CPPopover.j b/AppKit/CPPopover.j index a99a16543..689249477 100644 --- a/AppKit/CPPopover.j +++ b/AppKit/CPPopover.j @@ -221,6 +221,7 @@ var CPPopoverDelegate_popover_willShow_ = 1 << 0, [_attachedWindow setAppearance:_appearance]; [_attachedWindow setAnimates:_animates]; + [_attachedWindow setDelegate:self]; [_attachedWindow setMovableByWindowBackground:NO]; [_attachedWindow setFrame:[_attachedWindow frameRectForContentRect:[[_contentViewController view] frame]]]; [_attachedWindow setContentView:[_contentViewController view]]; @@ -268,6 +269,20 @@ var CPPopoverDelegate_popover_willShow_ = 1 << 0, [self close]; } + +#pragma mark - +#pragma mark Delegates + +/*! @ignore */ +- (BOOL)didAttachedWindowShouldClose:(_CPAttachedWindow)anAttachedWindow +{ + [self close]; + + // we return NO, because we want the CPPopover to compute + // if the attached can be close in order to send delegate messages + return NO; +} + @end diff --git a/AppKit/_CPAttachedWindow.j b/AppKit/_CPAttachedWindow.j index 70126b632..d0994fc98 100644 --- a/AppKit/_CPAttachedWindow.j +++ b/AppKit/_CPAttachedWindow.j @@ -410,10 +410,12 @@ CPPopoverAppearanceHUD = 1; { // set a close flag to avoid infinite loop _isClosed = YES; - [self close]; - if (_delegate && [_delegate respondsToSelector:@selector(didAttachedWindowClose:)]) - [_delegate didAttachedWindowClose:self]; + if (_delegate && [_delegate respondsToSelector:@selector(didAttachedWindowShouldClose:)]) + if ([_delegate didAttachedWindowShouldClose:self]) + [self close]; + else + [self close]; } } From 06985a5b6cbbbe06ac7abfe1290c8c2013e1b50b Mon Sep 17 00:00:00 2001 From: Antoine Mercadal Date: Wed, 2 Nov 2011 12:06:05 +0100 Subject: [PATCH 2/8] fix test --- AppKit/_CPAttachedWindow.j | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/AppKit/_CPAttachedWindow.j b/AppKit/_CPAttachedWindow.j index d0994fc98..0759ac4cb 100644 --- a/AppKit/_CPAttachedWindow.j +++ b/AppKit/_CPAttachedWindow.j @@ -408,14 +408,9 @@ CPPopoverAppearanceHUD = 1; { if (_closeOnBlur && !_isClosed) { - // set a close flag to avoid infinite loop - _isClosed = YES; - - if (_delegate && [_delegate respondsToSelector:@selector(didAttachedWindowShouldClose:)]) - if ([_delegate didAttachedWindowShouldClose:self]) - [self close]; - else - [self close]; + if (!_delegate || ([_delegate respondsToSelector:@selector(didAttachedWindowShouldClose:)] + && [_delegate didAttachedWindowShouldClose:self])) + [self close]; } } @@ -480,6 +475,9 @@ CPPopoverAppearanceHUD = 1; */ - (void)close { + // set a close flag to avoid infinite loop + _isClosed = YES; + if (_animates && typeof(_DOMElement.style.WebkitTransform) != "undefined") { _DOMElement.style.opacity = 0; From ddb6f63ea7c7528d7557d6cf61ae0f4cd04905ca Mon Sep 17 00:00:00 2001 From: Antoine Mercadal Date: Wed, 2 Nov 2011 15:55:58 +0100 Subject: [PATCH 3/8] use coherent delegate name --- AppKit/CPPopover.j | 2 +- AppKit/_CPAttachedWindow.j | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/AppKit/CPPopover.j b/AppKit/CPPopover.j index 689249477..c3d664707 100644 --- a/AppKit/CPPopover.j +++ b/AppKit/CPPopover.j @@ -274,7 +274,7 @@ var CPPopoverDelegate_popover_willShow_ = 1 << 0, #pragma mark Delegates /*! @ignore */ -- (BOOL)didAttachedWindowShouldClose:(_CPAttachedWindow)anAttachedWindow +- (BOOL)attachedWindowShouldClose:(_CPAttachedWindow)anAttachedWindow { [self close]; diff --git a/AppKit/_CPAttachedWindow.j b/AppKit/_CPAttachedWindow.j index 0759ac4cb..54dd524eb 100644 --- a/AppKit/_CPAttachedWindow.j +++ b/AppKit/_CPAttachedWindow.j @@ -408,8 +408,8 @@ CPPopoverAppearanceHUD = 1; { if (_closeOnBlur && !_isClosed) { - if (!_delegate || ([_delegate respondsToSelector:@selector(didAttachedWindowShouldClose:)] - && [_delegate didAttachedWindowShouldClose:self])) + if (!_delegate || ([_delegate respondsToSelector:@selector(attachedWindowShouldClose:)] + && [_delegate attachedWindowShouldClose:self])) [self close]; } } From 4303ea358482ec4af373929c072de3f122162814 Mon Sep 17 00:00:00 2001 From: Antoine Mercadal Date: Wed, 2 Nov 2011 16:59:34 +0100 Subject: [PATCH 4/8] cache delegates methods for _CPAttachedView --- AppKit/CPPopover.j | 2 +- AppKit/_CPAttachedWindow.j | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/AppKit/CPPopover.j b/AppKit/CPPopover.j index c3d664707..37f353019 100644 --- a/AppKit/CPPopover.j +++ b/AppKit/CPPopover.j @@ -39,7 +39,7 @@ CPPopoverBehaviorSemitransient = 2; var CPPopoverDelegate_popover_willShow_ = 1 << 0, CPPopoverDelegate_popover_didShow_ = 1 << 1, CPPopoverDelegate_popover_shouldClose_ = 1 << 2, - CPPopoverDelegate_popover_willClose_ = 1 << 3, + CPPopoverDelegate_popover_willClose_ = 1 << 3, CPPopoverDelegate_popover_didClose_ = 1 << 4; diff --git a/AppKit/_CPAttachedWindow.j b/AppKit/_CPAttachedWindow.j index 54dd524eb..34b953509 100644 --- a/AppKit/_CPAttachedWindow.j +++ b/AppKit/_CPAttachedWindow.j @@ -30,6 +30,9 @@ CPClosableOnBlurWindowMask = 1 << 4; CPPopoverAppearanceMinimal = 0; CPPopoverAppearanceHUD = 1; +var _CPAttachedWindow_attachedWindowShouldClose_ = 1 << 0, + _CPAttachedWindow_didAttachedWindowClose_ = 1 << 1; + /*! @ignore @@ -48,6 +51,7 @@ CPPopoverAppearanceHUD = 1; BOOL _shouldPerformAnimation; CPButton _closeButton; float _animationDuration; + CPInteger _implementedDelegateMethods; } /*! @@ -153,6 +157,21 @@ CPPopoverAppearanceHUD = 1; [_windowView setAppearance:anAppearance]; } +- (void)setDelegate:(id)aDelegate +{ + if (_delegate == aDelegate) + return; + + _delegate = aDelegate; + _implementedDelegateMethods = 0; + + if ([_delegate respondsToSelector:@selector(attachedWindowShouldClose:)]) + _implementedDelegateMethods |= _CPAttachedWindow_attachedWindowShouldClose_; + + if ([_delegate respondsToSelector:@selector(didAttachedWindowClose:)]) + _implementedDelegateMethods |= _CPAttachedWindow_didAttachedWindowClose_; +} + #pragma mark - #pragma mark Observer @@ -408,7 +427,7 @@ CPPopoverAppearanceHUD = 1; { if (_closeOnBlur && !_isClosed) { - if (!_delegate || ([_delegate respondsToSelector:@selector(attachedWindowShouldClose:)] + if (!_delegate || ((_implementedDelegateMethods & _CPAttachedWindow_attachedWindowShouldClose_) && [_delegate attachedWindowShouldClose:self])) [self close]; } @@ -494,7 +513,7 @@ CPPopoverAppearanceHUD = 1; _shouldPerformAnimation = _animates; - if (_delegate && [_delegate respondsToSelector:@selector(didAttachedWindowClose:)]) + if (_implementedDelegateMethods & _CPAttachedWindow_didAttachedWindowClose_) [_delegate didAttachedWindowClose:self]; } From 8ed2096de70d7a74b75f1848725af9397e691810 Mon Sep 17 00:00:00 2001 From: Antoine Mercadal Date: Thu, 3 Nov 2011 23:14:44 +0100 Subject: [PATCH 5/8] update weird delegate name --- AppKit/_CPAttachedWindow.j | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/AppKit/_CPAttachedWindow.j b/AppKit/_CPAttachedWindow.j index 34b953509..ad69465ef 100644 --- a/AppKit/_CPAttachedWindow.j +++ b/AppKit/_CPAttachedWindow.j @@ -31,7 +31,7 @@ CPPopoverAppearanceMinimal = 0; CPPopoverAppearanceHUD = 1; var _CPAttachedWindow_attachedWindowShouldClose_ = 1 << 0, - _CPAttachedWindow_didAttachedWindowClose_ = 1 << 1; + _CPAttachedWindow_attachedWindowDidClose_ = 1 << 1; /*! @@ -168,8 +168,8 @@ var _CPAttachedWindow_attachedWindowShouldClose_ = 1 << 0, if ([_delegate respondsToSelector:@selector(attachedWindowShouldClose:)]) _implementedDelegateMethods |= _CPAttachedWindow_attachedWindowShouldClose_; - if ([_delegate respondsToSelector:@selector(didAttachedWindowClose:)]) - _implementedDelegateMethods |= _CPAttachedWindow_didAttachedWindowClose_; + if ([_delegate respondsToSelector:@selector(attachedWindowDidClose:)]) + _implementedDelegateMethods |= _CPAttachedWindow_attachedWindowDidClose_; } #pragma mark - @@ -513,8 +513,8 @@ var _CPAttachedWindow_attachedWindowShouldClose_ = 1 << 0, _shouldPerformAnimation = _animates; - if (_implementedDelegateMethods & _CPAttachedWindow_didAttachedWindowClose_) - [_delegate didAttachedWindowClose:self]; + if (_implementedDelegateMethods & _CPAttachedWindow_attachedWindowDidClose_) + [_delegate attachedWindowDidClose:self]; } @end From 9848dabfa87a60d5dcad5810d3750ae220d98311 Mon Sep 17 00:00:00 2001 From: Randall Luecke Date: Fri, 4 Nov 2011 01:28:43 -0400 Subject: [PATCH 6/8] Fix typo in popover error. --- AppKit/CPPopover.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AppKit/CPPopover.j b/AppKit/CPPopover.j index 37f353019..0daffeef6 100644 --- a/AppKit/CPPopover.j +++ b/AppKit/CPPopover.j @@ -231,7 +231,7 @@ var CPPopoverDelegate_popover_willShow_ = 1 << 0, else if (positioningView) [_attachedWindow positionRelativeToView:positioningView preferredEdge:preferredEdge]; else - [CPException raise:CPInvalidArgumentException reason:@"you must set positioningRect or positioningRect"]; + [CPException raise:CPInvalidArgumentException reason:@"you must set positioningRect or positioningView"]; if (_implementedDelegateMethods & CPPopoverDelegate_popover_didShow_) [_delegate popoverDidShow:self]; From 543f91dd6e4c90c2c1cb6194eb577542d7b45514 Mon Sep 17 00:00:00 2001 From: Aparajita Fishman Date: Fri, 4 Nov 2011 12:09:07 -0700 Subject: [PATCH 7/8] Fixed typos and error message --- AppKit/CPPopover.j | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/AppKit/CPPopover.j b/AppKit/CPPopover.j index 0daffeef6..39e8309bd 100644 --- a/AppKit/CPPopover.j +++ b/AppKit/CPPopover.j @@ -103,7 +103,7 @@ var CPPopoverDelegate_popover_willShow_ = 1 << 0, @return CPRect represeting the frame of the popover */ -- (CPRect)positionningRect +- (CPRect)positioningRect { if (!_attachedWindow || ![_attachedWindow isVisible]) return nil; @@ -113,7 +113,7 @@ var CPPopoverDelegate_popover_willShow_ = 1 << 0, /*! Sets the frame of the popover @param aRect the desired frame */ -- (void)setPositionningRect:(CPRect)aRect +- (void)setPositioningRect:(CPRect)aRect { if (!_attachedWindow || ![_attachedWindow isVisible]) return; @@ -196,14 +196,14 @@ var CPPopoverDelegate_popover_willShow_ = 1 << 0, } #pragma mark - -#pragma mark Positionning +#pragma mark Positioning /*! Show the popover @param positioningRect if set, the popover will be positionned to a random rect relative to the window @param positioningView if set, the popover will be positioned relative to this view - @param preferredEdge: CPRectEdge representing the prefered positionning. + @param preferredEdge: CPRectEdge representing the preferred positioning. */ - (void)showRelativeToRect:(CPRect)positioningRect ofView:(CPView)positioningView preferredEdge:(CPRectEdge)preferredEdge { @@ -231,7 +231,7 @@ var CPPopoverDelegate_popover_willShow_ = 1 << 0, else if (positioningView) [_attachedWindow positionRelativeToView:positioningView preferredEdge:preferredEdge]; else - [CPException raise:CPInvalidArgumentException reason:@"you must set positioningRect or positioningView"]; + [CPException raise:CPInvalidArgumentException reason:@"a value must be passed for positioningRect or positioningView"]; if (_implementedDelegateMethods & CPPopoverDelegate_popover_didShow_) [_delegate popoverDidShow:self]; @@ -316,4 +316,4 @@ var CPPopoverDelegate_popover_willShow_ = 1 << 0, [aCoder encodeObject:_animates forKey:@"_animates"]; } -@end \ No newline at end of file +@end From d524accc98411cb61d895ba87ff437aaf0e7b027 Mon Sep 17 00:00:00 2001 From: Aparajita Fishman Date: Fri, 4 Nov 2011 12:50:00 -0700 Subject: [PATCH 8/8] Fix typo, unintended globals, use constants for CPCoding keys --- AppKit/CPPopover.j | 32 +++++++++++++++----------- Tests/Manual/CPPopover/AppController.j | 10 ++++---- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/AppKit/CPPopover.j b/AppKit/CPPopover.j index 39e8309bd..6d0f06cce 100644 --- a/AppKit/CPPopover.j +++ b/AppKit/CPPopover.j @@ -73,7 +73,7 @@ var CPPopoverDelegate_popover_willShow_ = 1 << 0, #pragma mark - -#pragma mark INitialization +#pragma mark Initialization /*! Initialize the CPPopover witn default values @@ -285,6 +285,12 @@ var CPPopoverDelegate_popover_willShow_ = 1 << 0, @end +var CPPopoverNeedsComputeKey = @"CPPopoverNeedsComputeKey", + CPPopoverAppearanceKey = @"CPPopoverAppearanceKey", + CPPopoverAnimatesKey = @"CPPopoverAnimatesKey", + CPPopoverContentViewControllerKey = @"CPPopoverContentViewControllerKey", + CPPopoverDelegateKey = @"CPPopoverDelegateKey", + CPPopoverBehaviorKey = @"CPPopoverBehaviorKey"; @implementation CPPopover (CPCoding) @@ -294,12 +300,12 @@ var CPPopoverDelegate_popover_willShow_ = 1 << 0, if (self) { - _needsCompute = [aCoder decodeIntForKey:@"_needsCompute"]; - _appearance = [aCoder decodeIntForKey:@"_appearance"]; - _animates = [aCoder decodeBoolForKey:@"_animates"]; - _contentViewController = [aCoder decodeObjectForKey:@"_contentViewController"]; - [self setDelegate:[aCoder decodeObjectForKey:@"_delegate"]]; - [self setBehaviour:[aCoder decodeIntForKey:@"_behavior"]]; + _needsCompute = [aCoder decodeIntForKey:CPPopoverNeedsComputeKey]; + _appearance = [aCoder decodeIntForKey:CPPopoverAppearanceKey]; + _animates = [aCoder decodeBoolForKey:CPPopoverAnimatesKey]; + _contentViewController = [aCoder decodeObjectForKey:CPPopoverContentViewControllerKey]; + [self setDelegate:[aCoder decodeObjectForKey:CPPopoverDelegateKey]]; + [self setBehaviour:[aCoder decodeIntForKey:CPPopoverBehaviorKey]]; } return self; } @@ -308,12 +314,12 @@ var CPPopoverDelegate_popover_willShow_ = 1 << 0, { [super encodeWithCoder:aCoder]; - [aCoder encodeInt:_behavior forKey:@"_behavior"]; - [aCoder encodeInt:_appearance forKey:@"_appearance"]; - [aCoder encodeBool:_needsCompute forKey:@"_needsCompute"]; - [aCoder encodeObject:_contentViewController forKey:@"_contentViewController"]; - [aCoder encodeObject:_delegate forKey:@"_delegate"]; - [aCoder encodeObject:_animates forKey:@"_animates"]; + [aCoder encodeBool:_needsCompute forKey:CPPopoverNeedsComputeKey]; + [aCoder encodeInt:_appearance forKey:CPPopoverAppearanceKey]; + [aCoder encodeObject:_animates forKey:CPPopoverAnimatesKey]; + [aCoder encodeObject:_contentViewController forKey:CPPopoverContentViewControllerKey]; + [aCoder encodeObject:_delegate forKey:CPPopoverDelegateKey]; + [aCoder encodeInt:_behavior forKey:CPPopoverBehaviorKey]; } @end diff --git a/Tests/Manual/CPPopover/AppController.j b/Tests/Manual/CPPopover/AppController.j index 722aa6489..bb3175f7a 100644 --- a/Tests/Manual/CPPopover/AppController.j +++ b/Tests/Manual/CPPopover/AppController.j @@ -84,7 +84,7 @@ - (IBAction)open:(id)sender { var g; - switch([buttonGravity title]) + switch ([buttonGravity title]) { case "Automatic": g = nil; @@ -104,7 +104,7 @@ } var a; - switch([buttonStyle title]) + switch ([buttonStyle title]) { case "Minimal": a = CPPopoverAppearanceMinimal; @@ -115,7 +115,7 @@ } var p = [[CPPopover alloc] init], - viewC = [[CPViewController alloc] init]; + viewC = [[CPViewController alloc] init], view = [[CPView alloc] initWithFrame:CPRectMake(0.0, 0.0, 320, 300)], label = [CPTextField labelWithTitle:[buttonGravity title]]; @@ -136,8 +136,8 @@ [p setDelegate:self]; [p showRelativeToRect:nil ofView:sender preferredEdge:g]; CPLog.info("content size - w:" + [p contentSize].width + " h:" + [p contentSize].width); - CPLog.info("positionning rect - x: " + [p positionningRect].origin.x + " y: " + [p positionningRect].origin.x - + " w:" + [p positionningRect].size.width + " h:" + [p positionningRect].size.width); + CPLog.info("positioning rect - x: " + [p positioningRect].origin.x + " y: " + [p positioningRect].origin.x + + " w:" + [p positioningRect].size.width + " h:" + [p positioningRect].size.width); }