From e8a572e64b1967f3cf9d855e1f2323f6b53629a7 Mon Sep 17 00:00:00 2001 From: FredKiefer Date: Thu, 26 May 2005 13:38:11 +0000 Subject: [PATCH] Improved mouseDown call handling for table view. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@21262 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 8 ++++ Source/NSTableView.m | 104 +++++++++++++++++-------------------------- 2 files changed, 48 insertions(+), 64 deletions(-) diff --git a/ChangeLog b/ChangeLog index b6183e0a0..4de5f5da6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2005-05-26 Fred Kiefer + + * Source/NSTableView.m (-mouseDown): Replaced use of + _sendsActionOn: with a check if the value did change + after the cell did track the mouse. Also use a copy of the cell, + that way other cells are not affected by changes in the tracked + cell. Patch based on code by Matt Rice . + 2005-05-25 Adam Fedor * Update FSF Address. diff --git a/Source/NSTableView.m b/Source/NSTableView.m index 45c8d272a..63a0978c6 100644 --- a/Source/NSTableView.m +++ b/Source/NSTableView.m @@ -3100,12 +3100,11 @@ byExtendingSelection: (BOOL)flag if (_textObject) { [_editedCell endEditing: _textObject]; - RELEASE (_editedCell); + DESTROY(_editedCell); [self setNeedsDisplayInRect: [self frameOfCellAtColumn: _editedColumn row: _editedRow]]; _editedRow = -1; _editedColumn = -1; - _editedCell = nil; _textObject = nil; return YES; } @@ -3375,7 +3374,7 @@ static inline float computePeriod(NSPoint mouseLocationWin, { // It is OK to edit column. Go on, do it. [self editColumn: _clickedColumn row: _clickedRow - withEvent: theEvent select: NO]; + withEvent: theEvent select: YES]; } } else @@ -3449,81 +3448,58 @@ static inline float computePeriod(NSPoint mouseLocationWin, // let's sort the _selectedRows oldSelectedRows = [_selectedRows copy]; - mouseLocationView = location; lastEvent = theEvent; + if ([self mouse: mouseLocationView inRect: _bounds]) { NSTableColumn *tb; NSCell *cell; NSRect cellFrame; - int actionMaskForCurrentEvent; - - switch ([lastEvent type]) - { - case NSLeftMouseDown: - actionMaskForCurrentEvent = NSLeftMouseDownMask - | NSLeftMouseUpMask - | NSLeftMouseDraggedMask; - break; - case NSRightMouseDown: - actionMaskForCurrentEvent = NSRightMouseDownMask - | NSRightMouseUpMask - | NSRightMouseDraggedMask; - break; - case NSOtherMouseDown: - actionMaskForCurrentEvent = NSOtherMouseDownMask - | NSOtherMouseUpMask - | NSOtherMouseDraggedMask; - break; - default: - /* Can't happen */ - actionMaskForCurrentEvent = -1; - break; - } - + id originalValue; + // Prepare the cell tb = [_tableColumns objectAtIndex: _clickedColumn]; - cell = [tb dataCellForRow: _clickedRow]; - if ([cell _sendsActionOn: actionMaskForCurrentEvent]) - { - [cell setObjectValue: [self _objectValueForTableColumn: tb - row: _clickedRow]]; - cellFrame = [self frameOfCellAtColumn: _clickedColumn + cell = [[tb dataCellForRow: _clickedRow] copy]; + originalValue = RETAIN([self _objectValueForTableColumn:tb row:_clickedRow]); + [cell setObjectValue: originalValue]; + cellFrame = [self frameOfCellAtColumn: _clickedColumn row: _clickedRow]; - [cell setHighlighted: YES]; - [self setNeedsDisplayInRect: cellFrame]; - /* give delegate a chance to i.e set target */ - [self _willDisplayCell: cell - forTableColumn: tb - row: _clickedRow]; - if ([cell trackMouse: lastEvent + [cell setHighlighted: YES]; + [self setNeedsDisplayInRect: cellFrame]; + /* give delegate a chance to i.e set target */ + [self _willDisplayCell: cell + forTableColumn: tb + row: _clickedRow]; + if ([cell trackMouse: lastEvent inRect: cellFrame ofView: self - untilMouseUp: [[cell class] prefersTrackingUntilMouseUp]]) + untilMouseUp: [[cell class] prefersTrackingUntilMouseUp]]) + { + id newValue = [cell objectValue]; + + if ([tb isEditable] && ![originalValue isEqual: newValue]) { - if ([tb isEditable]) - { - [self _setObjectValue: [cell objectValue] - forTableColumn: tb - row: _clickedRow]; - } - done = YES; - currentRow = _clickedRow; - computeNewSelection(self, - oldSelectedRows, - _selectedRows, - originalRow, - oldRow, - currentRow, - &_selectedRow, - selectionMode); - } - - [cell setHighlighted: NO]; - [self setNeedsDisplayInRect: cellFrame]; - lastEvent = [NSApp currentEvent]; + [self _setObjectValue: newValue + forTableColumn: tb + row: _clickedRow]; + } + done = YES; + currentRow = _clickedRow; + computeNewSelection(self, + oldSelectedRows, + _selectedRows, + originalRow, + oldRow, + currentRow, + &_selectedRow, + selectionMode); } + RELEASE(originalValue); + [cell setHighlighted: NO]; + RELEASE(cell); + [self setNeedsDisplayInRect: cellFrame]; + lastEvent = [NSApp currentEvent]; } while (done != YES)