Started handling table events. This covers checkboxes and buttons.

This commit is contained in:
Pietro Gagliardi 2018-06-17 11:48:39 -04:00
parent 2fb3676a8f
commit 6d0b276d6d
4 changed files with 80 additions and 3 deletions

View File

@ -53,6 +53,7 @@ list(APPEND _LIBUI_SOURCES
windows/table.cpp
windows/tabledispinfo.cpp
windows/tabledraw.cpp
windows/tableevents.cpp
windows/tabpage.cpp
windows/text.cpp
windows/utf16.cpp

View File

@ -166,7 +166,7 @@ static BOOL onWM_NOTIFY(uiControl *c, HWND hwnd, NMHDR *nmhdr, LRESULT *lResult)
}
return TRUE;
case NM_CLICK:
#if 1
#if 0
{
NMITEMACTIVATE *nm = (NMITEMACTIVATE *) nmhdr;
LVHITTESTINFO ht;
@ -182,10 +182,16 @@ static BOOL onWM_NOTIFY(uiControl *c, HWND hwnd, NMHDR *nmhdr, LRESULT *lResult)
MessageBoxW(GetAncestor(t->hwnd, GA_ROOT), buf, buf, MB_OK);
}
}
#else
#endif
*lResult = 0;
return TRUE;
#else
hr = uiprivTableHandleNM_CLICK(t, (NMITEMACTIVATE *) nmhdr, lResult);
if (hr != S_OK) {
// TODO
return FALSE;
}
return TRUE;
#endif
}
return FALSE;
}

View File

@ -42,3 +42,6 @@ extern HRESULT uiprivTableHandleLVN_GETDISPINFO(uiTable *t, NMLVDISPINFOW *nm, L
// tabledraw.cpp
extern HRESULT uiprivTableHandleNM_CUSTOMDRAW(uiTable *t, NMLVCUSTOMDRAW *nm, LRESULT *lResult);
extern HRESULT uiprivUpdateImageListSize(uiTable *t);
// tableevents.cpp
extern HRESULT uiprivTableHandleNM_CLICK(uiTable *t, NMITEMACTIVATE *nm, LRESULT *lResult);

67
windows/tableevents.cpp Normal file
View File

@ -0,0 +1,67 @@
// 17 june 2018
#include "uipriv_windows.hpp"
#include "table.hpp"
HRESULT uiprivTableHandleNM_CLICK(uiTable *t, NMITEMACTIVATE *nm, LRESULT *lResult)
{
LVHITTESTINFO ht;
uiprivTableColumnParams *p;
int modelColumn, editableColumn;
bool checkbox;
uiTableData *data;
int checked, editable;
ZeroMemory(&ht, sizeof (LVHITTESTINFO));
ht.pt = nm->ptAction;
if (SendMessageW(t->hwnd, LVM_SUBITEMHITTEST, 0, (LPARAM) (&ht)) == (LRESULT) (-1))
goto done;
modelColumn = -1;
editableColumn = -1;
checkbox = false;
p = (*(t->columns))[ht.iSubItem];
if (p->checkboxModelColumn != -1) {
modelColumn = p->checkboxModelColumn;
editableColumn = p->checkboxEditableColumn;
checkbox = true;
} else if (p->buttonModelColumn != -1) {
modelColumn = p->buttonModelColumn;
editableColumn = p->buttonClickableModelColumn;
}
if (modelColumn == -1)
goto done;
switch (editableColumn) {
case uiTableModelColumnNeverEditable:
goto done;
case uiTableModelColumnAlwaysEditable:
break;
default:
data = (*(t->model->mh->CellValue))(t->model->mh, t->model, ht.iItem, editableColumn);
editable = uiTableDataInt(data);
uiFreeTableData(data);
if (!editable)
goto done;
}
if (checkbox) {
if ((ht.flags & LVHT_ONITEMICON) == 0)
goto done;
data = (*(t->model->mh->CellValue))(t->model->mh, t->model, ht.iItem, modelColumn);
checked = uiTableDataInt(data);
uiFreeTableData(data);
data = uiNewTableDataInt(!checked);
(*(t->model->mh->SetCellValue))(t->model->mh, t->model, ht.iItem, modelColumn, data);
uiFreeTableData(data);
} else
(*(t->model->mh->SetCellValue))(t->model->mh, t->model, ht.iItem, modelColumn, NULL);
// always refresh the value in case the model rejected it
if (SendMessageW(t->hwnd, LVM_UPDATE, (WPARAM) (ht.iItem), 0) == (LRESULT) (-1)) {
logLastError(L"LVM_UPDATE");
return E_FAIL;
}
done:
*lResult = 0;
return S_OK;
}