mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-30 18:32:03 +00:00
Merge pull request #1915 from Dogild/PopUpListComboBox
Fixed: CPComboBox popupList should close if mouse is clicked outside
This commit is contained in:
commit
1aa0956b4d
1 file changed
+27
@@ -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,28 @@ 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];
|
||||
else 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
|
||||
Reference in new issue
Block a user