2014-07-29 09:32:49 -05:00
|
|
|
// 29 july 2014
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
2014-07-29 09:54:52 -05:00
|
|
|
"fmt"
|
2014-07-29 09:32:49 -05:00
|
|
|
"reflect"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
// #include "objc_darwin.h"
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
type table struct {
|
2014-07-30 11:34:54 -05:00
|
|
|
*scrolledcontrol
|
2014-07-29 09:32:49 -05:00
|
|
|
*tablebase
|
|
|
|
}
|
|
|
|
|
|
|
|
func finishNewTable(b *tablebase, ty reflect.Type) Table {
|
|
|
|
id := C.newTable()
|
|
|
|
t := &table{
|
2014-07-30 11:34:54 -05:00
|
|
|
scrolledcontrol: newScrolledControl(id),
|
|
|
|
tablebase: b,
|
2014-07-29 09:32:49 -05:00
|
|
|
}
|
2014-07-30 11:34:54 -05:00
|
|
|
C.tableMakeDataSource(t.id, unsafe.Pointer(t))
|
2014-07-29 09:32:49 -05:00
|
|
|
for i := 0; i < ty.NumField(); i++ {
|
|
|
|
cname := C.CString(ty.Field(i).Name)
|
2014-07-30 11:34:54 -05:00
|
|
|
C.tableAppendColumn(t.id, cname)
|
2014-07-29 09:32:49 -05:00
|
|
|
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()
|
2014-07-30 11:34:54 -05:00
|
|
|
C.tableUpdate(t.id)
|
2014-07-29 09:32:49 -05:00
|
|
|
}
|
2014-07-29 09:54:52 -05:00
|
|
|
|
|
|
|
//export goTableDataSource_getValue
|
|
|
|
func goTableDataSource_getValue(data unsafe.Pointer, row C.intptr_t, col C.intptr_t) *C.char {
|
|
|
|
t := (*table)(data)
|
|
|
|
t.RLock()
|
|
|
|
defer t.RUnlock()
|
|
|
|
d := reflect.Indirect(reflect.ValueOf(t.data))
|
|
|
|
datum := d.Index(int(row)).Field(int(col))
|
|
|
|
s := fmt.Sprintf("%v", datum)
|
|
|
|
return C.CString(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
//export goTableDataSource_getRowCount
|
|
|
|
func goTableDataSource_getRowCount(data unsafe.Pointer) C.intptr_t {
|
|
|
|
t := (*table)(data)
|
|
|
|
t.RLock()
|
|
|
|
defer t.RUnlock()
|
|
|
|
d := reflect.Indirect(reflect.ValueOf(t.data))
|
|
|
|
return C.intptr_t(d.Len())
|
|
|
|
}
|