summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--redo/objc_darwin.h6
-rw-r--r--redo/table_darwin.go45
-rw-r--r--redo/table_darwin.m61
3 files changed, 112 insertions, 0 deletions
diff --git a/redo/objc_darwin.h b/redo/objc_darwin.h
index 0d192a8..32a5f52 100644
--- a/redo/objc_darwin.h
+++ b/redo/objc_darwin.h
@@ -54,4 +54,10 @@ extern void moveControl(id, intptr_t, intptr_t, intptr_t, intptr_t);
extern id newTab(void *);
extern id tabAppend(id, char *);
+/* table_darwin.m */
+extern id newTable(void);
+extern void tableAppendColumn(id, char *);
+extern void tableUpdate(id);
+extern id newScrollView(id);
+
#endif
diff --git a/redo/table_darwin.go b/redo/table_darwin.go
new file mode 100644
index 0000000..91a57ac
--- /dev/null
+++ b/redo/table_darwin.go
@@ -0,0 +1,45 @@
+// 29 july 2014
+
+package ui
+
+import (
+// "fmt"
+ "reflect"
+ "unsafe"
+)
+
+// #include "objc_darwin.h"
+import "C"
+
+type table struct {
+ *widgetbase
+ *tablebase
+
+ // TODO kludge
+ table C.id
+}
+
+func finishNewTable(b *tablebase, ty reflect.Type) Table {
+ id := C.newTable()
+ t := &table{
+ widgetbase: newWidget(C.newScrollView(id)),
+ tablebase: b,
+ table: id,
+ }
+ // TODO model
+ for i := 0; i < ty.NumField(); i++ {
+ cname := C.CString(ty.Field(i).Name)
+ C.tableAppendColumn(t.table, cname)
+ C.free(unsafe.Pointer(cname)) // free now (not deferred) to conserve memory
+ }
+ return t
+}
+
+func (t *table) Unlock() {
+ t.unlock()
+ // TODO RACE CONDITION HERE
+ // not sure about this one...
+ t.RLock()
+ defer t.RUnlock()
+ C.tableUpdate(t.table)
+}
diff --git a/redo/table_darwin.m b/redo/table_darwin.m
new file mode 100644
index 0000000..45e9b0b
--- /dev/null
+++ b/redo/table_darwin.m
@@ -0,0 +1,61 @@
+// 29 july 2014
+
+#import "objc_darwin.h"
+#import "_cgo_export.h"
+#import <Cocoa/Cocoa.h>
+
+#define toNSTableView(x) ((NSTableView *) (x))
+#define toNSView(x) ((NSView *) (x))
+
+@interface goTableDataSource : NSObject <NSTableViewDataSource> {
+@public
+ void *gotable;
+}
+@end
+
+@implementation goTableDataSource
+@end
+
+id newTable(void)
+{
+ NSTableView *t;
+
+ // TODO makerect
+ t = [[NSTableView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];
+ [t setAllowsColumnReordering:NO];
+ [t setAllowsColumnResizing:YES];
+ // TODO make this an option on all platforms
+ [t setAllowsMultipleSelection:NO];
+ [t setAllowsEmptySelection:YES];
+ [t setAllowsColumnSelection:NO];
+ // TODO check against interface builder
+ return (id) t;
+}
+
+// TODO scroll view
+
+void tableAppendColumn(id t, char *name)
+{
+ NSTableColumn *c;
+
+ c = [[NSTableColumn alloc] initWithIdentifier:nil];
+ [c setEditable:NO];
+ [[c headerCell] setStringValue:[NSString stringWithUTF8String:name]];
+ // TODO other options
+ [toNSTableView(t) addTableColumn:c];
+}
+
+void tableUpdate(id t)
+{
+ [toNSTableView(t) reloadData];
+}
+
+// TODO SPLIT
+id newScrollView(id content)
+{
+ NSScrollView *sv;
+
+ sv = [[NSScrollView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];
+ [sv setDocumentView:toNSView(content)];
+ return (id) sv;
+}