Exemple #1
0
func finishNewTable(b *tablebase, ty reflect.Type) Table {
	hwnd := C.newControl(C.xtableWindowClass,
		C.WS_HSCROLL|C.WS_VSCROLL|C.WS_TABSTOP,
		C.WS_EX_CLIENTEDGE) // WS_EX_CLIENTEDGE without WS_BORDER will show the canonical visual styles border (thanks to MindChild in irc.efnet.net/#winprog)
	t := &table{
		controlSingleHWND: newControlSingleHWND(hwnd),
		tablebase:         b,
		selected:          newEvent(),
		free:              make(map[C.uintptr_t]bool),
	}
	t.fpreferredSize = t.xpreferredSize
	t.chainresize = t.fresize
	t.fresize = t.xresize
	C.setTableSubclass(t.hwnd, unsafe.Pointer(t))
	// TODO listview didn't need this; someone mentioned (TODO) it uses the small caption font???
	C.controlSetControlFont(t.hwnd)
	for i := 0; i < ty.NumField(); i++ {
		coltype := C.WPARAM(C.tableColumnText)
		switch {
		case ty.Field(i).Type == reflect.TypeOf((*image.RGBA)(nil)):
			coltype = C.tableColumnImage
		case ty.Field(i).Type.Kind() == reflect.Bool:
			coltype = C.tableColumnCheckbox
		}
		colname := ty.Field(i).Tag.Get("uicolumn")
		if colname == "" {
			colname = ty.Field(i).Name
		}
		ccolname := toUTF16(colname)
		C.SendMessageW(t.hwnd, C.tableAddColumn, coltype, C.LPARAM(uintptr(unsafe.Pointer(ccolname))))
		// TODO free ccolname
	}
	t.colcount = C.int(ty.NumField())
	return t
}
Exemple #2
0
func finishNewTable(b *tablebase, ty reflect.Type) Table {
	t := &table{
		_hwnd: C.newControl(C.xWC_LISTVIEW,
			C.LVS_REPORT|C.LVS_OWNERDATA|C.LVS_NOSORTHEADER|C.LVS_SHOWSELALWAYS|C.LVS_SINGLESEL|C.WS_HSCROLL|C.WS_VSCROLL|C.WS_TABSTOP,
			C.WS_EX_CLIENTEDGE), // WS_EX_CLIENTEDGE without WS_BORDER will show the canonical visual styles border (thanks to MindChild in irc.efnet.net/#winprog)
		tablebase: b,
		hotrow:    -1,
		hotcol:    -1,
		pushedrow: -1,
		pushedcol: -1,
		selected:  newEvent(),
	}
	C.setTableSubclass(t._hwnd, unsafe.Pointer(t))
	// LVS_EX_FULLROWSELECT gives us selection across the whole row, not just the leftmost column; this makes the list view work like on other platforms
	// LVS_EX_SUBITEMIMAGES gives us images in subitems, which will be important when both images and checkboxes are added
	C.tableAddExtendedStyles(t._hwnd, C.LVS_EX_FULLROWSELECT|C.LVS_EX_SUBITEMIMAGES)
	// this must come after the subclass because it uses one of our private messages
	C.SendMessageW(t._hwnd, C.msgTableMakeInitialCheckboxImageList, 0, 0)
	for i := 0; i < ty.NumField(); i++ {
		C.tableAppendColumn(t._hwnd, C.int(i), toUTF16(ty.Field(i).Name))
	}
	t.colcount = C.int(ty.NumField())
	return t
}