Made ComoboxCells usable in TableViews.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@19540 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
FredKiefer 2004-06-17 21:38:33 +00:00
parent a1f385f74a
commit 7a68fa6413
3 changed files with 73 additions and 36 deletions

View file

@ -1,3 +1,10 @@
2004-06-16 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSTableView.m: (-mouseDown:) Added mouse tracking in the cell.
* Source/NSComboBoxCell.m: (-trackMouse:...untilMouseUp:) Set _lastValidFrame
[GSComboWindow positionWithComboBoxCell:] compute position based on
_lastValidFrame not the frame from the control view.
2004-06-16 Fred Kiefer <FredKiefer@gmx.de> 2004-06-16 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSTableView.m: (-mouseDown:) Reordered code and * Source/NSTableView.m: (-mouseDown:) Reordered code and

View file

@ -313,27 +313,19 @@ static GSComboWindow *gsWindow = nil;
[self layoutWithComboBoxCell: comboBoxCell]; [self layoutWithComboBoxCell: comboBoxCell];
// Now we can ask for the size // Now we can ask for the size
comboWindowFrame = [self frame]; comboWindowFrame = [self frame];
if (comboWindowFrame.size.width == 0 || comboWindowFrame.size.height == 0) if (comboWindowFrame.size.width == 0 || comboWindowFrame.size.height == 0)
return; return;
screenFrame = [[[viewWithComboCell window] screen] frame]; screenFrame = [[[viewWithComboCell window] screen] frame];
viewWithComboCellFrame = [viewWithComboCell frame]; viewWithComboCellFrame = [comboBoxCell _textCellFrame];
point = viewWithComboCellFrame.origin; point = viewWithComboCellFrame.origin;
// Switch to the window coordinates // Switch to the window coordinates
point = [[viewWithComboCell superview] convertPoint: point toView: nil]; point = [viewWithComboCell convertPoint: point toView: nil];
// Switch to the screen coordinates // Switch to the screen coordinates
point = [[viewWithComboCell window] convertBaseToScreen: point]; point = [[viewWithComboCell window] convertBaseToScreen: point];
// Take in account flipped view
if ([superview isFlipped])
point.y += NSHeight([superview frame])
- (viewWithComboCellFrame.origin.y * 2 + NSHeight(viewWithComboCellFrame));
point.y -= 1 + NSHeight(comboWindowFrame); point.y -= 1 + NSHeight(comboWindowFrame);
if (point.y < 0) if (point.y < 0)
@ -345,16 +337,10 @@ static GSComboWindow *gsWindow = nil;
point.y = NSMaxY(viewWithComboCellFrame); point.y = NSMaxY(viewWithComboCellFrame);
// Switch to the window coordinates // Switch to the window coordinates
point = [[viewWithComboCell superview] convertPoint: point toView: nil]; point = [viewWithComboCell convertPoint: point toView: nil];
// Switch to the screen coordiantes // Switch to the screen coordiantes
point = [[viewWithComboCell window] convertBaseToScreen: point]; point = [[viewWithComboCell window] convertBaseToScreen: point];
// Take in account flipped view
if ([superview isFlipped])
point.y += NSHeight([superview frame])
- (viewWithComboCellFrame.origin.y * 2 + NSHeight(viewWithComboCellFrame));
point.y += 1; point.y += 1;
if (point.y + NSHeight(comboWindowFrame) > NSHeight(screenFrame)) if (point.y + NSHeight(comboWindowFrame) > NSHeight(screenFrame))
@ -1405,7 +1391,9 @@ static inline NSRect buttonCellFrameFromRect(NSRect cellRect)
// Should this be set by NSActionCell ? // Should this be set by NSActionCell ?
if (_control_view != controlView) if (_control_view != controlView)
_control_view = controlView; _control_view = controlView;
// Used by GSComboWindow to appear in the right position
_lastValidFrame = cellFrame;
point = [controlView convertPoint: [theEvent locationInWindow] point = [controlView convertPoint: [theEvent locationInWindow]
fromView: nil]; fromView: nil];
@ -1415,7 +1403,7 @@ static inline NSRect buttonCellFrameFromRect(NSRect cellRect)
{ {
if (NSMouseInRect(point, textCellFrameFromRect(cellFrame), isFlipped)) if (NSMouseInRect(point, textCellFrameFromRect(cellFrame), isFlipped))
{ {
return YES;// Continue return NO;
} }
else if (NSMouseInRect(point, buttonCellFrameFromRect(cellFrame), isFlipped)) else if (NSMouseInRect(point, buttonCellFrameFromRect(cellFrame), isFlipped))
{ {
@ -1429,16 +1417,14 @@ static inline NSRect buttonCellFrameFromRect(NSRect cellRect)
ofView: controlView ofView: controlView
untilMouseUp: NO]; untilMouseUp: NO];
/* We can do the call below but it is already done by the target/action we have set for the button cell /* The click will be send by the target/action we have set for the button cell. */
if (clicked)
[self _didClickWithinButton: self]; // Not to be used */
[controlView lockFocus]; [controlView lockFocus];
[_buttonCell highlight: NO withFrame: buttonCellFrameFromRect(cellFrame) inView: controlView]; [_buttonCell highlight: NO withFrame: buttonCellFrameFromRect(cellFrame) inView: controlView];
[controlView unlockFocus]; [controlView unlockFocus];
[cvWindow flushWindow]; [cvWindow flushWindow];
return NO; return clicked;
} }
} }

View file

@ -3387,9 +3387,10 @@ inline float computePeriod(NSPoint mouseLocationWin,
| NSPeriodicMask); | NSPeriodicMask);
unsigned selectionMode; unsigned selectionMode;
NSPoint mouseLocationWin; NSPoint mouseLocationWin;
NSPoint mouseLocationView;
NSDate *distantFuture = [NSDate distantFuture]; NSDate *distantFuture = [NSDate distantFuture];
NSEvent *lastEvent; NSEvent *lastEvent;
NSIndexSet *_oldSelectedRows; NSIndexSet *oldSelectedRows;
BOOL startedPeriodicEvents = NO; BOOL startedPeriodicEvents = NO;
BOOL mouseUp = NO; BOOL mouseUp = NO;
BOOL done = NO; BOOL done = NO;
@ -3446,9 +3447,58 @@ inline float computePeriod(NSPoint mouseLocationWin,
[self _setSelectingColumns: NO]; [self _setSelectingColumns: NO];
// let's sort the _selectedRows // let's sort the _selectedRows
_oldSelectedRows = [_selectedRows copy]; oldSelectedRows = [_selectedRows copy];
mouseLocationView = location;
lastEvent = theEvent; lastEvent = theEvent;
if ([self mouse: mouseLocationView inRect: _bounds])
{
NSTableColumn *tb;
NSCell *cell;
NSRect rect;
int columnIndex;
int rowIndex;
rowIndex = [self rowAtPoint: mouseLocationView];
columnIndex = [self columnAtPoint: mouseLocationView];
// Prepare the cell
tb = [_tableColumns objectAtIndex: columnIndex];
// NB: need to be released when no longer used
cell = [[tb dataCellForRow: rowIndex] copy];
[cell setEditable: YES];
[cell setObjectValue: [self _objectValueForTableColumn: tb
row: rowIndex]];
rect = [self frameOfCellAtColumn: columnIndex
row: rowIndex];
[cell setHighlighted: YES];
[self setNeedsDisplayInRect: rect];
if ([cell trackMouse: lastEvent
inRect: rect
ofView: self
untilMouseUp: [[cell class] prefersTrackingUntilMouseUp]])
{
done = YES;
currentRow = rowIndex;
computeNewSelection(self,
oldSelectedRows,
_selectedRows,
originalRow,
oldRow,
currentRow,
&_selectedRow,
selectionMode);
[self displayIfNeeded];
}
else
{
[cell setHighlighted: NO];
[self setNeedsDisplayInRect: rect];
}
DESTROY(cell);
}
while (done != YES) while (done != YES)
{ {
/* /*
@ -3467,8 +3517,6 @@ inline float computePeriod(NSPoint mouseLocationWin,
&& (mouseLocationWin.y < maxYVisible)) && (mouseLocationWin.y < maxYVisible))
{ {
// mouse dragged within table // mouse dragged within table
NSPoint mouseLocationView;
if (startedPeriodicEvents == YES) if (startedPeriodicEvents == YES)
{ {
[NSEvent stopPeriodicEvents]; [NSEvent stopPeriodicEvents];
@ -3495,6 +3543,8 @@ inline float computePeriod(NSPoint mouseLocationWin,
case NSLeftMouseDown: case NSLeftMouseDown:
case NSLeftMouseDragged: case NSLeftMouseDragged:
mouseLocationWin = [lastEvent locationInWindow]; mouseLocationWin = [lastEvent locationInWindow];
mouseLocationView = [self convertPoint: mouseLocationWin
fromView: nil];
if (fabs(mouseLocationWin.x - initialLocation.x) > 1 if (fabs(mouseLocationWin.x - initialLocation.x) > 1
|| fabs(mouseLocationWin.y - initialLocation.y) > 1) || fabs(mouseLocationWin.y - initialLocation.y) > 1)
@ -3512,13 +3562,9 @@ inline float computePeriod(NSPoint mouseLocationWin,
else if (mouseLocationWin.x - initialLocation.x >= 4 else if (mouseLocationWin.x - initialLocation.x >= 4
|| mouseLocationWin.x - initialLocation.x <= -4) || mouseLocationWin.x - initialLocation.x <= -4)
{ {
NSPoint mouseLocationView;
NSPasteboard *pboard; NSPasteboard *pboard;
NSArray *rows; NSArray *rows;
mouseLocationView = [self convertPoint:
mouseLocationWin
fromView: nil];
mouseLocationView.x = _bounds.origin.x; mouseLocationView.x = _bounds.origin.x;
oldRow = currentRow; oldRow = currentRow;
currentRow = [self rowAtPoint: mouseLocationView]; currentRow = [self rowAtPoint: mouseLocationView];
@ -3527,7 +3573,7 @@ inline float computePeriod(NSPoint mouseLocationWin,
/* Mouse drag in a row that wasn't selected. /* Mouse drag in a row that wasn't selected.
select the new row before dragging */ select the new row before dragging */
computeNewSelection(self, computeNewSelection(self,
_oldSelectedRows, oldSelectedRows,
_selectedRows, _selectedRows,
originalRow, originalRow,
oldRow, oldRow,
@ -3567,8 +3613,6 @@ inline float computePeriod(NSPoint mouseLocationWin,
&& (mouseLocationWin.y < maxYVisible)) && (mouseLocationWin.y < maxYVisible))
{ {
// mouse dragged within table // mouse dragged within table
NSPoint mouseLocationView;
if (startedPeriodicEvents == YES) if (startedPeriodicEvents == YES)
{ {
[NSEvent stopPeriodicEvents]; [NSEvent stopPeriodicEvents];
@ -3645,7 +3689,7 @@ inline float computePeriod(NSPoint mouseLocationWin,
if (shouldComputeNewSelection == YES) if (shouldComputeNewSelection == YES)
{ {
computeNewSelection(self, computeNewSelection(self,
_oldSelectedRows, oldSelectedRows,
_selectedRows, _selectedRows,
originalRow, originalRow,
oldRow, oldRow,
@ -3667,7 +3711,7 @@ inline float computePeriod(NSPoint mouseLocationWin,
if (startedPeriodicEvents == YES) if (startedPeriodicEvents == YES)
[NSEvent stopPeriodicEvents]; [NSEvent stopPeriodicEvents];
if (![_selectedRows isEqualToIndexSet: _oldSelectedRows]) if (![_selectedRows isEqualToIndexSet: oldSelectedRows])
{ {
[self _postSelectionDidChangeNotification]; [self _postSelectionDidChangeNotification];
} }