And fixed build errors. Now I just need to rewrite the tester and try this out...

This commit is contained in:
Pietro Gagliardi 2018-06-03 23:06:44 -04:00
parent 8fc4a9aaf5
commit 2b428d50f6
5 changed files with 75 additions and 64 deletions

View File

@ -17,7 +17,7 @@ struct uiTableData {
} u; } u;
}; };
static uiTableData *newTableData(uiTableData type) static uiTableData *newTableData(uiTableDataType type)
{ {
uiTableData *d; uiTableData *d;
@ -26,7 +26,7 @@ static uiTableData *newTableData(uiTableData type)
return d; return d;
} }
void uiFreeAttribute(uiTableData *a) void uiFreeTableData(uiTableData *d)
{ {
switch (d->type) { switch (d->type) {
case uiTableDataTypeString: case uiTableDataTypeString:

View File

@ -44,6 +44,7 @@ list(APPEND _LIBUI_SOURCES
darwin/stddialogs.m darwin/stddialogs.m
darwin/tab.m darwin/tab.m
darwin/table.m darwin/table.m
darwin/tablecolumn.m
darwin/text.m darwin/text.m
darwin/undocumented.m darwin/undocumented.m
darwin/util.m darwin/util.m

View File

@ -22,5 +22,5 @@ struct uiTable {
- (void)uiprivUpdate:(NSInteger)row; - (void)uiprivUpdate:(NSInteger)row;
@end @end
@interface uiprivTableColumn : NSTableColumn @interface uiprivTableColumn : NSTableColumn
- (uiprivColumnCellView *)uiprivMakeCellView; - (uiprivTableCellView *)uiprivMakeCellView;
@end @end

View File

@ -10,11 +10,11 @@
@implementation uiprivTableModel @implementation uiprivTableModel
- (id)initWithModel:(uiTableModel *)m - (id)initWithModel:(uiTableModel *)model
{ {
self = [super init]; self = [super init];
if (self) if (self)
self->libui_m = m; self->m = model;
return self; return self;
} }
@ -27,9 +27,9 @@
{ {
uiprivTableColumn *c = (uiprivTableColumn *) cc; uiprivTableColumn *c = (uiprivTableColumn *) cc;
// TODO consider renaming this type to uiprivTableCellView // TODO consider renaming this type to uiprivTableCellView
uiprivColumnCellView *cv; uiprivTableCellView *cv;
cv = (uiprivColumnCellView *) [tv makeViewWithIdentifier:[c identifier] owner:self]; cv = (uiprivTableCellView *) [tv makeViewWithIdentifier:[c identifier] owner:self];
if (cv == nil) if (cv == nil)
cv = [c uiprivMakeCellView]; cv = [c uiprivMakeCellView];
[cv uiprivUpdate:row]; [cv uiprivUpdate:row];
@ -38,7 +38,7 @@
- (void)tableView:(NSTableView *)nstv didAddRowView:(NSTableRowView *)rv forRow:(NSInteger)row - (void)tableView:(NSTableView *)nstv didAddRowView:(NSTableRowView *)rv forRow:(NSInteger)row
{ {
xx TODO set background color // TODO set background color
} }
@end @end
@ -79,16 +79,16 @@ void uiTableModelRowChanged(uiTableModel *m, int index)
NSTableView *tv; NSTableView *tv;
NSTableRowView *rv; NSTableRowView *rv;
NSUInteger i, n; NSUInteger i, n;
uiprivTableColumnView *cv; uiprivTableCellView *cv;
for (tv in m->tables) { for (tv in m->tables) {
rv = [tv rowViewForRow:index makeIfNecessary:NO]; rv = [tv rowViewAtRow:index makeIfNecessary:NO];
if (rv != nil) { if (rv != nil) {
xx TODO update colors // TODO update colors
} }
n = [[tv tableColumns] count]; n = [[tv tableColumns] count];
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
cv = (uiprivTableCellView *) [tv viewForColumn:i row:index makeIfNecessary:NO]; cv = (uiprivTableCellView *) [tv viewAtColumn:i row:index makeIfNecessary:NO];
if (cv != nil) if (cv != nil)
[cv uiprivUpdate:index]; [cv uiprivUpdate:index];
} }

View File

@ -58,6 +58,7 @@ static void layoutCellSubview(NSView *superview, NSView *subview, NSView *leadin
- (uiprivTableCellView *)uiprivMakeCellView - (uiprivTableCellView *)uiprivMakeCellView
{ {
[self doesNotRecognizeSelector:_cmd]; [self doesNotRecognizeSelector:_cmd];
return nil; // appease compiler
} }
@end @end
@ -122,11 +123,11 @@ struct textColumnCreateParams {
- (IBAction)uiprivOnCheckboxAction:(id)sender; - (IBAction)uiprivOnCheckboxAction:(id)sender;
@end @end
@implementation uiprivTextTableCellView @implementation uiprivTextImageCheckboxTableCellView
- (id)initWithFrame:(NSRect)r params:(struct textColumnCreateParams *)p - (id)initWithFrame:(NSRect)r params:(struct textColumnCreateParams *)p
{ {
self = [super initWithFrame:frame]; self = [super initWithFrame:r];
if (self) { if (self) {
NSView *left; NSView *left;
CGFloat leftConstant; CGFloat leftConstant;
@ -151,7 +152,8 @@ struct textColumnCreateParams {
left = nil; left = nil;
self->iv = nil; self->iv = nil;
if (p->makeImageView) { // TODO rename to makeImageView
if (p->makeImage) {
self->iv = [[NSImageView alloc] initWithFrame:NSZeroRect]; self->iv = [[NSImageView alloc] initWithFrame:NSZeroRect];
[self->iv setImageFrameStyle:NSImageFrameNone]; [self->iv setImageFrameStyle:NSImageFrameNone];
[self->iv setImageAlignment:NSImageAlignCenter]; [self->iv setImageAlignment:NSImageAlignCenter];
@ -239,11 +241,10 @@ struct textColumnCreateParams {
- (void)uiprivUpdate:(NSInteger)row - (void)uiprivUpdate:(NSInteger)row
{ {
uiTableData *data; uiTableData *data;
BOOL editable;
if (self->tv != nil) { if (self->tf != nil) {
NSString *str; NSString *str;
BOOL editable; NSColor *color;
data = (*(self->m->mh->CellValue))(self->m->mh, self->m, row, self->textModelColumn); data = (*(self->m->mh->CellValue))(self->m->mh, self->m, row, self->textModelColumn);
str = uiprivToNSString(uiTableDataString(data)); str = uiprivToNSString(uiTableDataString(data));
@ -263,7 +264,7 @@ struct textColumnCreateParams {
} }
if (color == nil) if (color == nil)
color = [NSColor controlTextColor]; color = [NSColor controlTextColor];
[self->tf setColor:color]; [self->tf setTextColor:color];
// we don't own color in ether case; don't release // we don't own color in ether case; don't release
} }
if (self->iv != nil) { if (self->iv != nil) {
@ -282,7 +283,7 @@ struct textColumnCreateParams {
[self->cb setState:NSOffState]; [self->cb setState:NSOffState];
uiFreeTableData(data); uiFreeTableData(data);
[self->cb setEditable:isCellEditable(self->m, row, self->checkboxEditableColumn)]; [self->cb setEnabled:isCellEditable(self->m, row, self->checkboxEditableColumn)];
} }
} }
@ -332,9 +333,9 @@ struct textColumnCreateParams {
return self; return self;
} }
- (uiprivColumnCellView *)uiprivMakeCellView - (uiprivTableCellView *)uiprivMakeCellView
{ {
uiprivColumnCellView *cv; uiprivTableCellView *cv;
cv = [[uiprivTextImageCheckboxTableCellView alloc] initWithFrame:NSZeroRect params:&(self->params)]; cv = [[uiprivTextImageCheckboxTableCellView alloc] initWithFrame:NSZeroRect params:&(self->params)];
[cv setIdentifier:[self identifier]]; [cv setIdentifier:[self identifier]];
@ -408,26 +409,32 @@ struct textColumnCreateParams {
@end @end
@interface uiprivProgressBarTableColumn : uiprivTableColumn { @interface uiprivProgressBarTableColumn : uiprivTableColumn {
uiTable *t;
// TODO remove the need for this given t (or make t not require m, one of the two)
uiTableModel *m;
int modelColumn; int modelColumn;
} }
- (id)initWithIdentifier:(NSString *)ident modelColumn:(int)mc; - (id)initWithIdentifier:(NSString *)ident table:(uiTable *)table model:(uiTableModel *)model modelColumn:(int)mc;
@end @end
@implementation uiprivProgressBarTableColumn @implementation uiprivProgressBarTableColumn
- (id)initWithIdentifier:(NSString *)ident modelColumn:(int)mc - (id)initWithIdentifier:(NSString *)ident table:(uiTable *)table model:(uiTableModel *)model modelColumn:(int)mc
{ {
self = [super initWithIdentifier:ident]; self = [super initWithIdentifier:ident];
if (self) if (self) {
self->t = table;
self->m = model;
self->modelColumn = mc; self->modelColumn = mc;
}
return self; return self;
} }
- (uiprivColumnCellView *)uiprivMakeCellView - (uiprivTableCellView *)uiprivMakeCellView
{ {
uiprivColumnCellView *cv; uiprivTableCellView *cv;
cv = [[uiprivProgressBarTableCellView alloc] initWithFrame:NSZeroRect modelColumn:self->modelColumn]; cv = [[uiprivProgressBarTableCellView alloc] initWithFrame:NSZeroRect table:self->t model:self->m modelColumn:self->modelColumn];
[cv setIdentifier:[self identifier]]; [cv setIdentifier:[self identifier]];
return cv; return cv;
} }
@ -445,7 +452,7 @@ struct textColumnCreateParams {
- (IBAction)uiprivOnClicked:(id)sender; - (IBAction)uiprivOnClicked:(id)sender;
@end @end
@implementation uiprivProgressBarTableCellView @implementation uiprivButtonTableCellView
- (id)initWithFrame:(NSRect)r table:(uiTable *)table model:(uiTableModel *)model modelColumn:(int)mc editableColumn:(int)ec - (id)initWithFrame:(NSRect)r table:(uiTable *)table model:(uiTableModel *)model modelColumn:(int)mc editableColumn:(int)ec
{ {
@ -473,8 +480,8 @@ struct textColumnCreateParams {
- (void)dealloc - (void)dealloc
{ {
[self->p release]; [self->b release];
self->p = nil; self->b = nil;
[super dealloc]; [super dealloc];
} }
@ -482,17 +489,16 @@ struct textColumnCreateParams {
{ {
uiTableData *data; uiTableData *data;
NSString *str; NSString *str;
BOOL editable;
data = (*(self->m->mh->CellValue))(self->m->mh, self->m, row, self->modelColumn); data = (*(self->m->mh->CellValue))(self->m->mh, self->m, row, self->modelColumn);
str = uiprivToNSString(uiTableDataString(data)); str = uiprivToNSString(uiTableDataString(data));
uiFreeTableData(data); uiFreeTableData(data);
[self->b setTitle:str]; [self->b setTitle:str];
[self->b setEditable:isCellEditable(self->m, row, self->editableColumn)]; [self->b setEnabled:isCellEditable(self->m, row, self->editableColumn)];
} }
- (id)uiprivOnClicked:(id)sender - (IBAction)uiprivOnClicked:(id)sender
{ {
// TODO // TODO
} }
@ -500,29 +506,33 @@ struct textColumnCreateParams {
@end @end
@interface uiprivButtonTableColumn : uiprivTableColumn { @interface uiprivButtonTableColumn : uiprivTableColumn {
uiTable *t;
uiTableModel *m;
int modelColumn; int modelColumn;
int editableColumn; int editableColumn;
} }
- (id)initWithIdentifier:(NSString *)ident modelColumn:(int)mc editableColumn:(int)ec; - (id)initWithIdentifier:(NSString *)ident table:(uiTable *)table model:(uiTableModel *)model modelColumn:(int)mc editableColumn:(int)ec;
@end @end
@implementation uiprivButtonTableColumn @implementation uiprivButtonTableColumn
- (id)initWithIdentifier:(NSString *)ident modelColumn:(int)mc editableColumn:(int)ec - (id)initWithIdentifier:(NSString *)ident table:(uiTable *)table model:(uiTableModel *)model modelColumn:(int)mc editableColumn:(int)ec
{ {
self = [super initWithIdentifier:ident]; self = [super initWithIdentifier:ident];
if (self) { if (self) {
self->t = table;
self->m = model;
self->modelColumn = mc; self->modelColumn = mc;
self->editableColumn = ec; self->editableColumn = ec;
} }
return self; return self;
} }
- (uiprivColumnCellView *)uiprivMakeCellView - (uiprivTableCellView *)uiprivMakeCellView
{ {
uiprivColumnCellView *cv; uiprivTableCellView *cv;
cv = [[uiprivButtonTableCellView alloc] initWithFrame:NSZeroRect modelColumn:self->modelColumn editableColumn:self->editableColumn]; cv = [[uiprivButtonTableCellView alloc] initWithFrame:NSZeroRect table:self->t model:self->m modelColumn:self->modelColumn editableColumn:self->editableColumn];
[cv setIdentifier:[self identifier]]; [cv setIdentifier:[self identifier]];
return cv; return cv;
} }
@ -541,15 +551,15 @@ void uiTableAppendTextColumn(uiTable *t, const char *name, int textModelColumn,
p.makeTextField = YES; p.makeTextField = YES;
p.textModelColumn = textModelColumn; p.textModelColumn = textModelColumn;
p.textEditableModelColumn = textEditableModelColumn; p.textEditableColumn = textEditableModelColumn;
if (params == NULL) if (params == NULL)
params = &defaultTextColumnOptionalParams; params = &defaultTextColumnOptionalParams;
p.textParams = *params; p.textParams = *params;
str = [NSString stringWithUTF8String:name]; str = [NSString stringWithUTF8String:name];
col = [[uiprivTextImageCheckboxTableColum alloc] initWithIdentifier:str params:&p]; col = [[uiprivTextImageCheckboxTableColumn alloc] initWithIdentifier:str params:&p];
[col setTitle:str]; [col setTitle:str];
return col; [t->tv addTableColumn:col];
} }
void uiTableAppendImageColumn(uiTable *t, const char *name, int imageModelColumn) void uiTableAppendImageColumn(uiTable *t, const char *name, int imageModelColumn)
@ -566,9 +576,9 @@ void uiTableAppendImageColumn(uiTable *t, const char *name, int imageModelColumn
p.imageModelColumn = imageModelColumn; p.imageModelColumn = imageModelColumn;
str = [NSString stringWithUTF8String:name]; str = [NSString stringWithUTF8String:name];
col = [[uiprivTextImageCheckboxTableColum alloc] initWithIdentifier:str params:&p]; col = [[uiprivTextImageCheckboxTableColumn alloc] initWithIdentifier:str params:&p];
[col setTitle:str]; [col setTitle:str];
return col; [t->tv addTableColumn:col];
} }
void uiTableAppendImageTextColumn(uiTable *t, const char *name, int imageModelColumn, int textModelColumn, int textEditableModelColumn, uiTableTextColumnOptionalParams *textParams) void uiTableAppendImageTextColumn(uiTable *t, const char *name, int imageModelColumn, int textModelColumn, int textEditableModelColumn, uiTableTextColumnOptionalParams *textParams)
@ -583,18 +593,18 @@ void uiTableAppendImageTextColumn(uiTable *t, const char *name, int imageModelCo
p.makeTextField = YES; p.makeTextField = YES;
p.textModelColumn = textModelColumn; p.textModelColumn = textModelColumn;
p.textEditableModelColumn = textEditableModelColumn; p.textEditableColumn = textEditableModelColumn;
if (params == NULL) if (textParams == NULL)
params = &defaultTextColumnOptionalParams; textParams = &defaultTextColumnOptionalParams;
p.textParams = *params; p.textParams = *textParams;
p.makeImage = YES; p.makeImage = YES;
p.imageModelColumn = imageModelColumn; p.imageModelColumn = imageModelColumn;
str = [NSString stringWithUTF8String:name]; str = [NSString stringWithUTF8String:name];
col = [[uiprivTextImageCheckboxTableColum alloc] initWithIdentifier:str params:&p]; col = [[uiprivTextImageCheckboxTableColumn alloc] initWithIdentifier:str params:&p];
[col setTitle:str]; [col setTitle:str];
return col; [t->tv addTableColumn:col];
} }
void uiTableAppendCheckboxColumn(uiTable *t, const char *name, int checkboxModelColumn, int checkboxEditableModelColumn) void uiTableAppendCheckboxColumn(uiTable *t, const char *name, int checkboxModelColumn, int checkboxEditableModelColumn)
@ -609,12 +619,12 @@ void uiTableAppendCheckboxColumn(uiTable *t, const char *name, int checkboxModel
p.makeCheckbox = YES; p.makeCheckbox = YES;
p.checkboxModelColumn = checkboxModelColumn; p.checkboxModelColumn = checkboxModelColumn;
p.checkboxEditableColumn = checkboxEditableColumn; p.checkboxEditableColumn = checkboxEditableModelColumn;
str = [NSString stringWithUTF8String:name]; str = [NSString stringWithUTF8String:name];
col = [[uiprivTextImageCheckboxTableColum alloc] initWithIdentifier:str params:&p]; col = [[uiprivTextImageCheckboxTableColumn alloc] initWithIdentifier:str params:&p];
[col setTitle:str]; [col setTitle:str];
return col; [t->tv addTableColumn:col];
} }
void uiTableAppendCheckboxTextColumn(uiTable *t, const char *name, int checkboxModelColumn, int checkboxEditableModelColumn, int textModelColumn, int textEditableModelColumn, uiTableTextColumnOptionalParams *textParams) void uiTableAppendCheckboxTextColumn(uiTable *t, const char *name, int checkboxModelColumn, int checkboxEditableModelColumn, int textModelColumn, int textEditableModelColumn, uiTableTextColumnOptionalParams *textParams)
@ -629,19 +639,19 @@ void uiTableAppendCheckboxTextColumn(uiTable *t, const char *name, int checkboxM
p.makeTextField = YES; p.makeTextField = YES;
p.textModelColumn = textModelColumn; p.textModelColumn = textModelColumn;
p.textEditableModelColumn = textEditableModelColumn; p.textEditableColumn = textEditableModelColumn;
if (params == NULL) if (textParams == NULL)
params = &defaultTextColumnOptionalParams; textParams = &defaultTextColumnOptionalParams;
p.textParams = *params; p.textParams = *textParams;
p.makeCheckbox = YES; p.makeCheckbox = YES;
p.checkboxModelColumn = checkboxModelColumn; p.checkboxModelColumn = checkboxModelColumn;
p.checkboxEditableColumn = checkboxEditableColumn; p.checkboxEditableColumn = checkboxEditableModelColumn;
str = [NSString stringWithUTF8String:name]; str = [NSString stringWithUTF8String:name];
col = [[uiprivTextImageCheckboxTableColum alloc] initWithIdentifier:str params:&p]; col = [[uiprivTextImageCheckboxTableColumn alloc] initWithIdentifier:str params:&p];
[col setTitle:str]; [col setTitle:str];
return col; [t->tv addTableColumn:col];
} }
void uiTableAppendProgressBarColumn(uiTable *t, const char *name, int progressModelColumn) void uiTableAppendProgressBarColumn(uiTable *t, const char *name, int progressModelColumn)
@ -650,9 +660,9 @@ void uiTableAppendProgressBarColumn(uiTable *t, const char *name, int progressMo
NSString *str; NSString *str;
str = [NSString stringWithUTF8String:name]; str = [NSString stringWithUTF8String:name];
col = [[uiprivProgressBarTableColum alloc] initWithIdentifier:str modelColumn:progressModelColumn]; col = [[uiprivProgressBarTableColumn alloc] initWithIdentifier:str table:t model:t->m modelColumn:progressModelColumn];
[col setTitle:str]; [col setTitle:str];
return col; [t->tv addTableColumn:col];
} }
void uiTableAppendButtonColumn(uiTable *t, const char *name, int buttonTextModelColumn, int buttonClickableModelColumn) void uiTableAppendButtonColumn(uiTable *t, const char *name, int buttonTextModelColumn, int buttonClickableModelColumn)
@ -661,7 +671,7 @@ void uiTableAppendButtonColumn(uiTable *t, const char *name, int buttonTextModel
NSString *str; NSString *str;
str = [NSString stringWithUTF8String:name]; str = [NSString stringWithUTF8String:name];
col = [[uiprivButtonTableColum alloc] initWithIdentifier:str modelColumn:buttonTextModelColumn editableColumn:buttonClickableModelColumn]; col = [[uiprivButtonTableColumn alloc] initWithIdentifier:str table:t model:t->m modelColumn:buttonTextModelColumn editableColumn:buttonClickableModelColumn];
[col setTitle:str]; [col setTitle:str];
return col; [t->tv addTableColumn:col];
} }