Added tableSetSelection to the new Windows Table and hooked it up to the package ui Table.

This commit is contained in:
Pietro Gagliardi 2015-02-19 23:25:51 -05:00
parent cab2d93449
commit 924352d76a
5 changed files with 23 additions and 28 deletions

View File

@ -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);
}
*/

View File

@ -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()) {

View File

@ -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);

View File

@ -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;
}

View File

@ -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 {