Added code for detecting that text is to be edited. Now for actually implementing editing text.

This commit is contained in:
Pietro Gagliardi 2018-06-17 15:06:45 -04:00
parent 6d0b276d6d
commit 799c613a6f
3 changed files with 47 additions and 3 deletions

View File

@ -83,9 +83,16 @@ void uiTableModelRowDeleted(uiTableModel *m, int oldIndex)
static LRESULT CALLBACK tableSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIDSubclass, DWORD_PTR dwRefData)
{
uiTable *t = (uiTable *) dwRefData;
LRESULT lResult;
switch (uMsg) {
case WM_TIMER:
if (wParam == (WPARAM) (&(t->inDoubleClickTimer))) {
t->inDoubleClickTimer = FALSE;
// TODO check errors
KillTimer(hwnd, wParam);
return 0;
}
if (wParam != (WPARAM) t)
break;
// TODO only increment and update if visible?
@ -95,6 +102,11 @@ static LRESULT CALLBACK tableSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
SendMessageW(hwnd, LVM_UPDATE, (WPARAM) (i.first.first), 0);
}
return 0;
case WM_LBUTTONDOWN:
t->inLButtonDown = TRUE;
lResult = DefSubclassProc(hwnd, uMsg, wParam, lParam);
t->inLButtonDown = FALSE;
return lResult;
case WM_NCDESTROY:
if (RemoveWindowSubclass(hwnd, tableSubProc, uIDSubclass) == FALSE)
logLastError(L"RemoveWindowSubclass()");
@ -192,6 +204,25 @@ static BOOL onWM_NOTIFY(uiControl *c, HWND hwnd, NMHDR *nmhdr, LRESULT *lResult)
}
return TRUE;
#endif
case LVN_ITEMCHANGED:
{
NMLISTVIEW *nm = (NMLISTVIEW *) nmhdr;
UINT oldSelected, newSelected;
if (!t->inLButtonDown)
return FALSE;
oldSelected = nm->uOldState & LVIS_SELECTED;
newSelected = nm->uNewState & LVIS_SELECTED;
if (oldSelected == 0 && newSelected != 0) {
t->inDoubleClickTimer = TRUE;
// TODO check error
SetTimer(t->hwnd, (UINT_PTR) (&(t->inDoubleClickTimer)),
GetDoubleClickTime(), NULL);
*lResult = 0;
return TRUE;
}
return FALSE;
}
}
return FALSE;
}

View File

@ -33,6 +33,8 @@ struct uiTable {
HIMAGELIST imagelist;
// TODO document all this
std::map<std::pair<int, int>, LONG> *indeterminatePositions;
BOOL inLButtonDown;
BOOL inDoubleClickTimer;
};
extern int uiprivTableProgress(uiTable *t, int item, int subitem, int modelColumn, LONG *pos);

View File

@ -7,7 +7,7 @@ HRESULT uiprivTableHandleNM_CLICK(uiTable *t, NMITEMACTIVATE *nm, LRESULT *lResu
LVHITTESTINFO ht;
uiprivTableColumnParams *p;
int modelColumn, editableColumn;
bool checkbox;
bool text, checkbox;
uiTableData *data;
int checked, editable;
@ -18,9 +18,14 @@ HRESULT uiprivTableHandleNM_CLICK(uiTable *t, NMITEMACTIVATE *nm, LRESULT *lResu
modelColumn = -1;
editableColumn = -1;
text = false;
checkbox = false;
p = (*(t->columns))[ht.iSubItem];
if (p->checkboxModelColumn != -1) {
if (p->textModelColumn != -1) {
modelColumn = p->textModelColumn;
editableColumn = p->textEditableColumn;
text = true;
} else if (p->checkboxModelColumn != -1) {
modelColumn = p->checkboxModelColumn;
editableColumn = p->checkboxEditableColumn;
checkbox = true;
@ -31,6 +36,10 @@ HRESULT uiprivTableHandleNM_CLICK(uiTable *t, NMITEMACTIVATE *nm, LRESULT *lResu
if (modelColumn == -1)
goto done;
if (text && t->inDoubleClickTimer)
// don't even ask for info if it's too soon to edit text
goto done;
switch (editableColumn) {
case uiTableModelColumnNeverEditable:
goto done;
@ -44,7 +53,9 @@ HRESULT uiprivTableHandleNM_CLICK(uiTable *t, NMITEMACTIVATE *nm, LRESULT *lResu
goto done;
}
if (checkbox) {
if (text) {
MessageBoxW(NULL, L"editing text", L"ok", MB_OK);
} else if (checkbox) {
if ((ht.flags & LVHT_ONITEMICON) == 0)
goto done;
data = (*(t->model->mh->CellValue))(t->model->mh, t->model, ht.iItem, modelColumn);