From 924352d76a2bdc54415c18246a57bf29322f7344 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 19 Feb 2015 23:25:51 -0500 Subject: [PATCH] Added tableSetSelection to the new Windows Table and hooked it up to the package ui Table. --- table_windows.c | 26 +------------------------- table_windows.go | 2 +- winapi_windows.h | 2 -- wintable/api.h | 15 +++++++++++++++ wintable/includethis.h | 6 ++++++ 5 files changed, 23 insertions(+), 28 deletions(-) diff --git a/table_windows.c b/table_windows.c index 8b352d7..92c58e5 100644 --- a/table_windows.c +++ b/table_windows.c @@ -82,31 +82,7 @@ intptr_t tableSelectedItem(HWND hwnd) return row; } -/* -TODO 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()); - } - if (index == -1) // select nothing - return; - 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()); + SendMessageW(hwnd, tableSetSelection, (WPARAM) (&index), (LPARAM) NULL); } -*/ diff --git a/table_windows.go b/table_windows.go index ceca0eb..8cd28c5 100644 --- a/table_windows.go +++ b/table_windows.go @@ -78,7 +78,7 @@ func (t *table) Selected() int { func (t *table) Select(index int) { t.RLock() defer t.RUnlock() -//TODO C.tableSelectItem(t.hwnd, C.intptr_t(index)) + C.tableSelectItem(t.hwnd, C.intptr_t(index)) } func (t *table) OnSelected(f func()) { diff --git a/winapi_windows.h b/winapi_windows.h index 28104be..ddb0bb3 100644 --- a/winapi_windows.h +++ b/winapi_windows.h @@ -115,9 +115,7 @@ extern void gotableSetRowCount(HWND, intptr_t); extern void tableAutosizeColumns(HWND, int); */ extern intptr_t tableSelectedItem(HWND); -/* TODO extern void tableSelectItem(HWND, intptr_t); -*/ // container_windows.c extern RECT containerBounds(HWND); diff --git a/wintable/api.h b/wintable/api.h index 78bf514..5016710 100644 --- a/wintable/api.h +++ b/wintable/api.h @@ -38,6 +38,7 @@ static void setRowCount(struct table *t, intptr_t rc) HANDLER(apiHandlers) { intptr_t *rcp; + intptr_t row; switch (uMsg) { case WM_SETFONT: @@ -72,6 +73,20 @@ HANDLER(apiHandlers) *rcp = t->selectedColumn; *lResult = 0; return TRUE; + case tableSetSelection: + // TODO does doselect() do validation? + rcp = (intptr_t *) wParam; + row = *rcp; + rcp = (intptr_t *) lParam; + if (rcp == NULL) + if (row == -1) + doselect(t, -1, -1); + else // select column 0, just like keyboard selections; TODO what if there aren't any columns? + doselect(t, row, 0); + else + doselect(t, row, *rcp); + *lResult = 0; + return TRUE; } return FALSE; } diff --git a/wintable/includethis.h b/wintable/includethis.h index f40c6f3..422b101 100644 --- a/wintable/includethis.h +++ b/wintable/includethis.h @@ -19,6 +19,12 @@ enum { // both will be -1 for no selection // if either is NULL, that value is not written tableGetSelection, + // wParam - pointer to intptr_t containing selected row + // lParam - pointer to intptr_t containing selected column + // if lParam is NULL, do not change selected column (selects column 0 if nothing previously selected; TODO explicitly document this?) + // TODO allow wParam to be NULL too; should both being NULL select nothing or keep the current selection? + // this WILL result in a selection changed notification (TODO work into the package ui Table) + tableSetSelection, }; enum {