Added the beginning of the Mac OS X Table code.
This commit is contained in:
parent
b37f32c142
commit
4e0436da18
|
@ -54,4 +54,10 @@ extern void moveControl(id, intptr_t, intptr_t, intptr_t, intptr_t);
|
||||||
extern id newTab(void *);
|
extern id newTab(void *);
|
||||||
extern id tabAppend(id, char *);
|
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
|
#endif
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in New Issue