continue param tree changes
take RAW_BYTES string out of bx_param_string_c into new param type bx_param_bytestring_c (better name, anybody?) this is intermediate step, later it would be better to merge bx_param_string into generic template bx_param<type> but bx_param_bytestring_cis not matching that concept (or probably will continue to inherit from bx_param<string>)
This commit is contained in:
parent
de30601ca6
commit
e8d0e718f1
@ -174,17 +174,16 @@ void bx_init_std_nic_options(const char *name, bx_list_c *menu)
|
||||
};
|
||||
|
||||
bx_param_enum_c *ethmod;
|
||||
bx_param_string_c *macaddr;
|
||||
bx_param_bytestring_c *macaddr;
|
||||
bx_param_filename_c *path, *bootrom;
|
||||
char descr[120];
|
||||
|
||||
sprintf(descr, "MAC address of the %s device. Don't use an address of a machine on your net.", name);
|
||||
macaddr = new bx_param_string_c(menu,
|
||||
macaddr = new bx_param_bytestring_c(menu,
|
||||
"mac",
|
||||
"MAC Address",
|
||||
descr,
|
||||
"", 6);
|
||||
macaddr->set_options(macaddr->RAW_BYTES);
|
||||
macaddr->set_initial_val("\xfe\xfd\xde\xad\xbe\xef");
|
||||
macaddr->set_separator(':');
|
||||
ethmod = new bx_param_enum_c(menu,
|
||||
|
@ -2408,6 +2408,7 @@ void MakeBL(TreeParent *h_P, bx_param_c *p)
|
||||
case BXT_PARAM_ENUM:
|
||||
case BXT_PARAM_NUM:
|
||||
case BXT_PARAM_STRING:
|
||||
case BXT_PARAM_BYTESTRING:
|
||||
p->dump_param(tmpstr, BX_PATHNAME_LEN);
|
||||
sprintf(tmpcb + j,": %s", tmpstr);
|
||||
break;
|
||||
|
@ -833,23 +833,6 @@ bx_param_string_c::bx_param_string_c(bx_param_c *parent,
|
||||
}
|
||||
}
|
||||
|
||||
bx_param_filename_c::bx_param_filename_c(bx_param_c *parent,
|
||||
const char *name,
|
||||
const char *label,
|
||||
const char *description,
|
||||
const char *initial_val,
|
||||
int maxsize)
|
||||
: bx_param_string_c(parent, name, label, description, initial_val, maxsize)
|
||||
{
|
||||
set_options(IS_FILENAME);
|
||||
int len = strlen(initial_val);
|
||||
if ((len > 4) && (initial_val[len - 4] == '.')) {
|
||||
ext = &initial_val[len - 3];
|
||||
} else {
|
||||
ext = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bx_param_string_c::~bx_param_string_c()
|
||||
{
|
||||
delete [] val;
|
||||
@ -901,10 +884,7 @@ void bx_param_string_c::set_dependent_list(bx_list_c *l)
|
||||
|
||||
Bit32s bx_param_string_c::get(char *buf, int len)
|
||||
{
|
||||
if (options & RAW_BYTES)
|
||||
memcpy(buf, val, len);
|
||||
else
|
||||
strncpy(buf, val, len);
|
||||
strncpy(buf, val, len);
|
||||
if (handler) {
|
||||
// the handler can choose to replace the value in val/len. Also its
|
||||
// return value is passed back as the return value of get.
|
||||
@ -917,50 +897,32 @@ void bx_param_string_c::set(const char *buf)
|
||||
{
|
||||
char *oldval = new char[maxsize];
|
||||
|
||||
if (options & RAW_BYTES) {
|
||||
memcpy(oldval, val, maxsize);
|
||||
} else {
|
||||
strncpy(oldval, val, maxsize);
|
||||
oldval[maxsize - 1] = 0;
|
||||
}
|
||||
strncpy(oldval, val, maxsize);
|
||||
oldval[maxsize - 1] = 0;
|
||||
if (handler) {
|
||||
// the handler can return a different char* to be copied into the value
|
||||
buf = (*handler)(this, 1, oldval, buf, -1);
|
||||
}
|
||||
if (options & RAW_BYTES) {
|
||||
memcpy(val, buf, maxsize);
|
||||
} else {
|
||||
strncpy(val, buf, maxsize);
|
||||
val[maxsize - 1] = 0;
|
||||
}
|
||||
strncpy(val, buf, maxsize);
|
||||
val[maxsize - 1] = 0;
|
||||
delete [] oldval;
|
||||
if (dependent_list != NULL) update_dependents();
|
||||
}
|
||||
|
||||
bx_bool bx_param_string_c::equals(const char *buf)
|
||||
bx_bool bx_param_string_c::equals(const char *buf) const
|
||||
{
|
||||
if (options & RAW_BYTES)
|
||||
return (memcmp(val, buf, maxsize) == 0);
|
||||
else
|
||||
return (strncmp(val, buf, maxsize) == 0);
|
||||
return (strncmp(val, buf, maxsize) == 0);
|
||||
}
|
||||
|
||||
void bx_param_string_c::set_initial_val(const char *buf)
|
||||
{
|
||||
if (options & RAW_BYTES)
|
||||
memcpy(initial_val, buf, maxsize);
|
||||
else
|
||||
strncpy(initial_val, buf, maxsize);
|
||||
strncpy(initial_val, buf, maxsize);
|
||||
set(initial_val);
|
||||
}
|
||||
|
||||
bx_bool bx_param_string_c::isempty() const
|
||||
{
|
||||
if (options & RAW_BYTES) {
|
||||
return (memcmp(val, initial_val, maxsize) == 0);
|
||||
} else {
|
||||
return ((strlen(val) == 0) || !strcmp(val, "none"));
|
||||
}
|
||||
return (strlen(val) == 0) || !strcmp(val, "none");
|
||||
}
|
||||
|
||||
int bx_param_string_c::parse_param(const char *ptr)
|
||||
@ -983,33 +945,92 @@ void bx_param_string_c::dump_param(FILE *fp)
|
||||
|
||||
int bx_param_string_c::dump_param(char *buf, int len, bx_bool dquotes)
|
||||
{
|
||||
char tmpbyte[4];
|
||||
|
||||
if (get_options() & RAW_BYTES) {
|
||||
buf[0] = 0;
|
||||
for (int j = 0; j < maxsize; j++) {
|
||||
if (j > 0) {
|
||||
tmpbyte[0] = separator;
|
||||
tmpbyte[1] = 0;
|
||||
strcat(buf, tmpbyte);
|
||||
}
|
||||
sprintf(tmpbyte, "%02x", (Bit8u)val[j]);
|
||||
strcat(buf, tmpbyte);
|
||||
if (!isempty()) {
|
||||
if (dquotes) {
|
||||
snprintf(buf, len, "\"%s\"", val);
|
||||
} else {
|
||||
snprintf(buf, len, "%s", val);
|
||||
}
|
||||
} else {
|
||||
if (!isempty()) {
|
||||
if (dquotes) {
|
||||
snprintf(buf, len, "\"%s\"", val);
|
||||
} else {
|
||||
snprintf(buf, len, "%s", val);
|
||||
}
|
||||
} else {
|
||||
strcpy(buf, "none");
|
||||
}
|
||||
strcpy(buf, "none");
|
||||
}
|
||||
return strlen(buf);
|
||||
}
|
||||
|
||||
Bit32s bx_param_bytestring_c::get(char *buf, int len)
|
||||
{
|
||||
memcpy(buf, val, len);
|
||||
if (handler) {
|
||||
// the handler can choose to replace the value in val/len. Also its
|
||||
// return value is passed back as the return value of get.
|
||||
(*handler)(this, 0, buf, buf, len);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void bx_param_bytestring_c::set(const char *buf)
|
||||
{
|
||||
char *oldval = new char[maxsize];
|
||||
|
||||
memcpy(oldval, val, maxsize);
|
||||
if (handler) {
|
||||
// the handler can return a different char* to be copied into the value
|
||||
buf = (*handler)(this, 1, oldval, buf, -1);
|
||||
}
|
||||
memcpy(val, buf, maxsize);
|
||||
delete [] oldval;
|
||||
if (dependent_list != NULL) update_dependents();
|
||||
}
|
||||
|
||||
bx_bool bx_param_bytestring_c::equals(const char *buf) const
|
||||
{
|
||||
return (memcmp(val, buf, maxsize) == 0);
|
||||
}
|
||||
|
||||
void bx_param_bytestring_c::set_initial_val(const char *buf)
|
||||
{
|
||||
memcpy(initial_val, buf, maxsize);
|
||||
set(initial_val);
|
||||
}
|
||||
|
||||
bx_bool bx_param_bytestring_c::isempty() const
|
||||
{
|
||||
return (memcmp(val, initial_val, maxsize) == 0);
|
||||
}
|
||||
|
||||
int bx_param_bytestring_c::dump_param(char *buf, int len, bx_bool dquotes)
|
||||
{
|
||||
buf[0] = 0;
|
||||
for (int j = 0; j < maxsize; j++) {
|
||||
char tmpbyte[4];
|
||||
if (j > 0) {
|
||||
tmpbyte[0] = separator;
|
||||
tmpbyte[1] = 0;
|
||||
strcat(buf, tmpbyte);
|
||||
}
|
||||
sprintf(tmpbyte, "%02x", (Bit8u)val[j]);
|
||||
strcat(buf, tmpbyte);
|
||||
}
|
||||
return strlen(buf);
|
||||
}
|
||||
|
||||
bx_param_filename_c::bx_param_filename_c(bx_param_c *parent,
|
||||
const char *name,
|
||||
const char *label,
|
||||
const char *description,
|
||||
const char *initial_val,
|
||||
int maxsize)
|
||||
: bx_param_string_c(parent, name, label, description, initial_val, maxsize)
|
||||
{
|
||||
set_options(IS_FILENAME);
|
||||
int len = strlen(initial_val);
|
||||
if ((len > 4) && (initial_val[len - 4] == '.')) {
|
||||
ext = &initial_val[len - 3];
|
||||
} else {
|
||||
ext = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bx_shadow_data_c::bx_shadow_data_c(bx_param_c *parent,
|
||||
const char *name,
|
||||
Bit8u *ptr_to_data,
|
||||
|
@ -60,6 +60,7 @@ typedef enum {
|
||||
BXT_PARAM_BOOL,
|
||||
BXT_PARAM_ENUM,
|
||||
BXT_PARAM_STRING,
|
||||
BXT_PARAM_BYTESTRING,
|
||||
BXT_PARAM_DATA,
|
||||
BXT_PARAM_FILEDATA,
|
||||
BXT_LIST
|
||||
@ -387,20 +388,19 @@ typedef const char* (*param_string_event_handler)(class bx_param_string_c *,
|
||||
int set, const char *oldval, const char *newval, int maxlen);
|
||||
|
||||
class BOCHSAPI bx_param_string_c : public bx_param_c {
|
||||
protected:
|
||||
int maxsize;
|
||||
char *val, *initial_val;
|
||||
param_string_event_handler handler;
|
||||
param_enable_handler enable_handler;
|
||||
char separator;
|
||||
void update_dependents();
|
||||
public:
|
||||
enum {
|
||||
RAW_BYTES = 1, // use binary text editor, like MAC addr
|
||||
IS_FILENAME = 2, // 1=yes it's a filename, 0=not a filename.
|
||||
IS_FILENAME = 1, // 1=yes it's a filename, 0=not a filename.
|
||||
// Some guis have a file browser. This
|
||||
// bit suggests that they use it.
|
||||
SAVE_FILE_DIALOG = 4, // Use save dialog opposed to open file dialog
|
||||
SELECT_FOLDER_DLG = 8 // Use folder selection dialog
|
||||
SAVE_FILE_DIALOG = 2, // Use save dialog opposed to open file dialog
|
||||
SELECT_FOLDER_DLG = 4 // Use folder selection dialog
|
||||
} bx_string_opt_bits;
|
||||
bx_param_string_c(bx_param_c *parent,
|
||||
const char *name,
|
||||
@ -418,9 +418,7 @@ public:
|
||||
char *getptr() {return val; }
|
||||
const char *getptr() const {return val; }
|
||||
void set(const char *buf);
|
||||
bx_bool equals(const char *buf);
|
||||
void set_separator(char sep) {separator = sep; }
|
||||
char get_separator() const {return separator; }
|
||||
bx_bool equals(const char *buf) const;
|
||||
int get_maxsize() const {return maxsize; }
|
||||
void set_initial_val(const char *buf);
|
||||
bx_bool isempty() const;
|
||||
@ -433,6 +431,35 @@ public:
|
||||
virtual int dump_param(char *buf, int buflen, bx_bool dquotes = BX_FALSE);
|
||||
};
|
||||
|
||||
class BOCHSAPI bx_param_bytestring_c : public bx_param_string_c {
|
||||
char separator;
|
||||
public:
|
||||
bx_param_bytestring_c(bx_param_c *parent,
|
||||
const char *name,
|
||||
const char *label,
|
||||
const char *description,
|
||||
const char *initial_val,
|
||||
int maxsize) : bx_param_string_c(parent, name, label, description, initial_val, maxsize)
|
||||
{
|
||||
set_type(BXT_PARAM_BYTESTRING);
|
||||
}
|
||||
|
||||
void set_separator(char sep) {separator = sep; }
|
||||
char get_separator() const {return separator; }
|
||||
|
||||
Bit32s get(char *buf, int len);
|
||||
void set(const char *buf);
|
||||
bx_bool equals(const char *buf) const;
|
||||
void set_initial_val(const char *buf);
|
||||
bx_bool isempty() const;
|
||||
|
||||
#if BX_USE_TEXTCONFIG
|
||||
virtual int text_ask();
|
||||
#endif
|
||||
|
||||
virtual int dump_param(char *buf, int buflen, bx_bool dquotes = BX_FALSE);
|
||||
};
|
||||
|
||||
// Declare a filename class. It is identical to a string, except that
|
||||
// it initializes the options differently. This is just a shortcut
|
||||
// for declaring a string param and setting the options with IS_FILENAME.
|
||||
|
@ -285,7 +285,7 @@ bx_param_num_c *bx_real_sim_c::get_param_num(const char *pname, bx_param_c *base
|
||||
int type = gen->get_type();
|
||||
if (type == BXT_PARAM_NUM || type == BXT_PARAM_BOOL || type == BXT_PARAM_ENUM)
|
||||
return (bx_param_num_c *)gen;
|
||||
BX_ERROR(("get_param_num(%s) could not find an integer parameter with that name", pname));
|
||||
BX_ERROR(("get_param_num(%s) could not find a number parameter with that name", pname));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -296,9 +296,9 @@ bx_param_string_c *bx_real_sim_c::get_param_string(const char *pname, bx_param_c
|
||||
BX_ERROR(("get_param_string(%s) could not find a parameter", pname));
|
||||
return NULL;
|
||||
}
|
||||
if (gen->get_type() == BXT_PARAM_STRING)
|
||||
if (gen->get_type() == BXT_PARAM_STRING || gen->get_type() == BXT_PARAM_BYTESTRING)
|
||||
return (bx_param_string_c *)gen;
|
||||
BX_ERROR(("get_param_string(%s) could not find an integer parameter with that name", pname));
|
||||
BX_ERROR(("get_param_string(%s) could not find a string parameter with that name", pname));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -1246,26 +1246,23 @@ bx_bool bx_real_sim_c::restore_bochs_param(bx_list_c *root, const char *sr_path,
|
||||
case BXT_PARAM_NUM:
|
||||
case BXT_PARAM_BOOL:
|
||||
case BXT_PARAM_ENUM:
|
||||
case BXT_PARAM_STRING:
|
||||
param->parse_param(ptr);
|
||||
break;
|
||||
case BXT_PARAM_STRING:
|
||||
case BXT_PARAM_BYTESTRING:
|
||||
{
|
||||
bx_param_string_c *sparam = (bx_param_string_c*)param;
|
||||
if (sparam->get_options() & bx_param_string_c::RAW_BYTES) {
|
||||
p = 0;
|
||||
for (j = 0; j < sparam->get_maxsize(); j++) {
|
||||
if (ptr[p] == sparam->get_separator()) {
|
||||
p++;
|
||||
}
|
||||
if (sscanf(ptr+p, "%02x", &n) == 1) {
|
||||
buf[j] = n;
|
||||
p += 2;
|
||||
}
|
||||
bx_param_bytestring_c *sparam = (bx_param_bytestring_c*)param;
|
||||
p = 0;
|
||||
for (j = 0; j < sparam->get_maxsize(); j++) {
|
||||
if (ptr[p] == sparam->get_separator()) {
|
||||
p++;
|
||||
}
|
||||
if (sscanf(ptr+p, "%02x", &n) == 1) {
|
||||
buf[j] = n;
|
||||
p += 2;
|
||||
}
|
||||
if (!sparam->equals(buf)) sparam->set(buf);
|
||||
} else {
|
||||
if (!sparam->equals(ptr)) sparam->set(ptr);
|
||||
}
|
||||
if (!sparam->equals(buf)) sparam->set(buf);
|
||||
}
|
||||
break;
|
||||
case BXT_PARAM_DATA:
|
||||
@ -1369,6 +1366,7 @@ bx_bool bx_real_sim_c::save_sr_param(FILE *fp, bx_param_c *node, const char *sr_
|
||||
case BXT_PARAM_BOOL:
|
||||
case BXT_PARAM_ENUM:
|
||||
case BXT_PARAM_STRING:
|
||||
case BXT_PARAM_BYTESTRING:
|
||||
node->dump_param(fp);
|
||||
fprintf(fp, "\n");
|
||||
break;
|
||||
|
@ -946,7 +946,6 @@ int parse_raw_bytes(char *dest, char *src, int destsize, char separator)
|
||||
int bx_param_string_c::text_ask()
|
||||
{
|
||||
bx_printf("\n");
|
||||
int status;
|
||||
const char *prompt = get_ask_format();
|
||||
if (prompt == NULL) {
|
||||
if (options & SELECT_FOLDER_DLG) {
|
||||
@ -961,23 +960,46 @@ int bx_param_string_c::text_ask()
|
||||
}
|
||||
while (1) {
|
||||
char buffer[1024];
|
||||
status = ask_string(prompt, getptr(), buffer);
|
||||
int status = ask_string(prompt, getptr(), buffer);
|
||||
if (status == -2) {
|
||||
bx_printf("\n%s\n", get_description());
|
||||
continue;
|
||||
}
|
||||
if (status < 0) return status;
|
||||
int opts = options;
|
||||
char buffer2[1024];
|
||||
strcpy(buffer2, buffer);
|
||||
if (opts & RAW_BYTES) {
|
||||
if (status == 0) return 0;
|
||||
// copy raw hex into buffer
|
||||
status = parse_raw_bytes(buffer, buffer2, maxsize, separator);
|
||||
if (status < 0) {
|
||||
bx_printf("Illegal raw byte format. I expected something like 3A%c03%c12%c...\n", separator, separator, separator);
|
||||
continue;
|
||||
}
|
||||
if (!equals(buffer))
|
||||
set(buffer);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int bx_param_bytestring_c::text_ask()
|
||||
{
|
||||
bx_printf("\n");
|
||||
const char *prompt = get_ask_format();
|
||||
if (prompt == NULL) {
|
||||
// default prompt, if they didn't set an ask format string
|
||||
text_print();
|
||||
bx_printf("\n");
|
||||
prompt = "Enter a new value, '?' for help, or press return for no change.\n";
|
||||
}
|
||||
while (1) {
|
||||
char buffer[1024];
|
||||
int status = ask_string(prompt, getptr(), buffer);
|
||||
if (status == -2) {
|
||||
bx_printf("\n%s\n", get_description());
|
||||
continue;
|
||||
}
|
||||
if (status < 0) return status;
|
||||
char buffer2[1024];
|
||||
strcpy(buffer2, buffer);
|
||||
if (status == 0) return 0;
|
||||
// copy raw hex into buffer
|
||||
status = parse_raw_bytes(buffer, buffer2, maxsize, separator);
|
||||
if (status < 0) {
|
||||
bx_printf("Illegal raw byte format. I expected something like 3A%c03%c12%c...\n", separator, separator, separator);
|
||||
continue;
|
||||
}
|
||||
if (!equals(buffer))
|
||||
set(buffer);
|
||||
|
@ -1875,6 +1875,7 @@ void MakeBL(HTREEITEM *h_P, bx_param_c *p)
|
||||
case BXT_PARAM_BOOL:
|
||||
case BXT_PARAM_ENUM:
|
||||
case BXT_PARAM_STRING:
|
||||
case BXT_PARAM_BYTESTRING:
|
||||
p->dump_param(tmpstr, BX_PATHNAME_LEN);
|
||||
sprintf(tmpcb + j,": %s", tmpstr);
|
||||
break;
|
||||
|
@ -623,7 +623,7 @@ BxEvent* win32_notify_callback(void *unused, BxEvent *event)
|
||||
return event;
|
||||
case BX_SYNC_EVT_ASK_PARAM:
|
||||
param = event->u.param.param;
|
||||
if (param->get_type() == BXT_PARAM_STRING) {
|
||||
if (param->get_type() == BXT_PARAM_STRING || param->get_type() == BXT_PARAM_BYTESTRING) {
|
||||
sparam = (bx_param_string_c *)param;
|
||||
opts = sparam->get_options();
|
||||
if (opts & sparam->IS_FILENAME) {
|
||||
|
@ -527,10 +527,10 @@ HWND CreateInput(HWND hDlg, UINT cid, UINT xpos, UINT ypos, BOOL hide, bx_param_
|
||||
|
||||
code = ID_PARAM + cid;
|
||||
style = WS_CHILD | WS_TABSTOP;
|
||||
if (param->get_type() == BXT_PARAM_STRING) {
|
||||
if (param->get_type() == BXT_PARAM_STRING || param->get_type() == BXT_PARAM_BYTESTRING) {
|
||||
sparam = (bx_param_string_c*)param;
|
||||
sparam->dump_param(buffer, 512);
|
||||
if ((sparam->get_options() & sparam->RAW_BYTES) == 0) {
|
||||
if (param->get_type() != BXT_PARAM_BYTESTRING) {
|
||||
style |= ES_AUTOHSCROLL;
|
||||
}
|
||||
} else {
|
||||
@ -763,7 +763,7 @@ SIZE CreateParamList(HWND hDlg, UINT lid, UINT xpos, UINT ypos, BOOL hide, bx_li
|
||||
CreateCombobox(hParent, cid, x1, y, hide, (bx_param_enum_c*)param);
|
||||
} else if (param->get_type() == BXT_PARAM_NUM) {
|
||||
CreateInput(hParent, cid, x1, y, hide, param);
|
||||
} else if (param->get_type() == BXT_PARAM_STRING) {
|
||||
} else if (param->get_type() == BXT_PARAM_STRING || param->get_type() == BXT_PARAM_BYTESTRING) {
|
||||
CreateInput(hParent, cid, x1, y, hide, param);
|
||||
sparam = (bx_param_string_c*)param;
|
||||
if (sparam->get_options() & sparam->IS_FILENAME) {
|
||||
@ -801,10 +801,6 @@ SIZE CreateParamList(HWND hDlg, UINT lid, UINT xpos, UINT ypos, BOOL hide, bx_li
|
||||
void SetParamList(HWND hDlg, bx_list_c *list)
|
||||
{
|
||||
bx_param_c *param;
|
||||
bx_param_num_c *nparam;
|
||||
bx_param_enum_c *eparam;
|
||||
bx_param_bool_c *bparam;
|
||||
bx_param_string_c *sparam;
|
||||
int j;
|
||||
Bit64s val;
|
||||
const char *src;
|
||||
@ -824,12 +820,12 @@ void SetParamList(HWND hDlg, bx_list_c *list)
|
||||
SetParamList(hDlg, (bx_list_c*)param);
|
||||
} else if (param->get_type() == BXT_PARAM_BOOL) {
|
||||
val = (SendMessage(GetDlgItem(hDlg, ID_PARAM + cid), BM_GETCHECK, 0, 0) == BST_CHECKED);
|
||||
bparam = (bx_param_bool_c*)param;
|
||||
bx_param_bool_c *bparam = (bx_param_bool_c*)param;
|
||||
if (val != bparam->get()) {
|
||||
bparam->set(val);
|
||||
}
|
||||
} else if (param->get_type() == BXT_PARAM_ENUM) {
|
||||
eparam = (bx_param_enum_c*)param;
|
||||
bx_param_enum_c *eparam = (bx_param_enum_c*)param;
|
||||
val = (LRESULT)(SendMessage(GetDlgItem(hDlg, ID_PARAM + cid), CB_GETCURSEL, 0, 0) + eparam->get_min());
|
||||
if (val != eparam->get()) {
|
||||
eparam->set(val);
|
||||
@ -837,7 +833,7 @@ void SetParamList(HWND hDlg, bx_list_c *list)
|
||||
} else {
|
||||
if (SendMessage(GetDlgItem(hDlg, ID_PARAM + cid), EM_GETMODIFY, 0, 0)) {
|
||||
if (param->get_type() == BXT_PARAM_NUM) {
|
||||
nparam = (bx_param_num_c*)param;
|
||||
bx_param_num_c *nparam = (bx_param_num_c*)param;
|
||||
if (nparam->get_base() == BASE_HEX) {
|
||||
GetWindowText(GetDlgItem(hDlg, ID_PARAM + cid), buffer, 511);
|
||||
sscanf(buffer, "%x", &val);
|
||||
@ -848,25 +844,25 @@ void SetParamList(HWND hDlg, bx_list_c *list)
|
||||
nparam->set(val);
|
||||
} else if (param->get_type() == BXT_PARAM_STRING) {
|
||||
GetWindowText(GetDlgItem(hDlg, ID_PARAM + cid), buffer, 511);
|
||||
sparam = (bx_param_string_c*)param;
|
||||
if (sparam->get_options() & sparam->RAW_BYTES) {
|
||||
src = &buffer[0];
|
||||
memset(rawbuf, 0, sparam->get_maxsize());
|
||||
for (j = 0; j < sparam->get_maxsize(); j++) {
|
||||
while (*src == sparam->get_separator())
|
||||
src++;
|
||||
if (*src == 0) break;
|
||||
if (sscanf(src, "%02x", &val)) {
|
||||
rawbuf[j] = (char) val;
|
||||
src += 2;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
bx_param_string_c *sparam = (bx_param_string_c*)param;
|
||||
sparam->set(buffer);
|
||||
} else if (param->get_type() == BXT_PARAM_BYTESTRING) {
|
||||
GetWindowText(GetDlgItem(hDlg, ID_PARAM + cid), buffer, 511);
|
||||
bx_param_bytestring_c *sparam = (bx_param_bytestring_c*)param;
|
||||
src = &buffer[0];
|
||||
memset(rawbuf, 0, sparam->get_maxsize());
|
||||
for (j = 0; j < sparam->get_maxsize(); j++) {
|
||||
while (*src == sparam->get_separator())
|
||||
src++;
|
||||
if (*src == 0) break;
|
||||
if (sscanf(src, "%02x", &val)) {
|
||||
rawbuf[j] = (char) val;
|
||||
src += 2;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
sparam->set(rawbuf);
|
||||
} else {
|
||||
sparam->set(buffer);
|
||||
}
|
||||
sparam->set(rawbuf);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -942,7 +938,8 @@ void ProcessDependentList(HWND hDlg, bx_param_c *param, BOOL enabled)
|
||||
}
|
||||
} else if ((param->get_type() == BXT_PARAM_BOOL) ||
|
||||
(param->get_type() == BXT_PARAM_NUM) ||
|
||||
(param->get_type() == BXT_PARAM_STRING)) {
|
||||
(param->get_type() == BXT_PARAM_STRING) ||
|
||||
(param->get_type() == BXT_PARAM_BYTESTRING)) {
|
||||
if (param->get_type() == BXT_PARAM_BOOL) {
|
||||
value = SendMessage(GetDlgItem(hDlg, ID_PARAM + cid), BM_GETCHECK, 0, 0);
|
||||
} else if (param->get_type() == BXT_PARAM_NUM) {
|
||||
|
@ -873,6 +873,7 @@ void ParamDialog::AddParam(
|
||||
break;
|
||||
}
|
||||
case BXT_PARAM_STRING:
|
||||
case BXT_PARAM_BYTESTRING:
|
||||
{
|
||||
bx_param_string_c *param = (bx_param_string_c*) param_generic;
|
||||
char value[1024];
|
||||
@ -882,7 +883,7 @@ void ParamDialog::AddParam(
|
||||
if (description) txtctrl->SetToolTip(wxString(description, wxConvUTF8));
|
||||
param->dump_param(value, 1024);
|
||||
txtctrl->SetValue(wxString(value, wxConvUTF8));
|
||||
if ((param->get_options() & param->RAW_BYTES) == 0) {
|
||||
if (type != BXT_PARAM_BYTESTRING) {
|
||||
txtctrl->SetMaxLength(param->get_maxsize());
|
||||
}
|
||||
sizer->Add(txtctrl, 0, wxALL, 2);
|
||||
@ -1079,28 +1080,33 @@ bool ParamDialog::CopyGuiToParam(bx_param_c *param)
|
||||
bx_param_string_c *stringp = (bx_param_string_c*) pstr->param;
|
||||
char buf[1024];
|
||||
wxString tmp(pstr->u.text->GetValue());
|
||||
if (stringp->get_options() & stringp->RAW_BYTES) {
|
||||
char src[1024];
|
||||
int p = 0;
|
||||
unsigned int n;
|
||||
strcpy(src, tmp.mb_str(wxConvUTF8));
|
||||
for (i=0; i<stringp->get_maxsize(); i++)
|
||||
buf[i] = 0;
|
||||
for (i=0; i<stringp->get_maxsize(); i++) {
|
||||
while (src[p] == stringp->get_separator())
|
||||
p++;
|
||||
if (src[p] == 0) break;
|
||||
// try to read a byte of hex
|
||||
if (sscanf(src+p, "%02x", &n) == 1) {
|
||||
buf[i] = n;
|
||||
p+=2;
|
||||
} else {
|
||||
wxMessageBox(wxT("Illegal raw byte format"), wxT("Error"), wxOK | wxICON_ERROR, this);
|
||||
return false;
|
||||
}
|
||||
strncpy(buf, tmp.mb_str(wxConvUTF8), sizeof(buf));
|
||||
buf[sizeof(buf)-1] = 0;
|
||||
if (!stringp->equals(buf)) stringp->set(buf);
|
||||
break;
|
||||
}
|
||||
case BXT_PARAM_BYTESTRING: {
|
||||
bx_param_bytestring_c *stringp = (bx_param_bytestring_c*) pstr->param;
|
||||
char buf[1024];
|
||||
wxString tmp(pstr->u.text->GetValue());
|
||||
char src[1024];
|
||||
int p = 0;
|
||||
unsigned int n;
|
||||
strcpy(src, tmp.mb_str(wxConvUTF8));
|
||||
for (i=0; i<stringp->get_maxsize(); i++)
|
||||
buf[i] = 0;
|
||||
for (i=0; i<stringp->get_maxsize(); i++) {
|
||||
while (src[p] == stringp->get_separator())
|
||||
p++;
|
||||
if (src[p] == 0) break;
|
||||
// try to read a byte of hex
|
||||
if (sscanf(src+p, "%02x", &n) == 1) {
|
||||
buf[i] = n;
|
||||
p+=2;
|
||||
} else {
|
||||
wxMessageBox(wxT("Illegal raw byte format"), wxT("Error"), wxOK | wxICON_ERROR, this);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
strncpy(buf, tmp.mb_str(wxConvUTF8), sizeof(buf));
|
||||
}
|
||||
buf[sizeof(buf)-1] = 0;
|
||||
if (!stringp->equals(buf)) stringp->set(buf);
|
||||
@ -1180,7 +1186,8 @@ void ParamDialog::ProcessDependentList(ParamStruct *pstrChanged, bool enabled)
|
||||
}
|
||||
} else if ((pstrChanged->param->get_type() == BXT_PARAM_BOOL) ||
|
||||
(pstrChanged->param->get_type() == BXT_PARAM_NUM) ||
|
||||
(pstrChanged->param->get_type() == BXT_PARAM_STRING)) {
|
||||
(pstrChanged->param->get_type() == BXT_PARAM_STRING) ||
|
||||
(pstrChanged->param->get_type() == BXT_PARAM_BYTESTRING)) {
|
||||
bx_param_c *param = pstrChanged->param;
|
||||
if (param->get_type() == BXT_PARAM_BOOL) {
|
||||
value = pstrChanged->u.checkbox->GetValue();
|
||||
@ -1242,7 +1249,8 @@ void ParamDialog::CopyParamToGui()
|
||||
pstr->u.choice->SetSelection(enump->get() - enump->get_min());
|
||||
break;
|
||||
}
|
||||
case BXT_PARAM_STRING: {
|
||||
case BXT_PARAM_STRING:
|
||||
case BXT_PARAM_BYTESTRING: {
|
||||
bx_param_string_c *stringp = (bx_param_string_c*) pstr->param;
|
||||
pstr->u.text->SetValue(wxString(stringp->getptr(), wxConvUTF8));
|
||||
break;
|
||||
@ -1271,6 +1279,7 @@ void ParamDialog::OnEvent(wxCommandEvent& event)
|
||||
case BXT_PARAM_NUM:
|
||||
case BXT_PARAM_ENUM:
|
||||
case BXT_PARAM_STRING:
|
||||
case BXT_PARAM_BYTESTRING:
|
||||
EnableChanged(pstr);
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user