界面增加值域检查

This commit is contained in:
gb 2023-09-14 14:52:02 +08:00
parent ad99d84053
commit d08bfdbc3c
2 changed files with 101 additions and 2 deletions

View File

@ -223,7 +223,7 @@ namespace known_name
IMPLEMENT_DYNAMIC(CDlgOptJson, CDialogEx)
CDlgOptJson::CDlgOptJson(CWnd* pParent /*=NULL*/)
: CDialogEx(CDlgOptJson::IDD, pParent)
: CDialogEx(CDlgOptJson::IDD, pParent), tooltips_(NULL)
{
//_CrtSetBreakAlloc(350252);
}
@ -232,6 +232,7 @@ CDlgOptJson::~CDlgOptJson()
{
delete_from_tree();
lang_initialize((void*)0xde1e);
delete tooltips_;
}
known_file_util::IJsonW* CDlgOptJson::SANEOPT::to_json(void)
@ -1075,7 +1076,7 @@ std::wstring CDlgOptJson::get_json_text(const wchar_t* tab)
void CDlgOptJson::from_ui(SANEOPT& sop)
{
std::wstring val(L"");
sop.name = get_item_text(IDC_EDIT_NAME);
sop.title = get_item_text(IDC_EDIT_TITLE);
sop.desc = get_item_text(IDC_EDIT_DESCRIPTION);
@ -1321,6 +1322,44 @@ HTREEITEM CDlgOptJson::insert_new_item(const SANEOPT& opt, bool sel)
if (opt.name == L"global")
return NULL;
int fid = known_name::name_to_fix_id(opt.name.c_str());
if (fid && fid != opt.fix_id)
{
std::wstring text(L"fix-id与固有的ID值");
wchar_t buf[40] = { 0 };
swprintf_s(buf, _countof(buf) - 1, L" 0x%04X ", fid);
text += buf;
text += L"不相同。";
::MessageBoxW(m_hWnd, text.c_str(), NULL, MB_OK);
GotoDlgCtrl(GetDlgItem(IDC_EDIT_FIXED_ID));
return NULL;
}
if (opt.fix_id)
{
for (auto& v : opts_)
{
if (v.fix_id == opt.fix_id)
{
wchar_t info[128] = { 0 };
swprintf_s(info, _countof(info) - 1, L"Fix-ID 与现有属性“%s”冲突", v.title.c_str());
::MessageBoxW(m_hWnd, info, NULL, MB_OK);
GotoDlgCtrl(GetDlgItem(IDC_EDIT_FIXED_ID));
return NULL;
}
else if (v.category == opt.category && v.category == L"图像处理" && v.pos == opt.pos)
{
wchar_t info[128] = { 0 };
swprintf_s(info, _countof(info) - 1, L"Position 与现有属性“%s”冲突", v.title.c_str());
::MessageBoxW(m_hWnd, info, NULL, MB_OK);
GotoDlgCtrl(GetDlgItem(IDC_EDIT_POSITION));
return NULL;
}
}
}
HTREEITEM item = tree_.InsertItem(opt.title.c_str());
wchar_t* name = new wchar_t[opt.name.length() + 2];
@ -1559,6 +1598,15 @@ BOOL CDlgOptJson::OnInitDialog()
export_type_.SetCurSel(1);
tooltips_ = new tooltip_wnd();
tooltips_->create(m_hWnd);
tooltips_->add_tool_tip_for_ctrl(::GetDlgItem(m_hWnd, IDC_CHECK_AUTO_RESTORE), L"\u662F\u5426\u652F\u6301\u6062\u590D\u5230\u9ED8\u8BA4\u503C\u7684\u64CD\u4F5C");
tooltips_->add_tool_tip_for_ctrl(::GetDlgItem(m_hWnd, IDC_CHECK_PUBLIC), L"\u662F\u5426\u5BF9\u666E\u901A\u7528\u6237\u5F00\u653E");
tooltips_->add_tool_tip_for_ctrl(::GetDlgItem(m_hWnd, IDC_COMBO_CATEGORY), L"\u5C5E\u6027\u5206\u7C7B\u3002\u5982\u679C\u4E3A\u56FE\u50CF\u5206\u7C7B\uFF0C\u4F1A\u6309\u7167\u201Cposition\u201D\u503C\u6392\u5E8F\uFF0C\u4EE5\u786E\u5B9A\u6267\u884C\u7684\u5148\u540E\u987A\u5E8F");
tooltips_->add_tool_tip_for_ctrl(::GetDlgItem(m_hWnd, IDC_EDIT_POSITION), L"\u8BE5\u5C5E\u6027\u5728\u6307\u5B9A\u5206\u7C7B\u4E2D\u7684\u6267\u884C\u987A\u5E8F");
tooltips_->add_tool_tip_for_ctrl(::GetDlgItem(m_hWnd, IDC_EDIT_FIXED_ID), L"\u63D0\u4F9B\u8BE5\u503C\uFF0C\u8BE5\u5C5E\u6027\u5373\u53EF\u88ABTWAIN\u534F\u8BAE\u4FA6\u6D4B\u5230");
tooltips_->add_tool_tip_for_ctrl(::GetDlgItem(m_hWnd, IDC_COMBO_GROUP), L"\u8BE5\u5C5E\u6027\u5728\u754C\u9762\u4E0A\u663E\u793A\u65F6\uFF0C\u6240\u5F52\u5C5E\u7684\u5206\u7EC4\u540D\u79F0");
return TRUE; // return TRUE unless you set the focus to a control
}
@ -1901,6 +1949,13 @@ void CDlgOptJson::OnBnClickedButtonModify()
SANEOPT sop;
from_ui(sop);
if (sop.fix_id > 0 && sop.fix_id < 0x8800)
{
::MessageBoxW(m_hWnd, L"Fix-ID 请指定“0x8800”以上的值", NULL, MB_OK);
GotoDlgCtrl(GetDlgItem(IDC_EDIT_FIXED_ID));
return;
}
if (sop.name.empty() || sop.title.empty())
{
MessageBox(TEXT("Name and Title must input!"));
@ -1920,6 +1975,47 @@ void CDlgOptJson::OnBnClickedButtonModify()
}
}
int fid = known_name::name_to_fix_id(sop.name.c_str());
if (fid && fid != sop.fix_id)
{
std::wstring text(L"fix-id与固有的ID值");
wchar_t buf[40] = { 0 };
swprintf_s(buf, _countof(buf) - 1, L" 0x%04X ", fid);
text += buf;
text += L"不相同。";
::MessageBoxW(m_hWnd, text.c_str(), NULL, MB_OK);
GotoDlgCtrl(GetDlgItem(IDC_EDIT_FIXED_ID));
return;
}
if (sop.fix_id)
{
for (auto& v : opts_)
{
if (v.fix_id == sop.fix_id)
{
if (v.name != sop.name)
{
wchar_t info[128] = { 0 };
swprintf_s(info, _countof(info) - 1, L"Fix-ID 与现有属性“%s”冲突", v.title.c_str());
::MessageBoxW(m_hWnd, info, NULL, MB_OK);
GotoDlgCtrl(GetDlgItem(IDC_EDIT_FIXED_ID));
return;
}
}
else if (v.category == sop.category && v.category == L"图像处理" && v.pos == sop.pos)
{
wchar_t info[128] = { 0 };
swprintf_s(info, _countof(info) - 1, L"Position 与现有属性“%s”冲突", v.title.c_str());
::MessageBoxW(m_hWnd, info, NULL, MB_OK);
GotoDlgCtrl(GetDlgItem(IDC_EDIT_POSITION));
return;
}
}
}
for (auto& v : opts_)
{
if (v.name == sop.name)
@ -2951,5 +3047,6 @@ void CDlgOptJson::OnBnClickedButtonShowui()
}
}
}
dlg_page;
}

View File

@ -31,6 +31,7 @@ namespace coding
// Cat: 图像处理;
//
class tooltip_wnd;
class CDlgOptJson : public CDialogEx
{
DECLARE_DYNAMIC(CDlgOptJson)
@ -54,6 +55,7 @@ class CDlgOptJson : public CDialogEx
CImageList tree_img_;
hex_edit fix_id_edit_;
tooltip_wnd* tooltips_;
std::wstring get_item_text(UINT id);
bool is_button_check(UINT id);