Stored table column numbers more efficiently on Mac OS X.
This commit is contained in:
parent
5ec2c768fa
commit
37b1c3309b
|
@ -81,7 +81,7 @@ extern struct xsize tabPreferredSize(id);
|
||||||
|
|
||||||
/* table_darwin.m */
|
/* table_darwin.m */
|
||||||
extern id newTable(void);
|
extern id newTable(void);
|
||||||
extern void tableAppendColumn(id, char *);
|
extern void tableAppendColumn(id, intptr_t, char *);
|
||||||
extern void tableUpdate(id);
|
extern void tableUpdate(id);
|
||||||
extern void tableMakeDataSource(id, void *);
|
extern void tableMakeDataSource(id, void *);
|
||||||
extern struct xsize tablePreferredSize(id);
|
extern struct xsize tablePreferredSize(id);
|
||||||
|
|
|
@ -28,7 +28,7 @@ func finishNewTable(b *tablebase, ty reflect.Type) Table {
|
||||||
C.tableMakeDataSource(t._id, unsafe.Pointer(t))
|
C.tableMakeDataSource(t._id, unsafe.Pointer(t))
|
||||||
for i := 0; i < ty.NumField(); i++ {
|
for i := 0; i < ty.NumField(); i++ {
|
||||||
cname := C.CString(ty.Field(i).Name)
|
cname := C.CString(ty.Field(i).Name)
|
||||||
C.tableAppendColumn(t._id, cname)
|
C.tableAppendColumn(t._id, C.intptr_t(i), cname)
|
||||||
C.free(unsafe.Pointer(cname)) // free now (not deferred) to conserve memory
|
C.free(unsafe.Pointer(cname)) // free now (not deferred) to conserve memory
|
||||||
}
|
}
|
||||||
return t
|
return t
|
||||||
|
|
|
@ -6,6 +6,17 @@
|
||||||
|
|
||||||
#define toNSTableView(x) ((NSTableView *) (x))
|
#define toNSTableView(x) ((NSTableView *) (x))
|
||||||
|
|
||||||
|
// NSTableColumn provides no provision to store an integer data
|
||||||
|
// it does provide an identifier tag, but that's a NSString, and I'd rather not risk the conversion overhead
|
||||||
|
@interface goTableColumn : NSTableColumn {
|
||||||
|
@public
|
||||||
|
intptr_t gocolnum;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation goTableColumn
|
||||||
|
@end
|
||||||
|
|
||||||
@interface goTableDataSource : NSObject <NSTableViewDataSource> {
|
@interface goTableDataSource : NSObject <NSTableViewDataSource> {
|
||||||
@public
|
@public
|
||||||
void *gotable;
|
void *gotable;
|
||||||
|
@ -23,9 +34,10 @@
|
||||||
{
|
{
|
||||||
char *str;
|
char *str;
|
||||||
NSString *s;
|
NSString *s;
|
||||||
|
intptr_t colnum;
|
||||||
|
|
||||||
// TODO there has to be a better way to get the column index
|
colnum = ((goTableColumn *) col)->gocolnum;
|
||||||
str = goTableDataSource_getValue(self->gotable, (intptr_t) row, (intptr_t) [[view tableColumns] indexOfObject:col]);
|
str = goTableDataSource_getValue(self->gotable, (intptr_t) row, colnum);
|
||||||
s = [NSString stringWithUTF8String:str];
|
s = [NSString stringWithUTF8String:str];
|
||||||
free(str); // allocated with C.CString() on the Go side
|
free(str); // allocated with C.CString() on the Go side
|
||||||
return s;
|
return s;
|
||||||
|
@ -46,11 +58,12 @@ id newTable(void)
|
||||||
return (id) t;
|
return (id) t;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tableAppendColumn(id t, char *name)
|
void tableAppendColumn(id t, intptr_t colnum, char *name)
|
||||||
{
|
{
|
||||||
NSTableColumn *c;
|
goTableColumn *c;
|
||||||
|
|
||||||
c = [[NSTableColumn alloc] initWithIdentifier:nil];
|
c = [[goTableColumn alloc] initWithIdentifier:nil];
|
||||||
|
c->gocolnum = colnum;
|
||||||
[c setEditable:NO];
|
[c setEditable:NO];
|
||||||
[[c headerCell] setStringValue:[NSString stringWithUTF8String:name]];
|
[[c headerCell] setStringValue:[NSString stringWithUTF8String:name]];
|
||||||
setSmallControlFont((id) [c headerCell]);
|
setSmallControlFont((id) [c headerCell]);
|
||||||
|
|
Loading…
Reference in New Issue