From 056a00e54ef4d5f577e05a97fc252af2fdea0100 Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Wed, 24 Apr 2013 00:33:56 -0700 Subject: [PATCH] Fixed: CPComboBox popupList should close if mouse is clicked outside of the control Previously the list of the CPComboBox didn't close when clicking outside of the control Now the list has the same behavior as Cocoa Fixes #1859 --- AppKit/_CPPopUpList.j | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/AppKit/_CPPopUpList.j b/AppKit/_CPPopUpList.j index 2dfbce85e..508490ccb 100644 --- a/AppKit/_CPPopUpList.j +++ b/AppKit/_CPPopUpList.j @@ -26,6 +26,7 @@ @import "_CPPopUpListDataSource.j" @class CPScrollView +@class CPApp @global CPLineBorder @@ -857,6 +858,8 @@ var _CPPopUpListDataSourceKey = @"_CPPopUpListDataSourceKey", if (self = [super initWithContentRect:aContentRect styleMask:aStyleMask]) _constrainsToUsableScreen = NO; + [self _trapNextMouseDown]; + return self; } @@ -870,4 +873,29 @@ var _CPPopUpListDataSourceKey = @"_CPPopUpListDataSourceKey", return [super sendEvent:anEvent]; } +- (void)orderFront:(id)sender +{ + [self _trapNextMouseDown]; + [super orderFront:sender]; +} + +- (void)_mouseWasClicked:(CPEvent)anEvent +{ + var mouseWindow = [anEvent window], + rect = [[[self delegate] dataSource] bounds], + point = [[[self delegate] dataSource] convertPoint:[anEvent locationInWindow] fromView:nil]; + + if (mouseWindow != self && !CGRectContainsPoint(rect, point)) + [[self delegate] close]; + + if ([mouseWindow firstResponder] == [[self delegate] dataSource]) + [self _trapNextMouseDown]; +} + +- (void)_trapNextMouseDown +{ + // Don't dequeue the event so clicks in controls will work + [CPApp setTarget:self selector:@selector(_mouseWasClicked:) forNextEventMatchingMask:CPLeftMouseDownMask untilDate:nil inMode:CPDefaultRunLoopMode dequeue:NO]; +} + @end