Finished the implementation of checkboxes on Windows Tables.

This commit is contained in:
Pietro Gagliardi 2014-08-17 18:06:36 -04:00
parent 01a8fbd652
commit c148ccaca6
2 changed files with 37 additions and 2 deletions

View File

@ -42,10 +42,19 @@ static LRESULT CALLBACK tableSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
handle(hwnd, wParam, lParam, tableSetHot, (void *) data); handle(hwnd, wParam, lParam, tableSetHot, (void *) data);
// and let the list view do its thing // and let the list view do its thing
return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam); return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam);
case WM_LBUTTONDOWN:
handle(hwnd, wParam, lParam, tablePushed, (void *) data);
// and let the list view do its thing
return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam);
case WM_LBUTTONUP: case WM_LBUTTONUP:
handle(hwnd, wParam, lParam, tableToggled, (void *) data); handle(hwnd, wParam, lParam, tableToggled, (void *) data);
// and let the list view do its thing // and let the list view do its thing
return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam); return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam);
case WM_MOUSELEAVE:
// TODO doesn't work
tablePushed((void *) data, -1, -1); // in case button held as drag out
// and let the list view do its thing
return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam);
// see table.autoresize() in table_windows.go for the column autosize policy // see table.autoresize() in table_windows.go for the column autosize policy
case WM_NOTIFY: // from the contained header control case WM_NOTIFY: // from the contained header control
if (nmhdr->code == HDN_BEGINTRACK) if (nmhdr->code == HDN_BEGINTRACK)

View File

@ -18,6 +18,8 @@ type table struct {
colcount C.int colcount C.int
hotrow C.int hotrow C.int
hotcol C.int hotcol C.int
pushedrow C.int
pushedcol C.int
} }
func finishNewTable(b *tablebase, ty reflect.Type) Table { func finishNewTable(b *tablebase, ty reflect.Type) Table {
@ -28,6 +30,8 @@ func finishNewTable(b *tablebase, ty reflect.Type) Table {
tablebase: b, tablebase: b,
hotrow: -1, hotrow: -1,
hotcol: -1, hotcol: -1,
pushedrow: -1,
pushedcol: -1,
} }
C.setTableSubclass(t._hwnd, unsafe.Pointer(t)) 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_FULLROWSELECT gives us selection across the whole row, not just the leftmost column; this makes the list view work like on other platforms
@ -86,6 +90,11 @@ func tableGetCell(data unsafe.Pointer, item *C.LVITEMW) {
} else { } else {
curstate &^= C.checkboxStateHot curstate &^= C.checkboxStateHot
} }
if item.iItem == t.pushedrow && item.iSubItem == t.pushedcol {
curstate |= C.checkboxStatePushed
} else {
curstate &^= C.checkboxStatePushed
}
item.state = (curstate + 1) << 12 item.state = (curstate + 1) << 12
default: default:
s := fmt.Sprintf("%v", datum) s := fmt.Sprintf("%v", datum)
@ -126,14 +135,31 @@ func tableSetHot(data unsafe.Pointer, row C.int, col C.int) {
} }
} }
//export tablePushed
func tablePushed(data unsafe.Pointer, row C.int, col C.int) {
t := (*table)(data)
t.pushedrow = row
t.pushedcol = col
C.tableUpdate(t._hwnd, C.int(reflect.Indirect(reflect.ValueOf(t.data)).Len()))
}
//export tableToggled //export tableToggled
func tableToggled(data unsafe.Pointer, row C.int, col C.int) { func tableToggled(data unsafe.Pointer, row C.int, col C.int) {
t := (*table)(data) t := (*table)(data)
t.Lock()
defer func() {
// reset for next time
t.pushedrow = -1
t.pushedcol = -1
// and THEN unlock so the reset takes effect
t.Unlock()
}()
if row == -1 || col == -1 { // discard extras sent by handle() in table_windows.c if row == -1 || col == -1 { // discard extras sent by handle() in table_windows.c
return return
} }
t.Lock() if row != t.pushedrow || col != t.pushedcol { // mouse moved out
defer t.Unlock() return
}
d := reflect.Indirect(reflect.ValueOf(t.data)) d := reflect.Indirect(reflect.ValueOf(t.data))
datum := d.Index(int(row)).Field(int(col)) datum := d.Index(int(row)).Field(int(col))
if datum.Kind() == reflect.Bool { if datum.Kind() == reflect.Bool {