diff --git a/darwin/table.h b/darwin/table.h index dbc26520..0871a740 100644 --- a/darwin/table.h +++ b/darwin/table.h @@ -14,6 +14,7 @@ struct uiTable { NSTableView *tv; uiprivScrollViewData *d; int backgroundColumn; + uiTableModel *m; }; // tablecolumn.m diff --git a/darwin/table.m b/darwin/table.m index 70b11c3e..b046c6db 100644 --- a/darwin/table.m +++ b/darwin/table.m @@ -106,81 +106,6 @@ void uiTableModelRowDeleted(uiTableModel *m, int oldIndex) // set is autoreleased } -=================== TODOTODO - -void uiTableColumnAppendTextPart(uiTableColumn *c, int modelColumn, int expand) -{ - tablePart *part; - - part = [tablePart new]; - part.type = partText; - part.textColumn = modelColumn; - part.expand = expand; - [c->parts addObject:part]; -} - -void uiTableColumnAppendImagePart(uiTableColumn *c, int modelColumn, int expand) -{ - tablePart *part; - - part = [tablePart new]; - part.type = partImage; - part.imageColumn = modelColumn; - part.expand = expand; - [c->parts addObject:part]; -} - -void uiTableColumnAppendButtonPart(uiTableColumn *c, int modelColumn, int expand) -{ - tablePart *part; - - part = [tablePart new]; - part.type = partButton; - part.textColumn = modelColumn; - part.expand = expand; - part.editable = 1; // editable by default - [c->parts addObject:part]; -} - -void uiTableColumnAppendCheckboxPart(uiTableColumn *c, int modelColumn, int expand) -{ - tablePart *part; - - part = [tablePart new]; - part.type = partCheckbox; - part.valueColumn = modelColumn; - part.expand = expand; - part.editable = 1; // editable by default - [c->parts addObject:part]; -} - -void uiTableColumnAppendProgressBarPart(uiTableColumn *c, int modelColumn, int expand) -{ - tablePart *part; - - part = [tablePart new]; - part.type = partProgressBar; - part.valueColumn = modelColumn; - part.expand = expand; - [c->parts addObject:part]; -} - -void uiTableColumnPartSetEditable(uiTableColumn *c, int part, int editable) -{ - tablePart *p; - - p = (tablePart *) [c->parts objectAtIndex:part]; - p.editable = editable; -} - -void uiTableColumnPartSetTextColor(uiTableColumn *c, int part, int modelColumn) -{ - tablePart *p; - - p = (tablePart *) [c->parts objectAtIndex:part]; - p.textColorColumn = modelColumn; -} - uiDarwinControlAllDefaultsExceptDestroy(uiTable, sv) static void uiTableDestroy(uiControl *c) @@ -192,27 +117,10 @@ static void uiTableDestroy(uiControl *c) uiFreeControl(uiControl(t)); } -uiTableColumn *uiTableAppendColumn(uiTable *t, const char *name) -{ - uiTableColumn *c; - - c = uiprivNew(uiTableColumn); - c->c = [[tableColumn alloc] initWithIdentifier:@""]; - c->c.libui_col = c; - // via Interface Builder - [c->c setResizingMask:(NSTableColumnAutoresizingMask | NSTableColumnUserResizingMask)]; - // 10.10 adds -[NSTableColumn setTitle:]; before then we have to do this - [[c->c headerCell] setStringValue:uiprivToNSString(name)]; - // TODO is this sufficient? - [[c->c headerCell] setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]]; - c->parts = [NSMutableArray new]; - [t->tv addTableColumn:c->c]; - return c; -} - void uiTableSetRowBackgroundColorModelColumn(uiTable *t, int modelColumn) { t->backgroundColumn = modelColumn; + // TODO update all rows } uiTable *uiNewTable(uiTableModel *model) @@ -221,9 +129,9 @@ uiTable *uiNewTable(uiTableModel *model) uiprivScrollViewCreateParams p; uiDarwinNewControl(uiTable, t); + t->m = model; - t->tv = [[tableView alloc] initWithFrame:NSZeroRect]; - t->tv.libui_t = t; + t->tv = [[NSTableView alloc] initWithFrame:NSZeroRect]; [t->tv setDataSource:model->m]; [t->tv setDelegate:model->m]; diff --git a/darwin/tablecolumn.m b/darwin/tablecolumn.m index 01ff5b27..339d4a6a 100644 --- a/darwin/tablecolumn.m +++ b/darwin/tablecolumn.m @@ -316,6 +316,33 @@ struct textColumnCreateParams { @end +@interface uiprivTextImageCheckboxTableColumn : uiprivTableColumn { + struct textColumnCreateParams params; +} +- (id)initWithIdentifier:(NSString *)ident params:(struct textColumnCreateParams *)p; +@end + +@implementation uiprivTextImageCheckboxTableColumn + +- (id)initWithIdentifier:(NSString *)ident params:(struct textColumnCreateParams *)p +{ + self = [super initWithIdentifier:ident]; + if (self) + self->params = *p; + return self; +} + +- (uiprivColumnCellView *)uiprivMakeCellView +{ + uiprivColumnCellView *cv; + + cv = [[uiprivTextImageCheckboxTableCellView alloc] initWithFrame:NSZeroRect params:&(self->params)]; + [cv setIdentifier:[self identifier]]; + return cv; +} + +@end + @interface uiprivProgressBarTableCellView : uiprivTableCellView { uiTable *t; uiTableModel *m; @@ -380,6 +407,33 @@ struct textColumnCreateParams { @end +@interface uiprivProgressBarTableColumn : uiprivTableColumn { + int modelColumn; +} +- (id)initWithIdentifier:(NSString *)ident modelColumn:(int)mc; +@end + +@implementation uiprivProgressBarTableColumn + +- (id)initWithIdentifier:(NSString *)ident modelColumn:(int)mc +{ + self = [super initWithIdentifier:ident]; + if (self) + self->modelColumn = mc; + return self; +} + +- (uiprivColumnCellView *)uiprivMakeCellView +{ + uiprivColumnCellView *cv; + + cv = [[uiprivProgressBarTableCellView alloc] initWithFrame:NSZeroRect modelColumn:self->modelColumn]; + [cv setIdentifier:[self identifier]]; + return cv; +} + +@end + @interface uiprivButtonTableCellView : uiprivTableCellView { uiTable *t; uiTableModel *m; @@ -445,41 +499,169 @@ struct textColumnCreateParams { @end -void uiTableAppendTextColumn(uiTable *t, - const char *name, - int textModelColumn, - int textEditableModelColumn, - uiTableTextColumnOptionalParams *params); +@interface uiprivButtonTableColumn : uiprivTableColumn { + int modelColumn; + int editableColumn; +} +- (id)initWithIdentifier:(NSString *)ident modelColumn:(int)mc editableColumn:(int)ec; +@end -void uiTableAppendImageColumn(uiTable *t, - const char *name, - int imageModelColumn); +@implementation uiprivButtonTableColumn -void uiTableAppendImageTextColumn(uiTable *t, - const char *name, - int imageModelColumn, - int textModelColumn, - int textEditableModelColumn, - uiTableTextColumnOptionalParams *textParams); +- (id)initWithIdentifier:(NSString *)ident modelColumn:(int)mc editableColumn:(int)ec +{ + self = [super initWithIdentifier:ident]; + if (self) { + self->modelColumn = mc; + self->editableColumn = ec; + } + return self; +} -void uiTableAppendCheckboxColumn(uiTable *t, - const char *name, - int checkboxModelColumn, - int checkboxEditableModelColumn); +- (uiprivColumnCellView *)uiprivMakeCellView +{ + uiprivColumnCellView *cv; -void uiTableAppendCheckboxTextColumn(uiTable *t, - const char *name, - int checkboxModelColumn, - int checkboxEditableModelColumn, - int textModelColumn, - int textEditableModelColumn, - uiTableTextColumnOptionalParams *textParams); + cv = [[uiprivButtonTableCellView alloc] initWithFrame:NSZeroRect modelColumn:self->modelColumn editableColumn:self->editableColumn]; + [cv setIdentifier:[self identifier]]; + return cv; +} -void uiTableAppendProgressBarColumn(uiTable *t, - const char *name, - int progressModelColumn); +@end -void uiTableAppendButtonColumn(uiTable *t, - const char *name, - int buttonTextModelColumn, - int buttonClickableModelColumn); +void uiTableAppendTextColumn(uiTable *t, const char *name, int textModelColumn, int textEditableModelColumn, uiTableTextColumnOptionalParams *params) +{ + struct textColumnCreateParams p; + uiprivTableColumn *col; + NSString *str; + + memset(&p, 0, sizeof (struct textColumnCreateParams)); + p.t = t; + p.m = t->m; + + p.makeTextField = YES; + p.textModelColumn = textModelColumn; + p.textEditableModelColumn = textEditableModelColumn; + if (params == NULL) + params = &defaultTextColumnOptionalParams; + p.textParams = *params; + + str = [NSString stringWithUTF8String:name]; + col = [[uiprivTextImageCheckboxTableColum alloc] initWithIdentifier:str params:&p]; + [col setTitle:str]; + return col; +} + +void uiTableAppendImageColumn(uiTable *t, const char *name, int imageModelColumn) +{ + struct textColumnCreateParams p; + uiprivTableColumn *col; + NSString *str; + + memset(&p, 0, sizeof (struct textColumnCreateParams)); + p.t = t; + p.m = t->m; + + p.makeImage = YES; + p.imageModelColumn = imageModelColumn; + + str = [NSString stringWithUTF8String:name]; + col = [[uiprivTextImageCheckboxTableColum alloc] initWithIdentifier:str params:&p]; + [col setTitle:str]; + return col; +} + +void uiTableAppendImageTextColumn(uiTable *t, const char *name, int imageModelColumn, int textModelColumn, int textEditableModelColumn, uiTableTextColumnOptionalParams *textParams) +{ + struct textColumnCreateParams p; + uiprivTableColumn *col; + NSString *str; + + memset(&p, 0, sizeof (struct textColumnCreateParams)); + p.t = t; + p.m = t->m; + + p.makeTextField = YES; + p.textModelColumn = textModelColumn; + p.textEditableModelColumn = textEditableModelColumn; + if (params == NULL) + params = &defaultTextColumnOptionalParams; + p.textParams = *params; + + p.makeImage = YES; + p.imageModelColumn = imageModelColumn; + + str = [NSString stringWithUTF8String:name]; + col = [[uiprivTextImageCheckboxTableColum alloc] initWithIdentifier:str params:&p]; + [col setTitle:str]; + return col; +} + +void uiTableAppendCheckboxColumn(uiTable *t, const char *name, int checkboxModelColumn, int checkboxEditableModelColumn) +{ + struct textColumnCreateParams p; + uiprivTableColumn *col; + NSString *str; + + memset(&p, 0, sizeof (struct textColumnCreateParams)); + p.t = t; + p.m = t->m; + + p.makeCheckbox = YES; + p.checkboxModelColumn = checkboxModelColumn; + p.checkboxEditableColumn = checkboxEditableColumn; + + str = [NSString stringWithUTF8String:name]; + col = [[uiprivTextImageCheckboxTableColum alloc] initWithIdentifier:str params:&p]; + [col setTitle:str]; + return col; +} + +void uiTableAppendCheckboxTextColumn(uiTable *t, const char *name, int checkboxModelColumn, int checkboxEditableModelColumn, int textModelColumn, int textEditableModelColumn, uiTableTextColumnOptionalParams *textParams) +{ + struct textColumnCreateParams p; + uiprivTableColumn *col; + NSString *str; + + memset(&p, 0, sizeof (struct textColumnCreateParams)); + p.t = t; + p.m = t->m; + + p.makeTextField = YES; + p.textModelColumn = textModelColumn; + p.textEditableModelColumn = textEditableModelColumn; + if (params == NULL) + params = &defaultTextColumnOptionalParams; + p.textParams = *params; + + p.makeCheckbox = YES; + p.checkboxModelColumn = checkboxModelColumn; + p.checkboxEditableColumn = checkboxEditableColumn; + + str = [NSString stringWithUTF8String:name]; + col = [[uiprivTextImageCheckboxTableColum alloc] initWithIdentifier:str params:&p]; + [col setTitle:str]; + return col; +} + +void uiTableAppendProgressBarColumn(uiTable *t, const char *name, int progressModelColumn) +{ + uiprivTableColumn *col; + NSString *str; + + str = [NSString stringWithUTF8String:name]; + col = [[uiprivProgressBarTableColum alloc] initWithIdentifier:str modelColumn:progressModelColumn]; + [col setTitle:str]; + return col; +} + +void uiTableAppendButtonColumn(uiTable *t, const char *name, int buttonTextModelColumn, int buttonClickableModelColumn) +{ + uiprivTableColumn *col; + NSString *str; + + str = [NSString stringWithUTF8String:name]; + col = [[uiprivButtonTableColum alloc] initWithIdentifier:str modelColumn:buttonTextModelColumn editableColumn:buttonClickableModelColumn]; + [col setTitle:str]; + return col; +}