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