From 8d7f0c9a62b9108e262380ae62f8c8b9cbb12bfc Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 29 Jul 2014 10:54:52 -0400 Subject: Wrote up the data model for Mac OS X Tables; now Tables work everywhere! --- redo/table_darwin.m | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'redo/table_darwin.m') diff --git a/redo/table_darwin.m b/redo/table_darwin.m index 45e9b0b..7fdef24 100644 --- a/redo/table_darwin.m +++ b/redo/table_darwin.m @@ -14,6 +14,24 @@ @end @implementation goTableDataSource + +- (NSInteger)numberOfRowsInTableView:(NSTableView *)view +{ + return (NSInteger) goTableDataSource_getRowCount(self->gotable); +} + +- (id)tableView:(NSTableView *)view objectValueForTableColumn:(NSTableColumn *)col row:(NSInteger)row +{ + char *str; + NSString *s; + + // TODO there has to be a better way to get the column index + str = goTableDataSource_getValue(self->gotable, (intptr_t) row, (intptr_t) [[view tableColumns] indexOfObject:col]); + s = [NSString stringWithUTF8String:str]; + free(str); // allocated with C.CString() on the Go side + return s; +} + @end id newTable(void) @@ -59,3 +77,12 @@ id newScrollView(id content) [sv setDocumentView:toNSView(content)]; return (id) sv; } + +void tableMakeDataSource(id table, void *gotable) +{ + goTableDataSource *model; + + model = [goTableDataSource new]; + model->gotable = gotable; + [toNSTableView(table) setDataSource:model]; +} -- cgit v1.2.3