00001
00002
00003
00004
00005
00006
00007
00008
00009 #import "LLStringTable.h"
00010
00011
00012
00013
00014 @implementation LLStringTable
00015
00016 - (void) awakeFromNib {
00017 notificationCenter = [LLNotificationCenter defaultCenter];
00018 columns = [[NSMutableArray alloc] init];
00019
00020 LLStringList *list = [[LLStringList alloc] init];
00021 [list setFrame:[self frame]];
00022 [list setBounds:[self bounds]];
00023 [list awakeFromNib];
00024 [columns addObject:list];
00025
00026 hasChanged = NO;
00027 }
00028
00029 - (bool) hasChanged {
00030 return hasChanged;
00031 }
00032
00033 - (void) disableSelection {
00034 hasChanged = YES;
00035 }
00036
00037
00038 - (bool) isFlipped {
00039 return YES;
00040 }
00041
00042 - (void)drawRect:(NSRect)aRect {
00043
00044 aRect = [self bounds];
00045
00046
00047 int nrOfColumns = [columns count];
00048 int columnWidth = [self bounds].size.width / [columns count];
00049
00050 aRect.size.width = columnWidth;
00051
00052 for (int i = 0; i < nrOfColumns; i++) {
00053 LLStringList *list = [columns objectAtIndex:i];
00054 [list setBounds:aRect];
00055 [list drawRect:aRect];
00056 aRect.origin.x += columnWidth;
00057 }
00058 hasChanged = NO;
00059 }
00060
00061 - (NSPoint) mousePos {
00062
00063 NSPoint mouseBase = [[self window] mouseLocationOutsideOfEventStream];
00064
00065
00066 NSPoint mouseLocation = [self convertPoint:mouseBase fromView:nil];
00067
00068 return mouseLocation;
00069 }
00070
00071 - (void) mouseDown:(NSEvent *)theEvent {
00072
00073 NSPoint mousePosition = [self mousePos];
00074
00075 int columnWidth = [self bounds].size.width / [columns count];
00076 int selectedColumn = mousePosition.x / columnWidth;
00077
00078
00079 int nrOfColumns = [columns count];
00080 for (int i = 0; i < nrOfColumns; i++) {
00081 LLStringList *list = [columns objectAtIndex:i];
00082 if (i == selectedColumn) {
00083 int row = mousePosition.y / [list rowHeigth];
00084 [list setSelectedRow:row];
00085 [self newStringSelected:[list selectedString]];
00086 } else {
00087 [list disableSelection];
00088 }
00089
00090 }
00091
00092 hasChanged = YES;
00093 }
00094
00095 - (void) newStringSelected:(NSString*)str {
00096 [notificationCenter postNotificationName:@"LL_STRING_TABLE_SELECTION" object:self userInfo:str];
00097 }
00098
00099 - (void) emptyAllColumns {
00100 int nrOfColumns = [columns count];
00101 for (int i = 0; i < nrOfColumns; i++) {
00102 LLStringList *list = [columns objectAtIndex:i];
00103 [list emptyAllRows];
00104 }
00105 }
00106
00107 - (int) maxNrOfRows {
00108 LLStringList *col0 = [columns objectAtIndex:0];
00109 return [col0 maxNrOfStrings];
00110 }
00111
00112 - (void) setNrOfColumns:(int)newNrOfColumns {
00113 if (newNrOfColumns < 1) {
00114 return;
00115 }
00116
00117
00118 NSRect listBounds = [self bounds];
00119 listBounds.size.width /= newNrOfColumns;
00120
00121
00122 for (int i = newNrOfColumns; i < [columns count]; i++) {
00123 [columns removeLastObject];
00124
00125 }
00126
00127
00128 for (int j = [columns count]; j < newNrOfColumns; j++) {
00129 LLStringList *list = [[LLStringList alloc] init];
00130 [list setIdentifer:[NSString stringWithFormat:@"[column %d]", j]];
00131 [columns addObject:list];
00132
00133 }
00134
00135
00136 for (int k = 0; k < [columns count]; k++) {
00137 LLStringList *list = [columns objectAtIndex:k];
00138 NSLog(@"LLStringTable.setNrOfColumns (%d) x=%f, y=%f, w=%f, h=%f", k, listBounds.origin.x, listBounds.origin.y, listBounds.size.width, listBounds.size.height);
00139 [list setFrame:listBounds];
00140 [list setBounds:listBounds];
00141 [list awakeFromNib];
00142 listBounds.origin.x += listBounds.size.width;
00143 }
00144 hasChanged = YES;
00145 }
00146
00147 - (void) removeString:(NSString *)str fromColumn:(int)column {
00148 if (column >= [columns count]) {
00149 NSLog(@"LLStringTable.removeString column %d does not exist", column);
00150 return;
00151 }
00152 LLStringList *list = [columns objectAtIndex:column];
00153 [list removeString:str];
00154 hasChanged = YES;
00155 }
00156
00157 - (void) addString:(NSString *)str toColumn:(int)column {
00158 if (column >= [columns count]) {
00159 NSLog(@"LLStringTable.addString column %d does not exist", column);
00160 return;
00161 }
00162
00163 LLStringList *list = [columns objectAtIndex:column];
00164 [list addString:str];
00165 hasChanged = YES;
00166 }
00167
00168 - (void) addString:(NSString *)str withColor:(NSColor *)col toColumn:(int)column {
00169 if (column >= [columns count]) {
00170 NSLog(@"LLStringTable.addStringWithColor column %d does not exist", column);
00171 return;
00172 }
00173 LLStringList *list = [columns objectAtIndex:column];
00174
00175 [list addString:str withColor:col];
00176 hasChanged = YES;
00177 }
00178
00179 @end