Minor tidyup.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3836 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-03-02 20:01:17 +00:00
parent 3fa6c2695a
commit ee0eb44c06

View file

@ -1,4 +1,4 @@
/* /*
NSMatrix.m NSMatrix.m
Matrix class for grouping controls Matrix class for grouping controls
@ -11,14 +11,14 @@
Scott Christley. Scott Christley.
Author: Felipe A. Rodriguez <far@ix.netcom.com> Author: Felipe A. Rodriguez <far@ix.netcom.com>
Date: August 1998 Date: August 1998
This file is part of the GNUstep GUI Library. This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version. version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
@ -28,7 +28,7 @@
License along with this library; see the file COPYING.LIB. License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation, If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#include <gnustep/gui/config.h> #include <gnustep/gui/config.h>
#include <stdlib.h> #include <stdlib.h>
@ -622,7 +622,7 @@ static int mouseDownFlags = 0;
[self sizeToCells]; [self sizeToCells];
} }
- (void)sortUsingFunction:(int (*)(id element1, id element2, - (void)sortUsingFunction:(int (*)(id element1, id element2,
void *userData))comparator void *userData))comparator
context:(void*)context context:(void*)context
{ {
@ -744,7 +744,7 @@ static int mouseDownFlags = 0;
} }
} }
if(!allowsEmptySelection) // if we don't allow an if (!allowsEmptySelection) // if we don't allow an
[self selectCellAtRow:0 column:0]; // empty selection [self selectCellAtRow:0 column:0]; // empty selection
} }
@ -990,7 +990,7 @@ fprintf(stderr, " NSMatrix: selectTextAtRow --- ");
[cellPrototype setScrollable:flag]; [cellPrototype setScrollable:flag];
} }
- (void)drawRect:(NSRect)rect - (void) drawRect: (NSRect)rect
{ {
int i, j; int i, j;
int row1, col1; // The cell at the upper left corner int row1, col1; // The cell at the upper left corner
@ -1003,47 +1003,56 @@ fprintf(stderr, " NSMatrix: selectTextAtRow --- ");
NSRectFill(rect); NSRectFill(rect);
} }
[self _getRow:&row1 column:&col1 [self _getRow: &row1 column: &col1 forPoint: rect.origin
forPoint:rect.origin above: NO right: NO isBetweenCells: NULL];
above:NO right:NO [self _getRow: &row2 column: &col2
isBetweenCells:NULL]; forPoint: NSMakePoint(NSMaxX(rect), NSMaxY(rect))
[self _getRow:&row2 column:&col2 above: NO right: NO isBetweenCells: NULL];
forPoint:NSMakePoint(NSMaxX(rect), NSMaxY(rect))
above:NO right:NO
isBetweenCells:NULL];
if (row1 < 0) if (row1 < 0)
row1 = 0; row1 = 0;
if (col1 < 0) if (col1 < 0)
col1 = 0; col1 = 0;
//NSLog (@"display cells between (%d, %d) and (%d, %d)",row1,col1, row2, col2);
/* Draw the cells within the drawing rectangle. */ /* Draw the cells within the drawing rectangle. */
for (i = row1; i <= row2 && i < numRows; i++) for (i = row1; i <= row2 && i < numRows; i++)
for (j = col1; j <= col2 && j < numCols; j++) for (j = col1; j <= col2 && j < numCols; j++)
[self drawCellAtRow:i column:j]; [self drawCellAtRow: i column: j];
} }
- (void)drawCellAtRow:(int)row column:(int)column - (void) drawCellAtRow: (int)row column: (int)column
{ {
NSCell *aCell = [self cellAtRow:row column:column]; NSCell *aCell = [self cellAtRow: row column: column];
NSRect cellFrame = [self cellFrameAtRow:row column:column];
[aCell drawWithFrame:cellFrame inView:self];
}
- (void)highlightCell:(BOOL)flag
atRow:(int)row
column:(int)column
{
NSCell *aCell = [self cellAtRow:row column:column];
if (aCell) if (aCell)
{ {
[aCell highlight:flag NSRect cellFrame = [self cellFrameAtRow: row column: column];
withFrame:[self cellFrameAtRow:row column:column]
inView:self]; if (drawsCellBackground)
{
[cellBackgroundColor set];
NSRectFill(cellFrame);
}
[aCell drawWithFrame: cellFrame inView: self];
}
}
- (void) highlightCell: (BOOL)flag atRow: (int)row column: (int)column
{
NSCell *aCell = [self cellAtRow: row column: column];
if (aCell)
{
NSRect cellFrame = [self cellFrameAtRow: row column: column];
if (drawsCellBackground)
{
[cellBackgroundColor set];
NSRectFill(cellFrame);
}
[aCell highlight: flag
withFrame: cellFrame
inView: self];
} }
} }
@ -1111,9 +1120,9 @@ fprintf(stderr, " NSMatrix: selectTextAtRow --- ");
[self sendAction]; [self sendAction];
} }
- (BOOL)acceptsFirstMouse:(NSEvent*)theEvent - (BOOL) acceptsFirstMouse: (NSEvent*)theEvent
{ {
return mode == NSListModeMatrix ? NO : YES; return mode == NSListModeMatrix ? NO : YES;
} }
- (void)_mouseDownNonListMode:(NSEvent *)theEvent - (void)_mouseDownNonListMode:(NSEvent *)theEvent
@ -1129,7 +1138,7 @@ fprintf(stderr, " NSMatrix: selectTextAtRow --- ");
NSRect mouseCellFrame; NSRect mouseCellFrame;
unsigned eventMask = NSLeftMouseUpMask | NSLeftMouseDownMask unsigned eventMask = NSLeftMouseUpMask | NSLeftMouseDownMask
| NSMouseMovedMask | NSLeftMouseDraggedMask; | NSMouseMovedMask | NSLeftMouseDraggedMask;
[self lockFocus]; [self lockFocus];
if ((mode == NSRadioModeMatrix) && selectedCell) if ((mode == NSRadioModeMatrix) && selectedCell)
@ -1137,7 +1146,7 @@ fprintf(stderr, " NSMatrix: selectTextAtRow --- ");
[selectedCell setState: NSOffState]; [selectedCell setState: NSOffState];
[self drawCellAtRow: selectedRow column: selectedColumn]; [self drawCellAtRow: selectedRow column: selectedColumn];
[window flushWindow]; [window flushWindow];
((tMatrix)selectedCells)->matrix[selectedRow][selectedColumn] = NO; ((tMatrix)selectedCells)->matrix[selectedRow][selectedColumn] = NO;
selectedCell = nil; selectedCell = nil;
selectedRow = selectedColumn = -1; selectedRow = selectedColumn = -1;
} }
@ -1148,16 +1157,16 @@ fprintf(stderr, " NSMatrix: selectTextAtRow --- ");
fromView: nil]; fromView: nil];
[self getRow: &mouseRow column: &mouseColumn forPoint: mouseLocation]; [self getRow: &mouseRow column: &mouseColumn forPoint: mouseLocation];
mouseCellFrame = [self cellFrameAtRow: mouseRow column: mouseColumn]; mouseCellFrame = [self cellFrameAtRow: mouseRow column: mouseColumn];
if (((mode == NSRadioModeMatrix) && ![self allowsEmptySelection]) if (((mode == NSRadioModeMatrix) && ![self allowsEmptySelection])
|| [self mouse: mouseLocation inRect: mouseCellFrame]) || [self mouse: mouseLocation inRect: mouseCellFrame])
{ {
mouseCell = [self cellAtRow: mouseRow column: mouseColumn]; mouseCell = [self cellAtRow: mouseRow column: mouseColumn];
selectedCell = mouseCell; selectedCell = mouseCell;
selectedRow = mouseRow; selectedRow = mouseRow;
selectedColumn = mouseColumn; selectedColumn = mouseColumn;
((tMatrix)selectedCells)->matrix[selectedRow][selectedColumn] = YES; ((tMatrix)selectedCells)->matrix[selectedRow][selectedColumn] = YES;
if (((mode == NSRadioModeMatrix) || (mode == NSHighlightModeMatrix)) if (((mode == NSRadioModeMatrix) || (mode == NSHighlightModeMatrix))
&& (highlightedCell != mouseCell)) && (highlightedCell != mouseCell))
@ -1166,7 +1175,7 @@ fprintf(stderr, " NSMatrix: selectTextAtRow --- ");
[self highlightCell: NO [self highlightCell: NO
atRow: highlightedRow atRow: highlightedRow
column: highlightedColumn]; column: highlightedColumn];
highlightedCell = mouseCell; highlightedCell = mouseCell;
highlightedRow = mouseRow; highlightedRow = mouseRow;
highlightedColumn = mouseColumn; highlightedColumn = mouseColumn;
@ -1175,7 +1184,7 @@ fprintf(stderr, " NSMatrix: selectTextAtRow --- ");
column: highlightedColumn]; column: highlightedColumn];
[window flushWindow]; [window flushWindow];
} }
mouseUpInCell = [mouseCell trackMouse: theEvent mouseUpInCell = [mouseCell trackMouse: theEvent
inRect: mouseCellFrame inRect: mouseCellFrame
ofView: self ofView: self
@ -1210,7 +1219,7 @@ fprintf(stderr, " NSMatrix: selectTextAtRow --- ");
inMode: NSEventTrackingRunLoopMode inMode: NSEventTrackingRunLoopMode
dequeue: YES]; dequeue: YES];
} }
// the mouse went up. // the mouse went up.
// if it was inside a cell, the cell has already sent the action. // if it was inside a cell, the cell has already sent the action.
// if not, selectedCell is the last cell that had the mouse, and // if not, selectedCell is the last cell that had the mouse, and
@ -1234,7 +1243,7 @@ fprintf(stderr, " NSMatrix: selectTextAtRow --- ");
} }
[self sendAction]; [self sendAction];
} }
if (highlightedCell) if (highlightedCell)
{ {
[self highlightCell: NO [self highlightCell: NO
@ -1251,7 +1260,7 @@ fprintf(stderr, " NSMatrix: selectTextAtRow --- ");
{ {
BOOL isBetweenCells, insideBounds; BOOL isBetweenCells, insideBounds;
int row, column; int row, column;
unsigned eventMask = NSLeftMouseUpMask | NSLeftMouseDownMask | NSMouseMovedMask unsigned eventMask = NSLeftMouseUpMask | NSLeftMouseDownMask | NSMouseMovedMask
| NSLeftMouseDraggedMask | NSPeriodicMask; | NSLeftMouseDraggedMask | NSPeriodicMask;
NSPoint lastLocation = [theEvent locationInWindow]; NSPoint lastLocation = [theEvent locationInWindow];
NSEvent* lastEvent = nil; NSEvent* lastEvent = nil;
@ -1263,94 +1272,94 @@ NSApplication *app = [NSApplication sharedApplication];
static MPoint anchor = {0, 0}; static MPoint anchor = {0, 0};
mouseDownFlags = [theEvent modifierFlags]; mouseDownFlags = [theEvent modifierFlags];
if (mode != NSListModeMatrix) if (mode != NSListModeMatrix)
{ {
[self _mouseDownNonListMode: theEvent]; [self _mouseDownNonListMode: theEvent];
return; return;
} }
//FIXME list mode is not working well. there is a flipping coordinates bug //FIXME list mode is not working well. there is a flipping coordinates bug
// when selecting by rect. the code here should be cleaned to eliminate // when selecting by rect. the code here should be cleaned to eliminate
// references to other modes. // references to other modes.
lastLocation = [self convertPoint:lastLocation fromView:nil]; lastLocation = [self convertPoint:lastLocation fromView:nil];
if ((mode != NSTrackModeMatrix) && (mode != NSHighlightModeMatrix)) if ((mode != NSTrackModeMatrix) && (mode != NSHighlightModeMatrix))
[NSEvent startPeriodicEventsAfterDelay:0.05 withPeriod:0.05]; [NSEvent startPeriodicEventsAfterDelay:0.05 withPeriod:0.05];
ASSIGN(lastEvent, theEvent); ASSIGN(lastEvent, theEvent);
[window _captureMouse: self]; // grab the mouse [window _captureMouse: self]; // grab the mouse
[self lockFocus]; // selection involves two steps, first [self lockFocus]; // selection involves two steps, first
// a loop that continues until the left // a loop that continues until the left
while (!done) // mouse goes up; then a series of while (!done) // mouse goes up; then a series of
{ // steps which send actions and display { // steps which send actions and display
BOOL shouldProceedEvent = NO; // the cell as it should appear after BOOL shouldProceedEvent = NO; // the cell as it should appear after
// the selection process is complete // the selection process is complete
insideBounds = [self _getRow:&row insideBounds = [self _getRow:&row
column:&column column:&column
forPoint:lastLocation forPoint:lastLocation
above:NO right:NO above:NO right:NO
isBetweenCells:&isBetweenCells]; isBetweenCells:&isBetweenCells];
if (insideBounds && !isBetweenCells) if (insideBounds && !isBetweenCells)
{ {
aCell = [self cellAtRow:row column:column]; aCell = [self cellAtRow:row column:column];
rect = [self cellFrameAtRow:row column:column]; rect = [self cellFrameAtRow:row column:column];
switch (mode) switch (mode)
{ {
case NSTrackModeMatrix: // in Track mode the cell case NSTrackModeMatrix: // in Track mode the cell
selectedCell = aCell; // should track the mouse selectedCell = aCell; // should track the mouse
selectedRow = row; // until the cursor either selectedRow = row; // until the cursor either
selectedColumn = column; // leaves the cellframe or selectedColumn = column; // leaves the cellframe or
// NSLeftMouseUp occurs // NSLeftMouseUp occurs
if([aCell trackMouse:lastEvent if ([aCell trackMouse:lastEvent
inRect:rect inRect:rect
ofView:self ofView:self
untilMouseUp:YES]) // YES if mouse untilMouseUp:YES]) // YES if mouse
done = YES; // went up in cell done = YES; // went up in cell
break; break;
case NSHighlightModeMatrix: // Highlight mode is like case NSHighlightModeMatrix: // Highlight mode is like
[aCell setState:1]; // Track mode except that [aCell setState:1]; // Track mode except that
selectedCell = aCell; // the cell is lit before selectedCell = aCell; // the cell is lit before
selectedRow = row; // it begins tracking and selectedRow = row; // it begins tracking and
selectedColumn = column; // unlit afterwards selectedColumn = column; // unlit afterwards
[aCell highlight: YES withFrame: rect inView: self]; [aCell highlight: YES withFrame: rect inView: self];
[window flushWindow]; [window flushWindow];
if([aCell trackMouse:lastEvent if ([aCell trackMouse:lastEvent
inRect:rect inRect:rect
ofView:self ofView:self
untilMouseUp:YES]) // YES if mouse untilMouseUp:YES]) // YES if mouse
done = YES; // went up in cell done = YES; // went up in cell
[aCell setState:0]; [aCell setState:0];
[aCell highlight: NO withFrame: rect inView: self]; [aCell highlight: NO withFrame: rect inView: self];
[window flushWindow]; [window flushWindow];
break; break;
case NSRadioModeMatrix: // Radio mode allows no case NSRadioModeMatrix: // Radio mode allows no
if (previousCell == aCell) // more than one cell if (previousCell == aCell) // more than one cell
break; // to be selected break; // to be selected
if(selectedCell) if (selectedCell)
{ {
[selectedCell setState:0]; // deselect previously [selectedCell setState:0]; // deselect previously
if (!previousCell) // selected cell if (!previousCell) // selected cell
previousCellRect = [self cellFrameAtRow:selectedRow previousCellRect = [self cellFrameAtRow:selectedRow
column:selectedColumn]; column:selectedColumn];
[selectedCell highlight:NO [selectedCell highlight:NO
withFrame:previousCellRect withFrame:previousCellRect
inView:self]; inView:self];
((tMatrix)selectedCells)->matrix[selectedRow] ((tMatrix)selectedCells)->matrix[selectedRow]
[selectedColumn] = NO; [selectedColumn] = NO;
} }
selectedCell = aCell; // select current cell selectedCell = aCell; // select current cell
selectedRow = row; selectedRow = row;
selectedColumn = column; selectedColumn = column;
[aCell setState:1]; [aCell setState:1];
[aCell highlight:YES withFrame:rect inView:self]; [aCell highlight:YES withFrame:rect inView:self];
((tMatrix)selectedCells)->matrix[row][column] = YES; ((tMatrix)selectedCells)->matrix[row][column] = YES;
[window flushWindow]; [window flushWindow];
break; break;
// List mode allows // List mode allows
@ -1359,27 +1368,27 @@ static MPoint anchor = {0, 0};
unsigned modifiers = [lastEvent modifierFlags]; unsigned modifiers = [lastEvent modifierFlags];
if (previousCell == aCell) if (previousCell == aCell)
break; // When the user first clicks on a cell break; // When the user first clicks on a cell
// we clear the existing selection // we clear the existing selection
if (!previousCell) // unless the Alternate or Shift keys if (!previousCell) // unless the Alternate or Shift keys
{ // have been pressed. { // have been pressed.
if (!(modifiers & NSShiftKeyMask) && if (!(modifiers & NSShiftKeyMask) &&
!(modifiers & NSAlternateKeyMask)) !(modifiers & NSAlternateKeyMask))
{ {
[self deselectAllCells]; [self deselectAllCells];
anchor = MakePoint (column, row); anchor = MakePoint (column, row);
} // Consider the selected cell as the } // Consider the selected cell as the
// anchor from which to extend the // anchor from which to extend the
// selection to the current cell // selection to the current cell
if (!(modifiers & NSAlternateKeyMask)) if (!(modifiers & NSAlternateKeyMask))
{ {
selectedCell = aCell; // select current cell selectedCell = aCell; // select current cell
selectedRow = row; selectedRow = row;
selectedColumn = column; selectedColumn = column;
[selectedCell setState:1]; [selectedCell setState:1];
[selectedCell highlight:YES [selectedCell highlight:YES
withFrame:rect withFrame:rect
inView:self]; inView:self];
((tMatrix)selectedCells)->matrix[row][column] =YES; ((tMatrix)selectedCells)->matrix[row][column] =YES;
[window flushWindow]; [window flushWindow];
@ -1410,13 +1419,13 @@ static MPoint anchor = {0, 0};
if (done) // if done break out of if (done) // if done break out of
break; // the selection loop break; // the selection loop
while (!shouldProceedEvent) while (!shouldProceedEvent)
{ // Get the next event { // Get the next event
theEvent = [app nextEventMatchingMask:eventMask theEvent = [app nextEventMatchingMask:eventMask
untilDate:[NSDate distantFuture] untilDate:[NSDate distantFuture]
inMode:NSEventTrackingRunLoopMode inMode:NSEventTrackingRunLoopMode
dequeue:YES]; dequeue:YES];
switch ([theEvent type]) switch ([theEvent type])
{ {
case NSPeriodic: case NSPeriodic:
NSDebugLog(@"NSMatrix: got NSPeriodic event\n"); NSDebugLog(@"NSMatrix: got NSPeriodic event\n");
@ -1426,9 +1435,9 @@ static MPoint anchor = {0, 0};
done = YES; // Track and Highlight modes do not use done = YES; // Track and Highlight modes do not use
case NSLeftMouseDown: // periodic events so we must break out case NSLeftMouseDown: // periodic events so we must break out
default: // and check if the mouse is in a cell default: // and check if the mouse is in a cell
if ((mode == NSTrackModeMatrix) || if ((mode == NSTrackModeMatrix) ||
(mode == NSHighlightModeMatrix)) (mode == NSHighlightModeMatrix))
shouldProceedEvent = YES; shouldProceedEvent = YES;
NSDebugLog(@"NSMatrix: got event of type: %d\n", NSDebugLog(@"NSMatrix: got event of type: %d\n",
[theEvent type]); [theEvent type]);
ASSIGN(lastEvent, theEvent); ASSIGN(lastEvent, theEvent);
@ -1438,40 +1447,40 @@ static MPoint anchor = {0, 0};
lastLocation = [lastEvent locationInWindow]; lastLocation = [lastEvent locationInWindow];
lastLocation = [self convertPoint:lastLocation fromView:nil]; lastLocation = [self convertPoint:lastLocation fromView:nil];
} }
[window _releaseMouse: self]; // Release the mouse [window _releaseMouse: self]; // Release the mouse
switch (mode) // Finish the selection switch (mode) // Finish the selection
{ // process { // process
case NSRadioModeMatrix: case NSRadioModeMatrix:
if(selectedCell) if (selectedCell)
[selectedCell highlight:NO withFrame:rect inView:self]; [selectedCell highlight:NO withFrame:rect inView:self];
case NSListModeMatrix: case NSListModeMatrix:
[self setNeedsDisplayInRect:rect]; // not needed by XRAW [self setNeedsDisplayInRect:rect]; // not needed by XRAW
[window flushWindow]; [window flushWindow];
case NSHighlightModeMatrix: case NSHighlightModeMatrix:
case NSTrackModeMatrix: case NSTrackModeMatrix:
break; break;
} }
if(selectedCell) if (selectedCell)
{ // send single click action { // send single click action
if(!(selectedCellTarget = [selectedCell target])) if (!(selectedCellTarget = [selectedCell target]))
{ // selected cell has no target so send single { // selected cell has no target so send single
if (target) // click action to matrix's (self's) target if (target) // click action to matrix's (self's) target
[target performSelector:action withObject:self]; [target performSelector:action withObject:self];
} // in Track and Highlight modes the single } // in Track and Highlight modes the single
else // click action has already been sent by the else // click action has already been sent by the
{ // cell to it's target (if it has one) { // cell to it's target (if it has one)
if ((mode != NSTrackModeMatrix) && (mode != NSHighlightModeMatrix)) if ((mode != NSTrackModeMatrix) && (mode != NSHighlightModeMatrix))
[selectedCellTarget performSelector:[selectedCell action] [selectedCellTarget performSelector:[selectedCell action]
withObject:self]; withObject:self];
} }
} }
// click count > 1 indicates a double click // click count > 1 indicates a double click
if (target && doubleAction && ([lastEvent clickCount] > 1)) if (target && doubleAction && ([lastEvent clickCount] > 1))
[target performSelector:doubleAction withObject:self]; [target performSelector:doubleAction withObject:self];
[self unlockFocus]; [self unlockFocus];
if ((mode != NSTrackModeMatrix) && (mode != NSHighlightModeMatrix)) if ((mode != NSTrackModeMatrix) && (mode != NSHighlightModeMatrix))
@ -1480,21 +1489,16 @@ static MPoint anchor = {0, 0};
[lastEvent release]; [lastEvent release];
} }
- (void)updateCell:(NSCell *)aCell - (void) updateCell: (NSCell*)aCell
{ // attempt to update {
int r, c; // only the cell and int row, col;
// not the hole matrix NSRect rect;
if([aCell isOpaque])
{
if([self getRow:&r column:&c ofCell:aCell])
{
[self setNeedsDisplayInRect:[self cellFrameAtRow:r column:c]];
return; if ([self getRow: &row column: &col ofCell: aCell] == NO)
} return; // Not a cell in this matrix - we can't update it.
}
// oh well, update the rect = [self cellFrameAtRow: row column: col];
[self setNeedsDisplay:YES]; // whole matrix [self setNeedsDisplayInRect: rect];
} }
- (BOOL)performKeyEquivalent:(NSEvent*)theEvent - (BOOL)performKeyEquivalent:(NSEvent*)theEvent
@ -1674,12 +1678,12 @@ fprintf(stderr, " NSMatrix: keyDown --- ");
Note that the cell numbering is flipped relative to the coordinate system. Note that the cell numbering is flipped relative to the coordinate system.
*/ */
- (BOOL)_getRow:(int*)row - (BOOL) _getRow: (int*)row
column:(int*)column column: (int*)column
forPoint:(NSPoint)point forPoint: (NSPoint)point
above:(BOOL)aboveRequired above: (BOOL)aboveRequired
right:(BOOL)rightRequired right: (BOOL)rightRequired
isBetweenCells:(BOOL*)isBetweenCells isBetweenCells: (BOOL*)isBetweenCells
{ {
BOOL rowReady = NO, colReady = NO; BOOL rowReady = NO, colReady = NO;
BOOL betweenRows = NO, betweenCols = NO; BOOL betweenRows = NO, betweenCols = NO;
@ -1688,78 +1692,87 @@ fprintf(stderr, " NSMatrix: keyDown --- ");
SET_POINTER_VALUE(isBetweenCells, NO); SET_POINTER_VALUE(isBetweenCells, NO);
/* First check the limit cases */ /* First check the limit cases */
if (point.x > theBounds.size.width) { if (point.x > theBounds.size.width)
SET_POINTER_VALUE(column, numCols - 1); {
colReady = YES; SET_POINTER_VALUE(column, numCols - 1);
} colReady = YES;
else if (point.x < 0) { }
SET_POINTER_VALUE(column, 0); else if (point.x < 0)
colReady = YES; {
} SET_POINTER_VALUE(column, 0);
colReady = YES;
}
if (point.y > theBounds.size.height) { if (point.y > theBounds.size.height)
SET_POINTER_VALUE(row, numRows - 1); {
rowReady = YES; SET_POINTER_VALUE(row, numRows - 1);
} rowReady = YES;
else if (point.y < 0) { }
SET_POINTER_VALUE(row, 0); else if (point.y < 0)
rowReady = YES; {
} SET_POINTER_VALUE(row, 0);
rowReady = YES;
}
if (rowReady && colReady) if (rowReady && colReady)
return NO; return NO;
if (!rowReady) { if (!rowReady)
int approxRow = point.y / (cellSize.height + intercell.height); {
float approxRowsHeight = approxRow * (cellSize.height + intercell.height); int approxRow = point.y / (cellSize.height + intercell.height);
float approxRowsHeight = approxRow * (cellSize.height + intercell.height);
/* Determine if the point is inside the cell */ /* Determine if the point is inside the cell */
betweenRows = !(point.y > approxRowsHeight betweenRows = !(point.y > approxRowsHeight
&& point.y <= approxRowsHeight + cellSize.height); && point.y <= approxRowsHeight + cellSize.height);
/* If the point is between cells then adjust the computed row taking into /* If the point is between cells then adjust the computed row taking into
account the `aboveRequired' flag. */ account the `aboveRequired' flag. */
if (aboveRequired && betweenRows) if (aboveRequired && betweenRows)
approxRow++; approxRow++;
#if HAS_FLIPPED_VIEWS #if HAS_FLIPPED_VIEWS == 0
SET_POINTER_VALUE(row, approxRow); approxRow = numRows - approxRow - 1;
#else
SET_POINTER_VALUE(row, numRows - approxRow - 1);
#endif #endif
if (*row < 0) { if (approxRow < 0)
*row = -1; {
rowReady = YES; approxRow = -1;
rowReady = YES;
}
else if (approxRow >= numRows)
{
approxRow = numRows - 1;
rowReady = YES;
}
SET_POINTER_VALUE(row, approxRow);
} }
else if (*row >= numRows) {
*row = numRows - 1; if (!colReady)
rowReady = YES; {
int approxCol = point.x / (cellSize.width + intercell.width);
float approxColsWidth = approxCol * (cellSize.width + intercell.width);
/* Determine if the point is inside the cell */
betweenCols = !(point.x > approxColsWidth
&& point.x <= approxColsWidth + cellSize.width);
/* If the point is between cells then adjust the computed column taking
into account the `rightRequired' flag. */
if (rightRequired && betweenCols)
approxCol++;
if (approxCol < 0)
{
approxCol = -1;
colReady = YES;
}
else if (approxCol >= numCols)
{
approxCol = numCols - 1;
colReady = YES;
}
SET_POINTER_VALUE(column, approxCol);
} }
}
if (!colReady) {
int approxCol = point.x / (cellSize.width + intercell.width);
float approxColsWidth = approxCol * (cellSize.width + intercell.width);
/* Determine if the point is inside the cell */
betweenCols = !(point.x > approxColsWidth
&& point.x <= approxColsWidth + cellSize.width);
/* If the point is between cells then adjust the computed column taking
into account the `rightRequired' flag. */
if (rightRequired && betweenCols)
approxCol++;
SET_POINTER_VALUE(column, approxCol);
if (*column < 0) {
*column = -1;
colReady = YES;
}
else if (*column >= numCols) {
*column = numCols - 1;
colReady = YES;
}
}
/* If the point is outside the matrix bounds return NO */ /* If the point is outside the matrix bounds return NO */
if (rowReady || colReady) if (rowReady || colReady)