Started the implementation of progressbar columns. This handles LVN_GETDISPINFO.

This commit is contained in:
Pietro Gagliardi 2018-06-16 13:06:20 -04:00
parent d63af885ba
commit f96c0f410e
2 changed files with 40 additions and 18 deletions

View File

@ -230,7 +230,10 @@ void uiTableAppendCheckboxTextColumn(uiTable *t, const char *name, int checkboxM
void uiTableAppendProgressBarColumn(uiTable *t, const char *name, int progressModelColumn) void uiTableAppendProgressBarColumn(uiTable *t, const char *name, int progressModelColumn)
{ {
// TODO uiprivTableColumnParams *p;
p = appendColumn(t, name, LVCFMT_LEFT);
p->progressBarModelColumn = progressModelColumn;
} }
void uiTableAppendButtonColumn(uiTable *t, const char *name, int buttonTextModelColumn, int buttonClickableModelColumn) void uiTableAppendButtonColumn(uiTable *t, const char *name, int buttonTextModelColumn, int buttonClickableModelColumn)

View File

@ -6,28 +6,47 @@ static HRESULT handleLVIF_TEXT(uiTable *t, NMLVDISPINFOW *nm, uiprivTableColumnP
{ {
uiTableData *data; uiTableData *data;
WCHAR *wstr; WCHAR *wstr;
int progress;
HRESULT hr; HRESULT hr;
if ((nm->item.mask & LVIF_TEXT) == 0) if ((nm->item.mask & LVIF_TEXT) == 0)
return S_OK; return S_OK;
if (p->textModelColumn == -1)
return S_OK;
data = (*(t->model->mh->CellValue))(t->model->mh, t->model, nm->item.iItem, p->textModelColumn); if (p->textModelColumn != -1) {
wstr = toUTF16(uiTableDataString(data)); data = (*(t->model->mh->CellValue))(t->model->mh, t->model, nm->item.iItem, p->textModelColumn);
uiFreeTableData(data); wstr = toUTF16(uiTableDataString(data));
// We *could* just make pszText into a freshly allocated uiFreeTableData(data);
// conversion and avoid the limitation of cchTextMax. // We *could* just make pszText into a freshly allocated
// But then, we would have to keep things around for some // conversion and avoid the limitation of cchTextMax.
// amount of time (some pages on MSDN say 2 additional // But then, we would have to keep things around for some
// LVN_GETDISPINFO messages). And in practice, anything // amount of time (some pages on MSDN say 2 additional
// that results in extra LVN_GETDISPINFO messages (such as // LVN_GETDISPINFO messages). And in practice, anything
// LVN_GETITEMRECT with LVIR_LABEL) will break this // that results in extra LVN_GETDISPINFO messages (such
// counting. // as LVN_GETITEMRECT with LVIR_LABEL) will break this
// TODO make it so we don't have to make a copy; instead we can convert directly into pszText (this will also avoid the risk of having a dangling surrogate pair at the end) // counting.
wcsncpy(nm->item.pszText, wstr, nm->item.cchTextMax); // TODO make it so we don't have to make a copy; instead we can convert directly into pszText (this will also avoid the risk of having a dangling surrogate pair at the end)
nm->item.pszText[nm->item.cchTextMax - 1] = L'\0'; wcsncpy(nm->item.pszText, wstr, nm->item.cchTextMax);
uiprivFree(wstr); nm->item.pszText[nm->item.cchTextMax - 1] = L'\0';
uiprivFree(wstr);
return S_OK;
}
if (p->progressBarModelColumn != -1) {
data = (*(t->model->mh->CellValue))(t->model->mh, t->model, nm->item.iItem, p->progressBarModelColumn);
progress = uiTableDataInt(data);
uiFreeTableData(data);
if (progress == -1) {
// TODO either localize this or replace it with something that's language-neutral
// TODO ensure null terminator
wcsncpy(nm->item.pszText, L"Indeterminate", nm->item.cchTextMax);
return S_OK;
}
// TODO ensure null terminator
_snwprintf(nm->item.pszText, nm->item.cchTextMax, L"%d%%", progress);
return S_OK;
}
return S_OK; return S_OK;
} }