修复自定义GAMMA数据不能保存;自定义区域无法拖曳的问题
This commit is contained in:
parent
0ada2413ac
commit
7586520973
|
@ -306,8 +306,8 @@ void dlg_area::drag_blocks(std::vector<DRAGRECT>& blocks)
|
|||
|
||||
r.left = user_sel_.left;
|
||||
r.top = user_sel_.top;
|
||||
r.right = r.left + 1;
|
||||
r.bottom = r.top + 1;
|
||||
r.right = r.left + l;
|
||||
r.bottom = r.top + l;
|
||||
r.pos = DRAG_POS_LT;
|
||||
|
||||
blocks.clear();
|
||||
|
|
|
@ -832,6 +832,10 @@ void dlg_page::handle_command(WORD code, WORD id, HANDLE ctrl)
|
|||
len = sizeof(gamma);
|
||||
dlg.get_gamma(&gamma);
|
||||
sane_.sane_io_control_api(dev_, IO_CTRL_CODE_SET_CUSTOM_GAMMA, &gamma, &len);
|
||||
|
||||
gb::sane_config* cfg = get_config();
|
||||
if (cfg)
|
||||
cfg->config_changed(id_custom_gamma_, (char*)&gamma, sizeof(gamma), true);
|
||||
}
|
||||
|
||||
return;
|
||||
|
|
|
@ -831,6 +831,8 @@ namespace gb
|
|||
|
||||
namespace gb
|
||||
{
|
||||
std::string sane_config::opt_data_appendix_("_data");
|
||||
|
||||
sane_config::sane_config() : jsn_(NULL), bkp_(NULL), in_setting_(false)
|
||||
{
|
||||
def_val_ = new gb::json();
|
||||
|
@ -881,6 +883,22 @@ namespace gb
|
|||
|
||||
return ret;
|
||||
}
|
||||
bool sane_config::is_option_data(std::string& name)
|
||||
{
|
||||
size_t pos = name.find(sane_config::opt_data_appendix_);
|
||||
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
if (pos + sane_config::opt_data_appendix_.length() == name.length())
|
||||
{
|
||||
name.erase(pos);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void sane_config::clear()
|
||||
{
|
||||
|
@ -1053,7 +1071,7 @@ namespace gb
|
|||
else
|
||||
jsn_->set_value(name, hex_v.c_str());
|
||||
}
|
||||
void sane_config::config_changed(int sn, const char* val, size_t bytes)
|
||||
void sane_config::config_changed(int sn, const char* val, size_t bytes, bool extra)
|
||||
{
|
||||
std::string name(""),
|
||||
hex_v(to_hex_letter(val, bytes)),
|
||||
|
@ -1062,11 +1080,22 @@ namespace gb
|
|||
if (id_name_.count(sn))
|
||||
{
|
||||
name = id_name_[sn];
|
||||
def = default_value(name.c_str());
|
||||
if (hex_v == def)
|
||||
jsn_->remove(name.c_str());
|
||||
else
|
||||
if (extra)
|
||||
{
|
||||
name += sane_config::opt_data_appendix_;
|
||||
jsn_->set_value(name.c_str(), hex_v.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
def = default_value(name.c_str());
|
||||
if (hex_v == def)
|
||||
{
|
||||
jsn_->remove(name.c_str());
|
||||
jsn_->remove((name + sane_config::opt_data_appendix_).c_str());
|
||||
}
|
||||
else
|
||||
jsn_->set_value(name.c_str(), hex_v.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
void sane_config::remove_config(const char* name)
|
||||
|
|
|
@ -100,8 +100,10 @@ namespace gb
|
|||
sane_config();
|
||||
~sane_config();
|
||||
|
||||
static std::string opt_data_appendix_;
|
||||
static bool hex(unsigned char ch, unsigned char* val);
|
||||
static bool hex_char(const char* data, unsigned char* val);
|
||||
static bool is_option_data(std::string& name); // reset baase option name into 'name' if name was option data, and return true
|
||||
|
||||
public:
|
||||
bool load_from_file(const wchar_t* file);
|
||||
|
@ -112,7 +114,7 @@ namespace gb
|
|||
bool next_config(std::string& name, std::string& val);
|
||||
void begin_setting(bool restore = false);
|
||||
void config_changed(const char* name, const char* val, size_t bytes);
|
||||
void config_changed(int sn, const char* val, size_t bytes);
|
||||
void config_changed(int sn, const char* val, size_t bytes, bool extra = false);
|
||||
void remove_config(const char* name);
|
||||
void end_setting(bool cancel);
|
||||
int id_from_name(const char* name);
|
||||
|
|
|
@ -478,13 +478,34 @@ void scanner::save_config(const wchar_t* file)
|
|||
void scanner::apply_config(void)
|
||||
{
|
||||
std::string n(""), v(""), ver(cfg_->get_version());
|
||||
std::wstring notice(L"");
|
||||
|
||||
if (cfg_->first_config(n, v))
|
||||
{
|
||||
do
|
||||
{
|
||||
int id = cfg_->id_from_name(n.c_str());
|
||||
if (id != -1)
|
||||
int id = cfg_->id_from_name(n.c_str());
|
||||
if (id == -1)
|
||||
{
|
||||
if (gb::sane_config::is_option_data(n))
|
||||
{
|
||||
id = cfg_->id_from_name(n.c_str());
|
||||
if (id == is_custom_gamma_id_)
|
||||
{
|
||||
if (v.length() == sizeof(SANE_Gamma))
|
||||
{
|
||||
unsigned int l = v.length();
|
||||
hg_sane_middleware::instance()->io_control(handle_, IO_CTRL_CODE_SET_CUSTOM_GAMMA, &v[0], &l);
|
||||
}
|
||||
else
|
||||
{
|
||||
wchar_t info[128] = { 0 };
|
||||
swprintf_s(info, _countof(info) - 1, L"ERROR: custom gamma data length is %u, but we expect %u.\r\n", v.length(), sizeof(SANE_Gamma));
|
||||
log_info(info, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
void* data = &v[0];
|
||||
SANE_Fixed fixed = 0;
|
||||
|
|
Loading…
Reference in New Issue