#include #include #include #include #include #include @implementation NSTableView + (void) initialize { if (self == [NSTableView class]) { [self setVersion: 1]; } } - (id)initWithFrame:(NSRect)frameRect { self = [super initWithFrame:frameRect]; tbv_interCellSpacing = NSMakeSize (3,2); tbv_rowHeight = 16.0; tbv_columns = [NSMutableArray new]; tbv_gridColor = [NSColor grayColor]; tbv_headerView = nil; } - (void)setDataSource:(id)anObject { if (![anObject respondsToSelector: @selector (numberOfRowsInTableView:)] || ![anObject respondsToSelector: @selector (tableView:objectValueForTableColumn:row:)]) { [NSException raise: NSInternalInconsistencyException format: @"Assigned data source does not respond to needed methods."]; } ASSIGN(tb_datasource, anObject); [self tile]; } - (id)dataSource { return tb_datasource; } - (void)reloadData { // anything else? [self setNeedsDisplay:YES]; } - (void)setDoubleAction:(SEL)aSelector { } - (SEL)doubleAction { } - (int)clickedColumn { return -1; } - (int)clickedRow { return -1; } - (void)setAllowsColumnReordering:(BOOL)flag { tbv_allowsColumnReordering = flag; } - (BOOL)allowsColumnReordering { return tbv_allowsColumnReordering; } - (void)setAllowsColumnResizing:(BOOL)flag { tbv_allowsColumnResizing = flag; } - (BOOL)allowsColumnResizing { return tbv_allowsColumnResizing; } - (void)setAllowsMultipleSelection:(BOOL)flag { tbv_allowsMultipleSelection = flag; } - (BOOL)allowsMultipleSelection { return tbv_allowsMultipleSelection; } - (void)setAllowsEmptySelection:(BOOL)flag { tbv_allowsEmptySelection = flag; } - (BOOL)allowsEmptySelection { return tbv_allowsEmptySelection; } - (void)setAllowsColumnSelection:(BOOL)flag { tbv_allowsColumnSelection = flag; } - (BOOL)allowsColumnSelection { return tbv_allowsColumnSelection; } - (void)setIntercellSpacing:(NSSize)aSize { tbv_interCellSpacing = aSize; } - (NSSize)intercellSpacing { return tbv_interCellSpacing; } - (void)setRowHeight:(float)rowHeight { tbv_rowHeight = rowHeight; [self tile]; } - (float)rowHeight { return tbv_rowHeight; } - (void)setBackgroundColor:(NSColor *)aColor { ASSIGN(tbv_backgroundColor, aColor); } - (NSColor *)backgroundColor { return tbv_backgroundColor; } - (void)addTableColumn:(NSTableColumn *)aColumn { [tbv_columns addObject:aColumn]; } - (void)removeTableColumn:(NSTableColumn *)aTableColumn { [tbv_columns removeObject:aTableColumn]; } - (void)moveColumn:(int)columnIndex toColumn:(int)newIndex { // FIXME, Michael: this is wrong, but what am I supposed to do? [tbv_columns replaceObjectAtIndex:newIndex withObject:[tbv_columns objectAtIndex:columnIndex]]; } - (NSArray *)tableColumns { return (NSArray *)tbv_columns; } - (int)columnWithIdentifier:(id)anObject { int howMany = [tbv_columns count]; int i; for (i=0;i 0 && aRect.size.height > 0) { for (i=0;i 0 && bRect.size.height > 0) { if (!location) location = i; else length = i; } } if (!length) length = 0; return NSMakeRange(location, length); } return NSMakeRange(0, 0); } - (NSRange)rowsInRect:(NSRect)aRect { int howMany = [self numberOfRows]; int location = 0; int length = 0; int i; if (aRect.size.width > 0 && aRect.size.height > 0) { for (i=0;i 0 && bRect.size.height > 0) { if (!location) location = i; else length = i; } } if (!length) length = 0; return NSMakeRange(location, length); } return NSMakeRange(0, 0); } - (int)columnAtPoint:(NSPoint)aPoint { int howMany = [tbv_columns count]; int i; for (i=0;i