Began implementing checkboxes in the Windows Table.
This commit is contained in:
parent
38e7565c37
commit
d7c173cc05
|
@ -41,6 +41,5 @@ func (i *imagelist) apply(hwnd C.HWND, uMsg C.UINT, wParam C.WPARAM) {
|
|||
for index := range i.list {
|
||||
C.addImage(il, hwnd, i.list[index], C.int(i.width[index]), C.int(i.height[index]), width, height)
|
||||
}
|
||||
// C.applyImageList(hwnd, uMsg, wParam, il)
|
||||
C.applyImageList(hwnd, uMsg, wParam, C.checkboxImageList)
|
||||
C.applyImageList(hwnd, uMsg, wParam, il)
|
||||
}
|
||||
|
|
|
@ -75,3 +75,10 @@ void tableAutosizeColumns(HWND hwnd, int nColumns)
|
|||
if (SendMessageW(hwnd, LVM_SETCOLUMNWIDTH, (WPARAM) i, (LPARAM) LVSCW_AUTOSIZE_USEHEADER) == FALSE)
|
||||
xpanic("error resizing columns of results list view", GetLastError());
|
||||
}
|
||||
|
||||
void tableSetCheckboxImageList(HWND hwnd)
|
||||
{
|
||||
if (SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM) checkboxImageList) == (LRESULT) NULL)
|
||||
;//TODO xpanic("error setting image list", GetLastError());
|
||||
// TODO free old one here if any/different
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ func finishNewTable(b *tablebase, ty reflect.Type) Table {
|
|||
// 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)
|
||||
C.tableSetCheckboxImageList(t._hwnd)
|
||||
for i := 0; i < ty.NumField(); i++ {
|
||||
C.tableAppendColumn(t._hwnd, C.int(i), toUTF16(ty.Field(i).Name))
|
||||
}
|
||||
|
@ -61,9 +62,22 @@ func tableGetCell(data unsafe.Pointer, item *C.LVITEMW) {
|
|||
d := reflect.Indirect(reflect.ValueOf(t.data))
|
||||
datum := d.Index(int(item.iItem)).Field(int(item.iSubItem))
|
||||
// TODO figure out why changing item.mask causes crashes or why "it just works"
|
||||
switch d := datum.Interface().(type) {
|
||||
case ImageIndex:
|
||||
item.iImage = C.int(d)
|
||||
switch {
|
||||
case datum.Type() == reflect.TypeOf(ImageIndex(0)):
|
||||
item.iImage = C.int(datum.Interface().(ImageIndex))
|
||||
case datum.Kind() == reflect.Bool:
|
||||
item.stateMask = C.LVIS_STATEIMAGEMASK
|
||||
// state image index is 1-based
|
||||
curstate := ((item.state & C.LVIS_STATEIMAGEMASK) >> 12)
|
||||
if curstate > 0 {
|
||||
curstate--
|
||||
}
|
||||
if datum.Bool() == true {
|
||||
curstate |= C.checkboxStateChecked
|
||||
} else {
|
||||
curstate &^= C.checkboxStateChecked
|
||||
}
|
||||
item.state = (curstate + 1) << 12
|
||||
default:
|
||||
s := fmt.Sprintf("%v", datum)
|
||||
item.pszText = toUTF16(s)
|
||||
|
|
|
@ -82,6 +82,7 @@ static LRESULT CALLBACK msgwinproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l
|
|||
// initial
|
||||
makeCheckboxImageList(hwnd);
|
||||
return 0;
|
||||
// TODO respond to WM_THEMECHANGED
|
||||
case msgRequest:
|
||||
doissue((void *) lParam);
|
||||
return 0;
|
||||
|
|
|
@ -104,6 +104,7 @@ extern void tableAppendColumn(HWND, int, LPWSTR);
|
|||
extern void tableUpdate(HWND, int);
|
||||
extern void tableAddExtendedStyles(HWND, LPARAM);
|
||||
extern void tableAutosizeColumns(HWND, int);
|
||||
extern void tableSetCheckboxImageList(HWND);
|
||||
|
||||
// container_windows.c
|
||||
extern DWORD makeContainerWindowClass(char **);
|
||||
|
|
Loading…
Reference in New Issue