Tiny format tidyups

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@11265 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2001-10-28 10:18:50 +00:00
parent dab1ab0c88
commit 90a732eb5a
2 changed files with 103 additions and 86 deletions

View file

@ -36,23 +36,24 @@
/* Class variables */ /* Class variables */
static Class defaultCellClass = nil; static Class defaultCellClass = nil;
+ (void)initialize + (void) initialize
{ {
if (self == [NSForm class]) { if (self == [NSForm class])
/* Set the initial version */ {
[self setVersion: 1]; /* Set the initial version */
[self setVersion: 1];
/* Set the default cell class */ /* Set the default cell class */
defaultCellClass = [NSFormCell class]; defaultCellClass = [NSFormCell class];
} }
} }
+ (Class)cellClass + (Class) cellClass
{ {
return defaultCellClass; return defaultCellClass;
} }
+ (void)setCellClass:(Class)classId + (void) setCellClass: (Class)classId
{ {
defaultCellClass = classId; defaultCellClass = classId;
} }
@ -69,9 +70,10 @@ static Class defaultCellClass = nil;
numberOfRows: (int)rowsHigh numberOfRows: (int)rowsHigh
numberOfColumns: (int)colsWide]; numberOfColumns: (int)colsWide];
[self setIntercellSpacing:NSMakeSize (0, 4)]; [self setIntercellSpacing: NSMakeSize (0, 4)];
return self; return self;
} }
- (id) initWithFrame: (NSRect)frameRect - (id) initWithFrame: (NSRect)frameRect
mode: (int)aMode mode: (int)aMode
prototype: (NSCell*)prototype prototype: (NSCell*)prototype
@ -79,40 +81,40 @@ static Class defaultCellClass = nil;
numberOfColumns: (int)colsWide numberOfColumns: (int)colsWide
{ {
self = [super initWithFrame: (NSRect)frameRect self = [super initWithFrame: (NSRect)frameRect
mode: (int)aMode mode: (int)aMode
prototype: (NSCell*)prototype prototype: (NSCell*)prototype
numberOfRows: (int)rowsHigh numberOfRows: (int)rowsHigh
numberOfColumns: (int)colsWide]; numberOfColumns: (int)colsWide];
[self setIntercellSpacing:NSMakeSize (0, 4)]; [self setIntercellSpacing: NSMakeSize (0, 4)];
return self; return self;
} }
- (NSFormCell*)addEntry:(NSString*)title - (NSFormCell*) addEntry: (NSString*)title
{ {
return [self insertEntry:title atIndex:[self numberOfRows]]; return [self insertEntry: title atIndex: [self numberOfRows]];
} }
- (NSFormCell*)insertEntry:(NSString*)title - (NSFormCell*) insertEntry: (NSString*)title
atIndex:(int)index atIndex: (int)index
{ {
NSFormCell *new_cell = [[[isa cellClass] alloc] initTextCell:title]; NSFormCell *new_cell = [[[isa cellClass] alloc] initTextCell: title];
[self insertRow:index]; [self insertRow: index];
[self putCell:new_cell atRow:index column:0]; [self putCell: new_cell atRow: index column: 0];
RELEASE (new_cell); RELEASE (new_cell);
return new_cell; return new_cell;
} }
- (void)removeEntryAtIndex:(int)index - (void) removeEntryAtIndex: (int)index
{ {
[[NSNotificationCenter defaultCenter] [[NSNotificationCenter defaultCenter]
removeObserver: self removeObserver: self
name: _NSFormCellDidChangeTitleWidthNotification name: _NSFormCellDidChangeTitleWidthNotification
object: [self cellAtRow:index column:0]]; object: [self cellAtRow: index column: 0]];
[self removeRow:index]; [self removeRow: index];
} }
/* Overriding this method allows decoding stuff to be inherited /* Overriding this method allows decoding stuff to be inherited
@ -130,12 +132,12 @@ static Class defaultCellClass = nil;
[[NSNotificationCenter defaultCenter] [[NSNotificationCenter defaultCenter]
addObserver: self addObserver: self
selector: @selector(_setTitleWidthNeedsUpdate:) selector: @selector(_setTitleWidthNeedsUpdate: )
name: _NSFormCellDidChangeTitleWidthNotification name: _NSFormCellDidChangeTitleWidthNotification
object: newCell]; object: newCell];
} }
- (void)dealloc - (void) dealloc
{ {
[[NSNotificationCenter defaultCenter] [[NSNotificationCenter defaultCenter]
removeObserver: self removeObserver: self
@ -145,106 +147,106 @@ static Class defaultCellClass = nil;
[super dealloc]; [super dealloc];
} }
- (void)setBezeled:(BOOL)flag - (void) setBezeled: (BOOL)flag
{ {
int i, count = [self numberOfRows]; int i, count = [self numberOfRows];
/* Set the bezeled attribute to the cell prototype */ /* Set the bezeled attribute to the cell prototype */
[[self prototype] setBezeled:flag]; [[self prototype] setBezeled: flag];
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
[[self cellAtRow:i column:0] setBezeled:flag]; [[self cellAtRow: i column: 0] setBezeled: flag];
} }
- (void)setBordered:(BOOL)flag - (void) setBordered: (BOOL)flag
{ {
int i, count = [self numberOfRows]; int i, count = [self numberOfRows];
/* Set the bordered attribute to the cell prototype */ /* Set the bordered attribute to the cell prototype */
[[self prototype] setBordered:flag]; [[self prototype] setBordered: flag];
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
[[self cellAtRow:i column:0] setBordered:flag]; [[self cellAtRow: i column: 0] setBordered: flag];
} }
- (void)setEntryWidth:(float)width - (void) setEntryWidth: (float)width
{ {
NSSize size = [self cellSize]; NSSize size = [self cellSize];
size.width = width; size.width = width;
[self setCellSize:size]; [self setCellSize: size];
} }
- (void)setInterlineSpacing:(float)spacing - (void) setInterlineSpacing: (float)spacing
{ {
[self setIntercellSpacing:NSMakeSize(0, spacing)]; [self setIntercellSpacing: NSMakeSize(0, spacing)];
} }
/* For the title attributes we use the corresponding attributes from the cell. /* For the title attributes we use the corresponding attributes from the cell.
For the text attributes we use instead the attributes inherited from the For the text attributes we use instead the attributes inherited from the
NSCell class. */ NSCell class. */
- (void)setTitleAlignment:(NSTextAlignment)aMode - (void) setTitleAlignment: (NSTextAlignment)aMode
{ {
int i, count = [self numberOfRows]; int i, count = [self numberOfRows];
/* Set the title alignment attribute to the cell prototype */ /* Set the title alignment attribute to the cell prototype */
[[self prototype] setTitleAlignment:aMode]; [[self prototype] setTitleAlignment: aMode];
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
[[self cellAtRow:i column:0] setTitleAlignment:aMode]; [[self cellAtRow: i column: 0] setTitleAlignment: aMode];
} }
- (void)setTextAlignment:(int)aMode - (void) setTextAlignment: (int)aMode
{ {
int i, count = [self numberOfRows]; int i, count = [self numberOfRows];
/* Set the text alignment attribute to the cell prototype */ /* Set the text alignment attribute to the cell prototype */
[[self prototype] setAlignment:aMode]; [[self prototype] setAlignment: aMode];
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
[[self cellAtRow:i column:0] setAlignment:aMode]; [[self cellAtRow: i column: 0] setAlignment: aMode];
} }
- (void)setTitleFont:(NSFont*)fontObject - (void) setTitleFont: (NSFont*)fontObject
{ {
int i, count = [self numberOfRows]; int i, count = [self numberOfRows];
/* Set the title font attribute to the cell prototype */ /* Set the title font attribute to the cell prototype */
[[self prototype] setTitleFont:fontObject]; [[self prototype] setTitleFont: fontObject];
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
[[self cellAtRow:i column:0] setTitleFont:fontObject]; [[self cellAtRow: i column: 0] setTitleFont: fontObject];
} }
- (void)setTextFont:(NSFont*)fontObject - (void) setTextFont: (NSFont*)fontObject
{ {
int i, count = [self numberOfRows]; int i, count = [self numberOfRows];
/* Set the text font attribute to the cell prototype */ /* Set the text font attribute to the cell prototype */
[[self prototype] setFont:fontObject]; [[self prototype] setFont: fontObject];
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
[[self cellAtRow:i column:0] setFont:fontObject]; [[self cellAtRow: i column: 0] setFont: fontObject];
} }
- (int)indexOfCellWithTag:(int)aTag - (int) indexOfCellWithTag: (int)aTag
{ {
int i, count = [self numberOfRows]; int i, count = [self numberOfRows];
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
if ([[self cellAtRow:i column:0] tag] == aTag) if ([[self cellAtRow: i column: 0] tag] == aTag)
return i; return i;
return -1; return -1;
} }
- (int)indexOfSelectedItem - (int) indexOfSelectedItem
{ {
return [self selectedRow]; return [self selectedRow];
} }
- (id)cellAtIndex:(int)index - (id) cellAtIndex: (int)index
{ {
return [self cellAtRow:index column:0]; return [self cellAtRow: index column: 0];
} }
-(void) _setTitleWidthNeedsUpdate: (NSNotification*)notification -(void) _setTitleWidthNeedsUpdate: (NSNotification*)notification
@ -292,22 +294,22 @@ static Class defaultCellClass = nil;
[super drawRect: rect]; [super drawRect: rect];
} }
- (void)drawCellAtIndex:(int)index - (void) drawCellAtIndex: (int)index
{ {
id theCell = [self cellAtIndex:index]; id theCell = [self cellAtIndex: index];
[theCell drawWithFrame:[self cellFrameAtRow:index column:0] [theCell drawWithFrame: [self cellFrameAtRow: index column: 0]
inView:self]; inView: self];
} }
- (void)drawCellAtRow:(int)row column:(int)column - (void) drawCellAtRow: (int)row column: (int)column
{ {
[self drawCellAtIndex:row]; [self drawCellAtIndex: row];
} }
- (void)selectTextAtIndex:(int)index - (void) selectTextAtIndex: (int)index
{ {
[self selectTextAtRow:index column:0]; [self selectTextAtRow: index column: 0];
} }
- (void) encodeWithCoder: (NSCoder*)aCoder - (void) encodeWithCoder: (NSCoder*)aCoder

View file

@ -117,10 +117,10 @@ static inline MPoint MakePoint (int x, int y)
highlight: (BOOL)highlight highlight: (BOOL)highlight
startIndex: (int)start startIndex: (int)start
endIndex: (int)end; endIndex: (int)end;
-(BOOL) _selectNextSelectableCellAfterRow: (int)row - (BOOL) _selectNextSelectableCellAfterRow: (int)row
column: (int)column; column: (int)column;
-(BOOL) _selectPreviousSelectableCellBeforeRow: (int)row - (BOOL) _selectPreviousSelectableCellBeforeRow: (int)row
column: (int)column; column: (int)column;
@end @end
enum { enum {
@ -359,8 +359,10 @@ static SEL getSel;
_cells[i][column] = old; _cells[i][column] = old;
_selectedCells[i][column] = NO; _selectedCells[i][column] = NO;
} }
if (_selectedCell && (_selectedColumn >= column)) if (_selectedCell && (_selectedColumn >= column))
_selectedColumn++; {
_selectedColumn++;
}
} }
/* /*
@ -376,7 +378,8 @@ static SEL getSel;
} }
} }
if (_mode == NSRadioModeMatrix && !_allowsEmptySelection && _selectedCell == nil) if (_mode == NSRadioModeMatrix && _allowsEmptySelection == NO
&& _selectedCell == nil)
[self selectCellAtRow: 0 column: 0]; [self selectCellAtRow: 0 column: 0];
} }
@ -459,8 +462,10 @@ static SEL getSel;
} }
if (_mode == NSRadioModeMatrix && !_allowsEmptySelection if (_mode == NSRadioModeMatrix && !_allowsEmptySelection
&& _selectedCell == nil) && _selectedCell == nil)
[self selectCellAtRow: 0 column: 0]; {
[self selectCellAtRow: 0 column: 0];
}
} }
- (NSCell*) makeCellAtRow: (int)row - (NSCell*) makeCellAtRow: (int)row
@ -497,9 +502,14 @@ static SEL getSel;
rect.origin.x = column * (_cellSize.width + _intercell.width); rect.origin.x = column * (_cellSize.width + _intercell.width);
if (_rFlags.flipped_view) if (_rFlags.flipped_view)
rect.origin.y = row * (_cellSize.height + _intercell.height); {
rect.origin.y = row * (_cellSize.height + _intercell.height);
}
else else
rect.origin.y = (_numRows - row - 1) * (_cellSize.height + _intercell.height); {
rect.origin.y = (_numRows - row - 1)
* (_cellSize.height + _intercell.height);
}
rect.size = _cellSize; rect.size = _cellSize;
return rect; return rect;
} }
@ -522,8 +532,10 @@ static SEL getSel;
} }
if ((row == _selectedRow) && (column == _selectedColumn) if ((row == _selectedRow) && (column == _selectedColumn)
&& (_selectedCell != nil)) && (_selectedCell != nil))
_selectedCell = newCell; {
_selectedCell = newCell;
}
ASSIGN(_cells[row][column], newCell); ASSIGN(_cells[row][column], newCell);
@ -893,7 +905,8 @@ static SEL getSel;
{ {
int i,j; int i,j;
if (!_selectedCell || (!_allowsEmptySelection && (_mode == NSRadioModeMatrix))) if (!_selectedCell
|| (!_allowsEmptySelection && (_mode == NSRadioModeMatrix)))
return; return;
/* /*
@ -929,7 +942,7 @@ static SEL getSel;
for (j = 0; j < _numCols; j++) for (j = 0; j < _numCols; j++)
{ {
if ([_cells[i][j] isEnabled] == YES if ([_cells[i][j] isEnabled] == YES
&& [_cells[i][j] isEditable] == NO) && [_cells[i][j] isEditable] == NO)
{ {
_selectedCell = _cells[i][j]; _selectedCell = _cells[i][j];
[_selectedCell setState: NSOnState]; [_selectedCell setState: NSOnState];
@ -956,7 +969,7 @@ static SEL getSel;
* is the same. (in NSRadioModeMatrix) * is the same. (in NSRadioModeMatrix)
*/ */
if (_mode == NSRadioModeMatrix && _selectedCell && aCell if (_mode == NSRadioModeMatrix && _selectedCell && aCell
&& _selectedCell != aCell) && _selectedCell != aCell)
{ {
_selectedCells[_selectedRow][_selectedColumn] = NO; _selectedCells[_selectedRow][_selectedColumn] = NO;
[_selectedCell setState: NSOffState]; [_selectedCell setState: NSOffState];
@ -993,9 +1006,11 @@ static SEL getSel;
_dottedColumn = column; _dottedColumn = column;
if (lastRow != -1 && lastColumn != -1 if (lastRow != -1 && lastColumn != -1
&& (lastRow != row || lastColumn != column) && (lastRow != row || lastColumn != column)
&& [self window] != nil) && [self window] != nil)
[self drawCellAtRow: lastRow column: lastColumn]; {
[self drawCellAtRow: lastRow column: lastColumn];
}
} }
[_selectedCell setState: NSOnState]; [_selectedCell setState: NSOnState];
@ -1265,7 +1280,7 @@ static SEL getSel;
if ([_selectedCell isSelectable]) if ([_selectedCell isSelectable])
{ {
[self selectTextAtRow: _selectedRow [self selectTextAtRow: _selectedRow
column: _selectedColumn]; column: _selectedColumn];
} }
else else
{ {
@ -3531,6 +3546,7 @@ static SEL getSel;
column: (int)column column: (int)column
{ {
int i,j; int i,j;
if (row > -1) if (row > -1)
{ {
// First look for cells in the same row // First look for cells in the same row
@ -3568,6 +3584,7 @@ static SEL getSel;
column: (int)column column: (int)column
{ {
int i,j; int i,j;
if (row < _numRows) if (row < _numRows)
{ {
// First look for cells in the same row // First look for cells in the same row
@ -3575,8 +3592,7 @@ static SEL getSel;
{ {
if ([_cells[row][j] isEnabled] && [_cells[row][j] isSelectable]) if ([_cells[row][j] isEnabled] && [_cells[row][j] isSelectable])
{ {
_selectedCell = [self selectTextAtRow: row _selectedCell = [self selectTextAtRow: row column: j];
column: j];
_selectedRow = row; _selectedRow = row;
_selectedColumn = j; _selectedColumn = j;
return YES; return YES;
@ -3590,8 +3606,7 @@ static SEL getSel;
{ {
if ([_cells[i][j] isEnabled] && [_cells[i][j] isSelectable]) if ([_cells[i][j] isEnabled] && [_cells[i][j] isSelectable])
{ {
_selectedCell = [self selectTextAtRow: i _selectedCell = [self selectTextAtRow: i column: j];
column: j];
_selectedRow = i; _selectedRow = i;
_selectedColumn = j; _selectedColumn = j;
return YES; return YES;