From 31ab70d6fca4c1a75e9c4e92ebcef99fc26c2d8f Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Wed, 1 Aug 2012 18:58:35 +0100 Subject: [PATCH] Refs #1530. Fixed: table views could not be interacted with if they couldn't become the first responder. --- AppKit/CPTableView.j | 7 +-- Tests/AppKit/CPTableViewTest.j | 48 ++++++++++++++----- .../Manual/TableTest/OldTest/AppController.j | 26 ++++++++-- 3 files changed, 59 insertions(+), 22 deletions(-) diff --git a/AppKit/CPTableView.j b/AppKit/CPTableView.j index 61045d64e..8d8361921 100644 --- a/AppKit/CPTableView.j +++ b/AppKit/CPTableView.j @@ -4037,8 +4037,8 @@ Your delegate can implement this method to avoid subclassing the tableview to ad */ - (BOOL)startTrackingAt:(CGPoint)aPoint { - if (![[self window] makeFirstResponder:self]) - return NO; + // Try to become the first responder, but if we can't, that's okay. + [[self window] makeFirstResponder:self]; var row = [self rowAtPoint:aPoint]; @@ -4189,9 +4189,6 @@ Your delegate can implement this method to avoid subclassing the tableview to ad */ - (void)stopTracking:(CGPoint)lastPoint at:(CGPoint)aPoint mouseIsUp:(BOOL)mouseIsUp { - if ([[self window] firstResponder] !== self) - return; - _isSelectingSession = NO; var CLICK_TIME_DELTA = 1000, diff --git a/Tests/AppKit/CPTableViewTest.j b/Tests/AppKit/CPTableViewTest.j index e07a63664..a65de663f 100644 --- a/Tests/AppKit/CPTableViewTest.j +++ b/Tests/AppKit/CPTableViewTest.j @@ -4,6 +4,7 @@ @implementation CPTableViewTest : OJTestCase { + CPWindow theWindow; CPTableView tableView; CPTableColumn tableColumn; @@ -15,19 +16,21 @@ - (void)setUp { // setup a reasonable table - tableView = [[CPTableView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; + theWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(0.0, 0.0, 1024.0, 768.0) + styleMask:CPWindowNotSizable]; + + tableView = [[FirstResponderConfigurableTableView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; tableColumn = [[CPTableColumn alloc] initWithIdentifier:@"Foo"]; + tableView.acceptsFirstResponder = YES; [tableView addTableColumn:tableColumn]; + + [[theWindow contentView] addSubview:tableView]; } - (void)testDoubleAction { doubleActionReceived = NO; - var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(0.0, 0.0, 1024.0, 768.0) - styleMask:CPWindowNotSizable]; - [[theWindow contentView] addSubview:tableView]; - [tableView setTarget:self]; [tableView setDoubleAction:@selector(doubleAction:)]; @@ -44,6 +47,20 @@ [tableView trackMouse:dblClkUp]; [self assertTrue:doubleActionReceived]; + + // The event should also work even if the table is not the first responder. + tableView.acceptsFirstResponder = NO; + [theWindow makeFirstResponder:nil]; + + doubleActionReceived = NO; + + [[CPApplication sharedApplication] sendEvent:dblClkDown]; + [tableView trackMouse:dblClkDown]; + + [[CPApplication sharedApplication] sendEvent:dblClkUp]; + [tableView trackMouse:dblClkUp]; + + [self assertTrue:doubleActionReceived]; } - (void)doubleAction:(id)sender @@ -124,11 +141,6 @@ */ - (void)testEditCell { - var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(0, 0, 200, 150) - styleMask:CPWindowNotSizable]; - - [[theWindow contentView] addSubview:tableView]; - var dataSource = [TestDataSource new]; [dataSource setTableEntries:["A", "B", "C"]]; @@ -230,9 +242,7 @@ - (void)testContentBinding { - var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(0, 0, 200, 150) - styleMask:CPWindowNotSizable], - contentBindingTable = [[CPTableView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)], + var contentBindingTable = [[CPTableView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)], tableColumn = [[CPTableColumn alloc] initWithIdentifier:@"A"], delegate = [ContentBindingTableDelegate new]; @@ -259,6 +269,18 @@ @end +@implementation FirstResponderConfigurableTableView : CPTableView +{ + BOOL acceptsFirstResponder; +} + +- (BOOL)acceptsFirstResponder +{ + return acceptsFirstResponder; +} + +@end + @implementation TestDataSource : CPObject { CPArray tableEntries @accessors; diff --git a/Tests/Manual/TableTest/OldTest/AppController.j b/Tests/Manual/TableTest/OldTest/AppController.j index a1ba38639..901a9bafd 100644 --- a/Tests/Manual/TableTest/OldTest/AppController.j +++ b/Tests/Manual/TableTest/OldTest/AppController.j @@ -10,6 +10,7 @@ tableTestDragType = @"CPTableViewTestDragType"; CPImage iconImage; CPArray dataSet1; CPArray dataSet2; + CPArray dataSet3; CPTableColumn randomColumn; } @@ -28,9 +29,15 @@ tableTestDragType = @"CPTableViewTestDragType"; } var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(50,50,700,500) styleMask:CPClosableWindowMask], - contentView = [theWindow contentView]; + contentView = [theWindow contentView], + label = [CPTextField new]; - tableView = [[CPTableView alloc] initWithFrame:CGRectMake(0.0, 0.0, 400.0, 400.0)]; + [label setStringValue:@"This table refuses to become the first responder but can still be interacted with."]; + [label sizeToFit]; + [label setFrameOrigin:CGPointMake(200, 10)] + [contentView addSubview:label]; + + tableView = [[CUTableView alloc] initWithFrame:CGRectMake(0.0, 0.0, 400.0, 400.0)]; [tableView setAllowsMultipleSelection:YES]; [tableView setAllowsColumnSelection:YES]; @@ -172,7 +179,6 @@ tableTestDragType = @"CPTableViewTestDragType"; - (void)newWindow { - var window2 = [[CPWindow alloc] initWithContentRect:CGRectMake(450, 50, 500, 400) styleMask:CPTitledWindowMask | CPResizableWindowMask]; tableView2 = [[CPTableView alloc] initWithFrame:CGRectMake(0.0, 0.0, 500.0, 500.0)]; @@ -186,7 +192,6 @@ tableTestDragType = @"CPTableViewTestDragType"; [tableView2 setDelegate:self]; [tableView2 setDataSource:self]; - var checkBox = [[CPCheckBox alloc] initWithFrame:CGRectMake(5,3,24,24)], checkBoxColumn = [[CPTableColumn alloc] initWithIdentifier:@"checkBox"]; [checkBoxColumn setDataView:checkBox]; @@ -475,3 +480,16 @@ tableTestDragType = @"CPTableViewTestDragType"; } @end + + +@implementation CUTableView : CPTableView +{ + +} + +- (BOOL)acceptsFirstResponder +{ + return NO; +} + +@end