Implemented Windows Table checkbox clicking.
This commit is contained in:
parent
8f5df78f2a
commit
01a8fbd652
|
@ -6,7 +6,7 @@
|
||||||
// provided for cgo's benefit
|
// provided for cgo's benefit
|
||||||
LPWSTR xWC_LISTVIEW = WC_LISTVIEW;
|
LPWSTR xWC_LISTVIEW = WC_LISTVIEW;
|
||||||
|
|
||||||
static void handleMouseMove(HWND hwnd, WPARAM wParam, LPARAM lParam, void *data)
|
static void handle(HWND hwnd, WPARAM wParam, LPARAM lParam, void (*handler)(void *, int, int), void *data)
|
||||||
{
|
{
|
||||||
LVHITTESTINFO ht;
|
LVHITTESTINFO ht;
|
||||||
|
|
||||||
|
@ -15,14 +15,14 @@ static void handleMouseMove(HWND hwnd, WPARAM wParam, LPARAM lParam, void *data)
|
||||||
ht.pt.x = GET_X_LPARAM(lParam);
|
ht.pt.x = GET_X_LPARAM(lParam);
|
||||||
ht.pt.y = GET_Y_LPARAM(lParam);
|
ht.pt.y = GET_Y_LPARAM(lParam);
|
||||||
if (SendMessageW(hwnd, LVM_SUBITEMHITTEST, 0, (LPARAM) (&ht)) == (LRESULT) -1) {
|
if (SendMessageW(hwnd, LVM_SUBITEMHITTEST, 0, (LPARAM) (&ht)) == (LRESULT) -1) {
|
||||||
tableSetHot(data, -1, -1);
|
(*handler)(data, -1, -1);
|
||||||
return; // no item
|
return; // no item
|
||||||
}
|
}
|
||||||
if (ht.flags != LVHT_ONITEMSTATEICON) {
|
if (ht.flags != LVHT_ONITEMSTATEICON) {
|
||||||
tableSetHot(data, -1, -1);
|
(*handler)(data, -1, -1);
|
||||||
return;
|
return; // not on a checkbox
|
||||||
}
|
}
|
||||||
tableSetHot(data, ht.iItem, ht.iSubItem);
|
(*handler)(data, ht.iItem, ht.iSubItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static LRESULT CALLBACK tableSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR id, DWORD_PTR data)
|
static LRESULT CALLBACK tableSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR id, DWORD_PTR data)
|
||||||
|
@ -39,7 +39,11 @@ static LRESULT CALLBACK tableSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
|
||||||
}
|
}
|
||||||
return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam);
|
return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam);
|
||||||
case WM_MOUSEMOVE:
|
case WM_MOUSEMOVE:
|
||||||
handleMouseMove(hwnd, wParam, lParam, (void *) data);
|
handle(hwnd, wParam, lParam, tableSetHot, (void *) data);
|
||||||
|
// and let the list view do its thing
|
||||||
|
return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam);
|
||||||
|
case WM_LBUTTONUP:
|
||||||
|
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);
|
||||||
// see table.autoresize() in table_windows.go for the column autosize policy
|
// see table.autoresize() in table_windows.go for the column autosize policy
|
||||||
|
|
|
@ -126,6 +126,23 @@ func tableSetHot(data unsafe.Pointer, row C.int, col C.int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//export tableToggled
|
||||||
|
func tableToggled(data unsafe.Pointer, row C.int, col C.int) {
|
||||||
|
t := (*table)(data)
|
||||||
|
if row == -1 || col == -1 { // discard extras sent by handle() in table_windows.c
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t.Lock()
|
||||||
|
defer t.Unlock()
|
||||||
|
d := reflect.Indirect(reflect.ValueOf(t.data))
|
||||||
|
datum := d.Index(int(row)).Field(int(col))
|
||||||
|
if datum.Kind() == reflect.Bool {
|
||||||
|
datum.SetBool(!datum.Bool())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
panic(fmt.Errorf("tableSetHot() on non-checkbox at (%d, %d)", row, col))
|
||||||
|
}
|
||||||
|
|
||||||
func (t *table) hwnd() C.HWND {
|
func (t *table) hwnd() C.HWND {
|
||||||
return t._hwnd
|
return t._hwnd
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue