From 676eb09e4f9e1321827f6268adb2f05763b35cad Mon Sep 17 00:00:00 2001 From: fredkiefer Date: Thu, 1 May 2008 19:48:28 +0000 Subject: [PATCH] Better check for click on table column border. Allow table column identifier to be nil. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@26482 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 16 +++++++++ Source/NSTableColumn.m | 71 +++++++++++++++++++++----------------- Source/NSTableHeaderView.m | 23 ++++++++---- Source/NSTableView.m | 8 +++-- 4 files changed, 78 insertions(+), 40 deletions(-) diff --git a/ChangeLog b/ChangeLog index fd9d93ec9..601bb2712 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2008-05-01 Fred Kiefer + + * Source/NSTableColumn.m (-initWithIdentifier:, -initWithCoder:): + Check for self becoming nil. + * Source/NSTableView.m (-columnWithIdentifier:): Allow the column + identifier to be nil. + +2008-04-28 Fred Kiefer + + * Source/NSTableHeaderView.m (-mouseDown:): Use new variable + mouse_sensitivity (value 4) to determine whether the click is on a + column border. + Patch by Andreas Höschler . + * Source/NSTableHeaderView.m (-initWithFrame:, -initWithCoder:): + Check for nil return from super call. + 2008-04-27 18:42-EDT Gregory John Casamento * Source/NSWindow.m: Change to correct issue with NSWindow placement diff --git a/Source/NSTableColumn.m b/Source/NSTableColumn.m index c15766c18..4baa00211 100644 --- a/Source/NSTableColumn.m +++ b/Source/NSTableColumn.m @@ -99,6 +99,9 @@ - (id)initWithIdentifier: (id)anObject { self = [super init]; + if (!self) + return nil; + _width = 100; _min_width = 10; _max_width = 100000; @@ -406,30 +409,33 @@ id identifier = [aDecoder decodeObjectForKey: @"NSIdentifier"]; self = [self initWithIdentifier: identifier]; + if (!self) + return nil; + if ([aDecoder containsValueForKey: @"NSDataCell"]) { - [self setDataCell: [aDecoder decodeObjectForKey: @"NSDataCell"]]; - } + [self setDataCell: [aDecoder decodeObjectForKey: @"NSDataCell"]]; + } if ([aDecoder containsValueForKey: @"NSHeaderCell"]) { - [self setHeaderCell: [aDecoder decodeObjectForKey: @"NSHeaderCell"]]; - } + [self setHeaderCell: [aDecoder decodeObjectForKey: @"NSHeaderCell"]]; + } if ([aDecoder containsValueForKey: @"NSIsResizeable"]) { - [self setResizable: [aDecoder decodeBoolForKey: @"NSIsResizeable"]]; - } + [self setResizable: [aDecoder decodeBoolForKey: @"NSIsResizeable"]]; + } if ([aDecoder containsValueForKey: @"NSWidth"]) { - [self setWidth: [aDecoder decodeFloatForKey: @"NSWidth"]]; - } + [self setWidth: [aDecoder decodeFloatForKey: @"NSWidth"]]; + } if ([aDecoder containsValueForKey: @"NSMinWidth"]) { - [self setMinWidth: [aDecoder decodeFloatForKey: @"NSMinWidth"]]; - } + [self setMinWidth: [aDecoder decodeFloatForKey: @"NSMinWidth"]]; + } if ([aDecoder containsValueForKey: @"NSMaxWidth"]) { - [self setMaxWidth: [aDecoder decodeFloatForKey: @"NSMaxWidth"]]; - } + [self setMaxWidth: [aDecoder decodeFloatForKey: @"NSMaxWidth"]]; + } } else { @@ -437,28 +443,31 @@ @"NSTableColumn"]; self = [super init]; - if (version == 2) + if (!self) + return nil; + + if (version == 2) { - _identifier = RETAIN([aDecoder decodeObject]); - [aDecoder decodeValueOfObjCType: @encode(float) at: &_width]; - [aDecoder decodeValueOfObjCType: @encode(float) at: &_min_width]; - [aDecoder decodeValueOfObjCType: @encode(float) at: &_max_width]; - [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_is_resizable]; - [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_is_editable]; - _headerCell = RETAIN([aDecoder decodeObject]); - _dataCell = RETAIN([aDecoder decodeObject]); - } + _identifier = RETAIN([aDecoder decodeObject]); + [aDecoder decodeValueOfObjCType: @encode(float) at: &_width]; + [aDecoder decodeValueOfObjCType: @encode(float) at: &_min_width]; + [aDecoder decodeValueOfObjCType: @encode(float) at: &_max_width]; + [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_is_resizable]; + [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_is_editable]; + _headerCell = RETAIN([aDecoder decodeObject]); + _dataCell = RETAIN([aDecoder decodeObject]); + } else { - _identifier = RETAIN([aDecoder decodeObject]); - _headerCell = RETAIN([aDecoder decodeObject]); - _dataCell = RETAIN([aDecoder decodeObject]); - [aDecoder decodeValueOfObjCType: @encode(float) at: &_width]; - [aDecoder decodeValueOfObjCType: @encode(float) at: &_min_width]; - [aDecoder decodeValueOfObjCType: @encode(float) at: &_max_width]; - [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_is_resizable]; - [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_is_editable]; - } + _identifier = RETAIN([aDecoder decodeObject]); + _headerCell = RETAIN([aDecoder decodeObject]); + _dataCell = RETAIN([aDecoder decodeObject]); + [aDecoder decodeValueOfObjCType: @encode(float) at: &_width]; + [aDecoder decodeValueOfObjCType: @encode(float) at: &_min_width]; + [aDecoder decodeValueOfObjCType: @encode(float) at: &_max_width]; + [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_is_resizable]; + [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_is_editable]; + } } return self; } diff --git a/Source/NSTableHeaderView.m b/Source/NSTableHeaderView.m index c05d6f4c2..e21f08464 100644 --- a/Source/NSTableHeaderView.m +++ b/Source/NSTableHeaderView.m @@ -43,6 +43,12 @@ #include "AppKit/NSScrollView.h" #include "AppKit/NSGraphics.h" +/* + * Number of pixels in either direction that will be counted as a hit + * on the column border and trigger a column resize. + */ +#define mouse_sensitivity 4 + @interface NSTableView (GNUstepPrivate) - (void) _userResizedTableColumn: (int)index width: (float)width; @@ -78,6 +84,9 @@ - (id)initWithFrame:(NSRect)frameRect { self = [super initWithFrame: frameRect]; + if (self == nil) + return nil; + _tableView = nil; _resizedColumn = -1; return self; @@ -301,26 +310,25 @@ /* Safety check */ if (_resizedColumn != -1) { - NSLog (@"Bug: starting resizing of column while already resizing!"); + NSLog(@"Bug: starting resizing of column while already resizing!"); _resizedColumn = -1; } if ([_tableView allowsColumnResizing]) { /* Start resizing if the mouse is down on the bounds of a column. */ - - if (location.x >= NSMaxX (rect) - 1) + if (location.x >= NSMaxX(rect) - mouse_sensitivity) { - if (columnIndex != ([_tableView numberOfColumns])) + if (columnIndex < [_tableView numberOfColumns]) { _resizedColumn = columnIndex; } else { - NSLog(@"ohoh"); + NSLog(@"Bug: Trying to resize column past the end of the table."); } } - else if (location.x <= NSMinX (rect) + 2) + else if (location.x <= NSMinX(rect) + mouse_sensitivity) { if (columnIndex > 0) { @@ -887,6 +895,9 @@ - (id) initWithCoder: (NSCoder*)aDecoder { self = [super initWithCoder: aDecoder]; + if (self == nil) + return nil; + _tableView = nil; _resizedColumn = -1; diff --git a/Source/NSTableView.m b/Source/NSTableView.m index 5e619c413..bd9c3e11f 100644 --- a/Source/NSTableView.m +++ b/Source/NSTableView.m @@ -2231,10 +2231,12 @@ static void computeNewSelection while ((tb = [enumerator nextObject]) != nil) { - if ([[tb identifier] isEqual: identifier]) - return return_value; + // Also handle a nil identifier. + if ((identifier == [tb identifier]) || + [[tb identifier] isEqual: identifier]) + return return_value; else - return_value++; + return_value++; } return -1; }