From f96c0f410ee8294dd66fa42b924b1458b75c8186 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 16 Jun 2018 13:06:20 -0400 Subject: [PATCH] Started the implementation of progressbar columns. This handles LVN_GETDISPINFO. --- windows/table.cpp | 5 +++- windows/tabledispinfo.cpp | 53 ++++++++++++++++++++++++++------------- 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/windows/table.cpp b/windows/table.cpp index 89276fee..b3409907 100644 --- a/windows/table.cpp +++ b/windows/table.cpp @@ -230,7 +230,10 @@ void uiTableAppendCheckboxTextColumn(uiTable *t, const char *name, int checkboxM 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) diff --git a/windows/tabledispinfo.cpp b/windows/tabledispinfo.cpp index 9912bebf..2e8a06e2 100644 --- a/windows/tabledispinfo.cpp +++ b/windows/tabledispinfo.cpp @@ -6,28 +6,47 @@ static HRESULT handleLVIF_TEXT(uiTable *t, NMLVDISPINFOW *nm, uiprivTableColumnP { uiTableData *data; WCHAR *wstr; + int progress; HRESULT hr; if ((nm->item.mask & LVIF_TEXT) == 0) 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); - wstr = toUTF16(uiTableDataString(data)); - uiFreeTableData(data); - // We *could* just make pszText into a freshly allocated - // conversion and avoid the limitation of cchTextMax. - // But then, we would have to keep things around for some - // amount of time (some pages on MSDN say 2 additional - // LVN_GETDISPINFO messages). And in practice, anything - // that results in extra LVN_GETDISPINFO messages (such as - // LVN_GETITEMRECT with LVIR_LABEL) will break this - // counting. - // 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) - wcsncpy(nm->item.pszText, wstr, nm->item.cchTextMax); - nm->item.pszText[nm->item.cchTextMax - 1] = L'\0'; - uiprivFree(wstr); + if (p->textModelColumn != -1) { + data = (*(t->model->mh->CellValue))(t->model->mh, t->model, nm->item.iItem, p->textModelColumn); + wstr = toUTF16(uiTableDataString(data)); + uiFreeTableData(data); + // We *could* just make pszText into a freshly allocated + // conversion and avoid the limitation of cchTextMax. + // But then, we would have to keep things around for some + // amount of time (some pages on MSDN say 2 additional + // LVN_GETDISPINFO messages). And in practice, anything + // that results in extra LVN_GETDISPINFO messages (such + // as LVN_GETITEMRECT with LVIR_LABEL) will break this + // counting. + // 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) + wcsncpy(nm->item.pszText, wstr, nm->item.cchTextMax); + 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; }