老界面支持动态刷新属性

This commit is contained in:
gb 2023-06-17 15:47:56 +08:00
parent e1095bef0e
commit e23b1b6890
1 changed files with 73 additions and 2 deletions

View File

@ -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;