diff --git a/windows/CMakeLists.txt b/windows/CMakeLists.txt index 5a15459c..c1747c50 100644 --- a/windows/CMakeLists.txt +++ b/windows/CMakeLists.txt @@ -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 diff --git a/windows/table.cpp b/windows/table.cpp index 42dd57d7..4dd1370d 100644 --- a/windows/table.cpp +++ b/windows/table.cpp @@ -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; } diff --git a/windows/table.hpp b/windows/table.hpp index bf55ef6f..30bea161 100644 --- a/windows/table.hpp +++ b/windows/table.hpp @@ -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); diff --git a/windows/tableevents.cpp b/windows/tableevents.cpp new file mode 100644 index 00000000..eae3a096 --- /dev/null +++ b/windows/tableevents.cpp @@ -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; +}