diff --git a/Source/NSBitmapImageRep.m b/Source/NSBitmapImageRep.m index 7ab274e2a..075a61acf 100644 --- a/Source/NSBitmapImageRep.m +++ b/Source/NSBitmapImageRep.m @@ -222,6 +222,22 @@ [super dealloc]; } +- (id) copyWithZone: (NSZone *)zone +{ + NSBitmapImageRep *copy; + + copy = (NSBitmapImageRep*)[super copyWithZone: zone]; + + copy->bytesPerRow = bytesPerRow; + copy->numColors = numColors; + copy->bitsPerPixel = bitsPerPixel; + copy->compression = compression; + copy->_isPlanar = _isPlanar; + copy->imagePlanes = 0; + copy->imageData = [imageData copy]; + + return copy; +} + (BOOL) canInitWithData: (NSData *)data { TIFF *image = NULL; diff --git a/Source/NSBrowser.m b/Source/NSBrowser.m index d75087620..3700c7c45 100644 --- a/Source/NSBrowser.m +++ b/Source/NSBrowser.m @@ -1386,35 +1386,38 @@ - (void)_adjustMatrixOfColumn: (int)column { -NSBrowserColumn *bc; -NSScrollView *sc; -id matrix; -NSSize cs, ms; -NSRect mr; + NSBrowserColumn *bc; + NSScrollView *sc; + id matrix; + NSSize cs, ms; + NSRect mr; - if (column >= (int)[_browserColumns count]) - return; + if (column >= (int)[_browserColumns count]) + return; - bc = [_browserColumns objectAtIndex: column]; - sc = [bc columnScrollView]; - matrix = [bc columnMatrix]; - // Adjust matrix to fit in scrollview - if (sc && matrix && [bc isLoaded]) // do it only if column has been loaded - { - cs = [sc contentSize]; - ms = [matrix cellSize]; - ms.width = cs.width; - [matrix setCellSize: ms]; - mr = [matrix frame]; + bc = [_browserColumns objectAtIndex: column]; + sc = [bc columnScrollView]; + matrix = [bc columnMatrix]; - if (mr.size.height < cs.height) // matrix smaller than - { // scrollview's content - mr.origin.y = cs.height; // view requires origin - [matrix setFrame: mr]; // adjustment for it to - } // appear at top + // Adjust matrix to fit in scrollview if column has been loaded + if (sc && matrix && [bc isLoaded]) + { + cs = [sc contentSize]; + ms = [matrix cellSize]; + ms.width = cs.width; + [matrix setCellSize: ms]; + mr = [matrix frame]; - [sc setDocumentView: matrix]; - } + // matrix smaller than scrollview's content + if (mr.size.height < cs.height) + { + // view requires origin adjustment for it to appear at top + mr.origin.y = cs.height; + [matrix setFrame: mr]; + } + + [sc setDocumentView: matrix]; + } } - (void)_adjustScrollerFrameOfColumn: (int)column force: (BOOL)flag @@ -1499,7 +1502,8 @@ NSRect mr; NSRect matrixRect = {{0, 0}, {100, 100}}; int i; - matrix = [[[_browserMatrixClass alloc] // create a new col matrix + // create a new col matrix + matrix = [[[_browserMatrixClass alloc] initWithFrame: matrixRect mode: NSListModeMatrix prototype: _browserCellPrototype @@ -1513,7 +1517,8 @@ NSRect mr; [matrix setAction: @selector(doClick:)]; [matrix setDoubleAction: @selector(doDoubleClick:)]; - [bc setColumnMatrix: matrix]; // set new col matrix and release old + // set new col matrix and release old + [bc setColumnMatrix: matrix]; [sc setDocumentView: matrix]; // Now loop through the cells and load each one @@ -1533,7 +1538,8 @@ NSRect mr; id oldm = [bc columnMatrix]; NSRect matrixRect = {{0, 0}, {100, 100}}; - matrix = [[[_browserMatrixClass alloc] // create a new col matrix + // create a new col matrix + matrix = [[[_browserMatrixClass alloc] initWithFrame: matrixRect mode: NSListModeMatrix prototype: _browserCellPrototype @@ -1547,16 +1553,19 @@ NSRect mr; [matrix setAction: @selector(doClick:)]; [matrix setDoubleAction: @selector(doDoubleClick:)]; - [bc setColumnMatrix: matrix]; // set new col matrix and release old + // set new col matrix and release old + [bc setColumnMatrix: matrix]; [sc setDocumentView: matrix]; // Tell the delegate to create the rows - [_browserDelegate browser: self createRowsForColumn: column - inMatrix: matrix]; + [_browserDelegate browser: self + createRowsForColumn: column + inMatrix: matrix]; } } [bc setIsLoaded: YES]; + [self setNeedsDisplayInRect: [self frameOfColumn: column]]; } - (void)_unloadFromColumn: (int)column diff --git a/Source/NSBrowserCell.m b/Source/NSBrowserCell.m index b1fcb4aad..d4fd2fe8e 100644 --- a/Source/NSBrowserCell.m +++ b/Source/NSBrowserCell.m @@ -268,10 +268,9 @@ static NSImage *highlight_image; control_view = controlView; // remember last view cell was drawn in if (cell_highlighted || cell_state) // temporary hack FAR FIX ME? { - NSColor *white = [NSColor whiteColor]; + NSColor *backColor = [NSColor selectedControlColor]; - [white set]; -// [_browserText setBackgroundColor: white]; + [backColor set]; if (!_isLeaf) { image = _highlightBranchImage; @@ -288,7 +287,6 @@ static NSImage *highlight_image; NSColor *backColor = [[controlView window] backgroundColor]; [backColor set]; -// [_browserText setBackgroundColor: backColor]; if (!_isLeaf) { image = _branchImage; diff --git a/Source/NSCell.m b/Source/NSCell.m index 1bf415409..ee7a097ed 100644 --- a/Source/NSCell.m +++ b/Source/NSCell.m @@ -442,7 +442,7 @@ delegate: (id)anObject start: (int)selStart length: (int)selLength -{ // preliminary FIX ME +{ if (!controlView || !textObject || !cell_font || (cell_type != NSTextCellType)) return; @@ -450,10 +450,13 @@ [[controlView window] makeFirstResponder: textObject]; [textObject setFrame: aRect]; + [textObject setAlignment: text_align]; [textObject setText: [self stringValue]]; [textObject setDelegate: anObject]; [controlView addSubview: textObject]; + [controlView lockFocus]; NSEraseRect(aRect); + [controlView unlockFocus]; [textObject display]; } diff --git a/Source/NSImageRep.m b/Source/NSImageRep.m index e10253929..21cb2e88e 100644 --- a/Source/NSImageRep.m +++ b/Source/NSImageRep.m @@ -1,30 +1,30 @@ -/* +/* NSImageRep.m Abstract representation of an image. Copyright (C) 1996 Free Software Foundation, Inc. - + Author: Adam Fedor Date: Feb 1996 - + This file is part of the GNUstep Application Kit Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. - + You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ +*/ #include #include @@ -130,7 +130,7 @@ static NSMutableArray* imageReps = NULL; NSString* ptype; Class rep = [imageReps objectAtIndex: i]; if ([rep respondsToSelector: @selector(imagePasteboardTypes)] - && (ptype = + && (ptype = [pasteboard availableTypeFromArray: [rep imagePasteboardTypes]])) { NSData* data = [pasteboard dataForType: ptype]; @@ -143,13 +143,30 @@ static NSMutableArray* imageReps = NULL; return (NSArray *)array; } +- (id) copyWithZone: (NSZone *)zone +{ + NSImageRep *copy; + + copy = (NSImageRep*)NSCopyObject(self, 0, zone); + + copy->size = size; + copy->hasAlpha = hasAlpha; + copy->isOpaque = isOpaque; + copy->bitsPerSample = bitsPerSample; + copy->_pixelsWide = _pixelsWide; + copy->_pixelsHigh = _pixelsHigh; + copy->_colorSpace = RETAIN(_colorSpace); + + return copy; +} + - (void) dealloc { [_colorSpace release]; [super dealloc]; } -// Checking Data Types +// Checking Data Types + (BOOL) canInitWithData: (NSData *)data { /* Subclass responsibility */ @@ -186,7 +203,7 @@ static NSMutableArray* imageReps = NULL; return nil; } -// Setting the Size of the Image +// Setting the Size of the Image - (void) setSize: (NSSize)aSize { size = aSize; @@ -197,7 +214,7 @@ static NSMutableArray* imageReps = NULL; return size; } -// Specifying Information about the Representation +// Specifying Information about the Representation - (int) bitsPerSample { return bitsPerSample; @@ -259,7 +276,7 @@ static NSMutableArray* imageReps = NULL; _pixelsHigh = anInt; } -// Drawing the Image +// Drawing the Image - (BOOL) draw { [self subclassResponsibility: _cmd]; @@ -276,7 +293,7 @@ static NSMutableArray* imageReps = NULL; return NO; } -// Managing NSImageRep Subclasses +// Managing NSImageRep Subclasses + (Class) imageRepClassForData: (NSData *)data { int i, count; @@ -328,10 +345,10 @@ static NSMutableArray* imageReps = NULL; + (void) registerImageRepClass: (Class)imageRepClass { [imageReps addObject: imageRepClass]; - [[NSNotificationCenter defaultCenter] + [[NSNotificationCenter defaultCenter] postNotificationName: NSImageRepRegistryChangedNotification object: self]; -} +} + (NSArray *) registeredImageRepClasses { @@ -341,7 +358,7 @@ static NSMutableArray* imageReps = NULL; + (void) unregisterImageRepClass: (Class)imageRepClass { [imageReps removeObject: imageRepClass]; - [[NSNotificationCenter defaultCenter] + [[NSNotificationCenter defaultCenter] postNotificationName: NSImageRepRegistryChangedNotification object: self]; } diff --git a/Source/NSMatrix.m b/Source/NSMatrix.m index cdf245cd1..57ba78853 100644 --- a/Source/NSMatrix.m +++ b/Source/NSMatrix.m @@ -54,15 +54,15 @@ # undef MIN #endif #define MIN(A,B) ({ typeof(A) __a = (A); \ - typeof(B) __b = (B); \ - __a < __b ? __a : __b; }) + typeof(B) __b = (B); \ + __a < __b ? __a : __b; }) #ifdef MAX # undef MAX #endif #define MAX(A,B) ({ typeof(A) __a = (A); \ - typeof(B) __b = (B); \ - __a < __b ? __b : __a; }) + typeof(B) __b = (B); \ + __a < __b ? __b : __a; }) #ifdef ABS # undef ABS @@ -93,12 +93,12 @@ static tMatrix newMatrix (int numRows, int numCols) { int rows = (numRows ? numRows : 1); int cols = (numCols ? numCols : 1); - tMatrix m = malloc (sizeof (struct _tMatrix)); + tMatrix m = malloc (sizeof(struct _tMatrix)); int i; - m->matrix = malloc (rows * sizeof (BOOL*)); + m->matrix = malloc (rows * sizeof(BOOL*)); for (i = 0; i < rows; i++) - m->matrix[i] = calloc (cols, sizeof (BOOL)); + m->matrix[i] = calloc (cols, sizeof(BOOL)); m->allocatedRows = rows; m->allocatedCols = cols; @@ -126,7 +126,7 @@ static void growMatrix (tMatrix m, int numRows, int numCols) if (numCols > m->allocatedCols) { /* Grow the existing rows to numCols */ for (i = 0; i < m->allocatedRows; i++) { - m->matrix[i] = realloc (m->matrix[i], numCols * sizeof (BOOL)); + m->matrix[i] = realloc (m->matrix[i], numCols * sizeof(BOOL)); for (j = m->allocatedCols - 1; j < numCols; j++) m->matrix[i][j] = NO; } @@ -135,16 +135,16 @@ static void growMatrix (tMatrix m, int numRows, int numCols) if (numRows > m->allocatedRows) { /* Grow the vector that keeps the rows */ - m->matrix = realloc (m->matrix, numRows * sizeof (BOOL*)); + m->matrix = realloc (m->matrix, numRows * sizeof(BOOL*)); /* Allocate the rows up to allocatedRows that are NULL */ for (i = 0; i < m->allocatedRows; i++) if (!m->matrix[i]) - m->matrix[i] = calloc (m->allocatedCols, sizeof (BOOL)); + m->matrix[i] = calloc (m->allocatedCols, sizeof(BOOL)); /* Add the necessary rows */ for (i = m->allocatedRows; i < numRows; i++) - m->matrix[i] = calloc (m->allocatedCols, sizeof (BOOL)); + m->matrix[i] = calloc (m->allocatedCols, sizeof(BOOL)); m->allocatedRows = numRows; } @@ -158,10 +158,11 @@ static void insertRow (tMatrix m, int rowPosition) int i; /* Create space for the new rows if necessary */ - if (rows > m->allocatedRows) { - m->matrix = realloc (m->matrix, rows * sizeof (BOOL*)); - m->allocatedRows = rows; - } + if (rows > m->allocatedRows) + { + m->matrix = realloc (m->matrix, rows * sizeof(BOOL*)); + m->allocatedRows = rows; + } /* Make room for the new row */ for (i = m->numRows - 1; i > rowPosition; i--) @@ -170,10 +171,10 @@ static void insertRow (tMatrix m, int rowPosition) /* Allocate any NULL row that exists up to rowPosition */ for (i = 0; i < rowPosition; i++) if (!m->matrix[i]) - m->matrix[i] = calloc (m->allocatedCols, sizeof (BOOL)); + m->matrix[i] = calloc (m->allocatedCols, sizeof(BOOL)); /* Create the required row */ - m->matrix[rowPosition] = calloc (m->allocatedCols, sizeof (BOOL)); + m->matrix[rowPosition] = calloc (m->allocatedCols, sizeof(BOOL)); m->numRows++; } @@ -184,26 +185,29 @@ static void insertColumn (tMatrix m, int colPosition) int i, j; /* First grow the rows to hold `cols' elements */ - if (cols > m->allocatedCols) { - for (i = 0; i < m->numRows; i++) - m->matrix[i] = realloc (m->matrix[i], cols * sizeof (BOOL)); - m->allocatedCols = cols; - } + if (cols > m->allocatedCols) + { + for (i = 0; i < m->numRows; i++) + m->matrix[i] = realloc (m->matrix[i], cols * sizeof(BOOL)); + m->allocatedCols = cols; + } /* Now insert a new column between the rows, in the required position. If it happens that a row is NULL create a new row with the maximum number of columns for it. */ - for (i = 0; i < m->numRows; i++) { - BOOL* row = m->matrix[i]; + for (i = 0; i < m->numRows; i++) + { + BOOL* row = m->matrix[i]; - if (!row) - m->matrix[i] = calloc (m->allocatedCols, sizeof (BOOL)); - else { - for (j = m->numCols - 1; j > colPosition; j--) - row[j] = row[j - 1]; - row[colPosition] = NO; + if (!row) + m->matrix[i] = calloc (m->allocatedCols, sizeof(BOOL)); + else + { + for (j = m->numCols - 1; j > colPosition; j--) + row[j] = row[j - 1]; + row[colPosition] = NO; + } } - } m->numCols++; } @@ -224,13 +228,14 @@ static void removeColumn (tMatrix m, int column) { int i, j; - for (i = 0; i < m->numRows; i++) { - BOOL* row = m->matrix[i]; + for (i = 0; i < m->numRows; i++) + { + BOOL* row = m->matrix[i]; - for (j = column; j < m->numCols - 1; j++) - row[j] = row[j + 1]; - row[m->numCols] = NO; - } + for (j = column; j < m->numCols - 1; j++) + row[j] = row[j + 1]; + row[m->numCols] = NO; + } m->numCols--; } @@ -259,20 +264,20 @@ static inline MPoint MakePoint (int x, int y) to the left or to the right of point. `point' is in the matrix coordinates. Returns NO if the point is outside the bounds of matrix, YES otherwise. */ -- (BOOL)_getRow:(int*)row - column:(int*)column - forPoint:(NSPoint)point - above:(BOOL)aboveRequired - right:(BOOL)rightRequired - isBetweenCells:(BOOL*)isBetweenCells; -- (void)_selectRectUsingAnchor:(MPoint)anchor - last:(MPoint)last - current:(MPoint)current; -- (void)_setState:(int)state inRect:(MRect)rect; -- (void)_selectContinuousUsingAnchor:(MPoint)anchor - last:(MPoint)last - current:(MPoint)current; -- (void)_setState:(int)state startIndex:(int)start endIndex:(int)end; +- (BOOL) _getRow: (int*)row + column: (int*)column + forPoint: (NSPoint)point + above: (BOOL)aboveRequired + right: (BOOL)rightRequired + isBetweenCells: (BOOL*)isBetweenCells; +- (void) _selectRectUsingAnchor: (MPoint)anchor + last: (MPoint)last + current: (MPoint)current; +- (void) _setState: (int)state inRect: (MRect)rect; +- (void) _selectContinuousUsingAnchor: (MPoint)anchor + last: (MPoint)last + current: (MPoint)current; +- (void) _setState: (int)state startIndex: (int)start endIndex: (int)end; @end enum { @@ -286,103 +291,107 @@ enum { static Class defaultCellClass = nil; static int mouseDownFlags = 0; -+ (void)initialize ++ (void) initialize { - if (self == [NSMatrix class]) { - /* Set the initial version */ - [self setVersion: 1]; + if (self == [NSMatrix class]) + { + /* Set the initial version */ + [self setVersion: 1]; - /* Set the default cell class */ - defaultCellClass = [NSCell class]; - } + /* Set the default cell class */ + defaultCellClass = [NSCell class]; + } } -+ (Class)cellClass ++ (Class) cellClass { return defaultCellClass; } -+ (void)setCellClass:(Class)classId ++ (void) setCellClass: (Class)classId { defaultCellClass = classId; } - init { - return [self initWithFrame:NSZeroRect - mode:NSRadioModeMatrix - prototype:[[[isa cellClass] new] autorelease] - numberOfRows:0 - numberOfColumns:1]; + return [self initWithFrame: NSZeroRect + mode: NSRadioModeMatrix + prototype: [[[isa cellClass] new] autorelease] + numberOfRows: 0 + numberOfColumns: 1]; } -- (id)initWithFrame:(NSRect)frameRect +- (id) initWithFrame: (NSRect)frameRect { - return [self initWithFrame:frameRect - mode:NSRadioModeMatrix - cellClass:[isa cellClass] - numberOfRows:0 - numberOfColumns:0]; + return [self initWithFrame: frameRect + mode: NSRadioModeMatrix + cellClass: [isa cellClass] + numberOfRows: 0 + numberOfColumns: 0]; } -- (id)initWithFrame:(NSRect)frameRect - mode:(int)aMode - cellClass:(Class)class - numberOfRows:(int)rowsHigh - numberOfColumns:(int)colsWide +- (id) initWithFrame: (NSRect)frameRect + mode: (int)aMode + cellClass: (Class)class + numberOfRows: (int)rowsHigh + numberOfColumns: (int)colsWide { - return [self initWithFrame:frameRect - mode:aMode - prototype:[[class new] autorelease] - numberOfRows:rowsHigh - numberOfColumns:colsWide]; + return [self initWithFrame: frameRect + mode: aMode + prototype: [[class new] autorelease] + numberOfRows: rowsHigh + numberOfColumns: colsWide]; } -- (id)initWithFrame:(NSRect)frameRect - mode:(int)aMode - prototype:(NSCell*)prototype - numberOfRows:(int)rows - numberOfColumns:(int)cols +- (id) initWithFrame: (NSRect)frameRect + mode: (int)aMode + prototype: (NSCell*)prototype + numberOfRows: (int)rows + numberOfColumns: (int)cols { int i, j; - [super initWithFrame:frameRect]; + [super initWithFrame: frameRect]; ASSIGN(cellPrototype, prototype); - cells = [[NSMutableArray alloc] initWithCapacity:rows]; + cells = [[NSMutableArray alloc] initWithCapacity: rows]; selectedCells = newMatrix (rows, cols); - for (i = 0; i < rows; i++) { - NSMutableArray* row = [NSMutableArray arrayWithCapacity:cols]; + for (i = 0; i < rows; i++) + { + NSMutableArray* row = [NSMutableArray arrayWithCapacity: cols]; - [cells addObject:row]; - for (j = 0; j < cols; j++) { - [row addObject:[[cellPrototype copy] autorelease]]; + [cells addObject: row]; + for (j = 0; j < cols; j++) + { + [row addObject: [[cellPrototype copy] autorelease]]; + } } - } numRows = rows; numCols = cols; mode = aMode; - [self setFrame:frameRect]; + [self setFrame: frameRect]; cellSize = NSMakeSize(DEFAULT_CELL_WIDTH, DEFAULT_CELL_HEIGHT); intercell = NSMakeSize(1, 1); - [self setBackgroundColor:[NSColor lightGrayColor]]; - [self setDrawsBackground:YES]; - [self setCellBackgroundColor:[NSColor lightGrayColor]]; - [self setSelectionByRect:YES]; - [self setAutosizesCells:YES]; - if (mode == NSRadioModeMatrix && numRows && numCols) { - [self selectCellAtRow:0 column:0]; - } + [self setBackgroundColor: [NSColor lightGrayColor]]; + [self setDrawsBackground: YES]; + [self setCellBackgroundColor: [NSColor lightGrayColor]]; + [self setSelectionByRect: YES]; + [self setAutosizesCells: YES]; + if (mode == NSRadioModeMatrix && numRows && numCols) + { + [self selectCellAtRow: 0 column: 0]; + } else selectedRow = selectedColumn = 0; return self; } -- (void)dealloc +- (void) dealloc { [cells release]; [cellPrototype release]; @@ -392,112 +401,114 @@ static int mouseDownFlags = 0; [super dealloc]; } -- (void)addColumn +- (void) addColumn { - [self insertColumn:numCols]; + [self insertColumn: numCols]; } -- (void)addColumnWithCells:(NSArray*)cellArray +- (void) addColumnWithCells: (NSArray*)cellArray { - [self insertColumn:numCols withCells:cellArray]; + [self insertColumn: numCols withCells: cellArray]; } -- (void)addRow +- (void) addRow { - [self insertRow:numRows]; + [self insertRow: numRows]; } -- (void)addRowWithCells:(NSArray*)cellArray +- (void) addRowWithCells: (NSArray*)cellArray { - [self insertRow:numRows withCells:cellArray]; + [self insertRow: numRows withCells: cellArray]; } -- (void)insertColumn:(int)column +- (void) insertColumn: (int)column { int i; /* Grow the matrix if necessary */ if (column >= numCols) - [self renewRows:(numRows == 0 ? 1 : numRows) columns:column]; - if (numRows == 0) { - numRows = 1; - [cells addObject:[NSMutableArray array]]; - } + [self renewRows: (numRows == 0 ? 1 : numRows) columns: column]; + if (numRows == 0) + { + numRows = 1; + [cells addObject: [NSMutableArray array]]; + } numCols++; for (i = 0; i < numRows; i++) - [self makeCellAtRow:i column:column]; + [self makeCellAtRow: i column: column]; insertColumn (selectedCells, column); if (mode == NSRadioModeMatrix && !allowsEmptySelection && !selectedCell) - [self selectCellAtRow:0 column:0]; + [self selectCellAtRow: 0 column: 0]; } -- (void)insertColumn:(int)column withCells:(NSArray*)cellArray +- (void) insertColumn: (int)column withCells: (NSArray*)cellArray { int i; /* Grow the matrix if necessary */ if (column >= numCols) - [self renewRows:(numRows == 0 ? 1 : numRows) columns:column]; - if (numRows == 0) { - numRows = 1; - [cells addObject:[NSMutableArray array]]; - } + [self renewRows: (numRows == 0 ? 1 : numRows) columns: column]; + if (numRows == 0) + { + numRows = 1; + [cells addObject: [NSMutableArray array]]; + } numCols++; for (i = 0; i < numRows; i++) - [[cells objectAtIndex:i] - replaceObjectAtIndex:column withObject:[cellArray objectAtIndex:i]]; + [[cells objectAtIndex: i] + replaceObjectAtIndex: column withObject: [cellArray objectAtIndex: i]]; insertColumn (selectedCells, column); if (mode == NSRadioModeMatrix && !allowsEmptySelection && !selectedCell) - [self selectCellAtRow:0 column:0]; + [self selectCellAtRow: 0 column: 0]; } -- (void)insertRow:(int)row +- (void) insertRow: (int)row { int i; /* Grow the matrix if necessary */ if (row >= numRows) - [self renewRows:row columns:(numCols == 0 ? 1 : numCols)]; + [self renewRows: row columns: (numCols == 0 ? 1 : numCols)]; if (numCols == 0) numCols = 1; - [cells insertObject:[NSMutableArray arrayWithCapacity:numCols] atIndex:row]; + [cells insertObject: [NSMutableArray arrayWithCapacity: numCols] atIndex: row]; numRows++; for (i = 0; i < numCols; i++) - [self makeCellAtRow:row column:i]; + [self makeCellAtRow: row column: i]; insertRow (selectedCells, row); if (mode == NSRadioModeMatrix && !allowsEmptySelection && !selectedCell) - [self selectCellAtRow:0 column:0]; + [self selectCellAtRow: 0 column: 0]; } -- (void)insertRow:(int)row withCells:(NSArray*)cellArray +- (void) insertRow: (int)row withCells: (NSArray*)cellArray { /* Grow the matrix if necessary */ if (row >= numRows) - [self renewRows:row columns:(numCols == 0 ? 1 : numCols)]; + [self renewRows: row columns: (numCols == 0 ? 1 : numCols)]; if (numCols == 0) numCols = 1; - [cells insertObject:[cellArray subarrayWithRange:NSMakeRange(0, numCols)] - atIndex:row]; + [cells insertObject: [cellArray subarrayWithRange: NSMakeRange(0, numCols)] + atIndex: row]; insertRow (selectedCells, row); numRows++; if (mode == NSRadioModeMatrix && !allowsEmptySelection && !selectedCell) - [self selectCellAtRow:0 column:0]; + [self selectCellAtRow: 0 column: 0]; } -- (NSCell*)makeCellAtRow:(int)row - column:(int)column +- (NSCell*) makeCellAtRow: (int)row + column: (int)column { NSCell* aCell; @@ -508,12 +519,12 @@ static int mouseDownFlags = 0; else aCell = [[NSActionCell new] autorelease]; - [[cells objectAtIndex:row] insertObject:aCell atIndex:column]; + [[cells objectAtIndex: row] insertObject: aCell atIndex: column]; return aCell; } -- (NSRect)cellFrameAtRow:(int)row - column:(int)column +- (NSRect) cellFrameAtRow: (int)row + column: (int)column { NSRect rect; @@ -527,22 +538,22 @@ static int mouseDownFlags = 0; return rect; } -- (void)getNumberOfRows:(int*)rowCount - columns:(int*)columnCount +- (void) getNumberOfRows: (int*)rowCount + columns: (int*)columnCount { *rowCount = numRows; *columnCount = numCols; } -- (void)putCell:(NSCell*)newCell - atRow:(int)row - column:(int)column +- (void) putCell: (NSCell*)newCell + atRow: (int)row + column: (int)column { - [[cells objectAtIndex:row] replaceObjectAtIndex:column withObject:newCell]; - [self setNeedsDisplayInRect:[self cellFrameAtRow:row column:column]]; + [[cells objectAtIndex: row] replaceObjectAtIndex: column withObject: newCell]; + [self setNeedsDisplayInRect: [self cellFrameAtRow: row column: column]]; } -- (void)removeColumn:(int)column +- (void) removeColumn: (int)column { int i; @@ -550,351 +561,377 @@ static int mouseDownFlags = 0; return; for (i = 0; i < numRows; i++) - [[cells objectAtIndex:i] removeObjectAtIndex:column]; + [[cells objectAtIndex: i] removeObjectAtIndex: column]; removeColumn (selectedCells, column); numCols--; if (column == selectedColumn) - { - selectedCell = nil; - [self selectCellAtRow:0 column:0]; - } + { + selectedCell = nil; + [self selectCellAtRow: 0 column: 0]; + } } -- (void)removeRow:(int)row +- (void) removeRow: (int)row { if (row >= numRows) return; - [cells removeObjectAtIndex:row]; + [cells removeObjectAtIndex: row]; removeRow (selectedCells, row); numRows--; if (row == selectedRow) - { - selectedCell = nil; - [self selectCellAtRow:0 column:0]; - } + { + selectedCell = nil; + [self selectCellAtRow: 0 column: 0]; + } } -- (void)renewRows:(int)newRows - columns:(int)newColumns +- (void) renewRows: (int)newRows + columns: (int)newColumns { int i, j; - if (newColumns > numCols) { - /* First check to see if the rows really have fewer cells than + if (newColumns > numCols) + { + /* First check to see if the rows really have fewer cells than newColumns. This may happen because the row arrays are not shrink when a lower number of cells is given. */ - if (numRows && newColumns > [[cells objectAtIndex:0] count]) { - /* Add columns to the existing rows. Call makeCellAtRow:column: - to be consistent. */ - for (i = 0; i < numRows; i++) { - for (j = numCols; j < newColumns; j++) - [self makeCellAtRow:i column:j]; - } + if (numRows && newColumns > [[cells objectAtIndex: 0] count]) + { + /* Add columns to the existing rows. Call makeCellAtRow: column: + to be consistent. */ + for (i = 0; i < numRows; i++) + { + for (j = numCols; j < newColumns; j++) + [self makeCellAtRow: i column: j]; + } + } } - } numCols = newColumns; - if (newRows > numRows) { - for (i = numRows; i < newRows; i++) { - [cells addObject:[NSMutableArray arrayWithCapacity:numCols]]; - for (j = 0; j < numCols; j++) - [self makeCellAtRow:i column:j]; + if (newRows > numRows) + { + for (i = numRows; i < newRows; i++) + { + [cells addObject: [NSMutableArray arrayWithCapacity: numCols]]; + for (j = 0; j < numCols; j++) + [self makeCellAtRow: i column: j]; + } } - } numRows = newRows; growMatrix (selectedCells, newRows, newColumns); } -- (void)setCellSize:(NSSize)size +- (void) setCellSize: (NSSize)size { cellSize = size; [self sizeToCells]; } -- (void)setIntercellSpacing:(NSSize)size +- (void) setIntercellSpacing: (NSSize)size { intercell = size; [self sizeToCells]; } -- (void)sortUsingFunction:(int (*)(id element1, id element2, +- (void) sortUsingFunction: (int (*)(id element1, id element2, void *userData))comparator - context:(void*)context + context: (void*)context { - NSMutableArray* sorted = [NSMutableArray arrayWithCapacity:numRows*numCols]; + NSMutableArray* sorted = [NSMutableArray arrayWithCapacity: numRows*numCols]; NSMutableArray* row; int i, j, index = 0; for (i = 0; i < numRows; i++) - [sorted addObjectsFromArray:[[cells objectAtIndex:i] - subarrayWithRange:NSMakeRange(0, numCols)]]; + [sorted addObjectsFromArray: [[cells objectAtIndex: i] + subarrayWithRange: NSMakeRange(0, numCols)]]; - [sorted sortUsingFunction:comparator context:context]; + [sorted sortUsingFunction: comparator context: context]; - for (i = 0; i < numRows; i++) { - row = [cells objectAtIndex:i]; - for (j = 0; j < numCols; j++) { - [row replaceObjectAtIndex:j withObject:[sorted objectAtIndex:index]]; - index++; + for (i = 0; i < numRows; i++) + { + row = [cells objectAtIndex: i]; + for (j = 0; j < numCols; j++) + { + [row replaceObjectAtIndex: j + withObject: [sorted objectAtIndex: index]]; + index++; + } } - } } -- (void)sortUsingSelector:(SEL)comparator +- (void) sortUsingSelector: (SEL)comparator { - NSMutableArray* sorted = [NSMutableArray arrayWithCapacity:numRows*numCols]; + NSMutableArray* sorted = [NSMutableArray arrayWithCapacity: numRows*numCols]; NSMutableArray* row; int i, j, index = 0; for (i = 0; i < numRows; i++) - [sorted addObjectsFromArray:[[cells objectAtIndex:i] - subarrayWithRange:NSMakeRange(0, numCols)]]; + [sorted addObjectsFromArray: [[cells objectAtIndex: i] + subarrayWithRange: NSMakeRange(0, numCols)]]; - [sorted sortUsingSelector:comparator]; + [sorted sortUsingSelector: comparator]; - for (i = 0; i < numRows; i++) { - row = [cells objectAtIndex:i]; - for (j = 0; j < numCols; j++) { - [row replaceObjectAtIndex:j withObject:[sorted objectAtIndex:index]]; - index++; + for (i = 0; i < numRows; i++) + { + row = [cells objectAtIndex: i]; + for (j = 0; j < numCols; j++) + { + [row replaceObjectAtIndex: j + withObject: [sorted objectAtIndex: index]]; + index++; + } } - } } -- (BOOL)getRow:(int*)row - column:(int*)column - forPoint:(NSPoint)aPoint +- (BOOL) getRow: (int*)row + column: (int*)column + forPoint: (NSPoint)aPoint { BOOL isBetweenCells, insideBounds; - insideBounds = [self _getRow:row column:column - forPoint:aPoint - above:NO right:NO - isBetweenCells:&isBetweenCells]; + insideBounds = [self _getRow: row column: column + forPoint: aPoint + above: NO right: NO + isBetweenCells: &isBetweenCells]; if (!insideBounds || isBetweenCells) return NO; - else return YES; + else + return YES; } -- (BOOL)getRow:(int*)row - column:(int*)column - ofCell:(NSCell*)aCell +- (BOOL) getRow: (int*)row + column: (int*)column + ofCell: (NSCell*)aCell { int i, j; - for (i = 0; i < numRows; i++) { - NSMutableArray* row = [cells objectAtIndex:i]; + for (i = 0; i < numRows; i++) + { + NSMutableArray* row = [cells objectAtIndex: i]; - for (j = 0; j < numCols; j++) - if ([row objectAtIndex:j] == aCell) - return YES; - } + for (j = 0; j < numCols; j++) + if ([row objectAtIndex: j] == aCell) + return YES; + } return NO; } -- (void)setState:(int)value - atRow:(int)row - column:(int)column +- (void) setState: (int)value + atRow: (int)row + column: (int)column { - NSCell* aCell = [self cellAtRow:row column:column]; + NSCell* aCell = [self cellAtRow: row column: column]; if (!aCell) return; - if (mode == NSRadioModeMatrix) { - if (value) { - selectedCell = aCell; // select current cell - selectedRow = row; - selectedColumn = column; - [selectedCell setState:1]; + if (mode == NSRadioModeMatrix) + { + if (value) + { + selectedCell = aCell; + selectedRow = row; + selectedColumn = column; + [selectedCell setState: 1]; + } + else if (allowsEmptySelection) + [self deselectSelectedCell]; } - else if (allowsEmptySelection) - [self deselectSelectedCell]; - } else - [aCell setState:value]; + [aCell setState: value]; - [self setNeedsDisplayInRect:[self cellFrameAtRow:row column:column]]; + [self setNeedsDisplayInRect: [self cellFrameAtRow: row column: column]]; } -- (void)deselectAllCells +- (void) deselectAllCells { - int i, j; - NSArray* row; - NSCell* aCell; + unsigned i, j; + NSArray *row; + NSCell *aCell; - for (i = 0; i < numRows; i++) { - row = [cells objectAtIndex:i]; - for (j = 0; j < numCols; j++) - if (((tMatrix)selectedCells)->matrix[i][j]) { - NSRect theFrame = [self cellFrameAtRow:i column:j]; + for (i = 0; i < numRows; i++) + { + row = [cells objectAtIndex: i]; + for (j = 0; j < numCols; j++) + if (((tMatrix)selectedCells)->matrix[i][j]) + { + NSRect theFrame = [self cellFrameAtRow: i column: j]; - aCell = [row objectAtIndex:j]; - [aCell setState:0]; - [aCell highlight:NO withFrame:theFrame inView:self]; - [self setNeedsDisplayInRect:theFrame]; - ((tMatrix)selectedCells)->matrix[i][j] = NO; - } - } + aCell = [row objectAtIndex: j]; + [aCell setState: 0]; + [aCell highlight: NO withFrame: theFrame inView: self]; + [self setNeedsDisplayInRect: theFrame]; + ((tMatrix)selectedCells)->matrix[i][j] = NO; + } + } - if (!allowsEmptySelection) // if we don't allow an - [self selectCellAtRow:0 column:0]; // empty selection + if (!allowsEmptySelection) + [self selectCellAtRow: 0 column: 0]; } -- (void)deselectSelectedCell +- (void) deselectSelectedCell { - [selectedCell setState:0]; + [selectedCell setState: 0]; selectedCell = nil; selectedRow = 0; selectedColumn = 0; } -- (void)selectAll:(id)sender +- (void) selectAll: (id)sender { - int i, j; - NSArray* row; + unsigned i, j; + NSArray *row; /* Make the selected cell the cell at (0, 0) */ - selectedCell = [self cellAtRow:0 column:0]; // select current cell + selectedCell = [self cellAtRow: 0 column: 0]; // select current cell selectedRow = 0; selectedColumn = 0; - for (i = 0; i < numRows; i++) { - row = [cells objectAtIndex:i]; + for (i = 0; i < numRows; i++) + { + row = [cells objectAtIndex: i]; - for (j = 0; j < numCols; j++) { - [[row objectAtIndex:j] setState:1]; - ((tMatrix)selectedCells)->matrix[i][j] = YES; + for (j = 0; j < numCols; j++) + { + [[row objectAtIndex: j] setState: 1]; + ((tMatrix)selectedCells)->matrix[i][j] = YES; + } } - } [self display]; } -- (void)selectCellAtRow:(int)row column:(int)column +- (void) selectCellAtRow: (int)row column: (int)column { - NSCell* aCell = [self cellAtRow:row column:column]; + NSCell* aCell = [self cellAtRow: row column: column]; - if (mode == NSRadioModeMatrix) { - /* Don't allow loss of selection if in radio mode and empty selection - is not allowed. Otherwise deselect the selected cell. */ - if (!aCell && !allowsEmptySelection) - return; - else if (selectedCell) - [selectedCell setState:0]; - } + if (mode == NSRadioModeMatrix) + { + /* Don't allow loss of selection if in radio mode and empty selection + is not allowed. Otherwise deselect the selected cell. */ + if (!aCell && !allowsEmptySelection) + return; + else if (selectedCell) + [selectedCell setState: 0]; + } else if (!aCell) return; selectedCell = aCell; // select current cell selectedRow = row; selectedColumn = column; - [selectedCell setState:1]; + [selectedCell setState: 1]; - [self setNeedsDisplayInRect:[self cellFrameAtRow:row column:column]]; + [self setNeedsDisplayInRect: [self cellFrameAtRow: row column: column]]; } -- (BOOL)selectCellWithTag:(int)anInt +- (BOOL) selectCellWithTag: (int)anInt { NSMutableArray* row; id aCell; int i, j; - for (i = numRows - 1; i >= 0; i--) { - row = [cells objectAtIndex:i]; - for (j = numCols - 1; j >= 0; j --) { - aCell = [row objectAtIndex:j]; - if ([aCell tag] == anInt) { - [self selectCellAtRow:i column:j]; - return YES; - } + for (i = numRows - 1; i >= 0; i--) + { + row = [cells objectAtIndex: i]; + for (j = numCols - 1; j >= 0; j --) + { + aCell = [row objectAtIndex: j]; + if ([aCell tag] == anInt) + { + [self selectCellAtRow: i column: j]; + return YES; + } + } } - } return NO; } -- (NSArray*)selectedCells +- (NSArray*) selectedCells { NSMutableArray* array = [NSMutableArray array]; int i, j; - for (i = 0; i < numRows; i++) { - NSArray* row = [cells objectAtIndex:i]; + for (i = 0; i < numRows; i++) + { + NSArray* row = [cells objectAtIndex: i]; - for (j = 0; j < numCols; j++) - if (((tMatrix)selectedCells)->matrix[i][j]) - [array addObject:[row objectAtIndex:j]]; - } + for (j = 0; j < numCols; j++) + if (((tMatrix)selectedCells)->matrix[i][j]) + [array addObject: [row objectAtIndex: j]]; + } return array; } -- (void)setSelectionFrom:(int)startPos - to:(int)endPos - anchor:(int)anchorPos - highlight:(BOOL)flag +- (void) setSelectionFrom: (int)startPos + to: (int)endPos + anchor: (int)anchorPos + highlight: (BOOL)flag { MPoint anchor = POINT_FROM_INDEX(anchorPos); MPoint last = POINT_FROM_INDEX(startPos); MPoint current = POINT_FROM_INDEX(endPos); if (selectionByRect) - [self _selectRectUsingAnchor:anchor last:last current:current]; + [self _selectRectUsingAnchor: anchor last: last current: current]; else - [self _selectContinuousUsingAnchor:anchor last:last current:current]; + [self _selectContinuousUsingAnchor: anchor last: last current: current]; [self display]; } -- (id)cellAtRow:(int)row - column:(int)column +- (id) cellAtRow: (int)row + column: (int)column { if (row < 0 || row >= numRows || column < 0 || column >= numCols) return nil; - return [[cells objectAtIndex:row] objectAtIndex:column]; + return [[cells objectAtIndex: row] objectAtIndex: column]; } -- (id)cellWithTag:(int)anInt +- (id) cellWithTag: (int)anInt { NSMutableArray* row; id aCell; int i, j; - for (i = numRows - 1; i >= 0; i--) { - row = [cells objectAtIndex:i]; - for (j = numCols - 1; j >= 0; j --) { - aCell = [row objectAtIndex:j]; - if ([aCell tag] == anInt) - return aCell; + for (i = numRows - 1; i >= 0; i--) + { + row = [cells objectAtIndex: i]; + for (j = numCols - 1; j >= 0; j --) + { + aCell = [row objectAtIndex: j]; + if ([aCell tag] == anInt) + return aCell; + } } - } return nil; } -- (NSArray*)cells +- (NSArray*) cells { return cells; } -- (void)selectText:(id)sender +- (void) selectText: (id)sender { fprintf(stderr, " NSMatrix: selectText --- "); // TODO } -- (id)selectTextAtRow:(int)row column:(int)column +- (id) selectTextAtRow: (int)row column: (int)column { // TODO -// NSCell* aCell = [self cellAtRow:row column:column]; +// NSCell* aCell = [self cellAtRow: row column: column]; fprintf(stderr, " NSMatrix: selectTextAtRow --- "); @@ -902,56 +939,56 @@ fprintf(stderr, " NSMatrix: selectTextAtRow --- "); return nil; } -- (id)nextText +- (id) nextText { // TODO return nil; } -- (id)previousText +- (id) previousText { // TODO return nil; } -- (void)textDidBeginEditing:(NSNotification*)notification +- (void) textDidBeginEditing: (NSNotification*)notification { } -- (void)textDidChange:(NSNotification*)notification +- (void) textDidChange: (NSNotification*)notification { } -- (void)textDidEndEditing:(NSNotification*)notification +- (void) textDidEndEditing: (NSNotification*)notification { } -- (BOOL)textShouldBeginEditing:(NSText*)textObject +- (BOOL) textShouldBeginEditing: (NSText*)textObject { return YES; } -- (BOOL)textShouldEndEditing:(NSText*)textObject +- (BOOL) textShouldEndEditing: (NSText*)textObject { return YES; } -- (void)setNextText:(id)anObject +- (void) setNextText: (id)anObject { // TODO } -- (void)setPreviousText:(id)anObject +- (void) setPreviousText: (id)anObject { // TODO } -- (void)setValidateSize:(BOOL)flag +- (void) setValidateSize: (BOOL)flag { // TODO } -- (void)sizeToCells +- (void) sizeToCells { NSSize newSize; int nc = numCols; @@ -963,31 +1000,32 @@ fprintf(stderr, " NSMatrix: selectTextAtRow --- "); nr = 1; newSize.width = nc * (cellSize.width + intercell.width) - intercell.width; newSize.height = nr * (cellSize.height + intercell.height) - intercell.height; - [self setFrameSize:newSize]; + [self setFrameSize: newSize]; } -- (void)scrollCellToVisibleAtRow:(int)row - column:(int)column +- (void) scrollCellToVisibleAtRow: (int)row + column: (int)column { - [self scrollRectToVisible:[self cellFrameAtRow:row column:column]]; + [self scrollRectToVisible: [self cellFrameAtRow: row column: column]]; } -- (void)setAutoscroll:(BOOL)flag +- (void) setAutoscroll: (BOOL)flag { autoscroll = flag; } -- (void)setScrollable:(BOOL)flag +- (void) setScrollable: (BOOL)flag { int i, j; - for (i = 0; i < numRows; i++) { - NSArray* row = [cells objectAtIndex:i]; + for (i = 0; i < numRows; i++) + { + NSArray* row = [cells objectAtIndex: i]; - for (j = 0; j < numCols; j++) - [[row objectAtIndex:j] setScrollable:flag]; - } - [cellPrototype setScrollable:flag]; + for (j = 0; j < numCols; j++) + [[row objectAtIndex: j] setScrollable: flag]; + } + [cellPrototype setScrollable: flag]; } - (void) drawRect: (NSRect)rect @@ -1057,21 +1095,22 @@ fprintf(stderr, " NSMatrix: selectTextAtRow --- "); } -- (BOOL)sendAction:(SEL)theAction - to:(id)theTarget +- (BOOL) sendAction: (SEL)theAction + to: (id)theTarget { - if (theAction) { - if (theTarget) - return [super sendAction: theAction to: theTarget]; - else - return [super sendAction: theAction to: [self target]]; - } + if (theAction) + { + if (theTarget) + return [super sendAction: theAction to: theTarget]; + else + return [super sendAction: theAction to: [self target]]; + } else return [super sendAction: [self action] to: [self target]]; } -- (BOOL)sendAction +- (BOOL) sendAction { if (![selectedCell isEnabled]) return NO; @@ -1079,43 +1118,47 @@ fprintf(stderr, " NSMatrix: selectTextAtRow --- "); return [self sendAction: [selectedCell action] to: [selectedCell target]]; } -- (void)sendAction:(SEL)aSelector - to:(id)anObject - forAllCells:(BOOL)flag +- (void) sendAction: (SEL)aSelector + to: (id)anObject + forAllCells: (BOOL)flag { int i, j; - if (flag) { - for (i = 0; i < numRows; i++) { - NSMutableArray* row = [cells objectAtIndex:i]; + if (flag) + { + for (i = 0; i < numRows; i++) + { + NSMutableArray* row = [cells objectAtIndex: i]; - for (j = 0; j < numCols; j++) - if (![anObject performSelector:aSelector - withObject:[row objectAtIndex:j]]) - return; + for (j = 0; j < numCols; j++) + if (![anObject performSelector: aSelector + withObject: [row objectAtIndex: j]]) + return; + } } - } - else { - for (i = 0; i < numRows; i++) { - BOOL* row = ((tMatrix)selectedCell)->matrix[i]; - NSMutableArray* cellRow = [cells objectAtIndex:i]; + else + { + for (i = 0; i < numRows; i++) + { + BOOL* row = ((tMatrix)selectedCell)->matrix[i]; + NSMutableArray* cellRow = [cells objectAtIndex: i]; - for (j = 0; j < numCols; j++) - if (row[i]) - if (![anObject performSelector:aSelector - withObject:[cellRow objectAtIndex:j]]) - return; + for (j = 0; j < numCols; j++) + if (row[i]) + if (![anObject performSelector: aSelector + withObject: [cellRow objectAtIndex: j]]) + return; + } } - } } -- (void)sendDoubleAction +- (void) sendDoubleAction { if (![selectedCell isEnabled]) return; if (doubleAction) - [target performSelector:doubleAction withObject:self]; + [target performSelector: doubleAction withObject: self]; else [self sendAction]; } @@ -1125,7 +1168,7 @@ fprintf(stderr, " NSMatrix: selectTextAtRow --- "); return mode == NSListModeMatrix ? NO : YES; } -- (void)_mouseDownNonListMode:(NSEvent *)theEvent +- (void) _mouseDownNonListMode: (NSEvent *)theEvent { BOOL mouseUpInCell = NO; NSCell *highlightedCell = nil; @@ -1236,7 +1279,8 @@ fprintf(stderr, " NSMatrix: selectTextAtRow --- "); { if (selectedCell) { - ((tMatrix)selectedCells)->matrix[selectedRow][selectedColumn] = NO; + ((tMatrix)selectedCells)->matrix[selectedRow][selectedColumn] + = NO; selectedCell = nil; selectedRow = selectedColumn = -1; } @@ -1256,237 +1300,263 @@ fprintf(stderr, " NSMatrix: selectTextAtRow --- "); } -- (void)mouseDown:(NSEvent*)theEvent +- (void) mouseDown: (NSEvent*)theEvent { -BOOL isBetweenCells, insideBounds; -int row, column; -unsigned eventMask = NSLeftMouseUpMask | NSLeftMouseDownMask | NSMouseMovedMask - | NSLeftMouseDraggedMask | NSPeriodicMask; -NSPoint lastLocation = [theEvent locationInWindow]; -NSEvent* lastEvent = nil; -BOOL done = NO; -NSRect rect; -id aCell, previousCell = nil, selectedCellTarget; -NSRect previousCellRect; -NSApplication *app = [NSApplication sharedApplication]; -static MPoint anchor = {0, 0}; + BOOL isBetweenCells, insideBounds; + int row, column; + unsigned eventMask = NSLeftMouseUpMask | NSLeftMouseDownMask + | NSMouseMovedMask | NSLeftMouseDraggedMask + | NSPeriodicMask; + NSPoint lastLocation = [theEvent locationInWindow]; + NSEvent* lastEvent = nil; + BOOL done = NO; + NSRect rect; + id aCell, previousCell = nil, selectedCellTarget; + NSRect previousCellRect; + NSApplication *app = [NSApplication sharedApplication]; + static MPoint anchor = {0, 0}; - mouseDownFlags = [theEvent modifierFlags]; + mouseDownFlags = [theEvent modifierFlags]; - if (mode != NSListModeMatrix) - { - [self _mouseDownNonListMode: theEvent]; - return; - } + if (mode != NSListModeMatrix) + { + [self _mouseDownNonListMode: theEvent]; + return; + } //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 // references to other modes. - lastLocation = [self convertPoint:lastLocation fromView:nil]; - if ((mode != NSTrackModeMatrix) && (mode != NSHighlightModeMatrix)) - [NSEvent startPeriodicEventsAfterDelay:0.05 withPeriod:0.05]; - ASSIGN(lastEvent, theEvent); + lastLocation = [self convertPoint: lastLocation fromView: nil]; + if ((mode != NSTrackModeMatrix) && (mode != NSHighlightModeMatrix)) + [NSEvent startPeriodicEventsAfterDelay: 0.05 withPeriod: 0.05]; + ASSIGN(lastEvent, theEvent); - [window _captureMouse: self]; // grab the mouse - [self lockFocus]; // selection involves two steps, first - // a loop that continues until the left - while (!done) // mouse goes up; then a series of - { // steps which send actions and display - BOOL shouldProceedEvent = NO; // the cell as it should appear after - // the selection process is complete - insideBounds = [self _getRow:&row - column:&column - forPoint:lastLocation - above:NO right:NO - isBetweenCells:&isBetweenCells]; - if (insideBounds && !isBetweenCells) + [window _captureMouse: self]; // grab the mouse + [self lockFocus]; + // selection involves two steps, first + // a loop that continues until the left mouse goes up; then a series of + // steps which send actions and display the cell as it should appear after + // the selection process is complete + while (!done) + { + BOOL shouldProceedEvent = NO; + + insideBounds = [self _getRow: &row + column: &column + forPoint: lastLocation + above: NO right: NO + isBetweenCells: &isBetweenCells]; + if (insideBounds && !isBetweenCells) + { + aCell = [self cellAtRow: row column: column]; + rect = [self cellFrameAtRow: row column: column]; + + switch (mode) + { + case NSTrackModeMatrix: + // in Track mode the cell should track the mouse + // until the cursor either leaves the cellframe or + // NSLeftMouseUp occurs + selectedCell = aCell; + selectedRow = row; + selectedColumn = column; + if ([aCell trackMouse: lastEvent + inRect: rect + ofView: self + untilMouseUp: YES]) + done = YES; + break; + + case NSHighlightModeMatrix: + // Highlight mode is like Track mode except that + // the cell is lit before begins tracking and + // unlit afterwards + [aCell setState: 1]; + selectedCell = aCell; + selectedRow = row; + selectedColumn = column; + [aCell highlight: YES withFrame: rect inView: self]; + [window flushWindow]; + + if ([aCell trackMouse: lastEvent + inRect: rect + ofView: self + untilMouseUp: YES]) + done = YES; + + [aCell setState: 0]; + [aCell highlight: NO withFrame: rect inView: self]; + [window flushWindow]; + break; + + case NSRadioModeMatrix: + // Radio mode allows no more than one cell to be selected + if (previousCell == aCell) + break; + + // deselect previously selected cell + if (selectedCell) + { + [selectedCell setState: 0]; + if (!previousCell) + previousCellRect = [self cellFrameAtRow: selectedRow + column: selectedColumn]; + [selectedCell highlight: NO + withFrame: previousCellRect + inView: self]; + ((tMatrix)selectedCells)->matrix[selectedRow][selectedColumn] = NO; + } + // select current cell + selectedCell = aCell; + selectedRow = row; + selectedColumn = column; + [aCell setState: 1]; + [aCell highlight: YES withFrame: rect inView: self]; + ((tMatrix)selectedCells)->matrix[row][column] = YES; + [window flushWindow]; + break; + + case NSListModeMatrix: + // List mode allows multiple cells to be selected + { + unsigned modifiers = [lastEvent modifierFlags]; + + if (previousCell == aCell) + break; + // When the user first clicks on a cell + // we clear the existing selection + // unless the Alternate or Shift keys have been pressed. + if (!previousCell) + { + if (!(modifiers & NSShiftKeyMask) && + !(modifiers & NSAlternateKeyMask)) { - aCell = [self cellAtRow:row column:column]; - rect = [self cellFrameAtRow:row column:column]; - - switch (mode) - { - case NSTrackModeMatrix: // in Track mode the cell - selectedCell = aCell; // should track the mouse - selectedRow = row; // until the cursor either - selectedColumn = column; // leaves the cellframe or - // NSLeftMouseUp occurs - if ([aCell trackMouse:lastEvent - inRect:rect - ofView:self - untilMouseUp:YES]) // YES if mouse - done = YES; // went up in cell - break; - - case NSHighlightModeMatrix: // Highlight mode is like - [aCell setState:1]; // Track mode except that - selectedCell = aCell; // the cell is lit before - selectedRow = row; // it begins tracking and - selectedColumn = column; // unlit afterwards - [aCell highlight: YES withFrame: rect inView: self]; - [window flushWindow]; - - if ([aCell trackMouse:lastEvent - inRect:rect - ofView:self - untilMouseUp:YES]) // YES if mouse - done = YES; // went up in cell - - [aCell setState:0]; - [aCell highlight: NO withFrame: rect inView: self]; - [window flushWindow]; - break; - - case NSRadioModeMatrix: // Radio mode allows no - if (previousCell == aCell) // more than one cell - break; // to be selected - - if (selectedCell) - { - [selectedCell setState:0]; // deselect previously - if (!previousCell) // selected cell - previousCellRect = [self cellFrameAtRow:selectedRow - column:selectedColumn]; - [selectedCell highlight:NO - withFrame:previousCellRect - inView:self]; - ((tMatrix)selectedCells)->matrix[selectedRow] - [selectedColumn] = NO; - } - selectedCell = aCell; // select current cell - selectedRow = row; - selectedColumn = column; - [aCell setState:1]; - [aCell highlight:YES withFrame:rect inView:self]; - ((tMatrix)selectedCells)->matrix[row][column] = YES; - [window flushWindow]; - break; - // List mode allows - case NSListModeMatrix: // multiple cells to be - { // selected - unsigned modifiers = [lastEvent modifierFlags]; - - if (previousCell == aCell) - break; // When the user first clicks on a cell - // we clear the existing selection - if (!previousCell) // unless the Alternate or Shift keys - { // have been pressed. - if (!(modifiers & NSShiftKeyMask) && - !(modifiers & NSAlternateKeyMask)) - { - [self deselectAllCells]; - anchor = MakePoint (column, row); - } // Consider the selected cell as the - // anchor from which to extend the - // selection to the current cell - if (!(modifiers & NSAlternateKeyMask)) - { - selectedCell = aCell; // select current cell - selectedRow = row; - selectedColumn = column; - - [selectedCell setState:1]; - [selectedCell highlight:YES - withFrame:rect - inView:self]; - ((tMatrix)selectedCells)->matrix[row][column] =YES; - [window flushWindow]; - break; - } - } - if (selectionByRect) - [self _selectRectUsingAnchor:anchor - last:MakePoint (selectedColumn, selectedRow) - current:MakePoint (column, row)]; - else - [self _selectContinuousUsingAnchor:anchor - last:MakePoint (selectedColumn, selectedRow) - current:MakePoint (column, row)]; - - [window flushWindow]; - selectedCell = aCell; // select current cell - selectedRow = row; - selectedColumn = column; - break; - } - } - previousCell = aCell; - previousCellRect = rect; - [self scrollRectToVisible:rect]; - } - - if (done) // if done break out of - break; // the selection loop - - while (!shouldProceedEvent) - { // Get the next event - theEvent = [app nextEventMatchingMask:eventMask - untilDate:[NSDate distantFuture] - inMode:NSEventTrackingRunLoopMode - dequeue:YES]; - switch ([theEvent type]) - { - case NSPeriodic: - NSDebugLog(@"NSMatrix: got NSPeriodic event\n"); - shouldProceedEvent = YES; // it's time to cycle - break; // thru the loop again - case NSLeftMouseUp: - done = YES; // Track and Highlight modes do not use - case NSLeftMouseDown: // periodic events so we must break out - default: // and check if the mouse is in a cell - if ((mode == NSTrackModeMatrix) || - (mode == NSHighlightModeMatrix)) - shouldProceedEvent = YES; - NSDebugLog(@"NSMatrix: got event of type: %d\n", - [theEvent type]); - ASSIGN(lastEvent, theEvent); - continue; - } - } - lastLocation = [lastEvent locationInWindow]; - lastLocation = [self convertPoint:lastLocation fromView:nil]; - } - - [window _releaseMouse: self]; // Release the mouse - - switch (mode) // Finish the selection - { // process - case NSRadioModeMatrix: - if (selectedCell) - [selectedCell highlight:NO withFrame:rect inView:self]; - case NSListModeMatrix: - [self setNeedsDisplayInRect:rect]; // not needed by XRAW - [window flushWindow]; - case NSHighlightModeMatrix: - case NSTrackModeMatrix: - break; - } - - if (selectedCell) - { // send single click action - if (!(selectedCellTarget = [selectedCell target])) - { // selected cell has no target so send single - if (target) // click action to matrix's (self's) target - [target performSelector:action withObject:self]; - } // in Track and Highlight modes the single - else // click action has already been sent by the - { // cell to it's target (if it has one) - if ((mode != NSTrackModeMatrix) && (mode != NSHighlightModeMatrix)) - [selectedCellTarget performSelector:[selectedCell action] - withObject:self]; + [self deselectAllCells]; + anchor = MakePoint (column, row); } + // Consider the selected cell as the + // anchor from which to extend the + // selection to the current cell + if (!(modifiers & NSAlternateKeyMask)) + { + selectedCell = aCell; // select current cell + selectedRow = row; + selectedColumn = column; + + [selectedCell setState: 1]; + [selectedCell highlight: YES + withFrame: rect + inView: self]; + ((tMatrix)selectedCells)->matrix[row][column] =YES; + [window flushWindow]; + break; + } + } + if (selectionByRect) + [self _selectRectUsingAnchor: anchor + last: MakePoint (selectedColumn, selectedRow) + current: MakePoint (column, row)]; + else + [self _selectContinuousUsingAnchor: anchor + last: MakePoint (selectedColumn, selectedRow) + current: MakePoint (column, row)]; + + [window flushWindow]; + selectedCell = aCell; + selectedRow = row; + selectedColumn = column; + break; } - // click count > 1 indicates a double click - if (target && doubleAction && ([lastEvent clickCount] > 1)) - [target performSelector:doubleAction withObject:self]; + } + previousCell = aCell; + previousCellRect = rect; + [self scrollRectToVisible: rect]; + } - [self unlockFocus]; + // if done break out of selection loop + if (done) + break; - if ((mode != NSTrackModeMatrix) && (mode != NSHighlightModeMatrix)) - [NSEvent stopPeriodicEvents]; + while (!shouldProceedEvent) + { + theEvent = [app nextEventMatchingMask: eventMask + untilDate: [NSDate distantFuture] + inMode: NSEventTrackingRunLoopMode + dequeue: YES]; + switch ([theEvent type]) + { + case NSPeriodic: + NSDebugLog(@"NSMatrix: got NSPeriodic event\n"); + shouldProceedEvent = YES; + break; - [lastEvent release]; + // Track and Highlight modes do not use + // periodic events so we must break out + // and check if the mouse is in a cell + case NSLeftMouseUp: + done = YES; + case NSLeftMouseDown: + default: + if ((mode == NSTrackModeMatrix) || + (mode == NSHighlightModeMatrix)) + shouldProceedEvent = YES; + NSDebugLog(@"NSMatrix: got event of type: %d\n", + [theEvent type]); + ASSIGN(lastEvent, theEvent); + continue; + } + } + lastLocation = [lastEvent locationInWindow]; + lastLocation = [self convertPoint: lastLocation fromView: nil]; + } + + [window _releaseMouse: self]; + + switch (mode) + { + case NSRadioModeMatrix: + if (selectedCell) + [selectedCell highlight: NO withFrame: rect inView: self]; + case NSListModeMatrix: + [self setNeedsDisplayInRect: rect]; + [window flushWindow]; + case NSHighlightModeMatrix: + case NSTrackModeMatrix: + break; + } + + if (selectedCell) + { + // send single click action + if (!(selectedCellTarget = [selectedCell target])) + { + // selected cell has no target so send single + // click action to matrix's (self's) target + if (target) + [target performSelector: action withObject: self]; + } + else + { + // in Track and Highlight modes the single + // click action has already been sent by the + // cell to it's target (if it has one) + if ((mode != NSTrackModeMatrix) && (mode != NSHighlightModeMatrix)) + [selectedCellTarget performSelector: [selectedCell action] + withObject: self]; + } + } + // click count > 1 indicates a double click + if (target && doubleAction && ([lastEvent clickCount] > 1)) + [target performSelector: doubleAction withObject: self]; + + [self unlockFocus]; + + if ((mode != NSTrackModeMatrix) && (mode != NSHighlightModeMatrix)) + [NSEvent stopPeriodicEvents]; + + [lastEvent release]; } - (void) updateCell: (NSCell*)aCell @@ -1501,47 +1571,54 @@ static MPoint anchor = {0, 0}; [self setNeedsDisplayInRect: rect]; } -- (BOOL)performKeyEquivalent:(NSEvent*)theEvent +- (BOOL) performKeyEquivalent: (NSEvent*)theEvent { int i, j; NSMutableArray* row; NSString* key = [theEvent charactersIgnoringModifiers]; - for (i = 0; i < numRows; i++) { - row = [cells objectAtIndex:i]; - for (j = 0; j < numCols; j++) { - NSCell* aCell = [row objectAtIndex:j]; + for (i = 0; i < numRows; i++) + { + row = [cells objectAtIndex: i]; + for (j = 0; j < numCols; j++) + { + NSCell* aCell = [row objectAtIndex: j]; - if ([aCell isEnabled] && [[aCell keyEquivalent] isEqualToString:key]) { - NSCell* oldSelectedCell = selectedCell; + if ([aCell isEnabled] + && [[aCell keyEquivalent] isEqualToString: key]) + { + NSCell* oldSelectedCell = selectedCell; - selectedCell = aCell; - [self highlightCell:YES atRow:i column:j]; - [aCell setState:![aCell state]]; - [self sendAction]; - [self highlightCell:NO atRow:i column:j]; - selectedCell = oldSelectedCell; + selectedCell = aCell; + [self highlightCell: YES atRow: i column: j]; + [aCell setState: ![aCell state]]; + [self sendAction]; + [self highlightCell: NO atRow: i column: j]; + selectedCell = oldSelectedCell; - return YES; - } + return YES; + } + } } - } return NO; } -- (void)resetCursorRects +- (void) resetCursorRects { int i, j; - for (i = 0; i < numRows; i++) { - NSArray* row = [cells objectAtIndex:i]; + for (i = 0; i < numRows; i++) + { + NSArray* row = [cells objectAtIndex: i]; - for (j = 0; j < numCols; j++) { - NSCell* aCell = [row objectAtIndex:j]; - [aCell resetCursorRect:[self cellFrameAtRow:i column:j] inView:self]; + for (j = 0; j < numCols; j++) + { + NSCell* aCell = [row objectAtIndex: j]; + [aCell resetCursorRect: [self cellFrameAtRow: i column: j] + inView: self]; + } } - } } - (void) encodeWithCoder: (NSCoder*)aCoder @@ -1556,48 +1633,168 @@ static MPoint anchor = {0, 0}; return self; } -- (void)setMode:(NSMatrixMode)aMode { mode = aMode; } -- (NSMatrixMode)mode { return mode; } -- (void)setCellClass:(Class)class { cellClass = class; } -- (Class)cellClass { return cellClass; } -- (void)setPrototype:(NSCell*)aCell { ASSIGN(cellPrototype, aCell); } -- (id)prototype { return cellPrototype; } -- (NSSize)cellSize { return cellSize; } -- (NSSize)intercellSpacing { return intercell; } -- (void)setBackgroundColor:(NSColor*)c { ASSIGN(backgroundColor, c); } -- (NSColor*)backgroundColor { return backgroundColor; } -- (void)setCellBackgroundColor:(NSColor*)c { ASSIGN(cellBackgroundColor, c); } -- (NSColor*)cellBackgroundColor { return cellBackgroundColor; } -- (void)setDelegate:(id)object { ASSIGN(delegate, object); } -- (id)delegate { return delegate; } -- (void)setTarget:anObject { ASSIGN(target, anObject); } -- (id)target { return target; } -- (void)setAction:(SEL)sel { action = sel; } -- (SEL)action { return action; } -- (void)setDoubleAction:(SEL)sel { doubleAction = sel; } -- (SEL)doubleAction { return doubleAction; } -- (void)setErrorAction:(SEL)sel { errorAction = sel; } -- (SEL)errorAction { return errorAction; } -- (void)setAllowsEmptySelection:(BOOL)f { allowsEmptySelection = f; } -- (BOOL)allowsEmptySelection { return allowsEmptySelection; } -- (void)setSelectionByRect:(BOOL)flag { selectionByRect = flag; } -- (BOOL)isSelectionByRect { return selectionByRect; } -- (void)setDrawsBackground:(BOOL)flag { drawsBackground = flag; } -- (BOOL)drawsBackground { return drawsBackground; } -- (void)setDrawsCellBackground:(BOOL)f { drawsCellBackground = f; } -- (BOOL)drawsCellBackground { return drawsCellBackground; } -- (void)setAutosizesCells:(BOOL)flag { autosizesCells = flag; } -- (BOOL)autosizesCells { return autosizesCells; } -- (BOOL)isAutoscroll { return autoscroll; } -- (int)numberOfRows { return numRows; } -- (int)numberOfColumns { return numCols; } -- (id)selectedCell { return selectedCell; } -- (int)selectedColumn { return selectedColumn; } -- (int)selectedRow { return selectedRow; } -- (int)mouseDownFlags { return mouseDownFlags; } +- (void) setMode: (NSMatrixMode)aMode +{ + mode = aMode; +} +- (NSMatrixMode) mode +{ + return mode; +} +- (void) setCellClass: (Class)class +{ + cellClass = class; +} +- (Class) cellClass +{ + return cellClass; +} +- (void) setPrototype: (NSCell*)aCell +{ + ASSIGN(cellPrototype, aCell); +} +- (id) prototype +{ + return cellPrototype; +} +- (NSSize) cellSize +{ + return cellSize; +} +- (NSSize) intercellSpacing +{ + return intercell; +} +- (void) setBackgroundColor: (NSColor*)c +{ + ASSIGN(backgroundColor, c); +} +- (NSColor*) backgroundColor +{ + return backgroundColor; +} +- (void) setCellBackgroundColor: (NSColor*)c +{ + ASSIGN(cellBackgroundColor, c); +} +- (NSColor*) cellBackgroundColor +{ + return cellBackgroundColor; +} +- (void) setDelegate: (id)object +{ + ASSIGN(delegate, object); +} +- (id) delegate +{ + return delegate; +} +- (void) setTarget: anObject +{ + ASSIGN(target, anObject); +} +- (id) target +{ + return target; +} +- (void) setAction: (SEL)sel +{ + action = sel; +} +- (SEL) action +{ + return action; +} +- (void) setDoubleAction: (SEL)sel +{ + doubleAction = sel; +} +- (SEL) doubleAction +{ + return doubleAction; +} +- (void) setErrorAction: (SEL)sel +{ + errorAction = sel; +} +- (SEL) errorAction +{ + return errorAction; +} +- (void) setAllowsEmptySelection: (BOOL)f +{ + allowsEmptySelection = f; +} +- (BOOL) allowsEmptySelection +{ + return allowsEmptySelection; +} +- (void) setSelectionByRect: (BOOL)flag +{ + selectionByRect = flag; +} +- (BOOL) isSelectionByRect +{ + return selectionByRect; +} +- (void) setDrawsBackground: (BOOL)flag +{ + drawsBackground = flag; +} +- (BOOL) drawsBackground +{ + return drawsBackground; +} +- (void) setDrawsCellBackground: (BOOL)f +{ + drawsCellBackground = f; +} +- (BOOL) drawsCellBackground +{ + return drawsCellBackground; +} +- (void) setAutosizesCells: (BOOL)flag +{ + autosizesCells = flag; +} +- (BOOL) autosizesCells +{ + return autosizesCells; +} +- (BOOL) isAutoscroll +{ + return autoscroll; +} +- (int) numberOfRows +{ + return numRows; +} +- (int) numberOfColumns +{ + return numCols; +} +- (id) selectedCell +{ + return selectedCell; +} +- (int) selectedColumn +{ + return selectedColumn; +} +- (int) selectedRow +{ + return selectedRow; +} +- (int) mouseDownFlags +{ + return mouseDownFlags; +} #if HAS_FLIPPED_VIEWS -- (BOOL)isFlipped { return YES; } +- (BOOL) isFlipped +{ + return YES; +} #endif @@ -1614,13 +1811,13 @@ static MPoint anchor = {0, 0}; * Deal with keyboard remapping. */ -- (void)keyDown:(NSEvent *)theEvent; +- (void) keyDown: (NSEvent *)theEvent; { -unsigned int flags = [theEvent modifierFlags]; -unsigned int key_code = [theEvent keyCode]; -NSRect rect = [self cellFrameAtRow:selectedRow column:selectedColumn]; + unsigned int flags = [theEvent modifierFlags]; + unsigned int key_code = [theEvent keyCode]; + NSRect rect = [self cellFrameAtRow: selectedRow column: selectedColumn]; -fprintf(stderr, " NSMatrix: keyDown --- "); + fprintf(stderr, " NSMatrix: keyDown --- "); // If not editable then don't recognize the key down if (![selectedCell isEditable]) return; @@ -1630,20 +1827,21 @@ fprintf(stderr, " NSMatrix: keyDown --- "); // If RETURN key then make the next text the first responder if (key_code == 0x0d) { - [selectedCell endEditing:nil]; - [selectedCell drawInteriorWithFrame: rect inView: self]; - return; + [selectedCell endEditing: nil]; + [selectedCell drawInteriorWithFrame: rect inView: self]; + [self unlockFocus]; + return; } // Hide the cursor during typing [NSCursor hide]; - [selectedCell _handleKeyEvent:theEvent]; + [selectedCell _handleKeyEvent: theEvent]; [selectedCell drawInteriorWithFrame: rect inView: self]; [self unlockFocus]; } -- (BOOL)acceptsFirstResponder +- (BOOL) acceptsFirstResponder { if ([selectedCell isSelectable]) return YES; @@ -1651,11 +1849,11 @@ fprintf(stderr, " NSMatrix: keyDown --- "); return NO; } -- (BOOL)becomeFirstResponder +- (BOOL) becomeFirstResponder { if ([selectedCell isSelectable]) { - // [selectedCell selectText:self]; + // [selectedCell selectText: self]; return YES; } else @@ -1789,9 +1987,9 @@ fprintf(stderr, " NSMatrix: keyDown --- "); selection has been made. `current' is the point to which we must extend the selection. */ -- (void)_selectRectUsingAnchor:(MPoint)anchor - last:(MPoint)last - current:(MPoint)current +- (void) _selectRectUsingAnchor: (MPoint)anchor + last: (MPoint)last + current: (MPoint)current { /* We use an imaginar coordinate system whose center is the `anchor' point. We should determine in which quadrants are located the `last' and the @@ -2072,12 +2270,12 @@ fprintf(stderr, " NSMatrix: keyDown --- "); those that must be selected. Iterate on them and do the work. First unselect and only then do the cells selection. */ for (i = 0; i < unselectRectsNo; i++) - [self _setState:0 inRect:unselectRect[i]]; + [self _setState: 0 inRect: unselectRect[i]]; for (i = 0; i < selectRectsNo; i++) - [self _setState:1 inRect:selectRect[i]]; + [self _setState: 1 inRect: selectRect[i]]; } -- (void)_setState:(int)state inRect:(MRect)matrixRect +- (void) _setState: (int)state inRect: (MRect)matrixRect { int i, j, rowNo, colNo; NSArray* row; @@ -2087,22 +2285,22 @@ fprintf(stderr, " NSMatrix: keyDown --- "); int cellsCount = [cells count]; int rowCount; - rect = upperLeftRect = [self cellFrameAtRow:matrixRect.y column:matrixRect.x]; + rect = upperLeftRect = [self cellFrameAtRow: matrixRect.y column: matrixRect.x]; for (i = 0, rowNo = matrixRect.y; i <= matrixRect.height && rowNo < cellsCount; i++, rowNo++) { - row = [cells objectAtIndex:rowNo]; + row = [cells objectAtIndex: rowNo]; rowCount = [row count]; rect.origin.x = upperLeftRect.origin.x; for (j = 0, colNo = matrixRect.x; j <= matrixRect.width && colNo < rowCount; j++, colNo++) { - aCell = [row objectAtIndex:colNo]; - [aCell setState:state]; - [aCell highlight:highlight withFrame:rect inView:self]; - [self setNeedsDisplayInRect:rect]; + aCell = [row objectAtIndex: colNo]; + [aCell setState: state]; + [aCell highlight: highlight withFrame: rect inView: self]; + [self setNeedsDisplayInRect: rect]; ((tMatrix)selectedCells)->matrix[rowNo][colNo] = YES; rect.origin.x += cellSize.width + intercell.width; } @@ -2114,9 +2312,9 @@ fprintf(stderr, " NSMatrix: keyDown --- "); /* This method is used to select and unselect the cells in the list mode with selection by rect option disabled. This method has a far lower complexity than the similar method used by list mode with selection by rect option. */ -- (void)_selectContinuousUsingAnchor:(MPoint)anchor - last:(MPoint)last - current:(MPoint)current +- (void) _selectContinuousUsingAnchor: (MPoint)anchor + last: (MPoint)last + current: (MPoint)current { /* The idea is to compare the points based on their linear index in matrix and do the appropriate action. */ @@ -2180,12 +2378,12 @@ fprintf(stderr, " NSMatrix: keyDown --- "); } if (doUnselect) - [self _setState:0 startIndex:unselectPoint.x endIndex:unselectPoint.y]; + [self _setState: 0 startIndex: unselectPoint.x endIndex: unselectPoint.y]; if (doSelect) - [self _setState:1 startIndex:selectPoint.x endIndex:selectPoint.y]; + [self _setState: 1 startIndex: selectPoint.x endIndex: selectPoint.y]; } -- (void)_setState:(int)state startIndex:(int)start endIndex:(int)end +- (void) _setState: (int)state startIndex: (int)start endIndex: (int)end { int i, j, colLimit; NSArray* row; @@ -2195,10 +2393,10 @@ fprintf(stderr, " NSMatrix: keyDown --- "); MPoint startPoint = POINT_FROM_INDEX(start); MPoint endPoint = POINT_FROM_INDEX(end); - rect = upperLeftRect = [self cellFrameAtRow:startPoint.y column:0]; + rect = upperLeftRect = [self cellFrameAtRow: startPoint.y column: 0]; for (i = startPoint.y; i <= endPoint.y; i++) { - row = [cells objectAtIndex:i]; + row = [cells objectAtIndex: i]; if (i == startPoint.y) { j = startPoint.x; @@ -2216,10 +2414,10 @@ fprintf(stderr, " NSMatrix: keyDown --- "); colLimit = numCols - 1; for (; j <= colLimit; j++) { - aCell = [row objectAtIndex:j]; - [aCell setState:state]; - [aCell highlight:highlight withFrame:rect inView:self]; - [self setNeedsDisplayInRect:rect]; + aCell = [row objectAtIndex: j]; + [aCell setState: state]; + [aCell highlight: highlight withFrame: rect inView: self]; + [self setNeedsDisplayInRect: rect]; ((tMatrix)selectedCells)->matrix[i][j] = YES; rect.origin.x += cellSize.width + intercell.width; } @@ -2231,9 +2429,9 @@ fprintf(stderr, " NSMatrix: keyDown --- "); #include /* A test to exhaustively check if the list selection mode works correctly. */ -- (void)_selectRect2UsingAnchor:(MPoint)anchor - last:(MPoint)last - current:(MPoint)current +- (void) _selectRect2UsingAnchor: (MPoint)anchor + last: (MPoint)last + current: (MPoint)current { MRect selectRect; MRect unselectRect; @@ -2248,13 +2446,13 @@ fprintf(stderr, " NSMatrix: keyDown --- "); unselectRect.width = ABS(current.x - last.x); unselectRect.height = ABS(current.y - last.y); - [self _setState:0 inRect:unselectRect]; - [self _setState:1 inRect:selectRect]; + [self _setState: 0 inRect: unselectRect]; + [self _setState: 1 inRect: selectRect]; } /* This method assumes the receiver matrix has at least 5 rows and 5 columns. */ -- (void)_test +- (void) _test { NSArray* selectedCellsByMethod1; NSArray* selectedCellsByMethod2; @@ -2280,16 +2478,16 @@ fprintf(stderr, " NSMatrix: keyDown --- "); fflush (stdout); /* First determine the selected cells using the sure method */ - [self _selectRect2UsingAnchor:anchor last:last current:current]; + [self _selectRect2UsingAnchor: anchor last: last current: current]; selectedCellsByMethod2 = [self selectedCells]; /* Then determine the same using the optimized method */ - [self _selectRectUsingAnchor:anchor last:last current:current]; + [self _selectRectUsingAnchor: anchor last: last current: current]; selectedCellsByMethod1 = [self selectedCells]; /* Compare the selected cells determined by the two methods */ - if (![selectedCellsByMethod1 isEqual:selectedCellsByMethod2]) { - NSLog (@"\nSelected cells are different for:\n" + if (![selectedCellsByMethod1 isEqual: selectedCellsByMethod2]) { + NSLog (@"\nSelected cells are different for: \n" @"anchor = (%d, %d)\nlast = (%d, %d)\ncurrent = (%d, %d)", anchor.x, anchor.y, last.x, last.y, current.x, current.y); noOfErrors++;