Filled in the rest of tablecolumn.m: wrote the NSTableColumn subclasses and implemented the public functions. Let's build and see what breaks!

This commit is contained in:
Pietro Gagliardi 2018-06-03 22:37:36 -04:00
parent 6457e1668f
commit 8fc4a9aaf5
3 changed files with 218 additions and 127 deletions

View File

@ -14,6 +14,7 @@ struct uiTable {
NSTableView *tv;
uiprivScrollViewData *d;
int backgroundColumn;
uiTableModel *m;
};
// tablecolumn.m

View File

@ -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];

View File

@ -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;
}