diff options
Diffstat (limited to 'redo/table_windows.c')
| -rw-r--r-- | redo/table_windows.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/redo/table_windows.c b/redo/table_windows.c index e10611e..a34e47a 100644 --- a/redo/table_windows.c +++ b/redo/table_windows.c @@ -122,3 +122,33 @@ void tableSetCheckboxImageList(HWND hwnd) if (SendMessageW(hwnd, LVM_SETCALLBACKMASK, LVIS_STATEIMAGEMASK, 0) == FALSE) xpanic("error marking state image list as application-managed", GetLastError()); } + +// because Go won't let me do C.WPARAM(-1) +intptr_t tableSelectedItem(HWND hwnd) +{ + return (intptr_t) SendMessageW(hwnd, LVM_GETNEXTITEM, (WPARAM) -1, LVNI_SELECTED); +} + +void tableSelectItem(HWND hwnd, intptr_t index) +{ + LVITEMW item; + LRESULT current; + + // via http://support.microsoft.com/kb/131284 + // we don't need to clear the other bits; Tables don't support cutting or drag/drop + current = SendMessageW(hwnd, LVM_GETNEXTITEM, (WPARAM) -1, LVNI_SELECTED); + if (current != (LRESULT) -1) { + ZeroMemory(&item, sizeof (LVITEMW)); + item.mask = LVIF_STATE; + item.state = 0; + item.stateMask = LVIS_FOCUSED | LVIS_SELECTED; + if (SendMessageW(hwnd, LVM_SETITEMSTATE, (WPARAM) current, (LPARAM) (&item)) == FALSE) + xpanic("error deselecting current Table item", GetLastError()); + } + ZeroMemory(&item, sizeof (LVITEMW)); + item.mask = LVIF_STATE; + item.state = LVIS_FOCUSED | LVIS_SELECTED; + item.stateMask = LVIS_FOCUSED | LVIS_SELECTED; + if (SendMessageW(hwnd, LVM_SETITEMSTATE, (WPARAM) index, (LPARAM) (&item)) == FALSE) + xpanic("error selecting new Table item", GetLastError()); +} |
