为string类型添加size成员

This commit is contained in:
gb 2023-09-18 15:59:52 +08:00
parent 9a2ff90875
commit fd93c1b594
5 changed files with 43 additions and 3 deletions

View File

@ -274,7 +274,7 @@ known_file_util::IJsonW* CDlgOptJson::SANEOPT::to_json(void)
jsn->set_value(L"visible", open); jsn->set_value(L"visible", open);
if(!enable) if(!enable)
jsn->set_value(L"enabled", enable); jsn->set_value(L"enabled", enable);
jsn->set_value(L"size", (int)sizeof(int)); jsn->set_value(L"size", size);
if (!auto_restore_default) if (!auto_restore_default)
jsn->set_value(L"auto", auto_restore_default); jsn->set_value(L"auto", auto_restore_default);
@ -412,7 +412,7 @@ known_file_util::IJsonW* CDlgOptJson::SANEOPT::to_json(void)
{ {
known_file_util::IJsonW* rng = NULL; known_file_util::IJsonW* rng = NULL;
jsn->set_value(L"size", (int)sizeof(double)); //jsn->set_value(L"size", (int)sizeof(double));
if (def_val.size() == 1) if (def_val.size() == 1)
{ {
jsn->set_value(L"cur", *(double*)def_val[0].val.c_str()); jsn->set_value(L"cur", *(double*)def_val[0].val.c_str());
@ -568,7 +568,7 @@ known_file_util::IJsonW* CDlgOptJson::SANEOPT::to_json(void)
} }
len += 4; len += 4;
len *= 3; len *= 3;
jsn->set_value(L"size", len); //jsn->set_value(L"size", len);
} }
if (!depend.empty()) if (!depend.empty())
@ -610,6 +610,8 @@ bool CDlgOptJson::SANEOPT::from_json(known_file_util::IJsonW* jsn)
type = strv; type = strv;
std::transform(type.begin(), type.end(), type.begin(), tolower); std::transform(type.begin(), type.end(), type.begin(), tolower);
jsn->get_value(L"size", size);
if (type == L"bool") if (type == L"bool")
{ {
bool v = false; bool v = false;
@ -1134,6 +1136,7 @@ void CDlgOptJson::from_ui(SANEOPT& sop)
val = get_item_text(IDC_EDIT_DEFAULT); val = get_item_text(IDC_EDIT_DEFAULT);
else else
val = get_item_text(IDC_COMBO_DEFAULT); val = get_item_text(IDC_COMBO_DEFAULT);
sop.size = GetDlgItemInt(IDC_EDIT_SIZE);
sop.def_val.clear(); // FIXED me to support multi-value!!! sop.def_val.clear(); // FIXED me to support multi-value!!!
if (sop.type == L"bool") if (sop.type == L"bool")
@ -1184,6 +1187,7 @@ void CDlgOptJson::to_ui(const SANEOPT& sop)
::SetDlgItemTextW(m_hWnd, IDC_EDIT_NAME, sop.name.c_str()); ::SetDlgItemTextW(m_hWnd, IDC_EDIT_NAME, sop.name.c_str());
::SetDlgItemTextW(m_hWnd, IDC_EDIT_TITLE, sop.title.c_str()); ::SetDlgItemTextW(m_hWnd, IDC_EDIT_TITLE, sop.title.c_str());
::SetDlgItemTextW(m_hWnd, IDC_EDIT_DESCRIPTION, sop.desc.c_str()); ::SetDlgItemTextW(m_hWnd, IDC_EDIT_DESCRIPTION, sop.desc.c_str());
SetDlgItemInt(IDC_EDIT_SIZE, sop.size);
n = group_.FindStringExact(-1, sop.group.c_str()); n = group_.FindStringExact(-1, sop.group.c_str());
if (n == -1) if (n == -1)
@ -1703,6 +1707,32 @@ void CDlgOptJson::OnCbnDataTypeSelchange()
OnCbnRangeSelchange(); OnCbnRangeSelchange();
range_.EnableWindow(FALSE); range_.EnableWindow(FALSE);
} }
if (val == L"bool" || val == L"int")
{
SetDlgItemInt(IDC_EDIT_SIZE, sizeof(int));
GetDlgItem(IDC_EDIT_SIZE)->EnableWindow(FALSE);
}
else if (val == L"float")
{
SetDlgItemInt(IDC_EDIT_SIZE, sizeof(double));
GetDlgItem(IDC_EDIT_SIZE)->EnableWindow(FALSE);
}
else // if (val == L"string")
{
int size = val == L"string" ? 16 : 4;
std::wstring n(get_item_text(IDC_EDIT_NAME));
for (auto& v : opts_)
{
if (v.name == n)
{
size = v.size;
break;
}
}
SetDlgItemInt(IDC_EDIT_SIZE, size);
GetDlgItem(IDC_EDIT_SIZE)->EnableWindow(TRUE);
}
} }
void CDlgOptJson::OnCbnRangeSelchange() void CDlgOptJson::OnCbnRangeSelchange()
{ {
@ -2373,11 +2403,14 @@ void CDlgOptJson::OnBnClickedButtonSet()
} }
else else
{ {
int len = 0;
for (auto& v : opt.def_val) for (auto& v : opt.def_val)
{ {
CDlgRange::CONDVAL cv; CDlgRange::CONDVAL cv;
cv.cond = local_trans::a2u(v.cond.c_str(), CP_UTF8); cv.cond = local_trans::a2u(v.cond.c_str(), CP_UTF8);
cv.val = (const wchar_t*)v.val.c_str(); cv.val = (const wchar_t*)v.val.c_str();
if (len < cv.val.length())
len = cv.val.length();
dlg.init_.push_back(cv); dlg.init_.push_back(cv);
} }
@ -2386,8 +2419,14 @@ void CDlgOptJson::OnBnClickedButtonSet()
CDlgRange::CONDVAL cv; CDlgRange::CONDVAL cv;
cv.cond = local_trans::a2u(v.cond.c_str(), CP_UTF8); cv.cond = local_trans::a2u(v.cond.c_str(), CP_UTF8);
cv.val = (const wchar_t*)v.val.c_str(); cv.val = (const wchar_t*)v.val.c_str();
if (len < cv.val.length())
len = cv.val.length();
dlg.vals_.push_back(cv); dlg.vals_.push_back(cv);
} }
len += 4;
len *= 3;
SetDlgItemInt(IDC_EDIT_SIZE, len);
} }
} }

View File

@ -89,6 +89,7 @@ public:
std::vector<CONDVAL> range; std::vector<CONDVAL> range;
std::wstring depend; std::wstring depend;
int size;
int ver; int ver;
int pos; int pos;
int fix_id; int fix_id;

Binary file not shown.

Binary file not shown.

Binary file not shown.