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
This commit is contained in:
Fred Kiefer 2008-05-01 19:48:28 +00:00
parent ddc130cae7
commit 0cba457027
4 changed files with 78 additions and 40 deletions

View file

@ -1,3 +1,19 @@
2008-05-01 Fred Kiefer <FredKiefer@gmx.de>
* 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 <FredKiefer@gmx.de>
* 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 <ahoesch@smartsoft.de>.
* Source/NSTableHeaderView.m (-initWithFrame:, -initWithCoder:):
Check for nil return from super call.
2008-04-27 18:42-EDT Gregory John Casamento <greg_casamento@yahoo.com>
* Source/NSWindow.m: Change to correct issue with NSWindow placement

View file

@ -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;
}

View file

@ -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;

View file

@ -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;
}