summaryrefslogtreecommitdiff
path: root/redo/table_windows.go
blob: 4711e374ad08335bdc5524db5459d16c63e93a75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// 28 july 2014

package ui

import (
	"unsafe"
	"reflect"
)

// #include "winapi_windows.h"
import "C"

type table struct {
	*widgetbase
	*tablebase
}

func finishNewTable(b *tablebase, ty reflect.Type) Table {
	t := &table{
		widgetbase:	newWidget(C.xWC_LISTVIEW,
			C.LVS_REPORT | C.LVS_OWNERDATA | C.LVS_NOSORTHEADER | C.LVS_SHOWSELALWAYS | C.WS_HSCROLL | C.WS_VSCROLL,
			0),		// TODO WS_EX_CLIENTEDGE?
		tablebase:		b,
	}
	C.setTableSubclass(t.hwnd, unsafe.Pointer(&t))
	for i := 0; i < ty.NumField(); i++ {
		C.tableAppendColumn(t.hwnd, C.int(i), toUTF16(ty.Field(i).Name))
	}
	return t
}

func (t *table) Unlock() {
	t.unlock()
	// TODO RACE CONDITION HERE
	// I think there's a way to set the item count without causing a refetch of data that works around this...
	t.RLock()
	defer t.RUnlock()
	C.tableUpdate(t.hwnd, C.int(reflect.Indirect(reflect.ValueOf(t.data)).Len()))
}