195 lines
5.6 KiB
C++
195 lines
5.6 KiB
C++
|
|
// hgjsonDlg.h : header file
|
|
//
|
|
|
|
#pragma once
|
|
#include "afxshelltreectrl.h"
|
|
#include "afxwin.h"
|
|
#include "afxcmn.h"
|
|
#include <vector>
|
|
#include <string>
|
|
#include <algorithm>
|
|
|
|
|
|
// ChgjsonDlg dialog
|
|
class ChgjsonDlg : public CDialogEx
|
|
{
|
|
// Construction
|
|
public:
|
|
ChgjsonDlg(CWnd* pParent = NULL); // standard constructor
|
|
|
|
// Dialog Data
|
|
enum { IDD = IDD_HGJSON_DIALOG };
|
|
|
|
protected:
|
|
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
|
|
|
|
public:
|
|
typedef struct _depend_item
|
|
{
|
|
std::wstring parent;
|
|
std::wstring logic_values; // include logic operator: "==2"
|
|
|
|
bool operator==(const wchar_t* name)
|
|
{
|
|
return wcscmp(name, parent.c_str()) == 0;
|
|
}
|
|
bool operator<(const struct _depend_item& r)
|
|
{
|
|
return parent < r.parent;
|
|
}
|
|
}DEPENDITEM;
|
|
enum range_type
|
|
{
|
|
RANGE_TYPE_NONE = 0,
|
|
RANGE_TYPE_RANGE,
|
|
RANGE_TYPE_LIST,
|
|
};
|
|
typedef struct _range
|
|
{
|
|
int type;
|
|
double lower;
|
|
double upper;
|
|
double step;
|
|
std::vector<std::wstring> queue;
|
|
}RANGE;
|
|
typedef struct _hg_item
|
|
{
|
|
std::wstring title;
|
|
std::wstring desc;
|
|
std::wstring type;
|
|
std::wstring init_val;
|
|
std::wstring group;
|
|
int index;
|
|
int bytes;
|
|
bool advanced;
|
|
bool readonly;
|
|
//bool deviceonly; // 只能在设备上操作的属性 - use readonly
|
|
bool visible;
|
|
int affect;
|
|
int position;
|
|
int field;
|
|
int unit;
|
|
bool depend_or; // or or and
|
|
std::vector<DEPENDITEM> depend;
|
|
RANGE range;
|
|
|
|
bool operator==(const wchar_t* name)
|
|
{
|
|
return wcscmp(name, title.c_str()) == 0;
|
|
}
|
|
struct _hg_item(const wchar_t* ti= L"")
|
|
{
|
|
title = ti ? ti : L"";
|
|
desc = L"";
|
|
type = L"bool";
|
|
init_val = L"true";
|
|
group = L"base";
|
|
bytes = 4;
|
|
advanced = readonly = /*deviceonly =*/ false;
|
|
visible = depend_or = true;
|
|
affect = position = field = unit = 0;
|
|
range.type = RANGE_TYPE_NONE;
|
|
}
|
|
}HGITEM;
|
|
typedef struct _def_h
|
|
{
|
|
std::wstring name;
|
|
std::wstring value;
|
|
std::wstring utf8_in_oct;
|
|
bool operator==(const std::wstring& n)
|
|
{
|
|
return name == n;
|
|
}
|
|
}DEFH;
|
|
std::vector<HGITEM> hg_items_;
|
|
bool show_tree_tooltips_;
|
|
bool show_list_tooltips_;
|
|
|
|
static std::wstring get_tree_item_text(CTreeCtrl* tree, HTREEITEM root, DWORD_PTR* data = NULL);
|
|
static std::wstring get_tree_selected_item_text(CTreeCtrl* tree, DWORD_PTR* data = NULL);
|
|
|
|
// Implementation
|
|
protected:
|
|
CMenu tree_menu_;
|
|
CMenu func_menu_;
|
|
CImageList tree_img_;
|
|
|
|
// Generated message map functions
|
|
virtual BOOL OnInitDialog();
|
|
afx_msg void OnPaint();
|
|
afx_msg HCURSOR OnQueryDragIcon();
|
|
afx_msg void OnPaste();
|
|
DECLARE_MESSAGE_MAP()
|
|
|
|
static void to_define_header(std::vector<DEFH>& defs, const wchar_t* str, const wchar_t* parent = NULL);
|
|
static std::string save_define_header_2_file(std::vector<DEFH>& defs, const wchar_t* file); // return BOM string
|
|
|
|
void init_control_statu(void);
|
|
void delete_tree_item(HTREEITEM root);
|
|
int find_config_item(const wchar_t* item_name);
|
|
int check_depend(const wchar_t* l, const wchar_t* r); // -1: l depends on r; 0: no depend; 1: r depends on l
|
|
void set_control_status(const HGITEM& item);
|
|
|
|
void* create_json(int item, std::vector<DEFH> *def_h = NULL, std::wstring* name = NULL);
|
|
std::string to_json_text(bool for_const = false, std::wstring *dev = NULL);
|
|
void add_item(void* jsn_root, void* jsn_obj, HTREEITEM parent, bool old_ver);
|
|
bool load_from_json_text(const wchar_t* txt, std::wstring* err_msg = NULL);
|
|
bool load_from_file(const wchar_t* path_file);
|
|
void get_all_names(HTREEITEM root, std::vector<std::wstring>& names, DWORD mask = 0);
|
|
void on_config_name_changed(const wchar_t* prev, const wchar_t* now);
|
|
HTREEITEM add_tree_item(const wchar_t* title, DWORD data, HTREEITEM parent = TVI_ROOT, HTREEITEM after = TVI_LAST);
|
|
void filter_tree_item(HTREEITEM item, const std::vector<HGITEM>& filter);
|
|
bool is_depend(const wchar_t* me, const wchar_t* parent, std::vector<std::wstring>* que = NULL); // whether me depend on parent
|
|
|
|
public:
|
|
afx_msg void OnTreeAddGroup();
|
|
afx_msg void OnTreeAddItem();
|
|
afx_msg void OnTreeDelItem();
|
|
CTreeCtrl tree_;
|
|
afx_msg void OnTreeAddProduct();
|
|
afx_msg void OnBnClickedButton3();
|
|
afx_msg void OnBnClickedButton1();
|
|
afx_msg void OnBnClickedButton2();
|
|
CListBox depends_;
|
|
CListCtrl constraint_list_;
|
|
afx_msg void OnCbnSelchangeDataType();
|
|
afx_msg void OnCbnSelchangeConstraintType();
|
|
afx_msg void OnCbnSelchangeDependItem();
|
|
afx_msg void OnCbnSelchangeLogic();
|
|
afx_msg void OnLvnEndlabeleditListValues(NMHDR *pNMHDR, LRESULT *pResult);
|
|
CComboBox type_;
|
|
CComboBox constraint_;
|
|
afx_msg void OnBnClickedDepend();
|
|
CComboBox logic_;
|
|
CComboBox depend_item_;
|
|
afx_msg void OnBnClickedButton4();
|
|
afx_msg void OnNMRClickMfcshelltree1(NMHDR *pNMHDR, LRESULT *pResult);
|
|
CComboBox combo_default_;
|
|
afx_msg void OnTvnSelchangedTree1(NMHDR *pNMHDR, LRESULT *pResult);
|
|
afx_msg void OnListmenuSetdefault();
|
|
afx_msg void OnListmenuDelete();
|
|
afx_msg void OnNMRClickListValues(NMHDR *pNMHDR, LRESULT *pResult);
|
|
afx_msg void OnLbnDblclkList3();
|
|
afx_msg void OnDropFiles(HDROP hDropInfo);
|
|
afx_msg void OnTreeRename();
|
|
afx_msg void OnTreeLoadfile();
|
|
afx_msg void OnLvnKeydownListValues(NMHDR *pNMHDR, LRESULT *pResult);
|
|
afx_msg void OnTvnKeydownTree1(NMHDR *pNMHDR, LRESULT *pResult);
|
|
afx_msg void OnTvnGetInfoTipTree1(NMHDR *pNMHDR, LRESULT *pResult);
|
|
afx_msg void OnLvnGetInfoTipListValues(NMHDR *pNMHDR, LRESULT *pResult);
|
|
afx_msg void OnTreeTooltips();
|
|
afx_msg void OnListmenuTooltips();
|
|
afx_msg void OnTreeExportCharConstants();
|
|
afx_msg void OnBnClickedToFile();
|
|
afx_msg void OnTreeLoadClipboard();
|
|
afx_msg void OnTreeUnifySequence();
|
|
CComboBox field_;
|
|
CComboBox unit_;
|
|
CComboBox group_;
|
|
CComboBox affect_;
|
|
};
|
|
|
|
|
|
|