diff --git a/tools/apps/hgjson/DlgOptJson.cpp b/tools/apps/hgjson/DlgOptJson.cpp index edf577c..afd474b 100644 --- a/tools/apps/hgjson/DlgOptJson.cpp +++ b/tools/apps/hgjson/DlgOptJson.cpp @@ -270,7 +270,7 @@ known_file_util::IJsonW* CDlgOptJson::SANEOPT::to_json(void) jsn->set_value(L"affect", nv); if(readonly) jsn->set_value(L"readonly", readonly); - if(!open) + if(open != OPT_VISIBLE_ALL) jsn->set_value(L"visible", open); if(!enable) jsn->set_value(L"enabled", enable); @@ -747,8 +747,12 @@ bool CDlgOptJson::SANEOPT::from_json(known_file_util::IJsonW* jsn) jsn->get_value(L"pos", pos); if (!jsn->get_value(L"readonly", readonly)) readonly = false; - if (!jsn->get_value(L"visible", open)) - open = true; + + bool bv = false; + if (jsn->get_value(L"visible", bv)) + open = bv ? OPT_VISIBLE_ALL : OPT_VISIBLE_HIDE; + else if (!jsn->get_value(L"visible", open)) + open = OPT_VISIBLE_ALL; if (!jsn->get_value(L"enabled", enable)) enable = true; if (!jsn->get_value(L"fix-id", fix_id) && !name.empty()) @@ -1050,6 +1054,23 @@ bool CDlgOptJson::SANEOPT::from_json(known_file_util::IJsonW* jsn) return ret; } +void CDlgOptJson::SANEOPT::init(struct _sane_opt_json* opt) +{ + opt->name = opt->title = opt->desc = L""; + opt->group = L"\u57FA\u672C\u8BBE\u7F6E"; + opt->category = opt->unit = opt->affect = opt->range_type = L"none"; + opt->range.clear(); + + opt->def_val.clear(); + opt->type = L"int"; + opt->ver = 1; + opt->fix_id = 0; + opt->pos = -1; + opt->readonly = false; + opt->open = OPT_VISIBLE_ALL; + opt->enable = true; + opt->auto_restore_default = true; +} std::wstring CDlgOptJson::get_item_text(UINT id) { @@ -1129,7 +1150,7 @@ void CDlgOptJson::from_ui(SANEOPT& sop) //sop.fix_id = GetDlgItemInt(IDC_EDIT_FIXED_ID); sop.fix_id = fix_id_edit_.value(); sop.readonly = is_button_check(IDC_CHECK_READONLY); - sop.open = is_button_check(IDC_CHECK_PUBLIC); + sop.open = visible_.GetCurSel(); // is_button_check(IDC_CHECK_PUBLIC); sop.range_type = get_item_text(IDC_COMBO_RANGE); if (GetDlgItem(IDC_EDIT_DEFAULT)->IsWindowVisible()) @@ -1179,6 +1200,16 @@ void CDlgOptJson::from_ui(SANEOPT& sop) sop.range_type = get_item_text(IDC_COMBO_RANGE); sop.auto_restore_default = is_button_check(IDC_CHECK_AUTO_RESTORE); sop.depend = get_item_text(IDC_EDIT_LOGIC); + + simple_logic logic; + int pos = 0; + + if (!logic.parse(local_trans::u2a(sop.depend.c_str(), CP_UTF8).c_str(), &pos)) + { + wchar_t info[128] = { 0 }; + swprintf_s(info, _countof(info) - 1, L"Invalid char at position %u('%c')!", pos, sop.depend[pos]); + MessageBox(info, L"Invalid Logic-Expression"); + } } void CDlgOptJson::to_ui(const SANEOPT& sop) { @@ -1215,7 +1246,8 @@ void CDlgOptJson::to_ui(const SANEOPT& sop) fix_id_edit_.set_value(sop.fix_id); set_button_check(IDC_CHECK_READONLY, sop.readonly); - set_button_check(IDC_CHECK_PUBLIC, sop.open); + //set_button_check(IDC_CHECK_PUBLIC, sop.open); + visible_.SetCurSel(sop.open); set_button_check(IDC_CHECK_ENABLE, sop.enable); set_button_check(IDC_CHECK_AUTO_RESTORE, sop.auto_restore_default); @@ -1607,6 +1639,7 @@ void CDlgOptJson::DoDataExchange(CDataExchange* pDX) DDX_Control(pDX, IDC_COMBO_LOW, lower_); DDX_Control(pDX, IDC_COMBO_BIG, upper_); DDX_Control(pDX, IDC_COMBO_EXPORT, export_type_); + DDX_Control(pDX, IDC_COMBO_VISIBLE, visible_); DDX_Control(pDX, IDC_LIST_DEPEND, depends_); DDX_Control(pDX, IDC_TREE2, tree_); } @@ -1641,6 +1674,7 @@ BOOL CDlgOptJson::OnInitDialog() fix_id_edit_.attach(GetDlgItem(IDC_EDIT_FIXED_ID)->m_hWnd); export_type_.SetCurSel(1); + visible_.SetCurSel(0); tooltips_ = new tooltip_wnd(); tooltips_->create(m_hWnd); diff --git a/tools/apps/hgjson/DlgOptJson.h b/tools/apps/hgjson/DlgOptJson.h index 32cffeb..5c133d1 100644 --- a/tools/apps/hgjson/DlgOptJson.h +++ b/tools/apps/hgjson/DlgOptJson.h @@ -48,6 +48,7 @@ class CDlgOptJson : public CDialogEx CComboBox logic_; CComboBox lower_; CComboBox upper_; + CComboBox visible_; CComboBox export_type_; CListBox depends_; CTreeCtrl tree_; @@ -93,8 +94,8 @@ public: int ver; int pos; int fix_id; + int open; bool readonly; - bool open; bool enable; bool auto_restore_default; @@ -109,23 +110,7 @@ public: init(this); } } - static void init(struct _sane_opt_json* opt) - { - opt->name = opt->title = opt->desc = L""; - opt->group = L"\u57FA\u672C\u8BBE\u7F6E"; - opt->category = opt->unit = opt->affect = opt->range_type = L"none"; - opt->range.clear(); - - opt->def_val.clear(); - opt->type = L"int"; - opt->ver = 1; - opt->fix_id = 0; - opt->pos = -1; - opt->readonly = false; - opt->open = true; - opt->enable = true; - opt->auto_restore_default = true; - } + static void init(struct _sane_opt_json* opt); static void affect_str(int& val, std::wstring& str, bool to_str) { static std::wstring affect_desc[] = { L"none", L"其它属性", L"图像参数", L"属性+参数" }; diff --git a/tools/apps/hgjson/hgjson.rc b/tools/apps/hgjson/hgjson.rc index fd2f77f..cb3ae09 100644 Binary files a/tools/apps/hgjson/hgjson.rc and b/tools/apps/hgjson/hgjson.rc differ diff --git a/tools/apps/hgjson/opt_ui/DlgPage.cpp b/tools/apps/hgjson/opt_ui/DlgPage.cpp index 68a1c24..6fd0a65 100644 --- a/tools/apps/hgjson/opt_ui/DlgPage.cpp +++ b/tools/apps/hgjson/opt_ui/DlgPage.cpp @@ -952,6 +952,9 @@ HWND dlg_page::create_control_bool(int sn, const SANE_Option_Descriptor* desc, v if (now) SendMessage(wnd, BM_SETCHECK, (WPARAM)BST_CHECKED, 0); + if (IS_CAP_READONLY(desc->cap)) + EnableWindow(wnd, FALSE); + return wnd; } HWND dlg_page::create_control_int(int sn, const SANE_Option_Descriptor* desc, void* cur_val, const wchar_t* title, LPSIZE text_size) @@ -1000,6 +1003,16 @@ HWND dlg_page::create_control_int(int sn, const SANE_Option_Descriptor* desc, vo x += dlg_page::spin_w; } text_size->cx = x + dlg_page::gap_x; + if (IS_CAP_READONLY(desc->cap)) + { + EnableWindow(label, FALSE); + if(slider) + EnableWindow(slider, FALSE); + EnableWindow(wnd, FALSE); + if(spin) + EnableWindow(spin, FALSE); + } + return wnd; } @@ -1052,6 +1065,16 @@ HWND dlg_page::create_control_float(int sn, const SANE_Option_Descriptor* desc, } text_size->cx = x + dlg_page::gap_x; + if (IS_CAP_READONLY(desc->cap)) + { + EnableWindow(label, FALSE); + if (slider) + EnableWindow(slider, FALSE); + EnableWindow(wnd, FALSE); + if (spin) + EnableWindow(spin, FALSE); + } + return wnd; } HWND dlg_page::create_control_string(int sn, const SANE_Option_Descriptor* desc, void* cur_val, const wchar_t* title, LPSIZE text_size) @@ -1060,7 +1083,12 @@ HWND dlg_page::create_control_string(int sn, const SANE_Option_Descriptor* desc, int x = pos_.x; std::wstring now(local_trans::a2u((char*)cur_val, CP_UTF8)); - create_label(sn, title, x, pos_.y, *text_size); + wnd = create_label(sn, title, x, pos_.y, *text_size); + if (IS_CAP_READONLY(desc->cap)) + { + EnableWindow(wnd, FALSE); + } + x += text_size->cx + dlg_page::gap_x; if (desc->constraint_type == SANE_CONSTRAINT_STRING_LIST) @@ -1084,6 +1112,10 @@ HWND dlg_page::create_control_string(int sn, const SANE_Option_Descriptor* desc, x += 200; } text_size->cx = x + dlg_page::gap_x; + if (IS_CAP_READONLY(desc->cap)) + { + EnableWindow(wnd, FALSE); + } return wnd; } @@ -1670,7 +1702,7 @@ bool dlg_page::refresh(int sn, const SANE_Option_Descriptor* desc, void* cur_val } set_ctrl_value(ctrls_[ind], desc->type, cur_val, true); - EnableWindow(ctrls_[ind], (desc->cap & SANE_CAP_INACTIVE) != SANE_CAP_INACTIVE); + EnableWindow(ctrls_[ind], (desc->cap & SANE_CAP_INACTIVE) != SANE_CAP_INACTIVE && !IS_CAP_READONLY(desc->cap)); host = (HWND)GetPropW(ctrls_[ind], dlg_page::property_host.c_str()); if (IsWindow(host)) { diff --git a/tools/apps/hgjson/resource.h b/tools/apps/hgjson/resource.h index f8bb97d..5fb66ac 100644 Binary files a/tools/apps/hgjson/resource.h and b/tools/apps/hgjson/resource.h differ diff --git a/tools/solution/Release/hgjson.exe b/tools/solution/Release/hgjson.exe index d64eb8e..43d691e 100644 Binary files a/tools/solution/Release/hgjson.exe and b/tools/solution/Release/hgjson.exe differ