Implemented Table.OnSelected() on Mac OS X.
This commit is contained in:
parent
6a0d1166d9
commit
e845fcbf78
|
@ -18,6 +18,7 @@ type table struct {
|
||||||
scroller *scroller
|
scroller *scroller
|
||||||
|
|
||||||
images []C.id
|
images []C.id
|
||||||
|
selected *event
|
||||||
}
|
}
|
||||||
|
|
||||||
func finishNewTable(b *tablebase, ty reflect.Type) Table {
|
func finishNewTable(b *tablebase, ty reflect.Type) Table {
|
||||||
|
@ -26,7 +27,9 @@ func finishNewTable(b *tablebase, ty reflect.Type) Table {
|
||||||
_id: id,
|
_id: id,
|
||||||
scroller: newScroller(id, true), // border on Table
|
scroller: newScroller(id, true), // border on Table
|
||||||
tablebase: b,
|
tablebase: b,
|
||||||
|
selected: newEvent(),
|
||||||
}
|
}
|
||||||
|
// also sets the delegate
|
||||||
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)
|
||||||
|
@ -74,6 +77,10 @@ func (t *table) Select(index int) {
|
||||||
C.tableSelect(t._id, C.intptr_t(index))
|
C.tableSelect(t._id, C.intptr_t(index))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *table) OnSelected(f func()) {
|
||||||
|
t.selected.set(f)
|
||||||
|
}
|
||||||
|
|
||||||
//export goTableDataSource_getValue
|
//export goTableDataSource_getValue
|
||||||
func goTableDataSource_getValue(data unsafe.Pointer, row C.intptr_t, col C.intptr_t, outtype *C.int) unsafe.Pointer {
|
func goTableDataSource_getValue(data unsafe.Pointer, row C.intptr_t, col C.intptr_t, outtype *C.int) unsafe.Pointer {
|
||||||
t := (*table)(data)
|
t := (*table)(data)
|
||||||
|
@ -119,6 +126,12 @@ func goTableDataSource_toggled(data unsafe.Pointer, row C.intptr_t, col C.intptr
|
||||||
datum.SetBool(fromBOOL(checked))
|
datum.SetBool(fromBOOL(checked))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//export tableSelectionChanged
|
||||||
|
func tableSelectionChanged(data unsafe.Pointer) {
|
||||||
|
t := (*table)(data)
|
||||||
|
t.selected.fire()
|
||||||
|
}
|
||||||
|
|
||||||
func (t *table) id() C.id {
|
func (t *table) id() C.id {
|
||||||
return t._id
|
return t._id
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
@implementation goTableColumn
|
@implementation goTableColumn
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface goTableDataSource : NSObject <NSTableViewDataSource> {
|
@interface goTableDataSource : NSObject <NSTableViewDataSource, NSTableViewDelegate> {
|
||||||
@public
|
@public
|
||||||
void *gotable;
|
void *gotable;
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,11 @@
|
||||||
goTableDataSource_toggled(self->gotable, (intptr_t) row, colnum, [value boolValue]);
|
goTableDataSource_toggled(self->gotable, (intptr_t) row, colnum, [value boolValue]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)tableViewSelectionDidChange:(NSNotification *)note
|
||||||
|
{
|
||||||
|
tableSelectionChanged(self->gotable);
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
id newTable(void)
|
id newTable(void)
|
||||||
|
@ -134,6 +139,7 @@ void tableUpdate(id t)
|
||||||
[toNSTableView(t) reloadData];
|
[toNSTableView(t) reloadData];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// also sets the delegate
|
||||||
void tableMakeDataSource(id table, void *gotable)
|
void tableMakeDataSource(id table, void *gotable)
|
||||||
{
|
{
|
||||||
goTableDataSource *model;
|
goTableDataSource *model;
|
||||||
|
@ -141,6 +147,7 @@ void tableMakeDataSource(id table, void *gotable)
|
||||||
model = [goTableDataSource new];
|
model = [goTableDataSource new];
|
||||||
model->gotable = gotable;
|
model->gotable = gotable;
|
||||||
[toNSTableView(table) setDataSource:model];
|
[toNSTableView(table) setDataSource:model];
|
||||||
|
[toNSTableView(table) setDelegate:model];
|
||||||
}
|
}
|
||||||
|
|
||||||
// -[NSTableView sizeToFit] does not actually size to fit
|
// -[NSTableView sizeToFit] does not actually size to fit
|
||||||
|
|
Loading…
Reference in New Issue