doc_and_tools/tools/apps/hgjson/DlgOptJson.h

210 lines
5.2 KiB
C++

#pragma once
// CDlgInput dialog
#include <string>
#include <vector>
#include <utility/known_file.h>
#include <coding/coding.h>
#include <file/file_util.h>
#include <sane/sane_ex.h>
#include "hex_edit.h"
namespace coding
{
typedef struct _clp_d
{
bool file;
std::wstring cont;
}CLPD, * LPCLPD;
INTER_MODULE_CALLBACK(get_string);
INTER_MODULE_CALLBACK(get_wstring);
INTER_MODULE_CALLBACK(get_clipboard_content);
std::wstring name_from_depend_exp(const std::wstring& depend_exp);
};
// Group: 基本设置;图像处理;送纸方式;高级设置;
//
// Cat: 图像处理;
//
class tooltip_wnd;
class CDlgOptJson : public CDialogEx
{
DECLARE_DYNAMIC(CDlgOptJson)
CComboBox group_;
CComboBox cat_;
CComboBox affect_;
CComboBox unit_;
CComboBox type_;
CComboBox range_;
CComboBox def_val_;
CComboBox depend_;
CComboBox parent_;
CComboBox logic_;
CComboBox lower_;
CComboBox upper_;
CComboBox visible_;
CComboBox export_type_;
CListBox depends_;
CTreeCtrl tree_;
CMenu tree_menu_;
CImageList tree_img_;
hex_edit fix_id_edit_;
tooltip_wnd* tooltips_;
std::wstring get_item_text(UINT id);
bool is_button_check(UINT id);
void set_button_check(UINT id, bool check);
std::wstring get_json_text(const wchar_t* tab = NULL);
public:
CDlgOptJson(CWnd* pParent = NULL); // standard constructor
virtual ~CDlgOptJson();
// Dialog Data
enum { IDD = IDD_NEW_JSON };
typedef struct _cond_val
{
std::string val;
std::string cond; // for range, must lead by 'min:' or 'max:' or 'step:'
}CONDVAL;
typedef struct _sane_opt_json
{
std::wstring name;
std::wstring title;
std::wstring desc;
std::wstring group;
std::wstring category;
std::wstring affect;
std::wstring unit;
std::wstring type;
std::vector<CONDVAL> def_val;
std::wstring range_type;
std::vector<CONDVAL> range;
std::wstring depend;
std::vector<CONDVAL> visible;
int size;
int ver;
int pos;
int ui_pos;
int fix_id;
int auth; // 用户权限
bool readonly;
bool enable;
bool bind_cur; // Whether to synchronize and change current value as the same when default value changes
bool auto_restore_default;
bool own_read; // 通常读取属性值都返回当前值。如果某属性读操作不同于此,则设置该属性
struct _sane_opt_json()
{
init(this);
}
struct _sane_opt_json(known_file_util::IJsonW* jsn)
{
if (!from_json(jsn))
{
init(this);
}
}
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"属性+参数" };
if (to_str)
{
int ind = val >> 1;
if (ind >= 0 && ind < _countof(affect_desc))
str = affect_desc[ind];
else
str = affect_desc[0];
}
else
{
val = 0;
for (int i = 0; i < _countof(affect_desc); ++i)
{
if (str == affect_desc[i])
val = i << 1;
}
}
}
static bool compare_name(const struct _sane_opt_json& l, const struct _sane_opt_json& r)
{
return l.name < r.name;
}
static bool compare_title(const struct _sane_opt_json& l, const struct _sane_opt_json& r)
{
return l.title < r.title;
}
static bool compare_group(const struct _sane_opt_json& l, const struct _sane_opt_json& r)
{
return l.group < r.group;
}
static bool compare_position(const struct _sane_opt_json& l, const struct _sane_opt_json& r)
{
return l.pos < r.pos;
}
known_file_util::IJsonW* to_json(void);
bool from_json(known_file_util::IJsonW* jsn);
}SANEOPT;
std::vector<SANEOPT> opts_;
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
virtual BOOL OnInitDialog();
void from_ui(SANEOPT& sop);
void to_ui(const SANEOPT& sop);
HTREEITEM insert_new_item(const SANEOPT& opt, bool sel = true);
void delete_from_tree(const wchar_t* name = NULL);
HTREEITEM modify_tree_title(const wchar_t* name, const wchar_t* title);
void update_opt_count(void);
void clear_visible(void);
bool load_from_file(const wchar_t* path_file);
bool load_from_json_text(const wchar_t* txt, std::wstring* err_msg = NULL);
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnCbnDataTypeSelchange();
afx_msg void OnCbnRangeSelchange();
afx_msg void OnCbnDependSelchange();
afx_msg void OnCbnParentSelchange();
afx_msg void OnCbnLogicSelchange();
afx_msg void OnCbnSelchange();
afx_msg void OnPaste();
afx_msg void OnBnClickedButtonModify();
afx_msg void OnBnClickedButtonAdd();
afx_msg void OnTvnSelchangedTree2(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnNMRClickTree2(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnTvnSelchangingTree2(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnTreeLoadfile();
afx_msg void OnTreeLoadclipboard();
afx_msg void OnLbnDblclkListDepend();
afx_msg void OnBnClickedButtonSet();
afx_msg void OnTreeDelitem();
afx_msg void OnBnClickedButtonExport();
afx_msg void OnTreeModifyallfield();
afx_msg void OnSortName();
afx_msg void OnSortTitle();
afx_msg void OnSortGroup();
afx_msg void OnSortPosition();
afx_msg void OnBnClickedButtonShowui();
afx_msg void OnDestroy();
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
afx_msg LRESULT OnStaticColor(WPARAM wp, LPARAM lp);
afx_msg void OnBnClickedButtonSetVisible();
afx_msg void OnTvnKeydownTree2(NMHDR* pNMHDR, LRESULT* pResult);
};