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:
Fred Kiefer 2004-06-17 21:38:33 +00:00
parent a6c243332f
commit a9031e5bfc
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>
* Source/NSTableView.m: (-mouseDown:) Reordered code and

View file

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

View file

@ -3387,9 +3387,10 @@ inline float computePeriod(NSPoint mouseLocationWin,
| NSPeriodicMask);
unsigned selectionMode;
NSPoint mouseLocationWin;
NSPoint mouseLocationView;
NSDate *distantFuture = [NSDate distantFuture];
NSEvent *lastEvent;
NSIndexSet *_oldSelectedRows;
NSIndexSet *oldSelectedRows;
BOOL startedPeriodicEvents = NO;
BOOL mouseUp = NO;
BOOL done = NO;
@ -3446,9 +3447,58 @@ inline float computePeriod(NSPoint mouseLocationWin,
[self _setSelectingColumns: NO];
// let's sort the _selectedRows
_oldSelectedRows = [_selectedRows copy];
oldSelectedRows = [_selectedRows copy];
mouseLocationView = location;
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)
{
/*
@ -3467,8 +3517,6 @@ inline float computePeriod(NSPoint mouseLocationWin,
&& (mouseLocationWin.y < maxYVisible))
{
// mouse dragged within table
NSPoint mouseLocationView;
if (startedPeriodicEvents == YES)
{
[NSEvent stopPeriodicEvents];
@ -3495,6 +3543,8 @@ inline float computePeriod(NSPoint mouseLocationWin,
case NSLeftMouseDown:
case NSLeftMouseDragged:
mouseLocationWin = [lastEvent locationInWindow];
mouseLocationView = [self convertPoint: mouseLocationWin
fromView: nil];
if (fabs(mouseLocationWin.x - initialLocation.x) > 1
|| fabs(mouseLocationWin.y - initialLocation.y) > 1)
@ -3512,13 +3562,9 @@ inline float computePeriod(NSPoint mouseLocationWin,
else if (mouseLocationWin.x - initialLocation.x >= 4
|| mouseLocationWin.x - initialLocation.x <= -4)
{
NSPoint mouseLocationView;
NSPasteboard *pboard;
NSArray *rows;
mouseLocationView = [self convertPoint:
mouseLocationWin
fromView: nil];
mouseLocationView.x = _bounds.origin.x;
oldRow = currentRow;
currentRow = [self rowAtPoint: mouseLocationView];
@ -3527,7 +3573,7 @@ inline float computePeriod(NSPoint mouseLocationWin,
/* Mouse drag in a row that wasn't selected.
select the new row before dragging */
computeNewSelection(self,
_oldSelectedRows,
oldSelectedRows,
_selectedRows,
originalRow,
oldRow,
@ -3567,8 +3613,6 @@ inline float computePeriod(NSPoint mouseLocationWin,
&& (mouseLocationWin.y < maxYVisible))
{
// mouse dragged within table
NSPoint mouseLocationView;
if (startedPeriodicEvents == YES)
{
[NSEvent stopPeriodicEvents];
@ -3645,7 +3689,7 @@ inline float computePeriod(NSPoint mouseLocationWin,
if (shouldComputeNewSelection == YES)
{
computeNewSelection(self,
_oldSelectedRows,
oldSelectedRows,
_selectedRows,
originalRow,
oldRow,
@ -3667,7 +3711,7 @@ inline float computePeriod(NSPoint mouseLocationWin,
if (startedPeriodicEvents == YES)
[NSEvent stopPeriodicEvents];
if (![_selectedRows isEqualToIndexSet: _oldSelectedRows])
if (![_selectedRows isEqualToIndexSet: oldSelectedRows])
{
[self _postSelectionDidChangeNotification];
}