diff --git a/sane/DlgPage.cpp b/sane/DlgPage.cpp index b8f2912..6a58247 100644 --- a/sane/DlgPage.cpp +++ b/sane/DlgPage.cpp @@ -1687,7 +1687,8 @@ void dlg_page::hide(void) bool dlg_page::refresh(int sn, const SANE_Option_Descriptor* desc, void* cur_val) { bool found = false; - int ind = 0; + int ind = 0, text_ind = 0; + wchar_t cls_name[40] = { 0 }; sn += dlg_page::dyn_id_base; for (; ind < (int)ctrls_.size(); ++ind) @@ -1703,9 +1704,79 @@ bool dlg_page::refresh(int sn, const SANE_Option_Descriptor* desc, void* cur_val { if (GetWindowLong(ctrls_[ind], GWL_ID) != sn) break; + + HWND host = ctrls_[ind]; + GetClassNameW(host, cls_name, _countof(cls_name) - 1); + if (IS_COMBOX(cls_name)) + { + if (desc->constraint_type == SANE_CONSTRAINT_STRING_LIST) + { + SendMessage(host, CB_RESETCONTENT, 0, 0); + for (int i = 0; desc->constraint.string_list[i]; ++i) + { + std::wstring text(local_trans::a2u(desc->constraint.string_list[i], CP_UTF8)); + SendMessageW(host, CB_ADDSTRING, 0, (LPARAM)text.c_str()); + } + } + else if (desc->constraint_type == SANE_CONSTRAINT_WORD_LIST) + { + SendMessage(host, CB_RESETCONTENT, 0, 0); + for (int i = 0; i < desc->constraint.word_list[0]; ++i) + { + SendMessageW(host, CB_ADDSTRING, 0, (LPARAM)std::to_wstring(desc->constraint.word_list[1 + i]).c_str()); + } + } + } + else if (IS_TRACKBAR(cls_name)) + { + if (desc->constraint_type == SANE_CONSTRAINT_RANGE) + { + if (desc->type == SANE_TYPE_FIXED) + { + double lower = SANE_UNFIX(desc->constraint.range->min), + upper = SANE_UNFIX(desc->constraint.range->max); + SendMessage(host, TBM_SETRANGEMIN, 1, (LPARAM)int(lower * 100.0f + .5f)); + SendMessage(host, TBM_SETRANGEMAX, 1, (LPARAM)int(upper * 100.0f + .5f)); + } + else + { + int lower = desc->constraint.range->min, + upper = desc->constraint.range->max; + SendMessage(host, TBM_SETRANGEMIN, 1, (LPARAM)int(lower * 1.0f + .5f)); + SendMessage(host, TBM_SETRANGEMAX, 1, (LPARAM)int(upper * 1.0f + .5f)); + } + + } + } + else if (IS_STATIC_TEXT(cls_name)) + { + if (desc->constraint_type == SANE_CONSTRAINT_RANGE) + { + if (text_ind == 1) + { + wchar_t t[20] = { 0 }; + if (desc->type == SANE_TYPE_FIXED) + swprintf_s(t, _countof(t) - 1, L"%.2f", SANE_UNFIX(desc->constraint.range->min)); + else + swprintf_s(t, _countof(t) - 1, L"%d", desc->constraint.range->min); + SetWindowTextW(host, t); + } + else if(text_ind == 2) + { + wchar_t t[20] = { 0 }; + if (desc->type == SANE_TYPE_FIXED) + swprintf_s(t, _countof(t) - 1, L"%.2f", SANE_UNFIX(desc->constraint.range->max)); + else + swprintf_s(t, _countof(t) - 1, L"%d", desc->constraint.range->max); + SetWindowTextW(host, t); + } + } + text_ind++; + } + set_ctrl_value(ctrls_[ind], desc->type, cur_val, true); EnableWindow(ctrls_[ind], (desc->cap & SANE_CAP_INACTIVE) != SANE_CAP_INACTIVE); - HWND host = (HWND)GetPropW(ctrls_[ind], dlg_page::property_host.c_str()); + host = (HWND)GetPropW(ctrls_[ind], dlg_page::property_host.c_str()); if (IsWindow(host)) { BOOL checked = SendMessage(host, BM_GETCHECK, 0, 0) == BST_CHECKED;