summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-08-20 21:43:28 -0400
committerPietro Gagliardi <[email protected]>2014-08-20 21:43:28 -0400
commite845fcbf78a0f170e48e2383bd6a60eee68064d0 (patch)
treefd7bc383ca3bb7ceb40839b5fbc33de7c1a5c3f0
parent6a0d1166d98c8f379fca1cb1a039959994ff9f96 (diff)
Implemented Table.OnSelected() on Mac OS X.
-rw-r--r--redo/table_darwin.go13
-rw-r--r--redo/table_darwin.m9
2 files changed, 21 insertions, 1 deletions
diff --git a/redo/table_darwin.go b/redo/table_darwin.go
index bccaf1b..904600d 100644
--- a/redo/table_darwin.go
+++ b/redo/table_darwin.go
@@ -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
}
diff --git a/redo/table_darwin.m b/redo/table_darwin.m
index 5fdac83..a8c85be 100644
--- a/redo/table_darwin.m
+++ b/redo/table_darwin.m
@@ -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