diff --git a/table_windows.c b/table_windows.c index 8d92a8e..8b352d7 100644 --- a/table_windows.c +++ b/table_windows.c @@ -74,10 +74,12 @@ void tableAutosizeColumns(HWND hwnd, int nColumns) xpanic("error resizing columns of results list view", 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); + intptr_t row; + + SendMessageW(hwnd, tableGetSelection, (WPARAM) (&row), (LPARAM) NULL); + return row; } /* diff --git a/table_windows.go b/table_windows.go index 7bd9df0..ceca0eb 100644 --- a/table_windows.go +++ b/table_windows.go @@ -72,8 +72,7 @@ func (t *table) Unlock() { func (t *table) Selected() int { t.RLock() defer t.RUnlock() -//TODO return int(C.tableSelectedItem(t.hwnd)) - return -1 + return int(C.tableSelectedItem(t.hwnd)) } func (t *table) Select(index int) { diff --git a/winapi_windows.h b/winapi_windows.h index b2b883d..28104be 100644 --- a/winapi_windows.h +++ b/winapi_windows.h @@ -113,7 +113,9 @@ extern void setTableSubclass(HWND, void *); extern void gotableSetRowCount(HWND, intptr_t); /* TODO extern void tableAutosizeColumns(HWND, int); +*/ extern intptr_t tableSelectedItem(HWND); +/* TODO extern void tableSelectItem(HWND, intptr_t); */ diff --git a/wintable/api.h b/wintable/api.h index 04c7561..78bf514 100644 --- a/wintable/api.h +++ b/wintable/api.h @@ -63,6 +63,15 @@ HANDLER(apiHandlers) setRowCount(t, *rcp); *lResult = 0; return TRUE; + case tableGetSelection: + rcp = (intptr_t *) wParam; + if (rcp != NULL) + *rcp = t->selectedRow; + rcp = (intptr_t *) lParam; + if (rcp != NULL) + *rcp = t->selectedColumn; + *lResult = 0; + return TRUE; } return FALSE; } diff --git a/wintable/includethis.h b/wintable/includethis.h index 4c7ee2a..f40c6f3 100644 --- a/wintable/includethis.h +++ b/wintable/includethis.h @@ -14,6 +14,11 @@ enum { // wParam - 0 // lParam - pointer to intptr_t containing new count tableSetRowCount, + // wParam - pointer to intptr_t where selected row will be stored + // lParam - pointer to intptr_t where selected column will be stored + // both will be -1 for no selection + // if either is NULL, that value is not written + tableGetSelection, }; enum {