Made selecting values from a combo box in a table view work.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@19568 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
FredKiefer 2004-06-20 22:25:17 +00:00
parent 395837a98a
commit 99fe5f4012
3 changed files with 78 additions and 22 deletions

View file

@ -1,3 +1,11 @@
2004-06-20 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSTableView.m: (-mouseDown:) Set value after cell tracking.
(_setObjectValue:forTableColumn:row:) Check for correct method.
Patch by Matt Rice <ratmice@yahoo.com>
* Source/NSComboBoxCell.m: (-objectValue) Added this method, as
the object value never gets set.
2004-06-19 Fred Kiefer <FredKiefer@gmx.de> 2004-06-19 Fred Kiefer <FredKiefer@gmx.de>
* Source/GSDragView.m: (-_handleEventDuringDragging:) Get mouse * Source/GSDragView.m: (-_handleEventDuringDragging:) Get mouse

View file

@ -1167,6 +1167,48 @@ numberOfRowsInColumn: (int)column
} }
} }
/* FIXME: Not sure, if this is the best way to implement objectValue,
* perhaps it would be better to store the current value with setObjectValue:
* whenever it changes.
*/
- (id) objectValue
{
int index = [self indexOfSelectedItem];
if (index == -1)
{
return nil;
}
else
{
if (_usesDataSource)
{
if (!_dataSource)
{
NSLog(@"%@: No data source currently specified", self);
return nil;
}
if ([_dataSource respondsToSelector:
@selector(comboBox:objectValueForItemAtIndex:)])
{
return [_dataSource comboBox: (NSComboBox *)[self controlView]
objectValueForItemAtIndex: index];
}
else if ([_dataSource respondsToSelector:
@selector(comboBoxCell:objectValueForItemAtIndex:)])
{
return [_dataSource comboBoxCell: self
objectValueForItemAtIndex: index];
}
}
else
{
return [self itemObjectValueAtIndex: index];
}
}
return nil;
}
/** /**
* Returns the object value of the selected item in the combo box cell default * Returns the object value of the selected item in the combo box cell default
* items list or nil when there is no selection. In the case * items list or nil when there is no selection. In the case

View file

@ -3455,31 +3455,40 @@ inline float computePeriod(NSPoint mouseLocationWin,
{ {
NSTableColumn *tb; NSTableColumn *tb;
NSCell *cell; NSCell *cell;
NSRect rect; NSRect cellFrame;
int columnIndex;
int rowIndex;
rowIndex = [self rowAtPoint: mouseLocationView];
columnIndex = [self columnAtPoint: mouseLocationView];
// Prepare the cell // Prepare the cell
tb = [_tableColumns objectAtIndex: columnIndex]; tb = [_tableColumns objectAtIndex: _clickedColumn];
// NB: need to be released when no longer used // NB: need to be released when no longer used
cell = [[tb dataCellForRow: rowIndex] copy]; // Not sure if we really need a copy here.
[cell setEditable: YES]; cell = [[tb dataCellForRow: _clickedRow] copy];
[cell setObjectValue: [self _objectValueForTableColumn: tb [cell setObjectValue: [self _objectValueForTableColumn: tb
row: rowIndex]]; row: _clickedRow]];
rect = [self frameOfCellAtColumn: columnIndex cellFrame = [self frameOfCellAtColumn: _clickedColumn
row: rowIndex]; row: _clickedRow];
[cell setHighlighted: YES]; [cell setHighlighted: YES];
[self setNeedsDisplayInRect: rect]; [self setNeedsDisplayInRect: cellFrame];
/* give delegate a chance to i.e set target */
if (_del_responds)
{
[_delegate tableView: self
willDisplayCell: cell
forTableColumn: tb
row: _clickedRow];
}
if ([cell trackMouse: lastEvent if ([cell trackMouse: lastEvent
inRect: rect inRect: cellFrame
ofView: self ofView: self
untilMouseUp: [[cell class] prefersTrackingUntilMouseUp]]) untilMouseUp: [[cell class] prefersTrackingUntilMouseUp]])
{ {
if ([tb isEditable])
{
[self _setObjectValue: [cell objectValue]
forTableColumn: tb
row: _clickedRow];
}
done = YES; done = YES;
currentRow = rowIndex; currentRow = _clickedRow;
computeNewSelection(self, computeNewSelection(self,
oldSelectedRows, oldSelectedRows,
_selectedRows, _selectedRows,
@ -3488,13 +3497,10 @@ inline float computePeriod(NSPoint mouseLocationWin,
currentRow, currentRow,
&_selectedRow, &_selectedRow,
selectionMode); selectionMode);
[self displayIfNeeded];
}
else
{
[cell setHighlighted: NO];
[self setNeedsDisplayInRect: rect];
} }
[cell setHighlighted: NO];
[self setNeedsDisplayInRect: cellFrame];
lastEvent = [NSApp currentEvent];
DESTROY(cell); DESTROY(cell);
} }
@ -5881,7 +5887,7 @@ inline float computePeriod(NSPoint mouseLocationWin,
row: (int) index row: (int) index
{ {
if([_dataSource respondsToSelector: if([_dataSource respondsToSelector:
@selector(tableView:objectValueForTableColumn:row:)]) @selector(tableView:setObjectValue:forTableColumn:row:)])
{ {
[_dataSource tableView: self [_dataSource tableView: self
setObjectValue: value setObjectValue: value